public void PrintNode(syntax_tree_node st) { if (printNodeType) { PrintNoOffset(st.GetType().Name + ": "); } Print("" + st); }
public override void Exit(syntax_tree_node st) { Tabs -= 2; if (st.GetType() == typeof(program_module)) { fs.Close(); } }
public void prepare_node(syntax_tree_node subnode, string node_name) { if (subnode == null) { return; } prepare_node_with_text(subnode, node_name + ":" + subnode.GetType().Name); }
public void PrintlnNode(syntax_tree_node st) { if (printNodeType) { Console.Write(st.GetType().Name + ": "); } Console.WriteLine(new string(' ', off) + st); }
public override void Exit(syntax_tree_node st) { if (st.GetType() == typeof(program_module)) { var t = (DateTime.Now - d).Milliseconds; fs.WriteLine(t.ToString()); fs.Close(); } }
public override void Enter(syntax_tree_node st) { if (d.ContainsKey(st.GetType())) { d[st.GetType()] += 1; } else { d[st.GetType()] = 1; } if (st is expression) { exprcount++; } if (st is statement) { statcount++; } }
public override void Exit(syntax_tree_node st) { if (st is procedure_definition || st is class_definition) { if (PrintInfo) { Console.WriteLine("-: " + st.GetType().Name); } list.RemoveAt(list.Count - 1); } base.Exit(st); }
public override void Enter(syntax_tree_node st) { base.Enter(st); if (st is procedure_definition || st is class_definition) { list.Add(st as declaration); if (PrintInfo) { Console.Write("+: " + st.GetType().Name); } } }
public override void Enter(syntax_tree_node st) { base.Enter(st); if (!(st is procedure_definition || st is block || st is statement_list || st.GetType() == typeof(case_node) || st.GetType() == typeof(for_node) || st.GetType() == typeof(foreach_stmt) || st.GetType() == typeof(if_node) || st.GetType() == typeof(repeat_node) || st.GetType() == typeof(while_node) || st.GetType() == typeof(with_statement) || st is try_stmt || st.GetType() == typeof(lock_stmt))) { //visitNode = false; } }
public virtual void Enter(syntax_tree_node st) { if (st is statement_list) { Println("begin"); off += 2; } else if (st is type_declarations) // надо в visit и самому всё обрабатывать { var tds = st is type_declarations; Println("type "); off += 2; } else if (st is case_variant) { var td = st as case_variant; Println(td.conditions.ToString() + ": "); off += 2; //ProcessNode(td.type_def); //visitNode = false; } else if (st is type_declaration) { var td = st as type_declaration; Print(td.type_name + " = "); ProcessNode(td.type_def); visitNode = false; } else if (st is procedure_definition) { //ProcessNode(st as procedure_definition); visitNode = visitNode; } else if (st is class_definition) { var cd = st as class_definition; PrintNoOffset("class"); if (cd.class_parents?.types.Count > 0) { PrintlnNoOffset("(" + cd.class_parents.ToString() + ")"); } else { PrintlnNoOffset(""); } off += 2; ProcessNode(cd.body); visitNode = false; } else if (st is access_modifer_node) { var am = st as access_modifer_node; Println(am.access_level.ToString().Replace("_modifier", "")); } else if (st is variable_definitions) { var vds = st as variable_definitions; Print("var"); off += 2; } else if (st is var_def_statement) { var vds = st as var_def_statement; Println(vds.ToString()); } else if (st is empty_statement || st is declarations || st is block || st is class_body || st is class_members || st is case_variants || st is program_module || st is no_type_foreach || st is template_param_list || st is yield_unknown_foreach_type || st is yield_unknown_expression_type ) { } /* else if (st is array_type) * { * var vds = st as array_type; * Println ("array of "+vds.elements_type.ToString()); * }*/ else if (st is if_node) { var ifn = st as if_node; Println("if " + ifn.condition.ToString() + " then"); off += 2; ProcessNode(ifn.then_body); if (ifn.else_body == null) { visitNode = false; return; } off -= 2; Println("else "); off += 2; ProcessNode(ifn.else_body); visitNode = false; } else if (st is while_node) { var wn = st as while_node; Println("while " + wn.expr.ToString() + " do"); off += 2; } else if (st is for_node) { var fn = st as for_node; Println("for var " + fn.loop_variable + " := " + fn.initial_value + " to " + fn.finish_value + " do "); off += 2; } else if (st is foreach_stmt) { var wn = st as foreach_stmt; Println("foreach " + wn.identifier.ToString() + " in " + wn.in_what + " do"); off += 2; } else if (st is case_node) { var cn = st as case_node; Println("case " + cn.param.ToString() + " of"); off += 2; } else if (st is labeled_statement) { var lst = st as labeled_statement; Println(lst.label_name.name + ": "); ProcessNode(lst.to_statement); visitNode = false; } else if (st is var_statement || st is procedure_header) { var s = st.ToString(); s = s.Replace("PascalABCCompiler.SyntaxTree.", "").Replace("System.Collections.Generic.", ""); Println(s); visitNode = false; } else if (st is procedure_definition) { Println(""); } else if (st is statement || st is variable_definitions || st is label_definitions) { PrintNode(st); if (st is statement) { PrintlnNoOffset(";"); } else { PrintlnNoOffset(""); } if (st is labeled_statement) { visitNode = false; } } else if (st is token_info) { var s = st.ToString(); if (s == "begin" || s == "end") { return; } PrintlnNode(st); } else if (st is function_lambda_definition) { var f = st as function_lambda_definition; //PrintNoOffset(f.ToString()); visitNode = false; } /*else if (st is named_type_reference) * { * var s = st.ToString(); * s = s.Replace("PascalABCCompiler.SyntaxTree.", "").Replace("System.Collections.Generic.",""); * * PrintlnNoOffset(s); * }*/ else { var q = st.GetType().GetMethod("ToString", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly); if (q == null) { Println(st.GetType().Name); } } }
public override void DefaultVisit(syntax_tree_node n) { fs.WriteLine(n.GetType().Name); base.DefaultVisit(n); }
public virtual void Enter(syntax_tree_node st) { if (st is statement_list) { Println("begin"); off += 2; } else if (st is type_declarations) // надо в visit и самому всё обрабатывать { var tds = st is type_declarations; Println("type "); off += 2; } else if (st is case_variant) { var td = st as case_variant; Println(td.conditions.ToString() + ": "); off += 2; //ProcessNode(td.type_def); //visitNode = false; } else if (st is type_declaration) { var td = st as type_declaration; Print(td.type_name + " = "); ProcessNode(td.type_def); visitNode = false; } else if (st is class_definition) { var cd = st as class_definition; PrintNoOffset("class"); if (cd.class_parents != null && cd.class_parents.types.Count > 0) { PrintlnNoOffset("(" + cd.class_parents.ToString() + ")"); } else { PrintlnNoOffset(""); } off += 2; ProcessNode(cd.body); visitNode = false; } else if (st is access_modifer_node) { var am = st as access_modifer_node; Println(am.access_level.ToString()); } else if (st is variable_definitions) { var vds = st as variable_definitions; Println("var"); off += 2; } else if (st is var_def_statement) { var vds = st as var_def_statement; Println(vds.ToString()); } else if (st is empty_statement || st is declarations || st is block || st is class_body || st is class_members || st is case_variants || st is program_module) { } else if (st is if_node) { var ifn = st as if_node; Println("if " + ifn.condition.ToString() + " then"); off += 2; ProcessNode(ifn.then_body); if (ifn.else_body == null) { visitNode = false; return; } off -= 2; Println("else "); off += 2; ProcessNode(ifn.else_body); visitNode = false; } else if (st is while_node) { var wn = st as while_node; Println("while " + wn.expr.ToString() + " do"); off += 2; } else if (st is case_node) { var cn = st as case_node; Println("case " + cn.param.ToString() + " of"); off += 2; } else if (st is labeled_statement) { var lst = st as labeled_statement; Println(lst.label_name.name + ": "); ProcessNode(lst.to_statement); visitNode = false; } else if (st is var_statement || st is procedure_header) { Println(st.ToString()); visitNode = false; } else if (st is procedure_definition) { Println(""); } else if (st is statement || st is variable_definitions || st is label_definitions) { PrintlnNode(st); if (st is labeled_statement) { visitNode = false; } } else if (st is token_info) { var s = st.ToString(); if (s == "begin" || s == "end") { return; } PrintlnNode(st); } else { var q = st.GetType().GetMethod("ToString", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly); if (q == null) { Println(st.GetType().Name); } } }