diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 834449ff1b999..397911894cc5d 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -250,13 +250,23 @@ raw_ostream& DeclPrinter::Indent(unsigned Indentation) { return Out; } +// For CLANG_ATTR_LIST_CanPrintOnLeft macro. +#include "clang/Basic/AttrLeftSideCanPrintList.inc" + +// For CLANG_ATTR_LIST_PrintOnLeft macro. +#include "clang/Basic/AttrLeftSideMustPrintList.inc" + static bool canPrintOnLeftSide(attr::Kind kind) { +#ifdef CLANG_ATTR_LIST_CanPrintOnLeft switch (kind) { -#include "clang/Basic/AttrLeftSideCanPrintList.inc" + CLANG_ATTR_LIST_CanPrintOnLeft return true; default: return false; } +#else + return false; +#endif } static bool canPrintOnLeftSide(const Attr *A) { @@ -268,11 +278,16 @@ static bool canPrintOnLeftSide(const Attr *A) { static bool mustPrintOnLeftSide(attr::Kind kind) { switch (kind) { -#include "clang/Basic/AttrLeftSideMustPrintList.inc" +#ifdef CLANG_ATTR_LIST_PrintOnLeft + switch (kind) { + CLANG_ATTR_LIST_PrintOnLeft return true; default: return false; } +#else + return false; +#endif } static bool mustPrintOnLeftSide(const Attr *A) { @@ -314,7 +329,6 @@ void DeclPrinter::prettyPrintAttributes(Decl *D, llvm::raw_ostream &Out, VD->getInitStyle() == VarDecl::CallInit) AttrLoc = AttrPrintLoc::Left; } - // Only print the side matches the user requested. if ((Loc & AttrLoc) != AttrPrintLoc::None) A->printPretty(Out, Policy); diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index ff6ffe16b4ccd..7ea09058c3d39 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -3217,6 +3217,8 @@ void EmitClangAttrPrintList(const std::string &FieldName, RecordKeeper &Records, std::vector Attrs = Records.getAllDerivedDefinitions("Attr"); std::vector PragmaAttrs; + bool first = false; + for (auto *Attr : Attrs) { if (!Attr->getValueAsBit("ASTNode")) continue; @@ -3224,8 +3226,15 @@ void EmitClangAttrPrintList(const std::string &FieldName, RecordKeeper &Records, if (!Attr->getValueAsBit(FieldName)) continue; - OS << "case attr::" << Attr->getName() << ":\n"; + if (!first) { + first = true; + OS << "#define CLANG_ATTR_LIST_" << FieldName; + } + + OS << " \\\n case attr::" << Attr->getName() << ":"; } + + OS << '\n'; } // Emits the enumeration list for attributes.