Skip to content

Commit

Permalink
Fix enum params in function calls and test runner warning
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Marklund <[email protected]>
  • Loading branch information
trollkarlen authored May 3, 2023
1 parent c589a9a commit 811a8b7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/c2v.v
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,15 @@ fn convert_type(typ_ string) Type {
name: '[' + typ.substr('void *['.len, typ.len - 1) + ']voidptr'
}
}

// enum
if typ.starts_with('enum ') {
return Type{
name: typ.substr('enum '.len, typ.len).capitalize()
is_const: is_const
}
}

// int[3]
mut idx := ''
if typ.contains('[') && typ.contains(']') {
Expand Down
10 changes: 9 additions & 1 deletion tests/11.enum_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ typedef enum myStrangeEnum {

enum { J = 1 };

void enum_func(enum myEnum a) {
}

void enum_func_const(const enum myEnum a) {
}

int main() {
enum myEnum myEnumVar = A;
myAnotherEnum myEnumVar2 = D;
myStrangeEnum myEnumVar3 = G;
int myIntVar = J;
enum_func(myEnumVar);
enum_func_const(myEnumVar);
return 0;
}
}
8 changes: 8 additions & 0 deletions tests/11.enum_default.out
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ const ( // empty enum
j = 1
)

fn enum_func(a MyEnum) {
}

fn enum_func_const(a MyEnum) {
}

fn main() {
myenumvar := MyEnum.a
myenumvar2 := MyAnotherEnum.d
myenumvar3 := MyStrangeEnum.g
myintvar := j
enum_func(myenumvar)
enum_func_const(myenumvar)
return
}
2 changes: 1 addition & 1 deletion tests/run_tests.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn execute_c2v_command(options string, file string, c2v_dir string) {
system('${c2v_dir}/c2v ' + options + ' ${file} > /dev/null')
}

fn try_get_generated_file(file string, test_file_extension string) ?string {
fn try_get_generated_file(file string, test_file_extension string) !string {
generated_file := file.replace(test_file_extension, '.v')

if !exists(generated_file) {
Expand Down

0 comments on commit 811a8b7

Please sign in to comment.