[cfe-commits] r39045 - in /cfe/cfe/trunk: AST/Expr.cpp AST/Sema.cpp AST/Stmt.cpp Sema/Sema.cpp clang.xcodeproj/project.pbxproj 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:05 PDT 2007


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

URL: http://llvm.org/viewvc/llvm-project?rev=39045&view=rev
Log:
Add new Stmt class

Added:
    cfe/cfe/trunk/AST/Stmt.cpp   (with props)
    cfe/cfe/trunk/include/clang/AST/Stmt.h   (with props)
Modified:
    cfe/cfe/trunk/AST/Expr.cpp
    cfe/cfe/trunk/AST/Sema.cpp
    cfe/cfe/trunk/Sema/Sema.cpp
    cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/cfe/trunk/include/clang/AST/Expr.h

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

==============================================================================
--- cfe/cfe/trunk/AST/Expr.cpp (original)
+++ cfe/cfe/trunk/AST/Expr.cpp Wed Jul 11 11:27:05 2007
@@ -17,21 +17,11 @@
 using namespace llvm;
 using namespace clang;
 
-void Expr::dump() const {
-  if (this == 0) {
-    std::cerr << "<null expr>";
-    return;
-  }
-  std::cerr << "(";
-  dump_impl();
-  std::cerr << ")";
-}
-
 //===----------------------------------------------------------------------===//
 // Primary Expressions.
 //===----------------------------------------------------------------------===//
 
-void DeclExpr::dump_impl() const {
+void DeclRefExpr::dump_impl() const {
   std::cerr << "x";
 }
 

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

==============================================================================
--- cfe/cfe/trunk/AST/Sema.cpp (original)
+++ cfe/cfe/trunk/AST/Sema.cpp Wed Jul 11 11:27:05 2007
@@ -176,7 +176,7 @@
   case tok::identifier: {
     // Could be enum-constant or decl.
     //Tok.getIdentifierInfo()
-    return new DeclExpr(*(Decl*)0);
+    return new DeclRefExpr(*(Decl*)0);
   }
     
   case tok::char_constant:     // constant: character-constant
@@ -184,7 +184,7 @@
   case tok::kw___FUNCTION__:   // primary-expression: __FUNCTION__ [GNU]
   case tok::kw___PRETTY_FUNCTION__:  // primary-expression: __P..Y_F..N__ [GNU]
     //assert(0 && "FIXME: Unimp so far!");
-    return new DeclExpr(*(Decl*)0);
+    return new DeclRefExpr(*(Decl*)0);
   }
 }
 

Added: cfe/cfe/trunk/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Stmt.cpp?rev=39045&view=auto

==============================================================================
--- cfe/cfe/trunk/AST/Stmt.cpp (added)
+++ cfe/cfe/trunk/AST/Stmt.cpp Wed Jul 11 11:27:05 2007
@@ -0,0 +1,29 @@
+//===--- Stmt.cpp - Statement AST Node Implementation ---------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the Stmt class and statement subclasses.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Expr.h"
+#include <iostream>
+using namespace llvm;
+using namespace clang;
+
+void Stmt::dump() const {
+  if (this == 0) {
+    std::cerr << "<null>";
+    return;
+  }
+  bool isExpr = dynamic_cast<const Expr*>(this) != 0;
+  if (isExpr) std::cerr << "(";
+  dump_impl();
+  if (isExpr) std::cerr << ")";
+}

Propchange: cfe/cfe/trunk/AST/Stmt.cpp

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/cfe/trunk/AST/Stmt.cpp

------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

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

==============================================================================
--- cfe/cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/cfe/trunk/Sema/Sema.cpp Wed Jul 11 11:27:05 2007
@@ -176,7 +176,7 @@
   case tok::identifier: {
     // Could be enum-constant or decl.
     //Tok.getIdentifierInfo()
-    return new DeclExpr(*(Decl*)0);
+    return new DeclRefExpr(*(Decl*)0);
   }
     
   case tok::char_constant:     // constant: character-constant
@@ -184,7 +184,7 @@
   case tok::kw___FUNCTION__:   // primary-expression: __FUNCTION__ [GNU]
   case tok::kw___PRETTY_FUNCTION__:  // primary-expression: __P..Y_F..N__ [GNU]
     //assert(0 && "FIXME: Unimp so far!");
-    return new DeclExpr(*(Decl*)0);
+    return new DeclRefExpr(*(Decl*)0);
   }
 }
 

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

