Ejemplo n.º 1
0
Archivo: enum.cs Proyecto: speier/shake
 public Enum(NamespaceEntry ns, DeclSpace parent, TypeExpr type,
     Modifiers mod_flags, MemberName name, Attributes attrs)
     : base(ns, parent, name, attrs, MemberKind.Enum)
 {
     this.base_type = 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);
 }
Ejemplo n.º 2
0
 //
 // These are expressions that represent some of the internal data types, used
 // elsewhere
 //
 public static void InitExpressionTypes()
 {
     system_object_expr  = new TypeLookupExpression (object_type);
     system_string_expr  = new TypeLookupExpression (string_type);
     system_boolean_expr = new TypeLookupExpression (bool_type);
     system_decimal_expr = new TypeLookupExpression (decimal_type);
     system_single_expr  = new TypeLookupExpression (float_type);
     system_double_expr  = new TypeLookupExpression (double_type);
     system_sbyte_expr   = new TypeLookupExpression (sbyte_type);
     system_byte_expr    = new TypeLookupExpression (byte_type);
     system_int16_expr   = new TypeLookupExpression (short_type);
     system_uint16_expr  = new TypeLookupExpression (ushort_type);
     system_int32_expr   = new TypeLookupExpression (int32_type);
     system_uint32_expr  = new TypeLookupExpression (uint32_type);
     system_int64_expr   = new TypeLookupExpression (int64_type);
     system_uint64_expr  = new TypeLookupExpression (uint64_type);
     system_char_expr    = new TypeLookupExpression (char_type);
     system_void_expr    = new TypeLookupExpression (void_type);
     system_valuetype_expr  = new TypeLookupExpression (value_type);
 }
Ejemplo n.º 3
0
        protected override TypeExpr[] ResolveBaseTypes(out TypeExpr base_class)
        {
            var mtype = Iterator.OriginalIteratorType;
            if (Mutator != null)
                mtype = Mutator.Mutate (mtype);

            iterator_type_expr = new TypeExpression (mtype, Location);
            generic_args = new TypeArguments (iterator_type_expr);

            var list = new List<FullNamedExpression> ();
            if (Iterator.IsEnumerable) {
                enumerable_type = new TypeExpression (
                    TypeManager.ienumerable_type, Location);
                list.Add (enumerable_type);

                if (TypeManager.generic_ienumerable_type != null) {
                    generic_enumerable_type = new GenericTypeExpr (
                        TypeManager.generic_ienumerable_type,
                        generic_args, Location);
                    list.Add (generic_enumerable_type);
                }
            }

            enumerator_type = new TypeExpression (
                TypeManager.ienumerator_type, Location);
            list.Add (enumerator_type);

            list.Add (new TypeExpression (TypeManager.idisposable_type, Location));

            if (TypeManager.generic_ienumerator_type != null) {
                generic_enumerator_type = new GenericTypeExpr (
                    TypeManager.generic_ienumerator_type,
                    generic_args, Location);
                list.Add (generic_enumerator_type);
            }

            type_bases = list;

            return base.ResolveBaseTypes (out base_class);
        }
Ejemplo n.º 4
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 TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
		{
			base_class = null;
			if (type_bases == null)
				return null;

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

				TypeExpr fne_resolved = fne.ResolveAsTypeTerminal (base_context, false);
				if (fne_resolved == null)
					continue;

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

						continue;
					}
					
					base_type = fne_resolved.Type;
					base_class = fne_resolved;
					continue;
				}

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

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

					if (Kind == MemberKind.Interface && !IsAccessibleAs (fne_resolved.Type)) {
						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.Type);
					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;
		}
