public StructDescription(AStructDecl structDecl)
        {
            Parser parser = new Parser(structDecl);

            Name = parser.Name;
            IsEnum = Name.StartsWith("enum ");
            if (IsEnum)
            {
                Name = Name.Substring(5);
                foreach (VariableDescription field in parser.Fields)
                {
                    field.PlacementPrefix = "Enum Field";
                }
            }
            Fields = parser.Fields;

            Methods = parser.Methods;
            Constructors = parser.Constructors;
            Deconstructors = parser.Deconstructors;
            LineFrom = structDecl.GetName().Line;
            LineTo = structDecl.GetEndToken().Line;
            if (structDecl.GetBase() is AGenericType)
                BaseRef = (ANamedType) ((AGenericType) structDecl.GetBase()).GetBase();
            else
                BaseRef = (ANamedType) structDecl.GetBase();
            structDecl.RemoveChild(BaseRef);
            foreach (TIdentifier identifier in structDecl.GetGenericVars())
            {
                GenericVars.Add(identifier.Text);
            }
            IsClass = structDecl.GetClassToken() != null;
            Visibility = (PVisibilityModifier)structDecl.GetVisibilityModifier().Clone();
            Position = TextPoint.FromCompilerCoords(structDecl.GetName());
        }
 private void CheckStructDependancies(AStructDecl currentStr, List<AStructDecl> checkedStructs, List<AStructDecl> path)
 {
     if (path.Contains(currentStr))
     {
         List<ErrorCollection.Error> subErrors = new List<ErrorCollection.Error>();
         for (int i = path.IndexOf(currentStr); i < path.Count; i++)
         {
             subErrors.Add(new ErrorCollection.Error(path[i].GetName(), Util.GetAncestor<AASourceFile>(path[i]), LocRM.GetString("ErrorText70")));
         }
         subErrors.Add(new ErrorCollection.Error(currentStr.GetName(), Util.GetAncestor<AASourceFile>(currentStr), LocRM.GetString("ErrorText70")));
         errors.Add(new ErrorCollection.Error(currentStr.GetName(), Util.GetAncestor<AASourceFile>(currentStr),
                                              LocRM.GetString("ErrorText71"),
                                              false, subErrors.ToArray()));
     }
     if (!checkedStructs.Contains(currentStr))
     {
         checkedStructs.Add(currentStr);
         path.Add(currentStr);
         foreach (AStructDecl nextStruct in StructDepandancies[currentStr])
         {
             CheckStructDependancies(nextStruct, checkedStructs, path);
         }
         path.Remove(currentStr);
     }
 }
 public override void CaseAStructDecl(AStructDecl node)
 {
     Write("struct " + node.GetName().Text + "\n{\n");
     foreach (AALocalDecl local in node.GetLocals().OfType<AALocalDecl>())
     {
         local.Apply(this);
         Write(";\n");
     }
     Write("};\n");
 }
 public override void CaseAStructDecl(AStructDecl node)
 {
     if (node.GetDimention() != null && !data.IsLiteCompile)
     {
         //Find int dim
         foldIntegerConstants = true;
         isInANewExp = true;//If false, we dont require a value
         node.GetDimention().Apply(this);
         isInANewExp = false;
         foldIntegerConstants = false;
         if (foldingFailed)
         {
             errors.Add(new ErrorCollection.Error(node.GetName(), currentSourceFile, LocRM.GetString("ErrorText166")));
             throw new ParserException(node.GetName(), "TypeLinking.CaseAStructDecl");
         }
         node.SetIntDim(new TIntegerLiteral(integerConstant.ToString()));
     }
     base.CaseAStructDecl(node);
 }
 public override void OutAStructDecl(AStructDecl node)
 {
     //Insert parameterless constructor
     if (
         !node.GetLocals().OfType<ADeclLocalDecl>().Select(localDecl => localDecl.GetDecl()).OfType
              <AConstructorDecl>().Any(constructor => constructor.GetFormals().Count == 0))
     {
         node.GetLocals().Add(
             new ADeclLocalDecl(new AConstructorDecl(new APublicVisibilityModifier(),
                                                     new TIdentifier(node.GetName().Text), new ArrayList(),
                                                     new ArrayList(),
                                                     new AABlock(new ArrayList(), new TRBrace("}")))));
     }
 }
        public override void OutAEnumDecl(AEnumDecl node)
        {
            AStructDecl replacer = new AStructDecl(node.GetVisibilityModifier(), null, null, null, node.GetEndToken(),
                                                   node.GetName(), new ArrayList(), null, new ArrayList());

            int intVal = 0;
            //int min = int.MaxValue;
            //int max = int.MinValue;
            //List<TIdentifier> types = new List<TIdentifier>();
            foreach (AAEnumLocal value in node.GetValues())
            {
                AIntConstExp intConst;
                if (value.GetValue() != null)
                {
                    intConst = (AIntConstExp) value.GetValue();
                    intVal = int.Parse(intConst.GetIntegerLiteral().Text) + 1;
                }
                else
                {
                    intConst = new AIntConstExp(new TIntegerLiteral(intVal.ToString(), value.GetName().Line, value.GetName().Pos));
                    intVal++;
                }
            //    min = Math.Min(intVal - 1, min);
            //    max = Math.Max(intVal - 1, max);
                TIdentifier typeIdentifier = new TIdentifier(replacer.GetName().Text, value.GetName().Line, value.GetName().Pos);
               // types.Add(typeIdentifier);
                AALocalDecl localDecl = new AALocalDecl(new APublicVisibilityModifier(),
                                                        new TStatic("static", value.GetName().Line, value.GetName().Pos),
                                                        null, null,
                                                        new TConst("const", value.GetName().Line, value.GetName().Pos),
                                                        new ANamedType(typeIdentifier, null), value.GetName(), intConst);
                replacer.GetLocals().Add(localDecl);
            }
             /*   if (min < 0 || max > 255)
                foreach (TIdentifier identifier in types)
                {
                    identifier.Text = "int";
                }*/
            node.ReplaceBy(replacer);

            replacer.Apply(this);
            replacer.GetName().Text = "enum " + replacer.GetName().Text;
        }
