*.cs: Moving to generics world.
svn path=/trunk/mcs/; revision=147572
+2009-12-03 Marek Safar <marek.safar@gmail.com>
+
+ *.cs: Moving to generics world.
+
2009-12-02 Marek Safar <marek.safar@gmail.com>
* typemanager.cs, parameter.cs, class.cs, delegate.cs, attribute.cs:
using System;
using System.Text;
using System.Collections;
-using System.Collections.Specialized;
+using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
}
}
- ListDictionary compatibles;
+ Dictionary<Type, Expression> compatibles;
public ToplevelBlock Block;
public AnonymousMethodExpression (Location loc)
{
this.loc = loc;
- this.compatibles = new ListDictionary ();
+ this.compatibles = new Dictionary<Type, Expression> ();
}
public override string ExprClassName {
//
public Expression Compatible (ResolveContext ec, Type type)
{
- Expression am = (Expression) compatibles [type];
- if (am != null)
+ Expression am;
+ if (compatibles.TryGetValue (type, out am))
return am;
Type delegate_type = CompatibleChecks (ec, type);
public const string ClassNamePrefix = "<>__AnonType";
public const string SignatureForError = "anonymous type";
- readonly ArrayList parameters;
+ readonly IList<AnonymousTypeParameter> parameters;
- private AnonymousTypeClass (DeclSpace parent, MemberName name, ArrayList parameters, Location loc)
+ private AnonymousTypeClass (DeclSpace parent, MemberName name, IList<AnonymousTypeParameter> parameters, Location loc)
: base (parent, name, (RootContext.EvalMode ? Modifiers.PUBLIC : 0) | Modifiers.SEALED)
{
this.parameters = parameters;
}
- public static AnonymousTypeClass Create (CompilerContext ctx, TypeContainer parent, ArrayList parameters, Location loc)
+ public static AnonymousTypeClass Create (CompilerContext ctx, TypeContainer parent, IList<AnonymousTypeParameter> parameters, Location loc)
{
string name = ClassNamePrefix + types_counter++;
return SignatureForError;
}
- public ArrayList Parameters {
+ public IList<AnonymousTypeParameter> Parameters {
get {
return parameters;
}
using System;
using System.Diagnostics;
using System.Collections;
-using System.Collections.Specialized;
+using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
/// Creates instance of SecurityAttribute class and add result of CreatePermission method to permission table.
/// </summary>
/// <returns></returns>
- public void ExtractSecurityPermissionSet (ListDictionary permissions)
+ public void ExtractSecurityPermissionSet (Dictionary<SecurityAction, PermissionSet> permissions)
{
Type orig_assembly_type = null;
}
}
- PermissionSet ps = (PermissionSet)permissions [action];
- if (ps == null) {
+ PermissionSet ps;
+ if (!permissions.TryGetValue (action, out ps)) {
if (sa is PermissionSetAttribute)
ps = new PermissionSet (sa.Unrestricted ? PermissionState.Unrestricted : PermissionState.None);
else
public override int GetHashCode ()
{
- return base.GetHashCode ();
+ return type.GetHashCode () ^ Target.GetHashCode ();
}
/// <summary>
/// Emit attribute for Attributable symbol
/// </summary>
- public void Emit (ListDictionary allEmitted)
+ public void Emit (Dictionary<Attribute, List<Attribute>> allEmitted)
{
CustomAttributeBuilder cb = Resolve ();
if (cb == null)
}
if (!usage_attr.AllowMultiple && allEmitted != null) {
- if (allEmitted.Contains (this)) {
- ArrayList a = allEmitted [this] as ArrayList;
+ if (allEmitted.ContainsKey (this)) {
+ var a = allEmitted [this];
if (a == null) {
- a = new ArrayList (2);
+ a = new List<Attribute> (2);
allEmitted [this] = a;
}
a.Add (this);
}
public class Attributes {
- public readonly ArrayList Attrs;
+ public readonly List<Attribute> Attrs;
public Attributes (Attribute a)
{
- Attrs = new ArrayList ();
+ Attrs = new List<Attribute> ();
Attrs.Add (a);
}
- public Attributes (ArrayList attrs)
+ public Attributes (List<Attribute> attrs)
{
Attrs = attrs;
}
- public void AddAttributes (ArrayList attrs)
+ public void AddAttributes (List<Attribute> attrs)
{
Attrs.AddRange (attrs);
}
public Attributes Clone ()
{
- ArrayList al = new ArrayList (Attrs.Count);
+ var al = new List<Attribute> (Attrs.Count);
foreach (Attribute a in Attrs)
al.Add (a.Clone ());
{
CheckTargets ();
- ListDictionary ld = Attrs.Count > 1 ? new ListDictionary () : null;
+ Dictionary<Attribute, List<Attribute>> ld = Attrs.Count > 1 ? new Dictionary<Attribute, List<Attribute>> () : null;
foreach (Attribute a in Attrs)
a.Emit (ld);
if (ld == null || ld.Count == 0)
return;
- foreach (DictionaryEntry d in ld) {
+ foreach (var d in ld) {
if (d.Value == null)
continue;
- Attribute a = (Attribute) d.Key;
+ Attribute a = d.Key;
- foreach (Attribute collision in (ArrayList)d.Value)
+ foreach (Attribute collision in d.Value)
a.Report.SymbolRelatedToPreviousError (collision.Location, "");
a.Report.Error (579, a.Location, "The attribute `{0}' cannot be applied multiple times",
using System;
using System.Collections;
-using System.Collections.Specialized;
+using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
public readonly Kind Kind;
// Holds a list of classes and structures
- protected ArrayList types;
+ protected MemberCoreArrayList types;
MemberCoreArrayList ordered_explicit_member_list;
MemberCoreArrayList ordered_member_list;
}
}
- public abstract class ClassOrStruct : TypeContainer {
- ListDictionary declarative_security;
+ public abstract class ClassOrStruct : TypeContainer
+ {
+ Dictionary<SecurityAction, PermissionSet> declarative_security;
public ClassOrStruct (NamespaceEntry ns, DeclSpace parent,
MemberName name, Attributes attrs, Kind kind)
{
if (a.IsValidSecurityAttribute ()) {
if (declarative_security == null)
- declarative_security = new ListDictionary ();
+ declarative_security = new Dictionary<SecurityAction, PermissionSet> ();
a.ExtractSecurityPermissionSet (declarative_security);
return;
base.Emit ();
if (declarative_security != null) {
- foreach (DictionaryEntry de in declarative_security) {
- TypeBuilder.AddDeclarativeSecurity ((SecurityAction)de.Key, (PermissionSet)de.Value);
+ foreach (var de in declarative_security) {
+ TypeBuilder.AddDeclarativeSecurity (de.Key, de.Value);
}
}
}
{
public MethodBuilder MethodBuilder;
ReturnParameter return_attributes;
- ListDictionary declarative_security;
+ Dictionary<SecurityAction, PermissionSet> declarative_security;
protected MethodData MethodData;
static string[] attribute_targets = new string [] { "method", "return" };
if (a.IsValidSecurityAttribute ()) {
if (declarative_security == null)
- declarative_security = new ListDictionary ();
+ declarative_security = new Dictionary<SecurityAction, PermissionSet> ();
a.ExtractSecurityPermissionSet (declarative_security);
return;
}
OptAttributes.Emit ();
if (declarative_security != null) {
- foreach (DictionaryEntry de in declarative_security) {
- MethodBuilder.AddDeclarativeSecurity ((SecurityAction)de.Key, (PermissionSet)de.Value);
+ foreach (var de in declarative_security) {
+ MethodBuilder.AddDeclarativeSecurity (de.Key, de.Value);
}
}
public class Constructor : MethodCore, IMethodData {
public ConstructorBuilder ConstructorBuilder;
public ConstructorInitializer Initializer;
- ListDictionary declarative_security;
+ Dictionary<SecurityAction, PermissionSet> declarative_security;
bool has_compliant_args;
// <summary>
{
if (a.IsValidSecurityAttribute ()) {
if (declarative_security == null) {
- declarative_security = new ListDictionary ();
+ declarative_security = new Dictionary<SecurityAction, PermissionSet> ();
}
a.ExtractSecurityPermissionSet (declarative_security);
return;
source.CloseMethod ();
if (declarative_security != null) {
- foreach (DictionaryEntry de in declarative_security) {
- ConstructorBuilder.AddDeclarativeSecurity ((SecurityAction)de.Key, (PermissionSet)de.Value);
+ foreach (var de in declarative_security) {
+ ConstructorBuilder.AddDeclarativeSecurity (de.Key, de.Value);
}
}
public abstract class AbstractPropertyEventMethod : MemberCore, IMethodData {
protected MethodData method_data;
protected ToplevelBlock block;
- protected ListDictionary declarative_security;
+ protected Dictionary<SecurityAction, PermissionSet> declarative_security;
// The accessor are created even if they are not wanted.
// But we need them because their names are reserved.
if (a.IsValidSecurityAttribute ()) {
if (declarative_security == null)
- declarative_security = new ListDictionary ();
+ declarative_security = new Dictionary<SecurityAction, PermissionSet> ();
a.ExtractSecurityPermissionSet (declarative_security);
return;
}
OptAttributes.Emit ();
if (declarative_security != null) {
- foreach (DictionaryEntry de in declarative_security) {
- method_data.MethodBuilder.AddDeclarativeSecurity ((SecurityAction)de.Key, (PermissionSet)de.Value);
+ foreach (var de in declarative_security) {
+ method_data.MethodBuilder.AddDeclarativeSecurity (de.Key, de.Value);
}
}
using System;
using System.IO;
using System.Collections;
-using System.Collections.Specialized;
+using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using System.Reflection.Emit;
public abstract class CommonAssemblyModulClass : Attributable, IMemberContext
{
- public void AddAttributes (ArrayList attrs, IMemberContext context)
+ public void AddAttributes (List<Attribute> attrs, IMemberContext context)
{
foreach (Attribute a in attrs)
a.AttachTo (this, context);
public Attribute ClsCompliantAttribute;
- ListDictionary declarative_security;
+ Dictionary<SecurityAction, PermissionSet> declarative_security;
bool has_extension_method;
public AssemblyName Name;
MethodInfo add_type_forwarder;
- ListDictionary emitted_forwarders;
+ Dictionary<Type, Attribute> emitted_forwarders;
// Module is here just because of error messages
static string[] attribute_targets = new string [] { "assembly", "module" };
g.AttachTo (this, this);
if (g.Resolve () != null) {
- declarative_security = new ListDictionary ();
+ declarative_security = new Dictionary<SecurityAction, PermissionSet> ();
g.ExtractSecurityPermissionSet (declarative_security);
}
}
{
if (a.IsValidSecurityAttribute ()) {
if (declarative_security == null)
- declarative_security = new ListDictionary ();
+ declarative_security = new Dictionary<SecurityAction, PermissionSet> ();
a.ExtractSecurityPermissionSet (declarative_security);
return;
t = TypeManager.DropGenericTypeArguments (t);
if (emitted_forwarders == null) {
- emitted_forwarders = new ListDictionary();
- } else if (emitted_forwarders.Contains(t)) {
- Report.SymbolRelatedToPreviousError(((Attribute)emitted_forwarders[t]).Location, null);
+ emitted_forwarders = new Dictionary<Type, Attribute> ();
+ } else if (emitted_forwarders.ContainsKey (t)) {
+ Report.SymbolRelatedToPreviousError(emitted_forwarders[t].Location, null);
Report.Error(739, a.Location, "A duplicate type forward of type `{0}'",
TypeManager.CSharpName(t));
return;
builder_instance = fi.GetValue (Builder);
}
- object[] args = new object [] { declarative_security [SecurityAction.RequestMinimum],
- declarative_security [SecurityAction.RequestOptional],
- declarative_security [SecurityAction.RequestRefuse] };
+ var args = new PermissionSet [3];
+ declarative_security.TryGetValue (SecurityAction.RequestMinimum, out args [0]);
+ declarative_security.TryGetValue (SecurityAction.RequestOptional, out args [1]);
+ declarative_security.TryGetValue (SecurityAction.RequestRefuse, out args [2]);
add_permission.Invoke (builder_instance, args);
}
catch {
using System.Text;
using System.IO;
using System;
+using System.Collections;
+using System.Collections.Generic;
namespace Mono.CSharp
{
- using System.Collections;
-
/// <summary>
/// The C# Parser
/// </summary>
: attribute_section
{
if (current_attr_target != String.Empty) {
- ArrayList sect = (ArrayList) $1;
+ var sect = (List<Attribute>) $1;
if (global_attrs_enabled) {
if (current_attr_target == "module") {
{
if (current_attr_target != String.Empty) {
Attributes attrs = $1 as Attributes;
- ArrayList sect = (ArrayList) $2;
+ var sect = (List<Attribute>) $2;
if (global_attrs_enabled) {
if (current_attr_target == "module") {
attribute_list
: attribute
{
- $$ = new ArrayList (4) { $1 };
+ $$ = new List<Attribute> (4) { (Attribute) $1 };
}
| attribute_list COMMA attribute
{
- ArrayList attrs = (ArrayList) $1;
- attrs.Add ($3);
+ var attrs = (List<Attribute>) $1;
+ attrs.Add ((Attribute) $3);
$$ = attrs;
}
else if (RootContext.Version <= LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
- $$ = new NewAnonymousType ((ArrayList) $3, current_container, GetLocation ($1));
+ $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
}
;
anonymous_type_parameters
: anonymous_type_parameter
{
- ArrayList a = new ArrayList (4);
- a.Add ($1);
+ var a = new List<AnonymousTypeParameter> (4);
+ a.Add ((AnonymousTypeParameter) $1);
$$ = a;
}
| anonymous_type_parameters COMMA anonymous_type_parameter
{
- ArrayList a = (ArrayList) $1;
- a.Add ($3);
+ var a = (List<AnonymousTypeParameter>) $1;
+ a.Add ((AnonymousTypeParameter) $3);
$$ = a;
}
;
}
| error
{
- Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " +
- "Anonymous type members must be a member assignment, simple name or member access expression");
+ Report.Error (746, lexer.Location,
+ "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
+ $$ = null;
}
;
if (arg.StartsWith (w_restore)) {
int[] codes = ParseNumbers (arg.Substring (w_restore.Length));
- Hashtable w_table = Report.warning_ignore_table;
+ var w_table = Report.warning_ignore_table;
foreach (int code in codes) {
- if (w_table != null && w_table.Contains (code))
+ if (w_table != null && w_table.ContainsKey (code))
Report.Warning (1635, 1, Location, "Cannot restore warning `CS{0:0000}' because it was disabled globally", code);
Report.RegisterWarningRegion (Location).WarningEnable (Location, code, Report);
}
using System;
using System.Collections;
-using System.Collections.Specialized;
+using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Reflection;
using System.Reflection.Emit;
using System.Collections;
- using System.Collections.Specialized;
+ using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Globalization;
//
// Assemblies references to be linked. Initialized with
// mscorlib.dll here.
- ArrayList references;
+ List<string> references;
//
// If any of these fail, we ignore the problem. This is so
// that we can list all the assemblies in Windows and not fail
// if they are missing on Linux.
//
- ArrayList soft_references;
+ List<string> soft_references;
//
// External aliases for assemblies.
//
- Hashtable external_aliases;
+ Dictionary<string, string> external_aliases;
//
// Modules to be linked
//
- ArrayList modules;
+ List<string> modules;
// Lookup paths
- static ArrayList link_paths;
+ List<string> link_paths;
// Whether we want to only run the tokenizer
bool tokenize;
foreach (string r in references)
LoadAssembly (r, false);
- foreach (DictionaryEntry entry in external_aliases)
- LoadAssembly ((string) entry.Value, (string) entry.Key, false);
+ foreach (var entry in external_aliases)
+ LoadAssembly (entry.Value, entry.Key, false);
GlobalRootNamespace.Instance.ComputeNamespaces (ctx);
}
bool ParseArguments (string[] args, bool require_files)
{
- references = new ArrayList ();
- external_aliases = new Hashtable ();
- soft_references = new ArrayList ();
- modules = new ArrayList (2);
- link_paths = new ArrayList ();
+ references = new List<string> ();
+ external_aliases = new Dictionary<string, string> ();
+ soft_references = new List<string> ();
+ modules = new List<string> (2);
+ link_paths = new List<string> ();
ArrayList response_file_list = null;
bool parsing_options = true;
{
Location.Initialize ();
- ArrayList cu = Location.SourceFiles;
+ var cu = Location.SourceFiles;
for (int i = 0; i < cu.Count; ++i) {
if (tokenize) {
- tokenize_file ((CompilationUnit) cu [i], ctx);
+ tokenize_file (cu [i], ctx);
} else {
- Parse ((CompilationUnit) cu [i]);
+ Parse (cu [i]);
}
}
}
}
- IDictionary embedded_resources = new HybridDictionary ();
+ Dictionary<string, IResource> embedded_resources = new Dictionary<string, IResource> ();
readonly CompilerContext ctx;
public Resources (CompilerContext ctx)
public void Add (bool embeded, string file, string name, bool isPrivate)
{
- if (embedded_resources.Contains (name)) {
+ if (embedded_resources.ContainsKey (name)) {
ctx.Report.Error (1508, "The resource identifier `{0}' has already been used in this assembly", name);
return;
}
using System;
using System.Collections;
-using System.Collections.Specialized;
+using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Globalization;
public class NewAnonymousType : New
{
- static readonly ArrayList EmptyParameters = new ArrayList (0);
+ static readonly IList<AnonymousTypeParameter> EmptyParameters = Array.AsReadOnly (new AnonymousTypeParameter[0]);
- ArrayList parameters;
+ List<AnonymousTypeParameter> parameters;
readonly TypeContainer parent;
AnonymousTypeClass anonymous_type;
- public NewAnonymousType (ArrayList parameters, TypeContainer parent, Location loc)
+ public NewAnonymousType (List<AnonymousTypeParameter> parameters, TypeContainer parent, Location loc)
: base (null, null, loc)
{
this.parameters = parameters;
return;
NewAnonymousType t = (NewAnonymousType) target;
- t.parameters = new ArrayList (parameters.Count);
+ t.parameters = new List<AnonymousTypeParameter> (parameters.Count);
foreach (AnonymousTypeParameter atp in parameters)
- t.parameters.Add (atp.Clone (clonectx));
+ t.parameters.Add ((AnonymousTypeParameter) atp.Clone (clonectx));
}
- AnonymousTypeClass CreateAnonymousType (ResolveContext ec, ArrayList parameters)
+ AnonymousTypeClass CreateAnonymousType (ResolveContext ec, IList<AnonymousTypeParameter> parameters)
{
AnonymousTypeClass type = parent.Module.Compiled.GetAnonymousType (parameters);
if (type != null)
using System;
using System.Reflection;
-using System.Collections;
+using System.Collections.Generic;
namespace Mono.CSharp.Linq
{
protected static Expression CreateRangeVariableType (ToplevelBlock block, IMemberContext context, SimpleMemberName name, Expression init)
{
- ArrayList args = new ArrayList (2);
+ var args = new List<AnonymousTypeParameter> (2);
args.Add (new AnonymousTypeParameter (block.Parameters [0]));
args.Add (new RangeAnonymousTypeParameter (init, name));
return new NewAnonymousType (args, context.CurrentTypeDefinition, name.Location);
using System;
using System.IO;
-using System.Collections;
+using System.Collections.Generic;
using Mono.CompilerServices.SymbolWriter;
namespace Mono.CSharp {
public class CompilationUnit : SourceFile, ICompileUnit
{
CompileUnitEntry comp_unit;
- Hashtable include_files;
- Hashtable conditionals;
+ Dictionary<string, SourceFile> include_files;
+ Dictionary<string, bool> conditionals;
public CompilationUnit (string name, string path, int index)
: base (name, path, index, false)
return;
if (include_files == null)
- include_files = new Hashtable ();
+ include_files = new Dictionary<string, SourceFile> ();
- if (!include_files.Contains (file.Path))
+ if (!include_files.ContainsKey (file.Path))
include_files.Add (file.Path, file);
}
public void AddDefine (string value)
{
if (conditionals == null)
- conditionals = new Hashtable (2);
+ conditionals = new Dictionary<string, bool> (2);
conditionals [value] = true;
}
public void AddUndefine (string value)
{
if (conditionals == null)
- conditionals = new Hashtable (2);
+ conditionals = new Dictionary<string, bool> (2);
- conditionals [value] = null;
+ conditionals [value] = false;
}
CompileUnitEntry ICompileUnit.Entry {
public bool IsConditionalDefined (string value)
{
if (conditionals != null) {
- object res = conditionals [value];
- if (res != null)
- return (bool)res;
+ bool res;
+ if (conditionals.TryGetValue (value, out res))
+ return res;
// When conditional was undefined
- if (conditionals.Contains (value))
+ if (conditionals.ContainsKey (value))
return false;
}
}
}
- static ArrayList source_list;
- static ArrayList compile_units;
- static Hashtable source_files;
+ static List<SourceFile> source_list;
+ static List<CompilationUnit> compile_units;
+ static Dictionary<string, int> source_files;
static int checkpoint_bits;
static int source_count;
static int current_source;
static Location ()
{
- source_files = new Hashtable ();
- source_list = new ArrayList ();
- compile_units = new ArrayList ();
- current_source = 0;
- current_compile_unit = 0;
+ Reset ();
checkpoints = new Checkpoint [10];
}
public static void Reset ()
{
- source_files = new Hashtable ();
- source_list = new ArrayList ();
- compile_units = new ArrayList ();
+ source_files = new Dictionary<string, int> ();
+ source_list = new List<SourceFile> ();
+ compile_units = new List<CompilationUnit> ();
current_source = 0;
current_compile_unit = 0;
source_count = 0;
static public void AddFile (Report r, string name)
{
string path = Path.GetFullPath (name);
-
- if (source_files.Contains (path)){
- int id = (int) source_files [path];
- string other_name = ((SourceFile) source_list [id - 1]).Name;
+ int id;
+ if (source_files.TryGetValue (path, out id)){
+ string other_name = source_list [id - 1].Name;
if (name.Equals (other_name))
r.Warning (2002, 1, "Source file `{0}' specified multiple times", other_name);
else
compile_units.Add (unit);
}
- // IList<CompilationUnit>
- static public ArrayList SourceFiles {
+ public static IList<CompilationUnit> SourceFiles {
get {
return compile_units;
}
} else
path = name;
- if (!source_files.Contains (path)) {
+ if (!source_files.ContainsKey (path)) {
if (source_count >= (1 << checkpoint_bits))
return new SourceFile (name, path, 0, true);
//
using System;
using System.Collections;
-using System.Collections.Specialized;
+using System.Collections.Generic;
using System.Reflection;
namespace Mono.CSharp {
protected readonly string alias_name;
protected Assembly [] referenced_assemblies;
- Hashtable all_namespaces;
+ Dictionary<string, Namespace> all_namespaces;
static RootNamespace ()
{
this.alias_name = alias_name;
referenced_assemblies = new Assembly [0];
- all_namespaces = new Hashtable ();
+ all_namespaces = new Dictionary<string, Namespace> ();
all_namespaces.Add ("", this);
}
public bool IsNamespace (string name)
{
- return all_namespaces.Contains (name);
+ return all_namespaces.ContainsKey (name);
}
protected void RegisterNamespace (string dotted_name)
void RegisterExtensionMethodClass (Type t)
{
string n = t.Namespace;
- Namespace ns = n == null ? GlobalRootNamespace.Instance : (Namespace) all_namespaces[n];
+ Namespace ns = null;
+ if (n == null)
+ ns = GlobalRootNamespace.Instance;
+ else
+ all_namespaces.TryGetValue (n, out ns);
+
if (ns == null)
ns = GetNamespace (n, true);
public class GlobalRootNamespace : RootNamespace {
Module [] modules;
- ListDictionary root_namespaces;
+ Dictionary<string, RootNamespace> root_namespaces;
public static GlobalRootNamespace Instance = new GlobalRootNamespace ();
GlobalRootNamespace ()
: base ("global")
{
- root_namespaces = new ListDictionary ();
+ root_namespaces = new Dictionary<string, RootNamespace> ();
root_namespaces.Add (alias_name, this);
}
public RootNamespace GetRootNamespace (string name)
{
- return (RootNamespace) root_namespaces[name];
+ RootNamespace rn;
+ if (!root_namespaces.TryGetValue (name, out rn))
+ return null;
+
+ return rn;
}
public override Type LookupTypeReflection (CompilerContext ctx, string name, Location loc, bool must_be_unique)
Namespace parent;
string fullname;
- IDictionary namespaces;
- IDictionary declspaces;
+ Dictionary<string, Namespace> namespaces;
+ Dictionary<string, DeclSpace> declspaces;
Hashtable cached_types;
RootNamespace root;
ArrayList external_exmethod_classes;
else
MemberName = new MemberName (name);
- namespaces = new HybridDictionary ();
+ namespaces = new Dictionary<string, Namespace> ();
cached_types = new Hashtable ();
root.RegisterNamespace (this);
else
first = name;
- ns = (Namespace) namespaces [first];
- if (ns == null) {
+ if (!namespaces.TryGetValue (first, out ns)) {
if (!create)
return null;
Type t = null;
if (declspaces != null) {
- DeclSpace tdecl = declspaces [name] as DeclSpace;
- if (tdecl != null) {
+ DeclSpace tdecl;
+ if (declspaces.TryGetValue (name, out tdecl)) {
//
// Note that this is not:
//
typeName = SimpleName.RemoveGenericArity (typeName);
- foreach (DictionaryEntry de in declspaces) {
- string type_item = (string) de.Key;
+ foreach (var de in declspaces) {
+ string type_item = de.Key;
int pos = type_item.LastIndexOf ('`');
if (pos == typeName.Length && String.Compare (typeName, 0, type_item, 0, pos) == 0)
- return ((DeclSpace) de.Value).TypeBuilder;
+ return de.Value.TypeBuilder;
}
return null;
}
public FullNamedExpression Lookup (CompilerContext ctx, string name, Location loc)
{
- if (namespaces.Contains (name))
- return (Namespace) namespaces [name];
+ if (namespaces.ContainsKey (name))
+ return namespaces [name];
return LookupType (ctx, name, loc);
}
public void AddDeclSpace (string name, DeclSpace ds)
{
if (declspaces == null)
- declspaces = new HybridDictionary ();
+ declspaces = new Dictionary<string, DeclSpace> ();
declspaces.Add (name, ds);
}
//
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
// bases that we must implement. Notice that this `flattens' the
// method search space, and takes into account overrides.
// </remarks>
- static ArrayList GetAbstractMethods (Type t)
+ static IList<MethodBase> GetAbstractMethods (Type t)
{
- ArrayList list = null;
+ List<MethodBase> list = null;
bool searching = true;
Type current_type = t;
return list;
}
- PendingImplementation (TypeContainer container, MissingInterfacesInfo [] missing_ifaces, ArrayList abstract_methods, int total)
+ PendingImplementation (TypeContainer container, MissingInterfacesInfo[] missing_ifaces, IList<MethodBase> abstract_methods, int total)
{
TypeBuilder type_builder = container.TypeBuilder;
// We also pre-compute the methods.
//
bool implementing_abstract = ((b != null) && b.IsAbstract && !type_builder.IsAbstract);
- ArrayList abstract_methods = null;
+ IList<MethodBase> abstract_methods = null;
if (implementing_abstract){
abstract_methods = GetAbstractMethods (b);
using System;
using System.IO;
using System.Text;
-using System.Collections;
+using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
/// Whether warnings should be considered errors
/// </summary>
public bool WarningsAreErrors;
- ArrayList warnings_as_error;
- ArrayList warnings_only;
+ List<int> warnings_as_error;
+ List<int> warnings_only;
public static int DebugFlags = 0;
//
// Keeps track of the warnings that we are ignoring
//
- public Hashtable warning_ignore_table;
+ public Dictionary<int, bool> warning_ignore_table;
- Hashtable warning_regions_table;
+ Dictionary<string, WarningRegions> warning_regions_table;
int warning_level;
/// <summary>
/// List of symbols related to reported error/warning. You have to fill it before error/warning is reported.
/// </summary>
- ArrayList extra_information = new ArrayList ();
+ List<string> extra_information = new List<string> ();
//
// IF YOU ADD A NEW WARNING YOU HAVE TO ADD ITS ID HERE
return false;
if (warning_ignore_table != null) {
- if (warning_ignore_table.Contains (code)) {
+ if (warning_ignore_table.ContainsKey (code)) {
return false;
}
}
if (warning_regions_table == null || loc.IsNull)
return true;
- WarningRegions regions = (WarningRegions) warning_regions_table [loc.Name];
- if (regions == null)
+ WarningRegions regions;
+ if (!warning_regions_table.TryGetValue (loc.Name, out regions))
return true;
return regions.IsWarningEnabled (code, loc.Row);
return;
if (warnings_as_error == null)
- warnings_as_error = new ArrayList ();
+ warnings_as_error = new List<int> ();
warnings_as_error.Add (id);
}
return;
if (warnings_only == null)
- warnings_only = new ArrayList ();
+ warnings_only = new List<int> ();
warnings_only.Add (id);
}
public WarningRegions RegisterWarningRegion (Location location)
{
- if (warning_regions_table == null)
- warning_regions_table = new Hashtable ();
+ WarningRegions regions;
+ if (warning_regions_table == null) {
+ regions = null;
+ warning_regions_table = new Dictionary<string, WarningRegions> ();
+ } else {
+ warning_regions_table.TryGetValue (location.Name, out regions);
+ }
- WarningRegions regions = (WarningRegions)warning_regions_table [location.Name];
if (regions == null) {
regions = new WarningRegions ();
warning_regions_table.Add (location.Name, regions);
}
+
return regions;
}
public void SetIgnoreWarning (int code)
{
if (warning_ignore_table == null)
- warning_ignore_table = new Hashtable ();
+ warning_ignore_table = new Dictionary<int, bool> ();
warning_ignore_table [code] = true;
}
sb.Append (", ");
if (arg == null)
sb.Append ("null");
- else if (arg is ICollection)
- sb.Append (PrintCollection ((ICollection) arg));
+// else if (arg is ICollection)
+// sb.Append (PrintCollection ((ICollection) arg));
else
sb.Append (arg);
}
Console.WriteLine (sb.ToString ());
}
-
+/*
static public string PrintCollection (ICollection collection)
{
StringBuilder sb = new StringBuilder ();
sb.Append (")");
return sb.ToString ();
}
+*/
}
public abstract class AbstractMessage
protected readonly Location location;
readonly string message;
- protected AbstractMessage (int code, Location loc, string msg, ArrayList extraInfo)
+ protected AbstractMessage (int code, Location loc, string msg, List<string> extraInfo)
{
this.code = code;
if (code < 0)
this.location = loc;
this.message = msg;
if (extraInfo.Count != 0) {
- this.extra_info = (string[])extraInfo.ToArray (typeof (string));
+ this.extra_info = extraInfo.ToArray ();
}
}
sealed class WarningMessage : AbstractMessage
{
- public WarningMessage (int code, Location loc, string message, ArrayList extra_info)
+ public WarningMessage (int code, Location loc, string message, List<string> extra_info)
: base (code, loc, message, extra_info)
{
}
sealed class ErrorMessage : AbstractMessage
{
- public ErrorMessage (int code, Location loc, string message, ArrayList extraInfo)
+ public ErrorMessage (int code, Location loc, string message, List<string> extraInfo)
: base (code, loc, message, extraInfo)
{
}
//
class SessionReportPrinter : ReportPrinter
{
- ArrayList session_messages;
+ List<AbstractMessage> session_messages;
//
// A collection of exactly same messages reported in all sessions
//
- ArrayList common_messages;
+ List<AbstractMessage> common_messages;
//
// A collection of unique messages reported in all sessions
//
- ArrayList merged_messages;
+ List<AbstractMessage> merged_messages;
public override void Print (AbstractMessage msg)
{
// Console.WriteLine ("RECORDING: {0} {1} {2}", code, location, message);
if (session_messages == null)
- session_messages = new ArrayList ();
+ session_messages = new List<AbstractMessage> ();
session_messages.Add (msg);
// Handles the first session
//
if (common_messages == null) {
- common_messages = new ArrayList (session_messages);
+ common_messages = new List<AbstractMessage> (session_messages);
merged_messages = session_messages;
session_messages = null;
return;
//
public bool Merge (ReportPrinter dest)
{
- ArrayList messages_to_print = merged_messages;
+ var messages_to_print = merged_messages;
if (common_messages != null && common_messages.Count > 0) {
messages_to_print = common_messages;
}
}
- ArrayList regions = new ArrayList ();
+ List<PragmaCmd> regions = new List<PragmaCmd> ();
public void WarningDisable (int line)
{
// Copyright 2004-2008 Novell, Inc
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Diagnostics;
// This hashtable contains all of the #definitions across the source code
// it is used by the ConditionalAttribute handler.
//
- static ArrayList AllDefines;
+ static List<string> AllDefines;
//
// This keeps track of the order in which classes were defined
// or abstract as well as the parent names (to implement new,
// override).
//
- static ArrayList type_container_resolve_order;
+ static List<TypeContainer> type_container_resolve_order;
//
// Holds a reference to the Private Implementation Details
// class.
//
- static ArrayList helper_classes;
+ static List<TypeBuilder> helper_classes;
static TypeBuilder impl_details_class;
if (full)
root = null;
- type_container_resolve_order = new ArrayList ();
+ type_container_resolve_order = new List<TypeContainer> ();
EntryPoint = null;
Checked = false;
Unsafe = false;
//
// Setup default defines
//
- AllDefines = new ArrayList ();
+ AllDefines = new List<string> ();
AddConditional ("__MonoCS__");
}
public static void RegisterCompilerGeneratedType (TypeBuilder helper_class)
{
if (helper_classes == null)
- helper_classes = new ArrayList ();
+ helper_classes = new List<TypeBuilder> ();
helper_classes.Add (helper_class);
}
}
}
- ArrayList delegates = root.Delegates;
+ var delegates = root.Delegates;
if (delegates != null){
foreach (Delegate d in delegates)
d.Define ();
// Check for cycles in the struct layout
//
if (type_container_resolve_order != null){
- Hashtable seen = new Hashtable ();
+ var seen = new Dictionary<TypeContainer, object> ();
foreach (TypeContainer tc in type_container_resolve_order)
TypeManager.CheckStructCycles (tc, seen);
}
//
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
//
public class ModuleCompiled : ModuleContainer
{
- // TODO: It'd be so nice to have generics
- Hashtable anonymous_types;
+ Dictionary<int, List<AnonymousTypeClass>> anonymous_types;
readonly bool is_unsafe;
readonly CompilerContext context;
this.is_unsafe = isUnsafe;
this.context = context;
- types = new ArrayList ();
- anonymous_types = new Hashtable ();
+ types = new MemberCoreArrayList ();
+ anonymous_types = new Dictionary<int, List<AnonymousTypeClass>> ();
}
public override AttributeTargets AttributeTargets {
public void AddAnonymousType (AnonymousTypeClass type)
{
- ArrayList existing = (ArrayList)anonymous_types [type.Parameters.Count];
+ List<AnonymousTypeClass> existing;
+ if (!anonymous_types.TryGetValue (type.Parameters.Count, out existing))
if (existing == null) {
- existing = new ArrayList ();
+ existing = new List<AnonymousTypeClass> ();
anonymous_types.Add (type.Parameters.Count, existing);
}
+
existing.Add (type);
}
- public void AddAttributes (ArrayList attrs)
+ public void AddAttributes (List<Attribute> attrs)
{
foreach (Attribute a in attrs)
a.AttachTo (this, CodeGen.Assembly);
}
}
- public AnonymousTypeClass GetAnonymousType (ArrayList parameters)
+ public AnonymousTypeClass GetAnonymousType (IList<AnonymousTypeParameter> parameters)
{
- ArrayList candidates = (ArrayList) anonymous_types [parameters.Count];
- if (candidates == null)
+ List<AnonymousTypeClass> candidates;
+ if (!anonymous_types.TryGetValue (parameters.Count, out candidates))
return null;
int i;
using System.Reflection.Emit;
using System.Diagnostics;
using System.Collections;
-using System.Collections.Specialized;
+using System.Collections.Generic;
namespace Mono.CSharp {
//
// The statements in this block
//
- protected ArrayList statements;
+ protected List<Statement> statements;
//
// An array of Blocks. We keep track of children just
// Statements and child statements are handled through the
// statements.
//
- ArrayList children;
+ List<Block> children;
//
// Labels. (label, block) pairs.
//
- protected HybridDictionary labels;
+ protected Dictionary<string, LabeledStatement> labels;
//
// Keeps track of (name, type) pairs
//
- IDictionary variables;
+ Dictionary<string, LocalInfo> variables;
//
// Keeps track of constants
- HybridDictionary constants;
+ Dictionary<string, Expression> constants;
//
// Temporary variables.
//
- ArrayList temporary_variables;
+ List<LocalInfo> temporary_variables;
//
// If this is a switch section, the enclosing switch block.
//
Block switch_block;
- protected ArrayList scope_initializers;
+ protected List<Statement> scope_initializers;
- ArrayList anonymous_children;
+ List<ToplevelBlock> anonymous_children;
protected static int id;
this.EndLocation = end;
this.loc = start;
this_id = id++;
- statements = new ArrayList (4);
+ statements = new List<Statement> (4);
}
public Block CreateSwitchBlock (Location start)
get { return this_id; }
}
- public IDictionary Variables {
+ public IDictionary<string, LocalInfo> Variables {
get {
if (variables == null)
- variables = new ListDictionary ();
+ variables = new Dictionary<string, LocalInfo> ();
return variables;
}
}
void AddChild (Block b)
{
if (children == null)
- children = new ArrayList (1);
+ children = new List<Block> (1);
children.Add (b);
}
Toplevel.CheckError158 (name, target.loc);
if (labels == null)
- labels = new HybridDictionary();
+ labels = new Dictionary<string, LabeledStatement> ();
labels.Add (name, target);
return true;
return switch_block.LookupLabel (name);
if (labels != null)
- if (labels.Contains (name))
- return ((LabeledStatement) labels [name]);
+ if (labels.ContainsKey (name))
+ return labels [name];
return null;
}
return false;
if (constants == null)
- constants = new HybridDictionary();
+ constants = new Dictionary<string, Expression> ();
constants.Add (name, value);
Report.Debug (64, "ADD TEMPORARY", this, Toplevel, loc);
if (temporary_variables == null)
- temporary_variables = new ArrayList ();
+ temporary_variables = new List<LocalInfo> ();
int id = ++next_temp_id;
string name = "$s_" + id.ToString ();
LocalInfo ret;
for (Block b = this; b != null; b = b.Parent) {
if (b.variables != null) {
- ret = (LocalInfo) b.variables [name];
- if (ret != null)
+ if (b.variables.TryGetValue (name, out ret))
return ret;
}
}
public Expression GetConstantExpression (string name)
{
+ Expression ret;
for (Block b = this; b != null; b = b.Parent) {
if (b.constants != null) {
- Expression ret = b.constants [name] as Expression;
- if (ret != null)
+ if (b.constants.TryGetValue (name, out ret))
return ret;
}
}
public void AddScopeStatement (Statement s)
{
if (scope_initializers == null)
- scope_initializers = new ArrayList ();
+ scope_initializers = new List<Statement> ();
scope_initializers.Add (s);
}
}
}
- public ArrayList AnonymousChildren {
+ public IList<ToplevelBlock> AnonymousChildren {
get { return anonymous_children; }
}
public void AddAnonymousChild (ToplevelBlock b)
{
if (anonymous_children == null)
- anonymous_children = new ArrayList ();
+ anonymous_children = new List<ToplevelBlock> ();
anonymous_children.Add (b);
}
if (variables == null)
throw new InternalErrorException ("cannot happen");
- foreach (DictionaryEntry de in variables) {
- string name = (string) de.Key;
- LocalInfo vi = (LocalInfo) de.Value;
+ foreach (var de in variables) {
+ string name = de.Key;
+ LocalInfo vi = de.Value;
Type variable_type = vi.VariableType;
if (variable_type == null) {
continue;
}
- Expression cv = (Expression) constants [name];
- if (cv == null)
+ Expression cv;
+ if (!constants.TryGetValue (name, out cv))
continue;
// Don't let 'const int Foo = Foo;' succeed.
if (variables == null || ec.Report.WarningLevel < 3)
return;
- foreach (DictionaryEntry de in variables) {
- LocalInfo vi = (LocalInfo) de.Value;
+ foreach (var de in variables) {
+ LocalInfo vi = de.Value;
if (!vi.Used) {
- string name = (string) de.Key;
+ string name = de.Key;
// vi.VariableInfo can be null for 'catch' variables
if (vi.VariableInfo != null && vi.VariableInfo.IsEverAssigned)
target.Parent = clonectx.RemapBlockCopy (Parent);
if (variables != null){
- target.variables = new Hashtable ();
+ target.variables = new Dictionary<string, LocalInfo> ();
- foreach (DictionaryEntry de in variables){
- LocalInfo newlocal = ((LocalInfo) de.Value).Clone (clonectx);
+ foreach (var de in variables){
+ LocalInfo newlocal = de.Value.Clone (clonectx);
target.variables [de.Key] = newlocal;
- clonectx.AddVariableMap ((LocalInfo) de.Value, newlocal);
+ clonectx.AddVariableMap (de.Value, newlocal);
}
}
- target.statements = new ArrayList (statements.Count);
+ target.statements = new List<Statement> (statements.Count);
foreach (Statement s in statements)
target.statements.Add (s.Clone (clonectx));
if (target.children != null){
- target.children = new ArrayList (children.Count);
+ target.children = new List<Block> (children.Count);
foreach (Block b in children){
target.children.Add (clonectx.LookupBlock (b));
}
}
}
- public class ExplicitBlock : Block {
- HybridDictionary known_variables;
+ public class ExplicitBlock : Block
+ {
+ Dictionary<string, IKnownVariable> known_variables;
protected AnonymousMethodStorey am_storey;
public ExplicitBlock (Block parent, Location start, Location end)
internal void AddKnownVariable (string name, IKnownVariable info)
{
if (known_variables == null)
- known_variables = new HybridDictionary();
+ known_variables = new Dictionary<string, IKnownVariable> ();
known_variables [name] = info;
internal IKnownVariable GetKnownVariable (string name)
{
- return known_variables == null ? null : (IKnownVariable) known_variables [name];
+ if (known_variables == null)
+ return null;
+
+ IKnownVariable kw;
+ if (!known_variables.TryGetValue (name, out kw))
+ return null;
+
+ return kw;
}
public bool HasCapturedThis
// Creates block with original statements
AddStatement (new IteratorStatement (iterator, new Block (this, source)));
- source.statements = new ArrayList (1);
+ source.statements = new List<Statement> (1);
source.AddStatement (new Return (iterator, iterator.Location));
source.IsIterator = false;
bool CheckSwitch (ResolveContext ec)
{
bool error = false;
- Elements = Sections.Count > 10 ?
- (IDictionary)new Hashtable () :
- (IDictionary)new ListDictionary ();
+ Elements = new Dictionary<object, SwitchLabel> ();
foreach (SwitchSection ss in Sections){
foreach (SwitchLabel sl in ss.Labels){
return (EventField) events [ei];
}
- public static bool CheckStructCycles (TypeContainer tc, Hashtable seen)
+ public static bool CheckStructCycles (TypeContainer tc, Dictionary<TypeContainer, object> seen)
{
- Hashtable hash = new Hashtable ();
+ var hash = new Dictionary<TypeContainer, object> ();
return CheckStructCycles (tc, seen, hash);
}
- public static bool CheckStructCycles (TypeContainer tc, Hashtable seen,
- Hashtable hash)
+ public static bool CheckStructCycles (TypeContainer tc, Dictionary<TypeContainer, object> seen,
+ Dictionary<TypeContainer, object> hash)
{
if ((tc.Kind != Kind.Struct) || IsBuiltinType (tc.TypeBuilder))
return true;
//
// `seen' contains all types we've already visited.
//
- if (seen.Contains (tc))
+ if (seen.ContainsKey (tc))
return true;
seen.Add (tc, null);
if (ftc == null)
continue;
- if (hash.Contains (ftc)) {
+ if (hash.ContainsKey (ftc)) {
tc.Compiler.Report.Error (523, tc.Location,
"Struct member `{0}.{1}' of type `{2}' " +
"causes a cycle in the struct layout",
if (!ok)
return false;
- if (!seen.Contains (ftc))
+ if (!seen.ContainsKey (ftc))
seen.Add (ftc, null);
}
//
// The name is assumed to be the same.
//
- public static ArrayList CopyNewMethods (ArrayList target_list, IList new_members)
+ public static List<MethodBase> CopyNewMethods (List<MethodBase> target_list, IList new_members)
{
if (target_list == null){
- target_list = new ArrayList ();
+ target_list = new List<MethodBase> ();
foreach (MemberInfo mi in new_members){
if (mi is MethodBase)
- target_list.Add (mi);
+ target_list.Add ((MethodBase) mi);
}
return target_list;
}
-
- MemberInfo [] target_array = new MemberInfo [target_list.Count];
+
+ MethodBase[] target_array = new MethodBase[target_list.Count];
target_list.CopyTo (target_array, 0);
foreach (MemberInfo mi in new_members){
{
BindingFlags bf = original_bf;
- ArrayList method_list = null;
+ List<MethodBase> method_list = null;
Type current_type = queried_type;
bool searching = (original_bf & BindingFlags.DeclaredOnly) == 0;
bool skip_iface_check = true, used_cache = false;
return first_members_list;
if (method_list != null && method_list.Count > 0) {
- return (MemberInfo []) method_list.ToArray (typeof (MemberInfo));
+ return method_list.ToArray ();
}
//
// This happens if we already used the cache in the first iteration, in this case