summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/NestedNameSpecifier.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-03-19 03:51:16 +0000
committerDouglas Gregor <dgregor@apple.com>2009-03-19 03:51:16 +0000
commit183539102563b85e9421d0fc5c3a650a20887840 (patch)
tree7a18d1af87575a34033cebf9778c66508d13eec9 /clang/lib/AST/NestedNameSpecifier.cpp
parent3b7b301a2462c9982192c41de7e11cbd804792a3 (diff)
downloadbcm5719-llvm-183539102563b85e9421d0fc5c3a650a20887840.tar.gz
bcm5719-llvm-183539102563b85e9421d0fc5c3a650a20887840.zip
Generalize printing of nested-name-specifier sequences for use in both
QualifiedNameType and QualifiedDeclRefExpr. We now keep track of the exact nested-name-specifier spelling for a QualifiedDeclRefExpr, and use that spelling when printing ASTs. This fixes PR3493. llvm-svn: 67283
Diffstat (limited to 'clang/lib/AST/NestedNameSpecifier.cpp')
-rw-r--r--clang/lib/AST/NestedNameSpecifier.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/clang/lib/AST/NestedNameSpecifier.cpp b/clang/lib/AST/NestedNameSpecifier.cpp
index 318c05fe7ca..ea4b506e640 100644
--- a/clang/lib/AST/NestedNameSpecifier.cpp
+++ b/clang/lib/AST/NestedNameSpecifier.cpp
@@ -15,6 +15,8 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/Type.h"
+#include "llvm/Support/raw_ostream.h"
+
using namespace clang;
DeclContext *
@@ -32,3 +34,28 @@ NestedNameSpecifier::computeDeclContext(ASTContext &Context) const {
assert(TagT && "No DeclContext from a non-tag type");
return TagT->getDecl();
}
+
+void NestedNameSpecifier::Print(llvm::raw_ostream &OS,
+ const NestedNameSpecifier *First,
+ const NestedNameSpecifier *Last) {
+ for (; First != Last; ++First) {
+ if (Type *T = First->getAsType()) {
+ std::string TypeStr;
+
+ // If this is a qualified name type, suppress the qualification:
+ // it's part of our nested-name-specifier sequence anyway.
+ if (const QualifiedNameType *QualT = dyn_cast<QualifiedNameType>(T))
+ T = QualT->getNamedType().getTypePtr();
+
+ if (const TagType *TagT = dyn_cast<TagType>(T))
+ TagT->getAsStringInternal(TypeStr, true);
+ else
+ T->getAsStringInternal(TypeStr);
+ OS << TypeStr;
+ } else if (NamedDecl *NamedDC
+ = dyn_cast_or_null<NamedDecl>(First->getAsDeclContext()))
+ OS << NamedDC->getNameAsString();
+
+ OS << "::";
+ }
+}
OpenPOWER on IntegriCloud