public void genRepeatExpresion(ILCodeGen cg, ArrayList exp, uint scope, string proc_actual, Emit.Label ini, Emit.Label body, Emit.Label fin) { int tipo = 0; Symbol s = null; bool hasAnd = hasToGenAndLabel(exp); ReorderWHILEExpression(exp, proc_actual, scope); cg.MarkLabel(ini); foreach (Expr e in exp) { if (e is IntLiteral) { IntLiteral lit = (IntLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.INT, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is RealLiteral) { RealLiteral lit = (RealLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.REAL, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is BoolLiteral) { BoolLiteral lit = (BoolLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.BOOLEAN, 0, null); cg.loadVariable(s, false, scope, proc_actual); if (lit.Value == "true") { cg.genFalseStatement(body); } else { cg.genTrueStatement(body); } } else if (e is StringLiteral) { StringLiteral lit = (StringLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.STRING, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is CharLiteral) { CharLiteral lit = (CharLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.CHAR, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is Variable) { Variable var = (Variable)e; if (scope == 0) { s = symtab.getSymbol(var.Value); } else { s = symtab.getSymbol(proc_actual, var.Value, ref tipo); } if (s != null) { if (tipo == 1) { Param p = (Param)s; cg.loadVariable(s, p.Reference, scope, proc_actual); } else { cg.loadVariable(s, false, scope, proc_actual); } } tipo = 0; if (s.Type.toString() == "BOOLEAN") { if (var.Tipo == "NOT") { cg.genTrueStatement(body); } else { cg.genFalseStatement(body); } } } else if (e is Function) { ExpFunction ex = (ExpFunction)e; } else if (e is EQExpresion) { if (hasAnd) { cg.genDFStatement(fin); } else { cg.genDFStatement(body); } hasAnd = false; } else if (e is DFExpresion) { if (hasAnd) { cg.genEQStatement(fin); } else { cg.genEQStatement(body); } hasAnd = false; } else if (e is GEExpresion) { if (hasAnd) { cg.genLTStatement(fin); } else { cg.genLTStatement(body); } hasAnd = false; } else if (e is GTExpresion) { if (hasAnd) { cg.genLEStatement(fin); } else { cg.genLEStatement(body); } hasAnd = false; } else if (e is LEExpresion) { if (hasAnd) { cg.genGTStatement(fin); } else { cg.genGTStatement(body); } hasAnd = false; } else if (e is LTExpresion) { if (hasAnd) { cg.genGEStatement(fin); } else { cg.genGEStatement(body); } hasAnd = false; } } }
public void genAritExpresion(ILCodeGen cg, ArrayList exp, uint scope, string proc_actual, string store) { int tipo = 0; Symbol s = null; foreach (Expr e in exp) { if (e is IntLiteral) { IntLiteral lit = (IntLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.INT, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is RealLiteral) { RealLiteral lit = (RealLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.REAL, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is BoolLiteral) { BoolLiteral lit = (BoolLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.BOOLEAN, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is StringLiteral) { StringLiteral lit = (StringLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.STRING, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is CharLiteral) { CharLiteral lit = (CharLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.CHAR, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is Variable) { Variable var = (Variable)e; if (scope == 0) { s = symtab.getSymbol(var.Value); } else { s = symtab.getSymbol(proc_actual, var.Value, ref tipo); } if (s != null) { if (tipo == 1) { Param p = (Param)s; cg.loadVariable(s, p.Reference, scope, proc_actual); } else { cg.loadVariable(s, false, scope, proc_actual); } } tipo = 0; } else if (e is Function) { ExpFunction ex = (ExpFunction)e; if (scope == 0) { s = symtab.find(store); } else { s = symtab.getSymbol(proc_actual, store, ref tipo); } if (s != null) { if (s.Type.toString() != ex.Tipo) { throw new fpc2ilException("Cannot assing type " + ex.Tipo + " to variable '" + s.Name + "' (" + s.Type.toString() + ")"); } } tipo = 0; } else if (e is PlusExpresion) { cg.genSuma(); } else if (e is MinusExpresion) { cg.genResta(); } else if (e is ProductoExpresion) { cg.genMult(); } else if (e is DivisionExpresion) { cg.genDivision(); } else if (e is DIVExpresion) { cg.genDivision(); } else if (e is MODExpresion) { cg.genMod(); } } /* Una vez estan generados todos los loads generamos el store */ if (scope == 0) { s = symtab.getSymbol(store); } else { s = symtab.getSymbol(proc_actual, store, ref tipo); } if (s != null) { if (tipo == 1) { Param p = (Param)s; cg.storeVariable(s, p.Reference, scope, proc_actual); } else { /* TODO: Si es una variable de retorno de funcion de momento no hacemos nada */ if (s.Name != proc_actual) { cg.storeVariable(s, false, scope, proc_actual); } } } }