Remove ASTContext::getCanonicalDecl() and use Decl::getCanonicalDecl in its place.

llvm-svn: 76274
This commit is contained in:
Argyrios Kyrtzidis 2009-07-18 00:34:25 +00:00
parent 5614aef776
commit 6b7e376160
9 changed files with 30 additions and 45 deletions

View File

@ -643,19 +643,6 @@ public:
return T1.getUnqualifiedType() == T2.getUnqualifiedType(); 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<TagDecl>(getCanonicalDecl((Decl *)Tag));
}
/// \brief Retrieves the "canonical" declaration of /// \brief Retrieves the "canonical" declaration of
/// \brief Retrieves the "canonical" nested name specifier for a /// \brief Retrieves the "canonical" nested name specifier for a

View File

@ -2082,17 +2082,11 @@ QualType ASTContext::getCanonicalType(QualType T) {
VAT->getBracketsRange()); VAT->getBracketsRange());
} }
Decl *ASTContext::getCanonicalDecl(Decl *D) {
if (!D)
return 0;
return D->getCanonicalDecl();
}
TemplateName ASTContext::getCanonicalTemplateName(TemplateName Name) { TemplateName ASTContext::getCanonicalTemplateName(TemplateName Name) {
// If this template name refers to a template, the canonical // If this template name refers to a template, the canonical
// template name merely stores the template itself. // template name merely stores the template itself.
if (TemplateDecl *Template = Name.getAsTemplateDecl()) if (TemplateDecl *Template = Name.getAsTemplateDecl())
return TemplateName(cast<TemplateDecl>(getCanonicalDecl(Template))); return TemplateName(cast<TemplateDecl>(Template->getCanonicalDecl()));
DependentTemplateName *DTN = Name.getAsDependentTemplateName(); DependentTemplateName *DTN = Name.getAsDependentTemplateName();
assert(DTN && "Non-dependent template names must refer to template decls."); assert(DTN && "Non-dependent template names must refer to template decls.");

View File

@ -200,7 +200,7 @@ QualType ClassTemplateDecl::getInjectedClassNameType(ASTContext &Context) {
TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*Param); TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*Param);
TemplateArgs.push_back(TemplateArgument(TTP->getLocation(), TTP)); TemplateArgs.push_back(TemplateArgument(TTP->getLocation(), TTP));
CanonTemplateArgs.push_back(TemplateArgument(TTP->getLocation(), CanonTemplateArgs.push_back(TemplateArgument(TTP->getLocation(),
Context.getCanonicalDecl(TTP))); TTP->getCanonicalDecl()));
} }
} }

View File

@ -217,7 +217,7 @@ MergeLookupResults(ASTContext &Context, LookupResultsTy &Results) {
NamedDecl *ND = I->getAsDecl()->getUnderlyingDecl(); NamedDecl *ND = I->getAsDecl()->getUnderlyingDecl();
if (TagDecl *TD = dyn_cast<TagDecl>(ND)) { if (TagDecl *TD = dyn_cast<TagDecl>(ND)) {
TagFound = Context.getCanonicalDecl(TD); TagFound = TD->getCanonicalDecl();
TagNames += FoundDecls.insert(TagFound)? 1 : 0; TagNames += FoundDecls.insert(TagFound)? 1 : 0;
} else if (ND->isFunctionOrFunctionTemplate()) } else if (ND->isFunctionOrFunctionTemplate())
Functions += FoundDecls.insert(ND)? 1 : 0; Functions += FoundDecls.insert(ND)? 1 : 0;

View File

@ -3764,7 +3764,7 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
assert(FunctionType assert(FunctionType
== Context.getCanonicalType(Specialization->getType())); == Context.getCanonicalType(Specialization->getType()));
Matches.insert( Matches.insert(
cast<FunctionDecl>(Context.getCanonicalDecl(Specialization))); cast<FunctionDecl>(Specialization->getCanonicalDecl()));
} }
} }
@ -3778,7 +3778,7 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
if (FunctionDecl *FunDecl = dyn_cast<FunctionDecl>(*Fun)) { if (FunctionDecl *FunDecl = dyn_cast<FunctionDecl>(*Fun)) {
if (FunctionType == Context.getCanonicalType(FunDecl->getType())) { if (FunctionType == Context.getCanonicalType(FunDecl->getType())) {
Matches.insert(cast<FunctionDecl>(Context.getCanonicalDecl(*Fun))); Matches.insert(cast<FunctionDecl>(Fun->getCanonicalDecl()));
FoundNonTemplateFunction = true; FoundNonTemplateFunction = true;
} }
} }

