Skip to content

Commit

Permalink
Add: is_read_only()
Browse files Browse the repository at this point in the history
  • Loading branch information
glx22 committed Oct 17, 2020
1 parent 316106d commit dfb4499
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nml/expression/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ def reduce(self, id_dicts = [], unknown_id_fatal = True):
def collect_references(self):
from itertools import chain
return list(chain.from_iterable(v.collect_references() for v in self.values))

def is_read_only(self):
return all(v.is_read_only() for v in self.values)
8 changes: 8 additions & 0 deletions nml/expression/base_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ def collect_references(self):
"""
return []

def is_read_only(self):
"""
Check if this expression store values.
@return: True if the expression doesn't store values.
"""
return True

def is_boolean(self):
"""
Check if this expression is limited to 0 or 1 as value.
Expand Down
6 changes: 6 additions & 0 deletions nml/expression/bin_not.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def supported_by_actionD(self, raise_error):
def collect_references(self):
return self.expr.collect_references()

def is_read_only(self):
return self.expr.is_read_only()

def __str__(self):
return "~" + str(self.expr)

Expand Down Expand Up @@ -82,6 +85,9 @@ def supported_by_actionD(self, raise_error):
def collect_references(self):
return self.expr.collect_references()

def is_read_only(self):
return self.expr.is_read_only()

def is_boolean(self):
return True

Expand Down
3 changes: 3 additions & 0 deletions nml/expression/binop.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ def supported_by_actionD(self, raise_error):
def collect_references(self):
return self.expr1.collect_references() + self.expr2.collect_references()

def is_read_only(self):
return self.expr1.is_read_only() and self.expr2.is_read_only()

def is_boolean(self):
if self.op in (nmlop.AND, nmlop.OR, nmlop.XOR):
return self.expr1.is_boolean() and self.expr2.is_boolean()
Expand Down
3 changes: 3 additions & 0 deletions nml/expression/bitmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ def collect_references(self):
from itertools import chain
return list(chain.from_iterable(v.collect_references() for v in self.values))

def is_read_only(self):
return all(v.is_read_only() for v in self.values)

def __str__(self):
return "bitmask(" + ", ".join(str(e) for e in self.values) + ")"
3 changes: 3 additions & 0 deletions nml/expression/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def supported_by_actionD(self, raise_error):
def collect_references(self):
return self.expr.collect_references()

def is_read_only(self):
return self.expr.is_read_only()

def is_boolean(self):
return True

Expand Down
4 changes: 4 additions & 0 deletions nml/expression/storage_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,7 @@ def supported_by_actionD(self, raise_error):

def collect_references(self):
return self.register.collect_references() + (self.value.collect_references() if self.value is not None else [])

def is_read_only(self):
assert(self.info['store'] == (self.value is not None))
return (not self.info['store']) and self.register.is_read_only()
3 changes: 3 additions & 0 deletions nml/expression/ternaryop.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def supported_by_actionD(self, raise_error):
def collect_references(self):
return self.guard.collect_references() + self.expr1.collect_references() + self.expr2.collect_references()

def is_read_only(self):
return self.expr1.is_read_only() and self.expr2.is_read_only()

def is_boolean(self):
return self.expr1.is_boolean() and self.expr2.is_boolean()

Expand Down

0 comments on commit dfb4499

Please sign in to comment.