diff --git a/Compiler/PCU/PCUReader.cs b/Compiler/PCU/PCUReader.cs index c855fe1af..c123ddfe9 100644 --- a/Compiler/PCU/PCUReader.cs +++ b/Compiler/PCU/PCUReader.cs @@ -467,9 +467,14 @@ namespace PascalABCCompiler.PCU { //PCUReturner.AddPCUReader((wrapped_definition_node)si.sym_info, this); //si.access_level = access_level.al_public; - SymbolInfo si2 = (cun.scope as WrappedUnitInterfaceScope).FindWithoutCreation(names[i].name); + SymbolInfo si2; + var temp = (cun.scope as WrappedUnitInterfaceScope).FindWithoutCreation(names[i].name); + if (temp != null) + si2 = temp.ToSymbolInfo(); + else + si2 = null; si.Next = si2; - Scope.AddSymbol(names[i].name, si); + Scope.AddSymbol(names[i].name, new SymbolInfoUnit(si)); } else { @@ -479,17 +484,12 @@ namespace PascalABCCompiler.PCU { if ((tn as compiled_type_node).scope == null) (tn as compiled_type_node).init_scope(); - (tn as compiled_type_node).scope.AddSymbol(names[i].name, si); + (tn as compiled_type_node).scope.AddSymbol(names[i].name, new SymbolInfoUnit(si)); } else if (tn is generic_instance_type_node) - tn.Scope.AddSymbol(names[i].name, si); + tn.Scope.AddSymbol(names[i].name, new SymbolInfoUnit(si)); else if (tn is common_type_node) - { - (tn as common_type_node).scope.AddSymbol(names[i].name, si); - if (tn.IsDelegate) - SystemLibrary.SystemLibrary.system_delegate_type.Scope.AddSymbol(names[i].name, si); - } - + (tn as common_type_node).scope.AddSymbol(names[i].name, new SymbolInfoUnit(si)); else throw new NotSupportedException(); } @@ -2226,10 +2226,10 @@ namespace PascalABCCompiler.PCU if (type_is_delegate) { - SymbolInfo sim = ctn.find_in_type(compiler_string_consts.invoke_method_name); - common_method_node invoke_method = sim.sym_info as common_method_node; + SymbolInfoList sim = ctn.find_in_type(compiler_string_consts.invoke_method_name); + common_method_node invoke_method = sim.First().sym_info as common_method_node; sim = ctn.find_in_type(compiler_string_consts.default_constructor_name); - common_method_node constructor = sim.sym_info as common_method_node; + common_method_node constructor = sim.First().sym_info as common_method_node; delegate_internal_interface dii = new delegate_internal_interface(invoke_method.return_value_type, invoke_method, constructor); dii.parameters.AddRange(invoke_method.parameters); ctn.add_internal_interface(dii); @@ -2252,10 +2252,10 @@ namespace PascalABCCompiler.PCU { foreach (common_type_node par in ctn.generic_params) { - SymbolInfo tsi = ctn.find_in_type(compiler_string_consts.generic_param_kind_prefix + par.name); + SymbolInfoList tsi = ctn.find_in_type(compiler_string_consts.generic_param_kind_prefix + par.name); if (tsi != null) { - par.runtime_initialization_marker = tsi.sym_info as class_field; + par.runtime_initialization_marker = tsi.First().sym_info as class_field; } } } @@ -2402,7 +2402,7 @@ namespace PascalABCCompiler.PCU //members[offset] = tc; AddMember(tc, offset); - cun.namespaces[0].scope.AddSymbol(name, new SymbolInfo(tc)); + cun.namespaces[0].scope.AddSymbol(name, new SymbolInfoUnit(tc)); return tc; } @@ -2446,7 +2446,7 @@ namespace PascalABCCompiler.PCU wrapped_type_synonym wts = CreateTypeSynonym(); SymbolInfo si = new SymbolInfo(); si.sym_info = wts; - scope.AddSymbol(wts.name, si); + scope.AddSymbol(wts.name, new SymbolInfoUnit(si)); } br.BaseStream.Seek(pos, SeekOrigin.Begin); } @@ -2563,7 +2563,7 @@ namespace PascalABCCompiler.PCU //Вроде это ненужно //SymbolInfo si2 = scope.FindWithoutCreation(name); //si.Next = si2; - scope.AddSymbol(name, si); + scope.AddSymbol(name, new SymbolInfoUnit(si)); names[i] = name; } return names; @@ -2807,19 +2807,13 @@ namespace PascalABCCompiler.PCU int_members.Add(cnfn); cnfn.ConnectedToType = ConnectedToType; if (cnfn.ConnectedToType != null && cnfn.ConnectedToType.type_special_kind == SemanticTree.type_special_kind.array_kind && cnfn.ConnectedToType.element_type.is_generic_parameter) - cnfn.ConnectedToType.base_type.Scope.AddSymbol(cnfn.name, new SymbolInfo(cnfn)); + cnfn.ConnectedToType.base_type.Scope.AddSymbol(cnfn.name, new SymbolInfoUnit(cnfn)); else if (cnfn.ConnectedToType != null && cnfn.ConnectedToType.is_generic_parameter) - cnfn.ConnectedToType.base_type.Scope.AddSymbol(cnfn.name, new SymbolInfo(cnfn)); + cnfn.ConnectedToType.base_type.Scope.AddSymbol(cnfn.name, new SymbolInfoUnit(cnfn)); else if (cnfn.ConnectedToType is compiled_generic_instance_type_node && cnfn.ConnectedToType.original_generic.Scope != null) - { - cnfn.ConnectedToType.original_generic.Scope.AddSymbol(cnfn.name, new SymbolInfo(cnfn)); - if (cnfn.ConnectedToType != null && cnfn.ConnectedToType.IsDelegate && cnfn.ConnectedToType.base_type.IsDelegate) - compiled_type_node.get_type_node(typeof(Delegate)).Scope.AddSymbol(cnfn.name, new SymbolInfo(cnfn)); - } + cnfn.ConnectedToType.original_generic.Scope.AddSymbol(cnfn.name, new SymbolInfoUnit(cnfn)); else if (cnfn.ConnectedToType != null && cnfn.ConnectedToType.IsDelegate && cnfn.ConnectedToType.base_type.IsDelegate) - compiled_type_node.get_type_node(typeof(Delegate)).Scope.AddSymbol(cnfn.name, new SymbolInfo(cnfn)); - else if (cnfn.ConnectedToType != null && cnfn.ConnectedToType.type_special_kind == SemanticTree.type_special_kind.typed_file && cnfn.ConnectedToType.element_type.is_generic_parameter && SystemLibrary.SystemLibInitializer.TypedFileType.sym_info != null) - (SystemLibrary.SystemLibInitializer.TypedFileType.sym_info as type_node).Scope.AddSymbol(cnfn.name, new SymbolInfo(cnfn)); + compiled_type_node.get_type_node(typeof(Delegate)).Scope.AddSymbol(cnfn.name, new SymbolInfoUnit(cnfn)); return cnfn; } @@ -2908,27 +2902,15 @@ namespace PascalABCCompiler.PCU for (int i=0; i mis = GetMembers(t,name); + name = s; + } + SymbolInfoList si = null; + + List mis = GetMembers(t, name); //(ssyy) Изменил алгоритм. //У нас некоторые алгоритмы базируются на том, что возвращённые //сущности будут одной природы (например, все - методы). Это неверно, @@ -1473,54 +1473,46 @@ namespace PascalABCCompiler.NetHelper //TODO: проанализировать и изменить алгоритмы, использующие поиск. List si_list = new List(); - SymbolInfo root_si = null; foreach (MemberInfo mi in mis) { if (mi.DeclaringType != null && PABCSystemType != null && mi.DeclaringType.Assembly == PABCSystemType.Assembly && !UsePABCRtl) continue; if (is_visible(mi)) { - SymbolInfo temp = null; + SymbolInfoUnit temp = null; switch (mi.MemberType) { case MemberTypes.Method: - temp = new SymbolInfo(compiled_function_node.get_compiled_method(mi as MethodInfo)); + temp = new SymbolInfoUnit(compiled_function_node.get_compiled_method(mi as MethodInfo)); break; case MemberTypes.Constructor: - temp = new SymbolInfo(compiled_constructor_node.get_compiled_constructor(mi as ConstructorInfo)); + temp = new SymbolInfoUnit(compiled_constructor_node.get_compiled_constructor(mi as ConstructorInfo)); break; case MemberTypes.Property: - temp = new SymbolInfo(GetPropertyNode(mi as PropertyInfo)); + temp = new SymbolInfoUnit(GetPropertyNode(mi as PropertyInfo)); break; case MemberTypes.Field: temp = GetSymbolInfoForFieldNode(mi as FieldInfo); break; case MemberTypes.Event: - temp = new SymbolInfo(GetEvent(mi as EventInfo)); + temp = new SymbolInfoUnit(GetEvent(mi as EventInfo)); break; default: continue; } - if (root_si == null) - { - root_si = temp; - si = temp; - } + if (si == null) + si = new SymbolInfoList(temp); else - { - si.Next = temp; - si = temp; - } - + si.Add(temp); + //temp.Next = si; //si = temp; } } - si = root_si; Type nested_t = null; foreach (Type nt in t.GetNestedTypes()) { - if (string.Compare(nt.Name,name, true) == 0) + if (string.Compare(nt.Name, name, true) == 0) { nested_t = nt; break; @@ -1528,28 +1520,29 @@ namespace PascalABCCompiler.NetHelper } if (nested_t != null) { - SymbolInfo temp = new SymbolInfo(compiled_type_node.get_type_node(nested_t)); - temp.Next = si; + SymbolInfoList temp = new SymbolInfoList(new SymbolInfoUnit(compiled_type_node.get_type_node(nested_t))); + temp.Add(si); si = temp; } - return si; - } - public static SymbolInfo GetSymbolInfoForFieldNode(FieldInfo fi) - { - SymbolInfo si = null; - if (fi.IsLiteral && !fi.FieldType.IsEnum) - { - compiled_class_constant_definition cd = GetConstantFieldNode(fi); - if (cd != null) - si = new SymbolInfo(cd); - } - if (si == null) - si = new SymbolInfo(GetFieldNode(fi)); return si; } - /* + public static SymbolInfoUnit GetSymbolInfoForFieldNode(FieldInfo fi) + { + SymbolInfoUnit si = null; + if (fi.IsLiteral && !fi.FieldType.IsEnum) + { + compiled_class_constant_definition cd = GetConstantFieldNode(fi); + if (cd != null) + si = new SymbolInfoUnit(cd); + } + if (si == null) + si = new SymbolInfoUnit(GetFieldNode(fi)); + return si; + } + + /* public static compiled_function_node GetMethodNode(MethodInfo mi) { compiled_function_node cfn = (compiled_function_node)meth_nodes[mi]; @@ -1560,7 +1553,7 @@ namespace PascalABCCompiler.NetHelper } */ - public static compiled_property_node GetPropertyNode(PropertyInfo pi) + public static compiled_property_node GetPropertyNode(PropertyInfo pi) { compiled_property_node cpn = null; if (prop_nodes.TryGetValue(pi, out cpn)) diff --git a/TreeConverter/SymbolTable/DSST/AreaListArray.cs b/TreeConverter/SymbolTable/DSST/AreaListArray.cs index 203904ddd..deb159521 100644 --- a/TreeConverter/SymbolTable/DSST/AreaListArray.cs +++ b/TreeConverter/SymbolTable/DSST/AreaListArray.cs @@ -43,7 +43,7 @@ namespace SymbolTable while (data[i].Area InfoList;//для перегузки + private List _InfoList;//для перегузки public AreaListNode() { - InfoList = new List(SymbolTableConstants.InfoList_StartSize); + _InfoList = new List(SymbolTableConstants.InfoList_StartSize); } - public AreaListNode(int ar,SymbolInfo inf) + public AreaListNode(int ar,SymbolInfoUnit inf) { - InfoList = new List(SymbolTableConstants.InfoList_StartSize); + var sym_inf = inf.ToSymbolInfo(); + + _InfoList = new List(SymbolTableConstants.InfoList_StartSize); Area=ar; - InfoList.Add(inf); + _InfoList.Add(sym_inf); } + + //DeleteThis + public List InfoList + { + get + { + List from_list = new List(_InfoList.Count); + foreach (var from_sym in _InfoList) + from_list.Add(new SymbolInfoUnit(from_sym)); + return from_list; + } + } + public void Add(SymbolInfoUnit need) + { + _InfoList.Add(need.ToSymbolInfo()); + } } #endregion @@ -594,47 +604,51 @@ namespace SymbolTable //Добавление символа //если такой символ в пр-ве имен уже существует то symbol_info добавляется к AreaListNode[].InfoList[] - public void Add(Scope InScope,string Name,SymbolInfo Inf) - { + public void Add(Scope InScope, string Name, SymbolInfoUnit Inf) + { //int.try - //{ - Inf.scope = InScope; - if (!InScope.CaseSensitive) Name = Name.ToLower(); - int hn = HashTable.Add(new HashTableNode(Name));//ЗДЕСь ВОЗНИКАЕТ НЕДЕТЕРМЕНИРОВАНЯ ОШИБКА - HashTable.hash_arr[hn].NumAreaList.Add(new AreaListNode(InScope.ScopeNum, Inf)); - //} - // catch (Exception e) //{ - // throw e; - // } - } - + Inf.scope = InScope; + if (!InScope.CaseSensitive) Name = Name.ToLower(); + int hn = HashTable.Add(new HashTableNode(Name));//ЗДЕСь ВОЗНИКАЕТ НЕДЕТЕРМЕНИРОВАНЯ ОШИБКА - + HashTable.hash_arr[hn].NumAreaList.Add(new AreaListNode(InScope.ScopeNum, Inf)); + //} + // catch (Exception e) + //{ + // throw e; + // } + } - //Этот метод ищет ТОЛЬКО В УКАЗАННОЙ ОВ, и не смотрит есть ли имя выше. - //Если это ОВ типа UnitImplementationScope то имя ищется также и - //в верней ОВ, которая типа UnitInterfaceScope - public SymbolInfo FindOnlyInScope(Scope scope,string Name, bool FindInUpperBlocks) - { + + + + //Этот метод ищет ТОЛЬКО В УКАЗАННОЙ ОВ, и не смотрит есть ли имя выше. + //Если это ОВ типа UnitImplementationScope то имя ищется также и + //в верней ОВ, которая типа UnitInterfaceScope + public SymbolInfoList FindOnlyInScope(Scope scope, string Name, bool FindInUpperBlocks) + { if (!scope.CaseSensitive) Name = Name.ToLower(); CurrentScope = null; - LastScope=null; - SymbolInfo FirstInfo = new SymbolInfo(); - SymbolInfo info=FirstInfo; - int Area=scope.ScopeNum; - int tn=HashTable.Find(Name); //найдем имя в хеше + LastScope = null; + + SymbolInfoList FirstInfo = new SymbolInfoList(); + + int Area = scope.ScopeNum; + int tn = HashTable.Find(Name); //найдем имя в хеше if (tn < 0 || scope is DotNETScope)//если нет такого ищем в областях .NET { Scope an; an = ScopeTable[Area]; if (an is DotNETScope) - info = AddToSymbolInfo(info, (DotNETScope)an, Name); - return FirstInfo.Next; + { + AddToSymbolInfo(FirstInfo, (DotNETScope)an, Name); + } + return FirstInfo.InfoUnitList.Count > 0 ? FirstInfo : null; } - - AreaNodesList AreaList=HashTable.hash_arr[tn].NumAreaList; - int CurrentArea=Area,ai,bs; + + AreaNodesList AreaList = HashTable.hash_arr[tn].NumAreaList; + int CurrentArea = Area, ai, bs; do { if (ScopeTable[CurrentArea] is UnitPartScope) //мы очутились в модуле @@ -645,149 +659,85 @@ namespace SymbolTable { ai = AreaList.IndexOf(CurrentArea); if (ai >= 0) //что-то нашли! - info = AddToSymbolInfo(info, AreaList[ai].InfoList, ScopeTable[CurrentArea],FirstInfo); + { + AddToSymbolInfo(AreaList[ai].InfoList, ScopeTable[CurrentArea], FirstInfo); + } CurrentArea = GetTopScopeNum(CurrentArea); } //сейча мы в InterfacePart ai = AreaList.IndexOf(CurrentArea); if (ai >= 0) //что-то нашли! - info = AddToSymbolInfo(info, AreaList[ai].InfoList, ScopeTable[CurrentArea],FirstInfo); - if(FirstInfo.Next!=null) - return FirstInfo.Next; + { + AddToSymbolInfo(AreaList[ai].InfoList, ScopeTable[CurrentArea], FirstInfo); + } + if (FirstInfo.InfoUnitList.Count > 0) + return FirstInfo; } if (ScopeTable[CurrentArea] is WithScope)//мы очутились в Width { ai = AreaList.IndexOf(CurrentArea); if (ai >= 0) //что-то нашли! - info = AddToSymbolInfo(info, AreaList[ai].InfoList, ScopeTable[CurrentArea],FirstInfo); - if (FirstInfo.Next != null) //если что-то нашли то заканчиваем - return FirstInfo.Next; - info = FindAllInAreaList(info, Name, (ScopeTable[CurrentArea] as WithScope).WithScopes, AreaList, true,FirstInfo); - if (FirstInfo.Next != null) //если что-то нашли то заканчиваем - return FirstInfo.Next; + { + AddToSymbolInfo(AreaList[ai].InfoList, ScopeTable[CurrentArea], FirstInfo); + } + if (FirstInfo.InfoUnitList.Count > 0) //если что-то нашли то заканчиваем + return FirstInfo; + + FindAllInAreaList(FirstInfo, Name, (ScopeTable[CurrentArea] as WithScope).WithScopes, AreaList, true, FirstInfo); + if (FirstInfo.InfoUnitList.Count > 0) //если что-то нашли то заканчиваем + return FirstInfo; } else { ai = AreaList.IndexOf(CurrentArea); if (ai >= 0) //что-то нашли! { - info = AddToSymbolInfo(info, AreaList[ai].InfoList, ScopeTable[CurrentArea],FirstInfo); - return FirstInfo.Next; + AddToSymbolInfo(AreaList[ai].InfoList, ScopeTable[CurrentArea], FirstInfo); + return FirstInfo.InfoUnitList.Count > 0 ? FirstInfo : null; } } bs = CurrentArea; CurrentArea = GetTopScopeNum(CurrentArea); } while (CurrentArea >= 0 && (FindInUpperBlocks && ScopeTable[bs] is BlockScope)); -// } while (CurrentArea >= 0 && ScopeTable[bs] is BlockScope); - /*if (!CaseSensitive) Name=Name.ToLower(); - int Area=scope.ScopeNum; - int tn=HashTable.Find(Name); - if (tn<0) return null; - int ai=HashTable.hash_arr[tn].NumAreaList.IndexOf(Area); - CurrentScope = null; - - if (ScopeTable[Area] is UnitImplementationScope) - { - int ai2=HashTable.hash_arr[tn].NumAreaList.IndexOf(ScopeTable[Area].TopScopeNum); - if ((ai < 0) && (ai2 >= 0)) - //Kolay modified if. - //return HashTable.hash_arr[tn].NumAreaList[ai2].InfoList[0]; - { - SymbolInfo si_init = HashTable.hash_arr[tn].NumAreaList[ai2].InfoList[0]; - SymbolInfo si_next = si_init; - for (int iter = 1; iter < HashTable.hash_arr[tn].NumAreaList[ai2].InfoList.Count; iter++) - { - si_next.Next = HashTable.hash_arr[tn].NumAreaList[ai2].InfoList[iter]; - si_next = si_next.Next; - } - return si_init; - } - if ((ai>=0)&&(ai2>=0)) - { - SymbolInfo si_int=HashTable.hash_arr[tn].NumAreaList[ai2].InfoList[0]; - SymbolInfo si_impl=HashTable.hash_arr[tn].NumAreaList[ai].InfoList[0]; - - //Kolay modified. All methods searched. - - //SymbolInfo si_init_interface = HashTable.hash_arr[tn].NumAreaList[ai].InfoList[0]; - SymbolInfo si_next = si_int; - for (int iter = 1; iter < HashTable.hash_arr[tn].NumAreaList[ai].InfoList.Count; iter++) - { - si_next.Next = HashTable.hash_arr[tn].NumAreaList[ai].InfoList[iter]; - si_next = si_next.Next; - } - - si_next.Next=si_impl; - si_next = si_next.Next; - for (int iter = 1; iter < HashTable.hash_arr[tn].NumAreaList[ai2].InfoList.Count; iter++) - { - si_next.Next = HashTable.hash_arr[tn].NumAreaList[ai2].InfoList[iter]; - si_next = si_next.Next; - } - - return si_int; - - - //return it; - } - } - - if (ai >= 0) - //Kolay modifeds this if. - //return HashTable.hash_arr[tn].NumAreaList[ai].InfoList[0]; - { - SymbolInfo si_init = HashTable.hash_arr[tn].NumAreaList[ai].InfoList[0]; - SymbolInfo si_next = si_init; - for (int iter = 1; iter < HashTable.hash_arr[tn].NumAreaList[ai].InfoList.Count;iter++ ) - { - si_next.Next = HashTable.hash_arr[tn].NumAreaList[ai].InfoList[iter]; - si_next = si_next.Next; - } - //Проверить не чиго ли это не портит! - PascalABCCompiler.TreeRealization.BasePCUReader.RestoreSymbolsImplementationMember(si_init, Name); - return si_init; - } - - - * */ return null; - - } + } - - - private SymbolInfo FindAllInClass(SymbolInfo si, string name, int ClassArea, AreaNodesList AreaList, bool OnlyInThisClass, SymbolInfo FirstInfo) - { - int ai; - + private SymbolInfoList FindAllInClass(SymbolInfoList si, string name, int ClassArea, AreaNodesList AreaList, bool OnlyInThisClass, SymbolInfoList FirstInfo) + { + int ai; Scope ar = ScopeTable[ClassArea]; - + if ((ai = AreaList.IndexOf(ClassArea)) >= 0) - si = AddToSymbolInfo(si, AreaList[ai].InfoList, ar, FirstInfo); + si = new SymbolInfoList(AddToSymbolInfo(AreaList[ai].InfoList, ar, FirstInfo)); if (ar is DotNETScope) { - PascalABCCompiler.TreeRealization.BasePCUReader.RestoreSymbols(si, name); - return AddToSymbolInfo(si, (DotNETScope)ar, name); + PascalABCCompiler.TreeRealization.BasePCUReader.RestoreSymbols(FirstInfo, name); + si = AddToSymbolInfo(FirstInfo, (DotNETScope)ar, name); + return si; } ClassScope cl = (ClassScope)ScopeTable[ClassArea]; - if(!OnlyInThisClass) + if (!OnlyInThisClass) while (cl.BaseClassScopeNum >= 0) { ai = AreaList.IndexOf(cl.BaseClassScopeNum); - if (ai >= 0) si = AddToSymbolInfo(si, AreaList[ai].InfoList, cl.BaseClassScope, FirstInfo); - + if (ai >= 0) + si = new SymbolInfoList(AddToSymbolInfo(AreaList[ai].InfoList, cl.BaseClassScope, FirstInfo)); //cl=(ClassScope)ScopeTable[cl.BaseClassScopeNum]; ar = ScopeTable[cl.BaseClassScopeNum]; if (ar is DotNETScope) - return AddToSymbolInfo(si, (DotNETScope)ar, name); + { + si = AddToSymbolInfo(FirstInfo, (DotNETScope)ar, name); + return si; + } cl = (ClassScope)ScopeTable[cl.BaseClassScopeNum]; } - return si; - } + return si; + } + private Scope FindUnitInterfaceScope(Scope scope) { while (scope!=null && !(scope is UnitInterfaceScope)) @@ -828,9 +778,9 @@ namespace SymbolTable } - private bool IsVisible(SymbolInfo ident, Scope fromScope) + private bool IsVisible(SymbolInfoUnit ident, Scope fromScope) { - if (fromScope == null) + if (fromScope == null) return true; if (FindClassScope(ident.scope) == null) return true; @@ -846,87 +796,90 @@ namespace SymbolTable } return true; } - - private bool IsNormal(SymbolInfo to,SymbolInfo add) - { - return //true; - (to.scope == null) || ((to.scope != null) && - (((to.symbol_kind==symbol_kind.sk_none)&&(add.symbol_kind==symbol_kind.sk_none))&&(to.scope==add.scope)) + + private bool IsNormal(SymbolInfoUnit to, SymbolInfoUnit add) + { + return //true; + (to == null) || (to.scope == null) || ((to.scope != null) && //to.scope == null не нужно? + (((to.symbol_kind == symbol_kind.sk_none) && (add.symbol_kind == symbol_kind.sk_none)) && (to.scope == add.scope)) || - ((to.symbol_kind==symbol_kind.sk_overload_function)&&(add.symbol_kind==symbol_kind.sk_overload_function)) + ((to.symbol_kind == symbol_kind.sk_overload_function) && (add.symbol_kind == symbol_kind.sk_overload_function)) || ((to.symbol_kind == symbol_kind.sk_overload_procedure) && (add.symbol_kind == symbol_kind.sk_overload_procedure)) ); - } - - private bool AlreadyAdded(SymbolInfo si, SymbolInfo FirstInfo) - { - if (FirstInfo == null) - return false; - while (FirstInfo.Next != null) - { - if (FirstInfo.Next == si) - return true; - FirstInfo = FirstInfo.Next; - } - return false; - } - - private SymbolInfo AddToSymbolInfo(SymbolInfo to, List from, Scope scope, SymbolInfo FirstInfo) - { + } + + private bool AlreadyAdded(SymbolInfoUnit si, SymbolInfoList FirstInfo) + { + if (FirstInfo.First() == null || si == null) + return false; + for (int i = 1; i < FirstInfo.InfoUnitList.Count; ++i) + if (FirstInfo.InfoUnitList[i] == si) + return true; + + return false; + } + + private SymbolInfoUnit AddToSymbolInfo(List from, Scope scope, SymbolInfoList FirstInfo) + { bool CheckVisible = CurrentScope != null, NeedAdd = false; - foreach (SymbolInfo si in from) + SymbolInfoUnit to = FirstInfo.Last(); + + foreach (SymbolInfoUnit si_unit in from) { if (CheckVisible) - NeedAdd = IsVisible(si, CurrentScope) && IsNormal(to, si); + NeedAdd = IsVisible(si_unit, CurrentScope) && IsNormal(to, si_unit); else - NeedAdd = IsNormal(to, si); - if (NeedAdd && !AlreadyAdded(si,FirstInfo)) + NeedAdd = IsNormal(to, si_unit); + if (NeedAdd && !AlreadyAdded(si_unit, FirstInfo)) { - to.Next = si; - si.Next = null; - to = si; + FirstInfo.Add(si_unit); + to = si_unit; } } - LastScope=scope; - return to; - } - private SymbolInfo AddToSymbolInfo(SymbolInfo to,SymbolInfo si,Scope scope) - { - if(si!=null) - if(IsNormal(to,si)) - { - to.Next=si;si.Next=null; - LastScope=scope; - return si; - } - LastScope=scope; - return to; - } - private SymbolInfo AddToSymbolInfo(SymbolInfo sito,DotNETScope ar,string name) - { - SymbolInfo si=ar.Find(name); - if(si!=null) - if (IsNormal(sito, si)) + LastScope=scope; + return to; + } + //Не используется ==> Не понятно работает или нет. + private SymbolInfoList AddToSymbolInfo(SymbolInfoList to, SymbolInfoList si, Scope scope) + { + if(si != null) + { + if(IsNormal(to.First(), si.First())) { - sito.Next = si; + to.Add(si.First()); si.InfoUnitList.RemoveRange(1, si.InfoUnitList.Count - 1); + LastScope = scope; + return si; } - - return sito; - } - private SymbolInfo FindAllInAreaList(SymbolInfo si, string name, Scope[] arr, AreaNodesList AreaNodes,SymbolInfo FirstInfo) + } + return to; + } + + private SymbolInfoList AddToSymbolInfo(SymbolInfoList sito, DotNETScope ar, string name) + { + SymbolInfoList si = ar.Find(name); + if (si != null) + if (IsNormal(sito.Last(), si.First())) + { + sito.Add(si); + return si; + } + return sito; + } + + private SymbolInfoList FindAllInAreaList(SymbolInfoList si, string name, Scope[] arr, AreaNodesList AreaNodes,SymbolInfoList FirstInfo) { return FindAllInAreaList(si, name, arr, AreaNodes, false, FirstInfo); } - private SymbolInfo FindAllInAreaList(SymbolInfo si,string name,Scope[] arr,AreaNodesList AreaNodes, bool StopIfFind, SymbolInfo FirstInfo) - { - if (arr==null) return si; - int p; - SymbolInfo sib=si; + private SymbolInfoList FindAllInAreaList(SymbolInfoList si, string name, Scope[] arr, AreaNodesList AreaNodes, bool StopIfFind, SymbolInfoList FirstInfo) + { + if (arr == null) return si; + int p; + int add = FirstInfo.IndexOf(si.First()); HashSet assm_cache = new HashSet(); - foreach(Scope sc in arr) - { + foreach (Scope sc in arr) + { if (sc is DotNETScope) { if (sc is PascalABCCompiler.NetHelper.NetScope) @@ -940,8 +893,8 @@ namespace SymbolTable continue; } } - si = AddToSymbolInfo(si, (DotNETScope)sc, name); - if (sib.Next != null && StopIfFind) + si = AddToSymbolInfo(FirstInfo, (DotNETScope)sc, name); + if (FirstInfo.InfoUnitList.Count > add && StopIfFind) return si; } else @@ -950,118 +903,147 @@ namespace SymbolTable p = AreaNodes.IndexOf(sc.ScopeNum); if (p >= 0) { - si = AddToSymbolInfo(si, AreaNodes[p].InfoList, sc, FirstInfo); - if (sib.Next != null && StopIfFind) + si = new SymbolInfoList(AddToSymbolInfo(AreaNodes[p].InfoList, sc, FirstInfo)); + if (FirstInfo.InfoUnitList.Count > add && StopIfFind) return si; } } - } - return si; - } - //поиск всех имен в ООВ. - // ищет наборы имен в ООВ, если находит то возвращает их список. - // иначе ищет в обьемлющем ООВ. - //SymbolInfo возвращаются в поряде в котором они встретились при проходе областей - public SymbolInfo Find(Scope scope,string Name) - { - return FindAll(scope, Name, false, false, null); - } - public SymbolInfo Find(Scope scope, string Name, Scope FromScope) + } + + return si; + } + //поиск всех имен в ООВ. + // ищет наборы имен в ООВ, если находит то возвращает их список. + // иначе ищет в обьемлющем ООВ. + //SymbolInfo возвращаются в поряде в котором они встретились при проходе областей + public SymbolInfoList Find(Scope scope, string Name) + { + return FindAll(scope, Name, false, false, null); + } + + public SymbolInfoList Find(Scope scope, string Name, Scope FromScope) { return FindAll(scope, Name, false, false, FromScope); } - public SymbolInfo FindOnlyInType(Scope scope, string Name) - { + public SymbolInfoList FindOnlyInType(Scope scope, string Name) + { //TODO: Почему ищет везде??? Только в типе и надтипах. А в юните он найдет? return FindAll(scope, Name, true, false, null); - } - public SymbolInfo FindOnlyInType(Scope scope, string Name, Scope FromScope) - { - return FindAll(scope, Name, true, false,FromScope); } - public SymbolInfo FindOnlyInThisClass(ClassScope scope, string Name) + public SymbolInfoList FindOnlyInType(Scope scope, string Name, Scope FromScope) + { + return FindAll(scope, Name, true, false, FromScope); + } + + public SymbolInfoList FindOnlyInThisClass(ClassScope scope, string Name) { return FindAll(scope, Name, true, true, null); } - - private SymbolInfo FindAll(Scope scope,string Name,bool OnlyInType,bool OnlyInThisClass, Scope FromScope) - { - if(OnlyInType && !(scope is ClassScope) && !(scope is SymbolTable.DotNETScope)) return null; - //if (!CaseSensitive) Name=Name.ToLower(); - if(!scope.CaseSensitive) + private SymbolInfoList FindAll(Scope scope, string Name, bool OnlyInType, bool OnlyInThisClass, Scope FromScope) + { + if (OnlyInType && !(scope is ClassScope) && !(scope is SymbolTable.DotNETScope)) return null; + //if (!CaseSensitive) Name=Name.ToLower(); + if (!scope.CaseSensitive) Name = Name.ToLower(); CurrentScope = FromScope; //глобальные переменные могут привести к ошибкам при поиске и поторном вызове! LastScope = null; //глобальные переменные могут привести к ошибкам при поиске и поторном вызове! - SymbolInfo FirstInfo = new SymbolInfo(); - SymbolInfo info=FirstInfo; - int Area=scope.ScopeNum; - Scope[] used_units=null; - int tn=HashTable.Find(Name); //найдем имя в хеше + + SymbolInfoList FirstInfo = new SymbolInfoList(new SymbolInfoUnit()); + SymbolInfoList info = FirstInfo; + + int Area = scope.ScopeNum; + Scope[] used_units = null; + int 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 < 0 || scope is DotNETScope)//если нет такого ищем в областях .NET + { //ssyy int NextUnitArea = -2; //\ssyy - Scope an; - while(Area>=0) - { - an=ScopeTable[Area]; + Scope an; + while (Area >= 0) + { + an = ScopeTable[Area]; if (an is DotNETScope) { if (tn < 0) - info = AddToSymbolInfo(info, (DotNETScope)an, Name); + { + info = AddToSymbolInfo(FirstInfo, (DotNETScope)an, Name); + } else + { info = FindAllInClass(info, Name, Area, HashTable.hash_arr[tn].NumAreaList, false, FirstInfo); + } + } + if (FirstInfo.InfoUnitList.Count > 1) + { + FirstInfo.InfoUnitList.RemoveAt(0); + return FirstInfo; + } + if (an is UnitPartScope) + { + if (an is UnitImplementationScope) + { + info = FindAllInAreaList(info, Name, (an as UnitImplementationScope).TopScopeArray, null, FirstInfo); + an = ScopeTable[an.TopScopeNum]; + } + + info = FindAllInAreaList(info, Name, (an as UnitInterfaceScope).TopScopeArray, null, FirstInfo); + + if (FirstInfo.InfoUnitList.Count > 1) + { + FirstInfo.InfoUnitList.RemoveAt(0); + return FirstInfo; + } } - if (FirstInfo.Next != null) - return FirstInfo.Next; - if (an is UnitPartScope) - { - if (an is UnitImplementationScope) - { - info=FindAllInAreaList(info,Name,(an as UnitImplementationScope).TopScopeArray,null,FirstInfo); - an=ScopeTable[an.TopScopeNum]; - } - info=FindAllInAreaList(info,Name,(an as UnitInterfaceScope).TopScopeArray,null,FirstInfo); - if (FirstInfo.Next!=null) - return FirstInfo.Next; - } if (an is WithScope)//мы очутились в Width { - info = FindAllInAreaList(info, Name, (an as WithScope).WithScopes, null, true,FirstInfo); - if (FirstInfo.Next != null) //если что-то нашли то заканчиваем - return FirstInfo.Next; + info = FindAllInAreaList(info, Name, (an as WithScope).WithScopes, null, true, FirstInfo); + + if (FirstInfo.InfoUnitList.Count > 1) //если что-то нашли то заканчиваем + { + FirstInfo.InfoUnitList.RemoveAt(0); + return FirstInfo; + } } - if (an is ClassScope) - { - int unit_area=an.TopScopeNum; + if (an is ClassScope) + { + int unit_area = an.TopScopeNum; InterfaceScope IntScope = an as InterfaceScope; while (((ClassScope)an).BaseClassScopeNum >= 0) - { - an=ScopeTable[((ClassScope)an).BaseClassScopeNum]; - if(an is DotNETScope) - { - info=AddToSymbolInfo(info,(DotNETScope)an,Name); - if (FirstInfo.Next != null) // || OnlyInType) - return FirstInfo.Next; - break; - } - } + { + an = ScopeTable[((ClassScope)an).BaseClassScopeNum]; + if (an is DotNETScope) + { + info = AddToSymbolInfo(FirstInfo, (DotNETScope)an, Name); + if (FirstInfo.InfoUnitList.Count > 1) // || OnlyInType) + { + FirstInfo.InfoUnitList.RemoveAt(0); + return FirstInfo; + } + break; + } + } //В предках ничего не нашли, ищем по интерфейсам... if (IntScope != null) { - info = FindAllInAreaList(info, Name, IntScope.TopInterfaceScopeArray, null,FirstInfo); - if (FirstInfo.Next != null) //если что-то нашли то заканчиваем - return FirstInfo.Next; + info = FindAllInAreaList(info, Name, IntScope.TopInterfaceScopeArray, null, FirstInfo); + if (FirstInfo.InfoUnitList.Count > 1) //если что-то нашли то заканчиваем + { + FirstInfo.InfoUnitList.RemoveAt(0); + return FirstInfo; + } } if (OnlyInType) - return FirstInfo.Next; + { + FirstInfo.InfoUnitList.RemoveAt(0); + return FirstInfo.InfoUnitList.Count > 0 ? FirstInfo : null; + } //ssyy if (NextUnitArea > -1) { @@ -1070,88 +1052,119 @@ namespace SymbolTable continue; } else - //\ssyy - an=ScopeTable[unit_area]; - } - if (info.Next!=null) return FirstInfo.Next; - - if (an is ClassMethodScope) - { + //\ssyy + an = ScopeTable[unit_area]; + } + if (info.InfoUnitList.Count > 1) + { + FirstInfo.InfoUnitList.RemoveAt(0); + return FirstInfo; + } + + if (an is ClassMethodScope) + { //ssyy NextUnitArea = an.TopScopeNum; //\ssyy - Area=(an as ClassMethodScope).MyClassNum; - } - else - { - Area=GetTopScopeNum(Area); - } + Area = (an as ClassMethodScope).MyClassNum; + } + else + { + Area = GetTopScopeNum(Area); + } - //Area=GetTopScopeNum(Area); - } - return null; //если такого нет то поиск окончен - } - - AreaNodesList AreaList=HashTable.hash_arr[tn].NumAreaList; - int CurrentArea=Area,ai; - while (CurrentArea>=0) - { - if (ScopeTable[CurrentArea] is UnitPartScope) //мы очутились в модуле - { - - //мы в ImplementationPart? - if (ScopeTable[CurrentArea] is UnitImplementationScope) - { - used_units=(ScopeTable[CurrentArea] as UnitImplementationScope).TopScopeArray; - ai=AreaList.IndexOf(CurrentArea); - if (ai>=0) //что-то нашли! - info=AddToSymbolInfo(info,AreaList[ai].InfoList,ScopeTable[CurrentArea],FirstInfo); - CurrentArea=GetTopScopeNum(CurrentArea); - } - //сейча мы в InterfacePart - ai=AreaList.IndexOf(CurrentArea); - if (ai>=0) //что-то нашли! - info=AddToSymbolInfo(info,AreaList[ai].InfoList,ScopeTable[CurrentArea],FirstInfo); - //смотрим в модулях - info=FindAllInAreaList(info,Name,used_units,AreaList,FirstInfo); - info=FindAllInAreaList(info,Name,(ScopeTable[CurrentArea] as UnitInterfaceScope).TopScopeArray,AreaList,FirstInfo); - return FirstInfo.Next; - } - else + //Area=GetTopScopeNum(Area); + } + return null; //если такого нет то поиск окончен + } + + AreaNodesList AreaList = HashTable.hash_arr[tn].NumAreaList; + int CurrentArea = Area, ai; + while (CurrentArea >= 0) + { + if (ScopeTable[CurrentArea] is UnitPartScope) //мы очутились в модуле + { + + //мы в ImplementationPart? + if (ScopeTable[CurrentArea] is UnitImplementationScope) + { + used_units = (ScopeTable[CurrentArea] as UnitImplementationScope).TopScopeArray; + ai = AreaList.IndexOf(CurrentArea); + + if (ai >= 0) //что-то нашли! + { + info = new SymbolInfoList(AddToSymbolInfo(AreaList[ai].InfoList, ScopeTable[CurrentArea], FirstInfo)); + } + CurrentArea = GetTopScopeNum(CurrentArea); + } + //сейча мы в InterfacePart + ai = AreaList.IndexOf(CurrentArea); + if (ai >= 0) //что-то нашли! + { + info = new SymbolInfoList(AddToSymbolInfo(AreaList[ai].InfoList, ScopeTable[CurrentArea], FirstInfo)); + } + //смотрим в модулях + info = FindAllInAreaList(info, Name, used_units, AreaList, FirstInfo); + info = FindAllInAreaList(info, Name, (ScopeTable[CurrentArea] as UnitInterfaceScope).TopScopeArray, AreaList, FirstInfo); + FirstInfo.InfoUnitList.RemoveAt(0); + return FirstInfo.InfoUnitList.Count > 0 ? FirstInfo : null; + } + else if (ScopeTable[CurrentArea] is IInterfaceScope) { - info = FindAllInClass(info, Name, CurrentArea, AreaList,OnlyInThisClass,FirstInfo); - if (FirstInfo.Next != null) //если что-то нашли то заканчиваем - return FirstInfo.Next; + info = FindAllInClass(info, Name, CurrentArea, AreaList, OnlyInThisClass, FirstInfo); + + if (FirstInfo.InfoUnitList.Count > 1) //если что-то нашли то заканчиваем + { + FirstInfo.InfoUnitList.RemoveAt(0); + return FirstInfo; + } //Зачем искать в интерфейсах? //(ssyy) Не понимаю вопрос. Спросившему подумать, зачем в компиляторе нужен поиск. info = FindAllInAreaList(info, Name, (ScopeTable[CurrentArea] as IInterfaceScope).TopInterfaceScopeArray, AreaList, FirstInfo); - if (FirstInfo.Next != null || OnlyInType) //если что-то нашли то заканчиваем - return FirstInfo.Next; + + if (FirstInfo.InfoUnitList.Count > 1 || OnlyInType) //если что-то нашли то заканчиваем + { + FirstInfo.InfoUnitList.RemoveAt(0); + return FirstInfo.InfoUnitList.Count > 0 ? FirstInfo : null; + } } else - if(ScopeTable[CurrentArea] is ClassScope)//мы очутились в классе - { - info=FindAllInClass(info,Name,CurrentArea,AreaList,OnlyInThisClass,FirstInfo);//надо сделать поиск по его предкам - if (FirstInfo.Next != null || OnlyInType) //если что-то нашли то заканчиваем - return FirstInfo.Next; - //иначе ищем дальше - } + if (ScopeTable[CurrentArea] is ClassScope)//мы очутились в классе + { + info = FindAllInClass(info, Name, CurrentArea, AreaList, OnlyInThisClass, FirstInfo);//надо сделать поиск по его предкам + + if (FirstInfo.InfoUnitList.Count > 1 || OnlyInType) //если что-то нашли то заканчиваем + { + FirstInfo.InfoUnitList.RemoveAt(0); + return FirstInfo.InfoUnitList.Count > 0 ? FirstInfo : null; + } + //иначе ищем дальше + } else if (ScopeTable[CurrentArea] is WithScope)//мы очутились в With { ai = AreaList.IndexOf(CurrentArea); if (ai >= 0) //что-то нашли! - info = AddToSymbolInfo(info, AreaList[ai].InfoList, ScopeTable[CurrentArea],FirstInfo); - if (FirstInfo.Next != null) //если что-то нашли то заканчиваем - return FirstInfo.Next; + { + info = new SymbolInfoList(AddToSymbolInfo(AreaList[ai].InfoList, ScopeTable[CurrentArea], FirstInfo)); + } + if (FirstInfo.InfoUnitList.Count > 1) //если что-то нашли то заканчиваем + { + FirstInfo.InfoUnitList.RemoveAt(0); + return FirstInfo; + } Scope[] wscopes = (ScopeTable[CurrentArea] as WithScope).WithScopes; - if(wscopes!=null) + if (wscopes != null) foreach (Scope wsc in wscopes) { - info = FindAllInClass(info, Name, wsc.ScopeNum, AreaList, OnlyInThisClass,FirstInfo);//надо сделать поиск по его предкам - if (FirstInfo.Next != null) //если что-то нашли то заканчиваем - return FirstInfo.Next; + info = FindAllInClass(info, Name, wsc.ScopeNum, AreaList, OnlyInThisClass, FirstInfo);//надо сделать поиск по его предкам + + if (FirstInfo.InfoUnitList.Count > 1) //если что-то нашли то заканчиваем + { + FirstInfo.InfoUnitList.RemoveAt(0); + return FirstInfo; + } } //info = FindAllInAreaList(info, Name, (ScopeTable[CurrentArea] as WithScope).WithScopes, AreaList, true); } @@ -1160,25 +1173,28 @@ namespace SymbolTable ai = AreaList.IndexOf(CurrentArea); if (ai >= 0) //что-то нашли! { - info = AddToSymbolInfo(info, AreaList[ai].InfoList, ScopeTable[CurrentArea],FirstInfo); - return FirstInfo.Next; + info = new SymbolInfoList(AddToSymbolInfo(AreaList[ai].InfoList, ScopeTable[CurrentArea], FirstInfo)); + FirstInfo.InfoUnitList.RemoveAt(0); + return FirstInfo.InfoUnitList.Count > 0 ? FirstInfo : null; } if (ScopeTable[CurrentArea] is ClassMethodScope)//мы очутились в методе класса { - info = FindAllInClass(info, Name, (ScopeTable[CurrentArea] as ClassMethodScope).MyClassNum, AreaList, OnlyInThisClass,FirstInfo);//надо сделать поиск по его классу - if (FirstInfo.Next != null) //если что-то нашли то заканчиваем - return FirstInfo.Next; + info = FindAllInClass(info, Name, (ScopeTable[CurrentArea] as ClassMethodScope).MyClassNum, AreaList, OnlyInThisClass, FirstInfo);//надо сделать поиск по его классу + + if (FirstInfo.InfoUnitList.Count > 1) //если что-то нашли то заканчиваем + { + FirstInfo.InfoUnitList.RemoveAt(0); + return FirstInfo; + } } } - CurrentArea=GetTopScopeNum(CurrentArea);//Пошли вверх - - } - return null; - } + CurrentArea = GetTopScopeNum(CurrentArea);//Пошли вверх - - } - public class TreeConverterSymbolTable:DSSymbolTable + } + return null; + } + } + public class TreeConverterSymbolTable:DSSymbolTable { public TreeConverterSymbolTable(bool case_sensitive):base(SymbolTableConstants.HashTable_StartSize,case_sensitive){} public TreeConverterSymbolTable():base(SymbolTableConstants.HashTable_StartSize,false){} diff --git a/TreeConverter/SymbolTable/symbol_information.cs b/TreeConverter/SymbolTable/symbol_information.cs index cd8015486..7d107ce46 100644 --- a/TreeConverter/SymbolTable/symbol_information.cs +++ b/TreeConverter/SymbolTable/symbol_information.cs @@ -3,6 +3,7 @@ using System; using PascalABCCompiler.TreeRealization; +using System.Collections.Generic; namespace PascalABCCompiler.TreeConverter { @@ -87,48 +88,48 @@ namespace PascalABCCompiler.TreeConverter } } - public class SymbolInfo - { - //private readonly name_information_type _name_information_type; - private definition_node _sym_info; + public class SymbolInfo + { + //private readonly name_information_type _name_information_type; + private definition_node _sym_info; - - private access_level _access_level; - private symbol_kind _symbol_kind; + private access_level _access_level; - public SymbolInfo Next; + private symbol_kind _symbol_kind; - public SymbolTable.Scope scope; + public SymbolInfo Next; - - public access_level access_level - { - get - { - return _access_level; - } + public SymbolTable.Scope scope; + + + public access_level access_level + { + get + { + return _access_level; + } set { _access_level = value; } - } + } - public symbol_kind symbol_kind - { - get - { - return _symbol_kind; - } - set - { - _symbol_kind=value; - } - } + public symbol_kind symbol_kind + { + get + { + return _symbol_kind; + } + set + { + _symbol_kind = value; + } + } - /*public name_information_type name_information_type + /*public name_information_type name_information_type { get { @@ -136,21 +137,21 @@ namespace PascalABCCompiler.TreeConverter } }*/ - public definition_node sym_info - { - get - { - return _sym_info; - } - set - { - _sym_info=value; - } - } + public definition_node sym_info + { + get + { + return _sym_info; + } + set + { + _sym_info = value; + } + } - public SymbolInfo() - { - } + public SymbolInfo() + { + } public SymbolInfo copy() { @@ -162,7 +163,7 @@ namespace PascalABCCompiler.TreeConverter si.Next = this.Next; return si; } - private symbol_kind get_function_kind(function_node fn,bool is_overload) + private symbol_kind get_function_kind(function_node fn, bool is_overload) { symbol_kind sk; if (is_overload) @@ -183,8 +184,8 @@ namespace PascalABCCompiler.TreeConverter return sk; } - private symbol_kind get_function_kind(function_node fn) - { + private symbol_kind get_function_kind(function_node fn) + { common_function_node cfn = fn as common_function_node; if (cfn != null) { @@ -196,22 +197,22 @@ namespace PascalABCCompiler.TreeConverter return get_function_kind(bfn, bfn.is_overload); } return symbol_kind.sk_none; - } + } - private access_level get_class_member_access_level(SemanticTree.IClassMemberNode icmn) - { - access_level al; - switch (icmn.field_access_level) - { - case SemanticTree.field_access_level.fal_public: al=access_level.al_public;break; - case SemanticTree.field_access_level.fal_protected: al=access_level.al_protected;break; - case SemanticTree.field_access_level.fal_private: al=access_level.al_private;break; + private access_level get_class_member_access_level(SemanticTree.IClassMemberNode icmn) + { + access_level al; + switch (icmn.field_access_level) + { + case SemanticTree.field_access_level.fal_public: al = access_level.al_public; break; + case SemanticTree.field_access_level.fal_protected: al = access_level.al_protected; break; + case SemanticTree.field_access_level.fal_private: al = access_level.al_private; break; case SemanticTree.field_access_level.fal_internal: al = access_level.al_internal; break; - default: - al=access_level.al_private;break; - } - return al; - } + default: + al = access_level.al_private; break; + } + return al; + } public SymbolInfo(template_class tc) { @@ -234,20 +235,20 @@ namespace PascalABCCompiler.TreeConverter _symbol_kind = symbol_kind.sk_none; } - public SymbolInfo(compiled_type_node value) - { - //_name_information_type=name_information_type.nit_compiled_type; - _sym_info=value; - _access_level=access_level.al_public; - _symbol_kind=symbol_kind.sk_none; - } - - public SymbolInfo(common_event value) - { - _sym_info = value; - _access_level = get_class_member_access_level(value); - _symbol_kind = symbol_kind.sk_none; - } + public SymbolInfo(compiled_type_node value) + { + //_name_information_type=name_information_type.nit_compiled_type; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfo(common_event value) + { + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = symbol_kind.sk_none; + } public SymbolInfo(common_namespace_event value) { @@ -263,37 +264,37 @@ namespace PascalABCCompiler.TreeConverter _symbol_kind = symbol_kind.sk_none; } - public SymbolInfo(compiled_function_node value) - { - //_name_information_type=name_information_type.nit_compiled_function; - _sym_info=value; - _access_level=get_class_member_access_level(value); - _symbol_kind=get_function_kind(value); - } + public SymbolInfo(compiled_function_node value) + { + //_name_information_type=name_information_type.nit_compiled_function; + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = get_function_kind(value); + } - public SymbolInfo(compiled_constructor_node value) - { - //_name_information_type=name_information_type.nit_compiled_function; - _sym_info=value; - _access_level=get_class_member_access_level(value); - _symbol_kind=get_function_kind(value); - } + public SymbolInfo(compiled_constructor_node value) + { + //_name_information_type=name_information_type.nit_compiled_function; + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = get_function_kind(value); + } - public SymbolInfo(compiled_property_node value) - { - //_name_information_type=name_information_type.nit_compiled_property; - _sym_info=value; - _access_level=get_class_member_access_level(value); - _symbol_kind=symbol_kind.sk_none; - } + public SymbolInfo(compiled_property_node value) + { + //_name_information_type=name_information_type.nit_compiled_property; + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = symbol_kind.sk_none; + } - public SymbolInfo(compiled_variable_definition value) - { - //_name_information_type=name_information_type.nit_compiled_variable; - _sym_info=value; - _access_level=get_class_member_access_level(value); - _symbol_kind=symbol_kind.sk_none; - } + public SymbolInfo(compiled_variable_definition value) + { + //_name_information_type=name_information_type.nit_compiled_variable; + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = symbol_kind.sk_none; + } public SymbolInfo(compiled_class_constant_definition value) { @@ -302,77 +303,77 @@ namespace PascalABCCompiler.TreeConverter _symbol_kind = symbol_kind.sk_none; } - public SymbolInfo(compiled_namespace_node value) - { - //_name_information_type=name_information_type.nit_compiled_namespace; - _sym_info=value; - _access_level=access_level.al_public; - _symbol_kind=symbol_kind.sk_none; - } + public SymbolInfo(compiled_namespace_node value) + { + //_name_information_type=name_information_type.nit_compiled_namespace; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } - public SymbolInfo(common_type_node value) - { - //_name_information_type=name_information_type.nit_common_type; - _sym_info=value; - _access_level=access_level.al_public; - _symbol_kind=symbol_kind.sk_none; - } + public SymbolInfo(common_type_node value) + { + //_name_information_type=name_information_type.nit_common_type; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } - public SymbolInfo(basic_function_node value) - { - //_name_information_type=name_information_type.nit_basic_function; - _sym_info=value; - _access_level=access_level.al_public; - _symbol_kind=get_function_kind(value); - } + public SymbolInfo(basic_function_node value) + { + //_name_information_type=name_information_type.nit_basic_function; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = get_function_kind(value); + } - public SymbolInfo(common_namespace_function_node value) - { - //_name_information_type=name_information_type.nit_common_namespace_function; - _sym_info=value; - _access_level=access_level.al_public; - _symbol_kind=get_function_kind(value); - } + public SymbolInfo(common_namespace_function_node value) + { + //_name_information_type=name_information_type.nit_common_namespace_function; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = get_function_kind(value); + } - public SymbolInfo(common_in_function_function_node value) - { - //_name_information_type=name_information_type.nit_common_in_function_function; - _sym_info=value; - _access_level=access_level.al_public; - _symbol_kind=get_function_kind(value); - } + public SymbolInfo(common_in_function_function_node value) + { + //_name_information_type=name_information_type.nit_common_in_function_function; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = get_function_kind(value); + } - public SymbolInfo(common_method_node value) - { - //_name_information_type=name_information_type.nit_common_method; - _sym_info=value; - _access_level=get_class_member_access_level(value); - _symbol_kind=get_function_kind(value); - } + public SymbolInfo(common_method_node value) + { + //_name_information_type=name_information_type.nit_common_method; + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = get_function_kind(value); + } - public SymbolInfo(common_namespace_node value) - { - //_name_information_type=name_information_type.nit_common_namespace; - _sym_info=value; - _access_level=access_level.al_public; - _symbol_kind=symbol_kind.sk_none; - } + public SymbolInfo(common_namespace_node value) + { + //_name_information_type=name_information_type.nit_common_namespace; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } - public SymbolInfo(unit_node value) - { - //_name_information_type=name_information_type.nit_unit; - _sym_info=value; - _access_level=access_level.al_public; - _symbol_kind=symbol_kind.sk_none; - } + public SymbolInfo(unit_node value) + { + //_name_information_type=name_information_type.nit_unit; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } - public SymbolInfo(local_variable value) - { - //_name_information_type=name_information_type.nit_local_variable; - _sym_info=value; - _access_level=access_level.al_public; - _symbol_kind=symbol_kind.sk_none; - } + public SymbolInfo(local_variable value) + { + //_name_information_type=name_information_type.nit_local_variable; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } public SymbolInfo(local_block_variable value) { @@ -382,61 +383,61 @@ namespace PascalABCCompiler.TreeConverter _symbol_kind = symbol_kind.sk_none; } - + public SymbolInfo(namespace_variable value) - { - //_name_information_type=name_information_type.nit_namespace_variable; - _sym_info=value; - _access_level=access_level.al_public; - _symbol_kind=symbol_kind.sk_none; - } + { + //_name_information_type=name_information_type.nit_namespace_variable; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } - public SymbolInfo(class_field value) - { - //_name_information_type=name_information_type.nit_class_field; - _sym_info=value; - _access_level=get_class_member_access_level(value); - _symbol_kind=symbol_kind.sk_none; - } + public SymbolInfo(class_field value) + { + //_name_information_type=name_information_type.nit_class_field; + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = symbol_kind.sk_none; + } - public SymbolInfo(common_parameter value) - { - //_name_information_type=name_information_type.nit_common_parameter; - _sym_info=value; - _access_level=access_level.al_public; - _symbol_kind=symbol_kind.sk_none; - } + public SymbolInfo(common_parameter value) + { + //_name_information_type=name_information_type.nit_common_parameter; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } - public SymbolInfo(basic_parameter value) - { - //_name_information_type=name_information_type.nit_basic_parameter; - _sym_info=value; - _access_level=access_level.al_public; - _symbol_kind=symbol_kind.sk_none; - } + public SymbolInfo(basic_parameter value) + { + //_name_information_type=name_information_type.nit_basic_parameter; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } - public SymbolInfo(constant_definition_node value) - { - //_name_information_type=name_information_type.nit_constant_defnition; - _sym_info=value; - _access_level=access_level.al_public; - _symbol_kind=symbol_kind.sk_none; - } + public SymbolInfo(constant_definition_node value) + { + //_name_information_type=name_information_type.nit_constant_defnition; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } - public SymbolInfo(common_property_node value) - { - //_name_information_type=name_information_type.nit_common_property; - _sym_info=value; - _access_level=get_class_member_access_level(value); - _symbol_kind=symbol_kind.sk_none; - } + public SymbolInfo(common_property_node value) + { + //_name_information_type=name_information_type.nit_common_property; + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = symbol_kind.sk_none; + } - public SymbolInfo(type_node value) - { - _sym_info=value; - _access_level=access_level.al_public; - _symbol_kind=symbol_kind.sk_none; - } + public SymbolInfo(type_node value) + { + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } public SymbolInfo(definition_node value, access_level alevel, symbol_kind skind) { @@ -444,6 +445,576 @@ namespace PascalABCCompiler.TreeConverter _access_level = alevel; _symbol_kind = skind; } - } + + public override bool Equals(System.Object obj) + { + if (obj == null) + { + return false; + } + + SymbolInfo p = obj as SymbolInfo; + if ((System.Object)p == null) + { + return false; + } + + return (_access_level == p._access_level) && (_symbol_kind == p._symbol_kind) && (_sym_info == p.sym_info) && (scope == p.scope) && (Next == p.Next); + } + + public bool Equals(SymbolInfo p) + { + if ((object)p == null) + { + return false; + } + return (_access_level == p._access_level) && (_symbol_kind == p._symbol_kind) && (_sym_info == p.sym_info) && (scope == p.scope) && (Next == p.Next); + } + + + public static bool operator ==(SymbolInfo a, SymbolInfo b) + { + if (object.ReferenceEquals(a, null)) + { + return object.ReferenceEquals(b, null); + } + + return a.Equals(b); + } + + public static bool operator !=(SymbolInfo a, SymbolInfo b) + { + return !(a == b); + } + } + public class SymbolInfoList + { + //private readonly name_information_type _name_information_type; + + public List InfoUnitList; + + public SymbolInfoList() + { + InfoUnitList = new List(SymbolTable.SymbolTableConstants.InfoList_StartSize); + } + + public SymbolInfoList(SymbolInfoUnit inf) + { + InfoUnitList = new List(SymbolTable.SymbolTableConstants.InfoList_StartSize); + InfoUnitList.Add(inf); + } + + public SymbolInfoList(SymbolInfo inf) + { + InfoUnitList = new List(SymbolTable.SymbolTableConstants.InfoList_StartSize); + while (inf != null) + { + SymbolInfoUnit temp = new SymbolInfoUnit(inf); + InfoUnitList.Add(temp); + inf = inf.Next; + } + } + + + public SymbolInfoList copy() + { + SymbolInfoList si = new SymbolInfoList(); + si.InfoUnitList = this.InfoUnitList; + return si; + } + + public void Add(SymbolInfoUnit value) + { + InfoUnitList.Add(value); + } + public void Add(SymbolInfoList value) + { + if(value != null) + InfoUnitList.AddRange(value.InfoUnitList); + } + + public SymbolInfoUnit First() + { + if (InfoUnitList.Count > 0) + return InfoUnitList[0]; + else + return null; + } + + public SymbolInfoUnit Last() + { + if (InfoUnitList.Count > 0) + return InfoUnitList[InfoUnitList.Count - 1]; + else + return null; + } + + public int IndexOf(SymbolInfoUnit x) + { + for (int i = 0; i < InfoUnitList.Count; ++i) + if (InfoUnitList[i] == x) + return i; + + return -1; + } + + public SymbolInfo ToSymbolInfo() + { + SymbolInfo first_temp = new SymbolInfo(); + SymbolInfo temp = first_temp; + foreach(var info_unit in InfoUnitList) + { + temp.Next = info_unit.ToSymbolInfo(); + temp = temp.Next; + } + return first_temp.Next; + } + + public static bool operator ==(SymbolInfoList a, SymbolInfoList b) + { + if (System.Object.ReferenceEquals(a, b)) + { + return true; + } + if (((object)a == null) || ((object)b == null)) + { + return false; + } + if (a.InfoUnitList.Count != b.InfoUnitList.Count) + return false; + for (int i = 0; i < a.InfoUnitList.Count; ++i) + if (a.InfoUnitList[i] != b.InfoUnitList[i]) + return false; + return true; + } + public static bool operator !=(SymbolInfoList a, SymbolInfoList b) + { + return !(a == b); + } + } + + + public class SymbolInfoUnit + { + //private readonly name_information_type _name_information_type; + private definition_node _sym_info; + + + private access_level _access_level; + + private symbol_kind _symbol_kind; + + public SymbolTable.Scope scope; + + public SymbolInfo reference; + + + public access_level access_level + { + get + { + return _access_level; + } + set + { + _access_level = value; + } + } + + public symbol_kind symbol_kind + { + get + { + return _symbol_kind; + } + set + { + _symbol_kind = value; + } + } + + /*public name_information_type name_information_type + { + get + { + return _name_information_type; + } + }*/ + + public definition_node sym_info + { + get + { + return _sym_info; + } + set + { + _sym_info = value; + } + } + + public SymbolInfoUnit() + { + reference = new SymbolInfo(); + } + + public SymbolInfoUnit copy() + { + SymbolInfoUnit si = new SymbolInfoUnit(); + si._access_level = this.access_level; + si._sym_info = this._sym_info; + si._symbol_kind = this._symbol_kind; + si.scope = this.scope; + return si; + } + + public SymbolInfo ToSymbolInfo() + { + reference.Next = null; + reference.access_level = _access_level; + reference.symbol_kind = _symbol_kind; + reference.sym_info = _sym_info; + reference.scope = scope; + return reference; + } + + public SymbolInfoUnit(SymbolInfo inf) + { + reference = inf; + _access_level = inf.access_level; + _symbol_kind = inf.symbol_kind; + _sym_info = inf.sym_info; + scope = inf.scope; + } + + private symbol_kind get_function_kind(function_node fn, bool is_overload) + { + symbol_kind sk; + if (is_overload) + { + if (fn.return_value_type == null) + { + sk = symbol_kind.sk_overload_procedure; + } + else + { + sk = symbol_kind.sk_overload_function; + } + } + else + { + sk = symbol_kind.sk_none; + } + return sk; + } + + private symbol_kind get_function_kind(function_node fn) + { + common_function_node cfn = fn as common_function_node; + if (cfn != null) + { + return get_function_kind(cfn, cfn.is_overload); + } + basic_function_node bfn = fn as basic_function_node; + if (bfn != null) + { + return get_function_kind(bfn, bfn.is_overload); + } + return symbol_kind.sk_none; + } + + private access_level get_class_member_access_level(SemanticTree.IClassMemberNode icmn) + { + access_level al; + switch (icmn.field_access_level) + { + case SemanticTree.field_access_level.fal_public: al = access_level.al_public; break; + case SemanticTree.field_access_level.fal_protected: al = access_level.al_protected; break; + case SemanticTree.field_access_level.fal_private: al = access_level.al_private; break; + case SemanticTree.field_access_level.fal_internal: al = access_level.al_internal; break; + default: + al = access_level.al_private; break; + } + return al; + } + + public SymbolInfoUnit(template_class tc) + { + reference = new SymbolInfo(tc); + _sym_info = tc; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(label_node lab) + { + reference = new SymbolInfo(lab); + _sym_info = lab; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(compiled_event ce) + { + reference = new SymbolInfo(ce); + _sym_info = ce; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(compiled_type_node value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_compiled_type; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(common_event value) + { + reference = new SymbolInfo(value); + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(common_namespace_event value) + { + reference = new SymbolInfo(value); + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(function_node value) + { + reference = new SymbolInfo(value); + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(compiled_function_node value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_compiled_function; + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = get_function_kind(value); + } + + public SymbolInfoUnit(compiled_constructor_node value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_compiled_function; + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = get_function_kind(value); + } + + public SymbolInfoUnit(compiled_property_node value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_compiled_property; + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(compiled_variable_definition value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_compiled_variable; + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(compiled_class_constant_definition value) + { + reference = new SymbolInfo(value); + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(compiled_namespace_node value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_compiled_namespace; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(common_type_node value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_common_type; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(basic_function_node value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_basic_function; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = get_function_kind(value); + } + + public SymbolInfoUnit(common_namespace_function_node value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_common_namespace_function; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = get_function_kind(value); + } + + public SymbolInfoUnit(common_in_function_function_node value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_common_in_function_function; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = get_function_kind(value); + } + + public SymbolInfoUnit(common_method_node value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_common_method; + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = get_function_kind(value); + } + + public SymbolInfoUnit(common_namespace_node value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_common_namespace; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(unit_node value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_unit; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(local_variable value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_local_variable; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(local_block_variable value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_local_variable; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(namespace_variable value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_namespace_variable; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(class_field value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_class_field; + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(common_parameter value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_common_parameter; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(basic_parameter value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_basic_parameter; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(constant_definition_node value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_constant_defnition; + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(common_property_node value) + { + reference = new SymbolInfo(value); + //_name_information_type=name_information_type.nit_common_property; + _sym_info = value; + _access_level = get_class_member_access_level(value); + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(type_node value) + { + reference = new SymbolInfo(value); + _sym_info = value; + _access_level = access_level.al_public; + _symbol_kind = symbol_kind.sk_none; + } + + public SymbolInfoUnit(definition_node value, access_level alevel, symbol_kind skind) + { + reference = new SymbolInfo(value, alevel, skind); + _sym_info = value; + _access_level = alevel; + _symbol_kind = skind; + } + + public static bool operator ==(SymbolInfoUnit a, SymbolInfoUnit b) + { + if (System.Object.ReferenceEquals(a, b)) + { + return true; + } + if (((object)a == null) || ((object)b == null)) + { + return false; + } + return (a._access_level == b._access_level) && (a._symbol_kind == b._symbol_kind) && (a._sym_info == b._sym_info) && (a.scope == b.scope); + } + public static bool operator !=(SymbolInfoUnit a, SymbolInfoUnit b) + { + return !(a == b); + } + } } diff --git a/TreeConverter/SystemLib/StaticSystemLib.cs b/TreeConverter/SystemLib/StaticSystemLib.cs index b88814b7c..41bc72055 100644 --- a/TreeConverter/SystemLib/StaticSystemLib.cs +++ b/TreeConverter/SystemLib/StaticSystemLib.cs @@ -956,18 +956,20 @@ namespace PascalABCCompiler.SystemLibrary basic_function_node inc_var = create_oti_method(vinc, type, SemanticTree.parameter_type.var); basic_function_node dec_var = create_oti_method(vdec, type, SemanticTree.parameter_type.var); - SymbolInfo si = type.find_in_type(compiler_string_consts.greq_name); - basic_function_node greq = (basic_function_node)si.sym_info; + SymbolInfoList si = type.find_in_type(compiler_string_consts.greq_name); + basic_function_node greq = (basic_function_node)si.First().sym_info; si = type.find(compiler_string_consts.smeq_name); - basic_function_node loeq = (basic_function_node)si.sym_info; + basic_function_node loeq = (basic_function_node)si.First().sym_info; + si = type.find(compiler_string_consts.sm_name); - basic_function_node lo = (basic_function_node)si.sym_info; + basic_function_node lo = (basic_function_node)si.First().sym_info; + si = type.find(compiler_string_consts.gr_name); - basic_function_node gr = (basic_function_node)si.sym_info; - + basic_function_node gr = (basic_function_node)si.First().sym_info; + ordinal_type_interface oti = new ordinal_type_interface(inc_value, dec_value, inc_var, dec_var, loeq, greq, lo, gr, lower_value, upper_value, t2i, t2i_comp); diff --git a/TreeConverter/SystemLib/SystemLibInitializer.cs b/TreeConverter/SystemLib/SystemLibInitializer.cs index fbbf528b7..8d6c9d6d9 100644 --- a/TreeConverter/SystemLib/SystemLibInitializer.cs +++ b/TreeConverter/SystemLib/SystemLibInitializer.cs @@ -21,10 +21,16 @@ namespace PascalABCCompiler.SystemLibrary if (_notCreatedSymbolInfo != null) return _notCreatedSymbolInfo; if (cmn != null) - _notCreatedSymbolInfo = cmn.scope.SymbolTable.Find(cmn.scope, name); + { + var temp = cmn.scope.SymbolTable.Find(cmn.scope, name); + if (temp != null) + _notCreatedSymbolInfo = temp.ToSymbolInfo(); + else + _notCreatedSymbolInfo = null; + } else { - Type t = NetHelper.NetHelper.PABCSystemType.Assembly.GetType("PABCSystem."+name); + Type t = NetHelper.NetHelper.PABCSystemType.Assembly.GetType("PABCSystem." + name); if (t != null) { _notCreatedSymbolInfo = new TreeConverter.SymbolInfo(compiled_type_node.get_type_node(t, SystemLibrary.syn_visitor.SymbolTable)); @@ -32,7 +38,10 @@ namespace PascalABCCompiler.SystemLibrary else { compiled_type_node ctn = compiled_type_node.get_type_node(NetHelper.NetHelper.PABCSystemType); - _notCreatedSymbolInfo = ctn.find_in_type(name); + _notCreatedSymbolInfo = null; + var temp = ctn.find_in_type(name); + if (temp != null) + _notCreatedSymbolInfo = temp.ToSymbolInfo(); /*if (name == TreeConverter.compiler_string_consts.read_procedure_name || name == TreeConverter.compiler_string_consts.readln_procedure_name) { compiled_type_node ctn2 = compiled_type_node.get_type_node(NetHelper.NetHelper.PT4Type); @@ -77,7 +86,13 @@ namespace PascalABCCompiler.SystemLibrary if (symbolInfo != null) return symbolInfo; if (cmn != null) - symbolInfo = cmn.scope.Find(name); + { + var temp = cmn.scope.Find(name); + if (temp != null) + symbolInfo = temp.ToSymbolInfo(); + else + symbolInfo = null; + } else { Type t = NetHelper.NetHelper.PABCSystemType.Assembly.GetType("PABCSystem." + name); @@ -88,7 +103,10 @@ namespace PascalABCCompiler.SystemLibrary else { compiled_type_node ctn = compiled_type_node.get_type_node(NetHelper.NetHelper.PABCSystemType); - symbolInfo = ctn.find_in_type(name); + symbolInfo = null; + var temp = ctn.find_in_type(name); + if (temp != null) + symbolInfo = temp.ToSymbolInfo(); /*if (name == TreeConverter.compiler_string_consts.read_procedure_name || name == TreeConverter.compiler_string_consts.readln_procedure_name) { compiled_type_node ctn2 = compiled_type_node.get_type_node(NetHelper.NetHelper.PT4Type); @@ -108,31 +126,31 @@ namespace PascalABCCompiler.SystemLibrary { common_type_node tctn = symbolInfo.sym_info as common_type_node; tctn.type_special_kind = SemanticTree.type_special_kind.base_set_type; - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.plus_name, SystemLibInitializer.SetUnionProcedure.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.mul_name, SystemLibInitializer.SetIntersectProcedure.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.in_name, SystemLibInitializer.InSetProcedure.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.minus_name, SystemLibInitializer.SetSubtractProcedure.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.gr_name, SystemLibInitializer.CompareSetGreater.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.greq_name, SystemLibInitializer.CompareSetGreaterEqual.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.sm_name, SystemLibInitializer.CompareSetLess.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.smeq_name, SystemLibInitializer.CompareSetLessEqual.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.eq_name, SystemLibInitializer.CompareSetEquals.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.noteq_name, SystemLibInitializer.CompareSetInEquals.SymbolInfo); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.plus_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.SetUnionProcedure.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.mul_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.SetIntersectProcedure.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.in_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.InSetProcedure.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.minus_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.SetSubtractProcedure.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.gr_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.CompareSetGreater.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.greq_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.CompareSetGreaterEqual.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.sm_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.CompareSetLess.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.smeq_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.CompareSetLessEqual.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.eq_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.CompareSetEquals.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.noteq_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.CompareSetInEquals.SymbolInfo)); } else { compiled_type_node tctn = symbolInfo.sym_info as compiled_type_node; tctn.type_special_kind = SemanticTree.type_special_kind.base_set_type; - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.plus_name, SystemLibInitializer.SetUnionProcedure.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.mul_name, SystemLibInitializer.SetIntersectProcedure.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.in_name, SystemLibInitializer.InSetProcedure.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.minus_name, SystemLibInitializer.SetSubtractProcedure.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.gr_name, SystemLibInitializer.CompareSetGreater.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.greq_name, SystemLibInitializer.CompareSetGreaterEqual.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.sm_name, SystemLibInitializer.CompareSetLess.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.smeq_name, SystemLibInitializer.CompareSetLessEqual.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.eq_name, SystemLibInitializer.CompareSetEquals.SymbolInfo); - tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.noteq_name, SystemLibInitializer.CompareSetInEquals.SymbolInfo); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.plus_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.SetUnionProcedure.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.mul_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.SetIntersectProcedure.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.in_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.InSetProcedure.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.minus_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.SetSubtractProcedure.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.gr_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.CompareSetGreater.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.greq_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.CompareSetGreaterEqual.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.sm_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.CompareSetLess.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.smeq_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.CompareSetLessEqual.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.eq_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.CompareSetEquals.SymbolInfo)); + tctn.scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.noteq_name, new TreeConverter.SymbolInfoUnit(SystemLibInitializer.CompareSetInEquals.SymbolInfo)); } } else if (symbolInfo != null && SystemLibInitializer.TextFileType.Equal(symbolInfo)) @@ -212,7 +230,11 @@ namespace PascalABCCompiler.SystemLibrary { if (symbolInfo != null) return symbolInfo.sym_info as type_node; - symbolInfo = cmn.scope.Find(name); + var temp = cmn.scope.Find(name); + if (temp != null) + symbolInfo = temp.ToSymbolInfo(); + else + symbolInfo = null; return symbolInfo.sym_info as type_node; } } @@ -416,8 +438,8 @@ namespace PascalABCCompiler.SystemLibrary PascalABCCompiler.TreeConverter.compiler_string_consts.false_const_name, SystemLibrary.false_constant, system_unit_location, system_namespace); system_namespace.constants.AddElement(_false_constant_definition); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.true_const_name, new PascalABCCompiler.TreeConverter.SymbolInfo(_true_constant_definition)); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.false_const_name, new PascalABCCompiler.TreeConverter.SymbolInfo(_false_constant_definition)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.true_const_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(_true_constant_definition)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.false_const_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(_false_constant_definition)); //TODO: Сделано по быстрому. Переделать. Можно просто один раз сериализовать модуль system и не инициализировать его всякий раз подобным образом. Неплохо-бы использовать NetHelper.GetMethod. @@ -435,7 +457,7 @@ namespace PascalABCCompiler.SystemLibrary _NewProcedure.symbol_kind = PascalABCCompiler.TreeConverter.symbol_kind.sk_overload_function; _NewProcedure.access_level = PascalABCCompiler.TreeConverter.access_level.al_public; _NewProcedureDecl = cnfn; - sc.AddSymbol(TreeConverter.compiler_string_consts.new_procedure_name, _NewProcedure); + sc.AddSymbol(TreeConverter.compiler_string_consts.new_procedure_name, new TreeConverter.SymbolInfoUnit(_NewProcedure)); cnfn = new common_namespace_function_node(TreeConverter.compiler_string_consts.dispose_procedure_name, null, null, system_namespace, null); cnfn.parameters.AddElement(new common_parameter("ptr", SystemLibrary.pointer_type, SemanticTree.parameter_type.value, @@ -445,7 +467,7 @@ namespace PascalABCCompiler.SystemLibrary _DisposeProcedure.access_level = PascalABCCompiler.TreeConverter.access_level.al_public; _DisposeProcedureDecl = cnfn; cnfn.SpecialFunctionKind = SemanticTree.SpecialFunctionKind.Dispose; - sc.AddSymbol(TreeConverter.compiler_string_consts.dispose_procedure_name, _DisposeProcedure); + sc.AddSymbol(TreeConverter.compiler_string_consts.dispose_procedure_name, new TreeConverter.SymbolInfoUnit(_DisposeProcedure)); cnfn = new common_namespace_function_node(TreeConverter.compiler_string_consts.new_array_procedure_name, compiled_type_node.get_type_node(typeof(Array)), null, system_namespace, null); cnfn.parameters.AddElement(new common_parameter("t", compiled_type_node.get_type_node(typeof(Type)), SemanticTree.parameter_type.value, cnfn, @@ -460,20 +482,20 @@ namespace PascalABCCompiler.SystemLibrary basic_function_node break_procedure = new basic_function_node(SemanticTree.basic_function_type.none, null, true); break_procedure.compile_time_executor = initialization_properties.break_executor; - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.break_procedure_name, new PascalABCCompiler.TreeConverter.SymbolInfo(break_procedure)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.break_procedure_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(break_procedure)); basic_function_node continue_procedure = new basic_function_node(SemanticTree.basic_function_type.none, null, true); continue_procedure.compile_time_executor = initialization_properties.continue_executor; - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.continue_procedure_name, new PascalABCCompiler.TreeConverter.SymbolInfo(continue_procedure)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.continue_procedure_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(continue_procedure)); basic_function_node exit_procedure = new basic_function_node(SemanticTree.basic_function_type.none, null, true); exit_procedure.compile_time_executor = initialization_properties.exit_executor; - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.exit_procedure_name, new PascalABCCompiler.TreeConverter.SymbolInfo(exit_procedure)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.exit_procedure_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(exit_procedure)); sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.set_length_procedure_name, - new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.resize_func, PascalABCCompiler.TreeConverter.access_level.al_public, PascalABCCompiler.TreeConverter.symbol_kind.sk_overload_function)); + new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.resize_func, PascalABCCompiler.TreeConverter.access_level.al_public, PascalABCCompiler.TreeConverter.symbol_kind.sk_overload_function)); } public static common_unit_node make_system_unit(SymbolTable.TreeConverterSymbolTable symbol_table, @@ -489,31 +511,31 @@ namespace PascalABCCompiler.SystemLibrary common_namespace_node cnn = new common_namespace_node(null, _system_unit, PascalABCCompiler.TreeConverter.compiler_string_consts.system_unit_name, symbol_table.CreateScope(main_scope),system_unit_location); - main_scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.system_unit_name, new PascalABCCompiler.TreeConverter.SymbolInfo(cnn)); + main_scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.system_unit_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(cnn)); //SymbolTable.Scope sc = cnn.scope; SymbolTable.Scope sc = main_scope; //Добавляем типы. - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.byte_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.byte_type)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.byte_type_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.byte_type)); //sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.decimal_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.decimal_type)); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.sbyte_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.sbyte_type)); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.short_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.short_type)); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.ushort_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.ushort_type)); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.integer_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.integer_type)); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.uint_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.uint_type)); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.long_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.int64_type)); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.ulong_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.uint64_type)); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.float_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.float_type)); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.real_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.double_type)); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.char_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.char_type)); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.bool_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.bool_type)); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.string_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.string_type)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.sbyte_type_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.sbyte_type)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.short_type_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.short_type)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.ushort_type_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.ushort_type)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.integer_type_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.integer_type)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.uint_type_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.uint_type)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.long_type_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.int64_type)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.ulong_type_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.uint64_type)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.float_type_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.float_type)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.real_type_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.double_type)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.char_type_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.char_type)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.bool_type_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.bool_type)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.string_type_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.string_type)); //sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.object_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.object_type)); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.pointer_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.pointer_type)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.pointer_type_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.pointer_type)); //sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.base_exception_class_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.exception_base_type)); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.base_array_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.array_base_type)); - sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.base_delegate_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.delegate_base_type)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.base_array_type_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.array_base_type)); + sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.base_delegate_type_name, new PascalABCCompiler.TreeConverter.SymbolInfoUnit(SystemLibrary.delegate_base_type)); //TODO: Переделать. Пусть таблица символов создается одна. Как статическая. compiled_type_node comp_byte_type = ((compiled_type_node)SystemLibrary.byte_type); diff --git a/TreeConverter/TreeConversion/compilation_context.cs b/TreeConverter/TreeConversion/compilation_context.cs index b0f19a5f9..4588faa40 100644 --- a/TreeConverter/TreeConversion/compilation_context.cs +++ b/TreeConverter/TreeConversion/compilation_context.cs @@ -41,11 +41,7 @@ namespace PascalABCCompiler.TreeConverter public Stack type_stack; // Для вложенных типов public statement_list_stack stlist_stack; public semantic_node ret_value; // Возвращаемое значение класса returner - public bool WithSection; - public Dictionary WithVariables; - public Stack WithTypes; //LambdaHelper.Reset(); // Пока не знаю, что с этим делать - } public class compilation_context @@ -100,9 +96,6 @@ namespace PascalABCCompiler.TreeConverter SavedContext.member_decls = member_decls; SavedContext.types_predefined = _types_predefined; SavedContext.ret_value = syntax_tree_visitor.ret.get_result(); - SavedContext.WithTypes = WithTypes; - SavedContext.WithSection = WithSection; - SavedContext.WithVariables = WithVariables; SavedContextStack.Push(SavedContext); // SavedContext.type_stack = type_stack; @@ -159,9 +152,6 @@ namespace PascalABCCompiler.TreeConverter _fal = SavedContext._fal; member_decls = SavedContext.member_decls; _types_predefined = SavedContext.types_predefined; - WithTypes = SavedContext.WithTypes; - WithVariables = SavedContext.WithVariables; - WithSection = SavedContext.WithSection; syntax_tree_visitor.ret.return_value(SavedContext.ret_value); if (SavedContextStack.Count == 0) @@ -174,9 +164,6 @@ namespace PascalABCCompiler.TreeConverter public common_type_node _ctn; // SSM - пытаюсь выходить из класса и входить заново private common_function_node_stack _func_stack=new common_function_node_stack(); private type_node _explicit_interface_type; - internal bool WithSection = false; - internal Dictionary WithVariables = new Dictionary(); - internal Stack WithTypes = new Stack(); internal common_function_node_stack func_stack { @@ -239,7 +226,6 @@ namespace PascalABCCompiler.TreeConverter } } - private int _num_for_delegates; private int _num_of_for_cycles; internal convertion_data_and_alghoritms convertion_data_and_alghoritms; @@ -290,7 +276,6 @@ namespace PascalABCCompiler.TreeConverter _cycles_stack.clear(); _num_of_for_cycles = 0; _fal = SemanticTree.field_access_level.fal_private; - _num_for_delegates = 0; rec_num = 1; var_defs_stack.Clear(); type_stack.Clear(); @@ -427,7 +412,7 @@ namespace PascalABCCompiler.TreeConverter public void AddTemplate(string name, template_class tc, location loc) { //check_name_free(name, loc); - _cmn.scope.AddSymbol(name, new SymbolInfo(tc)); + _cmn.scope.AddSymbol(name, new SymbolInfoUnit(tc)); _cmn.templates.AddElement(tc); } @@ -443,19 +428,19 @@ namespace PascalABCCompiler.TreeConverter if (instance.TypedSets.ContainsKey(tctn.element_type)) return instance.TypedSets[tctn.element_type]; instance.TypedSets.Add(tctn.element_type,tctn); tctn.add_name(compiler_string_consts.assign_name,new SymbolInfo(SystemLibrary.SystemLibrary.make_assign_operator(tctn,PascalABCCompiler.SemanticTree.basic_function_type.objassign))); - tctn.scope.AddSymbol(compiler_string_consts.plus_name, SystemLibrary.SystemLibInitializer.SetUnionProcedure.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.mul_name, SystemLibrary.SystemLibInitializer.SetIntersectProcedure.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.in_name, SystemLibrary.SystemLibInitializer.InSetProcedure.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.minus_name, SystemLibrary.SystemLibInitializer.SetSubtractProcedure.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.eq_name, SystemLibrary.SystemLibInitializer.CompareSetEquals.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.noteq_name, SystemLibrary.SystemLibInitializer.CompareSetInEquals.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.sm_name, SystemLibrary.SystemLibInitializer.CompareSetLess.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.smeq_name, SystemLibrary.SystemLibInitializer.CompareSetLessEqual.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.gr_name, SystemLibrary.SystemLibInitializer.CompareSetGreater.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.greq_name, SystemLibrary.SystemLibInitializer.CompareSetGreaterEqual.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.plusassign_name,new SymbolInfo(make_set_plus_assign(tctn))); - tctn.scope.AddSymbol(compiler_string_consts.minusassign_name,new SymbolInfo(make_set_minus_assign(tctn))); - tctn.scope.AddSymbol(compiler_string_consts.multassign_name,new SymbolInfo(make_set_mult_assign(tctn))); + tctn.scope.AddSymbol(compiler_string_consts.plus_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.SetUnionProcedure.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.mul_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.SetIntersectProcedure.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.in_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.InSetProcedure.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.minus_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.SetSubtractProcedure.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.eq_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetEquals.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.noteq_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetInEquals.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.sm_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetLess.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.smeq_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetLessEqual.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.gr_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetGreater.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.greq_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetGreaterEqual.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.plusassign_name,new SymbolInfoUnit(make_set_plus_assign(tctn))); + tctn.scope.AddSymbol(compiler_string_consts.minusassign_name,new SymbolInfoUnit(make_set_minus_assign(tctn))); + tctn.scope.AddSymbol(compiler_string_consts.multassign_name,new SymbolInfoUnit(make_set_mult_assign(tctn))); return tctn; } @@ -487,7 +472,7 @@ namespace PascalABCCompiler.TreeConverter public void AddTemplateInstance(string name, type_node t) { - _cmn.scope.AddSymbol(name, new SymbolInfo(t)); + _cmn.scope.AddSymbol(name, new SymbolInfoUnit(t)); } private void clear_special_local_vars() @@ -711,7 +696,7 @@ namespace PascalABCCompiler.TreeConverter } _cmn = new common_namespace_node(comprehensive_namespace, cont_unit, namespace_name, scope, loc); cont_unit.namespaces.AddElement(_cmn); - _cmn.scope.AddSymbol(namespace_name,new SymbolInfo(_cmn)); + _cmn.scope.AddSymbol(namespace_name,new SymbolInfoUnit(_cmn)); return _cmn; } @@ -758,22 +743,26 @@ namespace PascalABCCompiler.TreeConverter SymbolInfo si = find(name); return check_name_node_type(name, si, loc, expected_node_types); } - + //DeleteSymbolInfo public definition_node check_name_node_type(string name, SymbolInfo si, location loc, params general_node_type[] expected_node_types) // SSM перебросил сюда из syntax_tree_visitor 3.04.14 { - if (si == null) + SymbolInfoList si_list = new SymbolInfoList(si); + + if (si_list.First() == null) { AddError(new UndefinedNameReference(name, loc)); } int i = 0; - if (si.sym_info == null) + if (si_list.First().sym_info == null) AddError(new ExpectedType(loc)); - if (si.sym_info.semantic_node_type == semantic_node_type.wrap_def) - BasePCUReader.RestoreSymbols(si, name); + if (si_list.First().sym_info.semantic_node_type == semantic_node_type.wrap_def) + { + BasePCUReader.RestoreSymbols(si_list, name); + } while (i < expected_node_types.Length) { - if (si.sym_info.general_node_type == expected_node_types[i]) + if (si_list.First().sym_info.general_node_type == expected_node_types[i]) { break; } @@ -784,14 +773,14 @@ namespace PascalABCCompiler.TreeConverter if (expected_node_types.Length == 1) if (expected_node_types[0] == general_node_type.type_node) AddError(new ExpectedType(loc)); - AddError(new ExpectedAnotherKindOfObject(expected_node_types, si.sym_info.general_node_type, - convertion_data_and_alghoritms.get_location(si.sym_info), loc)); + AddError(new ExpectedAnotherKindOfObject(expected_node_types, si_list.First().sym_info.general_node_type, + convertion_data_and_alghoritms.get_location(si_list.First().sym_info), loc)); } //if (SystemUnitAssigned && SystemLibrary.SystemLibInitializer.ShortStringType.Found && SystemLibrary.SystemLibInitializer.ShortStringType.Equal(si)) // return context.create_short_string_type(SemanticRules.ShortStringDefaultLength, loc); - return si.sym_info; + return si_list.First().sym_info; } //ssyy @@ -806,15 +795,15 @@ namespace PascalABCCompiler.TreeConverter di = check_name_node_type(names.names[0].name, loc1, general_node_type.namespace_node, general_node_type.unit_node, general_node_type.type_node); for (int i = 1; i < names.names.Count - 1; i++) { - SymbolInfo si = null; + SymbolInfoList si = null; if (di is namespace_node) - si = (di as namespace_node).find(names.names[i].name); + si = new SymbolInfoList((di as namespace_node).find(names.names[i].name)); else si = (di as type_node).find_in_type(names.names[i].name); loc1 = syntax_tree_visitor.get_location(names.names[i]); if (loc1 == null) loc1 = loc; - di = check_name_node_type(names.names[i].name, si, loc1, general_node_type.namespace_node, general_node_type.type_node); + di = check_name_node_type(names.names[i].name, si.ToSymbolInfo(), loc1, general_node_type.namespace_node, general_node_type.type_node); } return di; } @@ -836,7 +825,10 @@ namespace PascalABCCompiler.TreeConverter } else if (di is type_node) { - return (di as type_node).find_in_type(names.names[num].name); + var temp = (di as type_node).find_in_type(names.names[num].name); + if (temp != null) + return temp.ToSymbolInfo(); + return null; } else { @@ -944,32 +936,32 @@ namespace PascalABCCompiler.TreeConverter if (_explicit_interface_type != null) { function_node fn = top_function; - SymbolInfo si = _ctn.Scope.FindOnlyInType(fn.name, null); + SymbolInfoList si = _ctn.Scope.FindOnlyInType(fn.name, null); function_node compar; - while (si != null) - { - compar = si.sym_info as function_node; - if (fn != compar && convertion_data_and_alghoritms.function_eq_params(fn, compar)) - //if (fn is common_namespace_function_node && compar is common_namespace_function_node && (fn as common_namespace_function_node).comprehensive_namespace == (compar as common_namespace_function_node).comprehensive_namespace) + if(si != null) + foreach(var si_unit in si.InfoUnitList) + { + compar = si_unit.sym_info as function_node; + if (fn != compar && convertion_data_and_alghoritms.function_eq_params(fn, compar)) + //if (fn is common_namespace_function_node && compar is common_namespace_function_node && (fn as common_namespace_function_node).comprehensive_namespace == (compar as common_namespace_function_node).comprehensive_namespace) - AddError(new FunctionDuplicateDefinition(compar, fn)); - si = si.Next; - } + AddError(new FunctionDuplicateDefinition(compar, fn)); + } } else if (_compiled_tn != null) { function_node fn = top_function; - SymbolInfo si = _compiled_tn.scope.FindOnlyInType(fn.name, null); + SymbolInfoList si = _compiled_tn.scope.FindOnlyInType(fn.name, null); function_node compar; - while (si != null) - { - compar = si.sym_info as function_node; - if (fn!=compar && convertion_data_and_alghoritms.function_eq_params(fn, compar,false)) - //if (fn is common_namespace_function_node && compar is common_namespace_function_node && (fn as common_namespace_function_node).comprehensive_namespace == (compar as common_namespace_function_node).comprehensive_namespace) + if(si != null) + foreach(var si_unit in si.InfoUnitList) + { + compar = si_unit.sym_info as function_node; + if (fn!=compar && convertion_data_and_alghoritms.function_eq_params(fn, compar,false)) + //if (fn is common_namespace_function_node && compar is common_namespace_function_node && (fn as common_namespace_function_node).comprehensive_namespace == (compar as common_namespace_function_node).comprehensive_namespace) - AddError(new FunctionDuplicateDefinition(compar, fn)); - si = si.Next; - } + AddError(new FunctionDuplicateDefinition(compar, fn)); + } } if (_explicit_interface_type == null) _ctn = null; @@ -981,8 +973,8 @@ namespace PascalABCCompiler.TreeConverter private void add_notequal_operator_if_need() { - SymbolInfo si = _ctn.find_in_type(compiler_string_consts.noteq_name); - if (si.sym_info is common_method_node) + SymbolInfoList si = _ctn.find_in_type(compiler_string_consts.noteq_name); + if (si.First().sym_info is common_method_node) return; SymbolTable.ClassMethodScope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_cmn.scope,_ctn.scope); common_method_node cmn = new common_method_node(compiler_string_consts.GetNETOperName(compiler_string_consts.noteq_name),SystemLibrary.SystemLibrary.bool_type,null,_ctn, @@ -1008,13 +1000,13 @@ namespace PascalABCCompiler.TreeConverter cmn.function_code = body; cmn.is_overload = true; _ctn.methods.AddElement(cmn); - _ctn.Scope.AddSymbol(compiler_string_consts.noteq_name,new SymbolInfo(cmn)); + _ctn.Scope.AddSymbol(compiler_string_consts.noteq_name,new SymbolInfoUnit(cmn)); } private void add_equal_operator_if_need() { - SymbolInfo si = _ctn.find_in_type(compiler_string_consts.eq_name); - if (si.sym_info is common_method_node) + SymbolInfoList si = _ctn.find_in_type(compiler_string_consts.eq_name); + if (si.First().sym_info is common_method_node) return; SymbolTable.ClassMethodScope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_cmn.scope,_ctn.scope); common_method_node cmn = new common_method_node(compiler_string_consts.GetNETOperName(compiler_string_consts.eq_name),SystemLibrary.SystemLibrary.bool_type,null,_ctn, @@ -1040,7 +1032,7 @@ namespace PascalABCCompiler.TreeConverter cmn.function_code = body; cmn.is_overload = true; _ctn.methods.AddElement(cmn); - _ctn.Scope.AddSymbol(compiler_string_consts.eq_name,new SymbolInfo(cmn)); + _ctn.Scope.AddSymbol(compiler_string_consts.eq_name,new SymbolInfoUnit(cmn)); } public void leave_record() @@ -1066,7 +1058,7 @@ namespace PascalABCCompiler.TreeConverter public SymbolInfo create_special_names() { SymbolInfo si= new SymbolInfo(top_function.return_variable); - top_function.scope.AddSymbol(compiler_string_consts.result_variable_name, si); + top_function.scope.AddSymbol(compiler_string_consts.result_variable_name, new SymbolInfoUnit(si)); return si; } @@ -1140,7 +1132,7 @@ namespace PascalABCCompiler.TreeConverter _last_created_function = new SymbolInfo(cmmn); if (add_symbol_info) - _ctn.Scope.AddSymbol(name, _last_created_function); + _ctn.Scope.AddSymbol(name, new SymbolInfoUnit(_last_created_function)); _ctn.methods.AddElement(cmmn); cfn = cmmn; @@ -1153,7 +1145,7 @@ namespace PascalABCCompiler.TreeConverter _cmn.functions.AddElement(cnfnn); _last_created_function = new SymbolInfo(cnfnn); if (add_symbol_info) - _cmn.scope.AddSymbol(name, _last_created_function); + _cmn.scope.AddSymbol(name, new SymbolInfoUnit(_last_created_function)); cfn = cnfnn; } @@ -1185,7 +1177,7 @@ namespace PascalABCCompiler.TreeConverter top_func.functions_nodes_list.AddElement(ciffn); _last_created_function = new SymbolInfo(ciffn); if (add_symbol_info) - top_func.scope.AddSymbol(name, _last_created_function); + top_func.scope.AddSymbol(name, new SymbolInfoUnit(_last_created_function)); cfn=ciffn; break; } @@ -1201,7 +1193,7 @@ namespace PascalABCCompiler.TreeConverter _last_created_function = new SymbolInfo(cmmn); if (add_symbol_info) - _ctn.Scope.AddSymbol(name, _last_created_function); + _ctn.Scope.AddSymbol(name, new SymbolInfoUnit(_last_created_function)); _ctn.methods.AddElement(cmmn); cfn = cmmn; @@ -1216,7 +1208,7 @@ namespace PascalABCCompiler.TreeConverter cnfnn.ConnectedToType = _ctn; _last_created_function = new SymbolInfo(cnfnn); if (add_symbol_info) - _ctn.scope.AddSymbol(name, _last_created_function); + _ctn.scope.AddSymbol(name, new SymbolInfoUnit(_last_created_function)); cfn = cnfnn; } break; @@ -1232,8 +1224,8 @@ namespace PascalABCCompiler.TreeConverter cnfnn.ConnectedToType = _compiled_tn; _last_created_function = new SymbolInfo(cnfnn); if (add_symbol_info) - _compiled_tn.scope.AddSymbol(name, _last_created_function); - SymbolInfo sss = _compiled_tn.find_in_type("Hello"); + _compiled_tn.scope.AddSymbol(name, new SymbolInfoUnit(_last_created_function)); + SymbolInfoList sss = _compiled_tn.find_in_type("Hello"); cfn = cnfnn; //if(_compiled_tn.compiled_type.IsPrimitive) // syntax_tree_visitor.WarningsList.Add(new PascalABCCompiler.Errors.CompilerWarning @@ -1247,7 +1239,7 @@ namespace PascalABCCompiler.TreeConverter _cmn.functions.AddElement(cnfnn); _last_created_function=new SymbolInfo(cnfnn); if (add_symbol_info) - _cmn.scope.AddSymbol(name,_last_created_function); + _cmn.scope.AddSymbol(name,new SymbolInfoUnit(_last_created_function)); cfn=cnfnn; break; } @@ -1290,7 +1282,7 @@ namespace PascalABCCompiler.TreeConverter tctn.Merge(partial_class); } set_field_access_level(SemanticTree.field_access_level.fal_public); - _cmn.scope.AddSymbol(name,new SymbolInfo(tctn)); + _cmn.scope.AddSymbol(name,new SymbolInfoUnit(tctn)); tctn.IsInterface = type_is_interface; //_cmn.types.AddElement(tctn); @@ -1308,7 +1300,7 @@ namespace PascalABCCompiler.TreeConverter SymbolTable.ClassScope scope = convertion_data_and_alghoritms.symbol_table.CreateClassScope(_cmn.scope, null); common_type_node tctn = new common_type_node(name, SemanticTree.type_access_level.tal_internal, _cmn, scope, def_loc); - _cmn.scope.AddSymbol(name, new SymbolInfo(tctn)); + _cmn.scope.AddSymbol(name, new SymbolInfoUnit(tctn)); tctn.IsInterface = false; _cmn.types.AddElement(tctn); _ctn = tctn; @@ -1345,7 +1337,7 @@ namespace PascalABCCompiler.TreeConverter common_type_node tctn = new common_type_node(name, SemanticTree.type_access_level.tal_public, _cmn, scope, def_loc); set_field_access_level(SemanticTree.field_access_level.fal_public); - _cmn.scope.AddSymbol(name, new SymbolInfo(tctn)); + _cmn.scope.AddSymbol(name, new SymbolInfoUnit(tctn)); tctn.type_special_kind = SemanticTree.type_special_kind.typed_file; tctn.element_type = elem_type; tctn.internal_is_value = base_type.is_value; @@ -1360,36 +1352,59 @@ namespace PascalABCCompiler.TreeConverter public common_type_node create_set_type(type_node elem_type, location def_loc) { + //if (elem_type == PascalABCCompiler.SystemLibrary.SystemLibrary.byte_type) + // elem_type = PascalABCCompiler.SystemLibrary.SystemLibrary.integer_type; if (TypedSets.ContainsKey(elem_type)) return TypedSets[elem_type]; string name = compiler_string_consts.GetSetTypeName(elem_type.name); + /*common_type_node sctn = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as common_type_node; + sctn.type_special_kind = SemanticTree.type_special_kind.set_type; + if (sctn.scope.Find(compiler_string_consts.assign_name) == null) + sctn.scope.AddSymbol(compiler_string_consts.assign_name, sctn.scope.Find(compiler_string_consts.AssignSetName)); + return sctn;*/ type_node base_type = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node; //check_name_free(name, def_loc); SymbolTable.ClassScope scope = convertion_data_and_alghoritms.symbol_table.CreateClassScope(_cmn.scope, null); common_type_node tctn = new common_type_node(name, SemanticTree.type_access_level.tal_public, _cmn, scope, def_loc); set_field_access_level(SemanticTree.field_access_level.fal_public); - _cmn.scope.AddSymbol(name, new SymbolInfo(tctn)); + _cmn.scope.AddSymbol(name, new SymbolInfoUnit(tctn)); tctn.type_special_kind = SemanticTree.type_special_kind.set_type; + //tctn.add_intersection_node(type_intersection_node); tctn.element_type = elem_type; tctn.internal_is_value = base_type.is_value; tctn.is_class = base_type.is_class; tctn.SetBaseType(base_type); tctn.add_name(compiler_string_consts.assign_name,new SymbolInfo(SystemLibrary.SystemLibrary.make_assign_operator(tctn,PascalABCCompiler.SemanticTree.basic_function_type.objassign))); + //tctn.add_name(compiler_string_consts.assign_name,SystemLibrary.SystemLibInitializer.AssignSetProcedure.SymbolInfo); + /*foreach (type_node tn in TypedSets.Keys) + { + type_compare tc = type_table.compare_types(elem_type,tn); + if (tc != type_compare.non_comparable_type) + { + tctn.add_name(compiler_string_consts.assign_name,new SymbolInfo(SystemLibrary.SystemLibrary.make_assign_operator(TypedSets[tn],PascalABCCompiler.SemanticTree.basic_function_type.objassign))); + TypedSets[tn].add_name(compiler_string_consts.assign_name,new SymbolInfo(SystemLibrary.SystemLibrary.make_assign_operator(tctn,PascalABCCompiler.SemanticTree.basic_function_type.objassign))); + } + }*/ tctn.ImplementingInterfaces.Add(compiled_type_node.get_type_node(NetHelper.NetHelper.FindType(compiler_string_consts.IEnumerableInterfaceName))); - tctn.scope.AddSymbol(compiler_string_consts.plus_name, SystemLibrary.SystemLibInitializer.SetUnionProcedure.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.mul_name, SystemLibrary.SystemLibInitializer.SetIntersectProcedure.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.in_name, SystemLibrary.SystemLibInitializer.InSetProcedure.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.minus_name, SystemLibrary.SystemLibInitializer.SetSubtractProcedure.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.eq_name, SystemLibrary.SystemLibInitializer.CompareSetEquals.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.noteq_name, SystemLibrary.SystemLibInitializer.CompareSetInEquals.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.sm_name, SystemLibrary.SystemLibInitializer.CompareSetLess.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.smeq_name, SystemLibrary.SystemLibInitializer.CompareSetLessEqual.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.gr_name, SystemLibrary.SystemLibInitializer.CompareSetGreater.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.greq_name, SystemLibrary.SystemLibInitializer.CompareSetGreaterEqual.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.plusassign_name,new SymbolInfo(make_set_plus_assign(tctn))); - tctn.scope.AddSymbol(compiler_string_consts.minusassign_name,new SymbolInfo(make_set_minus_assign(tctn))); - tctn.scope.AddSymbol(compiler_string_consts.multassign_name,new SymbolInfo(make_set_mult_assign(tctn))); + //tctn.scope.AddSymbol(compiler_string_consts.and_name,SystemLibrary.) + //_ctn = tctn; + //if (tctn.scope.Find(compiler_string_consts.assign_name) != tctn.scope.Find(compiler_string_consts.AssignSetName)) + // tctn.scope.AddSymbol(compiler_string_consts.assign_name, tctn.scope.Find(compiler_string_consts.AssignSetName)); + tctn.scope.AddSymbol(compiler_string_consts.plus_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.SetUnionProcedure.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.mul_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.SetIntersectProcedure.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.in_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.InSetProcedure.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.minus_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.SetSubtractProcedure.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.eq_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetEquals.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.noteq_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetInEquals.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.sm_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetLess.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.smeq_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetLessEqual.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.gr_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetGreater.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.greq_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetGreaterEqual.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.plusassign_name,new SymbolInfoUnit(make_set_plus_assign(tctn))); + tctn.scope.AddSymbol(compiler_string_consts.minusassign_name,new SymbolInfoUnit(make_set_minus_assign(tctn))); + tctn.scope.AddSymbol(compiler_string_consts.multassign_name,new SymbolInfoUnit(make_set_mult_assign(tctn))); + //SystemLibrary.SystemLibrary.init_reference_type(tctn); converted_namespace.types.AddElement(tctn); TypedSets.Add(elem_type, tctn); return tctn; @@ -1456,7 +1471,7 @@ namespace PascalABCCompiler.TreeConverter scope, def_loc, length); tctn.add_name(compiler_string_consts.assign_name,new SymbolInfo(SystemLibrary.SystemLibrary.make_assign_operator(tctn,PascalABCCompiler.SemanticTree.basic_function_type.objassign))); tctn.add_name(compiler_string_consts.plus_name,new SymbolInfo(SystemLibrary.SystemLibrary.string_add)); - tctn.scope.AddSymbol(compiler_string_consts.plusassign_name,new SymbolInfo(make_short_string_plus_assign(tctn))); + tctn.scope.AddSymbol(compiler_string_consts.plusassign_name,new SymbolInfoUnit(make_short_string_plus_assign(tctn))); type_intersection_node inter = new type_intersection_node(type_compare.greater_type); inter.another_to_this = new type_conversion(SystemLibrary.SystemLibrary.char_to_string); tctn.add_intersection_node(SystemLibrary.SystemLibrary.char_type, inter,false); @@ -1493,7 +1508,7 @@ namespace PascalABCCompiler.TreeConverter generic_indicator gi = new generic_indicator(generic); int pos = generic.name.LastIndexOf(compiler_string_consts.generic_params_infix); string name = generic.name.Substring(0, pos); - _cmn.scope.AddSymbol(name, new SymbolInfo(gi, access_level.al_public, symbol_kind.sk_none)); + _cmn.scope.AddSymbol(name, new SymbolInfoUnit(gi, access_level.al_public, symbol_kind.sk_none)); } public void save_var_definitions() @@ -1551,7 +1566,7 @@ namespace PascalABCCompiler.TreeConverter { namespace_variable nsv=new namespace_variable(name,null,_cmn,loc); //_cmn.scope.AddSymbol(name,new SymbolInfo(nsv)); - CurrentScope.AddSymbol(name, new SymbolInfo(nsv)); + CurrentScope.AddSymbol(name, new SymbolInfoUnit(nsv)); _cmn.variables.AddElement(nsv); var_defs.Add(nsv); return nsv; @@ -1591,7 +1606,7 @@ namespace PascalABCCompiler.TreeConverter cne.field = nv; this.converted_namespace.events.AddElement(cne); this.converted_namespace.variables.AddElement(nv); - CurrentScope.AddSymbol(name, new SymbolInfo(cne)); + CurrentScope.AddSymbol(name, new SymbolInfoUnit(cne)); return cne; } @@ -1615,7 +1630,7 @@ namespace PascalABCCompiler.TreeConverter add_meth.function_code = new statements_list(null); (add_meth.function_code as statements_list).statements.AddElement(en); } - converted_type.scope.AddSymbol(add_meth.name, new SymbolInfo(add_meth)); + converted_type.scope.AddSymbol(add_meth.name, new SymbolInfoUnit(add_meth)); //remove common_method_node remove_meth = new common_method_node(compiler_string_consts.GetRemoveHandler(name), null, this.converted_type, ps, SemanticTree.field_access_level.fal_public, null); @@ -1629,7 +1644,7 @@ namespace PascalABCCompiler.TreeConverter remove_meth.function_code = new statements_list(null); (remove_meth.function_code as statements_list).statements.AddElement(en); } - converted_type.scope.AddSymbol(remove_meth.name, new SymbolInfo(remove_meth)); + converted_type.scope.AddSymbol(remove_meth.name, new SymbolInfoUnit(remove_meth)); this.converted_type.methods.AddElement(add_meth); this.converted_type.methods.AddElement(remove_meth); ce.set_add_method(add_meth); @@ -1638,7 +1653,7 @@ namespace PascalABCCompiler.TreeConverter this.converted_type.events.AddElement(ce); if (!is_abstract) this.converted_type.fields.AddElement(cf); - converted_type.scope.AddSymbol(name, new SymbolInfo(ce)); + converted_type.scope.AddSymbol(name, new SymbolInfoUnit(ce)); return ce; } @@ -1648,7 +1663,7 @@ namespace PascalABCCompiler.TreeConverter { class_field cf = new class_field(name, tn, _ctn, ps, _fal, loc); //_ctn.Scope.AddSymbol(name,new SymbolInfo(cf)); - CurrentScope.AddSymbol(name, new SymbolInfo(cf)); + CurrentScope.AddSymbol(name, new SymbolInfoUnit(cf)); _ctn.fields.AddElement(cf); return cf; } @@ -1680,7 +1695,7 @@ namespace PascalABCCompiler.TreeConverter } } local_block_variable lv = new local_block_variable(name, tn, CurrentStatementList, loc); - CurrentScope.AddSymbol(name, new SymbolInfo(lv)); + CurrentScope.AddSymbol(name, new SymbolInfoUnit(lv)); lv.block.local_variables.Add(lv); if (tn == null) //Тип еще неизвестен, будем закрывать. var_defs.Add(lv); @@ -1694,7 +1709,7 @@ namespace PascalABCCompiler.TreeConverter local_variable lv=new local_variable(name,tn,top_func,loc); vdn=lv; top_func.var_definition_nodes_list.AddElement(lv); - CurrentScope.AddSymbol(name, new SymbolInfo(lv)); + CurrentScope.AddSymbol(name, new SymbolInfoUnit(lv)); //top_func.scope.AddSymbol(name,new SymbolInfo(lv)); break; } @@ -1704,7 +1719,7 @@ namespace PascalABCCompiler.TreeConverter class_field cf = new class_field(name,tn, _ctn, ps,_fal,loc); vdn=cf; //_ctn.Scope.AddSymbol(name,new SymbolInfo(cf)); - CurrentScope.AddSymbol(name, new SymbolInfo(cf)); + CurrentScope.AddSymbol(name, new SymbolInfoUnit(cf)); _ctn.fields.AddElement(cf); break; } @@ -1713,7 +1728,7 @@ namespace PascalABCCompiler.TreeConverter namespace_variable nsv=new namespace_variable(name,tn,_cmn,loc); vdn=nsv; //_cmn.scope.AddSymbol(name,new SymbolInfo(nsv)); - CurrentScope.AddSymbol(name, new SymbolInfo(nsv)); + CurrentScope.AddSymbol(name, new SymbolInfoUnit(nsv)); _cmn.variables.AddElement(nsv); break; } @@ -1734,12 +1749,12 @@ namespace PascalABCCompiler.TreeConverter { common_function_node top_func = _func_stack.top(); top_func.label_nodes_list.Add(lab); - top_func.scope.AddSymbol(name, new SymbolInfo(lab)); + top_func.scope.AddSymbol(name, new SymbolInfoUnit(lab)); break; } case block_type.namespace_block: { - _cmn.scope.AddSymbol(name, new SymbolInfo(lab)); + _cmn.scope.AddSymbol(name, new SymbolInfoUnit(lab)); _cmn.labels.Add(lab); break; } @@ -1806,7 +1821,7 @@ namespace PascalABCCompiler.TreeConverter public string get_delegate_type_name() { - return (compiler_string_consts.delegate_type_name_template + _num_for_delegates++); + return (compiler_string_consts.delegate_type_name_template+get_and_postinc_num_of_for_cycles()); } public var_definition_node create_for_temp_variable(type_node type,location loc) @@ -1862,7 +1877,7 @@ namespace PascalABCCompiler.TreeConverter common_function_node top_func = _func_stack.top(); common_parameter cp=new common_parameter(name,pt,top_func,cpt,loc); top_func.parameters.AddElement(cp); - top_func.scope.AddSymbol(name,new SymbolInfo(cp)); + top_func.scope.AddSymbol(name,new SymbolInfoUnit(cp)); var_defs.Add(cp); return cp; } @@ -1878,7 +1893,7 @@ namespace PascalABCCompiler.TreeConverter { common_function_node top_func = _func_stack.top(); function_constant_definition fcd = new function_constant_definition(name, loc, top_func); - top_func.scope.AddSymbol(name,new SymbolInfo(fcd)); + top_func.scope.AddSymbol(name,new SymbolInfoUnit(fcd)); top_func.constants.AddElement(fcd); cdn = fcd; break; @@ -1886,7 +1901,7 @@ namespace PascalABCCompiler.TreeConverter case block_type.type_block: { class_constant_definition ccd = new class_constant_definition(name, loc, _ctn, _fal); - _ctn.Scope.AddSymbol(name,new SymbolInfo(ccd)); + _ctn.Scope.AddSymbol(name,new SymbolInfoUnit(ccd)); _ctn.const_defs.AddElement(ccd); cdn = ccd; break; @@ -1894,7 +1909,7 @@ namespace PascalABCCompiler.TreeConverter case block_type.namespace_block: { namespace_constant_definition ncd = new namespace_constant_definition(name, loc, _cmn); - _cmn.scope.AddSymbol(name,new SymbolInfo(ncd)); + _cmn.scope.AddSymbol(name,new SymbolInfoUnit(ncd)); _cmn.constants.AddElement(ncd); cdn = ncd; break; @@ -2081,7 +2096,7 @@ namespace PascalABCCompiler.TreeConverter public SymbolInfo find(string name) { SymbolTable.Scope curscope = CurrentScope; - SymbolInfo si = curscope.Find(name, curscope); + SymbolInfoList si = curscope.Find(name, curscope); if (si == null && _compiled_tn != null && curscope.TopScope != null) { SymbolTable.Scope tmp = curscope.TopScope; @@ -2093,15 +2108,23 @@ namespace PascalABCCompiler.TreeConverter } if (_ctn != null && _ctn.base_generic_instance != null) { - return _ctn.base_generic_instance.ConvertSymbolInfo(si); + SymbolInfo temp = null; + if (si != null) + temp = si.ToSymbolInfo(); + return _ctn.base_generic_instance.ConvertSymbolInfo(temp); } - return si; + + if (si != null) + return si.ToSymbolInfo(); + return null; } public SymbolInfo find_only_in_namespace(string name) { - SymbolInfo si = CurrentScope.FindOnlyInScope(name); - return si; + SymbolInfoList si = CurrentScope.FindOnlyInScope(name); + if (si != null) + return si.ToSymbolInfo(); + return null; } public void leave_interface_part() @@ -2254,7 +2277,7 @@ namespace PascalABCCompiler.TreeConverter } if (stl.statements.Count == 0) return; string stat_ctor_name = compiler_string_consts.static_ctor_prefix + compiler_string_consts.default_constructor_name; - SymbolInfo si = generic_def.scope.FindOnlyInScope(stat_ctor_name); + SymbolInfoList si = generic_def.scope.FindOnlyInScope(stat_ctor_name); common_method_node stat_ctor; if (si == null) { @@ -2266,7 +2289,7 @@ namespace PascalABCCompiler.TreeConverter } else { - stat_ctor = si.sym_info as common_method_node; + stat_ctor = si.First().sym_info as common_method_node; } if (stat_ctor.function_code != null) { @@ -2522,13 +2545,13 @@ namespace PascalABCCompiler.TreeConverter private void check_implement_abstract_function(common_type_node cnode, function_node meth, type_node interf) { - SymbolInfo si = cnode.find_in_type(meth.name, cnode.Scope); + SymbolInfoList si = cnode.find_in_type2(meth.name, cnode.Scope); function_node fn = null; - while (si != null) + foreach(var si_unit in si.InfoUnitList) { - if (si.sym_info.general_node_type == general_node_type.function_node) + if (si_unit.sym_info.general_node_type == general_node_type.function_node) { - fn = si.sym_info as function_node; + fn = si_unit.sym_info as function_node; //Сверяем параметры и тип возвращаемого значения if (convertion_data_and_alghoritms.function_eq_params_and_result(meth, fn)) { @@ -2538,7 +2561,6 @@ namespace PascalABCCompiler.TreeConverter } } //Переходим к следующей функции-кандидату - si = si.Next; } if (si == null) { @@ -2549,8 +2571,8 @@ namespace PascalABCCompiler.TreeConverter } //Теперь проверяем на public и non-static bool bad = false; - common_method_node commn = si.sym_info as common_method_node; - compiled_function_node compn = si.sym_info as compiled_function_node; + common_method_node commn = si.First().sym_info as common_method_node; + compiled_function_node compn = si.First().sym_info as compiled_function_node; SemanticTree.polymorphic_state pstate = SemanticTree.polymorphic_state.ps_static; //Проверка пройдена! @@ -2893,30 +2915,30 @@ namespace PascalABCCompiler.TreeConverter /// /// Проверяемая функция /// + //DeleteSymbolInfo private bool check_unique_or_predefined(common_function_node fn) { - SymbolInfo si=null; - bool in_unit = false; + SymbolInfoList si_list = null; + bool in_unit = false; if (_func_stack.size<=1) { if (_explicit_interface_type != null) { - si = _explicit_interface_type.find_in_type(fn.name); + si_list = _explicit_interface_type.find_in_type(fn.name); } else if (_ctn!=null) { - si=_ctn.Scope.FindOnlyInScope(fn.name); + si_list = _ctn.Scope.FindOnlyInScope(fn.name); if (_ctn is compiled_generic_instance_type_node && fn is common_namespace_function_node) { - si = (_ctn as compiled_generic_instance_type_node).compiled_original_generic.find_in_type(fn.name); - SymbolInfo si_tmp = si; - while (si_tmp != null) + si_list = (_ctn as compiled_generic_instance_type_node).compiled_original_generic.find_in_type(fn.name); + foreach(var tmp_si in si_list.InfoUnitList) { - if (si_tmp.sym_info.general_node_type != general_node_type.function_node) + if (tmp_si.sym_info.general_node_type != general_node_type.function_node) { - TreeRealization.BasePCUReader.RestoreSymbols(si_tmp, fn.name); + TreeRealization.BasePCUReader.RestoreSymbols(si_list, fn.name); } - common_namespace_function_node cnfn = si_tmp.sym_info as common_namespace_function_node; + common_namespace_function_node cnfn = tmp_si.sym_info as common_namespace_function_node; if (cnfn != null) { if (cnfn.namespace_node == (fn as common_namespace_function_node).namespace_node) @@ -2924,309 +2946,310 @@ namespace PascalABCCompiler.TreeConverter break; } } - si_tmp = si_tmp.Next; } - si = si_tmp; } } else if (_compiled_tn != null) { - si = _compiled_tn.find_in_type(fn.name); + si_list = _compiled_tn.find_in_type(fn.name); } else { in_unit = true; - si = _cmn.scope.FindOnlyInScope(fn.name); + si_list = _cmn.scope.FindOnlyInScope(fn.name); } - } + } else { common_function_node temp=_func_stack.pop(); - si = _func_stack.top().scope.FindOnlyInScope(fn.name); + si_list = _func_stack.top().scope.FindOnlyInScope(fn.name); _func_stack.push(temp); } bool predef_find = false; - SymbolInfo tmp_si = si; int overloads = 0; - while(tmp_si!=null) - { - if (tmp_si.sym_info != fn && !(si.sym_info is basic_function_node)) - { - overloads++; - } - tmp_si = tmp_si.Next; - } - while(si!=null) - { - if (si.sym_info==fn) - { - si=si.Next; - continue; - } - if (si.sym_info.general_node_type != general_node_type.function_node) + if(si_list != null) + foreach (var tmp_si in si_list.InfoUnitList) { - TreeRealization.BasePCUReader.RestoreSymbols(si, fn.name); + if (tmp_si.sym_info != fn && !(si_list != null && si_list.First().sym_info is basic_function_node)) + overloads++; } -#if (DEBUG) - if (si.sym_info.general_node_type!=general_node_type.function_node) - { - throw new CompilerInternalError("Function name is used to define not function."); - } -#endif - if (si.sym_info is basic_function_node || si.sym_info is compiled_function_node) - { - si = si.Next; - continue; - } - //compar - найденная функция - common_function_node compar=((common_function_node)(si.sym_info)); - - //Проверяем, если мы нашли не предописание - if (compar.function_code != null || is_order_independed_method_description) - { - if (compar.is_overload == false) + if(si_list != null) + foreach(var tmp_si in si_list.InfoUnitList) + { + if (tmp_si.sym_info==fn) + continue; + if (tmp_si.sym_info.general_node_type != general_node_type.function_node) { - AddError(new FunctionMustBeWithOverloadDirective(compar, fn)); + TreeRealization.BasePCUReader.RestoreSymbols(si_list, fn.name); } - if (convertion_data_and_alghoritms.function_eq_params(fn, compar, false) && fn.is_extension_method == compar.is_extension_method) + #if (DEBUG) + if (tmp_si.sym_info.general_node_type!=general_node_type.function_node) + { + throw new CompilerInternalError("Function name is used to define not function."); + } + #endif + if (tmp_si.sym_info is basic_function_node || tmp_si.sym_info is compiled_function_node) { - if (fn.IsOperator && (fn.name == compiler_string_consts.explicit_operator_name || fn.name == compiler_string_consts.implicit_operator_name)) - { - if (convertion_data_and_alghoritms.function_eq_params_and_result(fn,compar)) - AddError(new FunctionDuplicateDefinition(compar, fn)); - } - else + continue; + } + //compar - найденная функция + common_function_node compar=((common_function_node)(tmp_si.sym_info)); + + //Проверяем, если мы нашли не предописание + if (compar.function_code != null || is_order_independed_method_description) + { + if (compar.is_overload == false) { - if (fn is common_method_node && compar is common_method_node) + AddError(new FunctionMustBeWithOverloadDirective(compar, fn)); + } + if (convertion_data_and_alghoritms.function_eq_params(fn, compar, false) && fn.is_extension_method == compar.is_extension_method) + { + if (fn.IsOperator && (fn.name == compiler_string_consts.explicit_operator_name || fn.name == compiler_string_consts.implicit_operator_name)) + { + if (convertion_data_and_alghoritms.function_eq_params_and_result(fn,compar)) + AddError(new FunctionDuplicateDefinition(compar, fn)); + } + else { - common_method_node cmn1 = fn as common_method_node; - common_method_node cmn2 = compar as common_method_node; - if (cmn1.explicit_interface == cmn2.explicit_interface) + if (fn is common_method_node && compar is common_method_node) + { + common_method_node cmn1 = fn as common_method_node; + common_method_node cmn2 = compar as common_method_node; + if (cmn1.explicit_interface == cmn2.explicit_interface) + AddError(new FunctionDuplicateDefinition(compar, fn)); + } + else + { AddError(new FunctionDuplicateDefinition(compar, fn)); - } - else - { - AddError(new FunctionDuplicateDefinition(compar, fn)); + } } } + continue; } - si = si.Next; - continue; - } - bool is_find_predefinition=false; + bool is_find_predefinition=false; - if (compar.is_overload==false || overloads == 1 && in_unit) - { - //Если нет параметров в описании тела функции - if (fn.parameters.Count==0) - { + if (compar.is_overload==false || overloads == 1 && in_unit) + { + //Если нет параметров в описании тела функции + if (fn.parameters.Count==0) + { - is_find_predefinition=true; - } - else - { - is_find_predefinition=is_predefinition(compar,fn,true); - } - } - else - { - is_find_predefinition=is_predefinition(compar,fn,false); - } + is_find_predefinition=true; + } + else + { + is_find_predefinition=is_predefinition(compar,fn,true); + } + } + else + { + is_find_predefinition=is_predefinition(compar,fn,false); + } - if (!is_find_predefinition) - { - si = si.Next; - continue; - } - else - { - predef_find = true; - foreach (common_parameter par in fn.parameters) + if (!is_find_predefinition) { - if (par.default_value != null) - { - syntax_tree_visitor.AddError(par.loc, "DEFAULT_VALUE_MUST_BE_ONLY_IN_FIRST_DECLARATION"); - } - } - } - - if (compar.function_code!=null) - { - AddError(fn.loc, "FUNCTION_{0}_ALREADY_HAVE_A_BODY", fn.name); - } - - if ((compar.polymorphic_state == PascalABCCompiler.SemanticTree.polymorphic_state.ps_static) != - (fn.polymorphic_state == PascalABCCompiler.SemanticTree.polymorphic_state.ps_static)) - { - syntax_tree_visitor.AddError(fn.loc, "CLASS_FUNCTION_ATTRIBUTE_MISMATCH"); - } - - common_method_node compiled_meth = fn as common_method_node; - - if (compiled_meth != null) - { - common_method_node finded_method = (common_method_node)compar; - if (compiled_meth.is_constructor) - { - if (finded_method.is_constructor == false) - { - AddError(finded_method.loc, "CONSTRUCTOR_MUST_BE_REALIZED_WITH_CONSTRUCTOR_KEYWORD"); - } - compiled_meth.return_value_type = finded_method.return_value_type; - convertion_data_and_alghoritms.create_function_return_variable(finded_method,null); - } - } - - if (!convertion_data_and_alghoritms.eq_type_nodes(compar.return_value_type,fn.return_value_type) && fn.return_value_type != null && !(fn.return_value_type is undefined_type)) - { - AddError(fn.loc, "FUNCTION_PREDEFINITION_AND_DEFINITION_HAVE_DIFFERENT_RESULT_TYPES"); - } - - //НУЖЕН СПИСОК ФУНКЦИЙ С ПРЕДОПРЕДЕЛЕНИЯМИ, ЧТОБЫ ОБНАРУЖИТЬ ОПИСАННЫЕ НО НЕ ОПРЕДЕЛЕННЫЕ - //Или не нужен??? - - //TODO: СИНХРОНИЗИРОВАТЬ АТТРИБУТЫ!!!!! - if (fn.is_overload) - { - compar.is_overload=true; - } - - //TODO: Внимательно проверить следующий if. - if (compar.is_overload) - { - fn.is_overload = true; - last_created_function.symbol_kind = symbol_kind.sk_overload_function; - } - - common_function_node cfn11=_func_stack.pop(); - compar.scope = cfn11.scope; - - common_method_node cmnode=compar as common_method_node; - if (cmnode != null) - { - SymbolInfo si_local = cfn11.scope.FindOnlyInScope(compiler_string_consts.self_word); - if (si_local != null) - { - si_local.sym_info = cmnode.self_variable; - } - } - - //Удаляем текущую функцию - SymbolInfo siint = null; - switch(converting_block()) - { - case block_type.function_block: - { - _func_stack.top().functions_nodes_list.remove((common_in_function_function_node)fn); - siint = _func_stack.top().scope.FindOnlyInScope(fn.name); - break; - } - case block_type.namespace_block: - { - _cmn.functions.remove((common_namespace_function_node)fn); - siint = _cmn.scope.FindOnlyInScope(fn.name); - break; - } - case block_type.type_block: - { - //TODO: Доделать описание методов класса. - _ctn.methods.remove((common_method_node)fn); - siint = _ctn.scope.FindOnlyInScope(fn.name); - break; - } - case block_type.compiled_type_block: - { - if (syntax_tree_visitor.compiled_unit.namespaces[0].functions.Contains((common_namespace_function_node)fn)) - syntax_tree_visitor.compiled_unit.namespaces[0].functions.remove((common_namespace_function_node)fn); - siint = _compiled_tn.find_in_type(fn.name); - break; - } - - default: - { - throw new CompilerInternalError("Undefined block type"); - } - } - while (siint.sym_info != fn && siint.Next != null) - { - siint = siint.Next; - } - siint.sym_info = compar; - - //Мы удалили новую функцию. Сейчас мы должны перенести параметры из новой функции в старую. - //TODO: У новой функции может вообще не быть параметров. Они все в старой. Разобраться с этим. А зачем вообще переносить параметры? - - if (compar.parameters.Count != 0) - { - if (fn.parameters.Count == 0) - { - foreach (common_parameter pr in compar.parameters) - { - compar.scope.AddSymbol(pr.name, new SymbolInfo(pr)); - } + continue; } else { - foreach (common_parameter pr in compar.parameters) + predef_find = true; + foreach (common_parameter par in fn.parameters) { - SymbolInfo par_sim_info = fn.scope.FindOnlyInScope(pr.name); - par_sim_info.sym_info = pr; + if (par.default_value != null) + { + syntax_tree_visitor.AddError(par.loc, "DEFAULT_VALUE_MUST_BE_ONLY_IN_FIRST_DECLARATION"); + } } } - } - if (fn.is_generic_function) - { - for (int i = 0; i < fn.generic_params.Count; ++i) + if (compar.function_code!=null) { - fn.generic_params[i] = compar.generic_params[i] as common_type_node; - common_type_node t_fn = fn.generic_params[i] as common_type_node; - common_type_node t_compar = compar.generic_params[i] as common_type_node; - /*t_fn.is_class = t_compar.is_class; - t_fn.internal_is_value = t_compar.internal_is_value; - t_fn.SetImplementingInterfaces(t_compar.ImplementingInterfaces); - (t_fn.Scope as SymbolTable.IInterfaceScope).TopInterfaceScopeArray = - (t_compar.Scope as SymbolTable.IInterfaceScope).TopInterfaceScopeArray; - t_fn.SetBaseType(t_compar.base_type);*/ - if (t_compar.has_default_constructor) - { - generic_parameter_eliminations.add_default_ctor(t_fn); - } - SymbolInfo par_sim_info = fn.scope.FindOnlyInScope(fn.generic_params[i].name); - par_sim_info.sym_info = fn.generic_params[i] as common_type_node; - //t_fn.generic_function_container = compar; + AddError(fn.loc, "FUNCTION_{0}_ALREADY_HAVE_A_BODY", fn.name); } - //конверитируем параметры предописания в параметры описания. - List fn_types = fn.get_generic_params_list(); - foreach (common_parameter par in compar.parameters) + + if ((compar.polymorphic_state == PascalABCCompiler.SemanticTree.polymorphic_state.ps_static) != + (fn.polymorphic_state == PascalABCCompiler.SemanticTree.polymorphic_state.ps_static)) { - par.type = generic_convertions.determine_type(par.type, fn_types, true); + syntax_tree_visitor.AddError(fn.loc, "CLASS_FUNCTION_ATTRIBUTE_MISMATCH"); } - if (compar.return_value_type != null) + + common_method_node compiled_meth = fn as common_method_node; + + if (compiled_meth != null) { - compar.return_value_type = generic_convertions.determine_type(compar.return_value_type, fn_types, true); - if (compar.return_variable != null) + common_method_node finded_method = (common_method_node)compar; + if (compiled_meth.is_constructor) { - compar.return_variable.type = compar.return_value_type; + if (finded_method.is_constructor == false) + { + AddError(compiled_meth.loc, "CONSTRUCTOR_MUST_BE_REALIZED_WITH_CONSTRUCTOR_KEYWORD"); + } + compiled_meth.return_value_type = finded_method.return_value_type; + convertion_data_and_alghoritms.create_function_return_variable(finded_method,null); } } - foreach (generic_parameter_eliminations gpe in compar.parameters_eliminations) - { - } - compar.generic_params = fn.generic_params; - foreach (common_type_node tn in compar.generic_params) - { - tn.generic_function_container = compar; - } - } + if (!convertion_data_and_alghoritms.eq_type_nodes(compar.return_value_type,fn.return_value_type) && fn.return_value_type != null && !(fn.return_value_type is undefined_type)) + { + AddError(fn.loc, "FUNCTION_PREDEFINITION_AND_DEFINITION_HAVE_DIFFERENT_RESULT_TYPES"); + } - _func_stack.push(compar); - compar.attributes.AddRange(fn.attributes); - //si.sym_info=fn; - break; - } + //НУЖЕН СПИСОК ФУНКЦИЙ С ПРЕДОПРЕДЕЛЕНИЯМИ, ЧТОБЫ ОБНАРУЖИТЬ ОПИСАННЫЕ НО НЕ ОПРЕДЕЛЕННЫЕ + //Или не нужен??? + + //TODO: СИНХРОНИЗИРОВАТЬ АТТРИБУТЫ!!!!! + if (fn.is_overload) + { + compar.is_overload=true; + } + + //TODO: Внимательно проверить следующий if. + if (compar.is_overload) + { + fn.is_overload = true; + last_created_function.symbol_kind = symbol_kind.sk_overload_function; + } + + common_function_node cfn11=_func_stack.pop(); + compar.scope = cfn11.scope; + + common_method_node cmnode=compar as common_method_node; + if (cmnode != null) + { + SymbolInfoList si_local = cfn11.scope.FindOnlyInScope(compiler_string_consts.self_word); + if (si_local != null && si_local.First() != null) + { + si_local.First().sym_info = cmnode.self_variable; + } + } + + //Удаляем текущую функцию + //Переопределить все методы для SymbolInfoList, иначе заменить siint не получится + SymbolInfoList siint_list = null; + SymbolInfo siint = null; + switch(converting_block()) + { + case block_type.function_block: + { + _func_stack.top().functions_nodes_list.remove((common_in_function_function_node)fn); + siint_list = _func_stack.top().scope.FindOnlyInScope(fn.name); + break; + } + case block_type.namespace_block: + { + _cmn.functions.remove((common_namespace_function_node)fn); + siint_list = _cmn.scope.FindOnlyInScope(fn.name); + break; + } + case block_type.type_block: + { + //TODO: Доделать описание методов класса. + _ctn.methods.remove((common_method_node)fn); + siint_list = _ctn.scope.FindOnlyInScope(fn.name); + break; + } + case block_type.compiled_type_block: + { + if (syntax_tree_visitor.compiled_unit.namespaces[0].functions.Contains((common_namespace_function_node)fn)) + syntax_tree_visitor.compiled_unit.namespaces[0].functions.remove((common_namespace_function_node)fn); + siint_list = _compiled_tn.find_in_type(fn.name); + break; + } + + default: + { + throw new CompilerInternalError("Undefined block type"); + } + } + bool compar_not_assign = true; + foreach(var siint_unit in siint_list.InfoUnitList) + { + if(siint_unit.sym_info == fn) + { + siint_unit.sym_info = compar; + compar_not_assign = false; + break; + } + } + if (compar_not_assign) + siint_list.InfoUnitList[siint_list.InfoUnitList.Count - 1].sym_info = compar; + + siint = siint_list.ToSymbolInfo(); + + //Мы удалили новую функцию. Сейчас мы должны перенести параметры из новой функции в старую. + //TODO: У новой функции может вообще не быть параметров. Они все в старой. Разобраться с этим. А зачем вообще переносить параметры? + + if (compar.parameters.Count != 0) + { + if (fn.parameters.Count == 0) + { + foreach (common_parameter pr in compar.parameters) + { + compar.scope.AddSymbol(pr.name, new SymbolInfoUnit(pr)); + } + } + else + { + foreach (common_parameter pr in compar.parameters) + { + SymbolInfo par_sim_info = fn.scope.FindOnlyInScope(pr.name).ToSymbolInfo(); + par_sim_info.sym_info = pr; + } + } + } + + if (fn.is_generic_function) + { + for (int i = 0; i < fn.generic_params.Count; ++i) + { + fn.generic_params[i] = compar.generic_params[i] as common_type_node; + common_type_node t_fn = fn.generic_params[i] as common_type_node; + common_type_node t_compar = compar.generic_params[i] as common_type_node; + /*t_fn.is_class = t_compar.is_class; + t_fn.internal_is_value = t_compar.internal_is_value; + t_fn.SetImplementingInterfaces(t_compar.ImplementingInterfaces); + (t_fn.Scope as SymbolTable.IInterfaceScope).TopInterfaceScopeArray = + (t_compar.Scope as SymbolTable.IInterfaceScope).TopInterfaceScopeArray; + t_fn.SetBaseType(t_compar.base_type);*/ + if (t_compar.has_default_constructor) + { + generic_parameter_eliminations.add_default_ctor(t_fn); + } + SymbolInfo par_sim_info = fn.scope.FindOnlyInScope(fn.generic_params[i].name).ToSymbolInfo(); + par_sim_info.sym_info = fn.generic_params[i] as common_type_node; + //t_fn.generic_function_container = compar; + } + //конверитируем параметры предописания в параметры описания. + List fn_types = fn.get_generic_params_list(); + foreach (common_parameter par in compar.parameters) + { + par.type = generic_convertions.determine_type(par.type, fn_types, true); + } + if (compar.return_value_type != null) + { + compar.return_value_type = generic_convertions.determine_type(compar.return_value_type, fn_types, true); + if (compar.return_variable != null) + { + compar.return_variable.type = compar.return_value_type; + } + } + foreach (generic_parameter_eliminations gpe in compar.parameters_eliminations) + { + + } + compar.generic_params = fn.generic_params; + foreach (common_type_node tn in compar.generic_params) + { + tn.generic_function_container = compar; + } + } + + _func_stack.push(compar); + compar.attributes.AddRange(fn.attributes); + //si_list.sym_info=fn; + break; + } if (fn is common_method_node && !predef_find && syntax_tree_visitor.current_converted_method_not_in_class_defined && _explicit_interface_type == null) { AddError(new NoMethodInClassWithThisParams(fn as common_method_node, (fn as common_method_node).cont_type, fn.loc)); @@ -3237,7 +3260,7 @@ namespace PascalABCCompiler.TreeConverter //Этот метод вызывается для предописания функции (только для предописания) private void check_function_not_exists(common_function_node fn) { - SymbolInfo si=null; + SymbolInfoList si=null; if (_func_stack.size<=1) { if (_ctn!=null) @@ -3255,42 +3278,38 @@ namespace PascalABCCompiler.TreeConverter si=_func_stack.top().scope.FindOnlyInScope(fn.name); _func_stack.push(temp); } + if(si != null) + foreach(SymbolInfoUnit si_unit in si.InfoUnitList) + { + if (si_unit.sym_info == fn || si_unit.sym_info is basic_function_node) + continue; + #if (DEBUG) + if (si_unit.sym_info.general_node_type!=general_node_type.function_node) + { + throw new CompilerInternalError("Function name is used to define not function."); + } + #endif + //compar - найденная функция - while(si!=null) - { - if (si.sym_info == fn || si.sym_info is basic_function_node) - { - si=si.Next; - continue; - } -#if (DEBUG) - if (si.sym_info.general_node_type!=general_node_type.function_node) - { - throw new CompilerInternalError("Function name is used to define not function."); - } -#endif - //compar - найденная функция + common_function_node compar=((common_function_node)(si_unit.sym_info)); - common_function_node compar=((common_function_node)(si.sym_info)); - - if (compar.is_overload==false) - { - AddError(new FunctionMustBeWithOverloadDirective(compar,fn)); - } - if (convertion_data_and_alghoritms.function_eq_params(fn,compar,false)) - { - if (fn.IsOperator && (fn.name == compiler_string_consts.explicit_operator_name || fn.name == compiler_string_consts.implicit_operator_name)) - { - if (convertion_data_and_alghoritms.function_eq_params_and_result(fn,compar)) - AddError(new FunctionDuplicateDefinition(compar, fn)); - } - else - { - AddError(new FunctionDuplicateDefinition(compar,fn)); - } - } - si = si.Next; - } + if (compar.is_overload==false) + { + AddError(new FunctionMustBeWithOverloadDirective(compar,fn)); + } + if (convertion_data_and_alghoritms.function_eq_params(fn,compar,false)) + { + if (fn.IsOperator && (fn.name == compiler_string_consts.explicit_operator_name || fn.name == compiler_string_consts.implicit_operator_name)) + { + if (convertion_data_and_alghoritms.function_eq_params_and_result(fn,compar)) + AddError(new FunctionDuplicateDefinition(compar, fn)); + } + else + { + AddError(new FunctionDuplicateDefinition(compar,fn)); + } + } + } } private void check_function_name(string name,location def_loc) @@ -3316,7 +3335,7 @@ namespace PascalABCCompiler.TreeConverter check_name_free(property_name,loc); common_property_node pn = new common_property_node(property_name, _ctn, loc, _fal, SemanticTree.polymorphic_state.ps_common); - _ctn.Scope.AddSymbol(property_name,new SymbolInfo(pn)); + _ctn.Scope.AddSymbol(property_name,new SymbolInfoUnit(pn)); _ctn.properties.AddElement(pn); return pn; } @@ -3338,7 +3357,7 @@ namespace PascalABCCompiler.TreeConverter _cmn.runtime_types.AddElement(comp_tn); } } - CurrentScope.AddSymbol(name, new SymbolInfo(tn)); + CurrentScope.AddSymbol(name, new SymbolInfoUnit(tn)); if (tn is ref_type_node && converting_block() == block_type.namespace_block) converted_namespace.ref_types.Add(tn as ref_type_node); @@ -3433,25 +3452,25 @@ namespace PascalABCCompiler.TreeConverter { return null; } - SymbolInfo si = base_class.find_in_type(cmn.name); + SymbolInfoList si = base_class.find_in_type(cmn.name); function_node fn = null; - while (si != null) - { - if (si.sym_info.general_node_type != general_node_type.function_node) + if(si != null) + foreach(SymbolInfoUnit si_unit in si.InfoUnitList) { - return null; + if (si_unit.sym_info.general_node_type != general_node_type.function_node) + { + return null; + } + fn = si_unit.sym_info as function_node; + //(ssyy) Сверяем как параметры функций, так и типы возвращаемых значений + if (cmn != fn && convertion_data_and_alghoritms.function_eq_params_and_result(cmn, fn)) + { + break; + } } - fn = si.sym_info as function_node; - //(ssyy) Сверяем как параметры функций, так и типы возвращаемых значений - if (cmn != fn && convertion_data_and_alghoritms.function_eq_params_and_result(cmn, fn)) - { - break; - } - si = si.Next; - } if (si == null) { - return null; + return null; //Никогда не зайдёт } compiled_function_node cfn_sec = fn as compiled_function_node; diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index 18bedccf4..d1d6abb1b 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -38,10 +38,7 @@ namespace PascalABCCompiler.TreeConverter } }*/ - public partial class syntax_tree_visitor : SyntaxTree.WalkingVisitorNew // SSM 02.01.17 менять на визитор с другим порядком обхода можно, но бессмысленно - // Порядок обхода не важен поскольку все узлы visit переопределяются - // SSM 02.01.17 Использование ReplaceStatement из BaseChangeVisitor плохо изучено - что-то не работает - // Поэтому используется явный Parent и ReplaceStatement из узла statement_list + public class syntax_tree_visitor : SyntaxTree.WalkingVisitorNew { public convertion_data_and_alghoritms convertion_data_and_alghoritms; @@ -168,13 +165,11 @@ namespace PascalABCCompiler.TreeConverter init_properties); SystemLibrary.SystemLibrary.system_unit = _system_unit; generic_convertions.reset_generics(); - generic_convertions.visitor = this; _record_created = false; RefTypesForCheckPointersTypeForDotNetFramework.Clear(); reset_for_interface(); _is_interface_part = false; - with_class_name = false; - disable_order_independ = false; + with_class_name=false; generic_param_abilities.Clear(); current_converted_method_not_in_class_defined = false; assign_is_converting = false; @@ -504,24 +499,24 @@ namespace PascalABCCompiler.TreeConverter return; common_type_node tctn = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as common_type_node; tctn.type_special_kind = SemanticTree.type_special_kind.base_set_type; - tctn.scope.AddSymbol(compiler_string_consts.plus_name, SystemLibrary.SystemLibInitializer.SetUnionProcedure.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.mul_name, SystemLibrary.SystemLibInitializer.SetIntersectProcedure.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.in_name, SystemLibrary.SystemLibInitializer.InSetProcedure.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.minus_name, SystemLibrary.SystemLibInitializer.SetSubtractProcedure.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.gr_name, SystemLibrary.SystemLibInitializer.CompareSetGreater.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.greq_name, SystemLibrary.SystemLibInitializer.CompareSetGreaterEqual.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.sm_name, SystemLibrary.SystemLibInitializer.CompareSetLess.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.smeq_name, SystemLibrary.SystemLibInitializer.CompareSetLessEqual.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.eq_name, SystemLibrary.SystemLibInitializer.CompareSetEquals.SymbolInfo); - tctn.scope.AddSymbol(compiler_string_consts.noteq_name, SystemLibrary.SystemLibInitializer.CompareSetInEquals.SymbolInfo); + tctn.scope.AddSymbol(compiler_string_consts.plus_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.SetUnionProcedure.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.mul_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.SetIntersectProcedure.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.in_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.InSetProcedure.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.minus_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.SetSubtractProcedure.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.gr_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetGreater.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.greq_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetGreaterEqual.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.sm_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetLess.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.smeq_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetLessEqual.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.eq_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetEquals.SymbolInfo)); + tctn.scope.AddSymbol(compiler_string_consts.noteq_name, new SymbolInfoUnit(SystemLibrary.SystemLibInitializer.CompareSetInEquals.SymbolInfo)); } private void CreateSpecialFields(common_unit_node psystem_unit) { - SymbolInfo si = psystem_unit.scope.Find(compiler_string_consts.IsConsoleApplicationVariableName); - if (si != null && si.sym_info is namespace_variable) + SymbolInfoList si = psystem_unit.scope.Find(compiler_string_consts.IsConsoleApplicationVariableName); + if (si != null && si.First().sym_info is namespace_variable) { - namespace_variable_reference nvr = new namespace_variable_reference(si.sym_info as namespace_variable, null); + namespace_variable_reference nvr = new namespace_variable_reference(si.First().sym_info as namespace_variable, null); psystem_unit.IsConsoleApplicationVariableAssignExpr = make_assign_operator(nvr, psystem_unit.IsConsoleApplicationVariableValue, null); } } @@ -772,9 +767,8 @@ namespace PascalABCCompiler.TreeConverter //try { sn = ret.visit(st); - // SSM 19/01/17 закомментировал две следующие строчки - //if (sn == null) - // sn = new empty_statement(null); + if (sn == null) + sn = new empty_statement(null); } /*catch (PascalABCCompiler.Errors.Error e) { @@ -811,17 +805,14 @@ namespace PascalABCCompiler.TreeConverter throw new CompilerInternalError("This syntax tree node can not be null."); } #endif - //if (expr.semantic_ex != null) // SSM 3.1.17 - возвращаем кешированное значение - // return expr.semantic_ex as expression_node; convertion_data_and_alghoritms.check_node_parser_error(expr); //Посмотреть, может вызвать ошибку //ssyy - motivation_keeper.reset(); // Это можно закомментировать - все тесты проходят SSM 2/1/17 + motivation_keeper.reset(); //\ssyy expression_node en = ret.visit(expr); - //expr.semantic_ex = en; // SSM 3.1.17 кешируем для последующего обращения //en.loc=get_location(expr); @@ -991,8 +982,8 @@ namespace PascalABCCompiler.TreeConverter throw new CompilerInternalError("Invalid operator name"); } //#endif - SymbolInfo si = expr.type.find(name, context.CurrentScope); - if (si == null || si.sym_info is wrapped_definition_node) + SymbolInfoList si = expr.type.find(name, context.CurrentScope); + if (si == null || si.First().sym_info is wrapped_definition_node) { AddError(new OperatorCanNotBeAppliedToThisType(name, expr)); } @@ -1000,7 +991,7 @@ namespace PascalABCCompiler.TreeConverter expressions_list pars = new expressions_list(); pars.AddElement(expr); - function_node fn = convertion_data_and_alghoritms.select_function(pars, si, loc); + function_node fn = convertion_data_and_alghoritms.select_function(pars, si.ToSymbolInfo(), loc); expr = pars[0]; if (fn == null) { @@ -1080,8 +1071,15 @@ namespace PascalABCCompiler.TreeConverter } } } + + //zdes ne vse verno. += odnostoronnjaa operacija, a += b pochemu esli tipy ne ravny, += ishetsja v tipe b??? + //TODO: Посмотреть. + //TODO: Не find а find_in_type. + //SymbolInfo si=left_type.find(name, context.CurrentScope); SymbolInfo si = left_type.find_in_type(name, left_type.Scope, no_search_in_extension_methods); + SymbolInfoList si_list = new SymbolInfoList(si); SymbolInfo added_symbols = null; + int added_symbols_ind = 0; SymbolInfo si2 = null; if (left_type != right_type && !one_way_operation(name)) { @@ -1095,55 +1093,65 @@ namespace PascalABCCompiler.TreeConverter //Возможно она занимает много времени, но, наверное, от нее нельзя отказаться. function_node_list funcs = new function_node_list(); SymbolInfo sic = si; + si_list = new SymbolInfoList(si); SymbolInfo sic_last = null; - while (sic != null) + foreach(var sic_unit in si_list.InfoUnitList) { - if (sic.sym_info.general_node_type != general_node_type.function_node) + if (sic_unit.sym_info.general_node_type != general_node_type.function_node) { - BasePCUReader.RestoreSymbols(sic, name); + BasePCUReader.RestoreSymbols(si_list, name); } #if (DEBUG) - if (sic.sym_info.general_node_type != general_node_type.function_node) + if (sic_unit.sym_info.general_node_type != general_node_type.function_node) { throw new CompilerInternalError("Expected operator."); } #endif - function_node fn = ((function_node)(sic.sym_info)); - if (convertion_data_and_alghoritms.is_exist_eq_method_in_list(fn, funcs) == null) + function_node fn = ((function_node)(sic_unit.sym_info)); + if (convertion_data_and_alghoritms.is_exist_eq_method_in_list(fn, funcs) != null) { - //break; - funcs.AddElement(fn); + break; } + funcs.AddElement(fn); + sic_last = sic; + } + si = si_list.ToSymbolInfo(); + sic = si; + while(sic != null) + { sic_last = sic; sic = sic.Next; } sic = si2; //TODO: Разобраться с зацикливанием. function_node_list fnl = new function_node_list(); - while (sic != null) + si_list = new SymbolInfoList(sic); + foreach(var sic_unit in si_list.InfoUnitList) { - if (sic.sym_info.general_node_type != general_node_type.function_node) + if (sic_unit.sym_info.general_node_type != general_node_type.function_node) { - BasePCUReader.RestoreSymbols(sic, name); + BasePCUReader.RestoreSymbols(si_list, name); } #if (DEBUG) - if (sic.sym_info.general_node_type != general_node_type.function_node) + if (sic_unit.sym_info.general_node_type != general_node_type.function_node) { throw new CompilerInternalError("Expected operator."); } #endif - fnl.AddElement(((function_node)(sic.sym_info))); - sic = sic.Next; + fnl.AddElement(((function_node)(sic_unit.sym_info))); } + sic = si_list.ToSymbolInfo(); + added_symbols = sic_last; + added_symbols_ind = si_list.InfoUnitList.Count; foreach (function_node fnode in fnl) { function_node eq_func = convertion_data_and_alghoritms.find_eq_method_in_list(fnode, funcs); if (eq_func != null) { //TODO: Проверить правильно ли это будет работать. - if (eq_func != fnode)//zachem eto nuzhno voobshe?? + if (eq_func != fnode) { basic_function_node bbfn1 = fnode as basic_function_node; basic_function_node bbfn2 = eq_func as basic_function_node; @@ -1164,8 +1172,7 @@ namespace PascalABCCompiler.TreeConverter || left.type.type_special_kind == SemanticTree.type_special_kind.base_set_type && right.type.type_special_kind == SemanticTree.type_special_kind.base_set_type || left.type == SystemLibrary.SystemLibrary.string_type && right.type.type_special_kind == SemanticTree.type_special_kind.short_string || right.type == SystemLibrary.SystemLibrary.string_type && left.type.type_special_kind == SemanticTree.type_special_kind.short_string - || left.type.type_special_kind == SemanticTree.type_special_kind.short_string && right.type.type_special_kind == SemanticTree.type_special_kind.short_string - || left.type.IsDelegate == right.type.IsDelegate) + || left.type.type_special_kind == SemanticTree.type_special_kind.short_string && right.type.type_special_kind == SemanticTree.type_special_kind.short_string) { //if (left.type.find_in_type(name) !=null) } @@ -1188,7 +1195,7 @@ namespace PascalABCCompiler.TreeConverter } //if (si == null) { - if (left_type.semantic_node_type == semantic_node_type.delegated_method && right_type.semantic_node_type == semantic_node_type.delegated_method) + if (/*si2 == null && */left_type.semantic_node_type == semantic_node_type.delegated_method && right_type.semantic_node_type == semantic_node_type.delegated_method) { SymbolInfo saved_si = si; SymbolInfo saved_si2 = si2; @@ -1196,10 +1203,18 @@ namespace PascalABCCompiler.TreeConverter AddError(new OperatorCanNotBeAppliedToThisTypes(name, left, right, loc)); base_function_call bfc = ((left as typed_expression).type as delegated_methods).proper_methods[0]; left = convertion_data_and_alghoritms.explicit_convert_type(left, CreateDelegate(bfc.simple_function_node)); - si = left.type.find_in_type(name); + var temp = left.type.find_in_type(name); + if (temp != null) + si = temp.ToSymbolInfo(); + else + si = null; bfc = ((right as typed_expression).type as delegated_methods).proper_methods[0]; right = convertion_data_and_alghoritms.explicit_convert_type(right, CreateDelegate(bfc.simple_function_node)); - si2 = right.type.find_in_type(name); + temp = right.type.find_in_type(name); + if (temp != null) + si2 = temp.ToSymbolInfo(); + else + si2 = null; if (saved_si != null) si.Next = saved_si; else @@ -1216,15 +1231,6 @@ namespace PascalABCCompiler.TreeConverter return find_operator(name, left, right, loc, false); } - } - else if (left_type.semantic_node_type == semantic_node_type.delegated_method) - { - - } - else if (si != null && left.semantic_node_type == semantic_node_type.delegated_method) - { - SymbolInfo local_si = si; - } else if (si == null) { @@ -1238,13 +1244,14 @@ namespace PascalABCCompiler.TreeConverter expressions_list pars = null; function_node fnsel = null; - SymbolInfo tmp_si = si; - while (tmp_si != null) + si_list = new SymbolInfoList(si); + foreach(SymbolInfoUnit tmp_si in si_list.InfoUnitList) { if (tmp_si.sym_info is wrapped_definition_node) - BasePCUReader.RestoreSymbols(tmp_si, name); - tmp_si = tmp_si.Next; + BasePCUReader.RestoreSymbols(si_list, name); } + si = si_list.ToSymbolInfo(); + pars = new expressions_list(); pars.AddElement(left); pars.AddElement(right); @@ -1270,7 +1277,10 @@ namespace PascalABCCompiler.TreeConverter AddError(new OperatorCanNotBeAppliedToThisTypes(name, left, right, loc)); } if (added_symbols != null) + { added_symbols.Next = null; + } + if (SystemUnitAssigned && in_check_range_region() && name == compiler_string_consts.assign_name && is_range_checkable(left.type) && is_range_checkable(right.type)) { @@ -2074,7 +2084,7 @@ namespace PascalABCCompiler.TreeConverter common_type_node ctn = tn as common_type_node; if (ctn.type_special_kind == SemanticTree.type_special_kind.array_wrapper) { - int len = ((ctn.find_in_type(compiler_string_consts.internal_array_name).sym_info as class_field).type as simple_array).length; + int len = ((ctn.find_in_type(compiler_string_consts.internal_array_name).First().sym_info as class_field).type as simple_array).length; return len*get_short_string_size(ctn.element_type); } else if (ctn.type_special_kind == SemanticTree.type_special_kind.record) @@ -2284,11 +2294,19 @@ namespace PascalABCCompiler.TreeConverter function_node fn = null; if (exl.Count > 1) { - fn = convertion_data_and_alghoritms.select_function(exl, (SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node).find_in_type(compiler_string_consts.default_constructor_name), loc); + var temp = (SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node).find_in_type(compiler_string_consts.default_constructor_name); + if(temp != null) + fn = convertion_data_and_alghoritms.select_function(exl, temp.ToSymbolInfo(), loc); + else + fn = convertion_data_and_alghoritms.select_function(exl,null, loc); } else { - fn = convertion_data_and_alghoritms.select_function(exl, (SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node).find_in_type(compiler_string_consts.default_constructor_name), loc); + var temp = (SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node).find_in_type(compiler_string_consts.default_constructor_name); + if(temp != null) + fn = convertion_data_and_alghoritms.select_function(exl, temp.ToSymbolInfo(), loc); + else + fn = convertion_data_and_alghoritms.select_function(exl, null, loc); } //expression_node expr = convertion_data_and_alghoritms.create_simple_function_call(fn, null, exl.ToArray()); expression_node expr = create_static_method_call_with_params(fn, loc, tn, false, exl); @@ -2501,8 +2519,7 @@ namespace PascalABCCompiler.TreeConverter public override void visit(SyntaxTree.block _block) { - List declarations_with_lambdas = new List(); - if (/*context.converting_block() != block_type.namespace_block && */_block.defs != null && _block.defs.defs != null) + if (context.converting_block() != block_type.namespace_block && _block.defs != null && _block.defs.defs != null) { foreach (var def in _block.defs.defs.Where(d => d is const_definition || d is consts_definitions_list || @@ -2511,26 +2528,7 @@ namespace PascalABCCompiler.TreeConverter var lambdaSearcher = new LambdaSearcher(def); if (lambdaSearcher.CheckIfContainsLambdas()) { - if (context.converting_block() != block_type.namespace_block || !(def is variable_definitions)) - AddError(new LambdasNotAllowedInDeclarationsSection(get_location(lambdaSearcher.FoundLambda))); // SSM 6.06.15 - Хочется убрать это. В разделе описаний лямбды нужны - пусть и без замыканий. Если внутри подпрограммы - не нужны, но Вы же запретили везде! - else - declarations_with_lambdas.Add(def as variable_definitions); - } - } - } - int lambda_init_index = 0; - foreach (variable_definitions vd in declarations_with_lambdas) - { - foreach (var_def_statement vds in vd.list) - { - var lambdaSearcher = new LambdaSearcher(vds); - if (lambdaSearcher.CheckIfContainsLambdas()) - { - procedure_definition func = new short_func_definition(SyntaxTreeBuilder.BuildShortFuncDefinition(new formal_parameters(), new procedure_attributes_list(), new method_name("<>lambda_initializer" + lambda_init_index), null, vds.inital_value, null)); - - vds.inital_value = new method_call(new ident("<>lambda_initializer"+lambda_init_index), new expression_list()); - _block.defs.InsertBefore(vd, func); - lambda_init_index++; + AddError(new LambdasNotAllowedInDeclarationsSection(get_location(lambdaSearcher.FoundLambda))); // SSM 6.06.15 - Хочется убрать это. В разделе описаний лямбды нужны - пусть и без замыканий. Если внутри подпрограммы - не нужны, но Вы же запретили везде! } } } @@ -3169,7 +3167,7 @@ namespace PascalABCCompiler.TreeConverter } //statement_node sn=convert_strong(_procedure_call.func_name); statement_node sn = convert_strong(mc); - //проверяем на случай вызова типа real(a) ... + //проверяем на слукчай вызова типа real(a) ... if (/*((sn is base_function_call) && (sn as base_function_call).IsExplicitConversion) || (sn is SemanticTree.IReferenceNode) || (sn is SemanticTree.IGetAddrNode) @@ -3305,8 +3303,8 @@ namespace PascalABCCompiler.TreeConverter foreach (SyntaxTree.enumerator en in _enum_type_definition.enumerators.enumerators) { SyntaxTree.ident id = (en.name as named_type_reference).FirstIdent; - var si = context.CurrentScope.Find(id.name); - if ((si==null) || !(si.sym_info is type_node)) + SymbolInfoList si = context.CurrentScope.Find(id.name); + if ((si==null) || !(si.First().sym_info is type_node)) { is_enum = true; break; @@ -3549,8 +3547,8 @@ namespace PascalABCCompiler.TreeConverter List types = new List(); if (((_class_definition.attribute & PascalABCCompiler.SyntaxTree.class_attribute.Auto) == class_attribute.Auto)) { - /*if (_class_definition.class_parents!=null) - AddError(new AutoClassMustNotHaveParents(get_location(_class_definition)));*/ + if (_class_definition.class_parents!=null) + AddError(new AutoClassMustNotHaveParents(get_location(_class_definition))); // добавление членов автоклассов. Не забыть сделать, что от автоклассов нельзя наследовать SyntaxTreeBuilder.AddMembersForAutoClass(_class_definition,ref names,ref types); for (var i = 0; i < types.Count; i++) @@ -3767,7 +3765,7 @@ namespace PascalABCCompiler.TreeConverter if (cmn.cont_type.is_generic_type_definition) self_type = cmn.cont_type.get_instance(cmn.cont_type.generic_params.ConvertAll(o => (type_node)o));// new generic_instance_type_node(self_type, self_type.generic_params.ConvertAll(o => (type_node)o), self_type.base_type, self_type.name, self_type.type_access_level, self_type.comprehensive_namespace, self_type.loc); local_variable lv = new local_variable(compiler_string_consts.self_word, self_type, cmn, null); - cmn.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfo(lv)); + cmn.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfoUnit(lv)); cmn.self_variable = lv; } if ((sd as SyntaxTree.procedure_definition).proc_body != null) @@ -4272,7 +4270,7 @@ namespace PascalABCCompiler.TreeConverter } } cmn.function_code = new return_node(meth_call, loc); - cpn.common_comprehensive_type.scope.AddSymbol("get_" + cpn.name, new SymbolInfo(cmn)); + cpn.common_comprehensive_type.scope.AddSymbol("get_" + cpn.name, new SymbolInfoUnit(cmn)); return cmn; } @@ -4307,7 +4305,7 @@ namespace PascalABCCompiler.TreeConverter } } cmn.function_code = meth_call; - cpn.common_comprehensive_type.scope.AddSymbol("set_" + cpn.name, new SymbolInfo(cmn)); + cpn.common_comprehensive_type.scope.AddSymbol("set_" + cpn.name, new SymbolInfoUnit(cmn)); return cmn; } @@ -4347,7 +4345,7 @@ namespace PascalABCCompiler.TreeConverter var_ref = new static_class_field_reference(cf, loc); } cmn.function_code = find_operator(compiler_string_consts.assign_name, var_ref, cpr, loc); - cf.cont_type.scope.AddSymbol(AcessorName, new SymbolInfo(cmn)); + cf.cont_type.scope.AddSymbol(AcessorName, new SymbolInfoUnit(cmn)); return cmn; } @@ -4387,7 +4385,7 @@ namespace PascalABCCompiler.TreeConverter var_ref = new static_class_field_reference(cf, loc); } cmn.function_code = new return_node(var_ref, loc); - cf.cont_type.scope.AddSymbol(AcessorName, new SymbolInfo(cmn)); + cf.cont_type.scope.AddSymbol(AcessorName, new SymbolInfoUnit(cmn)); return cmn; } @@ -4439,7 +4437,7 @@ namespace PascalABCCompiler.TreeConverter exist_si = exist_si.Next; } pn.common_comprehensive_type.methods.AddElement(cmn); - pn.common_comprehensive_type.scope.AddSymbol(AcessorName, new SymbolInfo(cmn)); + pn.common_comprehensive_type.scope.AddSymbol(AcessorName, new SymbolInfoUnit(cmn)); return cmn; } @@ -4855,8 +4853,10 @@ namespace PascalABCCompiler.TreeConverter else { si = exp.type.find_in_type(id_right.name, context.CurrentScope); - if (si != null && si.sym_info != null && si.sym_info.semantic_node_type == semantic_node_type.wrap_def) - BasePCUReader.RestoreSymbols(si, id_right.name); + SymbolInfoList si_list = new SymbolInfoList(si); + if (si_list.First() != null && si_list.First().sym_info != null && si_list.First().sym_info.semantic_node_type == semantic_node_type.wrap_def) + BasePCUReader.RestoreSymbols(si_list, id_right.name); + si = si_list.ToSymbolInfo(); } @@ -5261,6 +5261,8 @@ namespace PascalABCCompiler.TreeConverter ThrowCompilationError = true; throw LastError(); } + // else + // RemoveLastError(); // ошибка уже убрана чуть выше } } catch (Exception ex) @@ -5364,6 +5366,10 @@ namespace PascalABCCompiler.TreeConverter case general_node_type.type_node: { type_node tn = (type_node)sn; + /*if (tn == SystemLibrary.SystemLibrary.void_type) + { + throw new VoidNotValid(get_location(id_right)); + }*/ check_for_type_allowed(tn, get_location(id_right)); SyntaxTree.operator_name_ident oni_right = id_right as SyntaxTree.operator_name_ident; if (oni_right != null) @@ -5644,6 +5650,15 @@ namespace PascalABCCompiler.TreeConverter #endregion function_node fn = convertion_data_and_alghoritms.select_function(exprs, si, subloc, syntax_nodes_parameters); + if (!debug && fn == SystemLibrary.SystemLibrary.assert_method) + { + // return_value(new empty_statement(null)); + // return; + } + /*if ((proc_wait==false)&&(fn.return_value_type==null)) + { + throw new FunctionExpectedProcedureMeet(fn,get_location(id_right)); + }*/ base_function_call bfc2 = null; if (exp == null) @@ -5684,6 +5699,7 @@ namespace PascalABCCompiler.TreeConverter SyntaxTree.expression expr = deref_value as SyntaxTree.expression; if (expr != null) { + //throw new CompilerInternalError("Not supported"); expression_node exp_int = convert_strong(expr); location sloc = get_location(expr); internal_interface ii = exp_int.type.get_internal_interface(internal_interface_kind.delegate_interface); @@ -6070,7 +6086,7 @@ namespace PascalABCCompiler.TreeConverter expression_node en = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.CopyWithSizeFunction.sym_info as function_node, loc, param0, cnfc); function_node fn = convertion_data_and_alghoritms.get_empty_conversion(en.type, retv.type, false); en = convertion_data_and_alghoritms.create_simple_function_call(fn, loc, en); - basic_function_call bfc = new basic_function_call(tn.find(compiler_string_consts.assign_name).sym_info as basic_function_node, loc, param0, en); + basic_function_call bfc = new basic_function_call(tn.find(compiler_string_consts.assign_name).First().sym_info as basic_function_node, loc, param0, en); return_value(bfc); return; } @@ -6934,15 +6950,16 @@ namespace PascalABCCompiler.TreeConverter { if (SystemLibrary.SystemLibInitializer.PointerOutputConstructor == null) { - SymbolInfo si = (SystemLibrary.SystemLibInitializer.PointerOutputType.sym_info as common_type_node).find_in_type(compiler_string_consts.default_constructor_name); + SymbolInfoList si = (SystemLibrary.SystemLibInitializer.PointerOutputType.sym_info as common_type_node).find_in_type(compiler_string_consts.default_constructor_name); common_method_node cnode = null; + int cur_si_index = 0; do { - cnode = si.sym_info as common_method_node; + cnode = si.InfoUnitList[0].sym_info as common_method_node; if (cnode.parameters.Count != 1) { cnode = null; - si = si.Next; + ++cur_si_index; } } while (cnode == null); @@ -6966,15 +6983,16 @@ namespace PascalABCCompiler.TreeConverter { if (SystemLibrary.SystemLibInitializer.PointerOutputConstructor == null) { - SymbolInfo si = (SystemLibrary.SystemLibInitializer.PointerOutputType.sym_info as compiled_type_node).find_in_type(compiler_string_consts.default_constructor_name); + SymbolInfoList si = (SystemLibrary.SystemLibInitializer.PointerOutputType.sym_info as compiled_type_node).find_in_type(compiler_string_consts.default_constructor_name); compiled_constructor_node cnode = null; + int cur_si_index = 0; do { - cnode = si.sym_info as compiled_constructor_node; + cnode = si.InfoUnitList[cur_si_index].sym_info as compiled_constructor_node; if (cnode.parameters.Count != 1) { cnode = null; - si = si.Next; + ++cur_si_index; } } while (cnode == null); @@ -8112,12 +8130,12 @@ namespace PascalABCCompiler.TreeConverter internal expression_node GetCurrentObjectReference(SymbolTable.Scope scope, definition_node dn, location loc) { - if (context.WithSection) + if (WithSection) if (scope != null) - if (context.WithVariables.ContainsKey(scope)) - return context.WithVariables[scope]; + if (WithVariables.ContainsKey(scope)) + return WithVariables[scope]; else - if (context.WithTypes.Contains(scope)) + if (WithTypes.Contains(scope)) { switch (dn.semantic_node_type) { @@ -8137,7 +8155,9 @@ namespace PascalABCCompiler.TreeConverter else return new this_node(context.converted_type, loc); } - + bool WithSection = false; + Dictionary WithVariables = new Dictionary(); + Stack WithTypes = new Stack(); private expression_node create_with_expression(expression_node expr) { @@ -8177,7 +8197,7 @@ namespace PascalABCCompiler.TreeConverter public override void visit(SyntaxTree.with_statement _with_statement) { - context.WithSection = true; + WithSection = true; List Withs = new List(); List VarRefs = new List(); List WithTypesList = new List(); @@ -8254,20 +8274,20 @@ namespace PascalABCCompiler.TreeConverter Dictionary OldWithVariables = new Dictionary(); foreach (expression_node vr in VarRefs) { - if (context.WithVariables.ContainsKey(vr.type.Scope)) + if (WithVariables.ContainsKey(vr.type.Scope)) { //перекрытие области if (OldWithVariables.ContainsKey(vr.type.Scope)) //Это локальные перекрытия - OldWithVariables[vr.type.Scope] = context.WithVariables[vr.type.Scope]; + OldWithVariables[vr.type.Scope] = WithVariables[vr.type.Scope]; else - OldWithVariables.Add(vr.type.Scope, context.WithVariables[vr.type.Scope]); - context.WithVariables[vr.type.Scope] = vr; + OldWithVariables.Add(vr.type.Scope, WithVariables[vr.type.Scope]); + WithVariables[vr.type.Scope] = vr; } else { //добавляем текущие with - context.WithVariables.Add(vr.type.Scope, vr); + WithVariables.Add(vr.type.Scope, vr); } //ivan dobavil dlja bazovyh klassov @@ -8279,16 +8299,16 @@ namespace PascalABCCompiler.TreeConverter (tn as compiled_type_node).init_scope(); } if (tn.Scope != null) - if (!context.WithVariables.ContainsKey(tn.Scope)) - context.WithVariables.Add(tn.Scope, vr); + if (!WithVariables.ContainsKey(tn.Scope)) + WithVariables.Add(tn.Scope, vr); else { if (OldWithVariables.ContainsKey(tn.Scope)) //Это локальные перекрытия - OldWithVariables[tn.Scope] = context.WithVariables[tn.Scope]; + OldWithVariables[tn.Scope] = WithVariables[tn.Scope]; else - OldWithVariables.Add(tn.Scope, context.WithVariables[tn.Scope]); - context.WithVariables[tn.Scope] = vr; + OldWithVariables.Add(tn.Scope, WithVariables[tn.Scope]); + WithVariables[tn.Scope] = vr; } tn = tn.base_type; } @@ -8298,33 +8318,33 @@ namespace PascalABCCompiler.TreeConverter foreach (SymbolTable.Scope sc in WithTypesList) { - if (!context.WithTypes.Contains(sc)) - context.WithTypes.Push(sc); + if (!WithTypes.Contains(sc)) + WithTypes.Push(sc); } stl.statements.AddElement(ret.visit(_with_statement.what_do)); //восстанавливаем перекрытия foreach (SymbolTable.Scope sc in OldWithVariables.Keys) - context.WithVariables[sc] = OldWithVariables[sc]; + WithVariables[sc] = OldWithVariables[sc]; //удаляем текущие with foreach (expression_node vr in VarRefs) { - context.WithVariables.Remove(vr.type.Scope); + WithVariables.Remove(vr.type.Scope); type_node tn = vr.type.base_type; while (tn != null) { - if (tn.Scope != null && context.WithVariables.ContainsKey(tn.Scope)) - context.WithVariables.Remove(tn.Scope); + if (tn.Scope != null && WithVariables.ContainsKey(tn.Scope)) + WithVariables.Remove(tn.Scope); tn = tn.base_type; } } foreach (SymbolTable.Scope sc in WithTypesList) { - context.WithTypes.Pop(); + WithTypes.Pop(); } - - context.WithSection = context.WithVariables.Count > 0; + + WithSection = WithVariables.Count > 0; convertion_data_and_alghoritms.statement_list_stack_pop(); return_value(stl); @@ -8333,8 +8353,8 @@ namespace PascalABCCompiler.TreeConverter public override void visit(SyntaxTree.labeled_statement _labeled_statement) { convertion_data_and_alghoritms.check_node_parser_error(_labeled_statement.label_name); - SymbolInfo si = context.CurrentScope.FindOnlyInScopeAndBlocks(_labeled_statement.label_name.name); - if (_labeled_statement.to_statement is SyntaxTree.var_statement || _labeled_statement.to_statement is SyntaxTree.assign_var_tuple) + SymbolInfoList si = context.CurrentScope.FindOnlyInScopeAndBlocks(_labeled_statement.label_name.name); + if (_labeled_statement.to_statement is SyntaxTree.var_statement) { AddError(get_location(_labeled_statement.label_name), "LABELED_DECLARATION_NOT_ALLOWED"); } @@ -8342,7 +8362,7 @@ namespace PascalABCCompiler.TreeConverter { AddError(new UndefinedNameReference(_labeled_statement.label_name.name, get_location(_labeled_statement.label_name))); } - label_node lab = si.sym_info as label_node; + label_node lab = si.First().sym_info as label_node; if (lab == null) { AddError(get_location(_labeled_statement.label_name), "IDENT_{0}_IS_NOT_LABEL", _labeled_statement.label_name.name); @@ -8370,12 +8390,12 @@ namespace PascalABCCompiler.TreeConverter public override void visit(SyntaxTree.goto_statement _goto_statement) { - SymbolInfo si = context.CurrentScope.FindOnlyInScopeAndBlocks(_goto_statement.label.name); + SymbolInfoList si = context.CurrentScope.FindOnlyInScopeAndBlocks(_goto_statement.label.name); if (si == null) { AddError(new UndefinedNameReference(_goto_statement.label.name, get_location(_goto_statement.label))); } - label_node lab = si.sym_info as label_node; + label_node lab = si.First().sym_info as label_node; if (lab == null) { AddError(get_location(_goto_statement.label), "IDENT_{0}_IS_NOT_LABEL", _goto_statement.label.name); @@ -8990,54 +9010,13 @@ namespace PascalABCCompiler.TreeConverter { return new indefinite_reference(dn as indefinite_definition_node, get_location(id_right)); } - if (expected_delegate && en != null) - { - SymbolInfo tmp_si = si; - function_node tmp_fn = null; - bool has_empty_methods = false; - bool only_extension_methods = true; - while (tmp_si != null) - { - tmp_fn = tmp_si.sym_info as function_node; - if (tmp_fn != null) - { - if (!tmp_fn.is_extension_method) - only_extension_methods = false; - else - { - if (tmp_fn.parameters.Count == 1 || tmp_fn.parameters.Count == 2 && (tmp_fn.parameters[1].is_params || tmp_fn.parameters[1].default_value != null)) - has_empty_methods = true; - } - } - tmp_si = tmp_si.Next; - } - if (has_empty_methods && only_extension_methods) - expected_delegate = false; - } if (expected_delegate) return make_delegate_wrapper(en, si, get_location(id_right), false); else { - function_node tmp_fn = null; - SymbolInfo tmp_si = si; - expressions_list pars = new expressions_list(); - if (en != null) - while (tmp_si != null) - { - tmp_fn = tmp_si.sym_info as function_node; - if (tmp_fn != null && tmp_fn.is_extension_method && - (tmp_fn.parameters.Count == 1 || tmp_fn.parameters.Count == 2 && (tmp_fn.parameters[1].is_params || tmp_fn.parameters[1].default_value != null))) - { - pars.AddElement(en); - break; - } - tmp_si = tmp_si.Next; - } - function_node fn = convertion_data_and_alghoritms.select_function(pars, si, get_location(id_right)); - if (!fn.is_extension_method && fn.polymorphic_state != SemanticTree.polymorphic_state.ps_static) - return create_not_static_method_call(fn, en, get_location(id_right), false); - else - return create_static_method_call_with_params(fn, get_location(id_right), fn.return_value_type, false, pars); + function_node fn = convertion_data_and_alghoritms.select_function(new expressions_list(), + si, get_location(id_right)); + return create_not_static_method_call(fn, en, get_location(id_right), false); } } case general_node_type.property_node: @@ -9167,7 +9146,12 @@ namespace PascalABCCompiler.TreeConverter } case motivation.expression_evaluation: { - if (can_convert_to_method_call(ref si)) + //en = expression_value_reciving(id_right, si, en, true); + //try_convert_typed_expression_to_function_call(ref en); + //return_value(en); + if (si.sym_info is function_node && (si.sym_info as function_node).is_extension_method && !has_property(ref si) + || si.sym_info is common_method_node && (si.sym_info as common_method_node).is_constructor + || si.sym_info is compiled_constructor_node) { //dot_node dnode = new dot_node(syntax_node, template_id_right); template_id_right.name = new dot_node(syntax_node, id_right); @@ -9210,7 +9194,12 @@ namespace PascalABCCompiler.TreeConverter } case motivation.expression_evaluation: { - if (can_convert_to_method_call(ref si)) + //en = expression_value_reciving(id_right, si, en, true); + //try_convert_typed_expression_to_function_call(ref en); + //return_value(en); + if (si.sym_info is function_node && (si.sym_info as function_node).is_extension_method && !has_property(ref si) + || si.sym_info is common_method_node && (si.sym_info as common_method_node).is_constructor + || si.sym_info is compiled_constructor_node) { dot_node dnode = new dot_node(syntax_node, id_right); method_call mc = new method_call(dnode, new expression_list()); @@ -9296,20 +9285,6 @@ namespace PascalABCCompiler.TreeConverter throw new CompilerInternalError("Invalid left dot node kind"); } - private bool can_convert_to_method_call(ref SymbolInfo si) - { - SymbolInfo tmp_si = si; - while (tmp_si != null) - { - if (tmp_si.sym_info is function_node && (tmp_si.sym_info as function_node).is_extension_method && !has_property(ref si) - || tmp_si.sym_info is common_method_node && (tmp_si.sym_info as common_method_node).is_constructor - || tmp_si.sym_info is compiled_constructor_node) - return true; - tmp_si = tmp_si.Next; - } - return false; - } - public override void visit(SyntaxTree.dot_node _dot_node) { var mot = motivation_keeper.motivation; @@ -9434,7 +9409,7 @@ namespace PascalABCCompiler.TreeConverter if (def_temp is type_node && (def_temp as type_node).IsInterface) { context.converted_explicit_interface_type = def_temp as type_node; - SymbolInfo si = context.converted_explicit_interface_type.find_in_type(_method_name.meth_name.name); + SymbolInfoList si = context.converted_explicit_interface_type.find_in_type(_method_name.meth_name.name); if (si == null) AddError(new UndefinedNameReference(_method_name.meth_name.name, get_location(_method_name.meth_name))); } @@ -9513,7 +9488,7 @@ namespace PascalABCCompiler.TreeConverter } if (tp is compiled_generic_instance_type_node || tp is common_generic_instance_type_node) AddError(get_location(_method_name), "EXTENSION_METHOD_FOR_GENERIC_INSTANCES"); - SymbolInfo si = tp.scope.FindOnlyInScope(_method_name.meth_name.name); + SymbolInfoList si = tp.scope.FindOnlyInScope(_method_name.meth_name.name); if (tp.original_template == null && ((si == null && this._compiled_unit.namespaces.IndexOf(tp.comprehensive_namespace) == -1) || (si != null && this._compiled_unit.namespaces.IndexOf(tp.comprehensive_namespace) == -1))) { @@ -9798,7 +9773,7 @@ namespace PascalABCCompiler.TreeConverter { if_node main_ifn = null; if_node ifn = null; - compiled_function_node str_eq_meth = SystemLibrary.SystemLibrary.string_type.find_in_type("=").sym_info as compiled_function_node; + compiled_function_node str_eq_meth = SystemLibrary.SystemLibrary.string_type.find_in_type("=").First().sym_info as compiled_function_node; Dictionary case_constants = new Dictionary(); foreach (SyntaxTree.case_variant cv in _case_node.conditions.variants) { @@ -10341,7 +10316,7 @@ namespace PascalABCCompiler.TreeConverter par.SetBaseType(SystemLibrary.SystemLibrary.object_type); par.generic_type_container = ctn; ctn.generic_params.Add(par); - ctn.scope.AddSymbol(id.name, new SymbolInfo(par)); + ctn.scope.AddSymbol(id.name, new SymbolInfoUnit(par)); if (SemanticRules.RuntimeInitVariablesOfGenericParameters && !ctn.IsInterface && !ctn.IsDelegate) { class_field cf = new class_field( @@ -10369,7 +10344,7 @@ namespace PascalABCCompiler.TreeConverter par.SetBaseType(SystemLibrary.SystemLibrary.object_type); par.generic_function_container = cfn; cfn.generic_params.Add(par); - cfn.scope.AddSymbol(id.name, new SymbolInfo(par)); + cfn.scope.AddSymbol(id.name, new SymbolInfoUnit(par)); } } @@ -10447,7 +10422,7 @@ namespace PascalABCCompiler.TreeConverter { make_attributes_for_declaration(_type_declaration,del_type); } - context.converted_namespace.scope.AddSymbol(del_name, new SymbolInfo(del_type)); + context.converted_namespace.scope.AddSymbol(del_name, new SymbolInfoUnit(del_type)); return; } if (cl_def == null && ttn == null) @@ -10631,10 +10606,10 @@ namespace PascalABCCompiler.TreeConverter AddError(get_location(cl_def.template_args), "GENERIC_PARAMETERS_MISMATCH"); foreach (ident id in cl_def.template_args.idents) { - SymbolInfo si = ctn.find_in_type(id.name); + SymbolInfoList si = ctn.find_in_type(id.name); if (si == null) AddError(get_location(cl_def.template_args), "GENERIC_PARAMETERS_MISMATCH"); - if (!(si.sym_info is common_type_node && (si.sym_info as common_type_node).is_generic_parameter)) + if (!(si.First().sym_info is common_type_node && (si.First().sym_info as common_type_node).is_generic_parameter)) AddError(get_location(cl_def.template_args), "GENERIC_PARAMETERS_MISMATCH"); } } @@ -10679,7 +10654,7 @@ namespace PascalABCCompiler.TreeConverter { if (ctn.attributes[i].attribute_type == SystemLibrary.SystemLibrary.usage_attribute_type) { - int ind = ctn.attributes[i].prop_names.IndexOf(SystemLibrary.SystemLibrary.usage_attribute_type.find_in_type("AllowMultiple").sym_info as property_node); + int ind = ctn.attributes[i].prop_names.IndexOf(SystemLibrary.SystemLibrary.usage_attribute_type.find_in_type("AllowMultiple").First().sym_info as property_node); if (ind != -1) allowMultiple = (bool)ctn.attributes[i].prop_initializers[ind].get_object_value(); return (AttributeTargets)ctn.attributes[i].args[0].get_object_value(); @@ -10894,8 +10869,12 @@ namespace PascalABCCompiler.TreeConverter else { SyntaxTree.ident id = (e as SyntaxTree.bin_expr).left as SyntaxTree.ident; - SymbolInfo si = tn.find_in_type(id.name); - definition_node dn = context.check_name_node_type(id.name, si, get_location(id), general_node_type.property_node, general_node_type.variable_node); + SymbolInfoList si = tn.find_in_type(id.name); + definition_node dn; + if (si != null) + dn = context.check_name_node_type(id.name, si.ToSymbolInfo(), get_location(id), general_node_type.property_node, general_node_type.variable_node); + else + dn = context.check_name_node_type(id.name, null, get_location(id), general_node_type.property_node, general_node_type.variable_node); type_node mem_tn = null; if (dn is property_node) { @@ -11028,8 +11007,8 @@ namespace PascalABCCompiler.TreeConverter else { SyntaxTree.ident id = (e as SyntaxTree.bin_expr).left as SyntaxTree.ident; - SymbolInfo si = tn.find(id.name); - definition_node dn = context.check_name_node_type(id.name, si, get_location(id), general_node_type.property_node, general_node_type.variable_node); + SymbolInfoList si = tn.find(id.name); + definition_node dn = context.check_name_node_type(id.name, si.ToSymbolInfo(), get_location(id), general_node_type.property_node, general_node_type.variable_node); type_node mem_tn = null; if (dn is property_node) { @@ -11378,7 +11357,7 @@ namespace PascalABCCompiler.TreeConverter common_parameter cp = new common_parameter(compiler_string_consts.self_word, (context.top_function as common_namespace_function_node).ConnectedToType, pt, context.top_function, cpt, null, null); context.top_function.parameters.AddElementFirst(cp); - context.top_function.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfo(cp)); + context.top_function.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfoUnit(cp)); } } CheckOverrideOrReintroduceExpectedWarning(get_location(_function_header)); @@ -11611,7 +11590,7 @@ namespace PascalABCCompiler.TreeConverter if (cmn.cont_type.is_generic_type_definition) self_type = cmn.cont_type.get_instance(cmn.cont_type.generic_params.ConvertAll(o => (type_node)o)); local_variable lv = new local_variable(compiler_string_consts.self_word, self_type, cmn, null); - cmn.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfo(lv)); + cmn.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfoUnit(lv)); cmn.self_variable = lv; } if (_procedure_definition.proc_body != null) @@ -11772,7 +11751,7 @@ namespace PascalABCCompiler.TreeConverter else { common_parameter_reference cpr = new common_parameter_reference(prm, 0, null); - compiled_function_node get_func = (prm.type.find_in_type("Length").sym_info as compiled_property_node).get_function as compiled_function_node; + compiled_function_node get_func = (prm.type.find_in_type("Length").First().sym_info as compiled_property_node).get_function as compiled_function_node; local_variable var = context.create_for_temp_variable(SystemLibrary.SystemLibrary.integer_type, null) as local_variable; local_variable len_var = context.create_for_temp_variable(SystemLibrary.SystemLibrary.integer_type, null) as local_variable; statements_list body = new statements_list(null); @@ -11985,7 +11964,7 @@ namespace PascalABCCompiler.TreeConverter common_parameter cp = new common_parameter(compiler_string_consts.self_word, self_type, pt, context.top_function, cpt, null, null); context.top_function.parameters.AddElementFirst(cp); - context.top_function.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfo(cp)); + context.top_function.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfoUnit(cp)); } } CheckOverrideOrReintroduceExpectedWarning(get_location(_function_header)); @@ -12134,7 +12113,7 @@ namespace PascalABCCompiler.TreeConverter context.top_function, cpt, null, null); context.top_function.parameters.AddElementFirst(cp); - context.top_function.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfo(cp)); + context.top_function.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfoUnit(cp)); } } if (_procedure_header is SyntaxTree.constructor) @@ -12453,17 +12432,15 @@ namespace PascalABCCompiler.TreeConverter } if (top_function.ConnectedToType.Scope == null) AddError(context.top_function.loc, "EXTENSION_METHODS_FOR_CONSTRUCTED_TYPES_NOT_ALLOWED"); - top_function.ConnectedToType.Scope.AddSymbol(top_function.name, new SymbolInfo(context.top_function)); + top_function.ConnectedToType.Scope.AddSymbol(top_function.name, new SymbolInfoUnit(context.top_function)); if (top_function.ConnectedToType.type_special_kind == SemanticTree.type_special_kind.array_kind && top_function.ConnectedToType.element_type.is_generic_parameter) - top_function.ConnectedToType.base_type.Scope.AddSymbol(top_function.name, new SymbolInfo(context.top_function)); + top_function.ConnectedToType.base_type.Scope.AddSymbol(top_function.name, new SymbolInfoUnit(context.top_function)); else if (top_function.ConnectedToType.is_generic_parameter) - top_function.ConnectedToType.base_type.Scope.AddSymbol(top_function.name, new SymbolInfo(context.top_function)); + top_function.ConnectedToType.base_type.Scope.AddSymbol(top_function.name, new SymbolInfoUnit(context.top_function)); else if (top_function.ConnectedToType is compiled_generic_instance_type_node && top_function.ConnectedToType.original_generic.Scope != null) - top_function.ConnectedToType.original_generic.Scope.AddSymbol(top_function.name, new SymbolInfo(context.top_function)); + top_function.ConnectedToType.original_generic.Scope.AddSymbol(top_function.name, new SymbolInfoUnit(context.top_function)); else if (top_function.ConnectedToType.IsDelegate && top_function.ConnectedToType.base_type.IsDelegate) - compiled_type_node.get_type_node(typeof(Delegate)).Scope.AddSymbol(top_function.name, new SymbolInfo(context.top_function)); - else if (top_function.ConnectedToType.type_special_kind == SemanticTree.type_special_kind.typed_file && top_function.ConnectedToType.element_type.is_generic_parameter && SystemLibrary.SystemLibInitializer.TypedFileType.sym_info != null) - (SystemLibrary.SystemLibInitializer.TypedFileType.sym_info as type_node).Scope.AddSymbol(top_function.name, new SymbolInfo(context.top_function)); + compiled_type_node.get_type_node(typeof(Delegate)).Scope.AddSymbol(top_function.name, new SymbolInfoUnit(context.top_function)); if (top_function.ConnectedToType.IsDelegate && context.top_function.IsOperator && (context.top_function.name == "+" || context.top_function.name == "-" || context.top_function.name == "+=" || context.top_function.name == "-=")) AddError(get_location(_procedure_attributes_list), "CANNOT_EXTEND_STANDARD_OPERATORS_FOR_DELEGATE"); if (context.top_function.IsOperator && (context.top_function.name == compiler_string_consts.implicit_operator_name || context.top_function.name == compiler_string_consts.explicit_operator_name) && context.top_function.parameters.Count == 1 && context.top_function.return_value_type != null) @@ -14807,14 +14784,7 @@ namespace PascalABCCompiler.TreeConverter { if (tn == null) return expr; - if (expr is SyntaxTree.array_const && tn.full_name != null && tn.full_name.StartsWith("System.Tuple")) - { - method_call mc = new method_call(); - mc.parameters = (expr as SyntaxTree.array_const).elements; - mc.dereferencing_value = new dot_node(new ident("Tuple"), new ident("Create")); - return mc; - } - else if (expr is SyntaxTree.bracket_expr && (tn.type_special_kind == SemanticTree.type_special_kind.array_kind || tn.type_special_kind == SemanticTree.type_special_kind.array_wrapper)) + if (expr is SyntaxTree.bracket_expr && (tn.type_special_kind == SemanticTree.type_special_kind.array_kind || tn.type_special_kind == SemanticTree.type_special_kind.array_wrapper)) { array_internal_interface aii = tn.get_internal_interface(internal_interface_kind.unsized_array_interface) as array_internal_interface; if (aii != null && aii.rank > 1) @@ -14906,11 +14876,11 @@ namespace PascalABCCompiler.TreeConverter CheckForCircuralInRecord(tn, get_location(_var_def_statement.vars_type)); if (_var_def_statement.inital_value != null) if (is_event) AddError(new NotSupportedError(get_location(_var_def_statement.inital_value))); - else - { - _var_def_statement.inital_value = get_possible_array_const(_var_def_statement.inital_value,tn); - inital_value = convert_strong_to_constant_or_function_call_for_varinit(convert_strong(_var_def_statement.inital_value), tn); - } + else + { + _var_def_statement.inital_value = get_possible_array_const(_var_def_statement.inital_value,tn); + inital_value = convert_strong_to_constant_or_function_call_for_varinit(convert_strong(_var_def_statement.inital_value), tn); + } } else { @@ -14935,11 +14905,6 @@ namespace PascalABCCompiler.TreeConverter { AddError(inital_value.location, "CAN_NOT_DEDUCE_TYPE_{0}", null); } - foreach (parameter p in bfc.simple_function_node.parameters) - { - if (p.type.is_generic_parameter) - AddError(inital_value.location, "USE_ANONYMOUS_FUNCTION_TYPE_WITH_GENERICS"); - } common_type_node del = convertion_data_and_alghoritms.type_constructor.create_delegate(context.get_delegate_type_name(), bfc.simple_function_node.return_value_type, bfc.simple_function_node.parameters, context.converted_namespace, null); context.converted_namespace.types.AddElement(del); @@ -15364,7 +15329,7 @@ namespace PascalABCCompiler.TreeConverter { if ((context.converting_block() == block_type.function_block) && (context.top_function.return_variable != null)) { - SymbolInfo si = context.top_function.scope.FindOnlyInScope(_ident.name);//context.find_only_in_namespace(_ident.name); + SymbolInfoList si = context.top_function.scope.FindOnlyInScope(_ident.name);//context.find_only_in_namespace(_ident.name); if (si == null) { int comp = SystemLibrary.SystemLibrary.string_comparer.Compare(_ident.name, context.top_function.name); @@ -15738,17 +15703,7 @@ namespace PascalABCCompiler.TreeConverter expression_node left = convert_strong(_bin_expr.left); expression_node right = convert_strong(_bin_expr.right); expression_node res = find_operator(_bin_expr.operation_type, left, right, get_location(_bin_expr)); - if (res.type.type_special_kind == SemanticTree.type_special_kind.base_set_type) - { - if (left.type.element_type == right.type.element_type) - res.type = left.type; - else if (type_table.compare_types(left.type, right.type) == type_compare.greater_type) - res.type = left.type; - else if (type_table.compare_types(left.type, right.type) == type_compare.less_type) - res.type = right.type; - else if (type_table.compare_types(left.type, right.type) == type_compare.non_comparable_type) - res.type = context.create_set_type(SystemLibrary.SystemLibrary.object_type, get_location(_bin_expr)); - } + //ssyy, 15.05.2009 switch (_bin_expr.operation_type) { @@ -15931,7 +15886,6 @@ namespace PascalABCCompiler.TreeConverter // SSM 26.06.16 - правка в связи с автовыведением типов в yieldах if (to.type is auto_type) { - try_convert_typed_expression_to_function_call(ref from); if (to is class_field_reference) { var cfr = to as class_field_reference; @@ -16316,12 +16270,10 @@ namespace PascalABCCompiler.TreeConverter statement syntax_statement = _statement_list.subnodes[i]; try { - // SSM выкинул эти три строки - теперь внутриблочные описания обрабатываются как обычные операторы. - // При этом в конце visit(var_statement) стоит вызов ret.reset(), который возвращает нулевой semantic_statement - и всё работает эквивалентно - //if (syntax_statement is SyntaxTree.var_statement) - // visit(syntax_statement as SyntaxTree.var_statement); // Добавление в текущий statements_list происходит опосредованно !! - //else if (MustVisitBody) // MustVisitBody - всегда True!!! - //{ + if (syntax_statement is SyntaxTree.var_statement) + visit(syntax_statement as SyntaxTree.var_statement); + else if (MustVisitBody) + { //(ssyy) TODO Сделать по-другому!!! statement_node semantic_statement = convert_strong(syntax_statement); //(ssyy) Проверка для C @@ -16335,7 +16287,7 @@ namespace PascalABCCompiler.TreeConverter } context.allow_inherited_ctor_call = false; - //} + } } catch (Errors.Error ex) { @@ -16535,16 +16487,18 @@ namespace PascalABCCompiler.TreeConverter elem_type = tn.element_type; if (elem_type != null) return true; function_node get_enumerator_func = null; - SymbolInfo si = ctn.find_in_type(compiler_string_consts.GetEnumeratorMethodName); - while (get_enumerator_func == null && si != null) + SymbolInfoList si = ctn.find_in_type(compiler_string_consts.GetEnumeratorMethodName); + if(si != null) + foreach(var si_unit in si.InfoUnitList) { - get_enumerator_func = si.sym_info as function_node; + if(get_enumerator_func != null) + break; + get_enumerator_func = si.First().sym_info as function_node; if (get_enumerator_func.parameters.Count == 0) break; get_enumerator_func = null; - si = si.Next; } - elem_type = (get_enumerator_func.return_value_type.find_in_type(compiler_string_consts.CurrentPropertyName).sym_info as property_node).get_function.return_value_type; + elem_type = (get_enumerator_func.return_value_type.find_in_type(compiler_string_consts.CurrentPropertyName).First().sym_info as property_node).get_function.return_value_type; return true; } } @@ -16699,6 +16653,12 @@ namespace PascalABCCompiler.TreeConverter return new ident("$GenId" + GenIdNum.ToString()); } + public void ReplaceSTV(syntax_tree_node from, syntax_tree_node to) + { + from.Parent.Replace(from, to); + to.Parent = from.Parent; + } + public override void visit(SyntaxTree.foreach_stmt _foreach_stmt) { var lambdaSearcher = new LambdaSearcher(_foreach_stmt.in_what); @@ -16760,8 +16720,7 @@ namespace PascalABCCompiler.TreeConverter var fornode = new SyntaxTree.for_node(i, 0, high, newbody, for_cycle_type.to, null, null, true); var stl = new SyntaxTree.statement_list(vdarr, fornode); - // Замена 1 оператора на 1 оператор. Всё хорошо даже если оператор помечен меткой - ReplaceUsingParent(_foreach_stmt, stl); + ReplaceSTV(_foreach_stmt, stl); visit(stl); //visit(vdarr); @@ -17111,10 +17070,10 @@ namespace PascalABCCompiler.TreeConverter //А вдруг такая инстанция уже есть - вернём её string inst_name = tc.CreateTemplateInstance(template_params, loc); - SymbolInfo si = tc.cnn.scope.FindOnlyInScope(inst_name); + SymbolInfoList si = tc.cnn.scope.FindOnlyInScope(inst_name); if (si != null) { - return (common_type_node)si.sym_info; + return (common_type_node)si.First().sym_info; } //Переходим в место описания шаблона @@ -17202,7 +17161,7 @@ namespace PascalABCCompiler.TreeConverter //Ставим в соответствие формальным параметрам шаблона фактические for (int i = 0; i < template_params.Count; i++) { - ctn.Scope.AddSymbol(template_formals[i].name, new SymbolInfo(template_params[i])); + ctn.Scope.AddSymbol(template_formals[i].name, new SymbolInfoUnit(template_params[i])); } //Разбор тела класса @@ -17812,7 +17771,6 @@ namespace PascalABCCompiler.TreeConverter public override void visit(SyntaxTree.var_statement node) { visit(node.var_def); - ret.reset(); // SSM 19.01.17 не возвращать семантическое значение т.к. ничего не нужно добавлять в текущий список операторов!! } public override void visit(SyntaxTree.expression_as_statement node) @@ -17945,7 +17903,7 @@ namespace PascalABCCompiler.TreeConverter } local_variable lv = new local_variable(compiler_string_consts.self_word, gen_func.cont_type, gen_func, null); - gen_func.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfo(lv)); + gen_func.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfoUnit(lv)); gen_func.self_variable = lv; base_function_call bfc; @@ -18311,7 +18269,13 @@ namespace PascalABCCompiler.TreeConverter } SymbolInfo type_si = null; if (tn != null) - type_si = tn.find_in_type(id_ex.name + compiler_string_consts.generic_params_infix + par_count.ToString()); + { + var temp = tn.find_in_type(id_ex.name + compiler_string_consts.generic_params_infix + par_count.ToString()); + if (temp != null) + type_si = temp.ToSymbolInfo(); + else + type_si = null; + } else if (nn != null) type_si = nn.find(id_ex.name + compiler_string_consts.generic_params_infix + par_count.ToString()); else if (un != null) @@ -18322,7 +18286,13 @@ namespace PascalABCCompiler.TreeConverter return; } if (tn != null) - type_si = tn.find_in_type(id_ex.name); + { + var temp = tn.find_in_type(id_ex.name); + if (temp != null) + type_si = temp.ToSymbolInfo(); + else + type_si = null; + } else if (nn != null) type_si = nn.find(id_ex.name); else if (un != null) @@ -18805,7 +18775,7 @@ namespace PascalABCCompiler.TreeConverter common_parameter cp = new common_parameter(compiler_string_consts.self_word, (context.top_function as common_namespace_function_node).ConnectedToType, pt, context.top_function, cpt, null, null); context.top_function.parameters.AddElementFirst(cp); - context.top_function.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfo(cp)); + context.top_function.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfoUnit(cp)); } CheckOverrideOrReintroduceExpectedWarning(get_location(_function_header)); @@ -19050,10 +19020,19 @@ namespace PascalABCCompiler.TreeConverter public override void visit(matching_expression _matching_expression) { - throw new NotSupportedError(get_location(_matching_expression)); + SyntaxTree.procedure_call pc = new SyntaxTree.procedure_call(); + SyntaxTree.method_call mc = new SyntaxTree.method_call(); + dot_node dot = new dot_node(new ident("PABCSystem"), new ident("KV")); + mc.dereferencing_value = dot; + pc.func_name = mc; + pc.source_context = _matching_expression.source_context; + SyntaxTree.expression_list exl = new PascalABCCompiler.SyntaxTree.expression_list(); + exl.Add(_matching_expression.left); + exl.Add(_matching_expression.right); + mc.parameters = exl; + visit(pc); } - - public override void visit(SyntaxTree.sequence_type _sequence_type) // сахарный узел + public override void visit(SyntaxTree.sequence_type _sequence_type) { // SSM 11/05/15 sugared node var l = new List(); @@ -19066,8 +19045,7 @@ namespace PascalABCCompiler.TreeConverter _sequence_type.source_context); visit(tr); } - - public override void visit(SyntaxTree.modern_proc_type _modern_proc_type) // сахарный узел + public override void visit(SyntaxTree.modern_proc_type _modern_proc_type) { if (_modern_proc_type.res != null) { @@ -19162,33 +19140,120 @@ namespace PascalABCCompiler.TreeConverter return null; } - /*expression_list construct_expression_list_for_slice_expr(SyntaxTree.slice_expr sl) + public override void visit(SyntaxTree.assign_tuple asstup) { + // Проверить, что справа - Tuple + var expr = convert_strong(asstup.expr); + expr = convert_if_typed_expression_to_function_call(expr); + var t = ConvertSemanticTypeNodeToNETType(expr.type); + if (t == null) + AddError(expr.location, "TUPLE_EXPECTED"); + //if (t != typeof(System.Tuple<>)) + if (!t.FullName.StartsWith("System.Tuple")) + AddError(expr.location, "TUPLE_EXPECTED"); + + var n = asstup.vars.variables.Count(); + if (n > t.GetGenericArguments().Count()) + AddError(get_location(asstup.vars), "TOO_MANY_ELEMENTS_ON_LEFT_SIDE_OF_TUPLE_ASSIGNMRNT"); + + var tname = "#temp_var" + UniqueNumStr(); + + var tt = new var_statement(new ident(tname), new semantic_addr_value(expr)); // тут semantic_addr_value хранит на самом деле expr - просто неудачное название + + var st = new statement_list(tt); + for (var i = 0; i < n; i++) + { + var a = new assign(asstup.vars.variables[i], new dot_node(new ident(tname), + new ident("Item" + (i + 1).ToString())), Operators.Assignment, + asstup.vars.variables[i].source_context); + st.Add(a); + } + visit(st); + } + + public override void visit(SyntaxTree.assign_var_tuple asstup) + { + // Проверить, что справа - Tuple + var expr = convert_strong(asstup.expr); + expr = convert_if_typed_expression_to_function_call(expr); + var t = ConvertSemanticTypeNodeToNETType(expr.type); + if (t == null) + AddError(expr.location, "TUPLE_EXPECTED"); + //if (t != typeof(System.Tuple<>)) + if (!t.FullName.StartsWith("System.Tuple")) + AddError(expr.location, "TUPLE_EXPECTED"); + + var n = asstup.vars.variables.Count(); + if (n > t.GetGenericArguments().Count()) + AddError(get_location(asstup.vars), "TOO_MANY_ELEMENTS_ON_LEFT_SIDE_OF_TUPLE_ASSIGNMRNT"); + + var tname = "#temp_var" + UniqueNumStr(); + + var tt = new var_statement(new ident(tname), new semantic_addr_value(expr)); // тут semantic_addr_value хранит на самом деле expr - просто неудачное название + + visit(tt); + for (var i = 0; i < n; i++) + { + var rr = asstup.vars.variables[i] as ident; + var a = new var_statement(rr, + new dot_node(new ident(tname),new ident("Item" + (i + 1).ToString())), + asstup.vars.variables[i].source_context + ); + visit(a); + } + } + + public override void visit(SyntaxTree.slice_expr sl) + { + // Новое + // Последовательности исключены + // Преобразуется в вызов a.SystemSlice(situation,from,to,step) // situation = 0 - ничего не пропущено // situation = 1 - пропущен from // situation = 2 - пропущен to // situation = 3 - пропущены from и to - // Пропущенность кодируется тем, что в соответствующем поле - int.MaxValue - // step может просто отсутствовать - это параметр по умолчанию в SystemSlice + // пропущенность кодируется тем, что в соответствующем поле int.MaxValue + + var semvar = convert_strong(sl.v); + if (semvar is typed_expression) + semvar = convert_typed_expression_to_function_call(semvar as typed_expression); + + var semvartype = semvar.type; + + // semvartype должен быть array of T, List или string + + var IsSlicedType = 0; // проверим, является ли semvartype динамическим массивом, списком List или строкой + + var t = ConvertSemanticTypeNodeToNETType(semvartype); + + if (t.IsArray) + IsSlicedType = 1; + else if (t == typeof(System.String)) + IsSlicedType = 2; + else if (t.IsGenericType && t.GetGenericTypeDefinition()==typeof(System.Collections.Generic.List<>)) + IsSlicedType = 3; + + if (IsSlicedType==0) + AddError(get_location(sl.v), "BAD_SLICE_OBJECT"); int situation = 0; - if ((sl.from is int32_const) && (sl.from as int32_const).val == int.MaxValue) + if ((sl.from is int32_const) && (sl.from as int32_const).val==int.MaxValue) situation += 1; if ((sl.to is int32_const) && (sl.to as int32_const).val == int.MaxValue) situation += 2; var el = new SyntaxTree.expression_list(); el.Add(new int32_const(situation)); - el.Add(sl.from); // Это плохо - считается 2 раза. Надо делать semantic_expr_node !!!? Нет!!! - // Если там будет лямбда, то не будет работать - известно, что semantic_expr_node не работает с лямбдами - // т.к. они несколько раз обходят код. + el.Add(sl.from); el.Add(sl.to); + if (sl.step != null) el.Add(sl.step); - return el; - }*/ + var mc = new method_call(new dot_node(sl.v, new ident("SystemSlice", sl.v.source_context), sl.v.source_context), el, sl.source_context); + visit(mc); + } // frninja 04/03/16 - для yield @@ -19252,9 +19317,10 @@ namespace PascalABCCompiler.TreeConverter if (iteratorContainingClass != null) { // Search for unknown ident in class - var found = iteratorContainingClass.find(_unk.UnknownID.name); - if ((object)found != null) + var found_l = iteratorContainingClass.find(_unk.UnknownID.name); + if ((object)found_l != null) { + var found = found_l.First(); // class_field - поле класса // common_method_node - метод класса // common_property_node - свойство класса @@ -19325,15 +19391,6 @@ namespace PascalABCCompiler.TreeConverter } } - public override void visit(SyntaxTree.yield_node yn) - { - // надо что то сгенерировать, иначе выдается ложное предупреждение о недостижимом коде и проч. - /*var ass = new assign("Result", new nil_const()); - visit(ass); - var pc = new procedure_call("exit"); - visit(pc);*/ - } - // frninja - захват полей класса для yield public override void visit(SyntaxTree.yield_unknown_ident _unk) { @@ -19355,140 +19412,30 @@ namespace PascalABCCompiler.TreeConverter t.visit(this); } - public override void visit(SyntaxTree.dot_question_node dqn) + public override void visit(SyntaxTree.yield_node yn) { - // a?.b - AddError(get_location(dqn), "SUGARED_NODE_{0}_IN_SYNTAX_TREE_VISITOR", dqn.GetType().Name); - //var q = ConvertToQCE(dqn); - //visit(q); + // надо что то сгенерировать, иначе выдается ложное предупреждение о недостижимом коде и проч. + var ass = new assign("Result", new nil_const()); + visit(ass); + var pc = new procedure_call("exit"); + visit(pc); } - public override void visit(SyntaxTree.semantic_check_sugared_statement_node st) - { - if (st.typ as System.Type == typeof(SyntaxTree.assign_tuple)) - { - var vars = st.lst[0] as SyntaxTree.addressed_value_list; - var expr = st.lst[1] as SyntaxTree.expression; - semantic_check_assign_tuple(vars,expr); - } - else - { - AddError(get_location(st), "MISSED_SEMANTIC_CHECK_FOR_SUGARED_NODE_{0}", st.GetType().Name); - } - ret.reset(); // обязательно очистить - этот узел в семантику ничего не должен приносить! - } - - public override void visit(SyntaxTree.sugared_expression ex) - { - /*if (ex.sugared_expr is SyntaxTree.tuple_node) - { - semantic_check_tuple(ex.sugared_expr as SyntaxTree.tuple_node); - } - else*/ - { - AddError(get_location(ex), "MISSED_SEMANTIC_CHECK_FOR_SUGARED_NODE_{0}", ex.sugared_expr.GetType().Name); - } - - ProcessNode(ex.new_expr); // обойти десахарное выражение - обязательно ProcessNode - visit нельзя! - } - - public override void visit(SyntaxTree.sugared_addressed_value av) - { - if (av.sugared_expr is SyntaxTree.slice_expr) // и slice_expr_question - { - semantic_check_method_call_as_slice_expr(av.new_addr_value as SyntaxTree.method_call); - } - else - { - AddError(get_location(av), "MISSED_SEMANTIC_CHECK_FOR_SUGARED_NODE_{0}", av.sugared_expr.GetType().Name); - } - - ProcessNode(av.new_addr_value); // обойти десахарное - } - - public override void visit(SyntaxTree.assign_tuple asstup) // сахарный узел - { - AddError(get_location(asstup), "SUGARED_NODE_{0}_IN_SYNTAX_TREE_VISITOR", asstup.GetType().Name); - - /*semantic_check_assign_tuple(asstup); - - var tname = "#temp_var" + UniqueNumStr(); - - //var tt = new var_statement(new ident(tname), new semantic_addr_value(expr)); // тут semantic_addr_value хранит на самом деле expr - просто неудачное название - var tt = new var_statement(new ident(tname), asstup.expr); // тут semantic_addr_value хранит на самом деле expr - просто неудачное название - var st = new statement_list(tt); - - var n = asstup.vars.variables.Count(); - for (var i = 0; i < n; i++) - { - var a = new assign(asstup.vars.variables[i], new dot_node(new ident(tname), - new ident("Item" + (i + 1).ToString())), Operators.Assignment, - asstup.vars.variables[i].source_context); - st.Add(a); - } - visit(st); - // Замена 1 оператор на 1 оператор - всё OK - ReplaceUsingParent(asstup, st);*/ - } - - public override void visit(SyntaxTree.assign_var_tuple assvartup) // сахарный узел - { - AddError(get_location(assvartup), "SUGARED_NODE_{0}_IN_SYNTAX_TREE_VISITOR", assvartup.GetType().Name); - - /*check_sugared(assvartup); - - var tname = "#temp_var" + UniqueNumStr(); - - var tt = new var_statement(new ident(tname), assvartup.expr); // тут для assvartup.expr внутри повторно вызывается convert_strong, это плохо, но если там лямбда, то иначе - с semantic_addr_value - не работает!!! - //var tt = new var_statement(new ident(tname), new semantic_addr_value(expr)); // тут semantic_addr_value хранит на самом деле expr - просто неудачное название - visit(tt); // обходится первый элемент - вместо asstup - - var sl = new List(); - sl.Add(tt); // он же помещается в новое синтаксическое дерево - - var n = assvartup.vars.variables.Count(); - for (var i = 0; i < n; i++) - { - var rr = assvartup.vars.variables[i] as ident; - var a = new var_statement(rr, - new dot_node(new ident(tname),new ident("Item" + (i + 1).ToString())), - assvartup.vars.variables[i].source_context - ); - // Остальные элементы обходить не надо (!!!уже надо!) - они обходятся на следующих итерациях при обходе внешнего statement_list - //visit(a); - sl.Add(a); - } - ReplaceStatementUsingParent(assvartup, sl);*/ - } - - public override void visit(SyntaxTree.slice_expr sl) // сахарный узел - { - AddError(get_location(sl), "SUGARED_NODE_{0}_IN_SYNTAX_TREE_VISITOR", sl.GetType().Name); - - /* - // Преобразуется в вызов a.SystemSlice(situation,from,to,step) - // Тип a должен быть array of T, List или string - semcheck(sl); - - // Действия уровня синтаксиса. Можно вынести на синтаксический уровень как desugaring для сахарного узла - var el = construct_expression_list_for_slice_expr(sl); - var mc = new method_call(new dot_node(sl.v, new ident("SystemSlice", sl.v.source_context), sl.v.source_context), el, sl.source_context); - - visit(mc);*/ - } - - public override void visit(SyntaxTree.slice_expr_question sl) // сахарный узел - { - AddError(get_location(sl), "SUGARED_NODE_{0}_IN_SYNTAX_TREE_VISITOR", sl.GetType().Name); - /* - // Преобразуется в вызов a.SystemSlice(situation,from,to,step) - // Тип a должен быть array of T, List или string - semcheck(sl); - - var el = construct_expression_list_for_slice_expr(sl); - var mc = new method_call(new dot_node(sl.v, new ident("SystemSliceQuestion", sl.v.source_context), sl.v.source_context), el, sl.source_context); - - visit(mc);*/ - } + /*public SyntaxTree.question_colon_expression ConvertToQCE(dot_question_node dqn) + { + // Неверно работает. Пока не используется. Доделать + addressed_value left = dqn.left; + addressed_value right = dqn.right; + var eq = new bin_expr(left, new nil_const(), Operators.Equal, left.source_context); + var dn = new dot_node(left, right, dqn.source_context); + var q = new SyntaxTree.question_colon_expression(eq, new nil_const(), dn, dqn.source_context); + return q; + } + public override void visit(SyntaxTree.dot_question_node dqn) + { + // a?.b + var q = ConvertToQCE(dqn); + visit(q); + }*/ } } diff --git a/TreeConverter/TreeConversion/type_constructor.cs b/TreeConverter/TreeConversion/type_constructor.cs index 8f86c4b93..5aa847632 100644 --- a/TreeConverter/TreeConversion/type_constructor.cs +++ b/TreeConverter/TreeConversion/type_constructor.cs @@ -194,12 +194,12 @@ namespace PascalABCCompiler.TreeConverter el.AddElement(exprs[0]); el.AddElement(cfc); - SymbolInfo si = exprs[0].type.find_in_type(compiler_string_consts.assign_name); + SymbolInfoList si = exprs[0].type.find_in_type(compiler_string_consts.assign_name); if (si == null) { throw new CompilerInternalError("Undefined delegate operation"); } - function_node fn = (function_node)si.sym_info; + function_node fn = (function_node)si.First().sym_info; expression_node en = convertion_data_and_alghoritms.create_simple_function_call(fn, call_location, el[0], el[1]); @@ -221,12 +221,12 @@ namespace PascalABCCompiler.TreeConverter el.AddElement(exprs[0]); el.AddElement(cfc); - SymbolInfo si = exprs[0].type.find_in_type(compiler_string_consts.assign_name); + SymbolInfoList si = exprs[0].type.find_in_type(compiler_string_consts.assign_name); if (si == null) { throw new CompilerInternalError("Undefined delegate operation"); } - function_node fn = (function_node)si.sym_info; + function_node fn = (function_node)si.First().sym_info; expression_node en = convertion_data_and_alghoritms.create_simple_function_call(fn, call_location, el[0], el[1]); @@ -331,7 +331,7 @@ namespace PascalABCCompiler.TreeConverter common_method_node cmn_add = new common_method_node(compiler_string_consts.plus_name, ctn, loc, ctn, SemanticTree.polymorphic_state.ps_static, SemanticTree.field_access_level.fal_public, ctn.scope); cmn_add.compile_time_executor = delegate_add_compile_time_executor; - ctn.scope.AddSymbol(cmn_add.name, new SymbolInfo(cmn_add)); + ctn.scope.AddSymbol(cmn_add.name, new SymbolInfoUnit(cmn_add)); common_parameter cp1 = new common_parameter(compiler_string_consts.left_param_name, ctn, SemanticTree.parameter_type.value, cmn_add, concrete_parameter_type.cpt_none, null, loc); common_parameter cp2 = new common_parameter(compiler_string_consts.right_param_name, ctn, SemanticTree.parameter_type.value, @@ -343,7 +343,7 @@ namespace PascalABCCompiler.TreeConverter common_method_node cmn_add_assign = new common_method_node(compiler_string_consts.plusassign_name, ctn, loc, ctn, SemanticTree.polymorphic_state.ps_static, SemanticTree.field_access_level.fal_public, ctn.scope); cmn_add_assign.compile_time_executor = delegate_add_assign_compile_time_executor; - ctn.scope.AddSymbol(cmn_add_assign.name, new SymbolInfo(cmn_add_assign)); + ctn.scope.AddSymbol(cmn_add_assign.name, new SymbolInfoUnit(cmn_add_assign)); common_parameter cp3 = new common_parameter(compiler_string_consts.left_param_name, ctn, SemanticTree.parameter_type.value, cmn_add_assign, concrete_parameter_type.cpt_none, null, loc); common_parameter cp4 = new common_parameter(compiler_string_consts.right_param_name, ctn, SemanticTree.parameter_type.value, @@ -355,7 +355,7 @@ namespace PascalABCCompiler.TreeConverter common_method_node cmn_sub = new common_method_node(compiler_string_consts.minus_name, ctn, loc, ctn, SemanticTree.polymorphic_state.ps_static, SemanticTree.field_access_level.fal_public, ctn.scope); cmn_sub.compile_time_executor = delegate_sub_compile_time_executor; - ctn.scope.AddSymbol(cmn_sub.name, new SymbolInfo(cmn_sub)); + ctn.scope.AddSymbol(cmn_sub.name, new SymbolInfoUnit(cmn_sub)); common_parameter cp12 = new common_parameter(compiler_string_consts.left_param_name, ctn, SemanticTree.parameter_type.value, cmn_sub, concrete_parameter_type.cpt_none, null, loc); common_parameter cp22 = new common_parameter(compiler_string_consts.right_param_name, ctn, SemanticTree.parameter_type.value, @@ -367,7 +367,7 @@ namespace PascalABCCompiler.TreeConverter common_method_node cmn_sub_assign = new common_method_node(compiler_string_consts.minusassign_name, ctn, loc, ctn, SemanticTree.polymorphic_state.ps_static, SemanticTree.field_access_level.fal_public, ctn.scope); cmn_sub_assign.compile_time_executor = delegate_sub_assign_compile_time_executor; - ctn.scope.AddSymbol(cmn_sub_assign.name, new SymbolInfo(cmn_sub_assign)); + ctn.scope.AddSymbol(cmn_sub_assign.name, new SymbolInfoUnit(cmn_sub_assign)); common_parameter cp32 = new common_parameter(compiler_string_consts.left_param_name, ctn, SemanticTree.parameter_type.value, cmn_sub_assign, concrete_parameter_type.cpt_none, null, loc); common_parameter cp42 = new common_parameter(compiler_string_consts.right_param_name, ctn, SemanticTree.parameter_type.value, @@ -416,15 +416,15 @@ namespace PascalABCCompiler.TreeConverter class_constant_definition cdn1 = new class_constant_definition(compiler_string_consts.lower_array_const_name, oti_indexer.lower_value, loc, ctn, SemanticTree.field_access_level.fal_public); - ctn.scope.AddSymbol(cdn1.name, new SymbolInfo(cdn1)); + ctn.scope.AddSymbol(cdn1.name, new SymbolInfoUnit(cdn1)); class_constant_definition cdn2 = new class_constant_definition(compiler_string_consts.upper_array_const_name, oti_indexer.upper_value, loc, ctn, SemanticTree.field_access_level.fal_public); - ctn.scope.AddSymbol(cdn2.name, new SymbolInfo(cdn2)); + ctn.scope.AddSymbol(cdn2.name, new SymbolInfoUnit(cdn2)); class_field int_arr = new class_field(compiler_string_consts.internal_array_name, sa, ctn, SemanticTree.polymorphic_state.ps_common, SemanticTree.field_access_level.fal_public,loc); - ctn.scope.AddSymbol(int_arr.name, new SymbolInfo(int_arr)); + ctn.scope.AddSymbol(int_arr.name, new SymbolInfoUnit(int_arr)); ctn.fields.AddElement(int_arr); SystemLibrary.SystemLibrary.init_reference_type(ctn); @@ -479,20 +479,20 @@ namespace PascalABCCompiler.TreeConverter expression_node index_expr2 = new simple_array_indexing(cfr2, sub_expr2, element_type,loc); - SymbolInfo si = element_type.find_in_type(compiler_string_consts.assign_name); + SymbolInfoList si = element_type.find_in_type(compiler_string_consts.assign_name); if (si == null) { throw new NotSupportedError(loc); throw new CompilerInternalError("Varable of this type can not be assigned"); } - if (si.sym_info.general_node_type != general_node_type.function_node) + if (si.First().sym_info.general_node_type != general_node_type.function_node) { throw new CompilerInternalError("Invalid assign operator"); } expression_node val_ref = new common_parameter_reference(set_val, 0, loc); - function_node assign = (function_node)si.sym_info; + function_node assign = (function_node)si.First().sym_info; statement_node assign_call = convertion_data_and_alghoritms.create_simple_function_call(assign, /*loc*/new location(0xFFFFFF, 0, 0xFFFFFF, 0, loc.doc), index_expr2, val_ref); @@ -526,7 +526,7 @@ namespace PascalABCCompiler.TreeConverter ctn.ImplementingInterfaces.Add(compiled_type_node.get_type_node(NetHelper.NetHelper.FindType(compiler_string_consts.IEnumerableInterfaceName))); common_method_node en_cmn = new common_method_node(compiler_string_consts.GetEnumeratorMethodName, compiled_type_node.get_type_node(NetHelper.NetHelper.FindType(compiler_string_consts.IEnumeratorInterfaceName)), null, ctn, SemanticTree.polymorphic_state.ps_virtual, SemanticTree.field_access_level.fal_public, null); - compiled_function_node en_fnc = NetHelper.NetHelper.FindName(NetHelper.NetHelper.FindType(compiler_string_consts.IEnumerableInterfaceName), compiler_string_consts.GetEnumeratorMethodName).sym_info as compiled_function_node; + compiled_function_node en_fnc = NetHelper.NetHelper.FindName(NetHelper.NetHelper.FindType(compiler_string_consts.IEnumerableInterfaceName), compiler_string_consts.GetEnumeratorMethodName).First().sym_info as compiled_function_node; statements_list sl = new statements_list(null); sl.statements.AddElement(new return_node( new compiled_function_call(en_fnc, new class_field_reference(int_arr, new this_node(ctn, null), null), null), null)); @@ -543,10 +543,10 @@ namespace PascalABCCompiler.TreeConverter en_cmn = new common_method_node(compiler_string_consts.GetEnumeratorMethodName, compiled_type_node.get_type_node(NetHelper.NetHelper.FindType(compiler_string_consts.IGenericEnumeratorInterfaceName)).get_instance(generic_args), null, ctn, SemanticTree.polymorphic_state.ps_virtual, SemanticTree.field_access_level.fal_public, null); //en_fnc = en_tn.find_in_type("GetEnumerator").sym_info as function_node;//NetHelper.NetHelper.FindName(NetHelper.NetHelper.FindType(compiler_string_consts.IGenericEnumerableInterfaceName), compiler_string_consts.GetEnumeratorMethodName).sym_info as compiled_function_node; - SymbolInfo en_si = en_tn.find_in_type("GetEnumerator"); - if (en_si.Next != null && (en_si.Next.sym_info as function_node).return_value_type.is_generic_type_instance) - en_si = en_si.Next; - function_node en_fnc_inst = en_si.sym_info as function_node; ;//.get_instance(generic_args, true, loc); + SymbolInfoList en_si = en_tn.find_in_type("GetEnumerator"); + if (en_si.InfoUnitList.Count > 1 && (en_si.InfoUnitList[1].sym_info as function_node).return_value_type.is_generic_type_instance) + en_si.InfoUnitList = en_si.InfoUnitList.GetRange(1, en_si.InfoUnitList.Count - 1); + function_node en_fnc_inst = en_si.First().sym_info as function_node; ;//.get_instance(generic_args, true, loc); sl = new statements_list(null); if (en_fnc_inst is compiled_function_node) sl.statements.AddElement(new return_node( @@ -593,7 +593,7 @@ namespace PascalABCCompiler.TreeConverter cmn_eq.function_code = body; cmn_eq.is_overload = true; ctn.methods.AddElement(cmn_eq); - ctn.Scope.AddSymbol(compiler_string_consts.eq_name,new SymbolInfo(cmn_eq)); + ctn.Scope.AddSymbol(compiler_string_consts.eq_name,new SymbolInfoUnit(cmn_eq)); //<> operation scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_cmn.scope,ctn.scope); @@ -628,7 +628,7 @@ namespace PascalABCCompiler.TreeConverter cmn_noteq.function_code = body; cmn_noteq.is_overload = true; ctn.methods.AddElement(cmn_noteq); - ctn.Scope.AddSymbol(compiler_string_consts.noteq_name,new SymbolInfo(cmn_noteq)); + ctn.Scope.AddSymbol(compiler_string_consts.noteq_name,new SymbolInfoUnit(cmn_noteq)); //Equals /*scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_cmn.scope,ctn.scope); diff --git a/TreeConverter/TreeRealization/functions.cs b/TreeConverter/TreeRealization/functions.cs index d1e4c4c3e..2510316f2 100644 --- a/TreeConverter/TreeRealization/functions.cs +++ b/TreeConverter/TreeRealization/functions.cs @@ -786,7 +786,10 @@ namespace PascalABCCompiler.TreeRealization /// Информация о найленном символе. null, если ни чего не найдено. public PascalABCCompiler.TreeConverter.SymbolInfo find(string name, SymbolTable.Scope CurrentScope) { - return _scope.Find(name, CurrentScope);//y + var temp = _scope.Find(name, CurrentScope); + if (temp != null) + return temp.ToSymbolInfo(); + return null;//y } /// diff --git a/TreeConverter/TreeRealization/generics.cs b/TreeConverter/TreeRealization/generics.cs index 110563428..79c360d12 100644 --- a/TreeConverter/TreeRealization/generics.cs +++ b/TreeConverter/TreeRealization/generics.cs @@ -196,7 +196,6 @@ namespace PascalABCCompiler.TreeRealization } //Вспомогательный класс для создания псевдо-инстанций generic-типов. - //TODO: sdelat singletonom. staticheskie klassy eto gadost public static class generic_convertions { //Список, хранящий все псевдо-инстанции generic-типов, нужен для NetGenerator. @@ -208,8 +207,6 @@ namespace PascalABCCompiler.TreeRealization public static Hashtable generic_instances = new Hashtable(); - public static syntax_tree_visitor visitor; - public static List get_type_instances(type_node original_generic_type) { List instances = generic_instances[original_generic_type] as List; @@ -844,9 +841,6 @@ namespace PascalABCCompiler.TreeRealization for (int i = 0; i < count_params_to_see; ++i) { - if (alone && fact[i].type is delegated_methods && (fact[i].type as delegated_methods).empty_param_method != null && DeduceInstanceTypes(formal[i].type, (fact[i].type as delegated_methods).empty_param_method.type, deduced, nils)) - continue; - else if (!DeduceInstanceTypes(formal[i].type, fact[i].type, deduced, nils)) { if (alone && fact[i].type is delegated_methods && (fact[i].type as delegated_methods).empty_param_method != null) @@ -985,8 +979,6 @@ namespace PascalABCCompiler.TreeRealization //Выведение типов public static bool DeduceInstanceTypes(type_node formal_type, type_node fact_type, type_node[] deduced, List nils) { - if (fact_type == null)//issue #347 - return false; if (formal_type.generic_function_container == null && fact_type.generic_function_container != null) { //swap @@ -1006,25 +998,12 @@ namespace PascalABCCompiler.TreeRealization if (deduced[par_num] == null) { //Этот тип-параметр ещё не был выведен. - if (fact_type is delegated_methods && (fact_type as delegated_methods).empty_param_method != null && (fact_type as delegated_methods).empty_param_method.ret_type != null) - fact_type = (fact_type as delegated_methods).empty_param_method.ret_type; - //if (fact_type is delegated_methods) - // fact_type = visitor.CreateDelegate((fact_type as delegated_methods).proper_methods[0].simple_function_node); deduced[par_num] = fact_type; return true; } //Этот тип-параметр уже был выведен. Сравниваем с выведенным. if (!convertion_data_and_alghoritms.eq_type_nodes(fact_type, deduced[par_num], true)) { - if (fact_type is delegated_methods && deduced[par_num].IsDelegate) - { - delegate_internal_interface d1 = deduced[par_num].get_internal_interface(internal_interface_kind.delegate_interface) as delegate_internal_interface; - return convertion_data_and_alghoritms.function_eq_params_and_result((fact_type as delegated_methods).proper_methods[0].simple_function_node, d1.invoke_method); - } - else if (fact_type is delegated_methods && deduced[par_num] is delegated_methods) - { - return convertion_data_and_alghoritms.function_eq_params_and_result((fact_type as delegated_methods).proper_methods[0].simple_function_node, (deduced[par_num] as delegated_methods).proper_methods[0].simple_function_node); - } return false; } return true; @@ -1754,17 +1733,21 @@ namespace PascalABCCompiler.TreeRealization return rez_start; } - public override SymbolInfo find(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find(string name, bool no_search_in_extension_methods = false) { - SymbolInfo si = _original_generic.find(name); - si = ConvertSymbolInfo(si); - return si; + SymbolInfoList si = _original_generic.find(name); + if (si != null) + return new SymbolInfoList(ConvertSymbolInfo(si.ToSymbolInfo())); + return new SymbolInfoList(ConvertSymbolInfo(null));//delete } - public override SymbolInfo find_in_type(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find_in_type(string name, bool no_search_in_extension_methods = false) { - SymbolInfo si = _original_generic.find_in_type(name); - si = ConvertSymbolInfo(si); + SymbolInfoList si = _original_generic.find_in_type(name); + if (si != null) + si = new SymbolInfoList(ConvertSymbolInfo(si.ToSymbolInfo())); + else + si = new SymbolInfoList(ConvertSymbolInfo(null)); return si; } @@ -1777,8 +1760,8 @@ namespace PascalABCCompiler.TreeRealization private void conform_basic_function(string name, int base_func_num) { - SymbolInfo si1 = _original_generic.find_in_type(name); - AddMember(si1.sym_info, temp_names[base_func_num].sym_info); + SymbolInfoList si1 = _original_generic.find_in_type(name); + AddMember(si1.First().sym_info, temp_names[base_func_num].sym_info); } public void conform_basic_functions() @@ -2239,4 +2222,5 @@ namespace PascalABCCompiler.TreeRealization } } + } diff --git a/TreeConverter/TreeRealization/namespaces.cs b/TreeConverter/TreeRealization/namespaces.cs index af6142e67..81910920f 100644 --- a/TreeConverter/TreeRealization/namespaces.cs +++ b/TreeConverter/TreeRealization/namespaces.cs @@ -448,11 +448,17 @@ namespace PascalABCCompiler.TreeRealization /// Информация о найденом символе. null, если ни чего не найдена. public override SymbolInfo find(string name) { - return _scope.Find(name);//c,cc,c,cc - } + var temp = _scope.Find(name);//c,cc,c,cc + if (temp != null) + return temp.ToSymbolInfo(); + return null; + } public SymbolInfo findOnlyInNamespace(string name) { - return _scope.FindOnlyInScope(name);//c,cc,c,cc + var temp = _scope.FindOnlyInScope(name);//c,cc,c,cc + if (temp != null) + return temp.ToSymbolInfo(); + return null; } /// @@ -662,7 +668,11 @@ namespace PascalABCCompiler.TreeRealization t = NetHelper.NetHelper.FindType(_name+"."+_name); if (t != null && NetHelper.NetHelper.IsEntryType(t)) { - si = NetHelper.NetHelper.FindName(t,name); + var temp = NetHelper.NetHelper.FindName(t,name); + if (temp != null) + si = temp.ToSymbolInfo(); + else + si = null; if (si == null) { type_node tn = NetHelper.NetHelper.FindCompiledPascalType(_name + "." + name); diff --git a/TreeConverter/TreeRealization/templates.cs b/TreeConverter/TreeRealization/templates.cs index a15e5c2ef..4bfe7a719 100644 --- a/TreeConverter/TreeRealization/templates.cs +++ b/TreeConverter/TreeRealization/templates.cs @@ -63,8 +63,8 @@ namespace PascalABCCompiler.TreeRealization using_namespace_list new_unl = new using_namespace_list(); foreach (using_namespace un in unl) { - SymbolInfo si = netsc.FindOnlyInScope(un.namespace_name); - if ((si.sym_info as compiled_namespace_node) != null) + SymbolInfoList si = netsc.FindOnlyInScope(un.namespace_name); + if ((si.First().sym_info as compiled_namespace_node) != null) { new_unl.AddElement(un); } @@ -479,13 +479,13 @@ namespace PascalABCCompiler.TreeRealization // return rez; //} - public override SymbolInfo find_in_type(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find_in_type(string name, bool no_search_in_extension_methods = false) { indefinite_definition_node idn = new indefinite_definition_node(name, this); - return new SymbolInfo(idn, access_level.al_public, symbol_kind.sk_indefinite); + return new SymbolInfoList(new SymbolInfoUnit(idn, access_level.al_public, symbol_kind.sk_indefinite)); } - public override SymbolInfo find(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find(string name, bool no_search_in_extension_methods = false) { return find_in_type(name); } diff --git a/TreeConverter/TreeRealization/type_table.cs b/TreeConverter/TreeRealization/type_table.cs index 9172eb37d..ffb669f32 100644 --- a/TreeConverter/TreeRealization/type_table.cs +++ b/TreeConverter/TreeRealization/type_table.cs @@ -338,196 +338,196 @@ namespace PascalABCCompiler.TreeRealization } } } - - public static bool is_derived(type_node base_class, type_node derived_class) - { + + public static bool is_derived(type_node base_class,type_node derived_class) + { if (derived_class == null) //void? return false; if (base_class == null) return false; - type_node tn = derived_class.base_type; + type_node tn=derived_class.base_type; //TODO: Проверить на ссылочный и размерный тип. - if (derived_class.semantic_node_type == semantic_node_type.null_type_node) - if (is_with_nil_allowed(base_class) || base_class.IsPointer) - return true; - else - return false; - if (base_class.type_special_kind == SemanticTree.type_special_kind.short_string && derived_class.type_special_kind == SemanticTree.type_special_kind.short_string) return true; - else if (derived_class == SystemLibrary.SystemLibrary.string_type && base_class.type_special_kind == SemanticTree.type_special_kind.short_string) return true; - else if (base_class == SystemLibrary.SystemLibrary.string_type && derived_class.type_special_kind == SemanticTree.type_special_kind.short_string) return true; - if (SystemLibrary.SystemLibInitializer.TypedSetType != null && SystemLibrary.SystemLibInitializer.TypedSetType.Found && + if (derived_class.semantic_node_type == semantic_node_type.null_type_node) + if (is_with_nil_allowed(base_class) || base_class.IsPointer) + return true; + else + return false; + if (base_class.type_special_kind == SemanticTree.type_special_kind.short_string && derived_class.type_special_kind == SemanticTree.type_special_kind.short_string) return true; + else if (derived_class == SystemLibrary.SystemLibrary.string_type && base_class.type_special_kind == SemanticTree.type_special_kind.short_string) return true; + else if (base_class == SystemLibrary.SystemLibrary.string_type && derived_class.type_special_kind == SemanticTree.type_special_kind.short_string) return true; + if (SystemLibrary.SystemLibInitializer.TypedSetType != null && SystemLibrary.SystemLibInitializer.TypedSetType.Found && base_class.type_special_kind == SemanticTree.type_special_kind.set_type && derived_class == SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node ) return true; - if (base_class.type_special_kind == SemanticTree.type_special_kind.set_type && derived_class.type_special_kind == SemanticTree.type_special_kind.set_type) - { - if (base_class.element_type == derived_class.element_type) return true; - type_compare tc = get_table_type_compare(base_class.element_type, derived_class.element_type); - if (tc == type_compare.non_comparable_type) - { - if (base_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) - { - if (derived_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) - { - if (base_class.element_type.base_type == derived_class.element_type.base_type) return true; - tc = get_table_type_compare(base_class.element_type.base_type, derived_class.element_type.base_type); - if (tc == type_compare.non_comparable_type) return false; - type_intersection_node tin = base_class.element_type.base_type.get_type_intersection(derived_class.element_type.base_type); - if (tin == null || tin.this_to_another == null) - { - if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type) - { - if ((derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) - return false; - else return false; - } - else return true; - } - if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type - && (derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) - return false; - return !tin.this_to_another.is_explicit; - } - else - { - if (base_class.element_type.base_type == derived_class.element_type) return true; - tc = get_table_type_compare(base_class.element_type.base_type, derived_class.element_type); - if (tc == type_compare.non_comparable_type) return false; - type_intersection_node tin = base_class.element_type.base_type.get_type_intersection(derived_class.element_type); - if (tin == null || tin.this_to_another == null) - { - if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type) - { - if ((derived_class.element_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type == SystemLibrary.SystemLibrary.float_type)) - return false; - else return false; - } - else return true; - } - if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type - && (derived_class.element_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type == SystemLibrary.SystemLibrary.float_type)) - return false; - return !tin.this_to_another.is_explicit; - } - } - else - if (derived_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) - { - if (base_class.element_type == derived_class.element_type.base_type) return true; - tc = get_table_type_compare(base_class.element_type, derived_class.element_type.base_type); - if (tc == type_compare.non_comparable_type) return false; - type_intersection_node tin = base_class.element_type.get_type_intersection(derived_class.element_type.base_type); - if (tin == null || tin.this_to_another == null) - { - if (base_class.element_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type != SystemLibrary.SystemLibrary.float_type) - { - if ((derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) - return false; - else return false; - } - else return true; - } - if (base_class.element_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type != SystemLibrary.SystemLibrary.float_type - && (derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) - return false; - return !tin.this_to_another.is_explicit; - } - else if (base_class.element_type.type_special_kind == SemanticTree.type_special_kind.short_string && derived_class.element_type == SystemLibrary.SystemLibrary.string_type - || derived_class.element_type.type_special_kind == SemanticTree.type_special_kind.short_string && base_class.element_type == SystemLibrary.SystemLibrary.string_type) - return true; - else return false; - - } - else - { - type_intersection_node tin = base_class.element_type.get_type_intersection(derived_class.element_type); - if (tin == null || tin.this_to_another == null) - { - //proverka na diapasony - if (base_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) - { - if (derived_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) - { - if (base_class.element_type.base_type == derived_class.element_type.base_type) return true; - tc = get_table_type_compare(base_class.element_type.base_type, derived_class.element_type.base_type); - if (tc == type_compare.non_comparable_type) return false; - type_intersection_node tin2 = base_class.element_type.base_type.get_type_intersection(derived_class.element_type.base_type); - if (tin == null || tin.this_to_another == null) - { - if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type) - { - if ((derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) - return false; - else return false; - } - else return true; - } - if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type - && (derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) - return false; - return !tin.this_to_another.is_explicit; - } - else - { - if (base_class.element_type.base_type == derived_class.element_type) return true; - tc = get_table_type_compare(base_class.element_type.base_type, derived_class.element_type); - if (tc == type_compare.non_comparable_type) return false; - type_intersection_node tin2 = base_class.element_type.base_type.get_type_intersection(derived_class.element_type); - if (tin == null || tin.this_to_another == null) - { - if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type) - { - if ((derived_class.element_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type == SystemLibrary.SystemLibrary.float_type)) - return false; - else return false; - } - else return true; - } - if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type - && (derived_class.element_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type == SystemLibrary.SystemLibrary.float_type)) - return false; - return !tin.this_to_another.is_explicit; - } - } - else - if (derived_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) - { - if (base_class.element_type == derived_class.element_type.base_type) return true; - tc = get_table_type_compare(base_class.element_type, derived_class.element_type.base_type); - if (tc == type_compare.non_comparable_type) return false; - type_intersection_node tin2 = base_class.element_type.get_type_intersection(derived_class.element_type.base_type); - if (tin == null || tin.this_to_another == null) - { - if (base_class.element_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type != SystemLibrary.SystemLibrary.float_type) - { - if ((derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) - return false; - else return false; - } - else return true; - } - if (base_class.element_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type != SystemLibrary.SystemLibrary.float_type - && (derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) - return false; - return !tin.this_to_another.is_explicit; - } - if (base_class.element_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type != SystemLibrary.SystemLibrary.float_type) - { - if ((derived_class.element_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type == SystemLibrary.SystemLibrary.float_type)) - return false; - else return false; - } - else return true; - } - return !tin.this_to_another.is_explicit; - } - } + if (base_class.type_special_kind == SemanticTree.type_special_kind.set_type && derived_class.type_special_kind == SemanticTree.type_special_kind.set_type) + { + if (base_class.element_type == derived_class.element_type) return true; + type_compare tc = get_table_type_compare(base_class.element_type,derived_class.element_type); + if (tc == type_compare.non_comparable_type) + { + if (base_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) + { + if (derived_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) + { + if (base_class.element_type.base_type == derived_class.element_type.base_type) return true; + tc = get_table_type_compare(base_class.element_type.base_type,derived_class.element_type.base_type); + if (tc == type_compare.non_comparable_type) return false; + type_intersection_node tin = base_class.element_type.base_type.get_type_intersection(derived_class.element_type.base_type); + if (tin == null || tin.this_to_another == null) + { + if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type) + { + if ((derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) + return false; + else return false; + } + else return true; + } + if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type + && (derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) + return false; + return !tin.this_to_another.is_explicit; + } + else + { + if (base_class.element_type.base_type == derived_class.element_type) return true; + tc = get_table_type_compare(base_class.element_type.base_type,derived_class.element_type); + if (tc == type_compare.non_comparable_type) return false; + type_intersection_node tin = base_class.element_type.base_type.get_type_intersection(derived_class.element_type); + if (tin == null || tin.this_to_another == null) + { + if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type) + { + if ((derived_class.element_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type == SystemLibrary.SystemLibrary.float_type)) + return false; + else return false; + } + else return true; + } + if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type + && (derived_class.element_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type == SystemLibrary.SystemLibrary.float_type)) + return false; + return !tin.this_to_another.is_explicit; + } + } + else + if (derived_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) + { + if (base_class.element_type == derived_class.element_type.base_type) return true; + tc = get_table_type_compare(base_class.element_type,derived_class.element_type.base_type); + if (tc == type_compare.non_comparable_type) return false; + type_intersection_node tin = base_class.element_type.get_type_intersection(derived_class.element_type.base_type); + if (tin == null || tin.this_to_another == null) + { + if (base_class.element_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type != SystemLibrary.SystemLibrary.float_type) + { + if ((derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) + return false; + else return false; + } + else return true; + } + if (base_class.element_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type != SystemLibrary.SystemLibrary.float_type + && (derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) + return false; + return !tin.this_to_another.is_explicit; + } + else if (base_class.element_type.type_special_kind == SemanticTree.type_special_kind.short_string && derived_class.element_type == SystemLibrary.SystemLibrary.string_type + || derived_class.element_type.type_special_kind == SemanticTree.type_special_kind.short_string && base_class.element_type == SystemLibrary.SystemLibrary.string_type) + return true; + else return false; + + } + else + { + type_intersection_node tin = base_class.element_type.get_type_intersection(derived_class.element_type); + if (tin == null || tin.this_to_another == null) + { + //proverka na diapasony + if (base_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) + { + if (derived_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) + { + if (base_class.element_type.base_type == derived_class.element_type.base_type) return true; + tc = get_table_type_compare(base_class.element_type.base_type,derived_class.element_type.base_type); + if (tc == type_compare.non_comparable_type) return false; + type_intersection_node tin2 = base_class.element_type.base_type.get_type_intersection(derived_class.element_type.base_type); + if (tin == null || tin.this_to_another == null) + { + if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type) + { + if ((derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) + return false; + else return false; + } + else return true; + } + if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type + && (derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) + return false; + return !tin.this_to_another.is_explicit; + } + else + { + if (base_class.element_type.base_type == derived_class.element_type) return true; + tc = get_table_type_compare(base_class.element_type.base_type,derived_class.element_type); + if (tc == type_compare.non_comparable_type) return false; + type_intersection_node tin2 = base_class.element_type.base_type.get_type_intersection(derived_class.element_type); + if (tin == null || tin.this_to_another == null) + { + if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type) + { + if ((derived_class.element_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type == SystemLibrary.SystemLibrary.float_type)) + return false; + else return false; + } + else return true; + } + if (base_class.element_type.base_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type.base_type != SystemLibrary.SystemLibrary.float_type + && (derived_class.element_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type == SystemLibrary.SystemLibrary.float_type)) + return false; + return !tin.this_to_another.is_explicit; + } + } + else + if (derived_class.element_type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) + { + if (base_class.element_type == derived_class.element_type.base_type) return true; + tc = get_table_type_compare(base_class.element_type,derived_class.element_type.base_type); + if (tc == type_compare.non_comparable_type) return false; + type_intersection_node tin2 = base_class.element_type.get_type_intersection(derived_class.element_type.base_type); + if (tin == null || tin.this_to_another == null) + { + if (base_class.element_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type != SystemLibrary.SystemLibrary.float_type) + { + if ((derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) + return false; + else return false; + } + else return true; + } + if (base_class.element_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type != SystemLibrary.SystemLibrary.float_type + && (derived_class.element_type.base_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type.base_type == SystemLibrary.SystemLibrary.float_type)) + return false; + return !tin.this_to_another.is_explicit; + } + if (base_class.element_type != SystemLibrary.SystemLibrary.double_type && base_class.element_type != SystemLibrary.SystemLibrary.float_type) + { + if ((derived_class.element_type == SystemLibrary.SystemLibrary.double_type || derived_class.element_type == SystemLibrary.SystemLibrary.float_type)) + return false; + else return false; + } + else return true; + } + return !tin.this_to_another.is_explicit; + } + } //ssyy Рассматриваем случай интерфейса if (base_class.IsInterface) { bool implements = false; type_node tnode = derived_class; - while (!implements && tnode != null && tnode.ImplementingInterfaces != null) + while (!implements && tnode != null && tnode.ImplementingInterfaces!=null) { implements = tnode.ImplementingInterfaces.Contains(base_class); tnode = tnode.base_type; @@ -535,30 +535,30 @@ namespace PascalABCCompiler.TreeRealization return implements; } //\ssyy - + if (base_class.type_special_kind == SemanticTree.type_special_kind.diap_type && derived_class.type_special_kind == SemanticTree.type_special_kind.diap_type) - { - if (base_class.base_type == derived_class.base_type) return true; - type_compare tc = get_table_type_compare(base_class.base_type, derived_class.base_type); - if (tc == type_compare.non_comparable_type) return false; - type_intersection_node tin = base_class.base_type.get_type_intersection(derived_class.base_type); - if (tin == null || tin.this_to_another == null) - { - return false; - } - return !tin.this_to_another.is_explicit; + { + if (base_class.base_type == derived_class.base_type) return true; + type_compare tc = get_table_type_compare(base_class.base_type,derived_class.base_type); + if (tc == type_compare.non_comparable_type) return false; + type_intersection_node tin = base_class.base_type.get_type_intersection(derived_class.base_type); + if (tin == null || tin.this_to_another == null) + { + return false; + } + return !tin.this_to_another.is_explicit; } - - while ((tn != null) && (tn != base_class)) - { - tn = tn.base_type; - } - if (tn == null) - { - return false; - } - return true; - } + + while((tn!=null)&&(tn!=base_class)) + { + tn=tn.base_type; + } + if (tn==null) + { + return false; + } + return true; + } private static type_compare get_table_type_compare_in_specific_order(type_node left, type_node right) { @@ -770,9 +770,9 @@ namespace PascalABCCompiler.TreeRealization null_const_node ncn = new null_const_node(_to, call_location); null_const_node ncn2 = new null_const_node(_to, call_location); - PascalABCCompiler.TreeConverter.SymbolInfo si = pr.type.find_in_type(PascalABCCompiler.TreeConverter.compiler_string_consts.eq_name); + PascalABCCompiler.TreeConverter.SymbolInfoList si = pr.type.find_in_type(PascalABCCompiler.TreeConverter.compiler_string_consts.eq_name); - basic_function_node fn = si.sym_info as basic_function_node; + basic_function_node fn = si.First().sym_info as basic_function_node; expression_node condition = null; if (fn != null) { @@ -781,9 +781,9 @@ namespace PascalABCCompiler.TreeRealization condition_bfc.parameters.AddElement(ncn); condition = condition_bfc; } - else if (si.sym_info is compiled_function_node) + else if (si.First().sym_info is compiled_function_node) { - compiled_static_method_call condition_cfc = new compiled_static_method_call(si.sym_info as compiled_function_node, call_location); + compiled_static_method_call condition_cfc = new compiled_static_method_call(si.First().sym_info as compiled_function_node, call_location); condition_cfc.parameters.AddElement(pr); condition_cfc.parameters.AddElement(ncn); condition = condition_cfc; diff --git a/TreeConverter/TreeRealization/types.cs b/TreeConverter/TreeRealization/types.cs index 61c98e76c..5a0de6e7b 100644 --- a/TreeConverter/TreeRealization/types.cs +++ b/TreeConverter/TreeRealization/types.cs @@ -426,13 +426,20 @@ namespace PascalABCCompiler.TreeRealization return null; } - public abstract SymbolInfo find(string name, bool no_search_in_extension_methods = false); - public virtual SymbolInfo find(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) + public abstract SymbolInfoList find(string name, bool no_search_in_extension_methods = false); + public virtual SymbolInfoList find(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) { return find(name); } - public abstract SymbolInfo find_in_type(string name, bool no_search_in_extension_methods = false); + public abstract SymbolInfoList find_in_type(string name, bool no_search_in_extension_methods = false); public virtual SymbolInfo find_in_type(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) + { + var temp = find_in_type(name); + if (temp != null) + return temp.ToSymbolInfo(); + return null; + } + public virtual SymbolInfoList find_in_type2(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) { return find_in_type(name); } @@ -511,6 +518,8 @@ namespace PascalABCCompiler.TreeRealization return element_type; } } + + } //lroman// @@ -585,7 +594,7 @@ namespace PascalABCCompiler.TreeRealization } } - public override SymbolInfo find(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find(string name, bool no_search_in_extension_methods = false) { return null; } @@ -595,7 +604,7 @@ namespace PascalABCCompiler.TreeRealization } - public override SymbolInfo find_in_type(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find_in_type(string name, bool no_search_in_extension_methods = false) { return null; } @@ -748,12 +757,12 @@ namespace PascalABCCompiler.TreeRealization } } - public override SymbolInfo find(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find(string name, bool no_search_in_extension_methods = false) { return null; } - public override SymbolInfo find_in_type(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find_in_type(string name, bool no_search_in_extension_methods = false) { return null; } @@ -904,21 +913,34 @@ namespace PascalABCCompiler.TreeRealization get { return name; } } - public override SymbolInfo find(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find(string name, bool no_search_in_extension_methods = false) { - return find_in_additional_names(name); + var temp = find_in_additional_names(name); + if (temp != null) + return new SymbolInfoList(temp); + return null; } - public override SymbolInfo find_in_type(string name, bool no_search_in_extension_methods = false) - { - return find_in_additional_names(name); - } - + public override SymbolInfoList find_in_type(string name, bool no_search_in_extension_methods = false) + { + var temp = find_in_additional_names(name); + if (temp != null) + return new SymbolInfoList(temp); + return null; + } + public override SymbolInfo find_in_type(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) { return find_in_additional_names(name); - } - + } + public override SymbolInfoList find_in_type2(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) + { + var temp = find_in_additional_names(name); + if (temp != null) + return new SymbolInfoList(temp); + return null; + } + public override SemanticTree.node_kind node_kind { get @@ -1544,9 +1566,9 @@ namespace PascalABCCompiler.TreeRealization basic_function_node _int_and = SystemLibrary.SystemLibrary.make_binary_operator(compiler_string_consts.and_name, this, SemanticTree.basic_function_type.iand); basic_function_node _int_or = SystemLibrary.SystemLibrary.make_binary_operator(compiler_string_consts.or_name, this, SemanticTree.basic_function_type.ior); basic_function_node _int_xor = SystemLibrary.SystemLibrary.make_binary_operator(compiler_string_consts.xor_name, this, SemanticTree.basic_function_type.ixor); - scope.AddSymbol(compiler_string_consts.and_name, new SymbolInfo(_int_and)); - scope.AddSymbol(compiler_string_consts.or_name, new SymbolInfo(_int_or)); - scope.AddSymbol(compiler_string_consts.xor_name, new SymbolInfo(_int_xor)); + scope.AddSymbol(compiler_string_consts.and_name, new SymbolInfoUnit(_int_and)); + scope.AddSymbol(compiler_string_consts.or_name, new SymbolInfoUnit(_int_or)); + scope.AddSymbol(compiler_string_consts.xor_name, new SymbolInfoUnit(_int_xor)); } public common_property_node default_property @@ -1873,61 +1895,54 @@ namespace PascalABCCompiler.TreeRealization this._name = name; } - public override SymbolInfo find(string name, bool no_search_in_extension_methods = false) - { - return Scope.Find(name,null);//int,:= - } + public override SymbolInfoList find(string name, bool no_search_in_extension_methods = false) + { + return Scope.Find(name, null);//int,:= + } - public override SymbolInfo find(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) + public override SymbolInfoList find(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) { return Scope.Find(name, CurrentScope);//int,:= } - public override SymbolInfo find_in_type(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find_in_type(string name, bool no_search_in_extension_methods = false) { return Scope.FindOnlyInType(name, null);//:=,create,x } public override SymbolInfo find_in_type(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) { - SymbolInfo si = Scope.FindOnlyInType(name, CurrentScope);//:=,create,x + SymbolInfoList si = Scope.FindOnlyInType(name, CurrentScope);//:=,create,x if (si == null && base_type is compiled_type_node && string.Compare(name,"create",true) != 0) { - si = (base_type as compiled_type_node).find_in_type(name, CurrentScope); + var temp = (base_type as compiled_type_node).find_in_type(name, CurrentScope); + if (temp != null) + si = new SymbolInfoList(temp); + else + si = null; } if (this.is_generic_parameter && si != null) { - SymbolInfo tmp = si; //удаляем повторяющиеся символы - while (tmp != null) + for(int i = 0; i < si.InfoUnitList.Count; ++i) { - SymbolInfo p = tmp; - SymbolInfo s = tmp.Next; - while (s != null) + for (int j = i + 1; j < si.InfoUnitList.Count; ++j) { - if (tmp.sym_info == s.sym_info) + if (si.InfoUnitList[i].sym_info == si.InfoUnitList[j].sym_info) { - //удаляем s - p.Next = s.Next; + si.InfoUnitList.RemoveAt(j); + --j; } - else - { - p = s; - } - s = s.Next; } - tmp = tmp.Next; } - tmp = si; //конвертируем - while (tmp != null) + int index = 0; + while(index < si.InfoUnitList.Count) { - SemanticTree.IClassMemberNode imn = si.sym_info as SemanticTree.IClassMemberNode; + SemanticTree.IClassMemberNode imn = si.First().sym_info as SemanticTree.IClassMemberNode; if (imn != null && imn.comperehensive_type.IsInterface && imn.comperehensive_type.is_generic_type_definition) { - SymbolInfo start = new SymbolInfo(); - start.Next = null; - SymbolInfo cur = start; + SymbolInfoList start = new SymbolInfoList(); foreach (type_node interf in ImplementingInterfaces) { generic_instance_type_node gitn = interf as generic_instance_type_node; @@ -1935,30 +1950,24 @@ namespace PascalABCCompiler.TreeRealization continue; if (interf.original_generic == imn.comperehensive_type) { - definition_node dn = gitn.ConvertMember(tmp.sym_info); - SymbolInfo new_si = new SymbolInfo(dn, tmp.access_level, tmp.symbol_kind); - new_si.Next = null; - cur.Next = new_si; - cur = new_si; + definition_node dn = gitn.ConvertMember(si.InfoUnitList[index].sym_info); + SymbolInfoUnit new_si = new SymbolInfoUnit(dn, si.InfoUnitList[index].access_level, si.InfoUnitList[index].symbol_kind); + start.Add(new_si); } } - if (start.Next != null) + if(start.InfoUnitList.Count > 0) { - tmp.sym_info = start.Next.sym_info; - if (start.Next.Next != null) - { - SymbolInfo s = tmp.Next; - tmp.Next = start.Next.Next; - start.Next.Next.Next = s; - } + si.InfoUnitList[index].sym_info = start.First().sym_info; + if(start.InfoUnitList.Count > 1) + si.InfoUnitList.Insert(index + 1, start.InfoUnitList[1]); } } - tmp = tmp.Next; + ++index; } } if (this.base_generic_instance != null && si != null) { - return base_generic_instance.ConvertSymbolInfo(si); + return base_generic_instance.ConvertSymbolInfo(si.ToSymbolInfo()); } else if (si == null) { @@ -1966,17 +1975,103 @@ namespace PascalABCCompiler.TreeRealization { foreach (type_node ii_tn in ImplementingInterfaces) { - si = ii_tn.find_in_type(name, CurrentScope); + var temp = ii_tn.find_in_type(name, CurrentScope); + if (temp != null) + si = new SymbolInfoList(temp); + else + si = null; + if (si != null) + return si.ToSymbolInfo(); + } + } + } + if(si != null) + return si.ToSymbolInfo(); + return null; + } + public override SymbolInfoList find_in_type2(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) + { + SymbolInfoList si = Scope.FindOnlyInType(name, CurrentScope);//:=,create,x + if (si == null && base_type is compiled_type_node && string.Compare(name, "create", true) != 0) + { + var temp = (base_type as compiled_type_node).find_in_type(name, CurrentScope); + if (temp != null) + si = new SymbolInfoList(temp); + else + si = null; + } + if (this.is_generic_parameter && si != null) + { + //удаляем повторяющиеся символы + for (int i = 0; i < si.InfoUnitList.Count; ++i) + { + for (int j = i + 1; j < si.InfoUnitList.Count; ++j) + { + if (si.InfoUnitList[i].sym_info == si.InfoUnitList[j].sym_info) + { + si.InfoUnitList.RemoveAt(j); + --j; + } + } + } + //конвертируем + int index = 0; + while (index < si.InfoUnitList.Count) + { + SemanticTree.IClassMemberNode imn = si.First().sym_info as SemanticTree.IClassMemberNode; + if (imn != null && imn.comperehensive_type.IsInterface && imn.comperehensive_type.is_generic_type_definition) + { + SymbolInfoList start = new SymbolInfoList(); + foreach (type_node interf in ImplementingInterfaces) + { + generic_instance_type_node gitn = interf as generic_instance_type_node; + if (gitn == null) + continue; + if (interf.original_generic == imn.comperehensive_type) + { + definition_node dn = gitn.ConvertMember(si.InfoUnitList[index].sym_info); + SymbolInfoUnit new_si = new SymbolInfoUnit(dn, si.InfoUnitList[index].access_level, si.InfoUnitList[index].symbol_kind); + start.Add(new_si); + } + } + if (start.InfoUnitList.Count > 0) + { + si.InfoUnitList[index].sym_info = start.First().sym_info; + if (start.InfoUnitList.Count > 1) + si.InfoUnitList.Insert(index + 1, start.InfoUnitList[1]); + } + } + ++index; + } + } + if (this.base_generic_instance != null && si != null) + { + var tmp = base_generic_instance.ConvertSymbolInfo(si.ToSymbolInfo()); + if (tmp != null) + return new SymbolInfoList(tmp); + return null; + } + else if (si == null) + { + if (ImplementingInterfaces != null) + { + foreach (type_node ii_tn in ImplementingInterfaces) + { + var temp = ii_tn.find_in_type(name, CurrentScope); + if (temp != null) + si = new SymbolInfoList(temp); + else + si = null; if (si != null) return si; } } } return si; - } + } //(ssyy) Они нигде не используются - /*public SymbolInfo find_in_comprehensive_scope(string name) + /*public SymbolInfo find_in_comprehensive_scope(string name) { //TODO: Как это сделать. Спросить у Саши. return _scope.Find(name); @@ -1989,11 +2084,11 @@ namespace PascalABCCompiler.TreeRealization public override void add_name(string name, PascalABCCompiler.TreeConverter.SymbolInfo si) { - scope.AddSymbol(name, si); + scope.AddSymbol(name, new SymbolInfoUnit(si)); } public override void add_generated_name(string name, PascalABCCompiler.TreeConverter.SymbolInfo si) { - scope.AddSymbol(name, si); + scope.AddSymbol(name, new SymbolInfoUnit(si)); } /// @@ -2133,14 +2228,14 @@ namespace PascalABCCompiler.TreeRealization public override function_node get_implicit_conversion_to(type_node ctn) { - SymbolInfo si = this.find_in_type(compiler_string_consts.implicit_operator_name); + SymbolInfoList si = this.find_in_type(compiler_string_consts.implicit_operator_name); if (si != null) { function_node fn = null; - while (si != null) + foreach(var si_unit in si.InfoUnitList) { - fn = si.sym_info as function_node; - if (fn != null && type_table.is_type_or_original_generics_equal(fn.return_value_type, ctn) && type_table.is_type_or_original_generics_equal(fn.parameters[0].type, this)) + fn = si_unit.sym_info as function_node; + if (fn != null && type_table.is_type_or_original_generics_equal(fn.return_value_type, ctn) && type_table.is_type_or_original_generics_equal(fn.parameters[0].type, this)) { if (fn.is_generic_function) { @@ -2154,8 +2249,7 @@ namespace PascalABCCompiler.TreeRealization } } return fn; - } - si = si.Next; + } } return null; } @@ -2165,13 +2259,13 @@ namespace PascalABCCompiler.TreeRealization public override function_node get_implicit_conversion_from(type_node ctn) { - SymbolInfo si = this.find_in_type(compiler_string_consts.implicit_operator_name); + SymbolInfoList si = this.find_in_type(compiler_string_consts.implicit_operator_name); if (si != null) { function_node fn = null; - while (si != null) + foreach(var si_unit in si.InfoUnitList) { - fn = si.sym_info as function_node; + fn = si_unit.sym_info as function_node; if (fn != null && fn.parameters.Count == 1 && type_table.is_type_or_original_generics_equal(fn.parameters[0].type, ctn) && type_table.is_type_or_original_generics_equal(fn.return_value_type, this)) { if (fn.is_generic_function) @@ -2187,7 +2281,6 @@ namespace PascalABCCompiler.TreeRealization } return fn; } - si = si.Next; } return null; } @@ -2196,16 +2289,15 @@ namespace PascalABCCompiler.TreeRealization public override function_node get_explicit_conversion_to(type_node ctn) { - SymbolInfo si = this.find_in_type(compiler_string_consts.explicit_operator_name); + SymbolInfoList si = this.find_in_type(compiler_string_consts.explicit_operator_name); if (si != null) { function_node fn = null; - while (si != null) + foreach(var si_unit in si.InfoUnitList) { - fn = si.sym_info as function_node; + fn = si_unit.sym_info as function_node; if (fn != null && fn.return_value_type == ctn) return fn; - si = si.Next; } return null; } @@ -2215,16 +2307,15 @@ namespace PascalABCCompiler.TreeRealization public override function_node get_explicit_conversion_from(type_node ctn) { - SymbolInfo si = this.find_in_type(compiler_string_consts.explicit_operator_name); + SymbolInfoList si = this.find_in_type(compiler_string_consts.explicit_operator_name); if (si != null) { function_node fn = null; - while (si != null) + foreach(var si_unit in si.InfoUnitList) { - fn = si.sym_info as function_node; - if (fn != null && fn.parameters.Count == 1 && fn.parameters[0].type == ctn) - return fn; - si = si.Next; + fn = si_unit.sym_info as function_node; + if (fn != null && fn.parameters.Count == 1 && fn.parameters[0].type == ctn) + return fn; } return null; } @@ -2320,11 +2411,11 @@ namespace PascalABCCompiler.TreeRealization this.type_special_kind = SemanticTree.type_special_kind.short_string; } - public override SymbolInfo find(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find(string name, bool no_search_in_extension_methods = false) { //return this.find_in_additional_names(name); return _scope.Find(name); - } + } public property_node default_property { get { return _default_property_node; } @@ -2401,31 +2492,50 @@ namespace PascalABCCompiler.TreeRealization public override void add_name(string name, SymbolInfo si) { - _scope.AddSymbol(name, si); + _scope.AddSymbol(name, new SymbolInfoUnit(si)); } public override void add_generated_name(string name, SymbolInfo si) { - _scope.AddSymbol(name, si); + _scope.AddSymbol(name, new SymbolInfoUnit(si)); } - public override SymbolInfo find_in_type(string name, bool no_search_in_extension_methods = false) - { - //return this.find_in_additional_names(name) + public override SymbolInfoList find_in_type(string name, bool no_search_in_extension_methods = false) + { + //return this.find_in_additional_names(name) //SymbolInfo si = _scope.FindOnlyInType(name, null); //if (name ) - if (name == compiler_string_consts.assign_name || name == compiler_string_consts.plusassign_name) return _scope.FindOnlyInType(name, null); + if (name == compiler_string_consts.assign_name || name == compiler_string_consts.plusassign_name) + return _scope.FindOnlyInType(name, null); return SystemLibrary.SystemLibrary.string_type.find_in_type(name); - } + } public override SymbolInfo find_in_type(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) { //return this.find_in_additional_names(name); - //SymbolInfo si = _scope.FindOnlyInType(name, CurrentScope); - if (name == compiler_string_consts.assign_name || name == compiler_string_consts.plusassign_name) return _scope.FindOnlyInType(name, null); - return SystemLibrary.SystemLibrary.string_type.find_in_type(name); + //SymbolInfo si = _scope.FindOnlyInType(name, CurrentScope); + if (name == compiler_string_consts.assign_name || name == compiler_string_consts.plusassign_name) { + var temp = _scope.FindOnlyInType(name, null); + if (temp != null) + return temp.ToSymbolInfo(); + return null; + } + var tmp = SystemLibrary.SystemLibrary.string_type.find_in_type(name); + if (tmp != null) + return tmp.ToSymbolInfo(); + return null; } - + public override SymbolInfoList find_in_type2(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) + { + //return this.find_in_additional_names(name); + //SymbolInfo si = _scope.FindOnlyInType(name, CurrentScope); + if (name == compiler_string_consts.assign_name || name == compiler_string_consts.plusassign_name) + { + return _scope.FindOnlyInType(name, null); + } + return SystemLibrary.SystemLibrary.string_type.find_in_type(name); + } + public override string PrintableName { get @@ -2839,22 +2949,22 @@ namespace PascalABCCompiler.TreeRealization { if (base_type == SystemLibrary.SystemLibrary.delegate_base_type) { - SymbolInfo si_int = this.find_in_type(compiler_string_consts.invoke_method_name); + SymbolInfoList si_int = this.find_in_type(compiler_string_consts.invoke_method_name); #if DEBUG if (si_int == null) { throw new CompilerInternalError("No invoke method in class derived from MulticastDelegate"); } #endif - compiled_function_node invoke = si_int.sym_info as compiled_function_node; + compiled_function_node invoke = si_int.First().sym_info as compiled_function_node; #if DEBUG if (invoke == null) { throw new CompilerInternalError("No invoke method in class derived from MulticastDelegate"); } #endif - SymbolInfo si_cons = this.find_in_type(compiler_string_consts.net_constructor_name); - compiled_constructor_node ctor = si_cons.sym_info as compiled_constructor_node; + SymbolInfoList si_cons = this.find_in_type(compiler_string_consts.net_constructor_name); + compiled_constructor_node ctor = si_cons.First().sym_info as compiled_constructor_node; #if DEBUG if (ctor == null) { @@ -2937,9 +3047,9 @@ namespace PascalABCCompiler.TreeRealization basic_function_node _int_xor = SystemLibrary.SystemLibrary.make_binary_operator(compiler_string_consts.xor_name, ctn, SemanticTree.basic_function_type.ixor); if (ctn.scope != null) { - ctn.scope.AddSymbol(compiler_string_consts.and_name, new SymbolInfo(_int_and)); - ctn.scope.AddSymbol(compiler_string_consts.or_name, new SymbolInfo(_int_or)); - ctn.scope.AddSymbol(compiler_string_consts.xor_name, new SymbolInfo(_int_xor)); + ctn.scope.AddSymbol(compiler_string_consts.and_name, new SymbolInfoUnit(_int_and)); + ctn.scope.AddSymbol(compiler_string_consts.or_name, new SymbolInfoUnit(_int_or)); + ctn.scope.AddSymbol(compiler_string_consts.xor_name, new SymbolInfoUnit(_int_xor)); } } @@ -3169,20 +3279,30 @@ namespace PascalABCCompiler.TreeRealization //(ssyy) 24.10.2007. Эта функция работает неверно, возвращая дважды найденную функцию. //Попытался написать правильно. - public override SymbolInfo find(string name, bool no_search_in_extension_methods = false) - { + public override SymbolInfoList find(string name, bool no_search_in_extension_methods = false) + { + /*//Старый код + SymbolInfo si = AddToSymbolInfo(compiled_find(name), find_in_additional_names(name)); + if(scope!=null) + si = AddToSymbolInfo(si, scope.SymbolTable.Find(scope,name)); + return si; + */ if (this.type_special_kind == SemanticTree.type_special_kind.array_kind && scope == null) this.init_scope(); if (scope == null) { SymbolInfo si = compiled_find(name); SymbolInfo si2 = find_in_additional_names(name); - if (si == null && si2 == null && string.Compare(name,"Create",true) != 0) + if (si == null && si2 == null && string.Compare(name, "Create", true) != 0) { compiled_type_node bas_type = base_type as compiled_type_node; while (si == null && bas_type != null && bas_type.scope != null) { - si = bas_type.scope.SymbolTable.Find(bas_type.scope, name); + var temp = bas_type.scope.SymbolTable.Find(bas_type.scope, name); + if (temp != null) + si = temp.ToSymbolInfo(); + else + si = null; bas_type = bas_type.base_type as compiled_type_node; } if (si == null) @@ -3193,33 +3313,44 @@ namespace PascalABCCompiler.TreeRealization if (ctn.is_generic_type_instance) ctn = ctn.original_generic as compiled_type_node; if (ctn != null && ctn.scope != null) - si = ctn.scope.SymbolTable.Find(ctn.scope, name); + { + var temp = ctn.scope.SymbolTable.Find(ctn.scope, name); + if (temp != null) + si = temp.ToSymbolInfo(); + else + si = null; + } if (si != null) break; } } } - return AddToSymbolInfo(si, si2); + return new SymbolInfoList(AddToSymbolInfo(si, si2)); } else { - SymbolInfo si = scope.SymbolTable.Find(scope, name); + SymbolInfo si; + var temp = scope.SymbolTable.Find(scope, name); + if (temp != null) + si = temp.ToSymbolInfo(); + else + si = null; SymbolInfo si2 = find_in_additional_names(name); SymbolInfo si3 = compiled_find(name); bool clone = false; - if (!no_search_in_extension_methods || this._compiled_type.IsGenericType) + if (!no_search_in_extension_methods) { - + if (this.type_special_kind == SemanticTree.type_special_kind.array_kind && this.base_type.Scope != null) { - SymbolInfo tmp_si = this.base_type.Scope.SymbolTable.Find(this.base_type.Scope, name); + SymbolInfoList tmp_si = this.base_type.Scope.SymbolTable.Find(this.base_type.Scope, name); if (tmp_si != null) { if (si == null) - si = tmp_si; - else if (si.sym_info != tmp_si.sym_info) - si = AddToSymbolInfo(tmp_si, si, true); + si = tmp_si.ToSymbolInfo(); + else if (si.sym_info != tmp_si.ToSymbolInfo().sym_info) + si = AddToSymbolInfo(tmp_si.ToSymbolInfo(), si, true); clone = true; } } @@ -3228,13 +3359,13 @@ namespace PascalABCCompiler.TreeRealization compiled_type_node ctn = compiled_type_node.get_type_node(this.compiled_type.GetGenericTypeDefinition()); if (ctn.scope != null) { - SymbolInfo tmp_si = ctn.scope.SymbolTable.Find(ctn.scope, name); - if (tmp_si != null && tmp_si.sym_info is function_node && (tmp_si.sym_info as function_node).is_extension_method) + SymbolInfoList tmp_si = ctn.scope.SymbolTable.Find(ctn.scope, name); + if (tmp_si != null && tmp_si.ToSymbolInfo().sym_info is function_node && (tmp_si.ToSymbolInfo().sym_info as function_node).is_extension_method) { if (si == null) - si = tmp_si; - else if (si.sym_info != tmp_si.sym_info) - si = AddToSymbolInfo(si, tmp_si, true); + si = tmp_si.ToSymbolInfo(); + else if (si.sym_info != tmp_si.ToSymbolInfo().sym_info) + si = AddToSymbolInfo(si, tmp_si.ToSymbolInfo(), true); clone = true; } } @@ -3246,15 +3377,15 @@ namespace PascalABCCompiler.TreeRealization } while (bas_type != null && bas_type.scope != null) { - SymbolInfo tmp_si = bas_type.scope.SymbolTable.Find(bas_type.scope, name); - if (tmp_si != null && tmp_si.sym_info is function_node && (tmp_si.sym_info as function_node).is_extension_method) + SymbolInfoList tmp_si = bas_type.scope.SymbolTable.Find(bas_type.scope, name); + if (tmp_si != null && tmp_si.ToSymbolInfo().sym_info is function_node && (tmp_si.ToSymbolInfo().sym_info as function_node).is_extension_method) { if (si == null) - si = tmp_si; + si = tmp_si.ToSymbolInfo(); else { - if (si.sym_info != tmp_si.sym_info) - si = AddToSymbolInfo(si, tmp_si, true); + if (si.sym_info != tmp_si.ToSymbolInfo().sym_info) + si = AddToSymbolInfo(si, tmp_si.ToSymbolInfo(), true); } clone = true; } @@ -3267,15 +3398,15 @@ namespace PascalABCCompiler.TreeRealization ctn = ctn.original_generic as compiled_type_node; if (ctn != null && ctn.scope != null) { - SymbolInfo tmp_si = ctn.scope.SymbolTable.Find(ctn.scope, name); - if (tmp_si != null && tmp_si.sym_info is function_node && (tmp_si.sym_info as function_node).is_extension_method) + SymbolInfoList tmp_si = ctn.scope.SymbolTable.Find(ctn.scope, name); + if (tmp_si != null && tmp_si.ToSymbolInfo().sym_info is function_node && (tmp_si.ToSymbolInfo().sym_info as function_node).is_extension_method) { if (si == null) - si = tmp_si; + si = tmp_si.ToSymbolInfo(); else { - if (si.sym_info != tmp_si.sym_info) - si = AddToSymbolInfo(si, tmp_si, true); + if (si.sym_info != tmp_si.ToSymbolInfo().sym_info) + si = AddToSymbolInfo(si, tmp_si.ToSymbolInfo(), true); } clone = true; } @@ -3291,55 +3422,59 @@ namespace PascalABCCompiler.TreeRealization } else if (si3 != null) si = si3; - + if (si == null && si2 == null && this == SystemLibrary.SystemLibrary.string_type && SystemLibrary.SystemLibrary.syn_visitor.from_pabc_dll) { - si = compiled_type_node.get_type_node(NetHelper.NetHelper.PABCSystemType).find_in_type(name); + var si_su_tmp = compiled_type_node.get_type_node(NetHelper.NetHelper.PABCSystemType).find_in_type(name); + if (si_su_tmp != null) + si = si_su_tmp.ToSymbolInfo(); + else + si = null; } - return AddToSymbolInfo(si, si2, clone); + var temp_l = AddToSymbolInfo(si, si2, clone); + if (temp_l != null) + return new SymbolInfoList(temp_l); + return null; } - } + } + + public override SymbolInfoList find_in_type(string name, bool no_search_in_extension_methods = false) + { + return find(name, no_search_in_extension_methods); + } - public override SymbolInfo find_in_type(string name, bool no_search_in_extension_methods = false) - { - return find(name, no_search_in_extension_methods); - } - public override SymbolInfo find_in_type(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) { //return find(name); - SymbolInfo result = find(name, no_search_in_extension_methods); + SymbolInfoList result = find(name, no_search_in_extension_methods); //Поищем также среди extentions-методов. if (is_generic_type_instance) { - SymbolInfo ext = original_generic.find_in_type(name); - SymbolInfo start = null; - SymbolInfo current = null; - while (ext != null) + SymbolInfoList ext = original_generic.find_in_type(name); + SymbolInfoList start = null; + if (ext != null) { - SymbolInfo tmp = ext; - if (ext == result) + foreach (var ext_unit in ext.InfoUnitList) { - ext = ext.Next; - continue; - } - ext = ext.Next; - if (tmp.sym_info is wrapped_definition_node) - BasePCUReader.RestoreSymbols(tmp, name); - if (tmp.sym_info is common_namespace_function_node) - { - if (start == null) + SymbolInfoList tmp = new SymbolInfoList(); + int cur_index = ext.InfoUnitList.IndexOf(ext_unit); + tmp.InfoUnitList = ext.InfoUnitList.GetRange(cur_index, ext.InfoUnitList.Count - cur_index); //!!! + if (ext == result) + continue; + if (tmp.First().sym_info is wrapped_definition_node) + BasePCUReader.RestoreSymbols(tmp, name); + if (tmp.First().sym_info is common_namespace_function_node) { - start = tmp; - if (result != null) - result.Next = start; + if (start == null) + { + start = tmp; + if (result != null) + { + result.InfoUnitList.RemoveRange(1, result.InfoUnitList.Count - 1); + result.Add(start); + } + } } - else - { - current.Next = tmp; - } - tmp.Next = null; - current = tmp; } } //Построили список extentions-методов. Теперь сольём его с основным списком. @@ -3349,45 +3484,115 @@ namespace PascalABCCompiler.TreeRealization } else { - current = result; - List si_lst = new List(); + List si_lst = new List(); List lst = new List(); - while (current != null) + foreach(var current_unit in result.InfoUnitList) { - lst.Add(current.sym_info); + lst.Add(current_unit.sym_info); //si_lst.Add(current); - current = current.Next; } - current = result; - while (current != null) + foreach(var current_unit in result.InfoUnitList) { - if (!lst.Contains(current.sym_info)) + if (!lst.Contains(current_unit.sym_info)) { - lst.Add(current.sym_info); - si_lst.Add(current); + lst.Add(current_unit.sym_info); + si_lst.Add(current_unit); } - current = current.Next; } if (si_lst.Count > 0) - result.Next = si_lst[0]; - for (int i = 0; i < si_lst.Count-1; i++) { - si_lst[i].Next = si_lst[i + 1]; + result.InfoUnitList.RemoveRange(1, result.InfoUnitList.Count - 1); + for (int i = 0; i < si_lst.Count; i++) + { + result.Add(si_lst[i]); + } + } + } + } + if(result != null) + return result.ToSymbolInfo(); + return null; + } + public override SymbolInfoList find_in_type2(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) + { + //return find(name); + SymbolInfoList result = find(name, no_search_in_extension_methods); + //Поищем также среди extentions-методов. + if (is_generic_type_instance) + { + SymbolInfoList ext = original_generic.find_in_type(name); + SymbolInfoList start = null; + if (ext != null) + { + foreach (var ext_unit in ext.InfoUnitList) + { + SymbolInfoList tmp = new SymbolInfoList(); + int cur_index = ext.InfoUnitList.IndexOf(ext_unit); + tmp.InfoUnitList = ext.InfoUnitList.GetRange(cur_index, ext.InfoUnitList.Count - cur_index); //!!! + if (ext == result) + continue; + if (tmp.First().sym_info is wrapped_definition_node) + BasePCUReader.RestoreSymbols(tmp, name); + if (tmp.First().sym_info is common_namespace_function_node) + { + if (start == null) + { + start = tmp; + if (result != null) + { + result.InfoUnitList.RemoveRange(1, result.InfoUnitList.Count - 1); + result.Add(start); + } + } + } + } + } + //Построили список extentions-методов. Теперь сольём его с основным списком. + if (result == null) + { + result = start; + } + else + { + List si_lst = new List(); + List lst = new List(); + foreach (var current_unit in result.InfoUnitList) + { + lst.Add(current_unit.sym_info); + //si_lst.Add(current); + } + + foreach (var current_unit in result.InfoUnitList) + { + if (!lst.Contains(current_unit.sym_info)) + { + lst.Add(current_unit.sym_info); + si_lst.Add(current_unit); + } + } + if (si_lst.Count > 0) + { + result.InfoUnitList.RemoveRange(1, result.InfoUnitList.Count - 1); + for (int i = 0; i < si_lst.Count; i++) + { + result.Add(si_lst[i]); + } } } } return result; } - + private SymbolInfo compiled_find(string name) { - SymbolInfo si=null; - si = PascalABCCompiler.NetHelper.NetHelper.FindName(_compiled_type, name); - return si; + var temp = PascalABCCompiler.NetHelper.NetHelper.FindName(_compiled_type, name); + if(temp != null) + return temp.ToSymbolInfo(); + return null; } - public override semantic_node_type semantic_node_type + public override semantic_node_type semantic_node_type { get { @@ -3664,11 +3869,11 @@ namespace PascalABCCompiler.TreeRealization } } - public override SymbolInfo find(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find(string name, bool no_search_in_extension_methods = false) { //return this.find_in_additional_names(name); return _scope.Find(name); - } + } public override string name { @@ -3727,18 +3932,26 @@ namespace PascalABCCompiler.TreeRealization } } - public override SymbolInfo find_in_type(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find_in_type(string name, bool no_search_in_extension_methods = false) { //return this.find_in_additional_names(name); return _scope.FindOnlyInType(name, null); } public override SymbolInfo find_in_type(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) + { + //return this.find_in_additional_names(name); + var temp = _scope.FindOnlyInType(name, CurrentScope); + if (temp != null) + return temp.ToSymbolInfo(); + return null; + } + public override SymbolInfoList find_in_type2(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) { //return this.find_in_additional_names(name); return _scope.FindOnlyInType(name, CurrentScope); } - + public override void visit(SemanticTree.ISemanticVisitor visitor) { visitor.visit(this); @@ -3971,24 +4184,31 @@ namespace PascalABCCompiler.TreeRealization } } - public override SymbolInfo find(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find(string name, bool no_search_in_extension_methods = false) { return null; } public override void add_name(string name, SymbolInfo si) { - _scope.AddSymbol(name, si); + _scope.AddSymbol(name, new SymbolInfoUnit(si)); } - public override SymbolInfo find_in_type(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find_in_type(string name, bool no_search_in_extension_methods = false) { - return _scope.FindOnlyInScope(name); + return _scope.FindOnlyInScope(name); } public override SymbolInfo find_in_type(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) { - return _scope.FindOnlyInScope(name); + var temp = _scope.FindOnlyInScope(name); + if (temp != null) + return temp.ToSymbolInfo(); + return null; + } + public override SymbolInfoList find_in_type2(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) + { + return _scope.FindOnlyInScope(name); } public override bool is_value @@ -4185,8 +4405,7 @@ namespace PascalABCCompiler.TreeRealization return (new convert_types_function_node(cftfc2.compile_time_executor, false)); } else if (fn.simple_function_node.parameters.Count == 1 && fn.simple_function_node.parameters[0].default_value != null || - (fn.simple_function_node is common_namespace_function_node && (fn.simple_function_node as common_namespace_function_node).ConnectedToType != null - || fn.simple_function_node is compiled_function_node && (fn.simple_function_node as compiled_function_node).ConnectedToType != null) + (fn.simple_function_node is common_namespace_function_node && (fn.simple_function_node as common_namespace_function_node).ConnectedToType != null || fn.simple_function_node is compiled_function_node && (fn.simple_function_node as compiled_function_node).ConnectedToType != null) && fn.simple_function_node.parameters.Count == 2 && fn.simple_function_node.parameters[1].default_value != null) { int param_num = (fn.simple_function_node is common_namespace_function_node && (fn.simple_function_node as common_namespace_function_node).ConnectedToType != null || fn.simple_function_node is compiled_function_node && (fn.simple_function_node as compiled_function_node).ConnectedToType != null) ? 1 : 0; @@ -4412,32 +4631,39 @@ namespace PascalABCCompiler.TreeRealization } } - public override SymbolInfo find(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find(string name, bool no_search_in_extension_methods = false) { return find_in_type(name); } - public override SymbolInfo find_in_type(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find_in_type(string name, bool no_search_in_extension_methods = false) { if (name != compiler_string_consts.plusassign_name && name != compiler_string_consts.minusassign_name) - foreach (base_function_call fn in _proper_methods) - { - if (fn.simple_function_node.parameters.Count == 0) + foreach (base_function_call fn in _proper_methods) { - if (fn.simple_function_node.return_value_type != null) + if (fn.simple_function_node.parameters.Count == 0) { - return fn.simple_function_node.return_value_type.find_in_type(name); + if (fn.simple_function_node.return_value_type != null) + { + return fn.simple_function_node.return_value_type.find_in_type(name); + } } } - } return compiled_type_node.get_type_node(typeof(Delegate)).find(name); //return null; } public override SymbolInfo find_in_type(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) + { + var temp = find_in_type(name); + if (temp != null) + return temp.ToSymbolInfo(); + return null; + } + public override SymbolInfoList find_in_type2(string name, SymbolTable.Scope CurrentScope, bool no_search_in_extension_methods = false) { return find_in_type(name); } - + public override bool is_class { get @@ -4708,12 +4934,12 @@ namespace PascalABCCompiler.TreeRealization get { return SemanticTree.node_kind.basic; } } - public override SymbolInfo find(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find(string name, bool no_search_in_extension_methods = false) { return null; } - public override SymbolInfo find_in_type(string name, bool no_search_in_extension_methods = false) + public override SymbolInfoList find_in_type(string name, bool no_search_in_extension_methods = false) { return null; } diff --git a/TreeConverter/TreeRealization/units.cs b/TreeConverter/TreeRealization/units.cs index 58549c4e1..741df2fdb 100644 --- a/TreeConverter/TreeRealization/units.cs +++ b/TreeConverter/TreeRealization/units.cs @@ -70,7 +70,10 @@ namespace PascalABCCompiler.TreeRealization public override PascalABCCompiler.TreeConverter.SymbolInfo find_only_in_namespace(string name) { - return _dotNetScope.Find(name); + var temp = _dotNetScope.Find(name); + if (temp != null) + return temp.ToSymbolInfo(); + return null; } } @@ -145,7 +148,7 @@ namespace PascalABCCompiler.TreeRealization public void add_unit_name_to_namespace() { - this.scope.AddSymbol(unit_name, new TreeConverter.SymbolInfo(this)); + this.scope.AddSymbol(unit_name, new TreeConverter.SymbolInfoUnit(this)); } public string unit_name @@ -236,7 +239,10 @@ namespace PascalABCCompiler.TreeRealization public override PascalABCCompiler.TreeConverter.SymbolInfo find_only_in_namespace(string name) { - return _scope.FindOnlyInScope(name); + var temp = _scope.FindOnlyInScope(name); + if (temp != null) + return temp.ToSymbolInfo(); + return null; } }