diff --git a/src/Expr.cc b/src/Expr.cc index e7ff145042..b5cf00edba 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -19,6 +19,7 @@ #include "zeek/module_util.h" #include "zeek/DebugLogger.h" #include "zeek/Hash.h" +#include "zeek/script_opt/ExprOptInfo.h" #include "zeek/broker/Data.h" @@ -79,6 +80,12 @@ const char* expr_name(BroExprTag t) Expr::Expr(BroExprTag arg_tag) : tag(arg_tag), paren(false), type(nullptr) { SetLocationInfo(&start_location, &end_location); + opt_info = new ExprOptInfo(); + } + +Expr::~Expr() + { + delete opt_info; } const ListExpr* Expr::AsListExpr() const diff --git a/src/Expr.h b/src/Expr.h index afeb1425ff..9e19830870 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -117,6 +117,8 @@ using RefExprPtr = IntrusivePtr; class Stmt; using StmtPtr = IntrusivePtr; +class ExprOptInfo; + class Expr : public Obj { public: const TypePtr& GetType() const @@ -389,6 +391,12 @@ public: return Obj::GetLocationInfo(); } + // Access script optimization information associated with + // this statement. + ExprOptInfo* GetOptInfo() const { return opt_info; } + + ~Expr() override; + protected: Expr() = default; explicit Expr(BroExprTag arg_tag); @@ -418,6 +426,10 @@ protected: // derived, if any. Used as an aid for generating meaningful // and correctly-localized error messages. ExprPtr original = nullptr; + + // Information associated with the Expr for purposes of + // script optimization. + ExprOptInfo* opt_info; }; class NameExpr final : public Expr { diff --git a/src/script_opt/ExprOptInfo.h b/src/script_opt/ExprOptInfo.h new file mode 100644 index 0000000000..74822a6370 --- /dev/null +++ b/src/script_opt/ExprOptInfo.h @@ -0,0 +1,17 @@ +// See the file "COPYING" in the main distribution directory for copyright. + +// Auxiliary information associated with expressions to aid script +// optimization. + +#pragma once + +namespace zeek::detail { + +class ExprOptInfo { +public: + // The AST number of the statement in which this expression + // appears. + int stmt_num = -1; // -1 = not assigned yet +}; + +} // namespace zeek::detail