示例#1
0
        /// <summary>
        /// Creates a wrapper from a method entity.
        /// </summary>
        private MethodWrapper WrapMethod(MethodEntity method, bool isPartial = false)
        {
            return(new MethodWrapper
            {
                Name = method.Name,
                Type = method.ContainerType.TypeInfo,

                IsStatic = method.IsStatic,
                IsVirtual = method.IsVirtual,
                IsPartiallyApplied = isPartial,
                IsVariadic = method.IsVariadic,

                MethodInfo = method.MethodInfo,
                ArgumentTypes = method.GetArgumentTypes(this),
                ReturnType = method.ReturnType
            });
        }
示例#2
0
        protected override Type ResolveInternal(Context ctx, bool mustReturn)
        {
            if (Identifier == "_")
            {
                Error(CompilerMessages.UnderscoreNameUsed);
            }

            // local variable
            var local = Local ?? ctx.Scope.FindLocal(Identifier);

            if (local != null)
            {
                // only local constants are cached
                // because mutable variables could be closured later on
                if (local.IsConstant && local.IsImmutable && ctx.Options.UnrollConstants)
                {
                    _localConstant = local;
                }

                return(local.Type);
            }

            // static function declared in the script
            try
            {
                var methods = ctx.MainType.ResolveMethodGroup(Identifier);
                if (methods.Length > 1)
                {
                    Error(CompilerMessages.FunctionInvocationAmbiguous, Identifier);
                }

                _method = methods[0];
                return(FunctionalHelper.CreateFuncType(_method.ReturnType, _method.GetArgumentTypes(ctx)));
            }
            catch (KeyNotFoundException)
            {
            }

            // algebraic type without a constructor
            var type = ctx.FindType(Identifier);

            if (type != null && type.Kind == TypeEntityKind.TypeLabel)
            {
                try
                {
                    type.ResolveConstructor(new Type[0]);
                    _type = type;
                    return(_type.TypeInfo);
                }
                catch (KeyNotFoundException)
                {
                }
            }

            // global property
            try
            {
                _property = ctx.ResolveGlobalProperty(Identifier);
                return(_property.PropertyType);
            }
            catch (KeyNotFoundException)
            {
                Error(CompilerMessages.IdentifierNotFound, Identifier);
            }

            return(typeof(UnitType));
        }