Second round of WTK_ form normalization.
authorW. Trevor King <wking@drexel.edu>
Thu, 3 Mar 2011 22:09:29 +0000 (17:09 -0500)
committerW. Trevor King <wking@drexel.edu>
Thu, 3 Mar 2011 23:37:25 +0000 (18:37 -0500)
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
Cython/Compiler/Symtab.py

index 35532eb00942ca06680320a5da3a775b12a04385..188f787e10d2d108afdfe7e3bb9a437592f825b2 100644 (file)
@@ -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:
index dc783496faca3843988e2136e2275cbeae571ec7..4f71846f7c3ada2e61ef2ca7e92a43d6d312142f 100644 (file)
@@ -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)