Ejemplo n.º 1
0
 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())}]'
     )
Ejemplo n.º 2
0
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'
Ejemplo n.º 3
0
 def to_expr_str(self):
     return ExpressionString.highest(self.rvalue.format_for_expr())
Ejemplo n.º 4
0
 def to_expr_str(self):
     return ExpressionString.highest(f'%[{self.code}%]')
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 def to_expr_str(self):
     code = self.members.format()
     return ExpressionString.highest(f'({code})')
Ejemplo n.º 7
0
 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()})'
     )
Ejemplo n.º 8
0
 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())}'
     )
Ejemplo n.º 9
0
 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())}]')
Ejemplo n.º 10
0
 def to_expr_str(self):
     return ExpressionString.highest(
         f'({self.notes.format()}{str(self.val.to_expr_str())})')
Ejemplo n.º 11
0
 def to_expr_str(self):
     return ExpressionString.highest(self.reg.name.lower())
Ejemplo n.º 12
0
 def to_expr_str(self):
     return ExpressionString.highest(self.name)
Ejemplo n.º 13
0
 def to_expr_str(self):
     return ExpressionString.highest(f'nondet {self.to_str()}')
Ejemplo n.º 14
0
 def to_expr_str(self):
     if self.val >= 0:
         return ExpressionString.highest(str(self.val))
     return -ExpressionString.highest(str(-self.val))