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
1e6628f2
Commit
1e6628f2
authored
Jun 23, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make TreeFragment handle CArgDeclNodes as well
parent
ad8f6640
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
0 deletions
+34
-0
Cython/Compiler/Tests/TestTreeFragment.py
Cython/Compiler/Tests/TestTreeFragment.py
+27
-0
Cython/Compiler/TreeFragment.py
Cython/Compiler/TreeFragment.py
+7
-0
No files found.
Cython/Compiler/Tests/TestTreeFragment.py
View file @
1e6628f2
...
...
@@ -119,6 +119,33 @@ class TestTreeFragments(CythonTest):
self
.
assertTrue
(
isinstance
(
T3
.
stats
[
0
].
rhs
.
operand
,
NameNode
),
T3
)
self
.
assertTrue
(
T3
.
stats
[
0
].
rhs
.
operand
.
name
==
"c"
,
T3
)
def
test_args
(
self
):
F
=
self
.
fragment
(
u"def test(self, ARGS): pass"
)
args
=
[
CArgDeclNode
(
pos
=
None
,
base_type
=
CSimpleBaseTypeNode
(
pos
=
None
,
signed
=
1
),
declarator
=
CNameDeclaratorNode
(
pos
=
None
,
name
=
"a"
)
),
CArgDeclNode
(
pos
=
None
,
base_type
=
CSimpleBaseTypeNode
(
pos
=
None
,
signed
=
1
),
declarator
=
CNameDeclaratorNode
(
pos
=
None
,
name
=
"b"
)
)
]
T
=
F
.
substitute
({
"ARGS"
:
args
})
self
.
assertTrue
(
isinstance
(
T
.
stats
[
0
],
DefNode
),
T
)
self
.
assertTrue
(
isinstance
(
T
.
stats
[
0
].
args
[
0
],
CArgDeclNode
),
T
)
self
.
assertTrue
(
isinstance
(
T
.
stats
[
0
].
args
[
1
],
CArgDeclNode
),
T
)
self
.
assertTrue
(
isinstance
(
T
.
stats
[
0
].
args
[
2
],
CArgDeclNode
),
T
)
self
.
assertTrue
(
isinstance
(
T
.
stats
[
0
].
args
[
0
].
declarator
,
CNameDeclaratorNode
),
T
)
self
.
assertTrue
(
isinstance
(
T
.
stats
[
0
].
args
[
1
].
declarator
,
CNameDeclaratorNode
),
T
)
self
.
assertTrue
(
isinstance
(
T
.
stats
[
0
].
args
[
2
].
declarator
,
CNameDeclaratorNode
),
T
)
self
.
assertTrue
(
T
.
stats
[
0
].
args
[
0
].
declarator
.
name
==
"self"
,
T
)
self
.
assertTrue
(
T
.
stats
[
0
].
args
[
1
].
declarator
.
name
==
"a"
,
T
)
self
.
assertTrue
(
T
.
stats
[
0
].
args
[
2
].
declarator
.
name
==
"b"
,
T
)
self
.
assertTrue
(
len
(
T
.
stats
[
0
].
args
)
==
3
,
T
)
def
test_attribute
(
self
):
F
=
self
.
fragment
(
u"OBJ.ATTR"
)
base_type
=
CSimpleBaseTypeNode
(
pos
=
None
,
name
=
"int"
,
module_path
=
[],
...
...
Cython/Compiler/TreeFragment.py
View file @
1e6628f2
...
...
@@ -215,6 +215,13 @@ class TemplateTransform(VisitorTransform):
ret
.
attribute
=
EncodedString
(
sub
)
return
ret
def
visit_CArgDeclNode
(
self
,
node
):
if
isinstance
(
node
.
declarator
,
CNameDeclaratorNode
):
sub
=
self
.
substitutions
.
get
(
node
.
declarator
.
name
)
if
sub
is
not
None
:
return
sub
return
self
.
visit_Node
(
node
)
def
visit_ExprStatNode
(
self
,
node
):
# If an expression-as-statement consists of only a replaceable
# NameNode, we replace the entire statement, not only the NameNode
...
...
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