public override void CaseADelegateExp(ADelegateExp node)
        {
            /* Replace delegate<Type>(method)
             * With
             *
             * "method"
             *
             * or
             *
             * "method:reciever"
             */
            AMethodDecl method = finalTrans.data.DelegateCreationMethod[node];
            string d = GetName(method);
            PExp replacer;
            APointerLvalue reciever = finalTrans.data.DelegateRecieveres[node];
            if (reciever != null)
            {
                d += ":";
                AStringConstExp leftSide = new AStringConstExp(new TStringLiteral("\"" + d + "\""));
                replacer = new ABinopExp(leftSide, new APlusBinop(new TPlus("+")), reciever.GetBase());
                finalTrans.data.ExpTypes[leftSide] =
                    finalTrans.data.ExpTypes[replacer] = new ANamedType(new TIdentifier("string"), null);

                if (Util.IsIntPointer(reciever, data.LvalueTypes[reciever], data))
                {

                    ASimpleInvokeExp intToStringInvoke = new ASimpleInvokeExp(new TIdentifier("IntToString"),
                                                                              new ArrayList()
                                                                                  {((ABinopExp) replacer).GetRight()});
                    ((ABinopExp)replacer).SetRight(intToStringInvoke);

                    finalTrans.data.SimpleMethodLinks[intToStringInvoke] =
                        data.Libraries.Methods.First(m => m.GetName().Text == intToStringInvoke.GetName().Text);
                    data.ExpTypes[intToStringInvoke] = new ANamedType(new TIdentifier("string"), null);

                }
            }
            else
            {
                replacer = new AStringConstExp(new TStringLiteral("\"" + d + "\""));
                finalTrans.data.ExpTypes[replacer] = new ANamedType(new TIdentifier("string"), null);
            }
            MoveMethodDeclsOut mover = new MoveMethodDeclsOut("delegateVar", finalTrans.data);
            node.Apply(mover);
            node.ReplaceBy(replacer);
            foreach (PStm stm in mover.NewStatements)
            {
                stm.Apply(this);
            }
        }
 public virtual void OutADelegateExp(ADelegateExp node)
 {
     DefaultOut(node);
 }
 public virtual void InADelegateExp(ADelegateExp node)
 {
     DefaultIn(node);
 }
 public virtual void CaseADelegateExp(ADelegateExp node)
 {
     DefaultCase(node);
 }
 public override void CaseADelegateExp(ADelegateExp node)
 {
     InADelegateExp(node);
     if (node.GetLvalue() != null)
     {
         node.GetLvalue().Apply(this);
     }
     if (node.GetType() != null)
     {
         node.GetType().Apply(this);
     }
     if (node.GetToken() != null)
     {
         node.GetToken().Apply(this);
     }
     OutADelegateExp(node);
 }
 public override void CaseADelegateExp(ADelegateExp node)
 {
     IsConst = false;
 }
        public override void OutADelegateExp(ADelegateExp node)
        {
            //Find the type of delegate
            ANamedType type = (ANamedType) node.GetType();
            if (!data.DelegateTypeLinks.ContainsKey(type))
            {
                errors.Add(new ErrorCollection.Error(node.GetToken(), currentSourceFile, LocRM.GetString("ErrorText93")));
                throw new ParserException(node.GetToken(), "TypeChecking.OutADelegateExp");
            }
            AMethodDecl delegateDef = data.DelegateTypeLinks[type];
            List<PType> argTypes = new List<PType>();
            foreach (AALocalDecl formal in delegateDef.GetFormals())
            {
                argTypes.Add(formal.GetType());
            }

            APointerLvalue reciever = null;
            string methodName;
            Token token;
            Node targetReciever;
            if (node.GetLvalue() is AAmbiguousNameLvalue)
            {
                AAmbiguousNameLvalue ambigious = (AAmbiguousNameLvalue)node.GetLvalue();
                AAName aName = (AAName)ambigious.GetAmbiguous();
                methodName = aName.AsString();
                token = (TIdentifier)aName.GetIdentifier()[aName.GetIdentifier().Count - 1];
                aName.GetIdentifier().RemoveAt(aName.GetIdentifier().Count - 1);
                targetReciever = aName.GetIdentifier().Count > 0 ? aName : null;
            }
            else//node.getLvalue is AStructLvalue
            {
                AStructLvalue lvalue = (AStructLvalue) node.GetLvalue();
                token = lvalue.GetName();
                methodName = token.Text;
                targetReciever = lvalue.GetReceiver();
            }

            List<AMethodDecl> candidates = new List<AMethodDecl>();
            List<AMethodDecl> implicitCandidates = new List<AMethodDecl>();
            List<AMethodDecl> matchingNames = new List<AMethodDecl>();
            PExp baseExp;
            bool matchResize;
            GetTargets(token.Text, node.GetToken(), targetReciever, delegateDef.GetReturnType(), argTypes, candidates, out matchResize, implicitCandidates, matchingNames, out baseExp, null, data, errors);

            if (candidates.Count == 0 && implicitCandidates.Count > 0)
            {
                //Implicit candidates not allowed
                errors.Add(new ErrorCollection.Error(token, LocRM.GetString("ErrorText94"),
                                                     false,
                                                     new ErrorCollection.Error(implicitCandidates[0].GetName(),
                                                                               LocRM.GetString("ErrorText38"))));
                throw new ParserException(token, "OutADelegateExp");
            }

            if (baseExp is ALvalueExp)
            {
                ALvalueExp exp = (ALvalueExp)baseExp;
                if (exp.GetLvalue() is APointerLvalue)
                {
                    reciever = (APointerLvalue) exp.GetLvalue();
                    node.SetLvalue(reciever);
                    reciever.Apply(this);
                }
                else
                {
                    errors.Add(new ErrorCollection.Error(token, LocRM.GetString("ErrorText95"),
                                                         false,
                                                         new ErrorCollection.Error(candidates[0].GetName(),
                                                                                   LocRM.GetString("ErrorText38"))));
                    throw new ParserException(token, "OutADelegateExp");
                }
            }
            else if (baseExp == null)
            {
                //Target is either a global method, a static struct method, or a struct method -> struct method
                //Last one is invalid.
                AStructDecl parentStruct = Util.GetAncestor<AStructDecl>(candidates[0]);
                if (parentStruct != null && candidates[0].GetStatic() == null &&
                    Util.GetAncestor<AStructDecl>(node).GetClassToken() == null &&
                    Util.GetAncestor<AConstructorDecl>(node) == null &&
                    Util.GetAncestor<ADeconstructorDecl>(node) == null)
                {
                    errors.Add(new ErrorCollection.Error(token, LocRM.GetString("ErrorText95"),
                                                         false,
                                                         new ErrorCollection.Error(candidates[0].GetName(),
                                                                                   LocRM.GetString("ErrorText38"))));
                    throw new ParserException(token, "OutADelegateExp");
                }
            }
            else
            {
                errors.Add(new ErrorCollection.Error(token, LocRM.GetString("ErrorText96"),
                                                     false,
                                                     new ErrorCollection.Error(candidates[0].GetName(),
                                                                               LocRM.GetString("ErrorText38"))));
                throw new ParserException(token, "OutADelegateExp");
            }

            //Found exactly 1 delegate method
            data.DelegateCreationMethod[node] = candidates[0];
            data.ExpTypes[node] = node.GetType();
            data.DelegateRecieveres[node] = reciever;
        }
Esempio n. 8
0
 ArrayList New372()
 {
     ArrayList nodeList = new ArrayList();
     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();
     TDelegate tdelegateNode2 = (TDelegate)nodeArrayList1[0];
     PType ptypeNode3 = (PType)nodeArrayList3[0];
     PLvalue plvalueNode4 = (PLvalue)nodeArrayList6[0];
     ADelegateExp pexpNode1 = new ADelegateExp (
       tdelegateNode2,
       ptypeNode3,
       plvalueNode4
     );
     nodeList.Add(pexpNode1);
     return nodeList;
 }
 public override void CaseADelegateExp(ADelegateExp node)
 {
     node.GetType().Apply(this);
     DefaultOut(node);
 }