aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/cython/Cython/Compiler/UtilityCode.py
diff options
context:
space:
mode:
authororivej <orivej@yandex-team.ru>2022-02-10 16:44:49 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:49 +0300
commit718c552901d703c502ccbefdfc3c9028d608b947 (patch)
tree46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/tools/cython/Cython/Compiler/UtilityCode.py
parente9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff)
downloadydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/tools/cython/Cython/Compiler/UtilityCode.py')
-rw-r--r--contrib/tools/cython/Cython/Compiler/UtilityCode.py116
1 files changed, 58 insertions, 58 deletions
diff --git a/contrib/tools/cython/Cython/Compiler/UtilityCode.py b/contrib/tools/cython/Cython/Compiler/UtilityCode.py
index 98e9ab5bfb..91daffe65f 100644
--- a/contrib/tools/cython/Cython/Compiler/UtilityCode.py
+++ b/contrib/tools/cython/Cython/Compiler/UtilityCode.py
@@ -16,7 +16,7 @@ class NonManglingModuleScope(Symtab.ModuleScope):
def add_imported_entry(self, name, entry, pos):
entry.used = True
- return super(NonManglingModuleScope, self).add_imported_entry(name, entry, pos)
+ return super(NonManglingModuleScope, self).add_imported_entry(name, entry, pos)
def mangle(self, prefix, name=None):
if name:
@@ -28,13 +28,13 @@ class NonManglingModuleScope(Symtab.ModuleScope):
else:
return Symtab.ModuleScope.mangle(self, prefix)
-
+
class CythonUtilityCodeContext(StringParseContext):
scope = None
- def find_module(self, module_name, relative_to=None, pos=None, need_pxd=True, absolute_fallback=True):
- if relative_to:
- raise AssertionError("Relative imports not supported in utility code.")
+ def find_module(self, module_name, relative_to=None, pos=None, need_pxd=True, absolute_fallback=True):
+ if relative_to:
+ raise AssertionError("Relative imports not supported in utility code.")
if module_name != self.module_name:
if module_name not in self.modules:
raise AssertionError("Only the cython cimport is supported.")
@@ -42,7 +42,7 @@ class CythonUtilityCodeContext(StringParseContext):
return self.modules[module_name]
if self.scope is None:
- self.scope = NonManglingModuleScope(
+ self.scope = NonManglingModuleScope(
self.prefix, module_name, parent_module=None, context=self, cpp=self.cpp)
return self.scope
@@ -68,8 +68,8 @@ class CythonUtilityCode(Code.UtilityCodeBase):
is_cython_utility = True
def __init__(self, impl, name="__pyxutil", prefix="", requires=None,
- file=None, from_scope=None, context=None, compiler_directives=None,
- outer_module_scope=None):
+ file=None, from_scope=None, context=None, compiler_directives=None,
+ outer_module_scope=None):
# 1) We need to delay the parsing/processing, so that all modules can be
# imported without import loops
# 2) The same utility code object can be used for multiple source files;
@@ -90,25 +90,25 @@ class CythonUtilityCode(Code.UtilityCodeBase):
self.prefix = prefix
self.requires = requires or []
self.from_scope = from_scope
- self.outer_module_scope = outer_module_scope
- self.compiler_directives = compiler_directives
+ self.outer_module_scope = outer_module_scope
+ self.compiler_directives = compiler_directives
self.context_types = context_types
- def __eq__(self, other):
- if isinstance(other, CythonUtilityCode):
- return self._equality_params() == other._equality_params()
- else:
- return False
-
- def _equality_params(self):
- outer_scope = self.outer_module_scope
- while isinstance(outer_scope, NonManglingModuleScope):
- outer_scope = outer_scope.outer_scope
- return self.impl, outer_scope, self.compiler_directives
-
- def __hash__(self):
- return hash(self.impl)
-
+ def __eq__(self, other):
+ if isinstance(other, CythonUtilityCode):
+ return self._equality_params() == other._equality_params()
+ else:
+ return False
+
+ def _equality_params(self):
+ outer_scope = self.outer_module_scope
+ while isinstance(outer_scope, NonManglingModuleScope):
+ outer_scope = outer_scope.outer_scope
+ return self.impl, outer_scope, self.compiler_directives
+
+ def __hash__(self):
+ return hash(self.impl)
+
def get_tree(self, entries_only=False, cython_scope=None):
from .AnalysedTreeTransforms import AutoTestDictTransform
# The AutoTestDictTransform creates the statement "__test__ = {}",
@@ -117,14 +117,14 @@ class CythonUtilityCode(Code.UtilityCodeBase):
excludes = [AutoTestDictTransform]
from . import Pipeline, ParseTreeTransforms
- context = CythonUtilityCodeContext(
+ context = CythonUtilityCodeContext(
self.name, compiler_directives=self.compiler_directives,
cpp=cython_scope.is_cpp() if cython_scope else False)
context.prefix = self.prefix
context.cython_scope = cython_scope
#context = StringParseContext(self.name)
- tree = parse_from_strings(
- self.name, self.impl, context=context, allow_struct_enum_decorator=True)
+ tree = parse_from_strings(
+ self.name, self.impl, context=context, allow_struct_enum_decorator=True)
pipeline = Pipeline.create_pipeline(context, 'pyx', exclude_classes=excludes)
if entries_only:
@@ -143,33 +143,33 @@ class CythonUtilityCode(Code.UtilityCodeBase):
pipeline = Pipeline.insert_into_pipeline(pipeline, transform,
before=before)
- def merge_scope(scope):
- def merge_scope_transform(module_node):
- module_node.scope.merge_in(scope)
+ def merge_scope(scope):
+ def merge_scope_transform(module_node):
+ module_node.scope.merge_in(scope)
return module_node
- return merge_scope_transform
-
- if self.from_scope:
- pipeline = Pipeline.insert_into_pipeline(
- pipeline, merge_scope(self.from_scope),
- before=ParseTreeTransforms.AnalyseDeclarationsTransform)
-
- for dep in self.requires:
- if isinstance(dep, CythonUtilityCode) and hasattr(dep, 'tree') and not cython_scope:
- pipeline = Pipeline.insert_into_pipeline(
- pipeline, merge_scope(dep.tree.scope),
- before=ParseTreeTransforms.AnalyseDeclarationsTransform)
-
- if self.outer_module_scope:
- # inject outer module between utility code module and builtin module
- def scope_transform(module_node):
- module_node.scope.outer_scope = self.outer_module_scope
- return module_node
-
- pipeline = Pipeline.insert_into_pipeline(
- pipeline, scope_transform,
- before=ParseTreeTransforms.AnalyseDeclarationsTransform)
-
+ return merge_scope_transform
+
+ if self.from_scope:
+ pipeline = Pipeline.insert_into_pipeline(
+ pipeline, merge_scope(self.from_scope),
+ before=ParseTreeTransforms.AnalyseDeclarationsTransform)
+
+ for dep in self.requires:
+ if isinstance(dep, CythonUtilityCode) and hasattr(dep, 'tree') and not cython_scope:
+ pipeline = Pipeline.insert_into_pipeline(
+ pipeline, merge_scope(dep.tree.scope),
+ before=ParseTreeTransforms.AnalyseDeclarationsTransform)
+
+ if self.outer_module_scope:
+ # inject outer module between utility code module and builtin module
+ def scope_transform(module_node):
+ module_node.scope.outer_scope = self.outer_module_scope
+ return module_node
+
+ pipeline = Pipeline.insert_into_pipeline(
+ pipeline, scope_transform,
+ before=ParseTreeTransforms.AnalyseDeclarationsTransform)
+
if self.context_types:
# inject types into module scope
def scope_transform(module_node):
@@ -184,7 +184,7 @@ class CythonUtilityCode(Code.UtilityCodeBase):
(err, tree) = Pipeline.run_pipeline(pipeline, tree, printtree=False)
assert not err, err
- self.tree = tree
+ self.tree = tree
return tree
def put_code(self, output):
@@ -213,12 +213,12 @@ class CythonUtilityCode(Code.UtilityCodeBase):
entries.pop('__builtins__')
entries.pop('__doc__')
- for entry in entries.values():
+ for entry in entries.values():
entry.utility_code_definition = self
entry.used = used
original_scope = tree.scope
- dest_scope.merge_in(original_scope, merge_unused=True, whitelist=whitelist)
+ dest_scope.merge_in(original_scope, merge_unused=True, whitelist=whitelist)
tree.scope = dest_scope
for dep in self.requires:
@@ -227,7 +227,7 @@ class CythonUtilityCode(Code.UtilityCodeBase):
return original_scope
-
+
def declare_declarations_in_scope(declaration_string, env, private_type=True,
*args, **kwargs):
"""