public virtual void InANonstaticInvokeExp(ANonstaticInvokeExp node)
 {
     DefaultIn(node);
 }
 public virtual void CaseANonstaticInvokeExp(ANonstaticInvokeExp node)
 {
     DefaultCase(node);
 }
 public override void CaseANonstaticInvokeExp(ANonstaticInvokeExp node)
 {
     InANonstaticInvokeExp(node);
     {
         Object[] temp = new Object[node.GetArgs().Count];
         node.GetArgs().CopyTo(temp, 0);
         for (int i = temp.Length - 1; i >= 0; i--)
         {
             ((PExp)temp[i]).Apply(this);
         }
     }
     if (node.GetName() != null)
     {
         node.GetName().Apply(this);
     }
     if (node.GetDotType() != null)
     {
         node.GetDotType().Apply(this);
     }
     if (node.GetReceiver() != null)
     {
         node.GetReceiver().Apply(this);
     }
     OutANonstaticInvokeExp(node);
 }
 public override void CaseANonstaticInvokeExp(ANonstaticInvokeExp node)
 {
     IsConst = false;
 }
Esempio n. 5
0
 public override void CaseANonstaticInvokeExp(ANonstaticInvokeExp node)
 {
     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.CaseANonstaticInvokeExp(node);
 }
        public override void CaseANonstaticInvokeExp(ANonstaticInvokeExp node)
        {
            if (processStructs) return;

            AMethodDecl decl = finalTrans.data.StructMethodLinks[node];
            if (!processFieldsOnly && unusedMethods.Contains(decl))
                unusedMethods.Remove(decl);
            AFieldDecl field = Util.GetAncestor<AFieldDecl>(node);
            if (!processMethodsOnly && field != null)
            {
                if (!fieldsWithMethodCalls.Contains(field))
                    fieldsWithMethodCalls.Add(field);
            }
            base.CaseANonstaticInvokeExp(node);
        }
        public override void OutASimpleInvokeExp(ASimpleInvokeExp node)
        {
            if (data.SimpleMethodLinks.ContainsKey(node))
                return;

            List<AMethodDecl> candidates = new List<AMethodDecl>();
            List<AMethodDecl> implicitCandidates = new List<AMethodDecl>();
            List<AMethodDecl> matchingNames = new List<AMethodDecl>();

            List<PType> argTypes = new List<PType>();
            foreach (PExp exp in node.GetArgs())
            {
                argTypes.Add(data.ExpTypes[exp]);
            }
            PExp baseExp;
            bool matchResize;
            GetTargets(node.GetName().Text, node.GetName(), null, null, argTypes, candidates, out matchResize, implicitCandidates, matchingNames, out baseExp, null, data, errors);

            if (baseExp != null)
            {
                ANonstaticInvokeExp replacer = new ANonstaticInvokeExp(baseExp, new ADotDotType(new TDot(".")), node.GetName(), new ArrayList());
                while (node.GetArgs().Count > 0)
                {
                    replacer.GetArgs().Add(node.GetArgs()[0]);
                }
                node.ReplaceBy(replacer);
                baseExp.Apply(this);
                OutANonstaticInvokeExp(replacer);
                return;
            }

            AMethodDecl decl;
            if (candidates.Count == 0 && implicitCandidates.Count == 1)
            {
                //Do the implicit casts
                for (int i = 0; i < node.GetArgs().Count; i++)
                {
                    PType argType = data.ExpTypes[(PExp)node.GetArgs()[i]];
                    AALocalDecl formal = (AALocalDecl)implicitCandidates[0].GetFormals()[i];
                    PType formalType = formal.GetType();
                    if (formal.GetOut() != null && !Assignable(formalType, argType)
                        || formal.GetRef() != null && !(Assignable(argType, formalType) && Assignable(formalType, argType))
                        || formal.GetOut() == null && formal.GetRef() == null && !Assignable(argType, formalType))
                    {
                        PExp exp = (PExp)node.GetArgs()[i];
                        ACastExp cast = new ACastExp(new TLParen("("), Util.MakeClone(formalType, data), null);
                        exp.ReplaceBy(cast);
                        cast.SetExp(exp);
                        OutACastExp(cast);
                    }
                }
                decl = implicitCandidates[0];
            }
            else
                decl = candidates[0];

            data.SimpleMethodLinks.Add(node, decl);
            data.ExpTypes.Add(node, decl.GetReturnType());

            CheckInvoke(node, decl);

            base.OutASimpleInvokeExp(node);
        }
