Change lookup_ID() to return a const-reference

This commit is contained in:
Jon Siwek 2020-05-12 22:41:52 -07:00
parent 8f95a2a0bb
commit 0af7f8141b
9 changed files with 32 additions and 28 deletions

View file

@ -197,7 +197,7 @@ void get_first_statement(Stmt* list, Stmt*& first, Location& loc)
static void parse_function_name(vector<ParseLocationRec>& result,
ParseLocationRec& plr, const string& s)
{ // function name
auto id = lookup_ID(s.c_str(), current_module.c_str());
const auto& id = lookup_ID(s.c_str(), current_module.c_str());
if ( ! id )
{

View file

@ -39,7 +39,7 @@ FuncType* EventHandler::FType(bool check_export)
if ( type )
return type;
auto id = lookup_ID(name, current_module.c_str(), false, false,
const auto& id = lookup_ID(name, current_module.c_str(), false, false,
check_export);
if ( ! id )

View file

@ -587,7 +587,7 @@ BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name,
name = make_full_var_name(GLOBAL_MODULE_NAME, arg_name);
is_pure = arg_is_pure;
auto id = lookup_ID(Name(), GLOBAL_MODULE_NAME, false);
const auto& id = lookup_ID(Name(), GLOBAL_MODULE_NAME, false);
if ( ! id )
reporter->InternalError("built-in function %s missing", Name());
if ( id->HasVal() )

View file

@ -117,7 +117,7 @@ TraversalCode Scope::Traverse(TraversalCallback* cb) const
}
IntrusivePtr<ID> lookup_ID(const char* name, const char* curr_module,
const IntrusivePtr<ID>& lookup_ID(const char* name, const char* curr_module,
bool no_global, bool same_module_only,
bool check_export)
{
@ -148,7 +148,8 @@ IntrusivePtr<ID> lookup_ID(const char* name, const char* curr_module,
return global_scope()->Find(globalname);
}
return nullptr;
static IntrusivePtr<ID> nil;
return nil;
}
IntrusivePtr<ID> install_ID(const char* name, const char* module_name,

View file

@ -90,7 +90,7 @@ protected:
extern bool in_debug;
// If no_global is true, don't search in the default "global" namespace.
extern IntrusivePtr<ID> lookup_ID(const char* name, const char* module,
extern const IntrusivePtr<ID>& lookup_ID(const char* name, const char* module,
bool no_global = false,
bool same_module_only = false,
bool check_export = true);

View file

@ -186,7 +186,7 @@ static BroFile* print_stdout = nullptr;
static IntrusivePtr<EnumVal> lookup_enum_val(const char* module_name, const char* name)
{
auto id = lookup_ID(name, module_name);
const auto& id = lookup_ID(name, module_name);
assert(id);
assert(id->IsEnumConst());

View file

@ -688,13 +688,13 @@ Val* internal_const_val(const char* name)
Val* opt_internal_val(const char* name)
{
auto id = lookup_ID(name, GLOBAL_MODULE_NAME);
const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME);
return id ? id->GetVal().get() : nullptr;
}
double opt_internal_double(const char* name)
{
auto id = lookup_ID(name, GLOBAL_MODULE_NAME);
const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME);
if ( ! id ) return 0.0;
const auto& v = id->GetVal();
return v ? v->InternalDouble() : 0.0;
@ -702,7 +702,7 @@ double opt_internal_double(const char* name)
bro_int_t opt_internal_int(const char* name)
{
auto id = lookup_ID(name, GLOBAL_MODULE_NAME);
const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME);
if ( ! id ) return 0;
const auto& v = id->GetVal();
return v ? v->InternalInt() : 0;
@ -710,7 +710,7 @@ bro_int_t opt_internal_int(const char* name)
bro_uint_t opt_internal_unsigned(const char* name)
{
auto id = lookup_ID(name, GLOBAL_MODULE_NAME);
const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME);
if ( ! id ) return 0;
const auto& v = id->GetVal();
return v ? v->InternalUnsigned() : 0;
@ -718,7 +718,7 @@ bro_uint_t opt_internal_unsigned(const char* name)
StringVal* opt_internal_string(const char* name)
{
auto id = lookup_ID(name, GLOBAL_MODULE_NAME);
const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME);
if ( ! id ) return nullptr;
const auto& v = id->GetVal();
return v ? v->AsStringVal() : nullptr;
@ -726,7 +726,7 @@ StringVal* opt_internal_string(const char* name)
TableVal* opt_internal_table(const char* name)
{
auto id = lookup_ID(name, GLOBAL_MODULE_NAME);
const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME);
if ( ! id ) return nullptr;
const auto& v = id->GetVal();
return v ? v->AsTableVal() : nullptr;
@ -734,7 +734,7 @@ TableVal* opt_internal_table(const char* name)
ListVal* internal_list_val(const char* name)
{
auto id = lookup_ID(name, GLOBAL_MODULE_NAME);
const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME);
if ( ! id )
return nullptr;

View file

@ -1599,7 +1599,7 @@ event:
TOK_ID '(' opt_expr_list ')'
{
set_location(@1, @4);
auto id = lookup_ID($1, current_module.c_str());
const auto& id = lookup_ID($1, current_module.c_str());
if ( id )
{
@ -1769,7 +1769,8 @@ local_id:
TOK_ID
{
set_location(@1);
$$ = lookup_ID($1, current_module.c_str()).release();
auto id = lookup_ID($1, current_module.c_str());
$$ = id.release();
if ( $$ )
{
@ -1805,8 +1806,9 @@ global_or_event_id:
TOK_ID
{
set_location(@1);
$$ = lookup_ID($1, current_module.c_str(), false,
defining_global_ID).release();
auto id = lookup_ID($1, current_module.c_str(), false,
defining_global_ID);
$$ = id.release();
if ( $$ )
{
@ -1842,7 +1844,8 @@ resolve_id:
TOK_ID
{
set_location(@1);
$$ = lookup_ID($1, current_module.c_str()).release();
auto id = lookup_ID($1, current_module.c_str());
$$ = id.release();
if ( ! $$ )
reporter->Error("identifier not defined: %s", $1);

View file

@ -774,7 +774,7 @@ void do_atifdef(const char* id)
{
++current_depth;
auto i = lookup_ID(id, current_module.c_str());
const auto& i = lookup_ID(id, current_module.c_str());
if ( ! i )
{
@ -787,7 +787,7 @@ void do_atifndef(const char *id)
{
++current_depth;
auto i = lookup_ID(id, current_module.c_str());
const auto& i = lookup_ID(id, current_module.c_str());
if ( i )
{
@ -1000,7 +1000,7 @@ int yywrap()
// string type.) If no type is found, the value
// is left unchanged.
std::string opt_quote; // no optional quote by default
auto param_id = lookup_ID(param, GLOBAL_MODULE_NAME);
const auto& param_id = lookup_ID(param, GLOBAL_MODULE_NAME);
Val* v = param_id ? param_id->GetVal().get() : nullptr;
if ( v && v->GetType() && v->GetType()->Tag() == TYPE_STRING )