From 6b7e37616077495adc4f0fedccb7458b51817d66 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sat, 18 Jul 2009 00:34:25 +0000 Subject: [PATCH] Remove ASTContext::getCanonicalDecl() and use Decl::getCanonicalDecl in its place. llvm-svn: 76274 --- clang/include/clang/AST/ASTContext.h | 13 ------------ clang/lib/AST/ASTContext.cpp | 8 +------- clang/lib/AST/DeclTemplate.cpp | 2 +- clang/lib/Sema/SemaLookup.cpp | 2 +- clang/lib/Sema/SemaOverload.cpp | 4 ++-- clang/lib/Sema/SemaTemplate.cpp | 20 +++++++++++-------- clang/lib/Sema/SemaTemplateDeduction.cpp | 8 ++++---- clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 +- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 16 +++++++-------- 9 files changed, 30 insertions(+), 45 deletions(-) diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 19a4fbcdba20..6e4c1d6eaeea 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -643,19 +643,6 @@ public: return T1.getUnqualifiedType() == T2.getUnqualifiedType(); } - /// \brief Retrieves the "canonical" declaration of the given declaration. - Decl *getCanonicalDecl(Decl *D); - - /// \brief Retrieves the "canonical" declaration of the given tag - /// declaration. - /// - /// The canonical declaration for the given tag declaration is - /// either the definition of the tag (if it is a complete type) or - /// the first declaration of that tag. - TagDecl *getCanonicalDecl(TagDecl *Tag) { - return cast(getCanonicalDecl((Decl *)Tag)); - } - /// \brief Retrieves the "canonical" declaration of /// \brief Retrieves the "canonical" nested name specifier for a diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index f680606dcfee..046b27c9f320 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -2082,17 +2082,11 @@ QualType ASTContext::getCanonicalType(QualType T) { VAT->getBracketsRange()); } -Decl *ASTContext::getCanonicalDecl(Decl *D) { - if (!D) - return 0; - return D->getCanonicalDecl(); -} - TemplateName ASTContext::getCanonicalTemplateName(TemplateName Name) { // If this template name refers to a template, the canonical // template name merely stores the template itself. if (TemplateDecl *Template = Name.getAsTemplateDecl()) - return TemplateName(cast(getCanonicalDecl(Template))); + return TemplateName(cast(Template->getCanonicalDecl())); DependentTemplateName *DTN = Name.getAsDependentTemplateName(); assert(DTN && "Non-dependent template names must refer to template decls."); diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index e096e41aed2e..ce382dbdad6c 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -200,7 +200,7 @@ QualType ClassTemplateDecl::getInjectedClassNameType(ASTContext &Context) { TemplateTemplateParmDecl *TTP = cast(*Param); TemplateArgs.push_back(TemplateArgument(TTP->getLocation(), TTP)); CanonTemplateArgs.push_back(TemplateArgument(TTP->getLocation(), - Context.getCanonicalDecl(TTP))); + TTP->getCanonicalDecl())); } } diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index c88321e1a355..d9dea66f8257 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -217,7 +217,7 @@ MergeLookupResults(ASTContext &Context, LookupResultsTy &Results) { NamedDecl *ND = I->getAsDecl()->getUnderlyingDecl(); if (TagDecl *TD = dyn_cast(ND)) { - TagFound = Context.getCanonicalDecl(TD); + TagFound = TD->getCanonicalDecl(); TagNames += FoundDecls.insert(TagFound)? 1 : 0; } else if (ND->isFunctionOrFunctionTemplate()) Functions += FoundDecls.insert(ND)? 1 : 0; diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index d0d61c6ed1a0..503f226fd66c 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -3764,7 +3764,7 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType, assert(FunctionType == Context.getCanonicalType(Specialization->getType())); Matches.insert( - cast(Context.getCanonicalDecl(Specialization))); + cast(Specialization->getCanonicalDecl())); } } @@ -3778,7 +3778,7 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType, if (FunctionDecl *FunDecl = dyn_cast(*Fun)) { if (FunctionType == Context.getCanonicalType(FunDecl->getType())) { - Matches.insert(cast(Context.getCanonicalDecl(*Fun))); + Matches.insert(cast(Fun->getCanonicalDecl())); FoundNonTemplateFunction = true; } } diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 568d68c9a7e8..8fd9c58c8307 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -56,7 +56,7 @@ TemplateNameKind Sema::isTemplateName(const IdentifierInfo &II, Scope *S, // which could be the current specialization or another // specialization. if (Record->isInjectedClassName()) { - Record = cast(Context.getCanonicalDecl(Record)); + Record = cast(Record->getCanonicalDecl()); if ((Template = Record->getDescribedClassTemplate())) TNK = TNK_Type_template; else if (ClassTemplateSpecializationDecl *Spec @@ -795,7 +795,7 @@ static void CanonicalizeTemplateArguments(const TemplateArgument *TemplateArgs, case TemplateArgument::Declaration: Canonical.push_back( TemplateArgument(SourceLocation(), - Context.getCanonicalDecl(TemplateArgs[Idx].getAsDecl()))); + TemplateArgs[Idx].getAsDecl()->getCanonicalDecl())); break; case TemplateArgument::Integral: @@ -1278,7 +1278,7 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, // Add the converted template argument. Decl *D - = Context.getCanonicalDecl(cast(ArgExpr)->getDecl()); + = cast(ArgExpr)->getDecl()->getCanonicalDecl(); Converted.Append(TemplateArgument(Arg.getLocation(), D)); continue; } @@ -1702,7 +1702,8 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, if (CheckTemplateArgumentPointerToMember(Arg, Member)) return true; - Member = cast_or_null(Context.getCanonicalDecl(Member)); + if (Member) + Member = cast(Member->getCanonicalDecl()); Converted = TemplateArgument(StartLoc, Member); return false; } @@ -1711,7 +1712,8 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, if (CheckTemplateArgumentAddressOfObjectOrFunction(Arg, Entity)) return true; - Entity = cast_or_null(Context.getCanonicalDecl(Entity)); + if (Entity) + Entity = cast(Entity->getCanonicalDecl()); Converted = TemplateArgument(StartLoc, Entity); return false; } @@ -1750,7 +1752,8 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, if (CheckTemplateArgumentAddressOfObjectOrFunction(Arg, Entity)) return true; - Entity = cast_or_null(Context.getCanonicalDecl(Entity)); + if (Entity) + Entity = cast(Entity->getCanonicalDecl()); Converted = TemplateArgument(StartLoc, Entity); return false; } @@ -1791,7 +1794,7 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, if (CheckTemplateArgumentAddressOfObjectOrFunction(Arg, Entity)) return true; - Entity = cast(Context.getCanonicalDecl(Entity)); + Entity = cast(Entity->getCanonicalDecl()); Converted = TemplateArgument(StartLoc, Entity); return false; } @@ -1820,7 +1823,8 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, if (CheckTemplateArgumentPointerToMember(Arg, Member)) return true; - Member = cast_or_null(Context.getCanonicalDecl(Member)); + if (Member) + Member = cast(Member->getCanonicalDecl()); Converted = TemplateArgument(StartLoc, Member); return false; } diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index f6f9d105d95d..80e0da1adc1d 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -170,8 +170,8 @@ DeduceTemplateArguments(ASTContext &Context, return Sema::TDK_Inconsistent; } - ParamDecl = cast(Context.getCanonicalDecl(ParamDecl)); - ArgDecl = cast(Context.getCanonicalDecl(ArgDecl)); + ParamDecl = cast(ParamDecl->getCanonicalDecl()); + ArgDecl = cast(ArgDecl->getCanonicalDecl()); if (ParamDecl != ArgDecl) { // FIXME: fill in Info.Param/Info.FirstArg return Sema::TDK_Inconsistent; @@ -799,8 +799,8 @@ static bool isSameTemplateArg(ASTContext &Context, Context.getCanonicalType(Y.getAsType()); case TemplateArgument::Declaration: - return Context.getCanonicalDecl(X.getAsDecl()) == - Context.getCanonicalDecl(Y.getAsDecl()); + return X.getAsDecl()->getCanonicalDecl() == + Y.getAsDecl()->getCanonicalDecl(); case TemplateArgument::Integral: return *X.getAsIntegral() == *Y.getAsIntegral(); diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 6ee50ab98caf..c50faad58744 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -968,7 +968,7 @@ Sema::InstantiateClassTemplateSpecialization( bool ExplicitInstantiation) { // Perform the actual instantiation on the canonical declaration. ClassTemplateSpec = cast( - Context.getCanonicalDecl(ClassTemplateSpec)); + ClassTemplateSpec->getCanonicalDecl()); // We can only instantiate something that hasn't already been // instantiated or specialized. Fail without any diagnostics: our diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 8ff80af19030..49271893f93b 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -781,16 +781,16 @@ static bool isInstantiationOf(ASTContext &Ctx, NamedDecl *D, Decl *Other) { return false; if (CXXRecordDecl *Record = dyn_cast(Other)) - return Ctx.getCanonicalDecl(Record->getInstantiatedFromMemberClass()) - == Ctx.getCanonicalDecl(D); + return Record->getInstantiatedFromMemberClass()->getCanonicalDecl() + == D->getCanonicalDecl(); if (FunctionDecl *Function = dyn_cast(Other)) - return Ctx.getCanonicalDecl(Function->getInstantiatedFromMemberFunction()) - == Ctx.getCanonicalDecl(D); + return Function->getInstantiatedFromMemberFunction()->getCanonicalDecl() + == D->getCanonicalDecl(); if (EnumDecl *Enum = dyn_cast(Other)) - return Ctx.getCanonicalDecl(Enum->getInstantiatedFromMemberEnum()) - == Ctx.getCanonicalDecl(D); + return Enum->getInstantiatedFromMemberEnum()->getCanonicalDecl() + == D->getCanonicalDecl(); // FIXME: How can we find instantiations of anonymous unions? @@ -891,8 +891,8 @@ NamedDecl * Sema::InstantiateCurrentDeclRef(NamedDecl *D) { DC = DC->getParent()) { if (ClassTemplateSpecializationDecl *Spec = dyn_cast(DC)) - if (Context.getCanonicalDecl(Spec->getSpecializedTemplate()) - == Context.getCanonicalDecl(ClassTemplate)) + if (Spec->getSpecializedTemplate()->getCanonicalDecl() + == ClassTemplate->getCanonicalDecl()) return Spec; }