mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
remove non-functional column information from Location objects
This commit is contained in:
parent
5c63133226
commit
a9b37467a4
11 changed files with 15 additions and 32 deletions
|
@ -84,8 +84,7 @@ bool StmtLocMapping::StartsAfter(const StmtLocMapping* m2) {
|
||||||
if ( ! m2 )
|
if ( ! m2 )
|
||||||
reporter->InternalError("Assertion failed: m2 != 0");
|
reporter->InternalError("Assertion failed: m2 != 0");
|
||||||
|
|
||||||
return loc.FirstLine() > m2->loc.FirstLine() ||
|
return loc.FirstLine() > m2->loc.FirstLine();
|
||||||
(loc.FirstLine() == m2->loc.FirstLine() && loc.FirstColumn() > m2->loc.FirstColumn());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generic debug message output.
|
// Generic debug message output.
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
namespace zeek {
|
namespace zeek {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
Location start_location("<start uninitialized>", 0, 0, 0, 0);
|
Location start_location("<start uninitialized>", 0, 0);
|
||||||
Location end_location("<end uninitialized>", 0, 0, 0, 0);
|
Location end_location("<end uninitialized>", 0, 0);
|
||||||
|
|
||||||
void Location::Describe(ODesc* d) const {
|
void Location::Describe(ODesc* d) const {
|
||||||
if ( FileName() ) {
|
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.
|
// We already have a better location, so don't use this one.
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
auto new_location = new detail::Location(start->FileName(), start->FirstLine(), end->LastLine(),
|
auto new_location = new detail::Location(start->FileName(), start->FirstLine(), end->LastLine());
|
||||||
start->FirstColumn(), end->LastColumn());
|
|
||||||
|
|
||||||
// Don't delete this until we've constructed the new location, in case
|
// Don't delete this until we've constructed the new location, in case
|
||||||
// "start" or "end" are our own location.
|
// "start" or "end" are our own location.
|
||||||
|
@ -148,7 +147,6 @@ void Obj::UpdateLocationEndInfo(const detail::Location& end) {
|
||||||
SetLocationInfo(&end, &end);
|
SetLocationInfo(&end, &end);
|
||||||
|
|
||||||
location->SetLastLine(end.LastLine());
|
location->SetLastLine(end.LastLine());
|
||||||
location->SetLastColumn(end.LastColumn());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Obj::DoMsg(ODesc* d, const char s1[], const Obj* obj2, bool pinpoint_only,
|
void Obj::DoMsg(ODesc* d, const char s1[], const Obj* obj2, bool pinpoint_only,
|
||||||
|
|
14
src/Obj.h
14
src/Obj.h
|
@ -13,8 +13,7 @@ namespace detail {
|
||||||
|
|
||||||
class Location final {
|
class Location final {
|
||||||
public:
|
public:
|
||||||
constexpr Location(const char* fname, int line_f, int line_l, int col_f, int col_l) noexcept
|
constexpr Location(const char* fname, int line_f, int line_l) noexcept : filename(fname) {
|
||||||
: filename(fname), first_column(col_f), last_column(col_l) {
|
|
||||||
SetLines(line_f, line_l);
|
SetLines(line_f, line_l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,10 +28,6 @@ public:
|
||||||
int FirstLine() const { return first_line; }
|
int FirstLine() const { return first_line; }
|
||||||
int LastLine() const { return last_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 SetFile(const char* fname) { filename = fname; }
|
||||||
void SetLine(int line) { SetLines(line, line); }
|
void SetLine(int line) { SetLines(line, line); }
|
||||||
constexpr void SetLines(int first, int last) {
|
constexpr void SetLines(int first, int last) {
|
||||||
|
@ -53,14 +48,9 @@ public:
|
||||||
last_line += incr;
|
last_line += incr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetFirstColumn(int col) { first_column = col; }
|
|
||||||
void SetLastColumn(int col) { last_column = col; }
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char* filename = nullptr;
|
const char* filename = nullptr;
|
||||||
int first_line = 0, last_line = 0;
|
int first_line = 0, last_line = 0;
|
||||||
int first_column = 0, last_column = 0; // not currently maintained
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define YYLTYPE zeek::detail::yyltype
|
#define YYLTYPE zeek::detail::yyltype
|
||||||
|
@ -69,7 +59,7 @@ YYLTYPE GetCurrentLocation();
|
||||||
void SetCurrentLocation(YYLTYPE currloc);
|
void SetCurrentLocation(YYLTYPE currloc);
|
||||||
|
|
||||||
// Used to mean "no location associated with this object".
|
// 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.
|
// Current start/end location.
|
||||||
extern Location start_location;
|
extern Location start_location;
|
||||||
|
|
|
@ -2626,7 +2626,7 @@ const TypePtr& base_type(TypeTag tag) {
|
||||||
if ( ! base_types[tag] ) {
|
if ( ! base_types[tag] ) {
|
||||||
base_types[tag] = make_intrusive<Type>(tag, true);
|
base_types[tag] = make_intrusive<Type>(tag, true);
|
||||||
// Give the base types a pseudo-location for easier identification.
|
// 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);
|
base_types[tag]->SetLocationInfo(&l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ rule_list:
|
||||||
rule:
|
rule:
|
||||||
TOK_SIGNATURE TOK_IDENT
|
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);
|
current_rule = new zeek::detail::Rule(yylval.str, l);
|
||||||
}
|
}
|
||||||
'{' rule_attr_list '}'
|
'{' rule_attr_list '}'
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
|
|
||||||
using namespace zeek::detail;
|
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;
|
extern zeek::EnumType* cur_enum_type;
|
||||||
|
|
||||||
// Track the @if... depth.
|
// Track the @if... depth.
|
||||||
|
@ -218,8 +218,6 @@ static int switch_to(const char* file, YY_BUFFER_STATE buffer);
|
||||||
// for error reporting and debugging).
|
// for error reporting and debugging).
|
||||||
static zeek::name_list input_files;
|
static zeek::name_list input_files;
|
||||||
static zeek::name_list essential_input_files;
|
static zeek::name_list essential_input_files;
|
||||||
|
|
||||||
// ### TODO: columns too - use yyless with '.' action?
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%option nounput nodefault
|
%option nounput nodefault
|
||||||
|
|
|
@ -37,7 +37,7 @@ CPPStmt::CPPStmt(const char* _name, const char* filename, int line_num) : Stmt(S
|
||||||
auto empty_args = make_intrusive<ListExpr>();
|
auto empty_args = make_intrusive<ListExpr>();
|
||||||
|
|
||||||
ce = make_intrusive<CallExpr>(make_intrusive<ConstExpr>(fv), empty_args);
|
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);
|
ce->SetLocationInfo(&loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -498,8 +498,8 @@ void CPPCompile::GenAssertStmt(const AssertStmt* a) {
|
||||||
Emit("auto msg_val = zeek::val_mgr->EmptyString();");
|
Emit("auto msg_val = zeek::val_mgr->EmptyString();");
|
||||||
|
|
||||||
auto loc = a->GetLocationInfo();
|
auto loc = a->GetLocationInfo();
|
||||||
Emit("static Location loc(\"%s\", %s, %s, %s, %s);", loc->FileName(), std::to_string(loc->FirstLine()),
|
Emit("static Location loc(\"%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()));
|
std::to_string(loc->LastLine()));
|
||||||
Emit("report_assert(assert_result, \"%s\", msg_val, &loc);", CPPEscape(a->CondDesc().c_str()).c_str());
|
Emit("report_assert(assert_result, \"%s\", msg_val, &loc);", CPPEscape(a->CondDesc().c_str()).c_str());
|
||||||
EndBlock();
|
EndBlock();
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,7 @@ ZAMCompiler::ZAMCompiler(ScriptFuncPtr f, std::shared_ptr<ProfileFuncs> _pfs, st
|
||||||
|
|
||||||
auto loc = body->GetLocationInfo();
|
auto loc = body->GetLocationInfo();
|
||||||
ASSERT(loc->FirstLine() != 0 || body->Tag() == STMT_NULL);
|
ASSERT(loc->FirstLine() != 0 || body->Tag() == STMT_NULL);
|
||||||
auto loc_copy = std::make_shared<Location>(loc->FileName(), loc->FirstLine(), loc->LastLine(), loc->FirstColumn(),
|
auto loc_copy = std::make_shared<Location>(loc->FileName(), loc->FirstLine(), loc->LastLine());
|
||||||
loc->LastColumn());
|
|
||||||
ZAM::curr_func = func->GetName();
|
ZAM::curr_func = func->GetName();
|
||||||
ZAM::curr_loc = std::make_shared<ZAMLocInfo>(ZAM::curr_func, std::move(loc_copy), nullptr);
|
ZAM::curr_loc = std::make_shared<ZAMLocInfo>(ZAM::curr_func, std::move(loc_copy), nullptr);
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,7 @@ namespace zeek::detail {
|
||||||
const ZAMStmt ZAMCompiler::CompileStmt(const Stmt* s) {
|
const ZAMStmt ZAMCompiler::CompileStmt(const Stmt* s) {
|
||||||
auto loc = s->GetLocationInfo();
|
auto loc = s->GetLocationInfo();
|
||||||
ASSERT(loc->FirstLine() != 0 || s->Tag() == STMT_NULL);
|
ASSERT(loc->FirstLine() != 0 || s->Tag() == STMT_NULL);
|
||||||
auto loc_copy = std::make_shared<Location>(loc->FileName(), loc->FirstLine(), loc->LastLine(), loc->FirstColumn(),
|
auto loc_copy = std::make_shared<Location>(loc->FileName(), loc->FirstLine(), loc->LastLine());
|
||||||
loc->LastColumn());
|
|
||||||
ASSERT(! AST_blocks || s->Tag() == STMT_NULL || AST_blocks->HaveExpDesc(loc_copy.get()));
|
ASSERT(! AST_blocks || s->Tag() == STMT_NULL || AST_blocks->HaveExpDesc(loc_copy.get()));
|
||||||
auto loc_parent = ZAM::curr_loc->Parent();
|
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());
|
ZAM::curr_loc = std::make_shared<ZAMLocInfo>(ZAM::curr_func, std::move(loc_copy), ZAM::curr_loc->Parent());
|
||||||
|
|
|
@ -859,7 +859,7 @@ void Manager::searchModules(const std::string& paths) {
|
||||||
|
|
||||||
detail::Location Manager::makeLocation(const std::string& fname) {
|
detail::Location Manager::makeLocation(const std::string& fname) {
|
||||||
auto x = _locations.insert(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() {
|
void Manager::autoDiscoverModules() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue