diff --git a/src/parser/cxx/ast_rewriter.cc b/src/parser/cxx/ast_rewriter.cc index 6c44ade8..8d2b90ff 100644 --- a/src/parser/cxx/ast_rewriter.cc +++ b/src/parser/cxx/ast_rewriter.cc @@ -96,10 +96,7 @@ auto ASTRewriter::instantiateClassTemplate( ClassSymbol* classSymbol) -> ClassSymbol* { auto templateDecl = classSymbol->templateDeclaration(); - ClassSpecifierAST* classSpecifier = - ast_cast(classSymbol->declaration()); - - if (!classSpecifier) return nullptr; + if (!classSymbol->declaration()) return nullptr; auto templateArguments = make_substitution(unit, templateDecl, templateArgumentList); @@ -128,6 +125,9 @@ auto ASTRewriter::instantiateClassTemplate( return subst; } + auto classSpecifier = ast_cast(classSymbol->declaration()); + if (!classSpecifier) return nullptr; + auto parentScope = classSymbol->enclosingNonTemplateParametersScope(); auto rewriter = ASTRewriter{unit, parentScope, templateArguments}; diff --git a/src/parser/cxx/ast_rewriter.h b/src/parser/cxx/ast_rewriter.h index aa2aed3e..5bb03a60 100644 --- a/src/parser/cxx/ast_rewriter.h +++ b/src/parser/cxx/ast_rewriter.h @@ -54,6 +54,11 @@ class ASTRewriter { TemplateDeclarationAST* templateHead = nullptr) -> DeclarationAST*; + [[nodiscard]] static auto make_substitution( + TranslationUnit* unit, TemplateDeclarationAST* templateDecl, + List* templateArgumentList) + -> std::vector; + private: [[nodiscard]] auto templateArguments() const -> const std::vector& { @@ -73,11 +78,6 @@ class ASTRewriter { [[nodiscard]] auto restrictedToDeclarations() const -> bool; void setRestrictedToDeclarations(bool restrictedToDeclarations); - [[nodiscard]] static auto make_substitution( - TranslationUnit* unit, TemplateDeclarationAST* templateDecl, - List* templateArgumentList) - -> std::vector; - // run on the base nodes [[nodiscard]] auto unit(UnitAST* ast) -> UnitAST*; [[nodiscard]] auto statement(StatementAST* ast) -> StatementAST*; diff --git a/src/parser/cxx/ast_rewriter_specifiers.cc b/src/parser/cxx/ast_rewriter_specifiers.cc index f70ffa3c..ae1c15e8 100644 --- a/src/parser/cxx/ast_rewriter_specifiers.cc +++ b/src/parser/cxx/ast_rewriter_specifiers.cc @@ -787,10 +787,6 @@ auto ASTRewriter::SpecifierVisitor::operator()(ClassSpecifierAST* ast) classSymbol->setDeclaration(copy); classSymbol->setTemplateDeclaration(templateHead); - if (templateHead) { - classSymbol->setTemplateParameters(binder()->currentTemplateParameters()); - } - if (ast->symbol == rewrite.binder().instantiatingSymbol()) { ast->symbol->addSpecialization(rewrite.templateArguments(), classSymbol); } else { diff --git a/src/parser/cxx/binder.cc b/src/parser/cxx/binder.cc index 84a830cc..5b66c5d1 100644 --- a/src/parser/cxx/binder.cc +++ b/src/parser/cxx/binder.cc @@ -108,7 +108,7 @@ void Binder::setScope(ScopeSymbol* scope) { inTemplate_ = false; for (auto current = scope_; current; current = current->parent()) { - if (current->isTemplateParameters()) { + if (auto params = current->templateParameters()) { inTemplate_ = true; break; } @@ -212,7 +212,6 @@ void Binder::bind(ElaboratedTypeSpecifierAST* ast, DeclSpecs& declSpecs, classSymbol->setIsUnion(isUnion); classSymbol->setName(name); - classSymbol->setTemplateParameters(currentTemplateParameters()); classSymbol->setTemplateDeclaration(declSpecs.templateHead); declaringScope()->addSymbol(classSymbol); @@ -230,42 +229,99 @@ void Binder::bind(ElaboratedTypeSpecifierAST* ast, DeclSpecs& declSpecs, } void Binder::bind(ClassSpecifierAST* ast, DeclSpecs& declSpecs) { - auto templateParameters = currentTemplateParameters(); + auto check_optional_nested_name_specifier = [&] { + if (!ast->nestedNameSpecifier) return; - if (ast->nestedNameSpecifier) { auto parent = ast->nestedNameSpecifier->symbol; - if (parent && parent->isClassOrNamespace()) { - setScope(static_cast(parent)); + if (!parent || !parent->isClassOrNamespace()) { + error(ast->nestedNameSpecifier->firstSourceLocation(), + "nested name specifier must be a class or namespace"); + return; } - } - auto className = get_name(control(), ast->unqualifiedId); - auto templateId = ast_cast(ast->unqualifiedId); - if (templateId) { - className = templateId->identifier; - } + setScope(static_cast(parent)); + }; - auto location = ast->classLoc; - if (templateId) { - location = templateId->identifierLoc; - } else if (ast->unqualifiedId) { - location = ast->unqualifiedId->firstSourceLocation(); - } + auto check_template_specialization = [&] { + auto templateId = ast_cast(ast->unqualifiedId); + if (!templateId) return false; - ClassSymbol* primaryTemplate = nullptr; + const auto location = templateId->identifierLoc; - if (templateId && scope()->isTemplateParameters()) { - for (auto candidate : declaringScope()->find(className) | views::classes) { - primaryTemplate = candidate; + ClassSymbol* primaryTemplateSymbol = nullptr; + + for (auto candidate : + declaringScope()->find(templateId->identifier) | views::classes) { + primaryTemplateSymbol = candidate; break; } - if (!primaryTemplate) { + if (!primaryTemplateSymbol || + !primaryTemplateSymbol->templateParameters()) { error(location, std::format("specialization of undeclared template '{}'", templateId->identifier->name())); + // return true; } - } + + std::vector templateArguments; + ClassSymbol* specialization = nullptr; + + if (primaryTemplateSymbol) { + templateArguments = ASTRewriter::make_substitution( + unit_, primaryTemplateSymbol->templateDeclaration(), + templateId->templateArgumentList); + + specialization = + primaryTemplateSymbol + ? primaryTemplateSymbol->findSpecialization(templateArguments) + : nullptr; + + if (specialization) { + error(location, std::format("redefinition of specialization '{}'", + templateId->identifier->name())); + // return true; + } + } + + const auto isUnion = ast->classKey == TokenKind::T_UNION; + + auto classSymbol = control()->newClassSymbol(declaringScope(), location); + ast->symbol = classSymbol; + + classSymbol->setIsUnion(isUnion); + classSymbol->setName(templateId->identifier); + ast->symbol->setDeclaration(ast); + ast->symbol->setFinal(ast->isFinal); + + // if (declSpecs.templateHead) { + // warning(location, "setting template head"); + // ast->symbol->setTemplateDeclaration(declSpecs.templateHead); + // } + + declSpecs.setTypeSpecifier(ast); + declSpecs.setType(ast->symbol->type()); + + if (primaryTemplateSymbol) { + primaryTemplateSymbol->addSpecialization(std::move(templateArguments), + classSymbol); + } + + return true; + }; + + check_optional_nested_name_specifier(); + + if (check_template_specialization()) return; + + // get the component anme + const Identifier* className = nullptr; + if (auto nameId = ast_cast(ast->unqualifiedId)) + className = nameId->identifier; + + const auto location = ast->unqualifiedId + ? ast->unqualifiedId->firstSourceLocation() + : ast->classLoc; ClassSymbol* classSymbol = nullptr; @@ -277,6 +333,9 @@ void Binder::bind(ClassSpecifierAST* ast, DeclSpecs& declSpecs) { } if (classSymbol && classSymbol->isComplete()) { + // not a template-id, but a class with the same name already exists + error(location, + std::format("redefinition of class '{}'", to_string(className))); classSymbol = nullptr; } @@ -285,29 +344,22 @@ void Binder::bind(ClassSpecifierAST* ast, DeclSpecs& declSpecs) { classSymbol = control()->newClassSymbol(scope(), location); classSymbol->setIsUnion(isUnion); classSymbol->setName(className); - classSymbol->setTemplateParameters(templateParameters); - if (!primaryTemplate) { - declaringScope()->addSymbol(classSymbol); - } else { - std::vector arguments; - // TODO: parse template arguments - primaryTemplate->addSpecialization(arguments, classSymbol); - } + declaringScope()->addSymbol(classSymbol); } - classSymbol->setDeclaration(ast); + ast->symbol = classSymbol; + + ast->symbol->setDeclaration(ast); if (declSpecs.templateHead) { - classSymbol->setTemplateDeclaration(declSpecs.templateHead); + ast->symbol->setTemplateDeclaration(declSpecs.templateHead); } - classSymbol->setFinal(ast->isFinal); - - ast->symbol = classSymbol; + ast->symbol->setFinal(ast->isFinal); declSpecs.setTypeSpecifier(ast); - declSpecs.setType(classSymbol->type()); + declSpecs.setType(ast->symbol->type()); } void Binder::complete(ClassSpecifierAST* ast) { @@ -417,7 +469,6 @@ auto Binder::declareTypeAlias(SourceLocation identifierLoc, TypeIdAST* typeId, symbol->setName(name); if (typeId) symbol->setType(typeId->type); - symbol->setTemplateParameters(currentTemplateParameters()); if (auto classType = type_cast(symbol->type())) { auto classSymbol = classType->symbol(); @@ -565,7 +616,6 @@ void Binder::bind(ConceptDefinitionAST* ast) { auto symbol = control()->newConceptSymbol(scope(), ast->identifierLoc); symbol->setName(ast->identifier); - symbol->setTemplateParameters(templateParameters); declaringScope()->addSymbol(symbol); } @@ -708,7 +758,6 @@ auto Binder::declareFunction(DeclaratorAST* declarator, const Decl& decl) applySpecifiers(functionSymbol, decl.specs); functionSymbol->setName(name); functionSymbol->setType(type); - functionSymbol->setTemplateParameters(currentTemplateParameters()); if (isConstructor(functionSymbol)) { auto enclosingClass = symbol_cast(scope()); @@ -775,7 +824,6 @@ auto Binder::declareVariable(DeclaratorAST* declarator, const Decl& decl) applySpecifiers(symbol, decl.specs); symbol->setName(name); symbol->setType(type); - symbol->setTemplateParameters(currentTemplateParameters()); declaringScope()->addSymbol(symbol); return symbol; } @@ -890,13 +938,29 @@ auto Binder::resolve(NestedNameSpecifierAST* nestedNameSpecifier, } void Binder::bind(IdExpressionAST* ast) { - if (ast->unqualifiedId) { - auto name = get_name(control(), ast->unqualifiedId); - const Name* componentName = name; - if (auto templateId = name_cast(name)) - componentName = templateId->name(); - ast->symbol = Lookup{scope()}(ast->nestedNameSpecifier, componentName); + if (!ast->unqualifiedId) { + error(ast->firstSourceLocation(), + "expected an unqualified identifier in id expression"); + return; } + + auto name = get_name(control(), ast->unqualifiedId); + + const Name* componentName = name; + + if (auto templateId = name_cast(name)) { + componentName = templateId->name(); + } + + if (ast->nestedNameSpecifier) { + if (!ast->nestedNameSpecifier->symbol) { + error(ast->nestedNameSpecifier->firstSourceLocation(), + "nested name specifier must be a class or namespace"); + return; + } + } + + ast->symbol = Lookup{scope()}(ast->nestedNameSpecifier, componentName); } auto Binder::getFunction(ScopeSymbol* scope, const Name* name, const Type* type) diff --git a/src/parser/cxx/external_name_encoder.cc b/src/parser/cxx/external_name_encoder.cc index dbb96251..a0c3ecab 100644 --- a/src/parser/cxx/external_name_encoder.cc +++ b/src/parser/cxx/external_name_encoder.cc @@ -329,6 +329,31 @@ struct ExternalNameEncoder::EncodeUnqualifiedName { ExternalNameEncoder& encoder; Symbol* symbol = nullptr; + void encodeTemplateArguments(Symbol* symbol) { + if (!symbol) return; + + std::span args; + + if (auto classSymbol = symbol_cast(symbol)) { + args = classSymbol->templateArguments(); + } + + if (args.empty()) return; + + encoder.out("I"); + + for (const auto& arg : args) { + if (auto sym = std::get_if(&arg)) { + auto type = (*sym)->type(); + encoder.encodeType(type); + } else { + cxx_runtime_error("template argument not supported yet"); + } + } + + encoder.out("E"); + } + void operator()(const Identifier* id) { if (auto function = symbol_cast(symbol)) { if (function->isConstructor()) { @@ -338,6 +363,7 @@ struct ExternalNameEncoder::EncodeUnqualifiedName { } out(std::format("{}{}", id->name().length(), id->name())); + encodeTemplateArguments(symbol); } void operator()(const OperatorId* name) { diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index b1387b5c..71e2b2a6 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -1056,7 +1056,6 @@ auto Parser::parse_template_nested_name_specifier( unit, templateId->templateArgumentList, classSymbol); templateId->symbol = instance; - ast->symbol = instance; } else if (auto typeAliasSymbol = symbol_cast(templateId->symbol)) { @@ -5314,8 +5313,7 @@ void Parser::check_type_traits() { auto Parser::is_template(Symbol* symbol) const -> bool { if (!symbol) return false; if (symbol->isTemplateTypeParameter()) return true; - auto templateParameters = cxx::getTemplateParameters(symbol); - return templateParameters != nullptr; + return symbol_cast(symbol->parent()); } auto Parser::evaluate_constant_expression(ExpressionAST* expr) @@ -7900,19 +7898,11 @@ auto Parser::parse_class_specifier(ClassSpecifierAST*& yyast, DeclSpecs& specs) List* attributeList = nullptr; NestedNameSpecifierAST* nestedNameSpecifier = nullptr; UnqualifiedIdAST* unqualifiedId = nullptr; - SimpleTemplateIdAST* templateId = nullptr; - const Identifier* className = nullptr; - ClassSymbol* symbol = nullptr; SourceLocation finalLoc; - bool isUnion = false; - bool isTemplateSpecialization = false; - SourceLocation location = classLoc; auto lookat_class_head = [&] { LookaheadParser lookahead{this}; - isUnion = unit->tokenKind(classLoc) == TokenKind::T_UNION; - parse_optional_attribute_specifier_seq(attributeList); parse_optional_nested_name_specifier( @@ -7921,23 +7911,19 @@ auto Parser::parse_class_specifier(ClassSpecifierAST*& yyast, DeclSpecs& specs) if (lookat(TokenKind::T_IDENTIFIER)) { check_type_traits(); - if (parse_simple_template_id(templateId)) { + if (SimpleTemplateIdAST* templateId = nullptr; + parse_simple_template_id(templateId)) { unqualifiedId = templateId; - className = templateId->identifier; - isTemplateSpecialization = true; - location = templateId->firstSourceLocation(); } else { NameIdAST* nameId = nullptr; (void)parse_name_id(nameId); unqualifiedId = nameId; - className = nameId->identifier; - location = nameId->firstSourceLocation(); } (void)parse_class_virt_specifier(finalLoc); } - if (nestedNameSpecifier && !className) { + if (nestedNameSpecifier && !unqualifiedId) { parse_error("expected class name"); } diff --git a/src/parser/cxx/symbols.cc b/src/parser/cxx/symbols.cc index 027ddbec..2c9e9e2f 100644 --- a/src/parser/cxx/symbols.cc +++ b/src/parser/cxx/symbols.cc @@ -67,6 +67,10 @@ auto Symbol::EnclosingSymbolIterator::operator++(int) return it; } +auto Symbol::templateParameters() -> TemplateParametersSymbol* { + return symbol_cast(parent()); +} + auto Symbol::hasEnclosingSymbol(Symbol* symbol) const -> bool { for (auto enclosingSymbol : enclosingSymbols()) { if (enclosingSymbol == symbol) return true; @@ -296,15 +300,6 @@ ConceptSymbol::ConceptSymbol(ScopeSymbol* enclosingScope) ConceptSymbol::~ConceptSymbol() {} -auto ConceptSymbol::templateParameters() const -> TemplateParametersSymbol* { - return templateParameters_; -} - -void ConceptSymbol::setTemplateParameters( - TemplateParametersSymbol* templateParameters) { - templateParameters_ = templateParameters; -} - BaseClassSymbol::BaseClassSymbol(ScopeSymbol* enclosingScope) : Symbol(Kind, enclosingScope) {} @@ -419,19 +414,6 @@ void ClassSymbol::setTemplateDeclaration( templateDeclaration_ = templateDeclaration; } -auto ClassSymbol::templateParameters() const -> TemplateParametersSymbol* { - return templateInfo_ ? templateInfo_->templateParameters() : nullptr; -} - -void ClassSymbol::setTemplateParameters( - TemplateParametersSymbol* templateParameters) { - if (templateInfo_) { - cxx_runtime_error("symbol already has template parameters"); - } - templateInfo_ = - std::make_unique>(this, templateParameters); -} - auto ClassSymbol::specializations() const -> std::span> { if (!templateInfo_) return {}; @@ -440,11 +422,15 @@ auto ClassSymbol::specializations() const auto ClassSymbol::findSpecialization( const std::vector& arguments) const -> ClassSymbol* { + if (!templateInfo_) return {}; return templateInfo_->findSpecialization(arguments); } void ClassSymbol::addSpecialization(std::vector arguments, ClassSymbol* specialization) { + if (!templateInfo_) { + templateInfo_ = std::make_unique>(this); + } auto index = templateInfo_->specializations().size(); specialization->setSpecializationInfo(this, index); templateInfo_->addSpecialization(std::move(arguments), specialization); @@ -565,15 +551,6 @@ FunctionSymbol::FunctionSymbol(ScopeSymbol* enclosingScope) FunctionSymbol::~FunctionSymbol() {} -auto FunctionSymbol::templateParameters() const -> TemplateParametersSymbol* { - return templateParameters_; -} - -void FunctionSymbol::setTemplateParameters( - TemplateParametersSymbol* templateParameters) { - templateParameters_ = templateParameters; -} - auto FunctionSymbol::declaration() const -> DeclarationAST* { return declaration_; } @@ -681,15 +658,6 @@ LambdaSymbol::LambdaSymbol(ScopeSymbol* enclosingScope) LambdaSymbol::~LambdaSymbol() {} -auto LambdaSymbol::templateParameters() const -> TemplateParametersSymbol* { - return templateParameters_; -} - -void LambdaSymbol::setTemplateParameters( - TemplateParametersSymbol* templateParameters) { - templateParameters_ = templateParameters; -} - auto LambdaSymbol::isConstexpr() const -> bool { return isConstexpr_; } void LambdaSymbol::setConstexpr(bool isConstexpr) { @@ -730,15 +698,6 @@ TypeAliasSymbol::TypeAliasSymbol(ScopeSymbol* enclosingScope) TypeAliasSymbol::~TypeAliasSymbol() {} -auto TypeAliasSymbol::templateParameters() const -> TemplateParametersSymbol* { - return templateParameters_; -} - -void TypeAliasSymbol::setTemplateParameters( - TemplateParametersSymbol* templateParameters) { - templateParameters_ = templateParameters; -} - auto TypeAliasSymbol::templateDeclaration() const -> TemplateDeclarationAST* { return templateDeclaration_; } @@ -753,15 +712,6 @@ VariableSymbol::VariableSymbol(ScopeSymbol* enclosingScope) VariableSymbol::~VariableSymbol() {} -auto VariableSymbol::templateParameters() const -> TemplateParametersSymbol* { - return templateParameters_; -} - -void VariableSymbol::setTemplateParameters( - TemplateParametersSymbol* templateParameters) { - templateParameters_ = templateParameters; -} - auto VariableSymbol::isStatic() const -> bool { return isStatic_; } void VariableSymbol::setStatic(bool isStatic) { isStatic_ = isStatic; } diff --git a/src/parser/cxx/symbols.h b/src/parser/cxx/symbols.h index b2957dd1..a09b86c9 100644 --- a/src/parser/cxx/symbols.h +++ b/src/parser/cxx/symbols.h @@ -55,17 +55,7 @@ struct TemplateSpecialization { template class TemplateInfo { public: - TemplateInfo(S* templateSymbol, TemplateParametersSymbol* templateParameters) - : templateSymbol_(templateSymbol), - templateParameters_(templateParameters) {} - - [[nodiscard]] auto templateParameters() const -> TemplateParametersSymbol* { - return templateParameters_; - } - - void setTemplateParameters(TemplateParametersSymbol* templateParameters) { - templateParameters_ = templateParameters; - } + explicit TemplateInfo(S* templateSymbol) : templateSymbol_(templateSymbol) {} [[nodiscard]] auto specializations() const -> std::span> { @@ -94,7 +84,6 @@ class TemplateInfo { private: S* templateSymbol_ = nullptr; - TemplateParametersSymbol* templateParameters_ = nullptr; std::vector> specializations_; }; @@ -149,6 +138,8 @@ class Symbol { EnclosingSymbolIterator{}); } + [[nodiscard]] auto templateParameters() -> TemplateParametersSymbol*; + [[nodiscard]] auto hasEnclosingSymbol(Symbol* symbol) const -> bool; [[nodiscard]] auto next() const -> Symbol*; @@ -247,11 +238,7 @@ class ConceptSymbol final : public Symbol { explicit ConceptSymbol(ScopeSymbol* enclosingScope); ~ConceptSymbol() override; - [[nodiscard]] auto templateParameters() const -> TemplateParametersSymbol*; - void setTemplateParameters(TemplateParametersSymbol* templateParameters); - private: - TemplateParametersSymbol* templateParameters_ = nullptr; }; class BaseClassSymbol final : public Symbol { @@ -324,9 +311,6 @@ class ClassSymbol final : public ScopeSymbol { [[nodiscard]] auto templateDeclaration() const -> TemplateDeclarationAST*; void setTemplateDeclaration(TemplateDeclarationAST* templateDeclaration); - [[nodiscard]] auto templateParameters() const -> TemplateParametersSymbol*; - void setTemplateParameters(TemplateParametersSymbol* templateParameters); - [[nodiscard]] auto specializations() const -> std::span>; @@ -428,9 +412,6 @@ class FunctionSymbol final : public ScopeSymbol { explicit FunctionSymbol(ScopeSymbol* enclosingScope); ~FunctionSymbol() override; - [[nodiscard]] auto templateParameters() const -> TemplateParametersSymbol*; - void setTemplateParameters(TemplateParametersSymbol* templateParameters); - [[nodiscard]] auto isDefined() const -> bool; void setDefined(bool isDefined); @@ -474,7 +455,6 @@ class FunctionSymbol final : public ScopeSymbol { void setDeclaration(DeclarationAST* declaration); private: - TemplateParametersSymbol* templateParameters_ = nullptr; DeclarationAST* declaration_ = nullptr; union { @@ -519,9 +499,6 @@ class LambdaSymbol final : public ScopeSymbol { explicit LambdaSymbol(ScopeSymbol* enclosingScope); ~LambdaSymbol() override; - [[nodiscard]] auto templateParameters() const -> TemplateParametersSymbol*; - void setTemplateParameters(TemplateParametersSymbol* templateParameters); - [[nodiscard]] auto isConstexpr() const -> bool; void setConstexpr(bool isConstexpr); @@ -535,8 +512,6 @@ class LambdaSymbol final : public ScopeSymbol { void setStatic(bool isStatic); private: - TemplateParametersSymbol* templateParameters_ = nullptr; - union { std::uint32_t flags_{}; struct { @@ -579,14 +554,10 @@ class TypeAliasSymbol final : public Symbol { explicit TypeAliasSymbol(ScopeSymbol* enclosingScope); ~TypeAliasSymbol() override; - [[nodiscard]] auto templateParameters() const -> TemplateParametersSymbol*; - void setTemplateParameters(TemplateParametersSymbol* templateParameters); - [[nodiscard]] auto templateDeclaration() const -> TemplateDeclarationAST*; void setTemplateDeclaration(TemplateDeclarationAST* declaration); private: - TemplateParametersSymbol* templateParameters_ = nullptr; TemplateDeclarationAST* templateDeclaration_ = nullptr; }; @@ -597,9 +568,6 @@ class VariableSymbol final : public Symbol { explicit VariableSymbol(ScopeSymbol* enclosingScope); ~VariableSymbol() override; - [[nodiscard]] auto templateParameters() const -> TemplateParametersSymbol*; - void setTemplateParameters(TemplateParametersSymbol* templateParameters); - [[nodiscard]] auto isStatic() const -> bool; void setStatic(bool isStatic); @@ -628,7 +596,6 @@ class VariableSymbol final : public Symbol { void setConstValue(std::optional value); private: - TemplateParametersSymbol* templateParameters_ = nullptr; TemplateDeclarationAST* templateDeclaration_ = nullptr; ExpressionAST* initializer_ = nullptr; std::optional constValue_; @@ -863,47 +830,4 @@ inline auto symbol_cast(Symbol* symbol) -> ScopeSymbol* { return nullptr; } -struct GetTemplateParameters { - auto operator()(Symbol* symbol) const -> TemplateParametersSymbol* { - if (!symbol) return nullptr; - return visit(Visitor{*this}, symbol); - } - - private: - struct Visitor { - const GetTemplateParameters& getTemplateParameters; - - auto operator()(ConceptSymbol* symbol) const -> TemplateParametersSymbol* { - return symbol->templateParameters(); - } - - auto operator()(ClassSymbol* symbol) const -> TemplateParametersSymbol* { - return symbol->templateParameters(); - } - - auto operator()(FunctionSymbol* symbol) const -> TemplateParametersSymbol* { - return symbol->templateParameters(); - } - - auto operator()(LambdaSymbol* symbol) const -> TemplateParametersSymbol* { - return symbol->templateParameters(); - } - - auto operator()(TypeAliasSymbol* symbol) const - -> TemplateParametersSymbol* { - return symbol->templateParameters(); - } - - auto operator()(VariableSymbol* symbol) const -> TemplateParametersSymbol* { - return symbol->templateParameters(); - } - - auto operator()(auto symbol) const -> TemplateParametersSymbol* { - return nullptr; - } - }; -}; - -inline constexpr auto getTemplateParameters = GetTemplateParameters{}; - } // namespace cxx