Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
*.v linguist-language=V text=auto eol=lf
*.vv linguist-language=V text=auto eol=lf
*.vsh linguist-language=V text=auto eol=lf
**/v.mod linguist-language=V text=auto eol=lf
* text=auto eol=lf

*.bat text eol=crlf
*.cmd text eol=crlf
*.ps1 text eol=crlf

*.v linguist-language=V
*.vv linguist-language=V
*.vsh linguist-language=V
**/v.mod linguist-language=V

8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout V
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
repository: vlang/v
- name: Checkout C2V
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
path: c2v
- name: Install dependencies
Expand Down Expand Up @@ -72,11 +72,11 @@ jobs:
VTMP: /tmp
steps:
- name: Checkout V
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
repository: vlang/v
- name: Checkout C2V
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
path: c2v
- name: Install dependencies
Expand Down
40 changes: 23 additions & 17 deletions src/c2v.v → c2v.v
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const tabs = ['', '\t', '\t\t', '\t\t\t', '\t\t\t\t', '\t\t\t\t\t', '\t\t\t\t\t\
'\t\t\t\t\t\t\t\t', '\t\t\t\t\t\t\t\t\t', '\t\t\t\t\t\t\t\t\t\t', '\t\t\t\t\t\t\t\t\t\t\t',
'\t\t\t\t\t\t\t\t\t\t\t\t', '\t\t\t\t\t\t\t\t\t\t\t\t\t']

const cur_dir = os.getwd()
// const cur_dir = os.getwd()

const clang_exe = find_clang_in_path()

Expand All @@ -79,7 +79,8 @@ fn get_builtin_header_folders(clang_path string) []string {
''
}
program_paths := programs_line.all_after(': =').split(os.path_delimiter)
based_program_paths := program_paths.map(it.all_before_last('/usr/bin')).map(it.all_before_last('/bin'))
based_program_paths :=
program_paths.map(it.all_before_last('/usr/bin')).map(it.all_before_last('/bin'))
for p in based_program_paths {
folders[p] = true
}
Expand Down Expand Up @@ -1116,6 +1117,7 @@ fn convert_type(typ_ string) Type {
capitalized
}
}

mut amps := ''

if typ.ends_with('*') {
Expand Down Expand Up @@ -1196,7 +1198,8 @@ fn (mut c C2V) enum_decl(mut node Node) {
if c_enum_name in c.enums {
return
}
v_enum_name = c.add_struct_name(mut c.enums, c_enum_name) //.capitalize().replace('Enum ', '')
v_enum_name =
c.add_struct_name(mut c.enums, c_enum_name) //.capitalize().replace('Enum ', '')
c.gen_comment(node)
c.genln('enum ${v_enum_name} {')
}
Expand Down Expand Up @@ -2763,6 +2766,7 @@ fn (mut c C2V) expr(_node &Node) string {
'__file__' { '@FILE' }
else { '' }
}

if v_predefined != '' {
c.gen(v_predefined)
} else {
Expand Down Expand Up @@ -2895,7 +2899,8 @@ fn (mut c C2V) init_list_expr(mut node Node) {
for i, mut child in node.inner {
c.gen_comment(child)
if child.kind == .bad {
child.kind = convert_str_into_node_kind(child.kind_str) // array_filler nodes were not handled by set_kind_enum
child.kind =
convert_str_into_node_kind(child.kind_str) // array_filler nodes were not handled by set_kind_enum
}

// C allows not to set final fields (a = {1,2,,,,})
Expand Down Expand Up @@ -3160,6 +3165,7 @@ fn (mut c2v C2V) parse_comment(mut root_node Node, path string) {
}
}
}

offset++
}

Expand Down Expand Up @@ -3192,7 +3198,7 @@ fn (mut c2v C2V) translate_file(path string) {
vprintln('DA CMD')
vprintln(cmd)
out_ast := if c2v.is_dir {
os.getwd() + '/' + (os.dir(os.dir(path)) + '/${c2v.project_output_dirname}/' +
os.getwd() + '/' +(os.dir(os.dir(path)) + '/${c2v.project_output_dirname}/' +
os.base(path).replace(ext, '.json'))
} else {
// file.c => file.json
Expand Down Expand Up @@ -3457,18 +3463,18 @@ fn trim_underscores(s string) string {
return s[i..]
}

fn capitalize_type(s string) string {
mut name := s
if name.starts_with('_') {
// Trim "_" from the start of the struct name
// TODO this can result in conflicts
name = trim_underscores(name)
}
if !name.starts_with('fn ') {
name = name.capitalize()
}
return name
}
// fn capitalize_type(s string) string {
// mut name := s
// if name.starts_with('_') {
// // Trim "_" from the start of the struct name
// // TODO this can result in conflicts
// name = trim_underscores(name)
// }
// if !name.starts_with('fn ') {
// name = name.capitalize()
// }
// return name
//}

fn (c &C2V) verror(msg string) {
$if linux {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion command_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn testsuite_begin() {
}

fn test_verify_formatting_of_source_code() {
res := os.system('${os.quoted_path(@VEXE)} fmt -verify src/')
res := os.system('${os.quoted_path(@VEXE)} fmt -verify .')
assert res == 0
println('> source code is formatted, good')
}
Expand Down
15 changes: 9 additions & 6 deletions src/configuration.v → configuration.v
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn (mut c2v C2V) handle_configuration(args []string) {
c2v.set_config_overrides_for_project()
}

fn (mut c2v C2V) get_additional_flags(path string) string {
fn (mut c2v C2V) get_additional_flags(_ string) string {
return '${c2v.project_additional_flags} ${c2v.file_additional_flags} '
}

Expand All @@ -47,22 +47,25 @@ fn (mut c2v C2V) read_toml_configuration(toml_file string) {
// called once per invocation
fn (mut c2v C2V) set_config_overrides_for_project() {
c2v.project_uses_sdl = c2v.conf.value('project.uses_sdl').default_to(false).bool()
c2v.project_output_dirname = c2v.conf.value('project.output_dirname').default_to('c2v_output').string()
c2v.project_additional_flags = c2v.conf.value('project.additional_flags').default_to('-I.').string()
c2v.project_output_dirname =
c2v.conf.value('project.output_dirname').default_to('c2v_output').string()
c2v.project_additional_flags =
c2v.conf.value('project.additional_flags').default_to('-I.').string()
c2v.wrapper_module_name = c2v.conf.value('project.wrapper_module_name').default_to('').string()
c2v.keep_ast = c2v.conf.value('keep_ast').default_to(false).bool()
if c2v.project_uses_sdl {
sdl_cflags := get_sdl_cflags()
c2v.project_additional_flags += ' ' + sdl_cflags
}
c2v.project_globals_path = os.real_path(os.join_path(c2v.project_folder, c2v.project_output_dirname,
'_globals.v'))
c2v.project_globals_path = os.real_path(os.join_path(c2v.project_folder,
c2v.project_output_dirname, '_globals.v'))
}

// called once per each .c file
fn (mut c2v C2V) set_config_overrides_for_file(path string) {
fname := os.file_name(path)
c2v.file_additional_flags = c2v.conf.value("'${fname}'.additional_flags").default_to('').string()
c2v.file_additional_flags =
c2v.conf.value("'${fname}'.additional_flags").default_to('').string()
}

fn get_sdl_cflags() string {
Expand Down
3 changes: 2 additions & 1 deletion src/cpp.v → cpp.v
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ fn (mut c C2V) cpp_expr(_node &Node) bool {
c.gen('${method}(')
}
}

mut mat_tmp_expr := node.try_get_next_child() or {
println(err)
bad_node
Expand Down Expand Up @@ -258,7 +259,7 @@ fn (mut c C2V) constructor_decl(_node &Node) {
}

// CBattleAnimation::~CBattleAnimation()
fn (mut c C2V) destructor_decl(node &Node) {
fn (mut c C2V) destructor_decl(_ &Node) {
}

fn (mut c C2V) cxx_method_decl(_node &Node) {
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions src/struct.v → struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ fn (mut c C2V) record_decl(node &Node) {
if field_type.name.contains('unnamed enum at') {
// Generate a named enum for this anonymous enum
field_name := filter_name(field.name, false)
enum_name := c.generate_named_enum_for_anon(pending_enum, struct_v_name,
field_name)
enum_name := c.generate_named_enum_for_anon(pending_enum, struct_v_name, field_name)
anon_enum_names[i] = enum_name
}
pending_enum = unsafe { nil }
Expand Down
1 change: 1 addition & 0 deletions tests/13.switch.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fn main() {
C.printf(c'foo\n')
}
}

match a {
0 { // case comp body kind=CallExpr is_enum=true
C.printf(c'bar\n')
Expand Down
2 changes: 2 additions & 0 deletions tests/14.default.out
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ fn f() {
0, 1 {}
else {}
}

match a {
0 { // case comp body kind=BreakStmt is_enum=true
}
else {}
}

match a {
0 { // case comp body kind=BreakStmt is_enum=true
}
Expand Down
5 changes: 2 additions & 3 deletions tests/27.if_else_single_line_stmt.out
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ fn main() {
} else {
for {
// while()
if !(0) {
break
}
if !(0) { break
}
}
}
// else for
Expand Down
5 changes: 4 additions & 1 deletion tests/3.if_switch_enum.out
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fn main() {
}
else {}
}

n := Number.one
match n {
// case one: printf("one!"); int x = one + 1; break;
Expand All @@ -58,6 +59,7 @@ fn main() {
}
else {}
}

// handle enum <=> int in C: enum switch needs explicit casts to ints
m := 0
match Number(m) {
Expand All @@ -69,5 +71,6 @@ fn main() {
}
else {}
}

return
}
}
26 changes: 0 additions & 26 deletions tests/31.anon_enum_in_struct.out

This file was deleted.

5 changes: 2 additions & 3 deletions tests/ptr_deref.out
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ fn test_ptr_ops(endptr &&u8, value &int) {
dest3 += 320
frac += fracstep
// while()
if !(count--) {
break
}
if !(count--) { break
}
}
// check chained dereferencing:
the_thing := Mobj_t{}
Expand Down
5 changes: 3 additions & 2 deletions tests/run_tests.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ fn start_testing_process(filter string) {
}

fn run_tests(test_file_extension string, c2v_opts string, filter string) bool {
mut files := get_test_files(test_file_extension).filter(it.all_after_last('/').starts_with('IGNORE_') == false)
mut files :=
get_test_files(test_file_extension).filter(it.all_after_last('/').starts_with('IGNORE_') == false)

files.sort()

Expand Down Expand Up @@ -175,7 +176,7 @@ fn get_expected_file_content(file string, test_file_extension string) string {
return file_content.trim_space()
}

fn get_result_file_content(file string, test_file_extension string) string {
fn get_result_file_content(file string, _ string) string {
file_content := read_file(file) or { '' }
return file_content.after('// vstart').trim_space()
}
Expand Down
File renamed without changes.
Loading