Skip to content

Commit

Permalink
[FOLD]
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian committed Oct 30, 2023
1 parent 74955ed commit 2dc2818
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 219 deletions.
69 changes: 26 additions & 43 deletions src/lib/Metadata/Finalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,60 +31,37 @@ class Finalizer
SymbolLookup& lookup_;
Info* current_ = nullptr;

void resolveReference(doc::Reference& ref)
bool resolveReference(doc::Reference& ref)
{
Info* context = current_;
std::string_view str = ref.string;
std::vector<std::string_view> parts;
auto parse_result = parseIdExpression(ref.string);
if(! parse_result)
false;

if(auto r = parseIdExpression(str))
const Info* found = nullptr;
if(parse_result->qualified)
{
auto rr = *r;
rr = rr;
Info* context = current_;
std::vector<std::string_view> qualifier;
// KRYSTIAN FIXME: lookupQualified should accept
// std::vector<std::string> as the qualifier
for(auto& part : parse_result->qualifier)
qualifier.push_back(part);
if(parse_result->qualifier.empty())
context = info_.find(SymbolID::zero)->get();
found = lookup_.lookupQualified(
context, qualifier, parse_result->name);
}
else
{
auto rr = r.error().reason();
rr = rr;
}


// parse the referenced name
bool qualified = false;
if(str.starts_with("::"))
{
str.remove_prefix(2);
context = info_.find(SymbolID::zero)->get();
qualified = true;
}
do
{
std::size_t idx = str.find("::");
parts.emplace_back(str.substr(0, idx));
if(idx == std::string_view::npos)
break;
str.remove_prefix(idx + 2);
qualified = true;
found = lookup_.lookupUnqualified(
current_, parse_result->name);
}
while(! str.empty());
MRDOCS_ASSERT(! parts.empty());

// perform unqualified or qualified lookup for the symbol
std::string_view name = parts.back();
std::span<std::string_view> qualifier(
parts.begin(), parts.size() - 1);

const Info* found = nullptr;
if(qualified)
found = lookup_.lookupQualified(
context, qualifier, name);
else
found = lookup_.lookupUnqualified(context, name);

// if we found a symbol, replace the reference
// ID with the SymbolID of that symbol
if(found)
ref.id = found->id;
return found;
}

void finalize(SymbolID& id)
Expand Down Expand Up @@ -175,7 +152,13 @@ class Finalizer
finalize(N.children);

if constexpr(std::derived_from<NodeTy, doc::Reference>)
resolveReference(N);
{
if(! resolveReference(N))
{
report::warn("Failed to resolve reference to '{}' from '{}'",
N.string, current_->Name);
}
}
});
}

Expand Down
Loading

0 comments on commit 2dc2818

Please sign in to comment.