Move Location to zeek::detail and BroObj to zeek

This commit is contained in:
Tim Wojtulewicz 2020-06-24 13:09:43 -07:00
parent 58c6e10b62
commit 40ecede4ea
41 changed files with 158 additions and 131 deletions

View file

@ -6,8 +6,12 @@
class ODesc;
namespace zeek {
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_line(line_f), last_line(line_l),
@ -26,7 +30,7 @@ public:
int first_column = 0, last_column = 0;
};
#define YYLTYPE yyltype
#define YYLTYPE zeek::detail::yyltype
typedef Location yyltype;
YYLTYPE GetCurrentLocation();
@ -49,6 +53,8 @@ inline void set_location(const Location start, const Location end)
end_location = end;
}
} // namespace detail
class BroObj {
public:
BroObj()
@ -67,8 +73,8 @@ public:
// of 0, which should only happen if it's been assigned
// to no_location (or hasn't been initialized at all).
location = nullptr;
if ( start_location.first_line != 0 )
SetLocationInfo(&start_location, &end_location);
if ( detail::start_location.first_line != 0 )
SetLocationInfo(&detail::start_location, &detail::end_location);
}
virtual ~BroObj();
@ -81,9 +87,9 @@ public:
// included in the message, though if pinpoint_only is non-zero,
// then obj2 is only used to pinpoint the location.
void Warn(const char* msg, const BroObj* obj2 = nullptr,
bool pinpoint_only = false, const Location* expr_location = nullptr) const;
bool pinpoint_only = false, const detail::Location* expr_location = nullptr) const;
void Error(const char* msg, const BroObj* obj2 = nullptr,
bool pinpoint_only = false, const Location* expr_location = nullptr) const;
bool pinpoint_only = false, const detail::Location* expr_location = nullptr) const;
// Report internal errors.
void BadTag(const char* msg, const char* t1 = nullptr,
@ -102,18 +108,18 @@ public:
void AddLocation(ODesc* d) const;
// Get location info for debugging.
const Location* GetLocationInfo() const
{ return location ? location : &no_location; }
const detail::Location* GetLocationInfo() const
{ return location ? location : &detail::no_location; }
virtual bool SetLocationInfo(const Location* loc)
virtual bool SetLocationInfo(const detail::Location* loc)
{ return SetLocationInfo(loc, loc); }
// Location = range from start to end.
virtual bool SetLocationInfo(const Location* start, const Location* end);
virtual bool SetLocationInfo(const detail::Location* start, const detail::Location* end);
// Set new end-of-location information. This is used to
// extend compound objects such as statement lists.
virtual void UpdateLocationEndInfo(const Location& end);
virtual void UpdateLocationEndInfo(const detail::Location& end);
// Enable notification of plugins when this objects gets destroyed.
void NotifyPluginsOnDtor() { notify_plugins = true; }
@ -128,14 +134,16 @@ public:
~SuppressErrors() { --BroObj::suppress_errors; }
};
void Print() const;
protected:
Location* location; // all that matters in real estate
detail::Location* location; // all that matters in real estate
private:
friend class SuppressErrors;
void DoMsg(ODesc* d, const char s1[], const BroObj* obj2 = nullptr,
bool pinpoint_only = false, const Location* expr_location = nullptr) const;
bool pinpoint_only = false, const detail::Location* expr_location = nullptr) const;
void PinPoint(ODesc* d, const BroObj* obj2 = nullptr,
bool pinpoint_only = false) const;
@ -150,11 +158,6 @@ private:
static int suppress_errors;
};
// Prints obj to stderr, primarily for debugging.
extern void print(const BroObj* obj);
[[noreturn]] extern void bad_ref(int type);
// Sometimes useful when dealing with BroObj subclasses that have their
// own (protected) versions of Error.
inline void Error(const BroObj* o, const char* msg)
@ -162,6 +165,8 @@ inline void Error(const BroObj* o, const char* msg)
o->Error(msg);
}
[[noreturn]] extern void bad_ref(int type);
inline void Ref(BroObj* o)
{
if ( ++(o->ref_cnt) <= 1 )
@ -185,3 +190,12 @@ inline void Unref(BroObj* o)
// A dict_delete_func that knows to Unref() dictionary entries.
extern void bro_obj_delete_func(void* v);
} // namespace zeek
using Location [[deprecated("Remove in v4.1. Use zeek::detail::Location instead.")]] = zeek::detail::Location;
using yyltype [[deprecated("Remove in v4.1. Use zeek::detail::yyltype instead.")]] = zeek::detail::yyltype;
using BroObj [[deprecated("Remove in v4.1. Use zeek::BroObj instead.")]] = zeek::BroObj;
[[deprecated("Remove in v4.1. Use zeek::BroObj::Print instead.")]]
extern void print(const zeek::BroObj* obj);