Пример #1
0
 public virtual void CaseAIfExp(AIfExp node)
 {
     DefaultCase(node);
 }
Пример #2
0
 public virtual void OutAIfExp(AIfExp node)
 {
     DefaultOut(node);
 }
Пример #3
0
 public override void CaseAIfExp(AIfExp node)
 {
     InAIfExp(node);
     if (node.GetElse() != null)
     {
         node.GetElse().Apply(this);
     }
     if (node.GetThen() != null)
     {
         node.GetThen().Apply(this);
     }
     if (node.GetCond() != null)
     {
         node.GetCond().Apply(this);
     }
     if (node.GetToken() != null)
     {
         node.GetToken().Apply(this);
     }
     OutAIfExp(node);
 }
Пример #4
0
 public virtual void InAIfExp(AIfExp node)
 {
     DefaultIn(node);
 }
Пример #5
0
 public override void OutAIfExp(AIfExp node)
 {
     if (!Util.HasAncestor<PStm>(node))
         errors.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText178")));
     base.OutAIfExp(node);
 }
 public override void CaseAIfExp(AIfExp node)
 {
     IsConst = false;
 }
        public override void OutAIfExp(AIfExp node)
        {
            PType thenType = data.ExpTypes[node.GetThen()];
            PType elseType = data.ExpTypes[node.GetElse()];
            if (thenType is ANamedType && elseType is ANamedType)
            {
                ANamedType aThenType = (ANamedType) thenType;
                ANamedType aElseType = (ANamedType) elseType;

                if (aThenType.IsPrimitive("int") && aElseType.IsPrimitive("byte"))
                {
                    data.ExpTypes[node] = thenType;
                    return;
                }
            }
            if (Assignable(thenType, elseType))
                data.ExpTypes[node] = elseType;
            else if (Assignable(data.ExpTypes[node.GetElse()], data.ExpTypes[node.GetThen()]))
                data.ExpTypes[node] = data.ExpTypes[node.GetThen()];
            else
            {
                errors.Add(new ErrorCollection.Error(node.GetToken(),
                                                     LocRM.GetString("ErrorText135")));
                //So execution can continue
                data.ExpTypes[node] = data.ExpTypes[node.GetThen()];
            }

            base.OutAIfExp(node);
        }
Пример #8
0
 ArrayList New507()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList5 = (ArrayList) Pop();
     ArrayList nodeArrayList4 = (ArrayList) Pop();
     ArrayList nodeArrayList3 = (ArrayList) Pop();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TQuestionmark tquestionmarkNode2 = (TQuestionmark)nodeArrayList2[0];
     PExp pexpNode3 = (PExp)nodeArrayList1[0];
     PExp pexpNode4 = (PExp)nodeArrayList3[0];
     PExp pexpNode5 = (PExp)nodeArrayList5[0];
     AIfExp pexpNode1 = new AIfExp (
       tquestionmarkNode2,
       pexpNode3,
       pexpNode4,
       pexpNode5
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
        public override void OutAIfExp(AIfExp node)
        {
            //Transform to
            /*
             * var expIfVar;
             * if (<cond>)
             * {
             *     expIfVar = <then>;
             * }
             * else
             * {
             *     expIfVar = <else>;
             * }
             * ... expIfVar ...
             */

            AALocalDecl expIfVarDecl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, Util.MakeClone(data.ExpTypes[node], data), new TIdentifier("expIfVar"), null);

            ALocalLvalue thenExpIfVarLink = new ALocalLvalue(new TIdentifier("expIfVar"));
            ALocalLvalue elseExpIfVarLink = new ALocalLvalue(new TIdentifier("expIfVar"));
            ALocalLvalue usageExpIfVarLink = new ALocalLvalue(new TIdentifier("expIfVar"));

            ALvalueExp usageExpIfVarLinkExp = new ALvalueExp(usageExpIfVarLink);

            AAssignmentExp thenAssignment = new AAssignmentExp(new TAssign("="), thenExpIfVarLink, node.GetThen());
            AAssignmentExp elseAssignment = new AAssignmentExp(new TAssign("="), elseExpIfVarLink, node.GetElse());

            AIfThenElseStm ifStm = new AIfThenElseStm(new TLParen("("), node.GetCond(),
                                                      new ABlockStm(new TLBrace("{"),
                                                                    new AABlock(
                                                                        new ArrayList()
                                                                            {
                                                                                new AExpStm(new TSemicolon(";"),
                                                                                            thenAssignment)
                                                                            },
                                                                        new TRBrace("}"))),
                                                      new ABlockStm(new TLBrace("{"),
                                                                    new AABlock(
                                                                        new ArrayList()
                                                                            {
                                                                                new AExpStm(new TSemicolon(";"),
                                                                                            elseAssignment)
                                                                            },
                                                                        new TRBrace("}"))));

            data.LocalLinks[thenExpIfVarLink] =
                data.LocalLinks[elseExpIfVarLink] =
                data.LocalLinks[usageExpIfVarLink] = expIfVarDecl;

            data.LvalueTypes[thenExpIfVarLink] =
                data.LvalueTypes[elseExpIfVarLink] =
                data.LvalueTypes[usageExpIfVarLink] =
                data.ExpTypes[usageExpIfVarLinkExp] =
                data.ExpTypes[thenAssignment] =
                data.ExpTypes[elseAssignment] = expIfVarDecl.GetType();

            PStm pStm = Util.GetAncestor<PStm>(node);
            AABlock pBlock = (AABlock) pStm.Parent();

            pBlock.GetStatements().Insert(pBlock.GetStatements().IndexOf(pStm), new ALocalDeclStm(new TSemicolon(";"), expIfVarDecl));
            pBlock.GetStatements().Insert(pBlock.GetStatements().IndexOf(pStm), ifStm);
            node.ReplaceBy(usageExpIfVarLinkExp);

            base.OutAIfExp(node);
        }