Exemple #1
0
        internal static Type CheckReflectedMethod(ErrorCollector collector, AstNode where, List <MethodInfo> methods, List <expression> arguments, Type return_type, ref bool success)
        {
            /* If there are no candidate methods, don't bother checking the types. */
            if (methods.Count == 0)
            {
                return(0);
            }
            /* Find all the methods that match the needed type. */
            var candidate_methods = from method in methods
                                    where (TypeFromClrType(method.ReturnType) & return_type) != 0
                                    select method;

            Type candiate_return = 0;

            foreach (var method in !candidate_methods.Any() ? methods : candidate_methods)
            {
                candiate_return |= TypeFromClrType(method.ReturnType);
            }
            /* Produce an error for the union of all the types. */
            if (!candidate_methods.Any())
            {
                collector.ReportExpressionTypeError(where, return_type, candiate_return);
                return(0);
            }
            /* Check that the arguments match the union of the parameters of all the methods. This means that we might still not have a valid method, but we can check again during codegen. */
            for (var it = 0; it < arguments.Count; it++)
            {
                Type candidate_parameter_type = 0;
                foreach (var method in methods)
                {
                    var param_type = method.IsStatic ? method.GetParameters()[it].ParameterType : (it == 0 ? method.ReflectedType : method.GetParameters()[it - 1].ParameterType);
                    candidate_parameter_type |= TypeFromClrType(param_type);
                }
                arguments[it].EnsureType(collector, candidate_parameter_type, ref success, true);
            }
            return(candiate_return);
        }
Exemple #2
0
 internal Type EnsureIntrinsic(ErrorCollector collector, AstNode node, Type type, bool must_unbox, ref bool success)
 {
     if (Intrinsics.ContainsKey(node))
     {
         var intrinsic     = Intrinsics[node];
         var original_type = intrinsic.Item1;
         var result        = original_type & type;
         if (result == 0)
         {
             success = false;
             collector.ReportExpressionTypeError(node, original_type, type);
         }
         else
         {
             Intrinsics[node] = new Tuple <Type, bool>(result, intrinsic.Item2 & must_unbox);
         }
         return(result);
     }
     else
     {
         Intrinsics[node] = new Tuple <Type, bool>(type, must_unbox);
         return(type);
     }
 }