public static void AddUsingListToScope(PascalSharp.Internal.TreeConverter.SymbolTable.Scope scope, using_namespace_list unl) { PascalSharp.Internal.TreeConverter.SymbolTable.UnitPartScope ups = scope as PascalSharp.Internal.TreeConverter.SymbolTable.UnitPartScope; if (ups == null) { return; } foreach (PascalSharp.Internal.TreeConverter.SymbolTable.Scope sc in ups.TopScopeArray) { NetScope netsc = sc as NetScope; if (netsc != null && netsc.used_namespaces.Count == 0) { using_namespace_list new_unl = new using_namespace_list(); foreach (using_namespace un in unl) { SymbolInfoList sil = netsc.FindOnlyInScope(un.namespace_name); if ((sil.First().sym_info as compiled_namespace_node) != null) { new_unl.AddElement(un); } } netsc.used_namespaces = new_unl; } } }
public static void AddUsingListToScope(SymbolTable.Scope scope, using_namespace_list unl) { SymbolTable.UnitPartScope ups = scope as SymbolTable.UnitPartScope; if (ups == null) { return; } foreach (SymbolTable.Scope sc in ups.TopScopeArray) { NetHelper.NetScope netsc = sc as NetHelper.NetScope; if (netsc != null && netsc.used_namespaces.Count == 0) { using_namespace_list new_unl = new using_namespace_list(); foreach (using_namespace un in unl) { List <SymbolInfo> sil = netsc.FindOnlyInScope(un.namespace_name); if ((sil.FirstOrDefault().sym_info as compiled_namespace_node) != null) { new_unl.AddElement(un); } } netsc.used_namespaces = new_unl; } } }
/// <summary> /// Конструктор узла. /// </summary> /// <param name="name">Полное имя пространства имен.</param> public compiled_namespace_node(string name, SymbolTable.TreeConverterSymbolTable tcst) { _name = name; _tcst = tcst; using_namespace_list unl = new using_namespace_list(); unl.AddElement(new using_namespace(_name)); _scope = new NetHelper.NetScope(unl, _tcst); }
public template_class(type_declaration type_decl, string name, common_namespace_node cnn, /*common_type_node ctn,location loc,*/ document doc, using_namespace_list unl) { _cnn = cnn; _type_decl = type_decl; _name = name; _doc = doc; //(ssyy) using - список, по-видимому, можно только копировать, т.к. Николай его периодически чистит. _unl = new using_namespace_list(); foreach (using_namespace un in unl) { _unl.AddElement(un); } }
public static void AddUsingListToScope(SymbolTable.Scope scope, using_namespace_list unl) { SymbolTable.UnitPartScope ups = scope as SymbolTable.UnitPartScope; if (ups == null) return; foreach (SymbolTable.Scope sc in ups.TopScopeArray) { NetHelper.NetScope netsc = sc as NetHelper.NetScope; if (netsc != null && netsc.used_namespaces.Count == 0) { 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) { new_unl.AddElement(un); } } netsc.used_namespaces = new_unl; } } }
public template_class(SyntaxTree.type_declaration type_decl, string name,common_namespace_node cnn,/*common_type_node ctn,location loc,*/document doc,using_namespace_list unl) { _cnn = cnn; _type_decl = type_decl; _name = name; _doc = doc; //(ssyy) using - список, по-видимому, можно только копировать, т.к. Николай его периодически чистит. _unl = new using_namespace_list(); foreach (using_namespace un in unl) { _unl.AddElement(un); } }
internal SymbolTable.Scope[] build_referenced_units(unit_node_list referenced_units, bool try_get_system_module) { List<SymbolTable.Scope> used_units = new List<SymbolTable.Scope>(); Dictionary<System.Reflection.Assembly, dot_net_unit_node> assembly_references_dict = new Dictionary<System.Reflection.Assembly, dot_net_unit_node>(); for (int i = 0; i < referenced_units.Count; i++) { if (referenced_units[i] is dot_net_unit_node) if (!assembly_references_dict.ContainsKey((referenced_units[i] as dot_net_unit_node).dotNetScope._assembly)) assembly_references_dict.Add((referenced_units[i] as dot_net_unit_node).dotNetScope._assembly, referenced_units[i] as dot_net_unit_node); } dot_net_unit_node[] assembly_references = new dot_net_unit_node[assembly_references_dict.Values.Count]; assembly_references_dict.Values.CopyTo(assembly_references, 0); List<NetHelper.NetScope> def_scopes = new List<NetHelper.NetScope>(); if (SemanticRules.AllowGlobalVisibilityForPABCDll) { for (int i = 0; i < assembly_references.Length; i++) { if (assembly_references[i].dotNetScope.entry_type != null) def_scopes.Add(assembly_references[i].dotNetScope); } } //used_units.Add(_system_unit.scope); for (int i = 0; i < referenced_units.Count; i++) { if (!(referenced_units[i] is dot_net_unit_node)) { if (referenced_units[i] is namespace_unit_node) { for (int j = 0; j < assembly_references.Length; j++) { using_namespace_list unl = new using_namespace_list(); unl.AddElement((referenced_units[i] as namespace_unit_node).namespace_name); NetHelper.NetScope ns = new PascalABCCompiler.NetHelper.NetScope(unl, assembly_references[j].dotNetScope._assembly, SymbolTable); used_units.Add(ns); } if (_compiled_unit != null) _compiled_unit.used_namespaces.Add((referenced_units[i] as namespace_unit_node).namespace_name.namespace_name); } else { common_unit_node cun = _referenced_units[i] as common_unit_node; if (cun != null) { if (try_get_system_module && cun.IsSystemUnit) { get_system_module(cun); for (int j = 0; j < def_scopes.Count; j++) { used_units.Add(new PascalABCCompiler.NetHelper.NetScope(interface_using_list, def_scopes[j]._assembly, SymbolTable)); } } used_units.Add(cun.scope); } else { throw new CompilerInternalError("Unexpected unit type."); } } } else { dot_net_unit_node dun = referenced_units[i] as dot_net_unit_node; if (dun.dotNetScope.entry_type != null && dun.dotNetScope.entry_type.Name == "PABCRtl") { if (try_get_system_module) { from_pabc_dll = true; get_system_module_from_dll(dun); } } } } List<SymTable.Scope> fetched_used_units = new List<SymTable.Scope>(); Dictionary<System.Reflection.Assembly, PascalABCCompiler.NetHelper.NetScope> assm_cache = new Dictionary<System.Reflection.Assembly, PascalABCCompiler.NetHelper.NetScope>(); for (int i = 0; i < used_units.Count; i++) { PascalABCCompiler.NetHelper.NetScope net_scope = used_units[i] as PascalABCCompiler.NetHelper.NetScope; if (net_scope != null) { PascalABCCompiler.NetHelper.NetScope existing_scope = null; if (assm_cache.TryGetValue(net_scope.Assembly, out existing_scope)) { /*if (net_scope.used_namespaces) { foreach (using_namespace un in net_scope.used_namespaces) { if (un.namespace_name) } }*/ existing_scope.used_namespaces.AddRange(net_scope.used_namespaces); } else { if (NetHelper.NetHelper.PABCSystemType == null || net_scope.Assembly != NetHelper.NetHelper.PABCSystemType.Assembly) assm_cache.Add(net_scope.Assembly, net_scope); fetched_used_units.Add(net_scope); } } else fetched_used_units.Add(used_units[i]); } used_units = fetched_used_units; //Если компилими implementation то в начало кладем все что было в interface for (int i = 0; i < assembly_references.Length; i++) { used_units.Add(new PascalABCCompiler.NetHelper.NetScope(interface_using_list, (assembly_references[i] as dot_net_unit_node).dotNetScope._assembly, SymbolTable)); } used_units.Add(_system_unit.scope); return used_units.ToArray(); }
public common_type_node instance(template_class tc, List<type_node> template_params, location loc) { //Проверяем, что попытка инстанцирования корректна SyntaxTree.class_definition cl_def = tc.type_dec.type_def as SyntaxTree.class_definition; SyntaxTree.template_type_name ttn = tc.type_dec.type_name as SyntaxTree.template_type_name; #if (DEBUG) if (!tc.is_synonym) { if (cl_def == null) { throw new PascalABCCompiler.TreeConverter.CompilerInternalError("No body definition in template class."); } if (cl_def.template_args == null || cl_def.template_args.idents == null) { throw new PascalABCCompiler.TreeConverter.CompilerInternalError("No template arguments in syntax tree."); } } else { if (ttn == null) { throw new PascalABCCompiler.TreeConverter.CompilerInternalError("No template name."); } } #endif List<SyntaxTree.ident> template_formals = (tc.is_synonym) ? ttn.template_args.idents : cl_def.template_args.idents; if (template_formals.Count != ttn.template_args.idents.Count) { AddError(loc, "TEMPLATE_ARGUMENTS_COUNT_MISMATCH"); } if (!tc.is_synonym) { foreach (type_node tnode in template_params) { if (depended_from_generic_parameter(tnode)) { AddError(loc, "TEMPLATES_AND_GENERICS_ARE_INCOMPATIBLE"); } } } //А вдруг такая инстанция уже есть - вернём её string inst_name = tc.CreateTemplateInstance(template_params, loc); SymbolInfo si = tc.cnn.scope.FindOnlyInScope(inst_name); if (si != null) { return (common_type_node)si.sym_info; } //Переходим в место описания шаблона common_namespace_node current_namespace = context.converted_namespace; context.converted_namespace = tc.cnn; common_type_node current_type = context.converted_type; context.converted_type = null; template_class current_template = context.converted_template_type; context.converted_template_type = null; compiled_type_node current_compiled_type = context.converted_compiled_type; context.converted_compiled_type = null; common_function_node_stack current_funk_stack = context.converted_func_stack; context.converted_func_stack = new common_function_node_stack(); //Думаю, это будет работать //DarkStar statement_list_stack statement_list_stack = convertion_data_and_alghoritms.statement_list_stack; convertion_data_and_alghoritms.statement_list_stack = new statement_list_stack(); bool current_cur_meth_not_in_class = current_converted_method_not_in_class_defined; current_converted_method_not_in_class_defined = false; SymbolInfo current_last_created_function = context.last_created_function; context.last_created_function = null; bool current_record_created = _record_created; _record_created = false; SemanticTree.field_access_level current_fal = context.get_field_access_level(); document current_doc = current_document; current_document = tc.cur_document; bool current_body_exists = body_exists; body_exists = false; bool current_allow_inherited_ctor_call = context.allow_inherited_ctor_call; bool current_is_direct_type_decl = is_direct_type_decl; is_direct_type_decl = false; context.allow_inherited_ctor_call = false; bool current_type_section_converting = type_section_converting; type_section_converting = true; SemanticTree.field_access_level curr_fal = context.get_field_access_level(); List<var_definition_node> current_var_defs = context.var_defs; context.var_defs = new List<var_definition_node>(); Hashtable current_member_decls = context.member_decls; context.member_decls = new Hashtable(); //подменяем using-список using_namespace_list current_using_list = new using_namespace_list(); foreach (using_namespace un in using_list) { current_using_list.AddElement(un); } using_list.clear(); foreach (using_namespace un in tc.using_list) { using_list.AddElement(un); } context.converted_type = null; context.enter_code_block_without_bind(); common_type_node ctn; bool interface_creating = false; //Создаём инстанцию шаблона if (tc.is_synonym) { ctn = context.create_type(inst_name, get_location(ttn)); } else { if (cl_def.keyword == SyntaxTree.class_keyword.Record) { ctn = context.create_record_type(get_location(tc.type_dec.type_name), inst_name); } else { interface_creating = (cl_def.keyword == PascalABCCompiler.SyntaxTree.class_keyword.Interface); ctn = context.advanced_create_type(inst_name, get_location(tc.type_dec.type_name), interface_creating); } } ctn.original_template = tc; bool indefinite = false; foreach (type_node tn in template_params) { indefinite = indefinite || tn.depended_from_indefinite; } ctn.SetDependedFromIndefinite(indefinite); tc.instance_params.Add(ctn, template_params); //Ставим в соответствие формальным параметрам шаблона фактические for (int i = 0; i < template_params.Count; i++) { ctn.Scope.AddSymbol(template_formals[i].name, new SymbolInfo(template_params[i])); } //Разбор тела класса if (tc.is_synonym) { type_node synonym_value = convert_strong(tc.type_dec.type_def); ctn.fields.AddElement(new class_field(compiler_string_consts.synonym_value_name, synonym_value, ctn, PascalABCCompiler.SemanticTree.polymorphic_state.ps_static, PascalABCCompiler.SemanticTree.field_access_level.fal_public, null)); } else { if (cl_def.keyword == SyntaxTree.class_keyword.Record) { _record_created = true; } bool tmp_direct = is_direct_type_decl; is_direct_type_decl = true; hard_node_test_and_visit(cl_def); is_direct_type_decl = tmp_direct; //Разбор методов, описанных вне класса if (!interface_creating) { type_section_converting = false; foreach (procedure_definition_info pdi in tc.external_methods) { if (context.converted_namespace != pdi.nspace) { context.converted_namespace = pdi.nspace; using_namespace_list ulist = (pdi.nspace == tc.cnn) ? tc.using_list : tc.using_list2; using_list.clear(); foreach (using_namespace un in ulist) { using_list.AddElement(un); } template_class.AddUsingListToScope(context.converted_namespace.scope, ulist); } //Заменяем в дереве метода имя шаблонного класса на имя инстанции string tmp_name = pdi.proc.proc_header.name.class_name.name; pdi.proc.proc_header.name.class_name.name = inst_name; hard_node_test_and_visit(pdi.proc); //Обратная замена pdi.proc.proc_header.name.class_name.name = tmp_name; } foreach (common_method_node cmn in ctn.methods) { if (cmn.function_code == null) { AddError(cmn.loc, "FUNCTION_PREDEFINITION_WITHOUT_DEFINITION"); } } } } //Прыжок обратно context.leave_code_block(); context.converted_namespace = current_namespace; context.converted_type = current_type; context.converted_template_type = current_template; context.set_field_access_level(current_fal); context.converted_func_stack = current_funk_stack; context.converted_compiled_type = current_compiled_type; convertion_data_and_alghoritms.statement_list_stack = statement_list_stack; current_document = current_doc; body_exists = current_body_exists; _record_created = current_record_created; context.last_created_function = current_last_created_function; is_direct_type_decl = current_is_direct_type_decl; context.allow_inherited_ctor_call = current_allow_inherited_ctor_call; current_converted_method_not_in_class_defined = current_cur_meth_not_in_class; context.set_field_access_level(curr_fal); type_section_converting = current_type_section_converting; context.member_decls = current_member_decls; context.var_defs = current_var_defs; using_list.clear(); foreach (using_namespace un in current_using_list) { using_list.AddElement(un); } return ctn; }
private template_class CreateTemplateClass(int offset) { definition_node dn = null; if (members.TryGetValue(offset, out dn)) return dn as template_class; template_class tc = null; string name = br.ReadString(); bool is_syn = br.ReadByte() == 1; using_namespace_list unl = new using_namespace_list(); int using_count = br.ReadInt32(); for (int i = 0; i < using_count; i++) { unl.AddElement(new using_namespace(br.ReadString())); } using_namespace_list unl2 = null; if (CanReadObject()) { unl2 = new using_namespace_list(); int using_count2 = br.ReadInt32(); for (int i = 0; i < using_count2; i++) { unl2.AddElement(new using_namespace(br.ReadString())); } } document doc = null; if (br.ReadByte() == 1) { doc = new document(Path.Combine(Path.GetDirectoryName(cur_doc.file_name),br.ReadString())); } SyntaxTree.SyntaxTreeStreamReader str = new SyntaxTree.SyntaxTreeStreamReader(); str.br = br; SyntaxTree.type_declaration t_d = str._read_node() as SyntaxTree.type_declaration; int ext_count = br.ReadInt32(); List<procedure_definition_info> pdi_list = new List<procedure_definition_info>(ext_count); for (int i = 0; i < ext_count; i++) { byte num = br.ReadByte(); common_namespace_node c_m_n = cun.namespaces[num]; SyntaxTree.syntax_tree_node stn = str._read_node(); SyntaxTree.procedure_definition p_d = stn as SyntaxTree.procedure_definition; pdi_list.Add(new procedure_definition_info(c_m_n, p_d)); } //(ssyy) Далее формируем список областей видимости, которые //подключаются к модулю. Вообще-то шаблоны классов этим //заниматься не должны, но кроме них этот список //никому не нужен (по состоянию на 01.06.2007). if (cun.scope.TopScopeArray.Length == 0) { cun.scope.TopScopeArray = MakeTopScopeArray(unl, pcu_file.interface_uses_count); } if (cun.implementation_scope.TopScopeArray.Length == 0 && unl2 != null) { //формируем implementation - область cun.implementation_scope.TopScopeArray = MakeTopScopeArray(unl2, pcu_file.incl_modules.Length); } tc = new template_class(t_d, name, cun.namespaces[0], doc, unl); tc.external_methods = pdi_list; tc.using_list2 = unl2; tc.is_synonym = is_syn; //members[offset] = tc; AddMember(tc, offset); cun.namespaces[0].scope.AddSymbol(name, new SymbolInfo(tc)); return tc; }