How to use the nuitka.nodes.ExpressionBases.ExpressionChildrenHavingBase function in Nuitka

To help you get started, we’ve selected a few Nuitka examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Nuitka / Nuitka / nuitka / nodes / BuiltinOpenNodes.py View on Github external
named_children = (
            "filename",
            "mode",
            "buffering",
            "encoding",
            "errors",
            "newline",
            "closefd",
            "opener",
        )
        getEncoding = ExpressionChildrenHavingBase.childGetter("encoding")
        getErrors = ExpressionChildrenHavingBase.childGetter("errors")
        getNewline = ExpressionChildrenHavingBase.childGetter("newline")
        getCloseFd = ExpressionChildrenHavingBase.childGetter("closefd")
        getOpener = ExpressionChildrenHavingBase.childGetter("opener")

        def __init__(
            self,
            filename,
            mode,
            buffering,
            encoding,
            errors,
            newline,
            closefd,
            opener,
            source_ref,
        ):
            ExpressionChildrenHavingBase.__init__(
                self,
                values={
github Nuitka / Nuitka / nuitka / nodes / AttributeNodes.py View on Github external
These directly go to slots, and are performed for with statements
        of Python2.7 or higher.
    """

    kind = "EXPRESSION_ATTRIBUTE_LOOKUP_SPECIAL"

    def computeExpression(self, trace_collection):
        return self.getLookupSource().computeExpressionAttributeSpecial(
            lookup_node=self,
            attribute_name=self.getAttributeName(),
            trace_collection=trace_collection,
        )


class ExpressionBuiltinGetattr(ExpressionChildrenHavingBase):
    """ Built-in "getattr".

        Typical code like this: getattr(object_arg, name, default)

        The default is optional, but computed before the lookup is done.
    """

    kind = "EXPRESSION_BUILTIN_GETATTR"

    named_children = ("object", "name", "default")
    getLookupSource = ExpressionChildrenHavingBase.childGetter("object")
    getAttribute = ExpressionChildrenHavingBase.childGetter("name")
    getDefault = ExpressionChildrenHavingBase.childGetter("default")

    @calledWithBuiltinArgumentNamesDecorator
    def __init__(self, object_arg, name, default, source_ref):
github Nuitka / Nuitka / nuitka / nodes / SideEffectNodes.py View on Github external
if child.isExpressionSideEffects():
            real_value.extend(child.getSideEffects())
            real_value.append(child.getExpression())
        else:
            assert child.isExpression()

            real_value.append(child)

    return tuple(real_value)


class ExpressionSideEffects(ExpressionChildrenHavingBase):
    kind = "EXPRESSION_SIDE_EFFECTS"

    named_children = ("side_effects", "expression")
    getSideEffects = ExpressionChildrenHavingBase.childGetter("side_effects")
    setSideEffects = ExpressionChildrenHavingBase.childSetter("side_effects")
    getExpression = ExpressionChildrenHavingBase.childGetter("expression")

    checkers = {"side_effects": checkSideEffects}

    def __init__(self, side_effects, expression, source_ref):
        # We expect to be not used without there actually being side effects.
        assert side_effects

        ExpressionChildrenHavingBase.__init__(
            self,
            values={"side_effects": tuple(side_effects), "expression": expression},
            source_ref=source_ref,
        )

    def isExpressionSideEffects(self):
github Nuitka / Nuitka / nuitka / nodes / LocalsDictNodes.py View on Github external
from nuitka.PythonVersions import python_version
from nuitka.tree.TreeHelpers import makeStatementsSequence

from .AssignNodes import (
    StatementAssignmentVariable,
    StatementDelVariable,
    StatementReleaseVariable,
)
from .ConditionalNodes import ExpressionConditional
from .ConstantRefNodes import ExpressionConstantDictEmptyRef
from .ExpressionBases import ExpressionBase, ExpressionChildrenHavingBase
from .NodeBases import StatementBase, StatementChildHavingBase
from .VariableRefNodes import ExpressionTempVariableRef


class ExpressionLocalsVariableRefORFallback(ExpressionChildrenHavingBase):
    kind = "EXPRESSION_LOCALS_VARIABLE_REF_OR_FALLBACK"

    named_children = ("fallback",)

    def __init__(self, locals_scope, variable_name, fallback, source_ref):
        ExpressionChildrenHavingBase.__init__(
            self, values={"fallback": fallback}, source_ref=source_ref
        )

        assert locals_scope is not None

        self.locals_scope = locals_scope
        self.variable = locals_scope.getLocalsDictVariable(variable_name)

        self.variable_trace = None
github Nuitka / Nuitka / nuitka / nodes / BuiltinIntegerNodes.py View on Github external
ExpressionChildrenHavingBase.__init__(
            self, values={"value": value}, source_ref=source_ref
        )

    def getTypeShape(self):
        # TODO: Depending on input type shape and value, we should improve this.
        return ShapeTypeIntOrLongDerived

    def computeExpression(self, trace_collection):
        value = self.getValue()

        return value.computeExpressionInt(
            int_node=self, trace_collection=trace_collection
        )

    getValue = ExpressionChildrenHavingBase.childGetter("value")


class ExpressionBuiltinIntLong2Base(ExpressionSpecBasedComputationBase):
    named_children = ("value", "base")

    # Note: Version specific, may be allowed or not.
    try:
        int(base=2)
    except TypeError:
        base_only_value = False
    else:
        base_only_value = True

    # To be overloaded by child classes with int/long.
    builtin = int
github Nuitka / Nuitka / nuitka / nodes / BuiltinFormatNodes.py View on Github external
from nuitka.PythonVersions import python_version
from nuitka.specs import BuiltinParameterSpecs

from .ExpressionBases import (
    ExpressionBuiltinSingleArgBase,
    ExpressionChildrenHavingBase,
)
from .NodeMakingHelpers import makeStatementExpressionOnlyReplacementNode
from .shapes.BuiltinTypeShapes import (
    ShapeTypeIntOrLong,
    ShapeTypeStr,
    ShapeTypeStrOrUnicode,
)


class ExpressionBuiltinFormat(ExpressionChildrenHavingBase):
    kind = "EXPRESSION_BUILTIN_FORMAT"

    named_children = ("value", "format_spec")
    getValue = ExpressionChildrenHavingBase.childGetter("value")
    getFormatSpec = ExpressionChildrenHavingBase.childGetter("format_spec")
    setFormatSpec = ExpressionChildrenHavingBase.childSetter("format_spec")

    def __init__(self, value, format_spec, source_ref):
        ExpressionChildrenHavingBase.__init__(
            self,
            values={"value": value, "format_spec": format_spec},
            source_ref=source_ref,
        )

    def getTypeShape(self):
        return ShapeTypeStrOrUnicode
github Nuitka / Nuitka / nuitka / nodes / ComparisonNodes.py View on Github external
def __init__(self, left, right, source_ref):
        assert left.isExpression()
        assert right.isExpression()

        ExpressionChildrenHavingBase.__init__(
            self, values={"left": left, "right": right}, source_ref=source_ref
        )
github Nuitka / Nuitka / nuitka / nodes / FunctionNodes.py View on Github external
if needs_visit:
            function_body.computeFunctionRaw(trace_collection)

        # TODO: Function collection may now know something.
        return self, None, None

    def mayHaveSideEffects(self):
        # Using a function has no side effects.
        return False

    def mayRaiseException(self, exception_type):
        return False


class ExpressionFunctionCall(ExpressionChildrenHavingBase):
    """ Shared function call.

        This is for calling created function bodies with multiple users. Not
        clear if such a thing should exist. But what this will do is to have
        respect for the fact that there are multiple such calls.
    """

    kind = "EXPRESSION_FUNCTION_CALL"

    named_children = ("function", "values")

    def __init__(self, function, values, source_ref):
        assert function.isExpressionFunctionCreation()

        ExpressionChildrenHavingBase.__init__(
            self,
github Nuitka / Nuitka / nuitka / nodes / CoroutineNodes.py View on Github external
#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#     See the License for the specific language governing permissions and
#     limitations under the License.
#
""" Nodes for coroutine objects and their creations.

Coroutines are turned into normal functions that create generator objects,
whose implementation lives here. The creation itself also lives here.

"""

from .ExpressionBases import ExpressionChildrenHavingBase
from .FunctionNodes import ExpressionFunctionEntryPointBase


class ExpressionMakeCoroutineObject(ExpressionChildrenHavingBase):
    kind = "EXPRESSION_MAKE_COROUTINE_OBJECT"

    named_children = ("coroutine_ref",)

    getCoroutineRef = ExpressionChildrenHavingBase.childGetter("coroutine_ref")

    def __init__(self, coroutine_ref, source_ref):
        assert coroutine_ref.getFunctionBody().isExpressionCoroutineObjectBody()

        ExpressionChildrenHavingBase.__init__(
            self, values={"coroutine_ref": coroutine_ref}, source_ref=source_ref
        )

        self.variable_closure_traces = None

    def getDetailsForDisplay(self):
github Nuitka / Nuitka / nuitka / nodes / BuiltinRangeNodes.py View on Github external
if result >= high:
            return None
        else:
            return makeConstantReplacementNode(constant=result, node=self)

    def isKnownToBeIterable(self, count):
        return count is None or count == self.getIterationLength()


class ExpressionBuiltinRange3(
    ExpressionBuiltinRangeMixin, ExpressionChildrenHavingBase
):
    kind = "EXPRESSION_BUILTIN_RANGE3"

    named_children = ("low", "high", "step")
    getLow = ExpressionChildrenHavingBase.childGetter("low")
    getHigh = ExpressionChildrenHavingBase.childGetter("high")
    getStep = ExpressionChildrenHavingBase.childGetter("step")

    def __init__(self, low, high, step, source_ref):
        ExpressionChildrenHavingBase.__init__(
            self, values={"low": low, "high": high, "step": step}, source_ref=source_ref
        )

    builtin_spec = BuiltinParameterSpecs.builtin_range_spec

    def computeExpression(self, trace_collection):
        assert python_version < 300

        low = self.getLow()
        high = self.getHigh()
        step = self.getStep()