Skip to content

Commit 9ba1590

Browse files
committed
API: remove candidate contract
1 parent 8c22b98 commit 9ba1590

20 files changed

+292
-541
lines changed

chc/api/ApiAssumption.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# The MIT License (MIT)
66
#
77
# Copyright (c) 2017-2020 Kestrel Technology LLC
8-
# Copyright (c) 2021-2022 Henny Sipma
9-
# Copyright (c) 2023 Aarno Labs LLC
8+
# Copyright (c) 2021-2022 Henny B. Sipma
9+
# Copyright (c) 2023-2024 Aarno Labs LLC
1010
#
1111
# Permission is hereby granted, free of charge, to any person obtaining a copy
1212
# of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,9 @@
2626
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2727
# SOFTWARE.
2828
# ------------------------------------------------------------------------------
29+
"""Assumption on the function api.
30+
31+
"""
2932

3033
from typing import List, TYPE_CHECKING
3134

@@ -36,6 +39,19 @@
3639

3740

3841
class ApiAssumption:
42+
"""Assumption on the function api.
43+
44+
Args:
45+
capi (CFunctionApi): parent function api
46+
id (int): identification number
47+
predicate (CPOPredicate): expression of the assumption
48+
ppos (List[int]): list of primary proof obligation id's that depend on
49+
this assumption
50+
spos (List[int]): list of supporting proof obligation id's that depend
51+
on this assumption
52+
isglobal (bool=False): assumption holds globally
53+
isfile (bool=False): assumption holds for the entire c-file
54+
"""
3955

