mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
preserve whether a global is an option
This commit is contained in:
parent
60656dafd8
commit
63cf1ae1b0
4 changed files with 18 additions and 9 deletions
|
@ -382,7 +382,8 @@ GlobalInitInfo::GlobalInitInfo(CPPCompile* c, const ID* g, string _CPP_name)
|
||||||
else
|
else
|
||||||
attrs = -1;
|
attrs = -1;
|
||||||
|
|
||||||
exported = g->IsExport();
|
is_exported = g->IsExport();
|
||||||
|
is_option = g->IsOption();
|
||||||
val = ValElem(c, nullptr); // empty because we initialize dynamically
|
val = ValElem(c, nullptr); // empty because we initialize dynamically
|
||||||
|
|
||||||
if ( gt->Tag() == TYPE_FUNC && (! g->GetVal() || g->GetVal()->AsFunc()->GetKind() == Func::BUILTIN_FUNC) )
|
if ( gt->Tag() == TYPE_FUNC && (! g->GetVal() || g->GetVal()->AsFunc()->GetKind() == Func::BUILTIN_FUNC) )
|
||||||
|
@ -398,7 +399,8 @@ void GlobalInitInfo::InitializerVals(std::vector<std::string>& ivs) const {
|
||||||
ivs.push_back(Fmt(type));
|
ivs.push_back(Fmt(type));
|
||||||
ivs.push_back(Fmt(attrs));
|
ivs.push_back(Fmt(attrs));
|
||||||
ivs.push_back(val);
|
ivs.push_back(val);
|
||||||
ivs.push_back(Fmt(exported));
|
ivs.push_back(Fmt(is_exported));
|
||||||
|
ivs.push_back(Fmt(is_option));
|
||||||
ivs.push_back(Fmt(func_with_no_val));
|
ivs.push_back(Fmt(func_with_no_val));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -479,7 +479,8 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
// A lightweight initializer for a Zeek global that will look it up at
|
// A lightweight initializer for a Zeek global that will look it up at
|
||||||
// initialization time but not create it if missing.
|
// initialization time but not create it if missing. If do_init is true,
|
||||||
|
// then the global will be (re-)initialized to its value during compilation.
|
||||||
class GlobalLookupInitInfo : public CPP_InitInfo {
|
class GlobalLookupInitInfo : public CPP_InitInfo {
|
||||||
public:
|
public:
|
||||||
GlobalLookupInitInfo(CPPCompile* c, const ID* g, std::string CPP_name, bool do_init = false);
|
GlobalLookupInitInfo(CPPCompile* c, const ID* g, std::string CPP_name, bool do_init = false);
|
||||||
|
@ -505,7 +506,8 @@ protected:
|
||||||
int type;
|
int type;
|
||||||
int attrs;
|
int attrs;
|
||||||
std::string val;
|
std::string val;
|
||||||
bool exported;
|
bool is_exported;
|
||||||
|
bool is_option;
|
||||||
bool func_with_no_val = false; // needed to handle some error situations
|
bool func_with_no_val = false; // needed to handle some error situations
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -464,7 +464,10 @@ void CPP_GlobalLookupInit::Generate(InitsManager* im, std::vector<void*>& /* ini
|
||||||
|
|
||||||
void CPP_GlobalInit::Generate(InitsManager* im, std::vector<void*>& /* inits_vec */, int /* offset */) const {
|
void CPP_GlobalInit::Generate(InitsManager* im, std::vector<void*>& /* inits_vec */, int /* offset */) const {
|
||||||
auto& t = im->Types(type);
|
auto& t = im->Types(type);
|
||||||
global = lookup_global__CPP(name, t, exported);
|
global = lookup_global__CPP(name, t, is_exported);
|
||||||
|
|
||||||
|
if ( is_option )
|
||||||
|
global->SetOption();
|
||||||
|
|
||||||
if ( ! global->HasVal() ) {
|
if ( ! global->HasVal() ) {
|
||||||
if ( val >= 0 )
|
if ( val >= 0 )
|
||||||
|
|
|
@ -396,15 +396,16 @@ protected:
|
||||||
|
|
||||||
class CPP_GlobalInit : public CPP_Init<void*> {
|
class CPP_GlobalInit : public CPP_Init<void*> {
|
||||||
public:
|
public:
|
||||||
CPP_GlobalInit(IDPtr& _global, const char* _name, int _type, int _attrs, int _val, bool _exported,
|
CPP_GlobalInit(IDPtr& _global, const char* _name, int _type, int _attrs, int _val, bool _is_exported,
|
||||||
bool _func_with_no_val)
|
bool _is_option, bool _func_with_no_val)
|
||||||
: CPP_Init<void*>(),
|
: CPP_Init<void*>(),
|
||||||
global(_global),
|
global(_global),
|
||||||
name(_name),
|
name(_name),
|
||||||
type(_type),
|
type(_type),
|
||||||
attrs(_attrs),
|
attrs(_attrs),
|
||||||
val(_val),
|
val(_val),
|
||||||
exported(_exported),
|
is_exported(_is_exported),
|
||||||
|
is_option(_is_option),
|
||||||
func_with_no_val(_func_with_no_val) {}
|
func_with_no_val(_func_with_no_val) {}
|
||||||
|
|
||||||
void Generate(InitsManager* im, std::vector<void*>& /* inits_vec */, int /* offset */) const override;
|
void Generate(InitsManager* im, std::vector<void*>& /* inits_vec */, int /* offset */) const override;
|
||||||
|
@ -415,7 +416,8 @@ protected:
|
||||||
int type;
|
int type;
|
||||||
int attrs;
|
int attrs;
|
||||||
int val;
|
int val;
|
||||||
bool exported;
|
bool is_exported;
|
||||||
|
bool is_option;
|
||||||
bool func_with_no_val;
|
bool func_with_no_val;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue