cgen: #else

pull/4103/head
Alexander Medvednikov 2020-03-22 14:54:31 +01:00
parent 2738a0c776
commit ce73ced932
3 changed files with 10 additions and 4 deletions

View File

@ -391,6 +391,7 @@ pub:
stmts []Stmt
pos token.Position
mut:
has_else bool
else_stmts []Stmt
}

View File

@ -270,10 +270,12 @@ fn (g mut Gen) stmt(node ast.Stmt) {
ast.CompIf {
g.writeln('\n#ifdef ' + comp_if_to_ifdef(it.val))
g.writeln('// #if $it.val')
// g.expr(it.cond)
// println('comp if stmts $g.file.path:$it.pos.line_nr')
g.stmts(it.stmts)
// println('done')
if it.has_else {
g.writeln('#else')
g.stmts(it.else_stmts)
}
g.writeln('#endif')
}
ast.DeferStmt {
@ -1728,8 +1730,7 @@ fn (g mut Gen) write_types(types []table.TypeSymbol) {
g.definitions.writeln('};\n')
}
// table.Alias, table.SumType { TODO
table.Alias {
}
table.Alias {}
table.Enum {
g.definitions.writeln('typedef enum {')
for j, val in it.vals {
@ -2021,6 +2022,9 @@ fn comp_if_to_ifdef(name string) string {
'linux_or_macos' {
return ''
}
'mingw' {
return '__MINGW32__'
}
'no_bounds_checking' {
return 'NO_BOUNDS_CHECK'
}

View File

@ -23,6 +23,7 @@ pub fn (p mut Parser) comp_if() ast.CompIf {
if p.tok.kind == .dollar && p.peek_tok.kind == .key_else {
p.next()
p.check(.key_else)
node.has_else = true
node.else_stmts = p.parse_block()
}
return node