diff --git a/src/c2v.v b/src/c2v.v index 54c0e0a..d5ba1ad 100644 --- a/src/c2v.v +++ b/src/c2v.v @@ -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(']') { diff --git a/tests/11.enum_default.c b/tests/11.enum_default.c index 934758a..795830c 100644 --- a/tests/11.enum_default.c +++ b/tests/11.enum_default.c @@ -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; -} \ No newline at end of file +} diff --git a/tests/11.enum_default.out b/tests/11.enum_default.out index d2fe7d5..56a4276 100644 --- a/tests/11.enum_default.out +++ b/tests/11.enum_default.out @@ -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 } diff --git a/tests/run_tests.vsh b/tests/run_tests.vsh index 37a2098..7e62b05 100644 --- a/tests/run_tests.vsh +++ b/tests/run_tests.vsh @@ -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) {