Use string for TempVar::name

Nothing of consequence; just encapsulation of memory management
This commit is contained in:
Jon Siwek 2021-01-13 13:49:32 -08:00
parent 81fa7f7e3d
commit fe8db7f150
2 changed files with 5 additions and 5 deletions

View file

@ -10,7 +10,7 @@ TempVar::TempVar(int num, const TypePtr& t, ExprPtr _rhs) : type(t)
{ {
char buf[8192]; char buf[8192];
snprintf(buf, sizeof buf, "#%d", num); snprintf(buf, sizeof buf, "#%d", num);
name = util::copy_string(buf); name = buf;
id = nullptr; id = nullptr;
} }

View file

@ -5,18 +5,18 @@
// Class for managing temporary variables created during statement reduction // Class for managing temporary variables created during statement reduction
// for compilation. // for compilation.
#include <string>
#include "zeek/ID.h" #include "zeek/ID.h"
#include "zeek/Expr.h" #include "zeek/Expr.h"
namespace zeek::detail { namespace zeek::detail {
class TempVar { class TempVar {
public: public:
TempVar(int num, const TypePtr& t, ExprPtr rhs); TempVar(int num, const TypePtr& t, ExprPtr rhs);
~TempVar() { delete name; }
const char* Name() const { return name; } const char* Name() const { return name.data(); }
const zeek::Type* Type() const { return type.get(); } const zeek::Type* Type() const { return type.get(); }
const Expr* RHS() const { return rhs.get(); } const Expr* RHS() const { return rhs.get(); }
@ -26,7 +26,7 @@ public:
bool IsActive() const { return active; } bool IsActive() const { return active; }
protected: protected:
char* name; std::string name;
IDPtr id; IDPtr id;
const TypePtr& type; const TypePtr& type;
ExprPtr rhs; ExprPtr rhs;