示例#1
0
        public InvokeStm(ASyncInvokeExp node)
        {
            Node = node;
            if (node.GetName() is AAmbiguousNameLvalue)
            {
                AAmbiguousNameLvalue ambigious = (AAmbiguousNameLvalue)node.GetName();
                AAName name = (AAName)ambigious.GetAmbiguous();

                /*List<List<Node>>[] targets;
                 * List<ANamespaceDecl> namespaces = new List<ANamespaceDecl>();
                 * /*bool b;
                 * TypeLinking.GetTargets(name, out targets, namespaces, data, null, out b);
                 * for (int i = 0; i < 3; i++)
                 * {
                 *
                 * }*/
                Name = (TIdentifier)name.GetIdentifier()[name.GetIdentifier().Count - 1];
                name.GetIdentifier().RemoveAt(name.GetIdentifier().Count - 1);
                if (name.GetIdentifier().Count == 0)
                {
                    Base = null;
                }
                else
                {
                    Base = name;
                }
            }
            else
            {
                AStructLvalue lvalue = (AStructLvalue)node.GetName();
                Name = lvalue.GetName();
                Base = lvalue.GetReceiver();
            }
        }
示例#2
0
 public override void CaseAStructLvalue(AStructLvalue node)
 {
     //Only do namespace
     node.GetReceiver().Apply(this);
     node.GetDotType().Apply(this);
     Value += node.GetName().Text;
 }
示例#3
0
 public InvokeStm(AAsyncInvokeStm node)
 {
     Node = node;
     if (node.GetName() is AAmbiguousNameLvalue)
     {
         AAmbiguousNameLvalue ambigious = (AAmbiguousNameLvalue)node.GetName();
         AAName name = (AAName)ambigious.GetAmbiguous();
         Name = (TIdentifier)name.GetIdentifier()[name.GetIdentifier().Count - 1];
         name.GetIdentifier().RemoveAt(name.GetIdentifier().Count - 1);
         if (name.GetIdentifier().Count == 0)
         {
             Base = null;
         }
         else
         {
             Base = name;
         }
     }
     else
     {
         AStructLvalue lvalue = (AStructLvalue)node.GetName();
         Name = lvalue.GetName();
         Base = lvalue.GetReceiver();
     }
 }
        private List <PStm> MakeStatements(PExp exp, int line, int pos)
        {
            List <PStm> list = new List <PStm>();

            if (exp is ASimpleInvokeExp)
            {
                list.Add(new AExpStm(new TSemicolon(";", line, pos), exp));
                return(list);
            }
            if (exp is AAssignmentExp)
            {
                list.Add(new AExpStm(new TSemicolon(";", line, pos), exp));
                return(list);
            }
            if (exp is ANonstaticInvokeExp)
            {
                list.Add(new AExpStm(new TSemicolon(";", line, pos), exp));
                return(list);
            }
            if (exp is ABinopExp)
            {
                ABinopExp aExp = (ABinopExp)exp;
                list.AddRange(MakeStatements(aExp.GetLeft(), line, pos));
                list.AddRange(MakeStatements(aExp.GetRight(), line, pos));
                return(list);
            }
            if (exp is AUnopExp)
            {
                AUnopExp aExp = (AUnopExp)exp;
                list.AddRange(MakeStatements(aExp.GetExp(), line, pos));
                return(list);
            }
            if (exp is AParenExp)
            {
                AParenExp aExp = (AParenExp)exp;
                list.AddRange(MakeStatements(aExp.GetExp(), line, pos));
                return(list);
            }
            if (exp is ALvalueExp)
            {
                ALvalueExp aExp   = (ALvalueExp)exp;
                PLvalue    lvalue = aExp.GetLvalue();
                if (lvalue is AStructLvalue)
                {
                    AStructLvalue aLvalue = (AStructLvalue)lvalue;
                    list.AddRange(MakeStatements(aLvalue.GetReceiver(), line, pos));
                    return(list);
                }
                if (lvalue is AArrayLvalue)
                {
                    AArrayLvalue aLvalue = (AArrayLvalue)lvalue;
                    list.AddRange(MakeStatements(aLvalue.GetBase(), line, pos));
                    list.AddRange(MakeStatements(aLvalue.GetIndex(), line, pos));
                    return(list);
                }
            }
            return(list);
        }
