Update SymbolWriter to use generics collections
authorMarek Safar <marek.safar@gmail.com>
Sun, 1 Aug 2010 09:12:50 +0000 (10:12 +0100)
committerMarek Safar <marek.safar@gmail.com>
Sun, 1 Aug 2010 09:22:12 +0000 (10:22 +0100)
mcs/class/Mono.Cecil.Mdb/Makefile
mcs/class/Mono.CompilerServices.SymbolWriter/Makefile
mcs/class/Mono.CompilerServices.SymbolWriter/MonoSymbolFile.cs
mcs/class/Mono.CompilerServices.SymbolWriter/MonoSymbolTable.cs
mcs/class/Mono.CompilerServices.SymbolWriter/MonoSymbolWriter.cs

index 689f5d03ddf06c72c257c335730b40a73266c70a..ecb9bb41d834bde05644a3375205f0997ba535e4 100644 (file)
@@ -7,7 +7,7 @@ LIBRARY_PACKAGE = none
 
 CECIL = $(topdir)/class/lib/$(PROFILE)/Mono.Cecil.dll
 
-LIB_MCS_FLAGS = /r:$(corlib) /r:$(CECIL) /d:CECIL -keyfile:$(LIBRARY_SNK)
+LIB_MCS_FLAGS = /r:$(corlib) /r:System.dll /r:$(CECIL) /d:CECIL -keyfile:$(LIBRARY_SNK)
 
 NO_TEST = yes
 
index df0f8337baee5bbc02c547090ebbb65786baf213..4e8f2ab38911416faf5a0cadbcf77531dc79f6a6 100644 (file)
@@ -5,7 +5,7 @@ include ../../build/rules.make
 LIBRARY = Mono.CompilerServices.SymbolWriter.dll
 LIBRARY_USE_INTERMEDIATE_FILE = yes
 
-LIB_MCS_FLAGS = /r:$(corlib)
+LIB_MCS_FLAGS = /r:$(corlib) /r:System.dll
 NO_TEST = yes
 
 ifneq (basic, $(PROFILE))
index 3f11a0f56c7a77a68fb31c7bc77615e83c6b0466..8c2ee40d926c533f19bf3bf86cdbd65d33436693 100644 (file)
@@ -31,7 +31,7 @@
 using System;
 using System.Reflection;
 using SRE = System.Reflection.Emit;
-using System.Collections;
+using System.Collections.Generic;
 using System.Text;
 using System.Threading;
 using System.IO;
@@ -163,11 +163,11 @@ namespace Mono.CompilerServices.SymbolWriter
 
        public class MonoSymbolFile : IDisposable
        {
-               ArrayList methods = new ArrayList ();
-               ArrayList sources = new ArrayList ();
-               ArrayList comp_units = new ArrayList ();
-               Hashtable type_hash = new Hashtable ();
-               Hashtable anonymous_scopes;
+               List<MethodEntry> methods = new List<MethodEntry> ();
+               List<SourceFileEntry> sources = new List<SourceFileEntry> ();
+               List<CompileUnitEntry> comp_units = new List<CompileUnitEntry> ();
+               Dictionary<Type, int> type_hash = new Dictionary<Type, int> ();
+               Dictionary<int, AnonymousScopeEntry> anonymous_scopes;
 
                OffsetTable ot;
                int last_type_index;
@@ -199,10 +199,11 @@ namespace Mono.CompilerServices.SymbolWriter
 
                internal int DefineType (Type type)
                {
-                       if (type_hash.Contains (type))
-                               return (int) type_hash [type];
+                       int index;
+                       if (type_hash.TryGetValue (type, out index))
+                               return index;
 
-                       int index = ++last_type_index;
+                       index = ++last_type_index;
                        type_hash.Add (type, index);
                        return index;
                }
@@ -234,7 +235,7 @@ namespace Mono.CompilerServices.SymbolWriter
                                throw new InvalidOperationException ();
 
                        if (anonymous_scopes == null)
-                               anonymous_scopes = new Hashtable ();
+                               anonymous_scopes = new Dictionary<int, AnonymousScopeEntry>  ();
 
                        anonymous_scopes.Add (id, new AnonymousScopeEntry (id));
                }
@@ -245,7 +246,7 @@ namespace Mono.CompilerServices.SymbolWriter
                        if (reader != null)
                                throw new InvalidOperationException ();
 
-                       AnonymousScopeEntry scope = (AnonymousScopeEntry) anonymous_scopes [scope_id];
+                       AnonymousScopeEntry scope = anonymous_scopes [scope_id];
                        scope.AddCapturedVariable (name, captured_name, kind);
                }
 
@@ -254,7 +255,7 @@ namespace Mono.CompilerServices.SymbolWriter
                        if (reader != null)
                                throw new InvalidOperationException ();
 
-                       AnonymousScopeEntry scope = (AnonymousScopeEntry) anonymous_scopes [scope_id];
+                       AnonymousScopeEntry scope = anonymous_scopes [scope_id];
                        scope.AddCapturedScope (id, captured_name);
                }
 
@@ -381,12 +382,12 @@ namespace Mono.CompilerServices.SymbolWriter
                }
 
                MyBinaryReader reader;
-               Hashtable source_file_hash;
-               Hashtable compile_unit_hash;
+               Dictionary<int, SourceFileEntry> source_file_hash;
+               Dictionary<int, CompileUnitEntry> compile_unit_hash;
 
-               ArrayList method_list;
-               Hashtable method_token_hash;
-               Hashtable source_name_hash;
+               List<MethodEntry> method_list;
+               Dictionary<int, MethodEntry> method_token_hash;
+               Dictionary<string, int> source_name_hash;
 
                Guid guid;
 
@@ -427,8 +428,8 @@ namespace Mono.CompilerServices.SymbolWriter
                                        "Cannot read symbol file `{0}'", filename);
                        }
 
-                       source_file_hash = new Hashtable ();
-                       compile_unit_hash = new Hashtable ();
+                       source_file_hash = new Dictionary<int, SourceFileEntry> ();
+                       compile_unit_hash = new Dictionary<int, CompileUnitEntry> ();
                }
 
                void CheckGuidMatch (Guid other, string filename, string assembly)
@@ -530,8 +531,8 @@ namespace Mono.CompilerServices.SymbolWriter
                                throw new InvalidOperationException ();
 
                        lock (this) {
-                               SourceFileEntry source = (SourceFileEntry) source_file_hash [index];
-                               if (source != null)
+                               SourceFileEntry source;
+                               if (source_file_hash.TryGetValue (index, out source))
                                        return source;
 
                                long old_pos = reader.BaseStream.Position;
@@ -566,8 +567,8 @@ namespace Mono.CompilerServices.SymbolWriter
                                throw new InvalidOperationException ();
 
                        lock (this) {
-                               CompileUnitEntry unit = (CompileUnitEntry) compile_unit_hash [index];
-                               if (unit != null)
+                               CompileUnitEntry unit;
+                               if (compile_unit_hash.TryGetValue (index, out unit))
                                        return unit;
 
                                long old_pos = reader.BaseStream.Position;
@@ -600,8 +601,8 @@ namespace Mono.CompilerServices.SymbolWriter
                                if (method_token_hash != null)
                                        return;
 
-                               method_token_hash = new Hashtable ();
-                               method_list = new ArrayList ();
+                               method_token_hash = new Dictionary<int, MethodEntry> ();
+                               method_list = new List<MethodEntry> ();
 
                                long old_pos = reader.BaseStream.Position;
                                reader.BaseStream.Position = ot.MethodTableOffset;
@@ -623,7 +624,9 @@ namespace Mono.CompilerServices.SymbolWriter
 
                        lock (this) {
                                read_methods ();
-                               return (MethodEntry) method_token_hash [token];
+                               MethodEntry me;
+                               method_token_hash.TryGetValue (token, out me);
+                               return me;
                        }
                }
 
@@ -661,7 +664,7 @@ namespace Mono.CompilerServices.SymbolWriter
 
                        lock (this) {
                                if (source_name_hash == null) {
-                                       source_name_hash = new Hashtable ();
+                                       source_name_hash = new Dictionary<string, int> ();
 
                                        for (int i = 0; i < ot.SourceCount; i++) {
                                                SourceFileEntry source = GetSourceFile (i + 1);
@@ -669,10 +672,10 @@ namespace Mono.CompilerServices.SymbolWriter
                                        }
                                }
 
-                               object value = source_name_hash [file_name];
-                               if (value == null)
+                               int value;
+                               if (!source_name_hash.TryGetValue (file_name, out value))
                                        return -1;
-                               return (int) value;
+                               return value;
                        }
                }
 
@@ -681,18 +684,21 @@ namespace Mono.CompilerServices.SymbolWriter
                        if (reader == null)
                                throw new InvalidOperationException ();
 
