From d25652fbcf6fc20f0fce30e7c5d9ff379896330b Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 15 Feb 2022 13:20:40 +0200 Subject: [PATCH] parser, ast: support -d for trace_rewrite_already_registered_symbol, trace_register_sym, trace_parse_stmt, trace_parse_comptime, trace_parse_text, trace_parse_file, trace_parse_vet_file --- vlib/v/ast/table.v | 8 ++++++++ vlib/v/parser/parser.v | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 7f4e6db9d5..cdc3008022 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -756,6 +756,9 @@ pub fn (t &Table) unaliased_type(typ Type) Type { fn (mut t Table) rewrite_already_registered_symbol(typ TypeSymbol, existing_idx int) int { existing_symbol := t.type_symbols[existing_idx] + $if trace_rewrite_already_registered_symbol ? { + eprintln('>> rewrite_already_registered_symbol sym: $typ.name | existing_idx: $existing_idx | existing_symbol: $existing_symbol.name') + } if existing_symbol.kind == .placeholder { // override placeholder t.type_symbols[existing_idx] = &TypeSymbol{ @@ -789,6 +792,11 @@ fn (mut t Table) rewrite_already_registered_symbol(typ TypeSymbol, existing_idx [inline] pub fn (mut t Table) register_sym(sym TypeSymbol) int { mut idx := -2 + $if trace_register_sym ? { + defer { + eprintln('>> register_sym: ${sym.name:-60} | idx: $idx') + } + } mut existing_idx := t.type_idxs[sym.name] if existing_idx > 0 { idx = t.rewrite_already_registered_symbol(sym, existing_idx) diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index deb1770cf8..5620dc5952 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -94,6 +94,9 @@ __global codegen_files = []&ast.File{} // for tests pub fn parse_stmt(text string, table &ast.Table, scope &ast.Scope) ast.Stmt { + $if trace_parse_stmt ? { + eprintln('> ${@MOD}.${@FN} text: $text') + } mut p := Parser{ scanner: scanner.new_scanner(text, .skip_comments, &pref.Preferences{}) inside_test_file: true @@ -111,6 +114,9 @@ pub fn parse_stmt(text string, table &ast.Table, scope &ast.Scope) ast.Stmt { } pub fn parse_comptime(text string, table &ast.Table, pref &pref.Preferences, scope &ast.Scope) &ast.File { + $if trace_parse_comptime ? { + eprintln('> ${@MOD}.${@FN} text: $text') + } mut p := Parser{ scanner: scanner.new_scanner(text, .skip_comments, pref) table: table @@ -125,6 +131,9 @@ pub fn parse_comptime(text string, table &ast.Table, pref &pref.Preferences, sco } pub fn parse_text(text string, path string, table &ast.Table, comments_mode scanner.CommentsMode, pref &pref.Preferences) &ast.File { + $if trace_parse_text ? { + eprintln('> ${@MOD}.${@FN} comments_mode: ${comments_mode:-20} | path: ${path:-20} | text: $text') + } mut p := Parser{ scanner: scanner.new_scanner(text, comments_mode, pref) comments_mode: comments_mode @@ -199,6 +208,9 @@ pub fn parse_file(path string, table &ast.Table, comments_mode scanner.CommentsM // the parser gives feedback to the scanner about toplevel statements, so that the scanner can skip // all the tricky inner comments. This is needed because we do not have a good general solution // for handling them, and should be removed when we do (the general solution is also needed for vfmt) + $if trace_parse_file ? { + eprintln('> ${@MOD}.${@FN} comments_mode: ${comments_mode:-20} | path: $path') + } mut p := Parser{ scanner: scanner.new_scanner_file(path, comments_mode, pref) comments_mode: comments_mode @@ -218,6 +230,9 @@ pub fn parse_file(path string, table &ast.Table, comments_mode scanner.CommentsM } pub fn parse_vet_file(path string, table_ &ast.Table, pref &pref.Preferences) (&ast.File, []vet.Error) { + $if trace_parse_vet_file ? { + eprintln('> ${@MOD}.${@FN} path: $path') + } global_scope := &ast.Scope{ parent: 0 }