mirror of
https://github.com/aantron/better-enums.git
synced 2025-12-06 16:56:42 +08:00
Update make_macros.py for python 3
This commit is contained in:
parent
2fad3f60ee
commit
ee37bb4206
@ -53,7 +53,7 @@ class MultiLine(object):
|
|||||||
break_line = True
|
break_line = True
|
||||||
|
|
||||||
if break_line:
|
if break_line:
|
||||||
print >> self._stream, ' ' * (self._columns_left - 1) + '\\'
|
print(' ' * (self._columns_left - 1) + '\\', self._stream)
|
||||||
self._stream.write(' ' * self._indent)
|
self._stream.write(' ' * self._indent)
|
||||||
self._columns_left = self._columns - self._indent
|
self._columns_left = self._columns - self._indent
|
||||||
token = token.lstrip()
|
token = token.lstrip()
|
||||||
@ -62,42 +62,42 @@ class MultiLine(object):
|
|||||||
self._columns_left -= len(token)
|
self._columns_left -= len(token)
|
||||||
|
|
||||||
def generate(stream, constants, length, script):
|
def generate(stream, constants, length, script):
|
||||||
print >> stream, '// This file was automatically generated by ' + script
|
print('// This file was automatically generated by ' + script, stream)
|
||||||
|
|
||||||
print >> stream, ''
|
print('', stream)
|
||||||
print >> stream, '#pragma once'
|
print('#pragma once', stream)
|
||||||
print >> stream, ''
|
print('', stream)
|
||||||
print >> stream, '#ifndef BETTER_ENUMS_MACRO_FILE_H'
|
print('#ifndef BETTER_ENUMS_MACRO_FILE_H', stream)
|
||||||
print >> stream, '#define BETTER_ENUMS_MACRO_FILE_H'
|
print('#define BETTER_ENUMS_MACRO_FILE_H', stream)
|
||||||
|
|
||||||
print >> stream, ''
|
print('', stream)
|
||||||
print >> stream, '#define BETTER_ENUMS_PP_MAP(macro, data, ...) \\'
|
print('#define BETTER_ENUMS_PP_MAP(macro, data, ...) \\', stream)
|
||||||
print >> stream, ' BETTER_ENUMS_ID( \\'
|
print(' BETTER_ENUMS_ID( \\', stream)
|
||||||
print >> stream, ' BETTER_ENUMS_APPLY( \\'
|
print(' BETTER_ENUMS_APPLY( \\', stream)
|
||||||
print >> stream, ' BETTER_ENUMS_PP_MAP_VAR_COUNT, \\'
|
print(' BETTER_ENUMS_PP_MAP_VAR_COUNT, \\', stream)
|
||||||
print >> stream, ' BETTER_ENUMS_PP_COUNT(__VA_ARGS__)) \\'
|
print(' BETTER_ENUMS_PP_COUNT(__VA_ARGS__)) \\', stream)
|
||||||
print >> stream, ' (macro, data, __VA_ARGS__))'
|
print(' (macro, data, __VA_ARGS__))', stream)
|
||||||
|
|
||||||
print >> stream, ''
|
print('', stream)
|
||||||
print >> stream, '#define BETTER_ENUMS_PP_MAP_VAR_COUNT(count) ' + \
|
print('#define BETTER_ENUMS_PP_MAP_VAR_COUNT(count) ' + \
|
||||||
'BETTER_ENUMS_M ## count'
|
'BETTER_ENUMS_M ## count', stream)
|
||||||
|
|
||||||
print >> stream, ''
|
print('', stream)
|
||||||
print >> stream, '#define BETTER_ENUMS_APPLY(macro, ...) ' + \
|
print('#define BETTER_ENUMS_APPLY(macro, ...) ' + \
|
||||||
'BETTER_ENUMS_ID(macro(__VA_ARGS__))'
|
'BETTER_ENUMS_ID(macro(__VA_ARGS__))', stream)
|
||||||
|
|
||||||
print >> stream, ''
|
print('', stream)
|
||||||
print >> stream, '#define BETTER_ENUMS_ID(x) x'
|
print('#define BETTER_ENUMS_ID(x) x', stream)
|
||||||
|
|
||||||
print >> stream, ''
|
print('', stream)
|
||||||
print >> stream, '#define BETTER_ENUMS_M1(m, d, x) m(d,0,x)'
|
print('#define BETTER_ENUMS_M1(m, d, x) m(d,0,x)', stream)
|
||||||
for index in range(2, constants + 1):
|
for index in range(2, constants + 1):
|
||||||
print >> stream, '#define BETTER_ENUMS_M' + str(index) + \
|
print('#define BETTER_ENUMS_M' + str(index) + \
|
||||||
'(m,d,x,...) m(d,' + str(index - 1) + ',x) \\'
|
'(m,d,x,...) m(d,' + str(index - 1) + ',x) \\', stream)
|
||||||
print >> stream, ' BETTER_ENUMS_ID(BETTER_ENUMS_M' + \
|
print(' BETTER_ENUMS_ID(BETTER_ENUMS_M' + \
|
||||||
str(index - 1) + '(m,d,__VA_ARGS__))'
|
str(index - 1) + '(m,d,__VA_ARGS__))', stream)
|
||||||
|
|
||||||
print >> stream, ''
|
print('', stream)
|
||||||
pp_count_impl_prefix = '#define BETTER_ENUMS_PP_COUNT_IMPL(_1,'
|
pp_count_impl_prefix = '#define BETTER_ENUMS_PP_COUNT_IMPL(_1,'
|
||||||
stream.write(pp_count_impl_prefix)
|
stream.write(pp_count_impl_prefix)
|
||||||
pp_count_impl = MultiLine(stream = stream, indent = 4,
|
pp_count_impl = MultiLine(stream = stream, indent = 4,
|
||||||
@ -107,10 +107,10 @@ def generate(stream, constants, length, script):
|
|||||||
pp_count_impl.write(' count,')
|
pp_count_impl.write(' count,')
|
||||||
pp_count_impl.write(' ...)')
|
pp_count_impl.write(' ...)')
|
||||||
pp_count_impl.write(' count', last = True)
|
pp_count_impl.write(' count', last = True)
|
||||||
print >> stream, ''
|
print('', stream)
|
||||||
|
|
||||||
print >> stream, ''
|
print('', stream)
|
||||||
print >> stream, '#define BETTER_ENUMS_PP_COUNT(...) \\'
|
print('#define BETTER_ENUMS_PP_COUNT(...) \\', stream)
|
||||||
pp_count_prefix = \
|
pp_count_prefix = \
|
||||||
' BETTER_ENUMS_ID(BETTER_ENUMS_PP_COUNT_IMPL(__VA_ARGS__,'
|
' BETTER_ENUMS_ID(BETTER_ENUMS_PP_COUNT_IMPL(__VA_ARGS__,'
|
||||||
stream.write(pp_count_prefix)
|
stream.write(pp_count_prefix)
|
||||||
@ -119,28 +119,27 @@ def generate(stream, constants, length, script):
|
|||||||
for index in range(0, constants - 1):
|
for index in range(0, constants - 1):
|
||||||
pp_count.write(' ' + str(constants - index) + ',')
|
pp_count.write(' ' + str(constants - index) + ',')
|
||||||
pp_count.write(' 1))', last = True)
|
pp_count.write(' 1))', last = True)
|
||||||
print >> stream, ''
|
print('', stream)
|
||||||
|
|
||||||
print >> stream, ''
|
print('', stream)
|
||||||
iterate_prefix = '#define BETTER_ENUMS_ITERATE(X, f, l)'
|
iterate_prefix = '#define BETTER_ENUMS_ITERATE(X, f, l)'
|
||||||
stream.write(iterate_prefix)
|
stream.write(iterate_prefix)
|
||||||
iterate = MultiLine(stream = stream, indent = 4,
|
iterate = MultiLine(stream = stream, indent = 4,
|
||||||
initial_column = len(iterate_prefix))
|
initial_column = len(iterate_prefix))
|
||||||
for index in range(0, length):
|
for index in range(0, length):
|
||||||
iterate.write(' X(f, l, %i)' % index)
|
iterate.write(' X(f, l, %i)' % index)
|
||||||
print >> stream, ''
|
print('', stream)
|
||||||
|
|
||||||
print >> stream, ''
|
print('', stream)
|
||||||
print >> stream, '#endif // #ifndef BETTER_ENUMS_MACRO_FILE_H'
|
print('#endif // #ifndef BETTER_ENUMS_MACRO_FILE_H', stream)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) != 3:
|
if len(sys.argv) != 3:
|
||||||
print >> sys.stderr, \
|
print('Usage: ' + sys.argv[0] + ' CONSTANTS LENGTH > FILE', sys.stderr)
|
||||||
'Usage: ' + sys.argv[0] + ' CONSTANTS LENGTH > FILE'
|
print('', sys.stderr)
|
||||||
print >> sys.stderr, ''
|
print('Prints map macro definition to FILE.', sys.stderr)
|
||||||
print >> sys.stderr, 'Prints map macro definition to FILE.'
|
print('CONSTANTS is the number of constants to support.', sys.stderr)
|
||||||
print >> sys.stderr, 'CONSTANTS is the number of constants to support.'
|
print('LENGTH is the maximum length of a constant name.', sys.stderr)
|
||||||
print >> sys.stderr, 'LENGTH is the maximum length of a constant name.'
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
generate(sys.stdout, int(sys.argv[1]), int(sys.argv[2]),
|
generate(sys.stdout, int(sys.argv[1]), int(sys.argv[2]),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user