public MethodDescription(ADeconstructorDecl method)
        {
            Parser parser = new Parser(method);

            Start = parser.Start;
            End = parser.End;
            ReturnType = "void";
            Name = parser.Name;
            Formals = parser.Formals;
            Locals = parser.Locals;
            if (method.Parent() != null)
                method.Parent().RemoveChild(method);
            while (method.GetFormals().Count > 0)
                Decl.GetFormals().Add(method.GetFormals()[0]);
            Visibility = method.GetVisibilityModifier();
            Position = TextPoint.FromCompilerCoords(method.GetName());
        }
Example #2
0
 internal Formals_Cast(ADeconstructorDecl obj)
 {
     this.obj = obj;
 }
            public override void CaseADeconstructorDecl(ADeconstructorDecl node)
            {
                End = Start = TextPoint.FromCompilerCoords(node.GetName().Line, node.GetName().Pos);
                Name = node.GetName().Text;

                base.CaseADeconstructorDecl(node);
            }
 public virtual void InADeconstructorDecl(ADeconstructorDecl node)
 {
     DefaultIn(node);
 }
 public virtual void OutADeconstructorDecl(ADeconstructorDecl node)
 {
     DefaultOut(node);
 }
 public override void CaseADeconstructorDecl(ADeconstructorDecl node)
 {
     InADeconstructorDecl(node);
     if (node.GetBlock() != null)
     {
         node.GetBlock().Apply(this);
     }
     {
         Object[] temp = new Object[node.GetFormals().Count];
         node.GetFormals().CopyTo(temp, 0);
         for (int i = temp.Length - 1; i >= 0; i--)
         {
             ((PLocalDecl)temp[i]).Apply(this);
         }
     }
     if (node.GetName() != null)
     {
         node.GetName().Apply(this);
     }
     if (node.GetVisibilityModifier() != null)
     {
         node.GetVisibilityModifier().Apply(this);
     }
     OutADeconstructorDecl(node);
 }
 public virtual void CaseADeconstructorDecl(ADeconstructorDecl node)
 {
     DefaultCase(node);
 }
        public override void OutADeconstructorDecl(ADeconstructorDecl node)
        {
            //If void return is missing, insert it.
            AABlock block = (AABlock)node.GetBlock();
            bool insertReturn = false;
            while (true)
            {
                if (block.GetStatements().Count == 0)
                {
                    insertReturn = true;
                    break;
                }
                PStm lastStm = (PStm)block.GetStatements()[block.GetStatements().Count - 1];
                if (lastStm is AVoidReturnStm)
                    break;
                if (lastStm is ABlockStm)
                {
                    block = (AABlock)((ABlockStm)block.GetStatements()[block.GetStatements().Count - 1]).GetBlock();
                    continue;
                }
                insertReturn = true;
                break;
            }
            if (insertReturn)
            {
                block.GetStatements().Add(new AVoidReturnStm(new TReturn("return", block.GetToken().Line, block.GetToken().Pos)));
            }

            //Must be no parameters
            if (node.GetFormals().Count > 0)
            {
                errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText193")));
            }

            if (node.GetVisibilityModifier() is AProtectedVisibilityModifier && Util.HasAncestor<AEnrichmentDecl>(node))
            {
                errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText194")));
            }

            base.OutADeconstructorDecl(node);
        }
        public override void OutADeconstructorDecl(ADeconstructorDecl node)
        {
            AStructDecl parentStruct = Util.GetAncestor<AStructDecl>(node);
            if (parentStruct != null)
            {
                if (data.StructDeconstructor.ContainsKey(parentStruct) && data.StructDeconstructor[parentStruct] != node)
                {
                    errors.Add(new ErrorCollection.Error(node.GetName(),
                                                         LocRM.GetString("ErrorText13") +
                                                         Util.GetTypeName(parentStruct) + ".", false,
                                                         new[]
                                                             {
                                                                 new ErrorCollection.Error(
                                                                     data.StructDeconstructor[parentStruct].GetName(),
                                                                     LocRM.GetString("ErrorText15"))
                                                             }));
                }

                data.StructDeconstructor[parentStruct] = node;
                if (parentStruct.GetName().Text != node.GetName().Text)
                {
                    errors.Add(new ErrorCollection.Error(node.GetName(), currentSourceFile,
                                                         LocRM.GetString("ErrorText16")));
                }
            }
            base.OutADeconstructorDecl(node);
        }
