Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,123 @@
//
// Mono.ILASM.Assembly
//
// Represents .assembly { }
//
// Author(s):
// Ankit Jain <JAnkit@novell.com>
//
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
namespace Mono.ILASM {
public class Assembly : IDeclSecurityTarget, ICustomAttrTarget
{
private DeclSecurity decl_sec;
private ArrayList customattr_list;
private string name;
private byte [] public_key;
private int major_version;
private int minor_version;
private int build_version;
private int revision_version;
private string locale;
private int hash_algorithm;
private PEAPI.AssemAttr attr;
public Assembly (string name)
{
this.name = name;
}
public string Name {
get { return name; }
}
public DeclSecurity DeclSecurity {
get {
if (decl_sec == null)
decl_sec = new DeclSecurity ();
return decl_sec;
}
}
public void SetVersion (int major, int minor, int build, int revision)
{
this.major_version = major;
this.minor_version = minor;
this.build_version = build;
this.revision_version = revision;
}
public void SetLocale (string locale)
{
this.locale = locale;
}
public void SetHashAlgorithm (int algorithm)
{
hash_algorithm = algorithm;
}
public void SetPublicKey (byte [] public_key)
{
this.public_key = public_key;
}
public void SetAssemblyAttr (PEAPI.AssemAttr attr)
{
this.attr = attr;
}
public void AddCustomAttribute (CustomAttr customattr)
{
if (customattr_list == null)
customattr_list = new ArrayList ();
customattr_list.Add (customattr);
}
public void Resolve (CodeGen code_gen, PEAPI.Assembly asm)
{
if (customattr_list != null)
foreach (CustomAttr customattr in customattr_list) {
customattr.AddTo (code_gen, asm);
}
if (decl_sec != null)
decl_sec.AddTo (code_gen, asm);
asm.AddAssemblyInfo(major_version,
minor_version, build_version,
revision_version, public_key,
(uint) hash_algorithm, locale);
asm.AddAssemblyAttr (attr);
}
}
}

View File

@@ -0,0 +1,69 @@
//
// Mono.ILASM.BaseClassRef
//
// Author(s):
// Ankit Jain <jankit@novell.com>
//
// Copyright 2006 Novell, Inc (http://www.novell.com)
//
using System;
using System.Collections;
namespace Mono.ILASM {
public abstract class BaseClassRef : BaseTypeRef {
protected Hashtable p_genericinst_table;
protected bool is_valuetype;
protected BaseClassRef (string full_name, bool is_valuetype)
: this (full_name, is_valuetype, null, null)
{
}
protected BaseClassRef (string full_name, bool is_valuetype, ArrayList conv_list, string sig_mod)
: base (full_name, conv_list, sig_mod)
{
this.is_valuetype = is_valuetype;
p_genericinst_table = null;
}
public PEAPI.Class PeapiClass {
get { return type as PEAPI.Class; }
}
public virtual void MakeValueClass ()
{
is_valuetype = true;
}
public virtual GenericTypeInst GetGenericTypeInst (GenericArguments gen_args)
{
return new GenericTypeInst (this, gen_args, is_valuetype);
}
public virtual PEAPI.Type ResolveInstance (CodeGen code_gen, GenericArguments gen_args)
{
PEAPI.GenericTypeInst gtri = null;
string sig = gen_args.ToString ();
if (p_genericinst_table == null)
p_genericinst_table = new Hashtable ();
else
gtri = p_genericinst_table [sig] as PEAPI.GenericTypeInst;
if (gtri == null) {
if (!IsResolved)
Resolve (code_gen);
gtri = new PEAPI.GenericTypeInst (PeapiType, gen_args.Resolve (code_gen));
p_genericinst_table [sig] = gtri;
}
return gtri;
}
}
}

View File

@@ -0,0 +1,42 @@
//
// Mono.ILASM.BaseGenericTypeRef
//
// Author(s):
// Ankit Jain <jankit@novell.com>
//
// Copyright 2006 Novell, Inc (http://www.novell.com)
//
using System;
using System.Collections;
namespace Mono.ILASM {
public abstract class BaseGenericTypeRef : BaseClassRef {
public BaseGenericTypeRef (string full_name, bool is_valuetype, ArrayList conv_list, string sig_mod)
: base (full_name, is_valuetype, conv_list, sig_mod)
{
}
/* Used to resolve any gen params in arguments, constraints etc */
public abstract void Resolve (GenericParameters type_gen_params, GenericParameters method_gen_params);
/* Only resolves, does not add it to the TypeSpec
table */
public abstract void ResolveNoTypeSpec (CodeGen code_gen);
public override GenericTypeInst GetGenericTypeInst (GenericArguments gen_args)
{
Report.Error ("Invalid attempt to create '" + FullName + "''" + gen_args.ToString () + "'");
return null;
}
public override PEAPI.Type ResolveInstance (CodeGen code_gen, GenericArguments gen_args)
{
Report.Error ("Invalid attempt to create '" + FullName + "''" + gen_args.ToString () + "'");
return null;
}
}
}

View File

@@ -0,0 +1,79 @@
//
// Mono.ILASM.BaseMethodRef
//
// Author(s):
// Ankit Jain <JAnkit@novell.com>
//
// Copyright 2006 Novell, Inc (http://www.novell.com)
//
using System;
using System.Collections;
namespace Mono.ILASM {
public abstract class BaseMethodRef {
protected BaseTypeRef owner;
protected PEAPI.CallConv call_conv;
protected BaseTypeRef ret_type;
protected string name;
protected BaseTypeRef[] param;
protected PEAPI.Method peapi_method;
protected bool is_resolved;
protected int gen_param_count;
protected Hashtable gen_method_table;
public BaseMethodRef (BaseTypeRef owner, PEAPI.CallConv call_conv,
BaseTypeRef ret_type, string name, BaseTypeRef[] param, int gen_param_count)
{
this.owner = owner;
this.call_conv = call_conv;
this.ret_type = ret_type;
this.name = name;
this.param = param;
this.gen_param_count = gen_param_count;
if (gen_param_count > 0)
CallConv |= PEAPI.CallConv.Generic;
is_resolved = false;
}
public virtual PEAPI.Method PeapiMethod {
get { return peapi_method; }
}
public virtual PEAPI.CallConv CallConv {
get { return call_conv; }
set { call_conv = value; }
}
public virtual BaseTypeRef Owner {
get { return owner; }
}
public abstract void Resolve (CodeGen code_gen);
public GenericMethodRef GetGenericMethodRef (GenericArguments gen_args)
{
GenericMethodRef methref = null;
if (gen_method_table == null)
gen_method_table = new Hashtable ();
else
methref = (GenericMethodRef) gen_method_table [gen_args.ToString ()];
if (methref == null) {
methref = new GenericMethodRef (this, GenericMethodSig.GetInstance (gen_args));
gen_method_table [gen_args.ToString ()] = methref;
}
return methref;
}
}
}

View File

@@ -0,0 +1,103 @@
//
// Mono.ILASM.BaseTypeRef
//
// Author(s):
// Ankit Jain <jankit@novell.com>
//
// Copyright 2006 Novell, Inc (http://www.novell.com)
//
using System;
using System.Collections;
namespace Mono.ILASM {
public abstract class BaseTypeRef : ModifiableType {
protected string full_name;
protected string sig_mod;
protected PEAPI.Type type;
protected bool is_resolved;
protected Hashtable method_table;
protected Hashtable field_table;
protected BaseTypeRef (string full_name)
: this (full_name, null, null)
{
}
protected BaseTypeRef (string full_name, ArrayList conv_list, string sig_mod)
{
this.full_name = full_name;
this.sig_mod = sig_mod;
is_resolved = false;
if (conv_list != null)
ConversionList = conv_list;
}
public virtual string FullName {
get { return full_name + sig_mod; }
}
public override string SigMod {
get { return sig_mod; }
set { sig_mod = value; }
}
public PEAPI.Type PeapiType {
get { return type; }
}
public bool IsResolved {
get { return is_resolved; }
}
public abstract void Resolve (CodeGen code_gen);
public abstract BaseTypeRef Clone ();
protected abstract BaseMethodRef CreateMethodRef (BaseTypeRef ret_type,
PEAPI.CallConv call_conv, string name, BaseTypeRef[] param, int gen_param_count);
public virtual BaseMethodRef GetMethodRef (BaseTypeRef ret_type,
PEAPI.CallConv call_conv, string name, BaseTypeRef[] param, int gen_param_count)
{
BaseMethodRef mr = null;
/* Note: FullName not reqd as this is cached per object */
string key = MethodDef.CreateSignature (ret_type, call_conv, name, param, gen_param_count, true);
if (method_table == null)
method_table = new Hashtable ();
else
mr = (BaseMethodRef) method_table [key];
if (mr == null) {
mr = CreateMethodRef (ret_type, call_conv, name, param, gen_param_count);
method_table [key] = mr;
}
return mr;
}
protected abstract IFieldRef CreateFieldRef (BaseTypeRef ret_type, string name);
public virtual IFieldRef GetFieldRef (BaseTypeRef ret_type, string name)
{
IFieldRef fr = null;
string key = ret_type.FullName + name;
if (field_table == null)
field_table = new Hashtable ();
else
fr = (IFieldRef) field_table [key];
if (fr == null) {
fr = CreateFieldRef (ret_type, name);
field_table [key] = fr;
}
return fr;
}
}
}

View File

@@ -0,0 +1,36 @@
//
// Mono.ILASM.BranchInstr
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
namespace Mono.ILASM {
public class BranchInstr : IInstr {
private PEAPI.BranchOp op;
private LabelInfo label;
public BranchInstr (PEAPI.BranchOp op, LabelInfo label, Location loc)
: base (loc)
{
this.op = op;
this.label = label;
}
public override void Emit (CodeGen code_gen, MethodDef meth,
PEAPI.CILInstructions cil)
{
cil.Branch (op, label.Label);
}
}
}

View File

@@ -0,0 +1,56 @@
//
// Mono.ILASM.CalliInstr
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
namespace Mono.ILASM {
public class CalliInstr : IInstr {
private PEAPI.CallConv call_conv;
private BaseTypeRef ret_type;
private BaseTypeRef[] param;
public CalliInstr (PEAPI.CallConv call_conv, BaseTypeRef ret_type,
BaseTypeRef[] param, Location loc)
: base (loc)
{
this.call_conv = call_conv;
this.ret_type = ret_type;
this.param = param;
}
public override void Emit (CodeGen code_gen, MethodDef meth,
PEAPI.CILInstructions cil)
{
PEAPI.Type[] param_array;
PEAPI.CalliSig callisig;
if (param != null) {
param_array = new PEAPI.Type[param.Length];
int count = 0;
foreach (BaseTypeRef typeref in param) {
typeref.Resolve (code_gen);
param_array[count++] = typeref.PeapiType;
}
} else {
param_array = new PEAPI.Type[0];
}
ret_type.Resolve (code_gen);
callisig = new PEAPI.CalliSig (call_conv,
ret_type.PeapiType, param_array);
cil.calli (callisig);
}
}
}

View File

@@ -0,0 +1,45 @@
//
// Mono.ILASM.CatchBlock
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
namespace Mono.ILASM {
public class CatchBlock : ISehClause {
private BaseTypeRef type_ref;
private HandlerBlock handler_block;
public CatchBlock (BaseTypeRef type_ref)
{
this.type_ref = type_ref;
}
public void SetHandlerBlock (HandlerBlock hb)
{
handler_block = hb;
}
public PEAPI.HandlerBlock Resolve (CodeGen code_gen, MethodDef method)
{
PEAPI.CILLabel from = handler_block.GetFromLabel (code_gen, method);
PEAPI.CILLabel to = handler_block.GetToLabel (code_gen, method);
PEAPI.Catch katch;
type_ref.Resolve (code_gen);
katch = new PEAPI.Catch (type_ref.PeapiType, from, to);
return katch;
}
}
}

1926
mcs/ilasm/codegen/ChangeLog Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,58 @@
//
// Mono.ILASM.CustomAttr
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
using System.Collections;
namespace Mono.ILASM {
public interface ICustomAttrTarget {
void AddCustomAttribute (CustomAttr customattr);
}
public class CustomAttr {
private BaseMethodRef method_ref;
private byte[] data;
public CustomAttr (BaseMethodRef method_ref, byte[] data)
{
this.method_ref = method_ref;
this.data = data;
}
public void AddTo (CodeGen code_gen, PEAPI.MetaDataElement elem)
{
method_ref.Resolve (code_gen);
code_gen.PEFile.AddCustomAttribute (method_ref.PeapiMethod, data, elem);
}
public bool IsSuppressUnmanaged (CodeGen codegen)
{
string asmname = "";
BaseTypeRef owner = method_ref.Owner;
if (owner == null)
return false;
ExternTypeRef etr = owner as ExternTypeRef;
if (etr != null) {
ExternAssembly ea = etr.ExternRef as ExternAssembly;
if (ea != null)
asmname = ea.Name;
}
return (owner.FullName == "System.Security.SuppressUnmanagedCodeSecurityAttribute"
&& (asmname == "mscorlib" || codegen.IsThisAssembly ("mscorlib")) );
}
}
}

View File

@@ -0,0 +1,40 @@
//
// Mono.ILASM.DataDef
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
namespace Mono.ILASM {
public class DataDef {
private string name;
private bool is_tls;
private PEAPI.Constant constant;
public DataDef (string name, bool is_tls)
{
this.name = name;
this.is_tls = is_tls;
}
public PEAPI.Constant PeapiConstant {
get { return constant; }
set { constant = value; }
}
public string Name {
get { return name; }
set { name = value; }
}
}
}

View File

@@ -0,0 +1,107 @@
//
// Mono.ILASM.DebuggingInfo.cs
//
// Author(s):
// Martin Baulig (martin@ximian.com)
//
// Copyright (C) 2004 Novell, Inc.
//
using PEAPI;
using System;
using System.IO;
using System.Collections;
using Mono.CompilerServices.SymbolWriter;
namespace Mono.ILASM {
public class SymbolWriter : MonoSymbolWriter
{
Mono.ILASM.SourceMethod current_method;
CompileUnitEntry current_source;
ArrayList methods;
public SymbolWriter (string filename)
: base (filename)
{
methods = new ArrayList ();
}
public Mono.ILASM.SourceMethod BeginMethod (MethodDef method, Location start)
{
current_method = new Mono.ILASM.SourceMethod (current_source, method, start);
methods.Add (current_method);
return current_method;
}
public void EndMethod (Location end)
{
current_method.EndLine = end.line;
current_method = null;
}
public void BeginSourceFile (string filename)
{
SourceFileEntry file = DefineDocument (filename, null, null);
current_source = DefineCompilationUnit (file);
}
public void EndSourceFile ()
{
current_source = null;
}
public void Write (Guid guid)
{
foreach (Mono.ILASM.SourceMethod method in methods)
method.Write (this);
WriteSymbolFile (guid);
}
}
public class SourceMethod : IMethodDef
{
CompileUnitEntry file;
MethodDef method;
ArrayList lines;
public int StartLine, EndLine;
public SourceMethod (CompileUnitEntry file, MethodDef method, Location start)
{
this.file = file;
this.method = method;
this.StartLine = start.line;
lines = new ArrayList ();
MarkLocation (start.line, 0);
}
public string Name {
get { return method.Name; }
}
public int Token {
get {
PEAPI.MethodDef pemethod = method.PeapiMethodDef;
return (int) (((uint) PEAPI.MDTable.Method << 24) | pemethod.Row);
}
}
public void MarkLocation (int line, uint offset)
{
lines.Add (new LineNumberEntry (0, line, (int) offset));
}
public void Write (MonoSymbolWriter writer)
{
LineNumberEntry[] the_lines = new LineNumberEntry [lines.Count];
lines.CopyTo (the_lines, 0);
LocalVariableEntry[] locals = method.GetLocalVars ();
MethodEntry entry = writer.SymbolFile.DefineMethod (
file, Token, null, locals, the_lines, null, null, 0, 0);
}
}
}

View File

@@ -0,0 +1,105 @@
//
// Mono.ILASM.DeclSecurity
//
// Author(s):
// Ankit Jain <JAnkit@novell.com>
//
// (C) 2005 Ankit Jain, All rights reserved
//
using System;
using System.Collections;
using System.Security;
using System.Security.Permissions;
using SSPermissionSet = System.Security.PermissionSet;
using MIPermissionSet = Mono.ILASM.PermissionSet;
namespace Mono.ILASM {
public interface IDeclSecurityTarget {
DeclSecurity DeclSecurity { get; }
}
public class DeclSecurity {
private Hashtable permissionset_table;
private Hashtable permissionset20_table;
public DeclSecurity ()
{
permissionset_table = new Hashtable ();
}
public void AddPermission (PEAPI.SecurityAction sec_action, IPermission perm)
{
SSPermissionSet ps = (SSPermissionSet) permissionset_table [sec_action];
if (ps == null) {
ps = new SSPermissionSet (PermissionState.None);
permissionset_table [sec_action] = ps;
}
ps.AddPermission (perm);
}
public void AddPermissionSet (PEAPI.SecurityAction sec_action, SSPermissionSet perm_set)
{
SSPermissionSet ps = (SSPermissionSet) permissionset_table [sec_action];
if (ps == null) {
permissionset_table [sec_action] = perm_set;
return;
}
foreach (IPermission iper in perm_set)
ps.AddPermission (iper);
}
//Not called by parser for profile != NET_2_0
public void AddPermissionSet (PEAPI.SecurityAction sec_action, MIPermissionSet perm_set)
{
PermissionSet ps = null;
if (permissionset20_table == null)
permissionset20_table = new Hashtable ();
else
ps = (MIPermissionSet) permissionset20_table [sec_action];
if (ps == null) {
permissionset20_table [sec_action] = perm_set;
return;
}
foreach (Permission perm in perm_set.Permissions)
ps.AddPermission (perm);
}
public void AddTo (CodeGen code_gen, PEAPI.MetaDataElement elem)
{
System.Text.UnicodeEncoding ue = new System.Text.UnicodeEncoding ();
foreach (DictionaryEntry entry in permissionset_table) {
PEAPI.SecurityAction sec_action = (PEAPI.SecurityAction) entry.Key;
SSPermissionSet ps = (SSPermissionSet) entry.Value;
code_gen.PEFile.AddDeclSecurity (sec_action,
ue.GetBytes (ps.ToXml ().ToString ()),
elem);
}
if (permissionset20_table == null)
return;
foreach (DictionaryEntry entry in permissionset20_table) {
PEAPI.SecurityAction sec_action = (PEAPI.SecurityAction) entry.Key;
MIPermissionSet ps = (MIPermissionSet) entry.Value;
code_gen.PEFile.AddDeclSecurity (sec_action,
ps.Resolve (code_gen),
elem);
}
}
}
}

View File

@@ -0,0 +1,34 @@
//
// Mono.ILASM.EmitByteIntr.cs
//
// Author(s):
// Rodrigo Kumpera (rkumpera@novell.com)
//
// (C) 2007 Novell, Inc (http://www.novell.com)
//
using System;
using System.Collections;
namespace Mono.ILASM {
public class EmitByteInstr : IInstr {
private int value;
public EmitByteInstr (int value, Location loc)
: base (loc)
{
this.value = value;
}
public override void Emit (CodeGen code_gen, MethodDef meth,
PEAPI.CILInstructions cil)
{
cil.emitbyte ((byte)value);
}
}
}

View File

@@ -0,0 +1,130 @@
//
// Mono.ILASM.EventDef
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All right reserved
//
using System;
using System.Collections;
namespace Mono.ILASM {
public class EventDef : ICustomAttrTarget {
private FeatureAttr attr;
private string name;
private BaseTypeRef type;
private PEAPI.Event event_def;
private bool is_resolved;
private ArrayList customattr_list;
private MethodRef addon;
private MethodRef fire;
private ArrayList other_list;
private MethodRef removeon;
public EventDef (FeatureAttr attr, BaseTypeRef type, string name)
{
this.attr = attr;
this.name = name;
this.type = type;
is_resolved = false;
}
public void AddCustomAttribute (CustomAttr customattr)
{
if (customattr_list == null)
customattr_list = new ArrayList ();
customattr_list.Add (customattr);
}
public PEAPI.Event Resolve (CodeGen code_gen, PEAPI.ClassDef classdef)
{
if (is_resolved)
return event_def;
type.Resolve (code_gen);
event_def = classdef.AddEvent (name, type.PeapiType);
if ((attr & FeatureAttr.Rtspecialname) != 0)
event_def.SetRTSpecialName ();
if ((attr & FeatureAttr.Specialname) != 0)
event_def.SetSpecialName ();
if (customattr_list != null)
foreach (CustomAttr customattr in customattr_list)
customattr.AddTo (code_gen, event_def);
is_resolved = true;
return event_def;
}
private PEAPI.MethodDef AsMethodDef (PEAPI.Method method, string type)
{
PEAPI.MethodDef methoddef = method as PEAPI.MethodDef;
if (methoddef == null)
Report.Error (type + " method of event " + name + " not found");
return methoddef;
}
public void Define (CodeGen code_gen, PEAPI.ClassDef classdef)
{
if (!is_resolved)
Resolve (code_gen, classdef);
if (addon != null) {
addon.Resolve (code_gen);
event_def.AddAddon (AsMethodDef (addon.PeapiMethod, "addon"));
}
if (fire != null) {
fire.Resolve (code_gen);
event_def.AddFire (AsMethodDef (fire.PeapiMethod, "fire"));
}
if (other_list != null) {
foreach (MethodRef otherm in other_list) {
otherm.Resolve (code_gen);
event_def.AddOther (AsMethodDef (otherm.PeapiMethod, "other"));
}
}
if (removeon != null) {
removeon.Resolve (code_gen);
event_def.AddRemoveOn (AsMethodDef (removeon.PeapiMethod, "removeon"));
}
}
public void AddAddon (MethodRef method_ref)
{
addon = method_ref;
}
public void AddFire (MethodRef method_ref)
{
fire = method_ref;
}
public void AddOther (MethodRef method_ref)
{
if (other_list == null)
other_list = new ArrayList ();
other_list.Add (method_ref);
}
public void AddRemoveon (MethodRef method_ref)
{
removeon = method_ref;
}
}
}

View File

@@ -0,0 +1,60 @@
//
// Mono.ILASM.ExternFieldRef
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
namespace Mono.ILASM {
public class ExternFieldRef : IFieldRef {
private ExternTypeRef owner;
private BaseTypeRef type;
private string name;
private bool is_resolved;
private PEAPI.FieldRef peapi_field;
public ExternFieldRef (ExternTypeRef owner, BaseTypeRef type, string name)
{
this.owner = owner;
this.type = type;
this.name = name;
is_resolved = false;
}
public PEAPI.Field PeapiField {
get { return peapi_field; }
}
public void Resolve (CodeGen code_gen)
{
if (is_resolved)
return;
owner.Resolve (code_gen);
if (owner.UseTypeSpec) {
PEAPI.Type owner_ref = owner.PeapiType;
code_gen.PEFile.AddFieldToTypeSpec (owner_ref, name,
type.PeapiType);
} else {
PEAPI.ClassRef owner_ref;
owner_ref = (PEAPI.ClassRef) owner.PeapiType;
type.Resolve (code_gen);
peapi_field = owner_ref.AddField (name, type.PeapiType);
}
is_resolved = true;
}
}
}

View File

@@ -0,0 +1,125 @@
//
// Mono.ILASM.ExternMethodRef
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
using System.Collections;
namespace Mono.ILASM {
public class ExternMethodRef : BaseMethodRef {
public ExternMethodRef (ExternTypeRef owner, BaseTypeRef ret_type,
PEAPI.CallConv call_conv, string name, BaseTypeRef[] param, int gen_param_count)
: base (owner, call_conv, ret_type, name, param, gen_param_count)
{
}
public override void Resolve (CodeGen code_gen)
{
if (is_resolved)
return;
if ((call_conv & PEAPI.CallConv.Vararg) != 0) {
ResolveVararg (code_gen);
return;
}
PEAPI.Type[] param_list = new PEAPI.Type[param.Length];
string write_name;
ret_type.Resolve (code_gen);
int count = 0;
foreach (BaseTypeRef typeref in param) {
typeref.Resolve (code_gen);
param_list[count++] = typeref.PeapiType;
}
if (name == "<init>")
write_name = ".ctor";
else
write_name = name;
owner.Resolve (code_gen);
if (owner.UseTypeSpec) {
PEAPI.Type owner_ref = owner.PeapiType;
peapi_method = code_gen.PEFile.AddMethodToTypeSpec (owner_ref, write_name,
ret_type.PeapiType, param_list, gen_param_count);
} else {
PEAPI.ClassRef owner_ref;
owner_ref = (PEAPI.ClassRef) owner.PeapiType;
peapi_method = owner_ref.AddMethod (write_name,
ret_type.PeapiType, param_list, gen_param_count);
}
peapi_method.AddCallConv (call_conv);
is_resolved = true;
}
protected void ResolveVararg (CodeGen code_gen)
{
if (is_resolved)
return;
ArrayList param_list = new ArrayList ();
ArrayList opt_list = new ArrayList ();
bool in_opt = false;
string write_name;
ret_type.Resolve (code_gen);
foreach (BaseTypeRef typeref in param) {
if (in_opt) {
typeref.Resolve (code_gen);
opt_list.Add (typeref.PeapiType);
} else if (typeref is SentinelTypeRef) {
in_opt = true;
} else {
typeref.Resolve (code_gen);
param_list.Add (typeref.PeapiType);
}
}
if (name == "<init>")
write_name = ".ctor";
else
write_name = name;
if (owner.IsArray)
Report.Error ("Vararg methods on arrays are not supported yet.");
owner.Resolve (code_gen);
if (owner.UseTypeSpec) {
PEAPI.Type owner_ref = owner.PeapiType;
peapi_method = code_gen.PEFile.AddVarArgMethodToTypeSpec (owner_ref,
write_name, ret_type.PeapiType,
(PEAPI.Type[]) param_list.ToArray (typeof (PEAPI.Type)),
(PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)));
} else {
PEAPI.ClassRef owner_ref;
owner_ref = (PEAPI.ClassRef) owner.PeapiType;
peapi_method = owner_ref.AddVarArgMethod (write_name,
ret_type.PeapiType,
(PEAPI.Type[]) param_list.ToArray (typeof (PEAPI.Type)),
(PEAPI.Type[]) opt_list.ToArray (typeof (PEAPI.Type)));
}
peapi_method.AddCallConv (call_conv);
is_resolved = true;
}
}
}

