Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/parser/cxx/name_lookup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ auto Lookup::lookupHelper(Scope* scope, const Name* name,
cache.insert(scope);

for (auto symbol : scope->find(name)) {
if (auto u = symbol_cast<UsingDeclarationSymbol>(symbol);
u && u->target()) {
return u->target();
}

return symbol;
}

Expand Down Expand Up @@ -185,6 +190,30 @@ auto Lookup::lookupType(NestedNameSpecifierAST* nestedNameSpecifier,
return nullptr;
}

case SymbolKind::kUsingDeclaration: {
auto usingDeclaration =
symbol_cast<UsingDeclarationSymbol>(nestedNameSpecifier->symbol);

if (!usingDeclaration->target()) return nullptr;

if (auto classSymbol =
symbol_cast<ClassSymbol>(usingDeclaration->target())) {
return lookupTypeHelper(classSymbol->scope(), id, set);
}

if (auto enumSymbol =
symbol_cast<EnumSymbol>(usingDeclaration->target())) {
return lookupTypeHelper(enumSymbol->scope(), id, set);
}

if (auto scopedEnumSymbol =
symbol_cast<ScopedEnumSymbol>(usingDeclaration->target())) {
return lookupTypeHelper(scopedEnumSymbol->scope(), id, set);
}

return nullptr;
}

default:
return nullptr;
} // swotch
Expand All @@ -198,9 +227,9 @@ auto Lookup::lookupTypeHelper(Scope* scope, const Identifier* id,
}

for (auto candidate : scope->find(id)) {
if (candidate->isClassOrNamespace() || candidate->isEnumOrScopedEnum() ||
candidate->isTypeAlias() || candidate->isTypeParameter())
if (is_type(candidate) || candidate->isNamespace()) {
return candidate;
}
}

if (auto classSymbol = symbol_cast<ClassSymbol>(scope->owner())) {
Expand Down
18 changes: 4 additions & 14 deletions src/parser/cxx/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6588,20 +6588,6 @@ auto Parser::is_glvalue(ExpressionAST* expr) const -> bool {
expr->valueCategory == ValueCategory::kXValue;
}

auto Parser::is_type(Symbol* symbol) const -> bool {
if (!symbol) return false;
switch (symbol->kind()) {
case SymbolKind::kTypeParameter:
case SymbolKind::kTypeAlias:
case SymbolKind::kClass:
case SymbolKind::kEnum:
case SymbolKind::kScopedEnum:
return true;
default:
return false;
} // switch
}

auto Parser::is_template(Symbol* symbol) const -> bool {
auto templateParameters = cxx::getTemplateParameters(symbol);
return templateParameters != nullptr;
Expand Down Expand Up @@ -8325,6 +8311,10 @@ auto Parser::parse_using_declarator(UsingDeclaratorAST*& yyast) -> bool {

auto target = Lookup{scope_}.lookup(nestedNameSpecifier, name);

if (auto u = symbol_cast<UsingDeclarationSymbol>(target)) {
target = u->target();
}

auto symbol = control_->newUsingDeclarationSymbol(
scope_, unqualifiedId->firstSourceLocation());

Expand Down
1 change: 0 additions & 1 deletion src/parser/cxx/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,6 @@ class Parser final {
[[nodiscard]] auto is_xvalue(ExpressionAST* expr) const -> bool;
[[nodiscard]] auto is_glvalue(ExpressionAST* expr) const -> bool;

[[nodiscard]] auto is_type(Symbol* symbol) const -> bool;
[[nodiscard]] auto is_template(Symbol* symbol) const -> bool;
[[nodiscard]] auto is_constructor(Symbol* symbol) const -> bool;

Expand Down
19 changes: 19 additions & 0 deletions src/parser/cxx/symbols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -631,4 +631,23 @@ void UsingDeclarationSymbol::setDeclarator(UsingDeclaratorAST* declarator) {
declarator_ = declarator;
}

bool is_type(Symbol* symbol) {
if (!symbol) return false;
switch (symbol->kind()) {
case SymbolKind::kTypeParameter:
case SymbolKind::kConstraintTypeParameter:
case SymbolKind::kTypeAlias:
case SymbolKind::kClass:
case SymbolKind::kEnum:
case SymbolKind::kScopedEnum:
return true;
case SymbolKind::kUsingDeclaration: {
auto usingDeclaration = symbol_cast<UsingDeclarationSymbol>(symbol);
return is_type(usingDeclaration->target());
}
default:
return false;
} // switch
}

} // namespace cxx
6 changes: 4 additions & 2 deletions src/parser/cxx/symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Symbol {
[[nodiscard]] auto next() const -> Symbol*;

#define PROCESS_SYMBOL(S) \
[[nodiscard]] auto is##S() const->bool { return kind_ == SymbolKind::k##S; }
[[nodiscard]] auto is##S() const -> bool { return kind_ == SymbolKind::k##S; }
CXX_FOR_EACH_SYMBOL(PROCESS_SYMBOL)
#undef PROCESS_SYMBOL

Expand Down Expand Up @@ -715,6 +715,8 @@ class UsingDeclarationSymbol final : public Symbol {
UsingDeclaratorAST* declarator_ = nullptr;
};

bool is_type(Symbol* symbol);

template <typename Visitor>
auto visit(Visitor&& visitor, Symbol* symbol) {
#define PROCESS_SYMBOL(S) \
Expand All @@ -731,7 +733,7 @@ auto visit(Visitor&& visitor, Symbol* symbol) {
}

#define PROCESS_SYMBOL(S) \
inline auto is##S##Symbol(Symbol* symbol)->bool { \
inline auto is##S##Symbol(Symbol* symbol) -> bool { \
return symbol && symbol->kind() == SymbolKind::k##S; \
}

Expand Down
Loading