Add string conversions for predicates and encodings.

This is just used for printing better comments in generated code.
This commit is contained in:
Jakob Stoklund Olesen
2016-08-26 08:50:47 -07:00
parent 0c6e0e9cb7
commit 7cb975ce63
3 changed files with 20 additions and 0 deletions

View File

@@ -65,6 +65,14 @@ class Predicate(object):
(p.predicate_context() for p in parts))
assert self.context, "Incompatible predicate parts"
def __str__(self):
s = '{}({})'.format(
type(self).__name__,
' ,'.join(map(str, self.parts)))
if self.name:
s = '{}={}'.format(self.name, s)
return s
def predicate_context(self):
return self.context
@@ -164,6 +172,10 @@ class FieldPredicate(object):
self.function = function
self.args = args
def __str__(self):
args = (self.field.name,) + tuple(map(str, self.args))
return '{}({})'.format(self.function, ', '.join(args))
def predicate_context(self):
"""
This predicate can be evaluated in the context of an instruction