Изменён ClassMethodScope и алгоритм поиска дял него.

This commit is contained in:
andrewlord607 2018-05-22 13:05:36 +03:00
parent 0c1da87e6a
commit 76638383c8
3 changed files with 39 additions and 23 deletions

View file

@ -441,17 +441,18 @@ namespace SymbolTable
}
//\ssyy owns
public class ClassMethodScope:Scope
//В ClassMethodScope TopScope должен быть классом
public class ClassMethodScope:Scope
{
public Scope MyClass;
public Scope DefScope;
public ClassMethodScope(DSSymbolTable vSymbolTable,Scope TopScope,Scope MyClass, string Name):
public ClassMethodScope(DSSymbolTable vSymbolTable, Scope TopScope, Scope DefScope, string Name):
base(vSymbolTable,TopScope, Name)
{
this.Name = Name;
this.MyClass = null;
if (MyClass != null)
this.MyClass = MyClass;
this.DefScope = null;
if (DefScope != null)
this.DefScope = DefScope;
}
}
#endregion
@ -554,8 +555,21 @@ namespace SymbolTable
private Scope real_scope;
public PrimaryScope(Scope sc)
{
ScopeName = sc.Name;
real_scope = sc;
if(real_scope is BlockScope)
{
int deep = -1;
Scope Top = real_scope.TopScope;
while(Top != null && !(Top is BlockScope))
{
deep++;
Top = Top.TopScope;
}
ScopeName = "Begin—End;(Deep = " + deep + ")";
}
else
ScopeName = sc.Name;
}
}
#endregion
@ -666,9 +680,9 @@ namespace SymbolTable
{
return new UnitImplementationScope(this, InterfaceScope, UsedUnits, Name);
}
public ClassMethodScope CreateClassMethodScope(Scope TopScope,Scope MyClass, string Name = "")
public ClassMethodScope CreateClassMethodScope(Scope TopScope, Scope DefScope, string Name = "")
{
return new ClassMethodScope(this, TopScope, MyClass, Name);
return new ClassMethodScope(this, TopScope, DefScope, Name);
}
#endregion
@ -828,7 +842,7 @@ namespace SymbolTable
{
while (scope != null && !(scope is ClassScope))
if(scope is ClassMethodScope)
scope = ((ClassMethodScope)scope).MyClass;
scope = scope.TopScope;
else
scope = scope.TopScope;
return scope;
@ -1076,10 +1090,12 @@ namespace SymbolTable
}
if (CurrentArea is ClassMethodScope)//мы очутились в методе класса
{
FindAllInClass(Name, (CurrentArea as ClassMethodScope).MyClass, OnlyInThisClass, Result);//надо сделать поиск по его классу
FindAllInClass(Name, (CurrentArea as ClassMethodScope).TopScope, OnlyInThisClass, Result);//надо сделать поиск по его классу
if (Result.Count > 0) //если что-то нашли то заканчиваем
return Result;
CurrentArea = (CurrentArea as ClassMethodScope).DefScope;
continue;
}
}
CurrentArea = CurrentArea.TopScope;//Пошли вверх
@ -1174,9 +1190,9 @@ namespace SymbolTable
if (an is ClassMethodScope)
{
//ssyy
NextUnitArea = an.TopScope;
NextUnitArea = (an as ClassMethodScope).DefScope;
//\ssyy
Area = (an as ClassMethodScope).MyClass;
Area = an.TopScope;
}
else
Area = Area.TopScope;

View file

