Fixed problem with returns inside switch() statements not working correctly outside the switch block.

Issue #116


git-svn-id: http://picoc.googlecode.com/svn/trunk@506 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2011-02-11 04:49:44 +00:00
parent b6a760e554
commit e236537ab2
5 changed files with 33 additions and 25 deletions

View file

@ -1234,7 +1234,7 @@ void ExpressionParseMacroCall(struct ParseState *Parser, struct ExpressionStack
#ifndef NO_FP
ExpressionStackPushValueByType(Parser, StackTop, &FPType); /* largest return type there is */
#else
ExpressionStackPushValueByType(Parser, StackTop, VoidPtrType); /* largest return type there is */
ExpressionStackPushValueByType(Parser, StackTop, IntType); /* largest return type there is */
#endif
ReturnValue = (*StackTop)->Val;
HeapPushStackFrame();

View file

@ -635,7 +635,9 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
ParseBlock(Parser, TRUE, OldMode != RunModeSkip);
Parser->Mode = OldMode;
if (Parser->Mode != RunModeReturn)
Parser->Mode = OldMode;
Parser->SearchLabel = OldSearchLabel;
}

View file

@ -1,22 +1,23 @@
#include <stdio.h>
void fred(int x)
{
switch (x)
{
case 1: printf("1\n"); return;
case 2: printf("2\n"); break;
case 3: printf("3\n"); return;
}
printf("out\n");
}
int main()
{
fred(1);
fred(2);
fred(3);
return 0;
}
#include <stdio.h>
void fred(int x)
{
switch (x)
{
case 1: printf("1\n"); return;
case 2: printf("2\n"); break;
case 3: printf("3\n"); return;
}
printf("out\n");
}
int main()
{
fred(1);
fred(2);
fred(3);
return 0;
}

View file

@ -0,0 +1,4 @@
1
2
out
3

View file

@ -40,7 +40,8 @@ TESTS= 00_assignment.test \
41_hashif.test \
43_void_param.test \
44_scoped_declarations.test \
45_empty_for.test
45_empty_for.test \
47_switch_return.test
%.test: %.expect %.c
@echo Test: $*...