Пример #1
0
	def declare_cfunction(self, name, type, pos,
			cname = None, visibility = 'private', defining = 0, api = 0, in_pxd = 0):
		if get_special_method_signature(name):
			error(pos, "Special methods must be declared with 'def', not 'cdef'")
		args = type.args
		if not args:
			error(pos, "C method has no self argument")
		elif not args[0].type.same_as(self.parent_type):
			error(pos, "Self argument of C method does not match parent type")
		entry = self.lookup_here(name)
		if entry:
			if not entry.is_cfunction:
				entry.redeclared(pos)
			elif entry.is_builtin_method:
				self.overriding_builtin_method(name, pos)
			else:
				if defining and entry.func_cname:
					error(pos, "'%s' already defined" % name)
				if not entry.type.same_as(type, as_cmethod = 1):
					error(pos, "Signature does not match previous declaration")
					error(entry.pos, "Previous declaration is here")
		else:
			if self.defined:
				error(pos,
					"C method '%s' not previously declared in definition part of"
					" extension type" % name)
			entry = self.add_cfunction(name, type, pos, cname or name, visibility)
		if defining:
			entry.func_cname = self.mangle(Naming.func_prefix, name)
		return entry
Пример #2
0
 def declare_cfunction(self,
                       name,
                       type,
                       pos,
                       cname=None,
                       visibility='private',
                       defining=0):
     if get_special_method_signature(name):
         error(pos,
               "Special methods must be declared with 'def', not 'cdef'")
     args = type.args
     if not args:
         error(pos, "C method has no self argument")
     elif not args[0].type.same_as(self.parent_type):
         error(pos, "Self argument of C method does not match parent type")
     entry = self.lookup_here(name)
     if entry:
         if not entry.is_cfunction:
             error(pos, "'%s' redeclared" % name)
         else:
             if defining and entry.func_cname:
                 error(pos, "'%s' already defined" % name)
             if not entry.type.same_as(type, as_cmethod=1):
                 error(pos, "Signature does not match previous declaration")
     else:
         if self.defined:
             error(
                 pos,
                 "C method '%s' not previously declared in definition part of"
                 " extension type" % name)
         entry = self.add_cfunction(name, type, pos, cname or name,
                                    visibility)
     if defining:
         entry.func_cname = self.mangle(Naming.func_prefix, name)
     return entry
Пример #3
0
	def declare_var(self, name, type, pos, 
			cname = None, visibility = 'private', is_cdef = 0):
		# Add an entry for an attribute.
		if self.defined:
			error(pos,
				"C attributes cannot be added in implementation part of"
				" extension type")
		if get_special_method_signature(name):
			error(pos, 
				"The name '%s' is reserved for a special method."
					% name)
		if not cname:
			cname = name
		entry = self.declare(name, cname, type, pos)
		entry.visibility = visibility
		entry.is_variable = 1
		self.var_entries.append(entry)
		if type.is_pyobject and name <> "__weakref__":
			self.has_pyobject_attrs = 1
			self.pyattr_entries.append(entry)
		if visibility not in ('private', 'public', 'readonly'):
			error(pos,
				"Attribute of extension type cannot be declared %s" % visibility)
		if visibility in ('public', 'readonly'):
			if type.pymemberdef_typecode:
				self.public_attr_entries.append(entry)
				if name == "__weakref__":
					error(pos, "Special attribute __weakref__ cannot be exposed to Python")
			else:
				error(pos,
					"C attribute of type '%s' cannot be accessed from Python" % type)
		if visibility == 'public' and type.is_extension_type:
			error(pos,
				"Non-generic Python attribute cannot be exposed for writing from Python")
		return entry
Пример #4
0
 def declare_pyfunction(self, name, pos):
     # Add an entry for a method.
     entry = self.declare(name, name, py_object_type, pos)
     special_sig = get_special_method_signature(name)
     if special_sig:
         entry.signature = special_sig
         # Special methods don't get put in the method table
     else:
         entry.signature = pymethod_signature
         self.pyfunc_entries.append(entry)
     return entry
Пример #5
0
 def declare_pyfunction(self, name, pos):
     # Add an entry for a method.
     entry = self.declare(name, name, py_object_type, pos)
     special_sig = get_special_method_signature(name)
     if special_sig:
         entry.signature = special_sig
         # Special methods don't get put in the method table
     else:
         entry.signature = pymethod_signature
         self.pyfunc_entries.append(entry)
     return entry
Пример #6
0
 def declare_var(self,
                 name,
                 type,
                 pos,
                 cname=None,
                 visibility='private',
                 is_cdef=0):
     # Add an entry for an attribute.
     if self.defined:
         error(
             pos, "C attributes cannot be added in implementation part of"
             " extension type")
     if get_special_method_signature(name):
         error(pos,
               "The name '%s' is reserved for a special method." % name)
     if not cname:
         cname = name
     entry = self.declare(name, cname, type, pos)
     entry.visibility = visibility
     entry.is_variable = 1
     self.var_entries.append(entry)
     if type.is_pyobject:
         self.has_pyobject_attrs = 1
     if visibility not in ('private', 'public', 'readonly'):
         error(
             pos, "Attribute of extension type cannot be declared %s" %
             visibility)
     if visibility in ('public', 'readonly'):
         if type.pymemberdef_typecode:
             self.public_attr_entries.append(entry)
             if name == "__weakref__":
                 error(
                     pos,
                     "Special attribute __weakref__ cannot be exposed to Python"
                 )
         else:
             error(
                 pos,
                 "C attribute of type '%s' cannot be accessed from Python" %
                 type)
     if visibility == 'public' and type.is_extension_type:
         error(
             pos,
             "Non-generic Python attribute cannot be exposed for writing from Python"
         )
     return entry
Пример #7
0
	def declare_pyfunction(self, name, pos):
		# Add an entry for a method.
		if name == "__new__":
			error(pos, "__new__ method of extension type will change semantics "
				"in a future version of Pyrex. Use __cinit__ instead.")
			name = "__cinit__"
		entry = self.lookup_here(name)
		if entry and entry.is_builtin_method:
			self.overriding_builtin_method(name, pos)
		else:
			entry = self.declare(name, name, py_object_type, pos)
		special_sig = get_special_method_signature(name)
		if special_sig:
			entry.is_special = 1
			entry.signature = special_sig
			# Special methods don't get put in the method table
		else:
			entry.signature = pymethod_signature
			self.pyfunc_entries.append(entry)
		return entry