MCPcopy Create free account
hub / github.com/BasisResearch/lean.py / get_header_model

Function get_header_model

lean_py/_parse.py:338–369  ·  view source on GitHub ↗

Parse lean.h and return the HeaderModel, using a disk cache for speed.

()

Source from the content-addressed store, hash-verified

336 model.exported_functions.append(func)
337
338 return model
339
340
341# ============================================================================
342# Public API
343# ============================================================================
344
345_CACHE_DIR = Path(__file__).parent.parent / ".cache"
346
347
348def get_header_model() -> HeaderModel:
349 """Parse lean.h and return the HeaderModel, using a disk cache for speed."""
350 header_path = find_lean_header()
351 header_hash = hashlib.md5(header_path.read_bytes()).hexdigest()
352
353 cache_file = _CACHE_DIR / f"lean_h_{header_hash}.pickle"
354 if cache_file.exists():
355 try:
356 return pickle.loads(cache_file.read_bytes())
357 except Exception:
358 pass
359
360 # Parse fresh
361 preprocessed = _preprocess(header_path)
362 parser = pycparser.CParser()
363 with open(preprocessed) as f:
364 source = f.read()
365 try:
366 ast = parser.parse(source, filename=str(preprocessed))
367 except ParseError as e:
368 raise RuntimeError(f"Failed to parse lean.h: {e}") from e
369 finally:
370 preprocessed.unlink(missing_ok=True)
371
372 defines = extract_defines(header_path)

Callers 1

_ensure_builtFunction · 0.90

Calls 5

find_lean_headerFunction · 0.85
_preprocessFunction · 0.85
extract_definesFunction · 0.85
_classifyFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected