remove non-functional column information from Location objects

This commit is contained in:
Vern Paxson 2025-07-03 17:08:23 -07:00 committed by Arne Welzel
parent 5c63133226
commit a9b37467a4
11 changed files with 15 additions and 32 deletions

View file

@ -84,8 +84,7 @@ bool StmtLocMapping::StartsAfter(const StmtLocMapping* m2) {
if ( ! m2 )
reporter->InternalError("Assertion failed: m2 != 0");
return loc.FirstLine() > m2->loc.FirstLine() ||
(loc.FirstLine() == m2->loc.FirstLine() && loc.FirstColumn() > m2->loc.FirstColumn());
return loc.FirstLine() > m2->loc.FirstLine();
}
// Generic debug message output.

View file

@ -12,8 +12,8 @@
namespace zeek {
namespace detail {
Location start_location("<start uninitialized>", 0, 0, 0, 0);
Location end_location("<end uninitialized>", 0, 0, 0, 0);
Location start_location("<start uninitialized>", 0, 0);
Location end_location("<end uninitialized>", 0, 0);
void Location::Describe(ODesc* d) const {
if ( FileName() ) {
@ -132,8 +132,7 @@ bool Obj::SetLocationInfo(const detail::Location* start, const detail::Location*
// We already have a better location, so don't use this one.
return true;
auto new_location = new detail::Location(start->FileName(), start->FirstLine(), end->LastLine(),
start->FirstColumn(), end->LastColumn());
auto new_location = new detail::Location(start->FileName(), start->FirstLine(), end->LastLine());
// Don't delete this until we've constructed the new location, in case
// "start" or "end" are our own location.
@ -148,7 +147,6 @@ void Obj::UpdateLocationEndInfo(const detail::Location& end) {
SetLocationInfo(&end, &end);
location->SetLastLine(end.LastLine());
location->SetLastColumn(end.LastColumn());
}
void Obj::DoMsg(ODesc* d, const char s1[], const Obj* obj2, bool pinpoint_only,

View file

@ -13,8 +13,7 @@ namespace detail {
class Location final {
public:
constexpr Location(const char* fname, int line_f, int line_l, int col_f, int col_l) noexcept
: filename(fname), first_column(col_f), last_column(col_l) {
constexpr Location(const char* fname, int line_f, int line_l) noexcept : filename(fname) {
SetLines(line_f, line_l);
}
@ -29,10 +28,6 @@ public:
int FirstLine() const { return first_line; }
int LastLine() const { return last_line; }
// Columns are actually not currently maintained.
auto FirstColumn() const { return first_column; }
auto LastColumn() const { return last_column; }
void SetFile(const char* fname) { filename = fname; }
void SetLine(int line) { SetLines(line, line); }
constexpr void SetLines(int first, int last) {
@ -53,14 +48,9 @@ public:
last_line += incr;
}
void SetFirstColumn(int col) { first_column = col; }
void SetLastColumn(int col) { last_column = col; }
private:
const char* filename = nullptr;
int first_line = 0, last_line = 0;
int first_column = 0, last_column = 0; // not currently maintained
};
#define YYLTYPE zeek::detail::yyltype
@ -69,7 +59,7 @@ YYLTYPE GetCurrentLocation();
void SetCurrentLocation(YYLTYPE currloc);
// Used to mean "no location associated with this object".
inline constexpr Location no_location("<no location>", 0, 0, 0, 0);
inline constexpr Location no_location("<no location>", 0, 0);
// Current start/end location.
extern Location start_location;

View file

@ -2626,7 +2626,7 @@ const TypePtr& base_type(TypeTag tag) {
if ( ! base_types[tag] ) {
base_types[tag] = make_intrusive<Type>(tag, true);
// Give the base types a pseudo-location for easier identification.
detail::Location l(type_name(tag), 0, 0, 0, 0);
detail::Location l(type_name(tag), 0, 0);
base_types[tag]->SetLocationInfo(&l);
}

View file

@ -108,7 +108,7 @@ rule_list:
rule:
TOK_SIGNATURE TOK_IDENT
{
zeek::detail::Location l(current_rule_file, rules_line_number+1, 0, 0, 0);
zeek::detail::Location l(current_rule_file, rules_line_number+1, 0);
current_rule = new zeek::detail::Rule(yylval.str, l);
}
'{' rule_attr_list '}'

View file

@ -53,7 +53,7 @@
using namespace zeek::detail;
extern YYLTYPE yylloc; // holds start line and column of token
extern YYLTYPE yylloc; // holds location of token
extern zeek::EnumType* cur_enum_type;
// Track the @if... depth.
@ -218,8 +218,6 @@ static int switch_to(const char* file, YY_BUFFER_STATE buffer);
// for error reporting and debugging).
static zeek::name_list input_files;
static zeek::name_list essential_input_files;
// ### TODO: columns too - use yyless with '.' action?
%}
%option nounput nodefault

View file

@ -37,7 +37,7 @@ CPPStmt::CPPStmt(const char* _name, const char* filename, int line_num) : Stmt(S
auto empty_args = make_intrusive<ListExpr>();
ce = make_intrusive<CallExpr>(make_intrusive<ConstExpr>(fv), empty_args);
Location loc(filename, line_num, line_num, 1, 1);
Location loc(filename, line_num, line_num);
ce->SetLocationInfo(&loc);
}

View file

@ -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->FirstLine()),
std::to_string(loc->LastLine()), std::to_string(loc->FirstColumn()), std::to_string(loc->LastColumn()));
Emit("static Location loc(\"%s\", %s, %s);", loc->FileName(), std::to_string(loc->FirstLine()),
std::to_string(loc->LastLine()));
Emit("report_assert(assert_result, \"%s\", msg_val, &loc);", CPPEscape(a->CondDesc().c_str()).c_str());
EndBlock();

View file

@ -23,8 +23,7 @@ ZAMCompiler::ZAMCompiler(ScriptFuncPtr f, std::shared_ptr<ProfileFuncs> _pfs, st
auto loc = body->GetLocationInfo();
ASSERT(loc->FirstLine() != 0 || body->Tag() == STMT_NULL);
auto loc_copy = std::make_shared<Location>(loc->FileName(), loc->FirstLine(), loc->LastLine(), loc->FirstColumn(),
loc->LastColumn());
auto loc_copy = std::make_shared<Location>(loc->FileName(), loc->FirstLine(), loc->LastLine());
ZAM::curr_func = func->GetName();
ZAM::curr_loc = std::make_shared<ZAMLocInfo>(ZAM::curr_func, std::move(loc_copy), nullptr);

View file

@ -13,8 +13,7 @@ namespace zeek::detail {
const ZAMStmt ZAMCompiler::CompileStmt(const Stmt* s) {
auto loc = s->GetLocationInfo();
ASSERT(loc->FirstLine() != 0 || s->Tag() == STMT_NULL);
auto loc_copy = std::make_shared<Location>(loc->FileName(), loc->FirstLine(), loc->LastLine(), loc->FirstColumn(),
loc->LastColumn());
auto loc_copy = std::make_shared<Location>(loc->FileName(), loc->FirstLine(), loc->LastLine());
ASSERT(! AST_blocks || s->Tag() == STMT_NULL || AST_blocks->HaveExpDesc(loc_copy.get()));
auto loc_parent = ZAM::curr_loc->Parent();
ZAM::curr_loc = std::make_shared<ZAMLocInfo>(ZAM::curr_func, std::move(loc_copy), ZAM::curr_loc->Parent());

View file

@ -859,7 +859,7 @@ void Manager::searchModules(const std::string& paths) {
detail::Location Manager::makeLocation(const std::string& fname) {
auto x = _locations.insert(fname);
return {x.first->c_str(), 0, 0, 0, 0};
return {x.first->c_str(), 0, 0};
}
void Manager::autoDiscoverModules() {