Commit 5a8e9e62 authored by gsamain's avatar gsamain

ccdef in parsing

parent 9bc6d86e
......@@ -2239,7 +2239,7 @@ def p_statement(s, ctx, first_statement = 0):
s.error('decorator not allowed here')
s.level = ctx.level
decorators = p_decorators(s)
if not ctx.allow_struct_enum_decorator and s.sy not in ('def', 'cdef', 'cpdef', 'class'):
if not ctx.allow_struct_enum_decorator and s.sy not in ('def', 'cdef', 'cpdef', 'ccdef', 'class'):
if s.sy == 'IDENT' and s.systring == 'async':
pass # handled below
else:
......@@ -2249,9 +2249,18 @@ def p_statement(s, ctx, first_statement = 0):
return p_pass_statement(s, with_newline=1)
overridable = 0
nogil_flag = ctx.nogil
if s.sy == 'cdef':
#if ctx.level == 'c_class_nogil':
# s.error('cdef statement not allowed in nogil extension type')
cdef_flag = 1
s.next()
elif s.sy == 'ccdef':
cdef_flag = 1
nogil_flag = 1
s.next()
if s.sy != "class":
s.error('ccdef statement only allowed for extension type')
elif s.sy == 'cpdef':
if ctx.level == 'c_class_nogil':
s.error('cpdef statement not allowed in nogil extension type')
......@@ -2263,7 +2272,7 @@ def p_statement(s, ctx, first_statement = 0):
if ctx.level not in ('module', 'module_pxd', 'function', 'c_class', 'c_class_nogil', 'c_class_pxd'):
s.error('cdef statement not allowed here')
s.level = ctx.level
node = p_cdef_statement(s, ctx(overridable=overridable))
node = p_cdef_statement(s, ctx(overridable=overridable, nogil=nogil_flag))
if decorators is not None:
tup = (Nodes.CFuncDefNode, Nodes.CVarDefNode, Nodes.CClassDefNode)
if ctx.allow_struct_enum_decorator:
......@@ -3068,9 +3077,11 @@ def p_cdef_statement(s, ctx):
return p_cdef_extern_block(s, pos, ctx)
elif p_nogil(s):
ctx.nogil = 1
if ctx.overridable:
error(pos, "cdef blocks cannot be declared cpdef")
# if ctx.overridable:
# error(pos, "cdef blocks cannot be declared cpdef")
return p_cdef_block(s, ctx)
elif ctx.overridable and ctx.nogil:
error(pos, "nogil blocks cannot be declared cpdef")
elif s.sy == ':':
if ctx.overridable:
error(pos, "cdef blocks cannot be declared cpdef")
......@@ -3295,12 +3306,15 @@ def p_c_func_or_var_declaration(s, pos, ctx):
fatal=False)
s.next()
p_test(s) # Keep going, but ignore result.
nogil = ctx.nogil
if s.sy == 'nogil':
nogil = p_nogil(s)
s.next()
if ctx.level == 'c_class_nogil' and not nogil:
s.error("Only C function with nogil allowed in nogil extension")
# if ctx.level == 'c_class_nogil' and not nogil:
# s.error("Only C function with nogil allowed in nogil extension")
if s.sy == ':':
#if ctx.level == 'c_class_nogil' and not ctx.nogil:
# s.error("Only C function declared with ccdef allowed in nogil extension")
if ctx.level not in ('module', 'c_class', 'module_pxd', 'c_class_pxd', 'cpp_class', 'c_class_nogil') and not ctx.templates:
s.error("C function definition not allowed here")
doc, suite = p_suite_with_docstring(s, Ctx(level='function'))
......@@ -3530,7 +3544,8 @@ def p_c_class_definition(s, pos, ctx):
if ctx.visibility not in ('public', 'extern') and not ctx.api:
error(s.position(), "Name options only allowed for 'public', 'api', or 'extern' C class")
objstruct_name, typeobj_name, check_size = p_c_class_options(s)
nogil = p_nogil(s)
#nogil = p_nogil(s)
nogil = ctx.nogil
if s.sy == ':':
if ctx.level == 'module_pxd':
body_level = 'c_class_pxd'
......@@ -3538,7 +3553,7 @@ def p_c_class_definition(s, pos, ctx):
body_level = 'c_class_nogil'
else:
body_level = 'c_class'
doc, body = p_suite_with_docstring(s, Ctx(level=body_level))
doc, body = p_suite_with_docstring(s, Ctx(level=body_level, nogil=nogil))
else:
s.expect_newline("Syntax error in C class definition")
doc = None
......@@ -3575,7 +3590,8 @@ def p_c_class_definition(s, pos, ctx):
in_pxd = ctx.level == 'module_pxd',
doc = doc,
body = body,
nogil = nogil or ctx.nogil)
nogil = nogil)
# nogil = nogil or ctx.nogil)
def p_c_class_options(s):
......@@ -3798,7 +3814,7 @@ def p_cpp_class_definition(s, pos, ctx):
s.expect_indent()
doc = p_doc_string(s)
attributes = []
body_ctx = Ctx(visibility = ctx.visibility, level='cpp_class', nogil=nogil or ctx.nogil)
body_ctx = Ctx(visibility = ctx.visibility, level='cpp_class', nogil=nogil)
body_ctx.templates = template_names
while s.sy != 'DEDENT':
if s.sy != 'pass':
......
......@@ -47,7 +47,8 @@ py_reserved_words = [
pyx_reserved_words = py_reserved_words + [
"include", "ctypedef", "cdef", "cpdef",
"cimport", "DEF", "IF", "ELIF", "ELSE"
"cimport", "DEF", "IF", "ELIF", "ELSE",
"ccdef"
]
......
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