in cbmc_viewer/sourcet.py [0:0]
def __init__(self, source_jsons, sloc=False):
"""Read the list of source files from a set of json files.
The argument 'source_jsons' is a list of json files containing the
json serializations of Source objects. Confirm that these
lists all have the same source root, and merge these lists of
source files into a single list. Don't run sloc on the list
of source files, by default, since the list from find and walk
can be very long.
"""
if not source_jsons:
raise UserWarning('No sources')
def load(source_json):
try:
source = parse.parse_json_file(source_json)[JSON_TAG]
except TypeError:
raise UserWarning(
"Failed to load sources from {}".format(source_json)
) from None
self.validate(source)
return source
def merge(sources):
roots = list({source['root'] for source in sources})
files = list({src
for source in sources
for src in source['all_files']})
if len(roots) != 1:
raise UserWarning(
'Source lists have different roots: {}'.format(roots)
)
return {'root': roots[0], 'files': files}
source = merge([load(source_json) for source_json in source_jsons])
super().__init__(source['root'], source['files'], sloc)