Simplified pp_map_gen.py and some internals.

This commit is contained in:
Anton Bachin 2015-05-05 13:44:35 -04:00
parent 8fdaa54e08
commit 0a2ca77369
3 changed files with 16 additions and 26 deletions

25
enum.h
View File

@ -306,14 +306,8 @@ constexpr bool _namesMatchNocase(const char *stringizedName,
_namesMatchNocase(stringizedName, referenceName, index + 1); _namesMatchNocase(stringizedName, referenceName, index + 1);
} }
#define _ENUM_NOT_FOUND ((size_t)-1)
/// Functions and types used to compute range properties such as the minimum and
/// maximum declared enum values, and the total number of valid enum values.
namespace _range {
template <typename UnderlyingType> template <typename UnderlyingType>
constexpr UnderlyingType _findMinLoop(const UnderlyingType *values, constexpr UnderlyingType _findMinLoop(const UnderlyingType *values,
size_t valueCount, size_t index, size_t valueCount, size_t index,
@ -351,16 +345,7 @@ constexpr UnderlyingType _findMax(const UnderlyingType *values, size_t count)
return _findMaxLoop(values, count, 1, values[0]); return _findMaxLoop(values, count, 1, values[0]);
} }
} // namespace _range
} // namespace _enum
// TODO Note that the static_assert for _rawSize > 0 never really gets a chance
// to fail in practice, because the preprocessor macros break before that.
namespace _enum {
// TODO Consider reserving memory statically. This will probably entail a great // TODO Consider reserving memory statically. This will probably entail a great
// compile-time slowdown, however. // compile-time slowdown, however.
@ -439,6 +424,8 @@ template <typename Tag> class _GeneratedArrays;
\ \
} }
#define _ENUM_NOT_FOUND ((size_t)-1)
template <typename Tag> template <typename Tag>
class _Enum : public _GeneratedArrays<Tag> { class _Enum : public _GeneratedArrays<Tag> {
protected: protected:
@ -456,10 +443,8 @@ class _Enum : public _GeneratedArrays<Tag> {
constexpr static const _Enumerated _first = _value_array[0]; constexpr static const _Enumerated _first = _value_array[0];
constexpr static const _Enumerated _last = _value_array[_size - 1]; constexpr static const _Enumerated _last = _value_array[_size - 1];
constexpr static const _Enumerated _min = constexpr static const _Enumerated _min = _findMin(_value_array, _size);
_range::_findMin(_value_array, _size); constexpr static const _Enumerated _max = _findMax(_value_array, _size);
constexpr static const _Enumerated _max =
_range::_findMax(_value_array, _size);
constexpr static const size_t _span = _max - _min + 1; constexpr static const size_t _span = _max - _min + 1;
@ -669,7 +654,7 @@ class _Enum : public _GeneratedArrays<Tag> {
\ \
} }
} } // namespace _enum
#define ENUM(EnumType, UnderlyingType, ...) \ #define ENUM(EnumType, UnderlyingType, ...) \
_ENUM_TAG_DECLARATION(EnumType); \ _ENUM_TAG_DECLARATION(EnumType); \

View File

@ -1,4 +1,4 @@
/// @file EnumPreprocessorMap.h /// @file enum_preprocessor_map.h
/// @brief Preprocessor higher-order map macro. /// @brief Preprocessor higher-order map macro.
/// ///
/// This file was automatically generated by pp_map_gen.py /// This file was automatically generated by pp_map_gen.py

View File

@ -88,10 +88,15 @@ if __name__ == '__main__':
if len(sys.argv) != 3: if len(sys.argv) != 3:
print >> sys.stderr, 'Usage: ' + sys.argv[0] + ' FILE COUNT' print >> sys.stderr, 'Usage: ' + sys.argv[0] + ' FILE COUNT'
print >> sys.stderr, '' print >> sys.stderr, ''
print >> sys.stderr, 'Prints macro header file to standard output.' print >> sys.stderr, 'Prints map macro definition to FILE.'
print >> sys.stderr, 'The FILE parameter is used in the comment.' sys.exit(1)
sys.exit(2)
generate(sys.stdout, sys.argv[1], int(sys.argv[2]), output_file = open(sys.argv[1], "w")
try:
generate(output_file, sys.argv[1], int(sys.argv[2]),
os.path.basename(sys.argv[0])) os.path.basename(sys.argv[0]))
finally:
output_file.close()
sys.exit(0) sys.exit(0)