+                       AnonymousScopeEntry scope;
                        lock (this) {
-                               if (anonymous_scopes != null)
-                                       return (AnonymousScopeEntry) anonymous_scopes [id];
+                               if (anonymous_scopes != null) {
+                                       anonymous_scopes.TryGetValue (id, out scope);
+                                       return scope;
+                               }
 
-                               anonymous_scopes = new Hashtable ();
+                               anonymous_scopes = new Dictionary<int, AnonymousScopeEntry> ();
                                reader.BaseStream.Position = ot.AnonymousScopeTableOffset;
                                for (int i = 0; i < ot.AnonymousScopeCount; i++) {
-                                       AnonymousScopeEntry scope = new AnonymousScopeEntry (reader);
+                                       scope = new AnonymousScopeEntry (reader);
                                        anonymous_scopes.Add (scope.ID, scope);
                                }
 
-                               return (AnonymousScopeEntry) anonymous_scopes [id];
+                               return anonymous_scopes [id];
                        }
                }
 
index a044a60a2d13fb4a4ba8cb78e8aecb9fe97cb7af..5f30818ff626bf3ec23d046c9ee4e7f09cb5dc3b 100644 (file)
@@ -30,7 +30,7 @@
 
 using System;
 using System.Security.Cryptography;
-using System.Collections;
+using System.Collections.Generic;
 using System.Text;
 using System.IO;
 
@@ -202,13 +202,10 @@ namespace Mono.CompilerServices.SymbolWriter
 
                public static LineNumberEntry Null = new LineNumberEntry (0, 0, 0);
 
-               private class OffsetComparerClass : IComparer
+               private class OffsetComparerClass : IComparer<LineNumberEntry>
                {
-                       public int Compare (object a, object b)
+                       public int Compare (LineNumberEntry l1, LineNumberEntry l2)
                        {
-                               LineNumberEntry l1 = (LineNumberEntry) a;
-                               LineNumberEntry l2 = (LineNumberEntry) b;
-
                                if (l1.Offset < l2.Offset)
                                        return -1;
                                else if (l1.Offset > l2.Offset)
@@ -218,13 +215,10 @@ namespace Mono.CompilerServices.SymbolWriter
                        }
                }
 
-               private class RowComparerClass : IComparer
+               private class RowComparerClass : IComparer<LineNumberEntry>
                {
-                       public int Compare (object a, object b)
+                       public int Compare (LineNumberEntry l1, LineNumberEntry l2)
                        {
-                               LineNumberEntry l1 = (LineNumberEntry) a;
-                               LineNumberEntry l2 = (LineNumberEntry) b;
-
                                if (l1.Row < l2.Row)
                                        return -1;
                                else if (l1.Row > l2.Row)
@@ -234,8 +228,8 @@ namespace Mono.CompilerServices.SymbolWriter
                        }
                }
 
-               public static readonly IComparer OffsetComparer = new OffsetComparerClass ();
-               public static readonly IComparer RowComparer = new RowComparerClass ();
+               public static readonly IComparer<LineNumberEntry> OffsetComparer = new OffsetComparerClass ();
+               public static readonly IComparer<LineNumberEntry> RowComparer = new RowComparerClass ();
 
                public override string ToString ()
                {
@@ -453,8 +447,8 @@ namespace Mono.CompilerServices.SymbolWriter
                public readonly int ID;
                #endregion
 
-               ArrayList captured_vars = new ArrayList ();
-               ArrayList captured_scopes = new ArrayList ();
+               List<CapturedVariable> captured_vars = new List<CapturedVariable> ();
+               List<CapturedScope> captured_scopes = new List<CapturedScope> ();
 
                public AnonymousScopeEntry (int id)
                {
@@ -529,8 +523,8 @@ namespace Mono.CompilerServices.SymbolWriter
 
                MonoSymbolFile file;
                SourceFileEntry source;
-               ArrayList include_files;
-               ArrayList namespaces;
+               List<SourceFileEntry> include_files;
+               List<NamespaceEntry> namespaces;
 
                bool creating;
 
@@ -550,7 +544,7 @@ namespace Mono.CompilerServices.SymbolWriter
                        this.Index = file.AddCompileUnit (this);
 
                        creating = true;
-                       namespaces = new ArrayList ();
+                       namespaces = new List<NamespaceEntry> ();
                }
 
                public void AddFile (SourceFileEntry file)
@@ -559,7 +553,7 @@ namespace Mono.CompilerServices.SymbolWriter
                                throw new InvalidOperationException ();
 
                        if (include_files == null)
-                               include_files = new ArrayList ();
+                               include_files = new List<SourceFileEntry> ();
 
                        include_files.Add (file);
                }
@@ -635,13 +629,13 @@ namespace Mono.CompilerServices.SymbolWriter
 
                                int count_includes = reader.ReadLeb128 ();
                                if (count_includes > 0) {
-                                       include_files = new ArrayList ();
+                                       include_files = new List<SourceFileEntry> ();
                                        for (int i = 0; i < count_includes; i++)
                                                include_files.Add (file.GetSourceFile (reader.ReadLeb128 ()));
                                }
 
                                int count_ns = reader.ReadLeb128 ();
