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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
422a77f8
Commit
422a77f8
authored
Oct 15, 2009
by
Peter Alexander
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
naming references changed from 'option' to 'directive'
parent
49ef0f6b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
87 deletions
+87
-87
Cython/Compiler/CmdLine.py
Cython/Compiler/CmdLine.py
+1
-1
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+18
-18
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+65
-65
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+3
-3
No files found.
Cython/Compiler/CmdLine.py
View file @
422a77f8
...
@@ -126,7 +126,7 @@ def parse_command_line(args):
...
@@ -126,7 +126,7 @@ def parse_command_line(args):
options
.
emit_linenums
=
True
options
.
emit_linenums
=
True
elif
option
in
(
"-X"
,
"--directive"
):
elif
option
in
(
"-X"
,
"--directive"
):
try
:
try
:
options
.
compiler_directives
=
Options
.
parse_
option
_list
(
pop_arg
())
options
.
compiler_directives
=
Options
.
parse_
directive
_list
(
pop_arg
())
except
ValueError
,
e
:
except
ValueError
,
e
:
sys
.
stderr
.
write
(
"Error in compiler directive: %s
\
n
"
%
e
.
message
)
sys
.
stderr
.
write
(
"Error in compiler directive: %s
\
n
"
%
e
.
message
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
...
...
Cython/Compiler/Options.py
View file @
422a77f8
...
@@ -55,7 +55,7 @@ embed = False
...
@@ -55,7 +55,7 @@ embed = False
# Declare compiler directives
# Declare compiler directives
option
_defaults
=
{
directive
_defaults
=
{
'boundscheck'
:
True
,
'boundscheck'
:
True
,
'nonecheck'
:
False
,
'nonecheck'
:
False
,
'embedsignature'
:
False
,
'embedsignature'
:
False
,
...
@@ -77,35 +77,35 @@ option_defaults = {
...
@@ -77,35 +77,35 @@ option_defaults = {
}
}
# Override types possibilities above, if needed
# Override types possibilities above, if needed
option
_types
=
{}
directive
_types
=
{}
for
key
,
val
in
option
_defaults
.
items
():
for
key
,
val
in
directive
_defaults
.
items
():
if
key
not
in
option
_types
:
if
key
not
in
directive
_types
:
option
_types
[
key
]
=
type
(
val
)
directive
_types
[
key
]
=
type
(
val
)
option
_scopes
=
{
# defaults to available everywhere
directive
_scopes
=
{
# defaults to available everywhere
# 'module', 'function', 'class', 'with statement'
# 'module', 'function', 'class', 'with statement'
'autotestdict'
:
(
'module'
,),
'autotestdict'
:
(
'module'
,),
'test_assert_path_exists'
:
(
'function'
,),
'test_assert_path_exists'
:
(
'function'
,),
'test_fail_if_path_exists'
:
(
'function'
,),
'test_fail_if_path_exists'
:
(
'function'
,),
}
}
def
parse_
option
_value
(
name
,
value
):
def
parse_
directive
_value
(
name
,
value
):
"""
"""
Parses value as an option value for the given name and returns
Parses value as an option value for the given name and returns
the interpreted value. None is returned if the option does not exist.
the interpreted value. None is returned if the option does not exist.
>>> print parse_
option
_value('nonexisting', 'asdf asdfd')
>>> print parse_
directive
_value('nonexisting', 'asdf asdfd')
None
None
>>> parse_
option
_value('boundscheck', 'True')
>>> parse_
directive
_value('boundscheck', 'True')
True
True
>>> parse_
option
_value('boundscheck', 'true')
>>> parse_
directive
_value('boundscheck', 'true')
Traceback (most recent call last):
Traceback (most recent call last):
...
...
ValueError: boundscheck directive must be set to True or False
ValueError: boundscheck directive must be set to True or False
"""
"""
type
=
option
_types
.
get
(
name
)
type
=
directive
_types
.
get
(
name
)
if
not
type
:
return
None
if
not
type
:
return
None
if
type
is
bool
:
if
type
is
bool
:
if
value
==
"True"
:
return
True
if
value
==
"True"
:
return
True
...
@@ -119,25 +119,25 @@ def parse_option_value(name, value):
...
@@ -119,25 +119,25 @@ def parse_option_value(name, value):
else
:
else
:
assert
False
assert
False
def
parse_
option
_list
(
s
):
def
parse_
directive
_list
(
s
):
"""
"""
Parses a comma-seperated list of pragma options. Whitespace
Parses a comma-seperated list of pragma options. Whitespace
is not considered.
is not considered.
>>> parse_
option
_list(' ')
>>> parse_
directive
_list(' ')
{}
{}
>>> (parse_
option
_list('boundscheck=True') ==
>>> (parse_
directive
_list('boundscheck=True') ==
... {'boundscheck': True})
... {'boundscheck': True})
True
True
>>> parse_
option
_list(' asdf')
>>> parse_
directive
_list(' asdf')
Traceback (most recent call last):
Traceback (most recent call last):
...
...
ValueError: Expected "=" in option "asdf"
ValueError: Expected "=" in option "asdf"
>>> parse_
option
_list('boundscheck=hey')
>>> parse_
directive
_list('boundscheck=hey')
Traceback (most recent call last):
Traceback (most recent call last):
...
...
ValueError: Must pass a boolean value for option "boundscheck"
ValueError: Must pass a boolean value for option "boundscheck"
>>> parse_
option
_list('unknown=True')
>>> parse_
directive
_list('unknown=True')
Traceback (most recent call last):
Traceback (most recent call last):
...
...
ValueError: Unknown option: "unknown"
ValueError: Unknown option: "unknown"
...
@@ -149,7 +149,7 @@ def parse_option_list(s):
...
@@ -149,7 +149,7 @@ def parse_option_list(s):
if
not
'='
in
item
:
raise
ValueError
(
'Expected "=" in option "%s"'
%
item
)
if
not
'='
in
item
:
raise
ValueError
(
'Expected "=" in option "%s"'
%
item
)
name
,
value
=
item
.
strip
().
split
(
'='
)
name
,
value
=
item
.
strip
().
split
(
'='
)
try
:
try
:
type
=
option
_types
[
name
]
type
=
directive
_types
[
name
]
except
KeyError
:
except
KeyError
:
raise
ValueError
(
'Unknown option: "%s"'
%
name
)
raise
ValueError
(
'Unknown option: "%s"'
%
name
)
if
type
is
bool
:
if
type
is
bool
:
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
422a77f8
...
@@ -153,10 +153,10 @@ class PostParse(CythonTransform):
...
@@ -153,10 +153,10 @@ class PostParse(CythonTransform):
- For __cythonbufferdefaults__ the arguments are checked for
- For __cythonbufferdefaults__ the arguments are checked for
validity.
validity.
CBufferAccessTypeNode has its
option
s interpreted:
CBufferAccessTypeNode has its
directive
s interpreted:
Any first positional argument goes into the "dtype" attribute,
Any first positional argument goes into the "dtype" attribute,
any "ndim" keyword argument goes into the "ndim" attribute and
any "ndim" keyword argument goes into the "ndim" attribute and
so on. Also it is checked that the
option
combination is valid.
so on. Also it is checked that the
directive
combination is valid.
- __cythonbufferdefaults__ attributes are parsed and put into the
- __cythonbufferdefaults__ attributes are parsed and put into the
type information.
type information.
...
@@ -304,14 +304,14 @@ class PxdPostParse(CythonTransform, SkipDeclarations):
...
@@ -304,14 +304,14 @@ class PxdPostParse(CythonTransform, SkipDeclarations):
class
InterpretCompilerDirectives
(
CythonTransform
,
SkipDeclarations
):
class
InterpretCompilerDirectives
(
CythonTransform
,
SkipDeclarations
):
"""
"""
After parsing,
option
s can be stored in a number of places:
After parsing,
directive
s can be stored in a number of places:
- #cython-comments at the top of the file (stored in ModuleNode)
- #cython-comments at the top of the file (stored in ModuleNode)
- Command-line arguments overriding these
- Command-line arguments overriding these
- @cython.
option
name decorators
- @cython.
directive
name decorators
- with cython.
option
name: statements
- with cython.
directive
name: statements
This transform is responsible for interpreting these various sources
This transform is responsible for interpreting these various sources
and store the
option
in two ways:
and store the
directive
in two ways:
- Set the directives attribute of the ModuleNode for global directives.
- Set the directives attribute of the ModuleNode for global directives.
- Use a CompilerDirectivesNode to override directives for a subtree.
- Use a CompilerDirectivesNode to override directives for a subtree.
...
@@ -330,16 +330,16 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -330,16 +330,16 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
"""
"""
special_methods
=
set
([
'declare'
,
'union'
,
'struct'
,
'typedef'
,
'sizeof'
,
'typeof'
,
'cast'
,
'address'
,
'pointer'
,
'compiled'
,
'NULL'
])
special_methods
=
set
([
'declare'
,
'union'
,
'struct'
,
'typedef'
,
'sizeof'
,
'typeof'
,
'cast'
,
'address'
,
'pointer'
,
'compiled'
,
'NULL'
])
def
__init__
(
self
,
context
,
compilation_
option
_overrides
):
def
__init__
(
self
,
context
,
compilation_
directive
_overrides
):
super
(
InterpretCompilerDirectives
,
self
).
__init__
(
context
)
super
(
InterpretCompilerDirectives
,
self
).
__init__
(
context
)
self
.
compilation_
option
_overrides
=
{}
self
.
compilation_
directive
_overrides
=
{}
for
key
,
value
in
compilation_
option
_overrides
.
iteritems
():
for
key
,
value
in
compilation_
directive
_overrides
.
iteritems
():
self
.
compilation_
option
_overrides
[
unicode
(
key
)]
=
value
self
.
compilation_
directive
_overrides
[
unicode
(
key
)]
=
value
self
.
cython_module_names
=
set
()
self
.
cython_module_names
=
set
()
self
.
option
_names
=
{}
self
.
directive
_names
=
{}
def
check_directive_scope
(
self
,
pos
,
directive
,
scope
):
def
check_directive_scope
(
self
,
pos
,
directive
,
scope
):
legal_scopes
=
Options
.
option
_scopes
.
get
(
directive
,
None
)
legal_scopes
=
Options
.
directive
_scopes
.
get
(
directive
,
None
)
if
legal_scopes
and
scope
not
in
legal_scopes
:
if
legal_scopes
and
scope
not
in
legal_scopes
:
self
.
context
.
nonfatal_error
(
PostParseError
(
pos
,
'The %s compiler directive '
self
.
context
.
nonfatal_error
(
PostParseError
(
pos
,
'The %s compiler directive '
'is not allowed in %s scope'
%
(
directive
,
scope
)))
'is not allowed in %s scope'
%
(
directive
,
scope
)))
...
@@ -349,19 +349,19 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -349,19 +349,19 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
# Set up processing and handle the cython: comments.
# Set up processing and handle the cython: comments.
def
visit_ModuleNode
(
self
,
node
):
def
visit_ModuleNode
(
self
,
node
):
options
=
copy
.
copy
(
Options
.
option
_defaults
)
directives
=
copy
.
copy
(
Options
.
directive
_defaults
)
for
key
,
value
in
self
.
compilation_
option
_overrides
.
iteritems
():
for
key
,
value
in
self
.
compilation_
directive
_overrides
.
iteritems
():
if
not
self
.
check_directive_scope
(
node
.
pos
,
key
,
'module'
):
if
not
self
.
check_directive_scope
(
node
.
pos
,
key
,
'module'
):
self
.
wrong_scope_error
(
node
.
pos
,
key
,
'module'
)
self
.
wrong_scope_error
(
node
.
pos
,
key
,
'module'
)
del
self
.
compilation_
option
_overrides
[
key
]
del
self
.
compilation_
directive
_overrides
[
key
]
continue
continue
if
key
in
node
.
option_comments
and
node
.
option
_comments
[
key
]
!=
value
:
if
key
in
node
.
directive_comments
and
node
.
directive
_comments
[
key
]
!=
value
:
warning
(
node
.
pos
,
"Compiler directive differs between environment and file header; this will change "
warning
(
node
.
pos
,
"Compiler directive differs between environment and file header; this will change "
"in Cython 0.12. See http://article.gmane.org/gmane.comp.python.cython.devel/5233"
,
2
)
"in Cython 0.12. See http://article.gmane.org/gmane.comp.python.cython.devel/5233"
,
2
)
options
.
update
(
node
.
option
_comments
)
directives
.
update
(
node
.
directive
_comments
)
options
.
update
(
self
.
compilation_option
_overrides
)
directives
.
update
(
self
.
compilation_directive
_overrides
)
self
.
options
=
option
s
self
.
directives
=
directive
s
node
.
directives
=
option
s
node
.
directives
=
directive
s
self
.
visitchildren
(
node
)
self
.
visitchildren
(
node
)
node
.
cython_module_names
=
self
.
cython_module_names
node
.
cython_module_names
=
self
.
cython_module_names
return
node
return
node
...
@@ -380,15 +380,15 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -380,15 +380,15 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
if
node
.
module_name
==
u"cython"
:
if
node
.
module_name
==
u"cython"
:
newimp
=
[]
newimp
=
[]
for
pos
,
name
,
as_name
,
kind
in
node
.
imported_names
:
for
pos
,
name
,
as_name
,
kind
in
node
.
imported_names
:
if
(
name
in
Options
.
option
_types
or
if
(
name
in
Options
.
directive
_types
or
name
in
self
.
special_methods
or
name
in
self
.
special_methods
or
PyrexTypes
.
parse_basic_type
(
name
)):
PyrexTypes
.
parse_basic_type
(
name
)):
if
as_name
is
None
:
if
as_name
is
None
:
as_name
=
name
as_name
=
name
self
.
option
_names
[
as_name
]
=
name
self
.
directive
_names
[
as_name
]
=
name
if
kind
is
not
None
:
if
kind
is
not
None
:
self
.
context
.
nonfatal_error
(
PostParseError
(
pos
,
self
.
context
.
nonfatal_error
(
PostParseError
(
pos
,
"Compiler
option
imports must be plain imports"
))
"Compiler
directive
imports must be plain imports"
))
else
:
else
:
newimp
.
append
((
pos
,
name
,
as_name
,
kind
))
newimp
.
append
((
pos
,
name
,
as_name
,
kind
))
if
not
newimp
:
if
not
newimp
:
...
@@ -400,10 +400,10 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -400,10 +400,10 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
if
node
.
module
.
module_name
.
value
==
u"cython"
:
if
node
.
module
.
module_name
.
value
==
u"cython"
:
newimp
=
[]
newimp
=
[]
for
name
,
name_node
in
node
.
items
:
for
name
,
name_node
in
node
.
items
:
if
(
name
in
Options
.
option
_types
or
if
(
name
in
Options
.
directive
_types
or
name
in
self
.
special_methods
or
name
in
self
.
special_methods
or
PyrexTypes
.
parse_basic_type
(
name
)):
PyrexTypes
.
parse_basic_type
(
name
)):
self
.
option
_names
[
name_node
.
name
]
=
name
self
.
directive
_names
[
name_node
.
name
]
=
name
else
:
else
:
newimp
.
append
((
name
,
name_node
))
newimp
.
append
((
name
,
name_node
))
if
not
newimp
:
if
not
newimp
:
...
@@ -426,12 +426,12 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -426,12 +426,12 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
if
node
.
name
in
self
.
cython_module_names
:
if
node
.
name
in
self
.
cython_module_names
:
node
.
is_cython_module
=
True
node
.
is_cython_module
=
True
else
:
else
:
node
.
cython_attribute
=
self
.
option
_names
.
get
(
node
.
name
)
node
.
cython_attribute
=
self
.
directive
_names
.
get
(
node
.
name
)
return
node
return
node
def
try_to_parse_
option
(
self
,
node
):
def
try_to_parse_
directive
(
self
,
node
):
# If node is the contents of an
option
(in a with statement or
# If node is the contents of an
directive
(in a with statement or
# decorator), returns (
option
name, value).
# decorator), returns (
directive
name, value).
# Otherwise, returns None
# Otherwise, returns None
optname
=
None
optname
=
None
if
isinstance
(
node
,
CallNode
):
if
isinstance
(
node
,
CallNode
):
...
@@ -439,56 +439,56 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -439,56 +439,56 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
optname
=
node
.
function
.
as_cython_attribute
()
optname
=
node
.
function
.
as_cython_attribute
()
if
optname
:
if
optname
:
optiontype
=
Options
.
option
_types
.
get
(
optname
)
directivetype
=
Options
.
directive
_types
.
get
(
optname
)
if
option
type
:
if
directive
type
:
args
,
kwds
=
node
.
explicit_args_kwds
()
args
,
kwds
=
node
.
explicit_args_kwds
()
if
option
type
is
bool
:
if
directive
type
is
bool
:
if
kwds
is
not
None
or
len
(
args
)
!=
1
or
not
isinstance
(
args
[
0
],
BoolNode
):
if
kwds
is
not
None
or
len
(
args
)
!=
1
or
not
isinstance
(
args
[
0
],
BoolNode
):
raise
PostParseError
(
node
.
function
.
pos
,
raise
PostParseError
(
node
.
function
.
pos
,
'The %s
option
takes one compile-time boolean argument'
%
optname
)
'The %s
directive
takes one compile-time boolean argument'
%
optname
)
return
(
optname
,
args
[
0
].
value
)
return
(
optname
,
args
[
0
].
value
)
elif
option
type
is
str
:
elif
directive
type
is
str
:
if
kwds
is
not
None
or
len
(
args
)
!=
1
or
not
isinstance
(
args
[
0
],
(
StringNode
,
UnicodeNode
)):
if
kwds
is
not
None
or
len
(
args
)
!=
1
or
not
isinstance
(
args
[
0
],
(
StringNode
,
UnicodeNode
)):
raise
PostParseError
(
node
.
function
.
pos
,
raise
PostParseError
(
node
.
function
.
pos
,
'The %s
option
takes one compile-time string argument'
%
optname
)
'The %s
directive
takes one compile-time string argument'
%
optname
)
return
(
optname
,
str
(
args
[
0
].
value
))
return
(
optname
,
str
(
args
[
0
].
value
))
elif
option
type
is
dict
:
elif
directive
type
is
dict
:
if
len
(
args
)
!=
0
:
if
len
(
args
)
!=
0
:
raise
PostParseError
(
node
.
function
.
pos
,
raise
PostParseError
(
node
.
function
.
pos
,
'The %s
option
takes no prepositional arguments'
%
optname
)
'The %s
directive
takes no prepositional arguments'
%
optname
)
return
optname
,
dict
([(
key
.
value
,
value
)
for
key
,
value
in
kwds
.
key_value_pairs
])
return
optname
,
dict
([(
key
.
value
,
value
)
for
key
,
value
in
kwds
.
key_value_pairs
])
elif
option
type
is
list
:
elif
directive
type
is
list
:
if
kwds
and
len
(
kwds
)
!=
0
:
if
kwds
and
len
(
kwds
)
!=
0
:
raise
PostParseError
(
node
.
function
.
pos
,
raise
PostParseError
(
node
.
function
.
pos
,
'The %s
option
takes no keyword arguments'
%
optname
)
'The %s
directive
takes no keyword arguments'
%
optname
)
return
optname
,
[
str
(
arg
.
value
)
for
arg
in
args
]
return
optname
,
[
str
(
arg
.
value
)
for
arg
in
args
]
else
:
else
:
assert
False
assert
False
return
None
return
None
def
visit_with_
options
(
self
,
body
,
option
s
):
def
visit_with_
directives
(
self
,
body
,
directive
s
):
old
options
=
self
.
option
s
old
directives
=
self
.
directive
s
new
options
=
copy
.
copy
(
oldoption
s
)
new
directives
=
copy
.
copy
(
olddirective
s
)
new
options
.
update
(
option
s
)
new
directives
.
update
(
directive
s
)
self
.
options
=
newoption
s
self
.
directives
=
newdirective
s
assert
isinstance
(
body
,
StatListNode
),
body
assert
isinstance
(
body
,
StatListNode
),
body
retbody
=
self
.
visit_Node
(
body
)
retbody
=
self
.
visit_Node
(
body
)
directive
=
CompilerDirectivesNode
(
pos
=
retbody
.
pos
,
body
=
retbody
,
directive
=
CompilerDirectivesNode
(
pos
=
retbody
.
pos
,
body
=
retbody
,
directives
=
new
option
s
)
directives
=
new
directive
s
)
self
.
options
=
oldoption
s
self
.
directives
=
olddirective
s
return
directive
return
directive
# Handle decorators
# Handle decorators
def
visit_FuncDefNode
(
self
,
node
):
def
visit_FuncDefNode
(
self
,
node
):
option
s
=
[]
directive
s
=
[]
if
node
.
decorators
:
if
node
.
decorators
:
# Split the decorators into two lists -- real decorators and
option
s
# Split the decorators into two lists -- real decorators and
directive
s
realdecs
=
[]
realdecs
=
[]
for
dec
in
node
.
decorators
:
for
dec
in
node
.
decorators
:
option
=
self
.
try_to_parse_option
(
dec
.
decorator
)
directive
=
self
.
try_to_parse_directive
(
dec
.
decorator
)
if
option
is
not
None
:
if
directive
is
not
None
:
options
.
append
(
option
)
directives
.
append
(
directive
)
else
:
else
:
realdecs
.
append
(
dec
)
realdecs
.
append
(
dec
)
if
realdecs
and
isinstance
(
node
,
CFuncDefNode
):
if
realdecs
and
isinstance
(
node
,
CFuncDefNode
):
...
@@ -496,12 +496,12 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -496,12 +496,12 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
else
:
else
:
node
.
decorators
=
realdecs
node
.
decorators
=
realdecs
if
option
s
:
if
directive
s
:
optdict
=
{}
optdict
=
{}
option
s
.
reverse
()
# Decorators coming first take precedence
directive
s
.
reverse
()
# Decorators coming first take precedence
for
option
in
option
s
:
for
directive
in
directive
s
:
name
,
value
=
option
name
,
value
=
directive
legal_scopes
=
Options
.
option
_scopes
.
get
(
name
,
None
)
legal_scopes
=
Options
.
directive
_scopes
.
get
(
name
,
None
)
if
not
self
.
check_directive_scope
(
node
.
pos
,
name
,
'function'
):
if
not
self
.
check_directive_scope
(
node
.
pos
,
name
,
'function'
):
continue
continue
if
name
in
optdict
:
if
name
in
optdict
:
...
@@ -517,16 +517,16 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -517,16 +517,16 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
else
:
else
:
optdict
[
name
]
=
value
optdict
[
name
]
=
value
body
=
StatListNode
(
node
.
pos
,
stats
=
[
node
])
body
=
StatListNode
(
node
.
pos
,
stats
=
[
node
])
return
self
.
visit_with_
option
s
(
body
,
optdict
)
return
self
.
visit_with_
directive
s
(
body
,
optdict
)
else
:
else
:
return
self
.
visit_Node
(
node
)
return
self
.
visit_Node
(
node
)
def
visit_CVarDefNode
(
self
,
node
):
def
visit_CVarDefNode
(
self
,
node
):
if
node
.
decorators
:
if
node
.
decorators
:
for
dec
in
node
.
decorators
:
for
dec
in
node
.
decorators
:
option
=
self
.
try_to_parse_option
(
dec
.
decorator
)
directive
=
self
.
try_to_parse_directive
(
dec
.
decorator
)
if
option
is
not
None
and
option
[
0
]
==
u'locals'
:
if
directive
is
not
None
and
directive
[
0
]
==
u'locals'
:
node
.
directive_locals
=
option
[
1
]
node
.
directive_locals
=
directive
[
1
]
else
:
else
:
self
.
context
.
nonfatal_error
(
PostParseError
(
dec
.
pos
,
self
.
context
.
nonfatal_error
(
PostParseError
(
dec
.
pos
,
"Cdef functions can only take cython.locals() decorator."
))
"Cdef functions can only take cython.locals() decorator."
))
...
@@ -535,15 +535,15 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
...
@@ -535,15 +535,15 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
# Handle with statements
# Handle with statements
def
visit_WithStatNode
(
self
,
node
):
def
visit_WithStatNode
(
self
,
node
):
option
=
self
.
try_to_parse_option
(
node
.
manager
)
directive
=
self
.
try_to_parse_directive
(
node
.
manager
)
if
option
is
not
None
:
if
directive
is
not
None
:
if
node
.
target
is
not
None
:
if
node
.
target
is
not
None
:
self
.
context
.
nonfatal_error
(
self
.
context
.
nonfatal_error
(
PostParseError
(
node
.
pos
,
"Compiler
option
with statements cannot contain 'as'"
))
PostParseError
(
node
.
pos
,
"Compiler
directive
with statements cannot contain 'as'"
))
else
:
else
:
name
,
value
=
option
name
,
value
=
directive
if
self
.
check_directive_scope
(
node
.
pos
,
name
,
'with statement'
):
if
self
.
check_directive_scope
(
node
.
pos
,
name
,
'with statement'
):
return
self
.
visit_with_
option
s
(
node
.
body
,
{
name
:
value
})
return
self
.
visit_with_
directive
s
(
node
.
body
,
{
name
:
value
})
return
self
.
visit_Node
(
node
)
return
self
.
visit_Node
(
node
)
class
WithTransform
(
CythonTransform
,
SkipDeclarations
):
class
WithTransform
(
CythonTransform
,
SkipDeclarations
):
...
...
Cython/Compiler/Parsing.py
View file @
422a77f8
...
@@ -2582,7 +2582,7 @@ def p_compiler_directive_comments(s):
...
@@ -2582,7 +2582,7 @@ def p_compiler_directive_comments(s):
if m:
if m:
name = m.group(1)
name = m.group(1)
try:
try:
value = Options.parse_
option
_value(str(name), str(m.group(2).strip()))
value = Options.parse_
directive
_value(str(name), str(m.group(2).strip()))
if value is not None: # can be False!
if value is not None: # can be False!
result[name] = value
result[name] = value
except ValueError, e:
except ValueError, e:
...
@@ -2593,7 +2593,7 @@ def p_compiler_directive_comments(s):
...
@@ -2593,7 +2593,7 @@ def p_compiler_directive_comments(s):
def p_module(s, pxd, full_module_name):
def p_module(s, pxd, full_module_name):
pos = s.position()
pos = s.position()
option
_comments = p_compiler_directive_comments(s)
directive
_comments = p_compiler_directive_comments(s)
s.parse_comments = False
s.parse_comments = False
doc = p_doc_string(s)
doc = p_doc_string(s)
...
@@ -2608,7 +2608,7 @@ def p_module(s, pxd, full_module_name):
...
@@ -2608,7 +2608,7 @@ def p_module(s, pxd, full_module_name):
repr(s.sy), repr(s.systring)))
repr(s.sy), repr(s.systring)))
return ModuleNode(pos, doc = doc, body = body,
return ModuleNode(pos, doc = doc, body = body,
full_module_name = full_module_name,
full_module_name = full_module_name,
option_comments = option
_comments)
directive_comments = directive
_comments)
#----------------------------------------------
#----------------------------------------------
#
#
...
...
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