ast: change CompFor to ComptimeFor (#12482)
parent
927df948ae
commit
5a89c0a480
|
@ -405,7 +405,7 @@ fn (t Tree) stmt(node ast.Stmt) &Node {
|
||||||
ast.EnumDecl { return t.enum_decl(node) }
|
ast.EnumDecl { return t.enum_decl(node) }
|
||||||
ast.InterfaceDecl { return t.interface_decl(node) }
|
ast.InterfaceDecl { return t.interface_decl(node) }
|
||||||
ast.HashStmt { return t.hash_stmt(node) }
|
ast.HashStmt { return t.hash_stmt(node) }
|
||||||
ast.CompFor { return t.comptime_for(node) }
|
ast.ComptimeFor { return t.comptime_for(node) }
|
||||||
ast.GlobalDecl { return t.global_decl(node) }
|
ast.GlobalDecl { return t.global_decl(node) }
|
||||||
ast.DeferStmt { return t.defer_stmt(node) }
|
ast.DeferStmt { return t.defer_stmt(node) }
|
||||||
ast.TypeDecl { return t.type_decl(node) }
|
ast.TypeDecl { return t.type_decl(node) }
|
||||||
|
@ -700,9 +700,9 @@ fn (t Tree) hash_stmt(node ast.HashStmt) &Node {
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (t Tree) comptime_for(node ast.CompFor) &Node {
|
fn (t Tree) comptime_for(node ast.ComptimeFor) &Node {
|
||||||
mut obj := new_object()
|
mut obj := new_object()
|
||||||
obj.add('ast_type', t.string_node('CompFor'))
|
obj.add('ast_type', t.string_node('ComptimeFor'))
|
||||||
obj.add('val_var', t.string_node(node.val_var))
|
obj.add('val_var', t.string_node(node.val_var))
|
||||||
obj.add('typ', t.type_node(node.typ))
|
obj.add('typ', t.type_node(node.typ))
|
||||||
obj.add('kind', t.enum_node(node.kind))
|
obj.add('kind', t.enum_node(node.kind))
|
||||||
|
|
|
@ -65,7 +65,7 @@ pub type Stmt = AsmStmt
|
||||||
| AssignStmt
|
| AssignStmt
|
||||||
| Block
|
| Block
|
||||||
| BranchStmt
|
| BranchStmt
|
||||||
| CompFor
|
| ComptimeFor
|
||||||
| ConstDecl
|
| ConstDecl
|
||||||
| DeferStmt
|
| DeferStmt
|
||||||
| EmptyStmt
|
| EmptyStmt
|
||||||
|
@ -898,17 +898,17 @@ pub:
|
||||||
post_comments []Comment
|
post_comments []Comment
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum CompForKind {
|
pub enum ComptimeForKind {
|
||||||
methods
|
methods
|
||||||
fields
|
fields
|
||||||
attributes
|
attributes
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CompFor {
|
pub struct ComptimeFor {
|
||||||
pub:
|
pub:
|
||||||
val_var string
|
val_var string
|
||||||
stmts []Stmt
|
stmts []Stmt
|
||||||
kind CompForKind
|
kind ComptimeForKind
|
||||||
pos token.Position
|
pos token.Position
|
||||||
typ_pos token.Position
|
typ_pos token.Position
|
||||||
pub mut:
|
pub mut:
|
||||||
|
@ -1904,7 +1904,7 @@ pub fn (node Node) children() []Node {
|
||||||
}
|
}
|
||||||
} else if node is Stmt {
|
} else if node is Stmt {
|
||||||
match node {
|
match node {
|
||||||
Block, DeferStmt, ForCStmt, ForInStmt, ForStmt, CompFor {
|
Block, DeferStmt, ForCStmt, ForInStmt, ForStmt, ComptimeFor {
|
||||||
return node.stmts.map(Node(it))
|
return node.stmts.map(Node(it))
|
||||||
}
|
}
|
||||||
ExprStmt, AssertStmt {
|
ExprStmt, AssertStmt {
|
||||||
|
|
|
@ -580,7 +580,7 @@ fn field_to_string(f ConstField) string {
|
||||||
return '$x = $f.expr'
|
return '$x = $f.expr'
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (e CompForKind) str() string {
|
pub fn (e ComptimeForKind) str() string {
|
||||||
match e {
|
match e {
|
||||||
.methods { return 'methods' }
|
.methods { return 'methods' }
|
||||||
.fields { return 'fields' }
|
.fields { return 'fields' }
|
||||||
|
|
|
@ -4606,7 +4606,7 @@ fn (mut c Checker) stmt(node ast.Stmt) {
|
||||||
ast.BranchStmt {
|
ast.BranchStmt {
|
||||||
c.branch_stmt(node)
|
c.branch_stmt(node)
|
||||||
}
|
}
|
||||||
ast.CompFor {
|
ast.ComptimeFor {
|
||||||
c.comptime_for(node)
|
c.comptime_for(node)
|
||||||
}
|
}
|
||||||
ast.ConstDecl {
|
ast.ConstDecl {
|
||||||
|
@ -4783,7 +4783,7 @@ fn (mut c Checker) for_c_stmt(node ast.ForCStmt) {
|
||||||
c.in_for_count--
|
c.in_for_count--
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut c Checker) comptime_for(node ast.CompFor) {
|
fn (mut c Checker) comptime_for(node ast.ComptimeFor) {
|
||||||
typ := c.unwrap_generic(node.typ)
|
typ := c.unwrap_generic(node.typ)
|
||||||
sym := c.table.get_type_symbol(typ)
|
sym := c.table.get_type_symbol(typ)
|
||||||
if sym.kind == .placeholder || typ.has_flag(.generic) {
|
if sym.kind == .placeholder || typ.has_flag(.generic) {
|
||||||
|
|
|
@ -430,7 +430,7 @@ pub fn (mut f Fmt) stmt(node ast.Stmt) {
|
||||||
ast.BranchStmt {
|
ast.BranchStmt {
|
||||||
f.branch_stmt(node)
|
f.branch_stmt(node)
|
||||||
}
|
}
|
||||||
ast.CompFor {
|
ast.ComptimeFor {
|
||||||
f.comptime_for(node)
|
f.comptime_for(node)
|
||||||
}
|
}
|
||||||
ast.ConstDecl {
|
ast.ConstDecl {
|
||||||
|
@ -762,7 +762,7 @@ pub fn (mut f Fmt) branch_stmt(node ast.BranchStmt) {
|
||||||
f.writeln(node.str())
|
f.writeln(node.str())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut f Fmt) comptime_for(node ast.CompFor) {
|
pub fn (mut f Fmt) comptime_for(node ast.ComptimeFor) {
|
||||||
typ := f.no_cur_mod(f.table.type_to_str_using_aliases(node.typ, f.mod2alias))
|
typ := f.no_cur_mod(f.table.type_to_str_using_aliases(node.typ, f.mod2alias))
|
||||||
f.write('\$for $node.val_var in ${typ}.$node.kind.str() {')
|
f.write('\$for $node.val_var in ${typ}.$node.kind.str() {')
|
||||||
f.mark_types_import_as_used(node.typ)
|
f.mark_types_import_as_used(node.typ)
|
||||||
|
|
|
@ -1568,7 +1568,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
||||||
g.const_decl(node)
|
g.const_decl(node)
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
ast.CompFor {
|
ast.ComptimeFor {
|
||||||
g.comptime_for(node)
|
g.comptime_for(node)
|
||||||
}
|
}
|
||||||
ast.DeferStmt {
|
ast.DeferStmt {
|
||||||
|
|
|
@ -406,7 +406,7 @@ fn (mut g Gen) comptime_if_cond(cond ast.Expr, pkg_exist bool) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut g Gen) comptime_for(node ast.CompFor) {
|
fn (mut g Gen) comptime_for(node ast.ComptimeFor) {
|
||||||
sym := g.table.get_type_symbol(g.unwrap_generic(node.typ))
|
sym := g.table.get_type_symbol(g.unwrap_generic(node.typ))
|
||||||
g.writeln('/* \$for $node.val_var in ${sym.name}($node.kind.str()) */ {')
|
g.writeln('/* \$for $node.val_var in ${sym.name}($node.kind.str()) */ {')
|
||||||
g.indent++
|
g.indent++
|
||||||
|
|
|
@ -637,7 +637,7 @@ fn (mut g JsGen) stmt_no_semi(node ast.Stmt) {
|
||||||
g.write_v_source_line_info(node.pos)
|
g.write_v_source_line_info(node.pos)
|
||||||
g.gen_branch_stmt(node)
|
g.gen_branch_stmt(node)
|
||||||
}
|
}
|
||||||
ast.CompFor {}
|
ast.ComptimeFor {}
|
||||||
ast.ConstDecl {
|
ast.ConstDecl {
|
||||||
g.write_v_source_line_info(node.pos)
|
g.write_v_source_line_info(node.pos)
|
||||||
g.gen_const_decl(node)
|
g.gen_const_decl(node)
|
||||||
|
@ -740,7 +740,7 @@ fn (mut g JsGen) stmt(node ast.Stmt) {
|
||||||
g.write_v_source_line_info(node.pos)
|
g.write_v_source_line_info(node.pos)
|
||||||
g.gen_branch_stmt(node)
|
g.gen_branch_stmt(node)
|
||||||
}
|
}
|
||||||
ast.CompFor {}
|
ast.ComptimeFor {}
|
||||||
ast.ConstDecl {
|
ast.ConstDecl {
|
||||||
g.write_v_source_line_info(node.pos)
|
g.write_v_source_line_info(node.pos)
|
||||||
g.gen_const_decl(node)
|
g.gen_const_decl(node)
|
||||||
|
|
|
@ -92,7 +92,7 @@ pub fn (mut w Walker) stmt(node ast.Stmt) {
|
||||||
ast.Block {
|
ast.Block {
|
||||||
w.stmts(node.stmts)
|
w.stmts(node.stmts)
|
||||||
}
|
}
|
||||||
ast.CompFor {
|
ast.ComptimeFor {
|
||||||
w.stmts(node.stmts)
|
w.stmts(node.stmts)
|
||||||
}
|
}
|
||||||
ast.ConstDecl {
|
ast.ConstDecl {
|
||||||
|
|
|
@ -232,7 +232,7 @@ fn (mut p Parser) comptime_call() ast.ComptimeCall {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut p Parser) comptime_for() ast.CompFor {
|
fn (mut p Parser) comptime_for() ast.ComptimeFor {
|
||||||
// p.comptime_for() handles these special forms:
|
// p.comptime_for() handles these special forms:
|
||||||
// $for method in App(methods) {
|
// $for method in App(methods) {
|
||||||
// $for field in App(fields) {
|
// $for field in App(fields) {
|
||||||
|
@ -247,7 +247,7 @@ fn (mut p Parser) comptime_for() ast.CompFor {
|
||||||
typ_pos = typ_pos.extend(p.prev_tok.position())
|
typ_pos = typ_pos.extend(p.prev_tok.position())
|
||||||
p.check(.dot)
|
p.check(.dot)
|
||||||
for_val := p.check_name()
|
for_val := p.check_name()
|
||||||
mut kind := ast.CompForKind.methods
|
mut kind := ast.ComptimeForKind.methods
|
||||||
p.open_scope()
|
p.open_scope()
|
||||||
if for_val == 'methods' {
|
if for_val == 'methods' {
|
||||||
p.scope.register(ast.Var{
|
p.scope.register(ast.Var{
|
||||||
|
@ -272,12 +272,12 @@ fn (mut p Parser) comptime_for() ast.CompFor {
|
||||||
} else {
|
} else {
|
||||||
p.error_with_pos('unknown kind `$for_val`, available are: `methods`, `fields` or `attributes`',
|
p.error_with_pos('unknown kind `$for_val`, available are: `methods`, `fields` or `attributes`',
|
||||||
p.prev_tok.position())
|
p.prev_tok.position())
|
||||||
return ast.CompFor{}
|
return ast.ComptimeFor{}
|
||||||
}
|
}
|
||||||
spos := p.tok.position()
|
spos := p.tok.position()
|
||||||
stmts := p.parse_block()
|
stmts := p.parse_block()
|
||||||
p.close_scope()
|
p.close_scope()
|
||||||
return ast.CompFor{
|
return ast.ComptimeFor{
|
||||||
val_var: val_var
|
val_var: val_var
|
||||||
stmts: stmts
|
stmts: stmts
|
||||||
kind: kind
|
kind: kind
|
||||||
|
|
|
@ -43,7 +43,7 @@ pub fn (t Transformer) stmt(mut node ast.Stmt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast.BranchStmt {}
|
ast.BranchStmt {}
|
||||||
ast.CompFor {}
|
ast.ComptimeFor {}
|
||||||
ast.ConstDecl {
|
ast.ConstDecl {
|
||||||
for mut field in node.fields {
|
for mut field in node.fields {
|
||||||
expr := t.expr(field.expr)
|
expr := t.expr(field.expr)
|
||||||
|
|
Loading…
Reference in New Issue