diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/AST/DeclPrinter.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/AST/DeclPrinter.cpp | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/contrib/llvm/tools/clang/lib/AST/DeclPrinter.cpp b/contrib/llvm/tools/clang/lib/AST/DeclPrinter.cpp index b792c5920a55..d3d9c23cca6e 100644 --- a/contrib/llvm/tools/clang/lib/AST/DeclPrinter.cpp +++ b/contrib/llvm/tools/clang/lib/AST/DeclPrinter.cpp @@ -128,9 +128,7 @@ static QualType GetBaseType(QualType T) { // FIXME: This should be on the Type class! QualType BaseType = T; while (!BaseType->isSpecifierType()) { - if (isa<TypedefType>(BaseType)) - break; - else if (const PointerType* PTy = BaseType->getAs<PointerType>()) + if (const PointerType *PTy = BaseType->getAs<PointerType>()) BaseType = PTy->getPointeeType(); else if (const BlockPointerType *BPy = BaseType->getAs<BlockPointerType>()) BaseType = BPy->getPointeeType(); @@ -144,8 +142,11 @@ static QualType GetBaseType(QualType T) { BaseType = RTy->getPointeeType(); else if (const AutoType *ATy = BaseType->getAs<AutoType>()) BaseType = ATy->getDeducedType(); + else if (const ParenType *PTy = BaseType->getAs<ParenType>()) + BaseType = PTy->desugar(); else - llvm_unreachable("Unknown declarator!"); + // This must be a syntax error. + break; } return BaseType; } @@ -214,6 +215,8 @@ void DeclPrinter::prettyPrintAttributes(Decl *D) { if (D->hasAttrs()) { AttrVec &Attrs = D->getAttrs(); for (auto *A : Attrs) { + if (A->isInherited() || A->isImplicit()) + continue; switch (A->getKind()) { #define ATTR(X) #define PRAGMA_SPELLING_ATTR(X) case attr::X: @@ -372,21 +375,23 @@ void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) { !isa<ClassTemplateSpecializationDecl>(DC)) continue; - // The next bits of code handles stuff like "struct {int x;} a,b"; we're + // The next bits of code handle stuff like "struct {int x;} a,b"; we're // forced to merge the declarations because there's no other way to - // refer to the struct in question. This limited merging is safe without - // a bunch of other checks because it only merges declarations directly - // referring to the tag, not typedefs. + // refer to the struct in question. When that struct is named instead, we + // also need to merge to avoid splitting off a stand-alone struct + // declaration that produces the warning ext_no_declarators in some + // contexts. + // + // This limited merging is safe without a bunch of other checks because it + // only merges declarations directly referring to the tag, not typedefs. // // Check whether the current declaration should be grouped with a previous - // unnamed struct. + // non-free-standing tag declaration. QualType CurDeclType = getDeclType(*D); if (!Decls.empty() && !CurDeclType.isNull()) { QualType BaseType = GetBaseType(CurDeclType); - if (!BaseType.isNull() && isa<ElaboratedType>(BaseType)) - BaseType = cast<ElaboratedType>(BaseType)->getNamedType(); - if (!BaseType.isNull() && isa<TagType>(BaseType) && - cast<TagType>(BaseType)->getDecl() == Decls[0]) { + if (!BaseType.isNull() && isa<ElaboratedType>(BaseType) && + cast<ElaboratedType>(BaseType)->getOwnedTagDecl() == Decls[0]) { Decls.push_back(*D); continue; } @@ -396,9 +401,9 @@ void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) { if (!Decls.empty()) ProcessDeclGroup(Decls); - // If the current declaration is an unnamed tag type, save it + // If the current declaration is not a free standing declaration, save it // so we can merge it with the subsequent declaration(s) using it. - if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->getIdentifier()) { + if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->isFreeStanding()) { Decls.push_back(*D); continue; } @@ -495,14 +500,17 @@ void DeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) { void DeclPrinter::VisitEnumDecl(EnumDecl *D) { if (!Policy.SuppressSpecifiers && D->isModulePrivate()) Out << "__module_private__ "; - Out << "enum "; + Out << "enum"; if (D->isScoped()) { if (D->isScopedUsingClassTag()) - Out << "class "; + Out << " class"; else - Out << "struct "; + Out << " struct"; } - Out << *D; + + prettyPrintAttributes(D); + + Out << ' ' << *D; if (D->isFixed() && D->getASTContext().getLangOpts().CPlusPlus11) Out << " : " << D->getIntegerType().stream(Policy); @@ -512,7 +520,6 @@ void DeclPrinter::VisitEnumDecl(EnumDecl *D) { VisitDeclContext(D); Indent() << "}"; } - prettyPrintAttributes(D); } void DeclPrinter::VisitRecordDecl(RecordDecl *D) { @@ -669,7 +676,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { Proto += ")"; } else if (FT && isNoexceptExceptionSpec(FT->getExceptionSpecType())) { Proto += " noexcept"; - if (FT->getExceptionSpecType() == EST_ComputedNoexcept) { + if (isComputedNoexcept(FT->getExceptionSpecType())) { Proto += "("; llvm::raw_string_ostream EOut(Proto); FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy, @@ -1526,7 +1533,7 @@ void DeclPrinter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { E = D->varlist_end(); I != E; ++I) { Out << (I == D->varlist_begin() ? '(' : ','); - NamedDecl *ND = cast<NamedDecl>(cast<DeclRefExpr>(*I)->getDecl()); + NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl(); ND->printQualifiedName(Out); } Out << ")"; |