[cfe-commits] r39046 - in /cfe/cfe/trunk: AST/Sema.cpp AST/Stmt.cpp Sema/Sema.cpp clang.xcodeproj/project.pbxproj include/clang/AST/AST.h include/clang/AST/Stmt.h

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


Author: sabre
Date: Wed Jul 11 11:27:05 2007
New Revision: 39046

URL: http://llvm.org/viewvc/llvm-project?rev=39046&view=rev
Log:
Make AST nodes for ReturnStmt's and CompoundStmts

Modified:
    cfe/cfe/trunk/AST/Sema.cpp
    cfe/cfe/trunk/AST/Stmt.cpp
    cfe/cfe/trunk/Sema/Sema.cpp
    cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/cfe/trunk/include/clang/AST/AST.h
    cfe/cfe/trunk/include/clang/AST/Stmt.h

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

==============================================================================
--- cfe/cfe/trunk/AST/Sema.cpp (original)
+++ cfe/cfe/trunk/AST/Sema.cpp Wed Jul 11 11:27:05 2007
@@ -52,6 +52,19 @@
   virtual void PopScope(SourceLocation Loc, Scope *S);
   
   //===--------------------------------------------------------------------===//
+  // Statement Parsing Callbacks.
+
+  virtual StmtResult ParseCompoundStmt(SourceLocation L, SourceLocation R,
+                                       StmtTy **Elts, unsigned NumElts);
+  virtual StmtResult ParseExprStmt(ExprTy *Expr) {
+    // TODO: Full info should track this with a node.
+    return Expr; // Exprs are Stmts.
+  }
+  
+  virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc,
+                                     ExprTy *RetValExp);
+  
+  //===--------------------------------------------------------------------===//
   // Expression Parsing Callbacks.
 
   // Primary Expressions.
@@ -165,6 +178,28 @@
 }
 
 //===--------------------------------------------------------------------===//
+// Statement Parsing Callbacks.
+//===--------------------------------------------------------------------===//
+
+Action::StmtResult 
+ASTBuilder::ParseCompoundStmt(SourceLocation L, SourceLocation R,
+                              StmtTy **Elts, unsigned NumElts) {
+  if (FullLocInfo || NumElts > 1)
+    return new CompoundStmt((Stmt**)Elts, NumElts);
+  else if (NumElts == 1)
+    return Elts[0];        // {stmt} -> stmt
+  else
+    return 0;              // {}  -> ;
+}
+
+
+Action::StmtResult
+ASTBuilder::ParseReturnStmt(SourceLocation ReturnLoc,
+                            ExprTy *RetValExp) {
+  
+}
+
+//===--------------------------------------------------------------------===//
 // Expression Parsing Callbacks.
 //===--------------------------------------------------------------------===//
 

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

==============================================================================
--- cfe/cfe/trunk/AST/Stmt.cpp (original)
+++ cfe/cfe/trunk/AST/Stmt.cpp Wed Jul 11 11:27:05 2007
@@ -27,3 +27,19 @@
   dump_impl();
   if (isExpr) std::cerr << ")";
 }
+
+
+
+void CompoundStmt::dump_impl() const {
+  std::cerr << "{\n";
+  for (unsigned i = 0, e = Body.size(); i != e; ++i)
+    Body[i]->dump();
+  std::cerr << "}";
+}
+
+
+void ReturnStmt::dump_impl() const {
+  std::cerr << "return ";
+  if (RetExpr)
+    RetExpr->dump();
+}

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

==============================================================================
--- cfe/cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/cfe/trunk/Sema/Sema.cpp Wed Jul 11 11:27:05 2007
@@ -52,6 +52,19 @@
   virtual void PopScope(SourceLocation Loc, Scope *S);
   
   //===--------------------------------------------------------------------===//
+  // Statement Parsing Callbacks.
+
+  virtual StmtResult ParseCompoundStmt(SourceLocation L, SourceLocation R,
+                                       StmtTy **Elts, unsigned NumElts);
+  virtual StmtResult ParseExprStmt(ExprTy *Expr) {
+    // TODO: Full info should track this with a node.
+    return Expr; // Exprs are Stmts.
+  }
+  
+  virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc,
+                                     ExprTy *RetValExp);
+  
+  //===--------------------------------------------------------------------===//
   // Expression Parsing Callbacks.
 
   // Primary Expressions.
@@ -165,6 +178,28 @@
 }
 
 //===--------------------------------------------------------------------===//
+// Statement Parsing Callbacks.
+//===--------------------------------------------------------------------===//
+
+Action::StmtResult 
+ASTBuilder::ParseCompoundStmt(SourceLocation L, SourceLocation R,
+                              StmtTy **Elts, unsigned NumElts) {
+  if (FullLocInfo || NumElts > 1)
+    return new CompoundStmt((Stmt**)Elts, NumElts);
+  else if (NumElts == 1)
+    return Elts[0];        // {stmt} -> stmt
+  else
+    return 0;              // {}  -> ;
+}
+
+
+Action::StmtResult
+ASTBuilder::ParseReturnStmt(SourceLocation ReturnLoc,
+                            ExprTy *RetValExp) {
+  
+}
+
+//===--------------------------------------------------------------------===//
 // Expression Parsing Callbacks.
 //===--------------------------------------------------------------------===//
 

Modified: cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=39046&r1=39045&r2=39046&view=diff

