private void get_system_module(common_unit_node psystem_unit) { init_system_module(psystem_unit); //esli zapustili v otladke, to vosstanovim mnozhestvo i procedury sozdanija diapasonov, inache ne budet rabotat if (debugging) { SymbolInfo si = SystemLibrary.SystemLibInitializer.CreateDiapason.SymbolInfo; si = SystemLibrary.SystemLibInitializer.CreateObjDiapason.SymbolInfo; si = SystemLibrary.SystemLibInitializer.TypedSetType.SymbolInfo; } //if (SystemLibrary.SystemLibInitializer.TextFileType.Found) // SystemLibrary.SystemLibInitializer.TextFileType.GetTypeNodeSpecials().type_special_kind = PascalABCCompiler.SemanticTree.type_special_kind.text_file; SystemUnitAssigned = true; CreateSpecialFields(psystem_unit); }
private void CreateSpecialFields(common_unit_node psystem_unit) { /*SymbolInfo si = psystem_unit.scope.Find(compiler_string_consts.CommandLineArgsVariableName); if (si != null && si.sym_info is namespace_variable) { //location loc = (si.sym_info as namespace_variable).Location common_parameter args = new common_parameter(compiler_string_consts.MainArgsParamName, SystemLibrary.SystemLibrary.array_of_string, SemanticTree.parameter_type.value, null, concrete_parameter_type.cpt_none, null, null); namespace_variable_reference nvr = new namespace_variable_reference(si.sym_info as namespace_variable, null); psystem_unit.MainArgsParameter = args; psystem_unit.MainArgsAssignExpr = make_assign_operator(nvr, new common_parameter_reference(args, 0, null), null); }*/ SymbolInfo si = psystem_unit.scope.Find(compiler_string_consts.IsConsoleApplicationVariableName); if (si != null && si.sym_info is namespace_variable) { namespace_variable_reference nvr = new namespace_variable_reference(si.sym_info as namespace_variable, null); psystem_unit.IsConsoleApplicationVariableAssignExpr = make_assign_operator(nvr, psystem_unit.IsConsoleApplicationVariableValue, null); } }
public override void visit(SyntaxTree.c_module node) { string namespace_name = ""; location loc = null; // if (_program_module.program_name != null) // { // namespace_name = _program_module.program_name.prog_name.name; // loc = get_location(_program_module.program_name.prog_name); // if (namespace_name.ToLower() != System.IO.Path.GetFileNameWithoutExtension(_program_module.file_name).ToLower()) // throw new ProgramNameMustBeEqualProgramFileName(loc); // } _compiled_unit = new common_unit_node(); _compiled_unit.compiler_directives = ConvertDirectives(node); //PrepareDirectives(_compiled_unit.compiler_directives); //using_list.AddRange(interface_using_list); //weak_node_test_and_visit(_program_module.using_namespaces); //weak_node_test_and_visit(node.used_units); //compiled_main_unit=new unit_node(); //SymbolTable.Scope[] used_units=new SymbolTable.Scope[used_assemblyes.Count+1]; SymbolTable.Scope[] used_units = build_referenced_units(referenced_units,true); _compiled_unit.scope = convertion_data_and_alghoritms.symbol_table.CreateUnitInterfaceScope(used_units); common_namespace_node cnsn = context.create_namespace(namespace_name, _compiled_unit, _compiled_unit.scope, loc); cnsn.is_main = true; //compiled_program=new program_node(); //compiled_program.units.Add(compiled_main_unit); reset_for_interface(); UpdateUnitDefinitionItemForUnit(_compiled_unit); //_program_module.program_block.visit(this); //hard_node_test_and_visit(_program_module.program_block); //context.check_labels(context.converted_namespace.labels); //TODO: Доделать. //common_namespace_function_node main_function = new common_namespace_function_node(compiler_string_consts.temp_main_function_name, // null, null, cnsn, null); //main_function.function_code = context.code; //cnsn.functions.AddElement(main_function); weak_node_test_and_visit(node.defs); bool main_not_found = true; foreach (function_node fn in cnsn.functions) { if (fn.name == compiler_string_consts.c_main_function_name) { _compiled_unit.main_function = fn as common_namespace_function_node; //context.apply_special_local_vars(_compiled_unit.main_function); main_not_found = false; break; } } if (main_not_found) { AddError(get_location(node), "NO_MAIN_FUNCTION"); } context.leave_block(); //_compiled_unit.main_function = main_function; }
public static void init_system_module(common_unit_node psystem_unit) { SystemLibrary.SystemLibInitializer.format_function = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.format_procedure_name); SystemLibrary.SystemLibInitializer.read_procedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.read_procedure_name); SystemLibrary.SystemLibInitializer.write_procedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.write_procedure_name); SystemLibrary.SystemLibInitializer.writeln_procedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.writeln_procedure_name); SystemLibrary.SystemLibInitializer.readln_procedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.readln_procedure_name); SystemLibrary.SystemLibInitializer.TextFileType = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.text_file_name_type_name); SystemLibrary.SystemLibInitializer.TextFileInitProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.TextFileInitProcedureName); SystemLibrary.SystemLibInitializer.BinaryFileType = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.BinaryFileTypeName); SystemLibrary.SystemLibInitializer.AbstractBinaryFileType = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.AbstractBinaryFileTypeName); SystemLibrary.SystemLibInitializer.PointerOutputType = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.PointerOutputTypeName); SystemLibrary.SystemLibInitializer.BinaryFileReadProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.BinaryFileReadProcedureName); SystemLibrary.SystemLibInitializer.BinaryFileInitProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.BinaryFileInitProcedureName); SystemLibrary.SystemLibInitializer.StringDefaultPropertySetProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.StringDefaultPropertySetProcedureName); SystemLibrary.SystemLibInitializer.TypedFileType = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.TypedFileTypeName); SystemLibrary.SystemLibInitializer.TypedFileInitProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.TypedFileInitProcedureName); SystemLibrary.SystemLibInitializer.TypedFileReadProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.TypedFileReadProcedureName); SystemLibrary.SystemLibInitializer.ClipShortStringProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.ClipShortString); SystemLibrary.SystemLibInitializer.GetCharInShortStringProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.GetCharInShortString); SystemLibrary.SystemLibInitializer.SetCharInShortStringProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.SetCharInShortString); //SystemLibrary.SystemLibInitializer.ShortStringType = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.ShortStringTypeName); //SystemLibrary.SystemLibInitializer.ShortStringTypeInitProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.ShortStringTypeInitProcedure); SystemLibrary.SystemLibInitializer.TypedSetType = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.set_name); SystemLibrary.SystemLibInitializer.TypedSetInitProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.TypedSetInitProcedure); SystemLibrary.SystemLibInitializer.SetUnionProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.union_of_set); SystemLibrary.SystemLibInitializer.SetIntersectProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.intersect_of_set); SystemLibrary.SystemLibInitializer.SetSubtractProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.subtract_of_set); SystemLibrary.SystemLibInitializer.InSetProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.in_set); SystemLibrary.SystemLibInitializer.CreateSetProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.CreateSetProcedure); SystemLibrary.SystemLibInitializer.IncludeProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.IncludeProcedure); SystemLibrary.SystemLibInitializer.ExcludeProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.ExcludeProcedure); SystemLibrary.SystemLibInitializer.DiapasonType = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.DiapasonType); SystemLibrary.SystemLibInitializer.CreateDiapason = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.CreateDiapason); SystemLibrary.SystemLibInitializer.CreateObjDiapason = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.CreateObjDiapason); SystemLibrary.SystemLibInitializer.CompareSetEquals = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.CompareSetEquals); SystemLibrary.SystemLibInitializer.CompareSetInEquals = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.CompareSetInEquals); SystemLibrary.SystemLibInitializer.CompareSetLess = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.CompareSetLess); SystemLibrary.SystemLibInitializer.CompareSetLessEqual = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.CompareSetLessEqual); SystemLibrary.SystemLibInitializer.CompareSetGreater = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.CompareSetGreater); SystemLibrary.SystemLibInitializer.CompareSetGreaterEqual = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.CompareSetGreaterEqual); SystemLibrary.SystemLibInitializer.IncProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.IncProcedure); SystemLibrary.SystemLibInitializer.DecProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.DecProcedure); SystemLibrary.SystemLibInitializer.SuccFunction = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.SuccFunction); SystemLibrary.SystemLibInitializer.PredFunction = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.PredFunction); SystemLibrary.SystemLibInitializer.OrdFunction = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.OrdFunction); SystemLibrary.SystemLibInitializer.TypedSetInitProcedureWithBounds = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.TypedSetInitProcedureWithBounds); SystemLibrary.SystemLibInitializer.TypedSetInitWithShortString = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.TypedSetInitWithShortString); SystemLibrary.SystemLibInitializer.AssignSetProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.AssignSetProcedure); SystemLibrary.SystemLibInitializer.AssignSetProcedureWithBounds = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.AssignSetProcedureWithBounds); SystemLibrary.SystemLibInitializer.ClipProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.ClipProcedure); SystemLibrary.SystemLibInitializer.ClipFunction = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.ClipFunction); SystemLibrary.SystemLibInitializer.ClipShortStringInSetFunction = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.ClipShortStringInSetFunction); SystemLibrary.SystemLibInitializer.ClipShortStringInSetProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.ClipShortStringInSetProcedure); SystemLibrary.SystemLibInitializer.SetLengthForShortStringProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.set_length_for_short_string); SystemLibrary.SystemLibInitializer.SetLengthProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.set_length_procedure_name); SystemLibrary.SystemLibInitializer.read_short_string_procedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.read_short_string); SystemLibrary.SystemLibInitializer.read_short_string_from_file_procedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.read_short_string_from_file); SystemLibrary.SystemLibInitializer.InsertProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit,compiler_string_consts.Insert); SystemLibrary.SystemLibInitializer.InsertInShortStringProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit,compiler_string_consts.InsertInShortString); SystemLibrary.SystemLibInitializer.DeleteProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit,compiler_string_consts.Delete); SystemLibrary.SystemLibInitializer.LowFunction = new SystemLibrary.UnitDefinitionItem(psystem_unit,compiler_string_consts.Low); SystemLibrary.SystemLibInitializer.HighFunction = new SystemLibrary.UnitDefinitionItem(psystem_unit,compiler_string_consts.High); SystemLibrary.SystemLibInitializer.CheckCanUsePointerOnTypeProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.CheckCanUsePointerOnType_proc_name); SystemLibrary.SystemLibInitializer.CheckCanUseTypeForBinaryFilesProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.CheckCanUseTypeForBinaryFiles_proc_name); SystemLibrary.SystemLibInitializer.CheckCanUseTypeForTypedFilesProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.CheckCanUseTypeForTypedFiles_proc_name); SystemLibrary.SystemLibInitializer.RuntimeDetermineTypeFunction = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.RuntimeDetermineType_func_name); SystemLibrary.SystemLibInitializer.RuntimeInitializeFunction = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.RuntimeInitializeFunction_func_name); SystemLibrary.SystemLibInitializer.PointerToStringFunction = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.PointerToStringFunction_func_name); SystemLibrary.SystemLibInitializer.GetRuntimeSizeFunction = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.GetRuntimeSizeFunction_func_name); SystemLibrary.SystemLibInitializer.StrProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.StrProcedure_func_name); SystemLibrary.SystemLibInitializer.ChrUnicodeFunction = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.ChrUnicodeFunction_func_name); SystemLibrary.SystemLibInitializer.AssertProcedure = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.AssertProcedure); SystemLibrary.SystemLibInitializer.CheckRangeFunction = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.check_in_range); SystemLibrary.SystemLibInitializer.CheckCharRangeFunction = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.check_in_range_char); SystemLibrary.SystemLibInitializer.CopyWithSizeFunction = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.CopyWithSizeFunction); SystemLibrary.SystemLibInitializer.ArrayCopyFunction = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.ArrayCopyFunction); SystemLibrary.SystemLibInitializer.ConfigVariable = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.config_variable_name); //AddSpecialOperatorsToSetType(); //SystemLibrary.SystemLibrary.make_type_conversion(SystemLibrary.SystemLibInitializer.ShortStringType.sym_info as type_node,SystemLibrary.SystemLibrary.string_type,type_compare.less_type,SemanticTree.basic_function_type.none,true); //SystemLibrary.SystemLibrary.make_type_conversion(SystemLibrary.SystemLibrary.string_type,SystemLibrary.SystemLibInitializer.ShortStringType.sym_info as type_node,type_compare.greater_type,SemanticTree.basic_function_type.none,true); if(SystemLibrary.SystemLibInitializer.TextFileType.Found) SystemLibrary.SystemLibInitializer.TextFileType.TypeNode.type_special_kind = PascalABCCompiler.SemanticTree.type_special_kind.text_file; if (SemanticRules.GenerateNativeCode) { SystemLibrary.SystemLibInitializer.ObjectType = new SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.ObjectType); if (SystemLibrary.SystemLibInitializer.ObjectType.Found) SemanticRules.ClassBaseType = SystemLibrary.SystemLibInitializer.ObjectType.sym_info as TreeRealization.type_node; SystemLibrary.SystemLibInitializer.StringType = new PascalABCCompiler.SystemLibrary.UnitDefinitionItem(psystem_unit, compiler_string_consts.StringType); if (SystemLibrary.SystemLibInitializer.StringType.Found) SemanticRules.StringType = SystemLibrary.SystemLibInitializer.StringType.sym_info as TreeRealization.type_node; } }
public override void visit(SyntaxTree.unit_module _unit_module) { //MikhailoMMX Инициализация OpenMP OpenMP.InitOpenMP(_unit_module.compiler_directives, this, _unit_module); //\MikhailoMMX //current_document=new document(_unit_module.file_name); string namespace_name = ""; _is_interface_part = true; location loc = null; if (_unit_module.unit_name != null) { namespace_name = _unit_module.unit_name.idunit_name.name; loc = get_location(_unit_module.unit_name.idunit_name); if (namespace_name.ToLower() != System.IO.Path.GetFileNameWithoutExtension(_unit_module.file_name).ToLower()) AddError(loc, "UNIT_NAME_MUST_BE_EQUAL_UNIT_FILE_NAME"); } _compiled_unit = new common_unit_node(_unit_module.unit_name.idunit_name.name); assign_doc_info(_compiled_unit,_unit_module.unit_name); _compiled_unit.compiler_directives = ConvertDirectives(_unit_module); //PrepareDirectives(_compiled_unit.compiler_directives); //using_list.AddRange(interface_using_list); //weak_node_test_and_visit(_unit_module.interface_part.using_namespaces); //weak_node_test_and_visit(_program_module.used_units); //compiled_main_unit=new unit_node(); //SymbolTable.Scope[] used_units=new SymbolTable.Scope[used_assemblyes.Count+1]; SymbolTable.Scope[] used_units = build_referenced_units(referenced_units,true); _compiled_unit.scope = convertion_data_and_alghoritms.symbol_table.CreateUnitInterfaceScope(used_units); common_namespace_node cnsn = context.create_namespace(namespace_name, _compiled_unit, _compiled_unit.scope, loc); _compiled_unit.add_unit_name_to_namespace(); if (check_for_dll_entry_module(_compiled_unit.compiler_directives)) { cnsn.is_main = true; } UpdateUnitDefinitionItemForUnit(_compiled_unit); //cnsn.scope=_compiled_unit.scope; reset_for_interface(); in_interface_part = false; if (_unit_module.implementation_part != null) in_interface_part = true; hard_node_test_and_visit(_unit_module.interface_part); if (_unit_module.implementation_part != null) in_interface_part = false; //compiled_program=new program_node(); //compiled_program.units.Add(compiled_main_unit); //_program_module.program_block.visit(this); if (_unit_module.attributes != null) make_attributes_for_declaration(_unit_module, _compiled_unit); context.leave_interface_part(); _is_interface_part = false; }
//TODO: Слить как нибудь два следующих метода. public override void visit(SyntaxTree.program_module _program_module) { //MikhailoMMX Инициализация OpenMP OpenMP.InitOpenMP(_program_module.compiler_directives, this, _program_module); //\MikhailoMMX string namespace_name = ""; location loc = get_location(_program_module); if (_program_module.program_name != null) { namespace_name = _program_module.program_name.prog_name.name; loc = get_location(_program_module.program_name.prog_name); } _compiled_unit = new common_unit_node(); _compiled_unit.compiler_directives = ConvertDirectives(_program_module); SymbolTable.Scope[] used_units = build_referenced_units(referenced_units,true); _compiled_unit.scope = convertion_data_and_alghoritms.symbol_table.CreateUnitInterfaceScope(used_units); common_namespace_node cnsn = context.create_namespace(namespace_name, _compiled_unit, _compiled_unit.scope, loc); cnsn.is_main = true; reset_for_interface(); UpdateUnitDefinitionItemForUnit(_compiled_unit); hard_node_test_and_visit(_program_module.program_block); context.check_labels(context.converted_namespace.labels); // frninja 28/04/16 - режем мусорные методы хелперы yield { var toRemove = cnsn.functions.Where(m => m.is_yield_helper).ToArray(); foreach (var m in toRemove) { cnsn.functions.remove(m); } } // end frninja common_namespace_function_node main_function = new common_namespace_function_node(compiler_string_consts.temp_main_function_name, null, null, cnsn, null); main_function.function_code = context.code; context.apply_special_local_vars(main_function); cnsn.functions.AddElement(main_function); context.leave_block(); _compiled_unit.main_function = main_function; }
public common_namespace_node create_namespace(string namespace_name, common_unit_node cont_unit,SymbolTable.Scope _scope, location loc) { return create_namespace(null, namespace_name, cont_unit,_scope, loc); }
private void dot_node_as_unit_ident(common_unit_node cun, SyntaxTree.ident id_right, motivation mot) { dot_node_as_namespace_ident(cun.namespaces[0], id_right, mot); }
//десериализация модуля //читается только шапка PCU и заполняются имена сущностей модуля в таблицу символов public CompilationUnit GetCompilationUnit(string FileName, bool readDebugInfo) { try { this.FileName = FileName; this.readDebugInfo = readDebugInfo; unit_name = System.IO.Path.GetFileNameWithoutExtension(FileName); PCUReader pr = (PCUReader)units[unit_name]; if (pr != null) return pr.unit; if (!File.Exists(FileName)) return null; dir = System.IO.Path.GetDirectoryName(FileName); //fs = new FileStream(FileName, FileMode.Open, FileAccess.Read); ms = new MemoryStream(File.ReadAllBytes(FileName)); br = new BinaryReader(ms); ReadPCUHeader(); units[unit_name] = this; if (NeedRecompiled()) { CloseUnit(); need = true; return null; // return comp.RecompileUnit(unit_name); } unit = new CompilationUnit(); cun = new common_unit_node(); cun.compiler_directives = pcu_file.compiler_directives; unit.SemanticTree = cun; ChangeState(this, PCUReaderWriterState.BeginReadTree, unit); cun.scope = new WrappedUnitInterfaceScope(this); //TODO сохранить в PCU cun.scope.CaseSensitive = false; if (string.Compare(unit_name,PascalABCCompiler.TreeConverter.compiler_string_consts.system_unit_file_name)==0) PascalABCCompiler.TreeConverter.syntax_tree_visitor.init_system_module(cun); //ssyy //Создаём область видимости для implementation - части cun.implementation_scope = new WrappedUnitImplementationScope(this, cun.scope); //\ssyy //TODO сохранить в PCU cun.implementation_scope.CaseSensitive = false; string SourceFileName = pcu_file.SourceFileName; if (Path.GetDirectoryName(SourceFileName) == "") { SourceFileName = Path.Combine(Path.GetDirectoryName(FileName), SourceFileName); if (!File.Exists(SourceFileName)) SourceFileName = Path.Combine(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(FileName)),"LibSource"), pcu_file.SourceFileName); } cur_doc = new document(SourceFileName); AddNamespaces(); AddInterfaceNames(); //ssyy AddImplementationNames(); //\ssyy //AddInitFinalMethods(); //ProcessWaitedToRestoreFields(); unit.State = UnitState.Compiled; //ssyy AddTypeSynonyms(pcu_file.interface_synonyms_offset, cun.scope); AddTypeSynonyms(pcu_file.implementation_synonyms_offset, cun.implementation_scope); //\ssyy ChangeState(this, PCUReaderWriterState.EndReadTree, unit); return unit; } catch (Exception) { CloseUnit(); throw; } }
public common_namespace_node create_namespace(common_namespace_node comprehensive_namespace,string namespace_name, common_unit_node cont_unit,SymbolTable.Scope _scope,location loc) { SymbolTable.Scope scope; if (comprehensive_namespace == null) { //scope = convertion_data_and_alghoritms.symbol_table.CreateScope(cont_unit.scope); scope = _scope; } else { scope = convertion_data_and_alghoritms.symbol_table.CreateScope(comprehensive_namespace.scope); } _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)); return _cmn; }
//bool assigned=false; public UnitDefinitionItem(common_unit_node cmn, string name) { this.name = name; this.cmn = cmn; }
public static common_unit_node make_system_unit(SymbolTable.TreeConverterSymbolTable symbol_table, initialization_properties initialization_properties) { //TODO: В качестве location везде в этом методе следует указывать location system_unit-а. Имя файла мы знаем, а место - там где написано, что integer и прочие типы описаны как бы в модуле system. location system_unit_location = null; SymbolTable.UnitInterfaceScope main_scope = symbol_table.CreateUnitInterfaceScope(new SymbolTable.Scope[0]); SymbolTable.UnitImplementationScope impl_scope = symbol_table.CreateUnitImplementationScope(main_scope, new SymbolTable.Scope[0]); common_unit_node _system_unit = new common_unit_node(main_scope,impl_scope,null,null); 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)); //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.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.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.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)); //TODO: Переделать. Пусть таблица символов создается одна. Как статическая. compiled_type_node comp_byte_type = ((compiled_type_node)SystemLibrary.byte_type); compiled_type_node comp_sbyte_type = ((compiled_type_node)SystemLibrary.sbyte_type); compiled_type_node comp_short_type = ((compiled_type_node)SystemLibrary.short_type); compiled_type_node comp_ushort_type = ((compiled_type_node)SystemLibrary.ushort_type); compiled_type_node comp_integer_type = ((compiled_type_node)SystemLibrary.integer_type); compiled_type_node comp_uint_type = ((compiled_type_node)SystemLibrary.uint_type); compiled_type_node comp_long_type = ((compiled_type_node)SystemLibrary.int64_type); compiled_type_node comp_ulong_type = ((compiled_type_node)SystemLibrary.uint64_type); compiled_type_node comp_float_type = ((compiled_type_node)SystemLibrary.float_type); compiled_type_node comp_real_type = ((compiled_type_node)SystemLibrary.double_type); compiled_type_node comp_char_type=((compiled_type_node)SystemLibrary.char_type); compiled_type_node comp_bool_type = ((compiled_type_node)SystemLibrary.bool_type); compiled_type_node comp_string_type=((compiled_type_node)SystemLibrary.string_type); compiled_type_node comp_object_type=((compiled_type_node)SystemLibrary.object_type); compiled_type_node comp_pointer_type=((compiled_type_node)SystemLibrary.pointer_type); compiled_type_node comp_exception_type=((compiled_type_node)SystemLibrary.exception_base_type); compiled_type_node comp_array_type = ((compiled_type_node)SystemLibrary.array_base_type); compiled_type_node comp_delegate_type = ((compiled_type_node)SystemLibrary.delegate_base_type); comp_byte_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_byte_type.compiled_type, symbol_table); comp_sbyte_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_sbyte_type.compiled_type, symbol_table); comp_short_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_short_type.compiled_type, symbol_table); comp_ushort_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_ushort_type.compiled_type, symbol_table); comp_integer_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_integer_type.compiled_type, symbol_table); comp_uint_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_uint_type.compiled_type, symbol_table); comp_long_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_long_type.compiled_type, symbol_table); comp_ulong_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_ulong_type.compiled_type, symbol_table); comp_real_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_real_type.compiled_type, symbol_table); comp_char_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_char_type.compiled_type, symbol_table); comp_bool_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_bool_type.compiled_type, symbol_table); comp_string_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_string_type.compiled_type, symbol_table); comp_object_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_object_type.compiled_type, symbol_table); comp_pointer_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_pointer_type.compiled_type, symbol_table); comp_exception_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_exception_type.compiled_type, symbol_table); comp_array_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_array_type.compiled_type, symbol_table); comp_delegate_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_delegate_type.compiled_type, symbol_table); init_temp_methods_and_consts(cnn,sc, initialization_properties,system_unit_location); return _system_unit; }
public void check_all_name_unit_defined(common_unit_node cmn) { check_predefinition_defined(cmn.namespaces[0]); check_predefinition_defined(cmn.namespaces[1]); }
private void UpdateUnitDefinitionItemForUnit(common_unit_node unit) { if (!from_pabc_dll) { SystemLibrary.SystemLibInitializer.read_procedure = new SystemLibrary.UnitDefinitionItem(unit, compiler_string_consts.read_procedure_name); SystemLibrary.SystemLibInitializer.readln_procedure = new SystemLibrary.UnitDefinitionItem(unit, compiler_string_consts.readln_procedure_name); } else { //SystemLibrary.SystemLibInitializer.read_procedure = new SystemLibrary.UnitDefinitionItem(unit, compiler_string_consts.read_procedure_name); //SystemLibrary.SystemLibInitializer.readln_procedure = new SystemLibrary.UnitDefinitionItem(unit, compiler_string_consts.readln_procedure_name); } }
public void check_all_name_unit_defined(common_unit_node cmn) { common_namespace_node cfn = cmn.namespaces[0]; foreach (common_namespace_function_node cnfn in cfn.functions) { if (cnfn.function_code == null) { throw new FunctionPredefinitionWithoutDefinition(cnfn); } } }
public void reset() { _system_unit = null; SystemLibrary.SystemLibrary.system_unit = null; //SystemLibrary.SystemLibrary.Reset(); SystemUnitAssigned = false; _compiled_unit = null; _referenced_units = null; current_document = null; using_list.clear(); //_referenced_units.clear(); ret.reset(); motivation_keeper.reset(); context.reset(); convertion_data_and_alghoritms.reset(); //compiled_type_node.compiled_types.Clear(); internal_reset(); release_system_module(); WaitedRefTypes.Clear(); set_intls.Clear(); NetHelper.NetHelper.reset(); if (ErrorsList != null) ErrorsList.Clear(); from_pabc_dll = false; in_interface_part = false; compiled_type_node[] ctns = new compiled_type_node[compiled_type_node.compiled_types.Values.Count]; compiled_type_node.compiled_types.Values.CopyTo(ctns, 0); null_type_node.reset(); foreach (compiled_type_node ctn in ctns) { ctn.reinit_scope(); ctn.clear_generated_names(); ctn.clear_generated_intersections(); } }
private void make_attributes_for_declaration(SyntaxTree.unit_module un, common_unit_node cun) { if (cun.attributes != null) { Hashtable ht = new Hashtable(); foreach (SyntaxTree.simple_attribute_list sal in un.attributes.attributes) for (int j = 0; j < sal.attributes.Count; j++) { SyntaxTree.attribute attr = sal.attributes[j]; attribute_converted = true; type_node tn = convert_strong(attr.type); bool is_attr = false; type_node tmp = tn; while (tmp.base_type != null && !is_attr) { is_attr = tmp.base_type == SystemLibrary.SystemLibrary.attribute_type; tmp = tmp.base_type; } if (!is_attr) AddError(get_location(attr), "CLASS_{0}_NOT_ATTRIBUTE", tn.name); bool allowMultiple = false; AttributeTargets targets = get_usage_attrs(tn, out allowMultiple); if (ht.Contains(tn) && !allowMultiple) { AddError(get_location(attr), "DUPLICATE_ATTRIBUTE_{0}_APPLICATION", tn.name); } else ht[tn] = tn; SemanticTree.attribute_qualifier_kind qualifier = SemanticTree.attribute_qualifier_kind.none_kind; if (attr.qualifier != null) if (j == 0) { if (string.Compare(attr.qualifier.name, "return", true) == 0) { if (context.top_function == null) AddError(get_location(attr), "ATTRIBUTE_APPLICABLE_ONLY_TO_METHOD"); if (context.top_function.return_value_type == null || context.top_function.return_value_type == SystemLibrary.SystemLibrary.void_type) AddError(get_location(attr), "EXPECTED_RETURN_VALUE_FOR_ATTRIBUTE"); throw new NotSupportedError(get_location(attr.qualifier)); qualifier = SemanticTree.attribute_qualifier_kind.return_kind; } else throw new NotSupportedError(get_location(attr.qualifier)); } else AddError(get_location(attr.qualifier), "ATTRIBUTE_QUALIFIER_MUST_BE_FIRST"); check_for_usage_attribute(cun, targets, tn.name, get_location(attr), qualifier); attribute_converted = false; SyntaxTree.expression_list cnstr_args = new SyntaxTree.expression_list(); if (attr.arguments != null) { foreach (SyntaxTree.expression e in attr.arguments.expressions) { if (e is SyntaxTree.bin_expr && (e as SyntaxTree.bin_expr).operation_type == SyntaxTree.Operators.Equal && (e as SyntaxTree.bin_expr).left is SyntaxTree.ident) { break; } else { cnstr_args.expressions.Add(e); } } } expressions_list args = new expressions_list(); for (int i = 0; i < cnstr_args.expressions.Count; i++) { constant_node cn = convert_strong_to_constant_node(cnstr_args.expressions[i]); check_for_strong_constant(cn, get_location(cnstr_args.expressions[i])); args.AddElement(cn); } base_function_call bfc = create_constructor_call(tn, args, get_location(attr)); attribute_node attr_node = new attribute_node(bfc.simple_function_node, tn, get_location(un)); foreach (expression_node en in bfc.parameters) { constant_node cn = convert_strong_to_constant_node(en, en.type); check_for_strong_constant(cn, en.location); attr_node.args.Add(cn); } if (attr.arguments != null) { for (int i = cnstr_args.expressions.Count; i < attr.arguments.expressions.Count; i++) { SyntaxTree.expression e = attr.arguments.expressions[i]; if (!(e is SyntaxTree.bin_expr && (e as SyntaxTree.bin_expr).operation_type == SyntaxTree.Operators.Equal && (e as SyntaxTree.bin_expr).left is SyntaxTree.ident)) { AddError(get_location(e), "EXPECTED_ATTRIBUTE_INITIALIZER"); } 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); type_node mem_tn = null; if (dn is property_node) { property_node pn = dn as property_node; attr_node.prop_names.Add(pn); if (pn.set_function == null) AddError(new ThisPropertyCanNotBeWrited(pn, get_location(id))); if (pn.set_function.parameters.Count != 1) AddError(get_location(id), "INDEX_PROPERTY_INITIALIZING_NOT_VALID"); mem_tn = pn.set_function.parameters[0].type; } else if (dn is var_definition_node) { attr_node.field_names.Add(dn as var_definition_node); mem_tn = (dn as var_definition_node).type; } else { throw new CompilerInternalError("Bad general node type for attribute initializer"); } //SyntaxTree.assign tmp_ass = new SyntaxTree.assign(id,(e as SyntaxTree.bin_expr).right,SyntaxTree.Operators.Assignment); //tmp_ass.source_context = e.source_context; //basic_function_call tmp_bfc = convert_strong(tmp_ass) as basic_function_call; constant_node cn = convert_strong_to_constant_node((e as SyntaxTree.bin_expr).right, mem_tn); check_for_strong_constant(cn, get_location((e as SyntaxTree.bin_expr).right)); if (dn is property_node) attr_node.prop_initializers.Add(cn); else attr_node.field_initializers.Add(cn); } } } attr_node.qualifier = qualifier; cun.attributes.AddElement(attr_node); if (cun.namespaces.Count > 0) cun.namespaces[0].attributes.AddElement(attr_node); } } }
//TODO: Слить как нибудь два следующих метода. public override void visit(SyntaxTree.program_module _program_module) { //MikhailoMMX Инициализация OpenMP OpenMP.InitOpenMP(_program_module.compiler_directives, this, _program_module); //\MikhailoMMX //current_document=new document(_program_module.file_name); string namespace_name = ""; location loc = get_location(_program_module); if (_program_module.program_name != null) { namespace_name = _program_module.program_name.prog_name.name; loc = get_location(_program_module.program_name.prog_name); //if (namespace_name.ToLower() != System.IO.Path.GetFileNameWithoutExtension(_program_module.file_name).ToLower()) // throw new ProgramNameMustBeEqualProgramFileName(loc); } _compiled_unit = new common_unit_node(); _compiled_unit.compiler_directives = ConvertDirectives(_program_module); //PrepareDirectives(_compiled_unit.compiler_directives); //using_list.AddRange(interface_using_list); //weak_node_test_and_visit(_program_module.using_namespaces); //weak_node_test_and_visit(_program_module.used_units); //compiled_main_unit=new unit_node(); //SymbolTable.Scope[] used_units=new SymbolTable.Scope[used_assemblyes.Count+1]; SymbolTable.Scope[] used_units = build_referenced_units(referenced_units,true); _compiled_unit.scope = convertion_data_and_alghoritms.symbol_table.CreateUnitInterfaceScope(used_units); common_namespace_node cnsn = context.create_namespace(namespace_name, _compiled_unit, _compiled_unit.scope, loc); cnsn.is_main = true; //compiled_program=new program_node(); //compiled_program.units.Add(compiled_main_unit); reset_for_interface(); UpdateUnitDefinitionItemForUnit(_compiled_unit); //_program_module.program_block.visit(this); hard_node_test_and_visit(_program_module.program_block); context.check_labels(context.converted_namespace.labels); // frninja 28/04/16 - режем мусорные методы хелперы yield { var toRemove = cnsn.functions.Where(m => m.name.StartsWith(YieldHelpers.YieldConsts.YieldHelperMethodPrefix)).ToArray(); foreach (var m in toRemove) { cnsn.functions.remove(m); } } // end frninja //TODO: Доделать. common_namespace_function_node main_function = new common_namespace_function_node(compiler_string_consts.temp_main_function_name, null, null, cnsn, null); main_function.function_code = context.code; context.apply_special_local_vars(main_function); cnsn.functions.AddElement(main_function); context.leave_block(); _compiled_unit.main_function = main_function; //cnsn.SetNamespaceName(System.IO.Path.GetFileNameWithoutExtension(_program_module.file_name)); }
private void internal_reset() { PascalABCCompiler.SystemLibrary.SystemLibInitializer.initialization_properties init_properties = new PascalABCCompiler.SystemLibrary.SystemLibInitializer.initialization_properties(); init_properties.break_executor = make_break_node; init_properties.continue_executor = make_continue_node; init_properties.exit_executor = make_exit_node; _system_unit = SystemLibrary.SystemLibInitializer.make_system_unit(convertion_data_and_alghoritms.symbol_table, init_properties); SystemLibrary.SystemLibrary.system_unit = _system_unit; generic_convertions.reset_generics(); _record_created = false; RefTypesForCheckPointersTypeForDotNetFramework.Clear(); reset_for_interface(); _is_interface_part = false; with_class_name=false; generic_param_abilities.Clear(); current_converted_method_not_in_class_defined = false; assign_is_converting = false; motivation_keeper.reset(); SystemLibrary.SystemLibInitializer.NeedsToRestore.Clear(); type_section_converting = false; #region MikhailoMMX, реинициализация класса OpenMP OpenMP.InternalReset(); CurrentParallelPosition = ParallelPosition.Outside; #endregion lambdaProcessingState = LambdaProcessingState.None; //lroman CapturedVariablesSubstitutionClassGenerator.Reset(); }
//процедура сохранения модуля на диск public void SaveSemanticTree(CompilationUnit Unit, string TargetFileName, bool IncludeDebugInfo) { pcu_file.IncludeDebugInfo = IncludeDebugInfo; pcu_file.UseRtlDll = compiler.CompilerOptions.UseDllForSystemUnits; unit = Unit; cun = (common_unit_node)unit.SemanticTree; this.FileName = TargetFileName; string program_folder=System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(TargetFileName)); name = System.IO.Path.GetFileName(TargetFileName); //name = name.Substring(0,name.LastIndexOf('.'))+".pcu"; //FileStream fs = new FileStream(name,FileMode.Create,FileAccess.ReadWrite); ChangeState(this, PCUReaderWriterState.BeginSaveTree, TargetFileName); pcu_file.compiler_directives = cun.compiler_directives; if (Path.GetDirectoryName(TargetFileName).ToLower() == Path.GetDirectoryName(Unit.SyntaxTree.file_name).ToLower()) pcu_file.SourceFileName = Path.GetFileName(Unit.SyntaxTree.file_name); else pcu_file.SourceFileName = Unit.SyntaxTree.file_name; ms = new MemoryStream(); bw = new BinaryWriter(ms); //if (Unit.InterfaceUsedUnits.Count > 0) Console.WriteLine("{0} {1}",name,Unit.InterfaceUsedUnits[0].namespaces[0].namespace_name); cur_cnn = cun.namespaces[0]; //(ssyy) формируем список нешаблонных классов cur_cnn.MakeNonTemplateTypesList(); GetUsedUnits();//заполняем список полключаемых модулей GetCountOfMembers();//заполняем список имен интерфейсных сущностей WriteUnit();//пишем имя interface_namespace cur_cnn = cun.namespaces[1]; //(ssyy) формируем список нешаблонных классов cur_cnn.MakeNonTemplateTypesList(); GetCountOfImplementationMembers();//(ssyy) заполняем список имен сущностей реализации WriteUnit();//пишем имя implementation_namespace SaveOffsetForAttribute(cun.namespaces[0]); bw.Write(0);//attributes; cur_cnn = cun.namespaces[0]; //bw.Write((byte)0); //bw.Write((byte)0); //ssyy VisitTemplateClasses();//сериализуем шаблонные классы //\ssyy VisitTypeDefinitions();//сериализуем описания типов интерфейсной части //ssyy pcu_file.interface_synonyms_offset = (int)bw.BaseStream.Position; VisitTypeSynonyms(); //\ssyy cur_cnn = cun.namespaces[1]; is_interface = false; //ssyy VisitLabelDeclarations(cur_cnn.labels); //сериализуем метки type_entity_index = 0; VisitTemplateClasses();//сериализуем шаблонные классы //\ssyy VisitTypeDefinitions();//сериализуем описания типов имплемент. части //ssyy pcu_file.implementation_synonyms_offset = (int)bw.BaseStream.Position; VisitTypeSynonyms(); //\ssyy cur_cnn = cun.namespaces[0]; is_interface = true; foreach (common_type_node ctn in cur_cnn.non_template_types) { VisitTypeMemberDefinition(ctn); } cur_cnn = cun.namespaces[1]; is_interface = false; foreach (common_type_node ctn in cur_cnn.non_template_types) { VisitTypeMemberDefinition(ctn); } cur_cnn = cun.namespaces[0]; is_interface = true; VisitConstantDefinitions();//сериализуем константы VisitVariableDefinitions();//сериализуем переменные VisitFunctionDefinitions();//сериализуем функции VisitRefTypeDefinitions(); VisitEventDefinitions(); cur_cnn = cun.namespaces[1]; is_interface = false; entity_index = 0; //имплементационная часть VisitConstantDefinitions(); VisitVariableDefinitions(); VisitFunctionDefinitions(); VisitRefTypeDefinitions(); VisitEventDefinitions(); cur_cnn = cun.namespaces[0]; //сериализуем тела функций foreach (common_namespace_function_node cnfn in cur_cnn.functions) { VisitFunctionImplementation(cnfn); } //сериализуем тела методов и конструкторов типа foreach (common_type_node ctn in cur_cnn.non_template_types) { VisitTypeImplementation(ctn); } cur_cnn = cun.namespaces[1]; //имплементационная часть foreach (common_namespace_function_node cnfn in cur_cnn.functions) VisitFunctionImplementation(cnfn); foreach (common_type_node ctn in cur_cnn.non_template_types) { VisitTypeImplementation(ctn); } WriteVariablePositions(); WriteConstantPositions(); AddAttributes(); WriteInitExpressions(); //сохранение интерфейсной и имплементац. частей модуля if (ext_offsets.Count != 0) { List<definition_node> dnl = new List<definition_node>(ext_offsets.Keys); foreach (definition_node wdn in dnl) { if (wdn is wrapped_definition_node) AddOffsetForMembers(wdn, (wdn as wrapped_definition_node).offset); else if (wdn is wrapped_common_type_node) AddOffsetForMembers(wdn, (wdn as wrapped_common_type_node).offset); else if (PCUReader.AllReadOrWritedDefinitionNodesOffsets.ContainsKey(wdn)) AddOffsetForMembers(wdn, PCUReader.AllReadOrWritedDefinitionNodesOffsets[wdn]); } //ssyy 01.07.2007 //CloseWriter(); //\ssyy } //если нет импортирумых сущностей, смещение которых неизвестно else //if (ext_offsets.Count == 0) { //CloseWriter(); /*FileStream fs = new FileStream(TargetFileName, FileMode.Create, FileAccess.ReadWrite); BinaryWriter fbw = new BinaryWriter(fs); WritePCUHeader(fbw); //пишем заголовок PCU byte[] buf = new byte[bw.BaseStream.Length]; bw.Seek(0, SeekOrigin.Begin); bw.BaseStream.Read(buf, 0, buf.Length); fbw.Write(buf); bw.Close(); ms.Close(); fbw.Close(); fs.Close();*/ //если существовал pcu, который использовался reader-ом и была циклическая связь //if (pcu_reader != null) pcu_reader.OpenUnit(); } }
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) { namespace_variable_reference nvr = new namespace_variable_reference(si.sym_info as namespace_variable, null); psystem_unit.IsConsoleApplicationVariableAssignExpr = make_assign_operator(nvr, psystem_unit.IsConsoleApplicationVariableValue, null); } }