got rid of reference_wrappers

This commit is contained in:
lachrymaL 2021-05-17 15:16:02 -04:00
parent 53d9641e98
commit 93d6673226
No known key found for this signature in database
GPG key ID: F3640ACFA174B1C1
2 changed files with 16 additions and 14 deletions

View file

@ -151,7 +151,7 @@ namespace NVL
{ {
Object this_object; Object this_object;
Context this_context = parent_context; Context this_context = parent_context;
this_context.Scope_Hierarchy.push_back(this_object); this_context.Scope_Hierarchy.push_back(&this_object);
skip_ws(nvl); skip_ws(nvl);
@ -247,11 +247,13 @@ namespace NVL
this_object.Is_Symbol = is_symbol; this_object.Is_Symbol = is_symbol;
if (is_parent_call) if (is_parent_call)
(std::get<std::reference_wrapper<Call>>(parent_context.Scope_Hierarchy.back())).get().Objects.push_back(this_object); std::get<Call*>(parent_context.Scope_Hierarchy.back())->Objects.push_back(this_object);
else if ((std::get<std::reference_wrapper<Object>>(parent_context.Scope_Hierarchy.back())).get().Value.index() == 4) // 4 for list, indicates that parent is an object that is already a vector of objects else if (std::get<Object*>(parent_context.Scope_Hierarchy.back())->Value.index() == 4) // 4 for list, indicates that parent is an object that is already a vector of objects
std::get<std::vector<Object>>((std::get<std::reference_wrapper<Object>>(parent_context.Scope_Hierarchy.back())).get().Value).push_back(this_object); std::get<std::vector<Object>>(
std::get<Object*>(parent_context.Scope_Hierarchy.back())->Value
).push_back(this_object);
else // parent is not yet vector, initialize as (change from nil to) vector else // parent is not yet vector, initialize as (change from nil to) vector
(std::get<std::reference_wrapper<Object>>(parent_context.Scope_Hierarchy.back())).get().Value = std::vector<Object> { this_object }; std::get<Object*>(parent_context.Scope_Hierarchy.back())->Value = std::vector<Object> { this_object };
} }
void parse_Call(Context parent_context, std::ifstream& nvl) void parse_Call(Context parent_context, std::ifstream& nvl)
@ -259,7 +261,7 @@ namespace NVL
Call this_call; Call this_call;
Context this_context = parent_context; Context this_context = parent_context;
this_context.Scope_Hierarchy.push_back(this_call); this_context.Scope_Hierarchy.push_back(&this_call);
// parse the symbol (first obj in call) // parse the symbol (first obj in call)
parse_Object<true, true>(this_context, nvl); parse_Object<true, true>(this_context, nvl);
@ -270,14 +272,14 @@ namespace NVL
parse_Object<true, false>(this_context, nvl); parse_Object<true, false>(this_context, nvl);
} }
(std::get<std::reference_wrapper<Sequence>>(parent_context.Scope_Hierarchy.back())).get().Calls.push_back(this_call); std::get<Sequence*>(parent_context.Scope_Hierarchy.back())->Calls.push_back(this_call);
} }
void parse_Sequence(Context parent_context, std::ifstream& nvl) void parse_Sequence(Context parent_context, std::ifstream& nvl)
{ {
Sequence this_sequence; Sequence this_sequence;
Context this_context = parent_context; Context this_context = parent_context;
this_context.Scope_Hierarchy.push_back(this_sequence); this_context.Scope_Hierarchy.push_back(&this_sequence);
skip_ws(nvl); skip_ws(nvl);
@ -306,7 +308,7 @@ namespace NVL
nvl.get(c); // get } nvl.get(c); // get }
std::get<std::reference_wrapper<Tree>>(parent_context.Scope_Hierarchy.back()).get().Sequences.push_back(this_sequence); std::get<Tree*>(parent_context.Scope_Hierarchy.back())->Sequences.push_back(this_sequence);
} }
void parse_NVL(Tree& root, std::string path) void parse_NVL(Tree& root, std::string path)
@ -316,7 +318,7 @@ namespace NVL
if (nvl.is_open()) { if (nvl.is_open()) {
Context current_context; Context current_context;
current_context.Scope_Hierarchy.push_back(root); current_context.Scope_Hierarchy.push_back(&root);
while (!nvl.eof()) { while (!nvl.eof()) {
// parse_Sequence() already takes care of comments before a sequence // parse_Sequence() already takes care of comments before a sequence

View file

@ -56,10 +56,10 @@ namespace NVL
struct Context { struct Context {
std::vector<std::variant< std::vector<std::variant<
std::reference_wrapper<Tree>, Tree*,
std::reference_wrapper<Sequence>, Sequence*,
std::reference_wrapper<Call>, Call*,
std::reference_wrapper<Object> Object*
>> Scope_Hierarchy; >> Scope_Hierarchy;
}; };