def to_expr_str(self): self.notes.assert_no_comments() notes = '' if self.notes.empty else '\n' # If expr is not an atom, add parentheses. return ExpressionString.highest( f'{self.expr.to_expr_str():HIGHEST}[{notes}{str(self.offset.to_expr_str())}]' )
def test_expression_string(): # Declare a few variables. a = ExpressionString.highest('a') b = ExpressionString.highest('b') c = ExpressionString.highest('c') d = ExpressionString.highest('d') e = ExpressionString.highest('e') f = ExpressionString.highest('f') assert str(a + b + c + d) == 'a + b + c + d' assert str((a + b) + (c + (d + e) + f)) == 'a + b + c + d + e + f' assert str((a + b) - (c - (d - e + f))) == 'a + b - (c - (d - e + f))' assert str(-a + (-b)) == '(-a) + (-b)' assert str(a * b * c * d) == 'a * b * c * d' assert str((a * b) * (c * (d * e) * f)) == 'a * b * c * d * e * f' assert str((a * b) / (c / (d / e * f))) == 'a * b / (c / (d / e * f))' assert str((-a) * b) == '(-a) * b' assert str(-(a * b)) == '-(a * b)' assert str((a + b) * c + d + e * f) == '(a + b) * c + d + e * f' assert str(a - (b - c) / (d - e) / f) == 'a - (b - c) / (d - e) / f' assert str((a**b)**c) == '(a^b)^c' assert str(a**b**c) == 'a^(b^c)' assert str(a**((b**c)**(d**e))**f) == 'a^(((b^c)^(d^e))^f)' assert str(a / b**(c + d) * (e + f)) == 'a / b^(c + d) * (e + f)' assert str(-a) == '-a' assert str(-(a + b) + (-(a - b)) - (-(a - b))) == '(-(a + b)) + (-(a - b)) - (-(a - b))' assert str(-(a * b) * (-(a / b)) / (-(a / b))) == '(-(a * b)) * (-(a / b)) / (-(a / b))' assert str((-((-a)**(-b)))**c) == '(-((-a)^(-b)))^c' assert str(-(-a)) == '-(-a)' assert str((a**b).address_of().address_of()) == '&&(a^b)' assert str((-((-a).address_of())).address_of()) == '&(-&(-a))' assert str(a.address_of() - b.address_of()) == '&a - &b'
def to_expr_str(self): return ExpressionString.highest(self.rvalue.format_for_expr())
def to_expr_str(self): return ExpressionString.highest(f'%[{self.code}%]')
def to_expr_str(self): abs_format = str(abs( self.val)) if self.format_str is None else self.format_str if self.val >= 0: return ExpressionString.highest(abs_format) return -ExpressionString.highest(abs_format)
def to_expr_str(self): code = self.members.format() return ExpressionString.highest(f'({code})')
def to_expr_str(self): self.notes.assert_no_comments() notes = '' if self.notes.empty else '\n' return ExpressionString.highest( f'cast({notes}{str(self.expr.to_expr_str())}, {self.dest_type.format()})' )
def to_expr_str(self): # If expr is not an atom, add parentheses. return ExpressionString.highest( f'{self.expr.to_expr_str():HIGHEST}.{str(self.member.to_expr_str())}' )
def to_expr_str(self): self.notes.assert_no_comments() notes = '' if self.notes.empty else '\n' return ExpressionString.highest( f'[{notes}{str(self.addr.to_expr_str())}]')
def to_expr_str(self): return ExpressionString.highest( f'({self.notes.format()}{str(self.val.to_expr_str())})')
def to_expr_str(self): return ExpressionString.highest(self.reg.name.lower())
def to_expr_str(self): return ExpressionString.highest(self.name)
def to_expr_str(self): return ExpressionString.highest(f'nondet {self.to_str()}')
def to_expr_str(self): if self.val >= 0: return ExpressionString.highest(str(self.val)) return -ExpressionString.highest(str(-self.val))