[cfe-commits] r143599 - in /cfe/trunk: include/clang/AST/PrettyPrinter.h lib/AST/NestedNameSpecifier.cpp lib/AST/TypePrinter.cpp lib/Sema/SemaCodeComplete.cpp test/Index/complete-cxx-inline-methods.cpp
Douglas Gregor
dgregor at apple.com
Wed Nov 2 17:16:13 PDT 2011
Author: dgregor
Date: Wed Nov 2 19:16:13 2011
New Revision: 143599
URL: http://llvm.org/viewvc/llvm-project?rev=143599&view=rev
Log:
Add a printing policy flag to suppress printing "<anonymous>::" prior
to types. Enable this flag for code completion, where knowing whether
something is in an anonymous or inline namespace is actually not
useful, since you don't have to type it anyway. Fixes
<rdar://problem/10208818>.
Modified:
cfe/trunk/include/clang/AST/PrettyPrinter.h
cfe/trunk/lib/AST/NestedNameSpecifier.cpp
cfe/trunk/lib/AST/TypePrinter.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/Index/complete-cxx-inline-methods.cpp
Modified: cfe/trunk/include/clang/AST/PrettyPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/PrettyPrinter.h?rev=143599&r1=143598&r2=143599&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/PrettyPrinter.h (original)
+++ cfe/trunk/include/clang/AST/PrettyPrinter.h Wed Nov 2 19:16:13 2011
@@ -36,7 +36,7 @@
PrintingPolicy(const LangOptions &LO)
: Indentation(2), LangOpts(LO), SuppressSpecifiers(false),
SuppressTagKeyword(false), SuppressTag(false), SuppressScope(false),
- SuppressInitializers(false),
+ SuppressUnwrittenScope(false), SuppressInitializers(false),
Dump(false), ConstantArraySizeAsWritten(false),
AnonymousTagLocations(true), SuppressStrongLifetime(false),
Bool(LO.Bool) { }
@@ -86,6 +86,10 @@
/// \brief Suppresses printing of scope specifiers.
bool SuppressScope : 1;
+ /// \brief Suppress printing parts of scope specifiers that don't need
+ /// to be written, e.g., for inline or anonymous namespaces.
+ bool SuppressUnwrittenScope : 1;
+
/// \brief Suppress printing of variable initializers.
///
/// This flag is used when printing the loop variable in a for-range
Modified: cfe/trunk/lib/AST/NestedNameSpecifier.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/NestedNameSpecifier.cpp?rev=143599&r1=143598&r2=143599&view=diff
==============================================================================
--- cfe/trunk/lib/AST/NestedNameSpecifier.cpp (original)
+++ cfe/trunk/lib/AST/NestedNameSpecifier.cpp Wed Nov 2 19:16:13 2011
@@ -229,6 +229,9 @@
break;
case Namespace:
+ if (getAsNamespace()->isAnonymousNamespace())
+ return;
+
OS << getAsNamespace()->getName();
break;
Modified: cfe/trunk/lib/AST/TypePrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=143599&r1=143598&r2=143599&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)
+++ cfe/trunk/lib/AST/TypePrinter.cpp Wed Nov 2 19:16:13 2011
@@ -600,6 +600,9 @@
unsigned OldSize = Buffer.size();
if (NamespaceDecl *NS = dyn_cast<NamespaceDecl>(DC)) {
+ if (Policy.SuppressUnwrittenScope &&
+ (NS->isAnonymousNamespace() || NS->isInline()))
+ return;
if (NS->getIdentifier())
Buffer += NS->getNameAsString();
else
@@ -620,6 +623,8 @@
Buffer += Typedef->getIdentifier()->getName();
else if (Tag->getIdentifier())
Buffer += Tag->getIdentifier()->getName();
+ else
+ return;
}
if (Buffer.size() != OldSize)
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=143599&r1=143598&r2=143599&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed Nov 2 19:16:13 2011
@@ -1381,6 +1381,7 @@
PrintingPolicy Policy = S.getPrintingPolicy();
Policy.AnonymousTagLocations = false;
Policy.SuppressStrongLifetime = true;
+ Policy.SuppressUnwrittenScope = true;
return Policy;
}
Modified: cfe/trunk/test/Index/complete-cxx-inline-methods.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-cxx-inline-methods.cpp?rev=143599&r1=143598&r2=143599&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-cxx-inline-methods.cpp (original)
+++ cfe/trunk/test/Index/complete-cxx-inline-methods.cpp Wed Nov 2 19:16:13 2011
@@ -1,3 +1,4 @@
+namespace {
class MyCls {
void in_foo() {
vec.x = 0;
@@ -20,9 +21,10 @@
int value;
MyCls *object;
};
+}
-// RUN: c-index-test -code-completion-at=%s:3:9 %s | FileCheck %s
-// RUN: c-index-test -code-completion-at=%s:12:7 %s | FileCheck %s
+// RUN: c-index-test -code-completion-at=%s:4:9 %s | FileCheck %s
+// RUN: c-index-test -code-completion-at=%s:13:7 %s | FileCheck %s
// CHECK: CXXMethod:{ResultType MyCls::Vec &}{TypedText operator=}{LeftParen (}{Placeholder const MyCls::Vec &}{RightParen )} (34)
// CHECK-NEXT: StructDecl:{TypedText Vec}{Text ::} (75)
// CHECK-NEXT: FieldDecl:{ResultType int}{TypedText x} (35)
@@ -32,11 +34,11 @@
// CHECK-NEXT: Dot member access
// CHECK-NEXT: Container Kind: StructDecl
-// RUN: c-index-test -code-completion-at=%s:17:41 %s | FileCheck -check-prefix=CHECK-CTOR-INIT %s
+// RUN: c-index-test -code-completion-at=%s:18:41 %s | FileCheck -check-prefix=CHECK-CTOR-INIT %s
// CHECK-CTOR-INIT: NotImplemented:{TypedText MyCls}{LeftParen (}{Placeholder args}{RightParen )} (7)
// CHECK-CTOR-INIT: MemberRef:{TypedText object}{LeftParen (}{Placeholder args}{RightParen )} (35)
// CHECK-CTOR-INIT: MemberRef:{TypedText value}{LeftParen (}{Placeholder args}{RightParen )} (35)
-// RUN: c-index-test -code-completion-at=%s:17:55 %s | FileCheck -check-prefix=CHECK-CTOR-INIT-2 %s
+// RUN: c-index-test -code-completion-at=%s:18:55 %s | FileCheck -check-prefix=CHECK-CTOR-INIT-2 %s
// CHECK-CTOR-INIT-2-NOT: NotImplemented:{TypedText MyCls}{LeftParen (}{Placeholder args}{RightParen )}
// CHECK-CTOR-INIT-2: MemberRef:{TypedText object}{LeftParen (}{Placeholder args}{RightParen )} (35)
// CHECK-CTOR-INIT-2: MemberRef:{TypedText value}{LeftParen (}{Placeholder args}{RightParen )} (7)
More information about the cfe-commits
mailing list