if self.optional_arg_count:
scope = StructOrUnionScope()
arg_count_member = '%sn' % Naming.pyrex_prefix
- scope.declare_var(arg_count_member, PyrexTypes.c_int_type, self.pos)
+ binding = Binding(name = arg_count_member)
+ scope.declare_var(
+ binding, type = PyrexTypes.c_int_type, pos = self.pos)
for arg in func_type_args[len(func_type_args)-self.optional_arg_count:]:
- scope.declare_var(arg.name, arg.type, arg.pos, allow_pyobject = 1)
+ binding = Binding(name = arg.name)
+ scope.declare_var(
+ binding, type = arg.type, allow_pyobject = 1,
+ pos = arg.pos)
struct_cname = env.mangle(Naming.opt_arg_prefix, self.base.name)
binding = Binding(name = struct_cname, cname = struct_cname)
self.op_args_struct = env.global_scope().declare_struct_or_union(
if self.in_pxd and not self.extern:
error(self.pos,
"Only 'extern' C variable declaration allowed in .pxd file")
- entry = dest_scope.WTK_declare_var(
+ entry = dest_scope.declare_var(
binding, type = type, is_cdef = 1, pos = declarator.pos)
entry.needs_property = need_property
if entry and entry.type.is_cfunction and not self.is_wrapper:
warning(self.pos, "Overriding cdef method with def method.", 5)
binding = Binding(name = name)
+ if env.is_c_class_scope:
+ binding.extern = True
entry = env.declare_pyfunction(
binding, allow_redefine=not self.is_wrapper, pos = self.pos)
self.entry = entry
env.control_flow.set_state((), (arg.name, 'source'), 'arg')
env.control_flow.set_state((), (arg.name, 'initialized'), True)
if arg.needs_conversion:
- arg.entry = env.declare_var(arg.name, arg.type, arg.pos)
+ binding = Binding(name = arg.name)
+ arg.entry = env.declare_var(
+ binding, type = arg.type, pos = arg.pos)
if arg.type.is_pyobject:
arg.entry.init = "0"
arg.entry.init_to_none = 0
type = PyrexTypes.unspecified_type
else:
type = py_object_type
- entry = env.declare_var(arg.name, type, arg.pos)
+ binding = Binding(name = arg.name)
+ entry = env.declare_var(binding, type = type, pos = arg.pos)
entry.used = 1
entry.init = "0"
entry.init_to_none = 0
if type is None:
error(type_node.pos, "Unknown type")
else:
- env.declare_var(var.value, type, var.pos, is_cdef = True)
+ binding = Binding(name = var.value)
+ env.declare_var(
+ binding, type = type, is_cdef = True,
+ pos = var.pos)
self.__class__ = PassStatNode
def analyse_expressions(self, env):
error(lhs.pos, "Invalid declaration")
return
for var, pos in vars:
- env.declare_var(var, type, pos, is_cdef = True)
+ binding = Binding(name = var)
+ env.declare_var(
+ binding, type = type, is_cdef = True,
+ pos = pos)
if len(args) == 2:
# we have a value
self.rhs = args[1]
binding, kind = func_name, scope = scope,
pos = self.rhs.pos)
for member, type, pos in members:
- scope.declare_var(member, type, pos)
+ binding = Binding(name = member)
+ scope.declare_var(binding, type = type, pos = pos)
if self.declaration_only:
return
self.sue_entries.append(entry)
return entry
- def declare_var(self, name, type, pos,
- cname = None, visibility = 'private', is_cdef = 0):
- binding = self._WTK_setup(name, cname, visibility)
- return self.WTK_declare_var(
- binding, type, is_cdef, pos = pos)
-
- def WTK_declare_var(self, binding, type,
- is_cdef = 0, pos = None):
+ def declare_var(self, binding, type, is_cdef = 0, pos = None):
# Add an entry for a variable.
if not binding.cname:
if binding.c_visibility != 'private':
if entry and not entry.type.is_cfunction:
error(pos, "'%s' already declared" % binding.name)
error(entry.pos, "Previous declaration is here")
- entry = self.WTK_declare_var(binding, py_object_type, pos = pos)
+ entry = self.declare_var(binding, py_object_type, pos = pos)
entry.signature = pyfunction_signature
self.pyfunc_entries.append(entry)
return entry
return self._declare_pyfunction(
binding, entry = entry, pos = pos)
else: # declare entry stub
- self.WTK_declare_var(
- binding, py_object_type, pos = pos)
- entry = self.WTK_declare_var(Binding(name=None, cname=binding.name),
- py_object_type, pos = pos)
+ self.declare_var(binding, py_object_type, pos = pos)
+ entry = self.declare_var(
+ Binding(name=None, cname=binding.name),
+ py_object_type, pos = pos)
entry.name = EncodedString(binding.name)
entry.qualified_name = self.qualify_name(binding.name)
entry.signature = pyfunction_signature
def declare_lambda_function(self, binding, pos = None):
# Add an entry for an anonymous Python function.
- entry = self.WTK_declare_var(binding, py_object_type, pos = pos)
+ entry = self.declare_var(binding, py_object_type, pos = pos)
entry.name = EncodedString(binding.cname)
entry.func_cname = binding.cname
entry.signature = pyfunction_signature
entry = self.lookup_here(name)
if not entry:
binding = self._WTK_setup(name, None, 'private')
- entry = self.WTK_declare_var(binding, py_object_type)
+ entry = self.declare_var(binding, py_object_type)
return entry
def lookup_type(self, name):
for name, definition in self.builtin_entries.iteritems():
cname, type = definition
binding = self._WTK_setup(name, cname, 'private')
- self.WTK_declare_var(binding, type)
+ self.declare_var(binding, type)
def lookup(self, name, language_level=None):
# 'language_level' is passed by ModuleScope
self.undeclared_cached_builtins = []
self.namespace_cname = self.module_cname
for name in ['__builtins__', '__name__', '__file__', '__doc__']:
- self.declare_var(EncodedString(name), py_object_type, None)
+ binding = Binding(name = EncodedString(name))
+ self.declare_var(binding, type = py_object_type)
def qualifying_scope(self):
return self.parent_module
and binding.name != 'xrange'):
# 'xrange' is special cased in Code.py
if self.has_import_star:
- entry = self.WTK_declare_var(
- binding, py_object_type, pos = pos)
+ entry = self.declare_var(binding, py_object_type, pos = pos)
return entry
elif self.outer_scope is not None:
return self.outer_scope.declare_builtin(binding, pos = pos)
warning(pos, "'%s' redeclared " % scope.name, 0)
return None
else:
- entry = self.declare_var(as_name, py_object_type, pos)
+ binding = Binding(name=as_name)
+ entry = self.declare_var(binding, type =py_object_type, pos = pos)
entry.as_module = scope
self.add_imported_module(scope)
return entry
- def declare_var(self, name, type, pos,
- cname = None, visibility = 'private', is_cdef = 0):
- binding = self._WTK_setup(name, cname, visibility)
- return self.WTK_declare_var(
- binding, type, is_cdef, pos = pos)
-
- def WTK_declare_var(self, binding, type,
- is_cdef = 0, pos = None):
+ def declare_var(self, binding, type, is_cdef = 0, pos = None):
# Add an entry for a global variable. If it is a Python
# object type, and not declared with cdef, it will live
# in the module dictionary, otherwise it will be a C
# global variable.
- entry = Scope.WTK_declare_var(
- self, binding, type, is_cdef, pos = pos)
+ entry = Scope.declare_var(
+ self, binding, type, is_cdef = is_cdef, pos = pos)
if binding.c_visibility not in ('private', 'public'):
error(pos, "Module-level variable cannot be declared %s" %
binding.c_visibility)
entry = self.lookup_here(name)
if not entry:
binding = self._WTK_setup(name, name, 'private')
- self.WTK_declare_var(binding, py_object_type, pos = pos)
+ self.declare_var(binding, type = py_object_type, pos = pos)
def use_utility_code(self, new_code):
if new_code is not None:
self.control_flow.set_state((), (binding.name, 'source'), 'arg')
return entry
- def declare_var(self, name, type, pos,
- cname = None, visibility = 'private', is_cdef = 0):
- binding = self._WTK_setup(name, cname, visibility)
- return self.WTK_declare_var(
- binding, type, is_cdef, pos = pos)
-
- def WTK_declare_var(self, binding, type,
- is_cdef = 0, pos = None):
+ def declare_var(self, binding, type, is_cdef = 0, pos = None):
# Add an entry for a local variable.
if binding.c_visibility != 'private': #visibility in ('public', 'readonly'):
error(pos, "Local variable cannot be declared %s" % binding.c_visibility)
- entry = Scope.WTK_declare_var(
- self, binding, type, is_cdef,
- pos = pos)
+ entry = Scope.declare_var(self, binding, type, is_cdef, pos = pos)
if type.is_pyobject and not Options.init_local_none:
entry.init = "0"
entry.init_to_none = (type.is_pyobject or type.is_unspecified) and Options.init_local_none
def mangle(self, prefix, name):
return '%s%s' % (self.genexp_prefix, self.parent_scope.mangle(self, prefix, name))
- def declare_var(self, name, type, pos,
- cname = None, visibility = 'private', is_cdef = True):
- binding = self._WTK_setup(name, cname, visibility)
- return self.WTK_declare_var(
- binding, type, is_cdef, pos = pos)
-
- def WTK_declare_var(self, binding, type,
- is_cdef = 0, pos = None):
+ def declare_var(self, binding, type, is_cdef = 0, pos = None):
if type is unspecified_type:
# if the outer scope defines a type for this variable, inherit it
outer_entry = self.outer_scope.lookup(binding.name)
def __init__(self, name="?"):
Scope.__init__(self, name, None, None)
- def declare_var(self, name, type, pos,
- cname = None, visibility = 'private', is_cdef = 0, allow_pyobject = 0):
- binding = self._WTK_setup(name, cname, visibility)
- return self.WTK_declare_var(
- binding, type, is_cdef, allow_pyobject, pos = pos)
-
- def WTK_declare_var(self, binding, type,
- is_cdef = 0, allow_pyobject = 0, pos = None):
+ def declare_var(self, binding, type, is_cdef = 0, allow_pyobject = 0,
+ pos = None):
# Add an entry for an attribute.
if not binding.cname:
binding.cname = binding.name
def declare_cfunction(self, binding, type, defining = 0, in_pxd = 0,
modifiers = (), utility_code = None, pos = None):
- return self.WTK_declare_var(binding, type, pos=pos)
+ return self.declare_var(binding, type = type, pos = pos)
class ClassScope(Scope):
is_py_class_scope = 1
- def declare_var(self, name, type, pos,
- cname = None, visibility = 'private', is_cdef = 0):
- binding = self._WTK_setup(name, cname, visibility)
- return self.WTK_declare_var(
- binding, type, is_cdef, pos = pos)
-
- def WTK_declare_var(self, binding, type,
- is_cdef = 0, pos = None):
+ def declare_var(self, binding, type, is_cdef = 0, pos = None):
if type is unspecified_type:
type = py_object_type
# Add an entry for a class attribute.
- entry = Scope.WTK_declare_var(
- self, binding, type, is_cdef,
- pos = pos)
+ entry = Scope.declare_var(
+ self, binding, type = type, is_cdef = is_cdef, pos = pos)
entry.is_pyglobal = 1
entry.is_pyclass_attr = 1
return entry
self.parent_type.base_type.scope is not None and
self.parent_type.base_type.scope.needs_gc())
- def declare_var(self, name, type, pos,
- cname = None, visibility = 'private', is_cdef = 0):
- binding = self._WTK_setup(name, cname, visibility)
- if visibility == 'private':
- binding.visibility = 'private'
- return self.WTK_declare_var(
- binding, type, is_cdef, pos = pos)
-
- def WTK_declare_var(self, binding, type,
- is_cdef = 0, pos = None):
+ def declare_var(self, binding, type, is_cdef = 0, pos = None):
if is_cdef:
# Add an entry for an attribute.
if self.defined:
if type is unspecified_type:
type = py_object_type
# Add an entry for a class attribute.
- entry = Scope.WTK_declare_var(
- self, binding, type, is_cdef, pos = pos)
+ entry = Scope.declare_var(
+ self, binding, type, is_cdef = is_cdef, pos = pos)
entry.is_member = 1
entry.is_pyglobal = 1 # xxx: is_pyglobal changes behaviour in so many places that
# I keep it in for now. is_member should be enough
if binding.name == "__new__":
error(pos, "__new__ method of extension type will change semantics "
"in a future version of Pyrex and Cython. Use __cinit__ instead.")
- name = binding.name
- entry = self.declare_var(name, py_object_type, pos, visibility='extern')
- special_sig = get_special_method_signature(name)
- #entry = self.WTK_declare_var(
- # binding, py_object_type, pos = pos)
- #special_sig = get_special_method_signature(binding.name)
+ if not binding.extern:
+ error(pos, "C class pyfunctions may only be extern")
+ entry = self.declare_var(binding, type = py_object_type, pos = pos)
+ special_sig = get_special_method_signature(binding.name)
if special_sig:
# Special methods get put in the method table with a particular
# signature declared in advance.
self.directives = outer_scope.directives
self.inherited_var_entries = []
- def declare_var(self, name, type, pos,
- cname = None, visibility = 'extern', is_cdef = 0, allow_pyobject = 0):
- binding = self._WTK_setup(name, cname, visibility)
- return self.WTK_declare_var(
- binding, type, is_cdef, allow_pyobject, pos = pos)
-
- def WTK_declare_var(self, binding, type,
- is_cdef = 0, allow_pyobject = 0, pos = None):
+ def declare_var(self, binding, type, is_cdef = 0, allow_pyobject = 0,
+ pos = None):
+ if not binding.extern:
+ error(pos, "c++ variables must be 'extern'")
# Add an entry for an attribute.
if not binding.cname:
binding.cname = binding.name
binding.name = '<init>'
type.return_type = self.lookup(self.name).type
prev_entry = self.lookup_here(binding.name)
- entry = self.WTK_declare_var(binding, type, pos = pos)
+ entry = self.declare_var(binding, type = type, pos = pos)
if prev_entry:
entry.overloaded_alternatives = prev_entry.all_alternatives()
entry.utility_code = utility_code
else:
# binding = Binding()
# binding.pull(entry)
-# scope.WTK_declare_var(
-# binding,
-# type = entry.type.specialize(values), pos = entry.pos)
+# scope.declare_var(
+# binding, type = entry.type.specialize(values),
+# pos = entry.pos)
for e in entry.all_alternatives():
binding = Binding()
binding.pull(e)