Skip to content

Commit

Permalink
cgen: fix #preinclude, add test case for #postinclude too
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Feb 11, 2025
1 parent d82757a commit 305c56d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions vlib/v/gen/c/testdata/postinclude_example.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hi from V, p: 42
10 changes: 10 additions & 0 deletions vlib/v/gen/c/testdata/postinclude_example.vv
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions vlib/v/gen/c/testdata/postinclude_header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <assert.h>

int main( void ) {
int res = no_main__f(42);
assert(res == 987);
return 0;
}

0 comments on commit 305c56d

Please sign in to comment.