Esempio n. 1
0
		protected override TypeSpec[] ResolveBaseTypes (out FullNamedExpression base_class)
		{
			base_type = Compiler.BuiltinTypes.Object;

			base_class = null;
			return null;
		}
Esempio n. 2
0
		public MethodCore (DeclSpace parent, GenericMethod generic,
			FullNamedExpression type, Modifiers mod, Modifiers allowed_mod,
			MemberName name, Attributes attrs, ParametersCompiled parameters)
			: base (parent, generic, type, mod, allowed_mod, name, attrs)
		{
			this.parameters = parameters;
		}
        protected Event(DeclSpace parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
            : base(parent, null, type, mod_flags,
				parent.PartialContainer.Kind == MemberKind.Interface ? AllowedModifiersInterface :
				parent.PartialContainer.Kind == MemberKind.Struct ? AllowedModifiersStruct :
				AllowedModifiersClass,
				name, attrs)
        {
        }
Esempio n. 4
0
		public Const (DeclSpace parent, FullNamedExpression type, string name,
			      Expression expr, int mod_flags, Attributes attrs, Location loc)
			: base (parent, type, mod_flags, AllowedModifiers,
				new MemberName (name, loc), attrs)
		{
			initializer = expr;
			ModFlags |= Modifiers.STATIC;
		}
Esempio n. 5
0
		protected FieldBase (DeclSpace parent, FullNamedExpression type, Modifiers mod,
				     Modifiers allowed_mod, MemberName name, Attributes attrs)
			: base (parent, null, type, mod, allowed_mod | Modifiers.ABSTRACT, Modifiers.PRIVATE,
				name, attrs)
		{
			if ((mod & Modifiers.ABSTRACT) != 0)
				Report.Error (681, Location, "The modifier 'abstract' is not valid on fields. Try using a property instead");
		}
Esempio n. 6
0
 public Enum(TypeContainer parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
     : base(parent, name, attrs, MemberKind.Enum)
 {
     underlying_type_expr = type;
     var accmods = IsTopLevel ? Modifiers.INTERNAL : Modifiers.PRIVATE;
     ModFlags = ModifiersExtensions.Check (AllowedModifiers, mod_flags, accmods, Location, Report);
     spec = new EnumSpec (null, this, null, null, ModFlags);
 }
Esempio n. 7
0
        public Const(DeclSpace parent, FullNamedExpression type, string name,
            Expression expr, Modifiers mod_flags, Attributes attrs, Location loc)
            : base(parent, type, mod_flags, AllowedModifiers,
				new MemberName (name, loc), attrs)
        {
            if (expr != null)
                initializer = new ConstInitializer (this, expr);

            ModFlags |= Modifiers.STATIC;
        }
Esempio n. 8
0
        public Delegate(TypeContainer parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, ParametersCompiled param_list,
				 Attributes attrs)
            : base(parent, name, attrs, MemberKind.Delegate)
        {
            this.ReturnType = type;
            ModFlags        = ModifiersExtensions.Check (AllowedModifiers, mod_flags,
                               IsTopLevel ? Modifiers.INTERNAL :
                               Modifiers.PRIVATE, name.Location, Report);
            parameters      = param_list;
            spec = new TypeSpec (Kind, null, this, null, ModFlags | Modifiers.SEALED);
        }
Esempio n. 9
0
 		public Delegate (NamespaceEntry ns, DeclSpace parent, FullNamedExpression type,
				 int mod_flags, MemberName name, ParametersCompiled param_list,
				 Attributes attrs)
			: base (ns, parent, name, attrs, Kind.Delegate)

		{
			this.ReturnType = type;
			ModFlags        = Modifiers.Check (AllowedModifiers, mod_flags,
							   IsTopLevel ? Modifiers.INTERNAL :
							   Modifiers.PRIVATE, name.Location, Report);
			Parameters      = param_list;
		}
Esempio n. 10
0
		public Method (TypeDefinition parent, FullNamedExpression return_type, Modifiers mod, MemberName name, ParametersCompiled parameters, Attributes attrs)
			: base (parent, return_type, mod,
				parent.PartialContainer.Kind == MemberKind.Interface ? AllowedModifiersInterface :
				parent.PartialContainer.Kind == MemberKind.Struct ? AllowedModifiersStruct | Modifiers.ASYNC :
				AllowedModifiersClass | Modifiers.ASYNC,
				name, attrs, parameters)
		{
		}
Esempio n. 11
0
		public MethodCore (TypeDefinition parent, FullNamedExpression type, Modifiers mod, Modifiers allowed_mod,
			MemberName name, Attributes attrs, ParametersCompiled parameters)
			: base (parent, type, mod, allowed_mod, name, attrs)
		{
			this.parameters = parameters;
		}
Esempio n. 12
0
		public InteractiveMethod(TypeDefinition parent, FullNamedExpression returnType, Modifiers mod, ParametersCompiled parameters)
			: base(parent, returnType, mod, new MemberName("Host"), parameters, null)
		{
		}
Esempio n. 13
0
		public Property (TypeDefinition parent, FullNamedExpression type, Modifiers mod,
				 MemberName name, Attributes attrs)
			: base (parent, type, mod,
				parent.PartialContainer.Kind == MemberKind.Interface ? AllowedModifiersInterface :
				parent.PartialContainer.Kind == MemberKind.Struct ? AllowedModifiersStruct :
				AllowedModifiersClass,
				name, attrs)
		{
		}
Esempio n. 14
0
 GetEnumeratorMethod(IteratorStorey host, FullNamedExpression returnType, MemberName name)
     : base(host, null, returnType, Modifiers.DEBUGGER_HIDDEN, name, ToplevelBlock.Flags.CompilerGenerated | ToplevelBlock.Flags.NoFlowAnalysis)
 {
 }
Esempio n. 15
0
		public Field (TypeContainer parent, FullNamedExpression type, Modifiers mod, MemberName name, Attributes attrs)
			: base (parent, type, mod, AllowedModifiers, name, attrs)
		{
		}
Esempio n. 16
0
 public InteractiveMethod(TypeDefinition parent, FullNamedExpression returnType, Modifiers mod, ParametersCompiled parameters)
     : base(parent, returnType, mod, new MemberName("Host"), parameters, null)
 {
 }
Esempio n. 17
0
 public MemberName(MemberName left, string name, FullNamedExpression explicitInterface, Location loc)
     : this(left, name, loc)
 {
     this.ExplicitInterface = explicitInterface;
 }
Esempio n. 18
0
 public MemberName(string name, TypeParameters tparams, FullNamedExpression explicitInterface, Location loc)
     : this(name, tparams, loc)
 {
     this.ExplicitInterface = explicitInterface;
 }
Esempio n. 19
0
 protected override TypeSpec[] ResolveBaseTypes(out FullNamedExpression base_class)
 {
     base_type  = Compiler.BuiltinTypes.Enum;
     base_class = null;
     return(null);
 }
Esempio n. 20
0
        public static FullNamedExpression CreateDelegateTypeExpression(BuiltinTypes builtinTypes, ParametersCompiled parameters, FullNamedExpression retType, Location loc)
        {
            bool hasParams      = parameters != null && parameters.Count > 0;
            int  paramCount     = hasParams ? parameters.Count : 0;
            bool hasRetType     = !(retType is TypeExpression && ((TypeExpression)retType).Type == builtinTypes.Void);
            int  typeParamCount = paramCount;

            if (hasRetType)
            {
                typeParamCount++;
            }
            TypeArguments typeArgs = null;

            if (typeParamCount > 0)
            {
                var typeArgArray = new FullNamedExpression[typeParamCount];
                for (var i = 0; i < paramCount; i++)
                {
                    if (i < paramCount)
                    {
                        var param = parameters.FixedParameters[i] as Parameter;
                        typeArgArray[i] = param.TypeExpression;
                    }
                    else
                    {
                        typeArgArray[i] = retType;
                    }
                }
                typeArgs = new TypeArguments(typeArgArray);
            }
            if (!hasRetType)
            {
                return(new MemberAccess(new SimpleName("System", loc), "Action", typeArgs, loc));
            }
            else
            {
                return(new MemberAccess(new SimpleName("System", loc), "Func", typeArgs, loc));
            }
        }
Esempio n. 21
0
        TypeSpec FindDocumentedTypeNonArray(MemberCore mc, string identifier, DeclSpace ds, string cref)
        {
            var types = module.Compiler.BuiltinTypes;

            switch (identifier)
            {
            case "int":
                return(types.Int);

            case "uint":
                return(types.UInt);

            case "short":
                return(types.Short);

            case "ushort":
                return(types.UShort);

            case "long":
                return(types.Long);

            case "ulong":
                return(types.ULong);

            case "float":
                return(types.Float);

            case "double":
                return(types.Double);

            case "char":
                return(types.Char);

            case "decimal":
                return(types.Decimal);

            case "byte":
                return(types.Byte);

            case "sbyte":
                return(types.SByte);

            case "object":
                return(types.Object);

            case "bool":
                return(types.Bool);

            case "string":
                return(types.String);

            case "void":
                return(types.Void);
            }
            FullNamedExpression e = ds.LookupNamespaceOrType(identifier, 0, mc.Location, false);

            if (e != null)
            {
                if (!(e is TypeExpr))
                {
                    return(null);
                }
                return(e.Type);
            }
            int index = identifier.LastIndexOf('.');

            if (index < 0)
            {
                return(null);
            }

            var       nsName   = identifier.Substring(0, index);
            var       typeName = identifier.Substring(index + 1);
            Namespace ns       = ds.NamespaceEntry.NS.GetNamespace(nsName, false);

            ns = ns ?? mc.Module.GlobalRootNamespace.GetNamespace(nsName, false);
            if (ns != null)
            {
                var te = ns.LookupType(mc, typeName, 0, true, mc.Location);
                if (te != null)
                {
                    return(te.Type);
                }
            }

            int      warn;
            TypeSpec parent = FindDocumentedType(mc, identifier.Substring(0, index), ds, cref);

            if (parent == null)
            {
                return(null);
            }
            // no need to detect warning 419 here
            var ts = FindDocumentedMember(mc, parent,
                                          identifier.Substring(index + 1),
                                          null, ds, out warn, cref, false, null) as TypeSpec;

            if (ts != null)
            {
                return(ts);
            }
            return(null);
        }
Esempio n. 22
0
 public DocumentationParameter(FullNamedExpression type)
 {
     this.Type = type;
 }
Esempio n. 23
0
		public static Method Create (TypeDefinition parent, FullNamedExpression returnType, Modifiers mod,
				   MemberName name, ParametersCompiled parameters, Attributes attrs)
		{
			var m = new Method (parent, returnType, mod, name, parameters, attrs);

			if ((mod & Modifiers.PARTIAL) != 0) {
				const Modifiers invalid_partial_mod = Modifiers.AccessibilityMask | Modifiers.ABSTRACT | Modifiers.EXTERN |
					Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;

				if ((mod & invalid_partial_mod) != 0) {
					m.Report.Error (750, m.Location,
						"A partial method cannot define access modifier or any of abstract, extern, new, override, sealed, or virtual modifiers");
					mod &= ~invalid_partial_mod;
				}

				if ((parent.ModFlags & Modifiers.PARTIAL) == 0) {
					m.Report.Error (751, m.Location, 
						"A partial method must be declared within a partial class or partial struct");
				}
			}

			if ((mod & Modifiers.STATIC) == 0 && parameters.HasExtensionMethodType) {
				m.Report.Error (1105, m.Location, "`{0}': Extension methods must be declared static",
					m.GetSignatureForError ());
			}


			return m;
		}
Esempio n. 24
0
		protected MemberBase (DeclSpace parent, GenericMethod generic,
				      FullNamedExpression type, Modifiers mod, Modifiers allowed_mod, Modifiers def_mod,
				      MemberName name, Attributes attrs)
			: base (parent, name, attrs)
		{
			this.ds = generic != null ? generic : (DeclSpace) parent;
			this.type_expr = type;
			ModFlags = ModifiersExtensions.Check (allowed_mod, mod, def_mod, Location, Report);
			GenericMethod = generic;
			if (GenericMethod != null)
				GenericMethod.ModFlags = ModFlags;
		}
Esempio n. 25
0
 public GetEnumeratorMethod(IteratorStorey host, FullNamedExpression returnType, MemberName name)
     : base(host, returnType, Modifiers.DEBUGGER_HIDDEN, name)
 {
     Block.AddStatement(new GetEnumeratorStatement(host, this));
 }
Esempio n. 26
0
 public DocumentationParameter(Parameter.Modifier modifier, FullNamedExpression type)
     : this(type)
 {
     this.Modifier = modifier;
 }
Esempio n. 27
0
 public Const(TypeDefinition parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
     : base(parent, type, mod_flags, AllowedModifiers, name, attrs)
 {
     ModFlags |= Modifiers.STATIC;
 }
Esempio n. 28
0
 public static GetEnumeratorMethod Create(IteratorStorey host, FullNamedExpression returnType, MemberName name)
 {
     return(Create(host, returnType, name, null));
 }
Esempio n. 29
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, null, 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}'",
                                 TypeManager.CSharpName(partype), GetSignatureForError());
                }
            }

            ReturnType = ReturnType.ResolveAsType(this);
            if (ReturnType == null)
            {
                return(false);
            }

            var ret_type = ReturnType.Type;

            //
            // 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 `" +
                             TypeManager.CSharpName(ret_type) + "' is less " +
                             "accessible than delegate `" + GetSignatureForError() + "'");
                return(false);
            }

            CheckProtectedModifier();

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

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

            InvokeBuilder = new Method(this, null, ReturnType, 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(Parameters.CallingConvention);
            }

            return(true);
        }
