Add ast node support for case/default/label stmts.
llvm-svn: 39120
This commit is contained in:
parent
f2174b633b
commit
6c0ff13761
|
@ -99,6 +99,25 @@ ASTBuilder::ParseCompoundStmt(SourceLocation L, SourceLocation R,
|
|||
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,
|
||||
|
|
|
@ -56,7 +56,13 @@ public:
|
|||
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);
|
||||
|
|
|
@ -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 @@ void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
|
|||
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());
|
||||
|
|
|
@ -99,6 +99,25 @@ ASTBuilder::ParseCompoundStmt(SourceLocation L, SourceLocation R,
|
|||
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,
|
||||
|
|
|
@ -56,7 +56,13 @@ public:
|
|||
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);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
namespace llvm {
|
||||
namespace clang {
|
||||
class Expr;
|
||||
class IdentifierInfo;
|
||||
class StmtVisitor;
|
||||
|
||||
/// Stmt - This represents one statement.
|
||||
|
@ -52,6 +53,45 @@ public:
|
|||
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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue