diff --git a/src/BroList.h b/src/BroList.h index a37f40d84a..d2e77a33ca 100644 --- a/src/BroList.h +++ b/src/BroList.h @@ -13,8 +13,8 @@ typedef PList id_list; class Val; typedef PList val_list; -class Stmt; -typedef PList stmt_list; +FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); +typedef PList stmt_list; class BroType; typedef PList type_list; diff --git a/src/Brofiler.cc b/src/Brofiler.cc index ba7ff1b358..4eeb456380 100644 --- a/src/Brofiler.cc +++ b/src/Brofiler.cc @@ -26,7 +26,7 @@ Brofiler::~Brofiler() Unref(s); } -void Brofiler::AddStmt(Stmt* s) +void Brofiler::AddStmt(zeek::detail::Stmt* s) { if ( ignoring != 0 ) return; @@ -127,7 +127,7 @@ bool Brofiler::WriteStats() return false; } - for ( list::const_iterator it = stmts.begin(); + for ( list::const_iterator it = stmts.begin(); it != stmts.end(); ++it ) { ODesc location_info; @@ -154,4 +154,3 @@ bool Brofiler::WriteStats() fclose(f); return true; } - diff --git a/src/Brofiler.h b/src/Brofiler.h index 4d6bb2eaf5..95a0a17c59 100644 --- a/src/Brofiler.h +++ b/src/Brofiler.h @@ -5,7 +5,8 @@ #include #include -class Stmt; +#include "util.h" +FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); /** * A simple class for managing stats of Bro script coverage across Bro runs. @@ -39,13 +40,13 @@ public: void IncIgnoreDepth() { ignoring++; } void DecIgnoreDepth() { ignoring--; } - void AddStmt(Stmt* s); + void AddStmt(zeek::detail::Stmt* s); private: /** * The current, global Brofiler instance creates this list at parse-time. */ - std::list stmts; + std::list stmts; /** * Indicates whether new statments will not be considered as part of diff --git a/src/DbgBreakpoint.cc b/src/DbgBreakpoint.cc index 2ad5d3ef94..990ff070a3 100644 --- a/src/DbgBreakpoint.cc +++ b/src/DbgBreakpoint.cc @@ -166,7 +166,7 @@ bool DbgBreakpoint::SetLocation(ParseLocationRec plr, std::string_view loc_str) return true; } -bool DbgBreakpoint::SetLocation(Stmt* stmt) +bool DbgBreakpoint::SetLocation(zeek::detail::Stmt* stmt) { if ( ! stmt ) return false; @@ -290,7 +290,7 @@ BreakCode DbgBreakpoint::HasHit() return bcHit; } -BreakCode DbgBreakpoint::ShouldBreak(Stmt* s) +BreakCode DbgBreakpoint::ShouldBreak(zeek::detail::Stmt* s) { if ( ! IsEnabled() ) return bcNoHit; diff --git a/src/DbgBreakpoint.h b/src/DbgBreakpoint.h index 2e8e59a16c..bdc9f9bf09 100644 --- a/src/DbgBreakpoint.h +++ b/src/DbgBreakpoint.h @@ -3,9 +3,11 @@ #pragma once #include +#include "util.h" struct ParseLocationRec; -class Stmt; + +FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); enum BreakCode { bcNoHit, bcHit, bcHitAndDelete }; class DbgBreakpoint { @@ -20,7 +22,7 @@ public: // True if breakpoint could be set; false otherwise bool SetLocation(ParseLocationRec plr, std::string_view loc_str); - bool SetLocation(Stmt* stmt); + bool SetLocation(zeek::detail::Stmt* stmt); bool SetLocation(double time); bool Reset(); // cancel and re-apply bpt when restarting execution @@ -35,7 +37,7 @@ public: // // NOTE: If it returns a hit, the DbgBreakpoint object will take // appropriate action (e.g., resetting counters). - BreakCode ShouldBreak(Stmt* s); + BreakCode ShouldBreak(zeek::detail::Stmt* s); BreakCode ShouldBreak(double t); const std::string& GetCondition() const { return condition; } @@ -70,7 +72,7 @@ protected: bool enabled; // ### comment this and next bool temporary; - Stmt* at_stmt; + zeek::detail::Stmt* at_stmt; double at_time; // break when the virtual time is this // Support for conditional and N'th time breakpoints. diff --git a/src/Debug.cc b/src/Debug.cc index 3637516850..7cbc928943 100644 --- a/src/Debug.cc +++ b/src/Debug.cc @@ -135,7 +135,7 @@ int TraceState::LogTrace(const char* fmt, ...) // Prefix includes timestamp and file/line info. fprintf(trace_file, "%.6f ", network_time); - const Stmt* stmt; + const zeek::detail::Stmt* stmt; Location loc; loc.filename = nullptr; @@ -174,7 +174,7 @@ int TraceState::LogTrace(const char* fmt, ...) // Helper functions. -void get_first_statement(Stmt* list, Stmt*& first, Location& loc) +void get_first_statement(zeek::detail::Stmt* list, zeek::detail::Stmt*& first, Location& loc) { if ( ! list ) { @@ -231,7 +231,7 @@ static void parse_function_name(vector& result, return; } - Stmt* body = nullptr; // the particular body we care about; 0 = all + zeek::detail::Stmt* body = nullptr; // the particular body we care about; 0 = all if ( bodies.size() == 1 ) body = bodies[0].stmts.get(); @@ -243,7 +243,7 @@ static void parse_function_name(vector& result, "Please choose one of the following options:\n"); for ( unsigned int i = 0; i < bodies.size(); ++i ) { - Stmt* first; + zeek::detail::Stmt* first; 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); @@ -286,7 +286,7 @@ static void parse_function_name(vector& result, plr.type = plrFunction; // Find first atomic (non-STMT_LIST) statement - Stmt* first; + zeek::detail::Stmt* first; Location stmt_loc; if ( body ) @@ -728,7 +728,7 @@ static char* get_prompt(bool reset_counter = false) return prompt; } -string get_context_description(const Stmt* stmt, const Frame* frame) +string get_context_description(const zeek::detail::Stmt* stmt, const Frame* frame) { ODesc d; const BroFunc* func = frame ? frame->GetFunction() : nullptr; @@ -776,7 +776,7 @@ int dbg_handle_debug_input() else current_module = GLOBAL_MODULE_NAME; - const Stmt* stmt = curr_frame->GetNextStmt(); + const zeek::detail::Stmt* stmt = curr_frame->GetNextStmt(); if ( ! stmt ) reporter->InternalError("Assertion failed: stmt != 0"); @@ -840,7 +840,7 @@ int dbg_handle_debug_input() // Return true to continue execution, false to abort. -bool pre_execute_stmt(Stmt* stmt, Frame* f) +bool pre_execute_stmt(zeek::detail::Stmt* stmt, Frame* f) { if ( ! g_policy_debug || stmt->Tag() == STMT_LIST || stmt->Tag() == STMT_NULL ) @@ -905,7 +905,7 @@ bool pre_execute_stmt(Stmt* stmt, Frame* f) return true; } -bool post_execute_stmt(Stmt* stmt, Frame* f, Val* result, stmt_flow_type* flow) +bool post_execute_stmt(zeek::detail::Stmt* stmt, Frame* f, Val* result, stmt_flow_type* flow) { // Handle the case where someone issues a "next" debugger command, // but we're at a return statement, so the next statement is in diff --git a/src/Debug.h b/src/Debug.h index 5208e61780..6e07368a1c 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -5,6 +5,7 @@ #include "Obj.h" #include "Queue.h" #include "StmtEnums.h" +#include "util.h" #include #include @@ -12,14 +13,15 @@ template class IntrusivePtr; class Val; -class Stmt; + +FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); // This needs to be defined before we do the includes that come after it. enum ParseLocationRecType { plrUnknown, plrFileAndLine, plrFunction }; struct ParseLocationRec { ParseLocationRecType type; int32_t line; - Stmt* stmt; + zeek::detail::Stmt* stmt; const char* filename; }; @@ -33,7 +35,7 @@ class DbgDisplay; class StmtHashFn; typedef std::map BPIDMapType; -typedef std::multimap BPMapType; +typedef std::multimap BPMapType; extern std::string current_module; @@ -104,15 +106,15 @@ private: class StmtLocMapping { public: StmtLocMapping() { } - StmtLocMapping(const Location* l, Stmt* s) { loc = *l; stmt = s; } + StmtLocMapping(const Location* l, zeek::detail::Stmt* s) { loc = *l; stmt = s; } bool StartsAfter(const StmtLocMapping* m2); const Location& Loc() const { return loc; } - Stmt* Statement() const { return stmt; } + zeek::detail::Stmt* Statement() const { return stmt; } protected: Location loc; - Stmt* stmt; + zeek::detail::Stmt* stmt; }; @@ -143,8 +145,8 @@ std::vector parse_location_string(const std::string& s); // Debugging hooks. // Return true to continue execution, false to abort. -bool pre_execute_stmt(Stmt* stmt, Frame* f); -bool post_execute_stmt(Stmt* stmt, Frame* f, Val* result, stmt_flow_type* flow); +bool pre_execute_stmt(zeek::detail::Stmt* stmt, Frame* f); +bool post_execute_stmt(zeek::detail::Stmt* stmt, Frame* f, Val* result, stmt_flow_type* flow); // Returns 1 if successful, 0 otherwise. // If cmdfile is non-nil, it contains the location of a file of commands @@ -168,7 +170,7 @@ IntrusivePtr dbg_eval_expr(const char* expr); int dbg_read_internal_state(); // Get line that looks like "In FnFoo(arg = val) at File:Line". -std::string get_context_description(const Stmt* stmt, const Frame* frame); +std::string get_context_description(const zeek::detail::Stmt* stmt, const Frame* frame); extern Frame* g_dbg_locals; // variables created within debugger context diff --git a/src/DebugCmds.cc b/src/DebugCmds.cc index e36836e50a..93e1ef9f0e 100644 --- a/src/DebugCmds.cc +++ b/src/DebugCmds.cc @@ -216,7 +216,7 @@ static int dbg_backtrace_internal(int start, int end) for ( int i = start; i >= end; --i ) { const Frame* f = g_frame_stack[i]; - const Stmt* stmt = f ? f->GetNextStmt() : nullptr; + const zeek::detail::Stmt* stmt = f ? f->GetNextStmt() : nullptr; string context = get_context_description(stmt, f); debug_msg("#%d %s\n", @@ -333,7 +333,7 @@ int dbg_cmd_frame(DebugCmd cmd, const vector& args) // Set the current location to the new frame being looked at // for 'list', 'break', etc. - const Stmt* stmt = g_frame_stack[user_frame_number]->GetNextStmt(); + const zeek::detail::Stmt* stmt = g_frame_stack[user_frame_number]->GetNextStmt(); if ( ! stmt ) reporter->InternalError("Assertion failed: %s", "stmt != 0"); @@ -373,7 +373,7 @@ int dbg_cmd_break(DebugCmd cmd, const vector& args) g_frame_stack.size() - 1 - g_debugger_state.curr_frame_idx; - Stmt* stmt = g_frame_stack[user_frame_number]->GetNextStmt(); + zeek::detail::Stmt* stmt = g_frame_stack[user_frame_number]->GetNextStmt(); if ( ! stmt ) reporter->InternalError("Assertion failed: %s", "stmt != 0"); diff --git a/src/Expr.h b/src/Expr.h index cd09920522..d196a8069b 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -59,7 +59,6 @@ enum BroExprTag : int { extern const char* expr_name(BroExprTag t); template class IntrusivePtr; -class Stmt; class Frame; class Scope; class ListExpr; @@ -71,6 +70,7 @@ class EventExpr; struct function_ingredients; +FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); class Expr : public BroObj { public: diff --git a/src/File.h b/src/File.h index edf0b7d0f4..ab7ac5a993 100644 --- a/src/File.h +++ b/src/File.h @@ -2,23 +2,26 @@ #pragma once -#include "Obj.h" -#include "IntrusivePtr.h" - #include #include #include #include -# ifdef NEED_KRB5_H -# include -# endif // NEED_KRB5_H +#ifdef NEED_KRB5_H +#include +#endif // NEED_KRB5_H + +#include "Obj.h" +#include "IntrusivePtr.h" +#include "util.h" class Attributes; class BroType; class RecordVal; +FORWARD_DECLARE_NAMESPACED(PrintStmt, zeek::detail); + class BroFile final : public BroObj { public: explicit BroFile(FILE* arg_f); @@ -77,7 +80,7 @@ public: protected: - friend class PrintStmt; + friend class zeek::detail::PrintStmt; BroFile() { Init(); } void Init(); diff --git a/src/Frame.h b/src/Frame.h index a85254469c..e203fa17bd 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -118,12 +118,12 @@ public: * * @param stmt the statement to set it to. */ - void SetNextStmt(Stmt* stmt) { next_stmt = stmt; } + void SetNextStmt(zeek::detail::Stmt* stmt) { next_stmt = stmt; } /** * @return the next statement to be executed in the context of the frame. */ - Stmt* GetNextStmt() const { return next_stmt; } + zeek::detail::Stmt* GetNextStmt() const { return next_stmt; } /** Used to implement "next" command in debugger. */ void BreakBeforeNextStmt(bool should_break) @@ -319,7 +319,7 @@ private: const zeek::Args* func_args; /** The next statement to be evaluted in the context of this frame. */ - Stmt* next_stmt; + zeek::detail::Stmt* next_stmt; IntrusivePtr trigger; const CallExpr* call; diff --git a/src/Func.cc b/src/Func.cc index f0cb8e693a..77dbabaea6 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -121,7 +121,7 @@ Func::Func(Kind arg_kind) : kind(arg_kind) Func::~Func() = default; -void Func::AddBody(IntrusivePtr /* new_body */, +void Func::AddBody(IntrusivePtr /* new_body */, const std::vector>& /* new_inits */, size_t /* new_frame_size */, int /* priority */) { @@ -268,7 +268,7 @@ void Func::CheckPluginResult(bool handled, const IntrusivePtr& hook_result, } } -BroFunc::BroFunc(const IntrusivePtr& arg_id, IntrusivePtr arg_body, +BroFunc::BroFunc(const IntrusivePtr& arg_id, IntrusivePtr arg_body, const std::vector>& aggr_inits, size_t arg_frame_size, int priority) : Func(BRO_FUNC) @@ -449,7 +449,7 @@ IntrusivePtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const return result; } -void BroFunc::AddBody(IntrusivePtr new_body, +void BroFunc::AddBody(IntrusivePtr new_body, const std::vector>& new_inits, size_t new_frame_size, int priority) { @@ -574,14 +574,14 @@ void BroFunc::Describe(ODesc* d) const } } -IntrusivePtr BroFunc::AddInits(IntrusivePtr body, - const std::vector>& inits) +IntrusivePtr BroFunc::AddInits(IntrusivePtr body, + const std::vector>& inits) { if ( inits.empty() ) return body; - auto stmt_series = make_intrusive(); - stmt_series->Stmts().push_back(new InitStmt(inits)); + auto stmt_series = make_intrusive(); + stmt_series->Stmts().push_back(new zeek::detail::InitStmt(inits)); stmt_series->Stmts().push_back(body.release()); return stmt_series; @@ -879,7 +879,7 @@ static int get_func_priority(const std::vector>& attrs) return priority; } -function_ingredients::function_ingredients(IntrusivePtr scope, IntrusivePtr body) +function_ingredients::function_ingredients(IntrusivePtr scope, IntrusivePtr body) { frame_size = scope->Length(); inits = scope->GetInits(); diff --git a/src/Func.h b/src/Func.h index 5b2ee5eebc..88a805ad5a 100644 --- a/src/Func.h +++ b/src/Func.h @@ -22,12 +22,13 @@ class Val; class ListExpr; class FuncType; -class Stmt; class Frame; class ID; class CallExpr; class Scope; +FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); + class Func : public BroObj { public: static inline const IntrusivePtr nil; @@ -42,7 +43,7 @@ public: function_flavor Flavor() const { return GetType()->Flavor(); } struct Body { - IntrusivePtr stmts; + IntrusivePtr stmts; int priority; bool operator<(const Body& other) const { return priority > other.priority; } // reverse sort @@ -78,7 +79,7 @@ public: } // Add a new event handler to an existing function (event). - virtual void AddBody(IntrusivePtr new_body, + virtual void AddBody(IntrusivePtr new_body, const std::vector>& new_inits, size_t new_frame_size, int priority = 0); @@ -129,7 +130,7 @@ protected: class BroFunc final : public Func { public: - BroFunc(const IntrusivePtr& id, IntrusivePtr body, + BroFunc(const IntrusivePtr& id, IntrusivePtr body, const std::vector>& inits, size_t frame_size, int priority); @@ -167,7 +168,7 @@ public: */ broker::expected SerializeClosure() const; - void AddBody(IntrusivePtr new_body, + void AddBody(IntrusivePtr new_body, const std::vector>& new_inits, size_t new_frame_size, int priority) override; @@ -179,8 +180,8 @@ public: protected: BroFunc() : Func(BRO_FUNC) {} - IntrusivePtr AddInits(IntrusivePtr body, - const std::vector>& inits); + IntrusivePtr AddInits(IntrusivePtr body, + const std::vector>& inits); /** * Clones this function along with its closures. @@ -267,10 +268,10 @@ struct function_ingredients { // Gathers all of the information from a scope and a function body needed // to build a function. - function_ingredients(IntrusivePtr scope, IntrusivePtr body); + function_ingredients(IntrusivePtr scope, IntrusivePtr body); IntrusivePtr id; - IntrusivePtr body; + IntrusivePtr body; std::vector> inits; int frame_size; int priority; diff --git a/src/Stmt.cc b/src/Stmt.cc index e30233ccf3..b0ef9c4ab7 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -2,6 +2,8 @@ #include "zeek-config.h" +#include "Stmt.h" + #include "CompHash.h" #include "Expr.h" #include "Event.h" @@ -9,7 +11,6 @@ #include "File.h" #include "Reporter.h" #include "NetVar.h" -#include "Stmt.h" #include "Scope.h" #include "Var.h" #include "Desc.h" @@ -34,6 +35,8 @@ const char* stmt_name(BroStmtTag t) return stmt_names[int(t)]; } +namespace zeek::detail { + Stmt::Stmt(BroStmtTag arg_tag) { tag = arg_tag; @@ -1833,3 +1836,5 @@ TraversalCode WhenStmt::Traverse(TraversalCallback* cb) const tc = cb->PostStmt(this); HANDLE_TC_STMT_POST(tc); } + +} diff --git a/src/Stmt.h b/src/Stmt.h index 0cc4e8ae43..55cc919770 100644 --- a/src/Stmt.h +++ b/src/Stmt.h @@ -13,13 +13,16 @@ #include "TraverseTypes.h" -class StmtList; class CompositeHash; class EventExpr; class ListExpr; -class ForStmt; class Frame; +namespace zeek::detail { + +class StmtList; +class ForStmt; + class Stmt : public BroObj { public: BroStmtTag Tag() const { return tag; } @@ -447,3 +450,27 @@ protected: IntrusivePtr timeout; bool is_return; }; + +} + +using Stmt [[deprecated("Remove in v4.1. Use zeek::detail::Stmt instead.")]] = zeek::detail::Stmt; +using ExprListStmt [[deprecated("Remove in v4.1. Use zeek::detail::ExprListStmt instead.")]] = zeek::detail::ExprListStmt; +using PrintStmt [[deprecated("Remove in v4.1. Use zeek::detail::PrintStmt instead.")]] = zeek::detail::PrintStmt; +using ExprStmt [[deprecated("Remove in v4.1. Use zeek::detail::ExprStmt instead.")]] = zeek::detail::ExprStmt; +using IfStmt [[deprecated("Remove in v4.1. Use zeek::detail::IfStmt instead.")]] = zeek::detail::IfStmt; +using Case [[deprecated("Remove in v4.1. Use zeek::detail::Case instead.")]] = zeek::detail::Case; +using SwitchStmt [[deprecated("Remove in v4.1. Use zeek::detail::SwitchStmt instead.")]] = zeek::detail::SwitchStmt; +using AddStmt [[deprecated("Remove in v4.1. Use zeek::detail::AddStmt instead.")]] = zeek::detail::AddStmt; +using DelStmt [[deprecated("Remove in v4.1. Use zeek::detail::DelStmt instead.")]] = zeek::detail::DelStmt; +using EventStmt [[deprecated("Remove in v4.1. Use zeek::detail::EventStmt instead.")]] = zeek::detail::EventStmt; +using WhileStmt [[deprecated("Remove in v4.1. Use zeek::detail::WhileStmt instead.")]] = zeek::detail::WhileStmt; +using ForStmt [[deprecated("Remove in v4.1. Use zeek::detail::ForStmt instead.")]] = zeek::detail::ForStmt; +using NextStmt [[deprecated("Remove in v4.1. Use zeek::detail::NextStmt instead.")]] = zeek::detail::NextStmt; +using BreakStmt [[deprecated("Remove in v4.1. Use zeek::detail::BreakStmt instead.")]] = zeek::detail::BreakStmt; +using FallthroughStmt [[deprecated("Remove in v4.1. Use zeek::detail::FallthroughStmt instead.")]] = zeek::detail::FallthroughStmt; +using ReturnStmt [[deprecated("Remove in v4.1. Use zeek::detail::ReturnStmt instead.")]] = zeek::detail::ReturnStmt; +using StmtList [[deprecated("Remove in v4.1. Use zeek::detail::StmtList instead.")]] = zeek::detail::StmtList; +using EventBodyList [[deprecated("Remove in v4.1. Use zeek::detail::EventBodyList instead.")]] = zeek::detail::EventBodyList; +using InitStmt [[deprecated("Remove in v4.1. Use zeek::detail::InitStmt instead.")]] = zeek::detail::InitStmt; +using NullStmt [[deprecated("Remove in v4.1. Use zeek::detail::NullStmt instead.")]] = zeek::detail::NullStmt; +using WhenStmt [[deprecated("Remove in v4.1. Use zeek::detail::WhenStmt instead.")]] = zeek::detail::WhenStmt; diff --git a/src/Traverse.h b/src/Traverse.h index 2e528905e0..6c01fb88b7 100644 --- a/src/Traverse.h +++ b/src/Traverse.h @@ -6,10 +6,11 @@ class Func; class Scope; -class Stmt; class Expr; class ID; +FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); + class TraversalCallback { public: TraversalCallback() { current_scope = nullptr; } @@ -18,8 +19,8 @@ public: virtual TraversalCode PreFunction(const Func*) { return TC_CONTINUE; } virtual TraversalCode PostFunction(const Func*) { return TC_CONTINUE; } - virtual TraversalCode PreStmt(const Stmt*) { return TC_CONTINUE; } - virtual TraversalCode PostStmt(const Stmt*) { return TC_CONTINUE; } + virtual TraversalCode PreStmt(const zeek::detail::Stmt*) { return TC_CONTINUE; } + virtual TraversalCode PostStmt(const zeek::detail::Stmt*) { return TC_CONTINUE; } virtual TraversalCode PreExpr(const Expr*) { return TC_CONTINUE; } virtual TraversalCode PostExpr(const Expr*) { return TC_CONTINUE; } diff --git a/src/Trigger.cc b/src/Trigger.cc index 18fd850b64..0d26fb70d5 100644 --- a/src/Trigger.cc +++ b/src/Trigger.cc @@ -122,7 +122,8 @@ protected: } -Trigger::Trigger(Expr* arg_cond, Stmt* arg_body, Stmt* arg_timeout_stmts, +Trigger::Trigger(Expr* arg_cond, zeek::detail::Stmt* arg_body, + zeek::detail::Stmt* arg_timeout_stmts, Expr* arg_timeout, Frame* arg_frame, bool arg_is_return, const Location* arg_location) { diff --git a/src/Trigger.h b/src/Trigger.h index c26e6e7b05..bc6dcf50fd 100644 --- a/src/Trigger.h +++ b/src/Trigger.h @@ -1,21 +1,23 @@ #pragma once -#include "Obj.h" -#include "Notifier.h" -#include "iosource/IOSource.h" - #include #include #include +#include "Obj.h" +#include "Notifier.h" +#include "iosource/IOSource.h" +#include "util.h" + class CallExpr; class Expr; -class Stmt; class Frame; class Val; class ID; class ODesc; +FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); + namespace trigger { // Triggers are the heart of "when" statements: expressions that when // they become true execute a body of statements. @@ -29,7 +31,7 @@ public: // instantiation. Note that if the condition is already true, the // statements are executed immediately and the object is deleted // right away. - Trigger(Expr* cond, Stmt* body, Stmt* timeout_stmts, Expr* timeout, + Trigger(Expr* cond, zeek::detail::Stmt* body, zeek::detail::Stmt* timeout_stmts, Expr* timeout, Frame* f, bool is_return, const Location* loc); ~Trigger() override; @@ -92,8 +94,8 @@ private: void UnregisterAll(); Expr* cond; - Stmt* body; - Stmt* timeout_stmts; + zeek::detail::Stmt* body; + zeek::detail::Stmt* timeout_stmts; Expr* timeout; double timeout_value; Frame* frame; diff --git a/src/Var.cc b/src/Var.cc index af1665d92a..6f989174a8 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -316,7 +316,7 @@ void add_global(const IntrusivePtr& id, IntrusivePtr t, make_var(id, std::move(t), c, std::move(init), std::move(attr), dt, true); } -IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, +IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, init_class c, IntrusivePtr init, std::unique_ptr>> attr, decl_type dt) @@ -336,7 +336,7 @@ IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, auto assign_expr = make_intrusive(std::move(name_expr), std::move(init), 0, nullptr, id->GetAttrs()); - auto stmt = make_intrusive(std::move(assign_expr)); + auto stmt = make_intrusive(std::move(assign_expr)); stmt->SetLocationInfo(&location); return stmt; } @@ -344,7 +344,7 @@ IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, else { current_scope()->AddInit(std::move(id)); - return make_intrusive(); + return make_intrusive(); } } @@ -633,7 +633,7 @@ TraversalCode OuterIDBindingFinder::PostExpr(const Expr* expr) return TC_CONTINUE; } -void end_func(IntrusivePtr body) +void end_func(IntrusivePtr body) { auto ingredients = std::make_unique(pop_scope(), std::move(body)); @@ -668,7 +668,7 @@ Val* internal_val(const char* name) return zeek::id::find_val(name).get(); } -id_list gather_outer_ids(Scope* scope, Stmt* body) +id_list gather_outer_ids(Scope* scope, zeek::detail::Stmt* body) { OuterIDBindingFinder cb(scope); body->Traverse(&cb); diff --git a/src/Var.h b/src/Var.h index 935e276f86..ba44b8de00 100644 --- a/src/Var.h +++ b/src/Var.h @@ -8,13 +8,14 @@ class Expr; class FuncType; -class Stmt; class Scope; class EventHandlerPtr; class StringVal; class TableVal; class ListVal; +FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); + typedef enum { VAR_REGULAR, VAR_CONST, VAR_REDEF, VAR_OPTION, } decl_type; extern void add_global(const IntrusivePtr& id, @@ -24,12 +25,12 @@ extern void add_global(const IntrusivePtr& id, std::unique_ptr>> attr, decl_type dt); -extern IntrusivePtr add_local(IntrusivePtr id, - IntrusivePtr t, - init_class c, - IntrusivePtr init, - std::unique_ptr>> attr, - decl_type dt); +extern IntrusivePtr add_local(IntrusivePtr id, + IntrusivePtr t, + init_class c, + IntrusivePtr init, + std::unique_ptr>> attr, + decl_type dt); extern IntrusivePtr add_and_assign_local(IntrusivePtr id, IntrusivePtr init, @@ -43,10 +44,10 @@ extern void begin_func(IntrusivePtr id, const char* module_name, IntrusivePtr t, std::unique_ptr>> attrs = nullptr); -extern void end_func(IntrusivePtr body); +extern void end_func(IntrusivePtr body); // Gather all IDs referenced inside a body that aren't part of a given scope. -extern id_list gather_outer_ids(Scope* scope, Stmt* body); +extern id_list gather_outer_ids(Scope* scope, zeek::detail::Stmt* body); [[deprecated("Remove in v4.1. Use zeek::id::find_val().")]] extern Val* internal_val(const char* name); diff --git a/src/input.h b/src/input.h index 70aa75ae28..fa6da97cec 100644 --- a/src/input.h +++ b/src/input.h @@ -41,5 +41,5 @@ extern std::vector zeek_script_prefixes; // -p flag extern const char* command_line_policy; // -e flag extern std::vector params; -class Stmt; -extern Stmt* stmts; // global statements +FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); +extern zeek::detail::Stmt* stmts; // global statements diff --git a/src/parse.y b/src/parse.y index 59b229bdca..5900f7f64c 100644 --- a/src/parse.y +++ b/src/parse.y @@ -239,7 +239,7 @@ static bool expr_is_table_type_name(const Expr* expr) RE_Matcher* re; Expr* expr; EventExpr* event_expr; - Stmt* stmt; + zeek::detail::Stmt* stmt; ListExpr* list; BroType* type; RecordType* record; @@ -247,8 +247,8 @@ static bool expr_is_table_type_name(const Expr* expr) TypeList* type_l; TypeDecl* type_decl; type_decl_list* type_decl_l; - Case* c_case; - case_list* case_l; + zeek::detail::Case* c_case; + zeek::detail::case_list* case_l; Attr* attr; std::vector>* attr_l; attr_tag attrtag; @@ -994,7 +994,7 @@ type: { if ( ! $1 || ! ($$ = $1->IsType() ? $1->GetType().get() : nullptr) ) { - NullStmt here; + zeek::detail::NullStmt here; if ( $1 ) $1->Error("not a Zeek type", &here); $$ = error_type()->Ref(); @@ -1413,7 +1413,7 @@ stmt: | TOK_PRINT expr_list ';' opt_no_test { set_location(@1, @3); - $$ = new PrintStmt(IntrusivePtr{AdoptRef{}, $2}); + $$ = new zeek::detail::PrintStmt(IntrusivePtr{AdoptRef{}, $2}); if ( ! $4 ) brofiler.AddStmt($$); } @@ -1421,7 +1421,7 @@ stmt: | TOK_EVENT event ';' opt_no_test { set_location(@1, @3); - $$ = new EventStmt({AdoptRef{}, $2}); + $$ = new zeek::detail::EventStmt({AdoptRef{}, $2}); if ( ! $4 ) brofiler.AddStmt($$); } @@ -1429,19 +1429,19 @@ stmt: | TOK_IF '(' expr ')' stmt { set_location(@1, @4); - $$ = new IfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, make_intrusive()); + $$ = new zeek::detail::IfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, make_intrusive()); } | TOK_IF '(' expr ')' stmt TOK_ELSE stmt { set_location(@1, @4); - $$ = new IfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, {AdoptRef{}, $7}); + $$ = new zeek::detail::IfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, {AdoptRef{}, $7}); } | TOK_SWITCH expr '{' case_list '}' { set_location(@1, @2); - $$ = new SwitchStmt({AdoptRef{}, $2}, $4); + $$ = new zeek::detail::SwitchStmt({AdoptRef{}, $2}, $4); } | for_head stmt @@ -1451,13 +1451,13 @@ stmt: | TOK_WHILE '(' expr ')' stmt { - $$ = new WhileStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}); + $$ = new zeek::detail::WhileStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}); } | TOK_NEXT ';' opt_no_test { set_location(@1, @2); - $$ = new NextStmt; + $$ = new zeek::detail::NextStmt; if ( ! $3 ) brofiler.AddStmt($$); } @@ -1465,7 +1465,7 @@ stmt: | TOK_BREAK ';' opt_no_test { set_location(@1, @2); - $$ = new BreakStmt; + $$ = new zeek::detail::BreakStmt; if ( ! $3 ) brofiler.AddStmt($$); } @@ -1473,7 +1473,7 @@ stmt: | TOK_FALLTHROUGH ';' opt_no_test { set_location(@1, @2); - $$ = new FallthroughStmt; + $$ = new zeek::detail::FallthroughStmt; if ( ! $3 ) brofiler.AddStmt($$); } @@ -1481,7 +1481,7 @@ stmt: | TOK_RETURN ';' opt_no_test { set_location(@1, @2); - $$ = new ReturnStmt(0); + $$ = new zeek::detail::ReturnStmt(0); if ( ! $3 ) brofiler.AddStmt($$); } @@ -1489,7 +1489,7 @@ stmt: | TOK_RETURN expr ';' opt_no_test { set_location(@1, @2); - $$ = new ReturnStmt({AdoptRef{}, $2}); + $$ = new zeek::detail::ReturnStmt({AdoptRef{}, $2}); if ( ! $4 ) brofiler.AddStmt($$); } @@ -1497,7 +1497,7 @@ stmt: | TOK_ADD expr ';' opt_no_test { set_location(@1, @3); - $$ = new AddStmt({AdoptRef{}, $2}); + $$ = new zeek::detail::AddStmt({AdoptRef{}, $2}); if ( ! $4 ) brofiler.AddStmt($$); } @@ -1505,7 +1505,7 @@ stmt: | TOK_DELETE expr ';' opt_no_test { set_location(@1, @3); - $$ = new DelStmt({AdoptRef{}, $2}); + $$ = new zeek::detail::DelStmt({AdoptRef{}, $2}); if ( ! $4 ) brofiler.AddStmt($$); } @@ -1535,15 +1535,15 @@ stmt: | TOK_WHEN '(' expr ')' stmt { set_location(@3, @5); - $$ = new WhenStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, - nullptr, nullptr, false); + $$ = new zeek::detail::WhenStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, + nullptr, nullptr, false); } | TOK_WHEN '(' expr ')' stmt TOK_TIMEOUT expr '{' opt_no_test_block stmt_list '}' { set_location(@3, @9); - $$ = new WhenStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, - {AdoptRef{}, $10}, {AdoptRef{}, $7}, false); + $$ = new zeek::detail::WhenStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, + {AdoptRef{}, $10}, {AdoptRef{}, $7}, false); if ( $9 ) brofiler.DecIgnoreDepth(); } @@ -1552,15 +1552,15 @@ stmt: | TOK_RETURN TOK_WHEN '(' expr ')' stmt { set_location(@4, @6); - $$ = new WhenStmt({AdoptRef{}, $4}, {AdoptRef{}, $6}, nullptr, + $$ = new zeek::detail::WhenStmt({AdoptRef{}, $4}, {AdoptRef{}, $6}, nullptr, nullptr, true); } | TOK_RETURN TOK_WHEN '(' expr ')' stmt TOK_TIMEOUT expr '{' opt_no_test_block stmt_list '}' { set_location(@4, @10); - $$ = new WhenStmt({AdoptRef{}, $4}, {AdoptRef{}, $6}, - {AdoptRef{}, $11}, {AdoptRef{}, $8}, true); + $$ = new zeek::detail::WhenStmt({AdoptRef{}, $4}, {AdoptRef{}, $6}, + {AdoptRef{}, $11}, {AdoptRef{}, $8}, true); if ( $10 ) brofiler.DecIgnoreDepth(); } @@ -1568,7 +1568,7 @@ stmt: | index_slice '=' expr ';' opt_no_test { set_location(@1, @4); - $$ = new ExprStmt(get_assign_expr({AdoptRef{}, $1}, + $$ = new zeek::detail::ExprStmt(get_assign_expr({AdoptRef{}, $1}, {AdoptRef{}, $3}, in_init)); if ( ! $5 ) @@ -1578,7 +1578,7 @@ stmt: | expr ';' opt_no_test { set_location(@1, @2); - $$ = new ExprStmt({AdoptRef{}, $1}); + $$ = new zeek::detail::ExprStmt({AdoptRef{}, $1}); if ( ! $3 ) brofiler.AddStmt($$); } @@ -1586,11 +1586,11 @@ stmt: | ';' { set_location(@1, @1); - $$ = new NullStmt; + $$ = new zeek::detail::NullStmt; } | conditional - { $$ = new NullStmt; } + { $$ = new zeek::detail::NullStmt; } ; stmt_list: @@ -1601,7 +1601,7 @@ stmt_list: $1->UpdateLocationEndInfo(@2); } | - { $$ = new StmtList(); } + { $$ = new zeek::detail::StmtList(); } ; event: @@ -1630,18 +1630,18 @@ case_list: case_list case { $1->push_back($2); } | - { $$ = new case_list; } + { $$ = new zeek::detail::case_list; } ; case: TOK_CASE expr_list ':' stmt_list - { $$ = new Case({AdoptRef{}, $2}, 0, {AdoptRef{}, $4}); } + { $$ = new zeek::detail::Case({AdoptRef{}, $2}, 0, {AdoptRef{}, $4}); } | TOK_CASE case_type_list ':' stmt_list - { $$ = new Case(nullptr, $2, {AdoptRef{}, $4}); } + { $$ = new zeek::detail::Case(nullptr, $2, {AdoptRef{}, $4}); } | TOK_DEFAULT ':' stmt_list - { $$ = new Case(nullptr, 0, {AdoptRef{}, $3}); } + { $$ = new zeek::detail::Case(nullptr, 0, {AdoptRef{}, $3}); } ; case_type_list: @@ -1704,12 +1704,12 @@ for_head: id_list* loop_vars = new id_list; loop_vars->push_back(loop_var.release()); - $$ = new ForStmt(loop_vars, {AdoptRef{}, $5}); + $$ = new zeek::detail::ForStmt(loop_vars, {AdoptRef{}, $5}); } | TOK_FOR '(' '[' local_id_list ']' TOK_IN expr ')' { - $$ = new ForStmt($4, {AdoptRef{}, $7}); + $$ = new zeek::detail::ForStmt($4, {AdoptRef{}, $7}); } | TOK_FOR '(' TOK_ID ',' TOK_ID TOK_IN expr ')' @@ -1742,7 +1742,7 @@ for_head: id_list* loop_vars = new id_list; loop_vars->push_back(key_var.release()); - $$ = new ForStmt(loop_vars, {AdoptRef{}, $7}, std::move(val_var)); + $$ = new zeek::detail::ForStmt(loop_vars, {AdoptRef{}, $7}, std::move(val_var)); } | TOK_FOR '(' '[' local_id_list ']' ',' TOK_ID TOK_IN expr ')' @@ -1761,7 +1761,7 @@ for_head: else val_var = install_ID($7, module, false, false); - $$ = new ForStmt($4, {AdoptRef{}, $9}, std::move(val_var)); + $$ = new zeek::detail::ForStmt($4, {AdoptRef{}, $9}, std::move(val_var)); } ; diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index e204e59b3e..36e970a086 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -101,7 +101,7 @@ zeek::Supervisor* zeek::supervisor_mgr = nullptr; trigger::Manager* trigger_mgr = nullptr; std::vector zeek_script_prefixes; -Stmt* stmts; +zeek::detail::Stmt* stmts; RuleMatcher* rule_matcher = nullptr; EventRegistry* event_registry = nullptr; ProfileLogger* profiling_logger = nullptr;