ast: CompIf position

pull/4101/head
Alexander Medvednikov 2020-03-22 11:53:08 +01:00
parent ab3f6d9202
commit 7b689d8c52
3 changed files with 5 additions and 1 deletions

View File

@ -388,6 +388,7 @@ pub struct CompIf {
pub: pub:
cond Expr cond Expr
stmts []Stmt stmts []Stmt
pos token.Position
mut: mut:
else_stmts []Stmt else_stmts []Stmt
} }

View File

@ -259,10 +259,11 @@ fn (g mut Gen) stmt(node ast.Stmt) {
g.const_decl(it) g.const_decl(it)
} }
ast.CompIf { ast.CompIf {
// TODO
g.writeln('//#ifdef ') g.writeln('//#ifdef ')
// g.expr(it.cond) // g.expr(it.cond)
// println('comp if stmts $g.file.path:$it.pos.line_nr')
// g.stmts(it.stmts) // g.stmts(it.stmts)
// println('done')
g.writeln('//#endif') g.writeln('//#endif')
} }
ast.DeferStmt { ast.DeferStmt {

View File

@ -5,6 +5,7 @@ import (
) )
pub fn (p mut Parser) comp_if() ast.CompIf { pub fn (p mut Parser) comp_if() ast.CompIf {
pos := p.tok.position()
p.next() p.next()
p.check(.key_if) p.check(.key_if)
if p.tok.kind == .not { if p.tok.kind == .not {
@ -16,6 +17,7 @@ pub fn (p mut Parser) comp_if() ast.CompIf {
} }
mut node := ast.CompIf{ mut node := ast.CompIf{
stmts: p.parse_block() stmts: p.parse_block()
pos: pos
} }
if p.tok.kind == .dollar && p.peek_tok.kind == .key_else { if p.tok.kind == .dollar && p.peek_tok.kind == .key_else {
p.next() p.next()