cgen: fix #preinclude, add test case for #postinclude too

This commit is contained in:
Delyan Angelov 2025-02-12 01:45:00 +02:00
parent d82757abd9
commit 305c56dbf7
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
4 changed files with 19 additions and 0 deletions

View File

@ -570,6 +570,7 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO
}
b.write_string2('\n// V comptime_definitions:\n', g.comptime_definitions.str())
b.write_string2('\n// V typedefs:\n', g.typedefs.str())
b.write_string2('\n // V preincludes:\n', g.preincludes.str())
b.write_string2('\n// V cheaders:', g.cheaders.str())
if g.pcs_declarations.len > 0 {
b.write_string2('\n// V profile counters:\n', g.pcs_declarations.str())

View File

@ -0,0 +1 @@
Hi from V, p: 42

View File

@ -0,0 +1,10 @@
module no_main
#postinclude "@VEXEROOT/vlib/v/gen/c/testdata/postinclude_header.h"
@[markused]
pub fn f(p int) int {
assert p == 42
C.printf(c'Hi from V, p: %d\n', p)
return 987
}

View File

@ -0,0 +1,7 @@
#include <assert.h>
int main( void ) {
int res = no_main__f(42);
assert(res == 987);
return 0;
}