Esempio n. 30
0
 public Field(DeclSpace parent, FullNamedExpression type, Modifiers mod, MemberName name,
              Attributes attrs)
     : base(parent, type, mod ^ Modifiers.ROLE, AllowedModifiers, name, attrs)
 {
     isRole = (mod & Modifiers.ROLE) == Modifiers.ROLE;
 }
Esempio n. 31
0
 public static ParametersCompiled CreateImplicitParameter(FullNamedExpression texpr, Location loc)
 {
     return(new ParametersCompiled(
                new[] { new Parameter(texpr, "value", Parameter.Modifier.NONE, null, loc) },
                null));
 }
Esempio n. 32
0
		public EventProperty (TypeDefinition parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
			: base (parent, type, mod_flags, name, attrs)
		{
		}
Esempio n. 33
0
 public ParamsParameter(FullNamedExpression type, string name, Attributes attrs, Location loc) :
     base(type, name, Parameter.Modifier.PARAMS, attrs, loc)
 {
 }
Esempio n. 34
0
		public Operator (TypeDefinition parent, OpType type, FullNamedExpression ret_type, Modifiers mod_flags, ParametersCompiled parameters,
				 ToplevelBlock block, Attributes attrs, Location loc)
			: base (parent, ret_type, mod_flags, AllowedModifiers, new MemberName (GetMetadataName (type), loc), attrs, parameters)
		{
			OperatorType = type;
			Block = block;
		}
Esempio n. 35
0
        private static Type FindDocumentedTypeNonArray(MemberCore mc,
                                                       string identifier, DeclSpace ds, string cref)
        {
            switch (identifier)
            {
            case "int":
                return(TypeManager.int32_type);

            case "uint":
                return(TypeManager.uint32_type);

            case "short":
                return(TypeManager.short_type);;

            case "ushort":
                return(TypeManager.ushort_type);

            case "long":
                return(TypeManager.int64_type);

            case "ulong":
                return(TypeManager.uint64_type);;

            case "float":
                return(TypeManager.float_type);;

            case "double":
                return(TypeManager.double_type);

            case "char":
                return(TypeManager.char_type);;

            case "decimal":
                return(TypeManager.decimal_type);;

            case "byte":
                return(TypeManager.byte_type);;

            case "sbyte":
                return(TypeManager.sbyte_type);;

            case "object":
                return(TypeManager.object_type);;

            case "bool":
                return(TypeManager.bool_type);;

            case "string":
                return(TypeManager.string_type);;

            case "void":
                return(TypeManager.void_type);;
            }
            FullNamedExpression e = ds.LookupNamespaceOrType(identifier, mc.Location, false);

            if (e != null)
            {
                if (!(e is TypeExpr))
                {
                    return(null);
                }
                return(e.Type);
            }
            int index = identifier.LastIndexOf('.');

            if (index < 0)
            {
                return(null);
            }
            int  warn;
            Type parent = FindDocumentedType(mc, identifier.Substring(0, index), ds, cref);

            if (parent == null)
            {
                return(null);
            }
            // no need to detect warning 419 here
            return(FindDocumentedMember(mc, parent,
                                        identifier.Substring(index + 1),
                                        null, ds, out warn, cref, false, null).Member as Type);
        }
Esempio n. 36
0
		protected MethodOrOperator (TypeDefinition parent, FullNamedExpression type, Modifiers mod, Modifiers allowed_mod, MemberName name,
				Attributes attrs, ParametersCompiled parameters)
			: base (parent, type, mod, allowed_mod, name, attrs, parameters)
		{
		}
Esempio n. 37
0
File: field.cs Progetto: N3X15/mono
 public FixedField(TypeDefinition parent, FullNamedExpression type, Modifiers mod, MemberName name, Attributes attrs)
     : base(parent, type, mod, AllowedModifiers, name, attrs)
 {
 }
Esempio n. 38
0
		protected Method (TypeDefinition parent, FullNamedExpression return_type, Modifiers mod, Modifiers amod,
					MemberName name, ParametersCompiled parameters, Attributes attrs)
			: base (parent, return_type, mod, amod, name, attrs, parameters)
		{
		}
Esempio n. 39
0
		protected override TypeSpec[] ResolveBaseTypes (out FullNamedExpression base_class)
		{
			var ifaces = base.ResolveBaseTypes (out base_class);

			if (base_class == null) {
				if (spec.BuiltinType != BuiltinTypeSpec.Type.Object)
					base_type = Compiler.BuiltinTypes.Object;
			} else {
				if (base_type.IsGenericParameter){
					Report.Error (689, base_class.Location, "`{0}': Cannot derive from type parameter `{1}'",
						GetSignatureForError (), base_type.GetSignatureForError ());
				} else if (base_type.IsStatic) {
					Report.SymbolRelatedToPreviousError (base_type);
					Report.Error (709, Location, "`{0}': Cannot derive from static class `{1}'",
						GetSignatureForError (), base_type.GetSignatureForError ());
				} else if (base_type.IsSealed) {
					Report.SymbolRelatedToPreviousError (base_type);
					Report.Error (509, Location, "`{0}': cannot derive from sealed type `{1}'",
						GetSignatureForError (), base_type.GetSignatureForError ());
				} else if (PartialContainer.IsStatic && base_type.BuiltinType != BuiltinTypeSpec.Type.Object) {
					Report.Error (713, Location, "Static class `{0}' cannot derive from type `{1}'. Static classes must derive from object",
						GetSignatureForError (), base_type.GetSignatureForError ());
				}

				switch (base_type.BuiltinType) {
				case BuiltinTypeSpec.Type.Enum:
				case BuiltinTypeSpec.Type.ValueType:
				case BuiltinTypeSpec.Type.MulticastDelegate:
				case BuiltinTypeSpec.Type.Delegate:
				case BuiltinTypeSpec.Type.Array:
					if (!(spec is BuiltinTypeSpec)) {
						Report.Error (644, Location, "`{0}' cannot derive from special class `{1}'",
							GetSignatureForError (), base_type.GetSignatureForError ());

						base_type = Compiler.BuiltinTypes.Object;
					}
					break;
				}

				if (!IsAccessibleAs (base_type)) {
					Report.SymbolRelatedToPreviousError (base_type);
					Report.Error (60, Location, "Inconsistent accessibility: base class `{0}' is less accessible than class `{1}'",
						base_type.GetSignatureForError (), GetSignatureForError ());
				}
			}

			if (PartialContainer.IsStatic && ifaces != null) {
				foreach (var t in ifaces)
					Report.SymbolRelatedToPreviousError (t);
				Report.Error (714, Location, "Static class `{0}' cannot implement interfaces", GetSignatureForError ());
			}

			return ifaces;
		}
Esempio n. 40
0
		public InterfaceMemberBase (DeclSpace parent, GenericMethod generic,
				   FullNamedExpression type, Modifiers mod, Modifiers allowed_mod,
				   MemberName name, Attributes attrs)
			: base (parent, generic, type, mod, allowed_mod, Modifiers.PRIVATE,
				name, attrs)
		{
			IsInterface = parent.PartialContainer.Kind == MemberKind.Interface;
			IsExplicitImpl = (MemberName.ExplicitInterface != null);
			explicit_mod_flags = mod;
		}
Esempio n. 41
0
		public InterfaceMemberBase (TypeDefinition parent, FullNamedExpression type, Modifiers mod, Modifiers allowed_mod, MemberName name, Attributes attrs)
			: base (parent, type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs)
		{
			IsInterface = parent.Kind == MemberKind.Interface;
			IsExplicitImpl = (MemberName.ExplicitInterface != null);
			explicit_mod_flags = mod;
		}
Esempio n. 42
0
		TypeSpec[] GetNormalPartialBases ()
		{
			var ifaces = new List<TypeSpec> (0);
			if (iface_exprs != null)
				ifaces.AddRange (iface_exprs);

			foreach (TypeContainer part in partial_parts) {
				FullNamedExpression new_base_class;
				var new_ifaces = part.ResolveBaseTypes (out new_base_class);
				if (new_base_class != null) {
					if (base_type_expr != null && part.base_type != base_type) {
						Report.SymbolRelatedToPreviousError (new_base_class.Location, "");
						Report.Error (263, part.Location,
							"Partial declarations of `{0}' must not specify different base classes",
							part.GetSignatureForError ());
					} else {
						base_type_expr = new_base_class;
						base_type = part.base_type;
					}
				}

				if (new_ifaces == null)
					continue;

				foreach (var iface in new_ifaces) {
					if (ifaces.Contains (iface))
						continue;

					ifaces.Add (iface);
				}
			}

			if (ifaces.Count == 0)
				return null;

			return ifaces.ToArray ();
		}
Esempio n. 43
0
		protected Field AddCompilerGeneratedField (string name, FullNamedExpression type)
		{
			return AddCompilerGeneratedField (name, type, false);
		}
Esempio n. 44
0
		/// <summary>
		///   This function computes the Base class and also the
		///   list of interfaces that the class or struct @c implements.
		///   
		///   The return value is an array (might be null) of
		///   interfaces implemented (as Types).
		///   
		///   The @base_class argument is set to the base object or null
		///   if this is `System.Object'. 
		/// </summary>
		protected virtual TypeSpec[] ResolveBaseTypes (out FullNamedExpression base_class)
		{
			base_class = null;
			if (type_bases == null)
				return null;

			int count = type_bases.Count;
			TypeSpec[] ifaces = null;
			var base_context = new BaseContext (this);
			for (int i = 0, j = 0; i < count; i++){
				FullNamedExpression fne = type_bases [i];

				var fne_resolved = fne.ResolveAsType (base_context);
				if (fne_resolved == null)
					continue;

				if (i == 0 && Kind == MemberKind.Class && !fne_resolved.IsInterface) {
					if (fne_resolved.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
						Report.Error (1965, Location, "Class `{0}' cannot derive from the dynamic type",
							GetSignatureForError ());

						continue;
					}
					
					base_type = fne_resolved;
					base_class = fne;
					continue;
				}

				if (ifaces == null)
					ifaces = new TypeSpec [count - i];

				if (fne_resolved.IsInterface) {
					for (int ii = 0; ii < j; ++ii) {
						if (fne_resolved == ifaces [ii]) {
							Report.Error (528, Location, "`{0}' is already listed in interface list",
								fne_resolved.GetSignatureForError ());
							break;
						}
					}

					if (Kind == MemberKind.Interface && !IsAccessibleAs (fne_resolved)) {
						Report.Error (61, fne.Location,
							"Inconsistent accessibility: base interface `{0}' is less accessible than interface `{1}'",
							fne_resolved.GetSignatureForError (), GetSignatureForError ());
					}
				} else {
					Report.SymbolRelatedToPreviousError (fne_resolved);
					if (Kind != MemberKind.Class) {
						Report.Error (527, fne.Location, "Type `{0}' in interface list is not an interface", fne_resolved.GetSignatureForError ());
					} else if (base_class != null)
						Report.Error (1721, fne.Location, "`{0}': Classes cannot have multiple base classes (`{1}' and `{2}')",
							GetSignatureForError (), base_class.GetSignatureForError (), fne_resolved.GetSignatureForError ());
					else {
						Report.Error (1722, fne.Location, "`{0}': Base class `{1}' must be specified as first",
							GetSignatureForError (), fne_resolved.GetSignatureForError ());
					}
				}

				ifaces [j++] = fne_resolved;
			}

			return ifaces;
		}
Esempio n. 45
0
        //
        // Processes "see" or "seealso" elements from cref attribute.
        //
        void HandleXrefCommon(MemberCore mc, TypeContainer ds, XmlElement xref)
        {
            string cref = xref.GetAttribute("cref");

            // when, XmlReader, "if (cref == null)"
            if (!xref.HasAttribute("cref"))
            {
                return;
            }

            // Nothing to be resolved the reference is marked explicitly
            if (cref.Length > 2 && cref [1] == ':')
            {
                return;
            }

            // Additional symbols for < and > are allowed for easier XML typing
            cref = cref.Replace('{', '<').Replace('}', '>');

            var encoding = module.Compiler.Settings.Encoding;
            var s        = new MemoryStream(encoding.GetBytes(cref));

            var source_file = new CompilationSourceFile(doc_module, mc.Location.SourceFile);
            var report      = new Report(doc_module.Compiler, new NullReportPrinter());

            if (session == null)
            {
                session = new ParserSession()
                {
                    UseJayGlobalArrays = true
                }
            }
            ;

            SeekableStreamReader seekable = new SeekableStreamReader(s, encoding, session.StreamReaderBuffer);

            var parser = new CSharpParser(seekable, source_file, report, session);

            ParsedParameters          = null;
            ParsedName                = null;
            ParsedBuiltinType         = null;
            ParsedOperator            = null;
            parser.Lexer.putback_char = Tokenizer.DocumentationXref;
            parser.Lexer.parsing_generic_declaration_doc = true;
            parser.parse();
            if (report.Errors > 0)
            {
                Report.Warning(1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'",
                               mc.GetSignatureForError(), cref);

                xref.SetAttribute("cref", "!:" + cref);
                return;
            }

            MemberSpec          member;
            string              prefix = null;
            FullNamedExpression fne    = null;

            //
            // Try built-in type first because we are using ParsedName as identifier of
            // member names on built-in types
            //
            if (ParsedBuiltinType != null && (ParsedParameters == null || ParsedName != null))
            {
                member = ParsedBuiltinType.Type;
            }
            else
            {
                member = null;
            }

            if (ParsedName != null || ParsedOperator.HasValue)
            {
                TypeSpec type        = null;
                string   member_name = null;

                if (member == null)
                {
                    if (ParsedOperator.HasValue)
                    {
                        type = mc.CurrentType;
                    }
                    else if (ParsedName.Left != null)
                    {
                        fne = ResolveMemberName(mc, ParsedName.Left);
                        if (fne != null)
                        {
                            var ns = fne as Namespace;
                            if (ns != null)
                            {
                                fne = ns.LookupTypeOrNamespace(mc, ParsedName.Name, ParsedName.Arity, LookupMode.Probing, Location.Null);
                                if (fne != null)
                                {
                                    member = fne.Type;
                                }
                            }
                            else
                            {
                                type = fne.Type;
                            }
                        }
                    }
                    else
                    {
                        fne = ResolveMemberName(mc, ParsedName);
                        if (fne == null)
                        {
                            type = mc.CurrentType;
                        }
                        else if (ParsedParameters == null)
                        {
                            member = fne.Type;
                        }
                        else if (fne.Type.MemberDefinition == mc.CurrentType.MemberDefinition)
                        {
                            member_name = Constructor.ConstructorName;
                            type        = fne.Type;
                        }
                    }
                }
                else
                {
                    type   = (TypeSpec)member;
                    member = null;
                }

                if (ParsedParameters != null)
                {
                    var old_printer = mc.Module.Compiler.Report.SetPrinter(new NullReportPrinter());
                    try {
                        var context = new DocumentationMemberContext(mc, ParsedName ?? MemberName.Null);

                        foreach (var pp in ParsedParameters)
                        {
                            pp.Resolve(context);
                        }
                    } finally {
                        mc.Module.Compiler.Report.SetPrinter(old_printer);
                    }
                }

                if (type != null)
                {
                    if (member_name == null)
                    {
                        member_name = ParsedOperator.HasValue ?
                                      Operator.GetMetadataName(ParsedOperator.Value) : ParsedName.Name;
                    }

                    int parsed_param_count;
                    if (ParsedOperator == Operator.OpType.Explicit || ParsedOperator == Operator.OpType.Implicit)
                    {
                        parsed_param_count = ParsedParameters.Count - 1;
                    }
                    else if (ParsedParameters != null)
                    {
                        parsed_param_count = ParsedParameters.Count;
                    }
                    else
                    {
                        parsed_param_count = 0;
                    }

                    int parameters_match = -1;
                    do
                    {
                        var members = MemberCache.FindMembers(type, member_name, true);
                        if (members != null)
                        {
                            foreach (var m in members)
                            {
                                if (ParsedName != null && m.Arity != ParsedName.Arity)
                                {
                                    continue;
                                }

                                if (ParsedParameters != null)
                                {
                                    IParametersMember pm = m as IParametersMember;
                                    if (pm == null)
                                    {
                                        continue;
                                    }

                                    if (m.Kind == MemberKind.Operator && !ParsedOperator.HasValue)
                                    {
                                        continue;
                                    }

                                    var pm_params = pm.Parameters;

                                    int i;
                                    for (i = 0; i < parsed_param_count; ++i)
                                    {
                                        var pparam = ParsedParameters[i];

                                        if (i >= pm_params.Count || pparam == null || pparam.TypeSpec == null ||
                                            !TypeSpecComparer.Override.IsEqual(pparam.TypeSpec, pm_params.Types[i]) ||
                                            (pparam.Modifier & Parameter.Modifier.RefOutMask) != (pm_params.FixedParameters[i].ModFlags & Parameter.Modifier.RefOutMask))
                                        {
                                            if (i > parameters_match)
                                            {
                                                parameters_match = i;
                                            }

                                            i = -1;
                                            break;
                                        }
                                    }

                                    if (i < 0)
                                    {
                                        continue;
                                    }

                                    if (ParsedOperator == Operator.OpType.Explicit || ParsedOperator == Operator.OpType.Implicit)
                                    {
                                        if (pm.MemberType != ParsedParameters[parsed_param_count].TypeSpec)
                                        {
                                            parameters_match = parsed_param_count + 1;
                                            continue;
                                        }
                                    }
                                    else
                                    {
                                        if (parsed_param_count != pm_params.Count)
                                        {
                                            continue;
                                        }
                                    }
                                }

                                if (member != null)
                                {
                                    Report.Warning(419, 3, mc.Location,
                                                   "Ambiguous reference in cref attribute `{0}'. Assuming `{1}' but other overloads including `{2}' have also matched",
                                                   cref, member.GetSignatureForError(), m.GetSignatureForError());

                                    break;
                                }

                                member = m;
                            }
                        }

                        // Continue with parent type for nested types
                        if (member == null)
                        {
                            type = type.DeclaringType;
                        }
                        else
                        {
                            type = null;
                        }
                    } while (type != null);

                    if (member == null && parameters_match >= 0)
                    {
                        for (int i = parameters_match; i < parsed_param_count; ++i)
                        {
                            Report.Warning(1580, 1, mc.Location, "Invalid type for parameter `{0}' in XML comment cref attribute `{1}'",
                                           (i + 1).ToString(), cref);
                        }

                        if (parameters_match == parsed_param_count + 1)
                        {
                            Report.Warning(1581, 1, mc.Location, "Invalid return type in XML comment cref attribute `{0}'", cref);
                        }
                    }
                }
            }

            if (member == null)
            {
                Report.Warning(1574, 1, mc.Location, "XML comment on `{0}' has cref attribute `{1}' that could not be resolved",
                               mc.GetSignatureForError(), cref);
                cref = "!:" + cref;
            }
            else if (member == InternalType.Namespace)
            {
                cref = "N:" + fne.GetSignatureForError();
            }
            else
            {
                prefix = GetMemberDocHead(member);
                cref   = prefix + member.GetSignatureForDocumentation();
            }

            xref.SetAttribute("cref", cref);
        }
Esempio n. 46
0
		protected override TypeSpec[] ResolveBaseTypes (out FullNamedExpression base_class)
		{
			var ifaces = base.ResolveBaseTypes (out base_class);
			base_type = Compiler.BuiltinTypes.ValueType;
			return ifaces;
		}
Esempio n. 47
0
        private static TypeSpec FindDocumentedTypeNonArray(MemberCore mc,
                                                           string identifier, DeclSpace ds, string cref, Report r)
        {
            switch (identifier)
            {
            case "int":
                return(TypeManager.int32_type);

            case "uint":
                return(TypeManager.uint32_type);

            case "short":
                return(TypeManager.short_type);;

            case "ushort":
                return(TypeManager.ushort_type);

            case "long":
                return(TypeManager.int64_type);

            case "ulong":
                return(TypeManager.uint64_type);;

            case "float":
                return(TypeManager.float_type);;

            case "double":
                return(TypeManager.double_type);

            case "char":
                return(TypeManager.char_type);;

            case "decimal":
                return(TypeManager.decimal_type);;

            case "byte":
                return(TypeManager.byte_type);;

            case "sbyte":
                return(TypeManager.sbyte_type);;

            case "object":
                return(TypeManager.object_type);;

            case "bool":
                return(TypeManager.bool_type);;

            case "string":
                return(TypeManager.string_type);;

            case "void":
                return(TypeManager.void_type);;
            }
            FullNamedExpression e = ds.LookupNamespaceOrType(identifier, 0, mc.Location, false);

            if (e != null)
            {
                if (!(e is TypeExpr))
                {
                    return(null);
                }
                return(e.Type);
            }
            int index = identifier.LastIndexOf('.');

            if (index < 0)
            {
                return(null);
            }

            var       nsName   = identifier.Substring(0, index);
            var       typeName = identifier.Substring(index + 1);
            Namespace ns       = ds.NamespaceEntry.NS.GetNamespace(nsName, false);

            ns = ns ?? mc.Module.GlobalRootNamespace.GetNamespace(nsName, false);
            if (ns != null)
            {
                var te = ns.LookupType(mc.Compiler, typeName, 0, true, mc.Location);
                if (te != null)
                {
                    return(te.Type);
                }
            }

            int      warn;
            TypeSpec parent = FindDocumentedType(mc, identifier.Substring(0, index), ds, cref, r);

            if (parent == null)
            {
                return(null);
            }
            // no need to detect warning 419 here
            var ts = FindDocumentedMember(mc, parent,
                                          identifier.Substring(index + 1),
                                          null, ds, out warn, cref, false, null, r) as TypeSpec;

            if (ts != null)
            {
                return(ts);
            }
            return(null);
        }
Esempio n. 48
0
		protected MemberBase (TypeDefinition parent, FullNamedExpression type, Modifiers mod, Modifiers allowed_mod, Modifiers def_mod, MemberName name, Attributes attrs)
			: base (parent, name, attrs)
		{
			this.Parent = parent;
			this.type_expr = type;

			if (name != MemberName.Null)
				ModFlags = ModifiersExtensions.Check (allowed_mod, mod, def_mod, Location, Report);
		}
Esempio n. 49
0
 public RoleField(DeclSpace parent, FullNamedExpression type, Modifiers mod, MemberName name, Attributes attrs) : base(parent, type, mod, name, attrs)
 {
 }
Esempio n. 50
0
		protected Field AddCompilerGeneratedField (string name, FullNamedExpression type, bool privateAccess)
		{
			Modifiers mod = Modifiers.COMPILER_GENERATED | (privateAccess ? Modifiers.PRIVATE : Modifiers.INTERNAL);
			Field f = new Field (this, type, mod, new MemberName (name, Location), null);
			AddField (f);
			return f;
		}
Esempio n. 51
0
 public Self(string roleContractName, FullNamedExpression type, string name, Modifier mod, Attributes attrs, Location loc) : base(type, name, mod, attrs, loc)
 {
     _roleContractName = roleContractName;
 }
Esempio n. 52
0
			public HoistedField (HoistedStoreyClass parent, FullNamedExpression type, Modifiers mod, string name,
				  Attributes attrs, Location loc)
				: base (parent, type, mod, new MemberName (name, loc), attrs)
			{
			}
Esempio n. 53
0
 GetEnumeratorMethod(IteratorStorey host, FullNamedExpression returnType, MemberName name)
     : base(host, null, returnType, Modifiers.DEBUGGER_HIDDEN, name)
 {
 }