Skip to content

Instantly share code, notes, and snippets.

@ghassanpl
Created September 2, 2018 20:00
Show Gist options
  • Select an option

  • Save ghassanpl/c2e83cf4bc8dfea14420e6f1de1c2901 to your computer and use it in GitHub Desktop.

Select an option

Save ghassanpl/c2e83cf4bc8dfea14420e6f1de1c2901 to your computer and use it in GitHub Desktop.
void LookupTypeName(const AST::TypeName & tn, EntitySet & entity_list)
{
std::vector<TypePart> parts = ConvertToList(*this, tn);
EntitySet possible_places;
Entity* context = this;
do
{
possible_places.insert(context);
}
while (context = context->ParentEntity);
for (auto& part : parts)
{
EntitySet new_possible_places;
for (auto& place : possible_places)
{
EntitySet named;
place->GetChildEntities(part.Name, named);
for (auto& name : named)
{
if (name->IsTemplated())
{
auto templ = dynamic_cast<TemplateEntity*>(name);
if (templ->CanInstantiateWith(part.TemplateArguments))
{
auto instantiation = templ->CreateOrGetInstantiation(part.TemplateArguments);
new_possible_places.insert(instantiation);
}
}
else if (part.TemplateArguments.size() == 0 && !name->IsTemplated())
{
new_possible_places.insert(name);
}
}
}
possible_places = std::move(new_possible_places);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment