//
// Author: Miguel de Icaza (miguel@gnu.org)
// Ravi Pratap (ravi@ximian.com)
+// Marek Safar (marek.safar@seznam.cz)
//
// Licensed under the terms of the GNU GPL
//
static public Type conditional_attribute_type;
static public Type in_attribute_type;
static public Type out_attribute_type;
+ static public Type default_parameter_value_attribute_type;
+
static public Type anonymous_method_type;
static public Type cls_compliant_attribute_type;
static public Type typed_reference_type;
static public Type required_attr_type;
static public Type guid_attr_type;
static public Type assembly_culture_attribute_type;
+ static public Type coclass_attr_type;
+ static public Type comimport_attr_type;
///
/// .NET 2.0
static internal Type default_charset_type;
#endif
- //
- // An empty array of types
- //
- static public Type [] NoTypes;
- static public TypeExpr [] NoTypeExprs;
-
-
//
// Expressions representing the internal types. Used during declaration
// definition.
// The attribute constructors.
//
static public ConstructorInfo object_ctor;
- static public ConstructorInfo cons_param_array_attribute;
+ static private ConstructorInfo cons_param_array_attribute;
static public ConstructorInfo void_decimal_ctor_five_args;
static public ConstructorInfo void_decimal_ctor_int_arg;
static public ConstructorInfo unverifiable_code_ctor;
// </remarks>
static PtrHashtable builder_to_ifaces;
- // <remarks>
- // Maps MethodBase.RuntimeTypeHandle to a Type array that contains
- // the arguments to the method
- // </remarks>
- static Hashtable method_arguments;
-
// <remarks>
// Maps PropertyBuilder to a Type array that contains
// the arguments to the indexer
public static Hashtable AllClsTopLevelTypes;
static Hashtable fieldbuilders_to_fields;
+ static Hashtable propertybuilder_to_property;
static Hashtable fields;
+ static Hashtable events;
struct Signature {
public string name;
builder_to_declspace = null;
builder_to_member_cache = null;
builder_to_ifaces = null;
- method_arguments = null;
indexer_arguments = null;
method_params = null;
builder_to_method = null;
events = null;
priv_fields_events = null;
type_hash = null;
+ propertybuilder_to_property = null;
TypeHandle.CleanUp ();
}
int count = sig.args.Length;
if (mi is MethodBuilder || mi is ConstructorBuilder){
- Type [] candidate_args = GetArgumentTypes ((MethodBase) mi);
+ Type [] candidate_args = GetParameterData ((MethodBase) mi).Types;
if (candidate_args.Length != count)
return false;
builder_to_declspace = new PtrHashtable ();
builder_to_member_cache = new PtrHashtable ();
builder_to_method = new PtrHashtable ();
- method_arguments = new PtrHashtable ();
method_params = new PtrHashtable ();
method_overrides = new PtrHashtable ();
indexer_arguments = new PtrHashtable ();
builder_to_ifaces = new PtrHashtable ();
- NoTypes = new Type [0];
- NoTypeExprs = new TypeExpr [0];
-
fieldbuilders_to_fields = new Hashtable ();
+ propertybuilder_to_property = new Hashtable ();
fields = new Hashtable ();
type_hash = new DoubleHash ();
+
+ // to uncover regressions
+ cons_param_array_attribute = null;
}
- public static void AddUserType (string name, DeclSpace ds)
+ public static void AddUserType (DeclSpace ds)
{
builder_to_declspace.Add (ds.TypeBuilder, ds);
}
public static void AddMethod (MethodBase builder, IMethodData method)
{
builder_to_method.Add (builder, method);
+ method_params.Add (builder, method.ParameterInfo);
}
public static IMethodData GetMethod (MethodBase builder)
/// </summary>
static public string GetFullNameSignature (MemberInfo mi)
{
+ PropertyInfo pi = mi as PropertyInfo;
+ if (pi != null) {
+ MethodBase pmi = pi.GetGetMethod (true);
+ if (pmi == null)
+ pmi = pi.GetSetMethod (true);
+ if (GetParameterData (pmi).Count > 0)
+ mi = pmi;
+ }
return (mi is MethodBase)
? CSharpSignature (mi as MethodBase)
: CSharpName (mi.DeclaringType) + '.' + mi.Name;
// Is indexer
if (mb.IsSpecialName && !mb.IsConstructor) {
- if (iparams.Count > 1) {
+ if (iparams.Count > (mb.Name.StartsWith ("get_") ? 0 : 1)) {
sig.Append ("this[");
if (show_accessor) {
sig.Append (parameters.Substring (1, parameters.Length - 2));
}
else {
int before_ret_val = parameters.LastIndexOf (',');
- sig.Append (parameters.Substring (1, before_ret_val - 1));
+ if (before_ret_val < 0)
+ sig.Append (parameters.Substring (1, parameters.Length - 2));
+ else
+ sig.Append (parameters.Substring (1, before_ret_val - 1));
}
sig.Append (']');
} else {
/// <summary>
/// Returns the ConstructorInfo for "args"
/// </summary>
- public static ConstructorInfo GetConstructor (Type t, Type [] args)
+ private static ConstructorInfo GetConstructor (Type t, Type [] args)
{
MemberList list;
Signature sig;
sig.name = ".ctor";
sig.args = args;
+
+ if (t == null)
+ throw new InternalErrorException ("Core types haven't been initialized yet?");
list = FindMembers (t, MemberTypes.Constructor,
instance_and_static | BindingFlags.Public | BindingFlags.DeclaredOnly,
param_array_type = CoreLookupType ("System", "ParamArrayAttribute");
in_attribute_type = CoreLookupType ("System.Runtime.InteropServices", "InAttribute");
out_attribute_type = CoreLookupType ("System.Runtime.InteropServices", "OutAttribute");
+#if NET_2_0
+ default_parameter_value_attribute_type = CoreLookupType ("System.Runtime.InteropServices", "DefaultParameterValueAttribute");
+#endif
typed_reference_type = CoreLookupType ("System", "TypedReference");
arg_iterator_type = CoreLookupType ("System", "ArgIterator");
mbr_type = CoreLookupType ("System", "MarshalByRefObject");
required_attr_type = CoreLookupType ("System.Runtime.CompilerServices", "RequiredAttributeAttribute");
guid_attr_type = CoreLookupType ("System.Runtime.InteropServices", "GuidAttribute");
assembly_culture_attribute_type = CoreLookupType ("System.Reflection", "AssemblyCultureAttribute");
+ comimport_attr_type = CoreLookupType ("System.Runtime.InteropServices", "ComImportAttribute");
+ coclass_attr_type = CoreLookupType ("System.Runtime.InteropServices", "CoClassAttribute");
//
// .NET 2.0
system_type_type = typeof (System.Type);
system_assemblybuilder_type = typeof (System.Reflection.Emit.AssemblyBuilder);
- Type [] void_arg = { };
system_int_array_get_length = GetMethod (
- system_array_type, "get_Length", void_arg);
+ system_array_type, "get_Length", Type.EmptyTypes);
system_int_array_get_rank = GetMethod (
- system_array_type, "get_Rank", void_arg);
+ system_array_type, "get_Rank", Type.EmptyTypes);
system_object_array_clone = GetMethod (
- system_array_type, "Clone", void_arg);
+ system_array_type, "Clone", Type.EmptyTypes);
Type [] system_int_arg = { system_int32_type };
system_int_array_get_length_int = GetMethod (
//
// Void arguments
//
- Type [] void_arg = { };
ienumerator_getcurrent = GetProperty (
ienumerator_type, "Current");
bool_movenext_void = GetMethod (
- ienumerator_type, "MoveNext", void_arg);
+ ienumerator_type, "MoveNext", Type.EmptyTypes);
void_reset_void = GetMethod (
- ienumerator_type, "Reset", void_arg);
+ ienumerator_type, "Reset", Type.EmptyTypes);
void_dispose_void = GetMethod (
- idisposable_type, "Dispose", void_arg);
+ idisposable_type, "Dispose", Type.EmptyTypes);
int_get_offset_to_string_data = GetMethod (
- runtime_helpers_type, "get_OffsetToStringData", void_arg);
+ runtime_helpers_type, "get_OffsetToStringData", Type.EmptyTypes);
int_array_get_length = GetMethod (
- array_type, "get_Length", void_arg);
+ array_type, "get_Length", Type.EmptyTypes);
int_array_get_rank = GetMethod (
- array_type, "get_Rank", void_arg);
+ array_type, "get_Rank", Type.EmptyTypes);
ienumerable_getenumerator_void = GetMethod (
- ienumerable_type, "GetEnumerator", void_arg);
+ ienumerable_type, "GetEnumerator", Type.EmptyTypes);
//
// Int32 arguments
// System.Array methods
//
object_array_clone = GetMethod (
- array_type, "Clone", void_arg);
+ array_type, "Clone", Type.EmptyTypes);
Type [] array_int_arg = { array_type, int32_type };
void_array_copyto_array_int = GetMethod (
array_type, "CopyTo", array_int_arg);
//
// Attributes
//
- cons_param_array_attribute = GetConstructor (param_array_type, void_arg);
- unverifiable_code_ctor = GetConstructor (unverifiable_code_type, void_arg);
+ unverifiable_code_ctor = GetConstructor (unverifiable_code_type, Type.EmptyTypes);
default_member_ctor = GetConstructor (default_member_type, string_);
Type[] short_arg = { short_type };
//
#if NET_2_0
compiler_generated_attr = new CustomAttributeBuilder (
- GetConstructor (compiler_generated_attr_type, void_arg), new object[0]);
+ GetConstructor (compiler_generated_attr_type, Type.EmptyTypes), new object[0]);
Type[] type_int_arg = { type_type, int32_type };
fixed_buffer_attr_ctor = GetConstructor (fixed_buffer_attr_type, type_int_arg);
#endif
// Object
- object_ctor = GetConstructor (object_type, void_arg);
+ object_ctor = GetConstructor (object_type, Type.EmptyTypes);
}
+ static public ConstructorInfo ConsParamArrayAttribute {
+ get {
+ if (cons_param_array_attribute == null)
+ cons_param_array_attribute = GetConstructor (param_array_type, Type.EmptyTypes);
+ return cons_param_array_attribute;
+ }
+ }
+
const BindingFlags instance_and_static = BindingFlags.Static | BindingFlags.Instance;
/// <remarks>
// a TypeBuilder array will return a Type, not a TypeBuilder,
// and we can not call FindMembers on this type.
//
- if (t.IsSubclassOf (TypeManager.array_type))
+ if (TypeManager.IsSubclassOf (t, TypeManager.array_type))
return new MemberList (TypeManager.array_type.FindMembers (mt, bf, filter, criteria));
//
if (t is TypeBuilder){
TypeContainer tc = LookupTypeContainer (t);
if (tc.Fields != null){
- foreach (Field f in tc.Fields){
+ foreach (FieldMember f in tc.Fields){
// Avoid using f.FieldBuilder: f.Define () may not yet have been invoked.
if ((f.ModFlags & Modifiers.STATIC) != 0)
continue;
/// for anything which is dynamic, and we need this in a number of places,
/// we register this information here, and use it afterwards.
/// </remarks>
- static public void RegisterMethod (MethodBase mb, InternalParameters ip, Type [] args)
+ static public void RegisterMethod (MethodBase mb, Parameters ip)
{
- if (args == null)
- args = NoTypes;
-
- method_arguments.Add (mb, args);
method_params.Add (mb, ip);
}
static public ParameterData GetParameterData (MethodBase mb)
{
- object pd = method_params [mb];
+ ParameterData pd = (ParameterData)method_params [mb];
if (pd == null) {
if (mb is MethodBuilder || mb is ConstructorBuilder)
throw new InternalErrorException ("Argument for Method not registered" + mb);
- method_params [mb] = pd = new ReflectionParameters (mb);
+ pd = new ReflectionParameters (mb);
+ method_params.Add (mb, pd);
}
-
- return (ParameterData) pd;
+ return pd;
}
static public void RegisterOverride (MethodBase override_method, MethodBase base_method)
{
- if (method_overrides.Contains (override_method)) {
- if (method_overrides [override_method] != base_method)
- throw new InternalErrorException ("Override mismatch: " + override_method);
- return;
- }
- method_overrides [override_method] = base_method;
+ if (!method_overrides.Contains (override_method))
+ method_overrides [override_method] = base_method;
+ if (method_overrides [override_method] != base_method)
+ throw new InternalErrorException ("Override mismatch: " + override_method);
}
static public bool IsOverride (MethodBase m)
(m is MethodBuilder || method_overrides.Contains (m));
}
- /// <summary>
- /// Returns the argument types for a method based on its methodbase
- ///
- /// For dynamic methods, we use the compiler provided types, for
- /// methods from existing assemblies we load them from GetParameters,
- /// and insert them into the cache
- /// </summary>
- static public Type [] GetArgumentTypes (MethodBase mb)
+ static public MethodBase TryGetBaseDefinition (MethodBase m)
{
- object t = method_arguments [mb];
- if (t != null)
- return (Type []) t;
-
- ParameterInfo [] pi = mb.GetParameters ();
- int c = pi.Length;
- Type [] types;
-
- if (c == 0) {
- types = NoTypes;
- } else {
- types = new Type [c];
- for (int i = 0; i < c; i++)
- types [i] = pi [i].ParameterType;
- }
- method_arguments.Add (mb, types);
- return types;
+ return (MethodBase) method_overrides [m];
}
/// <summary>
// If we're a PropertyBuilder and not in the
// `indexer_arguments' hash, then we're a property and
// not an indexer.
- return NoTypes;
+ return Type.EmptyTypes;
else {
ParameterInfo [] pi = indexer.GetIndexParameters ();
// Property, not an indexer.
if (pi == null)
- return NoTypes;
+ return Type.EmptyTypes;
int c = pi.Length;
Type [] types = new Type [c];
return (IConstant)fields [fb];
}
+ public static void RegisterProperty (PropertyInfo pi, PropertyBase pb)
+ {
+ propertybuilder_to_property.Add (pi, pb);
+ }
+
+ public static PropertyBase GetProperty (PropertyInfo pi)
+ {
+ return (PropertyBase)propertybuilder_to_property [pi];
+ }
+
static public bool RegisterFieldBase (FieldBuilder fb, FieldBase f)
{
if (fieldbuilders_to_fields.Contains (fb))
return (FieldBase) fieldbuilders_to_fields [fb];
}
- static Hashtable events;
-
static public void RegisterEvent (MyEventBuilder eb, MethodBase add, MethodBase remove)
{
if (events == null)
/// This expands in context like: IA; IB : IA; IC : IA, IB; the interface "IC" to
/// be IA, IB, IC.
/// </remarks>
- public static Type[] ExpandInterfaces (EmitContext ec, TypeExpr [] base_interfaces)
+ public static Type[] ExpandInterfaces (TypeExpr [] base_interfaces)
{
ArrayList new_ifaces = new ArrayList ();
foreach (TypeExpr iface in base_interfaces){
- Type itype = iface.ResolveType (ec);
- if (itype == null)
- return null;
+ Type itype = iface.Type;
if (!new_ifaces.Contains (itype))
new_ifaces.Add (itype);
/// </summary>
public static Type [] GetInterfaces (Type t)
{
-
Type [] cached = iface_cache [t] as Type [];
if (cached != null)
return cached;
Type [] base_ifaces;
if (t.BaseType == null)
- base_ifaces = NoTypes;
+ base_ifaces = Type.EmptyTypes;
else
base_ifaces = GetInterfaces (t.BaseType);
Type [] type_ifaces = (Type []) builder_to_ifaces [t];
- if (type_ifaces == null)
- type_ifaces = NoTypes;
-
+ if (type_ifaces == null || type_ifaces.Length == 0)
+ type_ifaces = Type.EmptyTypes;
+
int base_count = base_ifaces.Length;
Type [] result = new Type [base_count + type_ifaces.Length];
base_ifaces.CopyTo (result, 0);
new Type [] { typeof (Type), typeof (bool)},
null);
if (declare_local_method == null){
- Report.Warning (-30, new Location (-1),
- "This version of the runtime does not support making pinned local variables. " +
- "This code may cause errors on a runtime with a moving GC");
+ Report.RuntimeMissingSupport (Location.Null, "pinned local variables");
return ig.DeclareLocal (t);
}
}
//
public static bool ArrayContainsMethod (MemberInfo [] array, MethodBase new_method)
{
- Type [] new_args = TypeManager.GetArgumentTypes (new_method);
+ Type [] new_args = TypeManager.GetParameterData (new_method).Types;
foreach (MethodBase method in array) {
if (method.Name != new_method.Name)
continue;
- Type [] old_args = TypeManager.GetArgumentTypes (method);
+ Type [] old_args = TypeManager.GetParameterData (method).Types;
int old_count = old_args.Length;
int i;
}
+ // This method always return false for non-generic compiler,
+ // while Type.IsGenericParameter is returned if it is supported.
+ public static bool IsGenericParameter (Type type)
+ {
+ return false;
+ }
+
+ public static int GenericParameterPosition (Type type)
+ {
+ throw new InternalErrorException ("should not be called");
+ }
+
#region MemberLookup implementation
//
// uses NonPublic for both protected and private), we need to distinguish.
//
- static internal bool FilterNone (MemberInfo m, object filter_criteria)
- {
- return true;
- }
-
internal class Closure {
internal bool private_ok;
return (MemberInfo []) first_members_list;
}
- if (method_list != null && method_list.Count > 0)
+ if (method_list != null && method_list.Count > 0) {
return (MemberInfo []) method_list.ToArray (typeof (MemberInfo));
-
+ }
//
// This happens if we already used the cache in the first iteration, in this case
// the cache already looked in all interfaces.