diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/Decl.cpp | 87 | ||||
-rw-r--r-- | lib/AST/DeclBase.cpp | 147 | ||||
-rw-r--r-- | lib/AST/DeclCXX.cpp | 15 | ||||
-rw-r--r-- | lib/AST/DeclTemplate.cpp | 28 |
4 files changed, 58 insertions, 219 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 7d4b461f5a..56db8c7e33 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -601,30 +601,6 @@ static void clearLinkageForClass(const CXXRecordDecl *record) { } } -void NamedDecl::getNameForDiagnostic(std::string &S, - const PrintingPolicy &Policy, - bool Qualified) const { - if (Qualified) - S += getQualifiedNameAsString(Policy); - else - S += getNameAsString(); - - const TemplateArgumentList *TemplateArgs = 0; - - if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) - TemplateArgs = FD->getTemplateSpecializationArgs(); - else if (const ClassTemplateSpecializationDecl *Spec - = dyn_cast<ClassTemplateSpecializationDecl>(this)) - TemplateArgs = &Spec->getTemplateArgs(); - - - if (TemplateArgs) - S += TemplateSpecializationType::PrintTemplateArgumentList( - TemplateArgs->data(), - TemplateArgs->size(), - Policy); -} - void NamedDecl::ClearLinkageCache() { // Note that we can't skip clearing the linkage of children just // because the parent doesn't have cached linkage: we don't cache @@ -981,20 +957,6 @@ void DeclaratorDecl::setQualifierInfo(NestedNameSpecifier *Qualifier, } } -SourceLocation DeclaratorDecl::getInnerLocStart() const { - if (const VarDecl *Var = dyn_cast<VarDecl>(this)) { - SourceLocation Start = Var->getTypeSpecStartLoc(); - if (Start.isValid()) - return Start; - } else if (const NonTypeTemplateParmDecl *NTTP - = dyn_cast<NonTypeTemplateParmDecl>(this)) { - SourceLocation Start = NTTP->getTypeSpecStartLoc(); - if (Start.isValid()) - return Start; - } - return getLocation(); -} - SourceLocation DeclaratorDecl::getOuterLocStart() const { return getTemplateOrInnerLocStart(this); } @@ -1055,6 +1017,13 @@ void VarDecl::setStorageClass(StorageClass SC) { SClass = SC; } +SourceLocation VarDecl::getInnerLocStart() const { + SourceLocation Start = getTypeSpecStartLoc(); + if (Start.isInvalid()) + Start = getLocation(); + return Start; +} + SourceRange VarDecl::getSourceRange() const { if (getInit()) return SourceRange(getOuterLocStart(), getInit()->getLocEnd()); @@ -1202,7 +1171,7 @@ const Expr *VarDecl::getAnyInitializer(const VarDecl *&D) const { } bool VarDecl::isOutOfLine() const { - if (getLexicalDeclContext() != getDeclContext()) + if (Decl::isOutOfLine()) return true; if (!isStaticDataMember()) @@ -1326,6 +1295,19 @@ bool ParmVarDecl::isParameterPack() const { // FunctionDecl Implementation //===----------------------------------------------------------------------===// +void FunctionDecl::getNameForDiagnostic(std::string &S, + const PrintingPolicy &Policy, + bool Qualified) const { + NamedDecl::getNameForDiagnostic(S, Policy, Qualified); + const TemplateArgumentList *TemplateArgs = getTemplateSpecializationArgs(); + if (TemplateArgs) + S += TemplateSpecializationType::PrintTemplateArgumentList( + TemplateArgs->data(), + TemplateArgs->size(), + Policy); + +} + bool FunctionDecl::isVariadic() const { if (const FunctionProtoType *FT = getType()->getAs<FunctionProtoType>()) return FT->isVariadic(); @@ -1913,7 +1895,7 @@ SourceLocation FunctionDecl::getPointOfInstantiation() const { } bool FunctionDecl::isOutOfLine() const { - if (getLexicalDeclContext() != getDeclContext()) + if (Decl::isOutOfLine()) return true; // If this function was instantiated from a member function of a @@ -1978,17 +1960,6 @@ unsigned FieldDecl::getFieldIndex() const { // TagDecl Implementation //===----------------------------------------------------------------------===// -SourceLocation TagDecl::getInnerLocStart() const { - if (const ClassTemplateSpecializationDecl *Spec - = dyn_cast<ClassTemplateSpecializationDecl>(this)) { - SourceLocation Start = Spec->getTemplateKeywordLoc(); - if (Start.isValid()) - return Start; - } - - return getTagKeywordLoc(); -} - SourceLocation TagDecl::getOuterLocStart() const { return getTemplateOrInnerLocStart(this); } @@ -2140,6 +2111,13 @@ RecordDecl::field_iterator RecordDecl::field_begin() const { return field_iterator(decl_iterator(FirstDecl)); } +/// completeDefinition - Notes that the definition of this type is now +/// complete. +void RecordDecl::completeDefinition() { + assert(!isDefinition() && "Cannot redefine record!"); + TagDecl::completeDefinition(); +} + void RecordDecl::LoadFieldsFromExternalStorage() const { ExternalASTSource *Source = getASTContext().getExternalSource(); assert(hasExternalLexicalStorage() && Source && "No external storage?"); @@ -2165,13 +2143,6 @@ void RecordDecl::LoadFieldsFromExternalStorage() const { llvm::tie(FirstDecl, LastDecl) = BuildDeclChain(Decls); } -void RecordDecl::completeDefinition() { - assert(!isDefinition() && "Cannot redefine record!"); - TagDecl::completeDefinition(); - if (CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(this)) - CXXRecord->completeDefinitionImpl(0); -} - //===----------------------------------------------------------------------===// // BlockDecl Implementation //===----------------------------------------------------------------------===// diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index be4d82a054..be379d522d 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -42,30 +42,6 @@ using namespace clang; static bool StatSwitch = false; -namespace { - template<typename Class> - inline SourceRange getSourceRangeImpl(const Decl *D, - SourceRange (Class::*)() const) { - return static_cast<const Class *>(D)->getSourceRange(); - } - - inline SourceRange getSourceRangeImpl(const Decl *D, - SourceRange (Decl::*)() const) { - return D->getLocation(); - } -} - -SourceRange Decl::getSourceRange() const { - switch (getKind()) { -#define ABSTRACT_DECL(Type) -#define DECL(Type, Base) \ - case Type: return getSourceRangeImpl(this, &Type##Decl::getSourceRange); -#include "clang/AST/DeclNodes.inc" - } - - return getLocation(); -} - const char *Decl::getDeclKindName() const { switch (DeclKind) { default: assert(0 && "Declaration not in DeclNodes.inc!"); @@ -167,101 +143,6 @@ bool Decl::isDefinedOutsideFunctionOrMethod() const { return true; } -namespace { - template<typename Class, typename Result> - inline Result *getCanonicalDeclImpl(Decl *D, Result *(Class::*)()) { - return static_cast<Class *>(D)->getCanonicalDecl(); - } - - inline Decl *getCanonicalDeclImpl(Decl *D, Decl *(Decl::*)()) { - // No specific implementation. - return D; - } -} - -Decl *Decl::getCanonicalDecl() { - switch (getKind()) { -#define ABSTRACT_DECL(Type) -#define DECL(Type, Base) \ - case Type: \ - return getCanonicalDeclImpl(this, &Type##Decl::getCanonicalDecl); -#include "clang/AST/DeclNodes.inc" - } - - return this; -} - -Decl *Decl::getNextRedeclaration() { - switch (getKind()) { - case Var: - return static_cast<VarDecl *>(this)->getNextRedeclaration(); - - case Function: - case CXXMethod: - case CXXConstructor: - case CXXDestructor: - case CXXConversion: - return static_cast<FunctionDecl *>(this)->getNextRedeclaration(); - - case Typedef: - return static_cast<TypedefDecl *>(this)->getNextRedeclaration(); - - case Enum: - case Record: - case CXXRecord: - case ClassTemplateSpecialization: - case ClassTemplatePartialSpecialization: - return static_cast<TagDecl *>(this)->getNextRedeclaration(); - - case ObjCMethod: - return static_cast<ObjCMethodDecl *>(this)->getNextRedeclaration(); - - case FunctionTemplate: - case ClassTemplate: - return static_cast<RedeclarableTemplateDecl *>(this) - ->getNextRedeclaration(); - - case Namespace: - case UsingDirective: - case NamespaceAlias: - case Label: - case UnresolvedUsingTypename: - case TemplateTypeParm: - case EnumConstant: - case UnresolvedUsingValue: - case IndirectField: - case Field: - case ObjCIvar: - case ObjCAtDefsField: - case ImplicitParam: - case ParmVar: - case NonTypeTemplateParm: - case TemplateTemplateParm: - case Using: - case UsingShadow: - case ObjCCategory: - case ObjCProtocol: - case ObjCInterface: - case ObjCCategoryImpl: - case ObjCImplementation: - case ObjCProperty: - case ObjCCompatibleAlias: - case LinkageSpec: - case ObjCPropertyImpl: - case ObjCForwardProtocol: - case ObjCClass: - case FileScopeAsm: - case AccessSpec: - case Friend: - case FriendTemplate: - case StaticAssert: - case Block: - case TranslationUnit: - return this; - } - - return this; -} //===----------------------------------------------------------------------===// // PrettyStackTraceDecl Implementation @@ -288,14 +169,8 @@ void PrettyStackTraceDecl::print(llvm::raw_ostream &OS) const { // Decl Implementation //===----------------------------------------------------------------------===// -bool Decl::isOutOfLine() const { - if (const VarDecl *VD = dyn_cast<VarDecl>(this)) - return VD->isOutOfLine(); - if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) - return FD->isOutOfLine(); - - return getLexicalDeclContext() != getDeclContext(); -} +// Out-of-line virtual method providing a home for Decl. +Decl::~Decl() { } void Decl::setDeclContext(DeclContext *DC) { if (isOutOfSemaDC()) @@ -546,24 +421,6 @@ DeclContext *Decl::castToDeclContext(const Decl *D) { } } -Stmt *Decl::getBody() const { - if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) - return FD->getBody(); - if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(this)) - return MD->getBody(); - if (const BlockDecl *BD = dyn_cast<BlockDecl>(this)) - return BD->getBody(); - - return 0; -} - -bool Decl::hasBody() const { - if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) - return FD->hasBody(); - - return getBody() != 0; -} - SourceLocation Decl::getBodyRBrace() const { // Special handling of FunctionDecl to avoid de-serializing the body from PCH. // FunctionDecl stores EndRangeLoc for this purpose. diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 1de3cc989e..fba73f59d5 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -819,8 +819,13 @@ CXXDestructorDecl *CXXRecordDecl::getDestructor() const { return Dtor; } -void -CXXRecordDecl::completeDefinitionImpl(CXXFinalOverriderMap *FinalOverriders) { +void CXXRecordDecl::completeDefinition() { + completeDefinition(0); +} + +void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) { + RecordDecl::completeDefinition(); + // If the class may be abstract (but hasn't been marked as such), check for // any pure final overriders. if (mayBeAbstract()) { @@ -860,12 +865,6 @@ CXXRecordDecl::completeDefinitionImpl(CXXFinalOverriderMap *FinalOverriders) { data().Conversions.setAccess(I, (*I)->getAccess()); } -void -CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) { - TagDecl::completeDefinition(); - completeDefinitionImpl(FinalOverriders); -} - bool CXXRecordDecl::mayBeAbstract() const { if (data().Abstract || isInvalidDecl() || !data().Polymorphic || isDependentContext()) diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index 980a373778..a73deeab3a 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -112,14 +112,6 @@ RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() { } -RedeclarableTemplateDecl::CommonBase * -RedeclarableTemplateDecl::newCommon(ASTContext &C) { - if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(this)) - return FunTmpl->newCommon(C); - - return cast<ClassTemplateDecl>(this)->newCommon(C); -} - RedeclarableTemplateDecl *RedeclarableTemplateDecl::getCanonicalDeclImpl() { RedeclarableTemplateDecl *Tmpl = this; while (Tmpl->getPreviousDeclaration()) @@ -455,6 +447,13 @@ NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, ExpandedTInfos); } +SourceLocation NonTypeTemplateParmDecl::getInnerLocStart() const { + SourceLocation Start = getTypeSpecStartLoc(); + if (Start.isInvalid()) + Start = getLocation(); + return Start; +} + SourceRange NonTypeTemplateParmDecl::getSourceRange() const { return SourceRange(getOuterLocStart(), getLocation()); } @@ -544,6 +543,19 @@ ClassTemplateSpecializationDecl::Create(ASTContext &Context, EmptyShell Empty) { new (Context)ClassTemplateSpecializationDecl(ClassTemplateSpecialization); } +void +ClassTemplateSpecializationDecl::getNameForDiagnostic(std::string &S, + const PrintingPolicy &Policy, + bool Qualified) const { + NamedDecl::getNameForDiagnostic(S, Policy, Qualified); + + const TemplateArgumentList &TemplateArgs = getTemplateArgs(); + S += TemplateSpecializationType::PrintTemplateArgumentList( + TemplateArgs.data(), + TemplateArgs.size(), + Policy); +} + ClassTemplateDecl * ClassTemplateSpecializationDecl::getSpecializedTemplate() const { if (SpecializedPartialSpecialization *PartialSpec |