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
parent
fb3dd82400
commit
d25652fbcf
|
@ -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 {
|
fn (mut t Table) rewrite_already_registered_symbol(typ TypeSymbol, existing_idx int) int {
|
||||||
existing_symbol := t.type_symbols[existing_idx]
|
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 {
|
if existing_symbol.kind == .placeholder {
|
||||||
// override placeholder
|
// override placeholder
|
||||||
t.type_symbols[existing_idx] = &TypeSymbol{
|
t.type_symbols[existing_idx] = &TypeSymbol{
|
||||||
|
@ -789,6 +792,11 @@ fn (mut t Table) rewrite_already_registered_symbol(typ TypeSymbol, existing_idx
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (mut t Table) register_sym(sym TypeSymbol) int {
|
pub fn (mut t Table) register_sym(sym TypeSymbol) int {
|
||||||
mut idx := -2
|
mut idx := -2
|
||||||
|
$if trace_register_sym ? {
|
||||||
|
defer {
|
||||||
|
eprintln('>> register_sym: ${sym.name:-60} | idx: $idx')
|
||||||
|
}
|
||||||
|
}
|
||||||
mut existing_idx := t.type_idxs[sym.name]
|
mut existing_idx := t.type_idxs[sym.name]
|
||||||
if existing_idx > 0 {
|
if existing_idx > 0 {
|
||||||
idx = t.rewrite_already_registered_symbol(sym, existing_idx)
|
idx = t.rewrite_already_registered_symbol(sym, existing_idx)
|
||||||
|
|
|
@ -94,6 +94,9 @@ __global codegen_files = []&ast.File{}
|
||||||
|
|
||||||
// for tests
|
// for tests
|
||||||
pub fn parse_stmt(text string, table &ast.Table, scope &ast.Scope) ast.Stmt {
|
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{
|
mut p := Parser{
|
||||||
scanner: scanner.new_scanner(text, .skip_comments, &pref.Preferences{})
|
scanner: scanner.new_scanner(text, .skip_comments, &pref.Preferences{})
|
||||||
inside_test_file: true
|
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 {
|
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{
|
mut p := Parser{
|
||||||
scanner: scanner.new_scanner(text, .skip_comments, pref)
|
scanner: scanner.new_scanner(text, .skip_comments, pref)
|
||||||
table: table
|
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 {
|
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{
|
mut p := Parser{
|
||||||
scanner: scanner.new_scanner(text, comments_mode, pref)
|
scanner: scanner.new_scanner(text, comments_mode, pref)
|
||||||
comments_mode: comments_mode
|
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
|
// 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
|
// 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)
|
// 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{
|
mut p := Parser{
|
||||||
scanner: scanner.new_scanner_file(path, comments_mode, pref)
|
scanner: scanner.new_scanner_file(path, comments_mode, pref)
|
||||||
comments_mode: comments_mode
|
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) {
|
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{
|
global_scope := &ast.Scope{
|
||||||
parent: 0
|
parent: 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue