Ejemplo n.º 1
0
 // If ---
 // Exp e;
 // Stmt s1, s2;
 public IrStmt visit(AstIf n)
 {
     IrName alt = new IrName();
     IrStmtList sl = new IrStmtList();
     IrExp exp = n.e.accept(this);
     sl.add(new IrCJump(IrCJump.OP.EQ, exp, cZero, alt));
     sl.add(n.s1.accept(this));
     if (n.s2 == null)
     {
         sl.add(new IrLabel(alt));
     }
     else
     {
         IrName done = new IrName();
         sl.add(new IrJump(done));
         sl.add(new IrLabel(alt));
         sl.add(n.s2.accept(this));
         sl.add(new IrLabel(done));
     }
     return sl;
 }
Ejemplo n.º 2
0
 public void visit(AstIf n)
 {
 }
Ejemplo n.º 3
0
 /* throws ParseException */
 /* final */
 public static AstStmt astStmt()
 {
     AstExp e1, e2; AstStmt s, s1, s2; AstExpList el; AstStmtList sl;
     jj_consume_token(AstRegExpId.kw56);
     switch ((jj_ntk == AstRegExpId.UNDEFINED)?jj_ntk_fn():jj_ntk) {
     case AstRegExpId.kwBlock:
       jj_consume_token(AstRegExpId.kwBlock);
       sl = astStmtList();
                                s = new AstBlock(sl);
       break;
     case AstRegExpId.kwAssign:
       jj_consume_token(AstRegExpId.kwAssign);
       e1 = astExp();
       e2 = astExp();
                                s = new AstAssign(e1,e2);
       break;
     case AstRegExpId.kwCallStmt:
       jj_consume_token(AstRegExpId.kwCallStmt);
       e1 = astExp();
       e2 = astExp();
       el = astExpList();
                                s = new AstCallStmt(e1,(AstId)e2,el);
       break;
     case AstRegExpId.kwIf:
       jj_consume_token(AstRegExpId.kwIf);
       e1 = astExp();
       s1 = astStmt();
       s2 = astStmt();
                                s = new AstIf(e1,s1,s2);
       break;
     case AstRegExpId.kwWhile:
       jj_consume_token(AstRegExpId.kwWhile);
       e1 = astExp();
       s1 = astStmt();
                                s = new AstWhile(e1,s1);
       break;
     case AstRegExpId.kwPrint:
       jj_consume_token(AstRegExpId.kwPrint);
       e1 = astExp();
                                s = new AstPrint(e1);
       break;
     case AstRegExpId.kwReturn:
       jj_consume_token(AstRegExpId.kwReturn);
       e1 = astExp();
                                s = new AstReturn(e1);
       break;
     case AstRegExpId.kwNullStmt:
       jj_consume_token(AstRegExpId.kwNullStmt);
                                s = null;
       break;
     default:
       jj_la1[8] = jj_gen;
       jj_consume_token(AstRegExpId.UNDEFINED);
       throw new AstParseException();
     }
     jj_consume_token(AstRegExpId.kw57);
     {if (true) return s;}
     throw new Error("Missing return statement in function");
 }
Ejemplo n.º 4
0
 /* throws Exception */
 // If ---
 // Exp e;
 // Stmt s1, s2;
 public void visit(AstIf n)
 {
     AstType t = n.e.accept(this);
     if (!isBoolType(t))
         throw new TypeException("Test of If is not of bool type: " + t);
     n.s1.accept(this);
     if (n.s2 != null)
         n.s2.accept(this);
 }