Generate the C declaration for a constant (a single value). tags may specify their values in several ways, but are usually just integers or floating-point numbers.
(self, enuminfo, name, alias)
| 888 | return (section, '\n'.join(body)) |
| 889 | |
| 890 | def buildConstantCDecl(self, enuminfo, name, alias): |
| 891 | """Generate the C declaration for a constant (a single <enum> |
| 892 | value). |
| 893 | |
| 894 | <enum> tags may specify their values in several ways, but are |
| 895 | usually just integers or floating-point numbers.""" |
| 896 | |
| 897 | (_, strVal) = self.enumToValue(enuminfo.elem, False) |
| 898 | |
| 899 | if self.misracppstyle() and enuminfo.elem.get('type') and not alias: |
| 900 | # Generate e.g.: static constexpr uint32_t x = ~static_cast<uint32_t>(1U); |
| 901 | # This appeases MISRA "underlying type" rules. |
| 902 | typeStr = enuminfo.elem.get('type'); |
| 903 | invert = '~' in strVal |
| 904 | number = strVal.strip("()~UL") |
| 905 | if typeStr != "float": |
| 906 | number += 'U' |
| 907 | strVal = "~" if invert else "" |
| 908 | strVal += f"static_cast<{typeStr}>({number})" |
| 909 | body = f"static constexpr {typeStr.ljust(9)}{name.ljust(33)} {{{strVal}}};" |
| 910 | elif enuminfo.elem.get('type') and not alias: |
| 911 | # Generate e.g.: #define x (~0ULL) |
| 912 | typeStr = enuminfo.elem.get('type'); |
| 913 | invert = '~' in strVal |
| 914 | paren = '(' in strVal |
| 915 | number = strVal.strip("()~UL") |
| 916 | if typeStr != "float": |
| 917 | if typeStr == "uint64_t": |
| 918 | number += 'ULL' |
| 919 | else: |
| 920 | number += 'U' |
| 921 | strVal = "~" if invert else "" |
| 922 | strVal += number |
| 923 | if paren: |
| 924 | strVal = f"({strVal})"; |
| 925 | body = f"#define {name.ljust(33)} {strVal}"; |
| 926 | else: |
| 927 | body = f"#define {name.ljust(33)} {strVal}" |
| 928 | |
| 929 | return body |
| 930 | |
| 931 | def makeDir(self, path): |
| 932 | """Create a directory, if not already done. |
no test coverage detected