From a5ada3ba5432190c208eaf693b1321dcb2459792 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 3 Mar 2011 17:09:29 -0500 Subject: [PATCH] Second round of WTK_ form normalization. This round removes the old interfaces to the following methods: * declare_enum * _declare_pyfunction * add_imported_entry * declare_module * declare_arg * declare_property --- Cython/Compiler/Nodes.py | 26 +++++++++++-------- Cython/Compiler/Symtab.py | 54 +++++++++++---------------------------- 2 files changed, 30 insertions(+), 50 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 35532eb0..188f787e 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1102,7 +1102,7 @@ class CEnumDefNode(StatNode): def analyse_declarations(self, env): binding = Binding() binding.pull(self) - self.entry = env.WTK_declare_enum( + self.entry = env.declare_enum( binding, typedef_flag = self.typedef_flag, pos = self.pos) if self.items is not None: if self.in_pxd and not env.in_cinclude: @@ -1547,7 +1547,8 @@ class FuncDefNode(StatNode, BlockNode): elif not arg.type.is_complete() and not arg.type.is_array: error(arg.pos, "Argument type '%s' is incomplete" % arg.type) - return env.declare_arg(arg.name, arg.type, arg.pos) + binding = Binding(name = arg.name) + return env.declare_arg(binding, type = arg.type, pos = arg.pos) def generate_arg_type_test(self, arg, code): # Generate type test for one argument. @@ -3290,7 +3291,7 @@ class CClassDefNode(ClassDefNode): if self.shadow: home_scope.lookup(self.class_name).as_variable = self.entry if home_scope is not env and self.extern: - env.add_imported_entry(self.class_name, self.entry, self.pos) + env.add_imported_entry(self.entry, self.class_name, pos = self.pos) self.scope = scope = self.entry.type.scope if scope is not None: scope.directives = env.directives @@ -3337,7 +3338,8 @@ class PropertyNode(StatNode): child_attrs = ["body"] def analyse_declarations(self, env): - entry = env.declare_property(self.name, self.doc, self.pos) + binding = Binding(name = self.name) + entry = env.declare_property(binding, self.doc, pos = self.pos) if entry: entry.scope.directives = env.directives self.body.analyse_declarations(entry.scope) @@ -5232,15 +5234,16 @@ class CImportStatNode(StatNode): module_scope = top_module_scope for name in names[1:]: submodule_scope = module_scope.find_submodule(name) - module_scope.declare_module(name, submodule_scope, self.pos) + module_scope.declare_module( + submodule_scope, name, pos = self.pos) module_scope = submodule_scope if self.as_name: - env.declare_module(self.as_name, module_scope, self.pos) + env.declare_module(module_scope, self.as_name, pos = self.pos) else: - env.declare_module(top_name, top_module_scope, self.pos) + env.declare_module(top_module_scope, top_name, pos = self.pos) else: name = self.as_name or self.module_name - env.declare_module(name, module_scope, self.pos) + env.declare_module(module_scope, name, pos = self.pos) def analyse_expressions(self, env): pass @@ -5266,7 +5269,7 @@ class FromCImportStatNode(StatNode): for pos, name, as_name, kind in self.imported_names: if name == "*": for local_name, entry in module_scope.entries.items(): - env.add_imported_entry(local_name, entry, pos) + env.add_imported_entry(entry, local_name, pos = pos) else: entry = module_scope.lookup(name) if entry: @@ -5282,14 +5285,15 @@ class FromCImportStatNode(StatNode): else: submodule_scope = env.context.find_module(name, relative_to = module_scope, pos = self.pos) if submodule_scope.parent_module is module_scope: - env.declare_module(as_name or name, submodule_scope, self.pos) + env.declare_module( + submodule_scope, as_name or name, pos = self.pos) else: error(pos, "Name '%s' not declared in module '%s'" % (name, self.module_name)) if entry: local_name = as_name or name - env.add_imported_entry(local_name, entry, pos) + env.add_imported_entry(entry, local_name, pos = pos) def declaration_matches(self, entry, kind): if not entry.is_type: diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index dc783496..4f71846f 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -552,13 +552,7 @@ class Scope(object): error(pos, "%s '%s' previously declared as '%s'" % ( type_name, entry.name, vis_diff)) - def declare_enum(self, name, pos, cname, typedef_flag, - visibility = 'private'): - binding = self._WTK_setup(name, cname, visibility=visibility) - return self.WTK_declare_enum(binding, pos, typedef_flag) - - def WTK_declare_enum(self, binding, pos, - typedef_flag): + def declare_enum(self, binding, typedef_flag, pos = None): if binding.name: if not binding.cname: if self.in_cinclude or binding.c_visibility == 'public': @@ -607,12 +601,7 @@ class Scope(object): def WTK_declare_builtin(self, binding, pos): return self.outer_scope.WTK_declare_builtin(binding, pos) - def _declare_pyfunction(self, name, pos, visibility='extern', entry=None): - binding = self._WTK_setup(name, name, visibility) - return self.WTK__declare_pyfunction(binding, entry, pos = pos) - - def WTK__declare_pyfunction(self, binding, - entry = None, pos = None): + def _declare_pyfunction(self, binding, entry = None, pos = None): if entry and not entry.type.is_cfunction: error(pos, "'%s' already declared" % binding.name) error(entry.pos, "Previous declaration is here") @@ -630,15 +619,17 @@ class Scope(object): # Add an entry for a Python function. entry = self.lookup_here(binding.name) if not allow_redefine or Options.disable_function_redefinition: - return self.WTK__declare_pyfunction( - binding, entry = entry, pos = pos) + binding.extern = 1 + binding.c_visibility = binding.visibility = 'public' + return self._declare_pyfunction(binding, entry = entry, pos = pos) if entry: if entry.type.is_unspecified: entry.type = py_object_type elif entry.type is not py_object_type: - return self.WTK__declare_pyfunction( - binding, entry = entry, - pos = pos) + binding.extern = 1 + binding.c_visibility = binding.visibility = 'public' + return self._declare_pyfunction( + binding, entry = entry, pos = pos) else: # declare entry stub self.WTK_declare_var( binding, py_object_type, pos = pos) @@ -1117,10 +1108,7 @@ class ModuleScope(Scope): for m in scope.cimported_modules: self.add_imported_module(m) - def add_imported_entry(self, name, entry, pos): - return self.WTK_add_imported_entry(entry, pos, as_name=name) - - def WTK_add_imported_entry(self, entry, pos, as_name=None): + def add_imported_entry(self, entry, as_name = None, pos = None): if not as_name: as_name = entry.name if entry not in self.entries: @@ -1128,10 +1116,7 @@ class ModuleScope(Scope): else: warning(pos, "'%s' redeclared " % entry.name, 0) - def declare_module(self, name, scope, pos): - return self.WTK_declare_module(scope, pos, as_name=name) - - def WTK_declare_module(self, scope, pos, as_name=None): + def declare_module(self, scope, as_name = None, pos = None): # Declare a cimported module. This is represented as a # Python module-level variable entry with a module # scope attached to it. Reports an error and returns @@ -1468,14 +1453,10 @@ class LocalScope(Scope): def mangle(self, prefix, name): return prefix + name - def declare_arg(self, name, type, pos): - binding = self._WTK_setup(name, None, 'private') - binding.cname = self.mangle(Naming.var_prefix, binding.name) - return self.WTK_declare_arg( - binding, type, pos = pos) - - def WTK_declare_arg(self, binding, type, pos = None): + def declare_arg(self, binding, type, pos = None): # Add an entry for an argument of a function. + if binding.cname is None: + binding.cname = self.mangle(Naming.var_prefix, binding.name) entry = self.WTK_declare(binding, type, pos = pos) entry.is_variable = 1 if type.is_pyobject: @@ -1941,12 +1922,7 @@ class CClassScope(ClassScope): entry.as_variable = var_entry return entry - def declare_property(self, name, doc, pos): - binding = self._WTK_setup(name, name, 'private') - return self.WTK_declare_property(binding, doc, pos = pos) - - def WTK_declare_property( - self, binding, doc, pos = None): + def declare_property(self, binding, doc, pos = None): entry = self.lookup_here(binding.name) if entry is None: entry = self.WTK_declare(binding, py_object_type, pos = pos) -- 2.26.2