[cfe-commits] r39048 - in /cfe/cfe/trunk: AST/Decl.cpp AST/Sema.cpp AST/Stmt.cpp Driver/clang.cpp Sema/Sema.cpp include/clang/AST/Decl.h include/clang/AST/Expr.h include/clang/AST/Stmt.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:27:07 PDT 2007


Author: sabre
Date: Wed Jul 11 11:27:07 2007
New Revision: 39048

URL: http://llvm.org/viewvc/llvm-project?rev=39048&view=rev
Log:
Make the driver print function bodies at -parse-print-ast

Modified:
    cfe/cfe/trunk/AST/Decl.cpp
    cfe/cfe/trunk/AST/Sema.cpp
    cfe/cfe/trunk/AST/Stmt.cpp
    cfe/cfe/trunk/Driver/clang.cpp
    cfe/cfe/trunk/Sema/Sema.cpp
    cfe/cfe/trunk/include/clang/AST/Decl.h
    cfe/cfe/trunk/include/clang/AST/Expr.h
    cfe/cfe/trunk/include/clang/AST/Stmt.h

Modified: cfe/cfe/trunk/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Decl.cpp?rev=39048&r1=39047&r2=39048&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Decl.cpp (original)
+++ cfe/cfe/trunk/AST/Decl.cpp Wed Jul 11 11:27:07 2007
@@ -12,4 +12,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/AST/Decl.h"
+using namespace llvm;
+using namespace clang;
 
+// Out-of-line virtual method providing a home for Decl.
+Decl::~Decl() {
+}

Modified: cfe/cfe/trunk/AST/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.cpp?rev=39048&r1=39047&r2=39048&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Sema.cpp (original)
+++ cfe/cfe/trunk/AST/Sema.cpp Wed Jul 11 11:27:07 2007
@@ -196,7 +196,7 @@
 Action::StmtResult
 ASTBuilder::ParseReturnStmt(SourceLocation ReturnLoc,
                             ExprTy *RetValExp) {
-  
+  return new ReturnStmt((Expr*)RetValExp);
 }
 
 //===--------------------------------------------------------------------===//

Modified: cfe/cfe/trunk/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Stmt.cpp?rev=39048&r1=39047&r2=39048&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Stmt.cpp (original)
+++ cfe/cfe/trunk/AST/Stmt.cpp Wed Jul 11 11:27:07 2007
@@ -22,18 +22,19 @@
     std::cerr << "<null>";
     return;
   }
-  bool isExpr = dynamic_cast<const Expr*>(this) != 0;
-  if (isExpr) std::cerr << "(";
+  if (isExpr()) std::cerr << "(";
   dump_impl();
-  if (isExpr) std::cerr << ")";
+  if (isExpr()) std::cerr << ")";
 }
 
 
 
 void CompoundStmt::dump_impl() const {
   std::cerr << "{\n";
-  for (unsigned i = 0, e = Body.size(); i != e; ++i)
+  for (unsigned i = 0, e = Body.size(); i != e; ++i) {
     Body[i]->dump();
+    std::cerr << "\n";
+  }
   std::cerr << "}";
 }
 

Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=39048&r1=39047&r2=39048&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:27:07 2007
@@ -790,11 +790,15 @@
   ASTStreamerTy *Streamer = ASTStreamer_Init(PP, MainFileID, true);
   
   while (Decl *D = ASTStreamer_ReadTopLevelDecl(Streamer)) {
-    std::cerr << "Read top-level decl: ";
+    std::cerr << "Read top-level decl: '";
     if (const IdentifierInfo *II = D->getIdentifier())
-      std::cerr << II->getName() << "\n";
+      std::cerr << II->getName() << "'\n";
     else
       std::cerr << "\n";
+    if (FunctionDecl *FD = D->isFunctionDecl()) {
+      FD->getBody()->dump();
+      std::cerr << "\n";
+    }
   }
   
   ASTStreamer_Terminate(Streamer);

Modified: cfe/cfe/trunk/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.cpp?rev=39048&r1=39047&r2=39048&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/cfe/trunk/Sema/Sema.cpp Wed Jul 11 11:27:07 2007
@@ -196,7 +196,7 @@
 Action::StmtResult
 ASTBuilder::ParseReturnStmt(SourceLocation ReturnLoc,
                             ExprTy *RetValExp) {
-  
+  return new ReturnStmt((Expr*)RetValExp);
 }
 
 //===--------------------------------------------------------------------===//

Modified: cfe/cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Decl.h?rev=39048&r1=39047&r2=39048&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Decl.h Wed Jul 11 11:27:07 2007
@@ -21,6 +21,7 @@
 namespace clang {
 class IdentifierInfo;
 class Stmt;
+class FunctionDecl;
   
 /// Decl - This represents one declaration (or definition), e.g. a variable, 
 /// typedef, function, struct, etc.  
@@ -43,12 +44,17 @@
 public:
   Decl(IdentifierInfo *Id, const Declarator &D, Decl *next)
     : Identifier(Id), DeclarationSpecifier(D.getDeclSpec()), Next(next) {}
+  virtual ~Decl();
   
   const IdentifierInfo *getIdentifier() const { return Identifier; }
   
   const DeclSpec &getDeclSpec() const { return DeclarationSpecifier; }
   
   Decl *getNext() const { return Next; }
+  
+  // FIXME: Implement cast/dyn_cast/etc
+  virtual FunctionDecl *isFunctionDecl() { return 0; }
+  virtual const FunctionDecl *isFunctionDecl() const { return 0; }
 };
 
 /// FunctionDecl - An instance of this class is created to represent a function
@@ -62,6 +68,11 @@
   
   Stmt *getBody() const { return Body; }
   void setBody(Stmt *B) { Body = B; }
+  
+  
+  // FIXME: Implement cast/dyn_cast/etc
+  virtual FunctionDecl *isFunctionDecl() { return this; }
+  virtual const FunctionDecl *isFunctionDecl() const { return this; }
 };
 
 /// VarDecl - An instance of this class is created to represent a variable

Modified: cfe/cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Expr.h?rev=39048&r1=39047&r2=39048&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Expr.h Wed Jul 11 11:27:07 2007
@@ -32,6 +32,9 @@
   Expr() {}
   ~Expr() {}
   
+  
+  // FIXME: move to isa/dyncast etc.
+  virtual bool isExpr() const { return true; }
 };
 
 //===----------------------------------------------------------------------===//

Modified: cfe/cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Stmt.h?rev=39048&r1=39047&r2=39048&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Stmt.h Wed Jul 11 11:27:07 2007
@@ -33,6 +33,9 @@
   // FIXME: Change to non-virtual method that uses visitor pattern to do this.
   void dump() const;
   
+  // FIXME: move to isa/dyncast etc.
+  virtual bool isExpr() const { return false; }
+  
 private:
   virtual void dump_impl() const = 0;
 };





More information about the cfe-commits mailing list