Example #1
0
def _build_unary_expression(state, addr, instruction):
    opcode = instruction.opcode

    variable = _build_slot(state, addr, instruction.CD)

    # Mind the inversion
    if opcode == ins.ISFC.opcode \
            or opcode == ins.ISF.opcode \
            or opcode == ins.MOV.opcode:
        return variable

    operator = nodes.UnaryOperator()
    operator.operand = variable

    if opcode == ins.ISTC.opcode \
            or opcode == ins.IST.opcode \
            or opcode == ins.NOT.opcode:
        operator.type = nodes.UnaryOperator.T_NOT
    elif opcode == ins.UNM.opcode:
        operator.type = nodes.UnaryOperator.T_MINUS
    elif ljd.config.version_config.use_version > 2.0 and opcode == ins.ISTYPE.opcode:
        operator.type = nodes.UnaryOperator.T_TOSTRING
    elif ljd.config.version_config.use_version > 2.0 and opcode == ins.ISNUM.opcode:
        operator.type = nodes.UnaryOperator.T_TONUMBER
    else:
        assert opcode == ins.LEN.opcode
        operator.type = nodes.UnaryOperator.T_LENGTH_OPERATOR

    return operator
Example #2
0
def _build_unary_expression(state, addr, instruction):
    opcode = instruction.opcode

    # ASSIGNMENT starting from FNEW and ending at MOV
    if state.new_func and opcode == ins.MOV.opcode:
        state.new_func = False
        return _build_identifier(state, addr, instruction.CD, nodes.Identifier.T_LOCAL, True)

    variable = _build_slot(state, addr, instruction.CD)

    # Mind the inversion
    if opcode == ins.ISFC.opcode			\
            or opcode == ins.ISF.opcode	\
            or opcode == ins.MOV.opcode:
        return variable

    operator = nodes.UnaryOperator()
    operator.operand = variable

    if opcode == ins.ISTC.opcode			\
            or opcode == ins.IST.opcode	\
            or opcode == ins.NOT.opcode:
        operator.type = nodes.UnaryOperator.T_NOT
    elif opcode == ins.UNM.opcode:
        operator.type = nodes.UnaryOperator.T_MINUS
    else:
        assert opcode == ins.LEN.opcode
        operator.type = nodes.UnaryOperator.T_LENGTH_OPERATOR

    return operator
Example #3
0
def _invert(expression):
	if isinstance(expression, nodes.UnaryOperator):
		return expression.operand

	if not isinstance(expression, nodes.BinaryOperator):
		node = nodes.UnaryOperator()
		node.type = nodes.UnaryOperator.T_NOT
		node.operand = expression

		return node

	# Just in case
	expression = copy.deepcopy(expression)

	new_type = _NEGATION_MAP[expression.type]

	assert new_type is not None

	expression.type = new_type

	return expression