Exemplo n.º 1
0
 public override void CaseALocalLvalue(ALocalLvalue node)
 {
     if (Util.HasAncestor <AMethodDecl>(node) &&                                         //Is in a method
         data.LocalLinks[node].Parent() == Util.GetAncestor <AMethodDecl>(node))         //Is a link to a formal in that method
     {
         if (Util.HasAncestor <AAssignmentExp>(node) &&                                  //Is in an assignement
             Util.IsAncestor(node, Util.GetAncestor <AAssignmentExp>(node).GetLvalue())) //Is left side of the assignment
         {
             AssignedFormals.Add(data.LocalLinks[node]);
         }
         else if (Util.HasAncestor <ASimpleInvokeExp>(node))
         {
             ASimpleInvokeExp invoke = Util.GetAncestor <ASimpleInvokeExp>(node);
             AMethodDecl      method = data.SimpleMethodLinks[invoke];
             for (int i = 0; i < invoke.GetArgs().Count; i++)
             {
                 AALocalDecl formal = (AALocalDecl)method.GetFormals()[i];
                 if ((formal.GetRef() != null || formal.GetOut() != null) && Util.IsAncestor(node, (Node)invoke.GetArgs()[i]))
                 {
                     AssignedFormals.Add(data.LocalLinks[node]);
                     return;
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 public override void CaseALocalLvalue(ALocalLvalue node)
 {
     if (isLeftsideOfAssignment)
     {
         assignedToLocals.Add(data.LocalLinks[node]);
     }
 }
 public override void CaseAAssignmentExp(AAssignmentExp node)
 {
     if (!processMethodsOnly && !processStructs)
     {
         if (!processFieldsOnly)
         {
             if (node.GetLvalue() is ALocalLvalue)
             {
                 ALocalLvalue lvalue = (ALocalLvalue)node.GetLvalue();
                 assignedToLocals[finalTrans.data.LocalLinks[lvalue]].Add(node);
                 node.GetExp().Apply(this);
                 return;
             }
         }
         if (node.GetLvalue() is AFieldLvalue)
         {
             AFieldLvalue lvalue = (AFieldLvalue)node.GetLvalue();
             AFieldDecl   decl   = finalTrans.data.FieldLinks[lvalue];
             if (!assignedToFields[decl].Contains(node))
             {
                 assignedToFields[decl].Add(node);
             }
             node.GetExp().Apply(this);
             return;
         }
     }
     base.CaseAAssignmentExp(node);
 }
Exemplo n.º 4
0
        public override void CaseALocalDeclStm(ALocalDeclStm node)
        {
            AMethodDecl pMethod = Util.GetAncestor <AMethodDecl>(node);
            AALocalDecl decl    = (AALocalDecl)node.GetLocalDecl();

            if (decl.GetInit() == null)
            {
                ALocalLvalue lvalue = new ALocalLvalue(new TIdentifier(decl.GetName().Text));
                data.LocalLinks[lvalue]  = decl;
                data.LvalueTypes[lvalue] = decl.GetType();
                List <PStm> statements = AssignDefault(lvalue);
                AABlock     pBlock     = (AABlock)node.Parent();
                foreach (PStm statement in statements)
                {
                    pBlock.GetStatements().Insert(pBlock.GetStatements().IndexOf(node), statement);
                }
                pBlock.RemoveChild(node);
            }
            else
            {
                //Make an assignment expression before moving
                ALocalLvalue lvalue = new ALocalLvalue(new TIdentifier(decl.GetName().Text));
                data.LvalueTypes[lvalue] = decl.GetType();
                AAssignmentExp exp    = new AAssignmentExp(new TAssign("="), lvalue, decl.GetInit());
                AExpStm        expStm = new AExpStm(new TSemicolon(";"), exp);
                node.ReplaceBy(expStm);
                data.LvalueTypes[lvalue] = decl.GetType();
                data.ExpTypes[exp]       = decl.GetType();
                data.LocalLinks[lvalue]  = decl;
            }

            AABlock block = (AABlock)pMethod.GetBlock();

            block.GetStatements().Insert(0, node);
        }
        public override void CaseAStructFieldLvalue(AStructFieldLvalue node)
        {
            //replace strField1
            //with <structFormal>.strField1
            AStructDecl  str = finalTrans.data.StructTypeLinks[(ANamedType)structFormal.GetType()];
            ALocalLvalue parameterRefference = new ALocalLvalue(new TIdentifier("tempName"));

            finalTrans.data.LocalLinks[parameterRefference]  = structFormal;
            finalTrans.data.LvalueTypes[parameterRefference] = structFormal.GetType();
            ALvalueExp exp = new ALvalueExp(parameterRefference);

            finalTrans.data.ExpTypes[exp] = structFormal.GetType();
            AStructLvalue replacer = new AStructLvalue(exp, new ADotDotType(new TDot(".")), node.GetName());

            foreach (AALocalDecl structField in finalTrans.data.StructFields[str])
            {
                if (structField.GetName().Text == replacer.GetName().Text)
                {
                    finalTrans.data.StructFieldLinks[replacer] = structField;
                    finalTrans.data.LvalueTypes[replacer]      = structField.GetType();
                    break;
                }
            }
            foreach (APropertyDecl property in finalTrans.data.StructProperties[str])
            {
                if (property.GetName().Text == replacer.GetName().Text)
                {
                    finalTrans.data.StructPropertyLinks[replacer] = property;
                    finalTrans.data.LvalueTypes[replacer]         = property.GetType();
                    break;
                }
            }
            node.ReplaceBy(replacer);
        }
Exemplo n.º 6
0
            public override void CaseAWhileStm(AWhileStm node)
            {
                /*
                 * while(...){...}
                 * ->
                 * while(...){...}
                 * if (hasMethodReturnedVar)
                 * {
                 *      break;
                 * }
                 */
                if (neededWhile)
                {
                    ALocalLvalue lvalue = new ALocalLvalue(new TIdentifier(hasMethodReturnedVar.GetName().Text));
                    data.LvalueTypes[lvalue] = hasMethodReturnedVar.GetType();
                    data.LocalLinks[lvalue]  = hasMethodReturnedVar;
                    ALvalueExp exp = new ALvalueExp(lvalue);
                    data.ExpTypes[exp] = hasMethodReturnedVar.GetType();

                    AABlock ifBlock = new AABlock();
                    ifBlock.GetStatements().Add(new ABreakStm(new TBreak("break")));
                    ABlockStm ifBlockStm = new ABlockStm(new TLBrace("{"), ifBlock);

                    AIfThenStm ifStm = new AIfThenStm(new TLParen("("), exp, ifBlockStm);

                    AABlock pBlock = (AABlock)node.Parent();
                    pBlock.GetStatements().Insert(pBlock.GetStatements().IndexOf(node) + 1, ifStm);
                }
                node.GetBody().Apply(this);
            }
Exemplo n.º 7
0
            public override void CaseAVoidReturnStm(AVoidReturnStm node)
            {
                if (!neededWhile)
                {
                    node.Parent().RemoveChild(node);
                    return;
                }

                /*
                 * return;
                 * ->
                 * hasMethodReturnedVar = true;
                 * break;
                 */
                ALocalLvalue lvalue = new ALocalLvalue(new TIdentifier(hasMethodReturnedVar.GetName().Text));

                data.LvalueTypes[lvalue] = hasMethodReturnedVar.GetType();
                data.LocalLinks[lvalue]  = hasMethodReturnedVar;
                PExp exp = new ABooleanConstExp(new ATrueBool());

                data.ExpTypes[exp] = new ANamedType(new TIdentifier("bool"), null);
                exp = new AAssignmentExp(new TAssign("="), lvalue, exp);
                data.ExpTypes[exp] = hasMethodReturnedVar.GetType();
                PStm    stm   = new AExpStm(new TSemicolon(";"), exp);
                AABlock block = new AABlock();

                block.GetStatements().Add(stm);

                block.GetStatements().Add(new ABreakStm(new TBreak("break")));

                node.ReplaceBy(new ABlockStm(new TLBrace("{"), block));
            }
Exemplo n.º 8
0
            public override void CaseAValueReturnStm(AValueReturnStm node)
            {
                /*
                 * return <exp>;
                 * ->
                 * methodReturnerVar = <exp>;
                 * hasMethodReturnedVar = true;
                 * break;
                 */
                ALocalLvalue lvalue = new ALocalLvalue(new TIdentifier(methodReturnerVar.GetName().Text));

                data.LvalueTypes[lvalue] = methodReturnerVar.GetType();
                data.LocalLinks[lvalue]  = methodReturnerVar;
                AAssignmentExp exp = new AAssignmentExp(new TAssign("="), lvalue, node.GetExp());

                data.ExpTypes[exp] = methodReturnerVar.GetType();
                PStm    stm   = new AExpStm(new TSemicolon(";"), exp);
                AABlock block = new AABlock();

                block.GetStatements().Add(stm);

                block.GetStatements().Add(new AVoidReturnStm(node.GetToken()));

                node.ReplaceBy(new ABlockStm(new TLBrace("{"), block));
                block.Apply(this);
            }
        public override void CaseASimpleInvokeExp(ASimpleInvokeExp node)
        {
            PExp  expNode = (PExp)node;
            PType type    = data.ExpTypes[expNode];

            if (type is APointerType)
            {
                type = new ANamedType(new TIdentifier("string"), null);
            }
            ALocalLvalue local = new ALocalLvalue(new TIdentifier("tempName", 0, 0));
            ALvalueExp   exp   = new ALvalueExp(local);
            PStm         stm   = Util.GetAncestor <PStm>(node);
            AABlock      block = (AABlock)stm.Parent();

            node.ReplaceBy(exp);
            AALocalDecl localDecl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null,
                                                    Util.MakeClone(type, data),
                                                    new TIdentifier(varName, 0, 0), expNode);
            ALocalDeclStm newStm = new ALocalDeclStm(new TSemicolon(";"), localDecl);

            block.GetStatements().Insert(block.GetStatements().IndexOf(stm), newStm);
            NewStatements.Add(newStm);

            data.LvalueTypes[local] = type;
            data.ExpTypes[exp]      = type;
            data.LocalLinks[local]  = localDecl;
            //localDecl.Apply(this);
            exp.Apply(this);
            return;
        }
Exemplo n.º 10
0
        private AMethodDecl GetIntPointerMethod()
        {
            if (GetIntPointerPartMethod != null)
            {
                return(GetIntPointerPartMethod);
            }

            /*
             *  int GetIntPointerPart(string delegate)
             *  {
             *      return IntToString(GetPointerPart(delegate));
             *  }
             */

            AASourceFile sourceFile     = Util.GetAncestor <AASourceFile>(finalTrans.mainEntry);
            AALocalDecl  delegateFormal = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null,
                                                          new ANamedType(new TIdentifier("string"), null),
                                                          new TIdentifier("delegate"), null);
            ALocalLvalue delegateRef1    = new ALocalLvalue(new TIdentifier("delegate"));
            ALvalueExp   delegateRef1Exp = new ALvalueExp(delegateRef1);

            ASimpleInvokeExp getPointerPartInvoke = new ASimpleInvokeExp(new TIdentifier("GetPointerPart"), new ArrayList()
            {
                delegateRef1Exp
            });

            ASimpleInvokeExp StringToIntInvoke = new ASimpleInvokeExp(new TIdentifier("StringToInt"), new ArrayList()
            {
                getPointerPartInvoke
            });

            GetIntPointerPartMethod = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null,
                                                      new ANamedType(new TIdentifier("int"), null),
                                                      new TIdentifier("GetPointerPart", finalTrans.data.LineCounts[sourceFile] + 1, 1), new ArrayList()
            {
                delegateFormal
            },
                                                      new AABlock(
                                                          new ArrayList()
            {
                new AValueReturnStm(new TReturn("return"), StringToIntInvoke)
            },
                                                          new TRBrace("}")));
            sourceFile.GetDecl().Add(GetIntPointerPartMethod);
            data.Methods.Add(new SharedData.DeclItem <AMethodDecl>(sourceFile, GetIntPointerPartMethod));

            finalTrans.data.LocalLinks[delegateRef1]               = delegateFormal;
            finalTrans.data.LvalueTypes[delegateRef1]              =
                finalTrans.data.ExpTypes[delegateRef1Exp]          =
                    finalTrans.data.ExpTypes[getPointerPartInvoke] = new ANamedType(new TIdentifier("string"), null);
            finalTrans.data.ExpTypes[StringToIntInvoke]            = new ANamedType(new TIdentifier("int"), null);


            finalTrans.data.SimpleMethodLinks[getPointerPartInvoke] = GetStringPointerMethod();
            finalTrans.data.SimpleMethodLinks[StringToIntInvoke]    =
                finalTrans.data.Libraries.Methods.First(m => m.GetName().Text == StringToIntInvoke.GetName().Text);

            return(GetIntPointerPartMethod);
        }
 public override void CaseALocalLvalue(ALocalLvalue node)
 {
     if (data.LocalLinks[node] == decl)
     {
         lvalue = node;
         count++;
     }
 }
Exemplo n.º 12
0
                public override void OutAValueLvalue(AValueLvalue node)
                {
                    ALocalLvalue replacer = new ALocalLvalue(new TIdentifier("value"));

                    node.ReplaceBy(replacer);
                    data.LocalLinks[replacer]  = valueDecl;
                    data.LvalueTypes[replacer] = valueDecl.GetType();
                }
            public override void CaseAVoidReturnStm(AVoidReturnStm node)
            {
                ALocalLvalue paramRef    = new ALocalLvalue(new TIdentifier("paramRef"));
                ALvalueExp   paramRefExp = new ALvalueExp(paramRef);

                node.ReplaceBy(new AValueReturnStm(node.GetToken(), paramRefExp));
                data.LocalLinks[paramRef]  = param;
                data.LvalueTypes[paramRef] = data.ExpTypes[paramRefExp] = param.GetType();
            }
Exemplo n.º 14
0
        public override void CaseALocalLvalue(ALocalLvalue node)
        {
            AALocalDecl decl = data.LocalLinks[node];

            if (!UsedLocals.Contains(decl))
            {
                UsedLocals.Add(decl);
            }
        }
        public override void CaseAThisLvalue(AThisLvalue node)
        {
            //Replace with <structFormal>
            ALocalLvalue parameterRefference = new ALocalLvalue(new TIdentifier("tempName"));

            finalTrans.data.LocalLinks[parameterRefference]  = structFormal;
            finalTrans.data.LvalueTypes[parameterRefference] = structFormal.GetType();
            node.ReplaceBy(parameterRefference);
            base.CaseAThisLvalue(node);
        }
        private int FoldInt(PLvalue lvalue, ref bool valid)
        {
            if (!valid)
            {
                return(-1);
            }

            if (lvalue is ALocalLvalue)
            {
                ALocalLvalue aLvalue = (ALocalLvalue)lvalue;
                AALocalDecl  decl    = data.LocalLinks[aLvalue];
                if (decl.GetConst() == null)
                {
                    valid = false;
                    return(-1);
                }
                return(FoldInt(decl.GetInit(), ref valid));
            }
            if (lvalue is AFieldLvalue)
            {
                AFieldLvalue aLvalue = (AFieldLvalue)lvalue;
                AFieldDecl   decl    = data.FieldLinks[aLvalue];
                if (decl.GetConst() == null)
                {
                    valid = false;
                    return(-1);
                }
                return(FoldInt(decl.GetInit(), ref valid));
            }
            if (lvalue is AStructFieldLvalue)
            {
                AStructFieldLvalue aLvalue = (AStructFieldLvalue)lvalue;
                AALocalDecl        decl    = data.StructMethodFieldLinks[aLvalue];
                if (decl.GetConst() == null)
                {
                    valid = false;
                    return(-1);
                }
                return(FoldInt(decl.GetInit(), ref valid));
            }
            if (lvalue is AStructLvalue)
            {
                AStructLvalue aLvalue = (AStructLvalue)lvalue;
                AALocalDecl   decl    = data.StructFieldLinks[aLvalue];
                if (decl.GetConst() == null)
                {
                    valid = false;
                    return(-1);
                }
                return(FoldInt(decl.GetInit(), ref valid));
            }

            valid = false;
            return(-1);
        }
Exemplo n.º 17
0
 public override void CaseAAssignmentExp(AAssignmentExp node)
 {
     currentLocal = null;
     node.GetLvalue().Apply(this);
     if (currentLocal != null)
     {
         AALocalDecl decl = data.LocalLinks[currentLocal];
         NeededRefs[Util.GetAncestor <AMethodDecl>(node)].Add(decl);
     }
     node.GetExp().Apply(this);
 }
Exemplo n.º 18
0
            public override void CaseAContinueStm(AContinueStm node)
            {
                AABlock          pBlock        = (AABlock)node.Parent();
                ALocalLvalue     replaceVarRef = new ALocalLvalue(new TIdentifier("whileVar"));
                ASimpleInvokeExp clone         = (ASimpleInvokeExp)Util.MakeClone(this.node, data);
                AAssignmentExp   assignment    = new AAssignmentExp(new TAssign("="), replaceVarRef, clone);

                data.LocalLinks[replaceVarRef] = replaceVarDecl;
                data.ExpTypes[assignment]      = data.LvalueTypes[replaceVarRef] = replaceVarDecl.GetType();
                pBlock.GetStatements().Insert(pBlock.GetStatements().IndexOf(node), new AExpStm(new TSemicolon(";"), assignment));
                replacementExpressions.Add(clone);
            }
Exemplo n.º 19
0
            public override void CaseALocalLvalue(ALocalLvalue node)
            {
                //Only if it is not what it is assigning to
                AAssignmentExp exp = Util.GetAncestor <AAssignmentExp>(node);

                if (exp != null && node == exp.GetLvalue())
                {
                    return;
                }

                UsedLocals.Add(data.LocalLinks[node]);
            }
Exemplo n.º 20
0
        //Convert struct variables to a collection of local variables
        public override void CaseAALocalDecl(AALocalDecl node)
        {
            if (node.GetType() is ANamedType && data.StructTypeLinks.ContainsKey((ANamedType)node.GetType()) && Util.HasAncestor <PStm>(node))
            {
                //Can not have init - it would be bulk copy
                AStructDecl str = data.StructTypeLinks[(ANamedType)node.GetType()];
                Dictionary <AALocalDecl, AALocalDecl> variableMap = new Dictionary <AALocalDecl, AALocalDecl>();
                PStm    pStm   = (PStm)node.Parent();
                AABlock pBlock = (AABlock)pStm.Parent();
                foreach (AALocalDecl structLocal in str.GetLocals())
                {
                    AALocalDecl replacementLocal = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null,
                                                                   Util.MakeClone(structLocal.GetType(), data),
                                                                   new TIdentifier(node.GetName().Text + "_" +
                                                                                   structLocal.GetName().Text), null);
                    pBlock.GetStatements().Insert(pBlock.GetStatements().IndexOf(pStm), new ALocalDeclStm(new TSemicolon(";"), replacementLocal));


                    AALocalDecl baseLocal = structLocal;
                    if (data.EnheritanceLocalMap.ContainsKey(baseLocal))
                    {
                        baseLocal = data.EnheritanceLocalMap[baseLocal];
                    }
                    List <AALocalDecl> localsToAdd = new List <AALocalDecl>();
                    localsToAdd.AddRange(data.EnheritanceLocalMap.Where(pair => pair.Value == baseLocal).Select(pair => pair.Key));
                    localsToAdd.Add(baseLocal);
                    foreach (AALocalDecl localDecl in localsToAdd)
                    {
                        variableMap[localDecl] = replacementLocal;
                    }
                }
                List <ALocalLvalue> uses = new List <ALocalLvalue>();
                uses.AddRange(data.LocalLinks.Where(k => k.Value == node && Util.GetAncestor <AAProgram>(k.Key) != null).Select(k => k.Key));
                foreach (ALocalLvalue lvalue in uses)
                {
                    AStructLvalue structLocalRef = (AStructLvalue)lvalue.Parent().Parent();

                    AALocalDecl  replacementLocal  = variableMap[data.StructFieldLinks[structLocalRef]];
                    ALocalLvalue replacementLvalue = new ALocalLvalue(new TIdentifier(replacementLocal.GetName().Text));
                    data.LocalLinks[replacementLvalue]  = replacementLocal;
                    data.LvalueTypes[replacementLvalue] = replacementLocal.GetType();
                    structLocalRef.ReplaceBy(replacementLvalue);
                }
                foreach (AALocalDecl replacementLocal in variableMap.Select(k => k.Value))
                {
                    replacementLocal.Apply(this);
                }
            }
            base.CaseAALocalDecl(node);
        }
        public override void CaseALocalLvalue(ALocalLvalue node)
        {
            if (processFieldsOnly || processMethodsOnly || processStructs)
            {
                return;
            }

            AALocalDecl decl = finalTrans.data.LocalLinks[node];

            if (!usedLocals.Contains(decl))
            {
                usedLocals.Add(decl);
            }
            base.CaseALocalLvalue(node);
        }
Exemplo n.º 22
0
        public override void OutAALocalDecl(AALocalDecl node)
        {
            if (!Util.HasAncestor <AABlock>(node) && !Util.HasAncestor <AMethodDecl>(node))
            {
                //OutStructFieldDecl(node);
                return;
            }

            if (node.GetInit() != null)
            {
                return;
            }

            AABlock pBlock;
            int     insertIndex;
            PLvalue lvalue;

            if (Util.HasAncestor <AABlock>(node))
            {
                //A local variable
                pBlock      = Util.GetAncestor <AABlock>(node);
                insertIndex = pBlock.GetStatements().IndexOf(Util.GetAncestor <PStm>(node)) + 1;
                lvalue      = new ALocalLvalue(new TIdentifier(node.GetName().Text));
                data.LocalLinks[(ALocalLvalue)lvalue] = node;
                data.LvalueTypes[lvalue] = node.GetType();
            }
            else
            {
                //Parameter

                //Parameters will be set from the caller
                return;

                pBlock      = (AABlock)Util.GetAncestor <AMethodDecl>(node).GetBlock();
                insertIndex = 0;
                lvalue      = new ALocalLvalue(new TIdentifier(node.GetName().Text));
                data.LocalLinks[(ALocalLvalue)lvalue] = node;
                data.LvalueTypes[lvalue] = node.GetType();
            }
            AABlock block = new AABlock(new ArrayList(), new TRBrace("}"));

            MakeAssignments(block, node.GetType(), lvalue, true);

            if (block.GetStatements().Count != 0)
            {
                pBlock.GetStatements().Insert(insertIndex, new ABlockStm(new TLBrace("{"), block));
            }
        }
Exemplo n.º 23
0
            public override void OutALocalLvalue(ALocalLvalue node)
            {
                if (currentMethod == null)
                {
                    return;
                }

                AALocalDecl decl = data.LocalLinks[node];

                Node n = node;

                while (true)
                {
                    n = Util.GetNearestAncestor(n.Parent(), typeof(AMethodDecl), typeof(AAssignmentExp), typeof(AArrayLvalue));
                    if (n is AMethodDecl)
                    {
                        break;
                    }
                    if (n is AAssignmentExp)
                    {
                        if (Util.IsAncestor(node, ((AAssignmentExp)n).GetLvalue()))
                        {
                            if (!WrittenLocals[currentMethod].Contains(decl))
                            {
                                WrittenLocals[currentMethod].Add(decl);
                            }
                            return;
                        }
                        break;
                    }
                    if (n is AArrayLvalue)
                    {
                        if (Util.IsAncestor(node, ((AArrayLvalue)n).GetBase()))
                        {
                            continue;
                        }
                        break;
                    }
                    break;
                }

                if (!ReadLocals[currentMethod].Contains(decl))
                {
                    ReadLocals[currentMethod].Add(decl);
                }
            }
Exemplo n.º 24
0
            private void MoveOut(PExp exp, PType type)
            {
                PStm    pStm   = Util.GetAncestor <PStm>(exp);
                AABlock pBlock = (AABlock)pStm.Parent();

                ALocalLvalue lvalue    = new ALocalLvalue(new TIdentifier("gppVar"));
                ALvalueExp   lvalueExp = new ALvalueExp(lvalue);

                exp.ReplaceBy(lvalueExp);
                AALocalDecl decl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, Util.MakeClone(type, data), new TIdentifier("gppVar"), exp);

                pBlock.GetStatements().Insert(pBlock.GetStatements().IndexOf(pStm), new ALocalDeclStm(new TSemicolon(";"), decl));

                data.LvalueTypes[lvalue]     =
                    data.ExpTypes[lvalueExp] = decl.GetType();
                data.LocalLinks[lvalue]      = decl;
            }
            public override void CaseAVoidReturnStm(AVoidReturnStm node)
            {
                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)node.Parent();

                block.GetStatements().Insert(block.GetStatements().IndexOf(node), 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();
            }
