@@ -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+
109128def _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+
205242def _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 ):
0 commit comments