Example #10
0
 ArrayList New225()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList5 = (ArrayList) Pop();
     ArrayList nodeArrayList4 = (ArrayList) Pop();
     ArrayList nodeArrayList3 = (ArrayList) Pop();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TypedList listNode5 = new TypedList();
     PVisibilityModifier pvisibilitymodifierNode2 = (PVisibilityModifier)nodeArrayList1[0];
     TIdentifier tidentifierNode3 = (TIdentifier)nodeArrayList3[0];
     TypedList listNode4 = (TypedList)nodeArrayList4[0];
     if ( listNode4 != null )
     {
     listNode5.AddAll(listNode4);
     }
     PBlock pblockNode6 = (PBlock)nodeArrayList5[0];
     ADeconstructorDecl pdeclNode1 = new ADeconstructorDecl (
       pvisibilitymodifierNode2,
       tidentifierNode3,
       listNode5,
       pblockNode6
     );
     nodeList.Add(pdeclNode1);
     return nodeList;
 }
 public override void CaseADeconstructorDecl(ADeconstructorDecl node)
 {
     MethodDescription method = new MethodDescription(node);
     Deconstructors.Add(method);
 }
        /*private class IsThisOnLeftSide : DepthFirstAdapter
        {
            private PType type;
            private SharedData data;
            public bool IsAssignedTo;
            private List<AMethodDecl> investigatedMethods = new List<AMethodDecl>();

            public IsThisOnLeftSide(PType type, SharedData data)
            {
                this.type = type;
                this.data = data;
            }

            //Check assignments, method invocations and nonstatic method invocations.

            public override void CaseAMethodDecl(AMethodDecl node)
            {
                investigatedMethods.Add(node);
            }

            public override void CaseAThisLvalue(AThisLvalue node)
            {
                if (IsAssignedTo)
                    return;

                Node iParent = GetClosestNodeOfType(node, typeof (AAssignmentExp),
                                                    typeof (ASimpleInvokeExp),
                                                    typeof (ANonstaticInvokeExp),
                                                    typeof (AAsyncInvokeStm),
                                                    typeof (ASyncInvokeExp),
                                                    typeof(AArrayLvalue),
                                                    typeof(APointerLvalue),
                                                    typeof(APropertyLvalue),
                                                    typeof(AStructLvalue));
                if (iParent == null)
                    return;

                if (iParent is AAssignmentExp)
                {
                    AAssignmentExp aParent = (AAssignmentExp) iParent;
                    if (Util.IsAncestor(node, aParent.GetLvalue()))
                    {
                        IsAssignedTo = true;
                    }
                    return;
                }
                if (iParent is ASimpleInvokeExp)
                {
                    ASimpleInvokeExp aParent = (ASimpleInvokeExp) iParent;
                    AMethodDecl method = data.SimpleMethodLinks[aParent];
                    if (investigatedMethods.Contains(method))
                        return;

                    if (Util.IsAncestor(node, aParent.GetLvalue()))
                    {
                        IsAssignedTo = true;
                    }
                    return;
                }
            }

            private Node GetClosestNodeOfType(Node node, params Type[] types)
            {
                if (node == null)
                    return null;
                if (types.Contains(node.GetType()))
                    return node;
                return GetClosestNodeOfType(node.Parent(), types);
            }
        }*/
        public override void CaseADeconstructorDecl(ADeconstructorDecl node)
        {
            AStructDecl str = Util.GetAncestor<AStructDecl>(node);
            AEnrichmentDecl enrichment = Util.GetAncestor<AEnrichmentDecl>(node);
            AMethodDecl replacer = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null, new AVoidType(new TVoid("void")),
                                                   node.GetName(), new ArrayList(), node.GetBlock());
            replacer.GetName().Text += "_Deconstructor";

            //Move the method outside the struct
            AASourceFile file = Util.GetAncestor<AASourceFile>(node);
            if (str != null)
                str.RemoveChild(node.Parent());
            /*else
                enrichment.RemoveChild(node);*/
            int i = file.GetDecl().IndexOf(str ?? (PDecl)enrichment);
            file.GetDecl().Insert(i/* + 1*/, replacer);
            //Add the struct as a parameter
            PType type;
            if (str != null)
            {
                ANamedType structType = new ANamedType(new TIdentifier(str.GetName().Text), null);
                finalTrans.data.StructTypeLinks[structType] = str;
                type = structType;
            }
            else
            {
                type = Util.MakeClone(enrichment.GetType(), finalTrans.data);
            }
            finalTrans.data.DeconstructorMap[node] = replacer;
            AALocalDecl structFormal = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, new APointerType(new TStar("*"), type), new TIdentifier("currentStruct", replacer.GetName().Line, replacer.GetName().Pos), null);
            replacer.GetFormals().Add(structFormal);
            finalTrans.data.Methods.Add(new SharedData.DeclItem<AMethodDecl>(file, replacer));

            //Call base deconstructor before each return
            if (str != null && str.GetBase() != null)
            {
                AStructDecl baseStruct = data.StructTypeLinks[(ANamedType) str.GetBase()];
                if (data.StructDeconstructor.ContainsKey(baseStruct))
                {
                    baseStruct.Apply(this);
                    replacer.Apply(new CallDeconstructors(baseStruct, structFormal, data));
                    /*AMethodDecl baseDeconstructor = data.DeconstructorMap[data.StructDeconstructor[baseStruct]];

                    ALocalLvalue structFormalRef = new ALocalLvalue(new TIdentifier("currentStruct"));
                    ALvalueExp structFormalRefExp = new ALvalueExp(structFormalRef);
                    ASimpleInvokeExp invoke = new ASimpleInvokeExp(new TIdentifier("baseDeconstructor"),
                                                                   new ArrayList() {structFormalRefExp});
                    AABlock block = (AABlock) replacer.GetBlock();
                    block.GetStatements().Insert(0, new AExpStm(new TSemicolon(";"), invoke));

                    data.LocalLinks[structFormalRef] = structFormal;
                    data.SimpleMethodLinks[invoke] = baseDeconstructor;
                    data.LvalueTypes[structFormalRef] = data.ExpTypes[structFormalRefExp] = structFormal.GetType();
                    data.ExpTypes[invoke] = baseDeconstructor.GetReturnType();*/
                }
            }
            this.structFormal = structFormal;
            base.CaseAMethodDecl(replacer);
        }