private void init_constants(SymbolTable.Scope sc) { _true_constant = new bool_const_node(true, _bool_type); _false_constant = new bool_const_node(false, _bool_type); _true_constant_definition = new constant_definition_node(compiler_string_consts.true_const_name, _true_constant); _false_constant_definition = new constant_definition_node(compiler_string_consts.false_const_name, _false_constant); sc.AddSymbol(compiler_string_consts.true_const_name, new SymbolInfo(_true_constant_definition)); sc.AddSymbol(compiler_string_consts.false_const_name, new SymbolInfo(_false_constant_definition)); }
private void init_procedures(convertion_data_and_alghoritms conv, SymbolTable.Scope susc) { pseudo_function break_procedure = new pseudo_function(compiler_string_consts.break_procedure_name, new pseudo_function_algorithm(conv.syntax_tree_visitor.make_break_node)); susc.AddSymbol(compiler_string_consts.break_procedure_name, new SymbolInfo(break_procedure)); pseudo_function continue_procedure = new pseudo_function(compiler_string_consts.continue_procedure_name, new pseudo_function_algorithm(conv.syntax_tree_visitor.make_continue_node)); susc.AddSymbol(compiler_string_consts.continue_procedure_name, new SymbolInfo(continue_procedure)); }
private void make_system_unit(convertion_data_and_alghoritms conv) { _system_unit = new unit_node(); _system_unit.scope = conv.symbol_table.CreateUnitInterfaceScope(new SymbolTable.Scope[0]); SymbolTable.Scope susc = _system_unit.scope; //Добавляем типы. susc.AddSymbol(compiler_string_consts.integer_type_name, new SymbolInfo(_integer_type)); susc.AddSymbol(compiler_string_consts.real_type_name, new SymbolInfo(_real_type)); susc.AddSymbol(compiler_string_consts.char_type_name, new SymbolInfo(_char_type)); susc.AddSymbol(compiler_string_consts.bool_type_name, new SymbolInfo(_bool_type)); susc.AddSymbol(compiler_string_consts.string_type_name, new SymbolInfo(_string_type)); susc.AddSymbol(compiler_string_consts.pointer_type_name, new SymbolInfo(_pointer_type)); init_constants(susc); init_procedures(conv, susc); init_temp_methods(susc); }
private void init_temp_methods(SymbolTable.Scope sc) { //TODO: Сделано по быстрому. Переделать. Type tp = typeof(Console); compiled_function_node cfn; System.Type[] arr = new System.Type[1]; System.Reflection.MethodInfo mi; arr[0] = typeof(int); mi = tp.GetMethod("WriteLine", arr); cfn = new compiled_function_node(mi); cfn.parameters.Clear(); cfn.parameters.Add(new common_parameter("val", _integer_type, SemanticTree.parameter_type.value, null)); sc.AddSymbol("writeln", new SymbolInfo(cfn)); arr[0] = typeof(double); mi = tp.GetMethod("WriteLine", arr); cfn = new compiled_function_node(mi); cfn.parameters.Clear(); cfn.parameters.Add(new common_parameter("val", _real_type, SemanticTree.parameter_type.value, null)); sc.AddSymbol("writeln", new SymbolInfo(cfn)); arr[0] = typeof(char); mi = tp.GetMethod("WriteLine", arr); cfn = new compiled_function_node(mi); cfn.parameters.Clear(); cfn.parameters.Add(new common_parameter("val", _char_type, SemanticTree.parameter_type.value, null)); sc.AddSymbol("writeln", new SymbolInfo(cfn)); arr[0] = typeof(bool); mi = tp.GetMethod("WriteLine", arr); cfn = new compiled_function_node(mi); cfn.parameters.Clear(); cfn.parameters.Add(new common_parameter("val", _bool_type, SemanticTree.parameter_type.value, null)); sc.AddSymbol("writeln", new SymbolInfo(cfn)); arr[0] = typeof(string); mi = tp.GetMethod("WriteLine", arr); cfn = new compiled_function_node(mi); cfn.parameters.Clear(); cfn.parameters.Add(new common_parameter("val", _string_type, SemanticTree.parameter_type.value, null)); sc.AddSymbol("writeln", new SymbolInfo(cfn)); mi = tp.GetMethod("ReadLine", new System.Type[0]); cfn = new compiled_function_node(mi); cfn.parameters.Clear(); cfn.return_value_type = _string_type; sc.AddSymbol("readline", new SymbolInfo(cfn)); make_assign_operator(_string_type, SemanticTree.basic_function_type.objassign); tp = typeof(int); arr[0] = typeof(string); mi = tp.GetMethod("Parse", arr); cfn = new compiled_function_node(mi); cfn.parameters.Clear(); cfn.parameters.Add(new common_parameter("val", _string_type, SemanticTree.parameter_type.value, null)); cfn.return_value_type = _integer_type; sc.AddSymbol("parseint", new SymbolInfo(cfn)); tp = typeof(double); arr[0] = typeof(string); mi = tp.GetMethod("Parse", arr); cfn = new compiled_function_node(mi); cfn.parameters.Clear(); cfn.parameters.Add(new common_parameter("val", _string_type, SemanticTree.parameter_type.value, null)); cfn.return_value_type = _real_type; sc.AddSymbol("parsereal", new SymbolInfo(cfn)); tp = typeof(bool); arr[0] = typeof(string); mi = tp.GetMethod("Parse", arr); cfn = new compiled_function_node(mi); cfn.parameters.Clear(); cfn.parameters.Add(new common_parameter("val", _string_type, SemanticTree.parameter_type.value, null)); cfn.return_value_type = _bool_type; sc.AddSymbol("parsebool", new SymbolInfo(cfn)); tp = typeof(char); arr[0] = typeof(string); mi = tp.GetMethod("Parse", arr); cfn = new compiled_function_node(mi); cfn.parameters.Clear(); cfn.parameters.Add(new common_parameter("val", _string_type, SemanticTree.parameter_type.value, null)); cfn.return_value_type = _char_type; sc.AddSymbol("parsechar", new SymbolInfo(cfn)); common_namespace_function_node cnfn = new common_namespace_function_node("New", null); cnfn.parameters.Clear(); cnfn.parameters.Add(new common_parameter("ptr", _pointer_type, SemanticTree.parameter_type.value, null)); sc.AddSymbol("new", new SymbolInfo(cnfn)); cnfn = new common_namespace_function_node("Dispose", null); cnfn.parameters.Clear(); cnfn.parameters.Add(new common_parameter("ptr", _pointer_type, SemanticTree.parameter_type.value, null)); sc.AddSymbol("dispose", new SymbolInfo(cnfn)); }
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); }
private static void init_temp_methods_and_consts(common_namespace_node system_namespace, SymbolTable.Scope where_add, initialization_properties initialization_properties, location system_unit_location) { //SymbolTable.Scope sc = system_namespace.scope; SymbolTable.Scope sc = where_add; namespace_constant_definition _true_constant_definition = new namespace_constant_definition( PascalABCCompiler.TreeConverter.compiler_string_consts.true_const_name, SystemLibrary.true_constant, system_unit_location, system_namespace); system_namespace.constants.AddElement(_true_constant_definition); namespace_constant_definition _false_constant_definition = new namespace_constant_definition( 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)); //TODO: Сделано по быстрому. Переделать. Можно просто один раз сериализовать модуль system и не инициализировать его всякий раз подобным образом. Неплохо-бы использовать NetHelper.GetMethod. Type tp = typeof(Console); compiled_function_node cfn; System.Type[] arr = new System.Type[1]; System.Reflection.MethodInfo mi; //TODO: Сделать узел или базовый метод создания и удаления объекта. common_namespace_function_node cnfn = new common_namespace_function_node(TreeConverter.compiler_string_consts.new_procedure_name, null, null, system_namespace, null); cnfn.parameters.AddElement(new common_parameter("ptr", SystemLibrary.pointer_type, SemanticTree.parameter_type.value, cnfn, concrete_parameter_type.cpt_var, null, null)); cnfn.SpecialFunctionKind = SemanticTree.SpecialFunctionKind.New; _NewProcedure = new PascalABCCompiler.TreeConverter.SymbolInfo(cnfn); _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); 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, cnfn, concrete_parameter_type.cpt_var, null, null)); _DisposeProcedure = new PascalABCCompiler.TreeConverter.SymbolInfo(cnfn); _DisposeProcedure.symbol_kind = PascalABCCompiler.TreeConverter.symbol_kind.sk_overload_function; _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); 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, concrete_parameter_type.cpt_none, null, null)); cnfn.parameters.AddElement(new common_parameter("n", SystemLibrary.integer_type, SemanticTree.parameter_type.value, cnfn, concrete_parameter_type.cpt_none, null, null)); cnfn.SpecialFunctionKind = SemanticTree.SpecialFunctionKind.NewArray; _NewArrayProcedure = new PascalABCCompiler.TreeConverter.SymbolInfo(cnfn); _NewArrayProcedureDecl = cnfn; //sc.AddSymbol(TreeConverter.compiler_string_consts.new_procedure_name, _NewProcedure); basic_function_node break_procedure = new basic_function_node(SemanticTree.basic_function_type.none, null, true, PascalABCCompiler.TreeConverter.compiler_string_consts.break_procedure_name); 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)); basic_function_node continue_procedure = new basic_function_node(SemanticTree.basic_function_type.none, null, true, PascalABCCompiler.TreeConverter.compiler_string_consts.continue_procedure_name); 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)); basic_function_node exit_procedure = new basic_function_node(SemanticTree.basic_function_type.none, null, true, PascalABCCompiler.TreeConverter.compiler_string_consts.exit_procedure_name); 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.set_length_procedure_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.resize_func, PascalABCCompiler.TreeConverter.access_level.al_public, PascalABCCompiler.TreeConverter.symbol_kind.sk_overload_function)); }