public TypeDef(PEAPI.TypeAttr attr, string name_space, string name, BaseClassRef parent, ArrayList impl_list, Location location, GenericParameters gen_params, TypeDef outer) { this.attr = attr; this.parent = parent; this.impl_list = impl_list; this.gen_params = gen_params; this.outer = outer; this.location = location; field_table = new Hashtable(); field_list = new ArrayList(); method_table = new Hashtable(); method_list = new ArrayList(); size = -1; pack = -1; is_defined = false; is_intransit = false; is_value_class = false; is_enum_class = false; ResolveGenParams(); int lastdot = name.LastIndexOf('.'); /* Namespace . name split should not be done for nested classes */ if (lastdot >= 0 && outer == null) { if (name_space == null || name_space == "") { this.name_space = name.Substring(0, lastdot); } else { this.name_space = name_space + "." + name.Substring(0, lastdot); } this.name = name.Substring(lastdot + 1); } else { this.name_space = name_space; this.name = name; } //Fixup attributes if (IsInterface) { this.attr |= PEAPI.TypeAttr.Abstract; } }
public TypeDef (PEAPI.TypeAttr attr, string name_space, string name, BaseClassRef parent, ArrayList impl_list, Location location, GenericParameters gen_params, TypeDef outer) { this.attr = attr; this.parent = parent; this.impl_list = impl_list; this.gen_params = gen_params; this.outer = outer; this.location = location; field_table = new Hashtable (); field_list = new ArrayList (); method_table = new Hashtable (); method_list = new ArrayList (); size = -1; pack = -1; is_defined = false; is_intransit = false; is_value_class = false; is_enum_class = false; ResolveGenParams (); int lastdot = name.LastIndexOf ('.'); /* Namespace . name split should not be done for nested classes */ if (lastdot >= 0 && outer == null) { if (name_space == null || name_space == "") this.name_space = name.Substring (0, lastdot); else this.name_space = name_space + "." + name.Substring (0, lastdot); this.name = name.Substring (lastdot + 1); } else { this.name_space = name_space; this.name = name; } //Fixup attributes if (IsInterface) this.attr |= PEAPI.TypeAttr.Abstract; }
public void Define(CodeGen code_gen) { if (is_defined) { return; } if (is_intransit) { // Circular definition Report.Error("Circular definition of class: " + FullName); } if (outer != null) { PEAPI.TypeAttr vis = attr & PEAPI.TypeAttr.VisibilityMask; if (vis == PEAPI.TypeAttr.Private || vis == PEAPI.TypeAttr.Public) { /* Nested class, but attr not set accordingly. */ Report.Warning(location, String.Format("Nested class '{0}' has non-nested visibility, set to such.", NestedFullName)); attr = attr ^ vis; attr |= (vis == PEAPI.TypeAttr.Public ? PEAPI.TypeAttr.NestedPublic : PEAPI.TypeAttr.NestedPrivate); } } if (parent != null) { is_intransit = true; parent.Resolve(code_gen); is_intransit = false; if (parent.PeapiClass == null) { Report.Error("this type can not be a base type: " + parent); } if (IsValueType(parent.PeapiClass.nameSpace, parent.PeapiClass.name)) { is_value_class = true; } else if (IsEnumType(parent.PeapiClass.nameSpace, parent.PeapiClass.name)) { is_enum_class = true; is_value_class = false; } if (!IsValueType(name_space, name) && !IsEnumType(name_space, name) && is_value_class && (attr & PEAPI.TypeAttr.Sealed) == 0) { attr |= PEAPI.TypeAttr.Sealed; } if (outer != null) { if (!outer.IsDefined) { outer.Define(code_gen); } classdef = outer.PeapiType.AddNestedClass(attr, name_space, name, parent.PeapiClass); } else { if (is_value_class || is_enum_class) { // Should probably confirm that the parent is System.ValueType classdef = code_gen.PEFile.AddValueClass(attr, name_space, name, is_value_class ? PEAPI.ValueClass.ValueType : PEAPI.ValueClass.Enum); } else { classdef = code_gen.PEFile.AddClass(attr, name_space, name, parent.PeapiClass); } } } else { if (outer != null) { if (!outer.IsDefined) { outer.Define(code_gen); } classdef = outer.PeapiType.AddNestedClass(attr, name_space, name); } else { if (is_value_class || is_enum_class) { classdef = code_gen.PEFile.AddValueClass(attr, name_space, name, is_value_class ? PEAPI.ValueClass.ValueType : PEAPI.ValueClass.Enum); } else { classdef = code_gen.PEFile.AddClass(attr, name_space, name); } } if (FullName == "System.Object") { classdef.SpecialNoSuper(); } } is_defined = true; if (size != -1 || pack != -1) { classdef.AddLayoutInfo((pack == -1) ? 1 : pack, (size == -1) ? 0 : size); } if (impl_list != null) { foreach (BaseClassRef impl in impl_list) { impl.Resolve(code_gen); classdef.AddImplementedInterface(impl.PeapiClass); } } if (gen_params != null) { gen_params.Resolve(code_gen, classdef); } is_intransit = false; code_gen.AddToDefineContentsList(this); }
public void Define (CodeGen code_gen) { if (is_defined) return; if (is_intransit) { // Circular definition Report.Error ("Circular definition of class: " + FullName); } if (outer != null) { PEAPI.TypeAttr vis = attr & PEAPI.TypeAttr.VisibilityMask; if (vis == PEAPI.TypeAttr.Private || vis == PEAPI.TypeAttr.Public) { /* Nested class, but attr not set accordingly. */ Report.Warning (location, String.Format ("Nested class '{0}' has non-nested visibility, set to such.", NestedFullName)); attr = attr ^ vis; attr |= (vis == PEAPI.TypeAttr.Public ? PEAPI.TypeAttr.NestedPublic : PEAPI.TypeAttr.NestedPrivate); } } if (parent != null) { is_intransit = true; parent.Resolve (code_gen); is_intransit = false; if (parent.PeapiClass == null) { Report.Error ("this type can not be a base type: " + parent); } if (IsValueType (parent.PeapiClass.nameSpace, parent.PeapiClass.name)) is_value_class = true; else if (IsEnumType (parent.PeapiClass.nameSpace, parent.PeapiClass.name)) is_enum_class = true; if (!IsValueType (name_space, name) && !IsEnumType (name_space, name) && is_value_class && (attr & PEAPI.TypeAttr.Sealed) == 0) { attr |= PEAPI.TypeAttr.Sealed; } if (outer != null) { if (!outer.IsDefined) outer.Define (code_gen); classdef = outer.PeapiType.AddNestedClass (attr, name_space, name, parent.PeapiClass); } else { if (is_value_class || is_enum_class) { // Should probably confirm that the parent is System.ValueType classdef = code_gen.PEFile.AddValueClass (attr, name_space, name, is_value_class ? PEAPI.ValueClass.ValueType : PEAPI.ValueClass.Enum); } else { classdef = code_gen.PEFile.AddClass (attr, name_space, name, parent.PeapiClass); } } } else { if (outer != null) { if (!outer.IsDefined) outer.Define (code_gen); classdef = outer.PeapiType.AddNestedClass (attr, name_space, name); } else { if (is_value_class || is_enum_class) { classdef = code_gen.PEFile.AddValueClass (attr, name_space, name, is_value_class ? PEAPI.ValueClass.ValueType : PEAPI.ValueClass.Enum); } else { classdef = code_gen.PEFile.AddClass (attr, name_space, name); } } if (FullName == "System.Object") classdef.SpecialNoSuper (); } is_defined = true; if (size != -1 || pack != -1) classdef.AddLayoutInfo ( (pack == -1) ? 1 : pack, (size == -1) ? 0 : size); if (impl_list != null) { foreach (BaseClassRef impl in impl_list) { impl.Resolve (code_gen); classdef.AddImplementedInterface (impl.PeapiClass); } } if (gen_params != null) gen_params.Resolve (code_gen, classdef); is_intransit = false; code_gen.AddToDefineContentsList (this); }