Zeekygen: Refine location tracking for Spicy events.

When Spicy defines an event through EVT, it would end up with
more-or-less random, stale Zeek-side location information. Now making
sure it's unset, plus then using any script-side prototype we may
encounter later to update it.

Also fixing a couple location comparisons that I believe were broken
because we do sometimes copy location objects and hence can't compare
by pointer.
This commit is contained in:
Robin Sommer 2023-09-18 14:10:40 +02:00
parent d45d197c21
commit 8a3d645caf
No known key found for this signature in database
GPG key ID: D8187293B3FFE5D0
3 changed files with 11 additions and 2 deletions

View file

@ -345,6 +345,13 @@ static StmtPtr build_local(ID* id, Type* t, InitClass ic, Expr* e,
return init;
}
static void refine_location(zeek::detail::ID* id)
{
if ( *id->GetLocationInfo() == zeek::detail::no_location )
id->SetLocationInfo(&detail::start_location, &detail::end_location);
}
%}
%union {
@ -2204,6 +2211,7 @@ global_or_event_id:
reporter->Deprecation($$->GetDeprecationWarning());
}
refine_location($$);
delete [] $1;
}

View file

@ -794,6 +794,7 @@ void Manager::loadModule(const hilti::rt::filesystem::path& path) {
if ( auto [library, inserted] = _libraries.insert({canonical_path, hilti::rt::Library(canonical_path)});
inserted ) {
SPICY_DEBUG(hilti::rt::fmt("Loading %s", canonical_path.native()));
set_location(detail::no_location); // make sure IDs get installed without stale location info
if ( auto load = library->second.open(); ! load )
hilti::rt::fatalError(
hilti::rt::fmt("could not open library path %s: %s", canonical_path, load.error()));

View file

@ -247,7 +247,7 @@ void Manager::StartType(zeek::detail::IDPtr id)
if ( disabled )
return;
if ( id->GetLocationInfo() == &zeek::detail::no_location )
if ( *id->GetLocationInfo() == zeek::detail::no_location )
{
DbgAndWarn(util::fmt("Can't generate zeekygen documentation for %s, "
"no location available",
@ -309,7 +309,7 @@ void Manager::Identifier(zeek::detail::IDPtr id, bool from_redef)
return;
}
if ( id->GetLocationInfo() == &zeek::detail::no_location )
if ( *id->GetLocationInfo() == zeek::detail::no_location )
{
// Internally-created identifier (e.g. file/proto analyzer enum tags).
// Handled specially since they don't have a script location.