Beispiel #1
0
        /// <summary>
        /// Create a type entry without setting its parent info.
        /// </summary>
        private TypeEntity createTypeCore(string name, bool isSealed, bool defaultCtor, bool prepare, Action<TypeEntity> extraInit = null)
        {
            if (_DefinedTypes.ContainsKey(name))
                Error(CompilerMessages.TypeDefined, name);

            var te = new TypeEntity(this)
            {
                Name = name,
                IsSealed = isSealed,
            };
            _DefinedTypes.Add(name, te);

            if (extraInit != null)
                extraInit(te);

            if (prepare)
                te.PrepareSelf();
            else
                UnpreparedTypes.Add(te);

            if (defaultCtor)
                te.CreateConstructor(null, prepare);

            return te;
        }
Beispiel #2
0
        protected MethodEntityBase(TypeEntity type, bool isImported = false)
            : base(type)
        {
            Arguments = new HashList<FunctionArgument>();

            IsImported = isImported;
        }
Beispiel #3
0
        public MethodEntity(TypeEntity type, bool isImported = false)
            : base(type, isImported)
        {
            var scopeKind = type.Kind == TypeEntityKind.Closure
                ? ScopeKind.LambdaRoot
                : ScopeKind.FunctionRoot;

            Body = new CodeBlockNode(scopeKind);
        }
Beispiel #4
0
 public FieldEntity(TypeEntity type)
     : base(type)
 {
 }
Beispiel #5
0
        protected override Type resolve(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);
        }
Beispiel #6
0
        protected MethodEntityBase(TypeEntity type, bool isImported = false) : base(type)
        {
            Arguments = new HashList <FunctionArgument>();

            IsImported = isImported;
        }
Beispiel #7
0
 public ConstructorEntity(TypeEntity type) : base(type)
 {
     Body = new CodeBlockNode(ScopeKind.FunctionRoot);
 }
Beispiel #8
0
 public FieldEntity(TypeEntity type) : base(type)
 {
 }
Beispiel #9
0
 public ConstructorEntity(TypeEntity type)
     : base(type)
 {
     Body = new CodeBlockNode(ScopeKind.FunctionRoot);
 }