@ -1022,7 +1022,7 @@ namespace PascalABCCompiler.TreeConverter
SymbolInfo si = _ctn.find_first_in_type(compiler_string_consts.noteq_name);
if (si.sym_info is common_method_node)
return;
SymbolTable.ClassMethodScope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_cmn.scope,_ctn.scope, si.ToString());
SymbolTable.ClassMethodScope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_ctn.scope, _cmn.scope, si.ToString());
common_method_node cmn = new common_method_node(compiler_string_consts.GetNETOperName(compiler_string_consts.noteq_name),SystemLibrary.SystemLibrary.bool_type,null,_ctn,
SemanticTree.polymorphic_state.ps_static,SemanticTree.field_access_level.fal_public,scope);
cmn.IsOperator = true;
@ -1056,7 +1056,7 @@ namespace PascalABCCompiler.TreeConverter
SymbolInfo si = _ctn.find_first_in_type(compiler_string_consts.eq_name);
if (si.sym_info is common_method_node)
return;
SymbolTable.ClassMethodScope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_cmn.scope,_ctn.scope, si.ToString());
SymbolTable.ClassMethodScope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope( _ctn.scope, _cmn.scope, si.ToString());
common_method_node cmn = new common_method_node(compiler_string_consts.GetNETOperName(compiler_string_consts.eq_name),SystemLibrary.SystemLibrary.bool_type,null,_ctn,
SemanticTree.polymorphic_state.ps_static,SemanticTree.field_access_level.fal_public,scope);
cmn.IsOperator = true;
@ -1175,7 +1175,7 @@ namespace PascalABCCompiler.TreeConverter
if (_ctn != null)
{
common_method_node cmmn;
SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(topScope, _ctn.Scope, "lambda " + name);
SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_ctn.Scope, topScope, "lambda " + name);
//TODO:сделать static и virtual.
//TODO: interface and implementation scopes.
cmmn = new common_method_node(name, def_loc, _ctn, SemanticTree.polymorphic_state.ps_common, _fal, scope);
@ -1235,7 +1235,7 @@ namespace PascalABCCompiler.TreeConverter
if (!extension_method)
{
common_method_node cmmn;
SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_cmn.scope, _ctn.Scope, name=="create"? "constructor " + _ctn.Scope : "method " + name + " from " + _ctn.Scope);
SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_ctn.Scope, _cmn.scope, name=="create"? "constructor " + _ctn.Scope : "method " + name);
//TODO:сделать static и virtual.
//TODO: interface and implementation scopes.
cmmn = new common_method_node(name, def_loc, _ctn, SemanticTree.polymorphic_state.ps_common, _fal, scope);
@ -1250,7 +1250,7 @@ namespace PascalABCCompiler.TreeConverter
else
{
common_namespace_function_node cnfnn;
SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_cmn.scope, _ctn.scope, name);
SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_ctn.scope, _cmn.scope, name);
cnfnn = new common_namespace_function_node(name, def_loc, _cmn, scope);
//_cmn.functions.AddElement(cnfnn);
syntax_tree_visitor.compiled_unit.namespaces[0].functions.AddElement(cnfnn);
@ -1266,7 +1266,7 @@ namespace PascalABCCompiler.TreeConverter
{
//string cname = compiler_string_consts.GetConnectedFunctionName(_compiled_tn.name, name);
common_namespace_function_node cnfnn;
SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_cmn.scope, _compiled_tn.scope, name);
SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_compiled_tn.scope, _cmn.scope, name);
cnfnn = new common_namespace_function_node(name, def_loc, _cmn, scope);
//_cmn.functions.AddElement(cnfnn);
syntax_tree_visitor.compiled_unit.namespaces[0].functions.AddElement(cnfnn);
@ -2149,9 +2149,9 @@ namespace PascalABCCompiler.TreeConverter
List<SymbolInfo> sil = curscope.Find(name, curscope);
List<SymbolInfo> si2 = null;
if (sil != null && sil.FirstOrDefault().scope is SymbolTable.ClassScope && curscope.TopScope is SymbolTable.BlockScope && curscope.TopScope.TopScope is SymbolTable.ClassMethodScope && curscope.TopScope.TopScope.TopScope is SymbolTable.BlockScope)
if (sil != null && sil.FirstOrDefault().scope is SymbolTable.ClassScope && curscope.TopScope is SymbolTable.BlockScope && curscope.TopScope.TopScope is SymbolTable.ClassMethodScope && ((SymbolTable.ClassMethodScope)curscope.TopScope.TopScope).DefScope is SymbolTable.BlockScope)
{
si2 = curscope.TopScope.TopScope.TopScope.Find(name, curscope.TopScope.TopScope.TopScope);
si2 = ((SymbolTable.ClassMethodScope)curscope.TopScope.TopScope).DefScope.Find(name, ((SymbolTable.ClassMethodScope)curscope.TopScope.TopScope).DefScope);
if (si2 != null && si2.FirstOrDefault().scope is SymbolTable.ClassMethodScope)
{
sil = si2;

View file

@ -562,7 +562,7 @@ namespace PascalABCCompiler.TreeConverter
}
//= operation
SymbolTable.ClassMethodScope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_cmn.scope,ctn.scope, "= operator from " + ctn.scope);
SymbolTable.ClassMethodScope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(ctn.scope, _cmn.scope, "= operator from " + ctn.scope);
common_method_node cmn_eq = new common_method_node(compiler_string_consts.GetNETOperName(compiler_string_consts.eq_name),SystemLibrary.SystemLibrary.bool_type,null,ctn,
SemanticTree.polymorphic_state.ps_static,SemanticTree.field_access_level.fal_public,scope);
cmn_eq.IsOperator = true;
@ -597,7 +597,7 @@ namespace PascalABCCompiler.TreeConverter
ctn.Scope.AddSymbol(compiler_string_consts.eq_name,new SymbolInfo(cmn_eq));
//<> operation
scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_cmn.scope,ctn.scope, "<> operator from " + ctn.scope);
scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(ctn.scope, _cmn.scope, "<> operator from " + ctn.scope);
common_method_node cmn_noteq = new common_method_node(compiler_string_consts.GetNETOperName(compiler_string_consts.noteq_name),SystemLibrary.SystemLibrary.bool_type,null,ctn,
SemanticTree.polymorphic_state.ps_static,SemanticTree.field_access_level.fal_public,scope);
cmn_noteq.IsOperator = true;