==============================================================================
--- cfe/cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/cfe/trunk/clang.xcodeproj/project.pbxproj Wed Jul 11 11:27:05 2007
@@ -26,6 +26,7 @@
 		DE3450D70AEB543100DBC861 /* DirectoryLookup.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE3450D60AEB543100DBC861 /* DirectoryLookup.h */; };
 		DE3451580AEC176100DBC861 /* MacroExpander.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE3451570AEC176100DBC861 /* MacroExpander.cpp */; };
 		DE3452410AEF1A2D00DBC861 /* Stmt.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE3452400AEF1A2D00DBC861 /* Stmt.cpp */; };
+		DE3452810AEF1B1800DBC861 /* Stmt.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE3452800AEF1B1800DBC861 /* Stmt.h */; };
 		DE46BF280AE0A82D00CC047C /* TargetInfo.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE46BF270AE0A82D00CC047C /* TargetInfo.h */; };
 		DE5932D10AD60FF400BC794C /* clang.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE5932CD0AD60FF400BC794C /* clang.cpp */; };
 		DE5932D20AD60FF400BC794C /* clang.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE5932CE0AD60FF400BC794C /* clang.h */; };
@@ -111,13 +112,14 @@
 				DE46BF280AE0A82D00CC047C /* TargetInfo.h in CopyFiles */,
 				DE344AB80AE5DF6D00DBC861 /* HeaderSearch.h in CopyFiles */,
 				DE3450D70AEB543100DBC861 /* DirectoryLookup.h in CopyFiles */,
+				DE3452810AEF1B1800DBC861 /* Stmt.h in CopyFiles */,
 			);
 			runOnlyForDeploymentPostprocessing = 1;
 		};
 /* End PBXCopyFilesBuildPhase section */
 
 /* Begin PBXFileReference section */
-		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
+		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
 		DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };
 		DE06BECA0A854E4B0050E87E /* Scope.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Scope.h; path = clang/Parse/Scope.h; sourceTree = "<group>"; };
 		DE06CC170A899E110050E87E /* Statement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Statement.cpp; path = Parse/Statement.cpp; sourceTree = "<group>"; };
@@ -137,6 +139,7 @@
 		DE3450D60AEB543100DBC861 /* DirectoryLookup.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DirectoryLookup.h; sourceTree = "<group>"; };
 		DE3451570AEC176100DBC861 /* MacroExpander.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = MacroExpander.cpp; sourceTree = "<group>"; };
 		DE3452400AEF1A2D00DBC861 /* Stmt.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Stmt.cpp; path = AST/Stmt.cpp; sourceTree = "<group>"; };
+		DE3452800AEF1B1800DBC861 /* Stmt.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Stmt.h; path = clang/AST/Stmt.h; sourceTree = "<group>"; };
 		DE46BF270AE0A82D00CC047C /* TargetInfo.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = TargetInfo.h; sourceTree = "<group>"; };
 		DE5932CD0AD60FF400BC794C /* clang.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = clang.cpp; path = Driver/clang.cpp; sourceTree = "<group>"; };
 		DE5932CE0AD60FF400BC794C /* clang.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = clang.h; path = Driver/clang.h; sourceTree = "<group>"; };
@@ -279,6 +282,7 @@
 				DEC8DABF0A94402500353FCA /* ASTStreamer.h */,
 				DEC8D9900A9433CD00353FCA /* Decl.h */,
 				DE0FCA620A95859D00248FD5 /* Expr.h */,
+				DE3452800AEF1B1800DBC861 /* Stmt.h */,
 			);
 			name = AST;
 			sourceTree = "<group>";

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

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/AST.h (original)
+++ cfe/cfe/trunk/include/clang/AST/AST.h Wed Jul 11 11:27:05 2007
@@ -17,5 +17,7 @@
 // This header exports all AST interfaces.
 #include "clang/AST/ASTStreamer.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Expr.h"
 
 #endif

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=39046&r1=39045&r2=39046&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Stmt.h Wed Jul 11 11:27:05 2007
@@ -19,6 +19,7 @@
 
 namespace llvm {
 namespace clang {
+  class Expr;
   
 /// Stmt - This represents one statement.  Note that statements are modelled as
 /// subclasses of exprs so that 
@@ -36,21 +37,31 @@
   virtual void dump_impl() const = 0;
 };
 
-//===----------------------------------------------------------------------===//
-// Primary Expressions.
-//===----------------------------------------------------------------------===//
-
-#if 0
-/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
-/// enum, etc.
-class DeclRefExpr : public Stmt {
-  // TODO: Union with the decl when resolved.
-  Decl &D;
+/// CompoundStmt - This represents a group of statements like { stmt stmt }.
+///
+class CompoundStmt : public Stmt {
+  SmallVector<Stmt*, 16> Body;
 public:
-  DeclRef(Decl &d) : D(d) {}
+  CompoundStmt(Stmt **StmtStart, unsigned NumStmts)
+    : Body(StmtStart, StmtStart+NumStmts) {}
+  
   virtual void dump_impl() const;
 };
-#endif
+
+
+
+
+/// ReturnStmt - This represents a return, optionally of an expression.
+///
+class ReturnStmt : public Stmt {
+  Expr *RetExpr;
+public:
+  ReturnStmt(Expr *E = 0) : RetExpr(E) {}
+  
+  virtual void dump_impl() const;
+};
+
+
   
 }  // end namespace clang
 }  // end namespace llvm





More information about the cfe-commits mailing list