Skip to content
Snippets Groups Projects
Commit 37f317c5 authored by Matt Wala's avatar Matt Wala
Browse files

C expression to code mapper: Parenthesize '&&' within '||' to avoid

warnings from clang-based compilers.
parent 61adce98
No related branches found
No related tags found
No related merge requests found
...@@ -685,6 +685,10 @@ class CExpressionToCodeMapper(RecursiveMapper): ...@@ -685,6 +685,10 @@ class CExpressionToCodeMapper(RecursiveMapper):
return f % tuple( return f % tuple(
self.rec(i, prec) for i in iterable) self.rec(i, prec) for i in iterable)
def join(self, joiner, iterable):
f = joiner.join("%s" for i in iterable)
return f % tuple(iterable)
# }}} # }}}
def map_constant(self, expr, prec): def map_constant(self, expr, prec):
...@@ -779,9 +783,16 @@ class CExpressionToCodeMapper(RecursiveMapper): ...@@ -779,9 +783,16 @@ class CExpressionToCodeMapper(RecursiveMapper):
enclosing_prec, PREC_LOGICAL_AND) enclosing_prec, PREC_LOGICAL_AND)
def map_logical_or(self, expr, enclosing_prec): def map_logical_or(self, expr, enclosing_prec):
return self.parenthesize_if_needed( mapped_children = []
self.join_rec(" || ", expr.children, PREC_LOGICAL_OR), from pymbolic.primitives import LogicalAnd
enclosing_prec, PREC_LOGICAL_OR) for child in expr.children:
mapped_child = self.rec(child, PREC_LOGICAL_OR)
# clang warns on unparenthesized && within ||
if isinstance(child, LogicalAnd):
mapped_child = "(%s)" % mapped_child
mapped_children.append(mapped_child)
return self.join(" || ", mapped_children)
def map_sum(self, expr, enclosing_prec): def map_sum(self, expr, enclosing_prec):
from pymbolic.mapper.stringifier import PREC_SUM from pymbolic.mapper.stringifier import PREC_SUM
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment