MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / parse_json

Function parse_json

tools/gen_struct_info.py:293–327  ·  view source on GitHub ↗
(path)

Source from the content-addressed store, hash-verified

291
292
293def parse_json(path):
294 header_files = []
295
296 with open(path, encoding='utf-8') as stream:
297 # Remove comments before loading the JSON.
298 data = json.loads(re.sub(r'//.*\n', '', stream.read()))
299
300 if not isinstance(data, list):
301 data = [data]
302
303 for item in data:
304 for key in item:
305 if key not in {'file', 'defines', 'structs'}:
306 raise 'Unexpected key in json file: %s' % key
307
308 header = {'name': item['file'], 'structs': {}, 'defines': {}}
309 for name, data in item.get('structs', {}).items():
310 if name in header['structs']:
311 show('WARN: Description of struct "' + name + '" in file "' + item['file'] + '" replaces an existing description!')
312
313 header['structs'][name] = data
314
315 for part in item.get('defines', []):
316 if not isinstance(part, list):
317 # If no type is specified, assume integer.
318 part = ['i', part]
319
320 if part[1] in header['defines']:
321 show('WARN: Description of define "' + part[1] + '" in file "' + item['file'] + '" replaces an existing description!')
322
323 header['defines'][part[1]] = part[0]
324
325 header_files.append(header)
326
327 return header_files
328
329
330def output_json(obj, stream):

Callers 1

mainFunction · 0.85

Calls 5

appendMethod · 0.80
showFunction · 0.70
getMethod · 0.65
openFunction · 0.50
readMethod · 0.45

Tested by

no test coverage detected