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
9330e1a0
Commit
9330e1a0
authored
Jan 17, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Plain Diff
...
parents
e10b4dae
db2dd527
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
0 deletions
+46
-0
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+2
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+44
-0
No files found.
Cython/Compiler/Code.py
View file @
9330e1a0
...
@@ -510,6 +510,7 @@ class CCodeWriter(object):
...
@@ -510,6 +510,7 @@ class CCodeWriter(object):
self
.
funcstate
=
None
self
.
funcstate
=
None
self
.
level
=
0
self
.
level
=
0
self
.
call_level
=
0
self
.
bol
=
1
self
.
bol
=
1
if
create_from
is
None
:
if
create_from
is
None
:
# Root CCodeWriter
# Root CCodeWriter
...
@@ -523,6 +524,7 @@ class CCodeWriter(object):
...
@@ -523,6 +524,7 @@ class CCodeWriter(object):
if
copy_formatting
:
if
copy_formatting
:
self
.
level
=
create_from
.
level
self
.
level
=
create_from
.
level
self
.
bol
=
create_from
.
bol
self
.
bol
=
create_from
.
bol
self
.
call_level
=
create_from
.
call_level
if
emit_linenums
is
None
:
if
emit_linenums
is
None
:
self
.
emit_linenums
=
self
.
globalstate
.
emit_linenums
self
.
emit_linenums
=
self
.
globalstate
.
emit_linenums
else
:
else
:
...
...
Cython/Compiler/Nodes.py
View file @
9330e1a0
...
@@ -69,11 +69,55 @@ def embed_position(pos, docstring):
...
@@ -69,11 +69,55 @@ def embed_position(pos, docstring):
doc
.
encoding
=
encoding
doc
.
encoding
=
encoding
return
doc
return
doc
from
Code
import
CCodeWriter
from
types
import
FunctionType
def
write_func_call
(
func
):
def
f
(
*
args
,
**
kwds
):
if
len
(
args
)
>
1
and
isinstance
(
args
[
1
],
CCodeWriter
):
# here we annotate the code with this function call
# but only if new code is generated
node
,
code
=
args
[:
2
]
marker
=
' /* %s -> %s.%s %s */'
%
(
' '
*
code
.
call_level
,
node
.
__class__
.
__name__
,
func
.
__name__
,
node
.
pos
[
1
:])
pristine
=
code
.
buffer
.
stream
.
tell
()
code
.
putln
(
marker
)
start
=
code
.
buffer
.
stream
.
tell
()
code
.
call_level
+=
4
res
=
func
(
*
args
,
**
kwds
)
code
.
call_level
-=
4
if
start
==
code
.
buffer
.
stream
.
tell
():
code
.
buffer
.
stream
.
seek
(
pristine
)
else
:
marker
=
marker
.
replace
(
'->'
,
'<-'
)
code
.
putln
(
marker
)
return
res
else
:
return
func
(
*
args
,
**
kwds
)
return
f
class
VerboseCodeWriter
(
type
):
# Set this as a metaclass to trace function calls in code.
# This slows down code generation and makes much larger files.
def
__new__
(
cls
,
name
,
bases
,
attrs
):
attrs
=
dict
(
attrs
)
for
mname
,
m
in
attrs
.
items
():
if
isinstance
(
m
,
FunctionType
):
attrs
[
mname
]
=
write_func_call
(
m
)
return
super
(
VerboseCodeWriter
,
cls
).
__new__
(
cls
,
name
,
bases
,
attrs
)
class
Node
(
object
):
class
Node
(
object
):
# pos (string, int, int) Source file position
# pos (string, int, int) Source file position
# is_name boolean Is a NameNode
# is_name boolean Is a NameNode
# is_literal boolean Is a ConstNode
# is_literal boolean Is a ConstNode
__metaclass__
=
VerboseCodeWriter
is_name
=
0
is_name
=
0
is_literal
=
0
is_literal
=
0
temps
=
None
temps
=
None
...
...
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