Пример #1
0
        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 += ")";
        }
        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);
            }
        }