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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67283 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp
index c52eb7e..3a6a01c 100644
--- a/lib/AST/StmtPrinter.cpp
+++ b/lib/AST/StmtPrinter.cpp
@@ -530,28 +530,10 @@
OS << Node->getDecl()->getNameAsString();
}
-void StmtPrinter::VisitQualifiedDeclRefExpr(QualifiedDeclRefExpr *Node) {
- // FIXME: Should we keep enough information in QualifiedDeclRefExpr
- // to produce the same qualification that the user wrote?
- llvm::SmallVector<DeclContext *, 4> Contexts;
-
+void StmtPrinter::VisitQualifiedDeclRefExpr(QualifiedDeclRefExpr *Node) {
NamedDecl *D = Node->getDecl();
- // Build up a stack of contexts.
- DeclContext *Ctx = D->getDeclContext();
- for (; Ctx; Ctx = Ctx->getParent())
- if (!Ctx->isTransparentContext())
- Contexts.push_back(Ctx);
-
- while (!Contexts.empty()) {
- DeclContext *Ctx = Contexts.back();
- if (isa<TranslationUnitDecl>(Ctx))
- OS << "::";
- else if (NamedDecl *ND = dyn_cast<NamedDecl>(Ctx))
- OS << ND->getNameAsString() << "::";
- Contexts.pop_back();
- }
-
+ NestedNameSpecifier::Print(OS, Node->begin(), Node->end());
OS << D->getNameAsString();
}