Exemplo n.º 1
0
def makeRaiseExceptionReplacementExpression(expression, exception_type,
                                            exception_value):
    source_ref = expression.getSourceReference()

    assert type( exception_type ) is str

    if shallWarnImplicitRaises():
        warning(
            "%s: Static exception raise",
            expression.getSourceReference().getAsString(),
        )

    result = ExpressionRaiseException(
        exception_type  = ExpressionBuiltinExceptionRef(
            exception_name = exception_type,
            source_ref     = source_ref
        ),
        exception_value = makeConstantReplacementNode(
            constant = exception_value,
            node     = expression
        ),
        source_ref      = source_ref
    )

    return result
Exemplo n.º 2
0
def makeRaiseExceptionReplacementExpression(expression, exception_type,
                                            exception_value):
    from .ExceptionNodes import ExpressionRaiseException

    source_ref = expression.getSourceReference()

    assert type(exception_type) is str

    if shallWarnImplicitRaises():
        warning(
            "%s: Static exception raise",
            expression.getSourceReference().getAsString(),
        )

    result = ExpressionRaiseException(
        exception_type  = ExpressionBuiltinExceptionRef(
            exception_name = exception_type,
            source_ref     = source_ref
        ),
        exception_value = makeConstantReplacementNode(
            constant = exception_value,
            node     = expression
        ),
        source_ref      = source_ref
    )

    return result
Exemplo n.º 3
0
def makeRaiseExceptionReplacementStatement(statement, exception_type,
                                           exception_value):
    from .ExceptionNodes import StatementRaiseExceptionImplicit
    from .BuiltinRefNodes import ExpressionBuiltinExceptionRef

    source_ref = statement.getSourceReference()

    assert type(exception_type) is str

    if shallWarnImplicitRaises():
        warning(
            '%s: Will always raise exception: "%s(%s)"',
            source_ref.getAsString(),
            exception_type,
            exception_value
        )

    result = StatementRaiseExceptionImplicit(
        exception_type  = ExpressionBuiltinExceptionRef(
            exception_name = exception_type,
            source_ref     = source_ref
        ),
        exception_value = makeConstantReplacementNode(
            constant = exception_value,
            node     = statement
        ),
        exception_cause = None,
        exception_trace = None,
        source_ref      = source_ref
    )

    return result
Exemplo n.º 4
0
def makeRaiseExceptionReplacementExpression(expression, exception_type,
                                            exception_value):
    from .ExceptionNodes import ExpressionRaiseException
    from .BuiltinRefNodes import ExpressionBuiltinExceptionRef

    source_ref = expression.getSourceReference()

    assert type(exception_type) is str

    if shallWarnImplicitRaises():
        warning(
            "%s: Will always raise exception %s(%s)",
            expression.getSourceReference().getAsString(),
            exception_type,
            exception_value
        )

    result = ExpressionRaiseException(
        exception_type  = ExpressionBuiltinExceptionRef(
            exception_name = exception_type,
            source_ref     = source_ref
        ),
        exception_value = makeConstantReplacementNode(
            constant = exception_value,
            node     = expression
        ),
        source_ref      = source_ref
    )

    return result
Exemplo n.º 5
0
def makeRaiseExceptionReplacementStatement(statement, exception_type, exception_value):
    from .ExceptionNodes import StatementRaiseExceptionImplicit
    from .BuiltinRefNodes import ExpressionBuiltinExceptionRef

    source_ref = statement.getSourceReference()

    assert type(exception_type) is str

    if shallWarnImplicitRaises():
        warning(
            '%s: Will always raise exception: "%s(%s)"',
            source_ref.getAsString(),
            exception_type,
            exception_value,
        )

    result = StatementRaiseExceptionImplicit(
        exception_type=ExpressionBuiltinExceptionRef(
            exception_name=exception_type, source_ref=source_ref
        ),
        exception_value=makeConstantReplacementNode(
            constant=exception_value, node=statement
        ),
        exception_cause=None,
        exception_trace=None,
        source_ref=source_ref,
    )

    return result