ast: change CompFor to ComptimeFor (#12482)

pull/12489/head
yuyi 2021-11-17 14:29:43 +08:00 committed by GitHub
parent 927df948ae
commit 5a89c0a480
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 23 additions and 23 deletions

View File

@ -405,7 +405,7 @@ fn (t Tree) stmt(node ast.Stmt) &Node {
ast.EnumDecl { return t.enum_decl(node) }
ast.InterfaceDecl { return t.interface_decl(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.DeferStmt { return t.defer_stmt(node) }
ast.TypeDecl { return t.type_decl(node) }
@ -700,9 +700,9 @@ fn (t Tree) hash_stmt(node ast.HashStmt) &Node {
return obj
}
fn (t Tree) comptime_for(node ast.CompFor) &Node {
fn (t Tree) comptime_for(node ast.ComptimeFor) &Node {
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('typ', t.type_node(node.typ))
obj.add('kind', t.enum_node(node.kind))

View File

@ -65,7 +65,7 @@ pub type Stmt = AsmStmt
| AssignStmt
| Block
| BranchStmt
| CompFor
| ComptimeFor
| ConstDecl
| DeferStmt
| EmptyStmt
@ -898,17 +898,17 @@ pub:
post_comments []Comment
}
pub enum CompForKind {
pub enum ComptimeForKind {
methods
fields
attributes
}
pub struct CompFor {
pub struct ComptimeFor {
pub:
val_var string
stmts []Stmt
kind CompForKind
kind ComptimeForKind
pos token.Position
typ_pos token.Position
pub mut:
@ -1904,7 +1904,7 @@ pub fn (node Node) children() []Node {
}
} else if node is Stmt {
match node {
Block, DeferStmt, ForCStmt, ForInStmt, ForStmt, CompFor {
Block, DeferStmt, ForCStmt, ForInStmt, ForStmt, ComptimeFor {
return node.stmts.map(Node(it))
}
ExprStmt, AssertStmt {

View File

@ -580,7 +580,7 @@ fn field_to_string(f ConstField) string {
return '$x = $f.expr'
}
pub fn (e CompForKind) str() string {
pub fn (e ComptimeForKind) str() string {
match e {
.methods { return 'methods' }
.fields { return 'fields' }

View File

@ -4606,7 +4606,7 @@ fn (mut c Checker) stmt(node ast.Stmt) {
ast.BranchStmt {
c.branch_stmt(node)
}
ast.CompFor {
ast.ComptimeFor {
c.comptime_for(node)
}
ast.ConstDecl {
@ -4783,7 +4783,7 @@ fn (mut c Checker) for_c_stmt(node ast.ForCStmt) {
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)
sym := c.table.get_type_symbol(typ)
if sym.kind == .placeholder || typ.has_flag(.generic) {

View File

@ -430,7 +430,7 @@ pub fn (mut f Fmt) stmt(node ast.Stmt) {
ast.BranchStmt {
f.branch_stmt(node)
}
ast.CompFor {
ast.ComptimeFor {
f.comptime_for(node)
}
ast.ConstDecl {
@ -762,7 +762,7 @@ pub fn (mut f Fmt) branch_stmt(node ast.BranchStmt) {
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))
f.write('\$for $node.val_var in ${typ}.$node.kind.str() {')
f.mark_types_import_as_used(node.typ)

View File

@ -1568,7 +1568,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
g.const_decl(node)
// }
}
ast.CompFor {
ast.ComptimeFor {
g.comptime_for(node)
}
ast.DeferStmt {

View File

@ -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))
g.writeln('/* \$for $node.val_var in ${sym.name}($node.kind.str()) */ {')
g.indent++

View File

@ -637,7 +637,7 @@ fn (mut g JsGen) stmt_no_semi(node ast.Stmt) {
g.write_v_source_line_info(node.pos)
g.gen_branch_stmt(node)
}
ast.CompFor {}
ast.ComptimeFor {}
ast.ConstDecl {
g.write_v_source_line_info(node.pos)
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.gen_branch_stmt(node)
}
ast.CompFor {}
ast.ComptimeFor {}
ast.ConstDecl {
g.write_v_source_line_info(node.pos)
g.gen_const_decl(node)

View File

@ -92,7 +92,7 @@ pub fn (mut w Walker) stmt(node ast.Stmt) {
ast.Block {
w.stmts(node.stmts)
}
ast.CompFor {
ast.ComptimeFor {
w.stmts(node.stmts)
}
ast.ConstDecl {

View File

@ -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:
// $for method in App(methods) {
// $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())
p.check(.dot)
for_val := p.check_name()
mut kind := ast.CompForKind.methods
mut kind := ast.ComptimeForKind.methods
p.open_scope()
if for_val == 'methods' {
p.scope.register(ast.Var{
@ -272,12 +272,12 @@ fn (mut p Parser) comptime_for() ast.CompFor {
} else {
p.error_with_pos('unknown kind `$for_val`, available are: `methods`, `fields` or `attributes`',
p.prev_tok.position())
return ast.CompFor{}
return ast.ComptimeFor{}
}
spos := p.tok.position()
stmts := p.parse_block()
p.close_scope()
return ast.CompFor{
return ast.ComptimeFor{
val_var: val_var
stmts: stmts
kind: kind

View File

@ -43,7 +43,7 @@ pub fn (t Transformer) stmt(mut node ast.Stmt) {
}
}
ast.BranchStmt {}
ast.CompFor {}
ast.ComptimeFor {}
ast.ConstDecl {
for mut field in node.fields {
expr := t.expr(field.expr)