Commit e352a0b3 authored by Robert Bradshaw's avatar Robert Bradshaw

rdef keyword for overridable methods

parent bc3427ca
......@@ -714,9 +714,7 @@ class CFuncDefNode(FuncDefNode):
defining = self.body is not None)
self.return_type = type.return_type
if 'overrideable' in self.modifiers or 'visible' in self.modifiers:
if 'visible' in self.modifiers:
self.modifiers.remove('visible')
if self.overridable:
import ExprNodes
arg_names = [arg.name for arg in self.type.args]
self_arg = ExprNodes.NameNode(self.pos, name=arg_names[0])
......@@ -735,10 +733,8 @@ class CFuncDefNode(FuncDefNode):
env.entries[name] = self.entry
if Options.intern_names:
self.py_func.interned_attr_cname = env.intern(self.py_func.entry.name)
if 'overrideable' in self.modifiers:
self.modifiers.remove('overrideable')
self.override = OverrideCheckNode(self.pos, py_func = self.py_func)
self.body.stats.insert(0, self.override)
self.override = OverrideCheckNode(self.pos, py_func = self.py_func)
self.body.stats.insert(0, self.override)
def declare_arguments(self, env):
......
......@@ -1211,11 +1211,19 @@ def p_statement(s, level, cdef_flag = 0, visibility = 'private'):
return p_ctypedef_statement(s, level, visibility)
if s.sy == 'cdef':
cdef_flag = 1
overridable = 0
s.next()
if s.sy == 'rdef':
cdef_flag = 1
overridable = 1
s.next()
if cdef_flag:
if level not in ('module', 'module_pxd', 'function', 'c_class', 'c_class_pxd'):
s.error('cdef statement not allowed here')
return p_cdef_statement(s, level, visibility)
return p_cdef_statement(s, level, visibility, overridable = overridable)
# elif s.sy == 'rdef':
# s.next()
# return p_c_func_or_var_declaration(s, level, s.position(), visibility = visibility, overridable = True)
elif s.sy == 'def':
if level not in ('module', 'class', 'c_class', 'property'):
s.error('def statement not allowed here')
......@@ -1570,8 +1578,10 @@ def p_c_arg_decl(s, in_pyfunc, cmethod_flag = 0, kw_only = 0):
default = default,
kw_only = kw_only)
def p_cdef_statement(s, level, visibility = 'private'):
def p_cdef_statement(s, level, visibility = 'private', overridable = False):
pos = s.position()
if overridable and level not in ('c_class', 'c_class_pxd'):
error(pos, "Overridable cdef function not allowed here")
visibility = p_visibility(s, visibility)
if visibility == 'extern' and s.sy in ('from' ,':'):
return p_cdef_extern_block(s, level, pos)
......@@ -1593,7 +1603,7 @@ def p_cdef_statement(s, level, visibility = 'private'):
s.expect_newline('Expected a newline')
return node
else:
return p_c_func_or_var_declaration(s, level, pos, visibility)
return p_c_func_or_var_declaration(s, level, pos, visibility, overridable)
def p_cdef_extern_block(s, level, pos):
include_file = None
......@@ -1698,13 +1708,13 @@ def p_visibility(s, prev_visibility):
return visibility
def p_c_modifiers(s):
if s.sy == 'IDENT' and s.systring in ('inline', 'visible', 'overrideable'):
if s.sy == 'IDENT' and s.systring in ('inline',):
modifier = s.systring
s.next()
return [modifier] + p_c_modifiers(s)
return []
def p_c_func_or_var_declaration(s, level, pos, visibility = 'private'):
def p_c_func_or_var_declaration(s, level, pos, visibility = 'private', overridable = False):
cmethod_flag = level in ('c_class', 'c_class_pxd')
modifiers = p_c_modifiers(s)
base_type = p_c_base_type(s)
......@@ -1718,7 +1728,8 @@ def p_c_func_or_var_declaration(s, level, pos, visibility = 'private'):
base_type = base_type,
declarator = declarator,
body = suite,
modifiers = modifiers)
modifiers = modifiers,
overridable = overridable)
else:
if level == 'module_pxd' and visibility <> 'extern':
error(pos,
......
......@@ -138,7 +138,7 @@ reserved_words = [
"raise", "import", "exec", "try", "except", "finally",
"while", "if", "elif", "else", "for", "in", "assert",
"and", "or", "not", "is", "in", "lambda", "from",
"NULL", "cimport", "by", "with"
"NULL", "cimport", "by", "with", "rdef"
]
function_contexts = [ # allowed arguments to the "with" option
......
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