Переделана на стандартную HashTable в таблице символов.
Скорость не упала! Сделаны ToString для некоторых классов для отображения символов в таблице символов
This commit is contained in:
parent
fe98023047
commit
2806f02333
|
|
@ -15,7 +15,7 @@ internal static class RevisionClass
|
|||
public const string Major = "3";
|
||||
public const string Minor = "3";
|
||||
public const string Build = "0";
|
||||
public const string Revision = "1542";
|
||||
public const string Revision = "1545";
|
||||
|
||||
public const string MainVersion = Major + "." + Minor;
|
||||
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
%MINOR%=3
|
||||
%REVISION%=1542
|
||||
%COREVERSION%=0
|
||||
%REVISION%=1545
|
||||
%MINOR%=3
|
||||
%MAJOR%=3
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
!define VERSION '3.3.0.1542'
|
||||
!define VERSION '3.3.0.1545'
|
||||
|
|
|
|||
|
|
@ -1,12 +1,30 @@
|
|||
// Copyright (c) Ivan Bondarev, Stanislav Mihalkovich (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace System.Linq
|
||||
{
|
||||
public static class ExtSeqMy
|
||||
{
|
||||
public static string JoinIntoString<T>(this IEnumerable<T> seq, string delim = " ")
|
||||
{
|
||||
var sb = new System.Text.StringBuilder();
|
||||
foreach (var x in seq)
|
||||
sb.Append(x.ToString() + delim);
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace SymbolTable
|
||||
{
|
||||
public class AreaNodesList
|
||||
{
|
||||
public AreaListNode[] data;
|
||||
public override string ToString() => data.Take(count).JoinIntoString();
|
||||
|
||||
public AreaListNode[] data;
|
||||
int count;
|
||||
|
||||
public int Count
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
// Copyright (c) Ivan Bondarev, Stanislav Mihalkovich (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SymbolTable
|
||||
{
|
||||
|
|
@ -10,7 +12,9 @@ namespace SymbolTable
|
|||
/// </summary>
|
||||
public class DSHashTable
|
||||
{
|
||||
private int count;
|
||||
public override string ToString() => dict.SkipWhile(x=>x.Key != "").Skip(1).JoinIntoString(Environment.NewLine);
|
||||
|
||||
/*private int count;
|
||||
private int hash_size
|
||||
{
|
||||
get
|
||||
|
|
@ -19,7 +23,7 @@ namespace SymbolTable
|
|||
}
|
||||
}
|
||||
|
||||
public HashTableNode[] hash_arr;
|
||||
private HashTableNode[] hash_arr;
|
||||
|
||||
private int HashFunc(string s)
|
||||
{
|
||||
|
|
@ -29,9 +33,11 @@ namespace SymbolTable
|
|||
return Math.Abs(n % hash_size);
|
||||
}
|
||||
|
||||
private System.Collections.Generic.Dictionary<int, object> ht = new System.Collections.Generic.Dictionary<int, object>();
|
||||
private System.Collections.Generic.Dictionary<int, object> ht = new System.Collections.Generic.Dictionary<int, object>();*/
|
||||
|
||||
private int GetHash(string s)
|
||||
private Dictionary<string,HashTableNode> dict = new Dictionary<string, HashTableNode>();
|
||||
|
||||
/*private int GetHash(string s)
|
||||
{
|
||||
int hash = HashFunc(s);
|
||||
int i = 1;
|
||||
|
|
@ -59,25 +65,43 @@ namespace SymbolTable
|
|||
if (hat.Length > new_size) return;
|
||||
for (int i = 0; i < hat.Length; i++)
|
||||
if (hat[i] != null) Add(hat[i]);
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
public DSHashTable(int start_size)
|
||||
{
|
||||
hash_arr = new HashTableNode[start_size];
|
||||
ClearTable();
|
||||
//hash_arr = new HashTableNode[start_size];
|
||||
//ClearTable();
|
||||
}
|
||||
|
||||
public void ClearTable()
|
||||
{
|
||||
count = 0;
|
||||
for (int i = 0; i < hash_size; i++)
|
||||
hash_arr[i] = null;
|
||||
dict.Clear();
|
||||
//count = 0;
|
||||
//for (int i = 0; i < hash_size; i++)
|
||||
// hash_arr[i] = null;
|
||||
}
|
||||
|
||||
public int Add(HashTableNode node)
|
||||
public HashTableNode Add(string name)
|
||||
{
|
||||
if (count / hash_size * 100 > SymbolTableConstants.HashTable_StartResise)
|
||||
HashTableNode node = null;
|
||||
var b = dict.TryGetValue(name, out node);
|
||||
if (!b)
|
||||
{
|
||||
node = new HashTableNode(name);
|
||||
dict[name] = node;
|
||||
}
|
||||
return node;
|
||||
|
||||
/*if (!dict.ContainsKey(name))
|
||||
{
|
||||
var node = new HashTableNode(name);
|
||||
dict[name] = node;
|
||||
return node;
|
||||
}
|
||||
return dict[name];*/
|
||||
|
||||
/*if (count / hash_size * 100 > SymbolTableConstants.HashTable_StartResise)
|
||||
Resize(hash_size + hash_size / 100 * SymbolTableConstants.HashTable_ProcResize);
|
||||
int tn = GetHash(node.Name);
|
||||
if (hash_arr[tn] == null)
|
||||
|
|
@ -85,15 +109,22 @@ namespace SymbolTable
|
|||
hash_arr[tn] = node;
|
||||
count++;
|
||||
}
|
||||
return tn;
|
||||
return hash_arr[tn];*/
|
||||
}
|
||||
|
||||
public int Find(string name)
|
||||
public HashTableNode Find(string name)
|
||||
{
|
||||
int h = GetHash(name);
|
||||
if (hash_arr[h] != null)
|
||||
return h;
|
||||
return -1;
|
||||
HashTableNode node = null;
|
||||
dict.TryGetValue(name, out node);
|
||||
return node;
|
||||
/*if (dict.ContainsKey(name))
|
||||
return dict[name];
|
||||
else return null;*/
|
||||
|
||||
/*int h = GetHash(name);
|
||||
//if (hash_arr[h] != null)
|
||||
// return hash_arr[h];
|
||||
return hash_arr[h];*/
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Ivan Bondarev, Stanislav Mihalkovich (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using PascalABCCompiler.TreeConverter;
|
||||
using System.Collections.Generic;
|
||||
using SymbolTable;
|
||||
|
|
@ -144,7 +144,16 @@ namespace SymbolTable
|
|||
//при создании добавляет себя в vSymbolTable
|
||||
public class Scope:BaseScope
|
||||
{
|
||||
public DSSymbolTable SymbolTable;
|
||||
private string ScopeName()
|
||||
{
|
||||
var s = this.GetType().Name;
|
||||
if (s == "UnitInterfaceScope")
|
||||
return "GLOBAL";
|
||||
return s;
|
||||
}
|
||||
public override string ToString() => ScopeNum + "->" + TopScopeNum + " ," + ScopeName();
|
||||
|
||||
public DSSymbolTable SymbolTable;
|
||||
public bool CaseSensitive;
|
||||
public int TopScopeNum;
|
||||
public bool AddStatementsToFront = false; // SSM - введено для необходимости добавлять statements не только в конец statement_list, но и в начало. Нужно для синтаксически сахарных конструкций: например, для создания объекта класса при замыканиях
|
||||
|
|
@ -454,7 +463,8 @@ namespace SymbolTable
|
|||
#region AreaListNode элемент списка областей видимости
|
||||
public class AreaListNode
|
||||
{
|
||||
public int Area;
|
||||
public override string ToString() => InfoList.JoinIntoString();
|
||||
public int Area;
|
||||
public List<SymbolInfoUnit> InfoList;//для перегузки
|
||||
public AreaListNode()
|
||||
{
|
||||
|
|
@ -466,7 +476,7 @@ namespace SymbolTable
|
|||
Area=ar;
|
||||
InfoList.Add(inf);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region HashTableNode элемент хеш-таблицы
|
||||
|
|
@ -479,7 +489,11 @@ namespace SymbolTable
|
|||
Name=name;
|
||||
NumAreaList=new AreaNodesList(SymbolTableConstants.AreaList_StartSize);
|
||||
}
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return NumAreaList.ToString();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
|
@ -611,9 +625,10 @@ namespace SymbolTable
|
|||
//{
|
||||
Inf.scope = InScope;
|
||||
if (!InScope.CaseSensitive) Name = Name.ToLower();
|
||||
int hn = HashTable.Add(new HashTableNode(Name));//ЗДЕСь ВОЗНИКАЕТ НЕДЕТЕРМЕНИРОВАНЯ ОШИБКА
|
||||
var hn = HashTable.Add(Name);//ЗДЕСь ВОЗНИКАЕТ НЕДЕТЕРМЕНИРОВАНЯ ОШИБКА - SSM 07.10.17 - странный комментарий. Вроде всё нормально.
|
||||
// SSM 07.10.17 - переделал внутреннее представление HashTable на основе Dictionary
|
||||
|
||||
HashTable.hash_arr[hn].NumAreaList.Add(new AreaListNode(InScope.ScopeNum, Inf));
|
||||
hn.NumAreaList.Add(new AreaListNode(InScope.ScopeNum, Inf));
|
||||
//}
|
||||
// catch (Exception e)
|
||||
//{
|
||||
|
|
@ -636,8 +651,8 @@ namespace SymbolTable
|
|||
SymbolInfoList FirstInfo = new SymbolInfoList();
|
||||
|
||||
int Area = scope.ScopeNum;
|
||||
int tn = HashTable.Find(Name); //найдем имя в хеше
|
||||
if (tn < 0 || scope is DotNETScope)//если нет такого ищем в областях .NET
|
||||
var tn = HashTable.Find(Name); //найдем имя в хеше
|
||||
if (tn == null || scope is DotNETScope)//если нет такого ищем в областях .NET
|
||||
{
|
||||
Scope an;
|
||||
an = ScopeTable[Area];
|
||||
|
|
@ -648,7 +663,7 @@ namespace SymbolTable
|
|||
return FirstInfo.InfoUnitList.Count > 0 ? FirstInfo : null;
|
||||
}
|
||||
|
||||
AreaNodesList AreaList = HashTable.hash_arr[tn].NumAreaList;
|
||||
AreaNodesList AreaList = tn.NumAreaList;
|
||||
int CurrentArea = Area, ai, bs;
|
||||
do
|
||||
{
|
||||
|
|
@ -950,14 +965,14 @@ namespace SymbolTable
|
|||
|
||||
int Area = scope.ScopeNum;
|
||||
Scope[] used_units = null;
|
||||
int tn = HashTable.Find(Name); //найдем имя в хеше
|
||||
var tn = HashTable.Find(Name); //найдем имя в хеше
|
||||
|
||||
// SSM 21.01.16
|
||||
if (Name.StartsWith("?")) // это значит, надо искать в областях .NET
|
||||
Name = Name.Substring(1); // съели ? и ищем т.к. tn<0
|
||||
// end SSM
|
||||
|
||||
if (tn < 0 || scope is DotNETScope)//если нет такого ищем в областях .NET
|
||||
if (tn == null || scope is DotNETScope)//если нет такого ищем в областях .NET
|
||||
{
|
||||
//ssyy
|
||||
int NextUnitArea = -2;
|
||||
|
|
@ -968,13 +983,13 @@ namespace SymbolTable
|
|||
an = ScopeTable[Area];
|
||||
if (an is DotNETScope)
|
||||
{
|
||||
if (tn < 0)
|
||||
if (tn == null)
|
||||
{
|
||||
AddToSymbolInfo(FirstInfo, (DotNETScope)an, Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
FindAllInClass(Name, Area, HashTable.hash_arr[tn].NumAreaList, false, FirstInfo);
|
||||
FindAllInClass(Name, Area, tn.NumAreaList, false, FirstInfo);
|
||||
}
|
||||
}
|
||||
if (FirstInfo.InfoUnitList.Count > 1)
|
||||
|
|
@ -1075,7 +1090,7 @@ namespace SymbolTable
|
|||
return null; //если такого нет то поиск окончен
|
||||
}
|
||||
|
||||
AreaNodesList AreaList = HashTable.hash_arr[tn].NumAreaList;
|
||||
AreaNodesList AreaList = tn.NumAreaList;
|
||||
int CurrentArea = Area, ai;
|
||||
while (CurrentArea >= 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -567,10 +567,11 @@ namespace PascalABCCompiler.TreeConverter
|
|||
|
||||
public class SymbolInfoUnit
|
||||
{
|
||||
public override string ToString() => "("+scope.ToString() + "," + sym_info.ToString()+")";
|
||||
|
||||
//private readonly name_information_type _name_information_type;
|
||||
private definition_node _sym_info;
|
||||
|
||||
|
||||
private access_level _access_level;
|
||||
|
||||
private symbol_kind _symbol_kind;
|
||||
|
|
@ -579,7 +580,6 @@ namespace PascalABCCompiler.TreeConverter
|
|||
|
||||
//public SymbolInfo reference;
|
||||
|
||||
|
||||
public access_level access_level
|
||||
{
|
||||
get
|
||||
|
|
|
|||
|
|
@ -91,7 +91,9 @@ namespace PascalABCCompiler.TreeRealization
|
|||
[Serializable]
|
||||
public abstract class definition_node : semantic_node, SemanticTree.IDefinitionNode
|
||||
{
|
||||
protected string doc;
|
||||
public override string ToString() => this.GetType().Name;
|
||||
|
||||
protected string doc;
|
||||
|
||||
protected attributes_list _attributes;
|
||||
|
||||
|
|
|
|||
|
|
@ -2489,7 +2489,9 @@ namespace PascalABCCompiler.TreeRealization
|
|||
[Serializable]
|
||||
public class compiled_type_node : wrapped_type, SemanticTree.ICompiledTypeNode , SemanticTree.ILocated
|
||||
{
|
||||
internal System.Type _compiled_type;
|
||||
public override string ToString() => compiled_type.Name.ToString();
|
||||
|
||||
internal System.Type _compiled_type;
|
||||
protected compiled_type_node _base_type;
|
||||
|
||||
//Если это не чистить, будет ошибка. Т.к. при следуйщей компиляции области видимости могут изменится.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ namespace PascalABCCompiler.TreeRealization
|
|||
[Serializable]
|
||||
public abstract class var_definition_node : definition_node, SemanticTree.IVAriableDefinitionNode
|
||||
{
|
||||
private string _name;
|
||||
public override string ToString() => this.GetType().Name + ": "+ type.ToString();
|
||||
|
||||
private string _name;
|
||||
private type_node _type;
|
||||
private expression_node _inital_value;
|
||||
private bool _is_ret_value;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace VisualPascalABC
|
|||
public void SetDisassembledCode(string code)
|
||||
{
|
||||
DisassemblyEditor.Document.TextContent = code;
|
||||
DisassemblyEditor.Refresh();
|
||||
//DisassemblyEditor.Refresh();
|
||||
}
|
||||
|
||||
public void ClearWindow()
|
||||
|
|
|
|||
Loading…
Reference in a new issue