-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove field split * Remove field loop * Remove field terminal * Remove field frontier * Remove field subsumptions * Remove method getTermHash * Remove method getNodeAttributes * Refactor and rename method getStateIdByShortHash * Refactor and rename insertNode * Refactor and rename removeNode * Remove class attribute _NODE_ATTRS * Refactor methods to_dict and from_dict * Add type annotations for fields * Change fields from List to Set where possible * Rename field states to _nodes * Create class KCFG.Node * Rename method add_node to create_node * Remove methods _encode and _decode * Create class KCFG.Edge * Rename field graph to _edges * Change edge type * Remove methods _assign and invalidateStates * Add method get_edge * Remove method getEdges * Rename get_node to node * Rename get_edge to edge * Add optional parameters to method edges * Remove methods getSuccessors and getPredecessors * Make return type of method edge Optional * Remove method getEdgeCondition * Remove methods markEdge* * Refactor abstractions * Refactor method getEdgeSentence to Edge.to_rule * Remove method getModule * Add class KCFG.Cover * Add class KCFG.EdgeLike * Simplify to_dot * Reimplement path algorithm * Reimplement transitive closure * Implement property frontier * Rename init to _init * Rename target to _target * Rename stuck to _stuck * Refactor getPathCondition * Add method prune * Add class FrozenDict * Add class Subst * Change KAtt backing data type from frozenset to FrozenDict * Change return type of KCFG.Cover.subst to Subst * Rename kastManip.removeGeneratedCells * Refactor and rename countVarOccurances * Add function if_ktype * Add function count_rhs_vars * Add further utils * Add class KRuleLike * Add class CTerm * Make kast.to_hash a cached property * Add properties for sets of nodes * Change type of KCFG.Node.term to CTerm * Change CTerm.constraints from FrozenSet to Tuple * Rename inline_generated_top * Move class Subst to module subst * Add tests for count_vars * Move AST traversal functions to module kast * Change return type of kastManip.match to Subst * Move function match from kastManip to subst * Add tests for matching property
- Loading branch information
1 parent
75f0dee
commit 47246c2
Showing
11 changed files
with
1,055 additions
and
660 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from dataclasses import dataclass | ||
from functools import cached_property | ||
from itertools import chain | ||
from typing import Iterable, Optional, Tuple | ||
|
||
from .kast import TOP, KInner, flattenLabel | ||
from .kastManip import match, splitConfigAndConstraints | ||
from .prelude import mlAnd, mlImplies | ||
from .subst import Subst | ||
|
||
|
||
@dataclass(frozen=True) | ||
class CTerm: | ||
config: KInner # TODO Optional? | ||
constraints: Tuple[KInner, ...] | ||
|
||
def __init__(self, cterm: KInner) -> None: | ||
config, constraint = splitConfigAndConstraints(cterm) | ||
constraints = tuple(flattenLabel('#And', constraint)) | ||
object.__setattr__(self, 'config', config) | ||
object.__setattr__(self, 'constraints', constraints) | ||
|
||
def __iter__(self): | ||
return chain([self.config], self.constraints) | ||
|
||
@cached_property | ||
def cterm(self) -> KInner: | ||
return mlAnd(self) | ||
|
||
@property | ||
def hash(self) -> str: | ||
return self.cterm.hash | ||
|
||
def match(self, pattern: 'CTerm') -> Optional[Tuple[Subst, KInner]]: | ||
subst = match(pattern=pattern.config, term=self.config) | ||
|
||
if subst is None: | ||
return None | ||
|
||
obligation = self._ml_impl(self.constraints, map(subst, pattern.constraints)) | ||
|
||
return subst, obligation | ||
|
||
@staticmethod | ||
def _ml_impl(antecedents: Iterable[KInner], consequents: Iterable[KInner]) -> KInner: | ||
antecedents = set(antecedents) | ||
|
||
antecedent = mlAnd(antecedents) | ||
consequent = mlAnd(set(term for term in consequents if term not in antecedents)) | ||
|
||
if antecedent == TOP: | ||
return consequent | ||
|
||
if consequent == TOP: | ||
return TOP | ||
|
||
return mlImplies(antecedent, consequent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.