public InvocationTypeInferenceRules() : base(CompilerContext.Current)
        {
            var Array_EnumerableConstructor            = Map(Methods.Of <IEnumerable, Array>(Builtins.array));
            var Array_TypedEnumerableConstructor       = Map(Methods.Of <Type, IEnumerable, Array>(Builtins.array));
            var MultiDimensionalArray_TypedConstructor = Map(Methods.Of <Type, int[], Array>(Builtins.matrix));

            RegisterTypeInferenceRuleFor(
                MultiDimensionalArray_TypedConstructor,
                (invocation, method) =>
            {
                IType type = TypeSystemServices.GetReferencedType(invocation.Arguments[0]);
                if (type == null)
                {
                    return(null);
                }
                return(type.MakeArrayType(invocation.Arguments.Count - 1));
            });

            RegisterTypeInferenceRuleFor(
                Array_EnumerableConstructor,
                (invocation, method) =>
            {
                IType enumeratorItemType = TypeSystemServices.GetEnumeratorItemType(TypeSystemServices.GetExpressionType(invocation.Arguments[0]));
                if (TypeSystemServices.ObjectType == enumeratorItemType)
                {
                    return(null);
                }

                invocation.Target.Entity  = Array_TypedEnumerableConstructor;
                invocation.ExpressionType = Array_TypedEnumerableConstructor.ReturnType;
                invocation.Arguments.Insert(0, CodeBuilder.CreateReference(enumeratorItemType));
                return(enumeratorItemType.MakeArrayType(1));
            });
        }
Beispiel #2
0
        private void LeaveExclusiveOr(BinaryExpression node)
        {
            IType type = TypeSystemServices.GetExpressionType(node);

            if (!type.IsEnum)
            {
                return;
            }

            object lhs = GetLiteral(node.Left);

            if (null == lhs)
            {
                return;
            }

            object rhs = GetLiteral(node.Right);

            if (null == rhs)
            {
                return;
            }

            ReplaceCurrentNode(
                CodeBuilder.CreateCast(type,
                                       CodeBuilder.CreateIntegerLiteral(GetLongValue(rhs) ^ GetLongValue(lhs))));
        }
        public static bool IsArrayArgumentExplicitlyProvided(IParameter[] parameters, ExpressionCollection args)
        {
            IType expressionType = TypeSystemServices.GetExpressionType(args[-1]);
            IType type           = parameters[parameters.Length + -1].Type;

            if (!RuntimeServices.EqualityOperator(expressionType, type))
            {
            }
            return((parameters.Length == args.Count) ? RuntimeServices.EqualityOperator(expressionType, EmptyArrayType.Default) : false);
        }
Beispiel #4
0
        private void LeaveOnesCompliment(UnaryExpression node)
        {
            IType type = TypeSystemServices.GetExpressionType(node);

            if (!type.IsEnum)
            {
                return;
            }

            object operand = GetLiteral(node.Operand);

            if (null == operand)
            {
                return;
            }

            ReplaceCurrentNode(
                CodeBuilder.CreateCast(type,
                                       CodeBuilder.CreateIntegerLiteral(~GetLongValue(operand))));
        }
 protected virtual IType GetExpressionType(Expression node)
 {
     return(TypeSystemServices.GetExpressionType(node));
 }
 public static IType TypeOfFirstArgument(MethodInvocationExpression invocation, IMethod method)
 {
     return(TypeSystemServices.GetExpressionType(invocation.Arguments[0]));
 }
Beispiel #7
0
 public bool IsVoid(Expression e) =>
 RuntimeServices.EqualityOperator(TypeSystemServices.GetExpressionType(e), this.TypeSystemServices.VoidType);