public class TypeDef : ICustomAttrTarget, IDeclSecurityTarget, IComparable {
- protected class GenericInfo {
- public string Id;
- public int num;
- public ArrayList ConstraintList;
- }
-
private PEAPI.TypeAttr attr;
private string name_space;
private string name;
private bool is_value_class;
private bool is_enum_class;
+ private Location location;
+
public TypeDef (PEAPI.TypeAttr attr, string name_space, string name,
BaseClassRef parent, ArrayList impl_list, Location location, GenericParameters gen_params, TypeDef outer)
{
this.impl_list = impl_list;
this.gen_params = gen_params;
this.outer = outer;
+ this.location = location;
field_table = new Hashtable ();
field_list = new ArrayList ();
this.name_space = name_space;
this.name = name;
}
+
+ //Fixup attributes
+ if (IsInterface)
+ this.attr |= PEAPI.TypeAttr.Abstract;
}
public string Name {
get { return (attr & PEAPI.TypeAttr.Interface) != 0; }
}
+ public bool IsAbstract {
+ get { return (attr & PEAPI.TypeAttr.Abstract) != 0; }
+ }
+
public GenericParameters TypeParameters {
get { return gen_params; }
}
+ public DeclSecurity DeclSecurity {
+ get {
+ if (decl_sec == null)
+ decl_sec = new DeclSecurity ();
+ return decl_sec;
+ }
+ }
+
public void AddOverride (MethodDef body, BaseTypeRef parent, string name)
{
if (override_list == null)
public void AddFieldDef (FieldDef fielddef)
{
if (IsInterface && !fielddef.IsStatic) {
- Console.WriteLine ("warning -- Non-static field in interface, set to such");
+ Report.Warning ("Non-static field in interface, set to such");
fielddef.Attributes |= PEAPI.FieldAttr.Static;
}
- field_table.Add (new DictionaryEntry (fielddef.Name, fielddef.Type.FullName), fielddef);
+ DictionaryEntry entry = new DictionaryEntry (fielddef.Name, fielddef.Type.FullName);
+ if (field_table [entry] != null)
+ Report.Error ("Duplicate field declaration: " + fielddef.Type.FullName + " " + fielddef.Name);
+ field_table.Add (entry, fielddef);
field_list.Add (fielddef);
}
public void AddMethodDef (MethodDef methoddef)
{
- if (IsInterface && !(methoddef.IsVirtual || methoddef.IsAbstract)) {
- Console.WriteLine ("warning -- Non-virtual, non-abstract instance method in interface, set to such");
+ if (IsInterface && !methoddef.IsStatic && (!methoddef.IsVirtual || !methoddef.IsAbstract)) {
+ Report.Warning (methoddef.StartLocation, "Non-virtual or non-abstract instance method in interface, set to such");
methoddef.Attributes |= PEAPI.MethAttr.Abstract | PEAPI.MethAttr.Virtual;
}
+ if (method_table [methoddef.Signature] != null)
+ Report.Error (methoddef.StartLocation, "Duplicate method declaration: " + methoddef.Signature);
+
method_table.Add (methoddef.Signature, methoddef);
}
public void BeginEventDef (EventDef event_def)
{
if (current_event != null)
- throw new Exception ("An event definition was not closed.");
+ Report.Error ("An event definition was not closed.");
current_event = event_def;
}
public void BeginPropertyDef (PropertyDef property_def)
{
if (current_property != null)
- throw new Exception ("A property definition was not closed.");
+ Report.Error ("A property definition was not closed.");
current_property = property_def;
}
customattr_list.Add (customattr);
}
- public void AddPermissionSet (PEAPI.SecurityAction sec_action, PermissionSet ps)
- {
- if (decl_sec == null)
- decl_sec = new DeclSecurity ();
-
- decl_sec.AddPermissionSet (sec_action, ps);
- }
-
- public void AddPermission (PEAPI.SecurityAction sec_action, IPermission iper)
- {
- if (decl_sec == null)
- decl_sec = new DeclSecurity ();
-
- decl_sec.AddPermission (sec_action, iper);
- }
-
public GenericParameter GetGenericParam (string id)
{
if (gen_params == null)
}
}
+ private bool IsValueType (string ns, string name)
+ {
+ return (ns == "System" && name == "ValueType");
+ }
+
+ private bool IsEnumType (string ns, string name)
+ {
+ return (ns == "System" && name == "Enum");
+ }
+
public void Define (CodeGen code_gen)
{
if (is_defined)
if (is_intransit) {
// Circular definition
- throw new Exception ("Circular definition of class: " + FullName);
+ Report.Error ("Circular definition of class: " + FullName);
}
if (outer != null) {
if (vis == PEAPI.TypeAttr.Private || vis == PEAPI.TypeAttr.Public) {
/* Nested class, but attr not set accordingly. */
- //FIXME: 'report' warning here
- Console.WriteLine ("Warning -- Nested class '{0}' has non-nested visibility, set to such.", NestedFullName);
+ 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);
}
is_intransit = false;
if (parent.PeapiClass == null) {
- throw new Exception ("this type can not be a base type: "
+ Report.Error ("this type can not be a base type: "
+ parent);
}
- if (parent.PeapiClass.nameSpace != null &&
- parent.PeapiClass.nameSpace.CompareTo ("System") == 0) {
-
- if (parent.PeapiClass.name.CompareTo ("ValueType") == 0)
- is_value_class = true;
- else
- if (parent.PeapiClass.name.CompareTo ("Enum") == 0 )
- is_enum_class = true;
- }
+ 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) {
+
+ Report.Warning (location, "Non-sealed value class, made sealed.");
+ attr |= PEAPI.TypeAttr.Sealed;
+ }
if (outer != null) {
if (!outer.IsDefined)
}
}
- public PEAPI.MethodDef ResolveMethod (string signature, CodeGen code_gen)
+ public PEAPI.Method ResolveMethod (BaseTypeRef ret_type, PEAPI.CallConv call_conv,
+ string name, BaseTypeRef [] param, int gen_param_count, CodeGen code_gen)
{
+ string signature = MethodDef.CreateSignature (ret_type, name, param, gen_param_count);
MethodDef methoddef = (MethodDef) method_table[signature];
- if (methoddef == null) {
- code_gen.Report.Error ("Unable to resolve method: " + signature);
- Environment.Exit (1);
- }
-
- return methoddef.Resolve (code_gen, classdef);
+ if (methoddef != null)
+ return methoddef.Resolve (code_gen, classdef);
+ return ResolveAsMethodRef (ret_type, call_conv, name, param, gen_param_count, code_gen);
}
- public PEAPI.Method ResolveVarargMethod (string signature,
- CodeGen code_gen, PEAPI.Type[] opt)
+ public PEAPI.Method ResolveVarargMethod (BaseTypeRef ret_type, PEAPI.CallConv call_conv,
+ string name, BaseTypeRef [] param, int gen_param_count, PEAPI.Type [] opt, CodeGen code_gen)
{
+ string signature = MethodDef.CreateVarargSignature (ret_type, name, param);
MethodDef methoddef = (MethodDef) method_table[signature];
- if (methoddef == null) {
- code_gen.Report.Error ("Unable to resolve method: " + signature);
- Environment.Exit (1);
+ if (methoddef != null) {
+ methoddef.Resolve (code_gen, classdef);
+ return methoddef.GetVarargSig (opt);
}
+
+ return ResolveAsMethodRef (ret_type, call_conv, name, param, gen_param_count, code_gen);
+ }
+
+ private PEAPI.Method ResolveAsMethodRef (BaseTypeRef ret_type, PEAPI.CallConv call_conv,
+ string name, BaseTypeRef [] param, int gen_param_count, CodeGen code_gen)
+ {
+ ExternTypeRef type_ref = code_gen.ThisModule.GetTypeRef (FullName, false);
+ ExternMethodRef methodref = (ExternMethodRef) type_ref.GetMethodRef (ret_type, call_conv, name, param, gen_param_count);
+ methodref.Resolve (code_gen);
- methoddef.Resolve (code_gen, classdef);
- return methoddef.GetVarargSig (opt);
+ return methodref.PeapiMethod;
}
- public PEAPI.Field ResolveField (string name, string type_name, CodeGen code_gen)
+ public PEAPI.Field ResolveField (string name, BaseTypeRef ret_type, CodeGen code_gen)
{
- FieldDef fielddef = (FieldDef) field_table[new DictionaryEntry (name, type_name)];
+ FieldDef fielddef = (FieldDef) field_table[new DictionaryEntry (name, ret_type.FullName)];
+ if (fielddef !=null)
+ return fielddef.Resolve (code_gen, classdef);
+
+ ExternTypeRef type_ref = code_gen.ThisModule.GetTypeRef (FullName, false);
+ IFieldRef fieldref = type_ref.GetFieldRef (ret_type, name);
+ fieldref.Resolve (code_gen);
- return fielddef.Resolve (code_gen, classdef);
+ return fieldref.PeapiField;
}
private string MakeFullName ()