Index: clang/include/clang-c/Index.h =================================================================== --- clang/include/clang-c/Index.h +++ clang/include/clang-c/Index.h @@ -4236,7 +4236,7 @@ CXPrintingPolicy_Indentation, CXPrintingPolicy_SuppressSpecifiers, CXPrintingPolicy_SuppressTagKeyword, - CXPrintingPolicy_IncludeTagDefinition, + CXPrintingPolicy_IncludeTagDefinition, ///< deprecated and has no effect CXPrintingPolicy_SuppressScope, CXPrintingPolicy_SuppressUnwrittenScope, CXPrintingPolicy_SuppressInitializers, Index: clang/include/clang/AST/PrettyPrinter.h =================================================================== --- clang/include/clang/AST/PrettyPrinter.h +++ clang/include/clang/AST/PrettyPrinter.h @@ -93,14 +93,7 @@ /// \endcode unsigned SuppressTagKeyword : 1; - /// When true, include the body of a tag definition. - /// - /// This is used to place the definition of a struct - /// in the middle of another declaration as with: - /// - /// \code - /// typedef struct { int x, y; } Point; - /// \endcode + /// This flag is deprecated and no longer has any effect. unsigned IncludeTagDefinition : 1; /// Suppresses printing of scope specifiers. @@ -225,6 +218,25 @@ /// When true, print the fully qualified name of function declarations. /// This is the opposite of SuppressScope and thus overrules it. unsigned FullyQualifiedName : 1; + + /// Transient state that's internal to the printing algorithm and that's not + /// intended to be exposed as part of its external configuration (via + /// libclang, for example). + /// + /// FIXME: Many more flags above should be moved here and should be + /// deprecated in libclang's CXPrintingPolicyProperty. + struct TransientState { + TransientState() : PrintOwnedTagDecl(false) {} + /// When true, print any tag declaration owned by an elaborated type. + /// + /// This is used to faithfully print the exact tag declaration that appears + /// within another declaration. For example: + /// + /// \code + /// typedef struct T { int x, y; } Point; + /// \endcode + unsigned PrintOwnedTagDecl : 1; + } State; }; } // end namespace clang Index: clang/lib/AST/DeclPrinter.cpp =================================================================== --- clang/lib/AST/DeclPrinter.cpp +++ clang/lib/AST/DeclPrinter.cpp @@ -178,12 +178,12 @@ for ( ; Begin != End; ++Begin) { if (isFirst) { if(TD) - SubPolicy.IncludeTagDefinition = true; + SubPolicy.State.PrintOwnedTagDecl = true; SubPolicy.SuppressSpecifiers = false; isFirst = false; } else { if (!isFirst) Out << ", "; - SubPolicy.IncludeTagDefinition = false; + SubPolicy.State.PrintOwnedTagDecl = false; SubPolicy.SuppressSpecifiers = true; } @@ -849,7 +849,7 @@ } PrintingPolicy SubPolicy(Policy); SubPolicy.SuppressSpecifiers = false; - SubPolicy.IncludeTagDefinition = false; + SubPolicy.State.PrintOwnedTagDecl = false; Init->printPretty(Out, nullptr, SubPolicy, Indentation); if ((D->getInitStyle() == VarDecl::CallInit) && !isa(Init)) Out << ")"; Index: clang/lib/AST/TypePrinter.cpp =================================================================== --- clang/lib/AST/TypePrinter.cpp +++ clang/lib/AST/TypePrinter.cpp @@ -455,7 +455,7 @@ OS << '('; PrintingPolicy InnerPolicy(Policy); - InnerPolicy.IncludeTagDefinition = false; + InnerPolicy.State.PrintOwnedTagDecl = false; TypePrinter(InnerPolicy).print(QualType(T->getClass(), 0), OS, StringRef()); OS << "::*"; @@ -1103,9 +1103,9 @@ } void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) { - if (Policy.IncludeTagDefinition) { + if (Policy.State.PrintOwnedTagDecl) { PrintingPolicy SubPolicy = Policy; - SubPolicy.IncludeTagDefinition = false; + SubPolicy.State.PrintOwnedTagDecl = false; D->print(OS, SubPolicy, Indentation); spaceBeforePlaceHolder(OS); return; @@ -1258,20 +1258,19 @@ void TypePrinter::printElaboratedBefore(const ElaboratedType *T, raw_ostream &OS) { - if (Policy.IncludeTagDefinition && T->getOwnedTagDecl()) { + if (Policy.State.PrintOwnedTagDecl && T->getOwnedTagDecl()) { TagDecl *OwnedTagDecl = T->getOwnedTagDecl(); assert(OwnedTagDecl->getTypeForDecl() == T->getNamedType().getTypePtr() && "OwnedTagDecl expected to be a declaration for the type"); PrintingPolicy SubPolicy = Policy; - SubPolicy.IncludeTagDefinition = false; + SubPolicy.State.PrintOwnedTagDecl = false; OwnedTagDecl->print(OS, SubPolicy, Indentation); spaceBeforePlaceHolder(OS); return; } // The tag definition will take care of these. - if (!Policy.IncludeTagDefinition) - { + if (!Policy.State.PrintOwnedTagDecl) { OS << TypeWithKeyword::getKeywordName(T->getKeyword()); if (T->getKeyword() != ETK_None) OS << " "; @@ -1286,7 +1285,7 @@ void TypePrinter::printElaboratedAfter(const ElaboratedType *T, raw_ostream &OS) { - if (Policy.IncludeTagDefinition && T->getOwnedTagDecl()) + if (Policy.State.PrintOwnedTagDecl && T->getOwnedTagDecl()) return; ElaboratedTypePolicyRAII PolicyRAII(Policy); printAfter(T->getNamedType(), OS); Index: clang/tools/c-index-test/c-index-test.c =================================================================== --- clang/tools/c-index-test/c-index-test.c +++ clang/tools/c-index-test/c-index-test.c @@ -103,8 +103,6 @@ CXPrintingPolicy_SuppressSpecifiers}, {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSTAGKEYWORD", CXPrintingPolicy_SuppressTagKeyword}, - {"CINDEXTEST_PRINTINGPOLICY_INCLUDETAGDEFINITION", - CXPrintingPolicy_IncludeTagDefinition}, {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSSCOPE", CXPrintingPolicy_SuppressScope}, {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSUNWRITTENSCOPE",