Skip to content

Commit 91e2a07

Browse files
FabioLuporinimloubout
authored andcommitted
compiler: Add List.inline for aesthetics
1 parent 4b97ddd commit 91e2a07

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

devito/ir/iet/nodes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class List(Node):
195195

196196
_traversable = ['body']
197197

198-
def __init__(self, header=None, body=None, footer=None):
198+
def __init__(self, header=None, body=None, footer=None, inline=False):
199199
body = as_tuple(body)
200200
if len(body) == 1 and all(type(i) is List for i in [self, body[0]]):
201201
# De-nest Lists
@@ -213,6 +213,8 @@ def __init__(self, header=None, body=None, footer=None):
213213
self.body = as_tuple(body)
214214
self.footer = as_tuple(footer)
215215

216+
self.inline = inline
217+
216218
def __repr__(self):
217219
return "<%s (%d, %d, %d)>" % (self.__class__.__name__, len(self.header),
218220
len(self.body), len(self.footer))

devito/ir/iet/visitors.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,11 @@ def visit_Block(self, o):
538538

539539
def visit_List(self, o):
540540
body = flatten(self._visit(i) for i in self._blankline_logic(o.children))
541-
return c.Module(o.header + (c.Collection(body),) + o.footer)
541+
if o.inline:
542+
body = c.Line(' '.join(str(i) for i in body))
543+
else:
544+
body = c.Collection(body)
545+
return c.Module(o.header + (body,) + o.footer)
542546

543547
def visit_Section(self, o):
544548
body = flatten(self._visit(i) for i in o.children)

tests/test_iet.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,3 +488,11 @@ class MyArray(Array):
488488
a = MyArray(name='a', dimensions=dim, scope='shared', dtype=np.uint8)
489489

490490
assert str(Definition(a)) == "extern unsigned char a[];"
491+
492+
493+
def test_list_inline():
494+
expr0 = DummyExpr(Symbol(name='a'), 1)
495+
expr1 = DummyExpr(Symbol(name='b'), 2)
496+
497+
lst = List(body=[expr0, expr1], inline=True)
498+
assert str(lst) == """a = 1; b = 2;"""

0 commit comments

Comments
 (0)