diff options
author | eli.bendersky <devnull@localhost> | 2011-05-26 07:01:43 +0300 |
---|---|---|
committer | eli.bendersky <devnull@localhost> | 2011-05-26 07:01:43 +0300 |
commit | 8348a9d2df7cd91f157578f9d503fd3c45977aa4 (patch) | |
tree | 90ada357d29aac25e85b2c6606792c1d88fd3b60 /examples | |
parent | cad1cfde6f60288f427114be2800a5afa3ec2a62 (diff) | |
download | pycparser-8348a9d2df7cd91f157578f9d503fd3c45977aa4.tar.gz |
Issue 37: c-to-c: sizeof arg parenthesizing
Diffstat (limited to 'examples')
-rw-r--r-- | examples/c-to-c.py | 12 | ||||
-rw-r--r-- | examples/tests/test_c-to-c.py | 9 |
2 files changed, 20 insertions, 1 deletions
diff --git a/examples/c-to-c.py b/examples/c-to-c.py index ec2f04b..713cdd3 100644 --- a/examples/c-to-c.py +++ b/examples/c-to-c.py @@ -70,6 +70,10 @@ class CGenerator(object): operand = self._parenthesize_unless_simple(n.expr) if n.op == 'p++': return '%s++' % operand + elif n.op == 'sizeof': + # Always parenthesize the argument of sizeof since it can be + # a name. + return 'sizeof(%s)' % self.visit(n.expr) else: return '%s%s' % (n.op, operand) @@ -401,7 +405,13 @@ def translate_to_c(filename): def zz_test_translate(): # internal use src = r''' -int main(){} ''' +int main(void) +{ + unsigned size; + size = sizeof(size); + return 0; +} +''' parser = c_parser.CParser() ast = parser.parse(src) ast.show() diff --git a/examples/tests/test_c-to-c.py b/examples/tests/test_c-to-c.py index eae0cce..83cc099 100644 --- a/examples/tests/test_c-to-c.py +++ b/examples/tests/test_c-to-c.py @@ -78,6 +78,15 @@ class TestCtoC(unittest.TestCase): int main() {
}''')
+ def test_issue37(self):
+ self._assert_ctoc_correct(r'''
+ int main(void)
+ {
+ unsigned size;
+ size = sizeof(size);
+ return 0;
+ }''')
+
if __name__ == "__main__":
|