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
747a0110
Commit
747a0110
authored
Jun 19, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Generates closure classes for all functions
parent
7308254f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
10 deletions
+46
-10
Cython/Compiler/Main.py
Cython/Compiler/Main.py
+2
-0
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+33
-2
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+1
-1
Cython/TestUtils.py
Cython/TestUtils.py
+10
-7
No files found.
Cython/Compiler/Main.py
View file @
747a0110
...
...
@@ -336,6 +336,7 @@ def create_generate_code(context, options, result):
def
create_default_pipeline
(
context
,
options
,
result
):
from
ParseTreeTransforms
import
WithTransform
,
PostParse
from
ParseTreeTransforms
import
AnalyseDeclarationsTransform
,
AnalyseExpressionsTransform
from
ParseTreeTransforms
import
CreateClosureClasses
from
ModuleNode
import
check_c_classes
return
[
...
...
@@ -345,6 +346,7 @@ def create_default_pipeline(context, options, result):
AnalyseDeclarationsTransform
(),
check_c_classes
,
AnalyseExpressionsTransform
(),
CreateClosureClasses
(),
create_generate_code
(
context
,
options
,
result
)
]
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
747a0110
from
Cython.Compiler.Visitor
import
VisitorTransform
,
temp_name_handle
from
Cython.Compiler.ModuleNode
import
ModuleNode
from
Cython.Compiler.Nodes
import
*
from
Cython.Compiler.ExprNodes
import
*
from
Cython.Compiler.TreeFragment
import
TreeFragment
class
PostParse
(
VisitorTransform
):
"""
This transform fixes up a few things after parsing
...
...
@@ -170,7 +170,6 @@ class AnalyseDeclarationsTransform(VisitorTransform):
class
AnalyseExpressionsTransform
(
VisitorTransform
):
def
visit_ModuleNode
(
self
,
node
):
node
.
body
.
analyse_expressions
(
node
.
scope
)
self
.
visitchildren
(
node
)
...
...
@@ -185,3 +184,35 @@ class AnalyseExpressionsTransform(VisitorTransform):
self
.
visitchildren
(
node
)
return
node
class
CreateClosureClasses
(
VisitorTransform
):
# Output closure classes in module scope for all functions
# that need it.
def
visit_ModuleNode
(
self
,
node
):
self
.
module_scope
=
node
.
scope
self
.
visitchildren
(
node
)
return
node
def
create_class_from_scope
(
self
,
node
,
target_module_scope
):
as_name
=
temp_name_handle
(
"closure"
)
func_scope
=
node
.
local_scope
entry
=
target_module_scope
.
declare_c_class
(
name
=
as_name
,
pos
=
node
.
pos
,
defining
=
True
,
implementing
=
True
)
class_scope
=
entry
.
type
.
scope
for
entry
in
func_scope
.
entries
.
values
():
class_scope
.
declare_var
(
pos
=
node
.
pos
,
name
=
entry
.
name
,
cname
=
entry
.
cname
,
type
=
entry
.
type
,
is_cdef
=
True
)
def
visit_FuncDefNode
(
self
,
node
):
self
.
create_class_from_scope
(
node
,
self
.
module_scope
)
return
node
def
visit_Node
(
self
,
node
):
self
.
visitchildren
(
node
)
return
node
Cython/Compiler/Parsing.py
View file @
747a0110
...
...
@@ -1386,7 +1386,7 @@ def p_statement(s, ctx, first_statement = 0):
if
ctx
.
api
:
error
(
s
.
pos
,
"'api' not allowed with this statement"
)
elif
s
.
sy
==
'def'
:
if
ctx
.
level
not
in
(
'module'
,
'class'
,
'c_class'
,
'property'
):
if
ctx
.
level
not
in
(
'module'
,
'class'
,
'c_class'
,
'
function'
,
'
property'
):
s
.
error
(
'def statement not allowed here'
)
s
.
level
=
ctx
.
level
return
p_def_statement
(
s
)
...
...
Cython/TestUtils.py
View file @
747a0110
...
...
@@ -27,6 +27,15 @@ class NodeTypeWriter(TreeVisitor):
self
.
visitchildren
(
node
)
self
.
_indents
-=
1
def
treetypes
(
root
):
"""Returns a string representing the tree by class names.
There's a leading and trailing whitespace so that it can be
compared by simple string comparison while still making test
cases look ok."""
w
=
NodeTypeWriter
()
w
.
visit
(
root
)
return
u"
\
n
"
.
join
([
u""
]
+
w
.
result
+
[
u""
])
class
CythonTest
(
unittest
.
TestCase
):
def
assertLines
(
self
,
expected
,
result
):
...
...
@@ -58,13 +67,7 @@ class CythonTest(unittest.TestCase):
return
TreeFragment
(
code
,
name
,
pxds
)
def
treetypes
(
self
,
root
):
"""Returns a string representing the tree by class names.
There's a leading and trailing whitespace so that it can be
compared by simple string comparison while still making test
cases look ok."""
w
=
NodeTypeWriter
()
w
.
visit
(
root
)
return
u"
\
n
"
.
join
([
u""
]
+
w
.
result
+
[
u""
])
return
treetypes
(
root
)
class
TransformTest
(
CythonTest
):
"""
...
...
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