diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 1c57e604f7..6189187216 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -388,6 +388,7 @@ pub struct CompIf { pub: cond Expr stmts []Stmt + pos token.Position mut: else_stmts []Stmt } diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 241a5c670e..e9131187f0 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -259,10 +259,11 @@ fn (g mut Gen) stmt(node ast.Stmt) { g.const_decl(it) } ast.CompIf { - // TODO g.writeln('//#ifdef ') // g.expr(it.cond) + // println('comp if stmts $g.file.path:$it.pos.line_nr') // g.stmts(it.stmts) + // println('done') g.writeln('//#endif') } ast.DeferStmt { diff --git a/vlib/v/parser/comptime.v b/vlib/v/parser/comptime.v index 517fe3d569..5b1ed3c71e 100644 --- a/vlib/v/parser/comptime.v +++ b/vlib/v/parser/comptime.v @@ -5,6 +5,7 @@ import ( ) pub fn (p mut Parser) comp_if() ast.CompIf { + pos := p.tok.position() p.next() p.check(.key_if) if p.tok.kind == .not { @@ -16,6 +17,7 @@ pub fn (p mut Parser) comp_if() ast.CompIf { } mut node := ast.CompIf{ stmts: p.parse_block() + pos: pos } if p.tok.kind == .dollar && p.peek_tok.kind == .key_else { p.next()