diff options
| author | Douglas Gregor <dgregor@apple.com> | 2009-01-06 05:10:23 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2009-01-06 05:10:23 +0000 |
| commit | c7acfdfe9a6f4c5dc045ca6061b69080e01c89e4 (patch) | |
| tree | 79e853b3418abe5a1203463a416ef8cf60733ff3 /clang/lib/AST/StmtPrinter.cpp | |
| parent | a8a3f73a47e7bf23e7b3f0f5dc098539d973ba81 (diff) | |
| download | bcm5719-llvm-c7acfdfe9a6f4c5dc045ca6061b69080e01c89e4.tar.gz bcm5719-llvm-c7acfdfe9a6f4c5dc045ca6061b69080e01c89e4.zip | |
Add QualifiedDeclRefExpr, which retains additional source-location
information for declarations that were referenced via a qualified-id,
e.g., N::C::value. We keep track of the location of the start of the
nested-name-specifier. Note that the difference between
QualifiedDeclRefExpr and DeclRefExpr does have an effect on the
semantics of function calls in two ways:
1) The use of a qualified-id instead of an unqualified-id suppresses
argument-dependent lookup
2) If the name refers to a virtual function, the qualified-id
version will call the function determined statically while the
unqualified-id version will call the function determined dynamically
(by looking up the appropriate function in the vtable).
Neither of these features is implemented yet, but we do print out
qualified names for QualifiedDeclRefExprs as part of the AST printing.
llvm-svn: 61789
Diffstat (limited to 'clang/lib/AST/StmtPrinter.cpp')
| -rw-r--r-- | clang/lib/AST/StmtPrinter.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index 89a185d965d..679c8974975 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "clang/AST/StmtVisitor.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/PrettyPrinter.h" #include "llvm/Support/Compiler.h" @@ -513,6 +514,35 @@ void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) { 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; + + NamedDecl *D = Node->getDecl(); + + // Build up a stack of contexts. + DeclContext *Ctx = 0; + if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) + Ctx = SD->getDeclContext(); + else if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) + Ctx = Ovl->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 (ScopedDecl *SD = dyn_cast<ScopedDecl>(Ctx)) + OS << SD->getNameAsString() << "::"; + Contexts.pop_back(); + } + + OS << D->getNameAsString(); +} + void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) { if (Node->getBase()) { PrintExpr(Node->getBase()); |

