1# -*- Python -*- vim: set syntax=python tabstop=4 expandtab cc=80: 2#===----------------------------------------------------------------------===## 3# 4# The LLVM Compiler Infrastructure 5# 6# This file is dual licensed under the MIT and the University of Illinois Open 7# Source Licenses. See LICENSE.TXT for details. 8# 9#===----------------------------------------------------------------------===## 10""" 11match - A set of functions for matching symbols in a list to a list of regexs 12""" 13 14import re 15 16 17def find_and_report_matching(symbol_list, regex_list): 18 report = '' 19 found_count = 0 20 for regex_str in regex_list: 21 report += 'Matching regex "%s":\n' % regex_str 22 matching_list = find_matching_symbols(symbol_list, regex_str) 23 if not matching_list: 24 report += ' No matches found\n\n' 25 continue 26 # else 27 found_count += len(matching_list) 28 for m in matching_list: 29 report += ' MATCHES: %s\n' % m['name'] 30 report += '\n' 31 return found_count, report 32 33 34def find_matching_symbols(symbol_list, regex_str): 35 regex = re.compile(regex_str) 36 matching_list = [] 37 for s in symbol_list: 38 if regex.match(s['name']): 39 matching_list += [s] 40 return matching_list 41