Add a predicate_leafs() method.

This collects all of the leaf predicates that go into a compound predicate.
Current leaf predicates are:

- Settings for ISA predicates, and
- FieldPredicates for instruction predicates.
This commit is contained in:
Jakob Stoklund Olesen
2016-08-25 09:50:23 -07:00
parent 46dec8a11d
commit a24daf5ded
2 changed files with 13 additions and 0 deletions

View File

@@ -41,6 +41,9 @@ class Setting(object):
"""
return self.group
def predicate_leafs(self, leafs):
leafs.add(self)
class BoolSetting(Setting):
"""

View File

@@ -68,6 +68,13 @@ class Predicate(object):
def predicate_context(self):
return self.context
def predicate_leafs(self, leafs):
"""
Collect all leaf predicates into the `leafs` set.
"""
for part in self.parts:
part.predicate_leafs(leafs)
class And(Predicate):
"""
@@ -164,6 +171,9 @@ class FieldPredicate(object):
"""
return self.field.format
def predicate_leafs(self, leafs):
leafs.add(self)
def rust_predicate(self, prec):
"""
Return a string of Rust code that evaluates this predicate.