summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-11-03 00:16:13 +0000
committerDouglas Gregor <dgregor@apple.com>2011-11-03 00:16:13 +0000
commit2e10cf9620885bb2d81b93ecd98421beb51c4889 (patch)
tree97f841f8e4b8f241def6102fd4fe406824873177
parent9589872af9e1a88799d43b1bd403db7d338ba5f0 (diff)
downloadbcm5719-llvm-2e10cf9620885bb2d81b93ecd98421beb51c4889.tar.gz
bcm5719-llvm-2e10cf9620885bb2d81b93ecd98421beb51c4889.zip
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>. llvm-svn: 143599
-rw-r--r--clang/include/clang/AST/PrettyPrinter.h6
-rw-r--r--clang/lib/AST/NestedNameSpecifier.cpp3
-rw-r--r--clang/lib/AST/TypePrinter.cpp5
-rw-r--r--clang/lib/Sema/SemaCodeComplete.cpp1
-rw-r--r--clang/test/Index/complete-cxx-inline-methods.cpp10
5 files changed, 20 insertions, 5 deletions
diff --git a/clang/include/clang/AST/PrettyPrinter.h b/clang/include/clang/AST/PrettyPrinter.h
index 2bdd8d3f4bc..2e34dc8cbd5 100644
--- a/clang/include/clang/AST/PrettyPrinter.h
+++ b/clang/include/clang/AST/PrettyPrinter.h
@@ -36,7 +36,7 @@ struct PrintingPolicy {
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 @@ struct PrintingPolicy {
/// \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
diff --git a/clang/lib/AST/NestedNameSpecifier.cpp b/clang/lib/AST/NestedNameSpecifier.cpp
index 1ff2e7177b3..858cf12dc66 100644
--- a/clang/lib/AST/NestedNameSpecifier.cpp
+++ b/clang/lib/AST/NestedNameSpecifier.cpp
@@ -229,6 +229,9 @@ NestedNameSpecifier::print(raw_ostream &OS,
break;
case Namespace:
+ if (getAsNamespace()->isAnonymousNamespace())
+ return;
+
OS << getAsNamespace()->getName();
break;
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index fb7b918ca2f..ec6cb48bf86 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -600,6 +600,9 @@ void TypePrinter::AppendScope(DeclContext *DC, std::string &Buffer) {
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 @@ void TypePrinter::AppendScope(DeclContext *DC, std::string &Buffer) {
Buffer += Typedef->getIdentifier()->getName();
else if (Tag->getIdentifier())
Buffer += Tag->getIdentifier()->getName();
+ else
+ return;
}
if (Buffer.size() != OldSize)
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 4066a06e529..f964ec14836 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -1381,6 +1381,7 @@ static PrintingPolicy getCompletionPrintingPolicy(Sema &S) {
PrintingPolicy Policy = S.getPrintingPolicy();
Policy.AnonymousTagLocations = false;
Policy.SuppressStrongLifetime = true;
+ Policy.SuppressUnwrittenScope = true;
return Policy;
}
diff --git a/clang/test/Index/complete-cxx-inline-methods.cpp b/clang/test/Index/complete-cxx-inline-methods.cpp
index 48fa8683af4..d441972dd6f 100644
--- a/clang/test/Index/complete-cxx-inline-methods.cpp
+++ b/clang/test/Index/complete-cxx-inline-methods.cpp
@@ -1,3 +1,4 @@
+namespace {
class MyCls {
void in_foo() {
vec.x = 0;
@@ -20,9 +21,10 @@ private:
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 @@ private:
// 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)
OpenPOWER on IntegriCloud