upgrade enum discriminants
This commit is contained in:
@@ -11951,6 +11951,107 @@ translate_c_emits_native_bindings_and_round_trips :: proc(t: ^testing.T) {
|
||||
testing.expect_value(t, len(diagnostics.items), 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
translate_c_package_deduplicates_compatible_declarations :: proc(t: ^testing.T) {
|
||||
first := cimport.init_result(context.allocator)
|
||||
second := cimport.init_result(context.allocator)
|
||||
defer {
|
||||
delete(first.types)
|
||||
delete(first.records[0].fields)
|
||||
delete(first.records)
|
||||
delete(first.functions)
|
||||
delete(first.macros)
|
||||
delete(second.types)
|
||||
delete(second.records[0].fields)
|
||||
delete(second.records)
|
||||
delete(second.functions)
|
||||
delete(second.macros)
|
||||
}
|
||||
|
||||
append(&first.types, cimport.Type{kind=.C_Int, child=cimport.INVALID_TYPE})
|
||||
append(&first.types, cimport.Type{kind=.Record, record=0, child=cimport.INVALID_TYPE})
|
||||
append(&first.types, cimport.Type{kind=.Pointer, child=1, mutable=true})
|
||||
append(&second.types, ..first.types[:])
|
||||
first_fields: [dynamic]cimport.Field
|
||||
second_fields: [dynamic]cimport.Field
|
||||
append(&first_fields, cimport.Field{name="value", type=0})
|
||||
append(&second_fields, cimport.Field{name="value", type=0})
|
||||
append(&first.records, cimport.Record{
|
||||
identity="shared-anonymous-record",
|
||||
kind=.Struct,
|
||||
complete=true,
|
||||
fields=first_fields,
|
||||
})
|
||||
append(&second.records, cimport.Record{
|
||||
identity="shared-anonymous-record",
|
||||
kind=.Struct,
|
||||
complete=true,
|
||||
fields=second_fields,
|
||||
})
|
||||
first_params := [?]cimport.Type_Id{0}
|
||||
second_params := [?]cimport.Type_Id{0}
|
||||
use_record_params := [?]cimport.Type_Id{2}
|
||||
first_names := [?]string{"left"}
|
||||
second_names := [?]string{"right"}
|
||||
append(&first.functions, cimport.Function{
|
||||
name="shared",
|
||||
params=first_params[:],
|
||||
param_names=first_names[:],
|
||||
result=0,
|
||||
})
|
||||
append(&second.functions, cimport.Function{
|
||||
name="shared",
|
||||
params=second_params[:],
|
||||
param_names=second_names[:],
|
||||
result=0,
|
||||
})
|
||||
append(&second.functions, cimport.Function{
|
||||
name="use_record",
|
||||
params=use_record_params[:],
|
||||
result=0,
|
||||
})
|
||||
append(&first.macros, cimport.Macro_Constant{
|
||||
name="SHARED_VALUE",
|
||||
type=0,
|
||||
value={kind=.Integer, type=0, integer=7},
|
||||
})
|
||||
append(&second.macros, first.macros[0])
|
||||
|
||||
inputs := [?]translatec.Package_Input{
|
||||
{result=&first, header="first.h", name="first.bro"},
|
||||
{result=&second, header="second.h", name="second.bro"},
|
||||
}
|
||||
outputs, generation_error := translatec.emit_package(inputs[:])
|
||||
defer translatec.destroy_package_outputs(outputs)
|
||||
defer delete(generation_error)
|
||||
testing.expect_value(t, generation_error, "")
|
||||
testing.expect_value(t, len(outputs), 2)
|
||||
if len(outputs) == 2 {
|
||||
combined := fmt.tprintf("%s%s", outputs[0].source, outputs[1].source)
|
||||
testing.expect_value(t, count_substring_occurrences(combined, "shared c_func("), 1)
|
||||
testing.expect_value(t, count_substring_occurrences(combined, "SHARED_VALUE c_int :: 7"), 1)
|
||||
testing.expect(t, strings.contains(outputs[0].source, "__c_first_bro_record_0 :: c_struct"))
|
||||
testing.expect(t, strings.contains(outputs[1].source, "use_record c_func(_ ?*mut __c_first_bro_record_0) c_int"))
|
||||
}
|
||||
|
||||
second.macros[0].value.integer = 8
|
||||
conflicting, conflict_error := translatec.emit_package(inputs[:])
|
||||
defer translatec.destroy_package_outputs(conflicting)
|
||||
defer delete(conflict_error)
|
||||
testing.expect_value(t, len(conflicting), 0)
|
||||
testing.expect(t, strings.contains(conflict_error, "conflicting generated C declaration 'SHARED_VALUE'"))
|
||||
}
|
||||
|
||||
@(test)
|
||||
translate_c_package_cli_requires_unambiguous_outputs :: proc(t: ^testing.T) {
|
||||
testing.expect_value(t, run_translate_c([]string{
|
||||
"brolang", "--translate-c", "first.h", "second.h",
|
||||
}), 2)
|
||||
testing.expect_value(t, run_translate_c([]string{
|
||||
"brolang", "--translate-c", "a/same.h", "b/same.h", "--output-dir", "/tmp/unused",
|
||||
}), 2)
|
||||
}
|
||||
|
||||
@(test)
|
||||
sink_named_parameters_are_allowed_and_not_duplicates :: proc(t: ^testing.T) {
|
||||
// Generated bindings use `_` for unnamed C params; the parser must accept it and
|
||||
|
||||
Reference in New Issue
Block a user