From 888f7ee24d6d333c6690b5684f42a8e1c61c8523 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Fri, 18 Apr 2003 03:52:17 +0000 Subject: [PATCH] * ExternTypeRef.cs: New file - Represents a reference to a type in an external assembly * FieldDef.cs: New file - Represents a field definition * IClassRef.cs: New file - Interface that classrefs must implement. This needs some more thought though because once a classref has been modified it is no longer a classref. * ITypeRef.cs: New file - Interface that references to types must implement * TypeDef.cs: New file - Represents the a class definition, and will hold all of the classes members. svn path=/trunk/mcs/; revision=13752 --- mcs/ilasm/codegen/ChangeLog | 13 ++++ mcs/ilasm/codegen/ExternTypeRef.cs | 28 ++++++++ mcs/ilasm/codegen/FieldDef.cs | 82 +++++++++++++++++++++++ mcs/ilasm/codegen/IClassRef.cs | 21 ++++++ mcs/ilasm/codegen/ITypeRef.cs | 71 ++++++++++++++++++++ mcs/ilasm/codegen/TypeDef.cs | 102 +++++++++++++++++++++++++++++ 6 files changed, 317 insertions(+) create mode 100644 mcs/ilasm/codegen/ExternTypeRef.cs create mode 100644 mcs/ilasm/codegen/FieldDef.cs create mode 100644 mcs/ilasm/codegen/IClassRef.cs create mode 100644 mcs/ilasm/codegen/ITypeRef.cs create mode 100644 mcs/ilasm/codegen/TypeDef.cs diff --git a/mcs/ilasm/codegen/ChangeLog b/mcs/ilasm/codegen/ChangeLog index 97370d3fe75..ba83522eb74 100644 --- a/mcs/ilasm/codegen/ChangeLog +++ b/mcs/ilasm/codegen/ChangeLog @@ -1,3 +1,16 @@ +2003-04-17 Jackson Harper + + * ExternTypeRef.cs: New file - Represents a reference to a type in + an external assembly + * FieldDef.cs: New file - Represents a field definition + * IClassRef.cs: New file - Interface that classrefs must + implement. This needs some more thought though because once a + classref has been modified it is no longer a classref. + * ITypeRef.cs: New file - Interface that references to types must + implement + * TypeDef.cs: New file - Represents the a class definition, and + will hold all of the classes members. + 2003-04-07 Jackson Harper * TypeRef.cs: Return FieldDef when adding a field def to a class diff --git a/mcs/ilasm/codegen/ExternTypeRef.cs b/mcs/ilasm/codegen/ExternTypeRef.cs new file mode 100644 index 00000000000..ef719a23124 --- /dev/null +++ b/mcs/ilasm/codegen/ExternTypeRef.cs @@ -0,0 +1,28 @@ +// +// Mono.ILASM.ExternTypeRef +// +// Author(s): +// Jackson Harper (Jackson@LatitudeGeo.com) +// +// (C) 2003 Jackson Harper, All rights reserved +// + + +using System; + +namespace Mono.ILASM { + + /// + /// A reference to a type in another assembly + /// + public class ExternTypeRef : PeapiTypeRef { + + public ExternTypeRef (PEAPI.ClassRef extern_type, + string full_name) : base (extern_type, full_name) + { + + } + } + +} + diff --git a/mcs/ilasm/codegen/FieldDef.cs b/mcs/ilasm/codegen/FieldDef.cs new file mode 100644 index 00000000000..af3074ac942 --- /dev/null +++ b/mcs/ilasm/codegen/FieldDef.cs @@ -0,0 +1,82 @@ +// +// Mono.ILASM.FieldDef +// +// Author(s): +// Jackson Harper (Jackson@LatitudeGeo.com) +// +// (C) 2003 Jackson Harper, All rights reserved +// + + +using System; + +namespace Mono.ILASM { + + public class FieldDef { + + private string name; + private ITypeRef type; + private PEAPI.FieldAttr attr; + private PEAPI.FieldDef field_def; + + private bool offset_set; + private bool datavalue_set; + private bool value_set; + + private uint offset; + + public FieldDef (PEAPI.FieldAttr attr, string name, + ITypeRef type) + { + this.attr = attr; + this.name = name; + this.type = type; + + offset_set = false; + datavalue_set = false; + value_set = false; + } + + public string Name { + get { return name; } + } + + public PEAPI.FieldDef FieldDef { + get { return field_def; } + } + + public void SetOffset (uint val) { + offset_set = true; + offset = val; + } + + /// + /// Define a global field + /// + public void Define (CodeGen code_gen) + { + type.Resolve (code_gen); + + field_def = code_gen.PEFile.AddField (attr, name, type.PeapiType); + + if (offset_set) { + field_def.SetOffset (offset); + + } + } + + /// + /// Define a field member of the specified class + /// + public void Define (CodeGen code_gen, PEAPI.ClassDef class_def) + { + type.Resolve (code_gen); + + class_def.AddField (attr, name, type.PeapiType); + } + } + +} + + + diff --git a/mcs/ilasm/codegen/IClassRef.cs b/mcs/ilasm/codegen/IClassRef.cs new file mode 100644 index 00000000000..af434fe0832 --- /dev/null +++ b/mcs/ilasm/codegen/IClassRef.cs @@ -0,0 +1,21 @@ +// +// Mono.ILASM.IClassRef +// +// Author(s): +// Jackson Harper (Jackson@LatitudeGeo.com) +// +// (C) 2003 Jackson Harper, All rights reserved +// + +using System; + +namespace Mono.ILASM { + + public interface IClassRef : ITypeRef { + + PEAPI.Class PeapiClass { get; } + + } + +} + diff --git a/mcs/ilasm/codegen/ITypeRef.cs b/mcs/ilasm/codegen/ITypeRef.cs new file mode 100644 index 00000000000..ffb7083ff83 --- /dev/null +++ b/mcs/ilasm/codegen/ITypeRef.cs @@ -0,0 +1,71 @@ +// +// Mono.ILASM.ITypeRef +// +// Interface that all Type references must implement +// +// Author(s): +// Jackson Harper (Jackson@LatitudeGeo.com) +// +// (C) 2003 Jackson Harper, All rights reserved +// + + +using System; +using System.Collections; + +namespace Mono.ILASM { + + public interface ITypeRef { + + /// + /// The full name of the type, . + /// ie System.Collections.ArrayList + /// + string FullName { get; } + + bool IsPinned { get; } + + /// + /// The PEAPI.Type of this typeref, this is not guaranteed + /// to be correct untill after this is resolved. + /// + PEAPI.Type PeapiType { get; } + + /// + /// Convert this typeref into a zero based array + /// + void MakeArray (); + + /// + /// Convert this typeref into a bound array. The ArrayList + /// should be in the format Entry (lower_bound, upper_bound) with + /// null being used for unset bounds. + /// + void MakeBoundArray (ArrayList bounds); + + /// + /// Convert this typeref into a reference + /// + void MakeManagedPointer (); + + /// + /// Convert this typeref into an unmanaged pointer + /// + void MakeUnmanagedPointer (); + + /// + /// Convert this typeref into a CustomModifiedType + /// + void MakeCustomModified (PEAPI.CustomModifier modifier); + + /// + /// Make this typeref pinned. + /// + void MakePinned (); + + void Resolve (CodeGen code_gen); + + } + +} + diff --git a/mcs/ilasm/codegen/TypeDef.cs b/mcs/ilasm/codegen/TypeDef.cs new file mode 100644 index 00000000000..b4837811ec5 --- /dev/null +++ b/mcs/ilasm/codegen/TypeDef.cs @@ -0,0 +1,102 @@ +// +// Mono.ILASM.TypeDef +// +// Author(s): +// Jackson Harper (Jackson@LatitudeGeo.com) +// +// (C) 2003 Jackson Harper, All rights reserved +// + + +using System; +using System.Collections; + +namespace Mono.ILASM { + + public class TypeDef { + + private PEAPI.TypeAttr attr; + private string name_space; + private string name; + private bool is_resolved; + private bool is_intransit; + private IClassRef parent; + private ArrayList impl_list; + private PEAPI.ClassDef classdef; + private ArrayList field_list; + + public TypeDef (PEAPI.TypeAttr attr, string name_space, string name, + IClassRef parent, ArrayList impl_list, Location location) + { + this.attr = attr; + this.name_space = name_space; + this.name = name; + this.parent = parent; + this.impl_list = impl_list; + field_list = new ArrayList (); + } + + public string FullName { + get { return MakeFullName (); } + } + + public PEAPI.ClassDef PeapiType { + get { return classdef; } + } + + public PEAPI.ClassDef ClassDef { + get { return classdef; } + } + + public bool IsResolved { + get { return is_resolved; } + } + + public void AddFieldDef (FieldDef fielddef) + { + field_list.Add (fielddef); + } + + public void Define (CodeGen code_gen) + { + if (is_resolved) + return; + + if (is_intransit) { + // Circular definition + throw new Exception ("Circular definition of class: " + this); + } + + is_intransit = true; + + if (parent != null) { + parent.Resolve (code_gen); + if (parent.PeapiClass == null) { + throw new Exception ("this type can not be a base type: " + + parent); + } + classdef = code_gen.PEFile.AddClass (attr, + name_space, name, parent.PeapiClass); + } else { + classdef = code_gen.PEFile.AddClass (attr, + name_space, name); + } + + foreach (FieldDef fielddef in field_list) { + fielddef.Define (code_gen, classdef); + } + + is_intransit = false; + } + + private string MakeFullName () + { + if (name_space == null || name_space == String.Empty) + return name; + + return name_space + "." + name; + } + } + +} + -- 2.25.1