Ejemplo n.º 5
0
		protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
		{
			TypeExpr[] ifaces = base.ResolveBaseTypes (out base_class);

			if (base_class == null) {
				if (spec != TypeManager.object_type)
					base_type = TypeManager.object_type;
			} else {
				if (base_type.IsGenericParameter){
					Report.Error (689, base_class.Location, "`{0}': Cannot derive from type parameter `{1}'",
						GetSignatureForError (), base_type.GetSignatureForError ());
				} else if (IsGeneric && base_type.IsAttribute) {
					Report.Error (698, base_class.Location,
						"A generic type cannot derive from `{0}' because it is an attribute class",
						base_class.GetSignatureForError ());
				} else if (base_type.IsStatic) {
					Report.SymbolRelatedToPreviousError (base_class.Type);
					Report.Error (709, Location, "`{0}': Cannot derive from static class `{1}'",
						GetSignatureForError (), base_type.GetSignatureForError ());
				} else if (base_type.IsSealed) {
					Report.SymbolRelatedToPreviousError (base_class.Type);
					Report.Error (509, Location, "`{0}': cannot derive from sealed type `{1}'",
						GetSignatureForError (), base_type.GetSignatureForError ());
				} else if (PartialContainer.IsStatic && base_class.Type != TypeManager.object_type) {
					Report.Error (713, Location, "Static class `{0}' cannot derive from type `{1}'. Static classes must derive from object",
						GetSignatureForError (), base_class.GetSignatureForError ());
				}

				if (base_type is BuildinTypeSpec && !(spec is BuildinTypeSpec) &&
					(base_type == TypeManager.enum_type || base_type == TypeManager.value_type || base_type == TypeManager.multicast_delegate_type ||
					base_type == TypeManager.delegate_type || base_type == TypeManager.array_type)) {
					Report.Error (644, Location, "`{0}' cannot derive from special class `{1}'",
						GetSignatureForError (), base_type.GetSignatureForError ());

					base_type = TypeManager.object_type;
				}

				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 (TypeExpr t in ifaces)
					Report.SymbolRelatedToPreviousError (t.Type);
				Report.Error (714, Location, "Static class `{0}' cannot implement interfaces", GetSignatureForError ());
			}

			return ifaces;
		}
Ejemplo n.º 6
0
			public AnonymousMethodMethod (DeclSpace parent, AnonymousExpression am, AnonymousMethodStorey storey,
							  GenericMethod generic, TypeExpr return_type,
							  Modifiers mod, string real_name, MemberName name,
							  ParametersCompiled parameters)
				: base (parent, generic, return_type, mod | Modifiers.COMPILER_GENERATED,
						name, parameters, null)
			{
				this.AnonymousMethod = am;
				this.Storey = storey;
				this.RealName = real_name;

				Parent.PartialContainer.AddMethod (this);
				Block = new ToplevelBlock (am.block, parameters);
			}
Ejemplo n.º 7
0
		public Enum (NamespaceContainer ns, TypeContainer parent, TypeExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
			: base (ns, 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);
		}
Ejemplo n.º 8
0
		public static void Reset ()
		{
			parameter_expr_tree_type = null;
		}
Ejemplo n.º 9
0
		public override Expression DoResolve (ResolveContext ec)
		{
			probe_type_expr = ProbeType.ResolveAsTypeTerminal (ec, false);
			if (probe_type_expr == null)
				return null;

			expr = expr.Resolve (ec);
			if (expr == null)
				return null;

			if ((probe_type_expr.Type.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute) {
				ec.Report.Error (-244, loc, "The `{0}' operator cannot be applied to an operand of a static type",
					OperatorName);
			}
			
			if (expr.Type.IsPointer || probe_type_expr.Type.IsPointer) {
				ec.Report.Error (244, loc, "The `{0}' operator cannot be applied to an operand of pointer type",
					OperatorName);
				return null;
			}

			if (expr.Type == InternalType.AnonymousMethod) {
				ec.Report.Error (837, loc, "The `{0}' operator cannot be applied to a lambda expression or anonymous method",
					OperatorName);
				return null;
			}

			return this;
		}
Ejemplo n.º 10
0
		/// <summary>
		///   Resolve the constraints into actual types.
		/// </summary>
		public bool ResolveTypes (IResolveContext ec)
		{
			if (resolved_types)
				return true;

			resolved_types = true;

			foreach (object obj in constraints) {
				GenericTypeExpr cexpr = obj as GenericTypeExpr;
				if (cexpr == null)
					continue;

				if (!cexpr.CheckConstraints (ec))
					return false;
			}

			if (type_param_constraints.Count != 0) {
				ArrayList seen = new ArrayList ();
				TypeExpr prev_constraint = class_constraint;
				foreach (TypeParameterExpr expr in type_param_constraints) {
					if (!CheckTypeParameterConstraints (expr.TypeParameter, ref prev_constraint, seen))
						return false;
					seen.Clear ();
				}
			}

			for (int i = 0; i < iface_constraints.Count; ++i) {
				TypeExpr iface_constraint = (TypeExpr) iface_constraints [i];
				iface_constraint = iface_constraint.ResolveAsTypeTerminal (ec, false);
				if (iface_constraint == null)
					return false;
				iface_constraints [i] = iface_constraint;
			}

			if (class_constraint != null) {
				class_constraint = class_constraint.ResolveAsTypeTerminal (ec, false);
				if (class_constraint == null)
					return false;
			}

			return true;
		}
Ejemplo n.º 11
0
		bool CheckTypeParameterConstraints (TypeParameter tparam, ref TypeExpr prevConstraint, ArrayList seen)
		{
			seen.Add (tparam);

			Constraints constraints = tparam.Constraints;
			if (constraints == null)
				return true;

			if (constraints.HasValueTypeConstraint) {
				Report.Error (456, loc,
					"Type parameter `{0}' has the `struct' constraint, so it cannot be used as a constraint for `{1}'",
					tparam.Name, name);
				return false;
			}

			//
			//  Checks whether there are no conflicts between type parameter constraints
			//
			//   class Foo<T, U>
			//      where T : A
			//      where U : A, B	// A and B are not convertible
			//
			if (constraints.HasClassConstraint) {
				if (prevConstraint != null) {
					Type t2 = constraints.ClassConstraint;
					TypeExpr e2 = constraints.class_constraint;

					if (!Convert.ImplicitReferenceConversionExists (prevConstraint, t2) &&
						!Convert.ImplicitReferenceConversionExists (e2, prevConstraint.Type)) {
						Report.Error (455, loc,
							"Type parameter `{0}' inherits conflicting constraints `{1}' and `{2}'",
							name, TypeManager.CSharpName (prevConstraint.Type), TypeManager.CSharpName (t2));
						return false;
					}
				}

				prevConstraint = constraints.class_constraint;
			}

			if (constraints.type_param_constraints == null)
				return true;

			foreach (TypeParameterExpr expr in constraints.type_param_constraints) {
				if (seen.Contains (expr.TypeParameter)) {
					Report.Error (454, loc, "Circular constraint " +
						      "dependency involving `{0}' and `{1}'",
						      tparam.Name, expr.GetSignatureForError ());
					return false;
				}

				if (!CheckTypeParameterConstraints (expr.TypeParameter, ref prevConstraint, seen))
					return false;
			}

			return true;
		}
Ejemplo n.º 12
0
		/// <summary>
		///   Resolve the constraints - but only resolve things into Expression's, not
		///   into actual types.
		/// </summary>
		public bool Resolve (IResolveContext ec)
		{
			if (resolved)
				return true;

			iface_constraints = new ArrayList (2);	// TODO: Too expensive allocation
			type_param_constraints = new ArrayList ();

			foreach (object obj in constraints) {
				if (HasConstructorConstraint) {
					Report.Error (401, loc,
						      "The new() constraint must be the last constraint specified");
					return false;
				}

				if (obj is SpecialConstraint) {
					SpecialConstraint sc = (SpecialConstraint) obj;

					if (sc == SpecialConstraint.Constructor) {
						if (!HasValueTypeConstraint) {
							attrs |= GenericParameterAttributes.DefaultConstructorConstraint;
							continue;
						}

						Report.Error (451, loc, "The `new()' constraint " +
							"cannot be used with the `struct' constraint");
						return false;
					}

					if ((num_constraints > 0) || HasReferenceTypeConstraint || HasValueTypeConstraint) {
						Report.Error (449, loc, "The `class' or `struct' " +
							      "constraint must be the first constraint specified");
						return false;
					}

					if (sc == SpecialConstraint.ReferenceType)
						attrs |= GenericParameterAttributes.ReferenceTypeConstraint;
					else
						attrs |= GenericParameterAttributes.NotNullableValueTypeConstraint;
					continue;
				}

				int errors = Report.Errors;
				FullNamedExpression fn = ((Expression) obj).ResolveAsTypeStep (ec, false);

				if (fn == null) {
					if (errors != Report.Errors)
						return false;

					NamespaceEntry.Error_NamespaceNotFound (loc, ((Expression)obj).GetSignatureForError ());
					return false;
				}

				TypeExpr expr;
				GenericTypeExpr cexpr = fn as GenericTypeExpr;
				if (cexpr != null) {
					expr = cexpr.ResolveAsBaseTerminal (ec, false);
				} else
					expr = ((Expression) obj).ResolveAsTypeTerminal (ec, false);

				if ((expr == null) || (expr.Type == null))
					return false;

				if (!ec.GenericDeclContainer.IsAccessibleAs (fn.Type)) {
					Report.SymbolRelatedToPreviousError (fn.Type);
					Report.Error (703, loc,
						"Inconsistent accessibility: constraint type `{0}' is less accessible than `{1}'",
						fn.GetSignatureForError (), ec.GenericDeclContainer.GetSignatureForError ());
					return false;
				}

				TypeParameterExpr texpr = expr as TypeParameterExpr;
				if (texpr != null)
					type_param_constraints.Add (expr);
				else if (expr.IsInterface)
					iface_constraints.Add (expr);
				else if (class_constraint != null || iface_constraints.Count != 0) {
					Report.Error (406, loc,
						"The class type constraint `{0}' must be listed before any other constraints. Consider moving type constraint to the beginning of the constraint list",
						expr.GetSignatureForError ());
					return false;
				} else if (HasReferenceTypeConstraint || HasValueTypeConstraint) {
					Report.Error (450, loc, "`{0}': cannot specify both " +
						      "a constraint class and the `class' " +
						      "or `struct' constraint", expr.GetSignatureForError ());
					return false;
				} else
					class_constraint = expr;

				num_constraints++;
			}

			ArrayList list = new ArrayList ();
			foreach (TypeExpr iface_constraint in iface_constraints) {
				foreach (Type type in list) {
					if (!type.Equals (iface_constraint.Type))
						continue;

					Report.Error (405, loc,
						      "Duplicate constraint `{0}' for type " +
						      "parameter `{1}'.", iface_constraint.GetSignatureForError (),
						      name);
					return false;
				}

				list.Add (iface_constraint.Type);
			}

			foreach (TypeParameterExpr expr in type_param_constraints) {
				foreach (Type type in list) {
					if (!type.Equals (expr.Type))
						continue;

					Report.Error (405, loc,
						      "Duplicate constraint `{0}' for type " +
						      "parameter `{1}'.", expr.GetSignatureForError (), name);
					return false;
				}

				list.Add (expr.Type);
			}

			iface_constraint_types = new Type [list.Count];
			list.CopyTo (iface_constraint_types, 0);

			if (class_constraint != null) {
				class_constraint_type = class_constraint.Type;
				if (class_constraint_type == null)
					return false;

				if (class_constraint_type.IsSealed) {
					if (class_constraint_type.IsAbstract)
					{
						Report.Error (717, loc, "`{0}' is not a valid constraint. Static classes cannot be used as constraints",
							TypeManager.CSharpName (class_constraint_type));
					}
					else
					{
						Report.Error (701, loc, "`{0}' is not a valid constraint. A constraint must be an interface, " +
							"a non-sealed class or a type parameter", TypeManager.CSharpName(class_constraint_type));
					}
					return false;
				}

				if ((class_constraint_type == TypeManager.array_type) ||
				    (class_constraint_type == TypeManager.delegate_type) ||
				    (class_constraint_type == TypeManager.enum_type) ||
				    (class_constraint_type == TypeManager.value_type) ||
				    (class_constraint_type == TypeManager.object_type) ||
					class_constraint_type == TypeManager.multicast_delegate_type) {
					Report.Error (702, loc,
							  "A constraint cannot be special class `{0}'",
						      TypeManager.CSharpName (class_constraint_type));
					return false;
				}
			}

			if (class_constraint_type != null)
				effective_base_type = class_constraint_type;
			else if (HasValueTypeConstraint)
				effective_base_type = TypeManager.value_type;
			else
				effective_base_type = TypeManager.object_type;

			if ((attrs & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0)
				attrs |= GenericParameterAttributes.DefaultConstructorConstraint;

			resolved = true;
			return true;
		}
Ejemplo n.º 13
0
        TypeExpr[] GetNormalPartialBases(ref TypeExpr base_class)
        {
            var ifaces = new List<TypeExpr> (0);
            if (iface_exprs != null)
                ifaces.AddRange (iface_exprs);

            foreach (TypeContainer part in partial_parts) {
                TypeExpr new_base_class;
                TypeExpr[] new_ifaces = part.ResolveBaseTypes (out new_base_class);
                if (new_base_class != TypeManager.system_object_expr) {
                    if (base_class == TypeManager.system_object_expr)
                        base_class = new_base_class;
                    else {
                        if (new_base_class != null && !TypeManager.IsEqual (new_base_class.Type, base_class.Type)) {
                            Report.SymbolRelatedToPreviousError (base_class.Location, "");
                            Report.Error (263, part.Location,
                                "Partial declarations of `{0}' must not specify different base classes",
                                part.GetSignatureForError ());

                            return null;
                        }
                    }
                }

                if (new_ifaces == null)
                    continue;

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

                    ifaces.Add (iface);
                }
            }

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

            return ifaces.ToArray ();
        }
Ejemplo n.º 14
0
        bool DefineBaseTypes()
        {
            iface_exprs = ResolveBaseTypes (out base_type);
            if (partial_parts != null) {
                iface_exprs = GetNormalPartialBases (ref base_type);
            }

            var cycle = CheckRecursiveDefinition (this);
            if (cycle != null) {
                Report.SymbolRelatedToPreviousError (cycle);
                if (this is Interface) {
                    Report.Error (529, Location,
                        "Inherited interface `{0}' causes a cycle in the interface hierarchy of `{1}'",
                        GetSignatureForError (), cycle.GetSignatureForError ());
                } else {
                    Report.Error (146, Location,
                        "Circular base class dependency involving `{0}' and `{1}'",
                        GetSignatureForError (), cycle.GetSignatureForError ());
                }

                base_type = null;
            }

            if (iface_exprs != null) {
                foreach (TypeExpr iface in iface_exprs) {
                    // Prevents a crash, the interface might not have been resolved: 442144
                    if (iface == null)
                        continue;

                    var iface_type = iface.Type;

                    if (!spec.AddInterface (iface_type))
                        continue;

                    if (iface_type.IsGeneric && spec.Interfaces != null) {
                        foreach (var prev_iface in iface_exprs) {
                            if (prev_iface == iface)
                                break;

                            if (!TypeSpecComparer.Unify.IsEqual (iface_type, prev_iface.Type))
                                continue;

                            Report.Error (695, Location,
                                "`{0}' cannot implement both `{1}' and `{2}' because they may unify for some type parameter substitutions",
                                GetSignatureForError (), prev_iface.GetSignatureForError (), iface_type.GetSignatureForError ());
                        }
                    }

                    TypeBuilder.AddInterfaceImplementation (iface_type.GetMetaInfo ());

                    // Ensure the base is always setup
                    var compiled_iface = iface_type.MemberDefinition as Interface;
                    if (compiled_iface != null) {
                        // TODO: Need DefineBaseType only
                        compiled_iface.DefineType ();
                    }

                    if (iface_type.Interfaces != null) {
                        var base_ifaces = new List<TypeSpec> (iface_type.Interfaces);
                        for (int i = 0; i < base_ifaces.Count; ++i) {
                            var ii_iface_type = base_ifaces[i];
                            if (spec.AddInterface (ii_iface_type)) {
                                TypeBuilder.AddInterfaceImplementation (ii_iface_type.GetMetaInfo ());

                                if (ii_iface_type.Interfaces != null)
                                    base_ifaces.AddRange (ii_iface_type.Interfaces);
                            }
                        }
                    }
                }
            }

            if (Kind == MemberKind.Interface) {
                spec.BaseType = TypeManager.object_type;
                return true;
            }

            TypeSpec base_ts;
            if (base_type != null)
                base_ts = base_type.Type;
            else if (spec.IsStruct)
                base_ts = TypeManager.value_type;
            else if (spec.IsEnum)
                base_ts = TypeManager.enum_type;
            else if (spec.IsDelegate)
                base_ts = TypeManager.multicast_delegate_type;
            else
                base_ts = null;

            if (base_ts != null) {
                spec.BaseType = base_ts;

                // Set base type after type creation
                TypeBuilder.SetParent (base_ts.GetMetaInfo ());
            }

            return true;
        }
Ejemplo n.º 15
0
 protected override TypeExpr[] ResolveBaseTypes(out TypeExpr base_class)
 {
     TypeExpr[] ifaces = base.ResolveBaseTypes (out base_class);
     base_class = TypeManager.system_valuetype_expr;
     return ifaces;
 }
Ejemplo n.º 16
0
		public LocalInfo AddTemporaryVariable (TypeExpr te, Location loc)
		{
			Report.Debug (64, "ADD TEMPORARY", this, Toplevel, loc);

			if (temporary_variables == null)
				temporary_variables = new List<LocalInfo> ();

			int id = ++next_temp_id;
			string name = "$s_" + id.ToString ();

			LocalInfo li = new LocalInfo (te, name, this, loc);
			li.CompilerGenerated = true;
			temporary_variables.Add (li);
			return li;
		}
Ejemplo n.º 17
0
		protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
		{
			base_type = TypeManager.enum_type;
			base_class = base_type_expr;
			return null;
		}
Ejemplo n.º 18
0
		protected override TypeExpr [] ResolveBaseTypes (out TypeExpr base_class)
		{
			var mtype = Iterator.OriginalIteratorType;
			if (Mutator != null)
				mtype = Mutator.Mutate (mtype);

			iterator_type_expr = new TypeExpression (mtype, Location);
			generic_args = new TypeArguments (iterator_type_expr);

			var list = new List<FullNamedExpression> ();
			if (Iterator.IsEnumerable) {
				enumerable_type = new TypeExpression (Compiler.BuiltinTypes.IEnumerable, Location);
				list.Add (enumerable_type);

				if (Module.PredefinedTypes.IEnumerableGeneric.Define ()) {
					generic_enumerable_type = new GenericTypeExpr (Module.PredefinedTypes.IEnumerableGeneric.TypeSpec, generic_args, Location);
					list.Add (generic_enumerable_type);
				}
			}

			enumerator_type = new TypeExpression (Compiler.BuiltinTypes.IEnumerator, Location);
			list.Add (enumerator_type);

			list.Add (new TypeExpression (Compiler.BuiltinTypes.IDisposable, Location));

			var ienumerator_generic = Module.PredefinedTypes.IEnumeratorGeneric;
			if (ienumerator_generic.Define ()) {
				generic_enumerator_type = new GenericTypeExpr (ienumerator_generic.TypeSpec, generic_args, Location);
				list.Add (generic_enumerator_type);
			}

			type_bases = list;

			return base.ResolveBaseTypes (out base_class);
		}
Ejemplo n.º 19
0
		//
		// System.Linq.Expressions.ParameterExpression type
		//
		public static TypeExpr ResolveParameterExpressionType (IMemberContext ec, Location location)
		{
			if (parameter_expr_tree_type != null)
				return parameter_expr_tree_type;

			TypeSpec p_type = TypeManager.parameter_expression_type;
			if (p_type == null) {
				p_type = TypeManager.CoreLookupType (ec.Compiler, "System.Linq.Expressions", "ParameterExpression", MemberKind.Class, true);
				TypeManager.parameter_expression_type = p_type;
			}

			parameter_expr_tree_type = new TypeExpression (p_type, location).
				ResolveAsTypeTerminal (ec, false);

			return parameter_expr_tree_type;
		}
Ejemplo n.º 20
0
		//
		// System.Linq.Expressions.ParameterExpression type
		//
		public static TypeExpr ResolveParameterExpressionType (IMemberContext ec, Location location)
		{
			if (parameter_expr_tree_type != null)
				return parameter_expr_tree_type;

			TypeSpec p_type = ec.Module.PredefinedTypes.ParameterExpression.Resolve (location);
			parameter_expr_tree_type = new TypeExpression (p_type, location).
				ResolveAsTypeTerminal (ec, false);

			return parameter_expr_tree_type;
		}
Ejemplo n.º 21
0
		protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
		{
			base_type = TypeManager.multicast_delegate_type;
			base_class = null;
			return null;
		}
Ejemplo n.º 22
0
		protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
		{
			base_type = Compiler.BuiltinTypes.MulticastDelegate;
			base_class = null;
			return null;
		}
Ejemplo n.º 23
0
	static public void Reset ()
	{
//		object_type = null;
	
		assembly_internals_vis_attrs = new Dictionary<Assembly, bool> ();
		
		// TODO: I am really bored by all this static stuff
		system_type_get_type_from_handle =
		bool_movenext_void =
		void_dispose_void =
		void_monitor_enter_object =
		void_monitor_exit_object =
		void_initializearray_array_fieldhandle =
		int_interlocked_compare_exchange =
		methodbase_get_type_from_handle =
		methodbase_get_type_from_handle_generic =
		fieldinfo_get_field_from_handle =
		fieldinfo_get_field_from_handle_generic =
		activator_create_instance =
		delegate_combine_delegate_delegate =
		delegate_remove_delegate_delegate = null;

		int_get_offset_to_string_data =
		ienumerator_getcurrent = null;

		void_decimal_ctor_five_args =
		void_decimal_ctor_int_arg =
		void_decimal_ctor_long_arg = null;

		string_empty = null;

		call_site_type =
		generic_call_site_type =
		binder_flags = null;

		binder_type = null;

		typed_reference_type = arg_iterator_type = mbr_type =
		runtime_helpers_type = iasyncresult_type = asynccallback_type =
		runtime_argument_handle_type = void_ptr_type = isvolatile_type =
		generic_ilist_type = generic_icollection_type = generic_ienumerator_type =
		generic_ienumerable_type = generic_nullable_type = expression_type =
		parameter_expression_type = fieldinfo_type = methodinfo_type = ctorinfo_type = null;

		expression_type_expr = null;
	}
Ejemplo n.º 24
0
		protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
		{
			base_type = Compiler.BuiltinTypes.Enum;
			base_class = base_type_expr;
			return null;
		}
Ejemplo n.º 25
0
		protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
		{
			TypeExpr[] ifaces = base.ResolveBaseTypes (out base_class);
			base_type = TypeManager.value_type;
			return ifaces;
		}
Ejemplo n.º 26
0
		protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
		{
			TypeExpr[] 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 (IsGeneric && base_type.IsAttribute) {
					Report.Error (698, base_class.Location,
						"A generic type cannot derive from `{0}' because it is an attribute class",
						base_class.GetSignatureForError ());
				} else if (base_type.IsStatic) {
					Report.SymbolRelatedToPreviousError (base_class.Type);
					Report.Error (709, Location, "`{0}': Cannot derive from static class `{1}'",
						GetSignatureForError (), base_type.GetSignatureForError ());
				} else if (base_type.IsSealed) {
					Report.SymbolRelatedToPreviousError (base_class.Type);
					Report.Error (509, Location, "`{0}': cannot derive from sealed type `{1}'",
						GetSignatureForError (), base_type.GetSignatureForError ());
				} else if (PartialContainer.IsStatic && base_class.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_class.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 (TypeExpr t in ifaces)
					Report.SymbolRelatedToPreviousError (t.Type);
				Report.Error (714, Location, "Static class `{0}' cannot implement interfaces", GetSignatureForError ());
			}

			return ifaces;
		}
Ejemplo n.º 27
0
		TypeExpr[] GetNormalPartialBases ()
		{
			var ifaces = new List<TypeExpr> (0);
			if (iface_exprs != null)
				ifaces.AddRange (iface_exprs);

			foreach (TypeContainer part in partial_parts) {
				TypeExpr new_base_class;
				TypeExpr[] new_ifaces = part.ResolveBaseTypes (out new_base_class);
				if (new_base_class != null) {
					if (base_type_expr != null && new_base_class.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 = base_type_expr.Type;
					}
				}

				if (new_ifaces == null)
					continue;

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

					ifaces.Add (iface);
				}
			}

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

			return ifaces.ToArray ();
		}
