private static SyntaxTree.expression ConvertConstant(SemanticTree.IConstantNode value) { if (value is bool_const_node) return new SyntaxTree.ident((value as bool_const_node).constant_value ? "true" : "false"); else if (value is null_const_node) return new SyntaxTree.nil_const(); else if (value is byte_const_node) return new SyntaxTree.int32_const((value as byte_const_node).constant_value); else if (value is char_const_node) return new SyntaxTree.char_const((value as char_const_node).constant_value); else if (value is double_const_node) return new SyntaxTree.double_const((value as double_const_node).constant_value); else if (value is float_const_node) return new SyntaxTree.double_const((value as float_const_node).constant_value); else if (value is int_const_node) return new SyntaxTree.int32_const((value as int_const_node).constant_value); else if (value is long_const_node) return new SyntaxTree.int64_const((value as long_const_node).constant_value); else if (value is sbyte_const_node) return new SyntaxTree.int32_const((value as sbyte_const_node).constant_value); else if (value is short_const_node) return new SyntaxTree.int32_const((value as short_const_node).constant_value); else if (value is uint_const_node) return new SyntaxTree.uint64_const((value as uint_const_node).constant_value); else if (value is ulong_const_node) return new SyntaxTree.uint64_const((value as ulong_const_node).constant_value); else if (value is ushort_const_node) return new SyntaxTree.int32_const((value as ushort_const_node).constant_value); else if (value is string_const_node) return new SyntaxTree.string_const((value as string_const_node).constant_value); else if (value is array_const) { array_const ac = value as array_const; SyntaxTree.expression_list el = new PascalABCCompiler.SyntaxTree.expression_list(); for (int i = 0; i < ac.element_values.Count; ++i) el.Add(ConvertConstant(ac.element_values[i])); SyntaxTree.array_const synAC = new PascalABCCompiler.SyntaxTree.array_const(); synAC.elements = el; return synAC; } else if (value is enum_const_node) { //Есть сомнения, что будет работать во всех случаях enum_const_node ec = value as enum_const_node; SyntaxTree.ident r = new SyntaxTree.ident((ec.type as common_type_node).const_defs[ec.constant_value].name); SyntaxTree.ident l = new SyntaxTree.ident(ec.type.name); return new SyntaxTree.dot_node(l, r); } else if (value is record_constant) { record_constant rc = value as record_constant; SyntaxTree.record_const synRC = new PascalABCCompiler.SyntaxTree.record_const(); for (int i = 0; i < rc.field_values.Count; ++i) { SyntaxTree.record_const_definition rcd = new PascalABCCompiler.SyntaxTree.record_const_definition(); rcd.name = rc.record_const_definition_list[i].name; rcd.val = rc.record_const_definition_list[i].val; synRC.rec_consts.Add(rcd); } return synRC; } else throw new Exception("Не реализовано"); //выяснить, что тут может быть }
private static bool GenerateOMPParallelSectionsCall(statements_list stmts, SyntaxTree.statement_list syntax_stmts, statements_list omp_stmts, syntax_tree_visitor syntax_tree_visitor) { SyntaxTree.expression_list delegates = new PascalABCCompiler.SyntaxTree.expression_list(); SyntaxTree.statement_list stlInit = new PascalABCCompiler.SyntaxTree.statement_list(); SyntaxTree.statement_list stlFinal = new PascalABCCompiler.SyntaxTree.statement_list(); VarInfoContainer Vars = new VarInfoContainer(); string ClassName = syntax_tree_visitor.context.get_free_name("$section_class{0}"); List<SyntaxTree.statement> Sections = new List<PascalABCCompiler.SyntaxTree.statement>(); foreach (SyntaxTree.statement syntax_statement in syntax_stmts.subnodes) { if (syntax_statement is SyntaxTree.empty_statement) continue; //А зачем? ;-) if (syntax_statement is SyntaxTree.var_statement) { //выдать предупреждение. Это не нормально для параллельных секций syntax_tree_visitor.visit(syntax_statement as SyntaxTree.var_statement); } else { //ищем используемые переменные VarFinderSyntaxVisitor VFvis = new VarFinderSyntaxVisitor(syntax_statement, syntax_tree_visitor.context, false); SyntaxTree.compiler_directive dir = syntax_tree_visitor.DirectivesToNodesLinks[syntax_stmts]; //if (DirInfosTable[dir].ErrorName == "WARNING_IN_CLAUSE_PARAMETERS_REPEATED_VARS") // syntax_tree_visitor.AddWarning(new Errors.CommonWarning(StringResources.Get(DirInfosTable[dir].ErrorName), syntax_stmts.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), syntax_stmts.source_context.FileName, DirInfosTable[dir].SC.begin_position.line_num, DirInfosTable[dir].SC.begin_position.column_num)); //} //else if (DirInfosTable[dir].ErrorName != null) { syntax_tree_visitor.AddWarning(new Errors.CommonWarning(PascalABCCompiler.StringResources.Get(DirInfosTable[dir].ErrorName), syntax_stmts.source_context.FileName, DirInfosTable[dir].SC.begin_position.line_num, DirInfosTable[dir].SC.begin_position.column_num)); } Vars.UnionWith(GetVarInfoContainer(VFvis, null, DirInfosTable[dir].Privates, syntax_tree_visitor, dir)); Sections.Add(syntax_statement); } } //сохраняем контекст ContextInfo contextInfo = new ContextInfo(syntax_tree_visitor); try { //создание и конвертирование класса SyntaxTree.class_members member; SyntaxTree.type_declarations Decls = CreateClass(ClassName, out member, Vars); for (int i = 0; i < Sections.Count; ++i) member.members.Add(CreateMethod("method" + i.ToString(), Sections[i], "", member, Vars)); syntax_tree_visitor.visit(Decls); } finally { //восстанавливаем контекст contextInfo.RestoreContext(syntax_tree_visitor); } //создаем инициализацию и финализацию int NameNum = 0; string ObjName = GetFreeName("$section_obj", ref NameNum, syntax_tree_visitor.context); stlInit.subnodes.AddRange(CreateInitPart(ClassName, ObjName, Vars).subnodes); stlFinal.subnodes.AddRange(CreateFinalPart(ObjName, Vars).subnodes); SyntaxTree.procedure_call pc = new PascalABCCompiler.SyntaxTree.procedure_call(); SyntaxTree.method_call mc = new PascalABCCompiler.SyntaxTree.method_call(); mc.dereferencing_value = CreateTPLFunctionReference("Invoke"); pc.func_name = mc; SyntaxTree.expression_list exl = new PascalABCCompiler.SyntaxTree.expression_list(); //foreach (string str in ObjNames) for (int i=0; i<Sections.Count; ++i) exl.Add(new SyntaxTree.dot_node(new SyntaxTree.ident(ObjName), new SyntaxTree.ident("Method"+i.ToString()))); mc.parameters = exl; stlInit.subnodes.Add(CreateNestedRegionBorder(true)); stlInit.subnodes.Add(pc); stlInit.subnodes.AddRange(stlFinal.subnodes); stlInit.subnodes.Add(CreateNestedRegionBorder(false)); statement_node st = syntax_tree_visitor.ret.visit(stlInit); omp_stmts.statements.AddElement(st); return true; }