public void write_syntax_tree_node(syntax_tree_node _syntax_tree_node) { if (_syntax_tree_node.source_context == null) { bw.Write((byte)0); } else { bw.Write((byte)1); if (_syntax_tree_node.source_context.begin_position == null) { bw.Write((byte)0); } else { bw.Write((byte)1); bw.Write(_syntax_tree_node.source_context.begin_position.line_num); bw.Write(_syntax_tree_node.source_context.begin_position.column_num); } if (_syntax_tree_node.source_context.end_position == null) { bw.Write((byte)0); } else { bw.Write((byte)1); bw.Write(_syntax_tree_node.source_context.end_position.line_num); bw.Write(_syntax_tree_node.source_context.end_position.column_num); } } }
public static string node(syntax_tree_node tn) { string_ref sr=new string_ref(); get_node_info gni=new get_node_info(sr); tn.visit(gni); return sr.s; }
/// <summary> /// Конструктор /// </summary> /// <param name="root">Корень обходимого поддерева</param> /// <param name="context">Контекст. Необходим для поиска переменных</param> /// <param name="isForNode">True при обходе цикла, False при обходе секций</param> public VarFinderSyntaxVisitor(syntax_tree_node root, compilation_context context, bool isForNode) { this.isForNode = isForNode; this.context = context; ProcessNode(root); FixResultVar(); }
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 override void Enter(syntax_tree_node st) { base.Enter(st); if (!(st is procedure_definition || st is block || st is statement_list || st is case_node || st is for_node || st is foreach_stmt || st is if_node || st is repeat_node || st is while_node || st is with_statement || st is try_stmt || st is lock_stmt)) { //visitNode = false; } }
public override void Enter(syntax_tree_node st) { base.Enter(st); // Не заходим во вложенные циклы, там свои break-continue if ((st is for_node || st is foreach_stmt || st is while_node || st is repeat_node)) { visitNode = false; } }
protected CapturedVariablesTreeNode(CapturedVariablesTreeNode parentNode, int scopeNum, syntax_tree_node correspondingSyntaxTreeNode) { ParentNode = parentNode; ChildNodes = new List<CapturedVariablesTreeNode>(); VariablesDefinedInScope = new List<CapturedSymbolInfo>(); ScopeIndex = scopeNum; CorrespondingSyntaxTreeNode = correspondingSyntaxTreeNode; LambdasDefinedInScope = new List<CapturedVariablesTreeNodeLambdaScope>(); }
public syntax_tree_node Find(SyntaxTree.compilation_unit unit, SourceContext findContext) { _findContext = findContext; _findResult = null; //unit.visit(this); ProcessNode(unit); return _findResult; }
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 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); countNodesVisited++; // сокращение обходимых узлов. Как сделать фильтр по тем узлам, которые необходимо обходить? Например, все операторы (без выражений и описаний), все описания (без операторов) if (st is assign || st is var_def_statement || st is procedure_call || st is procedure_header || st is expression) { visitNode = false; // фильтр - куда не заходить } }
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 program_module NewProgramModule(program_name progName, Object optHeadCompDirs, uses_list mainUsesClose, syntax_tree_node progBlock, Object optPoint, LexLocation loc) { var progModule = new program_module(progName, mainUsesClose, progBlock as block, null, loc); progModule.Language = LanguageId.PascalABCNET; if (optPoint == null && progBlock != null) { var fp = progBlock.source_context.end_position; var err_stn = progBlock; if ((progBlock is block) && (progBlock as block).program_code != null && (progBlock as block).program_code.subnodes != null && (progBlock as block).program_code.subnodes.Count > 0) err_stn = (progBlock as block).program_code.subnodes[(progBlock as block).program_code.subnodes.Count - 1]; parsertools.errors.Add(new PABCNETUnexpectedToken(parsertools.CurrentFileName, StringResources.Get("TKPOINT"), new SourceContext(fp.line_num, fp.column_num + 1, fp.line_num, fp.column_num + 1, 0, 0), err_stn)); } return progModule; }
protected bool visitNode = true; // в OnEnter можно сделать false public virtual void ProcessNode(syntax_tree_node Node) { if (Node != null) { if (OnEnter != null) OnEnter(Node); if (visitNode) Node.visit(this); else visitNode = true; if (OnLeave != null) OnLeave(Node); } }
public override void Exit(syntax_tree_node st) { if (st is procedure_definition) { if (mids.vars.Count>0) { d[st as procedure_definition] = new HashSet<string>(mids.vars); } var fld = new FindLocalDefsVisitor(); st.visit(fld); fld.Print(); var t = fld.ids.Intersect(mids.vars); // идентификаторы, захваченные из локального контекста } base.Exit(st); }
public override void Enter(syntax_tree_node st) { base.Enter(st); countNodesVisited++; if (st is procedure_definition) { // пока вложенные процедуры не анализируются, хотя надо mids.vars.Clear(); } // сокращение обходимых узлов. Как сделать фильтр по тем узлам, которые необходимо обходить? Например, все операторы (без выражений и описаний), все описания (без операторов) if (st is assign || st is var_def_statement || st is procedure_call || st is procedure_header || st is expression) { visitNode = false; } }
void connect(syntax_tree_node node) { if (node == null || node.source_context == null || documentation.ContainsKey(node)) return; if (line_to_section.ContainsKey(node.source_context.begin_position.line_num) ) { documentation_comment_section dsc = line_to_section[node.source_context.begin_position.line_num]; if (dsc.tags.Count == 0) if (dsc.text != null) { documentation.Add(node, dsc.text); return; } foreach (documentation_comment_tag dt in dsc.tags) if (dt.name.ToLower() == "summary") documentation.Add(node, dt.text); } }
private void prepare_node_with_text(syntax_tree_node subnode, string text) { if (subnode==null) { return; } TreeNode tn=new TreeNode(); tn.Text=text; tn.Tag=subnode; string s=get_node_info.node(subnode); if (s!=null) { tn.Text+=" "+s; } //tn.Nodes.Clear(); visualizator vs=new visualizator(tn.Nodes); subnode.visit(vs); nodes.Add(tn); }
public override void Exit(syntax_tree_node st) { var stl = st as statement_list; if (stl != null && UpperNode() is statement_list) ReplaceStatement(stl, stl.subnodes); var lst = st as labeled_statement; if (lst != null) { var sttl = lst.to_statement as statement_list; if (sttl != null) { sttl.subnodes[0] = new labeled_statement(lst.label_name, sttl.subnodes[0]); // а если [0] элемента вообще нет? ReplaceStatement(lst,sttl.subnodes); } } base.Exit(st); }
public override void ProcessNode(syntax_tree_node Node) { if (Node == null) return; if (Node.source_context == null) return; if (FindContextIn(Node)) Node.visit(this); else { if (ContextInRightOrder(_findContext, Node.source_context)) { if (_findResult == null) _findResult = Node; else if (ContextStartsInRightOrder(Node.source_context, _findResult.source_context)) _findResult = Node; } } }
public Dictionary<syntax_tree_node, string> Construct(syntax_tree_node tree_root, documentation_comment_list sections_list) { documentation = new Dictionary<syntax_tree_node, string>(); if (sections_list.sections.Count == 0) return documentation; foreach (documentation_comment_section dcs in sections_list.sections) line_to_section.Add(dcs.source_context.end_position.line_num + 1, dcs); try { visit_node(tree_root); } catch { } //visit_node(tree_root); line_to_section.Clear(); Dictionary<syntax_tree_node, string> dcn = documentation; documentation = null; return dcn; }
public syntax_tree_node Convert(syntax_tree_node root) { root.visit(new MarkMethodHasYieldAndCheckSomeErrorsVisitor()); ProcessYieldCapturedVarsVisitor.New.ProcessNode(root); //root.visit(py); - пропускал корень #if DEBUG try { //root.visit(new SimplePrettyPrinterVisitor(@"d:\\zzz1.txt")); } catch { } #endif return root; }
public override void Exit(syntax_tree_node st) { var sts = st as statement; if (sts != null && !(sts is statement_list) && !(sts is case_variant) && !(UpperNode() is statement_list)) { // Одиночный оператор var stl = new statement_list(sts, st.source_context); Replace(sts, stl); } var lst = st as labeled_statement; if (lst != null && !(lst.to_statement is statement_list) && !(lst.to_statement is case_variant)) { // Одиночный оператор var stl = new statement_list(sts, st.source_context); Replace(lst.to_statement, stl); } base.Exit(st); }
public override void Exit(syntax_tree_node st) { var stl = st as statement_list; if (stl != null && UpperNode() is statement_list) ReplaceStatement(stl, stl.subnodes); var lst = st as labeled_statement; if (lst != null) { var sttl = lst.to_statement as statement_list; if (sttl != null) { if (sttl.subnodes[0] is var_statement) // SSM - 17.07.16 - фикс - нельзя помечать меткой var_statement! { sttl.AddFirst(empty_statement.New); } sttl.subnodes[0] = new labeled_statement(lst.label_name, sttl.subnodes[0]); // [0] элемент есть обязательно - в случае пустого begin end это empty_statement ReplaceStatement(lst,sttl.subnodes); } } base.Exit(st); }
public SyntaxVisitorError(string resourcestring, PascalABCCompiler.SyntaxTree.syntax_tree_node bad_node) : base(StringResources.Get(resourcestring), "", bad_node.source_context, bad_node) { }
public void visit(syntax_tree_node _syntax_tree_node) { bw.Write((Int16)0); write_syntax_tree_node(_syntax_tree_node); }
public syntax_tree_node Convert(syntax_tree_node root) { //FillParentNodeVisitor.New.ProcessNode(root); // прошивание ссылками на Parent nodes // Пока нельзя вызывать - если это делать, то ObjectCopier.Clone провоцирует катастрофически долгое время работы!!! return root; }
public typecast_node NewAsIsExpr(syntax_tree_node term, op_typecast typecast_op, type_definition simple_or_template_type_reference, LexLocation loc) { var naie = new typecast_node((addressed_value)term, simple_or_template_type_reference, typecast_op, loc); if (!(term is addressed_value)) parsertools.errors.Add(new bad_operand_type(parsertools.CurrentFileName, term.source_context, naie)); return naie; }
public case_variants AddCaseItem(case_variants case_list, syntax_tree_node case_item, LexLocation loc) { var nci = case_list; if (case_item is case_variant) nci.Add((case_variant)case_item); nci.source_context = loc; return nci; }
public SyntaxError(string Message, PascalABCCompiler.SyntaxTree.syntax_tree_node bad_node) : this(Message, null, bad_node.source_context, bad_node) { }
public SyntaxError(string Message, string fileName, PascalABCCompiler.SyntaxTree.SourceContext _source_context, PascalABCCompiler.SyntaxTree.syntax_tree_node _bad_node) : base(Message, fileName) { source_context = _source_context; if (source_context != null && source_context.FileName != null) { base.fileName = source_context.FileName; } if (source_context == null && _bad_node != null) // искать source_context у Parentов { var bn = _bad_node; do { bn = bn.Parent; if (bn != null && bn.source_context != null) { source_context = bn.source_context; if (source_context.FileName != null) { base.fileName = source_context.FileName; } break; } } while (bn != null); } bad_node = _bad_node; }
public SyntaxError(string Message, string fileName, PascalABCCompiler.SyntaxTree.SourceContext _source_context, PascalABCCompiler.SyntaxTree.syntax_tree_node _bad_node) : base(Message, fileName) { source_context = _source_context; if (source_context != null && source_context.FileName != null) { base.fileName = source_context.FileName; } bad_node = _bad_node; }