Ejemplo n.º 28
0
		protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
		{
			TypeExpr[] ifaces = base.ResolveBaseTypes (out base_class);
			base_type = Compiler.BuiltinTypes.ValueType;
			return ifaces;
		}
Ejemplo n.º 29
0
			public AnonymousMethodMethod (TypeDefinition parent, AnonymousExpression am, AnonymousMethodStorey storey,
							  TypeExpr return_type,
							  Modifiers mod, MemberName name,
							  ParametersCompiled parameters)
				: base (parent, return_type, mod | Modifiers.COMPILER_GENERATED,
						name, parameters, null)
			{
				this.AnonymousMethod = am;
				this.Storey = storey;

				Parent.PartialContainer.Members.Add (this);
				Block = new ToplevelBlock (am.block, parameters);
			}
Ejemplo n.º 30
0
		protected override TypeExpr [] ResolveBaseTypes (out TypeExpr base_class)
		{
			iterator_type_expr = new TypeExpression (MutateType (Iterator.OriginalIteratorType), Location);

#if GMCS_SOURCE
			generic_args = new TypeArguments (iterator_type_expr);
#endif

			ArrayList list = new ArrayList ();
			if (Iterator.IsEnumerable) {
				enumerable_type = new TypeExpression (
					TypeManager.ienumerable_type, Location);
				list.Add (enumerable_type);

#if GMCS_SOURCE
				generic_enumerable_type = new GenericTypeExpr (
					TypeManager.generic_ienumerable_type,
					generic_args, Location);
				list.Add (generic_enumerable_type);
#endif
			}

			enumerator_type = new TypeExpression (
				TypeManager.ienumerator_type, Location);
			list.Add (enumerator_type);

			list.Add (new TypeExpression (TypeManager.idisposable_type, Location));

#if GMCS_SOURCE
			generic_enumerator_type = new GenericTypeExpr (
				TypeManager.generic_ienumerator_type,
				generic_args, Location);
			list.Add (generic_enumerator_type);
#endif

			type_bases = list;

			return base.ResolveBaseTypes (out base_class);
		}