def _make_symbol_table(self, symbols, root):
        '''Make symbol table.'''
        symbol_table = []
        for spec, mangled_name in symbols:
            if isinstance(spec, str):
                symbol = spec
                matcher = SyntaxTreeMatcher.make([{'name': '^%s$' % spec}])
            else:
                symbol = spec['name']
                matcher = SyntaxTreeMatcher.make([spec])
            symbol_table.append({
                'symbol': symbol,
                'matcher': matcher,
                'mangled_name': mangled_name,
            })

        def search_node(tree):
            '''Search matched node.'''
            for blob in symbol_table:
                if blob['matcher'].do_match(tree):
                    self.assertTrue('tree' not in blob)  # Unique matching
                    blob['tree'] = tree

        root.traverse(preorder=search_node)
        for blob in symbol_table:
            blob['output_name'] = mangle(blob['tree'])
        return symbol_table
    def _make_symbol_table(self, symbols, root):
        '''Make symbol table.'''
        symbol_table = []
        for spec, mangled_name in symbols:
            if isinstance(spec, str):
                symbol = spec
                matcher = SyntaxTreeMatcher.make([{'name': '^%s$' % spec}])
            else:
                symbol = spec['name']
                matcher = SyntaxTreeMatcher.make([spec])
            symbol_table.append({
                'symbol': symbol,
                'matcher': matcher,
                'mangled_name': mangled_name,
            })

        def search_node(tree):
            '''Search matched node.'''
            for blob in symbol_table:
                if blob['matcher'].do_match(tree):
                    self.assertTrue('tree' not in blob)  # Unique matching
                    blob['tree'] = tree

        root.traverse(preorder=search_node)
        for blob in symbol_table:
            blob['output_name'] = mangle(blob['tree'])
        return symbol_table
示例#3
0
 def config(self, config_data):
     '''Configure the generator.'''
     if 'preamble' in config_data:
         preamble = config_data['preamble']
         if isinstance(preamble, str):
             self._config['preamble'] = preamble
         else:
             self._config['preamble'] = preamble['codes']
             self._config['library'] = preamble.get('library')
             self._config['use_custom_loader'] = \
                 preamble.get('use_custom_loader')
     for name in 'enum errcheck import method mixin rename'.split():
         if name in config_data:
             matcher = SyntaxTreeMatcher.make(config_data[name])
             self._config[name] = getattr(matcher, 'do_' + name)