View File

@@ -0,0 +1,435 @@
//
// Mono.ILASM.ExternTable.cs
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Security;
using System.Globalization;
using PEAPI;
namespace Mono.ILASM {
public interface IScope {
ExternTypeRef GetTypeRef (string full_name, bool is_valuetype);
PEAPI.ClassRef GetType (string full_name, bool is_valuetype);
string FullName { get; }
}
public abstract class ExternRef : ICustomAttrTarget, IScope {
protected string name;
protected Hashtable class_table;
protected Hashtable typeref_table;
protected ArrayList customattr_list;
protected bool is_resolved;
public abstract void Resolve (CodeGen codegen);
public abstract PEAPI.IExternRef GetExternRef ();
public ExternRef (string name)
{
this.name = name;
typeref_table = new Hashtable ();
class_table = new Hashtable ();
}
public string Name {
get { return name; }
}
public virtual string FullName {
get { return name; }
}
public void AddCustomAttribute (CustomAttr customattr)
{
if (customattr_list == null)
customattr_list = new ArrayList ();
customattr_list.Add (customattr);
}
public ExternTypeRef GetTypeRef (string full_name, bool is_valuetype)
{
string first= full_name;
string rest = "";
int slash = full_name.IndexOf ('/');
if (slash > 0) {
first = full_name.Substring (0, slash);
rest = full_name.Substring (slash + 1);
}
ExternTypeRef type_ref = typeref_table [first] as ExternTypeRef;
if (type_ref != null) {
if (is_valuetype && rest == "")
type_ref.MakeValueClass ();
} else {
type_ref = new ExternTypeRef (this, first, is_valuetype);
typeref_table [first] = type_ref;
}
return (rest == "" ? type_ref : type_ref.GetTypeRef (rest, is_valuetype));
}
public PEAPI.ClassRef GetType (string full_name, bool is_valuetype)
{
PEAPI.ClassRef klass = class_table[full_name] as PEAPI.ClassRef;
if (klass != null)
return klass;
string name_space, name;
ExternTable.GetNameAndNamespace (full_name, out name_space, out name);
if (is_valuetype)
klass = (PEAPI.ClassRef) GetExternRef ().AddValueClass (name_space, name);
else
klass = (PEAPI.ClassRef) GetExternRef ().AddClass (name_space, name);
class_table [full_name] = klass;
return klass;
}
}
public class ExternModule : ExternRef {
public PEAPI.ModuleRef ModuleRef;
public ExternModule (string name) : base (name)
{
}
public override string FullName {
get {
//'name' field should not contain the [.module ]
//as its used for resolving
return String.Format ("[.module {0}]", name);
}
}
public override void Resolve (CodeGen codegen)
{
if (is_resolved)
return;
ModuleRef = codegen.PEFile.AddExternModule (name);
if (customattr_list != null)
foreach (CustomAttr customattr in customattr_list)
customattr.AddTo (codegen, ModuleRef);
is_resolved = true;
}
public override PEAPI.IExternRef GetExternRef ()
{
return ModuleRef;
}
}
public class ExternAssembly : ExternRef, IDeclSecurityTarget {
public PEAPI.AssemblyRef AssemblyRef;
private int major, minor, build, revision;
private byte [] public_key;
private byte [] public_key_token;
private string locale;
private byte [] hash;
private DeclSecurity decl_sec;
private AssemblyName asmb_name;
//flags
private PEAPI.AssemAttr attr;
public ExternAssembly (string name, AssemblyName asmb_name, PEAPI.AssemAttr attr) : base (name)
{
this.name = name;
this.asmb_name = asmb_name;
this.attr = attr;
major = minor = build = revision = -1;
}
public override string FullName {
get {
//'name' field should not contain the []
//as its used for resolving
return String.Format ("[{0}]", name);
}
}
public AssemblyName AssemblyName {
get { return asmb_name; }
}
public DeclSecurity DeclSecurity {
get {
if (decl_sec == null)
decl_sec = new DeclSecurity ();
return decl_sec;
}
}
public override void Resolve (CodeGen code_gen)
{
if (is_resolved)
return;
AssemblyRef = code_gen.PEFile.AddExternAssembly (name);
AssemblyRef.AddAssemblyAttr (attr);
if (major != -1)
AssemblyRef.AddVersionInfo (major, minor, build, revision);
if (public_key != null)
AssemblyRef.AddKey (public_key);
if (public_key_token != null)
AssemblyRef.AddKeyToken (public_key_token);
if (locale != null)
AssemblyRef.AddCulture (locale);
if (hash != null)
AssemblyRef.AddHash (hash);
if (customattr_list != null)
foreach (CustomAttr customattr in customattr_list)
customattr.AddTo (code_gen, AssemblyRef);
if (decl_sec != null)
decl_sec.AddTo (code_gen, AssemblyRef);
class_table = new Hashtable ();
is_resolved = true;
}
public override PEAPI.IExternRef GetExternRef ()
{
return AssemblyRef;
}
public void SetVersion (int major, int minor, int build, int revision)
{
this.major = major;
this.minor = minor;
this.build = build;
this.revision = revision;
asmb_name.Version = new Version (major, minor, build, revision);
}
public void SetPublicKey (byte [] public_key)
{
this.public_key = public_key;
asmb_name.SetPublicKey (public_key);
}
public void SetPublicKeyToken (byte [] public_key_token)
{
this.public_key_token = public_key_token;
asmb_name.SetPublicKey (public_key);
}
public void SetLocale (string locale)
{
this.locale = locale;
//FIXME: is this correct?
asmb_name.CultureInfo = new CultureInfo (locale);
}
public void SetHash (byte [] hash)
{
this.hash = hash;
}
}
public class ExternClass
{
string fullName;
TypeAttr ta;
string assemblyReference;
public ExternClass (string fullName, TypeAttr ta, string assemblyReference)
{
this.fullName = fullName;
this.ta = ta;
this.assemblyReference = assemblyReference;
}
public void Resolve (CodeGen code_gen, ExternTable table)
{
var ar = table.GetAssemblyRef (assemblyReference);
if (ar != null) {
string ns = null;
string name = fullName;
int pos = name.LastIndexOf ('.');
if (pos > 0) {
ns = name.Substring (0, pos);
name = name.Substring (pos + 1);
}
code_gen.PEFile.AddExternClass (ns, name, ta, ar.AssemblyRef);
}
}
}
public class ExternTable {
Hashtable assembly_table;
Hashtable module_table;
List<ExternClass> class_table;
bool is_resolved;
public void AddCorlib ()
{
// Add mscorlib
string mscorlib_name = "mscorlib";
AssemblyName mscorlib = new AssemblyName ();
mscorlib.Name = mscorlib_name;
AddAssembly (mscorlib_name, mscorlib, 0);
// Also need to alias corlib, normally corlib and
// mscorlib are used interchangably
assembly_table["corlib"] = assembly_table["mscorlib"];
}
public ExternAssembly AddAssembly (string name, AssemblyName asmb_name, PEAPI.AssemAttr attr)
{
ExternAssembly ea = null;
if (assembly_table == null) {
assembly_table = new Hashtable ();
} else {
ea = assembly_table [name] as ExternAssembly;
if (ea != null)
return ea;
}
ea = new ExternAssembly (name, asmb_name, attr);
assembly_table [name] = ea;
return ea;
}
public ExternModule AddModule (string name)
{
ExternModule em = null;
if (module_table == null) {
module_table = new Hashtable ();
} else {
em = module_table [name] as ExternModule;
if (em != null)
return em;
}
em = new ExternModule (name);
module_table [name] = em;
return em;
}
public void AddClass (string name, TypeAttr ta, string assemblyReference)
{
if (class_table == null)
class_table = new List<ExternClass> ();
class_table.Add (new ExternClass (name, ta, assemblyReference));
}
public void Resolve (CodeGen code_gen)
{
if (is_resolved)
return;
if (assembly_table != null)
foreach (ExternAssembly ext in assembly_table.Values)
ext.Resolve (code_gen);
if (module_table != null)
foreach (ExternModule ext in module_table.Values)
ext.Resolve (code_gen);
if (class_table != null)
foreach (var entry in class_table)
entry.Resolve (code_gen, this);
is_resolved = true;
}
public ExternTypeRef GetTypeRef (string asmb_name, string full_name, bool is_valuetype)
{
ExternAssembly ext_asmb = null;
if (assembly_table == null && (asmb_name == "mscorlib" || asmb_name == "corlib")) {
/* AddCorlib if mscorlib is being referenced but
we haven't encountered a ".assembly 'name'" as yet. */
Report.Warning (String.Format ("Reference to undeclared extern assembly '{0}', adding.", asmb_name));
AddCorlib ();
}
if (assembly_table != null)
ext_asmb = assembly_table[asmb_name] as ExternAssembly;
if (ext_asmb == null) {
System.Reflection.AssemblyName asmname = new System.Reflection.AssemblyName ();
asmname.Name = asmb_name;
Report.Warning (String.Format ("Reference to undeclared extern assembly '{0}', adding.", asmb_name));
ext_asmb = AddAssembly (asmb_name, asmname, 0);
}
return ext_asmb.GetTypeRef (full_name, is_valuetype);
}
public ExternTypeRef GetModuleTypeRef (string mod_name, string full_name, bool is_valuetype)
{
ExternModule mod = null;
if (module_table != null)
mod = module_table [mod_name] as ExternModule;
if (mod == null)
Report.Error ("Module " + mod_name + " not defined.");
return mod.GetTypeRef (full_name, is_valuetype);
}
public ExternAssembly GetAssemblyRef (string assembly_name)
{
ExternAssembly ass = null;
if (assembly_table != null)
ass = assembly_table [assembly_name] as ExternAssembly;
if (ass == null)
Report.Error ("Assembly " + assembly_name + " is not defined.");
return ass;
}
public static void GetNameAndNamespace (string full_name,
out string name_space, out string name) {
int last_dot = full_name.LastIndexOf ('.');
if (last_dot < 0) {
name_space = String.Empty;
name = full_name;
return;
}
name_space = full_name.Substring (0, last_dot);
name = full_name.Substring (last_dot + 1);
}
}
}

