mirror of
https://github.com/pragma-/pbot.git
synced 2024-10-03 01:48:38 +02:00
Improve verbosity of parenthesized precedence in parens module
This commit is contained in:
parent
f618b29282
commit
936d45e04e
@ -13,8 +13,8 @@ use warnings;
|
|||||||
# These are set automatically by the build/commit script
|
# These are set automatically by the build/commit script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 466,
|
BUILD_REVISION => 467,
|
||||||
BUILD_DATE => "2013-11-13",
|
BUILD_DATE => "2013-11-14",
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -42,6 +42,13 @@ class CParser(c_parser.CParser):
|
|||||||
|
|
||||||
|
|
||||||
class CGenerator(c_generator.CGenerator):
|
class CGenerator(c_generator.CGenerator):
|
||||||
|
def visit_BinaryOp(self, n):
|
||||||
|
lval_str = self._parenthesize_if(n.left,
|
||||||
|
lambda d: not self._is_simple_node(d))
|
||||||
|
rval_str = self._parenthesize_if(n.right,
|
||||||
|
lambda d: not self._is_simple_node(d))
|
||||||
|
return '(%s %s %s)' % (lval_str, n.op, rval_str)
|
||||||
|
|
||||||
def visit_UnaryOp(self, n):
|
def visit_UnaryOp(self, n):
|
||||||
# don't parenthesize an operand to sizeof if it's not a type
|
# don't parenthesize an operand to sizeof if it's not a type
|
||||||
if n.op == 'sizeof':
|
if n.op == 'sizeof':
|
||||||
@ -51,6 +58,12 @@ class CGenerator(c_generator.CGenerator):
|
|||||||
return 'sizeof %s' % self._parenthesize_unless_simple(n.expr)
|
return 'sizeof %s' % self._parenthesize_unless_simple(n.expr)
|
||||||
return super(CGenerator, self).visit_UnaryOp(n)
|
return super(CGenerator, self).visit_UnaryOp(n)
|
||||||
|
|
||||||
|
def _is_simple_node(self, n):
|
||||||
|
""" Returns True for nodes that are "simple" - i.e. nodes that always
|
||||||
|
have higher precedence than operators.
|
||||||
|
"""
|
||||||
|
return isinstance(n,( c_ast.Constant, c_ast.ID, c_ast.ArrayRef,
|
||||||
|
c_ast.StructRef, c_ast.FuncCall, c_ast.BinaryOp))
|
||||||
|
|
||||||
def translate_to_c(input):
|
def translate_to_c(input):
|
||||||
parser = CParser(yacc_optimize=False)
|
parser = CParser(yacc_optimize=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user