예제 #7
0
            public static AMethodDecl CreateDeleteStructMethodDataTable(Node node, AStructDecl structDecl, SharedData data)
            {
                AALocalDecl idDecl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, new ANamedType(new TIdentifier("string"), null), new TIdentifier("id"), null);
                AABlock block = new AABlock();
                AMethodDecl method = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null, new AVoidType(new TVoid("void")),
                                                     new TIdentifier("Delete" + structDecl.GetName().Text), new ArrayList() { idDecl }, block);

                ALocalLvalue idLink = new ALocalLvalue(new TIdentifier("id"));
                ALvalueExp idLinkExp = new ALvalueExp(idLink);

                data.Locals[block] = new List<AALocalDecl> { idDecl };
                data.LocalLinks[idLink] = idDecl;

                data.LvalueTypes[idLink] =
                    data.ExpTypes[idLinkExp] = new ANamedType(new TIdentifier("string"), null);

                ANamedType structType = new ANamedType(new TIdentifier(structDecl.GetName().Text), null);
                data.StructTypeLinks[structType] = structDecl;

                AddRemoves(idLinkExp, structType, block, data);

                AASourceFile sourceFile = Util.GetAncestor<AASourceFile>(node);
                sourceFile.GetDecl().Add(method);
                data.Methods.Add(new SharedData.DeclItem<AMethodDecl>(sourceFile, method));

                deleteStructMethod[structDecl] = method;
                return method;
            }
예제 #8
0
        public override void OutAStructDecl(AStructDecl node)
        {
            //Insert parameterless constructor
            if (
                !node.GetLocals().OfType<ADeclLocalDecl>().Select(localDecl => localDecl.GetDecl()).OfType
                     <AConstructorDecl>().Any(constructor => constructor.GetFormals().Count == 0))
            {
                PLocalDecl decl = new ADeclLocalDecl(new AConstructorDecl(new APublicVisibilityModifier(),
                                                                          new TIdentifier(node.GetName().Text),
                                                                          new ArrayList(),
                                                                          new ArrayList(),
                                                                          new AABlock(new ArrayList(), new TRBrace("}"))));
                node.GetLocals().Add(decl);
                decl.Apply(this);
            }

            //Add deconstructor if not present
            if (node.GetLocals().OfType<ADeclLocalDecl>().Select(localDecl => localDecl.GetDecl()).OfType<ADeconstructorDecl>().ToList().Count == 0)
            {
                PLocalDecl decl =
                    new ADeclLocalDecl(new ADeconstructorDecl(new APublicVisibilityModifier(),
                                                              new TIdentifier(node.GetName().Text), new ArrayList(),
                                                              new AABlock(new ArrayList(), new TRBrace("}"))));
                node.GetLocals().Add(decl);
                decl.Apply(this);
            }

            if (node.GetVisibilityModifier() is AProtectedVisibilityModifier)
                errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText201")));
        }
 public override void InAStructDecl(AStructDecl node)
 {
     node.GetName().Text = namespacePrefix + node.GetName().Text;
 }
예제 #10
0
 public override void CaseAStructDecl(AStructDecl node)
 {
     if (Structs.Any(structDecl => structDecl.GetName().Text == node.GetName().Text))
     {
         return;
     }
     Structs.Add(node);
     StructMethods.Add(node, new List<AMethodDecl>());
     StructFields.Add(node, new List<AALocalDecl>());
     base.CaseAStructDecl(node);
     node.Parent().RemoveChild(node);
 }
        public override void OutAStructDecl(AStructDecl node)
        {
            //Insert init in each constructor
            AThisLvalue thisLvalue = new AThisLvalue(new TThis("this"));
            ALvalueExp thisExp = new ALvalueExp(thisLvalue);
            APointerLvalue pointerLvalue = new APointerLvalue(new TStar("*"), thisExp);

            ANamedType namedType = new ANamedType(new TIdentifier(node.GetName().Text), null);
            data.StructTypeLinks[namedType] = node;
            data.LvalueTypes[thisLvalue] =
                data.ExpTypes[thisExp] = new APointerType(new TStar("*"), namedType);
            data.LvalueTypes[pointerLvalue] = namedType;

            foreach (AConstructorDecl constructor in node.GetLocals().OfType<ADeclLocalDecl>().Select(decl => decl.GetDecl()).OfType<AConstructorDecl>())
            {
                AABlock block = new AABlock(new ArrayList(), new TRBrace("}"));
                MakeAssignments(block, namedType, pointerLvalue, false);

                ((AABlock)constructor.GetBlock()).GetStatements().Insert(0, new ABlockStm(new TLBrace("{"), block));
            }

            base.OutAStructDecl(node);
        }
예제 #12
0
            //+20
            public static GlobalStructVars CreateStructFields(Node node, AStructDecl structDecl, SharedData data)
            {
                if (structFields.ContainsKey(structDecl))
                    return structFields[structDecl];

                ANamedType structType = new ANamedType(new TIdentifier(structDecl.GetName().Text), null);
                data.StructTypeLinks[structType] = structDecl;

                structFields[structDecl] = CreatePointerFields(node, structDecl.GetIntDim(), structDecl.GetName().Text,
                                                               structType, data, structDecl.GetLocals().Count > 0);
                return structFields[structDecl];
                /*
                AASourceFile file = Util.GetAncestor<AASourceFile>(node);

                ANamedType structType = new ANamedType(new TIdentifier(structDecl.GetName().Text), null);
                data.StructTypeLinks[structType] = structDecl;
                AFieldDecl array = new AFieldDecl(new APublicVisibilityModifier(), null, null,
                                                  new AArrayTempType(new TLBracket("["), structType,
                                                                     new AIntConstExp(
                                                                         new TIntegerLiteral(structDecl.GetIntDim().Text)),
                                                                     new TIntegerLiteral(structDecl.GetIntDim().Text)),
                                                                     new TIdentifier(structDecl.GetName().Text + "_array", data.LineCounts[file] + 20, 0),
                                                                     null);
                int length = (int) Math.Ceiling(float.Parse(structDecl.GetIntDim().Text)/31);
                AFieldDecl used = new AFieldDecl(new APublicVisibilityModifier(), null, null,
                                                  new AArrayTempType(new TLBracket("["), new ANamedType(new TIdentifier("int"), null),
                                                                     new AIntConstExp(
                                                                         new TIntegerLiteral(length.ToString())),
                                                                     new TIntegerLiteral(length.ToString())),
                                                                     new TIdentifier(structDecl.GetName().Text + "_used", data.LineCounts[file] + 20, 0),
                                                                     null);
                AFieldDecl index = new AFieldDecl(new APublicVisibilityModifier(), null, null,  new ANamedType(new TIdentifier("int"), null),
                                                                     new TIdentifier(structDecl.GetName().Text + "_index", data.LineCounts[file] + 20, 0),
                                                                     null);
                file.GetDecl().Add(array);
                file.GetDecl().Add(used);
                file.GetDecl().Add(index);

                data.ExpTypes[((AArrayTempType) array.GetType()).GetDimention()] =
                    data.ExpTypes[((AArrayTempType) used.GetType()).GetDimention()] =
                    new ANamedType(new TIdentifier("int"), null);

                data.Fields.Add(new SharedData.DeclItem<AFieldDecl>(file, array));
                data.Fields.Add(new SharedData.DeclItem<AFieldDecl>(file, used));
                data.Fields.Add(new SharedData.DeclItem<AFieldDecl>(file, index));

                structFields[structDecl] = new GlobalStructVars(array, used, index);
                return structFields[structDecl];*/
            }
예제 #13
0
            //+19
            /*public static AMethodDecl CreatePower2Method(Node node, SharedData data)
            {
                if (power2Method != null)
                    return power2Method;

                /*
                    int Power2(int i)
                    {
                        int ret = 1;
                        while (i > 0)
                        {
                            ret = ret * 2;
                            i = i - 1;
                        }
                        return ret;
                    }
                 */
            /*
                AASourceFile file = Util.GetAncestor<AASourceFile>(node);

                AIntConstExp intConst1 = new AIntConstExp(new TIntegerLiteral("1"));
                AIntConstExp intConst2 = new AIntConstExp(new TIntegerLiteral("0"));
                AIntConstExp intConst3 = new AIntConstExp(new TIntegerLiteral("2"));
                AIntConstExp intConst4 = new AIntConstExp(new TIntegerLiteral("1"));

                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"));
                ALvalueExp iRef1Exp = new ALvalueExp(iRef1);
                ALvalueExp iRef3Exp = new ALvalueExp(iRef3);

                AALocalDecl retDecl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, new ANamedType(new TIdentifier("int"), null),
                                                    new TIdentifier("ret"), intConst1);
                ALocalLvalue retRef1 = new ALocalLvalue(new TIdentifier("ret"));
                ALocalLvalue retRef2 = new ALocalLvalue(new TIdentifier("ret"));
                ALocalLvalue retRef3 = new ALocalLvalue(new TIdentifier("ret"));
                ALvalueExp retRef2Exp = new ALvalueExp(retRef2);
                ALvalueExp retRef3Exp = new ALvalueExp(retRef3);

                ABinopExp binop1 = new ABinopExp(iRef1Exp, new AGtBinop(new TGt(">")), intConst2);
                ABinopExp binop2 = new ABinopExp(retRef2Exp, new ATimesBinop(new TStar("*")), intConst3);
                ABinopExp binop3 = new ABinopExp(iRef3Exp, new AMinusBinop(new TMinus("-")), intConst4);

                AAssignmentExp assignment1 = new AAssignmentExp(new TAssign("="), retRef1, binop2);
                AAssignmentExp assignment2 = new AAssignmentExp(new TAssign("="), iRef2, binop3);

                power2Method = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null,
                                                     new ANamedType(new TIdentifier("int"), null),
                                                     new TIdentifier("Power2", data.LineCounts[file] + 19, 0),
                                                     new ArrayList() {iDecl},
                                                     new AABlock(
                                                         new ArrayList()
                                                             {
                                                                 new ALocalDeclStm(new TSemicolon(";"), retDecl),
                                                                 new AWhileStm(new TLParen("("), binop1,
                                                                               new ABlockStm(new TLBrace("{"),
                                                                                             new AABlock(
                                                                                                 new ArrayList()
                                                                                                     {
                                                                                                         new AExpStm(
                                                                                                             new TSemicolon
                                                                                                                 (";"),
                                                                                                             assignment1),
                                                                                                         new AExpStm(
                                                                                                             new TSemicolon
                                                                                                                 (";"),
                                                                                                             assignment2)
                                                                                                     },
                                                                                                 new TRBrace("}")))),
                                                                 new AValueReturnStm(new TReturn("return"), retRef3Exp)
                                                             },
                                                         new TRBrace("}")));

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

                data.LocalLinks[iRef1] =
                    data.LocalLinks[iRef2] =
                    data.LocalLinks[iRef3] = iDecl;
                data.LocalLinks[retRef1] =
                    data.LocalLinks[retRef2] =
                    data.LocalLinks[retRef3] = retDecl;
                data.ExpTypes[intConst1] =
                    data.ExpTypes[intConst2] =
                    data.ExpTypes[intConst3] =
                    data.ExpTypes[intConst4] =
                    data.LvalueTypes[iRef1] =
                    data.LvalueTypes[iRef2] =
                    data.LvalueTypes[iRef3] =
                    data.ExpTypes[iRef1Exp] =
                    data.ExpTypes[iRef3Exp] =
                    data.LvalueTypes[retRef1] =
                    data.LvalueTypes[retRef2] =
                    data.LvalueTypes[retRef3] =
                    data.ExpTypes[retRef2Exp] =
                    data.ExpTypes[retRef3Exp] =
                    data.ExpTypes[binop2] =
                    data.ExpTypes[binop3] =
                    data.ExpTypes[assignment1] =
                    data.ExpTypes[assignment2] = new ANamedType(new TIdentifier("int"), null);
                data.ExpTypes[binop1] = new ANamedType(new TIdentifier("bool"), null);

                return power2Method;
            }*/
            //+18
            public static AMethodDecl CreateNewObjectMethod(Node node, AStructDecl structDecl, SharedData data)
            {
                /*if (structDecl.GetIntDim() == null)
                    return CreateNewObjectMethod(node, data);*/

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

                createStructMethod[structDecl] = CreateNewObjectMethodP(node, structDecl.GetIntDim(), structDecl.GetName().Text,
                                       CreateStructFields(node, structDecl, data), data);

                return createStructMethod[structDecl];

                #region Comment

                /*
                    int CreateStr()
                    {
                        int i = Str_index;
                        while (Str_used[i / 31] & Power2(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;
                        return i;
                    }
                 */

                /*AASourceFile file = Util.GetAncestor<AASourceFile>(node);
                GlobalStructVars vars = CreateStructFields(node, structDecl, data);

                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(structDecl.GetIntDim().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"));

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

                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 " + structDecl.GetIntDim().Text +
                                           " dynamic " + structDecl.GetName().Text + " 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});

                createStructMethod[structDecl] = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null,
                                                                 new ANamedType(new TIdentifier("int"), null),
                                                                 new TIdentifier("Create" + structDecl.GetName().Text, data.LineCounts[file] + 18, 0),
                                                                 new ArrayList(),
                                                                 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 AValueReturnStm(new TReturn("return"),
                                                                                                 iRef12Exp)
                                                                         },
                                                                     new TRBrace("}")));//66 lines! YEAH! you can see what that statement did

                file.GetDecl().Add(createStructMethod[structDecl]);

                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.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[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 createStructMethod[structDecl];*/

                #endregion
            }
예제 #14
0
            public static AMethodDecl CreateDeleteStructMethodGlobalArray(Node node, AStructDecl structDecl, SharedData data)
            {
                deleteStructMethod[structDecl] = CreateDeleteStructMethodGlobalArrayP(node, structDecl.GetIntDim(),
                                                                                      structDecl.GetName().Text,
                                                                                      CreateStructFields(node,
                                                                                                         structDecl,
                                                                                                         data), data);
                return deleteStructMethod[structDecl];

                #region Comment

                /*
                GlobalStructVars vars = CreateStructFields(node, structDecl, data);
                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(structDecl.GetIntDim().Text) - 1).ToString()));

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

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

                deleteStructMethod[structDecl] = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null,
                                                                 new AVoidType(new TVoid("void")),
                                                                 new TIdentifier("Delete" + structDecl.GetName().Text, 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(deleteStructMethod[structDecl]);

                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.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[paren1] =
                    data.ExpTypes[paren2] =
                    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 deleteStructMethod[structDecl];*/

                #endregion
            }
        private List<ErrorCollection.Error> FindStructMember(AStructDecl structDecl, AStructLvalue node, out bool linked, bool onlyStatic = false)
        {
            linked = false;
            List<ErrorCollection.Error> errors = new List<ErrorCollection.Error>();
            AALocalDecl matchingLocal = data.StructFields[structDecl].FirstOrDefault(
                local =>
                local.GetName().Text == node.GetName().Text);
            APropertyDecl matchingProperty = data.StructProperties[structDecl].FirstOrDefault(
                property => property.GetName().Text == node.GetName().Text);
            if (matchingLocal == null && matchingProperty == null)
            {
                errors.Add(new ErrorCollection.Error(node.GetName(), currentSourceFile,
                                                     LocRM.GetString("ErrorText79") + node.GetName().Text));
                errors.Add(new ErrorCollection.Error(structDecl.GetName(), Util.GetAncestor<AASourceFile>(structDecl),
                                                     LocRM.GetString("ErrorText80") + structDecl.GetName().Text));
                return errors;
            }
            bool isStatic = false;
            if (matchingProperty == null)
            {
                isStatic = matchingLocal.GetStatic() != null;
                //Check visibility
                AALocalDecl originalLocal = matchingLocal;
                if (data.EnheritanceLocalMap.ContainsKey(originalLocal))
                    originalLocal = data.EnheritanceLocalMap[originalLocal];

                if (originalLocal.GetVisibilityModifier() is APrivateVisibilityModifier &&
                    Util.GetAncestor<AStructDecl>(originalLocal) != Util.GetAncestor<AStructDecl>(node))
                {
                    errors.Add(new ErrorCollection.Error(node.GetName(),
                                                         LocRM.GetString("ErrorText81"),
                                                         false,
                                                         new ErrorCollection.Error(originalLocal.GetName(),
                                                                                   LocRM.GetString("ErrorText82"))));
                }
                else if (originalLocal.GetVisibilityModifier() is AProtectedVisibilityModifier &&
                         (!Util.HasAncestor<AStructDecl>(node) ||
                          !Util.Extends(Util.GetAncestor<AStructDecl>(originalLocal), Util.GetAncestor<AStructDecl>(node),
                                       data)))
                {
                    errors.Add(new ErrorCollection.Error(node.GetName(),
                                                         LocRM.GetString("ErrorText83"),
                                                         false,
                                                         new ErrorCollection.Error(originalLocal.GetName(),
                                                                                   LocRM.GetString("ErrorText82"))));
                }

                //Not the visiblity static thingy. The regular static
                if (matchingLocal.GetStatic() != null && !onlyStatic)
                {
                    errors.Add(new ErrorCollection.Error(node.GetName(),
                                                         LocRM.GetString("ErrorText84") +
                                                         structDecl.GetName().Text + "." + node.GetName().Text, false,
                                                         new ErrorCollection.Error(matchingLocal.GetName(),
                                                                                   LocRM.GetString("ErrorText85"))));
                }
                else if (matchingLocal.GetStatic() == null && onlyStatic)
                {
                    errors.Add(new ErrorCollection.Error(node.GetName(),
                                                         LocRM.GetString("ErrorText86") +
                                                         structDecl.GetName().Text + ".", false,
                                                         new ErrorCollection.Error(matchingLocal.GetName(),
                                                                                   LocRM.GetString("ErrorText85"))));
                }

                data.LvalueTypes[node] = matchingLocal.GetType();
                data.StructFieldLinks[node] = matchingLocal;
                linked = true;
            }
            else
            {
                //Check visibility
                if (matchingProperty.GetVisibilityModifier() is APrivateVisibilityModifier &&
                    Util.GetAncestor<AStructDecl>(matchingProperty) != Util.GetAncestor<AStructDecl>(node))
                {
                    errors.Add(new ErrorCollection.Error(node.GetName(),
                                                         LocRM.GetString("ErrorText87"),
                                                         false,
                                                         new ErrorCollection.Error(matchingProperty.GetName(),
                                                                                   LocRM.GetString("ErrorText82"))));
                }
                else if (matchingProperty.GetVisibilityModifier() is AProtectedVisibilityModifier &&
                         (!Util.HasAncestor<AStructDecl>(node) ||
                          !Util.Extends(Util.GetAncestor<AStructDecl>(node), Util.GetAncestor<AStructDecl>(matchingProperty),
                                       data)))
                {
                    errors.Add(new ErrorCollection.Error(node.GetName(),
                                                         LocRM.GetString("ErrorText88"),
                                                         false,
                                                         new ErrorCollection.Error(matchingProperty.GetName(),
                                                                                   LocRM.GetString("ErrorText82"))));
                }

                //Not the visiblity static thingy. The regular static
                if (matchingProperty.GetStatic() != null && !onlyStatic)
                {
                    errors.Add(new ErrorCollection.Error(node.GetName(),
                                                         LocRM.GetString("ErrorText89") +
                                                         structDecl.GetName().Text + "." + node.GetName().Text, false,
                                                         new ErrorCollection.Error(matchingProperty.GetName(),
                                                                                   LocRM.GetString("ErrorText90"))));
                }
                else if (matchingProperty.GetStatic() == null && onlyStatic)
                {
                    errors.Add(new ErrorCollection.Error(node.GetName(),
                                                         LocRM.GetString("ErrorText91") +
                                                         structDecl.GetName().Text + ".", false,
                                                         new ErrorCollection.Error(matchingProperty.GetName(),
                                                                                   LocRM.GetString("ErrorText90"))));
                }

                data.LvalueTypes[node] = matchingProperty.GetType();
                data.StructPropertyLinks[node] = matchingProperty;
                CheckPropertyAccessibility(matchingProperty, node.Parent() is AAssignmentExp, node.GetName());
                linked = true;
            }

            if (!isStatic && Util.GetAncestor<AMethodDecl>(node) == null && Util.GetAncestor<AConstructorDecl>(node) == null &&
                !Util.HasAncestor<ADeconstructorDecl>(node) && !Util.HasAncestor<APropertyDecl>(node))
            {
                errors.Add(new ErrorCollection.Error(node.GetName(), currentSourceFile,
                    LocRM.GetString("ErrorText92")));
            }
            return errors;
        }
예제 #16
0
        public override void OutAEnumDecl(AEnumDecl node)
        {
            AStructDecl replacer = new AStructDecl(node.GetVisibilityModifier(), null, null, null, node.GetEndToken(),
                                                   node.GetName(), new ArrayList(), null, new ArrayList());

            TIdentifier typeIdentifier = new TIdentifier("byte");
            ASwitchStm switchStm = new ASwitchStm(new TSwitch("switch"),
                                                  new ALvalueExp(
                                                      new AAmbiguousNameLvalue(new AAName(new ArrayList() {new TIdentifier("enum")}))),
                                                  new ArrayList());
                ;
            AMethodDecl toStringMethod = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null,
                                                         new ANamedType(new TIdentifier("string"), null),
                                                         new TIdentifier("toString"),
                                                         new ArrayList()
                                                             {
                                                                 new AALocalDecl(new APublicVisibilityModifier(), null,
                                                                                 null, null, null,
                                                                                 new ANamedType(typeIdentifier, null),
                                                                                 new TIdentifier("enum"), null)
                                                             },
                                                         new AABlock(
                                                             new ArrayList()
                                                                 {
                                                                     switchStm,
                                                                     new AValueReturnStm(new TReturn("return"), new ANullExp())
                                                                 }, new TRBrace("}")));
            replacer.GetLocals().Add(new ADeclLocalDecl(toStringMethod));

            int intVal = 0;
            int min = int.MaxValue;
            int max = int.MinValue;
            List<TIdentifier> types = new List<TIdentifier>(){typeIdentifier};
            Dictionary<int, List<AALocalDecl>> usedValues = new Dictionary<int, List<AALocalDecl>>();
            foreach (AAEnumLocal value in node.GetValues())
            {
                AIntConstExp intConst;
                if (value.GetValue() != null)
                {
                    intConst = (AIntConstExp) value.GetValue();
                    intVal = int.Parse(intConst.GetIntegerLiteral().Text) + 1;
                }
                else
                {
                    intConst = new AIntConstExp(new TIntegerLiteral(intVal.ToString(), value.GetName().Line, value.GetName().Pos));
                    intVal++;
                }
                min = Math.Min(intVal - 1, min);
                max = Math.Max(intVal - 1, max);
                typeIdentifier = new TIdentifier("byte", value.GetName().Line, value.GetName().Pos);
                types.Add(typeIdentifier);
                switchStm.GetCases().Add(
                    new ASwitchCaseStm(new ACaseSwitchCaseType(new TCase("case"), (PExp) intConst.Clone()),
                                       new AABlock(
                                           new ArrayList()
                                               {
                                                   new AValueReturnStm(new TReturn("return"),
                                                                       new AStringConstExp(
                                                                           new TStringLiteral("\"" +
                                                                                              value.GetName().Text +
                                                                                              "\"")))
                                               }, new TRBrace("}"))));
                AALocalDecl localDecl = new AALocalDecl(new APublicVisibilityModifier(),
                                                        new TStatic("static", value.GetName().Line, value.GetName().Pos),
                                                        null, null,
                                                        new TConst("const", value.GetName().Line, value.GetName().Pos),
                                                        new ANamedType(typeIdentifier, null), value.GetName(), intConst);
                replacer.GetLocals().Add(localDecl);
                if (!usedValues.ContainsKey(intVal - 1))
                    usedValues[intVal - 1] = new List<AALocalDecl>();
                usedValues[intVal - 1].Add(localDecl);
            }
            if (min < 0 || max > 255)
                foreach (TIdentifier identifier in types)
                {
                    identifier.Text = "int";
                }
            node.ReplaceBy(replacer);
            foreach (KeyValuePair<int, List<AALocalDecl>> pair in usedValues)
            {
                if (pair.Value.Count <= 1)
                    continue;
                int value = pair.Key;
                List<ErrorCollection.Error> subErrors = new List<ErrorCollection.Error>();
                foreach (AALocalDecl decl in pair.Value)
                {
                    subErrors.Add(new ErrorCollection.Error(decl.GetName(), LocRM.GetString("ErrorText179")));
                }
                errors.Add(new ErrorCollection.Error(replacer.GetName(), LocRM.GetString("ErrorText180") + value + ".", false, subErrors.ToArray()));
            }
            replacer.Apply(this);
            data.Enums.Add(replacer, min < 0 || max > 255);
        }
            public override void CaseAStructDecl(AStructDecl node)
            {
                Name = node.GetName().Text;

                base.CaseAStructDecl(node);
            }
