From 6ea0e928d8aced4f8ce5ab451105c199092eb6df Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 11 Apr 2014 20:36:08 +0300 Subject: Revert "makeqstrdata.py: Add support for conditionally defined qstrs." This reverts commit acb133d1b1a68847bd85c545312c3e221a6f7c0b. Conditionals will be suported using C preprocessor. --- py/makeqstrdata.py | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) (limited to 'py/makeqstrdata.py') diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py index e60f00044..741336571 100644 --- a/py/makeqstrdata.py +++ b/py/makeqstrdata.py @@ -29,7 +29,6 @@ def do_work(infiles): 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,18 +37,6 @@ def do_work(infiles): if len(line) == 0 or line.startswith('//'): continue - if line[0] == '#': - if conditional == "": - assert line == "#endif" - conditional = None - else: - assert conditional is None - conditional = line - continue - - if conditional == "": - assert False, "#endif expected before '%s'" % line - # verify line is of the correct form match = re.match(r'Q\((.+)\)$', line) if not match: @@ -65,21 +52,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 = "" + 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 -- cgit v1.2.3 From a925cb54f1b3490a9e082816eb785750c4b25324 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 11 Apr 2014 20:50:15 +0300 Subject: py: Preprocess qstrdefs.h before feeding to makeqstrdata.py. This is alternative implementation of supporting conditionals in qstrdefs.h, hard to say if it's much cleaner than munging #ifdef's in Python code... --- py/makeqstrdata.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'py/makeqstrdata.py') diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py index 741336571..81b003545 100644 --- a/py/makeqstrdata.py +++ b/py/makeqstrdata.py @@ -26,6 +26,7 @@ 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 @@ -37,6 +38,14 @@ def do_work(infiles): if len(line) == 0 or line.startswith('//'): continue + # 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 + # verify line is of the correct form match = re.match(r'Q\((.+)\)$', line) if not match: -- cgit v1.2.3