replacing Hashtable with HashSet<T> and Dictionary<TKey, TValue> (#3343)

This commit is contained in:
samuraiGH 2025-10-09 18:40:11 +03:00 committed by GitHub
parent b4a77bfbbb
commit ab7d9dd492
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 295 additions and 306 deletions

View file

@ -42,7 +42,7 @@ namespace CodeCompletion
// TODO: Требуется адаптировать к многоязычности EVA // TODO: Требуется адаптировать к многоязычности EVA
public static SymInfo[] standard_units; public static SymInfo[] standard_units;
private Hashtable cur_used_assemblies; private HashSet<Assembly> cur_used_assemblies;
public CompilationUnit unit; public CompilationUnit unit;
private void InitModules() private void InitModules()
@ -1230,7 +1230,7 @@ namespace CodeCompletion
return false; return false;
} }
private Hashtable tmp_cur_used_assemblies; private HashSet<Assembly> tmp_cur_used_assemblies;
//kazhdaja programma mozhet imet svoj spisok podkluchaemyh sborok, //kazhdaja programma mozhet imet svoj spisok podkluchaemyh sborok,
//poetomu nado sohranat i vosstanavlivat tekushij kesh sborok //poetomu nado sohranat i vosstanavlivat tekushij kesh sborok

View file

@ -40,7 +40,7 @@ namespace CodeCompletion
private static Compiler compiler; private static Compiler compiler;
public static bool use_semantic_for_intellisense; public static bool use_semantic_for_intellisense;
private Dictionary<method_call, SymScope> method_call_cache = new Dictionary<method_call, SymScope>(); private Dictionary<method_call, SymScope> method_call_cache = new Dictionary<method_call, SymScope>();
public Hashtable cur_used_assemblies; public HashSet<Assembly> cur_used_assemblies;
public DomSyntaxTreeVisitor(DomConverter converter) public DomSyntaxTreeVisitor(DomConverter converter)
{ {
@ -69,7 +69,7 @@ namespace CodeCompletion
//throw e; //throw e;
//System.Diagnostics.Debug.WriteLine(e.StackTrace); //System.Diagnostics.Debug.WriteLine(e.StackTrace);
} }
cur_used_assemblies = (Hashtable)PascalABCCompiler.NetHelper.NetHelper.cur_used_assemblies.Clone(); cur_used_assemblies = new HashSet<Assembly>(PascalABCCompiler.NetHelper.NetHelper.cur_used_assemblies);
if (use_semantic_for_intellisense && !parse_only_interface) if (use_semantic_for_intellisense && !parse_only_interface)
try try
{ {

View file

@ -156,7 +156,6 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using Languages.Facade; using Languages.Facade;
using SyntaxVisitors;
namespace PascalABCCompiler namespace PascalABCCompiler
{ {
@ -680,7 +679,7 @@ namespace PascalABCCompiler
/// </summary> /// </summary>
private List<CompilationUnit> UnitsToCompileDelayedList = new List<CompilationUnit>(); private List<CompilationUnit> UnitsToCompileDelayedList = new List<CompilationUnit>();
public Hashtable RecompileList = new Hashtable(StringComparer.OrdinalIgnoreCase); public HashSet<string> RecompileList = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private CompilationUnit currentCompilationUnit = null; private CompilationUnit currentCompilationUnit = null;
@ -4005,7 +4004,7 @@ namespace PascalABCCompiler
{ {
if (UnitTable[Path.ChangeExtension(used_unit_fname, null)] != null) return true; if (UnitTable[Path.ChangeExtension(used_unit_fname, null)] != null) return true;
need = true; need = true;
RecompileList[pcu_name] = pcu_name; RecompileList.Add(pcu_name);
} }
} }
if (need) return true; if (need) return true;
@ -4027,7 +4026,7 @@ namespace PascalABCCompiler
pr.AddAlreadyCompiledUnit(pcu_name2); pr.AddAlreadyCompiledUnit(pcu_name2);
return true; return true;
} }
if (RecompileList.ContainsKey(pcu_name2)) if (RecompileList.Contains(pcu_name2))
{ {
return true; return true;
} }

View file

@ -2,13 +2,10 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.IO; using System.IO;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using TreeConverter;
using PascalABCCompiler.TreeConverter; using PascalABCCompiler.TreeConverter;
using PascalABCCompiler.TreeRealization; using PascalABCCompiler.TreeRealization;
using Languages.Facade;
namespace PascalABCCompiler.PCU namespace PascalABCCompiler.PCU
{ {
@ -50,11 +47,11 @@ namespace PascalABCCompiler.PCU
private Dictionary<int, definition_node> ext_members = new Dictionary<int, definition_node>(64);//таблица<int,definition_node> для связывания смещений с импортируемыми сущностями private Dictionary<int, definition_node> ext_members = new Dictionary<int, definition_node>(64);//таблица<int,definition_node> для связывания смещений с импортируемыми сущностями
private Dictionary<string, Assembly> assemblies = new Dictionary<string, Assembly>(); private Dictionary<string, Assembly> assemblies = new Dictionary<string, Assembly>();
private Dictionary<common_type_node, string[]> class_names = new Dictionary<common_type_node, string[]>(); private Dictionary<common_type_node, string[]> class_names = new Dictionary<common_type_node, string[]>();
private Hashtable used_units = new Hashtable(); private HashSet<string> used_units = new HashSet<string>();
public static Hashtable units = new Hashtable(StringComparer.OrdinalIgnoreCase); public static Dictionary<string, PCUReader> units = new Dictionary<string, PCUReader>(StringComparer.OrdinalIgnoreCase);
public static List<PCUReader> AllReaders = new List<PCUReader>(); public static List<PCUReader> AllReaders = new List<PCUReader>();
public bool need=false; public bool need=false;
private Hashtable already_compiled = new Hashtable(); private HashSet<string> already_compiled = new HashSet<string>();
private bool readDebugInfo=true; private bool readDebugInfo=true;
private int InitializationMethodOffset = 0; private int InitializationMethodOffset = 0;
private int FinalizationMethodOffset = 0; private int FinalizationMethodOffset = 0;
@ -183,12 +180,12 @@ namespace PascalABCCompiler.PCU
public void AddAlreadyCompiledUnit(string name) public void AddAlreadyCompiledUnit(string name)
{ {
already_compiled[name] = name; already_compiled.Add(name);
} }
public bool AlreadyCompiled(string name) public bool AlreadyCompiled(string name)
{ {
return already_compiled[name] != null; return already_compiled.Contains(name);
} }
public static void CloseUnits() public static void CloseUnits()
@ -233,8 +230,7 @@ namespace PascalABCCompiler.PCU
{ {
if (id == -1) return this; if (id == -1) return this;
string s = GetFullUnitName(pcu_file.incl_modules[id], pcu_file.languageCaseSensitive); string s = GetFullUnitName(pcu_file.incl_modules[id], pcu_file.languageCaseSensitive);
var pr = (PCUReader)units[s]; if ( !units.TryGetValue(s, out var pr) )
if (pr == null)
{ {
pr = new PCUReader(this); pr = new PCUReader(this);
pr.GetCompilationUnit(s, this.readDebugInfo, pcu_file.languageCaseSensitive); pr.GetCompilationUnit(s, this.readDebugInfo, pcu_file.languageCaseSensitive);
@ -257,8 +253,8 @@ namespace PascalABCCompiler.PCU
this.FileName = FileName; this.FileName = FileName;
this.readDebugInfo = readDebugInfo; this.readDebugInfo = readDebugInfo;
unit_name = System.IO.Path.GetFileNameWithoutExtension(FileName); unit_name = System.IO.Path.GetFileNameWithoutExtension(FileName);
PCUReader pr = (PCUReader)units[FileName]; if ( units.TryGetValue(FileName, out var pr) )
if (pr != null) return pr.unit; return pr.unit;
if (!File.Exists(FileName)) return null; if (!File.Exists(FileName)) return null;
//fs = new FileStream(file_name, FileMode.Open, FileAccess.Read); //fs = new FileStream(file_name, FileMode.Open, FileAccess.Read);
ms = new MemoryStream(File.ReadAllBytes(FileName)); ms = new MemoryStream(File.ReadAllBytes(FileName));
@ -361,7 +357,7 @@ namespace PascalABCCompiler.PCU
if (comp.NeedRecompiled(FileName, pcu_file.incl_modules, this, pcu_file.languageCaseSensitive)) if (comp.NeedRecompiled(FileName, pcu_file.incl_modules, this, pcu_file.languageCaseSensitive))
{ {
//comp.RecompileList.Add(unit_name,unit_name); //comp.RecompileList.Add(unit_name,unit_name);
comp.RecompileList[FileName] = FileName; comp.RecompileList.Add(FileName);
need = true; need = true;
return need; return need;
} }
@ -373,14 +369,13 @@ namespace PascalABCCompiler.PCU
var used_unit_fname = comp.GetUnitFileName(Path.GetFileNameWithoutExtension(pcu_file.incl_modules[i]), pcu_file.incl_modules[i], dir, new SyntaxTree.SourceContext(0,0,0,0, FileName), pcu_file.languageCaseSensitive); var used_unit_fname = comp.GetUnitFileName(Path.GetFileNameWithoutExtension(pcu_file.incl_modules[i]), pcu_file.incl_modules[i], dir, new SyntaxTree.SourceContext(0,0,0,0, FileName), pcu_file.languageCaseSensitive);
if (Path.GetExtension(used_unit_fname) != comp.CompilerOptions.CompiledUnitExtension) return true; if (Path.GetExtension(used_unit_fname) != comp.CompilerOptions.CompiledUnitExtension) return true;
PCUReader pr = (PCUReader)units[used_unit_fname]; if ( !units.TryGetValue(used_unit_fname, out var pr) );
if (pr == null)
pr = new PCUReader(this); pr = new PCUReader(this);
pr.AddAlreadyCompiledUnit(FileName); pr.AddAlreadyCompiledUnit(FileName);
if (used_units[used_unit_fname] == null) if (!used_units.Contains(used_unit_fname))
{ {
used_units[used_unit_fname] = used_units; used_units.Add(used_unit_fname);
if (already_compiled[used_unit_fname] == null) if (!already_compiled.Contains(used_unit_fname))
{ {
var sub_u = pr.GetCompilationUnit(used_unit_fname, this.readDebugInfo, pcu_file.languageCaseSensitive); var sub_u = pr.GetCompilationUnit(used_unit_fname, this.readDebugInfo, pcu_file.languageCaseSensitive);
if (sub_u == null) return true; if (sub_u == null) return true;
@ -2495,8 +2490,7 @@ namespace PascalABCCompiler.PCU
//Добавляем подключенные модули //Добавляем подключенные модули
for (int i = 0; i < uses_count; i++) for (int i = 0; i < uses_count; i++)
{ {
PCUReader pcu_r = units[GetFullUnitName(pcu_file.incl_modules[i], pcu_file.languageCaseSensitive)] as PCUReader; if ( units.TryGetValue(GetFullUnitName(pcu_file.incl_modules[i], pcu_file.languageCaseSensitive), out var pcu_r) );
if (pcu_r != null)
{ {
top_scopes.Add(pcu_r.cun.scope); top_scopes.Add(pcu_r.cun.scope);
} }

View file

@ -255,7 +255,7 @@ namespace PascalABCCompiler.PCU
//ivan //ivan
private List<DotNetNameRef> dot_net_name_list = new List<DotNetNameRef>(); private List<DotNetNameRef> dot_net_name_list = new List<DotNetNameRef>();
private Hashtable tokens = new Hashtable(); private Dictionary<MemberInfo, int> tokens = new Dictionary<MemberInfo, int>();
//ivan //ivan
@ -1202,8 +1202,10 @@ namespace PascalABCCompiler.PCU
private int GetTokenForNetEntity(FieldInfo val) private int GetTokenForNetEntity(FieldInfo val)
{ {
int off=0; int off=0;
object o = tokens[val];
if (o != null) return (int)o; if (tokens.TryGetValue(val, out var o))
return o;
DotNetNameRef dnnr = new DotNetNameRef(); DotNetNameRef dnnr = new DotNetNameRef();
dnnr.kind = DotNetKind.Field; dnnr.kind = DotNetKind.Field;
dnnr.name = val.Name; dnnr.name = val.Name;
@ -1218,8 +1220,10 @@ namespace PascalABCCompiler.PCU
{ {
int off = 0; int off = 0;
//if (tokens.TryGetValue(val, out off)) return off; //if (tokens.TryGetValue(val, out off)) return off;
object o = tokens[val];
if (o != null) return (int)o; if (tokens.TryGetValue(val, out var o))
return o;
DotNetNameRef dnnr = new DotNetNameRef(); DotNetNameRef dnnr = new DotNetNameRef();
dnnr.kind = DotNetKind.Method; dnnr.kind = DotNetKind.Method;
dnnr.name = val.Name; dnnr.name = val.Name;
@ -1255,8 +1259,10 @@ namespace PascalABCCompiler.PCU
{ {
int off = 0; int off = 0;
//if (tokens.TryGetValue(val, out off)) return off; //if (tokens.TryGetValue(val, out off)) return off;
object o = tokens[val];
if (o != null) return (int)o; if (tokens.TryGetValue(val, out var o))
return o;
DotNetNameRef dnnr = new DotNetNameRef(); DotNetNameRef dnnr = new DotNetNameRef();
dnnr.kind = DotNetKind.Constructor; dnnr.kind = DotNetKind.Constructor;
dnnr.name = ".ctor"; dnnr.name = ".ctor";
@ -1284,8 +1290,10 @@ namespace PascalABCCompiler.PCU
{ {
int off = 0; int off = 0;
//if (tokens.TryGetValue(val, out off)) return off; //if (tokens.TryGetValue(val, out off)) return off;
object o = tokens[val];
if (o != null) return (int)o; if (tokens.TryGetValue(val, out var o))
return o;
DotNetNameRef dnnr = new DotNetNameRef(); DotNetNameRef dnnr = new DotNetNameRef();
dnnr.kind = DotNetKind.Property; dnnr.kind = DotNetKind.Property;
dnnr.name = val.Name; dnnr.name = val.Name;
@ -1314,8 +1322,10 @@ namespace PascalABCCompiler.PCU
{ {
int off = 0; int off = 0;
//if (tokens.TryGetValue(val, out off)) return off; //if (tokens.TryGetValue(val, out off)) return off;
object o = tokens[val];
if (o != null) return (int)o; if (tokens.TryGetValue(val, out var o))
return o;
DotNetNameRef dnnr = new DotNetNameRef(); DotNetNameRef dnnr = new DotNetNameRef();
dnnr.kind = DotNetKind.Type; dnnr.kind = DotNetKind.Type;
if (val.FullName != null) if (val.FullName != null)
@ -1891,28 +1901,27 @@ namespace PascalABCCompiler.PCU
return offset; return offset;
} }
private Hashtable var_positions = new Hashtable(); private Dictionary<namespace_variable, List<int>> var_positions = new Dictionary<namespace_variable, List<int>>();
private Hashtable const_positions = new Hashtable(); private Dictionary<namespace_constant_definition, List<int>> const_positions = new Dictionary<namespace_constant_definition, List<int>>();
private void SaveVariableReferencePosition(namespace_variable nv) private void SaveVariableReferencePosition(namespace_variable nv)
{ {
List<int> offs = (List<int>)var_positions[nv]; if ( !var_positions.TryGetValue(nv, out var offs) ){
if (offs == null)
{
offs = new List<int>(); offs = new List<int>();
var_positions[nv] = offs; var_positions[nv] = offs;
} }
offs.Add((int)bw.BaseStream.Position); offs.Add((int)bw.BaseStream.Position);
} }
private void SaveConstantReferencePosition(namespace_constant_definition nv) private void SaveConstantReferencePosition(namespace_constant_definition nv)
{ {
List<int> offs = (List<int>)const_positions[nv]; if ( !const_positions.TryGetValue(nv, out var offs) )
if (offs == null)
{ {
offs = new List<int>(); offs = new List<int>();
const_positions[nv] = offs; const_positions[nv] = offs;
} }
offs.Add((int)bw.BaseStream.Position); offs.Add((int)bw.BaseStream.Position);
} }
@ -1921,7 +1930,7 @@ namespace PascalABCCompiler.PCU
int tmp = (int)bw.BaseStream.Position; int tmp = (int)bw.BaseStream.Position;
foreach (namespace_variable nv in var_positions.Keys) foreach (namespace_variable nv in var_positions.Keys)
{ {
List<int> offs = (List<int>)var_positions[nv]; List<int> offs = var_positions[nv];
byte is_def = 0; byte is_def = 0;
for (int i = 0; i < offs.Count; i++) for (int i = 0; i < offs.Count; i++)
{ {
@ -1931,13 +1940,13 @@ namespace PascalABCCompiler.PCU
} }
bw.BaseStream.Position = tmp; bw.BaseStream.Position = tmp;
} }
private void WriteConstantPositions() private void WriteConstantPositions()
{ {
int tmp = (int)bw.BaseStream.Position; int tmp = (int)bw.BaseStream.Position;
foreach (namespace_constant_definition nv in const_positions.Keys) foreach (namespace_constant_definition nv in const_positions.Keys)
{ {
List<int> offs = (List<int>)const_positions[nv]; List<int> offs = const_positions[nv];
byte is_def = 0; byte is_def = 0;
for (int i = 0; i < offs.Count; i++) for (int i = 0; i < offs.Count; i++)
{ {

View file

@ -2,8 +2,6 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.IO; using System.IO;
namespace PascalABCCompiler namespace PascalABCCompiler
@ -11,9 +9,9 @@ namespace PascalABCCompiler
public class StringResourcesLanguage public class StringResourcesLanguage
{ {
private static Hashtable AccessibleLanguagesHashtable = new Hashtable(StringComparer.OrdinalIgnoreCase); private static Dictionary<string, string> AccessibleLanguagesHashtable = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private static Hashtable AccessibleTwoLetterISOHashtable = new Hashtable(StringComparer.OrdinalIgnoreCase); private static Dictionary<string, string> AccessibleTwoLetterISOHashtable = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private static Hashtable AccessibleLCIDHashtable = new Hashtable(StringComparer.OrdinalIgnoreCase); private static Dictionary<string, string> AccessibleLCIDHashtable = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private static List<string> accessibleLanguages = new List<string>(); private static List<string> accessibleLanguages = new List<string>();
private static string DefaultLanguage = null; private static string DefaultLanguage = null;
private static string DefaultTwoLetterISO = null; private static string DefaultTwoLetterISO = null;
@ -119,11 +117,11 @@ namespace PascalABCCompiler
get{return currentLanguageName;} get{return currentLanguageName;}
set set
{ {
if (AccessibleLanguagesHashtable[value] == null) return; if (!AccessibleLanguagesHashtable.ContainsKey(value)) return;
currentLanguageName = value; currentLanguageName = value;
currentTwoLetterISO = AccessibleTwoLetterISOHashtable[value] as string; currentTwoLetterISO = AccessibleTwoLetterISOHashtable[value];
currentLCID = AccessibleLCIDHashtable[currentTwoLetterISO] as string; currentLCID = AccessibleLCIDHashtable[currentTwoLetterISO];
StringResources.ResDirectoryName = AccessibleLanguagesHashtable[currentLanguageName] as string; StringResources.ResDirectoryName = AccessibleLanguagesHashtable[currentLanguageName];
StringResources.UpdateObjectsText(); StringResources.UpdateObjectsText();
} }
} }
@ -146,7 +144,8 @@ namespace PascalABCCompiler
public static string GetLCIDByTwoLetterISO(string iso) public static string GetLCIDByTwoLetterISO(string iso)
{ {
return AccessibleLCIDHashtable[iso] as string; AccessibleLCIDHashtable.TryGetValue(iso, out var result);
return result;
} }
} }
} }

View file

@ -6,6 +6,7 @@ using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
using System.Collections; using System.Collections;
using System.Linq; using System.Linq;
using System.Collections.Generic;
namespace PascalABCCompiler.NETGenerator { namespace PascalABCCompiler.NETGenerator {
@ -515,11 +516,11 @@ namespace PascalABCCompiler.NETGenerator {
public class Helper { public class Helper {
public Hashtable defs=new Hashtable(); public Hashtable defs=new Hashtable();
private Hashtable processing_types = new Hashtable(); private HashSet<ICommonTypeNode> processing_types = new HashSet<ICommonTypeNode>();
private MethodInfo arr_mi=null; private MethodInfo arr_mi=null;
private Hashtable pas_defs = new Hashtable(); private Dictionary<ITypeNode, Type> pas_defs = new Dictionary<ITypeNode, Type>();
private Hashtable memoized_exprs = new Hashtable(); private Dictionary<IExpressionNode, LocalBuilder> memoized_exprs = new Dictionary<IExpressionNode, LocalBuilder>();
private Hashtable dummy_methods = new Hashtable(); private Dictionary<TypeBuilder, MethodBuilder> dummy_methods = new Dictionary<TypeBuilder, MethodBuilder>();
public Helper() {} public Helper() {}
@ -528,9 +529,9 @@ namespace PascalABCCompiler.NETGenerator {
dummy_methods[tb] = mb; dummy_methods[tb] = mb;
} }
public MethodBuilder GetDummyMethod(TypeBuilder tb) public MethodBuilder GetDummyMethod(TypeBuilder tb)
{ {
return dummy_methods[tb] as MethodBuilder; return dummy_methods[tb];
} }
public void AddPascalTypeReference(ITypeNode tn, Type t) public void AddPascalTypeReference(ITypeNode tn, Type t)
@ -540,7 +541,8 @@ namespace PascalABCCompiler.NETGenerator {
public Type GetPascalTypeReference(ITypeNode tn) public Type GetPascalTypeReference(ITypeNode tn)
{ {
return pas_defs[tn] as Type; pas_defs.TryGetValue(tn, out var result);
return result;
} }
public ConstInfo AddConstant(IConstantDefinitionNode cnst, FieldBuilder fb) public ConstInfo AddConstant(IConstantDefinitionNode cnst, FieldBuilder fb)
@ -872,14 +874,14 @@ namespace PascalABCCompiler.NETGenerator {
return null; return null;
} }
public void SetAsProcessing(ICommonTypeNode type) public void SetAsProcessing(ICommonTypeNode type)
{ {
processing_types[type] = true; processing_types.Add(type);
} }
public bool IsProcessing(ICommonTypeNode type) public bool IsProcessing(ICommonTypeNode type)
{ {
return processing_types[type] != null; return processing_types.Contains(type);
} }
public void LinkExpressionToLocalBuilder(IExpressionNode expr, LocalBuilder lb) public void LinkExpressionToLocalBuilder(IExpressionNode expr, LocalBuilder lb)
@ -889,7 +891,8 @@ namespace PascalABCCompiler.NETGenerator {
public LocalBuilder GetLocalBuilderForExpression(IExpressionNode expr) public LocalBuilder GetLocalBuilderForExpression(IExpressionNode expr)
{ {
return memoized_exprs[expr] as LocalBuilder; memoized_exprs.TryGetValue(expr, out var result);
return result;
} }
//получение типа //получение типа
@ -1050,6 +1053,4 @@ namespace PascalABCCompiler.NETGenerator {
return m; return m;
} }
} }
}
}

View file

@ -2,9 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using System.Reflection.Emit; using System.Reflection.Emit;
using System.Collections;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -19,7 +17,7 @@ namespace PascalABCCompiler.NETGenerator
public static TypeInfo string_type; public static TypeInfo string_type;
public static TypeInfo byte_type; public static TypeInfo byte_type;
public static Type ExceptionType = typeof(Exception); public static Type ExceptionType = typeof(Exception);
public static Type VoidType = typeof(void); public static Type VoidType = typeof(void);
public static Type StringType = typeof(string); public static Type StringType = typeof(string);
public static Type ObjectType = typeof(object); public static Type ObjectType = typeof(object);
public static Type MonitorType = typeof(System.Threading.Monitor); public static Type MonitorType = typeof(System.Threading.Monitor);
@ -46,7 +44,7 @@ namespace PascalABCCompiler.NETGenerator
public static Type DoubleType = typeof(Double); public static Type DoubleType = typeof(Double);
public static Type GCHandleType = typeof(GCHandle); public static Type GCHandleType = typeof(GCHandle);
public static Type MarshalType = typeof(Marshal); public static Type MarshalType = typeof(Marshal);
public static Type TypeType = typeof(Type); public static Type TypeType = typeof(Type);
public static Type ValueType = typeof(ValueType); public static Type ValueType = typeof(ValueType);
public static Type IEnumerableType = typeof(System.Collections.IEnumerable); public static Type IEnumerableType = typeof(System.Collections.IEnumerable);
public static Type IEnumeratorType = typeof(System.Collections.IEnumerator); public static Type IEnumeratorType = typeof(System.Collections.IEnumerator);
@ -54,13 +52,13 @@ namespace PascalABCCompiler.NETGenerator
public static Type IEnumerableGenericType = typeof(System.Collections.Generic.IEnumerable<>); public static Type IEnumerableGenericType = typeof(System.Collections.Generic.IEnumerable<>);
public static Type IEnumeratorGenericType = typeof(System.Collections.Generic.IEnumerator<>); public static Type IEnumeratorGenericType = typeof(System.Collections.Generic.IEnumerator<>);
private static Hashtable types; private static HashSet<Type> types;
private static Hashtable sizes; private static Dictionary<Type, int> sizes;
public static MethodInfo ArrayCopyMethod; public static MethodInfo ArrayCopyMethod;
public static MethodInfo GetTypeFromHandleMethod; public static MethodInfo GetTypeFromHandleMethod;
public static MethodInfo ResizeMethod; public static MethodInfo ResizeMethod;
public static MethodInfo GCHandleFreeMethod; public static MethodInfo GCHandleFreeMethod;
public static MethodInfo StringNullOrEmptyMethod; public static MethodInfo StringNullOrEmptyMethod;
public static MethodInfo UnsizedArrayCreateMethodTemplate = null; public static MethodInfo UnsizedArrayCreateMethodTemplate = null;
public static MethodInfo GCHandleAlloc; public static MethodInfo GCHandleAlloc;
public static MethodInfo GCHandleAllocPinned; public static MethodInfo GCHandleAllocPinned;
@ -86,34 +84,30 @@ namespace PascalABCCompiler.NETGenerator
char_type = new TypeInfo(typeof(char)); char_type = new TypeInfo(typeof(char));
string_type = new TypeInfo(typeof(string)); string_type = new TypeInfo(typeof(string));
byte_type = new TypeInfo(typeof(byte)); byte_type = new TypeInfo(typeof(byte));
types = new Hashtable();
types[BoolType] = BoolType;
types[SByteType] = SByteType;
types[ByteType] = ByteType;
types[CharType] = CharType;
types[Int16Type] = Int16Type;
types[Int32Type] = Int32Type;
types[Int64Type] = Int64Type;
types[UInt16Type] = UInt16Type;
types[UInt32Type] = UInt32Type;
types[UInt64Type] = UInt64Type;
types[SingleType] = SingleType;
types[DoubleType] = DoubleType;
sizes = new Hashtable(); types = new HashSet<Type>()
sizes[BoolType] = sizeof(Boolean); {
sizes[SByteType] = sizeof(SByte); BoolType, SByteType, ByteType, CharType,
sizes[ByteType] = sizeof(Byte); Int16Type, Int32Type, Int64Type,
sizes[CharType] = sizeof(Char); UInt16Type, UInt32Type, UInt64Type,
sizes[Int16Type] = sizeof(Int16); SingleType, DoubleType
sizes[Int32Type] = sizeof(Int32); };
sizes[Int64Type] = sizeof(Int64);
sizes[UInt16Type] = sizeof(UInt16); sizes = new Dictionary<Type, int>
sizes[UInt32Type] = sizeof(UInt32); {
sizes[UInt64Type] = sizeof(UInt64); [BoolType] = sizeof(Boolean),
sizes[SingleType] = sizeof(Single); [SByteType] = sizeof(SByte),
sizes[DoubleType] = sizeof(Double); [ByteType] = sizeof(Byte),
[CharType] = sizeof(Char),
[Int16Type] = sizeof(Int16),
[Int32Type] = sizeof(Int32),
[Int64Type] = sizeof(Int64),
[UInt16Type] = sizeof(UInt16),
[UInt32Type] = sizeof(UInt32),
[UInt64Type] = sizeof(UInt64),
[SingleType] = sizeof(Single),
[DoubleType] = sizeof(Double)
};
//sizes[UIntPtr] = sizeof(UIntPtr); //sizes[UIntPtr] = sizeof(UIntPtr);
//types[TypeType] = TypeType; //types[TypeType] = TypeType;
@ -133,12 +127,12 @@ namespace PascalABCCompiler.NETGenerator
public static bool IsStandType(Type t) public static bool IsStandType(Type t)
{ {
return types[t] != null; return types.Contains(t);
} }
public static int GetPrimitiveTypeSize(Type PrimitiveType) public static int GetPrimitiveTypeSize(Type PrimitiveType)
{ {
return (int)sizes[PrimitiveType]; return sizes[PrimitiveType];
} }
} }

View file

@ -1,8 +1,6 @@
// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt) // Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using PascalABCCompiler.TreeRealization; using PascalABCCompiler.TreeRealization;
using System.Collections; using System.Collections;
@ -37,8 +35,8 @@ namespace PascalABCCompiler
public class OptimizerHelper public class OptimizerHelper
{ {
private Hashtable ht = new Hashtable(); private Hashtable ht = new Hashtable();
private Hashtable warns = new Hashtable(); private Dictionary<var_definition_node, List<CompilerWarningWithLocation>> warns = new Dictionary<var_definition_node, List<CompilerWarningWithLocation>>();
private Hashtable ext_funcs = new Hashtable(); private HashSet<common_function_node> ext_funcs = new HashSet<common_function_node>();
public void AddVariable(var_definition_node vdn) public void AddVariable(var_definition_node vdn)
{ {
@ -76,8 +74,7 @@ namespace PascalABCCompiler
public void AddTempWarning(var_definition_node vdn, CompilerWarningWithLocation cw) public void AddTempWarning(var_definition_node vdn, CompilerWarningWithLocation cw)
{ {
List<CompilerWarningWithLocation> lst = (List<CompilerWarningWithLocation>)warns[vdn]; if ( !warns.TryGetValue(vdn, out var lst) )
if (lst == null)
{ {
lst = new List<CompilerWarningWithLocation>(); lst = new List<CompilerWarningWithLocation>();
warns[vdn] = lst; warns[vdn] = lst;
@ -87,18 +84,18 @@ namespace PascalABCCompiler
public void AddRealWarning(var_definition_node vdn, List<CompilerWarningWithLocation> cw) public void AddRealWarning(var_definition_node vdn, List<CompilerWarningWithLocation> cw)
{ {
List<CompilerWarningWithLocation> lst = (List<CompilerWarningWithLocation>)warns[vdn]; List<CompilerWarningWithLocation> lst = warns[vdn];
cw.AddRange(lst); cw.AddRange(lst);
} }
public void MarkAsExternal(common_function_node cfn) public void MarkAsExternal(common_function_node cfn)
{ {
ext_funcs[cfn] = cfn; ext_funcs.Add(cfn);
} }
public bool IsExternal(common_function_node cfn) public bool IsExternal(common_function_node cfn)
{ {
return ext_funcs[cfn] != null; return ext_funcs.Contains(cfn);
} }
} }
} }

View file

@ -1,25 +1,23 @@
// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt) // Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Xml; using System.Xml;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Globalization;
namespace CodeCompletionTools namespace CodeCompletionTools
{ {
public partial class AssemblyDocCache public partial class AssemblyDocCache
{ {
private static Hashtable ht=new Hashtable(); private static Dictionary<Assembly, XmlDoc> ht = new Dictionary<Assembly, XmlDoc>();
public static string Load(Assembly a, string path) public static string Load(Assembly a, string path)
{ {
if (ht[a] != null) return null; if (!ht.ContainsKey(a)) return null;
string dir; string dir;
if (string.IsNullOrEmpty(a.Location)) if (string.IsNullOrEmpty(a.Location))
dir = path; dir = path;
@ -177,7 +175,7 @@ namespace CodeCompletionTools
public static string GetDocumentation(Type t) public static string GetDocumentation(Type t)
{ {
XmlDoc xdoc = (XmlDoc)ht[t.Assembly]; ht.TryGetValue(t.Assembly, out var xdoc);
try try
{ {
if (xdoc != null) if (xdoc != null)
@ -195,7 +193,7 @@ namespace CodeCompletionTools
public static string GetFullDocumentation(Type t) public static string GetFullDocumentation(Type t)
{ {
XmlDoc xdoc = (XmlDoc)ht[t.Assembly]; ht.TryGetValue(t.Assembly, out var xdoc);
try try
{ {
if (xdoc != null) if (xdoc != null)
@ -277,11 +275,11 @@ namespace CodeCompletionTools
return sb.ToString(); return sb.ToString();
} }
public static string GetDocumentation(ConstructorInfo mi) public static string GetDocumentation(ConstructorInfo mi)
{ {
try try
{ {
XmlDoc xdoc = (XmlDoc)ht[mi.DeclaringType.Assembly]; ht.TryGetValue(mi.DeclaringType.Assembly, out var xdoc);
if (xdoc != null) if (xdoc != null)
{ {
string s = GetNormalHint(xdoc.GetDocumentation("M:" + mi.DeclaringType.FullName + ".#ctor" + GetParamNames(mi), false)); string s = GetNormalHint(xdoc.GetDocumentation("M:" + mi.DeclaringType.FullName + ".#ctor" + GetParamNames(mi), false));
@ -292,14 +290,14 @@ namespace CodeCompletionTools
{ {
} }
return ""; return "";
} }
public static string GetFullDocumentation(ConstructorInfo mi) public static string GetFullDocumentation(ConstructorInfo mi)
{ {
try try
{ {
XmlDoc xdoc = (XmlDoc)ht[mi.DeclaringType.Assembly]; ht.TryGetValue(mi.DeclaringType.Assembly, out var xdoc);
if (xdoc != null) if (xdoc != null)
{ {
return xdoc.GetDocumentation("M:" + mi.DeclaringType.FullName + ".#ctor" + GetParamNames(mi), false); return xdoc.GetDocumentation("M:" + mi.DeclaringType.FullName + ".#ctor" + GetParamNames(mi), false);
@ -316,7 +314,7 @@ namespace CodeCompletionTools
{ {
try try
{ {
XmlDoc xdoc = (XmlDoc)ht[fi.DeclaringType.Assembly]; ht.TryGetValue(fi.DeclaringType.Assembly, out var xdoc);
if (xdoc != null) if (xdoc != null)
{ {
string s = GetNormalHint(xdoc.GetDocumentation("F:"+fi.DeclaringType.FullName+"."+fi.Name,false)); string s = GetNormalHint(xdoc.GetDocumentation("F:"+fi.DeclaringType.FullName+"."+fi.Name,false));
@ -334,7 +332,7 @@ namespace CodeCompletionTools
{ {
try try
{ {
XmlDoc xdoc = (XmlDoc)ht[fi.DeclaringType.Assembly]; ht.TryGetValue(fi.DeclaringType.Assembly, out var xdoc);
if (xdoc != null) if (xdoc != null)
{ {
return xdoc.GetDocumentation("F:" + fi.DeclaringType.FullName + "." + fi.Name, false); return xdoc.GetDocumentation("F:" + fi.DeclaringType.FullName + "." + fi.Name, false);
@ -351,7 +349,7 @@ namespace CodeCompletionTools
{ {
try try
{ {
XmlDoc xdoc = (XmlDoc)ht[pi.DeclaringType.Assembly]; ht.TryGetValue(pi.DeclaringType.Assembly, out var xdoc);
if (xdoc != null) if (xdoc != null)
{ {
string s = GetNormalHint(xdoc.GetDocumentation("P:"+pi.DeclaringType.FullName+"."+pi.Name,false)); string s = GetNormalHint(xdoc.GetDocumentation("P:"+pi.DeclaringType.FullName+"."+pi.Name,false));
@ -369,7 +367,7 @@ namespace CodeCompletionTools
{ {
try try
{ {
XmlDoc xdoc = (XmlDoc)ht[pi.DeclaringType.Assembly]; ht.TryGetValue(pi.DeclaringType.Assembly, out var xdoc);
if (xdoc != null) if (xdoc != null)
{ {
return xdoc.GetDocumentation("P:" + pi.DeclaringType.FullName + "." + pi.Name, false); return xdoc.GetDocumentation("P:" + pi.DeclaringType.FullName + "." + pi.Name, false);
@ -386,7 +384,7 @@ namespace CodeCompletionTools
{ {
try try
{ {
XmlDoc xdoc = (XmlDoc)ht[ei.DeclaringType.Assembly]; ht.TryGetValue(ei.DeclaringType.Assembly, out var xdoc);
if (xdoc != null) if (xdoc != null)
{ {
string s = GetNormalHint(xdoc.GetDocumentation("E:"+ei.DeclaringType.FullName+"."+ei.Name,false)); string s = GetNormalHint(xdoc.GetDocumentation("E:"+ei.DeclaringType.FullName+"."+ei.Name,false));
@ -404,7 +402,7 @@ namespace CodeCompletionTools
{ {
try try
{ {
XmlDoc xdoc = (XmlDoc)ht[ei.DeclaringType.Assembly]; ht.TryGetValue(ei.DeclaringType.Assembly, out var xdoc);
if (xdoc != null) if (xdoc != null)
{ {
return xdoc.GetDocumentation("E:" + ei.DeclaringType.FullName + "." + ei.Name, false); return xdoc.GetDocumentation("E:" + ei.DeclaringType.FullName + "." + ei.Name, false);
@ -429,7 +427,7 @@ namespace CodeCompletionTools
{ {
try try
{ {
XmlDoc xdoc = (XmlDoc)ht[mi.DeclaringType.Assembly]; ht.TryGetValue(mi.DeclaringType.Assembly, out var xdoc);
if (xdoc != null) if (xdoc != null)
{ {
string generic_add = GetGenericAddString(mi); string generic_add = GetGenericAddString(mi);
@ -448,7 +446,7 @@ namespace CodeCompletionTools
{ {
try try
{ {
XmlDoc xdoc = (XmlDoc)ht[mi.DeclaringType.Assembly]; ht.TryGetValue(mi.DeclaringType.Assembly, out var xdoc);
if (xdoc != null) if (xdoc != null)
{ {
string generic_add = GetGenericAddString(mi); string generic_add = GetGenericAddString(mi);
@ -470,7 +468,7 @@ namespace CodeCompletionTools
public static string GetDocumentation(Assembly a, string descr) public static string GetDocumentation(Assembly a, string descr)
{ {
XmlDoc xdoc = (XmlDoc)ht[a]; ht.TryGetValue(a, out var xdoc);
try try
{ {
if (xdoc != null) if (xdoc != null)

View file

@ -6,7 +6,6 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Threading;
using PascalABCCompiler.TreeConverter; using PascalABCCompiler.TreeConverter;
using PascalABCCompiler.TreeRealization; using PascalABCCompiler.TreeRealization;
@ -286,9 +285,9 @@ namespace PascalABCCompiler.NetHelper
} }
public static class NetHelper { public static class NetHelper {
private static Hashtable namespaces; private static Dictionary<string, Type> namespaces;
private static Hashtable types; private static Hashtable types;
private static Dictionary<string,FoundInfo> type_search_cache; private static Dictionary<string, FoundInfo> type_search_cache;
private static Hashtable compiled_pascal_types; private static Hashtable compiled_pascal_types;
/*private static Hashtable methods; /*private static Hashtable methods;
private static Hashtable properties; private static Hashtable properties;
@ -300,19 +299,19 @@ namespace PascalABCCompiler.NetHelper
//private static Hashtable meth_nodes; //private static Hashtable meth_nodes;
private static Dictionary<PropertyInfo, compiled_property_node> prop_nodes; private static Dictionary<PropertyInfo, compiled_property_node> prop_nodes;
private static Hashtable field_nodes; private static Hashtable field_nodes;
private static Hashtable constr_nodes; private static Dictionary<ConstructorInfo, compiled_constructor_node> constr_nodes;
private static Hashtable stand_types; private static HashSet<Type> stand_types;
private static Hashtable type_handles; private static Dictionary<Assembly, Dictionary<int, Type>> type_handles;
private static Hashtable method_handles; private static Dictionary<Type, Dictionary<int, MethodInfo>> method_handles;
private static Hashtable constr_handles; private static Dictionary<Type, Dictionary<int, ConstructorInfo>> constr_handles;
private static Hashtable field_handles; private static Dictionary<Type, Dictionary<int, FieldInfo>> field_handles;
private static Hashtable assemblies; private static HashSet<Assembly> assemblies;
private static Hashtable special_types; private static Dictionary<int, Type> special_types;
private static Hashtable ns_types; private static Dictionary<string, Type[]> ns_types;
private static Type memberInfo; private static Type memberInfo;
private static Hashtable namespace_assemblies; private static Dictionary<Assembly, HashSet<string>> namespace_assemblies;
public static Hashtable cur_used_assemblies; public static HashSet<Assembly> cur_used_assemblies;
private static Hashtable cached_type_extensions; private static HashSet<Type> cached_type_extensions;
public static Type DelegateType; public static Type DelegateType;
public static Type EnumType; public static Type EnumType;
public static Type ArrayType; public static Type ArrayType;
@ -334,29 +333,28 @@ namespace PascalABCCompiler.NetHelper
public static Dictionary<string, List<int>> generics_names = new Dictionary<string, List<int>>(); public static Dictionary<string, List<int>> generics_names = new Dictionary<string, List<int>>();
private static Dictionary<string, MemberInfo> member_cache = new Dictionary<string, MemberInfo>(); private static Dictionary<string, MemberInfo> member_cache = new Dictionary<string, MemberInfo>();
public static void reset() public static void reset()
{ {
if (cur_used_assemblies == null) if (cur_used_assemblies == null)
cur_used_assemblies = new Hashtable(); cur_used_assemblies = new HashSet<Assembly>();
cur_used_assemblies.Clear(); cur_used_assemblies.Clear();
cur_used_assemblies[typeof(string).Assembly] = typeof(string).Assembly; cur_used_assemblies.Add(typeof(string).Assembly);
cur_used_assemblies[typeof(Microsoft.CSharp.CSharpCodeProvider).Assembly] = typeof(Microsoft.CSharp.CSharpCodeProvider).Assembly; cur_used_assemblies.Add(typeof(Microsoft.CSharp.CSharpCodeProvider).Assembly);
type_search_cache.Clear(); type_search_cache.Clear();
}
} private static Dictionary<string, Assembly> ass_name_cache;
private static Dictionary<Assembly, DateTime> file_dates;
private static Hashtable ass_name_cache;
private static Hashtable file_dates;
private static Dictionary<Assembly, string> assm_full_paths; private static Dictionary<Assembly, string> assm_full_paths;
public static bool IsAssemblyChanged(string name) public static bool IsAssemblyChanged(string name)
{ {
if (name == null) return false; if (name == null) return false;
Assembly a = ass_name_cache[name] as Assembly; ass_name_cache.TryGetValue(name, out var a);
if (a != null) if (a != null)
{ {
if (System.IO.File.GetLastWriteTime(name) != (DateTime)file_dates[a]) if (System.IO.File.GetLastWriteTime(name) != file_dates[a])
return true; return true;
return false; return false;
} }
@ -367,12 +365,12 @@ namespace PascalABCCompiler.NetHelper
public static Assembly LoadAssembly(string name, bool use_load_from = false) public static Assembly LoadAssembly(string name, bool use_load_from = false)
{ {
if (name == null) return null; if (name == null) return null;
Assembly a = ass_name_cache[name] as Assembly; ass_name_cache.TryGetValue(name, out var a);
if (a == null && name.IndexOf(System.IO.Path.DirectorySeparatorChar) == -1) if (a == null && name.IndexOf(System.IO.Path.DirectorySeparatorChar) == -1)
a = ass_name_cache[System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), name)] as Assembly; ass_name_cache.TryGetValue(System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), name), out a);
if (a != null) if (a != null)
{ {
if (System.IO.File.GetLastWriteTime(name) == (DateTime)file_dates[a]) if (System.IO.File.GetLastWriteTime(name) == file_dates[a])
return a; return a;
namespace_assemblies.Remove(a); namespace_assemblies.Remove(a);
assemblies.Remove(a); assemblies.Remove(a);
@ -433,24 +431,23 @@ namespace PascalABCCompiler.NetHelper
} }
public static Hashtable entry_types = new Hashtable(); public static Dictionary<Assembly, List<Type>> entry_types = new Dictionary<Assembly, List<Type>>();
private static string curr_inited_assm_path = null; private static string curr_inited_assm_path = null;
public static List<Type> init_namespaces(System.Reflection.Assembly _assembly) public static List<Type> init_namespaces(System.Reflection.Assembly _assembly)
{ {
Assembly assembly = (Assembly)assemblies[_assembly]; Assembly assembly = assemblies.Contains(_assembly) ? _assembly : null;
List<string> nss = new List<string>(); List<string> nss = new List<string>();
cur_used_assemblies[_assembly] = _assembly; cur_used_assemblies.Add(_assembly);
Type entry_type = null; Type entry_type = null;
List<Type> unit_types = entry_types[_assembly] as List<Type>; if ( !entry_types.TryGetValue(_assembly, out var unit_types) )
if (unit_types == null)
unit_types = new List<Type>(); unit_types = new List<Type>();
if (assembly == null) if (assembly == null)
{ {
Type[] tarr = _assembly.GetTypes(); Type[] tarr = _assembly.GetTypes();
//Hashtable ns_ht = new Hashtable(CaseInsensitiveHashCodeProvider.Default,CaseInsensitiveComparer.Default); //Hashtable ns_ht = new Hashtable(CaseInsensitiveHashCodeProvider.Default,CaseInsensitiveComparer.Default);
Hashtable ns_ht = new Hashtable(StringComparer.CurrentCultureIgnoreCase); var ns_ht = new HashSet<string>(StringComparer.CurrentCultureIgnoreCase);
foreach (Type t in tarr) foreach (Type t in tarr)
{ {
if (t.IsNotPublic) if (t.IsNotPublic)
@ -461,7 +458,7 @@ namespace PascalABCCompiler.NetHelper
int pos = s.LastIndexOf('.'); int pos = s.LastIndexOf('.');
//if (pos == -1) //if (pos == -1)
//if (namespaces[s] == null) ns_ht.Add(s,s); //if (namespaces[s] == null) ns_ht.Add(s,s);
ns_ht[s] = s; ns_ht.Add(s);
namespaces[s] = t; namespaces[s] = t;
// SSM 17.05.19 Запретил uses Reflection: https://github.com/pascalabcnet/pascalabcnet/issues/1941 // SSM 17.05.19 Запретил uses Reflection: https://github.com/pascalabcnet/pascalabcnet/issues/1941
/*if (pos != -1) /*if (pos != -1)
@ -482,9 +479,9 @@ namespace PascalABCCompiler.NetHelper
s = s.Substring(0, pos); s = s.Substring(0, pos);
pos = s.LastIndexOf('.'); pos = s.LastIndexOf('.');
//if (pos == -1) //if (pos == -1)
if (namespaces[s] == null) if (!namespaces.ContainsKey(s))
namespaces[s] = t; namespaces[s] = t;
ns_ht[s] = s; ns_ht.Add(s);
} }
} }
TypeInfo ti = new TypeInfo(t, t.FullName); TypeInfo ti = new TypeInfo(t, t.FullName);
@ -747,7 +744,7 @@ namespace PascalABCCompiler.NetHelper
} }
} }
namespace_assemblies[_assembly] = ns_ht; namespace_assemblies[_assembly] = ns_ht;
assemblies[_assembly] = _assembly; assemblies.Add(_assembly);
} }
return unit_types; return unit_types;
} }
@ -856,13 +853,13 @@ namespace PascalABCCompiler.NetHelper
public static bool NamespaceExists(string Namespace) public static bool NamespaceExists(string Namespace)
{ {
Type t = (Type)namespaces[Namespace]; namespaces.TryGetValue(Namespace, out var t);
if (t != null && cur_used_assemblies.ContainsKey(t.Assembly)) return true; if (t != null && cur_used_assemblies.Contains(t.Assembly)) return true;
foreach (Assembly a in namespace_assemblies.Keys) foreach (Assembly a in namespace_assemblies.Keys)
if (cur_used_assemblies.ContainsKey(a) && (namespace_assemblies[a] as Hashtable).ContainsKey(Namespace)) if (cur_used_assemblies.Contains(a) && namespace_assemblies[a].Contains(Namespace))
return true; return true;
return false; return false;
} }
static NetHelper() static NetHelper()
@ -875,46 +872,46 @@ namespace PascalABCCompiler.NetHelper
//types = new Hashtable(1024, CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default); //types = new Hashtable(1024, CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
types = new Hashtable(8096, StringComparer.CurrentCultureIgnoreCase); types = new Hashtable(8096, StringComparer.CurrentCultureIgnoreCase);
compiled_pascal_types = new Hashtable(1024, StringComparer.CurrentCultureIgnoreCase); compiled_pascal_types = new Hashtable(1024, StringComparer.CurrentCultureIgnoreCase);
namespaces = new Hashtable(1024, StringComparer.CurrentCultureIgnoreCase); namespaces = new Dictionary<string, Type>(1024, StringComparer.CurrentCultureIgnoreCase);
ass_name_cache = new Hashtable(1024, StringComparer.CurrentCultureIgnoreCase); ass_name_cache = new Dictionary<string, Assembly>(1024, StringComparer.CurrentCultureIgnoreCase);
assm_full_paths = new Dictionary<Assembly, string>(); assm_full_paths = new Dictionary<Assembly, string>();
//ass_name_cache = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default); //ass_name_cache = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
file_dates = new Hashtable(); file_dates = new Dictionary<Assembly, DateTime>();
//methods = new Hashtable(); //methods = new Hashtable();
//properties = new Hashtable(); //properties = new Hashtable();
members = new Dictionary<Type, Dictionary<string, List<MemberInfo>>>(128); members = new Dictionary<Type, Dictionary<string, List<MemberInfo>>>(128);
//fields = new Hashtable(); //fields = new Hashtable();
assemblies = new Hashtable(); assemblies = new HashSet<Assembly>();
//meth_nodes = new Hashtable(); //meth_nodes = new Hashtable();
prop_nodes = new Dictionary<PropertyInfo,compiled_property_node>(); prop_nodes = new Dictionary<PropertyInfo,compiled_property_node>();
field_nodes = new Hashtable(); field_nodes = new Hashtable();
constr_nodes = new Hashtable(); constr_nodes = new Dictionary<ConstructorInfo, compiled_constructor_node>();
stand_types = new Hashtable(); stand_types = new HashSet<Type>();
type_handles = new Hashtable(); type_handles = new Dictionary<Assembly, Dictionary<int, Type>>();
method_handles = new Hashtable(); method_handles = new Dictionary<Type, Dictionary<int, MethodInfo>>();
constr_handles = new Hashtable(); constr_handles = new Dictionary<Type, Dictionary<int, ConstructorInfo>>();
field_handles = new Hashtable(); field_handles = new Dictionary<Type, Dictionary<int, FieldInfo>>();
special_types = new Hashtable(); special_types = new Dictionary<int, Type>();
type_search_cache = new Dictionary<string,FoundInfo>(300); type_search_cache = new Dictionary<string,FoundInfo>(300);
cached_type_extensions = new Hashtable(); cached_type_extensions = new HashSet<Type>();
namespace_assemblies = new Hashtable(); namespace_assemblies = new Dictionary<Assembly, HashSet<string>>();
cur_used_assemblies = new Hashtable(); cur_used_assemblies = new HashSet<Assembly>();
//ns_types = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default); //ns_types = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
ns_types = new Hashtable(StringComparer.CurrentCultureIgnoreCase); ns_types = new Dictionary<string, Type[]>(StringComparer.CurrentCultureIgnoreCase);
memberInfo = typeof(MemberInfo); memberInfo = typeof(MemberInfo);
stand_types[typeof(int)] = stand_types; stand_types.Add(typeof(int));
stand_types[typeof(byte)] = stand_types; stand_types.Add(typeof(byte));
stand_types[typeof(bool)] = stand_types; stand_types.Add(typeof(bool));
stand_types[typeof(sbyte)] = stand_types; stand_types.Add(typeof(sbyte));
stand_types[typeof(short)] = stand_types; stand_types.Add(typeof(short));
stand_types[typeof(ushort)] = stand_types; stand_types.Add(typeof(ushort));
stand_types[typeof(uint)] = stand_types; stand_types.Add(typeof(uint));
stand_types[typeof(long)] = stand_types; stand_types.Add(typeof(long));
stand_types[typeof(ulong)] = stand_types; stand_types.Add(typeof(ulong));
stand_types[typeof(char)] = stand_types; stand_types.Add(typeof(char));
stand_types[typeof(float)] = stand_types; stand_types.Add(typeof(float));
stand_types[typeof(double)] = stand_types; stand_types.Add(typeof(double));
//stand_types[typeof(decimal)]=stand_types; //stand_types[typeof(decimal)]=stand_types;
//stand_types[NetHelper.void_ptr_type] = stand_types; //stand_types[NetHelper.void_ptr_type] = stand_types;
DelegateType = typeof(Delegate); DelegateType = typeof(Delegate);
@ -970,36 +967,35 @@ namespace PascalABCCompiler.NetHelper
special_types[t.MetadataToken] = t; special_types[t.MetadataToken] = t;
} }
public static bool IsStandType(Type t) public static bool IsStandType(Type t)
{ {
if (stand_types[t] != null) return true; return stand_types.Contains(t);
return false; }
}
public static bool IsNetNamespace(string name, Type tt = null)
public static bool IsNetNamespace(string name, Type tt = null) {
{
Type t = null; Type t = null;
if (tt != null) if (tt != null)
t = tt; t = tt;
else else
t = namespaces[name] as Type; namespaces.TryGetValue(name, out t);
if (t != null && cur_used_assemblies.ContainsKey(t.Assembly)) return true; if (t != null && cur_used_assemblies.Contains(t.Assembly)) return true;
foreach (Assembly a in namespace_assemblies.Keys) foreach (Assembly a in namespace_assemblies.Keys)
if (cur_used_assemblies != null && cur_used_assemblies.ContainsKey(a) && (namespace_assemblies[a] as Hashtable).ContainsKey(name)) if (cur_used_assemblies != null && cur_used_assemblies.Contains(a) && namespace_assemblies[a].Contains(name))
return true; return true;
return false; return false;
} }
public static bool IsNetNamespaceInAssembly(string name, Assembly a) public static bool IsNetNamespaceInAssembly(string name, Assembly a)
{ {
if (cur_used_assemblies != null && cur_used_assemblies.ContainsKey(a) && (namespace_assemblies[a] as Hashtable).ContainsKey(name)) if (cur_used_assemblies != null && cur_used_assemblies.Contains(a) && namespace_assemblies[a].Contains(name))
return true; return true;
return false; return false;
} }
public static bool IsNetNamespace(string name,PascalABCCompiler.TreeRealization.using_namespace_list _unar, out string full_ns) public static bool IsNetNamespace(string name,PascalABCCompiler.TreeRealization.using_namespace_list _unar, out string full_ns)
{ {
Type t = namespaces[name] as Type; namespaces.TryGetValue(name, out var t);
full_ns = name; full_ns = name;
if (t != null) if (t != null)
{ {
@ -1023,8 +1019,7 @@ namespace PascalABCCompiler.NetHelper
for (int i = 0; i < _unar.Count; i++) for (int i = 0; i < _unar.Count; i++)
{ {
string full_name = _unar[i].namespace_name + "." + name; string full_name = _unar[i].namespace_name + "." + name;
t = namespaces[full_name] as Type; if ( namespaces.TryGetValue(full_name, out t) )
if (t != null)
{ {
full_ns = full_name; full_ns = full_name;
return IsNetNamespace(full_ns, t); return IsNetNamespace(full_ns, t);
@ -1051,7 +1046,7 @@ namespace PascalABCCompiler.NetHelper
public static IEnumerable<MemberInfo> GetExtensionMethods(Type t) public static IEnumerable<MemberInfo> GetExtensionMethods(Type t)
{ {
List<MethodInfo> meths = null; List<MethodInfo> meths = null;
if (SystemCoreAssembly == null || !cur_used_assemblies.ContainsKey(SystemCoreAssembly)) if (SystemCoreAssembly == null || !cur_used_assemblies.Contains(SystemCoreAssembly))
return new List<MemberInfo>(); return new List<MemberInfo>();
if (type_extensions.TryGetValue(t, out meths) || t.IsGenericType && type_extensions.TryGetValue(t.GetGenericTypeDefinition(), out meths)) if (type_extensions.TryGetValue(t, out meths) || t.IsGenericType && type_extensions.TryGetValue(t.GetGenericTypeDefinition(), out meths))
{ {
@ -1213,14 +1208,14 @@ namespace PascalABCCompiler.NetHelper
public static string[] GetNamespaces(Assembly a) public static string[] GetNamespaces(Assembly a)
{ {
Hashtable ht = (Hashtable)namespace_assemblies[a]; var ht = namespace_assemblies[a];
List<string> lst = new List<string>(); List<string> lst = new List<string>();
foreach (string s in ht.Values) foreach (string s in ht)
//if (s.IndexOf('.') == -1) //if (s.IndexOf('.') == -1)
lst.Add(s); lst.Add(s);
return lst.ToArray(); return lst.ToArray();
} }
public static void FormBaseInterfacesList(Type t, List<Type> interfaces) public static void FormBaseInterfacesList(Type t, List<Type> interfaces)
{ {
if (interfaces.IndexOf(t) < 0) if (interfaces.IndexOf(t) < 0)
@ -1297,7 +1292,7 @@ namespace PascalABCCompiler.NetHelper
arrays_with_extension_methods[tmp_t] = tmp_t; arrays_with_extension_methods[tmp_t] = tmp_t;
if (tmp_t.IsGenericTypeDefinition) if (tmp_t.IsGenericTypeDefinition)
generics_with_extension_methods[tmp_t] = tmp_t; generics_with_extension_methods[tmp_t] = tmp_t;
cached_type_extensions[t] = t; cached_type_extensions.Add(t);
while (tmp_t != null) while (tmp_t != null)
{ {
List<MethodInfo> meths1 = null; List<MethodInfo> meths1 = null;
@ -1320,7 +1315,7 @@ namespace PascalABCCompiler.NetHelper
all_meths.AddRange(meths3); all_meths.AddRange(meths3);
foreach (MethodInfo mi in all_meths) foreach (MethodInfo mi in all_meths)
{ {
if (cur_used_assemblies.ContainsKey(mi.DeclaringType.Assembly)) if (cur_used_assemblies.Contains(mi.DeclaringType.Assembly))
{ {
List<MemberInfo> al = null; List<MemberInfo> al = null;
string s = StringConstants.GetNETOperName(mi.Name); string s = StringConstants.GetNETOperName(mi.Name);
@ -1348,7 +1343,7 @@ namespace PascalABCCompiler.NetHelper
{ {
foreach (MethodInfo mi in meths) foreach (MethodInfo mi in meths)
{ {
if (cur_used_assemblies.ContainsKey(mi.DeclaringType.Assembly)) if (cur_used_assemblies.Contains(mi.DeclaringType.Assembly))
{ {
List<MemberInfo> al = null; List<MemberInfo> al = null;
if (!ht.TryGetValue(mi.Name, out al)) if (!ht.TryGetValue(mi.Name, out al))
@ -1931,7 +1926,7 @@ namespace PascalABCCompiler.NetHelper
public static compiled_constructor_node GetConstructorNode(ConstructorInfo ci) public static compiled_constructor_node GetConstructorNode(ConstructorInfo ci)
{ {
return (compiled_constructor_node)constr_nodes[ci]; return constr_nodes[ci];
} }
public static void AddConstructor(ConstructorInfo ci, compiled_constructor_node ccn) public static void AddConstructor(ConstructorInfo ci, compiled_constructor_node ccn)
@ -2051,7 +2046,7 @@ namespace PascalABCCompiler.NetHelper
return null; return null;
List<TypeInfo> ti_list = fi.GetTypesByNamespaceList(_unar); List<TypeInfo> ti_list = fi.GetTypesByNamespaceList(_unar);
foreach (TypeInfo ti in ti_list) foreach (TypeInfo ti in ti_list)
if (cur_used_assemblies.ContainsKey(ti.type.Assembly)) if (cur_used_assemblies.Contains(ti.type.Assembly))
return ti.type; return ti.type;
} }
object o = types[name]; object o = types[name];
@ -2074,7 +2069,7 @@ namespace PascalABCCompiler.NetHelper
{ {
fi.type_infos.Add(new TypeNamespaceInfo(t, null)); fi.type_infos.Add(new TypeNamespaceInfo(t, null));
} }
if (cur_used_assemblies.ContainsKey(t.type.Assembly)) if (cur_used_assemblies.Contains(t.type.Assembly))
return t.type; return t.type;
else else
return null; return null;
@ -2092,7 +2087,7 @@ namespace PascalABCCompiler.NetHelper
{ {
fi.type_infos.Add(new TypeNamespaceInfo(t, _unar[i])); fi.type_infos.Add(new TypeNamespaceInfo(t, _unar[i]));
} }
if (cur_used_assemblies.ContainsKey(t.type.Assembly)) if (cur_used_assemblies.Contains(t.type.Assembly))
return t.type; return t.type;
else else
return null; return null;
@ -2116,7 +2111,7 @@ namespace PascalABCCompiler.NetHelper
{ {
fi.type_infos.Add(new TypeNamespaceInfo(t, null)); fi.type_infos.Add(new TypeNamespaceInfo(t, null));
} }
if (cur_used_assemblies.ContainsKey(t.type.Assembly)) if (cur_used_assemblies.Contains(t.type.Assembly))
return t.type; return t.type;
} }
for (int i = 0; i < _unar.Count; i++) for (int i = 0; i < _unar.Count; i++)
@ -2132,7 +2127,7 @@ namespace PascalABCCompiler.NetHelper
{ {
fi.type_infos.Add(new TypeNamespaceInfo(t, _unar[i])); fi.type_infos.Add(new TypeNamespaceInfo(t, _unar[i]));
} }
if (cur_used_assemblies.ContainsKey(t.type.Assembly)) if (cur_used_assemblies.Contains(t.type.Assembly))
return t.type; return t.type;
//else //else
// return null; // return null;
@ -2152,10 +2147,10 @@ namespace PascalABCCompiler.NetHelper
List<TypeInfo> founded_types = new List<TypeInfo>(); List<TypeInfo> founded_types = new List<TypeInfo>();
foreach (TypeInfo t in typs) foreach (TypeInfo t in typs)
{ {
if (cur_used_assemblies.ContainsKey(t.type.Assembly)) if (cur_used_assemblies.Contains(t.type.Assembly))
founded_types.Add(t); founded_types.Add(t);
} }
if (founded_types.Count == 1 && cur_used_assemblies.ContainsKey(founded_types[0].type.Assembly)) if (founded_types.Count == 1 && cur_used_assemblies.Contains(founded_types[0].type.Assembly))
return founded_types[0].type; return founded_types[0].type;
else else
return null; return null;
@ -2176,7 +2171,7 @@ namespace PascalABCCompiler.NetHelper
//ivan added - runtime types adding //ivan added - runtime types adding
Type t = Type.GetType(name, false, true); Type t = Type.GetType(name, false, true);
if (t == null) if (t == null)
foreach (Assembly a in assemblies.Values) foreach (Assembly a in assemblies)
{ {
t = a.GetType(name, false, true); t = a.GetType(name, false, true);
if (t != null) break; if (t != null) break;
@ -2210,8 +2205,8 @@ namespace PascalABCCompiler.NetHelper
public static Type[] FindTypesInNamespace(string name) public static Type[] FindTypesInNamespace(string name)
{ {
List<Type> lst = new List<Type>(); List<Type> lst = new List<Type>();
Type[] typs = (Type[])ns_types[name]; if ( ns_types.TryGetValue(name, out var typs) )
if (typs != null) return typs; return typs;
foreach (string s in types.Keys) foreach (string s in types.Keys)
{ {
TypeInfo ti = types[s] as TypeInfo; TypeInfo ti = types[s] as TypeInfo;
@ -2247,75 +2242,79 @@ namespace PascalABCCompiler.NetHelper
return lst.ToArray(); return lst.ToArray();
} }
private static Hashtable InitHandles(Assembly a) private static Dictionary<int, Type> InitHandles(Assembly a)
{ {
Type[] types = a.GetTypes(); Type[] types = a.GetTypes();
Hashtable ht = new Hashtable(); var ht = new Dictionary<int, Type>();
foreach (Type t in types) foreach (Type t in types)
ht[(int)t.MetadataToken] = t; ht[t.MetadataToken] = t;
type_handles[a] = ht; type_handles[a] = ht;
return ht; return ht;
} }
private static Hashtable InitMethodHandles(Type t) private static Dictionary<int, MethodInfo> InitMethodHandles(Type t)
{ {
MethodInfo[] mis = t.GetMethods(); MethodInfo[] mis = t.GetMethods();
Hashtable ht = new Hashtable(); var ht = new Dictionary<int, MethodInfo>();
foreach (MethodInfo mi in mis) foreach (MethodInfo mi in mis)
ht[(int)mi.MetadataToken] = mi; ht[mi.MetadataToken] = mi;
method_handles[t] = ht; method_handles[t] = ht;
return ht; return ht;
} }
private static Hashtable InitConstructorHandles(Type t) private static Dictionary<int, ConstructorInfo> InitConstructorHandles(Type t)
{ {
ConstructorInfo[] cis = t.GetConstructors(); ConstructorInfo[] cis = t.GetConstructors();
Hashtable ht = new Hashtable(); var ht = new Dictionary<int, ConstructorInfo>();
foreach (ConstructorInfo ci in cis) foreach (ConstructorInfo ci in cis)
ht[(int)ci.MetadataToken] = ci; ht[ci.MetadataToken] = ci;
constr_handles[t] = ht; constr_handles[t] = ht;
return ht; return ht;
} }
private static Hashtable InitFieldHandles(Type t) private static Dictionary<int, FieldInfo> InitFieldHandles(Type t)
{ {
FieldInfo[] fis = t.GetFields(); FieldInfo[] fis = t.GetFields();
Hashtable ht = new Hashtable(); var ht = new Dictionary<int, FieldInfo>();
foreach (FieldInfo fi in fis) foreach (FieldInfo fi in fis)
ht[(int)fi.MetadataToken] = fi; ht[fi.MetadataToken] = fi;
field_handles[t] = ht; field_handles[t] = ht;
return ht; return ht;
} }
public static Type FindTypeByHandle(Assembly a, int handle) public static Type FindTypeByHandle(Assembly a, int handle)
{ {
Hashtable ht = (Hashtable)type_handles[a]; if (!type_handles.TryGetValue(a, out var ht))
if (ht == null) ht = InitHandles(a); ht = InitHandles(a);
Type t = (Type)ht[handle];
if (t == null) if (!ht.TryGetValue(handle, out var t))
return (Type)special_types[handle]; t = special_types[handle];
return t; return t;
} }
public static MethodInfo FindMethodByHandle(Type t, int handle) public static MethodInfo FindMethodByHandle(Type t, int handle)
{ {
Hashtable ht = (Hashtable)method_handles[t]; if (!method_handles.TryGetValue(t, out var ht))
if (ht == null) ht = InitMethodHandles(t); ht = InitMethodHandles(t);
return (MethodInfo)ht[handle];
return ht[handle];
} }
public static ConstructorInfo FindConstructorByHandle(Type t, int handle) public static ConstructorInfo FindConstructorByHandle(Type t, int handle)
{ {
Hashtable ht = (Hashtable)constr_handles[t]; if (!constr_handles.TryGetValue(t, out var ht))
if (ht == null) ht = InitConstructorHandles(t); ht = InitConstructorHandles(t);
return (ConstructorInfo)ht[handle];
return ht[handle];
} }
public static FieldInfo FindFieldByHandle(Type t, int handle) public static FieldInfo FindFieldByHandle(Type t, int handle)
{ {
Hashtable ht = (Hashtable)field_handles[t]; if (!field_handles.TryGetValue(t, out var ht))
if (ht == null) ht = InitFieldHandles(t); ht = InitFieldHandles(t);
return (FieldInfo)ht[handle];
return ht[handle];
} }
public static void AddGenericInfo(Type t) public static void AddGenericInfo(Type t)

View file

@ -18,7 +18,6 @@ namespace PascalABCCompiler.SystemLibrary
//TODO: Все базовые методы должны быть определены здесь как статические и использовать их отсюда, а не создавать их по два раза. //TODO: Все базовые методы должны быть определены здесь как статические и использовать их отсюда, а не создавать их по два раза.
public static class SystemLibrary public static class SystemLibrary
{ {
private static compiled_type_node _bool_type; private static compiled_type_node _bool_type;
private static compiled_type_node _byte_type; private static compiled_type_node _byte_type;
private static compiled_type_node _sbyte_type; private static compiled_type_node _sbyte_type;
@ -95,7 +94,7 @@ namespace PascalABCCompiler.SystemLibrary
private static SymbolTable.TreeConverterSymbolTable _symtab; private static SymbolTable.TreeConverterSymbolTable _symtab;
private static System.Collections.Generic.Dictionary<SemanticTree.basic_function_type, basic_function_node> ht = new System.Collections.Generic.Dictionary<SemanticTree.basic_function_type, basic_function_node>(); private static System.Collections.Generic.Dictionary<SemanticTree.basic_function_type, basic_function_node> ht = new System.Collections.Generic.Dictionary<SemanticTree.basic_function_type, basic_function_node>();
private static System.Collections.Hashtable writable_in_typed_files_types = new System.Collections.Hashtable(); private static HashSet<compiled_type_node> writable_in_typed_files_types = new HashSet<compiled_type_node>();
private static string_const_node _empty_string; private static string_const_node _empty_string;
@ -2079,18 +2078,18 @@ namespace PascalABCCompiler.SystemLibrary
// То есть, это было неправильное исправление // То есть, это было неправильное исправление
writable_in_typed_files_types.Clear(); writable_in_typed_files_types.Clear();
writable_in_typed_files_types.Add(_bool_type, _bool_type); writable_in_typed_files_types.Add(_bool_type);
writable_in_typed_files_types.Add(_byte_type, _byte_type); writable_in_typed_files_types.Add(_byte_type);
writable_in_typed_files_types.Add(_sbyte_type, _sbyte_type); writable_in_typed_files_types.Add(_sbyte_type);
writable_in_typed_files_types.Add(_short_type, _short_type); writable_in_typed_files_types.Add(_short_type);
writable_in_typed_files_types.Add(_ushort_type, _ushort_type); writable_in_typed_files_types.Add(_ushort_type);
writable_in_typed_files_types.Add(_integer_type, _integer_type); writable_in_typed_files_types.Add(_integer_type);
writable_in_typed_files_types.Add(_uint_type, _uint_type); writable_in_typed_files_types.Add(_uint_type);
writable_in_typed_files_types.Add(_int64_type, _int64_type); writable_in_typed_files_types.Add(_int64_type);
writable_in_typed_files_types.Add(_uint64_type, _uint64_type); writable_in_typed_files_types.Add(_uint64_type);
writable_in_typed_files_types.Add(_double_type, _double_type); writable_in_typed_files_types.Add(_double_type);
writable_in_typed_files_types.Add(_char_type, _char_type); writable_in_typed_files_types.Add(_char_type);
writable_in_typed_files_types.Add(_float_type, _float_type); writable_in_typed_files_types.Add(_float_type);
foreach (type_node tn in wait_add_ref_list) foreach (type_node tn in wait_add_ref_list)
init_reference_type(tn); init_reference_type(tn);
@ -2120,7 +2119,7 @@ namespace PascalABCCompiler.SystemLibrary
public static bool CanUseThisTypeForTypedFiles(type_node tn) public static bool CanUseThisTypeForTypedFiles(type_node tn)
{ {
return writable_in_typed_files_types[tn] != null; return writable_in_typed_files_types.Contains(tn);
} }
private static void add_std_convertions() private static void add_std_convertions()

View file

@ -12761,7 +12761,7 @@ namespace PascalABCCompiler.TreeConverter
{ {
if (td.attributes != null) if (td.attributes != null)
{ {
Hashtable ht = new Hashtable(); var ht = new HashSet<type_node>();
foreach (SyntaxTree.simple_attribute_list sal in td.attributes.attributes) foreach (SyntaxTree.simple_attribute_list sal in td.attributes.attributes)
for (int j = 0; j < sal.attributes.Count; j++) for (int j = 0; j < sal.attributes.Count; j++)
{ {
@ -12784,7 +12784,7 @@ namespace PascalABCCompiler.TreeConverter
AddError(get_location(attr), "DUPLICATE_ATTRIBUTE_{0}_APPLICATION", tn.name); AddError(get_location(attr), "DUPLICATE_ATTRIBUTE_{0}_APPLICATION", tn.name);
} }
else else
ht[tn] = tn; ht.Add(tn);
SemanticTree.attribute_qualifier_kind qualifier = SemanticTree.attribute_qualifier_kind.none_kind; SemanticTree.attribute_qualifier_kind qualifier = SemanticTree.attribute_qualifier_kind.none_kind;
if (attr.qualifier != null) if (attr.qualifier != null)
if (j == 0) if (j == 0)
@ -12928,7 +12928,7 @@ namespace PascalABCCompiler.TreeConverter
{ {
if (cun.attributes != null) if (cun.attributes != null)
{ {
Hashtable ht = new Hashtable(); var ht = new HashSet<type_node>();
foreach (SyntaxTree.simple_attribute_list sal in un.attributes.attributes) foreach (SyntaxTree.simple_attribute_list sal in un.attributes.attributes)
for (int j = 0; j < sal.attributes.Count; j++) for (int j = 0; j < sal.attributes.Count; j++)
{ {
@ -12951,7 +12951,7 @@ namespace PascalABCCompiler.TreeConverter
AddError(get_location(attr), "DUPLICATE_ATTRIBUTE_{0}_APPLICATION", tn.name); AddError(get_location(attr), "DUPLICATE_ATTRIBUTE_{0}_APPLICATION", tn.name);
} }
else else
ht[tn] = tn; ht.Add(tn);
SemanticTree.attribute_qualifier_kind qualifier = SemanticTree.attribute_qualifier_kind.none_kind; SemanticTree.attribute_qualifier_kind qualifier = SemanticTree.attribute_qualifier_kind.none_kind;
if (attr.qualifier != null) if (attr.qualifier != null)
if (j == 0) if (j == 0)
@ -13258,7 +13258,7 @@ namespace PascalABCCompiler.TreeConverter
//Добавляет ограничители для параметра шаблона //Добавляет ограничители для параметра шаблона
private void add_generic_eliminations(common_type_node param, List<SyntaxTree.type_definition> specificators) private void add_generic_eliminations(common_type_node param, List<SyntaxTree.type_definition> specificators)
{ {
Hashtable used_interfs = new Hashtable(); var used_interfs = new HashSet<type_node>();
// System.Enum это класс, но его наследники - записи // System.Enum это класс, но его наследники - записи
// Если указать "where T: Enum, record" - станет нельзя применять T=Enum, с ошибкой что Enum не запись // Если указать "where T: Enum, record" - станет нельзя применять T=Enum, с ошибкой что Enum не запись
// Но чтобы в секции where override метода можно было указать record без System.Enum // Но чтобы в секции where override метода можно было указать record без System.Enum
@ -13320,13 +13320,13 @@ namespace PascalABCCompiler.TreeConverter
// param.is_class = true; // param.is_class = true;
if (spec_type.IsInterface) if (spec_type.IsInterface)
{ {
if (used_interfs[spec_type] != null) if (used_interfs.Contains(spec_type))
{ {
AddError(get_location(specificators[i]), "INTERFACE_{0}_ALREADY_ADDED_TO_IMPLEMENTING_LIST", spec_type.PrintableName); AddError(get_location(specificators[i]), "INTERFACE_{0}_ALREADY_ADDED_TO_IMPLEMENTING_LIST", spec_type.PrintableName);
} }
else else
{ {
used_interfs.Add(spec_type, spec_type); used_interfs.Add(spec_type);
} }
//Добавляем интерфейс //Добавляем интерфейс
type_table.AddInterface(param, spec_type, get_location(specificators[i])); type_table.AddInterface(param, spec_type, get_location(specificators[i]));
@ -13358,7 +13358,7 @@ namespace PascalABCCompiler.TreeConverter
{ {
foreach (type_node tn in spec_type.ImplementingInterfaces) foreach (type_node tn in spec_type.ImplementingInterfaces)
{ {
used_interfs.Add(tn, tn); used_interfs.Add(tn);
type_table.AddInterface(param, tn, get_location(specificators[i])); type_table.AddInterface(param, tn, get_location(specificators[i]));
} }
} }

View file

@ -100,8 +100,8 @@ namespace PascalABCCompiler.TreeRealization
common_namespace_node[] ret = new common_namespace_node[namespaces.Count]; common_namespace_node[] ret = new common_namespace_node[namespaces.Count];
namespaces.Values.CopyTo(ret, 0); namespaces.Values.CopyTo(ret, 0);
return ret;*/ return ret;*/
System.Collections.Hashtable ht = new System.Collections.Hashtable(); var ht = new Dictionary<string, common_namespace_node>();
System.Collections.ArrayList al = new System.Collections.ArrayList(); var al = new List<common_namespace_node>();
common_namespace_node main_cnn = null; common_namespace_node main_cnn = null;
foreach (common_unit_node un in units) foreach (common_unit_node un in units)
{ {
@ -109,7 +109,7 @@ namespace PascalABCCompiler.TreeRealization
{ {
//if (cnn.namespace_full_name != "") //if (cnn.namespace_full_name != "")
//{ //{
if (ht[cnn.namespace_name] == null) if (!ht.ContainsKey(cnn.namespace_name))
{ {
al.Add(cnn); ht[cnn.namespace_name] = cnn; al.Add(cnn); ht[cnn.namespace_name] = cnn;
} }
@ -160,15 +160,15 @@ namespace PascalABCCompiler.TreeRealization
if (_namespaces == null) if (_namespaces == null)
{ {
_namespaces = get_units_namespaces(_units); _namespaces = get_units_namespaces(_units);
System.Collections.Hashtable ns_ht = new System.Collections.Hashtable(); var ns_ht = new HashSet<string>();
foreach (common_unit_node un in units) foreach (common_unit_node un in units)
{ {
foreach (string s in un.used_namespaces) foreach (string s in un.used_namespaces)
{ {
if (!ns_ht.ContainsKey(s)) if (!ns_ht.Contains(s))
{ {
this._used_namespaces.Add(s); this._used_namespaces.Add(s);
ns_ht.Add(s,s); ns_ht.Add(s);
} }
} }
} }