* ExternTypeRef.cs: New file - Represents a reference to a type in
authorJackson Harper <jackson@novell.com>
Fri, 18 Apr 2003 03:52:17 +0000 (03:52 -0000)
committerJackson Harper <jackson@novell.com>
Fri, 18 Apr 2003 03:52:17 +0000 (03:52 -0000)
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
mcs/ilasm/codegen/ExternTypeRef.cs [new file with mode: 0644]
mcs/ilasm/codegen/FieldDef.cs [new file with mode: 0644]
mcs/ilasm/codegen/IClassRef.cs [new file with mode: 0644]
mcs/ilasm/codegen/ITypeRef.cs [new file with mode: 0644]
mcs/ilasm/codegen/TypeDef.cs [new file with mode: 0644]

index 97370d3fe7554bb1980af9312d48707e7e6060e7..ba83522eb745f07eb4654124d70a82f058f3c86b 100644 (file)
@@ -1,3 +1,16 @@
+2003-04-17 Jackson Harper <jackson@latitudegeo.com>
+
+       * 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 <jackson@latitudegeo.com>
 
        * 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 (file)
index 0000000..ef719a2
--- /dev/null
@@ -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 {
+
+        /// <summary>
+        /// A reference to a type in another assembly
+        /// </summary>
+        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 (file)
index 0000000..af3074a
--- /dev/null
@@ -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;
+                }
+
+                /// <summary>
+                ///  Define a global field
+                /// </summary>
+                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);
+
+                        }
+                }
+
+                /// <summary>
+                ///  Define a field member of the specified class
+                /// </summary>
+                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 (file)
index 0000000..af434fe
--- /dev/null
@@ -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 (file)
index 0000000..ffb7083
--- /dev/null
@@ -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 {
+
+                /// <summary>
+                ///  The full name of the type, <namespace>.<name>
+                /// ie System.Collections.ArrayList
+                /// </summary>
+                string FullName { get; }
+
+                bool IsPinned { get; }
+
+                /// <summary>
+                ///  The PEAPI.Type of this typeref, this is not guaranteed
+                ///  to be correct untill after this is resolved.
+                /// </summary>
+                PEAPI.Type PeapiType { get; }
+
+                /// <summary>
+                ///  Convert this typeref into a zero based array
+                /// </summary>
+                void MakeArray ();
+
+                /// <summary>
+                ///  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.
+                /// </summary>
+                void MakeBoundArray (ArrayList bounds);
+
+                /// <summary>
+                ///  Convert this typeref into a reference
+                /// </summary>
+                void MakeManagedPointer ();
+
+                /// <summary>
+                ///  Convert this typeref into an unmanaged pointer
+                /// </summary>
+                void MakeUnmanagedPointer ();
+
+                /// <summary>
+                ///  Convert this typeref into a CustomModifiedType
+                /// </summary>
+                void MakeCustomModified (PEAPI.CustomModifier modifier);
+
+                /// <summary>
+                ///  Make this typeref pinned.
+                /// </summary>
+                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 (file)
index 0000000..b483781
--- /dev/null
@@ -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;
+                }
+        }
+
+}
+