==============================================================================
--- cfe/cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/cfe/trunk/clang.xcodeproj/project.pbxproj Wed Jul 11 11:27:05 2007
@@ -25,6 +25,7 @@
 		DE344B540AE5E46C00DBC861 /* HeaderSearch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE344B530AE5E46C00DBC861 /* HeaderSearch.cpp */; };
 		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 */; };
 		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 */; };
@@ -116,7 +117,7 @@
 /* End PBXCopyFilesBuildPhase section */
 
 /* Begin PBXFileReference section */
-		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
+		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; 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>"; };
@@ -135,6 +136,7 @@
 		DE344B530AE5E46C00DBC861 /* HeaderSearch.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = HeaderSearch.cpp; sourceTree = "<group>"; };
 		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>"; };
 		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>"; };
@@ -287,6 +289,7 @@
 				DEC8DAAC0A94400300353FCA /* ASTStreamer.cpp */,
 				DEC8D9B50A9434FA00353FCA /* Builder.cpp */,
 				DE0FCB330A9C21F100248FD5 /* Expr.cpp */,
+				DE3452400AEF1A2D00DBC861 /* Stmt.cpp */,
 			);
 			name = AST;
 			sourceTree = "<group>";
@@ -439,6 +442,7 @@
 				DED62ABB0AE2EDF1001E80A4 /* Decl.cpp in Sources */,
 				DE344B540AE5E46C00DBC861 /* HeaderSearch.cpp in Sources */,
 				DE3451580AEC176100DBC861 /* MacroExpander.cpp in Sources */,
+				DE3452410AEF1A2D00DBC861 /* Stmt.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

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

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Expr.h Wed Jul 11 11:27:05 2007
@@ -14,8 +14,7 @@
 #ifndef LLVM_CLANG_AST_EXPR_H
 #define LLVM_CLANG_AST_EXPR_H
 
-#include "clang/Basic/SourceLocation.h"
-#include "llvm/ADT/SmallVector.h"
+#include "clang/AST/Stmt.h"
 
 namespace llvm {
 namespace clang {
@@ -23,32 +22,29 @@
   class Decl;
   class Type;
   
-/// Expr - This represents one expression etc.  
+/// Expr - This represents one expression.  Note that Expr's are subclasses of
+/// Stmt.  This allows an expression to be transparently used any place a Stmt
+/// is required.
 ///
-class Expr {
-  /// Type.
+class Expr : public Stmt {
+  /// TODO: Type.
 public:
   Expr() {}
-  virtual ~Expr() {}
+  ~Expr() {}
   
-  // FIXME: Change to non-virtual method that uses visitor pattern to do this.
-  void dump() const;
-  
-private:
-  virtual void dump_impl() const = 0;
 };
 
 //===----------------------------------------------------------------------===//
 // Primary Expressions.
 //===----------------------------------------------------------------------===//
 
-/// DeclExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
+/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
 /// enum, etc.
-class DeclExpr : public Expr {
+class DeclRefExpr : public Expr {
   // TODO: Union with the decl when resolved.
   Decl &D;
 public:
-  DeclExpr(Decl &d) : D(d) {}
+  DeclRefExpr(Decl &d) : D(d) {}
   virtual void dump_impl() const;
 };
 

Added: cfe/cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Stmt.h?rev=39045&view=auto

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Stmt.h (added)
+++ cfe/cfe/trunk/include/clang/AST/Stmt.h Wed Jul 11 11:27:05 2007
@@ -0,0 +1,58 @@
+//===--- Stmt.h - Classes for representing statements -----------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file defines the Stmt interface and subclasses.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_AST_STMT_H
+#define LLVM_CLANG_AST_STMT_H
+
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/SmallVector.h"
+
+namespace llvm {
+namespace clang {
+  
+/// Stmt - This represents one statement.  Note that statements are modelled as
+/// subclasses of exprs so that 
+///
+class Stmt {
+  /// Type.
+public:
+  Stmt() {}
+  virtual ~Stmt() {}
+  
+  // FIXME: Change to non-virtual method that uses visitor pattern to do this.
+  void dump() const;
+  
+private:
+  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;
+public:
+  DeclRef(Decl &d) : D(d) {}
+  virtual void dump_impl() const;
+};
+#endif
+  
+}  // end namespace clang
+}  // end namespace llvm
+
+#endif

Propchange: cfe/cfe/trunk/include/clang/AST/Stmt.h

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/cfe/trunk/include/clang/AST/Stmt.h

------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision





More information about the cfe-commits mailing list