4056
def __init__(
4157
self,

chc/api/ApiParameter.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,7 @@
2626
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2727
# SOFTWARE.
2828
# ------------------------------------------------------------------------------
29-
"""Object representation of api_parameter_t
30-
31-
cchlib/CCHLibTypes.api_parameter_t = predicate properties
32-
-------------------------------------------------
33-
type api_parameter_t =
34-
| ParFormal of int is_formal index: int
35-
| ParGlobal of string is_global name: str
36-
37-
"""
29+
"""Object representation of api_parameter_t"""
3830

3931
from typing import List, TYPE_CHECKING
4032

@@ -48,6 +40,13 @@
4840

4941

5042
class ApiParameter(InterfaceDictionaryRecord):
43+
"""Base class of formal parameter of a function.
44+
45+
Args:
46+
cd (InterfaceDictionary): The parent dictionary to resolve
47+
subexpressions
48+
ixval (IndexedTableValue): The backing record of the value
49+
"""
5150

5251
def __init__(
5352
self, cd: "InterfaceDictionary", ixval: IT.IndexedTableValue) -> None:
@@ -69,7 +68,7 @@ def __str__(self) -> str:
6968
class APFormal(ApiParameter):
7069
"""Formal parameter of a function.
7170
72-
args[0]: parameter index (starting at 1)
71+
* args[0]: parameter index (starting at 1)
7372
"""
7473

7574
def __init__(
@@ -90,6 +89,7 @@ def __str__(self) -> str:
9089

9190
@ifdregistry.register_tag("pg", ApiParameter)
9291
class APGlobal(ApiParameter):
92+
"""Global variable used in a function; treated as a formal parameter."""
9393

9494
def __init__(
9595
self, cd: "InterfaceDictionary", ixval: IT.IndexedTableValue) -> None:

chc/api/CFileCandidateContracts.py

Lines changed: 0 additions & 113 deletions
This file was deleted.

chc/api/CFileContracts.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# The MIT License (MIT)
66
#
77
# Copyright (c) 2017-2020 Kestrel Technology LLC
8-
# Copyright (c) 2020-2022 Henny Sipma
9-
# Copyright (c) 2023 Aarno Labs LLC
8+
# Copyright (c) 2020-2022 Henny B. Sipma
9+
# Copyright (c) 2023-2024 Aarno Labs LLC
1010
#
1111
# Permission is hereby granted, free of charge, to any person obtaining a copy
1212
# of this software and associated documentation files (the "Software"), to deal
@@ -26,12 +26,14 @@
2626
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2727
# SOFTWARE.
2828
# ------------------------------------------------------------------------------
29+
"""User-provided contracts for variables and functions in a c-file."""
2930

3031
import xml.etree.ElementTree as ET
3132

3233
from typing import Callable, Dict, List, Optional, TYPE_CHECKING
3334

3435
import chc.util.fileutil as UF
36+
from chc.util.loggingutil import chklogger
3537

3638
from chc.api.CFunctionContract import CFunctionContract
3739

@@ -64,10 +66,10 @@ class CFileContracts:
6466
def __init__(self, cfile: "CFile", contractpath: str) -> None:
6567
self._cfile = cfile
6668
self._contractpath = contractpath
67-
self.xnode = UF.get_contracts(self._contractpath, self._cfile.name)
69+
# self.xnode = UF.get_contracts(self._contractpath, self._cfile.name)
6870
self._functions: Dict[str, CFunctionContract] = {}
6971
self._globalvariables: Dict[str, CFileContractGlobalVar] = {}
70-
self._initialize(self.xnode)
72+
self._initialize()
7173

7274
@property
7375
def cfile(self) -> "CFile":
@@ -92,6 +94,8 @@ def function_contract(self, name: str) -> CFunctionContract:
9294
raise UF.CHCError("No function contract found for " + name)
9395

9496
def has_function_contract(self, name: str) -> bool:
97+
"""Returns true if this contract contains a function contract for name."""
98+
9599
return name in self.functions
96100

97101
def has_assertions(self) -> bool:
@@ -152,7 +156,8 @@ def __str__(self) -> str:
152156
lines.append("-" * 80)
153157
return "\n".join(lines)
154158

155-
def _initialize(self, xnode: Optional[ET.Element]) -> None:
159+
def _initialize(self) -> None:
160+
xnode = UF.get_contracts(self.contractpath, self.cfile.name)
156161
if xnode is None:
157162
return
158163
gvnode = xnode.find("global-variables")
@@ -161,7 +166,7 @@ def _initialize(self, xnode: Optional[ET.Element]) -> None:
161166
name = gnode.get("name")
162167
if name is None:
163168
raise UF.CHCError("No name specified for global variable")
164-
gvinfo = self.cfile.declarations.get_global_varinfo_by_name(name)
169+
gvinfo = self.cfile.get_global_varinfo_by_name(name)
165170
gconst = "const" in gnode.attrib and gnode.get("const") == "yes"
166171
gval = gnode.get("value")
167172
gvalue = int(gval) if gval else None
@@ -172,4 +177,5 @@ def _initialize(self, xnode: Optional[ET.Element]) -> None:
172177
if ffnode is not None:
173178
for fnode in ffnode.findall("function"):
174179
fn = CFunctionContract(self, fnode)
180+
chklogger.logger.info("Function contract found for %s", fn.name)
175181
self._functions[fn.name] = fn

chc/api/CFunctionApi.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# The MIT License (MIT)
66
#
77
# Copyright (c) 2017-2020 Kestrel Technology LLC
8-
# Copyright (c) 2020-2022 Henny Sipma
9-
# Copyright (c) 2023 Aarno Labs LLC
8+
# Copyright (c) 2020-2022 Henny B. Sipma
9+
# Copyright (c) 2023-2024 Aarno Labs LLC
1010
#
1111
# Permission is hereby granted, free of charge, to any person obtaining a copy
1212
# of this software and associated documentation files (the "Software"), to deal
@@ -29,7 +29,7 @@
2929

3030
import xml.etree.ElementTree as ET
3131

32-
from typing import Callable, Dict, List, Optional, Tuple, TYPE_CHECKING
32+
from typing import Callable, cast, Dict, List, Optional, Tuple, TYPE_CHECKING
3333

3434
from chc.api.ApiAssumption import ApiAssumption
3535
from chc.api.ContractAssumption import ContractAssumption
@@ -44,7 +44,7 @@
4444
from chc.api.XPredicate import XPredicate
4545
from chc.app.CApplication import CApplication
4646
from chc.app.CFile import CFile
47-
from chc.app.CTyp import CFunArg
47+
from chc.app.CTyp import CFunArg, CTypFun
4848
from chc.app.CFunction import CFunction
4949

5050
memory_free_functions = ["free", "realloc"]
@@ -187,7 +187,7 @@ def global_assumption_requests(self) -> Dict[int, GlobalAssumption]:
187187
self.xmsg(
188188
"ipr attribute missing in global-assumption-requests"))
189189
id = int(xid)
190-
p = self.cfile.predicatedictionary.get_predicate(id)
190+
p = self.cfile.interfacedictionary.get_xpredicate(id)
191191
ppos = IT.get_attribute_int_list(x, "ppos")
192192
spos = IT.get_attribute_int_list(x, "spos")
193193
gas = GlobalAssumption(self, id, p, ppos, spos)
@@ -226,7 +226,11 @@ def contract_condition_failures(self) -> List[Tuple[str, str]]:
226226

227227
@property
228228
def parameters(self) -> List["CFunArg"]:
229-
return self.cfun.ftype.funargs.arguments
229+
ftype = cast("CTypFun", self.cfun.ftype)
230+
if ftype.funargs is not None:
231+
return ftype.funargs.arguments
232+
else:
233+
raise UF.CHCError("Function signature without parameters")
230234
# return self.cfun.ftype.get_args().get_args()
231235

232236
@property

0 commit comments

Comments
 (0)