public override void CaseAArrayLvalue(AArrayLvalue node)
 {
     node.GetBase().Apply(this);
     Write("[");
     node.GetIndex().Apply(this);
     Write("]");
 }
 public override void CaseAArrayLvalue(AArrayLvalue node)
 {
     bool containedLiteral = containsLiteral;
     containsLiteral = false;
     node.GetIndex().Apply(this);
     bool hasLiteral = containsLiteral;
     containsLiteral = containedLiteral;
     PType type = data.ExpTypes[node.GetIndex()];
     if (!hasLiteral && type is ANamedType && ((ANamedType)type).IsPrimitive("byte"))
     {
         AIntConstExp intConst = new AIntConstExp(new TIntegerLiteral("0"));
         ABinopExp binop = new ABinopExp(node.GetIndex(), new APlusBinop(new TPlus("+")), intConst);
         data.ExpTypes[intConst] =
             data.ExpTypes[binop] = new ANamedType(new TIdentifier("int"), null);
         node.SetIndex(binop);
     }
     node.GetBase().Apply(this);
 }
 ArrayList New344()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList4 = (ArrayList) Pop();
     ArrayList nodeArrayList3 = (ArrayList) Pop();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TLBracket tlbracketNode2 = (TLBracket)nodeArrayList2[0];
     PExp pexpNode3 = (PExp)nodeArrayList1[0];
     PExp pexpNode4 = (PExp)nodeArrayList3[0];
     AArrayLvalue plvalueNode1 = new AArrayLvalue (
       tlbracketNode2,
       pexpNode3,
       pexpNode4
     );
     nodeList.Add(plvalueNode1);
     return nodeList;
 }
 public override void CaseAArrayLvalue(AArrayLvalue node)
 {
     base.CaseAArrayLvalue(node);
     currentPointer.Clear();//After an array index, it's always unsure - can't analyze what the index will be at runtime
     isSet = false;
     isExposed = true;
 }
 ArrayList New339()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList6 = (ArrayList) Pop();
     ArrayList nodeArrayList5 = (ArrayList) Pop();
     ArrayList nodeArrayList4 = (ArrayList) Pop();
     ArrayList nodeArrayList3 = (ArrayList) Pop();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TLBracket tlbracketNode2 = (TLBracket)nodeArrayList4[0];
     TIdentifier tidentifierNode5 = (TIdentifier)nodeArrayList3[0];
     AStructFieldLvalue plvalueNode4 = new AStructFieldLvalue (
       tidentifierNode5
     );
     ALvalueExp pexpNode3 = new ALvalueExp (
       plvalueNode4
     );
     PExp pexpNode6 = (PExp)nodeArrayList5[0];
     AArrayLvalue plvalueNode1 = new AArrayLvalue (
       tlbracketNode2,
       pexpNode3,
       pexpNode6
     );
     nodeList.Add(plvalueNode1);
     return nodeList;
 }
 ArrayList New342()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList4 = (ArrayList) Pop();
     ArrayList nodeArrayList3 = (ArrayList) Pop();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TLBracket tlbracketNode2 = (TLBracket)nodeArrayList2[0];
     TValue tvalueNode5 = (TValue)nodeArrayList1[0];
     AValueLvalue plvalueNode4 = new AValueLvalue (
       tvalueNode5
     );
     ALvalueExp pexpNode3 = new ALvalueExp (
       plvalueNode4
     );
     PExp pexpNode6 = (PExp)nodeArrayList3[0];
     AArrayLvalue plvalueNode1 = new AArrayLvalue (
       tlbracketNode2,
       pexpNode3,
       pexpNode6
     );
     nodeList.Add(plvalueNode1);
     return nodeList;
 }
 public virtual void InAArrayLvalue(AArrayLvalue node)
 {
     DefaultIn(node);
 }
            public static AMethodDecl CreateDeleteStructMethodGlobalArrayP(Node node, TIntegerLiteral intDim, string prefix, GlobalStructVars vars, SharedData data)
            {
                /*
                    void DeleteStr(int i)
                    {
                        if (!(Str_used[i / 31] & Power2(i % 31)))
                        {
                            return;
                        }
                        Str_used[i / 31] = Str_used[i / 31] - Power2(i % 31);
                        stack[freeCount] = i;
                        freeCount += 1;
                        /*if (i == Str_index)
                        {
                            while (!(Str_used[i / 31] & Power2(i % 31)))
                            {
                                i = i - 1;
                                if (i < 0)
                                {
                                    i = 41;
                                }
                                if (i == Str_index)
                                {
                                    //Everything is free
                                    break;
                                }
                            }
                            Str_index = i;
                        }* /
                    }
                 */

                AASourceFile file = Util.GetAncestor<AASourceFile>(node);

                AIntConstExp intConst1 = new AIntConstExp(new TIntegerLiteral("31"));
                AIntConstExp intConst2 = new AIntConstExp(new TIntegerLiteral("31"));
                AIntConstExp intConst3 = new AIntConstExp(new TIntegerLiteral("31"));
                AIntConstExp intConst4 = new AIntConstExp(new TIntegerLiteral("31"));
                AIntConstExp intConst5 = new AIntConstExp(new TIntegerLiteral("31"));
                AIntConstExp intConst6 = new AIntConstExp(new TIntegerLiteral("31"));
                AIntConstExp intConst7 = new AIntConstExp(new TIntegerLiteral("31"));
                AIntConstExp intConst8 = new AIntConstExp(new TIntegerLiteral("1"));
                AIntConstExp intConst9 = new AIntConstExp(new TIntegerLiteral("0"));
                AIntConstExp intConst10 = new AIntConstExp(new TIntegerLiteral((int.Parse(intDim.Text) - 1).ToString()));
                AIntConstExp intConst11 = new AIntConstExp(new TIntegerLiteral("1"));
                AIntConstExp intConst12 = new AIntConstExp(new TIntegerLiteral("1"));
                AIntConstExp intConst13 = new AIntConstExp(new TIntegerLiteral("1"));

                AFieldLvalue strUsedRef1 = new AFieldLvalue(new TIdentifier(vars.Used.GetName().Text));
                AFieldLvalue strUsedRef2 = new AFieldLvalue(new TIdentifier(vars.Used.GetName().Text));
                AFieldLvalue strUsedRef3 = new AFieldLvalue(new TIdentifier(vars.Used.GetName().Text));
                AFieldLvalue strUsedRef4 = new AFieldLvalue(new TIdentifier(vars.Used.GetName().Text));
                ALvalueExp strUsedRef1Exp = new ALvalueExp(strUsedRef1);
                ALvalueExp strUsedRef2Exp = new ALvalueExp(strUsedRef2);
                ALvalueExp strUsedRef3Exp = new ALvalueExp(strUsedRef3);
                ALvalueExp strUsedRef4Exp = new ALvalueExp(strUsedRef4);

                AFieldLvalue strIndexRef1 = new AFieldLvalue(new TIdentifier(vars.Index.GetName().Text));
                AFieldLvalue strIndexRef2 = new AFieldLvalue(new TIdentifier(vars.Index.GetName().Text));
                AFieldLvalue strIndexRef3 = new AFieldLvalue(new TIdentifier(vars.Index.GetName().Text));
                ALvalueExp strIndexRef1Exp = new ALvalueExp(strIndexRef1);
                ALvalueExp strIndexRef2Exp = new ALvalueExp(strIndexRef2);

                AALocalDecl iDecl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, new ANamedType(new TIdentifier("int"), null),
                                                    new TIdentifier("i"), null);
                ALocalLvalue iRef1 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef2 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef3 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef4 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef5 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef6 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef7 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef8 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef9 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef10 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef11 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef12 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef13 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef14 = new ALocalLvalue(new TIdentifier("i"));
                ALvalueExp iRef1Exp = new ALvalueExp(iRef1);
                ALvalueExp iRef2Exp = new ALvalueExp(iRef2);
                ALvalueExp iRef3Exp = new ALvalueExp(iRef3);
                ALvalueExp iRef4Exp = new ALvalueExp(iRef4);
                ALvalueExp iRef5Exp = new ALvalueExp(iRef5);
                ALvalueExp iRef6Exp = new ALvalueExp(iRef6);
                ALvalueExp iRef7Exp = new ALvalueExp(iRef7);
                ALvalueExp iRef8Exp = new ALvalueExp(iRef8);
                ALvalueExp iRef10Exp = new ALvalueExp(iRef10);
                ALvalueExp iRef11Exp = new ALvalueExp(iRef11);
                ALvalueExp iRef13Exp = new ALvalueExp(iRef13);
                ALvalueExp iRef14Exp = new ALvalueExp(iRef14);

                ABinopExp binop1 = new ABinopExp(iRef1Exp, new ADivideBinop(new TDiv("/")), intConst1);
                ABinopExp binop2 = new ABinopExp(iRef2Exp, new AModuloBinop(new TMod("%")), intConst2);
                ABinopExp binop3 = new ABinopExp(null, new AAndBinop(new TAnd("&")), null);
                ABinopExp binop4 = new ABinopExp(iRef3Exp, new ADivideBinop(new TDiv("/")), intConst3);
                ABinopExp binop5 = new ABinopExp(iRef4Exp, new ADivideBinop(new TDiv("/")), intConst4);
                ABinopExp binop6 = new ABinopExp(iRef5Exp, new AModuloBinop(new TMod("%")), intConst5);
                ABinopExp binop7 = new ABinopExp(null, new AMinusBinop(new TMinus("-")), null);
                ABinopExp binop8 = new ABinopExp(iRef6Exp, new AEqBinop(new TEq("==")), strIndexRef1Exp);
                ABinopExp binop9 = new ABinopExp(iRef7Exp, new ADivideBinop(new TDiv("/")), intConst6);
                ABinopExp binop10 = new ABinopExp(iRef8Exp, new AModuloBinop(new TMod("%")), intConst7);
                ABinopExp binop11 = new ABinopExp(null, new AAndBinop(new TAnd("&")), null);
                ABinopExp binop12 = new ABinopExp(iRef10Exp, new AMinusBinop(new TMinus("-")), intConst8);
                ABinopExp binop13 = new ABinopExp(iRef11Exp, new ALtBinop(new TLt("<")), intConst9);
                ABinopExp binop14 = new ABinopExp(iRef13Exp, new AEqBinop(new TEq("==")), strIndexRef2Exp);

                AArrayLvalue arrayIndex1 = new AArrayLvalue(new TLBracket("["), strUsedRef1Exp, binop1);
                AArrayLvalue arrayIndex2 = new AArrayLvalue(new TLBracket("["), strUsedRef2Exp, binop4);
                AArrayLvalue arrayIndex3 = new AArrayLvalue(new TLBracket("["), strUsedRef3Exp, binop5);
                AArrayLvalue arrayIndex4 = new AArrayLvalue(new TLBracket("["), strUsedRef4Exp, binop9);
                ALvalueExp arrayIndex1Exp = new ALvalueExp(arrayIndex1);
                ALvalueExp arrayIndex3Exp = new ALvalueExp(arrayIndex3);
                ALvalueExp arrayIndex4Exp = new ALvalueExp(arrayIndex4);
                binop3.SetLeft(arrayIndex1Exp);
                binop7.SetLeft(arrayIndex3Exp);
                binop11.SetLeft(arrayIndex4Exp);

                ABinopExp binop15 = new ABinopExp(intConst11, new ALBitShiftBinop(new TLBitShift("<<")), binop2);
                ABinopExp binop16 = new ABinopExp(intConst12, new ALBitShiftBinop(new TLBitShift("<<")), binop6);
                ABinopExp binop17 = new ABinopExp(intConst13, new ALBitShiftBinop(new TLBitShift("<<")), binop10);
                binop3.SetRight(binop15);
                binop7.SetRight(binop16);
                binop11.SetRight(binop17);
                /*ASimpleInvokeExp power2Invoke1 = new ASimpleInvokeExp(new TIdentifier("Power2"), new ArrayList() { binop2 });
                ASimpleInvokeExp power2Invoke2 = new ASimpleInvokeExp(new TIdentifier("Power2"), new ArrayList() { binop6 });
                ASimpleInvokeExp power2Invoke3 = new ASimpleInvokeExp(new TIdentifier("Power2"), new ArrayList() { binop10 });
                binop3.SetRight(power2Invoke1);
                binop7.SetRight(power2Invoke2);
                binop11.SetRight(power2Invoke3);*/

                AParenExp paren1 = new AParenExp(binop3);
                AParenExp paren2 = new AParenExp(binop11);

                AUnopExp unop1 = new AUnopExp(new AComplementUnop(new TComplement("!")), paren1);
                AUnopExp unop2 = new AUnopExp(new AComplementUnop(new TComplement("!")), paren2);

                AAssignmentExp assignment1 = new AAssignmentExp(new TAssign("="), arrayIndex2, binop7);
                AAssignmentExp assignment2 = new AAssignmentExp(new TAssign("="), iRef9, binop12);
                AAssignmentExp assignment3 = new AAssignmentExp(new TAssign("="), iRef12, intConst10);
                AAssignmentExp assignment4 = new AAssignmentExp(new TAssign("="), strIndexRef3, iRef14Exp);

                AMethodDecl method = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null,
                                                                 new AVoidType(new TVoid("void")),
                                                                 new TIdentifier("Delete" + prefix, data.LineCounts[file] + 18, 0),
                                                                 new ArrayList() { iDecl },
                                                                 new AABlock(
                                                                     new ArrayList()
                                                                         {
                                                                             new AIfThenStm(new TLParen("("), unop1,
                                                                                            new ABlockStm(
                                                                                                new TLBrace("{"),
                                                                                                new AABlock(
                                                                                                    new ArrayList()
                                                                                                        {
                                                                                                            new AVoidReturnStm
                                                                                                                (new TReturn
                                                                                                                     ("return"))
                                                                                                        },
                                                                                                    new TRBrace("}")))),
                                                                             new AExpStm(new TSemicolon(";"),
                                                                                         assignment1),
                                                                             new AIfThenStm(new TLParen("("), binop8,
                                                                                            new ABlockStm(
                                                                                                new TLBrace("{"),
                                                                                                new AABlock(
                                                                                                    new ArrayList()
                                                                                                        {
                                                                                                            new AWhileStm
                                                                                                                (new TLParen
                                                                                                                     ("("),
                                                                                                                 unop2,
                                                                                                                 new ABlockStm
                                                                                                                     (new TLBrace
                                                                                                                          ("{"),
                                                                                                                      new AABlock
                                                                                                                          (new ArrayList
                                                                                                                               ()
                                                                                                                               {
                                                                                                                                   new AExpStm
                                                                                                                                       (new TSemicolon
                                                                                                                                            (";"),
                                                                                                                                        assignment2),
                                                                                                                                   new AIfThenStm
                                                                                                                                       (new TLParen
                                                                                                                                            ("("),
                                                                                                                                        binop13,
                                                                                                                                        new ABlockStm
                                                                                                                                            (new TLBrace
                                                                                                                                                 ("{"),
                                                                                                                                             new AABlock
                                                                                                                                                 (new ArrayList
                                                                                                                                                      ()
                                                                                                                                                      {
                                                                                                                                                          new AExpStm
                                                                                                                                                              (new TSemicolon
                                                                                                                                                                   (";"),
                                                                                                                                                               assignment3)
                                                                                                                                                      },
                                                                                                                                                  new TRBrace
                                                                                                                                                      ("}")))),
                                                                                                                                   new AIfThenStm
                                                                                                                                       (new TLParen
                                                                                                                                            ("("),
                                                                                                                                        binop14,
                                                                                                                                        new ABlockStm
                                                                                                                                            (new TLBrace
                                                                                                                                                 ("{"),
                                                                                                                                             new AABlock
                                                                                                                                                 (new ArrayList
                                                                                                                                                      ()
                                                                                                                                                      {
                                                                                                                                                          new ABreakStm
                                                                                                                                                              (new TBreak
                                                                                                                                                                   ("break"))
                                                                                                                                                      },
                                                                                                                                                  new TRBrace
                                                                                                                                                      ("}"))))
                                                                                                                               },
                                                                                                                           new TRBrace
                                                                                                                               ("}")))),
                                                                                                            new AExpStm(
                                                                                                                new TSemicolon
                                                                                                                    (";"),
                                                                                                                assignment4)
                                                                                                        },
                                                                                                    new TRBrace("}"))))
                                                                         },
                                                                      new TRBrace("}")));

                file.GetDecl().Add(method);
                data.Methods.Add(new SharedData.DeclItem<AMethodDecl>(file, method));

                data.FieldLinks[strUsedRef1] =
                    data.FieldLinks[strUsedRef2] =
                    data.FieldLinks[strUsedRef3] =
                    data.FieldLinks[strUsedRef4] = vars.Used;
                data.FieldLinks[strIndexRef1] =
                    data.FieldLinks[strIndexRef2] =
                    data.FieldLinks[strIndexRef3] = vars.Index;
                data.LocalLinks[iRef1] =
                    data.LocalLinks[iRef2] =
                    data.LocalLinks[iRef3] =
                    data.LocalLinks[iRef4] =
                    data.LocalLinks[iRef5] =
                    data.LocalLinks[iRef6] =
                    data.LocalLinks[iRef7] =
                    data.LocalLinks[iRef8] =
                    data.LocalLinks[iRef9] =
                    data.LocalLinks[iRef10] =
                    data.LocalLinks[iRef11] =
                    data.LocalLinks[iRef12] =
                    data.LocalLinks[iRef13] =
                    data.LocalLinks[iRef14] = iDecl;
                //data.SimpleMethodLinks[power2Invoke1] =
                //    data.SimpleMethodLinks[power2Invoke2] =
                //    data.SimpleMethodLinks[power2Invoke3] = CreatePower2Method(node, data);

                data.ExpTypes[intConst1] =
                    data.ExpTypes[intConst2] =
                    data.ExpTypes[intConst3] =
                    data.ExpTypes[intConst4] =
                    data.ExpTypes[intConst5] =
                    data.ExpTypes[intConst6] =
                    data.ExpTypes[intConst7] =
                    data.ExpTypes[intConst8] =
                    data.ExpTypes[intConst9] =
                    data.ExpTypes[intConst10] =
                    data.ExpTypes[intConst11] =
                    data.ExpTypes[intConst12] =
                    data.ExpTypes[intConst13] =
                    data.LvalueTypes[iRef1] =
                    data.LvalueTypes[iRef2] =
                    data.LvalueTypes[iRef3] =
                    data.LvalueTypes[iRef4] =
                    data.LvalueTypes[iRef5] =
                    data.LvalueTypes[iRef6] =
                    data.LvalueTypes[iRef7] =
                    data.LvalueTypes[iRef8] =
                    data.LvalueTypes[iRef9] =
                    data.LvalueTypes[iRef10] =
                    data.LvalueTypes[iRef11] =
                    data.LvalueTypes[iRef12] =
                    data.LvalueTypes[iRef13] =
                    data.LvalueTypes[iRef14] =
                    data.ExpTypes[iRef1Exp] =
                    data.ExpTypes[iRef2Exp] =
                    data.ExpTypes[iRef3Exp] =
                    data.ExpTypes[iRef4Exp] =
                    data.ExpTypes[iRef5Exp] =
                    data.ExpTypes[iRef6Exp] =
                    data.ExpTypes[iRef7Exp] =
                    data.ExpTypes[iRef8Exp] =
                    data.ExpTypes[iRef10Exp] =
                    data.ExpTypes[iRef11Exp] =
                    data.ExpTypes[iRef13Exp] =
                    data.ExpTypes[iRef14Exp] =
                    data.LvalueTypes[arrayIndex1] =
                    data.LvalueTypes[arrayIndex2] =
                    data.LvalueTypes[arrayIndex3] =
                    data.LvalueTypes[arrayIndex4] =
                    data.ExpTypes[arrayIndex1Exp] =
                    data.ExpTypes[arrayIndex3Exp] =
                    data.ExpTypes[arrayIndex4Exp] =
                    data.ExpTypes[binop1] =
                    data.ExpTypes[binop2] =
                    data.ExpTypes[binop3] =
                    data.ExpTypes[binop4] =
                    data.ExpTypes[binop5] =
                    data.ExpTypes[binop6] =
                    data.ExpTypes[binop7] =
                    data.ExpTypes[binop9] =
                    data.ExpTypes[binop10] =
                    data.ExpTypes[binop11] =
                    data.ExpTypes[binop12] =
                    data.ExpTypes[binop15] =
                    data.ExpTypes[binop16] =
                    data.ExpTypes[binop17] =
                    data.ExpTypes[paren1] =
                    data.ExpTypes[paren2] =
                    data.ExpTypes[assignment1] =
                    data.ExpTypes[assignment2] =
                    data.ExpTypes[assignment3] =
                    data.ExpTypes[assignment4] =
                    /*data.ExpTypes[power2Invoke1] =
                    data.ExpTypes[power2Invoke2] =
                    data.ExpTypes[power2Invoke3] =*/ new ANamedType(new TIdentifier("int"), null);

                data.ExpTypes[binop8] =
                    data.ExpTypes[binop13] =
                    data.ExpTypes[binop14] =
                    data.ExpTypes[unop1] =
                    data.ExpTypes[unop2] = new ANamedType(new TIdentifier("bool"), null);

                return method;
            }
        private List<PStm> AssignDefault(PLvalue lvalue)
        {
            List<PStm> returner = new List<PStm>();
            PType type = data.LvalueTypes[lvalue];
            PExp rightSide = null;
            if (type is ANamedType)
            {
                ANamedType aType = (ANamedType)type;
                if (aType.IsPrimitive("string"))//aType.GetName().Text == "string")
                {
                    rightSide = new AStringConstExp(new TStringLiteral("\"\""));
                    data.ExpTypes[rightSide] = new ANamedType(new TIdentifier("string"), null);
                }
                else if (aType.IsPrimitive(GalaxyKeywords.NullablePrimitives.words)) //GalaxyKeywords.NullablePrimitives.words.Contains(aType.GetName().Text))
                {
                    rightSide = new ANullExp();
                    data.ExpTypes[rightSide] = new ANamedType(new TIdentifier("null"), null);
                }
                else if (aType.IsPrimitive(new []{"int", "byte", "fixed"}))
                    /*aType.GetName().Text == "int" ||
                    aType.GetName().Text == "byte" ||
                    aType.GetName().Text == "fixed")*/
                {
                    rightSide = new AIntConstExp(new TIntegerLiteral("0"));
                    data.ExpTypes[rightSide] = type;
                }
                else if (aType.IsPrimitive("bool"))//aType.GetName().Text == "bool")
                {
                    rightSide = new ABooleanConstExp(new AFalseBool());
                    data.ExpTypes[rightSide] = type;
                }
                else if (aType.IsPrimitive("color"))//aType.GetName().Text == "color")
                {
                    PExp arg1 = new AIntConstExp(new TIntegerLiteral("0"));
                    PExp arg2 = new AIntConstExp(new TIntegerLiteral("0"));
                    PExp arg3 = new AIntConstExp(new TIntegerLiteral("0"));
                    ASimpleInvokeExp invoke = new ASimpleInvokeExp(new TIdentifier("Color"), new ArrayList() { arg1, arg2, arg3 });
                    rightSide = invoke;
                    data.ExpTypes[rightSide] = type;
                    data.ExpTypes[arg1] =
                        data.ExpTypes[arg2] =
                        data.ExpTypes[arg3] = new ANamedType(new TIdentifier("int"), null);
                    data.SimpleMethodLinks[invoke] =
                        data.Libraries.Methods.First(func => func.GetName().Text == invoke.GetName().Text);
                }
                else if (aType.IsPrimitive("char"))//aType.GetName().Text == "char")
                {
                    //Dunno?!
                    rightSide = new ACharConstExp(new TCharLiteral("'\0'"));
                    data.ExpTypes[rightSide] = type;
                }
                else //Struct
                {
                    AStructDecl str = data.StructTypeLinks[aType];
                    foreach (AALocalDecl localDecl in str.GetLocals())
                    {
                        ALvalueExp reciever = new ALvalueExp(Util.MakeClone(lvalue, data));
                        AStructLvalue newLvalue = new AStructLvalue(reciever, new ADotDotType(new TDot(".")), new TIdentifier(localDecl.GetName().Text));
                        data.StructFieldLinks[newLvalue] = localDecl;
                        data.ExpTypes[reciever] = type;
                        data.LvalueTypes[newLvalue] = localDecl.GetType();
                        returner.AddRange(AssignDefault(newLvalue));
                    }
                    return returner;
                }
                AAssignmentExp assignment = new AAssignmentExp(new TAssign("="), Util.MakeClone(lvalue, data), rightSide);
                data.ExpTypes[assignment] = type;
                return new List<PStm>() { new AExpStm(new TSemicolon(";"), assignment) };
            }
            if (type is AArrayTempType)
            {
                AArrayTempType aType = (AArrayTempType)type;
                for (int i = 0; i < int.Parse(aType.GetIntDim().Text); i++)
                {
                    ALvalueExp reciever = new ALvalueExp(Util.MakeClone(lvalue, data));
                    AArrayLvalue newLvalue = new AArrayLvalue(new TLBracket("["), reciever, new AIntConstExp(new TIntegerLiteral(i.ToString())));
                    data.ExpTypes[reciever] = type;
                    data.LvalueTypes[newLvalue] = aType.GetType();
                    data.ExpTypes[newLvalue.GetIndex()] = new ANamedType(new TIdentifier("int"), null);
                    returner.AddRange(AssignDefault(newLvalue));
                }
                return returner;
            }

            throw new Exception("Unexpected type. (LivenessAnalasys.AssignDefault), got " + type);
        }
 public override void CaseAArrayLvalue(AArrayLvalue node)
 {
     InAArrayLvalue(node);
     if (node.GetIndex() != null)
     {
         node.GetIndex().Apply(this);
     }
     if (node.GetBase() != null)
     {
         node.GetBase().Apply(this);
     }
     if (node.GetToken() != null)
     {
         node.GetToken().Apply(this);
     }
     OutAArrayLvalue(node);
 }
            private void MakeAssignmentRightDynamic(PLvalue leftSide, PExp rightSide, PType type, AABlock block, ref int index)
            {
                if (Util.IsBulkCopy(type))
                {
                    if (type is ANamedType)
                    {
                        ANamedType aType = (ANamedType)type;
                        AStructDecl structDecl = data.StructTypeLinks[aType];
                        foreach (AALocalDecl localDecl in structDecl.GetLocals())
                        {
                            AStructLvalue newleftSide = new AStructLvalue(new ALvalueExp(leftSide),
                                                                          new ADotDotType(new TDot(".")),
                                                                          new TIdentifier(localDecl.GetName().Text));

                            ABinopExp newrightSide = new ABinopExp(rightSide, new APlusBinop(new TPlus("+")),
                                                     new AStringConstExp(
                                                         new TStringLiteral("\"." + localDecl.GetName().Text + "\"")));

                             data.ExpTypes[newrightSide] =
                                data.ExpTypes[newrightSide.GetRight()] =
                                new ANamedType(new TIdentifier("string"), null);

                            data.ExpTypes[newleftSide.GetReceiver()] = type;
                            data.LvalueTypes[newleftSide] = localDecl.GetType();

                            data.StructFieldLinks[newleftSide] = localDecl;

                            MakeAssignmentRightDynamic(newleftSide, newrightSide, localDecl.GetType(), block, ref index);
                        }
                    }
                    else
                    {//Is array type. Can Only be a constant array type
                        AArrayTempType aType = (AArrayTempType)type;
                        for (int i = 0; i < int.Parse(aType.GetIntDim().Text); i++)
                        {
                            AArrayLvalue newleftSide = new AArrayLvalue(new TLBracket("["), new ALvalueExp(leftSide), new AIntConstExp(new TIntegerLiteral(i.ToString())));

                            ABinopExp newrightSide = new ABinopExp(rightSide, new APlusBinop(new TPlus("+")),
                                                     new AStringConstExp(
                                                         new TStringLiteral("\"[" + i + "]\"")));
                            data.ExpTypes[newrightSide] =
                                data.ExpTypes[newrightSide.GetRight()] =
                                new ANamedType(new TIdentifier("string"), null);

                            data.ExpTypes[newleftSide.GetBase()] = type;
                            data.ExpTypes[newleftSide.GetIndex()] = new ANamedType(new TIdentifier("int"), null);
                            data.LvalueTypes[newleftSide] = aType.GetType();

                            MakeAssignmentRightDynamic(newleftSide, newrightSide, aType.GetType(), block, ref index);

                        }

                    }
                }
                else
                {
                    ANamedType aType;// = type is APointerType ? new ANamedType(new TIdentifier("string"), null) : (ANamedType)type;
                    if (type is APointerType)
                    {
                        if (Util.IsIntPointer(type, ((APointerType)type).GetType(), data))
                            aType = new ANamedType(new TIdentifier("int"), null);
                        else
                            aType = new ANamedType(new TIdentifier("string"), null);
                    }
                    else
                    {
                        aType = (ANamedType) type;
                    }
                    string capitalType = Util.Capitalize(aType.AsIdentifierString());//Char.ToUpper(aType.GetName().Text[0]) + aType.GetName().Text.Substring(1);
                    leftSide = Util.MakeClone(leftSide, data);
                    rightSide = Util.MakeClone(rightSide, data);

                    ABooleanConstExp trueConst1 = new ABooleanConstExp(new ATrueBool());
                    //ABooleanConstExp trueConst2 = new ABooleanConstExp(new ATrueBool());
                    ASimpleInvokeExp innerInvoke = new ASimpleInvokeExp(new TIdentifier("DataTableGet" + capitalType), new ArrayList() { trueConst1, rightSide });
                    //ASimpleInvokeExp outerInvoke = new ASimpleInvokeExp(new TIdentifier("DataTableSet" + capitalType), new ArrayList() { trueConst2, leftSide, innerInvoke });
                    AAssignmentExp assignment = new AAssignmentExp(new TAssign("="), leftSide, innerInvoke);
                    block.GetStatements().Insert(index, new AExpStm(new TSemicolon(";"), assignment));
                    index++;

                    data.ExpTypes[trueConst1] = new ANamedType(new TIdentifier("bool"), null);

                    data.ExpTypes[innerInvoke] = aType;
                    data.ExpTypes[assignment] = aType;

                    data.SimpleMethodLinks[innerInvoke] =
                        data.Libraries.Methods.First(m => m.GetName().Text == innerInvoke.GetName().Text);
                }
            }
        public override void OutAArrayLvalue(AArrayLvalue node)
        {
            PType type = data.ExpTypes[node.GetBase()];
            PType argType = data.ExpTypes[node.GetIndex()];

            List<APropertyDecl> matchingArrayProperties = new List<APropertyDecl>();
            List<APropertyDecl> implicitStructArrayProperties = new List<APropertyDecl>();

            if (type is ANamedType && data.StructTypeLinks.ContainsKey((ANamedType)type))
            {
                AStructDecl structDecl = data.StructTypeLinks[(ANamedType) type];
                foreach (APropertyDecl property in data.StructProperties[structDecl])
                {
                    if (property.GetName().Text == "")
                    {
                        PType proprtyArgType = data.ArrayPropertyLocals[property][0].GetType();
                        if (Assignable(argType, proprtyArgType))
                            matchingArrayProperties.Add(property);
                    }
                }
            }

            if (type is APointerType)
            {
                APointerType aType = (APointerType)type;
                PType baseType = aType.GetType();
                if (baseType is ANamedType && data.StructTypeLinks.ContainsKey((ANamedType)baseType))
                {
                    AStructDecl structDecl = data.StructTypeLinks[(ANamedType)baseType];
                    foreach (APropertyDecl property in data.StructProperties[structDecl])
                    {
                        if (property.GetName().Text == "")
                        {
                            PType proprtyArgType = data.ArrayPropertyLocals[property][0].GetType();
                            if (Assignable(argType, proprtyArgType))
                                implicitStructArrayProperties.Add(property);
                        }
                    }
                }
            }

            List<IList> visibleDecls = Util.GetVisibleDecls(node, true);
            foreach (IList declList in visibleDecls)
            {
                foreach (PDecl decl in declList)
                {
                    if (decl is AEnrichmentDecl)
                    {
                        AEnrichmentDecl enrichment = (AEnrichmentDecl)decl;
                        if (Util.TypesEqual(type, enrichment.GetType(), data))
                        {
                            foreach (PDecl enrichmentDecl in enrichment.GetDecl())
                            {
                                if (enrichmentDecl is APropertyDecl)
                                {
                                    APropertyDecl property = (APropertyDecl) enrichmentDecl;
                                    if (property.GetName().Text == "")
                                    {
                                        PType proprtyArgType = data.ArrayPropertyLocals[property][0].GetType();
                                        if (Assignable(argType, proprtyArgType))
                                            matchingArrayProperties.Add(property);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            bool matchesNormalArray = false;
            ALvalueExp replaceBaseExp = null;
            if (Assignable(argType, new ANamedType(new TIdentifier("int"), null)))
            {
                if (type is AArrayTempType)
                {
                    AArrayTempType aType = (AArrayTempType) type;
                    type = aType.GetType();
                    matchesNormalArray = true;
                }
                else if (type is ADynamicArrayType)
                {
                    ADynamicArrayType aType = (ADynamicArrayType) type;
                    type = aType.GetType();
                    matchesNormalArray = true;
                }
                else if (type is APointerType)
                {
                    //Implicit conversion for a[] to (*a)[]
                    APointerType aType = (APointerType) type;
                    if (aType.GetType() is AArrayTempType || aType.GetType() is ADynamicArrayType)
                    {
                        APointerLvalue pointer = new APointerLvalue(new TStar("*"), node.GetBase());
                        replaceBaseExp = new ALvalueExp(pointer);
                        matchesNormalArray = true;
                    }
                }
            }
            if (matchingArrayProperties.Count == 0 && !matchesNormalArray && implicitStructArrayProperties.Count == 0)
                errors.Add(new ErrorCollection.Error(node.GetToken(), currentSourceFile, LocRM.GetString("ErrorText72")));

            if (matchingArrayProperties.Count + (matchesNormalArray ? 1 : 0) > 1)
            {
                List<ErrorCollection.Error> subErrors = new List<ErrorCollection.Error>();
                foreach (APropertyDecl property in matchingArrayProperties)
                {
                    subErrors.Add(new ErrorCollection.Error(property.GetName(), LocRM.GetString("ErrorText62")));
                }
                if (matchesNormalArray)
                    subErrors.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText74")));
                errors.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText73"), false, subErrors.ToArray()));
                throw new ParserException(node.GetToken(), "TypeChecking.OutAArrayLvalue");
            }

            if (matchingArrayProperties.Count + (matchesNormalArray ? 1 : 0) == 0 &&
                implicitStructArrayProperties.Count > 1)
            {
                List<ErrorCollection.Error> subErrors = new List<ErrorCollection.Error>();
                foreach (APropertyDecl property in implicitStructArrayProperties)
                {
                    subErrors.Add(new ErrorCollection.Error(property.GetName(), LocRM.GetString("ErrorText62")));
                }
                errors.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText73"), false, subErrors.ToArray()));
                throw new ParserException(node.GetToken(), "TypeChecking.OutAArrayLvalue");
            }

            if (matchingArrayProperties.Count == 1)
            {
                APropertyDecl property = matchingArrayProperties[0];
                type = property.GetType();
                data.ArrayPropertyLinks[node] = new Util.Pair<APropertyDecl, bool>(property, false);

                CheckPropertyAccessibility(property, node.Parent() is AAssignmentExp, node.GetToken());
            }
            else if (implicitStructArrayProperties.Count == 1)
            {
                APropertyDecl property = implicitStructArrayProperties[0];
                type = property.GetType();
                data.ArrayPropertyLinks[node] = new Util.Pair<APropertyDecl, bool>(property, true);

                CheckPropertyAccessibility(property, node.Parent() is AAssignmentExp, node.GetToken());
            }

            if (replaceBaseExp == null)
                data.LvalueTypes[node] = type;
            else
            {
                node.SetBase(replaceBaseExp);
                //pointer.Apply(this);
                OutAPointerLvalue((APointerLvalue)replaceBaseExp.GetLvalue());
                OutALvalueExp(replaceBaseExp);
                OutAArrayLvalue(node);
            }

            //if (!Assignable(data.ExpTypes[node.GetIndex()], new ANamedType(new TIdentifier("int"), null)))
            //    errors.Add(new ErrorCollection.Error(node.GetToken(), currentSourceFile, "Indexes of arrays must be of integer type."));
        }
            private List<PStm> MakeAssignments(PLvalue lvalue, PExp exp, List<AALocalDecl> declChain)
            {
                PType type = data.LvalueTypes[lvalue]; //data.ExpTypes[exp];
                PType oldType = data.ExpTypes[exp];
                List<PStm> returner = new List<PStm>();
                if (type is ADynamicArrayType ||type is AArrayTempType)
                {
                    AArrayTempType aType;
                    if (type is ADynamicArrayType)
                        aType = (AArrayTempType) data.LvalueTypes[lvalue];
                    else
                        aType = (AArrayTempType) type;
                    for (int j = 0; j < int.Parse(aType.GetIntDim().Text); j++)
                    {
                        ALvalueExp bulkCopyRefExp = new ALvalueExp(Util.MakeClone(lvalue, data));
                        AIntConstExp index1 = new AIntConstExp(new TIntegerLiteral(j.ToString()));
                        AArrayLvalue leftSideIndex = new AArrayLvalue(new TLBracket("{"), bulkCopyRefExp, index1);

                        AIntConstExp index2 = new AIntConstExp(new TIntegerLiteral(j.ToString()));
                        AArrayLvalue rightSideIndex = new AArrayLvalue(new TLBracket("{"), Util.MakeClone(exp, data), index2);
                        ALvalueExp rightSideExp = new ALvalueExp(rightSideIndex);
                        data.ExpTypes[bulkCopyRefExp] = data.LvalueTypes[lvalue];
                        data.ExpTypes[index1] =
                            data.ExpTypes[index2] = new ANamedType(new TIdentifier("int"), null);
                        data.LvalueTypes[leftSideIndex] =
                            data.LvalueTypes[rightSideIndex] =
                            data.ExpTypes[rightSideExp] = aType.GetType();
                        returner.AddRange(MakeAssignments(leftSideIndex, rightSideExp, declChain));
                    }
                }
                else if (type is ANamedType)
                {
                    ANamedType aType = (ANamedType) type;
                    if (Util.IsBulkCopy(type))
                    {
                        AStructDecl str = data.StructTypeLinks[aType];
                        foreach (AALocalDecl localDecl in str.GetLocals())
                        {
                            ALvalueExp bulkCopyRefExp = new ALvalueExp(Util.MakeClone(lvalue, data));
                            AStructLvalue leftSide = new AStructLvalue(bulkCopyRefExp, new ADotDotType(new TDot(".")),
                                                                       new TIdentifier(localDecl.GetName().Text));

                            AStructLvalue rightSide = new AStructLvalue(Util.MakeClone(exp, data), new ADotDotType(new TDot(".")),
                                                                       new TIdentifier(localDecl.GetName().Text));
                            ALvalueExp rightSideExp = new ALvalueExp(rightSide);
                            List<AALocalDecl> newDeclChain = new List<AALocalDecl>();
                            newDeclChain.AddRange(declChain);
                            newDeclChain.Add(localDecl);
                            data.StructFieldLinks[leftSide] =
                                data.StructFieldLinks[rightSide] = localDecl;
                            data.ExpTypes[bulkCopyRefExp] = data.LvalueTypes[lvalue];
                            data.LvalueTypes[leftSide] =
                                data.LvalueTypes[rightSide] =
                                data.ExpTypes[rightSideExp] = localDecl.GetType();
                            returner.AddRange(MakeAssignments(leftSide, rightSideExp, newDeclChain));
                        }
                    }
                    else
                    {
                        //Primitive, find out if it is used
                        if (declChain[0] == null || UsedParameters[Util.GetAncestor<AMethodDecl>(declChain[0])].Where(usedParameter => usedParameter.Count <= declChain.Count).Any(
                                usedParameter => !usedParameter.Where((t, i) => t != declChain[i]).Any()))
                        {
                            AAssignmentExp assignment = new AAssignmentExp(new TAssign("="),
                                                                           Util.MakeClone(lvalue, data),
                                                                           Util.MakeClone(exp, data));
                            data.ExpTypes[assignment] = data.LvalueTypes[lvalue];
                            returner.Add(new AExpStm(new TSemicolon(";"), assignment));
                        }
                    }
                }
                else if (type is APointerType)
                {
                    //Assign as primitive, find out if it is used
                    if (declChain[0] == null || UsedParameters[Util.GetAncestor<AMethodDecl>(declChain[0])].Where(usedParameter => usedParameter.Count <= declChain.Count).Any(
                            usedParameter => !usedParameter.Where((t, i) => t != declChain[i]).Any()))
                    {
                        AAssignmentExp assignment = new AAssignmentExp(new TAssign("="),
                                                                       Util.MakeClone(lvalue, data),
                                                                       Util.MakeClone(exp, data));
                        data.ExpTypes[assignment] = data.LvalueTypes[lvalue];
                        returner.Add(new AExpStm(new TSemicolon(";"), assignment));
                    }
                }
                else
                {
                    throw new Exception("Unexpected type. Got " + (type == null ? "null" : type.ToString()));
                }
                return returner;
            }
            private static AMethodDecl CreateNullCheckMethodP(Node node, TIntegerLiteral intLiteral, string prefix, GlobalStructVars vars, SharedData data)
            {
                /*
                 *
                            <<usedBits := floor(log2(42))+1>>
                            <<bitsLeft := 31 - usedBits>>
                            <<biggestIdentifier := 2^(bitsLeft + 1) - 1>>
                 *
                 *  bool prefix_IsNull(int pointer)
                 *  {
                 *      int identifier;
                 *      if (pointer == 0)
                 *      {
                 *          return true;
                 *      }
                 *      identifier = pointer & biggestIdentifier;
                 *      pointer = pointer >> bitsLeft;
                 *      return (Str_used[pointer / 31] & (1 << (pointer % 31))) == 0 || identifierArray[pointer] != identifier;
                 *  }
                 */
                int usedLimit = int.Parse(intLiteral.Text);
                int usedBits = usedLimit == 0 ? 0 : ((int)Math.Floor(Math.Log(usedLimit, 2)) + 1);
                int bitsLeft = 31 - usedBits;
                int biggestIdentifier = (1 << (bitsLeft + 1)) - 1;

                AALocalDecl pointerDecl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null,
                                                          new ANamedType(new TIdentifier("int"), null),
                                                          new TIdentifier("pointer"), null);
                AALocalDecl identifierDecl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null,
                                                             new ANamedType(new TIdentifier("int"), null),
                                                             new TIdentifier("identifier"), null);

                ALocalLvalue pointerRef1 = new ALocalLvalue(new TIdentifier("pointer"));
                ALocalLvalue pointerRef2 = new ALocalLvalue(new TIdentifier("pointer"));
                ALocalLvalue pointerRef3 = new ALocalLvalue(new TIdentifier("pointer"));
                ALocalLvalue pointerRef4 = new ALocalLvalue(new TIdentifier("pointer"));
                ALocalLvalue pointerRef5 = new ALocalLvalue(new TIdentifier("pointer"));
                ALocalLvalue pointerRef6 = new ALocalLvalue(new TIdentifier("pointer"));
                ALocalLvalue pointerRef7 = new ALocalLvalue(new TIdentifier("pointer"));
                ALvalueExp pointerRef1Exp = new ALvalueExp(pointerRef1);
                ALvalueExp pointerRef2Exp = new ALvalueExp(pointerRef2);
                ALvalueExp pointerRef4Exp = new ALvalueExp(pointerRef4);
                ALvalueExp pointerRef5Exp = new ALvalueExp(pointerRef5);
                ALvalueExp pointerRef6Exp = new ALvalueExp(pointerRef6);
                ALvalueExp pointerRef7Exp = new ALvalueExp(pointerRef7);

                ALocalLvalue identifierRef1 = new ALocalLvalue(new TIdentifier("identifier"));
                ALocalLvalue identifierRef2 = new ALocalLvalue(new TIdentifier("identifier"));
                ALvalueExp identifierRef2Exp = new ALvalueExp(identifierRef2);

                AFieldLvalue usedRef = new AFieldLvalue(new TIdentifier("used"));
                ALvalueExp usedRefExp = new ALvalueExp(usedRef);

                AFieldLvalue identifierArrayRef = new AFieldLvalue(new TIdentifier("identifierArray"));
                ALvalueExp identifierArrayRefExp = new ALvalueExp(identifierArrayRef);

                AIntConstExp intConst1 = new AIntConstExp(new TIntegerLiteral("0"));
                AIntConstExp intConst2 = new AIntConstExp(new TIntegerLiteral(biggestIdentifier.ToString()));
                AIntConstExp intConst3 = new AIntConstExp(new TIntegerLiteral(bitsLeft.ToString()));
                AIntConstExp intConst4 = new AIntConstExp(new TIntegerLiteral("31"));
                AIntConstExp intConst5 = new AIntConstExp(new TIntegerLiteral("1"));
                AIntConstExp intConst6 = new AIntConstExp(new TIntegerLiteral("31"));
                AIntConstExp intConst7 = new AIntConstExp(new TIntegerLiteral("0"));

                ABinopExp binop4 = new ABinopExp(pointerRef5Exp, new ADivideBinop(new TDiv("/")), intConst4);

                AArrayLvalue arrayLvalue1 = new AArrayLvalue(new TLBracket("["), usedRefExp, binop4);
                AArrayLvalue arrayLvalue2 = new AArrayLvalue(new TLBracket("["), identifierArrayRefExp, pointerRef7Exp);
                ALvalueExp arrayLvalue1Exp = new ALvalueExp(arrayLvalue1);
                ALvalueExp arrayLvalue2Exp = new ALvalueExp(arrayLvalue2);

                ABinopExp binop1 = new ABinopExp(pointerRef1Exp, new AEqBinop(new TEq("==")), intConst1);
                ABinopExp binop2 = new ABinopExp(pointerRef2Exp, new AAndBinop(new TAnd("&")), intConst2);
                ABinopExp binop3 = new ABinopExp(pointerRef4Exp, new ARBitShiftBinop(new TRBitShift(">>")), intConst3);
                ABinopExp binop5 = new ABinopExp(pointerRef6Exp, new AModuloBinop(new TMod("%")), intConst6);
                ABinopExp binop6 = new ABinopExp(intConst5, new ALBitShiftBinop(new TLBitShift("<<")), binop5);
                ABinopExp binop7 = new ABinopExp(arrayLvalue1Exp, new AAndBinop(new TAnd("&")), binop6);
                ABinopExp binop8 = new ABinopExp(binop7, new AEqBinop(new TEq("==")), intConst7);
                ABinopExp binop9 = new ABinopExp(arrayLvalue2Exp, new ANeBinop(new TNeq("!=")), identifierRef2Exp);
                ABinopExp binop10 = new ABinopExp(binop8, new ALazyOrBinop(new TOrOr("||")), binop9);

                AAssignmentExp assignment1 = new AAssignmentExp(new TAssign("="), identifierRef1, binop2);
                AAssignmentExp assignment2 = new AAssignmentExp(new TAssign("="), pointerRef3, binop3);

                ABooleanConstExp boolConst = new ABooleanConstExp(new ATrueBool());

                AMethodDecl method = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null,
                                                     new ANamedType(new TIdentifier("bool"), null),
                                                     new TIdentifier(prefix + "_IsNull"), new ArrayList() {pointerDecl},
                                                     new AABlock(
                                                         new ArrayList()
                                                             {
                                                                 new ALocalDeclStm(new TSemicolon(";"), identifierDecl),
                                                                 new AIfThenStm(new TLParen("("), binop1,
                                                                                new ABlockStm(new TLBrace("{"),
                                                                                              new AABlock(
                                                                                                  new ArrayList()
                                                                                                      {
                                                                                                          new AValueReturnStm
                                                                                                              (new TReturn(
                                                                                                                   "return"),
                                                                                                               boolConst)
                                                                                                      },
                                                                                                  new TRBrace("}")))),
                                                                 new AExpStm(new TSemicolon(";"), assignment1),
                                                                 new AExpStm(new TSemicolon(";"), assignment2),
                                                                 new AValueReturnStm(new TReturn("return"), binop10)
                                                             },
                                                         new TRBrace("}")));

                AASourceFile sourceFile = Util.GetAncestor<AASourceFile>(node);
                sourceFile.GetDecl().Add(method);

                data.LocalLinks[pointerRef1] =
                    data.LocalLinks[pointerRef2] =
                    data.LocalLinks[pointerRef3] =
                    data.LocalLinks[pointerRef4] =
                    data.LocalLinks[pointerRef5] =
                    data.LocalLinks[pointerRef6] =
                    data.LocalLinks[pointerRef7] = pointerDecl;

                data.LocalLinks[identifierRef1] =
                    data.LocalLinks[identifierRef2] = identifierDecl;

                data.FieldLinks[usedRef] = vars.Used;
                data.FieldLinks[identifierArrayRef] = vars.IdentifierArray;

                data.LvalueTypes[pointerRef1] =
                    data.LvalueTypes[pointerRef2] =
                    data.LvalueTypes[pointerRef3] =
                    data.LvalueTypes[pointerRef4] =
                    data.LvalueTypes[pointerRef5] =
                    data.LvalueTypes[pointerRef6] =
                    data.LvalueTypes[pointerRef7] =
                    data.ExpTypes[pointerRef1Exp] =
                    data.ExpTypes[pointerRef2Exp] =
                    data.ExpTypes[pointerRef4Exp] =
                    data.ExpTypes[pointerRef5Exp] =
                    data.ExpTypes[pointerRef6Exp] =
                    data.ExpTypes[pointerRef7Exp] =
                    data.LvalueTypes[identifierRef1] =
                    data.LvalueTypes[identifierRef2] =
                    data.ExpTypes[identifierRef2Exp] =
                    data.ExpTypes[intConst1] =
                    data.ExpTypes[intConst2] =
                    data.ExpTypes[intConst3] =
                    data.ExpTypes[intConst4] =
                    data.ExpTypes[intConst5] =
                    data.ExpTypes[intConst6] =
                    data.ExpTypes[intConst7] =
                    data.ExpTypes[intConst1] =
                    data.ExpTypes[binop2] =
                    data.ExpTypes[binop3] =
                    data.ExpTypes[binop4] =
                    data.ExpTypes[binop5] =
                    data.ExpTypes[binop6] =
                    data.ExpTypes[binop7] =
                    data.LvalueTypes[arrayLvalue1] =
                    data.LvalueTypes[arrayLvalue2] =
                    data.ExpTypes[arrayLvalue1Exp] =
                    data.ExpTypes[arrayLvalue2Exp] =
                    data.ExpTypes[assignment1] =
                    data.ExpTypes[assignment2] = new ANamedType(new TIdentifier("int"), null);

                data.ExpTypes[binop1] =
                    data.ExpTypes[binop8] =
                    data.ExpTypes[binop9] =
                    data.ExpTypes[binop10] =
                    data.ExpTypes[boolConst] = new ANamedType(new TIdentifier("bool"), null);

                data.LvalueTypes[usedRef] =
                    data.LvalueTypes[identifierArrayRef] =
                    data.ExpTypes[usedRefExp] =
                    data.ExpTypes[identifierArrayRefExp] = vars.IdentifierArray.GetType();

                return method;
            }
            private static AMethodDecl CreateNewObjectMethodP(Node node, TIntegerLiteral intLiteral, string prefix, GlobalStructVars vars, SharedData data)
            {
                if (intLiteral == null)
                    return CreateNewObjectMethod(node, data);

                //if (createStructMethod.ContainsKey(structDecl))
                //    return createStructMethod[structDecl];

                /*
                    int CreateStr()
                    {
                        int i = Str_index;
                        while (Str_used[i / 31] & 1 << (i % 31))
                        {
                            i = i + 1;
                            if (i >= 42)
                            {
                                i = 0;
                            }
                            if (i == Str_index)
                            {
                                UIDisplayMessage(PlayerGroupAll(), c_messageAreaDebug, StringToText("Error: Unable to allocate more than 42 dynamic Str types"));
                                IntToString(1/0);
                            }
                        }
                        Str_used[i / 31] = Str_used[i / 31] + Power2(i % 31);
                        Str_index = i;
                        <<if it is being compared with null at any point in time>>
                            <<usedBits := floor(log2(42))+1>>
                            <<bitsLeft := 31 - usedBits>>
                            <<biggestIdentifier := 2^(bitsLeft + 1) - 1>>
                            identifierArray[i] = identifierNext;
                            i = (i << bitsLeft) + identifierNext;
                            identifierNext = identifierNext%biggestIdentifier + 1;
                        return i;
                    }
                 */

                AASourceFile file = Util.GetAncestor<AASourceFile>(node);

                AIntConstExp intConst1 = new AIntConstExp(new TIntegerLiteral("31"));
                AIntConstExp intConst2 = new AIntConstExp(new TIntegerLiteral("31"));
                AIntConstExp intConst3 = new AIntConstExp(new TIntegerLiteral("1"));
                AIntConstExp intConst4 = new AIntConstExp(new TIntegerLiteral(intLiteral.Text));
                AIntConstExp intConst5 = new AIntConstExp(new TIntegerLiteral("0"));
                AIntConstExp intConst6 = new AIntConstExp(new TIntegerLiteral("1"));
                AIntConstExp intConst7 = new AIntConstExp(new TIntegerLiteral("0"));
                AIntConstExp intConst8 = new AIntConstExp(new TIntegerLiteral("31"));
                AIntConstExp intConst9 = new AIntConstExp(new TIntegerLiteral("31"));
                AIntConstExp intConst10 = new AIntConstExp(new TIntegerLiteral("31"));

                AIntConstExp intConst11 = new AIntConstExp(new TIntegerLiteral("1"));
                AIntConstExp intConst12 = new AIntConstExp(new TIntegerLiteral("1"));

                AFieldLvalue strIndexRef1 = new AFieldLvalue(new TIdentifier(vars.Index.GetName().Text));
                AFieldLvalue strIndexRef2 = new AFieldLvalue(new TIdentifier(vars.Index.GetName().Text));
                AFieldLvalue strIndexRef3 = new AFieldLvalue(new TIdentifier(vars.Index.GetName().Text));
                ALvalueExp strIndexRef1Exp = new ALvalueExp(strIndexRef1);
                ALvalueExp strIndexRef2Exp = new ALvalueExp(strIndexRef2);

                AFieldLvalue strUsedRef1 = new AFieldLvalue(new TIdentifier(vars.Used.GetName().Text));
                AFieldLvalue strUsedRef2 = new AFieldLvalue(new TIdentifier(vars.Used.GetName().Text));
                AFieldLvalue strUsedRef3 = new AFieldLvalue(new TIdentifier(vars.Used.GetName().Text));
                ALvalueExp strUsedRef1Exp = new ALvalueExp(strUsedRef1);
                ALvalueExp strUsedRef2Exp = new ALvalueExp(strUsedRef2);
                ALvalueExp strUsedRef3Exp = new ALvalueExp(strUsedRef3);

                AALocalDecl iDecl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, new ANamedType(new TIdentifier("int"), null),
                                                    new TIdentifier("i"), strIndexRef1Exp);
                ALocalLvalue iRef1 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef2 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef3 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef4 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef5 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef6 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef7 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef8 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef9 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef10 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef11 = new ALocalLvalue(new TIdentifier("i"));
                ALocalLvalue iRef12 = new ALocalLvalue(new TIdentifier("i"));
                ALvalueExp iRef1Exp = new ALvalueExp(iRef1);
                ALvalueExp iRef2Exp = new ALvalueExp(iRef2);
                ALvalueExp iRef4Exp = new ALvalueExp(iRef4);
                ALvalueExp iRef5Exp = new ALvalueExp(iRef5);
                ALvalueExp iRef7Exp = new ALvalueExp(iRef7);
                ALvalueExp iRef8Exp = new ALvalueExp(iRef8);
                ALvalueExp iRef9Exp = new ALvalueExp(iRef9);
                ALvalueExp iRef10Exp = new ALvalueExp(iRef10);
                ALvalueExp iRef11Exp = new ALvalueExp(iRef11);
                ALvalueExp iRef12Exp = new ALvalueExp(iRef12);

                ABinopExp binop1 = new ABinopExp(iRef1Exp, new ADivideBinop(new TDiv("/")), intConst1);
                ABinopExp binop2 = new ABinopExp(iRef2Exp, new AModuloBinop(new TMod("%")), intConst2);
                ABinopExp binop3 = new ABinopExp(null, new AAndBinop(new TAnd("&")), null);
                ABinopExp binop4 = new ABinopExp(iRef4Exp, new APlusBinop(new TPlus("+")), intConst3);
                ABinopExp binop5 = new ABinopExp(iRef5Exp, new AGeBinop(new TGteq(">=")), intConst4);
                ABinopExp binop6 = new ABinopExp(iRef7Exp, new AEqBinop(new TEq("==")), strIndexRef2Exp);
                ABinopExp binop7 = new ABinopExp(intConst6, new ADivideBinop(new TDiv("/")), intConst7);
                ABinopExp binop8 = new ABinopExp(iRef8Exp, new ADivideBinop(new TDiv("/")), intConst8);
                ABinopExp binop9 = new ABinopExp(iRef9Exp, new ADivideBinop(new TDiv("/")), intConst9);
                ABinopExp binop10 = new ABinopExp(iRef10Exp, new AModuloBinop(new TMod("%")), intConst10);
                ABinopExp binop11 = new ABinopExp(null, new APlusBinop(new TPlus("+")), null);

                ABinopExp binop12 = new ABinopExp(intConst11, new ALBitShiftBinop(new TLBitShift("<<")), binop2);
                ABinopExp binop13 = new ABinopExp(intConst12, new ALBitShiftBinop(new TLBitShift("<<")), binop10);
                binop3.SetRight(binop12);
                binop11.SetRight(binop13);

                //ASimpleInvokeExp power2Invoke1 = new ASimpleInvokeExp(new TIdentifier("Power2"), new ArrayList() { binop2 });
                //ASimpleInvokeExp power2Invoke2 = new ASimpleInvokeExp(new TIdentifier("Power2"), new ArrayList() { binop10 });
                //binop3.SetRight(power2Invoke1);
                //binop11.SetRight(power2Invoke2);

                AArrayLvalue arrayIndex1 = new AArrayLvalue(new TLBracket("["), strUsedRef1Exp, binop1);
                AArrayLvalue arrayIndex2 = new AArrayLvalue(new TLBracket("["), strUsedRef2Exp, binop8);
                AArrayLvalue arrayIndex3 = new AArrayLvalue(new TLBracket("["), strUsedRef3Exp, binop9);
                ALvalueExp arrayIndex1Exp = new ALvalueExp(arrayIndex1);
                ALvalueExp arrayIndex3Exp = new ALvalueExp(arrayIndex3);
                binop3.SetLeft(arrayIndex1Exp);
                binop11.SetLeft(arrayIndex3Exp);

                AAssignmentExp assignement1 = new AAssignmentExp(new TAssign("="), iRef3, binop4);
                AAssignmentExp assignement2 = new AAssignmentExp(new TAssign("="), iRef6, intConst5);
                AAssignmentExp assignement3 = new AAssignmentExp(new TAssign("="), arrayIndex2, binop11);
                AAssignmentExp assignement4 = new AAssignmentExp(new TAssign("="), strIndexRef3, iRef11Exp);

                ASimpleInvokeExp playerGroupAllInvoke = new ASimpleInvokeExp(new TIdentifier("PlayerGroupAll"), new ArrayList());
                AFieldLvalue messageAreaDebugRef = new AFieldLvalue(new TIdentifier("c_messageAreaDebug"));
                ALvalueExp messageAreaDebugRefExp = new ALvalueExp(messageAreaDebugRef);
                AStringConstExp stringConst =
                    new AStringConstExp(
                        new TStringLiteral("\"Galaxy++ Error: Unable to allocate more than " + intLiteral.Text +
                                           " dynamic " + prefix + " types.\""));
                ASimpleInvokeExp stringToTextInvoke = new ASimpleInvokeExp(new TIdentifier("StringToText"), new ArrayList() { stringConst });
                ASimpleInvokeExp displayMessageInvoke = new ASimpleInvokeExp(new TIdentifier("UIDisplayMessage"),
                                                                             new ArrayList()
                                                                                 {
                                                                                     playerGroupAllInvoke,
                                                                                     messageAreaDebugRefExp,
                                                                                     stringToTextInvoke
                                                                                 });
                ASimpleInvokeExp intToStringInvoke = new ASimpleInvokeExp(new TIdentifier("IntToString"),
                                                                          new ArrayList() { binop7 });

                AABlock methodBlock = new AABlock(
                    new ArrayList()
                        {
                            new ALocalDeclStm(new TSemicolon(";"), iDecl),
                            new AWhileStm(new TLParen("("), binop3,
                                          new ABlockStm(new TLBrace("{"),
                                                        new AABlock(
                                                            new ArrayList()
                                                                {
                                                                    new AExpStm
                                                                        (new TSemicolon
                                                                             (";"),
                                                                         assignement1),
                                                                    new AIfThenStm
                                                                        (new TLParen
                                                                             ("("),
                                                                         binop5,
                                                                         new ABlockStm
                                                                             (new TLBrace
                                                                                  ("{"),
                                                                              new AABlock
                                                                                  (new ArrayList
                                                                                       ()
                                                                                       {
                                                                                           new AExpStm
                                                                                               (new TSemicolon
                                                                                                    (";"),
                                                                                                assignement2)
                                                                                       },
                                                                                   new TRBrace
                                                                                       ("}")))),
                                                                    new AIfThenStm
                                                                        (new TLParen
                                                                             ("("),
                                                                         binop6,
                                                                         new ABlockStm
                                                                             (new TLBrace
                                                                                  ("{"),
                                                                              new AABlock
                                                                                  (new ArrayList
                                                                                       ()
                                                                                       {
                                                                                           new AExpStm
                                                                                               (new TSemicolon
                                                                                                    (";"),
                                                                                                displayMessageInvoke),
                                                                                           new AExpStm
                                                                                               (new TSemicolon
                                                                                                    (";"),
                                                                                                intToStringInvoke)
                                                                                       },
                                                                                   new TRBrace
                                                                                       ("}"))))
                                                                },
                                                            new TRBrace(
                                                                "}")))),
                            new AExpStm(new TSemicolon(";"), assignement3),
                            new AExpStm(new TSemicolon(";"), assignement4)
                        },
                    new TRBrace("}"));

                if (vars.IdentifierArray != null)
                {
                    /*
                        <<if it is being compared with null at any point in time>>
                            <<usedBits := floor(log2(42))+1>>
                            <<bitsLeft := 31 - usedBits>>
                            <<biggestIdentifier := 2^(bitsLeft + 1) - 1>>
                            identifierArray[i] = identifierNext;
                            i = (i << bitsLeft) + identifierNext;
                            identifierNext = identifierNext%biggestIdentifier + 1;
                    */
                    int usedLimit = int.Parse(intLiteral.Text);
                    int usedBits = usedLimit == 0 ? 0 : ((int)Math.Floor(Math.Log(usedLimit, 2)) + 1);
                    int bitsLeft = 31 - usedBits;
                    int biggestIdentifier = (1 << (bitsLeft + 1)) - 1;

                    AIntConstExp bitsLeftConst = new AIntConstExp(new TIntegerLiteral(bitsLeft.ToString()));
                    AIntConstExp biggestIdentifierConst = new AIntConstExp(new TIntegerLiteral(biggestIdentifier.ToString()));
                    AIntConstExp oneIntConst = new AIntConstExp(new TIntegerLiteral("1"));
                    ALocalLvalue secondIRef1 = new ALocalLvalue(new TIdentifier("i"));
                    ALocalLvalue secondIRef2 = new ALocalLvalue(new TIdentifier("i"));
                    ALocalLvalue secondIRef3 = new ALocalLvalue(new TIdentifier("i"));
                    ALvalueExp secondIRef2Exp = new ALvalueExp(secondIRef2);
                    ALvalueExp secondIRef3Exp = new ALvalueExp(secondIRef3);
                    AFieldLvalue identierNExtRef1 = new AFieldLvalue(new TIdentifier("identiferNext"));
                    AFieldLvalue identierNExtRef2 = new AFieldLvalue(new TIdentifier("identiferNext"));
                    AFieldLvalue identierNExtRef3 = new AFieldLvalue(new TIdentifier("identiferNext"));
                    AFieldLvalue identierNExtRef4 = new AFieldLvalue(new TIdentifier("identiferNext"));
                    ALvalueExp identierNExtRef1Exp = new ALvalueExp(identierNExtRef1);
                    ALvalueExp identierNExtRef3Exp = new ALvalueExp(identierNExtRef3);
                    ALvalueExp identierNExtRef4Exp = new ALvalueExp(identierNExtRef4);
                    AFieldLvalue identifierArrayRef = new AFieldLvalue(new TIdentifier("identifierArray"));
                    ALvalueExp identifierArrayRefExp = new ALvalueExp(identifierArrayRef);

                    AArrayLvalue arrayLvalue = new AArrayLvalue(new TLBracket("["), identifierArrayRefExp, secondIRef3Exp);

                    AAssignmentExp secondAssignment3 = new AAssignmentExp(new TAssign("="), arrayLvalue, identierNExtRef4Exp);

                    methodBlock.GetStatements().Add(new AExpStm(new TSemicolon(";"), secondAssignment3));

                    ABinopExp secondBinop1 = new ABinopExp(secondIRef2Exp, new ALBitShiftBinop(new TLBitShift("<<")), bitsLeftConst);
                    ABinopExp secondBinop2 = new ABinopExp(secondBinop1, new APlusBinop(new TPlus("+")), identierNExtRef1Exp);

                    AAssignmentExp secondAssignment1 = new AAssignmentExp(new TAssign("="), secondIRef1, secondBinop2);

                    methodBlock.GetStatements().Add(new AExpStm(new TSemicolon(";"), secondAssignment1));

                    ABinopExp secondBinop3 = new ABinopExp(identierNExtRef3Exp, new AModuloBinop(new TMod("%")), biggestIdentifierConst);
                    ABinopExp secondBinop4 = new ABinopExp(secondBinop3, new APlusBinop(new TPlus("+")), oneIntConst);

                    AAssignmentExp secondAssignment2 = new AAssignmentExp(new TAssign("="), identierNExtRef2, secondBinop4);

                    methodBlock.GetStatements().Add(new AExpStm(new TSemicolon(";"), secondAssignment2));

                    data.LvalueTypes[secondIRef1] =
                        data.LvalueTypes[secondIRef2] =
                        data.ExpTypes[bitsLeftConst] =
                        data.ExpTypes[biggestIdentifierConst] =
                        data.ExpTypes[oneIntConst] =
                        data.ExpTypes[secondIRef2Exp] =
                        data.LvalueTypes[identierNExtRef1] =
                        data.LvalueTypes[identierNExtRef2] =
                        data.LvalueTypes[identierNExtRef3] =
                        data.ExpTypes[identierNExtRef1Exp] =
                        data.ExpTypes[identierNExtRef3Exp] =
                        data.ExpTypes[secondBinop1] =
                        data.ExpTypes[secondBinop2] =
                        data.ExpTypes[secondAssignment1] =
                        data.ExpTypes[secondBinop3] =
                        data.ExpTypes[secondBinop4] =
                        data.ExpTypes[secondAssignment2] =
                        data.LvalueTypes[secondIRef3] =
                        data.LvalueTypes[identierNExtRef4] =
                        data.ExpTypes[secondIRef3Exp] =
                        data.ExpTypes[identierNExtRef4Exp] =
                        data.LvalueTypes[arrayLvalue] =
                        data.ExpTypes[secondAssignment3] = new ANamedType(new TIdentifier("int"), null);

                    data.LvalueTypes[identifierArrayRef] =
                        data.ExpTypes[identifierArrayRefExp] = vars.IdentifierArray.GetType();

                    data.LocalLinks[secondIRef1] =
                        data.LocalLinks[secondIRef2] =
                        data.LocalLinks[secondIRef3] = iDecl;

                    data.FieldLinks[identierNExtRef1] =
                        data.FieldLinks[identierNExtRef2] =
                        data.FieldLinks[identierNExtRef3] =
                        data.FieldLinks[identierNExtRef4] = vars.IdentifierNext;

                    data.FieldLinks[identifierArrayRef] = vars.IdentifierArray;
                }

                methodBlock.GetStatements().Add(new AValueReturnStm(new TReturn("return"), iRef12Exp));

                AMethodDecl method = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null,
                                                                 new ANamedType(new TIdentifier("int"), null),
                                                                 new TIdentifier("Create" + prefix, data.LineCounts[file] + 18, 0),
                                                                 new ArrayList(),
                                                                 methodBlock);

                file.GetDecl().Add(method);
                data.Methods.Add(new SharedData.DeclItem<AMethodDecl>(file, method));

                data.LocalLinks[iRef1] =
                    data.LocalLinks[iRef2] =
                    data.LocalLinks[iRef3] =
                    data.LocalLinks[iRef4] =
                    data.LocalLinks[iRef5] =
                    data.LocalLinks[iRef6] =
                    data.LocalLinks[iRef7] =
                    data.LocalLinks[iRef8] =
                    data.LocalLinks[iRef9] =
                    data.LocalLinks[iRef10] =
                    data.LocalLinks[iRef11] =
                    data.LocalLinks[iRef12] = iDecl;
                data.FieldLinks[strUsedRef1] =
                    data.FieldLinks[strUsedRef2] =
                    data.FieldLinks[strUsedRef3] = vars.Used;
                data.FieldLinks[strIndexRef1] =
                    data.FieldLinks[strIndexRef2] =
                    data.FieldLinks[strIndexRef3] = vars.Index;
                //data.SimpleMethodLinks[power2Invoke1] =
                //    data.SimpleMethodLinks[power2Invoke2] = CreatePower2Method(node, data);
                data.FieldLinks[messageAreaDebugRef] =
                    data.Libraries.Fields.First(f => f.GetName().Text == messageAreaDebugRef.GetName().Text);
                data.SimpleMethodLinks[displayMessageInvoke] =
                    data.Libraries.Methods.First(m => m.GetName().Text == displayMessageInvoke.GetName().Text);
                data.SimpleMethodLinks[playerGroupAllInvoke] =
                    data.Libraries.Methods.First(m => m.GetName().Text == playerGroupAllInvoke.GetName().Text);
                data.SimpleMethodLinks[stringToTextInvoke] =
                    data.Libraries.Methods.First(m => m.GetName().Text == stringToTextInvoke.GetName().Text);
                data.SimpleMethodLinks[intToStringInvoke] =
                    data.Libraries.Methods.First(m => m.GetName().Text == intToStringInvoke.GetName().Text);

                data.ExpTypes[intConst1] =
                    data.ExpTypes[intConst2] =
                    data.ExpTypes[intConst3] =
                    data.ExpTypes[intConst4] =
                    data.ExpTypes[intConst5] =
                    data.ExpTypes[intConst6] =
                    data.ExpTypes[intConst7] =
                    data.ExpTypes[intConst8] =
                    data.ExpTypes[intConst9] =
                    data.ExpTypes[intConst10] =
                    data.ExpTypes[intConst11] =
                    data.ExpTypes[intConst12] =
                    data.LvalueTypes[strIndexRef1] =
                    data.LvalueTypes[strIndexRef2] =
                    data.LvalueTypes[strIndexRef3] =
                    data.ExpTypes[strIndexRef1Exp] =
                    data.ExpTypes[strIndexRef2Exp] =
                    data.LvalueTypes[iRef1] =
                    data.LvalueTypes[iRef2] =
                    data.LvalueTypes[iRef3] =
                    data.LvalueTypes[iRef4] =
                    data.LvalueTypes[iRef5] =
                    data.LvalueTypes[iRef6] =
                    data.LvalueTypes[iRef7] =
                    data.LvalueTypes[iRef8] =
                    data.LvalueTypes[iRef9] =
                    data.LvalueTypes[iRef10] =
                    data.LvalueTypes[iRef11] =
                    data.LvalueTypes[iRef12] =
                    data.ExpTypes[iRef1Exp] =
                    data.ExpTypes[iRef2Exp] =
                    data.ExpTypes[iRef4Exp] =
                    data.ExpTypes[iRef5Exp] =
                    data.ExpTypes[iRef7Exp] =
                    data.ExpTypes[iRef8Exp] =
                    data.ExpTypes[iRef9Exp] =
                    data.ExpTypes[iRef10Exp] =
                    data.ExpTypes[iRef11Exp] =
                    data.ExpTypes[iRef12Exp] =
                    data.LvalueTypes[arrayIndex1] =
                    data.LvalueTypes[arrayIndex2] =
                    data.LvalueTypes[arrayIndex3] =
                    data.ExpTypes[arrayIndex1Exp] =
                    data.ExpTypes[arrayIndex3Exp] =
                    data.ExpTypes[binop1] =
                    data.ExpTypes[binop2] =
                    data.ExpTypes[binop3] =
                    data.ExpTypes[binop4] =
                    data.ExpTypes[binop7] =
                    data.ExpTypes[binop8] =
                    data.ExpTypes[binop9] =
                    data.ExpTypes[binop10] =
                    data.ExpTypes[binop11] =
                    data.ExpTypes[binop12] =
                    data.ExpTypes[binop13] =
                    //data.ExpTypes[power2Invoke1] =
                    //data.ExpTypes[power2Invoke2] =
                    data.ExpTypes[intToStringInvoke] =
                    data.ExpTypes[assignement1] =
                    data.ExpTypes[assignement2] =
                    data.ExpTypes[assignement3] =
                    data.ExpTypes[assignement4] =
                    data.LvalueTypes[messageAreaDebugRef] =
                    data.ExpTypes[messageAreaDebugRefExp] = new ANamedType(new TIdentifier("int"), null);

                data.LvalueTypes[strUsedRef1] =
                    data.LvalueTypes[strUsedRef2] =
                    data.LvalueTypes[strUsedRef3] =
                    data.ExpTypes[strUsedRef1Exp] =
                    data.ExpTypes[strUsedRef2Exp] =
                    data.ExpTypes[strUsedRef3Exp] = vars.Used.GetType();

                data.ExpTypes[binop5] =
                    data.ExpTypes[binop6] = new ANamedType(new TIdentifier("int"), null);

                data.ExpTypes[stringConst] =
                    data.ExpTypes[intToStringInvoke] = new ANamedType(new TIdentifier("string"), null);

                data.ExpTypes[stringToTextInvoke] = new ANamedType(new TIdentifier("text"), null);

                data.ExpTypes[playerGroupAllInvoke] = new ANamedType(new TIdentifier("playergroup"), null);

                data.ExpTypes[displayMessageInvoke] = new AVoidType(new TVoid("void"));

                return method;
            }
            public override void CaseAPointerLvalue(APointerLvalue node)
            {
                hadPointer = false;
                nameExp = null;
                base.CaseAPointerLvalue(node);
                if (Util.IsIntPointer(node, data.LvalueTypes[node], data))
                {
                    if (nameExp != null)
                    {
                        //Create a data table get string exp
                        nameExp = CreateDynaicGetStm("int");
                    }
                    else
                    {
                        nameExp = node.GetBase();
                    }
                    //Replace by str_Array[<base>];
                    //If this is a compared pointer, replace it by str_Array[<base> >> <<bitsLeft>>]
                    GlobalStructVars vars;
                    int allocateLimit;
                    if (data.EnrichmentTypeLinks.ContainsKey(data.LvalueTypes[node]))
                    {
                        AEnrichmentDecl enrichmentDecl = data.EnrichmentTypeLinks[data.LvalueTypes[node]];
                        vars = CreateEnrichmentFields(node, enrichmentDecl, data);
                        allocateLimit = int.Parse(enrichmentDecl.GetIntDim().Text);
                    }
                    else
                    {
                        AStructDecl structDecl = data.StructTypeLinks[(ANamedType)data.LvalueTypes[node]];
                        vars = CreateStructFields(node, structDecl, data);
                        allocateLimit = int.Parse(structDecl.GetIntDim().Text);
                    }

                    AFieldLvalue array = new AFieldLvalue(new TIdentifier(vars.Array.GetName().Text));
                    ALvalueExp arrayExp = new ALvalueExp(array);

                    PExp arrayIndex = nameExp;
                    if (vars.IdentifierArray != null)
                    {
                        int usedBits = allocateLimit == 0 ? 0 : ((int)Math.Floor(Math.Log(allocateLimit, 2)) + 1);
                        int bitsLeft = 31 - usedBits;
                        int biggestIdentifier = (1 << (bitsLeft + 1)) - 1;

                        AIntConstExp bitsLeftConst = new AIntConstExp(new TIntegerLiteral(bitsLeft.ToString()));
                        arrayIndex = new ABinopExp(arrayIndex, new ARBitShiftBinop(new TRBitShift(">>")), bitsLeftConst);

                        data.ExpTypes[bitsLeftConst] =
                            data.ExpTypes[arrayIndex] = new ANamedType(new TIdentifier("int"), null);
                    }

                    AArrayLvalue replacer = new AArrayLvalue(new TLBracket("["), arrayExp, arrayIndex);
                    node.ReplaceBy(replacer);

                    data.FieldLinks[array] = vars.Array;
                    data.LvalueTypes[array] = data.ExpTypes[arrayExp] = vars.Array.GetType();
                    data.LvalueTypes[replacer] = ((AArrayTempType) vars.Array.GetType()).GetType();

                    hadPointer = false;
                    nameExp = null;
                    return;
                }
                //if (Util.GetAncestor<AAssignmentExp>(node) != null || Util.GetAncestor<APArrayLengthLvalue>(node) != null)
                {
                    if (nameExp != null)
                    {
                        //Create a data table get string exp

                        nameExp = CreateDynaicGetStm("string");
                    }
                    else
                    {
                        nameExp = node.GetBase();
                    }
                }
                hadPointer = true;
                CheckDynamicLvalue(node);
                //Todo: Insert runtime check that the pointer is actually not null / points to a delete object
                //(unless the same pointer was checked before, and it has not been assigned to since, and there has not been a method call since.
            }
            public override void CaseAArrayLvalue(AArrayLvalue node)
            {
                hadPointer = false;
                node.GetIndex().Apply(this);
                if (hadPointer)
                {//The index is a dynamic int
                    string typeName = ((ANamedType) data.ExpTypes[node.GetIndex()]).AsString();
                    node.GetIndex().ReplaceBy(CreateDynaicGetStm(typeName));
                }
                node.GetBase().Apply(this);
                if (hadPointer)
                {

                    //if (Util.GetAncestor<AAssignmentExp>(node) != null || Util.GetAncestor<APArrayLengthLvalue>(node) != null)
                    {
                        //Todo: Check if the index is within array (runtime)

                        ASimpleInvokeExp intToString = new ASimpleInvokeExp(new TIdentifier("IntToString"),
                                                                            new ArrayList());
                        intToString.GetArgs().Add(Util.MakeClone(node.GetIndex(), data));

                        ABinopExp binopExp1 = new ABinopExp(nameExp, new APlusBinop(new TPlus("+")), new AStringConstExp(new TStringLiteral("\"[\"")));
                        ABinopExp binopExp2 = new ABinopExp(binopExp1, new APlusBinop(new TPlus("+")), intToString);
                        ABinopExp binopExp3 = new ABinopExp(binopExp2, new APlusBinop(new TPlus("+")), new AStringConstExp(new TStringLiteral("\"]\"")));

                        data.ExpTypes[binopExp1] =
                        data.ExpTypes[binopExp2] =
                        data.ExpTypes[binopExp3] =
                        data.ExpTypes[binopExp1.GetRight()] =
                        data.ExpTypes[binopExp3.GetRight()] =
                            data.ExpTypes[intToString] =new ANamedType(new TIdentifier("string"), null);
                        data.SimpleMethodLinks[intToString] =
                            data.Libraries.Methods.First(method => method.GetName().Text == intToString.GetName().Text);
                        nameExp = binopExp3;
                    }
                    CheckDynamicLvalue(node);
                }
            }
 public override void CaseAArrayLvalue(AArrayLvalue node)
 {
     IsConst = false;
 }
        private void MakeAssignments(AABlock block, PType type, PLvalue leftSide, bool onEnhritedFields)
        {
            if (type is ANamedType && data.StructTypeLinks.ContainsKey((ANamedType) type))
            {
                AStructDecl str = data.StructTypeLinks[(ANamedType) type];
                foreach (AALocalDecl field in str.GetLocals().OfType<AALocalDecl>())
                {
                    if (!onEnhritedFields && data.EnheritanceLocalMap.ContainsKey(field))
                        continue;

                    ALvalueExp lvalueExp = new ALvalueExp(Util.MakeClone(leftSide, data));
                    data.ExpTypes[lvalueExp] = data.LvalueTypes[leftSide];
                    AStructLvalue newLeftSide = new AStructLvalue(lvalueExp, new ADotDotType(new TDot(".")), new TIdentifier(field.GetName().Text));
                    data.StructFieldLinks[newLeftSide] = field;
                    data.LvalueTypes[newLeftSide] = field.GetType();

                    if (field.GetInit() != null)
                    {
                        AAssignmentExp assignment = new AAssignmentExp(new TAssign("="), newLeftSide,
                                                                       Util.MakeClone(field.GetInit(), data));
                        data.ExpTypes[assignment] = data.LvalueTypes[newLeftSide];

                        block.GetStatements().Add(new AExpStm(new TSemicolon(";"),
                                                              assignment));
                    }
                    else
                    {
                        MakeAssignments(block, field.GetType(), newLeftSide, onEnhritedFields);
                    }
                }
            }
            else if (type is AArrayTempType)
            {
                AArrayTempType aType = (AArrayTempType) type;
                for (int i = 0; i < int.Parse(aType.GetIntDim().Text); i++)
                {
                    AIntConstExp index = new AIntConstExp(new TIntegerLiteral(i.ToString()));
                    data.ExpTypes[index] = new ANamedType(new TIdentifier("int"), null);

                    ALvalueExp lvalueExp = new ALvalueExp(Util.MakeClone(leftSide, data));
                    data.ExpTypes[lvalueExp] = data.LvalueTypes[leftSide];
                    AArrayLvalue newLeftSide = new AArrayLvalue(new TLBracket("["), lvalueExp, index);
                    data.LvalueTypes[newLeftSide] = aType.GetType();

                    MakeAssignments(block, aType.GetType(), newLeftSide, onEnhritedFields);
                }
            }
        }
 public override void CaseAArrayLvalue(AArrayLvalue node)
 {
     node.GetBase().Apply(this);
 }
 public override void CaseAArrayLvalue(AArrayLvalue node)
 {
     bool wasLeftAssign = isLeftAssign;
     node.GetBase().Apply(this);
     isLeftAssign = false;
     node.GetIndex().Apply(this);
     isLeftAssign = wasLeftAssign;
 }
 public virtual void CaseAArrayLvalue(AArrayLvalue node)
 {
     DefaultCase(node);
 }
 ArrayList New336()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList4 = (ArrayList) Pop();
     ArrayList nodeArrayList3 = (ArrayList) Pop();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TLBracket tlbracketNode2 = (TLBracket)nodeArrayList2[0];
     TypedList listNode7 = new TypedList();
     TypedList listNode6 = (TypedList)nodeArrayList1[0];
     if ( listNode6 != null )
     {
     listNode7.AddAll(listNode6);
     }
     AAName pnameNode5 = new AAName (
       listNode7
     );
     AAmbiguousNameLvalue plvalueNode4 = new AAmbiguousNameLvalue (
       pnameNode5
     );
     ALvalueExp pexpNode3 = new ALvalueExp (
       plvalueNode4
     );
     PExp pexpNode8 = (PExp)nodeArrayList3[0];
     AArrayLvalue plvalueNode1 = new AArrayLvalue (
       tlbracketNode2,
       pexpNode3,
       pexpNode8
     );
     nodeList.Add(plvalueNode1);
     return nodeList;
 }
 public virtual void OutAArrayLvalue(AArrayLvalue node)
 {
     DefaultOut(node);
 }
 public override void CaseAArrayLvalue(AArrayLvalue node)
 {
     node.GetIndex().Apply(this);
     currentLocal = null;
     node.GetBase().Apply(this);
 }