How to use the nuitka.nodes.ExpressionBases.ExpressionChildrenHavingBase.childGetter 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 / DictionaryNodes.py View on Github external
class ExpressionDictOperationGet(ExpressionChildrenHavingBase):
    kind = "EXPRESSION_DICT_OPERATION_GET"

    named_children = ("dict", "key")

    @calledWithBuiltinArgumentNamesDecorator
    def __init__(self, dict_arg, key, source_ref):
        assert dict_arg is not None
        assert key is not None

        ExpressionChildrenHavingBase.__init__(
            self, values={"dict": dict_arg, "key": key}, source_ref=source_ref
        )

    getDict = ExpressionChildrenHavingBase.childGetter("dict")
    getKey = ExpressionChildrenHavingBase.childGetter("key")

    def computeExpression(self, trace_collection):
        trace_collection.onExceptionRaiseExit(BaseException)

        return self, None, None


class StatementDictOperationUpdate(StatementChildrenHavingBase):
    """ Update dict value.

        This is mainly used for re-formulations, where a dictionary
        update will be performed on what is known not to be a
        general mapping.
    """
github Nuitka / Nuitka / nuitka / nodes / ExecEvalNodes.py View on Github external
return self, None, None

    def mayRaiseException(self, exception_type):
        return False


class ExpressionBuiltinCompile(ExpressionChildrenHavingBase):
    kind = "EXPRESSION_BUILTIN_COMPILE"

    named_children = ("source", "filename", "mode", "flags", "dont_inherit", "optimize")
    getSourceCode = ExpressionChildrenHavingBase.childGetter("source")
    getFilename = ExpressionChildrenHavingBase.childGetter("filename")
    getMode = ExpressionChildrenHavingBase.childGetter("mode")
    getFlags = ExpressionChildrenHavingBase.childGetter("flags")
    getDontInherit = ExpressionChildrenHavingBase.childGetter("dont_inherit")
    getOptimize = ExpressionChildrenHavingBase.childGetter("optimize")

    def __init__(
        self, source_code, filename, mode, flags, dont_inherit, optimize, source_ref
    ):
        ExpressionChildrenHavingBase.__init__(
            self,
            values={
                "source": source_code,
                "filename": filename,
                "mode": mode,
                "flags": flags,
                "dont_inherit": dont_inherit,
                "optimize": optimize,
            },
            source_ref=source_ref,
        )
github Nuitka / Nuitka / nuitka / nodes / BuiltinIntegerNodes.py View on Github external
def __init__(self, value, source_ref):
            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 ShapeTypeLongDerived

        def computeExpression(self, trace_collection):
            return self.subnode_value.computeExpressionLong(
                long_node=self, trace_collection=trace_collection
            )

        getValue = ExpressionChildrenHavingBase.childGetter("value")

        def mayRaiseException(self, exception_type):
            return self.subnode_value.mayRaiseExceptionLong(exception_type)

    class ExpressionBuiltinLong2(ExpressionBuiltinIntLong2Base):
        kind = "EXPRESSION_BUILTIN_LONG2"

        builtin_spec = BuiltinParameterSpecs.builtin_long_spec
        builtin = long

        def getTypeShape(self):
            return ShapeTypeLong
github Nuitka / Nuitka / nuitka / nodes / BuiltinDictNodes.py View on Github external
from nuitka.specs.BuiltinParameterSpecs import builtin_dict_spec

from .BuiltinIteratorNodes import ExpressionBuiltinIter1
from .ConstantRefNodes import makeConstantRefNode
from .DictionaryNodes import ExpressionKeyValuePair, ExpressionMakeDict
from .ExpressionBases import ExpressionChildrenHavingBase
from .NodeMakingHelpers import wrapExpressionWithNodeSideEffects


