jdenny updated this revision to Diff 151979.
jdenny added a comment.
Rebased. Ping.
https://reviews.llvm.org/D46919
Files:
include/clang-c/Index.h
include/clang/AST/PrettyPrinter.h
lib/AST/DeclPrinter.cpp
lib/AST/TypePrinter.cpp
tools/c-index-test/c-index-test.c
Index: tools/c-index-test/c-index-test.c
===================================================================
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -99,8 +99,6 @@
CXPrintingPolicy_SuppressSpecifiers},
{"CINDEXTEST_PRINTINGPOLICY_SUPPRESSTAGKEYWORD",
CXPrintingPolicy_SuppressTagKeyword},
- {"CINDEXTEST_PRINTINGPOLICY_INCLUDETAGDEFINITION",
- CXPrintingPolicy_IncludeTagDefinition},
{"CINDEXTEST_PRINTINGPOLICY_SUPPRESSSCOPE",
CXPrintingPolicy_SuppressScope},
{"CINDEXTEST_PRINTINGPOLICY_SUPPRESSUNWRITTENSCOPE",
Index: lib/AST/TypePrinter.cpp
===================================================================
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -454,7 +454,7 @@
OS << '(';
PrintingPolicy InnerPolicy(Policy);
- InnerPolicy.IncludeTagDefinition = false;
+ InnerPolicy.State.PrintOwnedTagDecl = false;
TypePrinter(InnerPolicy).print(QualType(T->getClass(), 0), OS, StringRef());
OS << "::*";
@@ -1054,9 +1054,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;
@@ -1209,35 +1209,34 @@
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 << " ";
NestedNameSpecifier *Qualifier = T->getQualifier();
if (Qualifier)
Qualifier->print(OS, Policy);
}
-
+
ElaboratedTypePolicyRAII PolicyRAII(Policy);
printBefore(T->getNamedType(), OS);
}
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: lib/AST/DeclPrinter.cpp
===================================================================
--- lib/AST/DeclPrinter.cpp
+++ 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<ParenListExpr>(Init))
Out << ")";
Index: include/clang/AST/PrettyPrinter.h
===================================================================
--- include/clang/AST/PrettyPrinter.h
+++ include/clang/AST/PrettyPrinter.h
@@ -93,14 +93,7 @@
/// \endcode
bool 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.
bool 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.
bool 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
+ bool PrintOwnedTagDecl : 1;
+ } State;
};
} // end namespace clang
Index: include/clang-c/Index.h
===================================================================
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -4129,7 +4129,7 @@
CXPrintingPolicy_Indentation,
CXPrintingPolicy_SuppressSpecifiers,
CXPrintingPolicy_SuppressTagKeyword,
- CXPrintingPolicy_IncludeTagDefinition,
+ CXPrintingPolicy_IncludeTagDefinition, ///< deprecated and has no effect
CXPrintingPolicy_SuppressScope,
CXPrintingPolicy_SuppressUnwrittenScope,
CXPrintingPolicy_SuppressInitializers,
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits