scan.l: Extract switch_to() from load_files()

This commit is contained in:
Arne Welzel 2025-02-28 17:36:23 +01:00
parent 2a8040039a
commit d079a2b9a8

View file

@ -219,6 +219,9 @@ static zeek::PList<FileInfo> file_stack;
// Returns true if the file is new, false if it's already been scanned. // Returns true if the file is new, false if it's already been scanned.
static int load_files(const char* file); static int load_files(const char* file);
// Update the current parsing and location state for the given file and buffer.
static int switch_to(const char* file, YY_BUFFER_STATE buffer);
// ### TODO: columns too - use yyless with '.' action? // ### TODO: columns too - use yyless with '.' action?
%} %}
@ -702,6 +705,23 @@ void zeek::detail::SetCurrentLocation(YYLTYPE currloc)
line_number = currloc.first_line; line_number = currloc.first_line;
} }
static int switch_to(const char* file, YY_BUFFER_STATE buffer)
{
yy_switch_to_buffer(buffer);
yylloc.first_line = yylloc.last_line = line_number = 1;
// Don't delete the old filename - it's pointed to by
// every Obj created when parsing it.
yylloc.filename = filename = zeek::util::copy_string(file);
current_file_has_conditionals = files_with_conditionals.count(filename) > 0;
entry_cond_depth.push_back(conditional_depth);
entry_pragma_stack_depth.push_back(pragma_stack.size());
return 1;
}
static int load_files(const char* orig_file) static int load_files(const char* orig_file)
{ {
std::string file_path = find_relative_script_file(orig_file); std::string file_path = find_relative_script_file(orig_file);
@ -800,19 +820,7 @@ static int load_files(const char* orig_file)
buffer = yy_create_buffer(f, YY_BUF_SIZE); buffer = yy_create_buffer(f, YY_BUF_SIZE);
} }
yy_switch_to_buffer(buffer); return switch_to(file_path.c_str(), buffer);
yylloc.first_line = yylloc.last_line = line_number = 1;
// Don't delete the old filename - it's pointed to by
// every Obj created when parsing it.
yylloc.filename = filename = zeek::util::copy_string(file_path.c_str());
current_file_has_conditionals = files_with_conditionals.count(filename) > 0;
entry_cond_depth.push_back(conditional_depth);
entry_pragma_stack_depth.push_back(pragma_stack.size());
return 1;
} }
void begin_RE() void begin_RE()