예제 #18
0
 public override void CaseAStructDecl(AStructDecl node)
 {
     InAStructDecl(node);
     {
         Object[] temp = new Object[node.GetLocals().Count];
         node.GetLocals().CopyTo(temp, 0);
         for (int i = temp.Length - 1; i >= 0; i--)
         {
             ((PLocalDecl)temp[i]).Apply(this);
         }
     }
     if (node.GetBase() != null)
     {
         node.GetBase().Apply(this);
     }
     {
         Object[] temp = new Object[node.GetGenericVars().Count];
         node.GetGenericVars().CopyTo(temp, 0);
         for (int i = temp.Length - 1; i >= 0; i--)
         {
             ((TIdentifier)temp[i]).Apply(this);
         }
     }
     if (node.GetName() != null)
     {
         node.GetName().Apply(this);
     }
     if (node.GetEndToken() != null)
     {
         node.GetEndToken().Apply(this);
     }
     if (node.GetIntDim() != null)
     {
         node.GetIntDim().Apply(this);
     }
     if (node.GetDimention() != null)
     {
         node.GetDimention().Apply(this);
     }
     if (node.GetClassToken() != null)
     {
         node.GetClassToken().Apply(this);
     }
     if (node.GetVisibilityModifier() != null)
     {
         node.GetVisibilityModifier().Apply(this);
     }
     OutAStructDecl(node);
 }
 public override void CaseAStructDecl(AStructDecl node)
 {
     node.GetName().Text = currentNamespace + node.GetName().Text;
 }