Issue 38: c-to-c: postfix -- behavior
diff --git a/examples/c-to-c.py b/examples/c-to-c.py
index 713cdd3..5b22ddf 100644
--- a/examples/c-to-c.py
+++ b/examples/c-to-c.py
@@ -70,6 +70,8 @@
operand = self._parenthesize_unless_simple(n.expr)
if n.op == 'p++':
return '%s++' % operand
+ elif n.op == 'p--':
+ return '%s--' % operand
elif n.op == 'sizeof':
# Always parenthesize the argument of sizeof since it can be
# a name.
@@ -407,9 +409,11 @@
src = r'''
int main(void)
{
- unsigned size;
- size = sizeof(size);
- return 0;
+ int a;
+ int b = a++;
+ int c = ++a;
+ int d = a--;
+ int e = --a;
}
'''
parser = c_parser.CParser()
diff --git a/examples/tests/test_c-to-c.py b/examples/tests/test_c-to-c.py
index 83cc099..f9f9aa3 100644
--- a/examples/tests/test_c-to-c.py
+++ b/examples/tests/test_c-to-c.py
@@ -65,6 +65,17 @@
def test_initlist(self):
self._assert_ctoc_correct('int arr[] = {1, 2, 3};')
+ def test_exprs(self):
+ self._assert_ctoc_correct('''
+ int main(void)
+ {
+ int a;
+ int b = a++;
+ int c = ++a;
+ int d = a--;
+ int e = --a;
+ }''')
+
def test_statements(self):
self._assert_ctoc_correct(r'''
int main() {