Skip to content

Commit 9c7b666

Browse files
committed
JSON: add program context to proof obligations
1 parent 020659c commit 9c7b666

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

chc/app/CContext.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ def __init__(
7373
def name(self) -> str:
7474
return self.tags[0]
7575

76+
def has_data_id(self) -> bool:
77+
return len(self.args) > 0
78+
7679
@property
7780
def data_id(self) -> int:
7881
if len(self.args) > 0:
@@ -81,6 +84,13 @@ def data_id(self) -> int:
8184
raise UF.CHCError(
8285
"Context node " + self.name + " does not have a data-id")
8386

87+
def has_additional_info(self) -> bool:
88+
return len(self.tags) > 1
89+
90+
@property
91+
def info(self) -> List[str]:
92+
return self.tags[1:]
93+
8494
def __str__(self) -> str:
8595
if len(self.args) == 0:
8696
return "_".join(self.tags)

chc/app/CHVersion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
chcversion: str = "0.2.0-2024-05-19"
1+
chcversion: str = "0.2.0-2024-11-04"

chc/cmdline/jsonresultutil.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
from chc.api.CFunctionApi import CFunctionApi
4242
from chc.api.GlobalAssumption import GlobalAssumption
4343
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
4448
from chc.app.CFile import CFile
4549
from chc.app.CFunction import CFunction
4650
from chc.proof.CFunctionPO import CFunctionPO
@@ -142,12 +146,62 @@ def fn_api_to_json_result(fapi: "CFunctionApi") -> JSONResult:
142146
return JSONResult("fnapi", content, "ok")
143147

144148

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+
145198
def ppo_to_json_result(po: "CFunctionPO") -> JSONResult:
146199
content: Dict[str, Any] = {}
147200
content["index"] = po.po_index
148201
content["line"] = po.line
149202
content["status"] = po.status
150203
content["predicate"] = str(po.predicate)
204+
content["context"] = programcontext_to_json_result(po.context).content
151205
if po.is_closed:
152206
content["expl"] = po.explanation
153207
else:

0 commit comments

Comments
 (0)