public virtual void OutAPlusBinop(APlusBinop node) { DefaultOut(node); }
public override void CaseAPlusBinop(APlusBinop node) { InAPlusBinop(node); if (node.GetToken() != null) { node.GetToken().Apply(this); } OutAPlusBinop(node); }
public virtual void InAPlusBinop(APlusBinop node) { DefaultIn(node); }
public override void OutASAssignmentExp(ASAssignmentExp node) { AAssignmentExp replacer = null; PAssignop assignop = node.GetAssignop(); Token token = null; PBinop binop = null; if (assignop is AAddAssignop) { token = ((AAddAssignop)assignop).GetToken(); binop = new APlusBinop(new TPlus("+", token.Line, token.Pos)); } else if (assignop is ASubAssignop) { token = ((ASubAssignop)assignop).GetToken(); binop = new AMinusBinop(new TMinus("-", token.Line, token.Pos)); } else if (assignop is AMulAssignop) { token = ((AMulAssignop)assignop).GetToken(); binop = new ATimesBinop(new TStar("*", token.Line, token.Pos)); } else if (assignop is ADivAssignop) { token = ((ADivAssignop)assignop).GetToken(); binop = new ADivideBinop(new TDiv("/", token.Line, token.Pos)); } else if (assignop is AModAssignop) { token = ((AModAssignop)assignop).GetToken(); binop = new AModuloBinop(new TMod("%", token.Line, token.Pos)); } else// if (assignop is AAssignAssignop) { token = ((AAssignAssignop)assignop).GetToken(); } PExp rightSide; if (binop != null) rightSide = new ABinopExp(new ALvalueExp((PLvalue)node.GetLvalue().Clone()), binop, (PExp)node.GetExp().Clone()); else rightSide = (PExp)node.GetExp().Clone(); replacer = new AAssignmentExp(new TAssign("=", token.Line, token.Pos), (PLvalue)node.GetLvalue().Clone(), rightSide); node.ReplaceBy(replacer); replacer.Apply(this); }
public virtual void CaseAPlusBinop(APlusBinop node) { DefaultCase(node); }
public override void OutAIncDecExp(AIncDecExp node) { PIncDecOp op = node.GetIncDecOp(); if (!Util.HasAncestor<AABlock>(node)) { Token token = null; if (op is APostDecIncDecOp) token = ((APostDecIncDecOp) op).GetToken(); else if (op is APreDecIncDecOp) token = ((APreDecIncDecOp)op).GetToken(); else if (op is APostIncIncDecOp) token = ((APostIncIncDecOp)op).GetToken(); else if (op is APreIncIncDecOp) token = ((APreIncIncDecOp)op).GetToken(); errors.Add(new ErrorCollection.Error(token, LocRM.GetString("ErrorText114"))); throw new ParserException(token, "TypeChecking.OutAIncDecExp"); } bool plus = op is APreIncIncDecOp || op is APostIncIncDecOp; if (op is APreIncIncDecOp || op is APreDecIncDecOp || node.Parent() is AExpStm) {//++i, --i, i++; or i--; //Replace with assignment //<exp>++ => <exp> + 1 //(... foo = <exp> ...)++ => (... foo = <exp> ...) = (... foo ...) + 1 //(... foo++ ...)++ => (... foo++ ...) = (... foo ...) + 1 PLvalue clone = Util.MakeClone(node.GetLvalue(), data); clone.Apply(new AssignFixup(data)); PBinop binop; if (plus) { binop = new APlusBinop(new TPlus("+")); } else { binop = new AMinusBinop(new TMinus("-")); } ABinopExp addExp = new ABinopExp(new ALvalueExp(clone), binop, new AIntConstExp(new TIntegerLiteral("1"))); AAssignmentExp exp = new AAssignmentExp(new TAssign("="), node.GetLvalue(), addExp); node.ReplaceBy(exp); exp.Apply(this); return; } {//i++ or i-- //Make a new local so //int newLocal = i; //++i; //...newLocal...; PLvalue lvalueClone = Util.MakeClone(node.GetLvalue(), data); PExp exp = new ALvalueExp(Util.MakeClone(node.GetLvalue(), data)); data.ExpTypes[exp] = data.LvalueTypes[node.GetLvalue()]; AALocalDecl localDecl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, Util.MakeClone(data.LvalueTypes[node.GetLvalue()], data), new TIdentifier("incDecVar"), exp); ALocalDeclStm localDeclStm = new ALocalDeclStm(new TSemicolon(";"), localDecl); node.SetIncDecOp(plus ? (PIncDecOp) new APreIncIncDecOp(new TPlusPlus("++")) : new APreDecIncDecOp(new TMinusMinus("--"))); ALocalLvalue lvalue = new ALocalLvalue(new TIdentifier(localDecl.GetName().Text)); exp = new ALvalueExp(lvalue); data.ExpTypes[exp] = data.LvalueTypes[lvalue] = data.LvalueTypes[node.GetLvalue()]; data.LocalLinks[lvalue] = localDecl; PStm pStm = Util.GetAncestor<PStm>(node); node.ReplaceBy(exp); PStm nodeStm = new AExpStm(new TSemicolon(";"), node); AABlock block = (AABlock) pStm.Parent(); block.GetStatements().Insert(block.GetStatements().IndexOf(pStm), localDeclStm); block.GetStatements().Insert(block.GetStatements().IndexOf(pStm), nodeStm); localDeclStm.Apply(this); nodeStm.Apply(this); exp.Apply(this); if (pStm is AWhileStm && Util.IsAncestor(exp, ((AWhileStm)pStm).GetCondition())) { AWhileStm aStm = (AWhileStm)pStm; //Insert // newLocal = i // ++i //Before each continue in the while, and at the end. //Add continue statement, if not present block = (AABlock)((ABlockStm)aStm.GetBody()).GetBlock(); if (block.GetStatements().Count == 0 || !(block.GetStatements()[block.GetStatements().Count - 1] is AContinueStm)) block.GetStatements().Add(new AContinueStm(new TContinue("continue"))); //Get all continue statements in the while ContinueFinder finder = new ContinueFinder(); block.Apply(finder); foreach (AContinueStm continueStm in finder.Continues) { PLvalue nodeLvalue1 = Util.MakeClone(lvalueClone, data); PExp nodeLvalue1Exp = new ALvalueExp(nodeLvalue1); PLvalue nodeLvalue2 = Util.MakeClone(lvalueClone, data); ALocalLvalue newLocalLvalue = new ALocalLvalue(new TIdentifier("newLocal")); data.LocalLinks[newLocalLvalue] = localDecl; AAssignmentExp assignment = new AAssignmentExp(new TAssign("="), newLocalLvalue, nodeLvalue1Exp); PStm assignmentStm = new AExpStm(new TSemicolon(";"), assignment); AIncDecExp newIncDecExp = new AIncDecExp(nodeLvalue2, plus ? (PIncDecOp) new APreIncIncDecOp( new TPlusPlus("++")) : new APreDecIncDecOp( new TMinusMinus("--"))); PStm newIncDecExpStm = new AExpStm(new TSemicolon(";"), newIncDecExp); block = (AABlock)continueStm.Parent(); block.GetStatements().Insert(block.GetStatements().IndexOf(continueStm), assignmentStm); block.GetStatements().Insert(block.GetStatements().IndexOf(continueStm), newIncDecExpStm); assignment.Apply(this); newIncDecExp.Apply(this); } } return; } }
public override void CaseAPlusBinop(APlusBinop node) { Write(" + "); }
ArrayList New483() { ArrayList nodeList = new ArrayList(); ArrayList nodeArrayList3 = (ArrayList) Pop(); ArrayList nodeArrayList2 = (ArrayList) Pop(); ArrayList nodeArrayList1 = (ArrayList) Pop(); PExp pexpNode2 = (PExp)nodeArrayList1[0]; TPlus tplusNode4 = (TPlus)nodeArrayList2[0]; APlusBinop pbinopNode3 = new APlusBinop ( tplusNode4 ); PExp pexpNode5 = (PExp)nodeArrayList3[0]; ABinopExp pexpNode1 = new ABinopExp ( pexpNode2, pbinopNode3, pexpNode5 ); nodeList.Add(pexpNode1); return nodeList; }
ArrayList New38() { ArrayList nodeList = new ArrayList(); ArrayList nodeArrayList1 = (ArrayList) Pop(); TPlus tplusNode2 = (TPlus)nodeArrayList1[0]; APlusBinop pbinopNode1 = new APlusBinop ( tplusNode2 ); nodeList.Add(pbinopNode1); return nodeList; }
public override void CaseAPlusBinop(APlusBinop node) { Value += " + "; }