|
41 | 41 | from chc.api.CFunctionApi import CFunctionApi |
42 | 42 | from chc.api.GlobalAssumption import GlobalAssumption |
43 | 43 | from chc.api.PostConditionRequest import PostConditionRequest |
| 44 | + from chc.app.CContext import CContextNode |
| 45 | + from chc.app.CContext import CfgContext |
| 46 | + from chc.app.CContext import ExpContext |
| 47 | + from chc.app.CContext import ProgramContext |
44 | 48 | from chc.app.CFile import CFile |
45 | 49 | from chc.app.CFunction import CFunction |
46 | 50 | from chc.proof.CFunctionPO import CFunctionPO |
@@ -142,12 +146,62 @@ def fn_api_to_json_result(fapi: "CFunctionApi") -> JSONResult: |
142 | 146 | return JSONResult("fnapi", content, "ok") |
143 | 147 |
|
144 | 148 |
|
| 149 | +def contextnode_to_json_result(node: "CContextNode") -> JSONResult: |
| 150 | + content: Dict[str, Any] = {} |
| 151 | + if node.has_data_id(): |
| 152 | + content["ctxtid"] = node.data_id |
| 153 | + content["name"] = node.name |
| 154 | + if node.has_additional_info(): |
| 155 | + content["info"] = node.info |
| 156 | + return JSONResult("contextnode", content, "ok") |
| 157 | + |
| 158 | + |
| 159 | +def expcontext_to_json_result(ectxt: "ExpContext") -> JSONResult: |
| 160 | + content: Dict[str, Any] = {} |
| 161 | + content["nodes"] = nodes = [] |
| 162 | + for n in ectxt.nodes: |
| 163 | + cnode = contextnode_to_json_result(n) |
| 164 | + if not cnode.is_ok: |
| 165 | + return JSONResult("contextnode", {}, "fail", cnode.reason) |
| 166 | + else: |
| 167 | + nodes.append(cnode.content) |
| 168 | + return JSONResult("expcontext", content, "ok") |
| 169 | + |
| 170 | + |
| 171 | +def cfgcontext_to_json_result(cctxt: "CfgContext") -> JSONResult: |
| 172 | + content: Dict[str, Any] = {} |
| 173 | + content["nodes"] = nodes = [] |
| 174 | + for n in cctxt.nodes: |
| 175 | + cnode = contextnode_to_json_result(n) |
| 176 | + if not cnode.is_ok: |
| 177 | + return JSONResult("contextnode", {}, "fail", cnode.reason) |
| 178 | + else: |
| 179 | + nodes.append(cnode.content) |
| 180 | + return JSONResult("cfgcontext", content, "ok") |
| 181 | + |
| 182 | + |
| 183 | +def programcontext_to_json_result(pctxt: "ProgramContext") -> JSONResult: |
| 184 | + content: Dict[str, Any] = {} |
| 185 | + jcfgcontext = cfgcontext_to_json_result(pctxt.cfg_context) |
| 186 | + if not jcfgcontext.is_ok: |
| 187 | + return JSONResult("programcontext", {}, "fail", jcfgcontext.reason) |
| 188 | + else: |
| 189 | + content["cfg-context"] = jcfgcontext.content |
| 190 | + jexpcontext = expcontext_to_json_result(pctxt.exp_context) |
| 191 | + if not jexpcontext.is_ok: |
| 192 | + return JSONResult("programcontext", {}, "fail", jexpcontext.reason) |
| 193 | + else: |
| 194 | + content["exp-context"] = jexpcontext.content |
| 195 | + return JSONResult("programcontext", content, "ok") |
| 196 | + |
| 197 | + |
145 | 198 | def ppo_to_json_result(po: "CFunctionPO") -> JSONResult: |
146 | 199 | content: Dict[str, Any] = {} |
147 | 200 | content["index"] = po.po_index |
148 | 201 | content["line"] = po.line |
149 | 202 | content["status"] = po.status |
150 | 203 | content["predicate"] = str(po.predicate) |
| 204 | + content["context"] = programcontext_to_json_result(po.context).content |
151 | 205 | if po.is_closed: |
152 | 206 | content["expl"] = po.explanation |
153 | 207 | else: |
|
0 commit comments