Commit 0dcc26cc authored by Stefan Behnel's avatar Stefan Behnel

major refactoring of builtin method/function overrides to support explicit...

major refactoring of builtin method/function overrides to support explicit function types and utility code dependencies
parent 9bb67b49
This diff is collapsed.
...@@ -539,7 +539,7 @@ class Scope(object): ...@@ -539,7 +539,7 @@ class Scope(object):
def declare_cfunction(self, name, type, pos, def declare_cfunction(self, name, type, pos,
cname = None, visibility = 'private', defining = 0, cname = None, visibility = 'private', defining = 0,
api = 0, in_pxd = 0, modifiers = ()): api = 0, in_pxd = 0, modifiers = (), utility_code = None):
# Add an entry for a C function. # Add an entry for a C function.
if not cname: if not cname:
if api or visibility != 'private': if api or visibility != 'private':
...@@ -585,6 +585,7 @@ class Scope(object): ...@@ -585,6 +585,7 @@ class Scope(object):
entry.is_implemented = True entry.is_implemented = True
if modifiers: if modifiers:
entry.func_modifiers = modifiers entry.func_modifiers = modifiers
entry.utility_code = utility_code
return entry return entry
def add_cfunction(self, name, type, pos, cname, visibility, modifiers): def add_cfunction(self, name, type, pos, cname, visibility, modifiers):
...@@ -722,8 +723,8 @@ class BuiltinScope(Scope): ...@@ -722,8 +723,8 @@ class BuiltinScope(Scope):
# If python_equiv == "*", the Python equivalent has the same name # If python_equiv == "*", the Python equivalent has the same name
# as the entry, otherwise it has the name specified by python_equiv. # as the entry, otherwise it has the name specified by python_equiv.
name = EncodedString(name) name = EncodedString(name)
entry = self.declare_cfunction(name, type, None, cname, visibility='extern') entry = self.declare_cfunction(name, type, None, cname, visibility='extern',
entry.utility_code = utility_code utility_code = utility_code)
if python_equiv: if python_equiv:
if python_equiv == "*": if python_equiv == "*":
python_equiv = name python_equiv = name
...@@ -1363,7 +1364,7 @@ class StructOrUnionScope(Scope): ...@@ -1363,7 +1364,7 @@ class StructOrUnionScope(Scope):
def declare_cfunction(self, name, type, pos, def declare_cfunction(self, name, type, pos,
cname = None, visibility = 'private', defining = 0, cname = None, visibility = 'private', defining = 0,
api = 0, in_pxd = 0, modifiers = ()): api = 0, in_pxd = 0, modifiers = ()): # currently no utility code ...
return self.declare_var(name, type, pos, cname, visibility) return self.declare_var(name, type, pos, cname, visibility)
class ClassScope(Scope): class ClassScope(Scope):
...@@ -1539,7 +1540,8 @@ class CClassScope(ClassScope): ...@@ -1539,7 +1540,8 @@ class CClassScope(ClassScope):
def declare_cfunction(self, name, type, pos, def declare_cfunction(self, name, type, pos,
cname = None, visibility = 'private', cname = None, visibility = 'private',
defining = 0, api = 0, in_pxd = 0, modifiers = ()): defining = 0, api = 0, in_pxd = 0, modifiers = (),
utility_code = None):
if get_special_method_signature(name): if get_special_method_signature(name):
error(pos, "Special methods must be declared with 'def', not 'cdef'") error(pos, "Special methods must be declared with 'def', not 'cdef'")
args = type.args args = type.args
...@@ -1573,6 +1575,7 @@ class CClassScope(ClassScope): ...@@ -1573,6 +1575,7 @@ class CClassScope(ClassScope):
visibility, modifiers) visibility, modifiers)
if defining: if defining:
entry.func_cname = self.mangle(Naming.func_prefix, name) entry.func_cname = self.mangle(Naming.func_prefix, name)
entry.utility_code = utility_code
return entry return entry
def add_cfunction(self, name, type, pos, cname, visibility, modifiers): def add_cfunction(self, name, type, pos, cname, visibility, modifiers):
...@@ -1671,7 +1674,7 @@ class CppClassScope(Scope): ...@@ -1671,7 +1674,7 @@ class CppClassScope(Scope):
def declare_cfunction(self, name, type, pos, def declare_cfunction(self, name, type, pos,
cname = None, visibility = 'extern', defining = 0, cname = None, visibility = 'extern', defining = 0,
api = 0, in_pxd = 0, modifiers = ()): api = 0, in_pxd = 0, modifiers = (), utility_code = None):
if name == self.name.split('::')[-1] and cname is None: if name == self.name.split('::')[-1] and cname is None:
self.check_base_default_constructor(pos) self.check_base_default_constructor(pos)
name = '<init>' name = '<init>'
...@@ -1680,6 +1683,8 @@ class CppClassScope(Scope): ...@@ -1680,6 +1683,8 @@ class CppClassScope(Scope):
entry = self.declare_var(name, type, pos, cname, visibility) entry = self.declare_var(name, type, pos, cname, visibility)
if prev_entry: if prev_entry:
entry.overloaded_alternatives = prev_entry.all_alternatives() entry.overloaded_alternatives = prev_entry.all_alternatives()
entry.utility_code = utility_code
return entry
def declare_inherited_cpp_attributes(self, base_scope): def declare_inherited_cpp_attributes(self, base_scope):
# Declare entries for all the C++ attributes of an # Declare entries for all the C++ attributes of an
...@@ -1700,7 +1705,8 @@ class CppClassScope(Scope): ...@@ -1700,7 +1705,8 @@ class CppClassScope(Scope):
for base_entry in base_scope.cfunc_entries: for base_entry in base_scope.cfunc_entries:
entry = self.declare_cfunction(base_entry.name, base_entry.type, entry = self.declare_cfunction(base_entry.name, base_entry.type,
base_entry.pos, base_entry.cname, base_entry.pos, base_entry.cname,
base_entry.visibility, base_entry.func_modifiers) base_entry.visibility, base_entry.func_modifiers,
utility_code = base_entry.utility_code)
entry.is_inherited = 1 entry.is_inherited = 1
def specialize(self, values): def specialize(self, values):
...@@ -1721,7 +1727,8 @@ class CppClassScope(Scope): ...@@ -1721,7 +1727,8 @@ class CppClassScope(Scope):
scope.declare_cfunction(e.name, scope.declare_cfunction(e.name,
e.type.specialize(values), e.type.specialize(values),
e.pos, e.pos,
e.cname) e.cname,
utility_code = e.utility_code)
return scope return scope
def add_include_file(self, filename): def add_include_file(self, filename):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment