return ts_node_start_point (node).row + 1;
}
+/* -------------------------------- The file -------------------------------- */
+
+/* The entire contents of the file being analyzed. */
+static const char *contents;
+
/* -------------------------------- Comments -------------------------------- */
/* These are for tracking whether comments count as immediately before
/* Forward declarations. */
static void extract_from_node (TSNode node,
flag_region_ty *outer_region,
- message_list_ty *mlp,
- const char *contents);
+ message_list_ty *mlp);
/* Extracts messages from the function call consisting of
- CALLEE_NODE: a tree node of type 'identifier',
extract_from_function_call (TSNode callee_node,
TSNode args_node,
flag_region_ty *outer_region,
- message_list_ty *mlp,
- const char *contents)
+ message_list_ty *mlp)
{
uint32_t args_count = ts_node_child_count (args_node);
_("too many open parentheses, brackets, or braces"));
extract_from_node (arg_node,
arg_region,
- mlp,
- contents);
+ mlp);
nesting_depth--;
}
_("too many open parentheses, brackets, or braces"));
extract_from_node (arg_node,
arg_region,
- mlp,
- contents);
+ mlp);
nesting_depth--;
unref_region (arg_region);
extract_from_function_call_like (TSNode *callee_node, bool callee_is_macro,
TSNode args_node,
flag_region_ty *outer_region,
- message_list_ty *mlp,
- const char *contents)
+ message_list_ty *mlp)
{
/* We have a macro, named by a relevant identifier, with an argument list.
The args_node contains the argument tokens (some of them of type
&identifier_node, false,
arg_node,
arg_region,
- mlp,
- contents);
+ mlp);
}
else if (prev2_token_in_same_arg > 0
&& ts_node_symbol (ts_node_child (args_node, prev2_token_in_same_arg)) == ts_symbol_identifier
&identifier_node, true,
arg_node,
arg_region,
- mlp,
- contents);
+ mlp);
}
else
/* A token sequence that looks like a parenthesized expression. */
NULL, false,
arg_node,
arg_region,
- mlp,
- contents);
+ mlp);
}
else
{
if (!already_extracted)
extract_from_node (arg_node,
arg_region,
- mlp,
- contents);
+ mlp);
}
nesting_depth--;
&identifier_node, false,
arg_node,
arg_region,
- mlp,
- contents);
+ mlp);
}
else if (prev2_token_in_same_arg > 0
&& ts_node_symbol (ts_node_child (args_node, prev2_token_in_same_arg)) == ts_symbol_identifier
&identifier_node, true,
arg_node,
arg_region,
- mlp,
- contents);
+ mlp);
}
else
/* A token sequence that looks like a parenthesized expression. */
NULL, false,
arg_node,
arg_region,
- mlp,
- contents);
+ mlp);
}
else
extract_from_node (arg_node,
arg_region,
- mlp,
- contents);
+ mlp);
nesting_depth--;
if (!(ts_node_symbol (arg_node) == ts_symbol_line_comment
static void
extract_from_node (TSNode node,
flag_region_ty *outer_region,
- message_list_ty *mlp,
- const char *contents)
+ message_list_ty *mlp)
{
if (extract_all
&& (ts_node_symbol (node) == ts_symbol_string_literal
}
extract_from_function_call (callee_node, args_node,
outer_region,
- mlp,
- contents);
+ mlp);
return;
}
}
extract_from_function_call_like (&callee_node, true,
args_node,
outer_region,
- mlp,
- contents);
+ mlp);
return;
}
}
_("too many open parentheses, brackets, or braces"));
extract_from_node (subnode,
outer_region,
- mlp,
- contents);
+ mlp);
nesting_depth--;
}
}
}
/* Read the file into memory. */
- char *contents;
+ char *contents_data;
size_t contents_length;
- contents = read_file (real_filename, 0, &contents_length);
- if (contents == NULL)
+ contents_data = read_file (real_filename, 0, &contents_length);
+ if (contents_data == NULL)
error (EXIT_FAILURE, errno, _("error while reading \"%s\""),
real_filename);
/* Rust source files are UTF-8 encoded.
<https://doc.rust-lang.org/1.6.0/reference.html#input-format> */
- if (u8_check ((uint8_t *) contents, contents_length) != NULL)
+ if (u8_check ((uint8_t *) contents_data, contents_length) != NULL)
error (EXIT_FAILURE, 0,
_("file \"%s\" is invalid because not UTF-8 encoded"),
real_filename);
ts_parser_set_language (parser, ts_language);
/* Parse the file, producing a syntax tree. */
- TSTree *tree = ts_parser_parse_string (parser, NULL, contents, contents_length);
+ TSTree *tree = ts_parser_parse_string (parser, NULL, contents_data, contents_length);
#if DEBUG_RUST
/* For debugging: Print the tree. */
}
#endif
+ contents = contents_data;
+
extract_from_node (ts_tree_root_node (tree),
null_context_region (),
- mlp,
- contents);
+ mlp);
ts_tree_delete (tree);
ts_parser_delete (parser);
- free (contents);
+ free (contents_data);
logical_file_name = NULL;
}