Пример #1
0
Файл: enum.cs Проект: kkdevs/mcs
        protected override void DoDefineContainer()
        {
            TypeSpec ut;

            if (underlying_type_expr != null)
            {
                ut = underlying_type_expr.ResolveAsType(this);
                if (!EnumSpec.IsValidUnderlyingType(ut))
                {
                    Error_UnderlyingType(underlying_type_expr.Location);
                    ut = null;
                }
            }
            else
            {
                ut = null;
            }

            if (ut == null)
            {
                ut = Compiler.BuiltinTypes.Int;
            }

            ((EnumSpec)spec).UnderlyingType = ut;

            TypeBuilder.DefineField(UnderlyingValueField, UnderlyingType.GetMetaInfo(),
                                    FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName);

            DefineBaseTypes();
        }
Пример #2
0
        public override FullNamedExpression Resolve(IMemberContext rc, bool local)
        {
            if (resolved != null || value == null)
            {
                return(resolved);
            }

            if (local)
            {
                return(null);
            }

            resolved = value.GetTypeExpression().ResolveAsTypeOrNamespace(rc);
            if (resolved == null)
            {
                value = null;
                return(null);
            }

            if (resolved is TypeExpr)
            {
                resolved = resolved.ResolveAsType(rc);
            }

            return(resolved);
        }
Пример #3
0
        // <summary>
        //   Resolve is used in method definitions
        // </summary>
        public virtual TypeSpec Resolve(IMemberContext rc, int index)
        {
            if (parameter_type != null)
            {
                return(parameter_type);
            }

            if (attributes != null)
            {
                attributes.AttachTo(this, rc);
            }

            var expr = texpr.ResolveAsType(rc);

            if (expr == null)
            {
                return(null);
            }

            this.idx       = index;
            texpr          = expr;
            parameter_type = texpr.Type;

            if ((modFlags & Parameter.Modifier.ISBYREF) != 0 && parameter_type.IsSpecialRuntimeType)
            {
                rc.Module.Compiler.Report.Error(1601, Location, "Method or delegate parameter cannot be of type `{0}'",
                                                GetSignatureForError());
                return(null);
            }

            TypeManager.CheckTypeVariance(parameter_type,
                                          (modFlags & Parameter.Modifier.ISBYREF) != 0 ? Variance.None : Variance.Contravariant,
                                          rc);

            if (parameter_type.IsStatic)
            {
                rc.Module.Compiler.Report.Error(721, Location, "`{0}': static types cannot be used as parameters",
                                                texpr.GetSignatureForError());
                return(parameter_type);
            }

            if ((modFlags & Modifier.This) != 0 && (parameter_type.IsPointer || parameter_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic))
            {
                rc.Module.Compiler.Report.Error(1103, Location, "The extension method cannot be of type `{0}'",
                                                TypeManager.CSharpName(parameter_type));
            }

            return(parameter_type);
        }
Пример #4
0
        protected override Expression DoResolve(ResolveContext rc)
        {
//			BEN: This won't work because the returned type won't pass Mono's type checkers.
//			if (rc.Target == Target.JavaScript) {
//				this.type = rc.Module.PredefinedTypes.AsArray.Resolve();
//				this.eclass = ExprClass.Value;
//				foreach (var elem in Elements)
//					elem.Resolve (rc);
//				return this;
//			}

            TypeExpression type;

            if (vectorType != null)               // For new <Type> [ initializer ] expressions..
            {
                var elemTypeSpec = vectorType.ResolveAsType(rc);
                if (elemTypeSpec != null)
                {
                    type = new TypeExpression(
                        rc.Module.PredefinedTypes.AsVector.Resolve().MakeGenericType(rc, new [] { elemTypeSpec }), Location);
                }
                else
                {
                    type = new TypeExpression(rc.Module.PredefinedTypes.AsArray.Resolve(), Location);
                }
            }
            else
            {
                type = new TypeExpression(rc.Module.PredefinedTypes.AsArray.Resolve(), Location);
            }

            TypeSpec typeSpec = type.ResolveAsType(rc.MemberContext);

            if (typeSpec.IsArray)
            {
                ArrayCreation arrayCreate = (ArrayCreation) new ArrayCreation(type, this).Resolve(rc);
                return(arrayCreate);
            }
            else
            {
                var initElems = new List <Expression>();
                foreach (var e in elements)
                {
                    initElems.Add(new CollectionElementInitializer(e));
                }
                return(new NewInitialize(type, null,
                                         new CollectionOrObjectInitializers(initElems, Location), Location).Resolve(rc));
            }
        }
