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
515cf371
Commit
515cf371
authored
Jun 06, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pyrex merge: parser context refactoring + nogil blocks
parent
7c4905dd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
166 additions
and
160 deletions
+166
-160
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+166
-160
No files found.
Cython/Compiler/Parsing.py
View file @
515cf371
...
@@ -12,6 +12,26 @@ from Errors import error, InternalError
...
@@ -12,6 +12,26 @@ from Errors import error, InternalError
from
Cython
import
Utils
from
Cython
import
Utils
import
Future
import
Future
class
Ctx
(
object
):
# Parsing context
level
=
'other'
visibility
=
'private'
cdef_flag
=
0
typedef_flag
=
0
api
=
0
overridable
=
0
nogil
=
0
def
__init__
(
self
,
**
kwds
):
self
.
__dict__
.
update
(
kwds
)
def
__call__
(
self
,
**
kwds
):
ctx
=
Ctx
()
d
=
ctx
.
__dict__
d
.
update
(
self
.
__dict__
)
d
.
update
(
kwds
)
return
ctx
def
p_ident
(
s
,
message
=
"Expected an identifier"
):
def
p_ident
(
s
,
message
=
"Expected an identifier"
):
if
s
.
sy
==
'IDENT'
:
if
s
.
sy
==
'IDENT'
:
name
=
s
.
systring
name
=
s
.
systring
...
@@ -37,9 +57,7 @@ def p_ident_list(s):
...
@@ -37,9 +57,7 @@ def p_ident_list(s):
#------------------------------------------
#------------------------------------------
def
p_binop_expr
(
s
,
ops
,
p_sub_expr
):
def
p_binop_expr
(
s
,
ops
,
p_sub_expr
):
#print "p_binop_expr:", ops, p_sub_expr ###
n1
=
p_sub_expr
(
s
)
n1
=
p_sub_expr
(
s
)
#print "p_binop_expr(%s):" % p_sub_expr, s.sy ###
while
s
.
sy
in
ops
:
while
s
.
sy
in
ops
:
op
=
s
.
sy
op
=
s
.
sy
pos
=
s
.
position
()
pos
=
s
.
position
()
...
@@ -73,7 +91,6 @@ def p_test(s):
...
@@ -73,7 +91,6 @@ def p_test(s):
#or_test: and_test ('or' and_test)*
#or_test: and_test ('or' and_test)*
def
p_or_test
(
s
):
def
p_or_test
(
s
):
#return p_binop_expr(s, ('or',), p_and_test)
return
p_rassoc_binop_expr
(
s
,
(
'or'
,),
p_and_test
)
return
p_rassoc_binop_expr
(
s
,
(
'or'
,),
p_and_test
)
def
p_rassoc_binop_expr
(
s
,
ops
,
p_subexpr
):
def
p_rassoc_binop_expr
(
s
,
ops
,
p_subexpr
):
...
@@ -1195,7 +1212,7 @@ def p_except_clause(s):
...
@@ -1195,7 +1212,7 @@ def p_except_clause(s):
return
Nodes
.
ExceptClauseNode
(
pos
,
return
Nodes
.
ExceptClauseNode
(
pos
,
pattern
=
exc_type
,
target
=
exc_value
,
body
=
body
)
pattern
=
exc_type
,
target
=
exc_value
,
body
=
body
)
def
p_include_statement
(
s
,
level
):
def
p_include_statement
(
s
,
ctx
):
pos
=
s
.
position
()
pos
=
s
.
position
()
s
.
next
()
# 'include'
s
.
next
()
# 'include'
_
,
include_file_name
=
p_string_literal
(
s
)
_
,
include_file_name
=
p_string_literal
(
s
)
...
@@ -1208,7 +1225,7 @@ def p_include_statement(s, level):
...
@@ -1208,7 +1225,7 @@ def p_include_statement(s, level):
s2
=
PyrexScanner
(
f
,
include_file_path
,
parent_scanner
=
s
,
s2
=
PyrexScanner
(
f
,
include_file_path
,
parent_scanner
=
s
,
source_encoding
=
f
.
encoding
)
source_encoding
=
f
.
encoding
)
try
:
try
:
tree
=
p_statement_list
(
s2
,
level
)
tree
=
p_statement_list
(
s2
,
ctx
)
finally
:
finally
:
f
.
close
()
f
.
close
()
return
tree
return
tree
...
@@ -1258,7 +1275,7 @@ def p_simple_statement(s, first_statement = 0):
...
@@ -1258,7 +1275,7 @@ def p_simple_statement(s, first_statement = 0):
node
=
p_expression_or_assignment
(
s
)
node
=
p_expression_or_assignment
(
s
)
return
node
return
node
def
p_simple_statement_list
(
s
,
first_statement
=
0
):
def
p_simple_statement_list
(
s
,
ctx
,
first_statement
=
0
):
# Parse a series of simple statements on one line
# Parse a series of simple statements on one line
# separated by semicolons.
# separated by semicolons.
stat
=
p_simple_statement
(
s
,
first_statement
=
first_statement
)
stat
=
p_simple_statement
(
s
,
first_statement
=
first_statement
)
...
@@ -1294,7 +1311,7 @@ def p_DEF_statement(s):
...
@@ -1294,7 +1311,7 @@ def p_DEF_statement(s):
s
.
expect_newline
()
s
.
expect_newline
()
return
Nodes
.
PassStatNode
(
pos
)
return
Nodes
.
PassStatNode
(
pos
)
def
p_IF_statement
(
s
,
level
,
cdef_flag
,
visibility
,
api
):
def
p_IF_statement
(
s
,
ctx
):
pos
=
s
.
position
()
pos
=
s
.
position
()
saved_eval
=
s
.
compile_time_eval
saved_eval
=
s
.
compile_time_eval
current_eval
=
saved_eval
current_eval
=
saved_eval
...
@@ -1304,7 +1321,7 @@ def p_IF_statement(s, level, cdef_flag, visibility, api):
...
@@ -1304,7 +1321,7 @@ def p_IF_statement(s, level, cdef_flag, visibility, api):
s
.
next
()
# 'IF' or 'ELIF'
s
.
next
()
# 'IF' or 'ELIF'
expr
=
p_compile_time_expr
(
s
)
expr
=
p_compile_time_expr
(
s
)
s
.
compile_time_eval
=
current_eval
and
bool
(
expr
.
compile_time_value
(
denv
))
s
.
compile_time_eval
=
current_eval
and
bool
(
expr
.
compile_time_value
(
denv
))
body
=
p_suite
(
s
,
level
,
cdef_flag
,
visibility
,
api
=
api
)
body
=
p_suite
(
s
,
ctx
)
if
s
.
compile_time_eval
:
if
s
.
compile_time_eval
:
result
=
body
result
=
body
current_eval
=
0
current_eval
=
0
...
@@ -1313,7 +1330,7 @@ def p_IF_statement(s, level, cdef_flag, visibility, api):
...
@@ -1313,7 +1330,7 @@ def p_IF_statement(s, level, cdef_flag, visibility, api):
if
s
.
sy
==
'ELSE'
:
if
s
.
sy
==
'ELSE'
:
s
.
next
()
s
.
next
()
s
.
compile_time_eval
=
current_eval
s
.
compile_time_eval
=
current_eval
body
=
p_suite
(
s
,
level
,
cdef_flag
,
visibility
,
api
=
api
)
body
=
p_suite
(
s
,
ctx
)
if
current_eval
:
if
current_eval
:
result
=
body
result
=
body
if
not
result
:
if
not
result
:
...
@@ -1321,18 +1338,18 @@ def p_IF_statement(s, level, cdef_flag, visibility, api):
...
@@ -1321,18 +1338,18 @@ def p_IF_statement(s, level, cdef_flag, visibility, api):
s
.
compile_time_eval
=
saved_eval
s
.
compile_time_eval
=
saved_eval
return
result
return
result
def
p_statement
(
s
,
level
,
cdef_flag
=
0
,
visibility
=
'private'
,
api
=
0
,
def
p_statement
(
s
,
ctx
,
first_statement
=
0
):
first_statement
=
0
):
cdef_flag
=
ctx
.
cdef_flag
if
s
.
sy
==
'ctypedef'
:
if
s
.
sy
==
'ctypedef'
:
if
level
not
in
(
'module'
,
'module_pxd'
):
if
ctx
.
level
not
in
(
'module'
,
'module_pxd'
):
s
.
error
(
"ctypedef statement not allowed here"
)
s
.
error
(
"ctypedef statement not allowed here"
)
if
api
:
if
ctx
.
api
:
error
(
s
.
position
(),
"'api' not allowed with 'ctypedef'"
)
error
(
s
.
position
(),
"'api' not allowed with 'ctypedef'"
)
return
p_ctypedef_statement
(
s
,
level
,
visibility
,
api
)
return
p_ctypedef_statement
(
s
,
ctx
)
elif
s
.
sy
==
'DEF'
:
elif
s
.
sy
==
'DEF'
:
return
p_DEF_statement
(
s
)
return
p_DEF_statement
(
s
)
elif
s
.
sy
==
'IF'
:
elif
s
.
sy
==
'IF'
:
return
p_IF_statement
(
s
,
level
,
cdef_flag
,
visibility
,
api
)
return
p_IF_statement
(
s
,
ctx
)
else
:
else
:
overridable
=
0
overridable
=
0
if
s
.
sy
==
'cdef'
:
if
s
.
sy
==
'cdef'
:
...
@@ -1343,36 +1360,32 @@ def p_statement(s, level, cdef_flag = 0, visibility = 'private', api = 0,
...
@@ -1343,36 +1360,32 @@ def p_statement(s, level, cdef_flag = 0, visibility = 'private', api = 0,
overridable
=
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
ctx
.
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'
)
s
.
level
=
level
s
.
level
=
ctx
.
level
return
p_cdef_statement
(
s
,
level
,
visibility
=
visibility
,
return
p_cdef_statement
(
s
,
ctx
(
overridable
=
overridable
))
api
=
api
,
overridable
=
overridable
)
else
:
# elif s.sy == 'cpdef':
if
ctx
.
api
:
# s.next()
# return p_c_func_or_var_declaration(s, level, s.position(), visibility = visibility, api = api, overridable = True)
else
:
if
api
:
error
(
s
.
pos
,
"'api' not allowed with this statement"
)
error
(
s
.
pos
,
"'api' not allowed with this statement"
)
elif
s
.
sy
==
'def'
:
elif
s
.
sy
==
'def'
:
if
level
not
in
(
'module'
,
'class'
,
'c_class'
,
'property'
):
if
ctx
.
level
not
in
(
'module'
,
'class'
,
'c_class'
,
'property'
):
s
.
error
(
'def statement not allowed here'
)
s
.
error
(
'def statement not allowed here'
)
s
.
level
=
level
s
.
level
=
ctx
.
level
return
p_def_statement
(
s
)
return
p_def_statement
(
s
)
elif
s
.
sy
==
'class'
:
elif
s
.
sy
==
'class'
:
if
level
!=
'module'
:
if
ctx
.
level
!=
'module'
:
s
.
error
(
"class definition not allowed here"
)
s
.
error
(
"class definition not allowed here"
)
return
p_class_statement
(
s
)
return
p_class_statement
(
s
)
elif
s
.
sy
==
'include'
:
elif
s
.
sy
==
'include'
:
if
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
,
level
)
return
p_include_statement
(
s
,
ctx
)
elif
level
==
'c_class'
and
s
.
sy
==
'IDENT'
and
s
.
systring
==
'property'
:
elif
ctx
.
level
==
'c_class'
and
s
.
sy
==
'IDENT'
and
s
.
systring
==
'property'
:
return
p_property_decl
(
s
)
return
p_property_decl
(
s
)
elif
s
.
sy
==
'pass'
and
level
!=
'property'
:
elif
s
.
sy
==
'pass'
and
ctx
.
level
!=
'property'
:
return
p_pass_statement
(
s
,
with_newline
=
1
)
return
p_pass_statement
(
s
,
with_newline
=
1
)
else
:
else
:
if
level
in
(
'c_class_pxd'
,
'property'
):
if
ctx
.
level
in
(
'c_class_pxd'
,
'property'
):
s
.
error
(
"Executable statement not allowed here"
)
s
.
error
(
"Executable statement not allowed here"
)
if
s
.
sy
==
'if'
:
if
s
.
sy
==
'if'
:
return
p_if_statement
(
s
)
return
p_if_statement
(
s
)
...
@@ -1385,25 +1398,22 @@ def p_statement(s, level, cdef_flag = 0, visibility = 'private', api = 0,
...
@@ -1385,25 +1398,22 @@ def p_statement(s, level, cdef_flag = 0, visibility = 'private', api = 0,
elif
s
.
sy
==
'with'
:
elif
s
.
sy
==
'with'
:
return
p_with_statement
(
s
)
return
p_with_statement
(
s
)
else
:
else
:
return
p_simple_statement_list
(
s
,
first_statement
=
first_statement
)
return
p_simple_statement_list
(
s
,
ctx
,
first_statement
=
first_statement
)
def
p_statement_list
(
s
,
level
,
def
p_statement_list
(
s
,
ctx
,
first_statement
=
0
):
cdef_flag
=
0
,
visibility
=
'private'
,
api
=
0
,
first_statement
=
0
):
# Parse a series of statements separated by newlines.
# Parse a series of statements separated by newlines.
pos
=
s
.
position
()
pos
=
s
.
position
()
stats
=
[]
stats
=
[]
while
s
.
sy
not
in
(
'DEDENT'
,
'EOF'
):
while
s
.
sy
not
in
(
'DEDENT'
,
'EOF'
):
stats
.
append
(
p_statement
(
s
,
level
,
stats
.
append
(
p_statement
(
s
,
ctx
,
first_statement
=
first_statement
))
cdef_flag
=
cdef_flag
,
visibility
=
visibility
,
api
=
api
,
first_statement
=
first_statement
))
first_statement
=
0
first_statement
=
0
if
len
(
stats
)
==
1
:
if
len
(
stats
)
==
1
:
return
stats
[
0
]
return
stats
[
0
]
else
:
else
:
return
Nodes
.
StatListNode
(
pos
,
stats
=
stats
)
return
Nodes
.
StatListNode
(
pos
,
stats
=
stats
)
def
p_suite
(
s
,
level
=
'other'
,
cdef_flag
=
0
,
def
p_suite
(
s
,
ctx
=
Ctx
(),
with_doc
=
0
,
with_pseudo_doc
=
0
):
visibility
=
'private'
,
with_doc
=
0
,
with_pseudo_doc
=
0
,
api
=
0
):
pos
=
s
.
position
()
pos
=
s
.
position
()
s
.
expect
(
':'
)
s
.
expect
(
':'
)
doc
=
None
doc
=
None
...
@@ -1413,17 +1423,13 @@ def p_suite(s, level = 'other', cdef_flag = 0,
...
@@ -1413,17 +1423,13 @@ def p_suite(s, level = 'other', cdef_flag = 0,
s
.
expect_indent
()
s
.
expect_indent
()
if
with_doc
or
with_pseudo_doc
:
if
with_doc
or
with_pseudo_doc
:
doc
=
p_doc_string
(
s
)
doc
=
p_doc_string
(
s
)
body
=
p_statement_list
(
s
,
body
=
p_statement_list
(
s
,
ctx
)
level
=
level
,
cdef_flag
=
cdef_flag
,
visibility
=
visibility
,
api
=
api
)
s
.
expect_dedent
()
s
.
expect_dedent
()
else
:
else
:
if
api
:
if
ctx
.
api
:
error
(
s
.
pos
,
"'api' not allowed with this statement"
)
error
(
s
.
pos
,
"'api' not allowed with this statement"
)
if
level
in
(
'module'
,
'class'
,
'function'
,
'other'
):
if
ctx
.
level
in
(
'module'
,
'class'
,
'function'
,
'other'
):
body
=
p_simple_statement_list
(
s
)
body
=
p_simple_statement_list
(
s
,
ctx
)
else
:
else
:
body
=
p_pass_statement
(
s
)
body
=
p_pass_statement
(
s
)
s
.
expect_newline
(
"Syntax error in declarations"
)
s
.
expect_newline
(
"Syntax error in declarations"
)
...
@@ -1556,8 +1562,9 @@ def p_opt_cname(s):
...
@@ -1556,8 +1562,9 @@ def p_opt_cname(s):
cname
=
None
cname
=
None
return
cname
return
cname
def
p_c_declarator
(
s
,
empty
=
0
,
is_type
=
0
,
cmethod_flag
=
0
,
assignable
=
0
,
def
p_c_declarator
(
s
,
ctx
=
Ctx
(),
empty
=
0
,
is_type
=
0
,
cmethod_flag
=
0
,
nonempty
=
0
,
calling_convention_allowed
=
0
):
assignable
=
0
,
nonempty
=
0
,
calling_convention_allowed
=
0
):
# If empty is true, the declarator must be empty. If nonempty is true,
# If empty is true, the declarator must be empty. If nonempty is true,
# the declarator must be nonempty. Otherwise we don't care.
# the declarator must be nonempty. Otherwise we don't care.
# If cmethod_flag is true, then if this declarator declares
# If cmethod_flag is true, then if this declarator declares
...
@@ -1567,13 +1574,16 @@ def p_c_declarator(s, empty = 0, is_type = 0, cmethod_flag = 0, assignable = 0,
...
@@ -1567,13 +1574,16 @@ def p_c_declarator(s, empty = 0, is_type = 0, cmethod_flag = 0, assignable = 0,
s
.
next
()
s
.
next
()
if
s
.
sy
==
')'
or
looking_at_type
(
s
):
if
s
.
sy
==
')'
or
looking_at_type
(
s
):
base
=
Nodes
.
CNameDeclaratorNode
(
pos
,
name
=
""
,
cname
=
None
)
base
=
Nodes
.
CNameDeclaratorNode
(
pos
,
name
=
""
,
cname
=
None
)
result
=
p_c_func_declarator
(
s
,
pos
,
base
,
cmethod_flag
)
result
=
p_c_func_declarator
(
s
,
pos
,
ctx
,
base
,
cmethod_flag
)
else
:
else
:
result
=
p_c_declarator
(
s
,
empty
,
is_type
,
cmethod_flag
,
nonempty
=
nonempty
,
result
=
p_c_declarator
(
s
,
ctx
,
empty
=
empty
,
is_type
=
is_type
,
cmethod_flag
=
cmethod_flag
,
nonempty
=
nonempty
,
calling_convention_allowed
=
1
)
calling_convention_allowed
=
1
)
s
.
expect
(
')'
)
s
.
expect
(
')'
)
else
:
else
:
result
=
p_c_simple_declarator
(
s
,
empty
,
is_type
,
cmethod_flag
,
assignable
,
nonempty
)
result
=
p_c_simple_declarator
(
s
,
ctx
,
empty
,
is_type
,
cmethod_flag
,
assignable
,
nonempty
)
if
not
calling_convention_allowed
and
result
.
calling_convention
and
s
.
sy
!=
'('
:
if
not
calling_convention_allowed
and
result
.
calling_convention
and
s
.
sy
!=
'('
:
error
(
s
.
position
(),
"%s on something that is not a function"
error
(
s
.
position
(),
"%s on something that is not a function"
%
result
.
calling_convention
)
%
result
.
calling_convention
)
...
@@ -1583,7 +1593,7 @@ def p_c_declarator(s, empty = 0, is_type = 0, cmethod_flag = 0, assignable = 0,
...
@@ -1583,7 +1593,7 @@ def p_c_declarator(s, empty = 0, is_type = 0, cmethod_flag = 0, assignable = 0,
result
=
p_c_array_declarator
(
s
,
result
)
result
=
p_c_array_declarator
(
s
,
result
)
else
:
# sy == '('
else
:
# sy == '('
s
.
next
()
s
.
next
()
result
=
p_c_func_declarator
(
s
,
pos
,
result
,
cmethod_flag
)
result
=
p_c_func_declarator
(
s
,
pos
,
ctx
,
result
,
cmethod_flag
)
cmethod_flag
=
0
cmethod_flag
=
0
return
result
return
result
...
@@ -1597,9 +1607,9 @@ def p_c_array_declarator(s, base):
...
@@ -1597,9 +1607,9 @@ 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_c_func_declarator
(
s
,
pos
,
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
,
in_pyfunc
=
0
,
cmethod_flag
=
cmethod_flag
,
args
=
p_c_arg_list
(
s
,
ctx
,
cmethod_flag
=
cmethod_flag
,
nonempty_declarators
=
0
)
nonempty_declarators
=
0
)
ellipsis
=
p_optional_ellipsis
(
s
)
ellipsis
=
p_optional_ellipsis
(
s
)
s
.
expect
(
')'
)
s
.
expect
(
')'
)
...
@@ -1609,19 +1619,24 @@ def p_c_func_declarator(s, pos, base, cmethod_flag):
...
@@ -1609,19 +1619,24 @@ def p_c_func_declarator(s, pos, base, cmethod_flag):
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
with_gil
,
with_gil
=
with_gil
)
nogil
=
nogil
or
ctx
.
nogil
or
with_gil
,
with_gil
=
with_gil
)
def
p_c_simple_declarator
(
s
,
empty
,
is_type
,
cmethod_flag
,
assignable
,
nonempty
):
def
p_c_simple_declarator
(
s
,
ctx
,
empty
,
is_type
,
cmethod_flag
,
assignable
,
nonempty
):
pos
=
s
.
position
()
pos
=
s
.
position
()
calling_convention
=
p_calling_convention
(
s
)
calling_convention
=
p_calling_convention
(
s
)
if
s
.
sy
==
'*'
:
if
s
.
sy
==
'*'
:
s
.
next
()
s
.
next
()
base
=
p_c_declarator
(
s
,
empty
,
is_type
,
cmethod_flag
,
assignable
,
nonempty
)
base
=
p_c_declarator
(
s
,
ctx
,
empty
=
empty
,
is_type
=
is_type
,
cmethod_flag
=
cmethod_flag
,
assignable
=
assignable
,
nonempty
=
nonempty
)
result
=
Nodes
.
CPtrDeclaratorNode
(
pos
,
result
=
Nodes
.
CPtrDeclaratorNode
(
pos
,
base
=
base
)
base
=
base
)
elif
s
.
sy
==
'**'
:
# scanner returns this as a single token
elif
s
.
sy
==
'**'
:
# scanner returns this as a single token
s
.
next
()
s
.
next
()
base
=
p_c_declarator
(
s
,
empty
,
is_type
,
cmethod_flag
,
assignable
,
nonempty
)
base
=
p_c_declarator
(
s
,
ctx
,
empty
=
empty
,
is_type
=
is_type
,
cmethod_flag
=
cmethod_flag
,
assignable
=
assignable
,
nonempty
=
nonempty
)
result
=
Nodes
.
CPtrDeclaratorNode
(
pos
,
result
=
Nodes
.
CPtrDeclaratorNode
(
pos
,
base
=
Nodes
.
CPtrDeclaratorNode
(
pos
,
base
=
Nodes
.
CPtrDeclaratorNode
(
pos
,
base
=
base
))
base
=
base
))
...
@@ -1687,28 +1702,14 @@ def p_exception_value_clause(s):
...
@@ -1687,28 +1702,14 @@ def p_exception_value_clause(s):
c_arg_list_terminators
=
(
'*'
,
'**'
,
'.'
,
')'
)
c_arg_list_terminators
=
(
'*'
,
'**'
,
'.'
,
')'
)
#def p_c_arg_list(s, in_pyfunc, cmethod_flag = 0, nonempty_declarators = 0,
def
p_c_arg_list
(
s
,
ctx
=
Ctx
(),
in_pyfunc
=
0
,
cmethod_flag
=
0
,
# kw_only = 0):
nonempty_declarators
=
0
,
kw_only
=
0
):
# args = []
# if s.sy not in c_arg_list_terminators:
# args.append(p_c_arg_decl(s, in_pyfunc, cmethod_flag,
# nonempty = nonempty_declarators, kw_only = kw_only))
# while s.sy == ',':
# s.next()
# if s.sy in c_arg_list_terminators:
# break
# args.append(p_c_arg_decl(s, in_pyfunc), nonempty = nonempty_declarators,
# kw_only = kw_only)
# return args
def
p_c_arg_list
(
s
,
in_pyfunc
,
cmethod_flag
=
0
,
nonempty_declarators
=
0
,
kw_only
=
0
):
# Comma-separated list of C argument declarations, possibly empty.
# Comma-separated list of C argument declarations, possibly empty.
# May have a trailing comma.
# May have a trailing comma.
args
=
[]
args
=
[]
is_self_arg
=
cmethod_flag
is_self_arg
=
cmethod_flag
while
s
.
sy
not
in
c_arg_list_terminators
:
while
s
.
sy
not
in
c_arg_list_terminators
:
args
.
append
(
p_c_arg_decl
(
s
,
in_pyfunc
,
is_self_arg
,
args
.
append
(
p_c_arg_decl
(
s
,
ctx
,
in_pyfunc
,
is_self_arg
,
nonempty
=
nonempty_declarators
,
kw_only
=
kw_only
))
nonempty
=
nonempty_declarators
,
kw_only
=
kw_only
))
if
s
.
sy
!=
','
:
if
s
.
sy
!=
','
:
break
break
...
@@ -1723,12 +1724,12 @@ def p_optional_ellipsis(s):
...
@@ -1723,12 +1724,12 @@ def p_optional_ellipsis(s):
else
:
else
:
return
0
return
0
def
p_c_arg_decl
(
s
,
in_pyfunc
,
cmethod_flag
=
0
,
nonempty
=
0
,
kw_only
=
0
):
def
p_c_arg_decl
(
s
,
ctx
,
in_pyfunc
,
cmethod_flag
=
0
,
nonempty
=
0
,
kw_only
=
0
):
pos
=
s
.
position
()
pos
=
s
.
position
()
not_none
=
0
not_none
=
0
default
=
None
default
=
None
base_type
=
p_c_base_type
(
s
,
cmethod_flag
,
nonempty
=
nonempty
)
base_type
=
p_c_base_type
(
s
,
cmethod_flag
,
nonempty
=
nonempty
)
declarator
=
p_c_declarator
(
s
,
nonempty
=
nonempty
)
declarator
=
p_c_declarator
(
s
,
ctx
,
nonempty
=
nonempty
)
if
s
.
sy
==
'not'
:
if
s
.
sy
==
'not'
:
s
.
next
()
s
.
next
()
if
s
.
sy
==
'IDENT'
and
s
.
systring
==
'None'
:
if
s
.
sy
==
'IDENT'
and
s
.
systring
==
'None'
:
...
@@ -1761,57 +1762,60 @@ def p_api(s):
...
@@ -1761,57 +1762,60 @@ def p_api(s):
else
:
else
:
return
0
return
0
def
p_cdef_statement
(
s
,
level
,
visibility
=
'private'
,
api
=
0
,
def
p_cdef_statement
(
s
,
ctx
):
overridable
=
False
):
pos
=
s
.
position
()
pos
=
s
.
position
()
visibility
=
p_visibility
(
s
,
visibility
)
ctx
.
visibility
=
p_visibility
(
s
,
ctx
.
visibility
)
api
=
api
or
p_api
(
s
)
ctx
.
api
=
ctx
.
api
or
p_api
(
s
)
if
api
:
if
ctx
.
api
:
if
visibility
not
in
(
'private'
,
'public'
):
if
ctx
.
visibility
not
in
(
'private'
,
'public'
):
error
(
pos
,
"Cannot combine 'api' with '%s'"
%
visibility
)
error
(
pos
,
"Cannot combine 'api' with '%s'"
%
ctx
.
visibility
)
if
(
visibility
==
'extern'
)
and
s
.
sy
==
'from'
:
if
(
ctx
.
visibility
==
'extern'
)
and
s
.
sy
==
'from'
:
return
p_cdef_extern_block
(
s
,
level
,
pos
)
return
p_cdef_extern_block
(
s
,
pos
,
ctx
)
elif
s
.
sy
==
'import'
:
elif
s
.
sy
==
'import'
:
s
.
next
()
s
.
next
()
return
p_cdef_extern_block
(
s
,
level
,
pos
)
return
p_cdef_extern_block
(
s
,
pos
,
ctx
)
elif
s
.
sy
==
':'
:
if
p_nogil
(
s
):
return
p_cdef_block
(
s
,
level
,
visibility
,
api
)
ctx
.
nogil
=
1
if
s
.
sy
==
':'
:
return
p_cdef_block
(
s
,
ctx
)
elif
s
.
sy
==
'class'
:
elif
s
.
sy
==
'class'
:
if
level
not
in
(
'module'
,
'module_pxd'
):
if
ctx
.
level
not
in
(
'module'
,
'module_pxd'
):
error
(
pos
,
"Extension type definition not allowed here"
)
error
(
pos
,
"Extension type definition not allowed here"
)
#if api:
#if
ctx.
api:
# error(pos, "'api' not allowed with extension class")
# error(pos, "'api' not allowed with extension class")
return
p_c_class_definition
(
s
,
level
,
pos
,
visibility
=
visibility
,
api
=
api
)
return
p_c_class_definition
(
s
,
pos
,
ctx
)
elif
s
.
sy
==
'IDENT'
and
s
.
systring
in
struct_union_or_enum
:
elif
s
.
sy
==
'IDENT'
and
s
.
systring
in
struct_union_or_enum
:
if
level
not
in
(
'module'
,
'module_pxd'
):
if
ctx
.
level
not
in
(
'module'
,
'module_pxd'
):
error
(
pos
,
"C struct/union/enum definition not allowed here"
)
error
(
pos
,
"C struct/union/enum definition not allowed here"
)
#if visibility == 'public':
#if
ctx.
visibility == 'public':
# error(pos, "Public struct/union/enum definition not implemented")
# error(pos, "Public struct/union/enum definition not implemented")
#if api:
#if
ctx.
api:
# error(pos, "'api' not allowed with '%s'" % s.systring)
# error(pos, "'api' not allowed with '%s'" % s.systring)
if
s
.
systring
==
"enum"
:
if
s
.
systring
==
"enum"
:
return
p_c_enum_definition
(
s
,
pos
,
level
,
visibility
)
return
p_c_enum_definition
(
s
,
pos
,
ctx
)
else
:
else
:
return
p_c_struct_or_union_definition
(
s
,
pos
,
level
,
visibility
)
return
p_c_struct_or_union_definition
(
s
,
pos
,
ctx
)
elif
s
.
sy
==
'pass'
:
elif
s
.
sy
==
'pass'
:
node
=
p_pass_statement
(
s
)
node
=
p_pass_statement
(
s
)
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
,
api
,
return
p_c_func_or_var_declaration
(
s
,
pos
,
ctx
)
overridable
)
def
p_cdef_block
(
s
,
level
,
visibility
,
api
):
def
p_cdef_block
(
s
,
ctx
):
return
p_suite
(
s
,
level
,
cdef_flag
=
1
,
visibility
=
visibility
,
api
=
api
)
return
p_suite
(
s
,
ctx
(
cdef_flag
=
1
)
)
def
p_cdef_extern_block
(
s
,
level
,
pos
):
def
p_cdef_extern_block
(
s
,
pos
,
ctx
):
include_file
=
None
include_file
=
None
s
.
expect
(
'from'
)
s
.
expect
(
'from'
)
if
s
.
sy
==
'*'
:
if
s
.
sy
==
'*'
:
s
.
next
()
s
.
next
()
else
:
else
:
_
,
include_file
=
p_string_literal
(
s
)
_
,
include_file
=
p_string_literal
(
s
)
body
=
p_suite
(
s
,
level
,
cdef_flag
=
1
,
visibility
=
'extern'
)
ctx
=
ctx
(
cdef_flag
=
1
,
visibility
=
'extern'
)
if
p_nogil
(
s
):
ctx
.
nogil
=
1
body
=
p_suite
(
s
,
ctx
)
return
Nodes
.
CDefExternNode
(
pos
,
return
Nodes
.
CDefExternNode
(
pos
,
include_file
=
include_file
,
include_file
=
include_file
,
body
=
body
)
body
=
body
)
...
@@ -1820,7 +1824,7 @@ struct_union_or_enum = (
...
@@ -1820,7 +1824,7 @@ struct_union_or_enum = (
"struct"
,
"union"
,
"enum"
"struct"
,
"union"
,
"enum"
)
)
def
p_c_enum_definition
(
s
,
pos
,
level
,
visibility
,
typedef_flag
=
0
):
def
p_c_enum_definition
(
s
,
pos
,
ctx
):
# s.sy == ident 'enum'
# s.sy == ident 'enum'
s
.
next
()
s
.
next
()
if
s
.
sy
==
'IDENT'
:
if
s
.
sy
==
'IDENT'
:
...
@@ -1842,9 +1846,10 @@ def p_c_enum_definition(s, pos, level, visibility, typedef_flag = 0):
...
@@ -1842,9 +1846,10 @@ def p_c_enum_definition(s, pos, level, visibility, typedef_flag = 0):
while
s
.
sy
not
in
(
'DEDENT'
,
'EOF'
):
while
s
.
sy
not
in
(
'DEDENT'
,
'EOF'
):
p_c_enum_line
(
s
,
items
)
p_c_enum_line
(
s
,
items
)
s
.
expect_dedent
()
s
.
expect_dedent
()
return
Nodes
.
CEnumDefNode
(
pos
,
name
=
name
,
cname
=
cname
,
return
Nodes
.
CEnumDefNode
(
items
=
items
,
typedef_flag
=
typedef_flag
,
visibility
=
visibility
,
pos
,
name
=
name
,
cname
=
cname
,
items
=
items
,
in_pxd
=
level
==
'module_pxd'
)
typedef_flag
=
ctx
.
typedef_flag
,
visibility
=
ctx
.
visibility
,
in_pxd
=
ctx
.
level
==
'module_pxd'
)
def
p_c_enum_line
(
s
,
items
):
def
p_c_enum_line
(
s
,
items
):
if
s
.
sy
!=
'pass'
:
if
s
.
sy
!=
'pass'
:
...
@@ -1869,7 +1874,7 @@ def p_c_enum_item(s, items):
...
@@ -1869,7 +1874,7 @@ def p_c_enum_item(s, items):
items
.
append
(
Nodes
.
CEnumDefItemNode
(
pos
,
items
.
append
(
Nodes
.
CEnumDefItemNode
(
pos
,
name
=
name
,
cname
=
cname
,
value
=
value
))
name
=
name
,
cname
=
cname
,
value
=
value
))
def
p_c_struct_or_union_definition
(
s
,
pos
,
level
,
visibility
,
typedef_flag
=
0
):
def
p_c_struct_or_union_definition
(
s
,
pos
,
ctx
):
# s.sy == ident 'struct' or 'union'
# s.sy == ident 'struct' or 'union'
kind
=
s
.
systring
kind
=
s
.
systring
s
.
next
()
s
.
next
()
...
@@ -1882,10 +1887,11 @@ def p_c_struct_or_union_definition(s, pos, level, visibility, typedef_flag = 0):
...
@@ -1882,10 +1887,11 @@ def p_c_struct_or_union_definition(s, pos, level, visibility, typedef_flag = 0):
s
.
expect
(
'NEWLINE'
)
s
.
expect
(
'NEWLINE'
)
s
.
expect_indent
()
s
.
expect_indent
()
attributes
=
[]
attributes
=
[]
body_ctx
=
Ctx
()
while
s
.
sy
!=
'DEDENT'
:
while
s
.
sy
!=
'DEDENT'
:
if
s
.
sy
!=
'pass'
:
if
s
.
sy
!=
'pass'
:
attributes
.
append
(
attributes
.
append
(
p_c_func_or_var_declaration
(
s
,
level
=
'other'
,
pos
=
s
.
position
()
))
p_c_func_or_var_declaration
(
s
,
s
.
position
(),
body_ctx
))
else
:
else
:
s
.
next
()
s
.
next
()
s
.
expect_newline
(
"Expected a newline"
)
s
.
expect_newline
(
"Expected a newline"
)
...
@@ -1894,8 +1900,8 @@ def p_c_struct_or_union_definition(s, pos, level, visibility, typedef_flag = 0):
...
@@ -1894,8 +1900,8 @@ def p_c_struct_or_union_definition(s, pos, level, visibility, typedef_flag = 0):
s
.
expect_newline
(
"Syntax error in struct or union definition"
)
s
.
expect_newline
(
"Syntax error in struct or union definition"
)
return
Nodes
.
CStructOrUnionDefNode
(
pos
,
return
Nodes
.
CStructOrUnionDefNode
(
pos
,
name
=
name
,
cname
=
cname
,
kind
=
kind
,
attributes
=
attributes
,
name
=
name
,
cname
=
cname
,
kind
=
kind
,
attributes
=
attributes
,
typedef_flag
=
typedef_flag
,
visibility
=
visibility
,
typedef_flag
=
ctx
.
typedef_flag
,
visibility
=
ctx
.
visibility
,
in_pxd
=
level
==
'module_pxd'
)
in_pxd
=
ctx
.
level
==
'module_pxd'
)
def
p_visibility
(
s
,
prev_visibility
):
def
p_visibility
(
s
,
prev_visibility
):
pos
=
s
.
position
()
pos
=
s
.
position
()
...
@@ -1915,26 +1921,26 @@ def p_c_modifiers(s):
...
@@ -1915,26 +1921,26 @@ def p_c_modifiers(s):
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'
,
api
=
0
,
def
p_c_func_or_var_declaration
(
s
,
pos
,
ctx
):
overridable
=
False
):
cmethod_flag
=
ctx
.
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
,
nonempty
=
1
)
base_type
=
p_c_base_type
(
s
,
nonempty
=
1
)
declarator
=
p_c_declarator
(
s
,
cmethod_flag
=
cmethod_flag
,
assignable
=
1
,
nonempty
=
1
)
declarator
=
p_c_declarator
(
s
,
ctx
,
cmethod_flag
=
cmethod_flag
,
declarator
.
overridable
=
overridable
assignable
=
1
,
nonempty
=
1
)
declarator
.
overridable
=
ctx
.
overridable
if
s
.
sy
==
':'
:
if
s
.
sy
==
':'
:
if
level
not
in
(
'module'
,
'c_class'
):
if
ctx
.
level
not
in
(
'module'
,
'c_class'
):
s
.
error
(
"C function definition not allowed here"
)
s
.
error
(
"C function definition not allowed here"
)
doc
,
suite
=
p_suite
(
s
,
'function'
,
with_doc
=
1
)
doc
,
suite
=
p_suite
(
s
,
Ctx
(
level
=
'function'
)
,
with_doc
=
1
)
result
=
Nodes
.
CFuncDefNode
(
pos
,
result
=
Nodes
.
CFuncDefNode
(
pos
,
visibility
=
visibility
,
visibility
=
ctx
.
visibility
,
base_type
=
base_type
,
base_type
=
base_type
,
declarator
=
declarator
,
declarator
=
declarator
,
body
=
suite
,
body
=
suite
,
doc
=
doc
,
doc
=
doc
,
modifiers
=
modifiers
,
modifiers
=
modifiers
,
api
=
api
,
api
=
ctx
.
api
,
overridable
=
overridable
)
overridable
=
ctx
.
overridable
)
else
:
else
:
#if api:
#if api:
# error(s.pos, "'api' not allowed with variable declaration")
# error(s.pos, "'api' not allowed with variable declaration")
...
@@ -1943,39 +1949,40 @@ def p_c_func_or_var_declaration(s, level, pos, visibility = 'private', api = 0,
...
@@ -1943,39 +1949,40 @@ def p_c_func_or_var_declaration(s, level, pos, visibility = 'private', api = 0,
s
.
next
()
s
.
next
()
if
s
.
sy
==
'NEWLINE'
:
if
s
.
sy
==
'NEWLINE'
:
break
break
declarator
=
p_c_declarator
(
s
,
cmethod_flag
=
cmethod_flag
,
assignable
=
1
,
nonempty
=
1
)
declarator
=
p_c_declarator
(
s
,
ctx
,
cmethod_flag
=
cmethod_flag
,
assignable
=
1
,
nonempty
=
1
)
declarators
.
append
(
declarator
)
declarators
.
append
(
declarator
)
s
.
expect_newline
(
"Syntax error in C variable declaration"
)
s
.
expect_newline
(
"Syntax error in C variable declaration"
)
result
=
Nodes
.
CVarDefNode
(
pos
,
result
=
Nodes
.
CVarDefNode
(
pos
,
visibility
=
visibility
,
visibility
=
ctx
.
visibility
,
base_type
=
base_type
,
base_type
=
base_type
,
declarators
=
declarators
,
declarators
=
declarators
,
in_pxd
=
level
==
'module_pxd'
,
in_pxd
=
ctx
.
level
==
'module_pxd'
,
api
=
api
,
api
=
ctx
.
api
,
overridable
=
overridable
)
overridable
=
ctx
.
overridable
)
return
result
return
result
def
p_ctypedef_statement
(
s
,
level
,
visibility
=
'private'
,
api
=
0
):
def
p_ctypedef_statement
(
s
,
ctx
):
# s.sy == 'ctypedef'
# s.sy == 'ctypedef'
pos
=
s
.
position
()
pos
=
s
.
position
()
s
.
next
()
s
.
next
()
visibility
=
p_visibility
(
s
,
visibility
)
visibility
=
p_visibility
(
s
,
ctx
.
visibility
)
ctx
=
ctx
(
typedef_flag
=
1
,
visibility
=
visibility
)
if
s
.
sy
==
'class'
:
if
s
.
sy
==
'class'
:
return
p_c_class_definition
(
s
,
level
,
pos
,
return
p_c_class_definition
(
s
,
pos
,
ctx
)
visibility
=
visibility
,
typedef_flag
=
1
,
api
=
api
)
elif
s
.
sy
==
'IDENT'
and
s
.
systring
in
(
'struct'
,
'union'
,
'enum'
):
elif
s
.
sy
==
'IDENT'
and
s
.
systring
in
(
'struct'
,
'union'
,
'enum'
):
if
s
.
systring
==
'enum'
:
if
s
.
systring
==
'enum'
:
return
p_c_enum_definition
(
s
,
pos
,
level
,
visibility
,
typedef_flag
=
1
)
return
p_c_enum_definition
(
s
,
pos
,
ctx
)
else
:
else
:
return
p_c_struct_or_union_definition
(
s
,
pos
,
level
,
visibility
,
return
p_c_struct_or_union_definition
(
s
,
pos
,
ctx
)
typedef_flag
=
1
)
else
:
else
:
base_type
=
p_c_base_type
(
s
,
nonempty
=
1
)
base_type
=
p_c_base_type
(
s
,
nonempty
=
1
)
declarator
=
p_c_declarator
(
s
,
is_type
=
1
,
nonempty
=
1
)
declarator
=
p_c_declarator
(
s
,
ctx
,
is_type
=
1
,
nonempty
=
1
)
s
.
expect_newline
(
"Syntax error in ctypedef statement"
)
s
.
expect_newline
(
"Syntax error in ctypedef statement"
)
return
Nodes
.
CTypeDefNode
(
pos
,
return
Nodes
.
CTypeDefNode
(
base_type
=
base_type
,
declarator
=
declarator
,
visibility
=
visibility
,
pos
,
base_type
=
base_type
,
in_pxd
=
level
==
'module_pxd'
)
declarator
=
declarator
,
visibility
=
visibility
,
in_pxd
=
ctx
.
level
==
'module_pxd'
)
def
p_def_statement
(
s
):
def
p_def_statement
(
s
):
# s.sy == 'def'
# s.sy == 'def'
...
@@ -2003,7 +2010,7 @@ def p_def_statement(s):
...
@@ -2003,7 +2010,7 @@ def p_def_statement(s):
s
.
expect
(
')'
)
s
.
expect
(
')'
)
if
p_nogil
(
s
):
if
p_nogil
(
s
):
error
(
s
.
pos
,
"Python function cannot be declared nogil"
)
error
(
s
.
pos
,
"Python function cannot be declared nogil"
)
doc
,
body
=
p_suite
(
s
,
'function'
,
with_doc
=
1
)
doc
,
body
=
p_suite
(
s
,
Ctx
(
level
=
'function'
)
,
with_doc
=
1
)
return
Nodes
.
DefNode
(
pos
,
name
=
name
,
args
=
args
,
return
Nodes
.
DefNode
(
pos
,
name
=
name
,
args
=
args
,
star_arg
=
star_arg
,
starstar_arg
=
starstar_arg
,
star_arg
=
star_arg
,
starstar_arg
=
starstar_arg
,
doc
=
doc
,
body
=
body
)
doc
=
doc
,
body
=
body
)
...
@@ -2025,14 +2032,13 @@ def p_class_statement(s):
...
@@ -2025,14 +2032,13 @@ def p_class_statement(s):
s
.
expect
(
')'
)
s
.
expect
(
')'
)
else
:
else
:
base_list
=
[]
base_list
=
[]
doc
,
body
=
p_suite
(
s
,
'class'
,
with_doc
=
1
)
doc
,
body
=
p_suite
(
s
,
Ctx
(
level
=
'class'
)
,
with_doc
=
1
)
return
Nodes
.
PyClassDefNode
(
pos
,
return
Nodes
.
PyClassDefNode
(
pos
,
name
=
class_name
,
name
=
class_name
,
bases
=
ExprNodes
.
TupleNode
(
pos
,
args
=
base_list
),
bases
=
ExprNodes
.
TupleNode
(
pos
,
args
=
base_list
),
doc
=
doc
,
body
=
body
)
doc
=
doc
,
body
=
body
)
def
p_c_class_definition
(
s
,
level
,
pos
,
def
p_c_class_definition
(
s
,
pos
,
ctx
):
visibility
=
'private'
,
typedef_flag
=
0
,
api
=
0
):
# s.sy == 'class'
# s.sy == 'class'
s
.
next
()
s
.
next
()
module_path
=
[]
module_path
=
[]
...
@@ -2041,7 +2047,7 @@ def p_c_class_definition(s, level, pos,
...
@@ -2041,7 +2047,7 @@ def p_c_class_definition(s, level, pos,
s
.
next
()
s
.
next
()
module_path
.
append
(
class_name
)
module_path
.
append
(
class_name
)
class_name
=
p_ident
(
s
)
class_name
=
p_ident
(
s
)
if
module_path
and
visibility
!=
'extern'
:
if
module_path
and
ctx
.
visibility
!=
'extern'
:
error
(
pos
,
"Qualified class name only allowed for 'extern' C class"
)
error
(
pos
,
"Qualified class name only allowed for 'extern' C class"
)
if
module_path
and
s
.
sy
==
'IDENT'
and
s
.
systring
==
'as'
:
if
module_path
and
s
.
sy
==
'IDENT'
and
s
.
systring
==
'as'
:
s
.
next
()
s
.
next
()
...
@@ -2065,38 +2071,38 @@ def p_c_class_definition(s, level, pos,
...
@@ -2065,38 +2071,38 @@ def p_c_class_definition(s, level, pos,
base_class_module
=
"."
.
join
(
base_class_path
[:
-
1
])
base_class_module
=
"."
.
join
(
base_class_path
[:
-
1
])
base_class_name
=
base_class_path
[
-
1
]
base_class_name
=
base_class_path
[
-
1
]
if
s
.
sy
==
'['
:
if
s
.
sy
==
'['
:
if
visibility
not
in
(
'public'
,
'extern'
):
if
ctx
.
visibility
not
in
(
'public'
,
'extern'
):
error
(
s
.
position
(),
"Name options only allowed for 'public' or 'extern' C class"
)
error
(
s
.
position
(),
"Name options only allowed for 'public' or 'extern' C class"
)
objstruct_name
,
typeobj_name
=
p_c_class_options
(
s
)
objstruct_name
,
typeobj_name
=
p_c_class_options
(
s
)
if
s
.
sy
==
':'
:
if
s
.
sy
==
':'
:
if
level
==
'module_pxd'
:
if
ctx
.
level
==
'module_pxd'
:
body_level
=
'c_class_pxd'
body_level
=
'c_class_pxd'
else
:
else
:
body_level
=
'c_class'
body_level
=
'c_class'
doc
,
body
=
p_suite
(
s
,
body_level
,
with_doc
=
1
)
doc
,
body
=
p_suite
(
s
,
Ctx
(
level
=
body_level
)
,
with_doc
=
1
)
else
:
else
:
s
.
expect_newline
(
"Syntax error in C class definition"
)
s
.
expect_newline
(
"Syntax error in C class definition"
)
doc
=
None
doc
=
None
body
=
None
body
=
None
if
visibility
==
'extern'
:
if
ctx
.
visibility
==
'extern'
:
if
not
module_path
:
if
not
module_path
:
error
(
pos
,
"Module name required for 'extern' C class"
)
error
(
pos
,
"Module name required for 'extern' C class"
)
if
typeobj_name
:
if
typeobj_name
:
error
(
pos
,
"Type object name specification not allowed for 'extern' C class"
)
error
(
pos
,
"Type object name specification not allowed for 'extern' C class"
)
elif
visibility
==
'public'
:
elif
ctx
.
visibility
==
'public'
:
if
not
objstruct_name
:
if
not
objstruct_name
:
error
(
pos
,
"Object struct name specification required for 'public' C class"
)
error
(
pos
,
"Object struct name specification required for 'public' C class"
)
if
not
typeobj_name
:
if
not
typeobj_name
:
error
(
pos
,
"Type object name specification required for 'public' C class"
)
error
(
pos
,
"Type object name specification required for 'public' C class"
)
elif
visibility
==
'private'
:
elif
ctx
.
visibility
==
'private'
:
if
api
:
if
ctx
.
api
:
error
(
pos
,
"Only 'public' C class can be declared 'api'"
)
error
(
pos
,
"Only 'public' C class can be declared 'api'"
)
else
:
else
:
error
(
pos
,
"Invalid class visibility '%s'"
%
visibility
)
error
(
pos
,
"Invalid class visibility '%s'"
%
ctx
.
visibility
)
return
Nodes
.
CClassDefNode
(
pos
,
return
Nodes
.
CClassDefNode
(
pos
,
visibility
=
visibility
,
visibility
=
ctx
.
visibility
,
typedef_flag
=
typedef_flag
,
typedef_flag
=
ctx
.
typedef_flag
,
api
=
api
,
api
=
ctx
.
api
,
module_name
=
"."
.
join
(
module_path
),
module_name
=
"."
.
join
(
module_path
),
class_name
=
class_name
,
class_name
=
class_name
,
as_name
=
as_name
,
as_name
=
as_name
,
...
@@ -2104,7 +2110,7 @@ def p_c_class_definition(s, level, pos,
...
@@ -2104,7 +2110,7 @@ def p_c_class_definition(s, level, pos,
base_class_name
=
base_class_name
,
base_class_name
=
base_class_name
,
objstruct_name
=
objstruct_name
,
objstruct_name
=
objstruct_name
,
typeobj_name
=
typeobj_name
,
typeobj_name
=
typeobj_name
,
in_pxd
=
level
==
'module_pxd'
,
in_pxd
=
ctx
.
level
==
'module_pxd'
,
doc
=
doc
,
doc
=
doc
,
body
=
body
)
body
=
body
)
...
@@ -2131,7 +2137,7 @@ def p_property_decl(s):
...
@@ -2131,7 +2137,7 @@ def p_property_decl(s):
pos
=
s
.
position
()
pos
=
s
.
position
()
s
.
next
()
# 'property'
s
.
next
()
# 'property'
name
=
p_ident
(
s
)
name
=
p_ident
(
s
)
doc
,
body
=
p_suite
(
s
,
'property'
,
with_doc
=
1
)
doc
,
body
=
p_suite
(
s
,
Ctx
(
level
=
'property'
)
,
with_doc
=
1
)
return
Nodes
.
PropertyNode
(
pos
,
name
=
name
,
doc
=
doc
,
body
=
body
)
return
Nodes
.
PropertyNode
(
pos
,
name
=
name
,
doc
=
doc
,
body
=
body
)
def
p_doc_string
(
s
):
def
p_doc_string
(
s
):
...
@@ -2152,7 +2158,7 @@ def p_module(s, pxd, full_module_name):
...
@@ -2152,7 +2158,7 @@ def p_module(s, pxd, full_module_name):
level
=
'module_pxd'
level
=
'module_pxd'
else
:
else
:
level
=
'module'
level
=
'module'
body
=
p_statement_list
(
s
,
level
,
first_statement
=
1
)
body
=
p_statement_list
(
s
,
Ctx
(
level
=
level
)
,
first_statement
=
1
)
if
s
.
sy
!=
'EOF'
:
if
s
.
sy
!=
'EOF'
:
s
.
error
(
"Syntax error in statement [%s,%s]"
%
(
s
.
error
(
"Syntax error in statement [%s,%s]"
%
(
repr
(
s
.
sy
),
repr
(
s
.
systring
)))
repr
(
s
.
sy
),
repr
(
s
.
systring
)))
...
...
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