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
2fa17728
Commit
2fa17728
authored
Mar 21, 2016
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify JoinedStrNode implementation by moving its substring values into a ListNode
parent
d782772e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
24 deletions
+13
-24
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+5
-24
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+8
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
2fa17728
...
...
@@ -2964,7 +2964,7 @@ class RawCNameExprNode(ExprNode):
class
JoinedStrNode
(
ExprNode
):
# F-strings
#
# values
[UnicodeNode|FormattedValueNode]
Substrings of the f-string
# values
ListNode([UnicodeNode|FormattedValueNode])
Substrings of the f-string
#
type
=
py_object_type
is_temp
=
True
...
...
@@ -2972,35 +2972,16 @@ class JoinedStrNode(ExprNode):
subexprs
=
[
'values'
]
def
analyse_types
(
self
,
env
):
values
=
[
v
.
analyse_types
(
env
).
coerce_to_pyobject
(
env
)
for
v
in
self
.
values
]
if
len
(
values
)
==
1
:
# this is not uncommon because f-string format specs are parsed into JoinedStrNodes
return
values
[
0
]
self
.
values
=
values
self
.
values
=
self
.
values
.
analyse_expressions
(
env
)
return
self
def
generate_result_code
(
self
,
code
):
list_var
=
Naming
.
quick_temp_cname
num_items
=
len
(
self
.
values
)
code
.
putln
(
'{'
)
code
.
putln
(
'PyObject *%s = PyList_New(%s); %s'
%
(
list_var
,
num_items
,
code
.
error_goto_if_null
(
list_var
,
self
.
pos
)))
code
.
put_gotref
(
list_var
)
for
i
,
value
in
enumerate
(
self
.
values
):
code
.
put_incref
(
value
.
result
(),
value
.
ctype
())
code
.
put_giveref
(
value
.
py_result
())
code
.
putln
(
'PyList_SET_ITEM(%s, %s, %s);'
%
(
list_var
,
i
,
value
.
py_result
()))
code
.
putln
(
'%s = PyUnicode_Join(%s, %s); __Pyx_DECREF(%s); %s'
%
(
code
.
putln
(
'%s = PyUnicode_Join(%s, %s); %s'
%
(
self
.
result
(),
Naming
.
empty_unicode
,
list_var
,
list_var
,
code
.
error_goto_if_null
(
list_var
,
self
.
pos
)))
self
.
values
.
py_result
(),
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
code
.
put_gotref
(
self
.
py_result
())
code
.
putln
(
'}'
)
class
FormattedValueNode
(
ExprNode
):
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
2fa17728
...
...
@@ -348,6 +348,14 @@ class PostParse(ScopeTrackingTransform):
self
.
visitchildren
(
node
)
return
node
def
visit_JoinedStrNode
(
self
,
node
):
if
len
(
node
.
values
)
==
1
:
# this is not uncommon because f-string format specs are parsed into JoinedStrNodes
return
node
.
values
[
0
]
node
.
values
=
ExprNodes
.
ListNode
(
node
.
pos
,
args
=
node
.
values
)
self
.
visitchildren
(
node
)
return
node
def
eliminate_rhs_duplicates
(
expr_list_list
,
ref_node_sequence
):
"""Replace rhs items by LetRefNodes if they appear more than once.
...
...
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