diff options
Diffstat (limited to 'gr-utils/modtool/tools/parser_cc_block.py')
-rw-r--r-- | gr-utils/modtool/tools/parser_cc_block.py | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/gr-utils/modtool/tools/parser_cc_block.py b/gr-utils/modtool/tools/parser_cc_block.py index d4e261cac7..c53f655357 100644 --- a/gr-utils/modtool/tools/parser_cc_block.py +++ b/gr-utils/modtool/tools/parser_cc_block.py @@ -15,17 +15,20 @@ import logging logger = logging.getLogger(__name__) + def dummy_translator(the_type, default_v=None): """ Doesn't really translate. """ return the_type + class ParserCCBlock(object): """ Class to read blocks written in C++ """ + def __init__(self, filename_cc, filename_h, blockname, version, type_trans=dummy_translator): with open(filename_cc) as f: self.code_cc = f.read() with open(filename_h) as f: - self.code_h = f.read() + self.code_h = f.read() self.blockname = blockname self.type_trans = type_trans self.version = version @@ -40,14 +43,16 @@ class ParserCCBlock(object): logger.error('tbi') raise ValueError return {'type': [_typestr_to_iotype(x) for x in typestr.split(',')], - 'vlen': [_typestr_to_vlen(x) for x in typestr.split(',')] - } + 'vlen': [_typestr_to_vlen(x) for x in typestr.split(',')] + } + def _typestr_to_iotype(typestr): """ Convert a type string (e.g. sizeof(int) * vlen) to the type (e.g. 'int'). """ type_match = re.search(r'sizeof\s*\(([^)]*)\)', typestr) if type_match is None: return self.type_trans('char') return self.type_trans(type_match.group(1)) + def _typestr_to_vlen(typestr): """ From a type identifier, returns the vector length of the block's input/out. E.g., for 'sizeof(int) * 10', it returns 10. For @@ -71,7 +76,8 @@ class ParserCCBlock(object): r'\s*(?P<intype>(\([^\)]*\)|[^)])+)\),\s*' + \ r'(?P<outcall>gr::io_signature::make[23v]?)\s*\(\s*(?P<outmin>[^,]+),\s*(?P<outmax>[^,]+),' + \ r'\s*(?P<outtype>(\([^\)]*\)|[^)])+)\)' - iosig_match = re.compile(iosig_regex, re.MULTILINE).search(self.code_cc) + iosig_match = re.compile( + iosig_regex, re.MULTILINE).search(self.code_cc) try: iosig['in'] = _figure_out_iotype_and_vlen(iosig_match.group('incall'), iosig_match.group('intype')) @@ -88,7 +94,6 @@ class ParserCCBlock(object): logger.error("Error: Can't parse output signature.") return iosig - def read_params(self): """ Read the parameters required to initialize the block """ def _scan_param_list(start_idx): @@ -104,8 +109,8 @@ class ParserCCBlock(object): param_list = [] read_state = 'type' in_string = False - parens_count = 0 # Counts () - brackets_count = 0 # Counts <> + parens_count = 0 # Counts () + brackets_count = 0 # Counts <> end_of_list = False this_type = '' this_name = '' @@ -118,12 +123,13 @@ class ParserCCBlock(object): if parens_count == 0: if read_state == 'type' and len(this_type): raise ValueError( - 'Found closing parentheses before finishing ' - 'last argument (this is how far I got: {})'.format \ - (str(param_list)) + 'Found closing parentheses before finishing ' + 'last argument (this is how far I got: {})'.format + (str(param_list)) ) if len(this_type): - param_list.append((this_type, this_name, this_defv)) + param_list.append( + (this_type, this_name, this_defv)) end_of_list = True break else: @@ -143,9 +149,9 @@ class ParserCCBlock(object): while c[i] in WHITESPACE: i += 1 continue - if this_type == 'const' or this_type == '': # Ignore this + if this_type == 'const' or this_type == '': # Ignore this this_type = '' - elif this_type == 'unsigned': # Continue + elif this_type == 'unsigned': # Continue this_type += ' ' continue else: @@ -161,16 +167,16 @@ class ParserCCBlock(object): elif c[i] == '=': if parens_count != 0: raise ValueError( - 'While parsing argument {} ({}): name finished but no closing parentheses.'.format \ - (len(param_list)+1, this_type + ' ' + this_name) + 'While parsing argument {} ({}): name finished but no closing parentheses.'.format + (len(param_list) + 1, this_type + ' ' + this_name) ) read_state = 'defv' i += 1 elif c[i] == ',': if parens_count: raise ValueError( - 'While parsing argument {} ({}): name finished but no closing parentheses.'.format \ - (len(param_list)+1, this_type + ' ' + this_name) + 'While parsing argument {} ({}): name finished but no closing parentheses.'.format + (len(param_list) + 1, this_type + ' ' + this_name) ) read_state = 'defv' else: @@ -180,15 +186,15 @@ class ParserCCBlock(object): # Default value if read_state == 'defv': if in_string: - if c[i] == '"' and c[i-1] != '\\': + if c[i] == '"' and c[i - 1] != '\\': in_string = False else: this_defv += c[i] elif c[i] == ',': if parens_count: raise ValueError( - 'While parsing argument {} ({}): default value finished but no closing parentheses.'.format \ - (len(param_list)+1, this_type + ' ' + this_name) + 'While parsing argument {} ({}): default value finished but no closing parentheses.'.format + (len(param_list) + 1, this_type + ' ' + this_name) ) read_state = 'type' param_list.append((this_type, this_name, this_defv)) |