From 5efbb33a6bec577ee97318a073ad0a71f1a72dc0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 20 Nov 2006 05:01:40 +0000 Subject: [PATCH] remember referenced decls in our AST's llvm-svn: 39193 --- clang/AST/SemaExpr.cpp | 3 +-- clang/AST/StmtPrinter.cpp | 4 ++-- clang/Sema/SemaExpr.cpp | 3 +-- clang/include/clang/AST/Expr.h | 8 +++++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clang/AST/SemaExpr.cpp b/clang/AST/SemaExpr.cpp index 52d2cd9f8ff7..ac3a954bf705 100644 --- a/clang/AST/SemaExpr.cpp +++ b/clang/AST/SemaExpr.cpp @@ -253,8 +253,7 @@ Sema::ExprResult Sema::ParseIdentifierExpr(SourceLocation Loc, return true; } - - return new DeclRefExpr(*(Decl*)0); + return new DeclRefExpr(D); } Sema::ExprResult Sema::ParseSimplePrimaryExpr(SourceLocation Loc, diff --git a/clang/AST/StmtPrinter.cpp b/clang/AST/StmtPrinter.cpp index 8aa05bbe8a32..023adb0fdf52 100644 --- a/clang/AST/StmtPrinter.cpp +++ b/clang/AST/StmtPrinter.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/AST/StmtVisitor.h" +#include "clang/AST/Decl.h" #include "clang/AST/Expr.h" #include "clang/Lex/IdentifierTable.h" #include "llvm/Support/Compiler.h" @@ -211,8 +212,7 @@ void StmtPrinter::VisitExpr(Expr *Node) { } void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) { - // FIXME: print name. - OS << "x"; + OS << Node->getDecl()->getName(); } void StmtPrinter::VisitIntegerConstant(IntegerConstant *Node) { diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp index 52d2cd9f8ff7..ac3a954bf705 100644 --- a/clang/Sema/SemaExpr.cpp +++ b/clang/Sema/SemaExpr.cpp @@ -253,8 +253,7 @@ Sema::ExprResult Sema::ParseIdentifierExpr(SourceLocation Loc, return true; } - - return new DeclRefExpr(*(Decl*)0); + return new DeclRefExpr(D); } Sema::ExprResult Sema::ParseSimplePrimaryExpr(SourceLocation Loc, diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index 27ffccf05f03..e4570de522b1 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -42,10 +42,12 @@ public: /// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function, /// enum, etc. class DeclRefExpr : public Expr { - // TODO: Union with the decl when resolved. - Decl &D; + Decl *D; public: - DeclRefExpr(Decl &d) : D(d) {} + DeclRefExpr(Decl *d) : D(d) {} + + Decl *getDecl() const { return D; } + virtual void visit(StmtVisitor &Visitor); };