Esempio n. 8
0
 ArrayList New395()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList8 = (ArrayList) Pop();
     ArrayList nodeArrayList7 = (ArrayList) Pop();
     ArrayList nodeArrayList6 = (ArrayList) Pop();
     ArrayList nodeArrayList5 = (ArrayList) Pop();
     ArrayList nodeArrayList4 = (ArrayList) Pop();
     ArrayList nodeArrayList3 = (ArrayList) Pop();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TypedList listNode8 = new TypedList();
     PExp pexpNode3 = (PExp)nodeArrayList2[0];
     AParenExp pexpNode2 = new AParenExp (
       pexpNode3
     );
     TArrow tarrowNode5 = (TArrow)nodeArrayList4[0];
     AArrowDotType pdottypeNode4 = new AArrowDotType (
       tarrowNode5
     );
     TIdentifier tidentifierNode6 = (TIdentifier)nodeArrayList5[0];
     TypedList listNode7 = (TypedList)nodeArrayList7[0];
     if ( listNode7 != null )
     {
     listNode8.AddAll(listNode7);
     }
     ANonstaticInvokeExp pexpNode1 = new ANonstaticInvokeExp (
       pexpNode2,
       pdottypeNode4,
       tidentifierNode6,
       listNode8
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
Esempio n. 9
0
 ArrayList New401()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList6 = (ArrayList) Pop();
     ArrayList nodeArrayList5 = (ArrayList) Pop();
     ArrayList nodeArrayList4 = (ArrayList) Pop();
     ArrayList nodeArrayList3 = (ArrayList) Pop();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TypedList listNode7 = new TypedList();
     PExp pexpNode2 = (PExp)nodeArrayList1[0];
     TArrow tarrowNode4 = (TArrow)nodeArrayList2[0];
     AArrowDotType pdottypeNode3 = new AArrowDotType (
       tarrowNode4
     );
     TIdentifier tidentifierNode5 = (TIdentifier)nodeArrayList3[0];
     TypedList listNode6 = (TypedList)nodeArrayList5[0];
     if ( listNode6 != null )
     {
     listNode7.AddAll(listNode6);
     }
     ANonstaticInvokeExp pexpNode1 = new ANonstaticInvokeExp (
       pexpNode2,
       pdottypeNode3,
       tidentifierNode5,
       listNode7
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
Esempio n. 10
0
 ArrayList New390()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList6 = (ArrayList) Pop();
     ArrayList nodeArrayList5 = (ArrayList) Pop();
     ArrayList nodeArrayList4 = (ArrayList) Pop();
     ArrayList nodeArrayList3 = (ArrayList) Pop();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TypedList listNode9 = new TypedList();
     TThis tthisNode4 = (TThis)nodeArrayList1[0];
     AThisLvalue plvalueNode3 = new AThisLvalue (
       tthisNode4
     );
     ALvalueExp pexpNode2 = new ALvalueExp (
       plvalueNode3
     );
     TDot tdotNode6 = (TDot)nodeArrayList2[0];
     ADotDotType pdottypeNode5 = new ADotDotType (
       tdotNode6
     );
     TIdentifier tidentifierNode7 = (TIdentifier)nodeArrayList3[0];
     TypedList listNode8 = (TypedList)nodeArrayList5[0];
     if ( listNode8 != null )
     {
     listNode9.AddAll(listNode8);
     }
     ANonstaticInvokeExp pexpNode1 = new ANonstaticInvokeExp (
       pexpNode2,
       pdottypeNode5,
       tidentifierNode7,
       listNode9
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
Esempio n. 11
0
 ArrayList New393()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList6 = (ArrayList) Pop();
     ArrayList nodeArrayList5 = (ArrayList) Pop();
     ArrayList nodeArrayList4 = (ArrayList) Pop();
     ArrayList nodeArrayList3 = (ArrayList) Pop();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TypedList listNode9 = new TypedList();
     TValue tvalueNode4 = (TValue)nodeArrayList1[0];
     AValueLvalue plvalueNode3 = new AValueLvalue (
       tvalueNode4
     );
     ALvalueExp pexpNode2 = new ALvalueExp (
       plvalueNode3
     );
     TArrow tarrowNode6 = (TArrow)nodeArrayList2[0];
     AArrowDotType pdottypeNode5 = new AArrowDotType (
       tarrowNode6
     );
     TIdentifier tidentifierNode7 = (TIdentifier)nodeArrayList3[0];
     TypedList listNode8 = (TypedList)nodeArrayList5[0];
     if ( listNode8 != null )
     {
     listNode9.AddAll(listNode8);
     }
     ANonstaticInvokeExp pexpNode1 = new ANonstaticInvokeExp (
       pexpNode2,
       pdottypeNode5,
       tidentifierNode7,
       listNode9
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
Esempio n. 12
0
 ArrayList New388()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList6 = (ArrayList) Pop();
     ArrayList nodeArrayList5 = (ArrayList) Pop();
     ArrayList nodeArrayList4 = (ArrayList) Pop();
     ArrayList nodeArrayList3 = (ArrayList) Pop();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TypedList listNode8 = new TypedList();
     PLvalue plvalueNode3 = (PLvalue)nodeArrayList1[0];
     ALvalueExp pexpNode2 = new ALvalueExp (
       plvalueNode3
     );
     TDot tdotNode5 = (TDot)nodeArrayList2[0];
     ADotDotType pdottypeNode4 = new ADotDotType (
       tdotNode5
     );
     TIdentifier tidentifierNode6 = (TIdentifier)nodeArrayList3[0];
     TypedList listNode7 = (TypedList)nodeArrayList5[0];
     if ( listNode7 != null )
     {
     listNode8.AddAll(listNode7);
     }
     ANonstaticInvokeExp pexpNode1 = new ANonstaticInvokeExp (
       pexpNode2,
       pdottypeNode4,
       tidentifierNode6,
       listNode8
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
Esempio n. 13
0
 ArrayList New381()
 {
     ArrayList nodeList = new ArrayList();
     ArrayList nodeArrayList6 = (ArrayList) Pop();
     ArrayList nodeArrayList5 = (ArrayList) Pop();
     ArrayList nodeArrayList4 = (ArrayList) Pop();
     ArrayList nodeArrayList3 = (ArrayList) Pop();
     ArrayList nodeArrayList2 = (ArrayList) Pop();
     ArrayList nodeArrayList1 = (ArrayList) Pop();
     TypedList listNode11 = new TypedList();
     TypedList listNode6 = new TypedList();
     TypedList listNode5 = (TypedList)nodeArrayList1[0];
     if ( listNode5 != null )
     {
     listNode6.AddAll(listNode5);
     }
     AAName pnameNode4 = new AAName (
       listNode6
     );
     AAmbiguousNameLvalue plvalueNode3 = new AAmbiguousNameLvalue (
       pnameNode4
     );
     ALvalueExp pexpNode2 = new ALvalueExp (
       plvalueNode3
     );
     TArrow tarrowNode8 = (TArrow)nodeArrayList2[0];
     AArrowDotType pdottypeNode7 = new AArrowDotType (
       tarrowNode8
     );
     TIdentifier tidentifierNode9 = (TIdentifier)nodeArrayList3[0];
     TypedList listNode10 = (TypedList)nodeArrayList5[0];
     if ( listNode10 != null )
     {
     listNode11.AddAll(listNode10);
     }
     ANonstaticInvokeExp pexpNode1 = new ANonstaticInvokeExp (
       pexpNode2,
       pdottypeNode7,
       tidentifierNode9,
       listNode11
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
        public override void CaseANonstaticInvokeExp(ANonstaticInvokeExp node)
        {
            PExp reciever = node.GetReceiver();
            PType type = finalTrans.data.ExpTypes[reciever];

            //If the reciever is not a var, put it in a new var.
            if (!(reciever is ALvalueExp))
            {
                AALocalDecl localDecl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, Util.MakeClone(type, data), new TIdentifier("nonstaticInvokeVar"), reciever);
                ALocalLvalue localRef = new ALocalLvalue(new TIdentifier("nonstaticInvokeVar"));
                ALvalueExp localRefExp = new ALvalueExp(localRef);
                node.SetReceiver(localRefExp);
                PStm pStm = Util.GetAncestor<PStm>(node);
                AABlock pBlock = (AABlock) pStm.Parent();
                pBlock.GetStatements().Insert(pBlock.GetStatements().IndexOf(pStm), new ALocalDeclStm(new TSemicolon(";"), localDecl));
                reciever = localRefExp;

                data.LvalueTypes[localRef] =
                    data.ExpTypes[localRefExp] = type;
                data.LocalLinks[localRef] = localDecl;

                localDecl.Apply(this);
            }

            if (type is ANamedType && finalTrans.data.StructTypeLinks.ContainsKey((ANamedType)type))
            {
                //ANamedType type = (ANamedType) finalTrans.data.ExpTypes[reciever];
                if (finalTrans.data.StructTypeLinks[(ANamedType) type].GetClassToken() != null)
                {
                    //Pass the pointer
                    ALvalueExp lvalueExp = (ALvalueExp) reciever;
                    APointerLvalue pointerLvalue = (APointerLvalue) lvalueExp.GetLvalue();
                    reciever = pointerLvalue.GetBase();
                }

                AMethodDecl method = finalTrans.data.StructMethodLinks[node];
                ASimpleInvokeExp simpleInvoke = new ASimpleInvokeExp();
                simpleInvoke.SetName(node.GetName());
                PExp[] exps = new PExp[node.GetArgs().Count];
                node.GetArgs().CopyTo(exps, 0);
                foreach (PExp exp in exps)
                {
                    simpleInvoke.GetArgs().Add(exp);
                }
                simpleInvoke.GetArgs().Add(reciever);
                node.ReplaceBy(simpleInvoke);
                finalTrans.data.SimpleMethodLinks[simpleInvoke] = method;
                finalTrans.data.StructMethodLinks.Remove(node);
                finalTrans.data.ExpTypes[simpleInvoke] = method.GetReturnType();
                finalTrans.data.ExpTypes.Remove(node);
                simpleInvoke.Apply(this);
            }
            else
            {//Enrichment
                /*AEnrichmentDecl enrichment = finalTrans.data.EnrichmentTypeLinks[type];

                foreach (AEnrichmentDecl enrichmentDecl in finalTrans.data.Enrichments)
                {
                    if (Util.IsVisible(node, enrichmentDecl) &&
                        Util.IsDeclVisible(enrichmentDecl, Util.GetAncestor<AASourceFile>(node)) &&
                        Util.TypesEqual(type, enrichmentDecl.GetType(), finalTrans.data))
                    {
                        enrichment = enrichmentDecl;
                        break;
                    }
                }
                if (enrichment == null)
                {
                    finalTrans.errors.Add(new ErrorCollection.Error(node.GetName(), "TransFormMethodDecls.NonStaticInvoke: Expected enrichment - this is a bug. It should have been caught earlier"));
                    throw new ParserException(node.GetName(), "");
                }*/
                AMethodDecl method = finalTrans.data.StructMethodLinks[node];
                ASimpleInvokeExp simpleInvoke = new ASimpleInvokeExp();
                simpleInvoke.SetName(node.GetName());
                PExp[] exps = new PExp[node.GetArgs().Count];
                node.GetArgs().CopyTo(exps, 0);
                foreach (PExp exp in exps)
                {
                    simpleInvoke.GetArgs().Add(exp);
                }
                simpleInvoke.GetArgs().Add(reciever);
                node.ReplaceBy(simpleInvoke);
                finalTrans.data.SimpleMethodLinks[simpleInvoke] = method;
                finalTrans.data.StructMethodLinks.Remove(node);
                finalTrans.data.ExpTypes[simpleInvoke] = method.GetReturnType();
                finalTrans.data.ExpTypes.Remove(node);
                simpleInvoke.Apply(this);

            }
        }
Esempio n. 15
0
 public virtual void OutANonstaticInvokeExp(ANonstaticInvokeExp node)
 {
     DefaultOut(node);
 }
        public override void OutANonstaticInvokeExp(ANonstaticInvokeExp node)
        {
            List<AMethodDecl> candidates = new List<AMethodDecl>();
            List<AMethodDecl> implicitCandidates = new List<AMethodDecl>();
            List<AMethodDecl> matchingNames = new List<AMethodDecl>();
            List<AMethodDecl> delegateCandidates = new List<AMethodDecl>();

            List<PType> argTypes = new List<PType>();
            foreach (PExp exp in node.GetArgs())
            {
                argTypes.Add(data.ExpTypes[exp]);
            }
            PExp baseExp;
            bool needsVistit = false;
            Node reciever = node.GetReceiver();
            bool visitBaseExp = false;
            if (node.GetReceiver() is ALvalueExp && ((ALvalueExp)node.GetReceiver()).GetLvalue() is AAmbiguousNameLvalue)
            {
                visitBaseExp = true;
                reciever = ((AAmbiguousNameLvalue) ((ALvalueExp) node.GetReceiver()).GetLvalue()).GetAmbiguous();
            }
            bool matchResize;
            GetTargets(node.GetName().Text, node.GetName(), reciever, null, argTypes, candidates, out matchResize, implicitCandidates, matchingNames, out baseExp, delegateCandidates, data, errors);

            if (visitBaseExp && baseExp != null)
            {
                node.GetArgs().Add(baseExp);
                baseExp.Apply(this);
                node.GetArgs().Remove(baseExp);
            }

            if (matchResize)
            {
                AArrayResizeExp replacer = new AArrayResizeExp(node.GetName(), baseExp, (PExp) node.GetArgs()[0]);
                node.ReplaceBy(replacer);
                data.ExpTypes[replacer] = new ANamedType(new TIdentifier("void"), null);
                return;
            }

            if (implicitCandidates.Count > 0)
            {
                //Do the implicit casts
                for (int i = 0; i < node.GetArgs().Count; i++)
                {
                    PType argType = data.ExpTypes[(PExp)node.GetArgs()[i]];
                    AALocalDecl formal = (AALocalDecl)implicitCandidates[0].GetFormals()[i];
                    PType formalType = formal.GetType();
                    if (formal.GetOut() != null && !Assignable(formalType, argType)
                        || formal.GetRef() != null && !(Assignable(argType, formalType) && Assignable(formalType, argType))
                        || formal.GetOut() == null && formal.GetRef() == null && !Assignable(argType, formalType))
                    {
                        PExp exp = (PExp)node.GetArgs()[i];
                        ACastExp cast = new ACastExp(new TLParen("("), Util.MakeClone(formalType, data), null);
                        exp.ReplaceBy(cast);
                        cast.SetExp(exp);
                        OutACastExp(cast);
                    }
                }
            }

            if (delegateCandidates.Count > 0)
            {//Target is a delegate invoke
                ADelegateInvokeExp replacer = new ADelegateInvokeExp(node.GetName(), baseExp, new ArrayList());
                while (node.GetArgs().Count > 0)
                {
                    replacer.GetArgs().Add(node.GetArgs()[0]);
                }
                data.ExpTypes[replacer] = delegateCandidates[0].GetReturnType();
                node.ReplaceBy(replacer);
                return;
            }
            AMethodDecl candidate = candidates.Count == 1 ? candidates[0] : implicitCandidates[0];

            if (baseExp == null)
            {
                //Replace with a simple invoke to it.
                ASimpleInvokeExp replacementInvoke = new ASimpleInvokeExp(node.GetName(), new ArrayList());
                while (node.GetArgs().Count > 0)
                {
                    replacementInvoke.GetArgs().Add(node.GetArgs()[0]);
                }
                data.SimpleMethodLinks[replacementInvoke] = candidate;
                data.ExpTypes[replacementInvoke] = candidate.GetReturnType();
                node.ReplaceBy(replacementInvoke);
                CheckInvoke(replacementInvoke, candidate);
                return;
            }
            node.SetReceiver(baseExp);

            data.StructMethodLinks[node] = candidate;
            data.ExpTypes[node] = candidate.GetReturnType();

            if (candidate.GetInline() != null)
            {
                AMethodDecl pMethod = Util.GetAncestor<AMethodDecl>(node);
                AConstructorDecl pConstructor = Util.GetAncestor<AConstructorDecl>(node);
                APropertyDecl pProperty = Util.GetAncestor<APropertyDecl>(node);
                if (pMethod == null && pConstructor == null && pProperty == null && !Util.HasAncestor<ADeconstructorDecl>(node))
                {
                    errors.Add(new ErrorCollection.Error(node.GetName(), currentSourceFile, LocRM.GetString("ErrorText133")));
                }
                else if (pMethod != null && !InlineMethodCalls[pMethod].Contains(candidate))
                    InlineMethodCalls[pMethod].Add(candidate);
            }

            base.OutANonstaticInvokeExp(node);
        }
Esempio n. 17
0
 internal Args_Cast(ANonstaticInvokeExp obj)
 {
     this.obj = obj;
 }
 public override void CaseANonstaticInvokeExp(ANonstaticInvokeExp node)
 {
     node.GetReceiver().Apply(this);
     node.GetDotType().Apply(this);
     Value += node.GetName().Text + "(";
     bool first = true;
     foreach (PExp arg in node.GetArgs())
     {
         if (!first)
             Value += ", ";
         else
             first = false;
         arg.Apply(this);
     }
     Value += ")";
 }