remove #ifdef, #ifndef, etc

pull/764/head
Alexander Medvednikov 2019-06-28 17:07:03 +02:00
parent 0026b228c3
commit 56608dfd2b
2 changed files with 6 additions and 33 deletions

View File

@ -62,6 +62,8 @@ pub fn malloc(n int) byteptr {
if n < 0 {
panic('malloc(<0)')
}
/*
TODO
#ifdef VPLAY
if n > 10000 {
panic('allocating more than 10 KB is not allowed in the playground')
@ -72,6 +74,7 @@ pub fn malloc(n int) byteptr {
println('\n\n\nmalloc($n) total=$total_m')
print_backtrace()
#endif
*/
ptr := C.malloc(n)
if isnil(ptr) {
panic('malloc($n) failed')

View File

@ -2627,48 +2627,18 @@ fn (p mut Parser) chash() {
p.genln('#include $file')
}
}
else if is_c_pre(hash) {
// Skip not current OS hack
if hash.starts_with('ifdef') {
os := hash.right(6).trim_space()
// println('ifdef "$os" $p.scanner.line_nr')
if os == 'linux' && p.os != LINUX {
// println('linux ifdef skip')
for p.tok != EOF {
if p.tok == HASH && p.lit.contains('else') || p.lit.contains('endif') {
break
}
// println('skipping')
p.next()
}
}
}
// Move defines on top (like old gdefine)
if hash.contains('define') {
p.cgen.includes << '#$hash'
}
else {
p.genln('#$hash')
}
else if hash.contains('define') {
// Move defines on top
p.cgen.includes << '#$hash'
}
else {
if !p.can_chash {
p.error('bad token `#` (embedding C code is no longer supported)')
}
//println('HASH!!! $p.file_name $p.scanner.line_nr')
if p.cur_fn.name == '' {
// p.error('# outside of fn')
}
p.genln(hash)
}
}
fn is_c_pre(hash string) bool {
return hash.contains('ifdef') || hash.contains('define') ||
hash.contains('endif') || hash.contains('elif') ||
hash.contains('ifndef') || (hash.contains('else') && !hash.contains('{'))
}
fn (p mut Parser) if_st(is_expr bool) string {
if is_expr {
if p.fileis('if_expr') {