[cfe-commits] r100470 - in /cfe/trunk: include/clang/AST/PrettyPrinter.h lib/AST/TypePrinter.cpp lib/Sema/SemaCodeComplete.cpp test/Index/complete-enums.c
Douglas Gregor
dgregor at apple.com
Mon Apr 5 14:25:31 PDT 2010
Author: dgregor
Date: Mon Apr 5 16:25:31 2010
New Revision: 100470
URL: http://llvm.org/viewvc/llvm-project?rev=100470&view=rev
Log:
Extend the type printing policy to allow one to turn off the printing
of file locations for anonymous tag types (e.g., "enum <anonymous at
t.h:15:6>"), which can get rather long.
Added:
cfe/trunk/test/Index/complete-enums.c
Modified:
cfe/trunk/include/clang/AST/PrettyPrinter.h
cfe/trunk/lib/AST/TypePrinter.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
Modified: cfe/trunk/include/clang/AST/PrettyPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/PrettyPrinter.h?rev=100470&r1=100469&r2=100470&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/PrettyPrinter.h (original)
+++ cfe/trunk/include/clang/AST/PrettyPrinter.h Mon Apr 5 16:25:31 2010
@@ -37,7 +37,8 @@
PrintingPolicy(const LangOptions &LO)
: Indentation(2), LangOpts(LO), SuppressSpecifiers(false),
SuppressTag(false), SuppressScope(false),
- Dump(false), ConstantArraySizeAsWritten(false) { }
+ Dump(false), ConstantArraySizeAsWritten(false),
+ AnonymousTagLocations(true) { }
/// \brief The number of spaces to use to indent each line.
unsigned Indentation : 8;
@@ -97,7 +98,11 @@
/// char a[9] = "A string";
/// \endcode
bool ConstantArraySizeAsWritten : 1;
-
+
+ /// \brief When printing an anonymous tag name, also print the location of
+ /// that entity (e.g., "enum <anonymous at t.h:10:5>"). Otherwise, just
+ /// prints "<anonymous>" for the name.
+ bool AnonymousTagLocations : 1;
};
} // end namespace clang
Modified: cfe/trunk/lib/AST/TypePrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=100470&r1=100469&r2=100470&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)
+++ cfe/trunk/lib/AST/TypePrinter.cpp Mon Apr 5 16:25:31 2010
@@ -442,18 +442,21 @@
llvm::raw_string_ostream OS(Buffer);
OS << "<anonymous";
- // Suppress the redundant tag keyword if we just printed one.
- // We don't have to worry about ElaboratedTypes here because you can't
- // refer to an anonymous type with one.
- if (!HasKindDecoration)
- OS << " " << D->getKindName();
-
- PresumedLoc PLoc = D->getASTContext().getSourceManager().getPresumedLoc(
- D->getLocation());
- OS << " at " << PLoc.getFilename()
- << ':' << PLoc.getLine()
- << ':' << PLoc.getColumn()
- << '>';
+ if (Policy.AnonymousTagLocations) {
+ // Suppress the redundant tag keyword if we just printed one.
+ // We don't have to worry about ElaboratedTypes here because you can't
+ // refer to an anonymous type with one.
+ if (!HasKindDecoration)
+ OS << " " << D->getKindName();
+
+ PresumedLoc PLoc = D->getASTContext().getSourceManager().getPresumedLoc(
+ D->getLocation());
+ OS << " at " << PLoc.getFilename()
+ << ':' << PLoc.getLine()
+ << ':' << PLoc.getColumn();
+ }
+
+ OS << '>';
OS.flush();
}
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=100470&r1=100469&r2=100470&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Mon Apr 5 16:25:31 2010
@@ -1338,8 +1338,11 @@
if (T.isNull() || Context.hasSameType(T, Context.DependentTy))
return;
+ PrintingPolicy Policy(Context.PrintingPolicy);
+ Policy.AnonymousTagLocations = false;
+
std::string TypeStr;
- T.getAsStringInternal(TypeStr, Context.PrintingPolicy);
+ T.getAsStringInternal(TypeStr, Policy);
Result->AddResultTypeChunk(TypeStr);
}
Added: cfe/trunk/test/Index/complete-enums.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-enums.c?rev=100470&view=auto
==============================================================================
--- cfe/trunk/test/Index/complete-enums.c (added)
+++ cfe/trunk/test/Index/complete-enums.c Mon Apr 5 16:25:31 2010
@@ -0,0 +1,15 @@
+// Note: the run lines follow their respective tests, since line/column
+// matter in this test.
+
+enum {
+ Red = 17,
+ Green,
+ Blue
+};
+
+void f() {
+
+}
+
+// RUN: c-index-test -code-completion-at=%s:11:1 %s | FileCheck -check-prefix=CHECK-CC1 %s
+// CHECK-CC1: EnumConstantDecl:{ResultType enum <anonymous>}{TypedText Red}
More information about the cfe-commits
mailing list