|
6 | 6 | # |
7 | 7 | # Copyright (c) 2017-2020 Kestrel Technology LLC |
8 | 8 | # Copyright (c) 2020-2022 Henny B. Sipma |
9 | | -# Copyright (c) 2023-2024 Aarno Labs LLC |
| 9 | +# Copyright (c) 2023-2025 Aarno Labs LLC |
10 | 10 | # |
11 | 11 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
12 | 12 | # of this software and associated documentation files (the "Software"), to deal |
|
51 | 51 | from chc.app.CFileGlobals import CGVarDecl |
52 | 52 | from chc.app.CFileGlobals import CGVarDef |
53 | 53 | from chc.app.CGXrefs import CGXrefs |
| 54 | +from chc.app.CPrettyPrinter import CPrettyPrinter |
54 | 55 |
|
55 | 56 | from chc.proof.CFilePredicateDictionary import CFilePredicateDictionary |
56 | 57 | from chc.proof.CFunctionPO import CFunctionPO |
@@ -183,6 +184,36 @@ def cfileglobals(self) -> CFileGlobals: |
183 | 184 | def gfunctions(self) -> Dict[int, "CGFunction"]: |
184 | 185 | return self.cfileglobals.gfunctions |
185 | 186 |
|
| 187 | + def header_declarations( |
| 188 | + self, |
| 189 | + gvarnames: Dict[str, str] = {}, |
| 190 | + fnnames: Dict[str, str] = {}) -> str: |
| 191 | + lines: List[str] = [] |
| 192 | + srcfilename = self.name + ".c" |
| 193 | + lines.append("// " + srcfilename + "\n") |
| 194 | + gvars = self.gvardefs.values() |
| 195 | + if len(gvars) > 0: |
| 196 | + lines.append("// static and global variable definitions\n") |
| 197 | + for gvar in gvars: |
| 198 | + pp = CPrettyPrinter() |
| 199 | + binloc: Optional[str] = gvarnames.get(gvar.varinfo.vname) |
| 200 | + gvardef = pp.gvar_definition_str( |
| 201 | + gvar.varinfo, srcloc=srcfilename, binloc=binloc) |
| 202 | + lines.append(gvardef) |
| 203 | + |
| 204 | + fns = self.gfunctions.values() |
| 205 | + if len(gvars) > 0 and len(fns) > 0: |
| 206 | + lines.append("// function signatures\n") |
| 207 | + for fn in fns: |
| 208 | + if fn.is_system_function: |
| 209 | + continue |
| 210 | + pp = CPrettyPrinter() |
| 211 | + binloc = fnnames.get(fn.varinfo.vname) |
| 212 | + fndecl = pp.function_declaration_str( |
| 213 | + fn.varinfo, srcloc=srcfilename, binloc=binloc) |
| 214 | + lines.append(fndecl) |
| 215 | + return "\n".join(lines) |
| 216 | + |
186 | 217 | @property |
187 | 218 | def functioncount(self) -> int: |
188 | 219 | return self.cfileglobals.functioncount |
|
0 commit comments