Exemplo n.º 1
0
    def visit_Num(self, new: ast27.Num) -> Expression:
        value = new.n
        is_inverse = False
        if str(new.n).startswith('-'):  # Hackish because of complex.
            value = -new.n
            is_inverse = True

        expr = None  # type: Expression
        if isinstance(value, int):
            expr = IntExpr(value)
        elif isinstance(value, float):
            expr = FloatExpr(value)
        elif isinstance(value, complex):
            expr = ComplexExpr(value)
        else:
            raise RuntimeError('num not implemented for ' + str(type(new.n)))

        if is_inverse:
            expr = UnaryExpr('-', expr)

        return expr
Exemplo n.º 2
0
    def visit_Num(self, n: ast27.Num) -> Expression:
        # The n field has the type complex, but complex isn't *really*
        # a parent of int and float, and this causes isinstance below
        # to think that the complex branch is always picked. Avoid
        # this by throwing away the type.
        value: object = n.n
        is_inverse = False
        if str(n.n).startswith('-'):  # Hackish because of complex.
            value = -n.n
            is_inverse = True

        if isinstance(value, int):
            expr: Expression = IntExpr(value)
        elif isinstance(value, float):
            expr = FloatExpr(value)
        elif isinstance(value, complex):
            expr = ComplexExpr(value)
        else:
            raise RuntimeError('num not implemented for ' + str(type(n.n)))

        if is_inverse:
            expr = UnaryExpr('-', expr)

        return self.set_line(expr, n)
Exemplo n.º 3
0
 def visit_float_expr(self, node: FloatExpr) -> Node:
     return FloatExpr(node.value)