|
30 | 30 | #include "c_qualifiers.h"
|
31 | 31 | #include "expr2c_class.h"
|
32 | 32 |
|
| 33 | +// clang-format off |
| 34 | + |
| 35 | +expr2c_configurationt expr2c_configurationt::default_configuration |
| 36 | +{ |
| 37 | + true, |
| 38 | + true, |
| 39 | + true, |
| 40 | + "TRUE", |
| 41 | + "FALSE" |
| 42 | +}; |
| 43 | + |
| 44 | +expr2c_configurationt expr2c_configurationt::clean_configuration |
| 45 | +{ |
| 46 | + false, |
| 47 | + false, |
| 48 | + false, |
| 49 | + "1", |
| 50 | + "0" |
| 51 | +}; |
| 52 | + |
| 53 | +// clang-format on |
33 | 54 | /*
|
34 | 55 |
|
35 | 56 | Precedences are as follows. Higher values mean higher precedence.
|
@@ -661,7 +682,12 @@ std::string expr2ct::convert_struct_type(
|
661 | 682 | const std::string &qualifiers_str,
|
662 | 683 | const std::string &declarator_str)
|
663 | 684 | {
|
664 |
| - return convert_struct_type(src, qualifiers_str, declarator_str, true, true); |
| 685 | + return convert_struct_type( |
| 686 | + src, |
| 687 | + qualifiers_str, |
| 688 | + declarator_str, |
| 689 | + configuration.print_struct_body_in_type, |
| 690 | + configuration.include_struct_padding_components); |
665 | 691 | }
|
666 | 692 |
|
667 | 693 | /// To generate C-like string for declaring (or defining) the given struct
|
@@ -734,7 +760,8 @@ std::string expr2ct::convert_array_type(
|
734 | 760 | const qualifierst &qualifiers,
|
735 | 761 | const std::string &declarator_str)
|
736 | 762 | {
|
737 |
| - return convert_array_type(src, qualifiers, declarator_str, true); |
| 763 | + return convert_array_type( |
| 764 | + src, qualifiers, declarator_str, configuration.include_array_size); |
738 | 765 | }
|
739 | 766 |
|
740 | 767 | /// To generate a C-like type declaration of an array. Optionally can include or
|
@@ -1996,18 +2023,18 @@ std::string expr2ct::convert_constant(
|
1996 | 2023 | /// FALSE.
|
1997 | 2024 | std::string expr2ct::convert_constant_bool(bool boolean_value)
|
1998 | 2025 | {
|
1999 |
| - // C doesn't really have these |
2000 | 2026 | if(boolean_value)
|
2001 |
| - return "TRUE"; |
| 2027 | + return configuration.true_string; |
2002 | 2028 | else
|
2003 |
| - return "FALSE"; |
| 2029 | + return configuration.false_string; |
2004 | 2030 | }
|
2005 | 2031 |
|
2006 | 2032 | std::string expr2ct::convert_struct(
|
2007 | 2033 | const exprt &src,
|
2008 | 2034 | unsigned &precedence)
|
2009 | 2035 | {
|
2010 |
| - return convert_struct(src, precedence, true); |
| 2036 | + return convert_struct( |
| 2037 | + src, precedence, configuration.include_struct_padding_components); |
2011 | 2038 | }
|
2012 | 2039 |
|
2013 | 2040 | /// To generate a C-like string representing a struct. Can optionally include
|
@@ -3947,17 +3974,55 @@ std::string expr2ct::convert(const exprt &src)
|
3947 | 3974 | return convert_with_precedence(src, precedence);
|
3948 | 3975 | }
|
3949 | 3976 |
|
3950 |
| -std::string expr2c(const exprt &expr, const namespacet &ns) |
| 3977 | +/// Build a declaration string, which requires converting both a type and |
| 3978 | +/// putting an identifier in the syntactically correct position. |
| 3979 | +/// \param src: the type to convert |
| 3980 | +/// \param identifier: the identifier to use as the type |
| 3981 | +/// \return A C declaration of the given type with the right identifier. |
| 3982 | +std::string expr2ct::convert_with_identifier( |
| 3983 | + const typet &src, |
| 3984 | + const std::string &identifier) |
| 3985 | +{ |
| 3986 | + return convert_rec(src, c_qualifierst(), identifier); |
| 3987 | +} |
| 3988 | + |
| 3989 | +std::string expr2c( |
| 3990 | + const exprt &expr, |
| 3991 | + const namespacet &ns, |
| 3992 | + const expr2c_configurationt &configuration) |
3951 | 3993 | {
|
3952 | 3994 | std::string code;
|
3953 |
| - expr2ct expr2c(ns); |
| 3995 | + expr2ct expr2c(ns, configuration); |
3954 | 3996 | expr2c.get_shorthands(expr);
|
3955 | 3997 | return expr2c.convert(expr);
|
3956 | 3998 | }
|
3957 | 3999 |
|
3958 |
| -std::string type2c(const typet &type, const namespacet &ns) |
| 4000 | +std::string expr2c(const exprt &expr, const namespacet &ns) |
| 4001 | +{ |
| 4002 | + return expr2c(expr, ns, expr2c_configurationt::default_configuration); |
| 4003 | +} |
| 4004 | + |
| 4005 | +std::string type2c( |
| 4006 | + const typet &type, |
| 4007 | + const namespacet &ns, |
| 4008 | + const expr2c_configurationt &configuration) |
3959 | 4009 | {
|
3960 |
| - expr2ct expr2c(ns); |
| 4010 | + expr2ct expr2c(ns, configuration); |
3961 | 4011 | // expr2c.get_shorthands(expr);
|
3962 | 4012 | return expr2c.convert(type);
|
3963 | 4013 | }
|
| 4014 | + |
| 4015 | +std::string type2c(const typet &type, const namespacet &ns) |
| 4016 | +{ |
| 4017 | + return type2c(type, ns, expr2c_configurationt::default_configuration); |
| 4018 | +} |
| 4019 | + |
| 4020 | +std::string type2c( |
| 4021 | + const typet &type, |
| 4022 | + const std::string &identifier, |
| 4023 | + const namespacet &ns, |
| 4024 | + const expr2c_configurationt &configuration) |
| 4025 | +{ |
| 4026 | + expr2ct expr2c(ns, configuration); |
| 4027 | + return expr2c.convert_with_identifier(type, identifier); |
| 4028 | +} |
0 commit comments