-                               namespaces = new ArrayList ();
+                               namespaces = new List<NamespaceEntry> ();
                                for (int i = 0; i < count_ns; i ++)
                                        namespaces.Add (new NamespaceEntry (file, reader));
 
@@ -913,7 +907,7 @@ namespace Mono.CompilerServices.SymbolWriter
 
                void DoRead (MonoSymbolFile file, MyBinaryReader br)
                {
-                       ArrayList lines = new ArrayList ();
+                       var lines = new List<LineNumberEntry> ();
 
                        bool is_hidden = false, modified = false;
                        int stm_line = 1, stm_offset = 0, stm_file = 1;
@@ -1118,9 +1112,9 @@ namespace Mono.CompilerServices.SymbolWriter
                        locals_check_done :
                                ;
                        } else {
-                               Hashtable local_names = new Hashtable ();
+                               var local_names = new Dictionary<string, LocalVariableEntry> ();
                                foreach (LocalVariableEntry local in locals) {
-                                       if (local_names.Contains (local.Name)) {
+                                       if (local_names.ContainsKey (local.Name)) {
                                                flags |= Flags.LocalNamesAmbiguous;
                                                break;
                                        }
index ae36bc6d727c5523c32b81f86ec1d003e17fd9e6..7c1152f302514b3e7816870737ccc4666bb0e6aa 100644 (file)
 
 using System;
 using System.Runtime.CompilerServices;
-using System.Collections;
+using System.Collections.Generic;
 using System.IO;
        
 namespace Mono.CompilerServices.SymbolWriter
 {
        public class MonoSymbolWriter
        {
-               ArrayList methods = null;
-               ArrayList sources = null;
-               ArrayList comp_units = null;
+               List<SourceMethodBuilder> methods;
+               List<SourceFileEntry> sources;
+               List<CompileUnitEntry> comp_units;
                protected readonly MonoSymbolFile file;
-               string filename = null;
+               string filename;
                
-               private SourceMethodBuilder current_method = null;
-               private Stack current_method_stack;
+               private SourceMethodBuilder current_method;
+               private Stack<SourceMethodBuilder> current_method_stack;
 
                public MonoSymbolWriter (string filename)
                {
-                       this.methods = new ArrayList ();
-                       this.sources = new ArrayList ();
-                       this.comp_units = new ArrayList ();
-                       this.current_method_stack = new Stack ();
+                       this.methods = new List<SourceMethodBuilder> ();
+                       this.sources = new List<SourceFileEntry> ();
+                       this.comp_units = new List<CompileUnitEntry> ();
+                       this.current_method_stack = new Stack<SourceMethodBuilder> ();
                        this.file = new MonoSymbolFile ();
 
                        this.filename = filename + ".mdb";
@@ -239,10 +239,10 @@ namespace Mono.CompilerServices.SymbolWriter
 
        public class SourceMethodBuilder
        {
-               ArrayList _locals;
-               ArrayList _blocks;
-               ArrayList _scope_vars;
-               Stack _block_stack;
+               List<LocalVariableEntry> _locals;
+               List<CodeBlockEntry> _blocks;
+               List<ScopeVariable> _scope_vars;
+               Stack<CodeBlockEntry> _block_stack;
                string _real_name;
                IMethodDef _method;
                ICompileUnit _comp_unit;
@@ -278,9 +278,9 @@ namespace Mono.CompilerServices.SymbolWriter
                public void StartBlock (CodeBlockEntry.Type type, int start_offset)
                {
                        if (_block_stack == null)
-                               _block_stack = new Stack ();
+                               _block_stack = new Stack<CodeBlockEntry> ();
                        if (_blocks == null)
-                               _blocks = new ArrayList ();
+                               _blocks = new List<CodeBlockEntry> ();
 
                        int parent = CurrentBlock != null ? CurrentBlock.Index : -1;
 
@@ -333,7 +333,7 @@ namespace Mono.CompilerServices.SymbolWriter
                public void AddLocal (int index, string name)
                {
                        if (_locals == null)
-                               _locals = new ArrayList ();
+                               _locals = new List<LocalVariableEntry> ();
                        int block_idx = CurrentBlock != null ? CurrentBlock.Index : 0;
                        _locals.Add (new LocalVariableEntry (index, name, block_idx));
                }
@@ -352,7 +352,7 @@ namespace Mono.CompilerServices.SymbolWriter
                public void AddScopeVariable (int scope, int index)
                {
                        if (_scope_vars == null)
-                               _scope_vars = new ArrayList ();
+                               _scope_vars = new List<ScopeVariable> ();
                        _scope_vars.Add (
                                new ScopeVariable (scope, index));
                }