View File

@ -56,7 +56,7 @@ TemplateNameKind Sema::isTemplateName(const IdentifierInfo &II, Scope *S,
// which could be the current specialization or another // which could be the current specialization or another
// specialization. // specialization.
if (Record->isInjectedClassName()) { if (Record->isInjectedClassName()) {
Record = cast<CXXRecordDecl>(Context.getCanonicalDecl(Record)); Record = cast<CXXRecordDecl>(Record->getCanonicalDecl());
if ((Template = Record->getDescribedClassTemplate())) if ((Template = Record->getDescribedClassTemplate()))
TNK = TNK_Type_template; TNK = TNK_Type_template;
else if (ClassTemplateSpecializationDecl *Spec else if (ClassTemplateSpecializationDecl *Spec
@ -795,7 +795,7 @@ static void CanonicalizeTemplateArguments(const TemplateArgument *TemplateArgs,
case TemplateArgument::Declaration: case TemplateArgument::Declaration:
Canonical.push_back( Canonical.push_back(
TemplateArgument(SourceLocation(), TemplateArgument(SourceLocation(),
Context.getCanonicalDecl(TemplateArgs[Idx].getAsDecl()))); TemplateArgs[Idx].getAsDecl()->getCanonicalDecl()));
break; break;
case TemplateArgument::Integral: case TemplateArgument::Integral:
@ -1278,7 +1278,7 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template,
// Add the converted template argument. // Add the converted template argument.
Decl *D Decl *D
= Context.getCanonicalDecl(cast<DeclRefExpr>(ArgExpr)->getDecl()); = cast<DeclRefExpr>(ArgExpr)->getDecl()->getCanonicalDecl();
Converted.Append(TemplateArgument(Arg.getLocation(), D)); Converted.Append(TemplateArgument(Arg.getLocation(), D));
continue; continue;
} }
@ -1702,7 +1702,8 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
if (CheckTemplateArgumentPointerToMember(Arg, Member)) if (CheckTemplateArgumentPointerToMember(Arg, Member))
return true; return true;
Member = cast_or_null<NamedDecl>(Context.getCanonicalDecl(Member)); if (Member)
Member = cast<NamedDecl>(Member->getCanonicalDecl());
Converted = TemplateArgument(StartLoc, Member); Converted = TemplateArgument(StartLoc, Member);
return false; return false;
} }
@ -1711,7 +1712,8 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
if (CheckTemplateArgumentAddressOfObjectOrFunction(Arg, Entity)) if (CheckTemplateArgumentAddressOfObjectOrFunction(Arg, Entity))
return true; return true;
Entity = cast_or_null<NamedDecl>(Context.getCanonicalDecl(Entity)); if (Entity)
Entity = cast<NamedDecl>(Entity->getCanonicalDecl());
Converted = TemplateArgument(StartLoc, Entity); Converted = TemplateArgument(StartLoc, Entity);
return false; return false;
} }
@ -1750,7 +1752,8 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
if (CheckTemplateArgumentAddressOfObjectOrFunction(Arg, Entity)) if (CheckTemplateArgumentAddressOfObjectOrFunction(Arg, Entity))
return true; return true;
Entity = cast_or_null<NamedDecl>(Context.getCanonicalDecl(Entity)); if (Entity)
Entity = cast<NamedDecl>(Entity->getCanonicalDecl());
Converted = TemplateArgument(StartLoc, Entity); Converted = TemplateArgument(StartLoc, Entity);
return false; return false;
} }
@ -1791,7 +1794,7 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
if (CheckTemplateArgumentAddressOfObjectOrFunction(Arg, Entity)) if (CheckTemplateArgumentAddressOfObjectOrFunction(Arg, Entity))
return true; return true;
Entity = cast<NamedDecl>(Context.getCanonicalDecl(Entity)); Entity = cast<NamedDecl>(Entity->getCanonicalDecl());
Converted = TemplateArgument(StartLoc, Entity); Converted = TemplateArgument(StartLoc, Entity);
return false; return false;
} }
@ -1820,7 +1823,8 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
if (CheckTemplateArgumentPointerToMember(Arg, Member)) if (CheckTemplateArgumentPointerToMember(Arg, Member))
return true; return true;
Member = cast_or_null<NamedDecl>(Context.getCanonicalDecl(Member)); if (Member)
Member = cast<NamedDecl>(Member->getCanonicalDecl());
Converted = TemplateArgument(StartLoc, Member); Converted = TemplateArgument(StartLoc, Member);
return false; return false;
} }

