mirror of
https://github.com/zeek/zeek.git
synced 2025-10-15 04:58:21 +00:00
restructured tracking of initializations of globals for script compilation
This commit is contained in:
parent
0d5c669c1c
commit
1af905a14f
5 changed files with 80 additions and 32 deletions
|
@ -105,6 +105,24 @@ protected:
|
|||
ExprPtr def_expr;
|
||||
};
|
||||
|
||||
// Class tracking information associated with a (global) identifier's
|
||||
// (re-)initialization.
|
||||
|
||||
class IDInitInfo
|
||||
{
|
||||
public:
|
||||
IDInitInfo(const ID* _id, ExprPtr _init, InitClass _ic) : id(_id), init(_init), ic(_ic) { }
|
||||
|
||||
const ID* Id() const { return id; }
|
||||
const ExprPtr& Init() const { return init; }
|
||||
InitClass IC() const { return ic; }
|
||||
|
||||
private:
|
||||
const ID* id;
|
||||
ExprPtr init;
|
||||
InitClass ic;
|
||||
};
|
||||
|
||||
// Class tracking optimization information associated with identifiers.
|
||||
|
||||
class IDOptInfo
|
||||
|
@ -118,11 +136,19 @@ public:
|
|||
void Clear();
|
||||
|
||||
// Used to track expressions employed when explicitly initializing
|
||||
// the identifier. These are needed by compile-to-C++ script
|
||||
// optimization. They're not used by ZAM optimization.
|
||||
void AddInitExpr(ExprPtr init_expr);
|
||||
// the (global) identifier. These are needed by compile-to-C++ script
|
||||
// optimization, and for tracking variable usage. An initialization
|
||||
// class other than INIT_NONE indicates that initialization should
|
||||
// be done with the ExprPtr form of ID::SetVal.
|
||||
void AddInitExpr(ExprPtr init_expr, InitClass ic = INIT_NONE);
|
||||
|
||||
// Returns the initialization expressions for this identifier.
|
||||
const std::vector<ExprPtr>& GetInitExprs() const { return init_exprs; }
|
||||
|
||||
// Returns a list of the initialization expressions seen for all
|
||||
// globals, ordered by when they were processed.
|
||||
static auto& GetGlobalInitExprs() { return global_init_exprs; }
|
||||
|
||||
// Associated constant expression, if any. This is only set
|
||||
// for identifiers that are aliases for a constant (i.e., there
|
||||
// are no other assignments to them).
|
||||
|
@ -224,6 +250,9 @@ private:
|
|||
// one of the earlier instances rather than the last one.
|
||||
std::vector<ExprPtr> init_exprs;
|
||||
|
||||
// Tracks initializations of globals in the order they're seen.
|
||||
static std::vector<IDInitInfo> global_init_exprs;
|
||||
|
||||
// If non-nil, a constant that this identifier always holds
|
||||
// once initially defined.
|
||||
const ConstExpr* const_expr = nullptr;
|
||||
|
@ -256,8 +285,12 @@ private:
|
|||
// Whether the identifier is a temporary variable.
|
||||
bool is_temp = false;
|
||||
|
||||
// Only needed for debugging purposes.
|
||||
// Associated identifier, to enable tracking of initialization
|
||||
// expressions for globals (for C++ compilation), and for debugging
|
||||
// output.
|
||||
const ID* my_id;
|
||||
|
||||
// Only needed for debugging purposes.
|
||||
bool tracing = false;
|
||||
|
||||
// Track whether we've already generated usage errors.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue