diff options
author | Vincent Burns <discoloda@gmail.com> | 2014-01-14 12:05:14 -0500 |
---|---|---|
committer | Vincent Burns <discoloda@gmail.com> | 2014-01-14 12:05:14 -0500 |
commit | 53953475825e1ab743a8d02ca0fca6b4eeee3ff4 (patch) | |
tree | 7f43f548a175fb07a829554284a389fc9ef3236c /compiler/c2nim | |
parent | d35dedf041d1ded5843a064c855e8e36dc194221 (diff) | |
download | Nim-53953475825e1ab743a8d02ca0fca6b4eeee3ff4.tar.gz |
removed hack for return statement
Diffstat (limited to 'compiler/c2nim')
-rw-r--r-- | compiler/c2nim/cparse.nim | 16 | ||||
-rw-r--r-- | compiler/c2nim/tests/vincent.c | 7 |
2 files changed, 14 insertions, 9 deletions
diff --git a/compiler/c2nim/cparse.nim b/compiler/c2nim/cparse.nim index aa9929139..8a8eeeb05 100644 --- a/compiler/c2nim/cparse.nim +++ b/compiler/c2nim/cparse.nim @@ -2038,6 +2038,10 @@ proc parseStandaloneClass(p: var TParser, isStruct: bool): PNode = result = declaration(p) p.currentClass = oldClass +proc unwrap(a: PNode): PNode = + if a.kind == nkPar: + return a.sons[0] + return a include cpp @@ -2072,16 +2076,10 @@ proc statement(p: var TParser): PNode = of "return": result = newNodeP(nkReturnStmt, p) getTok(p) - # special case for ``return (expr)`` because I hate the redundant - # parenthesis ;-) - if p.tok.xkind == pxParLe: - getTok(p, result) - addSon(result, expression(p)) - eat(p, pxParRi, result) - elif p.tok.xkind != pxSemicolon: - addSon(result, expression(p)) - else: + if p.tok.xkind == pxSemicolon: addSon(result, ast.emptyNode) + else: + addSon(result, unwrap(expression(p))) eat(p, pxSemicolon) of "enum": result = enumSpecifier(p) of "typedef": result = parseTypeDef(p) diff --git a/compiler/c2nim/tests/vincent.c b/compiler/c2nim/tests/vincent.c index a30077f77..24c6d6425 100644 --- a/compiler/c2nim/tests/vincent.c +++ b/compiler/c2nim/tests/vincent.c @@ -3,9 +3,16 @@ int rand(void); +int id2(void) { + return (int *)1; +} + int id(void (*f)(void)) { f(); ((void (*)(int))f)(10); + return 10; + return (20+1); + return (int *)id; } int main() { |