//
// 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 security_attr_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
///
#if NET_2_0
+ static internal Type runtime_compatibility_attr_type;
static internal Type compiler_generated_attr_type;
static internal Type fixed_buffer_attr_type;
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;
static internal ConstructorInfo fixed_buffer_attr_ctor;
#endif
- // <remarks>
- // Holds the Array of Assemblies that have been loaded
- // (either because it is the default or the user used the
- // -r command line option)
- // </remarks>
- static Assembly [] assemblies;
-
- // <remarks>
- // Keeps a list of modules. We used this to do lookups
- // on the module using GetType -- needed for arrays
- // </remarks>
- static Module [] modules;
-
- // <remarks>
- // This is the type_cache from the assemblies to avoid
- // hitting System.Reflection on every lookup.
- // </summary>
- static Hashtable types;
-
- // <remarks>
- // This is used to hotld the corresponding TypeContainer objects
- // since we need this in FindMembers
- // </remarks>
- static Hashtable typecontainers;
-
- // <remarks>
- // Keeps track of those types that are defined by the
- // user's program
- // </remarks>
- static ArrayList user_types;
-
static PtrHashtable builder_to_declspace;
static PtrHashtable builder_to_member_cache;
// </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
// Contains all public types from referenced assemblies.
// This member is used only if CLS Compliance verification is required.
// </remarks>
- public static Hashtable all_imported_types;
+ 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;
public static void CleanUp ()
{
// Lets get everything clean so that we can collect before generating code
- assemblies = null;
- modules = null;
- types = null;
- typecontainers = null;
- user_types = null;
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;
fields = null;
- builder_to_constant = null;
fieldbuilders_to_fields = null;
events = null;
priv_fields_events = null;
- properties = 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;
static public void Reset ()
{
- assemblies = new Assembly [0];
- modules = null;
- user_types = new ArrayList ();
-
- types = new Hashtable ();
- typecontainers = new Hashtable ();
-
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 ();
- }
- public static void HandleDuplicate (string name, Type t)
- {
- Type prev = (Type) types [name];
- TypeContainer tc = builder_to_declspace [prev] as TypeContainer;
-
- if (tc != null){
- //
- // This probably never happens, as we catch this before
- //
- Report.Error (-17, "The type `" + name + "' has already been defined.");
- return;
- }
-
- tc = builder_to_declspace [t] as TypeContainer;
- if (tc != null){
- Report.Warning (
- 1595, "The type `" + name + "' is defined in an existing assembly;"+
- " Using the new definition from: " + tc.Location);
- } else {
- Report.Warning (
- 1595, "The type `" + name + "' is defined in an existing assembly;");
- }
-
- Report.Warning (1595, "Previously defined in: " + prev.Assembly.FullName);
-
- types.Remove (name);
- types.Add (name, t);
+ // to uncover regressions
+ cons_param_array_attribute = null;
}
-
- public static void AddUserType (string name, TypeBuilder t)
- {
- try {
- types.Add (name, t);
- } catch {
- HandleDuplicate (name, t);
- }
- user_types.Add (t);
+ public static void AddUserType (DeclSpace ds)
+ {
+ builder_to_declspace.Add (ds.TypeBuilder, ds);
}
//
{
if (ifaces != null)
builder_to_ifaces [tb] = ifaces;
- }
-
- public static void AddUserType (string name, TypeBuilder t, TypeContainer tc)
- {
- builder_to_declspace.Add (t, tc);
- typecontainers.Add (name, tc);
- AddUserType (name, t);
- }
-
- public static void AddDelegateType (string name, TypeBuilder t, Delegate del)
- {
- try {
- types.Add (name, t);
- } catch {
- HandleDuplicate (name, t);
- }
-
- builder_to_declspace.Add (t, del);
- }
-
- public static void AddEnumType (string name, TypeBuilder t, Enum en)
- {
- try {
- types.Add (name, t);
- } catch {
- HandleDuplicate (name, t);
- }
- builder_to_declspace.Add (t, en);
- }
+ }
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)
return builder_to_declspace [t] as Delegate;
}
- public static Enum LookupEnum (Type t)
- {
- return builder_to_declspace [t] as Enum;
- }
-
public static Class LookupClass (Type t)
{
return (Class) builder_to_declspace [t];
}
-
- /// <summary>
- /// Registers an assembly to load types from.
- /// </summary>
- public static void AddAssembly (Assembly a)
- {
- foreach (Assembly assembly in assemblies) {
- if (a == assembly)
- return;
- }
-
- int top = assemblies.Length;
- Assembly [] n = new Assembly [top + 1];
-
- assemblies.CopyTo (n, 0);
-
- n [top] = a;
- assemblies = n;
- }
-
- public static Assembly [] GetAssemblies ()
- {
- return assemblies;
- }
-
- /// <summary>
- /// Registers a module builder to lookup types from
- /// </summary>
- public static void AddModule (Module mb)
- {
- int top = modules != null ? modules.Length : 0;
- Module [] n = new Module [top + 1];
-
- if (modules != null)
- modules.CopyTo (n, 0);
- n [top] = mb;
- modules = n;
- }
-
- public static Module[] Modules {
- get {
- return modules;
- }
- }
//
// We use this hash for multiple kinds of constructed types:
{
object ret = null;
if (!type_hash.Lookup (t, name, out ret)) {
- string lookup = t.ToString () + "+" + name;
- ret = t.Module.GetType (lookup);
+ ret = t.GetNestedType (name,
+ BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
type_hash.Insert (t, name, ret);
}
return (Type) ret;
}
-
- //
- // Low-level lookup, cache-less
- //
- public static Type LookupTypeReflection (string name)
- {
- Type t;
-
- foreach (Assembly a in assemblies){
- t = a.GetType (name);
- if (t == null)
- continue;
-
- do {
- TypeAttributes ta = t.Attributes & TypeAttributes.VisibilityMask;
- if (ta == TypeAttributes.NotPublic ||
- ta == TypeAttributes.NestedPrivate ||
- ta == TypeAttributes.NestedAssembly ||
- ta == TypeAttributes.NestedFamANDAssem){
-
- //
- // In .NET pointers turn out to be private, even if their
- // element type is not
- //
- if (t.IsPointer){
- t = t.GetElementType ();
- continue;
- } else
- t = null;
- } else {
- return t;
- }
- } while (t != null);
- }
-
- foreach (Module mb in modules) {
- t = mb.GetType (name);
- if (t != null)
- return t;
- }
-
- return null;
- }
-
- /// <summary>
- /// Computes the namespaces that we import from the assemblies we reference.
- /// </summary>
- public static void ComputeNamespaces ()
- {
- MethodInfo assembly_get_namespaces = typeof (Assembly).GetMethod ("GetNamespaces", BindingFlags.Instance|BindingFlags.NonPublic);
-
- Hashtable cache = null;
-
- //
- // First add the assembly namespaces
- //
- if (assembly_get_namespaces != null){
- int count = assemblies.Length;
-
- for (int i = 0; i < count; i++){
- Assembly a = assemblies [i];
- string [] namespaces = (string []) assembly_get_namespaces.Invoke (a, null);
- foreach (string ns in namespaces){
- if (ns == "")
- continue;
- Namespace.LookupNamespace (ns, true);
- }
- }
- } else {
- cache = new Hashtable ();
- cache.Add ("", null);
- foreach (Assembly a in assemblies) {
- foreach (Type t in a.GetExportedTypes ()) {
- string ns = t.Namespace;
- if (ns == null || cache.Contains (ns))
- continue;
-
- Namespace.LookupNamespace (ns, true);
- cache.Add (ns, null);
- }
- }
- }
-
- //
- // Then add module namespaces
- //
- foreach (Module m in modules) {
- if (m == CodeGen.Module.Builder)
- continue;
- if (cache == null) {
- cache = new Hashtable ();
- cache.Add ("", null);
- }
- foreach (Type t in m.GetTypes ()) {
- string ns = t.Namespace;
- if (ns == null || cache.Contains (ns))
- continue;
- Namespace.LookupNamespace (ns, true);
- cache.Add (ns, null);
- }
- }
- }
/// <summary>
/// Fills static table with exported types from all referenced assemblies.
/// </summary>
public static void LoadAllImportedTypes ()
{
- all_imported_types = new Hashtable ();
- foreach (Assembly a in assemblies) {
+ AllClsTopLevelTypes = new Hashtable (1500);
+ foreach (Assembly a in RootNamespace.Global.Assemblies) {
foreach (Type t in a.GetExportedTypes ()) {
- all_imported_types [t.FullName] = t;
+ AllClsTopLevelTypes [t.FullName.ToLower (System.Globalization.CultureInfo.InvariantCulture)] = null;
}
}
}
public static bool NamespaceClash (string name, Location loc)
{
- if (Namespace.LookupNamespace (name, false) == null)
+ if (! RootNamespace.Global.IsNamespace (name))
return false;
Report.Error (519, loc, String.Format ("`{0}' clashes with a predefined namespace", name));
/// </summary>
static public string GetFullNameSignature (MemberInfo mi)
{
- // Unfortunately, there's no dynamic dispatch on the arguments of a function.
- return (mi is MethodBase)
- ? GetFullNameSignature (mi as MethodBase)
- : mi.DeclaringType.FullName.Replace ('+', '.') + '.' + mi.Name;
- }
-
- static public string GetFullNameSignature (MethodBase mb)
- {
- string name = mb.Name;
- if (name == ".ctor")
- name = mb.DeclaringType.Name;
-
- if (mb.IsSpecialName) {
- if (name.StartsWith ("get_") || name.StartsWith ("set_")) {
- name = name.Remove (0, 4);
- }
-
- if (name == "Item")
- name = "this";
+ 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 mb.DeclaringType.FullName.Replace ('+', '.') + '.' + name;
+ return (mi is MethodBase)
+ ? CSharpSignature (mi as MethodBase)
+ : CSharpName (mi.DeclaringType) + '.' + mi.Name;
}
/// <summary>
- /// Returns the signature of the property and indexer
+ /// When we need to report accessors as well
/// </summary>
- static public string CSharpSignature (PropertyBuilder pb, bool is_indexer)
+ static public string CSharpSignature (MethodBase mb)
{
- if (!is_indexer) {
- return GetFullNameSignature (pb);
- }
-
- MethodBase mb = pb.GetSetMethod (true) != null ? pb.GetSetMethod (true) : pb.GetGetMethod (true);
- string signature = GetFullNameSignature (mb);
- string arg = GetParameterData (mb).ParameterDesc (0);
- return String.Format ("{0}.this[{1}]", signature.Substring (0, signature.LastIndexOf ('.')), arg);
+ return CSharpSignature (mb, false);
}
/// <summary>
/// Returns the signature of the method
/// </summary>
- static public string CSharpSignature (MethodBase mb)
+ static public string CSharpSignature (MethodBase mb, bool show_accessor)
{
- StringBuilder sig = new StringBuilder ("(");
+ StringBuilder sig = new StringBuilder (CSharpName (mb.DeclaringType));
+ sig.Append ('.');
ParameterData iparams = GetParameterData (mb);
+ string parameters = iparams.GetSignatureForError ();
+ string accessor = "";
// Is property
- if (mb.IsSpecialName && iparams.Count == 0 && !mb.IsConstructor)
- return GetFullNameSignature (mb);
-
- for (int i = 0; i < iparams.Count; i++) {
- if (i > 0) {
- sig.Append (", ");
+ if (mb.IsSpecialName) {
+ Operator.OpType ot = Operator.GetOperatorType (mb.Name);
+ if (ot != Operator.OpType.TOP) {
+ sig.Append ("operator ");
+ sig.Append (Operator.GetName (ot));
+ sig.Append (parameters);
+ return sig.ToString ();
+ }
+
+ if (mb.Name.StartsWith ("get_") || mb.Name.StartsWith ("set_")) {
+ accessor = mb.Name.Substring (0, 3);
}
- sig.Append (iparams.ParameterDesc (i));
}
- sig.Append (")");
// Is indexer
- if (mb.IsSpecialName && iparams.Count == 1 && !mb.IsConstructor) {
- sig.Replace ('(', '[');
- sig.Replace (')', ']');
+ if (mb.IsSpecialName && !mb.IsConstructor) {
+ 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 (',');
+ 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 {
+ sig.Append (mb.Name.Substring (4));
+ }
+ } else {
+ if (mb.Name == ".ctor")
+ sig.Append (mb.DeclaringType.Name);
+ else
+ sig.Append (mb.Name);
+
+ sig.Append (parameters);
}
- return GetFullNameSignature (mb) + sig.ToString ();
+ if (show_accessor && accessor.Length > 0) {
+ sig.Append ('.');
+ sig.Append (accessor);
+ }
+
+ return sig.ToString ();
+ }
+
+ static public string CSharpSignature (EventInfo ei)
+ {
+ return CSharpName (ei.DeclaringType) + '.' + ei.Name;
}
/// <summary>
/// Looks up a type, and aborts if it is not found. This is used
/// by types required by the compiler
/// </summary>
- static Type CoreLookupType (string name)
+ static Type CoreLookupType (string ns_name, string name)
{
- Type t = null;
- if (types.Contains (name))
- t = (Type) types [name];
- else
- t = LookupTypeReflection (name);
-
+ Namespace ns = RootNamespace.Global.GetNamespace (ns_name, true);
+ FullNamedExpression fne = ns.Lookup (RootContext.Tree.Types, name, Location.Null);
+ Type t = fne == null ? null : fne.Type;
if (t == null)
Report.Error (518, "The predefined type `" + name + "' is not defined or imported");
-
- types [name] = t;
return t;
}
/// <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,
public static void InitEnumUnderlyingTypes ()
{
- int32_type = CoreLookupType ("System.Int32");
- int64_type = CoreLookupType ("System.Int64");
- uint32_type = CoreLookupType ("System.UInt32");
- uint64_type = CoreLookupType ("System.UInt64");
- byte_type = CoreLookupType ("System.Byte");
- sbyte_type = CoreLookupType ("System.SByte");
- short_type = CoreLookupType ("System.Int16");
- ushort_type = CoreLookupType ("System.UInt16");
+ int32_type = CoreLookupType ("System", "Int32");
+ int64_type = CoreLookupType ("System", "Int64");
+ uint32_type = CoreLookupType ("System", "UInt32");
+ uint64_type = CoreLookupType ("System", "UInt64");
+ byte_type = CoreLookupType ("System", "Byte");
+ sbyte_type = CoreLookupType ("System", "SByte");
+ short_type = CoreLookupType ("System", "Int16");
+ ushort_type = CoreLookupType ("System", "UInt16");
}
/// <remarks>
/// </remarks>
public static void InitCoreTypes ()
{
- object_type = CoreLookupType ("System.Object");
- value_type = CoreLookupType ("System.ValueType");
+ object_type = CoreLookupType ("System", "Object");
+ value_type = CoreLookupType ("System", "ValueType");
InitEnumUnderlyingTypes ();
- char_type = CoreLookupType ("System.Char");
- string_type = CoreLookupType ("System.String");
- float_type = CoreLookupType ("System.Single");
- double_type = CoreLookupType ("System.Double");
- char_ptr_type = CoreLookupType ("System.Char*");
- decimal_type = CoreLookupType ("System.Decimal");
- bool_type = CoreLookupType ("System.Boolean");
- enum_type = CoreLookupType ("System.Enum");
-
- multicast_delegate_type = CoreLookupType ("System.MulticastDelegate");
- delegate_type = CoreLookupType ("System.Delegate");
-
- array_type = CoreLookupType ("System.Array");
- void_type = CoreLookupType ("System.Void");
- type_type = CoreLookupType ("System.Type");
-
- runtime_field_handle_type = CoreLookupType ("System.RuntimeFieldHandle");
- runtime_argument_handle_type = CoreLookupType ("System.RuntimeArgumentHandle");
- runtime_helpers_type = CoreLookupType ("System.Runtime.CompilerServices.RuntimeHelpers");
- default_member_type = CoreLookupType ("System.Reflection.DefaultMemberAttribute");
- runtime_handle_type = CoreLookupType ("System.RuntimeTypeHandle");
- asynccallback_type = CoreLookupType ("System.AsyncCallback");
- iasyncresult_type = CoreLookupType ("System.IAsyncResult");
- ienumerator_type = CoreLookupType ("System.Collections.IEnumerator");
- ienumerable_type = CoreLookupType ("System.Collections.IEnumerable");
- idisposable_type = CoreLookupType ("System.IDisposable");
- icloneable_type = CoreLookupType ("System.ICloneable");
- iconvertible_type = CoreLookupType ("System.IConvertible");
- monitor_type = CoreLookupType ("System.Threading.Monitor");
- intptr_type = CoreLookupType ("System.IntPtr");
-
- attribute_type = CoreLookupType ("System.Attribute");
- attribute_usage_type = CoreLookupType ("System.AttributeUsageAttribute");
- dllimport_type = CoreLookupType ("System.Runtime.InteropServices.DllImportAttribute");
- methodimpl_attr_type = CoreLookupType ("System.Runtime.CompilerServices.MethodImplAttribute");
- marshal_as_attr_type = CoreLookupType ("System.Runtime.InteropServices.MarshalAsAttribute");
- param_array_type = CoreLookupType ("System.ParamArrayAttribute");
- in_attribute_type = CoreLookupType ("System.Runtime.InteropServices.InAttribute");
- out_attribute_type = CoreLookupType ("System.Runtime.InteropServices.OutAttribute");
- typed_reference_type = CoreLookupType ("System.TypedReference");
- arg_iterator_type = CoreLookupType ("System.ArgIterator");
- mbr_type = CoreLookupType ("System.MarshalByRefObject");
- decimal_constant_attribute_type = CoreLookupType ("System.Runtime.CompilerServices.DecimalConstantAttribute");
-
- unverifiable_code_type= CoreLookupType ("System.Security.UnverifiableCodeAttribute");
-
- void_ptr_type = CoreLookupType ("System.Void*");
-
- indexer_name_type = CoreLookupType ("System.Runtime.CompilerServices.IndexerNameAttribute");
-
- exception_type = CoreLookupType ("System.Exception");
- invalid_operation_exception_type = CoreLookupType ("System.InvalidOperationException");
- not_supported_exception_type = CoreLookupType ("System.NotSupportedException");
+ char_type = CoreLookupType ("System", "Char");
+ string_type = CoreLookupType ("System", "String");
+ float_type = CoreLookupType ("System", "Single");
+ double_type = CoreLookupType ("System", "Double");
+ char_ptr_type = GetPointerType (char_type);
+ decimal_type = CoreLookupType ("System", "Decimal");
+ bool_type = CoreLookupType ("System", "Boolean");
+ enum_type = CoreLookupType ("System", "Enum");
+
+ multicast_delegate_type = CoreLookupType ("System", "MulticastDelegate");
+ delegate_type = CoreLookupType ("System", "Delegate");
+
+ array_type = CoreLookupType ("System", "Array");
+ void_type = CoreLookupType ("System", "Void");
+ type_type = CoreLookupType ("System", "Type");
+
+ runtime_field_handle_type = CoreLookupType ("System", "RuntimeFieldHandle");
+ runtime_argument_handle_type = CoreLookupType ("System", "RuntimeArgumentHandle");
+ runtime_helpers_type = CoreLookupType ("System.Runtime.CompilerServices", "RuntimeHelpers");
+ default_member_type = CoreLookupType ("System.Reflection", "DefaultMemberAttribute");
+ runtime_handle_type = CoreLookupType ("System", "RuntimeTypeHandle");
+ asynccallback_type = CoreLookupType ("System", "AsyncCallback");
+ iasyncresult_type = CoreLookupType ("System", "IAsyncResult");
+ ienumerator_type = CoreLookupType ("System.Collections", "IEnumerator");
+ ienumerable_type = CoreLookupType ("System.Collections", "IEnumerable");
+ idisposable_type = CoreLookupType ("System", "IDisposable");
+ icloneable_type = CoreLookupType ("System", "ICloneable");
+ iconvertible_type = CoreLookupType ("System", "IConvertible");
+ monitor_type = CoreLookupType ("System.Threading", "Monitor");
+ intptr_type = CoreLookupType ("System", "IntPtr");
+
+ attribute_type = CoreLookupType ("System", "Attribute");
+ attribute_usage_type = CoreLookupType ("System", "AttributeUsageAttribute");
+ dllimport_type = CoreLookupType ("System.Runtime.InteropServices", "DllImportAttribute");
+ methodimpl_attr_type = CoreLookupType ("System.Runtime.CompilerServices", "MethodImplAttribute");
+ marshal_as_attr_type = CoreLookupType ("System.Runtime.InteropServices", "MarshalAsAttribute");
+ 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");
+ decimal_constant_attribute_type = CoreLookupType ("System.Runtime.CompilerServices", "DecimalConstantAttribute");
+
+ unverifiable_code_type= CoreLookupType ("System.Security", "UnverifiableCodeAttribute");
+
+ void_ptr_type = GetPointerType (void_type);
+
+ indexer_name_type = CoreLookupType ("System.Runtime.CompilerServices", "IndexerNameAttribute");
+
+ exception_type = CoreLookupType ("System", "Exception");
+ invalid_operation_exception_type = CoreLookupType ("System", "InvalidOperationException");
+ not_supported_exception_type = CoreLookupType ("System", "NotSupportedException");
//
// Attribute types
//
- obsolete_attribute_type = CoreLookupType ("System.ObsoleteAttribute");
- conditional_attribute_type = CoreLookupType ("System.Diagnostics.ConditionalAttribute");
- cls_compliant_attribute_type = CoreLookupType ("System.CLSCompliantAttribute");
- struct_layout_attribute_type = CoreLookupType ("System.Runtime.InteropServices.StructLayoutAttribute");
- field_offset_attribute_type = CoreLookupType ("System.Runtime.InteropServices.FieldOffsetAttribute");
- security_attr_type = CoreLookupType ("System.Security.Permissions.SecurityAttribute");
- required_attr_type = CoreLookupType ("System.Runtime.CompilerServices.RequiredAttributeAttribute");
- guid_attr_type = CoreLookupType ("System.Runtime.InteropServices.GuidAttribute");
+ obsolete_attribute_type = CoreLookupType ("System", "ObsoleteAttribute");
+ conditional_attribute_type = CoreLookupType ("System.Diagnostics", "ConditionalAttribute");
+ cls_compliant_attribute_type = CoreLookupType ("System", "CLSCompliantAttribute");
+ struct_layout_attribute_type = CoreLookupType ("System.Runtime.InteropServices", "StructLayoutAttribute");
+ field_offset_attribute_type = CoreLookupType ("System.Runtime.InteropServices", "FieldOffsetAttribute");
+ security_attr_type = CoreLookupType ("System.Security.Permissions", "SecurityAttribute");
+ 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
//
#if NET_2_0
- compiler_generated_attr_type = CoreLookupType ("System.Runtime.CompilerServices.CompilerGeneratedAttribute");
- fixed_buffer_attr_type = CoreLookupType ("System.Runtime.CompilerServices.FixedBufferAttribute");
- default_charset_type = CoreLookupType ("System.Runtime.InteropServices.DefaultCharSetAttribute");
+ compiler_generated_attr_type = CoreLookupType ("System.Runtime.CompilerServices", "CompilerGeneratedAttribute");
+ fixed_buffer_attr_type = CoreLookupType ("System.Runtime.CompilerServices", "FixedBufferAttribute");
+ default_charset_type = CoreLookupType ("System.Runtime.InteropServices", "DefaultCharSetAttribute");
+ runtime_compatibility_attr_type = CoreLookupType ("System.Runtime.CompilerServices", "RuntimeCompatibilityAttribute");
#endif
//
// When compiling corlib, store the "real" types here.
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));
//
public static bool IsEnumType (Type t)
{
- if (t.IsSubclassOf (TypeManager.enum_type))
+ if (builder_to_declspace [t] is Enum)
return true;
- else
- return false;
+
+ return t.IsEnum;
}
+
public static bool IsBuiltinOrEnum (Type t)
{
if (IsBuiltinType (t))
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;
{
return t.IsArray || t.IsPointer || t.IsByRef;
}
-
- /// <summary>
- /// Returns the User Defined Types
- /// </summary>
- public static ArrayList UserTypes {
- get {
- return user_types;
- }
- }
-
- public static Hashtable TypeContainers {
- get {
- return typecontainers;
- }
- }
-
- static Hashtable builder_to_constant;
-
- public static void RegisterConstant (FieldBuilder fb, Const c)
- {
- if (builder_to_constant == null)
- builder_to_constant = new PtrHashtable ();
-
- if (builder_to_constant.Contains (fb))
- return;
-
- builder_to_constant.Add (fb, c);
- }
-
- public static Const LookupConstant (FieldBuilder fb)
- {
- if (builder_to_constant == null)
- return null;
-
- return (Const) builder_to_constant [fb];
- }
/// <summary>
/// Gigantic work around for missing features in System.Reflection.Emit follows.
/// 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];
}
}
- // <remarks>
- // This is a workaround the fact that GetValue is not
- // supported for dynamic types
- // </remarks>
- static public bool RegisterFieldValue (FieldBuilder fb, object value)
+ public static void RegisterConstant (FieldInfo fb, IConstant ic)
{
- if (fields.Contains (fb))
- return false;
+ fields.Add (fb, ic);
+ }
- fields.Add (fb, value);
+ public static IConstant GetConstant (FieldInfo fb)
+ {
+ if (fb == null)
+ return null;
- return true;
+ return (IConstant)fields [fb];
}
- static public object GetValue (FieldBuilder fb)
+ public static void RegisterProperty (PropertyInfo pi, PropertyBase pb)
{
- return fields [fb];
+ 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)
return (FieldBase) fieldbuilders_to_fields [fb];
}
- static Hashtable events;
-
static public void RegisterEvent (MyEventBuilder eb, MethodBase add, MethodBase remove)
{
if (events == null)
return (MemberInfo) priv_fields_events [ei];
}
- static Hashtable properties;
-
- static public bool RegisterProperty (PropertyBuilder pb, MethodBase get, MethodBase set)
- {
- if (properties == null)
- properties = new Hashtable ();
-
- if (properties.Contains (pb))
- return false;
-
- properties.Add (pb, new Pair (get, set));
-
- return true;
- }
-
static public bool RegisterIndexer (PropertyBuilder pb, MethodBase get,
MethodBase set, Type[] args)
{
- if (!RegisterProperty (pb, get,set))
- return false;
-
indexer_arguments.Add (pb, args);
return true;
/// 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);
if (IsUnmanagedType (t))
return true;
- Report.Error (
- 208, loc,
- "Cannot take the address or size of a variable of a managed type ('" +
- CSharpName (t) + "')");
+ Report.Error (208, loc, "Cannot take the address of, get the size of, or declare a pointer to a managed type `{0}'",
+ CSharpName (t));
+
return false;
}
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;
Type current_type = queried_type;
bool searching = (original_bf & BindingFlags.DeclaredOnly) == 0;
bool skip_iface_check = true, used_cache = false;
- bool always_ok_flag = false;
+ bool always_ok_flag = invocation_type != null && IsNestedChildOf (invocation_type, queried_type);
closure.invocation_type = invocation_type;
closure.invocation_assembly = invocation_type != null ? invocation_type.Assembly : null;
closure.qualifier_type = qualifier_type;
closure.almost_match = almost_match;
-
- //
- // If we are a nested class, we always have access to our container
- // type names
- //
- if (invocation_type != null){
- string invocation_name = invocation_type.FullName;
- if (invocation_name.IndexOf ('+') != -1){
- string container = queried_type.FullName + "+";
- int container_length = container.Length;
-
- if (invocation_name.Length > container_length){
- string shared = invocation_name.Substring (0, container_length);
-
- if (shared == container)
- always_ok_flag = true;
- }
- }
- }
// This is from the first time we find a method
// in most cases, we do not actually find a method in the base class
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.