From 40ecede4ea848cdebf08f30eebefdcfe2d81dbe3 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Wed, 24 Jun 2020 13:09:43 -0700 Subject: [PATCH] Move Location to zeek::detail and BroObj to zeek --- src/Brofiler.cc | 2 +- src/Conn.h | 2 +- src/DFA.h | 4 +- src/DbgBreakpoint.cc | 6 +-- src/DbgWatch.cc | 2 +- src/DbgWatch.h | 7 ++- src/Debug.cc | 12 ++--- src/Debug.h | 8 ++-- src/DebugCmds.cc | 2 +- src/Event.h | 16 +++---- src/Expr.h | 2 +- src/File.h | 2 +- src/Frame.cc | 4 +- src/Func.cc | 2 +- src/Func.h | 2 +- src/NFA.h | 4 +- src/Obj.cc | 38 ++++++++++----- src/Obj.h | 48 ++++++++++++------- src/Queue.h | 1 + src/Reassem.h | 2 +- src/Reporter.cc | 8 ++-- src/Reporter.h | 15 +++--- src/Rule.h | 6 +-- src/Stats.cc | 10 ++-- src/Stats.h | 18 +++---- src/Stmt.h | 2 +- src/Type.cc | 2 +- src/Type.h | 2 +- src/Val.cc | 2 +- src/Val.h | 4 +- src/Var.cc | 6 +-- src/analyzer/protocol/arp/ARP.h | 6 +-- .../protocol/stepping-stone/SteppingStone.h | 6 +-- src/parse.y | 6 +-- src/plugin/Manager.cc | 7 +-- src/plugin/Manager.h | 2 +- src/plugin/Plugin.cc | 3 +- src/plugin/Plugin.h | 8 ++-- src/rule-parse.y | 4 +- src/threading/MsgThread.h | 2 +- src/zeekygen/Manager.cc | 4 +- 41 files changed, 158 insertions(+), 131 deletions(-) diff --git a/src/Brofiler.cc b/src/Brofiler.cc index 4eeb456380..951062a17b 100644 --- a/src/Brofiler.cc +++ b/src/Brofiler.cc @@ -31,7 +31,7 @@ void Brofiler::AddStmt(zeek::detail::Stmt* s) if ( ignoring != 0 ) return; - ::Ref(s); + zeek::Ref(s); stmts.push_back(s); } diff --git a/src/Conn.h b/src/Conn.h index 9221f563b2..a65b34b9ab 100644 --- a/src/Conn.h +++ b/src/Conn.h @@ -65,7 +65,7 @@ static inline int addr_port_canon_lt(const IPAddr& addr1, uint32_t p1, namespace analyzer { class Analyzer; } -class Connection final : public BroObj { +class Connection final : public zeek::BroObj { public: Connection(NetSessions* s, const ConnIDKey& k, double t, const ConnID* id, uint32_t flow, const Packet* pkt, const EncapsulationStack* arg_encap); diff --git a/src/DFA.h b/src/DFA.h index 332cdaff8e..d35fca15e7 100644 --- a/src/DFA.h +++ b/src/DFA.h @@ -24,7 +24,7 @@ class DFA_State; class DFA_Machine; class DFA_State; -class DFA_State : public BroObj { +class DFA_State : public zeek::BroObj { public: DFA_State(int state_num, const EquivClass* ec, NFA_state_list* nfa_states, AcceptingSet* accept); @@ -109,7 +109,7 @@ private: std::map states; }; -class DFA_Machine : public BroObj { +class DFA_Machine : public zeek::BroObj { public: DFA_Machine(NFA_Machine* n, EquivClass* ec); ~DFA_Machine() override; diff --git a/src/DbgBreakpoint.cc b/src/DbgBreakpoint.cc index 94c6ee8378..2e74961629 100644 --- a/src/DbgBreakpoint.cc +++ b/src/DbgBreakpoint.cc @@ -153,7 +153,7 @@ bool DbgBreakpoint::SetLocation(ParseLocationRec plr, std::string_view loc_str) function_name = make_full_var_name(zeek::detail::current_module.c_str(), loc_s.c_str()); at_stmt = plr.stmt; - const Location* loc = at_stmt->GetLocationInfo(); + const zeek::detail::Location* loc = at_stmt->GetLocationInfo(); snprintf(description, sizeof(description), "%s at %s:%d", function_name.c_str(), loc->filename, loc->last_line); @@ -176,7 +176,7 @@ bool DbgBreakpoint::SetLocation(zeek::detail::Stmt* stmt) SetEnable(true); AddToGlobalMap(); - const Location* loc = stmt->GetLocationInfo(); + const zeek::detail::Location* loc = stmt->GetLocationInfo(); snprintf(description, sizeof(description), "%s:%d", loc->filename, loc->last_line); @@ -356,7 +356,7 @@ void DbgBreakpoint::PrintHitMsg() if ( func ) func->DescribeDebug (&d, f->GetFuncArgs()); - const Location* loc = at_stmt->GetLocationInfo(); + const zeek::detail::Location* loc = at_stmt->GetLocationInfo(); debug_msg("Breakpoint %d, %s at %s:%d\n", GetID(), d.Description(), diff --git a/src/DbgWatch.cc b/src/DbgWatch.cc index 5d286afc1c..1b4b338b8b 100644 --- a/src/DbgWatch.cc +++ b/src/DbgWatch.cc @@ -7,7 +7,7 @@ #include "Reporter.h" // Support classes -DbgWatch::DbgWatch(BroObj* var_to_watch) +DbgWatch::DbgWatch(zeek::BroObj* var_to_watch) { reporter->InternalError("DbgWatch unimplemented"); } diff --git a/src/DbgWatch.h b/src/DbgWatch.h index 72a0bbe7fd..4a53dbd969 100644 --- a/src/DbgWatch.h +++ b/src/DbgWatch.h @@ -4,17 +4,16 @@ #include "util.h" -class BroObj; - ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(BroObj, zeek); class DbgWatch { public: - explicit DbgWatch(BroObj* var_to_watch); + explicit DbgWatch(zeek::BroObj* var_to_watch); explicit DbgWatch(zeek::detail::Expr* expr_to_watch); ~DbgWatch(); protected: - BroObj* var; + zeek::BroObj* var; zeek::detail::Expr* expr; }; diff --git a/src/Debug.cc b/src/Debug.cc index a17b57df63..4818058648 100644 --- a/src/Debug.cc +++ b/src/Debug.cc @@ -136,7 +136,7 @@ int TraceState::LogTrace(const char* fmt, ...) fprintf(trace_file, "%.6f ", network_time); const zeek::detail::Stmt* stmt; - Location loc; + zeek::detail::Location loc; loc.filename = nullptr; if ( g_frame_stack.size() > 0 && g_frame_stack.back() ) @@ -174,7 +174,7 @@ int TraceState::LogTrace(const char* fmt, ...) // Helper functions. -void get_first_statement(zeek::detail::Stmt* list, zeek::detail::Stmt*& first, Location& loc) +void get_first_statement(zeek::detail::Stmt* list, zeek::detail::Stmt*& first, zeek::detail::Location& loc) { if ( ! list ) { @@ -244,7 +244,7 @@ static void parse_function_name(vector& result, for ( unsigned int i = 0; i < bodies.size(); ++i ) { zeek::detail::Stmt* first; - Location stmt_loc; + zeek::detail::Location stmt_loc; get_first_statement(bodies[i].stmts.get(), first, stmt_loc); debug_msg("[%d] %s:%d\n", i+1, stmt_loc.filename, stmt_loc.first_line); } @@ -287,7 +287,7 @@ static void parse_function_name(vector& result, // Find first atomic (non-STMT_LIST) statement zeek::detail::Stmt* first; - Location stmt_loc; + zeek::detail::Location stmt_loc; if ( body ) { @@ -738,7 +738,7 @@ string get_context_description(const zeek::detail::Stmt* stmt, const zeek::detai else d.Add("", 0); - Location loc; + zeek::detail::Location loc; if ( stmt ) loc = *stmt->GetLocationInfo(); else @@ -780,7 +780,7 @@ int dbg_handle_debug_input() if ( ! stmt ) reporter->InternalError("Assertion failed: stmt != 0"); - const Location loc = *stmt->GetLocationInfo(); + const zeek::detail::Location loc = *stmt->GetLocationInfo(); if ( ! step_or_next_pending || g_frame_stack.back() != last_frame ) { diff --git a/src/Debug.h b/src/Debug.h index a53746728a..1829c7a473 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -89,7 +89,7 @@ public: bool already_did_list; // did we already do a 'list' command? - Location last_loc; // used by 'list'; the last location listed + zeek::detail::Location last_loc; // used by 'list'; the last location listed BPIDMapType breakpoints; // BPID -> Breakpoint std::vector watches; @@ -111,14 +111,14 @@ private: class StmtLocMapping { public: StmtLocMapping() { } - StmtLocMapping(const Location* l, zeek::detail::Stmt* s) { loc = *l; stmt = s; } + StmtLocMapping(const zeek::detail::Location* l, zeek::detail::Stmt* s) { loc = *l; stmt = s; } bool StartsAfter(const StmtLocMapping* m2); - const Location& Loc() const { return loc; } + const zeek::detail::Location& Loc() const { return loc; } zeek::detail::Stmt* Statement() const { return stmt; } protected: - Location loc; + zeek::detail::Location loc; zeek::detail::Stmt* stmt; }; diff --git a/src/DebugCmds.cc b/src/DebugCmds.cc index 525fc73342..c2723ce930 100644 --- a/src/DebugCmds.cc +++ b/src/DebugCmds.cc @@ -336,7 +336,7 @@ int dbg_cmd_frame(DebugCmd cmd, const vector& args) if ( ! stmt ) reporter->InternalError("Assertion failed: %s", "stmt != 0"); - const Location loc = *stmt->GetLocationInfo(); + const zeek::detail::Location loc = *stmt->GetLocationInfo(); g_debugger_state.last_loc = loc; g_debugger_state.already_did_list = false; diff --git a/src/Event.h b/src/Event.h index 5849bc53ee..614ba43c3d 100644 --- a/src/Event.h +++ b/src/Event.h @@ -14,11 +14,11 @@ class EventMgr; -class Event final : public BroObj { +class Event final : public zeek::BroObj { public: Event(EventHandlerPtr handler, zeek::Args args, SourceID src = SOURCE_LOCAL, analyzer::ID aid = 0, - BroObj* obj = nullptr); + zeek::BroObj* obj = nullptr); void SetNext(Event* n) { next_event = n; } Event* NextEvent() const { return next_event; } @@ -41,14 +41,14 @@ protected: zeek::Args args; SourceID src; analyzer::ID aid; - BroObj* obj; + zeek::BroObj* obj; Event* next_event; }; extern uint64_t num_events_queued; extern uint64_t num_events_dispatched; -class EventMgr final : public BroObj, public iosource::IOSource { +class EventMgr final : public zeek::BroObj, public iosource::IOSource { public: EventMgr(); ~EventMgr() override; @@ -64,7 +64,7 @@ public: [[deprecated("Remove in v4.1. Use Enqueue() instead.")]] void QueueEventFast(const EventHandlerPtr &h, val_list vl, SourceID src = SOURCE_LOCAL, analyzer::ID aid = 0, - TimerMgr* mgr = nullptr, BroObj* obj = nullptr); + TimerMgr* mgr = nullptr, zeek::BroObj* obj = nullptr); // Queues an event if there's an event handler (or remote consumer). This // function always takes ownership of decrementing the reference count of @@ -75,7 +75,7 @@ public: [[deprecated("Remove in v4.1. Use Enqueue() instead.")]] void QueueEvent(const EventHandlerPtr &h, val_list vl, SourceID src = SOURCE_LOCAL, analyzer::ID aid = 0, - TimerMgr* mgr = nullptr, BroObj* obj = nullptr); + TimerMgr* mgr = nullptr, zeek::BroObj* obj = nullptr); // Same as QueueEvent, except taking the event's argument list via a // pointer instead of by value. This function takes ownership of the @@ -84,7 +84,7 @@ public: [[deprecated("Remove in v4.1. Use Enqueue() instead.")]] void QueueEvent(const EventHandlerPtr &h, val_list* vl, SourceID src = SOURCE_LOCAL, analyzer::ID aid = 0, - TimerMgr* mgr = nullptr, BroObj* obj = nullptr); + TimerMgr* mgr = nullptr, zeek::BroObj* obj = nullptr); /** * Adds an event to the queue. If no handler is found for the event @@ -100,7 +100,7 @@ public: */ void Enqueue(const EventHandlerPtr& h, zeek::Args vl, SourceID src = SOURCE_LOCAL, analyzer::ID aid = 0, - BroObj* obj = nullptr); + zeek::BroObj* obj = nullptr); /** * A version of Enqueue() taking a variable number of arguments. diff --git a/src/Expr.h b/src/Expr.h index 4fbb990dd4..654d9caa47 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -98,7 +98,7 @@ public: BroExprTag Tag() const { return tag; } - Expr* Ref() { ::Ref(this); return this; } + Expr* Ref() { zeek::Ref(this); return this; } // Evaluates the expression and returns a corresponding Val*, // or nil if the expression's value isn't fixed. diff --git a/src/File.h b/src/File.h index d11d7c03d6..b7d6660da0 100644 --- a/src/File.h +++ b/src/File.h @@ -29,7 +29,7 @@ ZEEK_FORWARD_DECLARE_NAMESPACED(RecordVal, zeek); class BroFile; using BroFilePtr = zeek::IntrusivePtr; -class BroFile final : public BroObj { +class BroFile final : public zeek::BroObj { public: explicit BroFile(FILE* arg_f); BroFile(FILE* arg_f, const char* filename, const char* access); diff --git a/src/Frame.cc b/src/Frame.cc index fa5a11bc32..3f5c995477 100644 --- a/src/Frame.cc +++ b/src/Frame.cc @@ -55,7 +55,7 @@ Frame::~Frame() void Frame::AddFunctionWithClosureRef(BroFunc* func) { - ::Ref(func); + zeek::Ref(func); if ( ! functions_with_closure_frame_reference ) functions_with_closure_frame_reference = std::make_unique>(); @@ -493,7 +493,7 @@ void Frame::CaptureClosure(Frame* c, id_list arg_outer_ids) outer_ids = std::move(arg_outer_ids); for ( auto& i : outer_ids ) - ::Ref(i); + zeek::Ref(i); closure = c; if ( closure ) diff --git a/src/Func.cc b/src/Func.cc index a3fc49cbba..796a2f4cfd 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -876,7 +876,7 @@ void builtin_error(const char* msg, zeek::ValPtr arg) zeek::emit_builtin_error(msg, arg); } -void builtin_error(const char* msg, BroObj* arg) +void builtin_error(const char* msg, zeek::BroObj* arg) { zeek::emit_builtin_error(msg, arg); } diff --git a/src/Func.h b/src/Func.h index b2a89a0baa..dc9c2fbc92 100644 --- a/src/Func.h +++ b/src/Func.h @@ -305,4 +305,4 @@ extern void builtin_error(const char* msg); [[deprecated("Remove in v4.1. Use zeek::emit_builtin_error.")]] extern void builtin_error(const char* msg, zeek::ValPtr); [[deprecated("Remove in v4.1. Use zeek::emit_builtin_error.")]] -extern void builtin_error(const char* msg, BroObj* arg); +extern void builtin_error(const char* msg, zeek::BroObj* arg); diff --git a/src/NFA.h b/src/NFA.h index c4430a88c0..0e24a1daab 100644 --- a/src/NFA.h +++ b/src/NFA.h @@ -25,7 +25,7 @@ using NFA_state_list = zeek::PList; #define SYM_CCL 260 -class NFA_State : public BroObj { +class NFA_State : public zeek::BroObj { public: NFA_State(int sym, EquivClass* ec); explicit NFA_State(CCL* ccl); @@ -82,7 +82,7 @@ public: EpsilonState() : NFA_State(SYM_EPSILON, nullptr) { } }; -class NFA_Machine : public BroObj { +class NFA_Machine : public zeek::BroObj { public: explicit NFA_Machine(NFA_State* first, NFA_State* final = nullptr); ~NFA_Machine() override; diff --git a/src/Obj.cc b/src/Obj.cc index 62d4897280..be5f6794d8 100644 --- a/src/Obj.cc +++ b/src/Obj.cc @@ -10,6 +10,9 @@ #include "File.h" #include "plugin/Manager.h" +namespace zeek { +namespace detail { + Location start_location("", 0, 0, 0, 0); Location end_location("", 0, 0, 0, 0); @@ -48,6 +51,8 @@ bool Location::operator==(const Location& l) const return false; } +} // namespace detail + int BroObj::suppress_errors = 0; BroObj::~BroObj() @@ -58,7 +63,7 @@ BroObj::~BroObj() delete location; } -void BroObj::Warn(const char* msg, const BroObj* obj2, bool pinpoint_only, const Location* expr_location) const +void BroObj::Warn(const char* msg, const BroObj* obj2, bool pinpoint_only, const detail::Location* expr_location) const { ODesc d; DoMsg(&d, msg, obj2, pinpoint_only, expr_location); @@ -66,7 +71,7 @@ void BroObj::Warn(const char* msg, const BroObj* obj2, bool pinpoint_only, const reporter->PopLocation(); } -void BroObj::Error(const char* msg, const BroObj* obj2, bool pinpoint_only, const Location* expr_location) const +void BroObj::Error(const char* msg, const BroObj* obj2, bool pinpoint_only, const detail::Location* expr_location) const { if ( suppress_errors ) return; @@ -127,7 +132,7 @@ void BroObj::AddLocation(ODesc* d) const location->Describe(d); } -bool BroObj::SetLocationInfo(const Location* start, const Location* end) +bool BroObj::SetLocationInfo(const detail::Location* start, const detail::Location* end) { if ( ! start || ! end ) return false; @@ -135,20 +140,20 @@ bool BroObj::SetLocationInfo(const Location* start, const Location* end) if ( end->filename && ! streq(start->filename, end->filename) ) return false; - if ( location && (start == &no_location || end == &no_location) ) + if ( location && (start == &zeek::detail::no_location || end == &zeek::detail::no_location) ) // We already have a better location, so don't use this one. return true; delete location; - location = new Location(start->filename, - start->first_line, end->last_line, - start->first_column, end->last_column); + location = new detail::Location(start->filename, + start->first_line, end->last_line, + start->first_column, end->last_column); return true; } -void BroObj::UpdateLocationEndInfo(const Location& end) +void BroObj::UpdateLocationEndInfo(const detail::Location& end) { if ( ! location ) SetLocationInfo(&end, &end); @@ -158,15 +163,15 @@ void BroObj::UpdateLocationEndInfo(const Location& end) } void BroObj::DoMsg(ODesc* d, const char s1[], const BroObj* obj2, - bool pinpoint_only, const Location* expr_location) const + bool pinpoint_only, const detail::Location* expr_location) const { d->SetShort(); d->Add(s1); PinPoint(d, obj2, pinpoint_only); - const Location* loc2 = nullptr; - if ( obj2 && obj2->GetLocationInfo() != &no_location && + const detail::Location* loc2 = nullptr; + if ( obj2 && obj2->GetLocationInfo() != &zeek::detail::no_location && *obj2->GetLocationInfo() != *GetLocationInfo() ) loc2 = obj2->GetLocationInfo(); else if ( expr_location ) @@ -188,11 +193,11 @@ void BroObj::PinPoint(ODesc* d, const BroObj* obj2, bool pinpoint_only) const d->Add(")"); } -void print(const BroObj* obj) +void BroObj::Print() const { static BroFile fstderr(stderr); ODesc d(DESC_READABLE, &fstderr); - obj->Describe(&d); + Describe(&d); d.Add("\n"); } @@ -206,3 +211,10 @@ void bro_obj_delete_func(void* v) { Unref((BroObj*) v); } + +} // namespace zeek + +void print(const zeek::BroObj* obj) + { + obj->Print(); + } diff --git a/src/Obj.h b/src/Obj.h index cab0ab92d5..4829a80921 100644 --- a/src/Obj.h +++ b/src/Obj.h @@ -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); diff --git a/src/Queue.h b/src/Queue.h index c3fba49ef9..5d92e9b29c 100644 --- a/src/Queue.h +++ b/src/Queue.h @@ -2,6 +2,7 @@ #pragma once +#include #include // Queue.h -- diff --git a/src/Reassem.h b/src/Reassem.h index 079de77584..43d0278163 100644 --- a/src/Reassem.h +++ b/src/Reassem.h @@ -251,7 +251,7 @@ private: DataBlockMap block_map; }; -class Reassembler : public BroObj { +class Reassembler : public zeek::BroObj { public: Reassembler(uint64_t init_seq, ReassemblerType reassem_type = REASSEM_UNKNOWN); ~Reassembler() override {} diff --git a/src/Reporter.cc b/src/Reporter.cc index 66c048137e..893073fac7 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -165,7 +165,7 @@ void Reporter::ExprRuntimeError(const zeek::detail::Expr* expr, const char* fmt, throw InterpreterException(); } -void Reporter::RuntimeError(const Location* location, const char* fmt, ...) +void Reporter::RuntimeError(const zeek::detail::Location* location, const char* fmt, ...) { ++errors; PushLocation(location); @@ -469,11 +469,11 @@ void Reporter::DoLog(const char* prefix, EventHandlerPtr event, FILE* out, { ODesc d; - std::pair locs = locations.back(); + std::pair locs = locations.back(); if ( locs.first ) { - if ( locs.first != &no_location ) + if ( locs.first != &zeek::detail::no_location ) locs.first->Describe(&d); else @@ -483,7 +483,7 @@ void Reporter::DoLog(const char* prefix, EventHandlerPtr event, FILE* out, { d.Add(" and "); - if ( locs.second != &no_location ) + if ( locs.second != &zeek::detail::no_location ) locs.second->Describe(&d); else diff --git a/src/Reporter.h b/src/Reporter.h index 4aab22604f..d82e4d4ac9 100644 --- a/src/Reporter.h +++ b/src/Reporter.h @@ -18,7 +18,6 @@ namespace analyzer { class Analyzer; } namespace file_analysis { class File; } class Connection; -class Location; class Reporter; class EventHandlerPtr; ZEEK_FORWARD_DECLARE_NAMESPACED(RecordVal, zeek); @@ -30,6 +29,8 @@ using RecordValPtr = zeek::IntrusivePtr; using StringValPtr = zeek::IntrusivePtr; } +ZEEK_FORWARD_DECLARE_NAMESPACED(Location, zeek::detail); + // One cannot raise this exception directly, go through the // Reporter's methods instead. @@ -94,7 +95,7 @@ public: // Report a runtime error in evaluating a Bro script expression. This // function will not return but raise an InterpreterException. - [[noreturn]] void RuntimeError(const Location* location, const char* fmt, ...) __attribute__((format(printf, 3, 4))); + [[noreturn]] void RuntimeError(const zeek::detail::Location* location, const char* fmt, ...) __attribute__((format(printf, 3, 4))); // Report a traffic weirdness, i.e., an unexpected protocol situation // that may lead to incorrectly processing a connnection. @@ -130,11 +131,11 @@ public: // stack of location so that the most recent is always the one that // will be assumed to be the current one. The pointer must remain // valid until the location is popped. - void PushLocation(const Location* location) - { locations.push_back(std::pair(location, 0)); } + void PushLocation(const zeek::detail::Location* location) + { locations.push_back(std::pair(location, 0)); } - void PushLocation(const Location* loc1, const Location* loc2) - { locations.push_back(std::pair(loc1, loc2)); } + void PushLocation(const zeek::detail::Location* loc1, const zeek::detail::Location* loc2) + { locations.push_back(std::pair(loc1, loc2)); } // Removes the top-most location information from stack. void PopLocation() @@ -288,7 +289,7 @@ private: bool after_zeek_init; bool abort_on_scripting_errors = false; - std::list > locations; + std::list > locations; uint64_t weird_count; WeirdCountMap weird_count_by_type; diff --git a/src/Rule.h b/src/Rule.h index ad22186339..5cfbcb3d4e 100644 --- a/src/Rule.h +++ b/src/Rule.h @@ -19,7 +19,7 @@ using rule_dict = std::map; class Rule { public: - Rule(const char* arg_id, const Location& arg_location) + Rule(const char* arg_id, const zeek::detail::Location& arg_location) { id = copy_string(arg_id); idx = rule_counter++; @@ -47,7 +47,7 @@ public: uint32_t offset = 0, uint32_t depth = INT_MAX); void AddRequires(const char* id, bool opposite_direction, bool negate); - const Location& GetLocation() const { return location; } + const zeek::detail::Location& GetLocation() const { return location; } void PrintDebug(); @@ -98,7 +98,7 @@ private: Rule* next; // Linkage within RuleHdrTest tree: // Ptr to next rule using the same RuleHdrTests - Location location; + zeek::detail::Location location; // Rules and payloads are numbered individually. static unsigned int rule_counter; diff --git a/src/Stats.cc b/src/Stats.cc index 0bf1330b9e..821d6e1900 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -319,8 +319,8 @@ void ProfileLogger::Log() } } -void ProfileLogger::SegmentProfile(const char* name, const Location* loc, - double dtime, int dmem) +void ProfileLogger::SegmentProfile(const char* name, const zeek::detail::Location* loc, + double dtime, int dmem) { if ( name ) file->Write(fmt("%.06f segment-%s dt=%.06f dmem=%d\n", @@ -358,15 +358,15 @@ void SampleLogger::FunctionSeen(const zeek::detail::Func* func) load_samples->Assign(std::move(idx), nullptr); } -void SampleLogger::LocationSeen(const Location* loc) +void SampleLogger::LocationSeen(const zeek::detail::Location* loc) { auto idx = zeek::make_intrusive(loc->filename); load_samples->Assign(std::move(idx), nullptr); } void SampleLogger::SegmentProfile(const char* /* name */, - const Location* /* loc */, - double dtime, int dmem) + const zeek::detail::Location* /* loc */, + double dtime, int dmem) { if ( load_sample ) mgr.Enqueue(load_sample, diff --git a/src/Stats.h b/src/Stats.h index 5b8e56f434..91dd274e42 100644 --- a/src/Stats.h +++ b/src/Stats.h @@ -9,11 +9,11 @@ #include #include -class Location; class BroFile; ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(TableVal, zeek); +ZEEK_FORWARD_DECLARE_NAMESPACED(Location, zeek::detail); // Object called by SegmentProfiler when it is done and reports its // cumulative CPU/memory statistics. @@ -22,7 +22,7 @@ public: SegmentStatsReporter() { } virtual ~SegmentStatsReporter() { } - virtual void SegmentProfile(const char* name, const Location* loc, + virtual void SegmentProfile(const char* name, const zeek::detail::Location* loc, double dtime, int dmem) = 0; }; @@ -44,7 +44,7 @@ public: } SegmentProfiler(SegmentStatsReporter* arg_reporter, - const Location* arg_loc) + const zeek::detail::Location* arg_loc) : reporter(arg_reporter), name(), loc(arg_loc), initial_rusage() { if ( reporter ) @@ -63,7 +63,7 @@ protected: SegmentStatsReporter* reporter; const char* name; - const Location* loc; + const zeek::detail::Location* loc; struct rusage initial_rusage; }; @@ -77,8 +77,8 @@ public: BroFile* File() { return file; } protected: - void SegmentProfile(const char* name, const Location* loc, - double dtime, int dmem) override; + void SegmentProfile(const char* name, const zeek::detail::Location* loc, + double dtime, int dmem) override; private: BroFile* file; @@ -95,11 +95,11 @@ public: // These are called to report that a given function or location // has been seen during the sampling. void FunctionSeen(const zeek::detail::Func* func); - void LocationSeen(const Location* loc); + void LocationSeen(const zeek::detail::Location* loc); protected: - void SegmentProfile(const char* name, const Location* loc, - double dtime, int dmem) override; + void SegmentProfile(const char* name, const zeek::detail::Location* loc, + double dtime, int dmem) override; zeek::TableVal* load_samples; }; diff --git a/src/Stmt.h b/src/Stmt.h index 7eeec1b613..4b62d2a252 100644 --- a/src/Stmt.h +++ b/src/Stmt.h @@ -38,7 +38,7 @@ public: virtual ValPtr Exec(Frame* f, stmt_flow_type& flow) const = 0; - Stmt* Ref() { ::Ref(this); return this; } + Stmt* Ref() { zeek::Ref(this); return this; } bool SetLocationInfo(const Location* loc) override { return Stmt::SetLocationInfo(loc, loc); } diff --git a/src/Type.cc b/src/Type.cc index 91409aeeb5..f9cf811e25 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -2076,7 +2076,7 @@ const TypePtr& base_type(zeek::TypeTag tag) { base_types[tag] = zeek::make_intrusive(tag, true); // Give the base types a pseudo-location for easier identification. - Location l(type_name(tag), 0, 0, 0, 0); + zeek::detail::Location l(type_name(tag), 0, 0, 0, 0); base_types[tag]->SetLocationInfo(&l); } diff --git a/src/Type.h b/src/Type.h index ac5bab4422..2f1a5207d9 100644 --- a/src/Type.h +++ b/src/Type.h @@ -350,7 +350,7 @@ public: return tag == TYPE_TABLE && Yield(); } - Type* Ref() { ::Ref(this); return this; } + Type* Ref() { zeek::Ref(this); return this; } void Describe(ODesc* d) const override; virtual void DescribeReST(ODesc* d, bool roles_only = false) const; diff --git a/src/Val.cc b/src/Val.cc index a179373841..32f688234e 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -3191,7 +3191,7 @@ void VectorVal::ValDescribe(ODesc* d) const ValPtr check_and_promote(ValPtr v, const Type* t, bool is_init, - const Location* expr_location) + const zeek::detail::Location* expr_location) { if ( ! v ) return nullptr; diff --git a/src/Val.h b/src/Val.h index 9c8c831199..a10cebf815 100644 --- a/src/Val.h +++ b/src/Val.h @@ -172,7 +172,7 @@ public: ~Val() override; - Val* Ref() { ::Ref(this); return this; } + Val* Ref() { zeek::Ref(this); return this; } ValPtr Clone(); bool IsZero() const; @@ -1376,7 +1376,7 @@ protected: // true, then the checking is done in the context of an initialization. extern ValPtr check_and_promote( ValPtr v, const zeek::Type* t, bool is_init, - const Location* expr_location = nullptr); + const zeek::detail::Location* expr_location = nullptr); extern bool same_val(const Val* v1, const Val* v2); extern bool same_atomic_val(const Val* v1, const Val* v2); diff --git a/src/Var.cc b/src/Var.cc index 087084e3ff..a45a3c9ad9 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -122,7 +122,7 @@ static void make_var(const zeek::detail::IDPtr& id, zeek::TypePtr t, { if ( id->IsRedefinable() || (! init && attr && ! zeek::IsFunc(id->GetType()->Tag())) ) { - BroObj* redef_obj = init ? (BroObj*) init.get() : (BroObj*) t.get(); + zeek::BroObj* redef_obj = init ? (zeek::BroObj*) init.get() : (zeek::BroObj*) t.get(); if ( dt != VAR_REDEF ) id->Warn("redefinition requires \"redef\"", redef_obj, true); } @@ -336,8 +336,8 @@ zeek::detail::StmtPtr add_local( id->Error("can't use += / -= for initializations of local variables"); // copy Location to the stack, because AssignExpr may free "init" - const Location location = init->GetLocationInfo() ? - *init->GetLocationInfo() : no_location; + const zeek::detail::Location location = init->GetLocationInfo() ? + *init->GetLocationInfo() : zeek::detail::no_location; auto name_expr = zeek::make_intrusive(id, dt == VAR_CONST); auto assign_expr = zeek::make_intrusive(std::move(name_expr), diff --git a/src/analyzer/protocol/arp/ARP.h b/src/analyzer/protocol/arp/ARP.h index 36322ce8d2..1a181473f4 100644 --- a/src/analyzer/protocol/arp/ARP.h +++ b/src/analyzer/protocol/arp/ARP.h @@ -30,9 +30,9 @@ extern "C" { #include } -namespace analyzer { namespace arp { +namespace analyzer::arp { -class ARP_Analyzer : public BroObj { +class ARP_Analyzer : public zeek::BroObj { public: ARP_Analyzer(); ~ARP_Analyzer() override; @@ -57,4 +57,4 @@ protected: void Corrupted(const char* string); }; -} } // namespace analyzer::* +} // namespace analyzer::arp diff --git a/src/analyzer/protocol/stepping-stone/SteppingStone.h b/src/analyzer/protocol/stepping-stone/SteppingStone.h index 77796a5694..9ae3fcea18 100644 --- a/src/analyzer/protocol/stepping-stone/SteppingStone.h +++ b/src/analyzer/protocol/stepping-stone/SteppingStone.h @@ -7,12 +7,12 @@ class NetSessions; -namespace analyzer { namespace stepping_stone { +namespace analyzer::stepping_stone { class SteppingStoneEndpoint; class SteppingStoneManager; -class SteppingStoneEndpoint : public BroObj { +class SteppingStoneEndpoint : public zeek::BroObj { public: SteppingStoneEndpoint(tcp::TCP_Endpoint* e, SteppingStoneManager* m); ~SteppingStoneEndpoint() override; @@ -81,4 +81,4 @@ protected: int endp_cnt = 0; }; -} } // namespace analyzer::* +} // namespace analyzer::stepping_stone diff --git a/src/parse.y b/src/parse.y index c403a9df6f..c7aa6b30f9 100644 --- a/src/parse.y +++ b/src/parse.y @@ -126,8 +126,6 @@ extern zeek::detail::Expr* g_curr_debug_expr; extern bool in_debug; extern const char* g_curr_debug_error; -#define YYLTYPE yyltype - static int in_hook = 0; int in_init = 0; int in_record = 0; @@ -135,7 +133,7 @@ bool resolving_global_ID = false; bool defining_global_ID = false; std::vector saved_in_init; -static Location func_hdr_location; +static zeek::detail::Location func_hdr_location; zeek::EnumType* cur_enum_type = nullptr; static zeek::detail::ID* cur_decl_type_id = nullptr; @@ -267,7 +265,7 @@ bro: // Any objects creates from here on out should not // have file positions associated with them. - set_location(no_location); + set_location(zeek::detail::no_location); } | /* Silly way of allowing the debugger to call yyparse() diff --git a/src/plugin/Manager.cc b/src/plugin/Manager.cc index e985177e53..165c27de2a 100644 --- a/src/plugin/Manager.cc +++ b/src/plugin/Manager.cc @@ -865,9 +865,10 @@ bool Manager::HookLogWrite(const std::string& writer, } bool Manager::HookReporter(const std::string& prefix, const EventHandlerPtr event, - const Connection* conn, const val_list* addl, bool location, - const Location* location1, const Location* location2, - bool time, const std::string& message) + const Connection* conn, const val_list* addl, bool location, + const zeek::detail::Location* location1, + const zeek::detail::Location* location2, + bool time, const std::string& message) { HookArgumentList args; diff --git a/src/plugin/Manager.h b/src/plugin/Manager.h index 7771b238f6..3a42c29c3f 100644 --- a/src/plugin/Manager.h +++ b/src/plugin/Manager.h @@ -389,7 +389,7 @@ public: */ bool HookReporter(const std::string& prefix, const EventHandlerPtr event, const Connection* conn, const val_list* addl, bool location, - const Location* location1, const Location* location2, + const zeek::detail::Location* location1, const zeek::detail::Location* location2, bool time, const std::string& message); /** diff --git a/src/plugin/Plugin.cc b/src/plugin/Plugin.cc index 86c30d6d24..2f7f734fdc 100644 --- a/src/plugin/Plugin.cc +++ b/src/plugin/Plugin.cc @@ -441,7 +441,8 @@ bool Plugin::HookLogWrite(const std::string& writer, const std::string& filter, bool Plugin::HookReporter(const std::string& prefix, const EventHandlerPtr event, const Connection* conn, const val_list* addl, bool location, - const Location* location1, const Location* location2, + const zeek::detail::Location* location1, + const zeek::detail::Location* location2, bool time, const std::string& message) { return true; diff --git a/src/plugin/Plugin.h b/src/plugin/Plugin.h index f22050d5a2..816141ce53 100644 --- a/src/plugin/Plugin.h +++ b/src/plugin/Plugin.h @@ -251,7 +251,7 @@ public: /** * Constructor with a location argument. */ - explicit HookArgument(const Location* location) { type = LOCATION; arg.loc = location; } + explicit HookArgument(const zeek::detail::Location* location) { type = LOCATION; arg.loc = location; } /** * Constructor with a zeek::Args argument. @@ -374,7 +374,7 @@ private: const zeek::Args* args; const void* voidp; const logging::WriterBackend::WriterInfo* winfo; - const Location* loc; + const zeek::detail::Location* loc; } arg; // Outside union because these have dtors. @@ -621,7 +621,7 @@ protected: * * @param handler The object being interested in. */ - void RequestBroObjDtor(BroObj* obj); + void RequestBroObjDtor(zeek::BroObj* obj); // Hook functions. @@ -829,7 +829,7 @@ protected: */ virtual bool HookReporter(const std::string& prefix, const EventHandlerPtr event, const Connection* conn, const val_list* addl, bool location, - const Location* location1, const Location* location2, + const zeek::detail::Location* location1, const zeek::detail::Location* location2, bool time, const std::string& message); // Meta hooks. diff --git a/src/rule-parse.y b/src/rule-parse.y index 34199c1443..b15763614a 100644 --- a/src/rule-parse.y +++ b/src/rule-parse.y @@ -104,7 +104,7 @@ rule_list: rule: TOK_SIGNATURE TOK_IDENT { - Location l(current_rule_file, rules_line_number+1, 0, 0, 0); + zeek::detail::Location l(current_rule_file, rules_line_number+1, 0, 0, 0); current_rule = new Rule(yylval.str, l); } '{' rule_attr_list '}' @@ -440,7 +440,7 @@ void rules_error(const char* msg, const char* addl) void rules_error(Rule* r, const char* msg) { - const Location& l = r->GetLocation(); + const zeek::detail::Location& l = r->GetLocation(); reporter->Error("Error in signature %s (%s:%d): %s\n", r->ID(), l.filename, l.first_line, msg); rule_matcher->SetParseError(); diff --git a/src/threading/MsgThread.h b/src/threading/MsgThread.h index c95a424777..f9000f1893 100644 --- a/src/threading/MsgThread.h +++ b/src/threading/MsgThread.h @@ -8,7 +8,7 @@ #include "iosource/IOSource.h" #include "Flare.h" -class BroObj; +ZEEK_FORWARD_DECLARE_NAMESPACED(BroObj, zeek); namespace threading { diff --git a/src/zeekygen/Manager.cc b/src/zeekygen/Manager.cc index 59ef519491..a0a08ff27e 100644 --- a/src/zeekygen/Manager.cc +++ b/src/zeekygen/Manager.cc @@ -252,7 +252,7 @@ void Manager::StartType(zeek::detail::IDPtr id) if ( disabled ) return; - if ( id->GetLocationInfo() == &no_location ) + if ( id->GetLocationInfo() == &zeek::detail::no_location ) { DbgAndWarn(fmt("Can't generate zeekygen doumentation for %s, " "no location available", id->Name())); @@ -313,7 +313,7 @@ void Manager::Identifier(zeek::detail::IDPtr id) return; } - if ( id->GetLocationInfo() == &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.