Commit e352a0b3 authored by Robert Bradshaw's avatar Robert Bradshaw

rdef keyword for overridable methods

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