View File

@@ -0,0 +1,160 @@
//
// Mono.ILASM.ExternTypeRef
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
using System.Collections;
namespace Mono.ILASM {
/// <summary>
/// A reference to a type in another assembly
/// </summary>
public class ExternTypeRef : BaseClassRef , IScope {
private IScope extern_ref;
private Hashtable nestedtypes_table;
private Hashtable nestedclass_table;
public ExternTypeRef (IScope extern_ref, string full_name, bool is_valuetype)
: this (extern_ref, full_name, is_valuetype, null, null)
{
}
private ExternTypeRef (IScope extern_ref, string full_name,
bool is_valuetype, ArrayList conv_list, string sig_mod)
: base (full_name, is_valuetype, conv_list, sig_mod)
{
this.extern_ref = extern_ref;
nestedclass_table = new Hashtable ();
nestedtypes_table = new Hashtable ();
}
public override BaseTypeRef Clone ()
{
return new ExternTypeRef (extern_ref, full_name, is_valuetype,
(ArrayList) ConversionList.Clone (), sig_mod);
}
public override string FullName {
get {
if (extern_ref == null)
return full_name + sig_mod;
else
return extern_ref.FullName + (extern_ref is ExternTypeRef ? "/" : "") + full_name + sig_mod;
}
}
public string Name {
get { return full_name + sig_mod; }
}
public IScope ExternRef {
get { return extern_ref; }
}
public override void Resolve (CodeGen code_gen)
{
if (is_resolved)
return;
ExternTypeRef etr = extern_ref as ExternTypeRef;
if (etr != null)
//This is a nested class, so resolve parent
etr.Resolve (code_gen);
type = extern_ref.GetType (full_name, is_valuetype);
type = Modify (code_gen, type);
is_resolved = true;
}
protected override BaseMethodRef CreateMethodRef (BaseTypeRef ret_type, PEAPI.CallConv call_conv,
string name, BaseTypeRef[] param, int gen_param_count)
{
return new ExternMethodRef (this, ret_type, call_conv, name, param, gen_param_count);
}
protected override IFieldRef CreateFieldRef (BaseTypeRef ret_type, string name)
{
return new ExternFieldRef (this, ret_type, name);
}
public ExternTypeRef GetTypeRef (string _name, bool is_valuetype)
{
string first= _name;
string rest = "";
int slash = _name.IndexOf ('/');
if (slash > 0) {
first = _name.Substring (0, slash);
rest = _name.Substring (slash + 1);
}
ExternTypeRef ext_typeref = nestedtypes_table [first] as ExternTypeRef;
if (ext_typeref != null) {
if (is_valuetype && rest == "")
ext_typeref.MakeValueClass ();
} else {
ext_typeref = new ExternTypeRef (this, first, is_valuetype);
nestedtypes_table [first] = ext_typeref;
}
return (rest == "" ? ext_typeref : ext_typeref.GetTypeRef (rest, is_valuetype));
}
public PEAPI.IExternRef GetExternTypeRef ()
{
//called by GetType for a nested type
//should this cant be 'modified' type, so it should
//be ClassRef
return (PEAPI.ClassRef) type;
}
public PEAPI.ClassRef GetType (string _name, bool is_valuetype)
{
PEAPI.ClassRef klass = nestedclass_table [_name] as PEAPI.ClassRef;
if (klass != null)
return klass;
string name_space, name;
ExternTable.GetNameAndNamespace (_name, out name_space, out name);
if (is_valuetype)
klass = (PEAPI.ClassRef) GetExternTypeRef ().AddValueClass (name_space, name);
else
klass = (PEAPI.ClassRef) GetExternTypeRef ().AddClass (name_space, name);
nestedclass_table [_name] = klass;
return klass;
}
public System.Type GetReflectedType ()
{
ExternRef er = extern_ref as ExternRef;
if (er != null) {
ExternAssembly ea = er as ExternAssembly;
if (ea != null) {
System.Reflection.Assembly asm = System.Reflection.Assembly.Load (ea.Name);
//Type name required here, so don't use FullName
return asm.GetType (Name);
}/* else ExternModule */
} /*else - nested type? */
return null;
}
}
}

Some files were not shown because too many files have changed in this diff Show More