mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-20 01:48:31 +00:00
removed hack for return statement
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user