[cfe-commits] r39119 - in /cfe/cfe/trunk: AST/Sema.cpp AST/Sema.h AST/StmtPrinter.cpp Sema/Sema.cpp Sema/Sema.h include/clang/AST/Stmt.h include/clang/AST/StmtNodes.def

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


Author: sabre
Date: Wed Jul 11 11:27:42 2007
New Revision: 39119

URL: http://llvm.org/viewvc/llvm-project?rev=39119&view=rev
Log:
implement AST node for switch stmt

Modified:
    cfe/cfe/trunk/AST/Sema.cpp
    cfe/cfe/trunk/AST/Sema.h
    cfe/cfe/trunk/AST/StmtPrinter.cpp
    cfe/cfe/trunk/Sema/Sema.cpp
    cfe/cfe/trunk/Sema/Sema.h
    cfe/cfe/trunk/include/clang/AST/Stmt.h
    cfe/cfe/trunk/include/clang/AST/StmtNodes.def

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

==============================================================================
--- cfe/cfe/trunk/AST/Sema.cpp (original)
+++ cfe/cfe/trunk/AST/Sema.cpp Wed Jul 11 11:27:42 2007
@@ -105,6 +105,11 @@
                         StmtTy *ElseVal) {
   return new IfStmt((Expr*)CondVal, (Stmt*)ThenVal, (Stmt*)ElseVal);
 }
+Action::StmtResult
+ASTBuilder::ParseSwitchStmt(SourceLocation SwitchLoc, ExprTy *Cond,
+                            StmtTy *Body) {
+  return new SwitchStmt((Expr*)Cond, (Stmt*)Body);
+}
 
 Action::StmtResult 
 ASTBuilder::ParseForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, 

Modified: cfe/cfe/trunk/AST/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.h?rev=39119&r1=39118&r2=39119&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Sema.h (original)
+++ cfe/cfe/trunk/AST/Sema.h Wed Jul 11 11:27:42 2007
@@ -60,7 +60,8 @@
   virtual StmtResult ParseIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
                                  StmtTy *ThenVal, SourceLocation ElseLoc,
                                  StmtTy *ElseVal);
-  
+  virtual StmtResult ParseSwitchStmt(SourceLocation SwitchLoc, ExprTy *Cond,
+                                     StmtTy *Body);
   virtual StmtResult ParseWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
                                     StmtTy *Body);
   virtual StmtResult ParseDoStmt(SourceLocation DoLoc, StmtTy *Body,

Modified: cfe/cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/StmtPrinter.cpp?rev=39119&r1=39118&r2=39119&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/cfe/trunk/AST/StmtPrinter.cpp Wed Jul 11 11:27:42 2007
@@ -76,27 +76,9 @@
     }
     
     virtual void VisitStmt(Stmt *Node);
-    virtual void VisitCompoundStmt(CompoundStmt *Node);
-    virtual void VisitIfStmt(IfStmt *Node);
-    virtual void VisitWhileStmt(WhileStmt *Node);
-    virtual void VisitDoStmt(DoStmt *Node);
-    virtual void VisitForStmt(ForStmt *Node);
-    virtual void VisitReturnStmt(ReturnStmt *Node);
-
-    virtual void VisitExpr(Expr *Node);
-    virtual void VisitDeclRefExpr(DeclRefExpr *Node);
-    virtual void VisitIntegerConstant(IntegerConstant *Node);
-    virtual void VisitFloatingConstant(FloatingConstant *Node);
-    virtual void VisitStringExpr(StringExpr *Node);
-    virtual void VisitParenExpr(ParenExpr *Node);
-    virtual void VisitUnaryOperator(UnaryOperator *Node);
-    virtual void VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node);
-    virtual void VisitArraySubscriptExpr(ArraySubscriptExpr *Node);
-    virtual void VisitCallExpr(CallExpr *Node);
-    virtual void VisitMemberExpr(MemberExpr *Node);
-    virtual void VisitCastExpr(CastExpr *Node);
-    virtual void VisitBinaryOperator(BinaryOperator *Node);
-    virtual void VisitConditionalOperator(ConditionalOperator *Node);
+#define STMT(CLASS, PARENT) \
+    virtual void Visit##CLASS(CLASS *Node);
+#include "clang/AST/StmtNodes.def"
   };
 }
 
@@ -130,6 +112,13 @@
   }
 }
 
+void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
+  Indent() << "switch (";
+  PrintExpr(Node->getCond());
+  OS << ")\n";
+  PrintStmt(Node->getBody());
+}
+
 void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
   Indent() << "while (";
   PrintExpr(Node->getCond());

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

==============================================================================
--- cfe/cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/cfe/trunk/Sema/Sema.cpp Wed Jul 11 11:27:42 2007
@@ -105,6 +105,11 @@
                         StmtTy *ElseVal) {
   return new IfStmt((Expr*)CondVal, (Stmt*)ThenVal, (Stmt*)ElseVal);
 }
+Action::StmtResult
+ASTBuilder::ParseSwitchStmt(SourceLocation SwitchLoc, ExprTy *Cond,
+                            StmtTy *Body) {
+  return new SwitchStmt((Expr*)Cond, (Stmt*)Body);
+}
 
 Action::StmtResult 
 ASTBuilder::ParseForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, 

Modified: cfe/cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.h?rev=39119&r1=39118&r2=39119&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/Sema.h (original)
+++ cfe/cfe/trunk/Sema/Sema.h Wed Jul 11 11:27:42 2007
@@ -60,7 +60,8 @@
   virtual StmtResult ParseIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
                                  StmtTy *ThenVal, SourceLocation ElseLoc,
                                  StmtTy *ElseVal);
-  
+  virtual StmtResult ParseSwitchStmt(SourceLocation SwitchLoc, ExprTy *Cond,
+                                     StmtTy *Body);
   virtual StmtResult ParseWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
                                     StmtTy *Body);
   virtual StmtResult ParseDoStmt(SourceLocation DoLoc, StmtTy *Body,

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=39119&r1=39118&r2=39119&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Stmt.h Wed Jul 11 11:27:42 2007
@@ -72,6 +72,22 @@
   virtual void visit(StmtVisitor &Visitor);
 };
 
+/// SwitchStmt - This represents a 'switch' stmt.
+///
+class SwitchStmt : public Stmt {
+  Expr *Cond;
+  Stmt *Body;
+public:
+  SwitchStmt(Expr *cond, Stmt *body)
+    : Cond(cond), Body(body) {}
+  
+  Expr *getCond() { return Cond; }
+  Stmt *getBody() { return Body; }
+  
+  virtual void visit(StmtVisitor &Visitor);
+};
+
+
 /// WhileStmt - This represents a 'while' stmt.
 ///
 class WhileStmt : public Stmt {

Modified: cfe/cfe/trunk/include/clang/AST/StmtNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/StmtNodes.def?rev=39119&r1=39118&r2=39119&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/cfe/trunk/include/clang/AST/StmtNodes.def Wed Jul 11 11:27:42 2007
@@ -14,6 +14,7 @@
 // Normal Statements.
 STMT(CompoundStmt, Stmt)
 STMT(IfStmt      , Stmt)
+STMT(SwitchStmt  , Stmt)
 STMT(WhileStmt   , Stmt)
 STMT(DoStmt      , Stmt)
 STMT(ForStmt     , Stmt)





More information about the cfe-commits mailing list