示例#5
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());
 }
示例#6
0
 public override void CaseAStructLvalue(AStructLvalue node)
 {
     //a->b => (*a).b
     if (node.GetDotType() is AArrowDotType)
     {
         TArrow arrow = ((AArrowDotType)node.GetDotType()).GetToken();
         node.SetReceiver(new ALvalueExp(new APointerLvalue(new TStar("*", arrow.Line, arrow.Pos), node.GetReceiver())));
         node.SetDotType(new ADotDotType(new TDot(".", arrow.Line, arrow.Pos)));
     }
     base.CaseAStructLvalue(node);
 }
示例#7
0
            /*
             * Apply after assignement fixup
             * Assume no i++
             *
             * Convert usages to method invocations.
             */

            public static void Parse(FinalTransformations finalTrans)
            {
                SharedData data = finalTrans.data;

                foreach (KeyValuePair <APropertyLvalue, APropertyDecl> pair in data.PropertyLinks)
                {
                    APropertyLvalue lvalue   = pair.Key;
                    APropertyDecl   property = pair.Value;

                    if (Util.GetAncestor <AAProgram>(lvalue) == null)
                    {
                        continue;
                    }

                    if (lvalue.Parent() is AAssignmentExp)
                    {
                        AAssignmentExp   assignment = (AAssignmentExp)lvalue.Parent();
                        ASimpleInvokeExp invoke     =
                            new ASimpleInvokeExp(
                                new TIdentifier("Set" + property.GetName().Text, lvalue.GetName().Line,
                                                lvalue.GetName().Pos), new ArrayList()
                        {
                            assignment.GetExp()
                        });
                        assignment.ReplaceBy(invoke);
                        data.SimpleMethodLinks[invoke] = data.Setters[property];
                        data.ExpTypes[invoke]          = new AVoidType(new TVoid("void"));
                    }
                    else
                    {
                        ALvalueExp       exp    = (ALvalueExp)lvalue.Parent();
                        ASimpleInvokeExp invoke =
                            new ASimpleInvokeExp(
                                new TIdentifier("Get" + property.GetName().Text, lvalue.GetName().Line,
                                                lvalue.GetName().Pos), new ArrayList()
                        {
                        });
                        exp.ReplaceBy(invoke);
                        data.SimpleMethodLinks[invoke] = data.Getters[property];
                        data.ExpTypes[invoke]          = property.GetType();
                    }
                }
                foreach (KeyValuePair <AStructLvalue, APropertyDecl> pair in data.StructPropertyLinks)
                {
                    AStructLvalue   lvalue         = pair.Key;
                    APropertyDecl   property       = pair.Value;
                    AEnrichmentDecl enrichmentDecl = null;
                    AStructDecl     structDecl     = null;
                    if (data.EnrichmentTypeLinks.ContainsKey(data.ExpTypes[lvalue.GetReceiver()]))
                    {
                        enrichmentDecl = data.EnrichmentTypeLinks[data.ExpTypes[lvalue.GetReceiver()]];
                    }
                    if (enrichmentDecl == null)
                    {
                        structDecl = data.StructTypeLinks[(ANamedType)data.ExpTypes[lvalue.GetReceiver()]];
                    }

                    if (Util.GetAncestor <AAProgram>(lvalue) == null)
                    {
                        continue;
                    }

                    PExp structArg;
                    if (structDecl == null || structDecl.GetClassToken() == null)
                    {
                        structArg = lvalue.GetReceiver();
                    }
                    else
                    {
                        //Send pointer
                        ALvalueExp     lvalueExp    = (ALvalueExp)lvalue.GetReceiver();
                        APointerLvalue pointerValue = (APointerLvalue)lvalueExp.GetLvalue();
                        structArg = pointerValue.GetBase();
                    }

                    if (lvalue.Parent() is AAssignmentExp)
                    {
                        AAssignmentExp   assignment = (AAssignmentExp)lvalue.Parent();
                        ASimpleInvokeExp invoke     =
                            new ASimpleInvokeExp(
                                new TIdentifier("Set" + property.GetName().Text, lvalue.GetName().Line,
                                                lvalue.GetName().Pos), new ArrayList()
                        {
                            assignment.GetExp(), structArg
                        });
                        assignment.ReplaceBy(invoke);
                        data.SimpleMethodLinks[invoke] = data.Setters[property];
                        data.ExpTypes[invoke]          = new AVoidType(new TVoid("void"));
                    }
                    else
                    {
                        ALvalueExp       exp    = (ALvalueExp)lvalue.Parent();
                        ASimpleInvokeExp invoke =
                            new ASimpleInvokeExp(
                                new TIdentifier("Get" + property.GetName().Text, lvalue.GetName().Line,
                                                lvalue.GetName().Pos), new ArrayList()
                        {
                            structArg
                        });
                        exp.ReplaceBy(invoke);
                        data.SimpleMethodLinks[invoke] = data.Getters[property];
                        data.ExpTypes[invoke]          = property.GetType();
                    }
                }
                foreach (KeyValuePair <AArrayLvalue, Util.Pair <APropertyDecl, bool> > pair in data.ArrayPropertyLinks)
                {
                    AArrayLvalue    lvalue         = pair.Key;
                    APropertyDecl   property       = pair.Value.First;
                    bool            implicitMatch  = pair.Value.Second;
                    AEnrichmentDecl enrichmentDecl = null;
                    AStructDecl     structDecl     = null;

                    if (OldEnrichmentParents.ContainsKey(property))
                    {
                        enrichmentDecl = OldEnrichmentParents[property];
                    }
                    else
                    {
                        structDecl = OldStructParents[property];
                    }
                    if (Util.GetAncestor <AAProgram>(lvalue) == null)
                    {
                        continue;
                    }

                    PExp structArg;
                    if (structDecl == null || structDecl.GetClassToken() == null)
                    {
                        structArg = lvalue.GetBase();
                    }
                    else
                    {
                        //Send pointer
                        if (implicitMatch)
                        {
                            structArg = lvalue.GetBase();
                        }
                        else
                        {
                            ALvalueExp     lvalueExp    = (ALvalueExp)lvalue.GetBase();
                            APointerLvalue pointerValue = (APointerLvalue)lvalueExp.GetLvalue();
                            structArg = pointerValue.GetBase();
                        }
                    }

                    /*  if (!(structArg is ALvalueExp &&
                     *    (((ALvalueExp)structArg).GetLvalue() is ALocalLvalue || ((ALvalueExp)structArg).GetLvalue() is AFieldLvalue ||
                     *    ((ALvalueExp)structArg).GetLvalue() is AStructLvalue || ((ALvalueExp)structArg).GetLvalue() is AStructFieldLvalue))
                     * {
                     *    //Make new local
                     *    AALocalDecl decl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null,
                     *                                       Util.MakeClone(data.ExpTypes[structArg], data),
                     *                                       new TIdentifier("propertyVar"), structArg);
                     *    ALocalLvalue declRef = new ALocalLvalue(new TIdentifier("propertyVar"));
                     *    structArg = new ALvalueExp(declRef);
                     *    PStm stm = Util.GetAncestor<PStm>(lvalue);
                     * }*/

                    if (lvalue.Parent() is AAssignmentExp)
                    {
                        AAssignmentExp   assignment = (AAssignmentExp)lvalue.Parent();
                        ASimpleInvokeExp invoke     =
                            new ASimpleInvokeExp(
                                new TIdentifier("SetThis", lvalue.GetToken().Line,
                                                lvalue.GetToken().Pos), new ArrayList()
                        {
                            lvalue.GetIndex(), assignment.GetExp(), structArg
                        });
                        assignment.ReplaceBy(invoke);
                        data.SimpleMethodLinks[invoke] = data.Setters[property];
                        data.ExpTypes[invoke]          = new AVoidType(new TVoid("void"));
                    }
                    else
                    {
                        ALvalueExp       exp    = (ALvalueExp)lvalue.Parent();
                        ASimpleInvokeExp invoke =
                            new ASimpleInvokeExp(
                                new TIdentifier("GetThis", lvalue.GetToken().Line,
                                                lvalue.GetToken().Pos), new ArrayList()
                        {
                            lvalue.GetIndex(), structArg
                        });
                        exp.ReplaceBy(invoke);
                        data.SimpleMethodLinks[invoke] = data.Getters[property];
                        data.ExpTypes[invoke]          = property.GetType();
                    }
                }
            }
