diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-11 23:26:18 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-11 23:26:18 +0100 |
commit | c42e4b6c5364eae3c3db23627d2b3c661c0c2580 (patch) | |
tree | 18c864fad94f94bbbab936594c6ff545c01cf72d /py/makeqstrdata.py | |
parent | 8b19db00aa78e13793185b8734840c88c2938d5b (diff) | |
parent | b9b1c00c8af9e4d654aed30f8f98875657f14891 (diff) |
Merge branch 'master' of github.com:micropython/micropython
Diffstat (limited to 'py/makeqstrdata.py')
-rw-r--r-- | py/makeqstrdata.py | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py index e60f00044..81b003545 100644 --- a/py/makeqstrdata.py +++ b/py/makeqstrdata.py @@ -26,10 +26,10 @@ def compute_hash(qstr): def do_work(infiles): # read the qstrs in from the input files qstrs = {} + cpp_header_blocks = 3 for infile in infiles: with open(infile, 'rt') as f: line_number = 0 - conditional = None for line in f: line_number += 1 line = line.strip() @@ -38,17 +38,13 @@ def do_work(infiles): if len(line) == 0 or line.startswith('//'): continue - if line[0] == '#': - if conditional == "<endif>": - assert line == "#endif" - conditional = None - else: - assert conditional is None - conditional = line + # We'll have 3 line-number lines for py/qstrdefs.h - initial, leaving it to + # go into other headers, and returning to it. + if line.startswith('# ') and 'py/qstrdefs.h' in line: + cpp_header_blocks -= 1 + continue + if cpp_header_blocks != 0: continue - - if conditional == "<endif>": - assert False, "#endif expected before '%s'" % line # verify line is of the correct form match = re.match(r'Q\((.+)\)$', line) @@ -65,21 +61,15 @@ def do_work(infiles): continue # add the qstr to the list, with order number to retain original order in file - qstrs[ident] = (len(qstrs), ident, qstr, conditional) - if conditional is not None: - conditional = "<endif>" + qstrs[ident] = (len(qstrs), ident, qstr) # process the qstrs, printing out the generated C header file print('// This file was automatically generated by makeqstrdata.py') print('') - for order, ident, qstr, conditional in sorted(qstrs.values(), key=lambda x: x[0]): + for order, ident, qstr in sorted(qstrs.values(), key=lambda x: x[0]): qhash = compute_hash(qstr) qlen = len(qstr) - if conditional: - print(conditional) print('Q({}, (const byte*)"\\x{:02x}\\x{:02x}\\x{:02x}\\x{:02x}" "{}")'.format(ident, qhash & 0xff, (qhash >> 8) & 0xff, qlen & 0xff, (qlen >> 8) & 0xff, qstr)) - if conditional: - print('#endif') return True |