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);
        }
 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);
 }
        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);
        }