public void AddTempWarning(var_definition_node vdn, CompilerWarningWithLocation cw) { List<CompilerWarningWithLocation> lst = (List<CompilerWarningWithLocation>)warns[vdn]; if (lst == null) { lst = new List<CompilerWarningWithLocation>(); warns[vdn] = lst; } lst.Add(cw); }
internal expression_node get_init_call_for_short_string(var_definition_node vdn) { location loc = (vdn.type as short_string_type_node).loc; type_node tn = vdn.type; //vdn.type = SystemLibrary.SystemLibInitializer.ShortStringType.TypeNode; vdn.type = SystemLibrary.SystemLibrary.string_type; int Length = (tn as short_string_type_node).Length; expression_node var_ref = create_variable_reference(vdn, loc); expressions_list exl = new expressions_list(); exl.AddElement(var_ref); exl.AddElement(new int_const_node(Length, loc)); expression_node expr = null; //if (SystemLibrary.SystemLibInitializer.ShortStringTypeInitProcedure != null) //convertion_data_and_alghoritms.create_full_function_call(exl, SystemLibrary.SystemLibInitializer.ShortStringTypeInitProcedure.SymbolInfo, null, context.converted_type, context.top_function, true); vdn.type = tn; return expr; }
internal expression_node get_init_call_for_set_as_constr(var_definition_node vdn, expression_node init_value) { location loc = (vdn.type as common_type_node).loc; if (!SystemUnitAssigned) AddError(new NotSupportedError(loc)); //Когда заработает наследование конструкторов надо вставить это /* expression_node var_ref = create_variable_reference(vdn, loc); expressions_list exl = new expressions_list(); exl.AddElement(new typeof_operator(element_type, loc)); base_function_call bfc = create_constructor_call(vdn.type, exl, loc); expression_node expr = find_operator(compiler_string_consts.assign_name, var_ref, bfc, loc); */ type_node tn = vdn.type; vdn.type = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node; expression_node var_ref = create_variable_reference(vdn, loc); expressions_list exl = new expressions_list(); //exl.AddElement(var_ref); //exl.AddElement(new typeof_operator(element_type, loc)); if (tn.element_type == SystemLibrary.SystemLibrary.byte_type) { exl.AddElement(new byte_const_node(byte.MinValue,null)); exl.AddElement(new byte_const_node(byte.MaxValue,null)); } else if (tn.element_type == SystemLibrary.SystemLibrary.sbyte_type) { exl.AddElement(new sbyte_const_node(sbyte.MinValue,null)); exl.AddElement(new sbyte_const_node(sbyte.MaxValue,null)); } else if (tn.element_type == SystemLibrary.SystemLibrary.short_type) { exl.AddElement(new short_const_node(short.MinValue,null)); exl.AddElement(new short_const_node(short.MaxValue,null)); } else if (tn.element_type == SystemLibrary.SystemLibrary.ushort_type) { exl.AddElement(new ushort_const_node(ushort.MinValue,null)); exl.AddElement(new ushort_const_node(ushort.MaxValue,null)); } else if (tn.element_type.type_special_kind == SemanticTree.type_special_kind.diap_type || tn.element_type.type_special_kind == SemanticTree.type_special_kind.enum_kind) { ordinal_type_interface ii = tn.element_type.get_internal_interface(internal_interface_kind.ordinal_interface) as ordinal_type_interface; exl.AddElement(ii.lower_value); exl.AddElement(ii.upper_value); } exl.AddElement(init_value); function_node fn = null; if (exl.Count > 1) { fn = convertion_data_and_alghoritms.select_function(exl, (SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node).find_in_type(compiler_string_consts.default_constructor_name), loc); } else { fn = convertion_data_and_alghoritms.select_function(exl, (SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node).find_in_type(compiler_string_consts.default_constructor_name), loc); } //expression_node expr = convertion_data_and_alghoritms.create_simple_function_call(fn, null, exl.ToArray()); expression_node expr = create_static_method_call_with_params(fn, loc, tn, false, exl); vdn.type = tn; return expr; }
internal expression_node get_init_call_for_binary_file(var_definition_node vdn) { location loc = null; if (vdn.type is common_type_node) loc = (vdn.type as common_type_node).loc; if (!SystemUnitAssigned) AddError(new NotSupportedError(loc)); type_node tn = vdn.type; vdn.type = SystemLibrary.SystemLibInitializer.BinaryFileType.sym_info as type_node; expression_node var_ref = create_variable_reference(vdn, loc); expressions_list exl = new expressions_list(); exl.AddElement(var_ref); function_node fn = convertion_data_and_alghoritms.select_function(exl, SystemLibrary.SystemLibInitializer.BinaryFileInitProcedure.SymbolInfo, loc); expression_node expr = convertion_data_and_alghoritms.create_simple_function_call(fn, null, exl.ToArray()); vdn.type = tn; return expr; }
internal expression_node get_init_call_for_typed_file(var_definition_node vdn, type_node element_type) { location loc = (vdn.type as common_type_node).loc; if (!SystemUnitAssigned) AddError(new NotSupportedError(loc)); //Когда заработает наследование конструкторов надо вставить это /* expression_node var_ref = create_variable_reference(vdn, loc); expressions_list exl = new expressions_list(); exl.AddElement(new typeof_operator(element_type, loc)); base_function_call bfc = create_constructor_call(vdn.type, exl, loc); expression_node expr = find_operator(compiler_string_consts.assign_name, var_ref, bfc, loc); */ type_node tn = vdn.type; vdn.type = SystemLibrary.SystemLibInitializer.TypedFileType.sym_info as type_node; expression_node var_ref = create_variable_reference(vdn, loc); expressions_list exl = new expressions_list(); exl.AddElement(var_ref); exl.AddElement(new typeof_operator(element_type, loc)); List<int> lens = get_short_string_lens(element_type); int sz = get_short_string_size(element_type); if (sz > 0) { exl.AddElement(new int_const_node(get_short_string_size(element_type),null)); for (int i=0; i<lens.Count; i++) exl.AddElement(new int_const_node(lens[i],null)); } this.context.save_var_definitions(); function_node fn = convertion_data_and_alghoritms.select_function(exl, SystemLibrary.SystemLibInitializer.TypedFileInitProcedure.SymbolInfo, loc); this.context.restore_var_definitions(); expression_node expr = convertion_data_and_alghoritms.create_simple_function_call(fn, null, exl.ToArray()); vdn.type = tn; return expr; }
internal expression_node GetInitalValueForVariable(var_definition_node vdn, expression_node userInitalValue) { if (userInitalValue != null) { if (CurrentStatementList != null) { //Инициализировать надо в текущем стейтменте location lid = ((local_block_variable)vdn).loc; local_block_variable_reference lbvr = new local_block_variable_reference((local_block_variable)vdn, lid); if (vdn.type.type_special_kind == SemanticTree.type_special_kind.set_type) { userInitalValue = syntax_tree_visitor.get_init_call_for_set_as_constr(vdn,userInitalValue); //userInitalValue.type = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node; } else if (userInitalValue is array_initializer) { array_initializer arr = userInitalValue as array_initializer; if (vdn.type.element_type.type_special_kind == SemanticTree.type_special_kind.short_string) { for (int i=0; i<arr.element_values.Count; i++) { //arr.element_values[i] = syntax_tree_visitor.find_operator(compiler_string_consts.assign_name, varref2, arr.element_values[i], null); arr.element_values[i] = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as function_node,null,convertion_data_and_alghoritms.convert_type(arr.element_values[i],SystemLibrary.SystemLibrary.string_type),new int_const_node((vdn.type.element_type as short_string_type_node).Length,null)); } } } CurrentStatementList.statements.AddElement(syntax_tree_visitor.find_operator(compiler_string_consts.assign_name, lbvr, userInitalValue, lid)); if (vdn.type.type_special_kind == SemanticTree.type_special_kind.set_type) { lbvr.type = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node; } return null; } if (userInitalValue is constant_node) { if (vdn.type.type_special_kind == SemanticTree.type_special_kind.short_string) { expression_node varref2 = convertion_data_and_alghoritms.CreateVariableReference(vdn, null); userInitalValue = syntax_tree_visitor.find_operator(compiler_string_consts.assign_name, varref2, userInitalValue, null); } return userInitalValue; } if (userInitalValue is array_initializer) { array_initializer arr = userInitalValue as array_initializer; if (vdn.type.element_type.type_special_kind == SemanticTree.type_special_kind.short_string) { expression_node varref2 = convertion_data_and_alghoritms.CreateVariableReference(vdn, null); for (int i=0; i<arr.element_values.Count; i++) { //arr.element_values[i] = syntax_tree_visitor.find_operator(compiler_string_consts.assign_name, varref2, arr.element_values[i], null); arr.element_values[i] = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as function_node,null,convertion_data_and_alghoritms.convert_type(arr.element_values[i],SystemLibrary.SystemLibrary.string_type),new int_const_node((vdn.type.element_type as short_string_type_node).Length,null)); } } return userInitalValue; } expression_node varref = convertion_data_and_alghoritms.CreateVariableReference(vdn, userInitalValue.location); if (vdn.type.type_special_kind == SemanticTree.type_special_kind.set_type) { userInitalValue = syntax_tree_visitor.get_init_call_for_set_as_constr(vdn,userInitalValue); //userInitalValue.type = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node; } else if (vdn.type.type_special_kind == SemanticTree.type_special_kind.short_string) { expression_node cmc = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as function_node,null,convertion_data_and_alghoritms.convert_type(userInitalValue,SystemLibrary.SystemLibrary.string_type),new int_const_node((vdn.type as short_string_type_node).Length,null)); userInitalValue = cmc; } userInitalValue = syntax_tree_visitor.find_operator(compiler_string_consts.assign_name, varref, userInitalValue, userInitalValue.location); if (vdn.type.type_special_kind == SemanticTree.type_special_kind.set_type) { varref.type = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node; } return userInitalValue; } type_node tp = vdn.type; if (syntax_tree_visitor.SystemUnitAssigned && SystemLibrary.SystemLibInitializer.TextFileType.Found && tp.name == compiler_string_consts.text_file_name_type_name) if (tp == SystemLibrary.SystemLibInitializer.TextFileType.TypeNode) SystemLibrary.SystemLibInitializer.TextFileType.TypeNode.type_special_kind = PascalABCCompiler.SemanticTree.type_special_kind.text_file; //(ssyy) Вставил switch и обработку BinaryFile switch (tp.type_special_kind) { case SemanticTree.type_special_kind.typed_file: userInitalValue = syntax_tree_visitor.get_init_call_for_typed_file(vdn, tp.element_type); break; case SemanticTree.type_special_kind.set_type: userInitalValue = syntax_tree_visitor.get_init_call_for_set(vdn); break; case SemanticTree.type_special_kind.binary_file: userInitalValue = syntax_tree_visitor.get_init_call_for_binary_file(vdn); break; case SemanticTree.type_special_kind.text_file: userInitalValue = syntax_tree_visitor.get_init_call_for_text_file(vdn); break; default: if (tp is short_string_type_node) userInitalValue = SystemLibrary.SystemLibrary.empty_string;//syntax_tree_visitor.get_init_call_for_short_string(vdn); else if (tp == SystemLibrary.SystemLibrary.string_type && SemanticRules.InitStringAsEmptyString) userInitalValue = SystemLibrary.SystemLibrary.empty_string; break; } return userInitalValue; }
public void AddRealWarning(var_definition_node vdn, List<CompilerWarningWithLocation> cw) { List<CompilerWarningWithLocation> lst = (List<CompilerWarningWithLocation>)warns[vdn]; cw.AddRange(lst); }
public VarInfo GetVariable(var_definition_node vdn) { return (VarInfo)ht[vdn]; }
private void SaveVariable(var_definition_node cfn) { if (!string.IsNullOrEmpty(cfn.documentation)) { if (!cfn.documentation.Trim(' ','\t').StartsWith("<summary>")) { xtw.WriteStartElement("member"); xtw.WriteStartAttribute("name"); if (!is_assembly) xtw.WriteString("V:"+cfn.name); else xtw.WriteString("F:"+unit_name+"."+unit_name+"."+cfn.name); xtw.WriteEndAttribute(); xtw.WriteStartElement("summary"); xtw.WriteString(cfn.documentation); xtw.WriteEndElement(); xtw.WriteEndElement(); } else { string doc = string.Concat("<member name=\""+(is_assembly?"F:"+unit_name+"."+unit_name+".":"V:")+cfn.name+"\">",cfn.documentation,"</member>"); StringReader sr = new StringReader(doc); XmlReader xr = XmlTextReader.Create(sr); xr.Read(); xtw.WriteNode(xr.ReadSubtree(),false); sr.Close(); xr.Close(); } } }
public CanNotReferenceToNonStaticFieldWithType(var_definition_node field, location loc, type_node tn) { _field = field; _loc = loc; _tn = tn; }
public CanNotReferanceToStaticFieldWithExpression(var_definition_node field, location loc, expression_node en) { _field = field; _loc = loc; _en = en; }
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; }
//Проверки на доступность OMP и директиву проводятся перед вызовом. internal static statements_list TryConvertFor(statements_list for_head_stmts, SyntaxTree.for_node for_node, for_node fn, var_definition_node loop_variable, expression_node fromInclusive, expression_node toInclusive, syntax_tree_visitor syntax_tree_visitor) { try { location loc = fn.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 доступен то (выполнять паралельно) иначе (выполнять for) if_node ifnode = CreateIfCondition(syntax_tree_visitor, omp_stmts, for_head_stmts, loc); head_stmts.statements.AddElement(ifnode); //генерим ветку в случае когда доступен omp if (!GenerateOMPParallelForCall(fn.body, for_node, loop_variable, omp_stmts, syntax_tree_visitor, fromInclusive, toInclusive)) { 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, fn.location)); } return null; }
public foreach_node(var_definition_node _ident, expression_node _in_what, statement_node _what_do, location loc):base(loc) { this._ident = _ident; this._in_what = _in_what; this._what_do = _what_do; }
private void WriteFieldReference(var_definition_node vdn) { if (vdn is class_field) { bw.Write((byte)0); WriteFieldReference(vdn as class_field); } else if (vdn is compiled_variable_definition) { bw.Write((byte)1); bw.Write(GetCompiledVariable(vdn as compiled_variable_definition)); } }
public void AddVariable(var_definition_node vdn) { VarInfo vi = new VarInfo(); ht[vdn] = vi; }
internal void AddImplVarToOrderList(var_definition_node vdn, int ind) { impl_var_list.Add(ind,vdn); }
public variable_reference CreateVariableReference(var_definition_node vd, location loc) { switch (vd.semantic_node_type) { case semantic_node_type.local_variable: return new local_variable_reference((local_variable)vd, 0, loc); case semantic_node_type.class_field: if (vd.polymorphic_state == polymorphic_state.ps_static) return new static_class_field_reference((class_field)vd, loc); else return new class_field_reference((class_field)vd, syntax_tree_visitor.GetCurrentObjectReference((vd as class_field).cont_type.Scope,vd,loc), loc); case semantic_node_type.namespace_variable: return new namespace_variable_reference((namespace_variable)vd, loc); case semantic_node_type.local_block_variable: return new local_block_variable_reference((local_block_variable)vd, loc); } throw new NotSupportedError(loc); }
public foreach_node(var_definition_node _ident, expression_node _in_what, statement_node _what_do, location loc) : base(loc) { this._ident = _ident; this._in_what = _in_what; this._what_do = _what_do; }
private void IncreaseNumUseVar(var_definition_node lvr) { VarInfo vi = helper.GetVariable(lvr); vi.num_use++; vi.act_num_use++; vi.cur_use++; //if (vi.cur_ass == 0 && !lvr.var.name.Contains("$")) helper.AddTempWarning(lvr.var,new UseWithoutAssign(lvr.var.name, lvr.location)); }
public bool is_loop_variable(var_definition_node vdn) { return loop_var_stack.Contains(vdn); }