Skip to content

Commit

Permalink
pp2git add ast_expr.cc ast_expr.h ast_stmt.cc ast_stmt.h parser.y
Browse files Browse the repository at this point in the history
  • Loading branch information
mzweilin committed Oct 26, 2013
1 parent ce058e4 commit 27421c3
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 97 deletions.
10 changes: 9 additions & 1 deletion wx4ed/src/pp2/ast_expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,18 @@ CompoundExpr::CompoundExpr(Operator *o, Expr *r)
(right=r)->SetParent(this);
}

CompoundExpr::CompoundExpr(Expr *l, Operator *o)
: Expr(Join(l->GetLocation(), o->GetLocation())) {
Assert(l != NULL && o != NULL);
right = NULL;
(op=o)->SetParent(this);
(left=l)->SetParent(this);
}

void CompoundExpr::PrintChildren(int indentLevel) {
if (left) left->Print(indentLevel+1);
op->Print(indentLevel+1);
right->Print(indentLevel+1);
if (right) right->Print(indentLevel+1);
}


Expand Down
10 changes: 9 additions & 1 deletion wx4ed/src/pp2/ast_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,18 @@ class CompoundExpr : public Expr

public:
CompoundExpr(Expr *lhs, Operator *op, Expr *rhs); // for binary
CompoundExpr(Operator *op, Expr *rhs); // for unary
CompoundExpr(Operator *op, Expr *rhs); // for unary
CompoundExpr(Expr *lhs, Operator *op); // for postfix
void PrintChildren(int indentLevel);
};

class PostfixExpr : public CompoundExpr
{
public:
PostfixExpr(Expr *lhs, Operator *op) : CompoundExpr(lhs,op) {}
const char *GetPrintNameForNode() { return "PostfixExpr"; }
};

class ArithmeticExpr : public CompoundExpr
{
public:
Expand Down
34 changes: 34 additions & 0 deletions wx4ed/src/pp2/ast_stmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,37 @@ void PrintStmt::PrintChildren(int indentLevel) {
}


SwitchStmt::SwitchStmt(Expr *e, List<CaseStmt*> *s, DefaultStmt *d) {
Assert(e != NULL && s != NULL && d != NULL);
(expr=e)->SetParent(this);
(caseStmts=s)->SetParentAll(this);
(defaultStmt=d)->SetParent(this);
}

void SwitchStmt::PrintChildren(int indentLevel) {
expr->Print(indentLevel+1);
caseStmts->PrintAll(indentLevel+1);
defaultStmt->Print(indentLevel+1);
}

SwitchStmt::CaseStmt::CaseStmt(Expr *e, List<Stmt*> *s) {
Assert(e != NULL && s != NULL);
(intConst=e)->SetParent(this);
(caseBody=s)->SetParentAll(this);
}

void SwitchStmt::CaseStmt::PrintChildren(int indentLevel) {
intConst->Print(indentLevel+1);
caseBody->PrintAll(indentLevel+1);
}

SwitchStmt::DefaultStmt::DefaultStmt(List<Stmt*> *s) {
Assert(s != NULL);
(defaultBody=s)->SetParentAll(this);
}

void SwitchStmt::DefaultStmt::PrintChildren(int indentLevel) {
defaultBody->PrintAll(indentLevel+1);
}


38 changes: 38 additions & 0 deletions wx4ed/src/pp2/ast_stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,44 @@ class BreakStmt : public Stmt
const char *GetPrintNameForNode() { return "BreakStmt"; }
};

class SwitchStmt : public Stmt
{
public:
class CaseStmt : public Stmt
{
protected:
Expr *intConst;
List<Stmt*> *caseBody;

public:
CaseStmt(Expr *intConst, List<Stmt*> *caseBody);
const char *GetPrintNameForNode() { return "Case"; }
void PrintChildren(int indentLevel);
};

class DefaultStmt : public Stmt
{
protected:
List<Stmt*> *defaultBody;

public:
DefaultStmt(List<Stmt*> *defaultBody);
const char *GetPrintNameForNode() { return "Default"; }
void PrintChildren(int indentLevel);
};

protected:
Expr *expr;
List<CaseStmt*> *caseStmts;
DefaultStmt *defaultStmt;

public:
SwitchStmt(Expr *expr, List<CaseStmt*> *caseStmts,
DefaultStmt *defaultStmt);
const char *GetPrintNameForNode() { return "SwitchStmt"; }
void PrintChildren(int indentLevel);
};

class ReturnStmt : public Stmt
{
protected:
Expand Down
Loading

0 comments on commit 27421c3

Please sign in to comment.