class ExpressionBuiltinDict(ExpressionChildrenHavingBase):
    kind = "EXPRESSION_BUILTIN_DICT"

    named_children = ("pos_arg", "pairs")
    getPositionalArgument = ExpressionChildrenHavingBase.childGetter("pos_arg")
    getNamedArgumentPairs = ExpressionChildrenHavingBase.childGetter("pairs")

    def __init__(self, pos_arg, pairs, source_ref):
        assert type(pos_arg) not in (tuple, list), source_ref
        assert type(pairs) in (tuple, list), source_ref

        ExpressionChildrenHavingBase.__init__(
            self,
            values={
                "pos_arg": pos_arg,
                "pairs": tuple(
                    ExpressionKeyValuePair(
                        makeConstantRefNode(key, source_ref),
                        value,
                        value.getSourceReference(),
                    )
                    for key, value in pairs
github Nuitka / Nuitka / nuitka / nodes / ImportNodes.py View on Github external
# For "package.sub_package.module" we also need to import the package,
        # because the imported_module not be found, as it's not a module, e.g.
        # in the case of "os.path" or "six.moves".
        self.package_modules_desc = None

        self.finding = None

        self.type_shape = ShapeTypeModule

        self.builtin_module = None

    getImportName = ExpressionChildrenHavingBase.childGetter("name")
    getFromList = ExpressionChildrenHavingBase.childGetter("fromlist")
    getGlobals = ExpressionChildrenHavingBase.childGetter("globals")
    getLocals = ExpressionChildrenHavingBase.childGetter("locals")
    getLevel = ExpressionChildrenHavingBase.childGetter("level")

    def _consider(self, trace_collection, module_filename, module_package):
        assert module_package is None or (
            type(module_package) is str and module_package != ""
        ), repr(module_package)

        module_filename = os.path.normpath(module_filename)

        module_name, module_kind = getModuleNameAndKindFromFilename(module_filename)

        if module_kind is not None:
            if module_package is None:
                module_fullpath = module_name
            else:
                module_fullpath = module_package + "." + module_name
github Nuitka / Nuitka / nuitka / nodes / BuiltinFormatNodes.py View on Github external
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

    def computeExpression(self, trace_collection):
        # TODO: Can use the format built-in on compile time constants at least.

        value = self.getValue()
github Nuitka / Nuitka / nuitka / nodes / ExecEvalNodes.py View on Github external
from .ExpressionBases import ExpressionChildrenHavingBase
from .NodeBases import StatementChildHavingBase, StatementChildrenHavingBase
from .NodeMakingHelpers import (
    convertNoneConstantToNone,
    makeStatementOnlyNodesFromExpressions,
)


class ExpressionBuiltinEval(ExpressionChildrenHavingBase):
    kind = "EXPRESSION_BUILTIN_EVAL"

    named_children = ("source", "globals", "locals")
    getSourceCode = ExpressionChildrenHavingBase.childGetter("source")
    getGlobals = ExpressionChildrenHavingBase.childGetter("globals")
    getLocals = ExpressionChildrenHavingBase.childGetter("locals")

    def __init__(self, source_code, globals_arg, locals_arg, source_ref):
        ExpressionChildrenHavingBase.__init__(
            self,
            values={
                "source": source_code,
                "globals": globals_arg,
                "locals": locals_arg,
            },
            source_ref=source_ref,
        )

    def computeExpression(self, trace_collection):
        # TODO: Attempt for constant values to do it.
        return self, None, None
github Nuitka / Nuitka / nuitka / nodes / BuiltinOpenNodes.py View on Github external
):
        kind = "EXPRESSION_BUILTIN_OPEN"

        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__(
github Nuitka / Nuitka / nuitka / nodes / ExceptionNodes.py View on Github external
def __init__(self, exception_type, exception_value, source_ref):
        ExpressionChildrenHavingBase.__init__(
            self,
            values={
                "exception_type": exception_type,
                "exception_value": exception_value,
            },
            source_ref=source_ref,
        )

    def willRaiseException(self, exception_type):
        # One thing is clear, it will raise. TODO: Match exception_type more
        # closely if it is predictable.
        return exception_type is BaseException

    getExceptionType = ExpressionChildrenHavingBase.childGetter("exception_type")
    getExceptionValue = ExpressionChildrenHavingBase.childGetter("exception_value")

    def computeExpression(self, trace_collection):
        return self, None, None

    def computeExpressionDrop(self, statement, trace_collection):
        result = self.asStatement()

        del self.parent

        return (
            result,
            "new_raise",
            """\
Propagated implicit raise expression to raise statement.""",
        )
github Nuitka / Nuitka / nuitka / nodes / BuiltinOpenNodes.py View on Github external
kind = "EXPRESSION_BUILTIN_OPEN"

        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,