mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00
initial implementation of class for temporary variables; this will grow in complexity as we add additional optimization stages
This commit is contained in:
parent
8d77194719
commit
6aa84087b0
3 changed files with 54 additions and 0 deletions
|
@ -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
|
||||
|
|
17
src/script_opt/TempVar.cc
Normal file
17
src/script_opt/TempVar.cc
Normal file
|
@ -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
|
36
src/script_opt/TempVar.h
Normal file
36
src/script_opt/TempVar.h
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue