isolate Location specifics to private class variables to enforce correct line number ordering

This commit is contained in:
Vern Paxson 2025-07-03 16:41:14 -07:00 committed by Arne Welzel
parent eb6b4a0c46
commit 5c63133226
30 changed files with 172 additions and 136 deletions

View file

@ -148,7 +148,7 @@ void CPPCompile::DeclareSubclass(const FuncTypePtr& ft, const ProfileFunc* pf, c
stmts = pf->ProfiledExpr();
auto loc = stmts->GetLocationInfo();
auto loc_info = string("\"") + loc->filename + "\", " + Fmt(loc->first_line);
auto loc_info = string("\"") + loc->FileName() + "\", " + Fmt(loc->FirstLine());
Emit("%s_cl(const char* name%s) : CPPStmt(name, %s)%s { }", fname, addl_args, loc_info, inits);
// An additional constructor just used to generate place-holder

View file

@ -193,7 +193,7 @@ bool CPPCompile::AnalyzeFuncBody(FuncInfo& fi, unordered_set<string>& filenames_
const auto& f = fi.Func();
auto& body = fi.Body();
string fn = body->GetLocationInfo()->filename;
string fn = body->GetLocationInfo()->FileName();
if ( ! analysis_options.allow_cond && ! fi.ShouldSkip() ) {
if ( ! analysis_options.only_files.empty() && files_with_conditionals.count(fn) > 0 ) {
@ -358,7 +358,7 @@ void CPPCompile::RegisterCompiledBody(const string& f) {
auto h = body_hashes[f];
auto p = body_priorities[f];
auto loc = body_locs[f];
auto body_info = Fmt(p) + ", " + Fmt(h) + ", \"" + loc->filename + " (C++)\", " + Fmt(loc->first_line);
auto body_info = Fmt(p) + ", " + Fmt(h) + ", \"" + loc->FileName() + " (C++)\", " + Fmt(loc->FirstLine());
Emit("\tCPP_RegisterBody(\"%s\", (void*) %s, %s, %s, std::vector<std::string>(%s)),", f, f, Fmt(type_signature),
body_info, events);

View file

@ -182,8 +182,8 @@ string CPPCompile::BodyName(const FuncInfo& func) {
// Extend name with location information.
auto loc = body->GetLocationInfo();
if ( loc->filename ) {
auto fn = loc->filename;
if ( loc->FileName() ) {
auto fn = loc->FileName();
// Skip leading goop that gets added by search paths.
while ( *fn == '.' || *fn == '/' )

View file

@ -11,7 +11,7 @@ using namespace std;
void CPPCompile::GenStmt(const Stmt* s) {
auto loc = s->GetLocationInfo();
if ( loc != &detail::no_location && s->Tag() != STMT_LIST )
Emit("// %s:%s", loc->filename, to_string(loc->first_line));
Emit("// %s:%d", loc->FileName(), loc->FirstLine());
switch ( s->Tag() ) {
case STMT_INIT: GenInitStmt(s->AsInitStmt()); break;
@ -498,8 +498,8 @@ void CPPCompile::GenAssertStmt(const AssertStmt* a) {
Emit("auto msg_val = zeek::val_mgr->EmptyString();");
auto loc = a->GetLocationInfo();
Emit("static Location loc(\"%s\", %s, %s, %s, %s);", loc->filename, std::to_string(loc->first_line),
std::to_string(loc->last_line), std::to_string(loc->first_column), std::to_string(loc->last_column));
Emit("static Location loc(\"%s\", %s, %s, %s, %s);", loc->FileName(), std::to_string(loc->FirstLine()),
std::to_string(loc->LastLine()), std::to_string(loc->FirstColumn()), std::to_string(loc->LastColumn()));
Emit("report_assert(assert_result, \"%s\", msg_val, &loc);", CPPEscape(a->CondDesc().c_str()).c_str());
EndBlock();

View file

@ -205,7 +205,7 @@ shared_ptr<CPP_InitInfo> CPPCompile::RegisterType(const TypePtr& tp) {
auto tr = tp->AsRecordType();
for ( auto i = tr->NumOrigFields(); i < tr->NumFields(); ++i ) {
auto fd = tr->FieldDecl(i);
if ( filename_matches_opt_files(fd->GetLocationInfo()->filename) ) {
if ( filename_matches_opt_files(fd->GetLocationInfo()->FileName()) ) {
if ( addl_fields == 0 )
addl_fields = i;
}