示例#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())}]'
     )
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())
示例#4
0
 def to_expr_str(self):
     return ExpressionString.highest(f'%[{self.code}%]')
示例#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)
示例#6
0
 def to_expr_str(self):
     code = self.members.format()
     return ExpressionString.highest(f'({code})')
示例#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()})'
     )
示例#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())}'
     )
示例#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())}]')
示例#10
0
 def to_expr_str(self):
     return ExpressionString.highest(
         f'({self.notes.format()}{str(self.val.to_expr_str())})')
示例#11
0
 def to_expr_str(self):
     return ExpressionString.highest(self.reg.name.lower())
示例#12
0
 def to_expr_str(self):
     return ExpressionString.highest(self.name)
示例#13
0
 def to_expr_str(self):
     return ExpressionString.highest(f'nondet {self.to_str()}')
示例#14
0
 def to_expr_str(self):
     if self.val >= 0:
         return ExpressionString.highest(str(self.val))
     return -ExpressionString.highest(str(-self.val))