Inheritance: Expression
Beispiel #1
0
 public AssignStatement(string name, Expression value, Location location)
     : base(location)
 {
     this.name = name;
     this.value = value;
     call = null;
 }
Beispiel #2
0
        protected virtual void SetupMethod(CallExpression call,
                                           MethodInfo method,
                                           TypeData receiverType)
        {
            if (!method.IsPublic &&
                typeManager.GetTypeData(currentClass.TypeBuilder) !=
                receiverType) {
                report.Error(call.Location,
                             "cannot call private routine {0}",
                             call.Name);
                return;
            }

            call.Method = method;
            call.NodeType = typeManager.GetReturnType(method);
            ParameterInfo[] parameters = typeManager.GetParameters(method);
            int i = 0;
            foreach (ModalExpression arg in call.Arguments) {
                ParameterInfo param = parameters[i++];
                if (arg.NodeType == null) // void expression
                    arg.NodeType = typeManager.GetTypeData(param.ParameterType);
            }
            if (call.Receiver == null &&
                (call.IsBuiltin || !method.IsStatic)) {
                call.Receiver = new VoidExpression(call.Location);
                call.Receiver.NodeType = receiverType;
            }
        }
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 VisitCall(CallExpression call)
 {
     TypeData receiverType;
     if (call.Receiver != null) {
         call.Receiver.Accept(this);
         receiverType = call.Receiver.NodeType;
     }
     else {
         call.TypeSpecifier.Accept(this);
         receiverType = call.TypeSpecifier.NodeType;
     }
     if (receiverType == null) {
         report.Error(call.Location, "no match for {0}", call.Name);
         return;
     }
     call.Arguments.Accept(this);
     try {
         MethodData method = receiverType.LookupMethod(call.Name,
                                                       call.Arguments,
                                                       call.HasValue);
         call.IsBuiltin = method.IsBuiltin;
         SetupMethod(call, method.MethodInfo, receiverType);
     }
     catch (LookupMethodException e) {
         string routInfo = receiverType.FullName +
             "::" + call.Name;
         if (call.Arguments.Length > 0) {
             routInfo += "(";
             foreach (ModalExpression arg in call.Arguments) {
                 if (arg != call.Arguments.First)
                     routInfo += ",";
                 routInfo += arg.NodeType.FullName;
             }
             routInfo += ")";
         }
         if (call.HasValue)
             routInfo += ":_";
         report.Error(call.Location,
                      "{0} for {1}", e.Message, routInfo);
     }
 }
Beispiel #5
0
 public LocalExpression(string name, Location location)
     : base(location)
 {
     this.name = name;
     call = null;
 }
Beispiel #6
0
 public override void VisitCall(CallExpression call)
 {
     MethodInfo method = call.Method;
     ParameterInfo[] parameters = typeManager.GetParameters(method);
     int i = call.IsBuiltin ? 1 : 0;
     if (call.Flip) {
         ModalExpression arg = (ModalExpression) call.Arguments.First;
         arg.Accept(this);
         BoxIfNecessary(arg.RawType, parameters[i].ParameterType);
         LocalBuilder tmp =
             ilGenerator.DeclareLocal(parameters[i].ParameterType);
         ilGenerator.Emit(OpCodes.Stloc, tmp);
         call.Receiver.Accept(this);
         ilGenerator.Emit(OpCodes.Ldloc, tmp);
     }
     else {
         if (call.Receiver != null) {
             if (!call.IsBuiltin &&
                 call.Receiver.RawType.IsValueType) {
                 if (call.Receiver is LocalExpression) {
                     LocalExpression localExpr =
                         (LocalExpression) call.Receiver;
                     Argument arg =
                         currentRoutine.GetArgument(localExpr.Name);
                     if (arg != null) {
                         ilGenerator.Emit(OpCodes.Ldarga, arg.Index);
                     }
                     else {
                         LocalVariable local =
                             localVariableStack.GetLocal(localExpr.Name);
                         local.EmitLoadAddress(ilGenerator);
                     }
                 }
                 else {
                     LocalBuilder tmp2 =
                         ilGenerator.DeclareLocal(call.Receiver.RawType);
                     call.Receiver.Accept(this);
                     ilGenerator.Emit(OpCodes.Stloc, tmp2);
                     ilGenerator.Emit(OpCodes.Ldloca, tmp2);
                 }
             }
             else {
                 call.Receiver.Accept(this);
             }
         }
         foreach (ModalExpression arg in call.Arguments) {
             arg.Accept(this);
             BoxIfNecessary(arg.RawType, parameters[i].ParameterType);
             i++;
         }
     }
     if (call.Receiver != null &&
         call.Receiver.RawType.IsInterface)
         ilGenerator.EmitCall(OpCodes.Callvirt, method, null);
     else
         ilGenerator.EmitCall(OpCodes.Call, method, null);
 }
Beispiel #7
0
 public virtual void VisitCall(CallExpression call)
 {
 }