Fixed a problem with nested while() loops not handling break and continue correctly.
Fixes issue #96. git-svn-id: http://picoc.googlecode.com/svn/trunk@509 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
318db09eb7
commit
b4f882354d
5
parse.c
5
parse.c
|
@ -516,6 +516,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
||||||
case TokenWhile:
|
case TokenWhile:
|
||||||
{
|
{
|
||||||
struct ParseState PreConditional;
|
struct ParseState PreConditional;
|
||||||
|
enum RunMode PreMode = Parser->Mode;
|
||||||
|
|
||||||
if (LexGetToken(Parser, NULL, TRUE) != TokenOpenBracket)
|
if (LexGetToken(Parser, NULL, TRUE) != TokenOpenBracket)
|
||||||
ProgramFail(Parser, "'(' expected");
|
ProgramFail(Parser, "'(' expected");
|
||||||
|
@ -532,12 +533,12 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
||||||
ProgramFail(Parser, "statement expected");
|
ProgramFail(Parser, "statement expected");
|
||||||
|
|
||||||
if (Parser->Mode == RunModeContinue)
|
if (Parser->Mode == RunModeContinue)
|
||||||
Parser->Mode = RunModeRun;
|
Parser->Mode = PreMode;
|
||||||
|
|
||||||
} while (Parser->Mode == RunModeRun && Condition);
|
} while (Parser->Mode == RunModeRun && Condition);
|
||||||
|
|
||||||
if (Parser->Mode == RunModeBreak)
|
if (Parser->Mode == RunModeBreak)
|
||||||
Parser->Mode = RunModeRun;
|
Parser->Mode = PreMode;
|
||||||
|
|
||||||
CheckTrailingSemicolon = FALSE;
|
CheckTrailingSemicolon = FALSE;
|
||||||
}
|
}
|
||||||
|
|
24
tests/48_nested_break.c
Normal file
24
tests/48_nested_break.c
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int a;
|
||||||
|
char b;
|
||||||
|
|
||||||
|
a = 0;
|
||||||
|
while (a < 2)
|
||||||
|
{
|
||||||
|
printf("%d", a++);
|
||||||
|
break;
|
||||||
|
|
||||||
|
b = 'A';
|
||||||
|
while (b < 'C')
|
||||||
|
{
|
||||||
|
printf("%c", b++);
|
||||||
|
}
|
||||||
|
printf("e");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
1
tests/48_nested_break.expect
Normal file
1
tests/48_nested_break.expect
Normal file
|
@ -0,0 +1 @@
|
||||||
|
0
|
|
@ -42,7 +42,8 @@ TESTS= 00_assignment.test \
|
||||||
43_void_param.test \
|
43_void_param.test \
|
||||||
44_scoped_declarations.test \
|
44_scoped_declarations.test \
|
||||||
45_empty_for.test \
|
45_empty_for.test \
|
||||||
47_switch_return.test
|
47_switch_return.test \
|
||||||
|
48_nested_break.test
|
||||||
|
|
||||||
%.test: %.expect %.c
|
%.test: %.expect %.c
|
||||||
@echo Test: $*...
|
@echo Test: $*...
|
||||||
|
|
Loading…
Reference in a new issue