Skip to content

Commit

Permalink
parser, ast: support -d for trace_rewrite_already_registered_symbol, …
Browse files Browse the repository at this point in the history
…trace_register_sym, trace_parse_stmt, trace_parse_comptime, trace_parse_text, trace_parse_file, trace_parse_vet_file
  • Loading branch information
spytheman committed Feb 15, 2022
1 parent fb3dd82 commit d25652f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions vlib/v/ast/table.v
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions vlib/v/parser/parser.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit d25652f

Please sign in to comment.