diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ca7736485f..2da4e12e6f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -327,6 +327,7 @@ set(MAIN_SRCS script_opt/ProfileFunc.cc script_opt/ScriptOpt.cc script_opt/Stmt.cc + script_opt/TempVar.cc nb_dns.c digest.h diff --git a/src/script_opt/TempVar.cc b/src/script_opt/TempVar.cc new file mode 100644 index 0000000000..4ce879e37e --- /dev/null +++ b/src/script_opt/TempVar.cc @@ -0,0 +1,17 @@ +// See the file "COPYING" in the main distribution directory for copyright. + +#include "TempVar.h" +#include "Reporter.h" + + +namespace zeek::detail { + +TempVar::TempVar(int num, const TypePtr& t, ExprPtr _rhs) : type(t) + { + char buf[8192]; + snprintf(buf, sizeof buf, "#%d", num); + name = util::copy_string(buf); + id = nullptr; + } + +} // zeek::detail diff --git a/src/script_opt/TempVar.h b/src/script_opt/TempVar.h new file mode 100644 index 0000000000..6360521d11 --- /dev/null +++ b/src/script_opt/TempVar.h @@ -0,0 +1,36 @@ +// See the file "COPYING" in the main distribution directory for copyright. + +#pragma once + +// Class for managing temporary variables created during statement reduction +// for compilation. + +#include "ID.h" +#include "Expr.h" + + +namespace zeek::detail { + +class TempVar { +public: + TempVar(int num, const TypePtr& t, ExprPtr rhs); + ~TempVar() { delete name; } + + const char* Name() const { return name; } + const zeek::Type* Type() const { return type.get(); } + const Expr* RHS() const { return rhs.get(); } + + IDPtr Id() const { return id; } + void SetID(IDPtr _id) { id = std::move(_id); } + void Deactivate() { active = false; } + bool IsActive() const { return active; } + +protected: + char* name; + IDPtr id; + const TypePtr& type; + ExprPtr rhs; + bool active = true; +}; + +} // zeek::detail