Exemplo n.º 26
0
        public override void CaseASimpleInvokeExp(ASimpleInvokeExp node)
        {
            AMethodDecl target = data.SimpleMethodLinks[node];

            for (int i = 0; i < node.GetArgs().Count; i++)
            {
                PExp arg = (PExp)node.GetArgs()[i];
                currentLocal = null;
                arg.Apply(this);
                if (currentLocal != null && target.GetFormals().Cast <AALocalDecl>().ToList()[i].GetRef() != null)
                {
                    ALocalLvalue local = currentLocal;
                    target.Apply(this);
                    if (target.GetFormals().Cast <AALocalDecl>().ToList()[i].GetRef() != null)
                    {
                        AALocalDecl decl = data.LocalLinks[local];
                        NeededRefs[Util.GetAncestor <AMethodDecl>(node)].Add(decl);
                    }
                }
            }
        }
Exemplo n.º 27
0
 public override void OutALocalLvalue(ALocalLvalue node)
 {
     if (folding)
     {
         AALocalDecl local = data.LocalLinks[node];
         if (local.GetConst() == null)
         {
             if (!isANewExp)
             {
                 errors.Add(
                     new ErrorCollection.Error(node.GetName(),
                                               LocRM.GetString("ErrorText61"),
                                               false), true);
                 throw new ParserException(null, null);
             }
         }
         if (local.GetInit() == null)//An error will be given earlier
         {
             throw new ParserException(null, null);
         }
         local.GetInit().Apply(this);
     }
 }
