Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jonas Plewinski
pystencils
Commits
0f33273b
Commit
0f33273b
authored
Sep 24, 2019
by
Stephan Seitz
Browse files
Add SourceCodeComment/EmptyLine as AST nodes
parent
48646a0b
Changes
3
Hide whitespace changes
Inline
Side-by-side
pystencils/astnodes.py
View file @
0f33273b
...
...
@@ -730,3 +730,49 @@ class DestructuringBindingsForFieldClass(Node):
def
get_dummy_symbol
(
dtype
=
'bool'
):
return
TypedSymbol
(
'dummy%s'
%
uuid
.
uuid4
().
hex
,
create_type
(
dtype
))
class
SourceCodeComment
(
Node
):
def
__init__
(
self
,
text
):
self
.
text
=
text
@
property
def
args
(
self
):
return
[]
@
property
def
symbols_defined
(
self
):
return
set
()
@
property
def
undefined_symbols
(
self
):
return
set
()
def
__str__
(
self
):
return
"/* "
+
self
.
text
+
" */"
def
__repr__
(
self
):
return
self
.
__str__
()
class
EmptyLine
(
Node
):
def
__init__
(
self
):
pass
@
property
def
args
(
self
):
return
[]
@
property
def
symbols_defined
(
self
):
return
set
()
@
property
def
undefined_symbols
(
self
):
return
set
()
def
__str__
(
self
):
return
""
def
__repr__
(
self
):
return
self
.
__str__
()
pystencils/backends/cbackend.py
View file @
0f33273b
...
...
@@ -264,6 +264,12 @@ class CBackend:
def
_print_CustomCodeNode
(
self
,
node
):
return
node
.
get_code
(
self
.
_dialect
,
self
.
_vector_instruction_set
)
def
_print_SourceCodeComment
(
self
,
node
):
return
"/* "
+
node
.
text
+
" */"
def
_print_EmptyLine
(
self
,
node
):
return
""
def
_print_Conditional
(
self
,
node
):
cond_type
=
get_type_of_expression
(
node
.
condition_expr
)
if
isinstance
(
cond_type
,
VectorType
):
...
...
pystencils_tests/test_source_code_comment.py
0 → 100644
View file @
0f33273b
# -*- coding: utf-8 -*-
#
# Copyright © 2019 Stephan Seitz <stephan.seitz@fau.de>
#
# Distributed under terms of the GPLv3 license.
"""
"""
import
pystencils
import
pystencils.astnodes
def
test_source_code_comment
():
a
,
b
=
pystencils
.
fields
(
'a,b: float[2D]'
)
assignments
=
pystencils
.
AssignmentCollection
(
{
a
.
center
():
b
[
0
,
2
]
+
b
[
0
,
0
]},
{}
)
ast
=
pystencils
.
create_kernel
(
assignments
,
target
=
'cpu'
)
ast
.
body
.
append
(
pystencils
.
astnodes
.
SourceCodeComment
(
"Hallo"
))
ast
.
body
.
append
(
pystencils
.
astnodes
.
EmptyLine
())
ast
.
body
.
append
(
pystencils
.
astnodes
.
SourceCodeComment
(
"World!"
))
print
(
ast
)
compiled
=
ast
.
compile
()
assert
compiled
is
not
None
print
(
pystencils
.
show_code
(
ast
))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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