Hack for "true" and "false" used as enum element values

This is not a full solution by far, but should address the most common case.

This also allows "cpp_enum" unit test to pass.
This commit is contained in:
Vadim Zeitlin 2016-04-16 00:45:58 +02:00
commit 44d68197d6
3 changed files with 14 additions and 4 deletions

View file

@ -51,7 +51,6 @@ FAILING_CPP_TESTS := \
cpp_basic_global_var_class \
cpp_basic_template_class \
cpp_basic_template_function \
cpp_enum \
c_backend_cpp_natural_std_string \
c_backend_cpp_exception \
default_args \

View file

@ -63,10 +63,10 @@ int main(int argc, const char *argv[]) {
play_state t;
t = PLAY;
assert(t == true);
assert(t == 1);
t = STOP;
assert(t == false);
assert(t == 0);
return 0;
}
}

View file

@ -1774,6 +1774,17 @@ ready:
Append(cvalue, "'");
}
// Boolean constants can't appear in C code neither, so replace them with their values in the simplest possible case. This is not exhaustive, of course,
// but better than nothing and doing the right thing is not simple at all as we'd need to really parse the expression, just textual substitution wouldn't
// be enough (consider e.g. an enum element called "very_true" and another one using it as its value).
if (Cmp(value, "true") == 0) {
Clear(cvalue);
Append(cvalue, "1");
} else if (Cmp(value, "false") == 0) {
Clear(cvalue);
Append(cvalue, "0");
}
Printv(f_wrappers_types, " = ", cvalue, NIL);
Delete(cvalue);