public override void visit(statement_list stmtList) { var stl = new statements_list(_visitor.get_location(stmtList), _visitor.get_location_with_check(stmtList.left_logical_bracket), _visitor.get_location_with_check(stmtList.right_logical_bracket)); _visitor.convertion_data_and_alghoritms.statement_list_stack_push(stl); var newTreeNode = new CapturedVariablesTreeNodeBlockScope(_currentTreeNode, stl.Scope.ScopeNum, stmtList); if (_rootNode == null) { _rootNode = newTreeNode; } if (_currentTreeNode != null) { _currentTreeNode.ChildNodes.Add(newTreeNode); } _currentTreeNode = newTreeNode; _scopesCapturedVarsNodesDictionary.Add(stl.Scope.ScopeNum, _currentTreeNode); if (stmtList.subnodes != null) { foreach (var stmt in stmtList.subnodes) { ProcessNode(stmt); } } _visitor.convertion_data_and_alghoritms.statement_list_stack.pop(); _currentTreeNode = _currentTreeNode.ParentNode; }
public override void visit(statement_list stmtList) { var stl = new statements_list(syntaxTreeVisitor.get_location(stmtList), syntaxTreeVisitor.get_location_with_check(stmtList.left_logical_bracket), syntaxTreeVisitor.get_location_with_check(stmtList.right_logical_bracket)); syntaxTreeVisitor.convertion_data_and_alghoritms.statement_list_stack_push(stl); if (stmtList.subnodes != null) foreach (var stmt in stmtList.subnodes) ProcessNode(stmt); syntaxTreeVisitor.convertion_data_and_alghoritms.statement_list_stack.pop(); }
public void create_main_function_as_in_module() { add_needed_cctors(); statements_list sl = new statements_list(loc); statements_list intern_sl = new statements_list(loc); statements_list sl2 = sl; sl = new statements_list(null); common_namespace_function_node init_func = new common_namespace_function_node("$_Init_", null, null, common_namespaces[0], null); common_namespaces[0].functions.AddElement(init_func); namespace_variable init_var = new namespace_variable("$is_init", SystemLibrary.SystemLibrary.bool_type, common_namespaces[0], null); common_namespaces[0].variables.AddElement(init_var); for (int i = 0; i < units.Count; i++) { if (units[i].main_function != null) { common_namespace_function_call cnfc = new common_namespace_function_call(units[i].main_function, loc); sl.statements.AddElement(cnfc); } } /*for (int i = units.Count - 1; i >= 0; i--) * { * if (units[i].finalization_method != null) * { * common_namespace_function_call cnfc = new common_namespace_function_call(units[i].finalization_method, loc); * sl.statements.AddElement(cnfc); * } * }*/ sl2 = new statements_list(loc); basic_function_call bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_assign as basic_function_node, null); bfc.parameters.AddElement(new namespace_variable_reference(init_var, null)); bfc.parameters.AddElement(new bool_const_node(true, null)); sl.statements.AddElementFirst(bfc); bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_not as basic_function_node, null); bfc.parameters.AddElement(new namespace_variable_reference(init_var, null)); sl2.statements.AddElement(new if_node(bfc, sl, null, null)); init_func.function_code = sl2; _init_code = new common_namespace_function_call(init_func, null); add_initialization_to_cctors(); }
public override void visit(SyntaxTree.repeat_node _repeat_node) { repeat_node rep = new repeat_node(get_location(_repeat_node)); context.cycle_stack.push(rep); statements_list sl = new statements_list(get_location(_repeat_node.statements)); convertion_data_and_alghoritms.statement_list_stack_push(sl); CheckToEmbeddedStatementCannotBeADeclaration(_repeat_node.statements); statement_node st = convert_strong(_repeat_node.statements); sl = convertion_data_and_alghoritms.statement_list_stack.pop(); //if (!(st is statements_list)) if (sl.statements.Count > 0 || sl.local_variables.Count > 0) { sl.statements.AddElement(st); st = sl; } rep.body = st; expression_node expr = convert_strong(_repeat_node.expr); expr = convertion_data_and_alghoritms.convert_type(expr, SystemLibrary.SystemLibrary.bool_type); rep.condition = expr; context.cycle_stack.pop(); return_value(rep); }
private static bool GenerateOMPParallelForCall(statement_node body, SyntaxTree.for_node for_node, var_definition_node loop_variable, statements_list omp_stmts, syntax_tree_visitor syntax_tree_visitor, expression_node fromInclusive, expression_node toInclusive) { SyntaxTree.statement syntax_body = for_node.statements; expression_node omp_call = null; base_function_call bfc = body as base_function_call; if (bfc != null && bfc.parameters.Count == 1 && bfc.parameters[0] is variable_reference && ((variable_reference)bfc.parameters[0]).VariableDefinition == loop_variable && ((bfc.function.parameters[0].type as type_node).PrintableName.ToLower() == "integer")) { //если тело цикла - вызов функции с одни параметром - переменной цикла, //если при этом у вызываемой функции тип параметра - integer, а не какой-нибудь object, как это бывает с write и вообще может быть с перегрузкой //то генерировать класс не надо. //генерируем вызов и все omp_call = syntax_tree_visitor.CreateDelegateCall(bfc); if (omp_call == null) { syntax_tree_visitor.AddWarning(new OMP_ConstructionNotSupportedNow(body.location)); syntax_tree_visitor.convertion_data_and_alghoritms.statement_list_stack_pop(); return false; } base_function_call omp_parallel_for_call = null; if (SystemLibrary.SystemLibInitializer.OMP_ParallelFor.sym_info is common_namespace_function_node) omp_parallel_for_call = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.OMP_ParallelFor.sym_info as common_namespace_function_node, body.location); else omp_parallel_for_call = new compiled_static_method_call(SystemLibrary.SystemLibInitializer.OMP_ParallelFor.sym_info as compiled_function_node, body.location); omp_parallel_for_call.parameters.AddElement(fromInclusive); omp_parallel_for_call.parameters.AddElement(toInclusive); omp_parallel_for_call.parameters.AddElement(omp_call); omp_stmts.statements.AddElement(omp_parallel_for_call); } else { //ищем используемые переменные, получаем редукцию из директивы и составляем список переменных по типам VarFinderSyntaxVisitor VFvis = new VarFinderSyntaxVisitor(syntax_body, syntax_tree_visitor.context, true); SyntaxTree.compiler_directive dir = syntax_tree_visitor.DirectivesToNodesLinks[for_node]; //if (DirInfosTable[dir].ErrorName == "WARNING_IN_CLAUSE_PARAMETERS_REPEATED_VARS") // syntax_tree_visitor.AddWarning(new Errors.CommonWarning(StringResources.Get(DirInfosTable[dir].ErrorName), for_node.source_context.FileName, DirInfosTable[dir].SC.begin_position.line_num, DirInfosTable[dir].SC.begin_position.column_num)); //else if (DirInfosTable[dir].ErrorName == "ERROR_IN_CLAUSE_PARAMETERS") //{ // syntax_tree_visitor.AddWarning(new Errors.CommonWarning(StringResources.Get(DirInfosTable[dir].ErrorName), for_node.source_context.FileName, DirInfosTable[dir].SC.begin_position.line_num, DirInfosTable[dir].SC.begin_position.column_num)); //} //else if (DirInfosTable[dir].ErrorName !=null)//== "ERROR_IN_CLAUSE") { syntax_tree_visitor.AddWarning(new Errors.CommonWarning(PascalABCCompiler.StringResources.Get(DirInfosTable[dir].ErrorName), for_node.source_context.FileName, DirInfosTable[dir].SC.begin_position.line_num, DirInfosTable[dir].SC.begin_position.column_num)); } VarInfoContainer Vars = GetVarInfoContainer(VFvis, DirInfosTable[dir].Reductions, DirInfosTable[dir].Privates, syntax_tree_visitor, dir); //сохраняем контекст ContextInfo contextInfo = new ContextInfo(syntax_tree_visitor); string ClassName = syntax_tree_visitor.context.get_free_name("$for_class{0}"); try { //создаем и конвертируем класс SyntaxTree.class_members member; SyntaxTree.type_declarations Decls = CreateClass(ClassName, out member, Vars); member.members.Add(CreateMethod("Method", syntax_body, for_node.loop_variable.name, member, Vars)); syntax_tree_visitor.visit(Decls); } finally { //восстанавливаем контекст contextInfo.RestoreContext(syntax_tree_visitor); } //создаем инициализацию, вызов и финализацию string ObjName = syntax_tree_visitor.context.get_free_name("$for_obj{0}"); SyntaxTree.dot_node dn = new SyntaxTree.dot_node(new SyntaxTree.ident(ObjName), new SyntaxTree.ident("Method")); SyntaxTree.statement_list stl = CreateInitPart(ClassName, ObjName, Vars); stl.subnodes.Add(CreateNestedRegionBorder(true)); stl.subnodes.Add(CreateOMPParallelForCall(dn, for_node.initial_value, for_node.finish_value)); stl.subnodes.Add(CreateNestedRegionBorder(false)); stl.subnodes.AddRange(CreateFinalPart(ObjName, Vars).subnodes); omp_stmts.statements.AddElement(syntax_tree_visitor.ret.visit(stl)); } return true; }
public override void visit(SyntaxTree.while_node _while_node) { expression_node expr = convert_strong(_while_node.expr); expr = convertion_data_and_alghoritms.convert_type(expr, SystemLibrary.SystemLibrary.bool_type); CheckToEmbeddedStatementCannotBeADeclaration(_while_node.statements); while_node wn = new while_node(expr, get_location(_while_node)); context.cycle_stack.push(wn); statements_list sl = new statements_list(get_location(_while_node.statements)); convertion_data_and_alghoritms.statement_list_stack_push(sl); context.enter_code_block_with_bind(); statement_node st = convert_strong(_while_node.statements); context.leave_code_block(); sl = convertion_data_and_alghoritms.statement_list_stack.pop(); if (sl.statements.Count > 0 || sl.local_variables.Count > 0) { sl.statements.AddElement(st); st = sl; } wn.body = st; context.cycle_stack.pop(); return_value(wn); }
public void create_main_function(string[] used_stand_modules, Dictionary <string, object> config) { add_needed_cctors(); common_namespace_function_node temp = _main_function; _main_function = new common_namespace_function_node("Main", null, null, (common_namespace_node)_main_function.comprehensive_namespace, null); location loc = temp.loc; statements_list sl = new statements_list(loc); _main_function.function_code = sl; // if (units[0].MainArgsParameter!=null) // { // _main_function.parameters.AddElement(units[0].MainArgsParameter); // sl.statements.AddElement(units[0].MainArgsAssignExpr); // } // if (units[0].IsConsoleApplicationVariableAssignExpr!=null) // { // sl.statements.AddElement(units[0].IsConsoleApplicationVariableAssignExpr); // } statements_list sl2 = sl; sl = new statements_list(null); common_namespace_function_node init_func = new common_namespace_function_node("$_Init_", null, null, (common_namespace_node)_main_function.comprehensive_namespace, null); ((common_namespace_node)_main_function.comprehensive_namespace).functions.AddElement(init_func); namespace_variable init_var = new namespace_variable("$is_init", SystemLibrary.SystemLibrary.bool_type, (common_namespace_node)_main_function.comprehensive_namespace, null); ((common_namespace_node)_main_function.comprehensive_namespace).variables.AddElement(init_var); if (SystemLibrary.SystemLibInitializer.ConfigVariable != null && SystemLibrary.SystemLibInitializer.ConfigVariable.Found) { namespace_variable conf_nv = null; compiled_variable_definition conf_cf = null; if (SystemLibrary.SystemLibInitializer.ConfigVariable.sym_info is namespace_variable) { conf_nv = SystemLibrary.SystemLibInitializer.ConfigVariable.sym_info as namespace_variable; } else { conf_cf = SystemLibrary.SystemLibInitializer.ConfigVariable.sym_info as compiled_variable_definition; } foreach (string config_var in config.Keys) { var config_value = config[config_var]; compiled_function_call cfc = new compiled_function_call(compiled_function_node.get_compiled_method(NetHelper.NetHelper.AddToDictionaryMethod), (conf_nv != null) ? (expression_node) new namespace_variable_reference(conf_nv, null) : (expression_node) new static_compiled_variable_reference(conf_cf, null), null); cfc.parameters.AddElement(new string_const_node(config_var, null)); switch (Type.GetTypeCode(config_value.GetType())) { case TypeCode.String: cfc.parameters.AddElement(new string_const_node((string)config_value, null)); break; case TypeCode.Int32: cfc.parameters.AddElement(new int_const_node((int)config_value, null)); break; case TypeCode.Boolean: cfc.parameters.AddElement(new bool_const_node((bool)config_value, null)); break; case TypeCode.Double: cfc.parameters.AddElement(new double_const_node((double)config_value, null)); break; default: throw new NotSupportedException("Config value type is nort supported"); } sl.statements.AddElement(cfc); } } if (units[0].MainArgsParameter != null) { _main_function.parameters.AddElement(units[0].MainArgsParameter); sl.statements.AddElementFirst(units[0].MainArgsAssignExpr); } if (units[0].IsConsoleApplicationVariableAssignExpr != null) { sl.statements.AddElementFirst(units[0].IsConsoleApplicationVariableAssignExpr); } for (int i = 0; i < units.Count; i++) { if (units[i].main_function != null) { if (units[i].main_function.name != TreeConverter.compiler_string_consts.temp_main_function_name) { common_namespace_function_call cnfc = new common_namespace_function_call(units[i].main_function, loc); sl.statements.AddElement(cnfc); } else { common_namespace_function_call cnfc = new common_namespace_function_call(units[i].main_function, loc); sl2.statements.AddElement(cnfc); } } } //if (units.Count == 1) for (int i = 0; i < used_stand_modules.Length; i++) { Type t = NetHelper.NetHelper.FindRtlType(used_stand_modules[i] + "." + used_stand_modules[i]); if (t == null) { continue; } compiled_type_node ctn = compiled_type_node.get_type_node(t); System.Reflection.MethodInfo mi = ctn.compiled_type.GetMethod("__InitModule__"); if (mi == null) { continue; } compiled_static_method_call csmc = new compiled_static_method_call(compiled_function_node.get_compiled_method(mi), null); sl.statements.AddElement(csmc); } for (int i = units.Count - 1; i >= 0; i--) { if (units[i].finalization_method != null) { common_namespace_function_call cnfc = new common_namespace_function_call(units[i].finalization_method, loc); sl2.statements.AddElement(cnfc); } } //if (units.Count == 1) for (int i = 0; i < used_stand_modules.Length; i++) { Type t = NetHelper.NetHelper.FindRtlType(used_stand_modules[i] + "." + used_stand_modules[i]); if (t == null) { continue; } compiled_type_node ctn = compiled_type_node.get_type_node(t); System.Reflection.MethodInfo mi = ctn.compiled_type.GetMethod("__FinalizeModule__"); if (mi == null) { continue; } compiled_static_method_call csmc = new compiled_static_method_call(compiled_function_node.get_compiled_method(mi), null); sl2.statements.AddElement(csmc); } sl2 = new statements_list(loc); basic_function_call bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_assign as basic_function_node, null); bfc.parameters.AddElement(new namespace_variable_reference(init_var, null)); bfc.parameters.AddElement(new bool_const_node(true, null)); sl.statements.AddElementFirst(bfc); bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_not as basic_function_node, null); bfc.parameters.AddElement(new namespace_variable_reference(init_var, null)); sl2.statements.AddElement(new if_node(bfc, sl, null, null)); init_func.function_code = sl2; sl = new statements_list(null); sl.statements.AddElement(new common_namespace_function_call(init_func, null)); common_namespace_function_node init_variables_func = new common_namespace_function_node("$_InitVariables_", null, null, (common_namespace_node)_main_function.comprehensive_namespace, null); init_variables_func.function_code = new statements_list(null); ((common_namespace_node)_main_function.comprehensive_namespace).functions.AddElement(init_variables_func); sl.statements.AddElement(new common_namespace_function_call(init_variables_func, null)); _init_code = sl; }
private void VisitStatementList(statements_list stmt) { bw.Write(stmt.local_variables.Count); foreach (local_block_variable lv in stmt.local_variables) VisitLocalBlockVariable(lv); bw.Write(stmt.statements.Count); foreach (statement_node sn in stmt.statements) VisitStatement(sn); WriteDebugInfo(stmt.LeftLogicalBracketLocation); WriteDebugInfo(stmt.RightLogicalBracketLocation); }
public override void visit(SyntaxTree.try_stmt _try_stmt) { context.enter_code_block_without_bind(); context.enter_exception_handlers(); statement_node try_statements = convert_strong(_try_stmt.stmt_list); context.leave_code_block(); location loc = get_location(_try_stmt); exception_filters_list efl = new exception_filters_list(); SyntaxTree.try_handler_except try_hand_except = _try_stmt.handler as SyntaxTree.try_handler_except; if (try_hand_except != null) { if (try_hand_except.except_block.handlers != null) { int hand_count = try_hand_except.except_block.handlers.handlers.Count; for (int i = 0; i < hand_count; i++) { SyntaxTree.exception_handler eh = try_hand_except.except_block.handlers.handlers[i]; type_node filter_type = convert_strong(eh.type_name); if (!SemanticRules.GenerateNativeCode && !(filter_type.is_generic_parameter || filter_type == SystemLibrary.SystemLibrary.exception_base_type || type_table.is_derived(SystemLibrary.SystemLibrary.exception_base_type, filter_type))) { AddError(get_location(eh.type_name), "EXCEPTION_TYPE_MUST_BE_SYSTEM_EXCEPTION_OR_DERIVED_FROM_EXCEPTION"); } current_catch_excep = new int_const_node(2,null);//create_constructor_call(filter_type, new expressions_list(), null); local_block_variable_reference lvr = null; context.enter_code_block_without_bind(); if (eh.variable != null) { context.check_name_redefinition = false; local_block_variable lbv = context.add_var_definition(eh.variable.name, get_location(eh.variable), filter_type, SemanticTree.polymorphic_state.ps_common) as local_block_variable; context.check_name_redefinition = true; lvr = new local_block_variable_reference(lbv, lbv.loc); } statement_node stm = convert_strong(eh.statements); context.leave_code_block(); /*if (eh.variable != null) { context.leave_scope(); }*/ exception_filter ef = new exception_filter(filter_type, lvr, stm, get_location(eh)); efl.AddElement(ef); current_catch_excep = null; } } else { context.enter_code_block_without_bind(); exception_filter ef = new exception_filter(null, null, convert_strong(try_hand_except.except_block.stmt_list), get_location(try_hand_except.except_block.stmt_list)); context.leave_code_block(); efl.AddElement(ef); } if (try_hand_except.except_block.else_stmt_list != null) { context.enter_code_block_without_bind(); statement_node else_stm = convert_strong(try_hand_except.except_block.else_stmt_list); context.leave_code_block(); type_node ftype = SystemLibrary.SystemLibrary.object_type; exception_filter else_ef = new exception_filter(ftype, null, else_stm, else_stm.location); efl.AddElement(else_ef); } } else { type_node filter_type = compiled_type_node.get_type_node(NetHelper.NetHelper.FindType(compiler_string_consts.ExceptionName)); expression_node current_catch_excep = create_constructor_call(filter_type, new expressions_list(), null); local_block_variable_reference lvr = null; local_block_variable tmp_var = context.add_var_definition(context.BuildName("$try_temp" + UniqueNumStr()), null, SystemLibrary.SystemLibrary.bool_type, null) as local_block_variable; statements_list stm = new statements_list(null); SyntaxTree.try_handler_finally try_hndlr_finally = _try_stmt.handler as SyntaxTree.try_handler_finally; context.enter_code_block_without_bind(); statement_node finally_stmt = convert_strong(try_hndlr_finally.stmt_list); context.leave_code_block(); stm.statements.AddElement(finally_stmt); basic_function_call bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_not as basic_function_node,null); bfc.parameters.AddElement(new local_block_variable_reference(tmp_var,null)); stm.statements.AddElement(new if_node(bfc,new rethrow_statement_node(null),null,null)); exception_filter ef = new exception_filter(filter_type, lvr, stm, null); efl.AddElement(ef); bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_assign as basic_function_node,null); bfc.parameters.AddElement(new local_block_variable_reference(tmp_var,null)); bfc.parameters.AddElement(new bool_const_node(true,null)); (try_statements as statements_list).statements.AddElement(bfc); (try_statements as statements_list).statements.AddElement(new throw_statement_node(current_catch_excep,null)); return_value(new try_block(try_statements, null, efl, loc)); context.leave_exception_handlers(); return; } statement_node finally_st = null; SyntaxTree.try_handler_finally try_handler_finally = _try_stmt.handler as SyntaxTree.try_handler_finally; if (try_handler_finally != null) { context.enter_code_block_without_bind(); finally_st = convert_strong(try_handler_finally.stmt_list); context.leave_code_block(); } try_block tb = new try_block(try_statements, finally_st, efl, loc); context.leave_exception_handlers(); return_value(tb); }
private statements_list get_statements_list(statement_node sn) { statements_list snl = sn as statements_list; if (snl != null) { return snl; } snl = new statements_list(null); snl.statements.AddElement(sn); return snl; }
public override void visit(SyntaxTree.external_directive _external_directive) { string module_name = ""; string name = ""; if (_external_directive.modulename == null) { if (!has_dll_import_attribute(context.top_function)) { AddError(context.top_function.loc, "FUNCTION_MUST_HAVE_DLLIMPORT_ATTRIBUTE"); } else { location loc2 = get_location(_external_directive); pinvoke_statement pinv_stmt = new pinvoke_statement(loc2); //statement_node_list sal = new statement_node_list(loc); //sal.AddElement(ext_stmt); statements_list sl2 = new statements_list(loc2); sl2.statements.AddElement(pinv_stmt); //return_value(sl); context.code = sl2; return; } } if (has_dll_import_attribute(context.top_function)) { AddError(get_location(_external_directive.modulename), "FUNCTION_MUST_HAVE_ONLY_EXTERNAL_STATEMENT"); } if (_external_directive.modulename is SyntaxTree.string_const) { module_name = ((SyntaxTree.string_const)_external_directive.modulename).Value; } else if (_external_directive.modulename is SyntaxTree.ident) { //throw new CompilerInternalError("Unsupported now"); //throw new NotSupportedError(get_location(_external_directive)); expression_node en = convert_strong(_external_directive.modulename as SyntaxTree.ident); if (en is string_const_node) module_name = (en as string_const_node).constant_value; else AddError(get_location(_external_directive.modulename), "STRING_CONSTANT_EXPECTED"); } else AddError(get_location(_external_directive.modulename), "STRING_CONSTANT_OR_IDENTIFIER_EXPECTED"); if (_external_directive.name == null) { name = context.converted_func_stack.top().name; } else if (_external_directive.name is SyntaxTree.string_const) { name = ((SyntaxTree.string_const)_external_directive.name).Value; } else if (_external_directive.name is SyntaxTree.ident) { expression_node en = convert_strong(_external_directive.name as SyntaxTree.ident); if (en is string_const_node) name = (en as string_const_node).constant_value; else AddError(get_location(_external_directive.name), "STRING_CONSTANT_EXPECTED"); } else { //throw new CompilerInternalError("Unsupported now"); AddError(get_location(_external_directive.name), "STRING_CONSTANT_OR_IDENTIFIER_EXPECTED"); } location loc = get_location(_external_directive); external_statement ext_stmt = new external_statement(module_name, name, loc); //statement_node_list sal = new statement_node_list(loc); //sal.AddElement(ext_stmt); statements_list sl = new statements_list(loc); sl.statements.AddElement(ext_stmt); //return_value(sl); context.code = sl; }
//ssyy public void generate_inherit_constructors() { common_type_node _ctn = context.converted_type; if (_ctn == null) { throw new CompilerInternalError("Can generate inherited constructors only in class."); } if (_ctn.has_user_defined_constructor) { //Пользователь определил хотя бы один конструктор, никакие конструкторы не наследуем. return; } //Получили список процедур предка, имеющих имя Create SymbolInfo si = _ctn.base_type.find_in_type(compiler_string_consts.default_constructor_name, _ctn.base_type.Scope); delete_inherited_constructors(ref si, _ctn.base_type); while (si != null) { function_node fn = si.sym_info as function_node; compiled_constructor_node pconstr = fn as compiled_constructor_node; common_method_node mconstr = fn as common_method_node; //Если это конструктор... if (pconstr != null || mconstr != null && mconstr.is_constructor) { //Генерируем унаследованный конструктор location loc = null; SemanticTree.polymorphic_state ps; if (mconstr != null) { loc = mconstr.loc; ps = mconstr.polymorphic_state; } else //значит (pconstr != null) { ps = pconstr.polymorphic_state; } if (pconstr != null) context.set_field_access_level(pconstr.field_access_level); else context.set_field_access_level(mconstr.field_access_level); common_method_node gen_constr = context.create_function(compiler_string_consts.default_constructor_name, loc) as common_method_node; gen_constr.polymorphic_state = ps; gen_constr.is_overload = true; gen_constr.is_constructor = true; gen_constr.field_access_level = fn.field_access_level; gen_constr.return_value_type = _ctn; foreach (parameter par in fn.parameters) { //(ssyy) Интересно, зачем это. concrete_parameter_type cpt = (par.parameter_type == SemanticTree.parameter_type.var) ? concrete_parameter_type.cpt_var : concrete_parameter_type.cpt_none; common_parameter c_p = new common_parameter(par.name, par.parameter_type, gen_constr, cpt, null); c_p.type = par.type; c_p.set_param_is_params(par.is_params); c_p.inital_value = par.inital_value; gen_constr.parameters.AddElement(c_p); c_p.default_value = par.default_value; } base_function_call bfc; if (mconstr != null) { common_constructor_call c1 = new common_constructor_call(mconstr, null); c1._new_obj_awaited = false; bfc = c1; } else { compiled_constructor_call c2 = new compiled_constructor_call(pconstr, null); c2._new_obj_awaited = false; bfc = c2; } foreach (parameter p in gen_constr.parameters) { bfc.parameters.AddElement( create_variable_reference(p, null)); } statements_list snlist = new statements_list(null); snlist.statements.AddElement(bfc); snlist.statements.AddElement(new empty_statement(null)); gen_constr.function_code = snlist; context.leave_block(); if (fn.parameters.Count == 0 || fn.parameters[0].default_value != null) { _ctn.has_default_constructor = true; } } si = si.Next; } }
public void create_main_function_as_in_module() { add_needed_cctors(); statements_list sl = new statements_list(loc); statements_list intern_sl = new statements_list(loc); statements_list sl2 = sl; sl = new statements_list(null); common_namespace_function_node init_func = new common_namespace_function_node("$_Init_", null, null, common_namespaces[0], null); common_namespaces[0].functions.AddElement(init_func); namespace_variable init_var = new namespace_variable("$is_init", SystemLibrary.SystemLibrary.bool_type, common_namespaces[0], null); common_namespaces[0].variables.AddElement(init_var); for (int i = 0; i < units.Count; i++) { if (units[i].main_function != null) { common_namespace_function_call cnfc = new common_namespace_function_call(units[i].main_function, loc); sl.statements.AddElement(cnfc); } } /*for (int i = units.Count - 1; i >= 0; i--) { if (units[i].finalization_method != null) { common_namespace_function_call cnfc = new common_namespace_function_call(units[i].finalization_method, loc); sl.statements.AddElement(cnfc); } }*/ sl2 = new statements_list(loc); basic_function_call bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_assign as basic_function_node, null); bfc.parameters.AddElement(new namespace_variable_reference(init_var, null)); bfc.parameters.AddElement(new bool_const_node(true, null)); sl.statements.AddElementFirst(bfc); bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_not as basic_function_node, null); bfc.parameters.AddElement(new namespace_variable_reference(init_var, null)); sl2.statements.AddElement(new if_node(bfc, sl, null, null)); init_func.function_code = sl2; _init_code = new common_namespace_function_call(init_func, null); add_initialization_to_cctors(); }
public override void visit(SyntaxTree.for_node _for_node) { #region MikhailoMMX, обработка omp parallel for bool isGenerateParallel = false; bool isGenerateSequential = true; if (OpenMP.ForsFound) { OpenMP.LoopVariables.Push(_for_node.loop_variable.name.ToLower()); //если в программе есть хоть одна директива parallel for - проверяем: if (DirectivesToNodesLinks.ContainsKey(_for_node) && OpenMP.IsParallelForDirective(DirectivesToNodesLinks[_for_node])) { //перед этим узлом есть директива parallel for if (CurrentParallelPosition == ParallelPosition.Outside) //входим в самый внешний параллельный for { if (_for_node.create_loop_variable || (_for_node.type_name != null)) { //сгенерировать сначала последовательную ветку, затем параллельную //устанавливаем флаг и продолжаем конвертирование, считая, что конвертируем последовательную ветку isGenerateParallel = true; CurrentParallelPosition = ParallelPosition.InsideSequential; //в конце за счет флага вернем состояние обратно и сгенерируем и параллельную ветку тоже } else WarningsList.Add(new OMP_BuildigError(new Exception("Переменная параллельного цикла должна быть определена в заголовке цикла"), new location(_for_node.source_context.begin_position.line_num, _for_node.source_context.begin_position.column_num, _for_node.source_context.end_position.line_num, _for_node.source_context.end_position.column_num, new document(_for_node.source_context.FileName)))); } else //уже генерируем одну из веток //если это параллельная ветка - последовательную генерировать не будем if (CurrentParallelPosition == ParallelPosition.InsideParallel) { isGenerateParallel = true; isGenerateSequential = false; } //else //а если последовательная - то флаг isGenerateParallel не установлен, сгенерируется только последовательная } } #endregion location loc1 = get_location(_for_node.loop_variable); var_definition_node vdn = null; expression_node left, right, res; expression_node initv = convert_strong(_for_node.initial_value); expression_node tmp = initv; if (initv is typed_expression) initv = convert_typed_expression_to_function_call(initv as typed_expression); if (initv.type == null) initv = tmp; statements_list head_stmts = new statements_list(loc1); convertion_data_and_alghoritms.statement_list_stack_push(head_stmts); if (_for_node.type_name == null && !_for_node.create_loop_variable) { definition_node dn = context.check_name_node_type(_for_node.loop_variable.name, loc1, general_node_type.variable_node); vdn = (var_definition_node)dn; if (context.is_loop_variable(vdn)) AddError(get_location(_for_node.loop_variable), "CANNOT_ASSIGN_TO_LOOP_VARIABLE"); if (!check_name_in_current_scope(_for_node.loop_variable.name)) AddError(new ForLoopControlMustBeSimpleLocalVariable(loc1)); } else { //В разработке DS //throw new NotSupportedError(get_location(_for_node.type_name)); type_node tn; if (_for_node.type_name != null) tn = convert_strong(_for_node.type_name); else tn = initv.type; //if (tn == SystemLibrary.SystemLibrary.void_type && _for_node.type_name != null) // AddError(new VoidNotValid(get_location(_for_node.type_name))) if (_for_node.type_name != null) check_for_type_allowed(tn,get_location(_for_node.type_name)); vdn = context.add_var_definition(_for_node.loop_variable.name, get_location(_for_node.loop_variable), tn, SemanticTree.polymorphic_state.ps_common); } internal_interface ii = vdn.type.get_internal_interface(internal_interface_kind.ordinal_interface); if (ii == null) { AddError(new OrdinalTypeExpected(loc1)); } ordinal_type_interface oti = (ordinal_type_interface)ii; location loc2 = get_location(_for_node.finish_value); var_definition_node vdn_finish = context.create_for_temp_variable(vdn.type, loc2); //Это должно стаять первее! left = create_variable_reference(vdn_finish, loc1); expression_node finishValue = convert_strong(_for_node.finish_value); right = finishValue; if (right is typed_expression) right = convert_typed_expression_to_function_call(right as typed_expression); res = find_operator(compiler_string_consts.assign_name, left, right, loc2); head_stmts.statements.AddElement(res); left = create_variable_reference(vdn, loc1); right = initv; res = find_operator(compiler_string_consts.assign_name, left, right, loc1); head_stmts.statements.AddElement(res); //for_node fn=new for_node(sl,; //fn.initialization_statement=sl; location loc3 = get_location(_for_node.initial_value); statement_node sn_inc = null; expression_node sn_while = null; expression_node sn_init_while = null; left = create_variable_reference(vdn, loc3); right = create_variable_reference(vdn, loc2); expression_node right_border = create_variable_reference(vdn_finish, loc2); switch (_for_node.cycle_type) { case SyntaxTree.for_cycle_type.to: { sn_inc = convertion_data_and_alghoritms.create_simple_function_call(oti.inc_method, loc1, left); //if (vdn.type != SystemLibrary.SystemLibrary.bool_type) sn_while = convertion_data_and_alghoritms.create_simple_function_call(oti.lower_method, loc2, right, right_border); sn_init_while = convertion_data_and_alghoritms.create_simple_function_call(oti.lower_eq_method, loc2, right, right_border); // else // sn_while = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibrary.bool_noteq, loc2, right, right_border); break; } case SyntaxTree.for_cycle_type.downto: { sn_inc = convertion_data_and_alghoritms.create_simple_function_call(oti.dec_method, loc1, left); //if (vdn.type != SystemLibrary.SystemLibrary.bool_type) sn_while = convertion_data_and_alghoritms.create_simple_function_call(oti.greater_method, loc2, right, right_border); sn_init_while = convertion_data_and_alghoritms.create_simple_function_call(oti.greater_eq_method, loc2, right, right_border); // else // sn_while = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibrary.bool_noteq, loc2, right, right_border); break; } } //fn.increment_statement=sn_inc; //fn.while_expr=sn_while; CheckToEmbeddedStatementCannotBeADeclaration(_for_node.statements); //DarkStar Modifed //исправил ошибку: не работали break в циклах for_node fn = new for_node(null, sn_while, sn_init_while, sn_inc, null, get_location(_for_node)); if (vdn.type == SystemLibrary.SystemLibrary.bool_type) fn.bool_cycle = true; context.cycle_stack.push(fn); context.loop_var_stack.Push(vdn); statements_list slst = new statements_list(get_location(_for_node.statements)); convertion_data_and_alghoritms.statement_list_stack_push(slst); context.enter_code_block_with_bind(); fn.body = convert_strong(_for_node.statements); context.leave_code_block(); slst = convertion_data_and_alghoritms.statement_list_stack.pop(); if (slst.statements.Count > 0 || slst.local_variables.Count > 0) { slst.statements.AddElement(fn.body); fn.body = slst; } context.cycle_stack.pop(); context.loop_var_stack.Pop(); head_stmts = convertion_data_and_alghoritms.statement_list_stack.pop(); head_stmts.statements.AddElement(fn); #region MikhailoMMX, обработка omp parallel for //флаг был установлен только если это самый внешний parallel for и нужно сгенерировать обе ветки //или если это вложенный parallel for, нужно сгенерировать обе ветки, но без проверки на OMP_Available //Последовательная ветка только что сгенерирована, теперь меняем состояние и генерируем параллельную if (isGenerateParallel) { CurrentParallelPosition = ParallelPosition.InsideParallel; statements_list stl = OpenMP.TryConvertFor(head_stmts, _for_node, fn, vdn, initv, finishValue, this); CurrentParallelPosition = ParallelPosition.Outside; if (stl != null) { OpenMP.LoopVariables.Pop(); return_value(stl); return; } } if (OpenMP.ForsFound) { OpenMP.LoopVariables.Pop(); } #endregion return_value(head_stmts); }
public void create_main_function(string[] used_stand_modules, Dictionary<string, object> config) { add_needed_cctors(); common_namespace_function_node temp = _main_function; _main_function = new common_namespace_function_node("Main", null, null, (common_namespace_node)_main_function.comprehensive_namespace, null); location loc = temp.loc; statements_list sl = new statements_list(loc); _main_function.function_code = sl; // if (units[0].MainArgsParameter!=null) // { // _main_function.parameters.AddElement(units[0].MainArgsParameter); // sl.statements.AddElement(units[0].MainArgsAssignExpr); // } // if (units[0].IsConsoleApplicationVariableAssignExpr!=null) // { // sl.statements.AddElement(units[0].IsConsoleApplicationVariableAssignExpr); // } statements_list sl2 = sl; sl = new statements_list(null); common_namespace_function_node init_func = new common_namespace_function_node("$_Init_",null,null,(common_namespace_node)_main_function.comprehensive_namespace,null); ((common_namespace_node)_main_function.comprehensive_namespace).functions.AddElement(init_func); namespace_variable init_var = new namespace_variable("$is_init",SystemLibrary.SystemLibrary.bool_type,(common_namespace_node)_main_function.comprehensive_namespace,null); ((common_namespace_node)_main_function.comprehensive_namespace).variables.AddElement(init_var); if (SystemLibrary.SystemLibInitializer.ConfigVariable.Found) { namespace_variable conf_nv = null; compiled_variable_definition conf_cf = null; if (SystemLibrary.SystemLibInitializer.ConfigVariable.sym_info is namespace_variable) conf_nv = SystemLibrary.SystemLibInitializer.ConfigVariable.sym_info as namespace_variable; else conf_cf = SystemLibrary.SystemLibInitializer.ConfigVariable.sym_info as compiled_variable_definition; foreach (string config_var in config.Keys) { var config_value = config[config_var]; compiled_function_call cfc = new compiled_function_call(compiled_function_node.get_compiled_method(NetHelper.NetHelper.AddToDictionaryMethod), (conf_nv != null) ? (expression_node)new namespace_variable_reference(conf_nv, null) : (expression_node)new static_compiled_variable_reference(conf_cf, null), null); cfc.parameters.AddElement(new string_const_node(config_var, null)); switch (Type.GetTypeCode(config_value.GetType())) { case TypeCode.String: cfc.parameters.AddElement(new string_const_node((string)config_value, null)); break; case TypeCode.Int32: cfc.parameters.AddElement(new int_const_node((int)config_value, null)); break; case TypeCode.Boolean: cfc.parameters.AddElement(new bool_const_node((bool)config_value, null)); break; case TypeCode.Double: cfc.parameters.AddElement(new double_const_node((double)config_value, null)); break; default: throw new NotSupportedException("Config value type is nort supported"); } sl.statements.AddElement(cfc); } } if (units[0].MainArgsParameter!=null) { _main_function.parameters.AddElement(units[0].MainArgsParameter); sl.statements.AddElementFirst(units[0].MainArgsAssignExpr); } if (units[0].IsConsoleApplicationVariableAssignExpr!=null) { sl.statements.AddElementFirst(units[0].IsConsoleApplicationVariableAssignExpr); } for (int i = 0; i < units.Count; i++) { if (units[i].main_function != null) { if (units[i].main_function.name != TreeConverter.compiler_string_consts.temp_main_function_name) { common_namespace_function_call cnfc = new common_namespace_function_call(units[i].main_function, loc); sl.statements.AddElement(cnfc); } else { common_namespace_function_call cnfc = new common_namespace_function_call(units[i].main_function, loc); sl2.statements.AddElement(cnfc); } } } //if (units.Count == 1) for (int i = 0; i < used_stand_modules.Length; i++) { Type t = NetHelper.NetHelper.FindRtlType(used_stand_modules[i] + "." + used_stand_modules[i]); if (t == null) continue; compiled_type_node ctn = compiled_type_node.get_type_node(t); System.Reflection.MethodInfo mi = ctn.compiled_type.GetMethod("__InitModule__"); if (mi == null) { continue; } compiled_static_method_call csmc = new compiled_static_method_call(compiled_function_node.get_compiled_method(mi), null); sl.statements.AddElement(csmc); } for (int i = units.Count - 1; i >= 0; i--) { if (units[i].finalization_method != null) { common_namespace_function_call cnfc = new common_namespace_function_call(units[i].finalization_method, loc); sl2.statements.AddElement(cnfc); } } //if (units.Count == 1) for (int i = 0; i < used_stand_modules.Length; i++) { Type t = NetHelper.NetHelper.FindRtlType(used_stand_modules[i] + "." + used_stand_modules[i]); if (t == null) continue; compiled_type_node ctn = compiled_type_node.get_type_node(t); System.Reflection.MethodInfo mi = ctn.compiled_type.GetMethod("__FinalizeModule__"); if (mi == null) continue; compiled_static_method_call csmc = new compiled_static_method_call(compiled_function_node.get_compiled_method(mi), null); sl2.statements.AddElement(csmc); } sl2 = new statements_list(loc); basic_function_call bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_assign as basic_function_node,null); bfc.parameters.AddElement(new namespace_variable_reference(init_var,null)); bfc.parameters.AddElement(new bool_const_node(true,null)); sl.statements.AddElementFirst(bfc); bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_not as basic_function_node,null); bfc.parameters.AddElement(new namespace_variable_reference(init_var,null)); sl2.statements.AddElement(new if_node(bfc,sl,null,null)); init_func.function_code = sl2; sl = new statements_list(null); sl.statements.AddElement(new common_namespace_function_call(init_func,null)); common_namespace_function_node init_variables_func = new common_namespace_function_node("$_InitVariables_", null, null, (common_namespace_node)_main_function.comprehensive_namespace, null); init_variables_func.function_code = new statements_list(null); ((common_namespace_node)_main_function.comprehensive_namespace).functions.AddElement(init_variables_func); sl.statements.AddElement(new common_namespace_function_call(init_variables_func,null)); _init_code = sl; }
public local_block_variable(string name, type_node type, statements_list stmt_list, location loc) : base(name, type) { this.stmt_list = stmt_list; _loc = loc; }
internal static statements_list TryConvertSections(statements_list semantic_stmts, SyntaxTree.statement_list syntax_stmts, syntax_tree_visitor syntax_tree_visitor) { try { location loc = semantic_stmts.location; statements_list omp_stmts = new statements_list(loc); statements_list head_stmts = new statements_list(loc); syntax_tree_visitor.convertion_data_and_alghoritms.statement_list_stack_push(head_stmts); if (!InParallelSectionCreated) CreateInParallelVariable(syntax_tree_visitor, out InParallelSection); //если omp доступен то (выполнять паралельно) иначе (выполнять последовательно операторы) if_node ifnode = CreateIfCondition(syntax_tree_visitor, omp_stmts, semantic_stmts, loc); head_stmts.statements.AddElement(ifnode); //генерим ветку в случае когда доступен omp if (!GenerateOMPParallelSectionsCall(semantic_stmts, syntax_stmts, omp_stmts, syntax_tree_visitor)) { syntax_tree_visitor.convertion_data_and_alghoritms.statement_list_stack_pop(); return null; } syntax_tree_visitor.convertion_data_and_alghoritms.statement_list_stack_pop(); return head_stmts; } catch (OpenMPException e) { Exception ex = new Exception(e.ToString()); syntax_tree_visitor.convertion_data_and_alghoritms.statement_list_stack_pop(); syntax_tree_visitor.WarningsList.Add(new OMP_BuildigError(ex, syntax_tree_visitor.get_location(new SyntaxTree.syntax_tree_node(e.SC)))); } catch (Exception e) { syntax_tree_visitor.convertion_data_and_alghoritms.statement_list_stack_pop(); syntax_tree_visitor.WarningsList.Add(new OMP_BuildigError(e, semantic_stmts.location)); } return null; }
public override void visit(PascalABCCompiler.SyntaxTree.for_node _for_node) { var loc1 = _visitor.get_location(_for_node.loop_variable); var loopIdentName = _for_node.loop_variable.name.ToLower(); var nodesToProcess = new List<syntax_tree_node>(); var_definition_node vdn; var initv = _visitor.convert_strong(_for_node.initial_value); var tmp = initv; if (initv is typed_expression) { initv = _visitor.convert_typed_expression_to_function_call(initv as typed_expression); } if (initv.type == null) { initv = tmp; } var headStmts = new statements_list(loc1); _visitor.convertion_data_and_alghoritms.statement_list_stack_push(headStmts); var newTreeNode = new CapturedVariablesTreeNodeForScope(_currentTreeNode, headStmts.Scope.ScopeNum, _for_node); if (_currentTreeNode != null) { _currentTreeNode.ChildNodes.Add(newTreeNode); } _currentTreeNode = newTreeNode; _scopesCapturedVarsNodesDictionary.Add(headStmts.Scope.ScopeNum, _currentTreeNode); if (_for_node.type_name == null && !_for_node.create_loop_variable) { var dn = _visitor.context.check_name_node_type(loopIdentName, loc1, general_node_type.variable_node); vdn = (var_definition_node)dn; nodesToProcess.Add(_for_node.loop_variable); } else { var tn = _for_node.type_name != null ? _visitor.convert_strong(_for_node.type_name) : initv.type; vdn = _visitor.context.add_var_definition(loopIdentName, _visitor.get_location(_for_node.loop_variable), tn, polymorphic_state.ps_common); _currentTreeNode.VariablesDefinedInScope.Add(new CapturedVariablesTreeNode.CapturedSymbolInfo(_for_node, _visitor.context.find(loopIdentName))); } newTreeNode.SymbolInfoLoopVar = _visitor.context.find(loopIdentName); var fn = new PascalABCCompiler.TreeRealization.for_node(null, null, null, null, null, _visitor.get_location(_for_node)); if (vdn.type == SystemLibrary.bool_type) { fn.bool_cycle = true; } _visitor.context.cycle_stack.push(fn); _visitor.context.loop_var_stack.Push(vdn); nodesToProcess.Add(_for_node.initial_value); nodesToProcess.Add(_for_node.finish_value); nodesToProcess.Add(_for_node.increment_value); foreach (var n in nodesToProcess) { ProcessNode(n); } if (!(_for_node.statements is statement_list)) { var stmtList = new statement_list(_for_node.statements, _for_node.statements.source_context); _for_node.statements = stmtList; } ProcessNode(_for_node.statements); _visitor.context.cycle_stack.pop(); _visitor.context.loop_var_stack.Pop(); _visitor.convertion_data_and_alghoritms.statement_list_stack.pop(); _currentTreeNode = _currentTreeNode.ParentNode; }
public override void visit(foreach_stmt _foreach_stmt) { var loopIdentName = _foreach_stmt.identifier.name.ToLower(); definition_node dn = null; var_definition_node vdn = null; var sl2 = new statements_list(_visitor.get_location(_foreach_stmt)); _visitor.convertion_data_and_alghoritms.statement_list_stack_push(sl2); var newTreeNode = new CapturedVariablesTreeNodeForEachScope(_currentTreeNode, sl2.Scope.ScopeNum, _foreach_stmt); if (_currentTreeNode != null) { _currentTreeNode.ChildNodes.Add(newTreeNode); } _currentTreeNode = newTreeNode; _scopesCapturedVarsNodesDictionary.Add(sl2.Scope.ScopeNum, _currentTreeNode); var inWhat = _visitor.convert_strong(_foreach_stmt.in_what); var tmp = inWhat; if (inWhat is typed_expression) inWhat = _visitor.convert_typed_expression_to_function_call(inWhat as typed_expression); type_node elemType = null; if (inWhat.type == null) inWhat = tmp; _visitor.FindIEnumerableElementType(_foreach_stmt, inWhat.type, ref elemType); if (_foreach_stmt.type_name == null) { var loc1 = _visitor.get_location(_foreach_stmt.identifier); dn = _visitor.context.check_name_node_type(loopIdentName, loc1, general_node_type.variable_node); vdn = (var_definition_node)dn; } else { vdn = _visitor.context.add_var_definition(loopIdentName, _visitor.get_location(_foreach_stmt.identifier)); type_node tn; if (_foreach_stmt.type_name is no_type_foreach) { tn = elemType; } else { tn = _visitor.convert_strong(_foreach_stmt.type_name); _visitor.check_for_type_allowed(tn, _visitor.get_location(_foreach_stmt.type_name)); } _visitor.context.close_var_definition_list(tn, null); _currentTreeNode.VariablesDefinedInScope.Add(new CapturedVariablesTreeNode.CapturedSymbolInfo(_foreach_stmt, _visitor.context.find(loopIdentName))); } newTreeNode.SymbolInfoLoopVar = _visitor.context.find(loopIdentName); if (!(vdn.type is compiled_generic_instance_type_node)) _visitor.convertion_data_and_alghoritms.check_convert_type_with_inheritance(vdn.type, elemType, _visitor.get_location(_foreach_stmt.identifier)); var fn = new foreach_node(vdn, inWhat, null, _visitor.get_location(_foreach_stmt)); _visitor.context.cycle_stack.push(fn); _visitor.context.loop_var_stack.Push(vdn); ProcessNode(_foreach_stmt.in_what); if (!(_foreach_stmt.stmt is statement_list)) { var stmtList = new statement_list(_foreach_stmt.stmt, _foreach_stmt.stmt.source_context); _foreach_stmt.stmt = stmtList; } ProcessNode(_foreach_stmt.stmt); _visitor.context.loop_var_stack.Pop(); _visitor.convertion_data_and_alghoritms.statement_list_stack.pop(); _visitor.context.cycle_stack.pop(); _currentTreeNode = _currentTreeNode.ParentNode; }
public override void visit(SyntaxTree.statement_list _statement_list) { #region MikhailoMMX, обработка omp parallel section bool isGenerateParallel = false; bool isGenerateSequential = true; if (OpenMP.SectionsFound) //если в программе есть хоть одна директива parallel sections - проверяем: if (DirectivesToNodesLinks.ContainsKey(_statement_list) && OpenMP.IsParallelSectionsDirective(DirectivesToNodesLinks[_statement_list])) { //перед этим узлом есть директива parallel sections if (CurrentParallelPosition == ParallelPosition.Outside) //входим в самый внешний параллельный sections { //сгенерировать сначала последовательную ветку, затем параллельную //устанавливаем флаг и продолжаем конвертирование, считая, что конвертируем последовательную ветку isGenerateParallel = true; CurrentParallelPosition = ParallelPosition.InsideSequential; //в конце за счет флага вернем состояние обратно и сгенерируем и параллельную ветку тоже } else //уже генерируем одну из веток if (CurrentParallelPosition == ParallelPosition.InsideParallel) { isGenerateParallel = true; isGenerateSequential = false; } //else //флаг isGenerateParallel не установлен, параллельная ветка не сгенерируется } #endregion statements_list stl = new statements_list(get_location(_statement_list), get_location_with_check(_statement_list.left_logical_bracket), get_location_with_check(_statement_list.right_logical_bracket)); convertion_data_and_alghoritms.statement_list_stack_push(stl); foreach (SyntaxTree.statement syntax_statement in _statement_list.subnodes) { try { 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 if (semantic_statement != null) { //Обработать по другому - комментарий не мой - SSM //if (context.CurrentScope.AddStatementsToFront) // stl.statements.AddElementFirst(semantic_statement); //else stl.statements.AddElement(semantic_statement); } context.allow_inherited_ctor_call = false; } } catch (Errors.Error ex) { if (ThrowCompilationError) throw ex; else ErrorsList.Add(ex); } } convertion_data_and_alghoritms.statement_list_stack.pop(); #region MikhailoMMX, обработка omp parallel sections //флаг был установлен только если это самый внешний parallel sections и нужно сгенерировать обе ветки //или если это вложенный parallel sections, нужно сгенерировать обе ветки, но без проверки на OMP_Available //Последовательная ветка только что сгенерирована, теперь меняем состояние и генерируем параллельную if (isGenerateParallel) { CurrentParallelPosition = ParallelPosition.InsideParallel; statements_list omp_stl = OpenMP.TryConvertSections(stl, _statement_list, this); CurrentParallelPosition = ParallelPosition.Outside; if (omp_stl != null) { return_value(omp_stl); return; } } #endregion return_value(stl); }
private statement_node CreateStatementList() { statements_list stmt = new statements_list(null); int num = br.ReadInt32(); for (int i = 0; i < num; i++) stmt.local_variables.Add(CreateLocalBlockVariable(stmt)); num = br.ReadInt32(); for (int i=0; i<num; i++) stmt.statements.AddElement(CreateStatement()); stmt.LeftLogicalBracketLocation = ReadDebugInfo(); stmt.RightLogicalBracketLocation = ReadDebugInfo(); return stmt; }
public override void visit(SyntaxTree.foreach_stmt _foreach_stmt) { var lambdaSearcher = new LambdaSearcher(_foreach_stmt.in_what); if (lambdaSearcher.CheckIfContainsLambdas()) { AddError(new LambdasNotAllowedInForeachInWhatSatetement(get_location(lambdaSearcher.FoundLambda))); } //throw new NotSupportedError(get_location(_foreach_stmt)); definition_node dn = null; var_definition_node vdn = null; statements_list sl2 = new statements_list(get_location(_foreach_stmt)); convertion_data_and_alghoritms.statement_list_stack_push(sl2); expression_node in_what = convert_strong(_foreach_stmt.in_what); expression_node tmp = in_what; if (in_what is typed_expression) in_what = convert_typed_expression_to_function_call(in_what as typed_expression); type_node elem_type = null; if (in_what.type == null) in_what = tmp; //if (in_what.type.find_in_type("GetEnumerator") == null) if (!FindIEnumerableElementType(_foreach_stmt, in_what.type, ref elem_type)) //if (!IsGetEnumerator(in_what.type, ref elem_type)) AddError(in_what.location, "CAN_NOT_EXECUTE_FOREACH_BY_EXPR_OF_TYPE_{0}", in_what.type.name); if (_foreach_stmt.type_name == null) { location loc1 = get_location(_foreach_stmt.identifier); dn = context.check_name_node_type(_foreach_stmt.identifier.name, loc1, general_node_type.variable_node); vdn = (var_definition_node)dn; if (!check_name_in_current_scope(_foreach_stmt.identifier.name)) AddError(loc1, "FOREACH_LOOP_CONTROL_MUST_BE_SIMPLE_LOCAL_VARIABLE"); } else { //AddError(new NotSupportedError(get_location(_foreach_stmt.type_name))); vdn = context.add_var_definition(_foreach_stmt.identifier.name, get_location(_foreach_stmt.identifier)); type_node tn; if (_foreach_stmt.type_name is SyntaxTree.no_type_foreach) { tn = elem_type; } else { tn = convert_strong(_foreach_stmt.type_name); //if (tn == SystemLibrary.SystemLibrary.void_type) // AddError(new VoidNotValid(get_location(_foreach_stmt.type_name))); check_for_type_allowed(tn, get_location(_foreach_stmt.type_name)); } context.close_var_definition_list(tn, null); } //elem_type = vdn.type; if (!(vdn.type is compiled_generic_instance_type_node)) convertion_data_and_alghoritms.check_convert_type_with_inheritance(vdn.type, elem_type, get_location(_foreach_stmt.identifier)); //if (!convertion_data_and_alghoritms.eq_type_nodes(elem_type, vdn.type)) //AddError(new TypesOfVarAndElementsInForeachMustBeEqual(vdn.type.name,elem_type.name,get_location(_foreach_stmt.identifier))); //AddError(new SimpleSemanticError("Тип элемента контейнера: " + elem_type.ToString() + " Тип переменной foreach: " + vdn.type.ToString(), get_location(_foreach_stmt.identifier))); //convertion_data_and_alghoritms.check_convert_type_with_inheritance(vdn.type, elem_type, get_location(_foreach_stmt.identifier)); //if (in_what.type.type_special_kind == SemanticTree.type_special_kind.set_type) /*{ if (!convertion_data_and_alghoritms.eq_type_nodes(elem_type, vdn.type)) { possible_type_convertions ptc = type_table.get_convertions(vdn.type,elem_type); if (ptc.first == null || ptc.first.is_explicit) if (vdn.node_location_kind == SemanticTree.node_location_kind.in_namespace_location) throw new CanNotConvertTypes(new namespace_variable_reference(vdn as namespace_variable, get_location(_foreach_stmt.identifier)), vdn.type, elem_type, get_location(_foreach_stmt.identifier)); else if (vdn.node_location_kind == SemanticTree.node_location_kind.in_function_location) throw new CanNotConvertTypes(new local_variable_reference(vdn as local_variable, 0, get_location(_foreach_stmt.identifier)), vdn.type, elem_type, get_location(_foreach_stmt.identifier)); else if (vdn.node_location_kind == SemanticTree.node_location_kind.in_block_location) throw new CanNotConvertTypes(new local_block_variable_reference(vdn as local_block_variable,get_location(_foreach_stmt.identifier)),vdn.type,elem_type, get_location(_foreach_stmt.identifier)); else throw new ForeachLoopControlMustBeSimpleLocalVariable(get_location(_foreach_stmt.identifier)); } }*/ statements_list sl = new statements_list(get_location(_foreach_stmt.stmt)); convertion_data_and_alghoritms.statement_list_stack_push(sl); CheckToEmbeddedStatementCannotBeADeclaration(_foreach_stmt.stmt); foreach_node fn = new foreach_node(vdn, in_what, null, get_location(_foreach_stmt)); context.cycle_stack.push(fn); context.loop_var_stack.Push(vdn); context.enter_code_block_with_bind(); statement_node body = convert_strong(_foreach_stmt.stmt); context.leave_code_block(); context.loop_var_stack.Pop(); sl = convertion_data_and_alghoritms.statement_list_stack.pop(); //if (!(st is statements_list)) if (sl.statements.Count > 0 || sl.local_variables.Count > 0) { sl.statements.AddElement(body); body = sl; } //CheckToEmbeddedStatementCannotBeADeclaration(_foreach_stmt.stmt); //statement_node body = convert_strong(_foreach_stmt.stmt); //foreach_node fn = new foreach_node(vdn, in_what, body, get_location(_foreach_stmt)); fn.what_do = body; //statements_list sl2 = new statements_list(get_location(_foreach_stmt)); convertion_data_and_alghoritms.statement_list_stack.pop(); sl2.statements.AddElement(fn); context.cycle_stack.pop(); //if (_foreach_stmt.type_name != null) //sl2.local_variables.Add(vdn as local_block_variable); return_value(sl2); }
private local_block_variable CreateLocalBlockVariable(statements_list stmt) { int offset = (int)br.BaseStream.Position - start_pos; string name = br.ReadString(); type_node tn = GetTypeReference(); expression_node initv = null; local_block_variable lv = new local_block_variable(name, tn, stmt, null); AddMember(lv, offset); if (CanReadObject()) initv = CreateExpressionWithOffset(); lv.loc = ReadDebugInfo(); lv.inital_value = initv; return lv; }
//\ssyy //ssyy public void generate_inherited_from_base_and_interface_function(common_type_node ctype, function_node func) { common_method_node gen_func = context.create_function(func.name, null) as common_method_node; gen_func.polymorphic_state = SemanticTree.polymorphic_state.ps_common; gen_func.newslot_awaited = true; gen_func.is_final = true; gen_func.is_overload = true; gen_func.field_access_level = SemanticTree.field_access_level.fal_public; gen_func.return_value_type = func.return_value_type; //gen_func.return_variable = func.retu foreach (parameter par in func.parameters) { concrete_parameter_type cpt = (par.parameter_type == SemanticTree.parameter_type.value) ? concrete_parameter_type.cpt_const : concrete_parameter_type.cpt_var; common_parameter c_p = new common_parameter(par.name, par.parameter_type, gen_func, cpt, null); c_p.type = par.type; c_p.set_param_is_params(par.is_params); c_p.inital_value = par.inital_value; gen_func.parameters.AddElement(c_p); } 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.self_variable = lv; base_function_call bfc; this_node tn = null; common_method_node commn = func as common_method_node; if (commn != null) { tn = new this_node(commn.comperehensive_type as type_node, null); bfc = new common_method_call(commn, tn, null); } else { compiled_function_node compn = func as compiled_function_node; tn = new this_node(compn.comperehensive_type as type_node, null); bfc = new compiled_function_call(compn, tn, null); } foreach (parameter p in gen_func.parameters) { bfc.parameters.AddElement( create_variable_reference(p, null)); } //Это запретит чистку стека bfc.last_result_function_call = true; statements_list snlist = new statements_list(null); snlist.statements.AddElement(bfc); snlist.statements.AddElement(new empty_statement(null)); gen_func.function_code = snlist; context.pop_top_function(); //context.leave_block(); }
/* public special_operation_kind current_operation_kind { get { return _current_operation_kind; } set { _current_operation_kind = value; } } */ internal void statement_list_stack_push(statements_list sl) { sl.Scope = new SymbolTable.BlockScope(symbol_table, syntax_tree_visitor.context.CurrentScope); statement_list_stack.push(sl); }
public override void visit(SyntaxTree.c_for_cycle node) { //throw new NotSupportedError(get_location(node)); location loc1 = get_location(node.expr1); statements_list head_stmts = new statements_list(loc1); convertion_data_and_alghoritms.statement_list_stack_push(head_stmts); //statement_node sn_init = convert_weak((SyntaxTree.statement)node.expr1); // SSM 12/06/15 - всё равно c-узлы никому не нужны statement_node sn_init = convert_weak(node.expr1); // SSM 12/06/15 expression_node sn_cond = convert_weak(node.expr2); //statement_node sn_next = convert_weak((SyntaxTree.statement)node.expr3); // SSM 12/06/15 statement_node sn_next = convert_weak(node.expr3); // SSM 12/06/15 CheckToEmbeddedStatementCannotBeADeclaration(node.stmt); for_node fn = new for_node(sn_init, sn_cond, null, sn_next, null, get_location(node)); context.cycle_stack.push(fn); statements_list slst = new statements_list(get_location(node.stmt)); convertion_data_and_alghoritms.statement_list_stack_push(slst); context.enter_code_block_with_bind(); fn.body = convert_strong(node.stmt); context.leave_code_block(); slst = convertion_data_and_alghoritms.statement_list_stack.pop(); if (slst.statements.Count > 0 || slst.local_variables.Count > 0) { slst.statements.AddElement(fn.body); fn.body = slst; } context.cycle_stack.pop(); head_stmts = convertion_data_and_alghoritms.statement_list_stack.pop(); head_stmts.statements.AddElement(fn); return_value(head_stmts); /*slst = convertion_data_and_alghoritms.statement_list_stack.pop(); if (slst.statements.Count > 0 || slst.local_variables.Count > 0) { slst.statements.AddElement(fn.body); fn.body = slst; } context.cycle_stack.pop();*/ //ret.return_value(slst); }
internal void statement_list_stack_push(statements_list sl, SymbolTable.Scope Scope) { sl.Scope = Scope; statement_list_stack.push(sl); }
public override void visit(SyntaxTree.with_statement _with_statement) { WithSection = true; List<SymbolTable.Scope> Withs = new List<SymbolTable.Scope>(); List<expression_node> VarRefs = new List<expression_node>(); List<SymbolTable.Scope> WithTypesList = new List<SymbolTable.Scope>(); statements_list stl = new statements_list(get_location(_with_statement.do_with), null, null); SymbolTable.WithScope WithScope = new SymbolTable.WithScope(SymbolTable, context.CurrentScope, null); convertion_data_and_alghoritms.statement_list_stack_push(stl, WithScope); foreach (SyntaxTree.expression s_expr in _with_statement.do_with.expressions) { //expression_node expr = ret.visit(s_expr); motivation mot = motivation_keeper.motivation; motivation_keeper.set_motivation_to_except_semantic_node(); semantic_node sn = ret.visit(s_expr as SyntaxTree.syntax_tree_node); motivation_keeper.reset(); expression_node expr = sn as expression_node; if (expr is null_const_node) AddError(expr.location, "NIL_IN_THIS_CONTEXT_NOT_ALLOWED"); if (expr is typed_expression) expr = convert_typed_expression_to_function_call(expr as typed_expression); if (expr != null) { variable_reference vr = expr as variable_reference; if (expr.type == null) AddError(get_location(s_expr), "UNEXPECTED_EXPRESSION_IN_WITH"); if (expr.type is ref_type_node) AddError(get_location(s_expr), "UNEXPECTED_EXPRESSION_IN_WITH"); if (vr == null) { location sl = get_location(s_expr); if (expr.type.type_special_kind != SemanticTree.type_special_kind.record) vr = convertion_data_and_alghoritms.CreateVariableReference(context.add_var_definition(compiler_string_consts.GetTempVariableName(), sl, expr.type, expr), sl); else expr = create_with_expression(expr); } if (vr != null && vr is class_field_reference && vr.type.type_special_kind == SemanticTree.type_special_kind.record) { vr = null; expr = create_with_expression(expr); } if (vr != null) { VarRefs.Add(vr); if (vr.type.Scope == null) { if (vr.type is compiled_type_node) (vr.type as compiled_type_node).scope = new NetHelper.NetTypeScope((vr.type as compiled_type_node).compiled_type, SystemLibrary.SystemLibrary.symtab); else throw new CompilerInternalError("Cannot create With statement because variable reference scope == null"); } //если не нужны локальные перекрытия, здесь нужна проверка Withs.Add(vr.type.Scope); } else { VarRefs.Add(expr); Withs.Add(expr.type.Scope); } } else if (sn is type_node) { type_node tn = sn as type_node; Withs.Add(tn.Scope); while (tn != null) { if (tn.Scope == null && tn is compiled_type_node) { (tn as compiled_type_node).init_scope(); } WithTypesList.Add(tn.Scope); tn = tn.base_type; } } } WithScope.WithScopes = Withs.ToArray(); Dictionary<SymbolTable.Scope, expression_node> OldWithVariables = new Dictionary<SymbolTable.Scope, expression_node>(); foreach (expression_node vr in VarRefs) { if (WithVariables.ContainsKey(vr.type.Scope)) { //перекрытие области if (OldWithVariables.ContainsKey(vr.type.Scope)) //Это локальные перекрытия OldWithVariables[vr.type.Scope] = WithVariables[vr.type.Scope]; else OldWithVariables.Add(vr.type.Scope, WithVariables[vr.type.Scope]); WithVariables[vr.type.Scope] = vr; } else { //добавляем текущие with WithVariables.Add(vr.type.Scope, vr); } //ivan dobavil dlja bazovyh klassov type_node tn = vr.type.base_type; while (tn != null) { if (tn.Scope == null && tn is compiled_type_node) { (tn as compiled_type_node).init_scope(); } if (tn.Scope != null) if (!WithVariables.ContainsKey(tn.Scope)) WithVariables.Add(tn.Scope, vr); else { if (OldWithVariables.ContainsKey(tn.Scope)) //Это локальные перекрытия OldWithVariables[tn.Scope] = WithVariables[tn.Scope]; else OldWithVariables.Add(tn.Scope, WithVariables[tn.Scope]); WithVariables[tn.Scope] = vr; } tn = tn.base_type; } } //Ivan dobavil dlja tipov foreach (SymbolTable.Scope sc in WithTypesList) { if (!WithTypes.Contains(sc)) WithTypes.Push(sc); } stl.statements.AddElement(ret.visit(_with_statement.what_do)); //восстанавливаем перекрытия foreach (SymbolTable.Scope sc in OldWithVariables.Keys) WithVariables[sc] = OldWithVariables[sc]; //удаляем текущие with foreach (expression_node vr in VarRefs) { WithVariables.Remove(vr.type.Scope); type_node tn = vr.type.base_type; while (tn != null) { if (tn.Scope != null && WithVariables.ContainsKey(tn.Scope)) WithVariables.Remove(tn.Scope); tn = tn.base_type; } } foreach (SymbolTable.Scope sc in WithTypesList) { WithTypes.Pop(); } WithSection = WithVariables.Count > 0; convertion_data_and_alghoritms.statement_list_stack_pop(); return_value(stl); }
public void make_constructor() { #if (DEBUG) if (converting_block()!=block_type.function_block) { throw new CompilerInternalError("Create constructor call without function"); } if (_func_stack.top().node_location_kind!=SemanticTree.node_location_kind.in_class_location) { throw new CompilerInternalError("Create constructor applied to non class method"); } #endif common_function_node top_func=_func_stack.top(); top_func.return_value_type=_ctn; common_method_node top_method=(common_method_node)top_func; common_method_node cmn=new common_method_node(top_func.name,_ctn,top_method.loc,_ctn, SemanticTree.polymorphic_state.ps_static,_fal,top_func.scope); cmn.is_constructor=true; cmn.is_overload=top_function.is_overload; //parameter_list pl = new parameter_list(); foreach (common_parameter pr in top_method.parameters) { common_parameter new_par = new common_parameter(pr.name, pr.type, pr.parameter_type, cmn, pr.concrete_parameter_type, pr.default_value, pr.loc); cmn.parameters.AddElement(new_par); } //cmn.parameters.AddRange(top_method.parameters); statements_list stl=new statements_list(top_func.loc); cmn.function_code=stl; this_node thn=new this_node(_ctn,top_func.loc); common_method_call csmc=new common_method_call(top_method,thn,top_func.loc); foreach(common_parameter cp in cmn.parameters) { common_parameter_reference cpr=new common_parameter_reference(cp,0,top_func.loc); csmc.parametres.AddElement(cpr); } stl.statements.AddElement(csmc); _ctn.methods.AddElement(cmn); top_method.pascal_associated_constructor=cmn; }
internal void add_clip_for_set(common_function_node cfn) { statements_list sl = cfn.function_code as statements_list; if (sl == null) return; foreach (common_parameter prm in cfn.parameters) { if (prm.type.type_special_kind == SemanticTree.type_special_kind.set_type && prm.parameter_type == SemanticTree.parameter_type.value || prm.is_params && prm.type.element_type.type_special_kind == SemanticTree.type_special_kind.set_type) { if (!prm.is_params) { ordinal_type_interface oti = prm.type.element_type.get_internal_interface(internal_interface_kind.ordinal_interface) as ordinal_type_interface; if (oti == null) if (prm.type.element_type.type_special_kind == SemanticTree.type_special_kind.short_string) { base_function_call cmc2 = null; if (SystemLibrary.SystemLibInitializer.ClipShortStringInSetProcedure.sym_info is common_namespace_function_node) cmc2 = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringInSetProcedure.sym_info as common_namespace_function_node, null); else cmc2 = new compiled_static_method_call(SystemLibrary.SystemLibInitializer.ClipShortStringInSetProcedure.sym_info as compiled_function_node, null); cmc2.parameters.AddElement(new common_parameter_reference(prm,0,null)); cmc2.parameters.AddElement(new int_const_node((prm.type.element_type as short_string_type_node).Length,null)); sl.statements.AddElementFirst(cmc2); continue; } else continue; base_function_call cmc = null; if (SystemLibrary.SystemLibInitializer.ClipProcedure.sym_info is common_namespace_function_node) cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipProcedure.sym_info as common_namespace_function_node, null); else cmc = new compiled_static_method_call(SystemLibrary.SystemLibInitializer.ClipProcedure.sym_info as compiled_function_node, null); cmc.parameters.AddElement(new common_parameter_reference(prm,0,null)); cmc.parameters.AddElement(oti.lower_value); cmc.parameters.AddElement(oti.upper_value); sl.statements.AddElementFirst(cmc); } else { var_definition_node var = context.create_for_temp_variable(prm.type.element_type,null); expression_node in_what = new common_parameter_reference(prm,0,null); statements_list what_do = new statements_list(null); ordinal_type_interface oti = prm.type.element_type.element_type.get_internal_interface(internal_interface_kind.ordinal_interface) as ordinal_type_interface; bool short_str = false; if (oti == null) if (prm.type.element_type.element_type.type_special_kind == SemanticTree.type_special_kind.short_string) { short_str = true; } else continue; base_function_call cmc = null; if (!short_str) { if (SystemLibrary.SystemLibInitializer.ClipProcedure.sym_info is common_namespace_function_node) cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipProcedure.sym_info as common_namespace_function_node, null); else cmc = new compiled_static_method_call(SystemLibrary.SystemLibInitializer.ClipProcedure.sym_info as compiled_function_node, null); } else { if (SystemLibrary.SystemLibInitializer.ClipShortStringInSetProcedure.sym_info is common_namespace_function_node) cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringInSetProcedure.sym_info as common_namespace_function_node, null); else cmc = new compiled_static_method_call(SystemLibrary.SystemLibInitializer.ClipShortStringInSetProcedure.sym_info as compiled_function_node, null); } if (var is local_block_variable) cmc.parameters.AddElement(new local_block_variable_reference(var as local_block_variable,null)); else cmc.parameters.AddElement(new local_variable_reference(var as local_variable,0,null)); if (!short_str) { cmc.parameters.AddElement(oti.lower_value); cmc.parameters.AddElement(oti.upper_value); } else { cmc.parameters.AddElement(new int_const_node((prm.type.element_type.element_type as short_string_type_node).Length,null)); } what_do.statements.AddElement(cmc); foreach_node fn = new foreach_node(var,in_what,what_do,null); sl.statements.AddElementFirst(fn); } } else if (prm.type.type_special_kind == SemanticTree.type_special_kind.short_string && prm.parameter_type == SemanticTree.parameter_type.value || prm.is_params && prm.type.element_type.type_special_kind == SemanticTree.type_special_kind.short_string) { if (!prm.is_params) { base_function_call cmc = null; if (SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info is common_namespace_function_node) cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as common_namespace_function_node, null); else cmc = new compiled_static_method_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as compiled_function_node, null); cmc.parameters.AddElement(new common_parameter_reference(prm, 0, null)); cmc.parameters.AddElement(new int_const_node((prm.type as short_string_type_node).Length, null)); concrete_parameter_type tmp_cpt = prm.concrete_parameter_type; prm.concrete_parameter_type = concrete_parameter_type.cpt_none; sl.statements.AddElementFirst(find_operator(compiler_string_consts.assign_name, new common_parameter_reference(prm, 0, null), cmc, null)); prm.concrete_parameter_type = tmp_cpt; } 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; 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); //compiled_property_node item_prop = prm.type.find_in_type("Item").sym_info as compiled_property_node; base_function_call cmc = null; if (SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info is common_namespace_function_node) cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as common_namespace_function_node, null); else cmc = new compiled_static_method_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as compiled_function_node, null); expression_node cond = new basic_function_call(SystemLibrary.SystemLibrary.int_sm as basic_function_node, null, new local_variable_reference(var, 0, null), new local_variable_reference(len_var, 0, null)); //compiled_function_call get_item = new compiled_function_call(item_prop.get_function as compiled_function_node,cpr,null); //get_item.parameters.AddElement(new local_variable_reference(var,0,null)); cmc.parameters.AddElement(new simple_array_indexing(cpr, new local_variable_reference(var, 0, null), prm.type.element_type, null)); cmc.parameters.AddElement(new int_const_node((prm.type.element_type as short_string_type_node).Length, null)); body.statements.AddElement(find_operator(compiler_string_consts.assign_name, new simple_array_indexing(cpr, new local_variable_reference(var, 0, null), prm.type.element_type, null), cmc, null)); body.statements.AddElement(new basic_function_call(SystemLibrary.SystemLibrary.int_assign as basic_function_node, null, new local_variable_reference(var, 0, null), new basic_function_call(SystemLibrary.SystemLibrary.int_add as basic_function_node, null, new local_variable_reference(var, 0, null), new int_const_node(1, null)))); while_node wn = new while_node(cond, body, null); sl.statements.AddElementFirst(wn); sl.statements.AddElementFirst(new basic_function_call(SystemLibrary.SystemLibrary.int_assign as basic_function_node, null, new local_variable_reference(len_var, 0, null), new compiled_function_call(get_func, cpr, null))); } } } }
public override void visit(SyntaxTree.if_node _if_node) { expression_node condition = convert_strong(_if_node.condition); condition = convertion_data_and_alghoritms.convert_type(condition, SystemLibrary.SystemLibrary.bool_type); CheckToEmbeddedStatementCannotBeADeclaration(_if_node.then_body); CheckToEmbeddedStatementCannotBeADeclaration(_if_node.else_body); statements_list sl = new statements_list(get_location(_if_node.then_body)); convertion_data_and_alghoritms.statement_list_stack_push(sl); context.enter_code_block_with_bind(); statement_node then_st = convert_strong(_if_node.then_body); context.leave_code_block(); sl = convertion_data_and_alghoritms.statement_list_stack.pop(); if (sl.statements.Count > 0 || sl.local_variables.Count > 0) { sl.statements.AddElement(then_st); then_st = sl; } if (_if_node.else_body != null) { sl = new statements_list(get_location(_if_node.else_body)); convertion_data_and_alghoritms.statement_list_stack_push(sl); } context.enter_code_block_with_bind(); statement_node else_st = convert_weak(_if_node.else_body); context.leave_code_block(); if (_if_node.else_body != null) { sl = convertion_data_and_alghoritms.statement_list_stack.pop(); if (sl.statements.Count > 0 || sl.local_variables.Count > 0) { sl.statements.AddElement(else_st); else_st = sl; } } if_node if_node = new if_node(condition, then_st, else_st, get_location(_if_node)); return_value(if_node); }
private void VisitStatementList(statements_list stmt) { statement_node sn = null; foreach (local_block_variable lbv in stmt.local_variables) { helper.AddVariable(lbv); if(lbv.inital_value!=null) VisitExpression(lbv.inital_value); } for (int i = 0; i < stmt.statements.Count; i++) { if (is_break_stmt && stmt.statements[i].semantic_node_type != semantic_node_type.empty_statement) warns.Add(new UnreachableCodeDetected(stmt.statements[i].location)); is_break_stmt = false; sn = stmt.statements[i]; VisitStatement(sn); if (is_break_stmt && i < stmt.statements.Count - 1 && stmt.statements[i + 1].semantic_node_type != semantic_node_type.empty_statement) warns.Add(new UnreachableCodeDetected(stmt.statements[i + 1].location)); is_break_stmt = false; } foreach (local_block_variable vdn in stmt.local_variables) { VarInfo vi = helper.GetVariable(vdn); if (vi.num_use == 0 && !vdn.is_special_name) warns.Add(new UnusedVariable(vdn.name, vdn.loc)); if (vi.num_ass > 0 && vi.act_num_use == 0 && !vdn.is_special_name) warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc)); } }
public local_block_variable(string name, type_node type, statements_list stmt_list, location loc) : base(name, type) { this.stmt_list = stmt_list; _loc = loc; }