Beispiel #1
0
        protected virtual void SetupIter(IterCallExpression iter,
                                         MethodData method,
                                         TypeData receiverType)
        {
            if (!method.MethodInfo.IsPublic &&
                currentClass.TypeData != receiverType) {
                report.Error(iter.Location,
                             "cannot call private iterator {0}",
                             iter.Name);
                return;
            }

            iter.IsBuiltin = method.IsBuiltin;
            MethodData creator = method.IterCreator;

            iter.Method = creator.MethodInfo;
            iter.NodeType = method.ReturnType;
            if (iter.Receiver == null &&
                (iter.IsBuiltin || !method.MethodInfo.IsStatic)) {
                iter.Receiver = new VoidExpression(iter.Location);
                iter.Receiver.NodeType = receiverType;
            }

            TypeData iterType = creator.ReturnType;

            string localName = getTemporallyName();
            iter.Local = localVariableStack.AddLocal(localName,
                                                     iterType);

            iter.CreatorArguments = new TypedNodeList();
            TypedNodeList moveNextArguments = new TypedNodeList();
            ModalExpression receiver =
                new ModalExpression(ArgumentMode.In,
                                    (Expression) iter.Receiver.Clone(),
                                    iter.Receiver.Location);
            ParameterInfo[] parameters =
                typeManager.GetParameters(method.MethodInfo);
            int i;
            if (iter.IsBuiltin)
                i = 1;
            else
                i = 0;
            foreach (ModalExpression arg in iter.Arguments) {
                ParameterInfo param = parameters[i++];
                if (arg.NodeType == null) // void expression
                    arg.NodeType = typeManager.GetTypeData(param.ParameterType);
                ArgumentMode mode = typeManager.GetArgumentMode(param);
                if (mode == ArgumentMode.Once) {
                    ModalExpression me = (ModalExpression) arg.Clone();
                    me.Mode = ArgumentMode.In;
                    iter.CreatorArguments.Append(me);
                }
                else {
                    moveNextArguments.Append((ModalExpression) arg.Clone());
                }
            }
            LocalExpression moveNextReceiver =
                new LocalExpression(iter.Local.Name, iter.Location);
            iter.MoveNext = new CallExpression(moveNextReceiver,
                                               "MoveNext",
                                               moveNextArguments,
                                               iter.Location);
            iter.MoveNext.Accept(this);
            if (!iter.NodeType.IsVoid) {
                LocalExpression getCurrentReceiver =
                    new LocalExpression(iter.Local.Name, iter.Location);
                iter.GetCurrent = new CallExpression(getCurrentReceiver,
                                                     "GetCurrent",
                                                     new TypedNodeList(),
                                                     iter.Location);
                iter.GetCurrent.Accept(this);
            }
        }
Beispiel #2
0
 public override void VisitLocal(LocalExpression localExpr)
 {
     if (!inSharedContext) {
         Argument arg = currentRoutine.GetArgument(localExpr.Name);
         if (arg != null) {
             if (arg.NodeType.IsByRef)
                 localExpr.NodeType = arg.NodeType.ElementType;
             else
                 localExpr.NodeType = arg.NodeType;
             return;
         }
         LocalVariable local =
             localVariableStack.GetLocal(localExpr.Name);
         if (local != null) {
             localExpr.NodeType = local.LocalType;
             return;
         }
     }
     Expression self = new SelfExpression(localExpr.Location);
     localExpr.Call = new CallExpression(self, localExpr.Name,
                                         new TypedNodeList(),
                                         localExpr.Location);
     localExpr.Call.HasValue = localExpr.HasValue;
     localExpr.Call.Accept(this);
     localExpr.NodeType = localExpr.Call.NodeType;
 }
Beispiel #3
0
 public override void VisitCase(CaseStatement caseStmt)
 {
     caseStmt.Test.Accept(this);
     caseStmt.TestName = getTemporallyName();
     localVariableStack.AddLocal(caseStmt.TestName,
                                 caseStmt.Test.NodeType);
     foreach (CaseWhen when in caseStmt.WhenPartList) {
         foreach (Expression value in when.ValueList) {
             LocalExpression test =
                 new LocalExpression(caseStmt.TestName, value.Location);
             ModalExpression arg =
                 new ModalExpression(ArgumentMode.In, value,
                                     value.Location);
             TypedNodeList args = new TypedNodeList(arg);
             CallExpression call =
                 new CallExpression(test, "is_eq", args, value.Location);
             call.Accept(this);
             if (call.NodeType == typeManager.BoolType) {
                 when.TestCallList.Append(call);
             }
             else {
                 if (call.NodeType != null) {
                     report.Error(value.Location,
                                  "no match for {0}::is_eq({1}):BOOL",
                                  caseStmt.Test.NodeType.FullName,
                                  value.NodeType.FullName);
                 }
             }
         }
         when.ThenPart.Accept(this);
     }
     if (caseStmt.ElsePart != null)
         caseStmt.ElsePart.Accept(this);
 }
Beispiel #4
0
 public override void VisitLocal(LocalExpression localExpr)
 {
     Argument arg = currentRoutine.GetArgument(localExpr.Name);
     if (arg != null) {
         ilGenerator.Emit(OpCodes.Ldarg, arg.Index);
         if (arg.RawType.IsByRef)
             EmitLdind(arg.RawType.GetElementType());
         return;
     }
     LocalVariable local = localVariableStack.GetLocal(localExpr.Name);
     local.EmitLoad(ilGenerator);
 }
Beispiel #5
0
 public TypecaseStatement(LocalExpression variable,
                          NodeList whenPartList,
                          StatementList elsePart,
                          Location location)
     : base(location)
 {
     this.variable = variable;
     this.whenPartList = whenPartList;
     this.elsePart = elsePart;
 }
Beispiel #6
0
 public virtual void VisitLocal(LocalExpression local)
 {
 }