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
8f8ef4e9
Commit
8f8ef4e9
authored
Nov 11, 2008
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compile Cython.Compiler.Parsing.py, auto_cpdef, fix bugs in AlignFunctionDefinitions
parent
ecd248ed
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
32 deletions
+63
-32
Cython/Compiler/Main.py
Cython/Compiler/Main.py
+1
-1
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+48
-24
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+3
-1
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+5
-2
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+4
-3
Cython/Plex/Scanners.pxd
Cython/Plex/Scanners.pxd
+1
-0
setup.py
setup.py
+1
-1
No files found.
Cython/Compiler/Main.py
View file @
8f8ef4e9
...
@@ -102,8 +102,8 @@ class Context:
...
@@ -102,8 +102,8 @@ class Context:
NormalizeTree
(
self
),
NormalizeTree
(
self
),
PostParse
(
self
),
PostParse
(
self
),
_specific_post_parse
,
_specific_post_parse
,
_align_function_definitions
,
InterpretCompilerDirectives
(
self
,
self
.
pragma_overrides
),
InterpretCompilerDirectives
(
self
,
self
.
pragma_overrides
),
_align_function_definitions
,
FlattenInListTransform
(),
FlattenInListTransform
(),
WithTransform
(
self
),
WithTransform
(
self
),
DecoratorTransform
(
self
),
DecoratorTransform
(
self
),
...
...
Cython/Compiler/Nodes.py
View file @
8f8ef4e9
...
@@ -1212,6 +1212,7 @@ class CFuncDefNode(FuncDefNode):
...
@@ -1212,6 +1212,7 @@ class CFuncDefNode(FuncDefNode):
self
.
args
=
declarator
.
args
self
.
args
=
declarator
.
args
for
formal_arg
,
type_arg
in
zip
(
self
.
args
,
type
.
args
):
for
formal_arg
,
type_arg
in
zip
(
self
.
args
,
type
.
args
):
formal_arg
.
type
=
type_arg
.
type
formal_arg
.
type
=
type_arg
.
type
formal_arg
.
name
=
type_arg
.
name
formal_arg
.
cname
=
type_arg
.
cname
formal_arg
.
cname
=
type_arg
.
cname
name
=
name_declarator
.
name
name
=
name_declarator
.
name
cname
=
name_declarator
.
cname
cname
=
name_declarator
.
cname
...
@@ -1466,42 +1467,61 @@ class DefNode(FuncDefNode):
...
@@ -1466,42 +1467,61 @@ class DefNode(FuncDefNode):
self
.
num_required_kw_args
=
rk
self
.
num_required_kw_args
=
rk
self
.
num_required_args
=
r
self
.
num_required_args
=
r
def
as_cfunction
(
self
,
cfunc
):
def
as_cfunction
(
self
,
cfunc
=
None
,
scope
=
None
):
if
self
.
star_arg
:
if
self
.
star_arg
:
error
(
self
.
star_arg
.
pos
,
"cdef function cannot have star argument"
)
error
(
self
.
star_arg
.
pos
,
"cdef function cannot have star argument"
)
if
self
.
starstar_arg
:
if
self
.
starstar_arg
:
error
(
self
.
starstar_arg
.
pos
,
"cdef function cannot have starstar argument"
)
error
(
self
.
starstar_arg
.
pos
,
"cdef function cannot have starstar argument"
)
if
len
(
self
.
args
)
!=
len
(
cfunc
.
type
.
args
)
or
cfunc
.
type
.
has_varargs
:
if
cfunc
is
None
:
error
(
self
.
pos
,
"wrong number of arguments"
)
cfunc_args
=
[]
error
(
declarator
.
pos
,
"previous declaration here"
)
for
formal_arg
in
self
.
args
:
for
formal_arg
,
type_arg
in
zip
(
self
.
args
,
cfunc
.
type
.
args
):
name_declarator
,
type
=
formal_arg
.
analyse
(
scope
,
nonempty
=
1
)
name_declarator
,
type
=
formal_arg
.
analyse
(
cfunc
.
scope
,
nonempty
=
1
)
cfunc_args
.
append
(
PyrexTypes
.
CFuncTypeArg
(
name
=
name_declarator
.
name
,
if
type
is
PyrexTypes
.
py_object_type
or
formal_arg
.
is_self
:
cname
=
None
,
formal_arg
.
type
=
type_arg
.
type
type
=
py_object_type
,
formal_arg
.
name_declarator
=
name_declarator
pos
=
formal_arg
.
pos
))
cfunc_type
=
PyrexTypes
.
CFuncType
(
return_type
=
py_object_type
,
args
=
cfunc_args
,
has_varargs
=
False
,
exception_value
=
None
,
exception_check
=
False
,
nogil
=
False
,
with_gil
=
False
,
is_overridable
=
True
)
cfunc
=
CVarDefNode
(
self
.
pos
,
type
=
cfunc_type
,
pxd_locals
=
[])
else
:
cfunc_type
=
cfunc
.
type
if
len
(
self
.
args
)
!=
len
(
cfunc_type
.
args
)
or
cfunc_type
.
has_varargs
:
error
(
self
.
pos
,
"wrong number of arguments"
)
error
(
declarator
.
pos
,
"previous declaration here"
)
for
formal_arg
,
type_arg
in
zip
(
self
.
args
,
cfunc_type
.
args
):
name_declarator
,
type
=
formal_arg
.
analyse
(
cfunc
.
scope
,
nonempty
=
1
)
if
type
is
None
or
type
is
PyrexTypes
.
py_object_type
or
formal_arg
.
is_self
:
formal_arg
.
type
=
type_arg
.
type
formal_arg
.
name_declarator
=
name_declarator
import
ExprNodes
import
ExprNodes
if
cfunc
.
type
.
exception_value
is
None
:
if
cfunc
_
type
.
exception_value
is
None
:
exception_value
=
None
exception_value
=
None
else
:
else
:
exception_value
=
ExprNodes
.
ConstNode
(
self
.
pos
,
value
=
cfunc
.
type
.
exception_value
,
type
=
cfunc
.
type
.
return_type
)
exception_value
=
ExprNodes
.
ConstNode
(
self
.
pos
,
value
=
cfunc
_type
.
exception_value
,
type
=
cfunc_
type
.
return_type
)
declarator
=
CFuncDeclaratorNode
(
self
.
pos
,
declarator
=
CFuncDeclaratorNode
(
self
.
pos
,
base
=
CNameDeclaratorNode
(
self
.
pos
,
name
=
self
.
name
,
cname
=
None
),
base
=
CNameDeclaratorNode
(
self
.
pos
,
name
=
self
.
name
,
cname
=
None
),
args
=
self
.
args
,
args
=
self
.
args
,
has_varargs
=
False
,
has_varargs
=
False
,
exception_check
=
cfunc
.
type
.
exception_check
,
exception_check
=
cfunc
_
type
.
exception_check
,
exception_value
=
exception_value
,
exception_value
=
exception_value
,
with_gil
=
cfunc
.
type
.
with_gil
,
with_gil
=
cfunc
_
type
.
with_gil
,
nogil
=
cfunc
.
type
.
nogil
)
nogil
=
cfunc
_
type
.
nogil
)
return
CFuncDefNode
(
self
.
pos
,
return
CFuncDefNode
(
self
.
pos
,
modifiers
=
[],
modifiers
=
[],
base_type
=
CAnalysedBaseTypeNode
(
self
.
pos
,
type
=
cfunc
.
type
.
return_type
),
base_type
=
CAnalysedBaseTypeNode
(
self
.
pos
,
type
=
cfunc
_
type
.
return_type
),
declarator
=
declarator
,
declarator
=
declarator
,
body
=
self
.
body
,
body
=
self
.
body
,
doc
=
self
.
doc
,
doc
=
self
.
doc
,
overridable
=
cfunc
.
type
.
is_overridable
,
overridable
=
cfunc
_
type
.
is_overridable
,
type
=
cfunc
.
type
,
type
=
cfunc
_
type
,
with_gil
=
cfunc
.
type
.
with_gil
,
with_gil
=
cfunc
_
type
.
with_gil
,
nogil
=
cfunc
.
type
.
nogil
,
nogil
=
cfunc
_
type
.
nogil
,
visibility
=
'private'
,
visibility
=
'private'
,
api
=
False
,
api
=
False
,
pxd_locals
=
cfunc
.
pxd_locals
)
pxd_locals
=
cfunc
.
pxd_locals
)
...
@@ -1513,10 +1533,14 @@ class DefNode(FuncDefNode):
...
@@ -1513,10 +1533,14 @@ class DefNode(FuncDefNode):
directive_locals
=
{}
directive_locals
=
{}
self
.
directive_locals
=
directive_locals
self
.
directive_locals
=
directive_locals
for
arg
in
self
.
args
:
for
arg
in
self
.
args
:
base_type
=
arg
.
base_type
.
analyse
(
env
)
if
hasattr
(
arg
,
'name'
):
name_declarator
,
type
=
\
type
=
arg
.
type
arg
.
declarator
.
analyse
(
base_type
,
env
)
name_declarator
=
None
arg
.
name
=
name_declarator
.
name
else
:
base_type
=
arg
.
base_type
.
analyse
(
env
)
name_declarator
,
type
=
\
arg
.
declarator
.
analyse
(
base_type
,
env
)
arg
.
name
=
name_declarator
.
name
if
arg
.
name
in
directive_locals
:
if
arg
.
name
in
directive_locals
:
type_node
=
directive_locals
[
arg
.
name
]
type_node
=
directive_locals
[
arg
.
name
]
other_type
=
type_node
.
analyse_as_type
(
env
)
other_type
=
type_node
.
analyse_as_type
(
env
)
...
@@ -1528,7 +1552,7 @@ class DefNode(FuncDefNode):
...
@@ -1528,7 +1552,7 @@ class DefNode(FuncDefNode):
error
(
type_node
.
pos
,
"Previous declaration here"
)
error
(
type_node
.
pos
,
"Previous declaration here"
)
else
:
else
:
type
=
other_type
type
=
other_type
if
name_declarator
.
cname
:
if
name_declarator
and
name_declarator
.
cname
:
error
(
self
.
pos
,
error
(
self
.
pos
,
"Python function argument cannot have C name specification"
)
"Python function argument cannot have C name specification"
)
arg
.
type
=
type
.
as_argument_type
()
arg
.
type
=
type
.
as_argument_type
()
...
...
Cython/Compiler/Options.py
View file @
8f8ef4e9
...
@@ -60,13 +60,15 @@ option_types = {
...
@@ -60,13 +60,15 @@ option_types = {
'nonecheck'
:
bool
,
'nonecheck'
:
bool
,
'embedsignature'
:
bool
,
'embedsignature'
:
bool
,
'locals'
:
dict
,
'locals'
:
dict
,
'auto_cpdef'
:
bool
,
}
}
option_defaults
=
{
option_defaults
=
{
'boundscheck'
:
True
,
'boundscheck'
:
True
,
'nonecheck'
:
False
,
'nonecheck'
:
False
,
'embedsignature'
:
False
,
'embedsignature'
:
False
,
'locals'
:
{}
'locals'
:
{},
'auto_cpdef'
:
False
,
}
}
def
parse_option_value
(
name
,
value
):
def
parse_option_value
(
name
,
value
):
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
8f8ef4e9
...
@@ -619,6 +619,7 @@ class AlignFunctionDefinitions(CythonTransform):
...
@@ -619,6 +619,7 @@ class AlignFunctionDefinitions(CythonTransform):
def
visit_ModuleNode
(
self
,
node
):
def
visit_ModuleNode
(
self
,
node
):
self
.
scope
=
node
.
scope
self
.
scope
=
node
.
scope
self
.
directives
=
node
.
directives
self
.
visitchildren
(
node
)
self
.
visitchildren
(
node
)
return
node
return
node
...
@@ -631,8 +632,8 @@ class AlignFunctionDefinitions(CythonTransform):
...
@@ -631,8 +632,8 @@ class AlignFunctionDefinitions(CythonTransform):
error
(
node
.
pos
,
"'%s' redeclared"
%
node
.
name
)
error
(
node
.
pos
,
"'%s' redeclared"
%
node
.
name
)
error
(
pxd_def
.
pos
,
"previous declaration here"
)
error
(
pxd_def
.
pos
,
"previous declaration here"
)
return
None
return
None
self
.
visitchildren
(
node
)
else
:
return
node
return
node
def
visit_CClassDefNode
(
self
,
node
,
pxd_def
=
None
):
def
visit_CClassDefNode
(
self
,
node
,
pxd_def
=
None
):
if
pxd_def
is
None
:
if
pxd_def
is
None
:
...
@@ -654,6 +655,8 @@ class AlignFunctionDefinitions(CythonTransform):
...
@@ -654,6 +655,8 @@ class AlignFunctionDefinitions(CythonTransform):
error
(
node
.
pos
,
"'%s' redeclared"
%
node
.
name
)
error
(
node
.
pos
,
"'%s' redeclared"
%
node
.
name
)
error
(
pxd_def
.
pos
,
"previous declaration here"
)
error
(
pxd_def
.
pos
,
"previous declaration here"
)
return
None
return
None
elif
self
.
scope
.
is_module_scope
and
self
.
directives
[
'auto_cpdef'
]:
node
=
node
.
as_cfunction
(
scope
=
self
.
scope
)
# Enable this when internal def functions are allowed.
# Enable this when internal def functions are allowed.
# self.visitchildren(node)
# self.visitchildren(node)
return
node
return
node
...
...
Cython/Compiler/Parsing.py
View file @
8f8ef4e9
# cython: auto_cpdef=True
#
#
# Pyrex Parser
# Pyrex Parser
#
#
...
@@ -6,7 +7,7 @@ import os
...
@@ -6,7 +7,7 @@ import os
import
re
import
re
import
sys
import
sys
from
types
import
ListType
,
TupleType
from
types
import
ListType
,
TupleType
from
Scanning
import
PyrexScanner
,
FileSourceDescriptor
from
Cython.Compiler.
Scanning
import
PyrexScanner
,
FileSourceDescriptor
import
Nodes
import
Nodes
import
ExprNodes
import
ExprNodes
import
StringEncoding
import
StringEncoding
...
@@ -1307,7 +1308,7 @@ def p_with_statement(s):
...
@@ -1307,7 +1308,7 @@ def p_with_statement(s):
if
not
allow_multi
and
isinstance
(
target
,
ExprNodes
.
TupleNode
):
if
not
allow_multi
and
isinstance
(
target
,
ExprNodes
.
TupleNode
):
s
.
error
(
"Multiple with statement target values not allowed without paranthesis"
)
s
.
error
(
"Multiple with statement target values not allowed without paranthesis"
)
body
=
p_suite
(
s
)
body
=
p_suite
(
s
)
return
Nodes
.
WithStatNode
(
pos
,
manager
=
manager
,
return
Nodes
.
WithStatNode
(
pos
,
manager
=
manager
,
target
=
target
,
body
=
body
)
target
=
target
,
body
=
body
)
def
p_simple_statement
(
s
,
first_statement
=
0
):
def
p_simple_statement
(
s
,
first_statement
=
0
):
...
@@ -2382,7 +2383,7 @@ def p_code(s, level=None):
...
@@ -2382,7 +2383,7 @@ def p_code(s, level=None):
repr
(
s
.
sy
),
repr
(
s
.
systring
)))
repr
(
s
.
sy
),
repr
(
s
.
systring
)))
return
body
return
body
COMPILER_DIRECTIVE_COMMENT_RE
=
re
.
compile
(
r"^#\
s*cy
thon:\
s*([
a-z]+)\
s*=(.*)$
")
COMPILER_DIRECTIVE_COMMENT_RE
=
re
.
compile
(
r"^#\
s*cy
thon:\
s*([
a-z
_
]+)\
s*=(.*)$
")
def p_compiler_directive_comments(s):
def p_compiler_directive_comments(s):
result = {}
result = {}
...
...
Cython/Plex/Scanners.pxd
View file @
8f8ef4e9
...
@@ -28,6 +28,7 @@ cdef class Scanner:
...
@@ -28,6 +28,7 @@ cdef class Scanner:
cdef
:
cdef
:
long
input_state
long
input_state
cpdef
read
(
self
)
cpdef
read
(
self
)
cpdef
position
(
self
)
cpdef
run_machine_inlined
(
self
):
cpdef
run_machine_inlined
(
self
):
cdef
:
cdef
:
...
...
setup.py
View file @
8f8ef4e9
...
@@ -31,7 +31,7 @@ except ValueError:
...
@@ -31,7 +31,7 @@ except ValueError:
try
:
try
:
from
Cython.Compiler.Main
import
compile
from
Cython.Compiler.Main
import
compile
source_root
=
os
.
path
.
dirname
(
__file__
)
source_root
=
os
.
path
.
dirname
(
__file__
)
compiled_modules
=
[
"Cython.Plex.Scanners"
,
"Cython.Compiler.Scanning"
]
compiled_modules
=
[
"Cython.Plex.Scanners"
,
"Cython.Compiler.Scanning"
,
"Cython.Compiler.Parsing"
]
extensions
=
[]
extensions
=
[]
for
module
in
compiled_modules
:
for
module
in
compiled_modules
:
source_file
=
os
.
path
.
join
(
source_root
,
*
module
.
split
(
'.'
))
source_file
=
os
.
path
.
join
(
source_root
,
*
module
.
split
(
'.'
))
...
...
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