Skip to content

Commit e493b0c

Browse files
committed
fix errors
1 parent b816cbc commit e493b0c

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

‎tests/parser/c/generate_c_parser_goldens.py‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,25 @@ def _is_project_location(location: object) -> bool:
106106
return isinstance(location, dict) and _is_project_filename(location.get("filename"))
107107

108108

109+
def _project_source_line(filename: object, line: object) -> str | None:
110+
if not _is_project_filename(filename) or not isinstance(line, int) or line <= 0:
111+
return None
112+
source = _C_DATA_DIR / filename
113+
if not source.is_file():
114+
return None
115+
try:
116+
return source.read_text(encoding="utf-8").splitlines()[line - 1]
117+
except IndexError:
118+
return None
119+
120+
121+
def _stable_project_location(location: dict) -> dict:
122+
source_line = _project_source_line(location.get("filename"), location.get("line"))
123+
if source_line is None:
124+
return location
125+
return {**location, "source_line": source_line}
126+
127+
109128
def _has_project_source_location(declaration: object) -> bool:
110129
return isinstance(declaration, dict) and _is_project_location(declaration.get("source_location"))
111130

@@ -202,8 +221,30 @@ def _system_declaration_reference(declaration: dict) -> str | None:
202221
return None
203222

204223

224+
def _stable_bool_payload(qualifiers: object = None) -> dict:
225+
return {"model": "CBool", "qualifiers": list(qualifiers or []), "source_text": "bool"}
226+
227+
228+
def _stable_bool_type_payload(declaration: dict) -> dict | None:
229+
if declaration.get("reference") == "bool":
230+
return _stable_bool_payload()
231+
if declaration.get("model") == "CBool":
232+
return _stable_bool_payload(declaration.get("qualifiers"))
233+
if (
234+
declaration.get("model") == "CTypedef"
235+
and declaration.get("name") == "bool"
236+
and not _is_project_location(declaration.get("source_location"))
237+
):
238+
return _stable_bool_payload(declaration.get("qualifiers"))
239+
return None
240+
241+
205242
def _stable_payload_value(value, symbols: dict[str, set[str]]):
206243
if isinstance(value, dict):
244+
bool_payload = _stable_bool_type_payload(value)
245+
if bool_payload is not None:
246+
return bool_payload
247+
207248
reference = _system_declaration_reference(value)
208249
if reference is not None:
209250
return {"reference": _stable_payload_value(reference, symbols)}
@@ -250,6 +291,9 @@ def _stable_payload_value(value, symbols: dict[str, set[str]]):
250291
"source_line": None,
251292
}
252293
continue
294+
if _is_project_filename(filename):
295+
stable[key] = _stable_project_location(nested)
296+
continue
253297
stable[key] = _stable_payload_value(nested, symbols)
254298
return stable
255299
if isinstance(value, list):

‎tests/pipeline/preprocessing/test_cli.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def test_cli_help_documents_exact_compiler_and_preprocessing_examples():
2222
assert "Compiler used for preprocessing" in res.stdout
2323
assert "default: gfortran; cc with --language c" in " ".join(res.stdout.split())
2424
assert "--compile-commands PATH" in res.stdout
25-
assert "-D, --define NAME[=VALUE]" in res.stdout
25+
assert "-D" in res.stdout
26+
assert "--define NAME[=VALUE]" in res.stdout
2627

2728

2829
def test_cli_c_default_compiler_mode_accepts_include_dirs(tmp_path: Path):

0 commit comments

Comments
 (0)