Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
773b6f3b
Commit
773b6f3b
authored
Nov 28, 2018
by
Boxiang Sun
Committed by
gsamain
Apr 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let parser handle nogil keyword in extension declaration
parent
40fd31ce
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
7 deletions
+21
-7
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+21
-7
No files found.
Cython/Compiler/Parsing.py
View file @
773b6f3b
...
@@ -2235,7 +2235,7 @@ def p_statement(s, ctx, first_statement = 0):
...
@@ -2235,7 +2235,7 @@ def p_statement(s, ctx, first_statement = 0):
elif
s
.
sy
==
'IF'
:
elif
s
.
sy
==
'IF'
:
return
p_IF_statement
(
s
,
ctx
)
return
p_IF_statement
(
s
,
ctx
)
elif
s
.
sy
==
'@'
:
elif
s
.
sy
==
'@'
:
if
ctx
.
level
not
in
(
'module'
,
'class'
,
'c_class'
,
'function'
,
'property'
,
'module_pxd'
,
'c_class_pxd'
,
'other'
):
if
ctx
.
level
not
in
(
'module'
,
'class'
,
'c_class'
,
'
class_nogil'
,
'
function'
,
'property'
,
'module_pxd'
,
'c_class_pxd'
,
'other'
):
s
.
error
(
'decorator not allowed here'
)
s
.
error
(
'decorator not allowed here'
)
s
.
level
=
ctx
.
level
s
.
level
=
ctx
.
level
decorators
=
p_decorators
(
s
)
decorators
=
p_decorators
(
s
)
...
@@ -2253,11 +2253,14 @@ def p_statement(s, ctx, first_statement = 0):
...
@@ -2253,11 +2253,14 @@ def p_statement(s, ctx, first_statement = 0):
cdef_flag
=
1
cdef_flag
=
1
s
.
next
()
s
.
next
()
elif
s
.
sy
==
'cpdef'
:
elif
s
.
sy
==
'cpdef'
:
if
ctx
.
level
==
'c_class_nogil'
:
s
.
error
(
'cpdef statement not allowed in nogil extension type'
)
s
.
level
=
ctx
.
level
cdef_flag
=
1
cdef_flag
=
1
overridable
=
1
overridable
=
1
s
.
next
()
s
.
next
()
if
cdef_flag
:
if
cdef_flag
:
if
ctx
.
level
not
in
(
'module'
,
'module_pxd'
,
'function'
,
'c_class'
,
'c_class_pxd'
):
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
.
error
(
'cdef statement not allowed here'
)
s
.
level
=
ctx
.
level
s
.
level
=
ctx
.
level
node
=
p_cdef_statement
(
s
,
ctx
(
overridable
=
overridable
))
node
=
p_cdef_statement
(
s
,
ctx
(
overridable
=
overridable
))
...
@@ -2277,6 +2280,8 @@ def p_statement(s, ctx, first_statement = 0):
...
@@ -2277,6 +2280,8 @@ def p_statement(s, ctx, first_statement = 0):
# as part of a cdef class
# as part of a cdef class
if
(
'pxd'
in
ctx
.
level
)
and
(
ctx
.
level
!=
'c_class_pxd'
):
if
(
'pxd'
in
ctx
.
level
)
and
(
ctx
.
level
!=
'c_class_pxd'
):
s
.
error
(
'def statement not allowed here'
)
s
.
error
(
'def statement not allowed here'
)
if
ctx
.
level
==
'c_class_nogil'
:
s
.
error
(
'def statement not allowed in nogil extension type, only cdef with nogil is allowed'
)
s
.
level
=
ctx
.
level
s
.
level
=
ctx
.
level
return
p_def_statement
(
s
,
decorators
)
return
p_def_statement
(
s
,
decorators
)
elif
s
.
sy
==
'class'
:
elif
s
.
sy
==
'class'
:
...
@@ -2287,7 +2292,7 @@ def p_statement(s, ctx, first_statement = 0):
...
@@ -2287,7 +2292,7 @@ def p_statement(s, ctx, first_statement = 0):
if
ctx
.
level
not
in
(
'module'
,
'module_pxd'
):
if
ctx
.
level
not
in
(
'module'
,
'module_pxd'
):
s
.
error
(
"include statement not allowed here"
)
s
.
error
(
"include statement not allowed here"
)
return
p_include_statement
(
s
,
ctx
)
return
p_include_statement
(
s
,
ctx
)
elif
ctx
.
level
==
'c_class'
and
s
.
sy
==
'IDENT'
and
s
.
systring
==
'property'
:
elif
ctx
.
level
in
(
'c_class'
,
'c_class_nogil'
)
and
s
.
sy
==
'IDENT'
and
s
.
systring
==
'property'
:
return
p_property_decl
(
s
)
return
p_property_decl
(
s
)
elif
s
.
sy
==
'pass'
and
ctx
.
level
!=
'property'
:
elif
s
.
sy
==
'pass'
and
ctx
.
level
!=
'property'
:
return
p_pass_statement
(
s
,
with_newline
=
True
)
return
p_pass_statement
(
s
,
with_newline
=
True
)
...
@@ -3271,7 +3276,7 @@ def p_c_modifiers(s):
...
@@ -3271,7 +3276,7 @@ def p_c_modifiers(s):
return
[]
return
[]
def
p_c_func_or_var_declaration
(
s
,
pos
,
ctx
):
def
p_c_func_or_var_declaration
(
s
,
pos
,
ctx
):
cmethod_flag
=
ctx
.
level
in
(
'c_class'
,
'c_class_pxd'
)
cmethod_flag
=
ctx
.
level
in
(
'c_class'
,
'c_class_pxd'
,
'c_class_nogil'
)
modifiers
=
p_c_modifiers
(
s
)
modifiers
=
p_c_modifiers
(
s
)
base_type
=
p_c_base_type
(
s
,
nonempty
=
1
,
templates
=
ctx
.
templates
)
base_type
=
p_c_base_type
(
s
,
nonempty
=
1
,
templates
=
ctx
.
templates
)
declarator
=
p_c_declarator
(
s
,
ctx
(
modifiers
=
modifiers
),
cmethod_flag
=
cmethod_flag
,
declarator
=
p_c_declarator
(
s
,
ctx
(
modifiers
=
modifiers
),
cmethod_flag
=
cmethod_flag
,
...
@@ -3290,8 +3295,13 @@ def p_c_func_or_var_declaration(s, pos, ctx):
...
@@ -3290,8 +3295,13 @@ def p_c_func_or_var_declaration(s, pos, ctx):
fatal
=
False
)
fatal
=
False
)
s
.
next
()
s
.
next
()
p_test
(
s
)
# Keep going, but ignore result.
p_test
(
s
)
# Keep going, but ignore result.
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
s
.
sy
==
':'
:
if
s
.
sy
==
':'
:
if
ctx
.
level
not
in
(
'module'
,
'c_class'
,
'module_pxd'
,
'c_class_pxd'
,
'cpp_class'
)
and
not
ctx
.
templates
:
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"
)
s
.
error
(
"C function definition not allowed here"
)
doc
,
suite
=
p_suite_with_docstring
(
s
,
Ctx
(
level
=
'function'
))
doc
,
suite
=
p_suite_with_docstring
(
s
,
Ctx
(
level
=
'function'
))
result
=
Nodes
.
CFuncDefNode
(
pos
,
result
=
Nodes
.
CFuncDefNode
(
pos
,
...
@@ -3319,7 +3329,7 @@ def p_c_func_or_var_declaration(s, pos, ctx):
...
@@ -3319,7 +3329,7 @@ def p_c_func_or_var_declaration(s, pos, ctx):
declarators
.
append
(
declarator
)
declarators
.
append
(
declarator
)
doc_line
=
s
.
start_line
+
1
doc_line
=
s
.
start_line
+
1
s
.
expect_newline
(
"Syntax error in C variable declaration"
,
ignore_semicolon
=
True
)
s
.
expect_newline
(
"Syntax error in C variable declaration"
,
ignore_semicolon
=
True
)
if
ctx
.
level
in
(
'c_class'
,
'c_class_pxd'
)
and
s
.
start_line
==
doc_line
:
if
ctx
.
level
in
(
'c_class'
,
'c_class_pxd'
,
'c_class_nogil'
)
and
s
.
start_line
==
doc_line
:
doc
=
p_doc_string
(
s
)
doc
=
p_doc_string
(
s
)
else
:
else
:
doc
=
None
doc
=
None
...
@@ -3506,9 +3516,12 @@ def p_c_class_definition(s, pos, ctx):
...
@@ -3506,9 +3516,12 @@ def p_c_class_definition(s, pos, ctx):
if
ctx
.
visibility
not
in
(
'public'
,
'extern'
)
and
not
ctx
.
api
:
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"
)
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
)
objstruct_name
,
typeobj_name
,
check_size
=
p_c_class_options
(
s
)
nogil
=
p_nogil
(
s
)
if
s
.
sy
==
':'
:
if
s
.
sy
==
':'
:
if
ctx
.
level
==
'module_pxd'
:
if
ctx
.
level
==
'module_pxd'
:
body_level
=
'c_class_pxd'
body_level
=
'c_class_pxd'
elif
nogil
:
body_level
=
'c_class_nogil'
else
:
else
:
body_level
=
'c_class'
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
))
...
@@ -3547,7 +3560,8 @@ def p_c_class_definition(s, pos, ctx):
...
@@ -3547,7 +3560,8 @@ def p_c_class_definition(s, pos, ctx):
check_size
=
check_size
,
check_size
=
check_size
,
in_pxd
=
ctx
.
level
==
'module_pxd'
,
in_pxd
=
ctx
.
level
==
'module_pxd'
,
doc
=
doc
,
doc
=
doc
,
body
=
body
)
body
=
body
,
nogil
=
nogil
or
ctx
.
nogil
)
def
p_c_class_options
(
s
):
def
p_c_class_options
(
s
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment