public virtual void OutAIncDecExp(AIncDecExp node)
 {
     DefaultOut(node);
 }
 public virtual void InAIncDecExp(AIncDecExp node)
 {
     DefaultIn(node);
 }
 public virtual void CaseAIncDecExp(AIncDecExp node)
 {
     DefaultCase(node);
 }
 public override void CaseAIncDecExp(AIncDecExp node)
 {
     IsConst = false;
 }
 public override void CaseAIncDecExp(AIncDecExp node)
 {
     InAIncDecExp(node);
     if (node.GetIncDecOp() != null)
     {
         node.GetIncDecOp().Apply(this);
     }
     if (node.GetLvalue() != null)
     {
         node.GetLvalue().Apply(this);
     }
     OutAIncDecExp(node);
 }
示例#6
0
 ArrayList New477()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TValue tvalueNode3 = (TValue)nodeArrayList2[0];
     AValueLvalue plvalueNode2 = new AValueLvalue (
       tvalueNode3
     );
     TMinusMinus tminusminusNode5 = (TMinusMinus)nodeArrayList1[0];
     APreDecIncDecOp pincdecopNode4 = new APreDecIncDecOp (
       tminusminusNode5
     );
     AIncDecExp pexpNode1 = new AIncDecExp (
       plvalueNode2,
       pincdecopNode4
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
        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;
            }
        }
示例#8
0
 ArrayList New470()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TypedList listNode5 = new TypedList();
     TypedList listNode4 = (TypedList)nodeArrayList2[0];
     if ( listNode4 != null )
     {
     listNode5.AddAll(listNode4);
     }
     AAName pnameNode3 = new AAName (
       listNode5
     );
     AAmbiguousNameLvalue plvalueNode2 = new AAmbiguousNameLvalue (
       pnameNode3
     );
     TMinusMinus tminusminusNode7 = (TMinusMinus)nodeArrayList1[0];
     APreDecIncDecOp pincdecopNode6 = new APreDecIncDecOp (
       tminusminusNode7
     );
     AIncDecExp pexpNode1 = new AIncDecExp (
       plvalueNode2,
       pincdecopNode6
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
示例#9
0
 ArrayList New472()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList4 = (ArrayList) Pop();
     ArrayList nodeArrayList3 = (ArrayList) Pop();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TIdentifier tidentifierNode3 = (TIdentifier)nodeArrayList4[0];
     AStructFieldLvalue plvalueNode2 = new AStructFieldLvalue (
       tidentifierNode3
     );
     TMinusMinus tminusminusNode5 = (TMinusMinus)nodeArrayList1[0];
     APreDecIncDecOp pincdecopNode4 = new APreDecIncDecOp (
       tminusminusNode5
     );
     AIncDecExp pexpNode1 = new AIncDecExp (
       plvalueNode2,
       pincdecopNode4
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
示例#10
0
 ArrayList New467()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     PLvalue plvalueNode2 = (PLvalue)nodeArrayList2[0];
     TPlusPlus tplusplusNode4 = (TPlusPlus)nodeArrayList1[0];
     APreIncIncDecOp pincdecopNode3 = new APreIncIncDecOp (
       tplusplusNode4
     );
     AIncDecExp pexpNode1 = new AIncDecExp (
       plvalueNode2,
       pincdecopNode3
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
示例#11
0
 ArrayList New468()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TThis tthisNode3 = (TThis)nodeArrayList2[0];
     AThisLvalue plvalueNode2 = new AThisLvalue (
       tthisNode3
     );
     TPlusPlus tplusplusNode5 = (TPlusPlus)nodeArrayList1[0];
     APreIncIncDecOp pincdecopNode4 = new APreIncIncDecOp (
       tplusplusNode5
     );
     AIncDecExp pexpNode1 = new AIncDecExp (
       plvalueNode2,
       pincdecopNode4
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
示例#12
0
 ArrayList New463()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList4 = (ArrayList) Pop();
     ArrayList nodeArrayList3 = (ArrayList) Pop();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TIdentifier tidentifierNode3 = (TIdentifier)nodeArrayList4[0];
     AFieldLvalue plvalueNode2 = new AFieldLvalue (
       tidentifierNode3
     );
     TPlusPlus tplusplusNode5 = (TPlusPlus)nodeArrayList1[0];
     APreIncIncDecOp pincdecopNode4 = new APreIncIncDecOp (
       tplusplusNode5
     );
     AIncDecExp pexpNode1 = new AIncDecExp (
       plvalueNode2,
       pincdecopNode4
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
示例#13
0
 ArrayList New446()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TThis tthisNode3 = (TThis)nodeArrayList1[0];
     AThisLvalue plvalueNode2 = new AThisLvalue (
       tthisNode3
     );
     TMinusMinus tminusminusNode5 = (TMinusMinus)nodeArrayList2[0];
     APostDecIncDecOp pincdecopNode4 = new APostDecIncDecOp (
       tminusminusNode5
     );
     AIncDecExp pexpNode1 = new AIncDecExp (
       plvalueNode2,
       pincdecopNode4
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
示例#14
0
 ArrayList New445()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     PLvalue plvalueNode2 = (PLvalue)nodeArrayList1[0];
     TMinusMinus tminusminusNode4 = (TMinusMinus)nodeArrayList2[0];
     APostDecIncDecOp pincdecopNode3 = new APostDecIncDecOp (
       tminusminusNode4
     );
     AIncDecExp pexpNode1 = new AIncDecExp (
       plvalueNode2,
       pincdecopNode3
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
示例#15
0
 ArrayList New440()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TValue tvalueNode3 = (TValue)nodeArrayList1[0];
     AValueLvalue plvalueNode2 = new AValueLvalue (
       tvalueNode3
     );
     TPlusPlus tplusplusNode5 = (TPlusPlus)nodeArrayList2[0];
     APostIncIncDecOp pincdecopNode4 = new APostIncIncDecOp (
       tplusplusNode5
     );
     AIncDecExp pexpNode1 = new AIncDecExp (
       plvalueNode2,
       pincdecopNode4
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
 public override void CaseAIncDecExp(AIncDecExp node)
 {
     if (node.GetIncDecOp() is APreIncIncDecOp)
         Value += "++";
     if (node.GetIncDecOp() is APreDecIncDecOp)
         Value += "--";
     base.CaseAIncDecExp(node);
     if (node.GetIncDecOp() is APostIncIncDecOp)
         Value += "++";
     if (node.GetIncDecOp() is APostDecIncDecOp)
         Value += "--";
 }