示例#8
0
 public override void CaseAStructLvalue(AStructLvalue node)
 {
     node.GetReceiver().Apply(this);
     Write("." + node.GetName().Text);
 }
示例#9
0
 private static void MakeCloneRefferences(PLvalue clone, PLvalue lvalue, SharedData data)
 {
     data.LvalueTypes[clone] = data.LvalueTypes[lvalue];
     if (lvalue is ALocalLvalue)
     {
         data.LocalLinks[(ALocalLvalue)clone] = data.LocalLinks[(ALocalLvalue)lvalue];
     }
     else if (lvalue is AFieldLvalue)
     {
         data.FieldLinks[(AFieldLvalue)clone] = data.FieldLinks[(AFieldLvalue)lvalue];
     }
     else if (lvalue is AStructLvalue)
     {
         AStructLvalue aLvalue = (AStructLvalue)lvalue;
         AStructLvalue aClone  = (AStructLvalue)clone;
         if (data.StructFieldLinks.ContainsKey(aLvalue))
         {
             data.StructFieldLinks[aClone] =
                 data.StructFieldLinks[aLvalue];
         }
         else
         {
             data.StructPropertyLinks[aClone] =
                 data.StructPropertyLinks[aLvalue];
         }
         MakeCloneRefferences(aClone.GetReceiver(), aLvalue.GetReceiver(), data);
     }
     else if (lvalue is AStructFieldLvalue)
     {
         AStructFieldLvalue aLvalue = (AStructFieldLvalue)lvalue;
         AStructFieldLvalue aClone  = (AStructFieldLvalue)clone;
         if (data.StructMethodFieldLinks.ContainsKey(aLvalue))
         {
             data.StructMethodFieldLinks[aClone] = data.StructMethodFieldLinks[aLvalue];
         }
         if (data.StructMethodPropertyLinks.ContainsKey(aLvalue))
         {
             data.StructMethodPropertyLinks[aClone] = data.StructMethodPropertyLinks[aLvalue];
         }
     }
     else if (lvalue is AArrayLvalue)
     {
         AArrayLvalue aLvalue = (AArrayLvalue)lvalue;
         AArrayLvalue aClone  = (AArrayLvalue)clone;
         MakeCloneRefferences(aClone.GetBase(), aLvalue.GetBase(), data);
         MakeCloneRefferences(aClone.GetIndex(), aLvalue.GetIndex(), data);
     }
     else if (lvalue is APointerLvalue)
     {
         APointerLvalue aLvalue = (APointerLvalue)lvalue;
         APointerLvalue aClone  = (APointerLvalue)clone;
         MakeCloneRefferences(aClone.GetBase(), aLvalue.GetBase(), data);
     }
     else if (lvalue is AThisLvalue || lvalue is AValueLvalue)
     {
         //AThisLvalue aLvalue = (AThisLvalue)lvalue;
         //Do nothing more
     }
     else if (lvalue is APropertyLvalue)
     {
         APropertyLvalue aLvalue = (APropertyLvalue)lvalue;
         APropertyLvalue aClone  = (APropertyLvalue)clone;
         data.PropertyLinks[aClone] = data.PropertyLinks[aLvalue];
     }
     else
     {
         throw new Exception("Unexpect lvalue. Got " + lvalue.GetType());
     }
 }