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
17 changes: 17 additions & 0 deletions compiler/back_end/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,17 @@ emboss_cc_test(
],
)

emboss_cc_test(
name = "many_conditionals_benchmark",
srcs = [
"testcode/many_conditionals_benchmark.cc",
],
deps = [
"//testdata:many_conditionals_emboss",
"@com_google_googletest//:gtest_main",
],
)

# New golden test infrastructure
py_library(
name = "one_golden_test_lib",
Expand Down Expand Up @@ -598,3 +609,9 @@ cpp_golden_test(
emb_file = "//testdata:imported_genfiles.emb",
golden_file = "//testdata/golden_cpp:imported_genfiles.emb.h",
)

cpp_golden_test(
name = "many_conditionals_golden_test",
emb_file = "//testdata:many_conditionals.emb",
golden_file = "//testdata/golden_cpp:many_conditionals.emb.h",
)
25 changes: 23 additions & 2 deletions compiler/back_end/cpp/generated_code_templates
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class Generic${name}View final {
bool Ok() const {
if (!IsComplete()) return false;
${parameter_ok_checks}
${ok_subexpressions}
${field_ok_checks}
${requires_check}
return true;
Expand Down Expand Up @@ -391,11 +392,31 @@ ${write_fields}
// ** ok_method_test ** ////////////////////////////////////////////////////////
// If we don't have enough information to determine whether ${field} is
// present in the structure, then structure.Ok() should be false.
if (!has_${field}.Known()) return false;
if (!has_${field}().Known()) return false;
// If ${field} is present, but not Ok(), then structure.Ok() should be
// false. If ${field} is not present, it does not matter whether it is
// Ok().
if (has_${field}.ValueOrDefault() && !${field}.Ok()) return false;
if (has_${field}().ValueOrDefault() && !${field}().Ok()) return false;


// ** ok_method_switch_block ** ////////////////////////////////////////////////
// Check fields that depend on a common discriminant using a switch.
{
${inner_scope_definitions}
const auto emboss_reserved_switch_discrim = ${discriminant};
if (!emboss_reserved_switch_discrim.Known()) return false;
switch (emboss_reserved_switch_discrim.ValueOrDefault()) {
${switch_cases}
}
}


// ** ok_method_switch_case ** /////////////////////////////////////////////////
case ${case_value}:
if (!${field}().Ok()) return false;
break;




// ** equals_method_test ** ////////////////////////////////////////////////////
Expand Down
Loading
Loading