View File

@ -170,8 +170,8 @@ DeduceTemplateArguments(ASTContext &Context,
return Sema::TDK_Inconsistent; return Sema::TDK_Inconsistent;
} }
ParamDecl = cast<TemplateDecl>(Context.getCanonicalDecl(ParamDecl)); ParamDecl = cast<TemplateDecl>(ParamDecl->getCanonicalDecl());
ArgDecl = cast<TemplateDecl>(Context.getCanonicalDecl(ArgDecl)); ArgDecl = cast<TemplateDecl>(ArgDecl->getCanonicalDecl());
if (ParamDecl != ArgDecl) { if (ParamDecl != ArgDecl) {
// FIXME: fill in Info.Param/Info.FirstArg // FIXME: fill in Info.Param/Info.FirstArg
return Sema::TDK_Inconsistent; return Sema::TDK_Inconsistent;
@ -799,8 +799,8 @@ static bool isSameTemplateArg(ASTContext &Context,
Context.getCanonicalType(Y.getAsType()); Context.getCanonicalType(Y.getAsType());
case TemplateArgument::Declaration: case TemplateArgument::Declaration:
return Context.getCanonicalDecl(X.getAsDecl()) == return X.getAsDecl()->getCanonicalDecl() ==
Context.getCanonicalDecl(Y.getAsDecl()); Y.getAsDecl()->getCanonicalDecl();
case TemplateArgument::Integral: case TemplateArgument::Integral:
return *X.getAsIntegral() == *Y.getAsIntegral(); return *X.getAsIntegral() == *Y.getAsIntegral();

View File

@ -968,7 +968,7 @@ Sema::InstantiateClassTemplateSpecialization(
bool ExplicitInstantiation) { bool ExplicitInstantiation) {
// Perform the actual instantiation on the canonical declaration. // Perform the actual instantiation on the canonical declaration.
ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>( ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>(
Context.getCanonicalDecl(ClassTemplateSpec)); ClassTemplateSpec->getCanonicalDecl());
// We can only instantiate something that hasn't already been // We can only instantiate something that hasn't already been
// instantiated or specialized. Fail without any diagnostics: our // instantiated or specialized. Fail without any diagnostics: our

View File

@ -781,16 +781,16 @@ static bool isInstantiationOf(ASTContext &Ctx, NamedDecl *D, Decl *Other) {
return false; return false;
if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Other)) if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Other))
return Ctx.getCanonicalDecl(Record->getInstantiatedFromMemberClass()) return Record->getInstantiatedFromMemberClass()->getCanonicalDecl()
== Ctx.getCanonicalDecl(D); == D->getCanonicalDecl();
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Other)) if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Other))
return Ctx.getCanonicalDecl(Function->getInstantiatedFromMemberFunction()) return Function->getInstantiatedFromMemberFunction()->getCanonicalDecl()
== Ctx.getCanonicalDecl(D); == D->getCanonicalDecl();
if (EnumDecl *Enum = dyn_cast<EnumDecl>(Other)) if (EnumDecl *Enum = dyn_cast<EnumDecl>(Other))
return Ctx.getCanonicalDecl(Enum->getInstantiatedFromMemberEnum()) return Enum->getInstantiatedFromMemberEnum()->getCanonicalDecl()
== Ctx.getCanonicalDecl(D); == D->getCanonicalDecl();
// FIXME: How can we find instantiations of anonymous unions? // FIXME: How can we find instantiations of anonymous unions?
@ -891,8 +891,8 @@ NamedDecl * Sema::InstantiateCurrentDeclRef(NamedDecl *D) {
DC = DC->getParent()) { DC = DC->getParent()) {
if (ClassTemplateSpecializationDecl *Spec if (ClassTemplateSpecializationDecl *Spec
= dyn_cast<ClassTemplateSpecializationDecl>(DC)) = dyn_cast<ClassTemplateSpecializationDecl>(DC))
if (Context.getCanonicalDecl(Spec->getSpecializedTemplate()) if (Spec->getSpecializedTemplate()->getCanonicalDecl()
== Context.getCanonicalDecl(ClassTemplate)) == ClassTemplate->getCanonicalDecl())
return Spec; return Spec;
} }