ArrayList type_bases;
- // Attributes for this type
- protected Attributes attributes;
-
// Information in the case we are an attribute type
public AttributeTargets Targets = AttributeTargets.All;
public bool Inherited;
// The interfaces we implement.
- Type [] ifaces;
+ TypeExpr [] ifaces;
// The parent member container and our member cache
IMemberContainer parent_container;
//
public string IndexerName;
- public TypeContainer (TypeContainer parent, string name, Location l)
- : base (parent, name, l)
+ Type GenericType;
+
+ public TypeContainer ():
+ this (null, null, "", null, new Location (-1)) {
+ }
+
+ public TypeContainer (NamespaceEntry ns, TypeContainer parent, string name, Attributes attrs, Location l)
+ : base (ns, parent, name, attrs, l)
{
- string n;
types = new ArrayList ();
- if (parent == null)
- n = "";
- else
- n = parent.Name;
-
base_class_name = null;
-
- //Console.WriteLine ("New class " + name + " inside " + n);
}
public AdditionResult AddConstant (Const constant)
if (methods == null)
methods = new ArrayList ();
- if (method.Name.IndexOf (".") != -1)
+ if (method.Name.IndexOf ('.') != -1)
methods.Insert (0, method);
else
methods.Add (method);
public AdditionResult AddProperty (Property prop)
{
AdditionResult res;
- string basename = prop.Name;
- string fullname = Name + "." + basename;
- if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
+ if ((res = AddProperty (prop, prop.Name)) != AdditionResult.Success)
+ return res;
+
+ if (prop.Get != null) {
+ if ((res = AddProperty (prop, "get_" + prop.Name)) != AdditionResult.Success)
+ return res;
+ }
+
+ if (prop.Set != null) {
+ if ((res = AddProperty (prop, "set_" + prop.Name)) != AdditionResult.Success)
return res;
+ }
if (properties == null)
properties = new ArrayList ();
- if (prop.Name.IndexOf (".") != -1)
+ if (prop.Name.IndexOf ('.') != -1)
properties.Insert (0, prop);
else
properties.Add (prop);
+
+ return AdditionResult.Success;
+ }
+
+ AdditionResult AddProperty (Property prop, string basename)
+ {
+ AdditionResult res;
+ string fullname = Name + "." + basename;
+
+ if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
+ return res;
+
DefineName (fullname, prop);
return AdditionResult.Success;
return AdditionResult.Success;
}
- public AdditionResult AddIndexer (Indexer i)
+ public void AddIndexer (Indexer i)
{
if (indexers == null)
indexers = new ArrayList ();
indexers.Insert (0, i);
else
indexers.Add (i);
-
- return AdditionResult.Success;
}
public AdditionResult AddOperator (Operator op)
operators.Add (op);
+ string basename = op.Name;
+ string fullname = Name + "." + basename;
+ if (!defined_names.Contains (fullname))
+ {
+ DefineName (fullname, op);
+ }
return AdditionResult.Success;
}
}
}
- public Attributes OptAttributes {
- get {
- return attributes;
- }
- }
-
public bool HaveStaticConstructor {
get {
return have_static_constructor;
public bool EmitFieldInitializers (EmitContext ec)
{
ArrayList fields;
- ILGenerator ig = ec.ig;
Expression instance_expr;
if (ec.IsStatic){
void DefineDefaultConstructor (bool is_static)
{
Constructor c;
- int mods = 0;
- c = new Constructor (Basename, Parameters.EmptyReadOnlyParameters,
+ // The default constructor is public
+ // If the class is abstract, the default constructor is protected
+ // The default static constructor is private
+
+ int mods = Modifiers.PUBLIC;
+ if (is_static)
+ mods = Modifiers.STATIC | Modifiers.PRIVATE;
+ else if ((ModFlags & Modifiers.ABSTRACT) != 0)
+ mods = Modifiers.PROTECTED;
+
+ c = new Constructor (this, Basename, mods, Parameters.EmptyReadOnlyParameters,
new ConstructorBaseInitializer (
null, Parameters.EmptyReadOnlyParameters,
Location),
Location);
- if (is_static)
- mods = Modifiers.STATIC;
-
- c.ModFlags = mods;
-
AddConstructor (c);
- c.Block = new Block (null);
+ c.Block = new ToplevelBlock (null, Location);
}
void Error_TypeParameterAsBase (TypeParameterExpr e)
{
Report.Error (
- -213, e.Location,
+ -216, e.Location,
String.Format ("Type parameter `{0}' can not be used t as a base class or interface", e.Name));
}
/// The @parent argument is set to the parent object or null
/// if this is `System.Object'.
/// </summary>
- Type [] GetClassBases (bool is_class, out Type parent, out bool error)
+ TypeExpr [] GetClassBases (bool is_class, out TypeExpr parent, out bool error)
{
ArrayList bases = Bases;
int count;
if (is_class)
parent = null;
else
- parent = TypeManager.value_type;
+ parent = TypeManager.system_valuetype_expr;
if (bases == null){
if (is_class){
if (RootContext.StdLib)
- parent = TypeManager.object_type;
+ parent = TypeManager.system_object_expr;
else if (Name != "System.Object")
- parent = TypeManager.object_type;
+ parent = TypeManager.system_object_expr;
} else {
//
// If we are compiling our runtime,
// parent is `System.Object'.
//
if (!RootContext.StdLib && Name == "System.ValueType")
- parent = TypeManager.object_type;
+ parent = TypeManager.system_object_expr;
}
return null;
count = bases.Count;
if (is_class){
- Expression name = (Expression) bases [0];
- name = ResolveTypeExpr (name, false, Location);
+ TypeExpr name = ResolveTypeExpr ((Expression) bases [0], false, Location);
if (name == null){
error = true;
return null;
}
- Type first = name.Type;
-
- if (first.IsClass){
- parent = first;
+ if (name.IsClass){
+ parent = name;
start = 1;
} else {
- parent = TypeManager.object_type;
+ parent = TypeManager.system_object_expr;
start = 0;
}
- if (first.IsSealed){
+ if (name.IsSealed){
string detail = "";
- if (first.IsValueType)
+ if (name.IsValueType)
detail = " (a class can not inherit from a struct/enum)";
Report.Error (509, "class `"+ Name +
"': Cannot inherit from sealed class `"+
- first + "'" + detail);
+ name.Name + "'" + detail);
+ error = true;
+ return null;
+ }
+
+ if (!parent.CanInheritFrom ()){
+ Report.Error (644, Location,
+ "`{0}' cannot inherit from special class `{1}'",
+ Name, parent.Name);
error = true;
return null;
}
- if (!AsAccessible (parent, ModFlags))
+ if (!parent.AsAccessible (this, ModFlags))
Report.Error (60, Location,
"Inconsistent accessibility: base class `" +
- TypeManager.CSharpName (parent) + "' is less " +
- "accessible than class `" +
+ name.Name + "' is less accessible than class `" +
Name + "'");
} else {
if (parent != null)
base_class_name = parent.Name;
- Type [] ifaces = new Type [count-start];
+ TypeExpr [] ifaces = new TypeExpr [count-start];
for (i = start, j = 0; i < count; i++, j++){
Expression name = (Expression) bases [i];
- Expression resolved = ResolveTypeExpr (name, false, Location);
+ TypeExpr resolved = ResolveTypeExpr (name, false, Location);
if (resolved == null)
return null;
bases [i] = resolved;
- Type t = resolved.Type;
- if (t == null){
- error = true;
- return null;
- }
-
- if (is_class == false && !t.IsInterface){
+ if (is_class == false && !resolved.IsInterface){
Report.Error (527, "In Struct `" + Name + "', type `"+
name +"' is not an interface");
error = true;
return null;
}
- if (t.IsClass) {
+ if (resolved.IsClass) {
if (parent != null){
Report.Error (527, "In Class `" + Name + "', type `"+
name+"' is not an interface");
}
for (int x = 0; x < j; x++) {
- if (t == ifaces [x]) {
+ if (resolved == ifaces [x]) {
Report.Error (528, "`" + name + "' is already listed in interface list");
error = true;
return null;
}
}
- ifaces [j] = t;
+ ifaces [j] = resolved;
}
return TypeManager.ExpandInterfaces (ifaces);
}
+
+ bool error = false;
//
// Defines the type in the appropriate ModuleBuilder or TypeBuilder.
//
public override TypeBuilder DefineType ()
{
- Type parent;
- bool error;
+ TypeExpr parent;
bool is_class;
if (TypeBuilder != null)
return TypeBuilder;
+
+ if (error)
+ return null;
- if (InTransit)
+ if (InTransit) {
+ Report.Error (146, Location, "Class definition is circular: `{0}'", Name);
+ error = true;
return null;
+ }
InTransit = true;
if (error)
return null;
- if (is_class && parent != null){
- if (parent == TypeManager.enum_type ||
- (parent == TypeManager.value_type && RootContext.StdLib) ||
- parent == TypeManager.delegate_type ||
- parent == TypeManager.array_type){
- Report.Error (
- 644, Location, "`" + Name + "' cannot inherit from " +
- "special class `" + TypeManager.CSharpName (parent) + "'");
- return null;
- }
- }
-
- if (IsGeneric && (parent == TypeManager.attribute_type ||
- parent.IsSubclassOf (TypeManager.attribute_type))){
- Report.Error (-214, Location, "Generic type can not derive from Attribute");
- return null;
+ if (IsGeneric) {
+ foreach (TypeParameter type_param in TypeParameters)
+ if (!type_param.Resolve (this)) {
+ error = true;
+ return null;
+ }
}
if (!is_class && TypeManager.value_type == null)
TypeAttributes type_attributes = TypeAttr;
- // if (parent_builder is ModuleBuilder) {
+ Type ptype;
+ ConstructedType constructed = parent as ConstructedType;
+ if ((constructed == null) && (parent != null))
+ ptype = parent.ResolveType (ec);
+ else
+ ptype = null;
+
if (IsTopLevel){
- if (TypeManager.NamespaceClash (Name, Location))
+ if (TypeManager.NamespaceClash (Name, Location)) {
+ error = true;
return null;
-
- ModuleBuilder builder = CodeGen.ModuleBuilder;
+ }
+
+ ModuleBuilder builder = CodeGen.Module.Builder;
TypeBuilder = builder.DefineType (
- Name, type_attributes, parent, ifaces);
+ Name, type_attributes, ptype, null);
} else {
- TypeBuilder builder = Parent.TypeBuilder;
+ TypeBuilder builder = Parent.DefineType ();
+ if (builder == null)
+ return null;
+
TypeBuilder = builder.DefineNestedType (
- Basename, type_attributes, parent, ifaces);
+ Basename, type_attributes, ptype, null);
}
-
+
+ if (IsGeneric) {
+ CurrentType = new ConstructedType (
+ Name, CurrentTypeParameters, Location);
+
+ foreach (TypeParameter type_param in TypeParameters)
+ type_param.Define (TypeBuilder);
+ }
+
+ if (constructed != null) {
+ ptype = constructed.ResolveType (ec);
+ if (ptype == null)
+ return null;
+
+ TypeBuilder.SetParent (ptype);
+ }
+
+ if (IsGeneric) {
+ foreach (TypeParameter type_param in TypeParameters)
+ type_param.DefineType (ec, TypeBuilder);
+ }
+
//
// Structs with no fields need to have at least one byte.
// The right thing would be to set the PackingSize in a DefineType
if (!is_class && !have_nonstatic_fields){
TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
FieldAttributes.Private);
- // add interfaces that were not added at type creation
- if (ifaces != null) {
- foreach (Type i in ifaces)
- TypeBuilder.AddInterfaceImplementation (i);
+ }
+
+ // add interfaces that were not added at type creation
+ if (ifaces != null) {
+ foreach (TypeExpr iface in ifaces) {
+ Type itype = iface.ResolveType (ec);
+ TypeBuilder.AddInterfaceImplementation (itype);
}
}
TypeManager.AddUserType (Name, TypeBuilder, this, ifaces);
- if ((parent != null) &&
- (parent == TypeManager.attribute_type ||
- parent.IsSubclassOf (TypeManager.attribute_type))) {
+ if ((parent != null) && parent.IsAttribute) {
RootContext.RegisterAttribute (this);
TypeManager.RegisterAttrType (TypeBuilder, this);
} else
if (Interfaces != null) {
foreach (Interface iface in Interfaces)
- iface.DefineType ();
+ if (iface.DefineType () == null) {
+ error = true;
+ return null;
+ }
}
if (Types != null) {
foreach (TypeContainer tc in Types)
- tc.DefineType ();
+ if (tc.DefineType () == null) {
+ error = true;
+ return null;
+ }
}
if (Delegates != null) {
foreach (Delegate d in Delegates)
- d.DefineType ();
+ if (d.DefineType () == null) {
+ error = true;
+ return null;
+ }
}
if (Enums != null) {
foreach (Enum en in Enums)
- en.DefineType ();
+ if (en.DefineType () == null) {
+ error = true;
+ return null;
+ }
}
InTransit = false;
if (idx < 0){
if (RootContext.WarningLevel >= 4){
if ((mc.ModFlags & Modifiers.NEW) != 0)
- Warning_KewywordNewNotRequired (mc.Location, mc);
+ Warning_KeywordNewNotRequired (mc.Location, mc);
}
} else if (mc is MethodCore)
((MethodCore) mc).OverridesSomething = true;
Type ptype = null;
Type t = pclass.TypeBuilder.BaseType;
while ((t != null) && (ptype == null)) {
- pname = MakeFQN (t.FullName, Basename);
+ pname = t.FullName + "." + Basename;
ptype = RootContext.LookupType (this, pname, true, Location.Null);
t = t.BaseType;
}
if (fields != null)
DefineMembers (fields, defined_names);
- if ((RootContext.WarningLevel >= 4) && (fields != null)) {
- foreach (Field f in fields) {
- if (((f.ModFlags & Modifiers.READONLY) != 0) && !f.IsAssigned)
- Report.Warning (649, "Field `" + MakeFQN (Name, f.Name) + "; is never " +
- "assigned and will ever have its default value");
- }
- }
-
if (this is Class){
if (instance_constructors == null){
if (default_constructor == null)
if (delegates != null)
DefineMembers (delegates, defined_names);
+ if (CurrentType != null) {
+ GenericType = CurrentType.ResolveType (ec);
+
+ ec.ContainerType = GenericType;
+ }
+
+
#if CACHE
if (TypeBuilder.BaseType != null)
parent_container = TypeManager.LookupMemberContainer (TypeBuilder.BaseType);
public override MemberList FindMembers (MemberTypes mt, BindingFlags bf,
MemberFilter filter, object criteria)
{
- ArrayList members = new ArrayList ();
+ ArrayList members = null;
int modflags = 0;
if ((bf & BindingFlags.Public) != 0)
if ((mt & MemberTypes.Field) != 0) {
if (fields != null) {
- foreach (Field f in fields) {
+ int len = fields.Count;
+ for (int i = 0; i < len; i++) {
+ Field f = (Field) fields [i];
+
if ((f.ModFlags & modflags) == 0)
continue;
if ((f.ModFlags & static_mask) != static_flags)
continue;
FieldBuilder fb = f.FieldBuilder;
- if (fb != null && filter (fb, criteria) == true)
+ if (fb != null && filter (fb, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (fb);
}
}
+ }
if (constants != null) {
- foreach (Const con in constants) {
+ int len = constants.Count;
+ for (int i = 0; i < len; i++) {
+ Const con = (Const) constants [i];
+
if ((con.ModFlags & modflags) == 0)
continue;
if ((con.ModFlags & static_mask) != static_flags)
continue;
FieldBuilder fb = con.FieldBuilder;
- if (fb != null && filter (fb, criteria) == true)
+ if (fb != null && filter (fb, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (fb);
}
}
}
+ }
if ((mt & MemberTypes.Method) != 0) {
if (methods != null) {
- foreach (Method m in methods) {
+ int len = methods.Count;
+ for (int i = 0; i < len; i++) {
+ Method m = (Method) methods [i];
+
if ((m.ModFlags & modflags) == 0)
continue;
if ((m.ModFlags & static_mask) != static_flags)
MethodBuilder mb = m.MethodBuilder;
- if (mb != null && filter (mb, criteria) == true)
+ if (mb != null && filter (mb, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (mb);
}
}
+ }
+
+ if (operators != null) {
+ int len = operators.Count;
+ for (int i = 0; i < len; i++) {
+ Operator o = (Operator) operators [i];
- if (operators != null){
- foreach (Operator o in operators) {
if ((o.ModFlags & modflags) == 0)
continue;
if ((o.ModFlags & static_mask) != static_flags)
continue;
MethodBuilder ob = o.OperatorMethodBuilder;
- if (ob != null && filter (ob, criteria) == true)
+ if (ob != null && filter (ob, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (ob);
}
}
+ }
+
+ if (properties != null) {
+ int len = properties.Count;
+ for (int i = 0; i < len; i++) {
+ Property p = (Property) properties [i];
- if (properties != null){
- foreach (Property p in properties){
if ((p.ModFlags & modflags) == 0)
continue;
if ((p.ModFlags & static_mask) != static_flags)
MethodBuilder b;
b = p.GetBuilder;
- if (b != null && filter (b, criteria) == true)
+ if (b != null && filter (b, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (b);
+ }
b = p.SetBuilder;
- if (b != null && filter (b, criteria) == true)
+ if (b != null && filter (b, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (b);
}
}
+ }
+
+ if (indexers != null) {
+ int len = indexers.Count;
+ for (int i = 0; i < len; i++) {
+ Indexer ix = (Indexer) indexers [i];
- if (indexers != null){
- foreach (Indexer ix in indexers){
if ((ix.ModFlags & modflags) == 0)
continue;
if ((ix.ModFlags & static_mask) != static_flags)
MethodBuilder b;
b = ix.GetBuilder;
- if (b != null && filter (b, criteria) == true)
+ if (b != null && filter (b, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (b);
+ }
b = ix.SetBuilder;
- if (b != null && filter (b, criteria) == true)
+ if (b != null && filter (b, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (b);
}
}
}
+ }
if ((mt & MemberTypes.Event) != 0) {
- if (events != null)
- foreach (Event e in events) {
+ if (events != null) {
+ int len = events.Count;
+ for (int i = 0; i < len; i++) {
+ Event e = (Event) events [i];
+
if ((e.ModFlags & modflags) == 0)
continue;
if ((e.ModFlags & static_mask) != static_flags)
continue;
MemberInfo eb = e.EventBuilder;
- if (eb != null && filter (eb, criteria) == true)
+ if (eb != null && filter (eb, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (e.EventBuilder);
}
}
+ }
+ }
if ((mt & MemberTypes.Property) != 0){
- if (properties != null)
- foreach (Property p in properties) {
+ if (properties != null) {
+ int len = properties.Count;
+ for (int i = 0; i < len; i++) {
+ Property p = (Property) properties [i];
+
if ((p.ModFlags & modflags) == 0)
continue;
if ((p.ModFlags & static_mask) != static_flags)
MemberInfo pb = p.PropertyBuilder;
if (pb != null && filter (pb, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (p.PropertyBuilder);
}
}
+ }
+
+ if (indexers != null) {
+ int len = indexers.Count;
+ for (int i = 0; i < len; i++) {
+ Indexer ix = (Indexer) indexers [i];
- if (indexers != null)
- foreach (Indexer ix in indexers) {
if ((ix.ModFlags & modflags) == 0)
continue;
if ((ix.ModFlags & static_mask) != static_flags)
MemberInfo ib = ix.PropertyBuilder;
if (ib != null && filter (ib, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (ix.PropertyBuilder);
}
}
}
+ }
if ((mt & MemberTypes.NestedType) != 0) {
- if (types != null){
- foreach (TypeContainer t in types) {
+ if (types != null) {
+ int len = types.Count;
+ for (int i = 0; i < len; i++) {
+ TypeContainer t = (TypeContainer) types [i];
+
if ((t.ModFlags & modflags) == 0)
continue;
TypeBuilder tb = t.TypeBuilder;
- if (tb != null && (filter (tb, criteria) == true))
+ if (tb != null && (filter (tb, criteria) == true)) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (tb);
}
}
+ }
+
+ if (enums != null) {
+ int len = enums.Count;
+ for (int i = 0; i < len; i++) {
+ Enum en = (Enum) enums [i];
- if (enums != null){
- foreach (Enum en in enums){
if ((en.ModFlags & modflags) == 0)
continue;
TypeBuilder tb = en.TypeBuilder;
- if (tb != null && (filter (tb, criteria) == true))
+ if (tb != null && (filter (tb, criteria) == true)) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (tb);
}
}
+ }
+
+ if (delegates != null) {
+ int len = delegates.Count;
+ for (int i = 0; i < len; i++) {
+ Delegate d = (Delegate) delegates [i];
- if (delegates != null){
- foreach (Delegate d in delegates){
if ((d.ModFlags & modflags) == 0)
continue;
TypeBuilder tb = d.TypeBuilder;
- if (tb != null && (filter (tb, criteria) == true))
+ if (tb != null && (filter (tb, criteria) == true)) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (tb);
}
}
+ }
+
+ if (interfaces != null) {
+ int len = interfaces.Count;
+ for (int i = 0; i < len; i++) {
+ Interface iface = (Interface) interfaces [i];
- if (interfaces != null){
- foreach (Interface iface in interfaces){
if ((iface.ModFlags & modflags) == 0)
continue;
TypeBuilder tb = iface.TypeBuilder;
- if (tb != null && (filter (tb, criteria) == true))
+ if (tb != null && (filter (tb, criteria) == true)) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (tb);
}
}
}
+ }
if ((mt & MemberTypes.Constructor) != 0){
if (((bf & BindingFlags.Instance) != 0) && (instance_constructors != null)){
- foreach (Constructor c in instance_constructors){
+ int len = instance_constructors.Count;
+ for (int i = 0; i < len; i++) {
+ Constructor c = (Constructor) instance_constructors [i];
+
ConstructorBuilder cb = c.ConstructorBuilder;
- if (cb != null)
- if (filter (cb, criteria) == true)
+ if (cb != null && filter (cb, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (cb);
}
}
+ }
if (((bf & BindingFlags.Static) != 0) && (default_static_constructor != null)){
ConstructorBuilder cb =
default_static_constructor.ConstructorBuilder;
- if (cb != null)
- if (filter (cb, criteria) == true)
+ if (cb != null && filter (cb, criteria) == true) {
+ if (members == null)
+ members = new ArrayList ();
+
members.Add (cb);
}
}
+ }
//
// Lookup members in parent if requested.
//
if (((bf & BindingFlags.DeclaredOnly) == 0) && (TypeBuilder.BaseType != null)) {
MemberList list = FindMembers (TypeBuilder.BaseType, mt, bf, filter, criteria);
+ if (list.Count > 0) {
+ if (members == null)
+ members = new ArrayList ();
+
members.AddRange (list);
}
+ }
Timer.StopTimer (TimerType.TcFindMembers);
+ if (members == null)
+ return MemberList.Empty;
+ else
return new MemberList (members);
}
{
if (constants != null)
foreach (Const con in constants)
- con.EmitConstant (this);
+ con.Emit (this);
return;
}
if (RootContext.WarningLevel >= 3) {
if (fields != null){
foreach (Field f in fields) {
- if ((f.ModFlags & Modifiers.PUBLIC) != 0)
+ if ((f.ModFlags & Modifiers.Accessibility) != Modifiers.PRIVATE)
continue;
- if (f.status == 0){
+ if ((f.status & Field.Status.USED) == 0){
Report.Warning (
169, f.Location, "Private field " +
MakeName (f.Name) + " is never used");
public override void CloseType ()
{
+ if (Created)
+ return;
+
try {
- if (!Created){
Created = true;
TypeBuilder.CreateType ();
- }
} catch (TypeLoadException){
//
// This is fine, the code still created the type
if (Delegates != null)
foreach (Delegate d in Delegates)
d.CloseType ();
+
+ types = null;
+ properties = null;
+ enums = null;
+ delegates = null;
+ fields = null;
+ initialized_fields = null;
+ initialized_static_fields = null;
+ constants = null;
+ interfaces = null;
+ interface_order = null;
+ methods = null;
+ events = null;
+ indexers = null;
+ operators = null;
+ ec = null;
+ default_constructor = null;
+ default_static_constructor = null;
+ type_bases = null;
+ OptAttributes = null;
+ ifaces = null;
+ parent_container = null;
+ member_cache = null;
}
public string MakeName (string n)
mi.ReflectedType.Name + "." + mi.Name + "'");
}
- public void Warning_KewywordNewNotRequired (Location l, MemberCore mc)
+ public void Warning_KeywordNewNotRequired (Location l, MemberCore mc)
{
Report.Warning (
109, l, "The member " + MakeName (mc.Name) + " does not hide an " +
return ok;
}
- // Access level of a type.
- enum AccessLevel {
- Public = 0,
- ProtectedInternal = 1,
- Internal = 2,
- Protected = 3,
- Private = 4
- }
-
- // Check whether `flags' denotes a more restricted access than `level'
- // and return the new level.
- static AccessLevel CheckAccessLevel (AccessLevel level, int flags)
- {
- AccessLevel old_level = level;
-
- if ((flags & Modifiers.INTERNAL) != 0) {
- if ((flags & Modifiers.PROTECTED) != 0) {
- if ((int) level < (int) AccessLevel.ProtectedInternal)
- level = AccessLevel.ProtectedInternal;
- } else {
- if ((int) level < (int) AccessLevel.Internal)
- level = AccessLevel.Internal;
- }
- } else if ((flags & Modifiers.PROTECTED) != 0) {
- if ((int) level < (int) AccessLevel.Protected)
- level = AccessLevel.Protected;
- } else if ((flags & Modifiers.PRIVATE) != 0)
- level = AccessLevel.Private;
-
- return level;
- }
-
- // Return the access level for a new member which is defined in the current
- // TypeContainer with access modifiers `flags'.
- AccessLevel GetAccessLevel (int flags)
- {
- if ((flags & Modifiers.PRIVATE) != 0)
- return AccessLevel.Private;
-
- AccessLevel level;
- if (!IsTopLevel && (Parent != null))
- level = Parent.GetAccessLevel (flags);
- else
- level = AccessLevel.Public;
-
- return CheckAccessLevel (CheckAccessLevel (level, flags), ModFlags);
- }
-
- // Return the access level for type `t', but don't give more access than `flags'.
- static AccessLevel GetAccessLevel (Type t, int flags)
- {
- if (((flags & Modifiers.PRIVATE) != 0) || t.IsNestedPrivate)
- return AccessLevel.Private;
-
- AccessLevel level;
- if (TypeManager.IsBuiltinType (t))
- return AccessLevel.Public;
- else if ((t.DeclaringType != null) && (t != t.DeclaringType))
- level = GetAccessLevel (t.DeclaringType, flags);
- else {
- level = CheckAccessLevel (AccessLevel.Public, flags);
- }
-
- if (t.IsNestedPublic)
- return level;
-
- if (t.IsNestedAssembly || t.IsNotPublic) {
- if ((int) level < (int) AccessLevel.Internal)
- level = AccessLevel.Internal;
- }
-
- if (t.IsNestedFamily) {
- if ((int) level < (int) AccessLevel.Protected)
- level = AccessLevel.Protected;
- }
-
- if (t.IsNestedFamORAssem) {
- if ((int) level < (int) AccessLevel.ProtectedInternal)
- level = AccessLevel.ProtectedInternal;
- }
-
- return level;
- }
-
- //
- // Returns true if `parent' is as accessible as the flags `flags'
- // given for this member.
- //
- public bool AsAccessible (Type parent, int flags)
- {
- while (parent.IsArray || parent.IsPointer || parent.IsByRef)
- parent = TypeManager.GetElementType (parent);
-
- AccessLevel level = GetAccessLevel (flags);
- AccessLevel level2 = GetAccessLevel (parent, flags);
-
- return (int) level >= (int) level2;
- }
-
Hashtable builder_and_args;
public bool RegisterMethod (MethodBuilder mb, InternalParameters ip, Type [] args)
bool found = false;
if (ifaces != null){
- foreach (Type t in ifaces){
- if (t == interface_type){
+ foreach (TypeExpr t in ifaces){
+ if (t.Type == interface_type){
found = true;
break;
}
return true;
}
- public static void Error_ExplicitInterfaceNotMemberInterface (Location loc, string name)
- {
- Report.Error (539, loc, "Explicit implementation: `" + name + "' is not a member of the interface");
- }
-
//
// IMemberContainer
//
MemberList IMemberContainer.GetMembers (MemberTypes mt, BindingFlags bf)
{
- return FindMembers (mt, bf | BindingFlags.DeclaredOnly, null, null);
+ BindingFlags new_bf = bf | BindingFlags.DeclaredOnly;
+
+ if (GenericType != null)
+ return TypeManager.FindMembers (GenericType, mt, new_bf,
+ null, null);
+ else
+ return FindMembers (mt, new_bf, null, null);
}
//
Modifiers.SEALED |
Modifiers.UNSAFE;
- public Class (TypeContainer parent, string name, int mod, Attributes attrs, Location l)
- : base (parent, name, l)
+ public Class (NamespaceEntry ns, TypeContainer parent, string name, int mod, Attributes attrs, Location l)
+ : base (ns, parent, name, attrs, l)
{
int accmods;
accmods = Modifiers.PRIVATE;
this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
- this.attributes = attrs;
}
//
Modifiers.UNSAFE |
Modifiers.PRIVATE;
- public Struct (TypeContainer parent, string name, int mod, Attributes attrs, Location l)
- : base (parent, name, l)
+ public Struct (NamespaceEntry ns, TypeContainer parent, string name, int mod, Attributes attrs, Location l)
+ : base (ns, parent, name, attrs, l)
{
int accmods;
this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
this.ModFlags |= Modifiers.SEALED;
- this.attributes = attrs;
-
}
//
public abstract class MethodCore : MemberBase {
public readonly Parameters Parameters;
protected Block block;
+ protected DeclSpace ds;
//
// Parameters, cached for semantic analysis.
// </summary>
public bool OverridesSomething;
- public MethodCore (Expression type, int mod, int allowed_mod, string name,
- Attributes attrs, Parameters parameters, Location loc)
- : base (type, mod, allowed_mod, name, attrs, loc)
+ public MethodCore (DeclSpace ds, Expression type, int mod, int allowed_mod,
+ string name, Attributes attrs, Parameters parameters, Location loc)
+ : base (type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs, loc)
{
Parameters = parameters;
+ this.ds = ds;
}
//
}
}
- protected virtual bool DoDefineParameters (TypeContainer container)
+ protected virtual bool DoDefineParameters ()
{
// Check if arguments were correct
- parameter_types = Parameters.GetParameterInfo (container);
- if ((parameter_types == null) || !CheckParameters (container, parameter_types))
+ parameter_types = Parameters.GetParameterInfo (ds);
+ if ((parameter_types == null) || !CheckParameters (ds, parameter_types))
return false;
- parameter_info = new InternalParameters (container, Parameters);
+ parameter_info = new InternalParameters (ds, Parameters);
Parameter array_param = Parameters.ArrayParameter;
if ((array_param != null) &&
// The method's attributes are passed in because we need to extract
// the "return:" attribute from there to apply on the return type
//
- public void LabelParameters (EmitContext ec, MethodBase builder, Attributes method_attrs)
+ static public void LabelParameters (EmitContext ec,
+ MethodBase builder,
+ Parameters parameters,
+ Attributes method_attrs,
+ Location loc)
{
//
// Define each type attribute (in/out/ref) and
// the argument names.
//
- Parameter [] p = Parameters.FixedParameters;
+ Parameter [] p = parameters.FixedParameters;
int i = 0;
MethodBuilder mb = null;
if (par_attr == ParameterAttributes.Out){
if (attr.Contains (TypeManager.in_attribute_type))
- Report.Error (36, Location,
+ Report.Error (36, loc,
"Can not use [In] attribute on out parameter");
}
}
}
}
- if (Parameters.ArrayParameter != null){
+ if (parameters.ArrayParameter != null){
ParameterBuilder pb;
- Parameter array_param = Parameters.ArrayParameter;
+ Parameter array_param = parameters.ArrayParameter;
if (mb == null)
pb = cb.DefineParameter (
try {
ret_pb = mb.DefineParameter (0, ParameterAttributes.None, "");
Attribute.ApplyAttributes (ec, ret_pb, ret_pb, ret_attrs);
- } catch (ArgumentOutOfRangeException) {
+
+ } catch (ArgumentOutOfRangeException) {
Report.Warning (
- -24, Location,
+ -24, loc,
".NET SDK 1.0 does not permit setting custom attributes" +
" on the return type of a method");
}
public class Method : MethodCore, IIteratorContainer {
public MethodBuilder MethodBuilder;
public MethodData MethodData;
+ public readonly GenericMethod GenericMethod;
/// <summary>
/// Modifiers allowed in a class declaration
Modifiers.OVERRIDE |
Modifiers.ABSTRACT |
Modifiers.UNSAFE |
+ Modifiers.METHOD_YIELDS |
Modifiers.EXTERN;
//
// return_type can be "null" for VOID values.
//
- public Method (Expression return_type, int mod, string name, Parameters parameters,
- Attributes attrs, Location l)
- : base (return_type, mod, AllowedModifiers, name, attrs, parameters, l)
- { }
+ public Method (DeclSpace ds, Expression return_type, int mod, string name,
+ Parameters parameters, Attributes attrs, Location l)
+ : base (ds, return_type, mod, AllowedModifiers, name, attrs, parameters, l)
+ {
+ }
+
+ public Method (GenericMethod generic, Expression return_type, int mod, string name,
+ Parameters parameters, Attributes attrs, Location l)
+ : base (generic, return_type, mod, AllowedModifiers, name, attrs, parameters, l)
+ {
+ GenericMethod = generic;
+ }
//
// Returns the `System.Type' for the ReturnType of this
base.CheckBase (container);
// Check whether arguments were correct.
- if (!DoDefineParameters (container))
+ if (!DoDefineParameters ())
return false;
MethodSignature ms = new MethodSignature (Name, null, ParameterTypes);
//
public override bool Define (TypeContainer container)
{
- if (!DoDefine (container))
+ DeclSpace decl;
+ MethodBuilder mb = null;
+ if (GenericMethod != null) {
+ mb = container.TypeBuilder.DefineGenericMethod (Name, flags);
+ if (!GenericMethod.Define (mb))
+ return false;
+ decl = GenericMethod;
+ } else
+ decl = container;
+
+ if (!DoDefine (decl, container))
return false;
if (!CheckBase (container))
CallingConventions cc = GetCallingConvention (container is Class);
- MethodData = new MethodData (this, null, MemberType, ParameterTypes,
- ParameterInfo, cc, OptAttributes,
- ModFlags, flags, true);
+ MethodData = new MethodData (ds, this, null, MemberType,
+ ParameterTypes, ParameterInfo, cc,
+ OptAttributes, ModFlags, flags, true, mb);
if (!MethodData.Define (container))
return false;
}
MethodBuilder = MethodData.MethodBuilder;
-
+
//
// This is used to track the Entry Point,
//
if (Name == "Main" &&
- ((ModFlags & Modifiers.STATIC) != 0) &&
+ ((ModFlags & Modifiers.STATIC) != 0) && RootContext.NeedsEntryPoint &&
(RootContext.MainClass == null ||
RootContext.MainClass == container.TypeBuilder.FullName)){
if (IsEntryPoint (MethodBuilder, ParameterInfo)) {
{
MethodData.Emit (container, Block, this);
Block = null;
+ MethodData = null;
}
void IIteratorContainer.SetYields ()
Expression parent_constructor_group;
Type t;
- ec.CurrentBlock = new Block (null, Block.Flags.Implicit, parameters);
+ ec.CurrentBlock = new ToplevelBlock (Block.Flags.Implicit, parameters, loc);
if (argument_list != null){
foreach (Argument a in argument_list){
public class Constructor : MethodCore {
public ConstructorBuilder ConstructorBuilder;
public ConstructorInitializer Initializer;
- new public Attributes OptAttributes;
// <summary>
// Modifiers allowed for a constructor.
// The spec claims that static is not permitted, but
// my very own code has static constructors.
//
- public Constructor (string name, Parameters args, ConstructorInitializer init, Location l)
- : base (null, 0, AllowedModifiers, name, null, args, l)
+ public Constructor (DeclSpace ds, string name, int mod, Parameters args,
+ ConstructorInitializer init, Location l)
+ : base (ds, null, mod, AllowedModifiers, name, null, args, l)
{
Initializer = init;
}
MethodAttributes.SpecialName);
// Check if arguments were correct.
- if (!DoDefineParameters (container))
+ if (!DoDefineParameters ())
return false;
if ((ModFlags & Modifiers.STATIC) != 0){
ec.IsStatic = false;
}
- LabelParameters (ec, ConstructorBuilder, OptAttributes);
+ MethodCore.LabelParameters (ec, ConstructorBuilder,
+ Parameters, OptAttributes, Location);
SymbolWriter sw = CodeGen.SymbolWriter;
bool generate_debugging = false;
//
// Protected data.
//
+ protected DeclSpace ds;
protected MemberBase member;
protected int modifiers;
protected MethodAttributes flags;
}
}
- public MethodData (MemberBase member, string name, Type return_type,
+ public MethodData (DeclSpace ds, MemberBase member, string name, Type return_type,
Type [] parameter_types, InternalParameters parameters,
CallingConventions cc, Attributes opt_attrs,
int modifiers, MethodAttributes flags, bool is_method)
{
+ this.ds = ds;
this.member = member;
this.accessor_name = name;
this.ReturnType = return_type;
this.conditionals = null;
}
+ public MethodData (DeclSpace ds, MemberBase member, string name, Type return_type,
+ Type [] parameter_types, InternalParameters parameters,
+ CallingConventions cc, Attributes opt_attrs,
+ int modifiers, MethodAttributes flags, bool is_method,
+ MethodBuilder builder)
+ : this (ds, member, name, return_type, parameter_types, parameters,
+ cc, opt_attrs, modifiers, flags, is_method)
+ {
+ this.builder = builder;
+ }
+
//
// Attributes.
//
member.InterfaceType, name, ReturnType, ParameterTypes);
if (member.InterfaceType != null && implementing == null){
- TypeContainer.Error_ExplicitInterfaceNotMemberInterface (
- Location, name);
+ Report.Error (539, Location, "'{0}' in explicit interface declaration is not an interface", method_name);
return false;
}
}
Modifiers.Error_InvalidModifier (Location, "public, virtual or abstract");
implementing = null;
}
- } else {
- //
- // If this is an interface method implementation,
- // check for public accessibility
- //
- if ((flags & MethodAttributes.MemberAccessMask) != MethodAttributes.Public){
- if (TypeManager.IsInterfaceType (implementing.DeclaringType))
- implementing = null;
+ } else if ((flags & MethodAttributes.MemberAccessMask) != MethodAttributes.Public){
+ if (TypeManager.IsInterfaceType (implementing.DeclaringType)){
+ //
+ // If this is an interface method implementation,
+ // check for public accessibility
+ //
+ implementing = null;
+ } else if ((flags & MethodAttributes.MemberAccessMask) == MethodAttributes.Private){
+ // We may never be private.
+ implementing = null;
+ } else if ((modifiers & Modifiers.OVERRIDE) == 0){
+ //
+ // We may be protected if we're overriding something.
+ //
+ implementing = null;
}
}
}
EmitContext ec = new EmitContext (
- container, Location, null, ReturnType, modifiers);
+ container, ds, Location, null, ReturnType, modifiers, false);
builder = dllimport_attribute.DefinePInvokeMethod (
ec, container.TypeBuilder, method_name, flags,
ReturnType, ParameterTypes);
- } else
+ } else if (builder == null)
builder = container.TypeBuilder.DefineMethod (
method_name, flags, CallingConventions,
ReturnType, ParameterTypes);
+ else
+ builder.SetGenericMethodSignature (
+ flags, CallingConventions,
+ ReturnType, ParameterTypes);
if (builder == null)
return false;
else
ig = null;
- ec = new EmitContext (container, Location, ig, ReturnType, modifiers);
+ ec = new EmitContext (container, ds, Location, ig, ReturnType, modifiers, false);
if (OptAttributes != null)
Attribute.ApplyAttributes (ec, builder, kind, OptAttributes);
if (member is MethodCore)
- ((MethodCore) member).LabelParameters (ec, MethodBuilder, OptAttributes);
-
+ MethodCore.LabelParameters (ec, MethodBuilder,
+ ((MethodCore) member).Parameters,
+ OptAttributes,
+ Location);
+
//
// abstract or extern methods have no bodies
//
//
// FIXME: This code generates buggy code
//
- if (member.Name == "Finalize" && ReturnType == TypeManager.void_type)
+ if (member is Destructor)
EmitDestructor (ec, block);
else {
SymbolWriter sw = CodeGen.SymbolWriter;
ILGenerator ig = ec.ig;
Label finish = ig.DefineLabel ();
- bool old_in_try = ec.InTry;
+
+ block.SetDestructor ();
ig.BeginExceptionBlock ();
- ec.InTry = true;
ec.ReturnLabel = finish;
ec.HasReturnLabel = true;
ec.EmitTopBlock (block, null, Location);
- ec.InTry = old_in_try;
// ig.MarkLabel (finish);
- bool old_in_finally = ec.InFinally;
- ec.InFinally = true;
ig.BeginFinallyBlock ();
if (ec.ContainerType.BaseType != null) {
ig.Emit (OpCodes.Call, (MethodInfo) parent_destructor.Methods [0]);
}
}
- ec.InFinally = old_in_finally;
ig.EndExceptionBlock ();
//ig.MarkLabel (ec.ReturnLabel);
}
}
+ public class Destructor : Method {
+
+ public Destructor (DeclSpace ds, Expression return_type, int mod, string name,
+ Parameters parameters, Attributes attrs, Location l)
+ : base (ds, return_type, mod, name, parameters, attrs, l)
+ { }
+
+ }
+
abstract public class MemberBase : MemberCore {
public Expression Type;
- public readonly Attributes OptAttributes;
protected MethodAttributes flags;
+ protected readonly int explicit_mod_flags;
+
//
// The "short" name of this property / indexer / event. This is the
// name without the explicit interface.
//
// The constructor is only exposed to our children
//
- protected MemberBase (Expression type, int mod, int allowed_mod, string name,
+ protected MemberBase (Expression type, int mod, int allowed_mod, int def_mod, string name,
Attributes attrs, Location loc)
- : base (name, loc)
+ : base (name, attrs, loc)
{
+ explicit_mod_flags = mod;
Type = type;
- ModFlags = Modifiers.Check (allowed_mod, mod, Modifiers.PRIVATE, loc);
- OptAttributes = attrs;
+ ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, loc);
}
protected virtual bool CheckBase (TypeContainer container)
return true;
}
- protected virtual bool CheckParameters (TypeContainer container, Type [] parameters)
+ protected void WarningNotHiding (TypeContainer parent)
+ {
+ Report.Warning (
+ 109, Location,
+ "The member " + parent.MakeName (Name) + " does not hide an " +
+ "inherited member. The keyword new is not required");
+
+ }
+
+ void Error_CannotChangeAccessModifiers (TypeContainer parent, MethodInfo parent_method,
+ string name)
+ {
+ //
+ // FIXME: report the old/new permissions?
+ //
+ Report.Error (
+ 507, Location, parent.MakeName (Name) +
+ ": can't change the access modifiers when overriding inherited " +
+ "member `" + name + "'");
+ }
+
+ //
+ // Performs various checks on the MethodInfo `mb' regarding the modifier flags
+ // that have been defined.
+ //
+ // `name' is the user visible name for reporting errors (this is used to
+ // provide the right name regarding method names and properties)
+ //
+ protected bool CheckMethodAgainstBase (TypeContainer parent, MethodAttributes my_attrs,
+ MethodInfo mb, string name)
+ {
+ bool ok = true;
+
+ if ((ModFlags & Modifiers.OVERRIDE) != 0){
+ if (!(mb.IsAbstract || mb.IsVirtual)){
+ Report.Error (
+ 506, Location, parent.MakeName (Name) +
+ ": cannot override inherited member `" +
+ name + "' because it is not " +
+ "virtual, abstract or override");
+ ok = false;
+ }
+
+ // Now we check that the overriden method is not final
+
+ if (mb.IsFinal) {
+ // This happens when implementing interface methods.
+ if (mb.IsHideBySig && mb.IsVirtual) {
+ Report.Error (
+ 506, Location, parent.MakeName (Name) +
+ ": cannot override inherited member `" +
+ name + "' because it is not " +
+ "virtual, abstract or override");
+ } else
+ Report.Error (239, Location, parent.MakeName (Name) + " : cannot " +
+ "override inherited member `" + name +
+ "' because it is sealed.");
+ ok = false;
+ }
+ //
+ // Check that the permissions are not being changed
+ //
+ MethodAttributes thisp = my_attrs & MethodAttributes.MemberAccessMask;
+ MethodAttributes parentp = mb.Attributes & MethodAttributes.MemberAccessMask;
+
+ //
+ // special case for "protected internal"
+ //
+
+ if ((parentp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
+ //
+ // when overriding protected internal, the method can be declared
+ // protected internal only within the same assembly
+ //
+
+ if ((thisp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
+ if (parent.TypeBuilder.Assembly != mb.DeclaringType.Assembly){
+ //
+ // assemblies differ - report an error
+ //
+
+ Error_CannotChangeAccessModifiers (parent, mb, name);
+ ok = false;
+ } else if (thisp != parentp) {
+ //
+ // same assembly, but other attributes differ - report an error
+ //
+
+ Error_CannotChangeAccessModifiers (parent, mb, name);
+ ok = false;
+ };
+ } else if ((thisp & MethodAttributes.Family) != MethodAttributes.Family) {
+ //
+ // if it's not "protected internal", it must be "protected"
+ //
+
+ Error_CannotChangeAccessModifiers (parent, mb, name);
+ ok = false;
+ } else if (parent.TypeBuilder.Assembly == mb.DeclaringType.Assembly) {
+ //
+ // protected within the same assembly - an error
+ //
+ Error_CannotChangeAccessModifiers (parent, mb, name);
+ ok = false;
+ } else if ((thisp & ~(MethodAttributes.Family | MethodAttributes.FamORAssem)) !=
+ (parentp & ~(MethodAttributes.Family | MethodAttributes.FamORAssem))) {
+ //
+ // protected ok, but other attributes differ - report an error
+ //
+ Error_CannotChangeAccessModifiers (parent, mb, name);
+ ok = false;
+ }
+ } else {
+ if (thisp != parentp){
+ Error_CannotChangeAccessModifiers (parent, mb, name);
+ ok = false;
+ }
+ }
+ }
+
+ if (mb.IsVirtual || mb.IsAbstract){
+ if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0){
+ if (Name != "Finalize"){
+ Report.Warning (
+ 114, 2, Location, parent.MakeName (Name) +
+ " hides inherited member `" + name +
+ "'. To make the current member override that " +
+ "implementation, add the override keyword, " +
+ "otherwise use the new keyword");
+ ModFlags |= Modifiers.NEW;
+ }
+ }
+ } else {
+ if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0){
+ if (Name != "Finalize"){
+ Report.Warning (
+ 108, 1, Location, "The keyword new is required on " +
+ parent.MakeName (Name) + " because it hides " +
+ "inherited member `" + name + "'");
+ ModFlags |= Modifiers.NEW;
+ }
+ }
+ }
+
+ return ok;
+ }
+
+ protected virtual bool CheckParameters (DeclSpace ds, Type [] parameters)
{
bool error = false;
foreach (Type partype in parameters){
if (partype.IsPointer){
- if (!UnsafeOK (container))
+ if (!UnsafeOK (ds))
error = true;
if (!TypeManager.VerifyUnManaged (TypeManager.GetElementType (partype), Location))
error = true;
}
- if (container.AsAccessible (partype, ModFlags))
+ if (ds.AsAccessible (partype, ModFlags))
continue;
if (this is Indexer)
return !error;
}
- protected virtual bool DoDefine (TypeContainer container)
+ protected virtual bool DoDefine (DeclSpace decl, TypeContainer container)
{
if (Name == null)
Name = "this";
flags = Modifiers.MethodAttr (ModFlags);
// Lookup Type, verify validity
- MemberType = container.ResolveType (Type, false, Location);
+ MemberType = decl.ResolveType (Type, false, Location);
if (MemberType == null)
return false;
//
// Check for explicit interface implementation
//
- if ((ExplicitInterfaceName == null) && (Name.IndexOf (".") != -1)){
- int pos = Name.LastIndexOf (".");
+ if ((ExplicitInterfaceName == null) && (Name.IndexOf ('.') != -1)){
+ int pos = Name.LastIndexOf ('.');
ExplicitInterfaceName = Name.Substring (0, pos);
ShortName = Name.Substring (pos + 1);
if (InterfaceType == null)
return false;
+ if (InterfaceType.IsClass) {
+ Report.Error (538, Location, "'{0}' in explicit interface declaration is not an interface", ExplicitInterfaceName);
+ return false;
+ }
+
// Compute the full name that we need to export.
Name = InterfaceType.FullName + "." + ShortName;
if (!container.VerifyImplements (InterfaceType, ShortName, Name, Location))
return false;
+ Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
+
IsExplicitImpl = true;
} else
IsExplicitImpl = false;
//
protected FieldBase (Expression type, int mod, int allowed_mod, string name,
object init, Attributes attrs, Location loc)
- : base (type, mod, allowed_mod, name, attrs, loc)
+ : base (type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs, loc)
{
this.init = init;
}
}
}
- public bool IsAssigned;
-
protected readonly Object init;
// Private.
Expression init_expr;
return init_expr;
}
+
+ public void SetAssigned ()
+ {
+ status |= Status.ASSIGNED;
+ }
}
//
return false;
}
+ try {
FieldBuilder = container.TypeBuilder.DefineField (
Name, t, Modifiers.FieldAttr (ModFlags));
TypeManager.RegisterFieldBase (FieldBuilder, this);
+ }
+ catch (ArgumentException) {
+ Report.Warning (-24, Location, "The Microsoft runtime is unable to use [void|void*] as a field type, try using the Mono runtime.");
+ return false;
+ }
+
return true;
}
protected EmitContext ec;
- public PropertyBase (Expression type, string name, int mod_flags, int allowed_mod,
- Parameters parameters, Accessor get_block, Accessor set_block,
+ public PropertyBase (DeclSpace ds, Expression type, string name, int mod_flags,
+ int allowed_mod, Parameters parameters,
+ Accessor get_block, Accessor set_block,
Attributes attrs, Location loc)
- : base (type, mod_flags, allowed_mod, name, attrs, parameters, loc)
+ : base (ds, type, mod_flags, allowed_mod, name, attrs, parameters, loc)
{
Get = get_block;
Set = set_block;
}
- protected override bool DoDefine (TypeContainer container)
+ protected override bool DoDefine (DeclSpace decl, TypeContainer container)
{
- if (!base.DoDefine (container))
+ if (!base.DoDefine (decl, container))
return false;
ec = new EmitContext (container, Location, null, MemberType, ModFlags);
base.CheckBase (container);
// Check whether arguments were correct.
- if (!DoDefineParameters (container))
+ if (!DoDefineParameters ())
return false;
if (IsExplicitImpl)
}
}
- public class Property : PropertyBase {
+ public class Property : PropertyBase, IIteratorContainer {
const int AllowedModifiers =
Modifiers.NEW |
Modifiers.PUBLIC |
Modifiers.ABSTRACT |
Modifiers.UNSAFE |
Modifiers.EXTERN |
+ Modifiers.METHOD_YIELDS |
Modifiers.VIRTUAL;
- public Property (Expression type, string name, int mod_flags,
+ public Property (DeclSpace ds, Expression type, string name, int mod_flags,
Accessor get_block, Accessor set_block,
Attributes attrs, Location loc)
- : base (type, name, mod_flags, AllowedModifiers,
+ : base (ds, type, name, mod_flags, AllowedModifiers,
Parameters.EmptyReadOnlyParameters,
get_block, set_block, attrs, loc)
{
public override bool Define (TypeContainer container)
{
- if (!DoDefine (container))
+ if (!DoDefine (container, container))
return false;
if (!CheckBase (container))
InternalParameters ip = new InternalParameters (
container, Parameters.EmptyReadOnlyParameters);
- GetData = new MethodData (this, "get", MemberType,
+ GetData = new MethodData (container, this, "get", MemberType,
parameters, ip, CallingConventions.Standard,
Get.OptAttributes, ModFlags, flags, false);
+ //
+ // Setup iterator if we are one
+ //
+ if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
+ IteratorHandler ih = new IteratorHandler (
+ "get", container, MemberType,
+ parameters, ip, ModFlags, Location);
+
+ Block new_block = ih.Setup (block);
+ if (new_block == null)
+ return false;
+ block = new_block;
+ }
+
if (!GetData.Define (container))
return false;
InternalParameters ip = new InternalParameters (
container, new Parameters (parms, null, Location));
- SetData = new MethodData (this, "set", TypeManager.void_type,
+ SetData = new MethodData (container, this, "set", TypeManager.void_type,
parameters, ip, CallingConventions.Standard,
Set.OptAttributes, ModFlags, flags, false);
}
return true;
}
+
+ public void SetYields ()
+ {
+ ModFlags |= Modifiers.METHOD_YIELDS;
+ }
}
/// </summary>
EventAttributes e_attr = EventAttributes.RTSpecialName | EventAttributes.SpecialName;
MethodAttributes m_attr = MethodAttributes.HideBySig | MethodAttributes.SpecialName
;
- if (!DoDefine (container))
+ if (!DoDefine (container, container))
return false;
if (init != null && ((ModFlags & Modifiers.ABSTRACT) != 0)){
//
// Now define the accessors
//
- AddData = new MethodData (this, "add", TypeManager.void_type,
+ AddData = new MethodData (container, this, "add", TypeManager.void_type,
parameter_types, ip, CallingConventions.Standard,
(Add != null) ? Add.OptAttributes : null,
ModFlags, flags | m_attr, false);
AddBuilder = AddData.MethodBuilder;
AddBuilder.DefineParameter (1, ParameterAttributes.None, "value");
- RemoveData = new MethodData (this, "remove", TypeManager.void_type,
+ RemoveData = new MethodData (container, this, "remove", TypeManager.void_type,
parameter_types, ip, CallingConventions.Standard,
(Remove != null) ? Remove.OptAttributes : null,
ModFlags, flags | m_attr, false);
//
// Are we implementing an interface ?
//
- bool IsImplementing = false;
-
- public Indexer (Expression type, string int_type, int flags, Parameters parameters,
- Accessor get_block, Accessor set_block, Attributes attrs, Location loc)
- : base (type, "", flags, AllowedModifiers, parameters, get_block, set_block,
+ public Indexer (DeclSpace ds, Expression type, string int_type, int flags,
+ Parameters parameters, Accessor get_block, Accessor set_block,
+ Attributes attrs, Location loc)
+ : base (ds, type, "", flags, AllowedModifiers, parameters, get_block, set_block,
attrs, loc)
{
ExplicitInterfaceName = int_type;
PropertyAttributes.RTSpecialName |
PropertyAttributes.SpecialName;
- if (!DoDefine (container))
+ if (!DoDefine (container, container))
return false;
IndexerName = Attribute.ScanForIndexerName (ec, OptAttributes);
Name = ShortName;
}
+ if (!CheckNameCollision (container))
+ return false;
+
if (!CheckBase (container))
return false;
if (Get != null){
InternalParameters ip = new InternalParameters (container, Parameters);
- GetData = new MethodData (this, "get", MemberType,
+ GetData = new MethodData (container, this, "get", MemberType,
ParameterTypes, ip, CallingConventions.Standard,
Get.OptAttributes, ModFlags, flags, false);
InternalParameters ip = new InternalParameters (container, set_formal_params);
- SetData = new MethodData (this, "set", TypeManager.void_type,
+ SetData = new MethodData (container, this, "set", TypeManager.void_type,
set_pars, ip, CallingConventions.Standard,
Set.OptAttributes, ModFlags, flags, false);
}
}
- if (GetData != null)
- IsImplementing = GetData.IsImplementing;
- else if (SetData != null)
- IsImplementing = SetData.IsImplementing;
-
//
// Define the PropertyBuilder if one of the following conditions are met:
// a) we're not implementing an interface indexer.
return true;
}
+
+ bool CheckNameCollision (TypeContainer container) {
+ switch (VerifyName (container)){
+ case DeclSpace.AdditionResult.NameExists:
+ Report.Error (102, Location, "The container '{0}' already contains a definition for '{1}'", container.GetSignatureForError (), Name);
+ return false;
+
+ case DeclSpace.AdditionResult.Success:
+ return true;
+ }
+ throw new NotImplementedException ();
+ }
+
+ DeclSpace.AdditionResult VerifyName (TypeContainer container) {
+ if (!AddIndexer (container, container.Name + "." + Name))
+ return DeclSpace.AdditionResult.NameExists;
+
+ if (Get != null) {
+ if (!AddIndexer (container, container.Name + ".get_" + Name))
+ return DeclSpace.AdditionResult.NameExists;
+ }
+
+ if (Set != null) {
+ if (!AddIndexer (container, container.Name + ".set_" + Name))
+ return DeclSpace.AdditionResult.NameExists;
+ }
+ return DeclSpace.AdditionResult.Success;
+ }
+
+ bool AddIndexer (TypeContainer container, string fullname)
+ {
+ object value = container.GetDefinition (fullname);
+
+ if (value != null) {
+ return value.GetType () != GetType () ? false : true;
+ }
+
+ container.DefineName (fullname, this);
+ return true;
+ }
+
+ public override string GetSignatureForError () {
+ return TypeManager.CSharpSignature (PropertyBuilder, true);
+ }
}
- public class Operator : MemberCore {
+ public class Operator : MemberBase, IIteratorContainer {
const int AllowedModifiers =
Modifiers.PUBLIC |
public readonly Expression FirstArgType, SecondArgType;
public readonly string FirstArgName, SecondArgName;
public Block Block;
- public Attributes OptAttributes;
public MethodBuilder OperatorMethodBuilder;
public string MethodName;
public Method OperatorMethod;
- public Operator (OpType type, Expression ret_type, int flags,
+ public Operator (OpType type, Expression ret_type, int mod_flags,
Expression arg1type, string arg1name,
Expression arg2type, string arg2name,
Block block, Attributes attrs, Location loc)
- : base ("", loc)
+ : base (ret_type, mod_flags, AllowedModifiers, Modifiers.PUBLIC, "", attrs, loc)
{
OperatorType = type;
+ Name = "op_" + OperatorType;
ReturnType = ret_type;
- ModFlags = Modifiers.Check (AllowedModifiers, flags, Modifiers.PUBLIC, loc);
FirstArgType = arg1type;
FirstArgName = arg1name;
SecondArgType = arg2type;
SecondArgName = arg2name;
Block = block;
- OptAttributes = attrs;
}
string Prototype (TypeContainer container)
param_list[1] = new Parameter (SecondArgType, SecondArgName,
Parameter.Modifier.NONE, null);
- OperatorMethod = new Method (ReturnType, ModFlags, MethodName,
+ OperatorMethod = new Method (container, ReturnType, ModFlags, MethodName,
new Parameters (param_list, null, Location),
OptAttributes, Location);
+ OperatorMethod.Block = Block;
OperatorMethod.IsOperator = true;
OperatorMethod.Define (container);
if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
return;
- OperatorMethod.Block = Block;
OperatorMethod.Emit (container);
Block = null;
}
GetName (OperatorType),
param_types [0], param_types [1]);
}
+
+ public void SetYields ()
+ {
+ ModFlags |= Modifiers.METHOD_YIELDS;
+ }
}
//
// If only accessible to the defining assembly or
if (prot == MethodAttributes.FamANDAssem ||
prot == MethodAttributes.Assembly){
- if (m.DeclaringType.Assembly == CodeGen.AssemblyBuilder)
- return true;
- else
- return false;
+ return m.DeclaringType.Assembly == CodeGen.Assembly.Builder;
}
// Anything else (FamOrAssembly and Public) is fine