Exemplo n.º 28
0
 public override void OutALocalLvalue(ALocalLvalue node)
 {
     if (folding)
     {
         AALocalDecl local = data.LocalLinks[node];
         if (local.GetConst() == null)
         {
             if (!isANewExp)
             {
                 errors.Add(
                     new ErrorCollection.Error(node.GetName(),
                                               "Dimensions of array types must be constant expressions.",
                                               false), true);
                 throw new ParserException(null, null);
             }
         }
         if (local.GetInit() == null)//An error will be given earlier
         {
             throw new ParserException(null, null);
         }
         local.GetInit().Apply(this);
     }
 }
Exemplo n.º 29
0
        public override void OutAAProgram(AAProgram node)
        {
            //Fix types
            foreach (var pair in data.LocalLinks.Where(pair => Util.HasAncestor <AAProgram>(pair.Key) &&
                                                       !Util.TypesEqual(data.ExpTypes[(PExp)pair.Key.Parent()], pair.Value.GetType(), data)))
            {
                ALocalLvalue lvalue = pair.Key;
                AALocalDecl  decl   = pair.Value;


                data.LvalueTypes[lvalue] = decl.GetType();
                if (lvalue.Parent() is ALvalueExp)
                {
                    data.ExpTypes[(PExp)lvalue.Parent()] = decl.GetType();
                    if (lvalue.Parent().Parent() is APointerLvalue)
                    {
                        data.LvalueTypes[(PLvalue)lvalue.Parent().Parent()] = ((APointerType)decl.GetType()).GetType();
                    }
                }
            }

            base.OutAAProgram(node);
        }
