[cfe-commits] r39120 - 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:43 PDT 2007
Author: sabre
Date: Wed Jul 11 11:27:43 2007
New Revision: 39120
URL: http://llvm.org/viewvc/llvm-project?rev=39120&view=rev
Log:
Add ast node support for case/default/label stmts.
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=39120&r1=39119&r2=39120&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Sema.cpp (original)
+++ cfe/cfe/trunk/AST/Sema.cpp Wed Jul 11 11:27:43 2007
@@ -99,6 +99,25 @@
return 0; // {} -> ;
}
+Action::StmtResult
+ASTBuilder::ParseCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
+ SourceLocation DotDotDotLoc, ExprTy *RHSVal,
+ SourceLocation ColonLoc, StmtTy *SubStmt) {
+ return new CaseStmt((Expr*)LHSVal, (Expr*)RHSVal, (Stmt*)SubStmt);
+}
+
+Action::StmtResult
+ASTBuilder::ParseDefaultStmt(SourceLocation DefaultLoc,
+ SourceLocation ColonLoc, StmtTy *SubStmt) {
+ return new DefaultStmt((Stmt*)SubStmt);
+}
+
+Action::StmtResult
+ASTBuilder::ParseLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
+ SourceLocation ColonLoc, StmtTy *SubStmt) {
+ return new LabelStmt(II, (Stmt*)SubStmt);
+}
+
Action::StmtResult
ASTBuilder::ParseIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
StmtTy *ThenVal, SourceLocation ElseLoc,
Modified: cfe/cfe/trunk/AST/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.h?rev=39120&r1=39119&r2=39120&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Sema.h (original)
+++ cfe/cfe/trunk/AST/Sema.h Wed Jul 11 11:27:43 2007
@@ -56,7 +56,13 @@
virtual StmtResult ParseExprStmt(ExprTy *Expr) {
return Expr; // Exprs are Stmts.
}
-
+ virtual StmtResult ParseCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
+ SourceLocation DotDotDotLoc, ExprTy *RHSVal,
+ SourceLocation ColonLoc, StmtTy *SubStmt);
+ virtual StmtResult ParseDefaultStmt(SourceLocation DefaultLoc,
+ SourceLocation ColonLoc, StmtTy *SubStmt);
+ virtual StmtResult ParseLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
+ SourceLocation ColonLoc, StmtTy *SubStmt);
virtual StmtResult ParseIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
StmtTy *ThenVal, SourceLocation ElseLoc,
StmtTy *ElseVal);
Modified: cfe/cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/StmtPrinter.cpp?rev=39120&r1=39119&r2=39120&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/cfe/trunk/AST/StmtPrinter.cpp Wed Jul 11 11:27:43 2007
@@ -13,6 +13,7 @@
#include "clang/AST/StmtVisitor.h"
#include "clang/AST/Expr.h"
+#include "clang/Lex/IdentifierTable.h"
#include "llvm/Support/Compiler.h"
#include <iostream>
using namespace llvm;
@@ -100,6 +101,31 @@
Indent() << "}\n";
}
+void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
+ Indent() << "case ";
+ PrintExpr(Node->getLHS());
+ if (Node->getRHS()) {
+ OS << " ... ";
+ PrintExpr(Node->getRHS());
+ }
+ OS << ":\n";
+
+ // FIXME: This recursively indents consequtive cases.
+ PrintStmt(Node->getSubStmt());
+}
+
+void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
+ Indent() << "default:\n";
+ // FIXME: This recursively indents consequtive cases.
+ PrintStmt(Node->getSubStmt());
+}
+
+void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
+ Indent() << Node->getLabel()->getName() << ":\n";
+ // FIXME: This recursively indents consequtive cases.
+ PrintStmt(Node->getSubStmt());
+}
+
void StmtPrinter::VisitIfStmt(IfStmt *If) {
Indent() << "if (";
PrintExpr(If->getCond());
Modified: cfe/cfe/trunk/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.cpp?rev=39120&r1=39119&r2=39120&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/cfe/trunk/Sema/Sema.cpp Wed Jul 11 11:27:43 2007
@@ -99,6 +99,25 @@
return 0; // {} -> ;
}
+Action::StmtResult
+ASTBuilder::ParseCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
+ SourceLocation DotDotDotLoc, ExprTy *RHSVal,
+ SourceLocation ColonLoc, StmtTy *SubStmt) {
+ return new CaseStmt((Expr*)LHSVal, (Expr*)RHSVal, (Stmt*)SubStmt);
+}
+
+Action::StmtResult
+ASTBuilder::ParseDefaultStmt(SourceLocation DefaultLoc,
+ SourceLocation ColonLoc, StmtTy *SubStmt) {
+ return new DefaultStmt((Stmt*)SubStmt);
+}
+
+Action::StmtResult
+ASTBuilder::ParseLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
+ SourceLocation ColonLoc, StmtTy *SubStmt) {
+ return new LabelStmt(II, (Stmt*)SubStmt);
+}
+
Action::StmtResult
ASTBuilder::ParseIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
StmtTy *ThenVal, SourceLocation ElseLoc,
Modified: cfe/cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.h?rev=39120&r1=39119&r2=39120&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/Sema.h (original)
+++ cfe/cfe/trunk/Sema/Sema.h Wed Jul 11 11:27:43 2007
@@ -56,7 +56,13 @@
virtual StmtResult ParseExprStmt(ExprTy *Expr) {
return Expr; // Exprs are Stmts.
}
-
+ virtual StmtResult ParseCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
+ SourceLocation DotDotDotLoc, ExprTy *RHSVal,
+ SourceLocation ColonLoc, StmtTy *SubStmt);
+ virtual StmtResult ParseDefaultStmt(SourceLocation DefaultLoc,
+ SourceLocation ColonLoc, StmtTy *SubStmt);
+ virtual StmtResult ParseLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
+ SourceLocation ColonLoc, StmtTy *SubStmt);
virtual StmtResult ParseIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
StmtTy *ThenVal, SourceLocation ElseLoc,
StmtTy *ElseVal);
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=39120&r1=39119&r2=39120&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Stmt.h Wed Jul 11 11:27:43 2007
@@ -21,6 +21,7 @@
namespace llvm {
namespace clang {
class Expr;
+ class IdentifierInfo;
class StmtVisitor;
/// Stmt - This represents one statement.
@@ -52,6 +53,45 @@
virtual void visit(StmtVisitor &Visitor);
};
+class CaseStmt : public Stmt {
+ Expr *LHSVal;
+ Expr *RHSVal; // Non-null for GNU "case 1 ... 4" extension
+ Stmt *SubStmt;
+public:
+ CaseStmt(Expr *lhs, Expr *rhs, Stmt *substmt)
+ : LHSVal(lhs), RHSVal(rhs), SubStmt(substmt) {}
+
+ Expr *getLHS() { return LHSVal; }
+ Expr *getRHS() { return RHSVal; }
+ Stmt *getSubStmt() { return SubStmt; }
+
+ virtual void visit(StmtVisitor &Visitor);
+};
+
+class DefaultStmt : public Stmt {
+ Stmt *SubStmt;
+public:
+ DefaultStmt(Stmt *substmt) : SubStmt(substmt) {}
+
+ Stmt *getSubStmt() { return SubStmt; }
+
+ virtual void visit(StmtVisitor &Visitor);
+};
+
+class LabelStmt : public Stmt {
+ IdentifierInfo *Label;
+ Stmt *SubStmt;
+public:
+ LabelStmt(IdentifierInfo *label, Stmt *substmt)
+ : Label(label), SubStmt(substmt) {}
+
+ IdentifierInfo *getLabel() { return Label; }
+ Stmt *getSubStmt() { return SubStmt; }
+
+ virtual void visit(StmtVisitor &Visitor);
+};
+
+
/// IfStmt - This represents an if/then/else.
///
class IfStmt : 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=39120&r1=39119&r2=39120&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/cfe/trunk/include/clang/AST/StmtNodes.def Wed Jul 11 11:27:43 2007
@@ -13,6 +13,9 @@
// Normal Statements.
STMT(CompoundStmt, Stmt)
+STMT(CaseStmt , Stmt)
+STMT(DefaultStmt , Stmt)
+STMT(LabelStmt , Stmt)
STMT(IfStmt , Stmt)
STMT(SwitchStmt , Stmt)
STMT(WhileStmt , Stmt)
More information about the cfe-commits
mailing list