Commit f410b12d authored by Xavier Thompson's avatar Xavier Thompson

Parse C++ const method qualifiers in a cleaner way

parent 4fddf35e
...@@ -2698,6 +2698,7 @@ class CFuncDefNode(FuncDefNode): ...@@ -2698,6 +2698,7 @@ class CFuncDefNode(FuncDefNode):
#name = name_declarator.name #name = name_declarator.name
#cname = name_declarator.cname #cname = name_declarator.cname
self.is_const_method = self.cfunc_declarator.is_const_method
typ.is_const_method = self.is_const_method typ.is_const_method = self.is_const_method
typ.is_static_method = self.is_static_method typ.is_static_method = self.is_static_method
......
...@@ -2845,6 +2845,12 @@ def p_c_array_declarator(s, base): ...@@ -2845,6 +2845,12 @@ def p_c_array_declarator(s, base):
s.expect(']') s.expect(']')
return Nodes.CArrayDeclaratorNode(pos, base = base, dimension = dim) return Nodes.CArrayDeclaratorNode(pos, base = base, dimension = dim)
def p_cpp_const_method(s, ctx):
if s.sy == 'IDENT' and s.systring == 'const' and ctx.level == 'cpp_class':
s.next()
return 1
return 0
def p_c_func_declarator(s, pos, ctx, base, cmethod_flag): def p_c_func_declarator(s, pos, ctx, base, cmethod_flag):
# Opening paren has already been skipped # Opening paren has already been skipped
args = p_c_arg_list(s, ctx, cmethod_flag = cmethod_flag, args = p_c_arg_list(s, ctx, cmethod_flag = cmethod_flag,
...@@ -2854,10 +2860,12 @@ def p_c_func_declarator(s, pos, ctx, base, cmethod_flag): ...@@ -2854,10 +2860,12 @@ def p_c_func_declarator(s, pos, ctx, base, cmethod_flag):
nogil = p_nogil(s) nogil = p_nogil(s)
exc_val, exc_check = p_exception_value_clause(s) exc_val, exc_check = p_exception_value_clause(s)
with_gil = p_with_gil(s) with_gil = p_with_gil(s)
is_const_method = p_cpp_const_method(s, ctx)
return Nodes.CFuncDeclaratorNode(pos, return Nodes.CFuncDeclaratorNode(pos,
base = base, args = args, has_varargs = ellipsis, base = base, args = args, has_varargs = ellipsis,
exception_value = exc_val, exception_check = exc_check, exception_value = exc_val, exception_check = exc_check,
nogil = nogil or ctx.nogil or with_gil, with_gil = with_gil) nogil = nogil or ctx.nogil or with_gil, with_gil = with_gil,
is_const_method = is_const_method)
supported_overloaded_operators = cython.declare(set, set([ supported_overloaded_operators = cython.declare(set, set([
'+', '-', '*', '/', '%', '+', '-', '*', '/', '%',
...@@ -3345,11 +3353,6 @@ def p_c_func_or_var_declaration(s, pos, ctx): ...@@ -3345,11 +3353,6 @@ def p_c_func_or_var_declaration(s, pos, ctx):
declarator = p_c_declarator(s, ctx(modifiers=modifiers), cmethod_flag = cmethod_flag, declarator = p_c_declarator(s, ctx(modifiers=modifiers), cmethod_flag = cmethod_flag,
assignable = 1, nonempty = 1) assignable = 1, nonempty = 1)
declarator.overridable = ctx.overridable declarator.overridable = ctx.overridable
if s.sy == 'IDENT' and s.systring == 'const' and ctx.level == 'cpp_class':
s.next()
is_const_method = 1
else:
is_const_method = 0
if s.sy == '->': if s.sy == '->':
# Special enough to give a better error message and keep going. # Special enough to give a better error message and keep going.
s.error( s.error(
...@@ -3370,13 +3373,10 @@ def p_c_func_or_var_declaration(s, pos, ctx): ...@@ -3370,13 +3373,10 @@ def p_c_func_or_var_declaration(s, pos, ctx):
doc = doc, doc = doc,
modifiers = modifiers, modifiers = modifiers,
api = ctx.api, api = ctx.api,
overridable = ctx.overridable, overridable = ctx.overridable)
is_const_method = is_const_method)
else: else:
#if api: #if api:
# s.error("'api' not allowed with variable declaration") # s.error("'api' not allowed with variable declaration")
if is_const_method:
declarator.is_const_method = is_const_method
declarators = [declarator] declarators = [declarator]
while s.sy == ',': while s.sy == ',':
s.next() s.next()
......
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