Exemplo n.º 30
0
 public static bool ReturnsTheSame(PLvalue left, PLvalue right, SharedData data)
 {
     if (left.GetType() != right.GetType())
     {
         return(false);
     }
     if (left is ALocalLvalue)
     {
         ALocalLvalue aLeft  = (ALocalLvalue)left;
         ALocalLvalue aRight = (ALocalLvalue)right;
         return(data.LocalLinks[aLeft] == data.LocalLinks[aRight]);
     }
     if (left is AFieldLvalue)
     {
         AFieldLvalue aLeft  = (AFieldLvalue)left;
         AFieldLvalue aRight = (AFieldLvalue)right;
         return(data.FieldLinks[aLeft] == data.FieldLinks[aRight]);
     }
     if (left is AStructLvalue)
     {
         AStructLvalue aLeft  = (AStructLvalue)left;
         AStructLvalue aRight = (AStructLvalue)right;
         if (data.StructFieldLinks[aLeft] != data.StructFieldLinks[aRight])
         {
             return(false);
         }
         return(ReturnsTheSame(aLeft.GetReceiver(), aRight.GetReceiver(), data));
     }
     if (left is AArrayLvalue)
     {
         AArrayLvalue aLeft  = (AArrayLvalue)left;
         AArrayLvalue aRight = (AArrayLvalue)right;
         return(ReturnsTheSame(aLeft.GetIndex(), aRight.GetIndex(), data) &&
                ReturnsTheSame(aLeft.GetBase(), aRight.GetBase(), data));
     }
     throw new Exception("Util.ReturnsTheSame. Unexpected type, got " + left.GetType());
 }