Пример #5
0
        protected override bool DoDefineMembers()
        {
            var builtin_types = Compiler.BuiltinTypes;

            var ctor_parameters = ParametersCompiled.CreateFullyResolved(
                new [] {
                new Parameter(new TypeExpression(builtin_types.Object, Location), "object", Parameter.Modifier.NONE, null, Location),
                new Parameter(new TypeExpression(builtin_types.IntPtr, Location), "method", Parameter.Modifier.NONE, null, Location)
            },
                new [] {
                builtin_types.Object,
                builtin_types.IntPtr
            }
                );

            Constructor = new Constructor(this, Constructor.ConstructorName,
                                          Modifiers.PUBLIC, null, ctor_parameters, Location);
            Constructor.Define();

            //
            // Here the various methods like Invoke, BeginInvoke etc are defined
            //
            // First, call the `out of band' special method for
            // defining recursively any types we need:
            //
            var p = parameters;

            if (!p.Resolve(this))
            {
                return(false);
            }

            //
            // Invoke method
            //

            // Check accessibility
            foreach (var partype in p.Types)
            {
                if (!IsAccessibleAs(partype))
                {
                    Report.SymbolRelatedToPreviousError(partype);
                    Report.Error(59, Location,
                                 "Inconsistent accessibility: parameter type `{0}' is less accessible than delegate `{1}'",
                                 partype.GetSignatureForError(), GetSignatureForError());
                }
            }

            var ret_type = ReturnType.ResolveAsType(this);

            if (ret_type == null)
            {
                return(false);
            }

            //
            // We don't have to check any others because they are all
            // guaranteed to be accessible - they are standard types.
            //
            if (!IsAccessibleAs(ret_type))
            {
                Report.SymbolRelatedToPreviousError(ret_type);
                Report.Error(58, Location,
                             "Inconsistent accessibility: return type `" +
                             ret_type.GetSignatureForError() + "' is less " +
                             "accessible than delegate `" + GetSignatureForError() + "'");
                return(false);
            }

            CheckProtectedModifier();

            if (Compiler.Settings.StdLib && ret_type.IsSpecialRuntimeType)
            {
                Method.Error1599(Location, ret_type, Report);
                return(false);
            }

            VarianceDecl.CheckTypeVariance(ret_type, Variance.Covariant, this);

            var resolved_rt = new TypeExpression(ret_type, Location);

            InvokeBuilder = new Method(this, resolved_rt, MethodModifiers, new MemberName(InvokeMethodName), p, null);
            InvokeBuilder.Define();

            //
            // Don't emit async method for compiler generated delegates (e.g. dynamic site containers)
            //
            if (!IsCompilerGenerated)
            {
                DefineAsyncMethods(resolved_rt);
            }

            return(true);
        }
Пример #6
0
 public void Resolve(IMemberContext context)
 {
     type = Type.ResolveAsType(context);
 }
Пример #7
0
		public override FullNamedExpression Resolve (IMemberContext rc, bool local)
		{
			if (resolved != null || value == null)
				return resolved;

			if (local)
				return null;

			resolved = value.GetTypeExpression ().ResolveAsTypeOrNamespace (rc);
			if (resolved == null) {
				value = null;
				return null;
			}

			if (resolved is TypeExpr)
				resolved = resolved.ResolveAsType (rc);

			return resolved;
		}
Пример #8
0
        protected override Expression DoResolve(ResolveContext rc)
        {
//			BEN: This won't work because the returned type won't pass Mono's type checkers.
//			if (rc.Target == Target.JavaScript) {
//				this.type = rc.Module.PredefinedTypes.AsArray.Resolve();
//				this.eclass = ExprClass.Value;
//				foreach (var elem in Elements)
//					elem.Resolve (rc);
//				return this;
//			}

            // Attempt to build simple const initializer
            bool     is_const_init = false;
            TypeSpec const_type    = null;

            if (elements.Count > 0)
            {
                is_const_init = true;
                const_type    = vectorType != null?vectorType.ResolveAsType(rc) : null;

                foreach (var elem in elements)
                {
                    if (elem == null)
                    {
                        is_const_init = false;
                        break;
                    }
                    if (!(elem is Constant) && !(elem is Unary && ((Unary)elem).Expr is Constant))
                    {
                        is_const_init = false;
                        break;
                    }
                    TypeSpec elemType = elem.Type;
                    if (vectorType == null)
                    {
                        if (elemType == null)
                        {
                            is_const_init = false;
                            break;
                        }
                        if (const_type == null)
                        {
                            const_type = BuiltinTypeSpec.IsPrimitiveType(elemType) ? elemType : rc.BuiltinTypes.Object;
                        }
                        if (const_type != elemType)
                        {
                            if (((const_type == rc.BuiltinTypes.Int || const_type == rc.BuiltinTypes.UInt) && elemType == rc.BuiltinTypes.Double) ||
                                (const_type == rc.BuiltinTypes.Double && (elemType == rc.BuiltinTypes.Int || elemType == rc.BuiltinTypes.UInt)))
                            {
                                const_type = rc.BuiltinTypes.Double;
                            }
                            else
                            {
                                const_type = rc.BuiltinTypes.Object;
                            }
                        }
                    }
                }
            }

            TypeExpression type;

            if (vectorType != null)               // For new <Type> [ initializer ] expressions..
            {
                var elemTypeSpec = vectorType.ResolveAsType(rc);
                if (elemTypeSpec != null)
                {
                    type = new TypeExpression(
                        rc.Module.PredefinedTypes.AsVector.Resolve().MakeGenericType(rc, new [] { elemTypeSpec }), Location);
                }
                else
                {
                    type = new TypeExpression(rc.Module.PredefinedTypes.AsArray.Resolve(), Location);
                }
            }
            else
            {
                type = new TypeExpression(rc.Module.PredefinedTypes.AsArray.Resolve(), Location);
            }

            TypeSpec typeSpec = type.ResolveAsType(rc.MemberContext);

            if (typeSpec.IsArray)
            {
                ArrayCreation arrayCreate = (ArrayCreation) new ArrayCreation(type, this).Resolve(rc);
                return(arrayCreate);
            }
            else if (is_const_init)
            {
                // If all elements in the initializer list are simple constants, we just pass the elements in a .NET array to the
                // PS Array initializer.
                var newArgs = new Arguments(1);
                newArgs.Add(new Argument(new ArrayCreation(new TypeExpression(const_type, loc), this, loc)));
                return(new New(type, newArgs, loc).Resolve(rc));
            }
            else
            {
                var initElems = new List <Expression>();
                foreach (var e in elements)
                {
                    initElems.Add(new CollectionElementInitializer(e));
                }
                return(new NewInitialize(type, null,
                                         new CollectionOrObjectInitializers(initElems, Location), Location).Resolve(rc));
            }
        }