Fixed bug108 - brackets were not collapsing the expression stack
as they should have. Now more permissive in declarations of void main() git-svn-id: http://picoc.googlecode.com/svn/trunk@520 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
3893e46c26
commit
b2c4d6ce83
13
expression.c
13
expression.c
|
@ -475,16 +475,6 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack
|
||||||
ExpressionPushInt(Parser, StackTop, TypeSize(TopValue->Typ, TopValue->Typ->ArraySize, TRUE));
|
ExpressionPushInt(Parser, StackTop, TypeSize(TopValue->Typ, TopValue->Typ->ArraySize, TRUE));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TokenLeftSquareBracket:
|
|
||||||
/* XXX */
|
|
||||||
ProgramFail(Parser, "not supported");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TokenOpenBracket:
|
|
||||||
/* XXX - cast */
|
|
||||||
ProgramFail(Parser, "not supported");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* an arithmetic operator */
|
/* an arithmetic operator */
|
||||||
#ifndef NO_FP
|
#ifndef NO_FP
|
||||||
|
@ -1065,6 +1055,9 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
BracketPrecedence -= BRACKET_PRECEDENCE;
|
BracketPrecedence -= BRACKET_PRECEDENCE;
|
||||||
|
|
||||||
|
/* collapse to the bracket precedence */
|
||||||
|
ExpressionStackCollapse(Parser, &StackTop, BracketPrecedence);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
6
parse.c
6
parse.c
|
@ -130,8 +130,9 @@ struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueTyp
|
||||||
if (strcmp(Identifier, "main") == 0)
|
if (strcmp(Identifier, "main") == 0)
|
||||||
{
|
{
|
||||||
/* make sure it's int main() */
|
/* make sure it's int main() */
|
||||||
if (FuncValue->Val->FuncDef.ReturnType != &IntType)
|
if ( FuncValue->Val->FuncDef.ReturnType != &IntType &&
|
||||||
ProgramFail(Parser, "main() should return an int");
|
FuncValue->Val->FuncDef.ReturnType != &VoidType )
|
||||||
|
ProgramFail(Parser, "main() should return an int or void");
|
||||||
|
|
||||||
if (FuncValue->Val->FuncDef.NumParams != 0 &&
|
if (FuncValue->Val->FuncDef.NumParams != 0 &&
|
||||||
(FuncValue->Val->FuncDef.NumParams != 2 || FuncValue->Val->FuncDef.ParamType[0] != &IntType) )
|
(FuncValue->Val->FuncDef.NumParams != 2 || FuncValue->Val->FuncDef.ParamType[0] != &IntType) )
|
||||||
|
@ -498,6 +499,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
||||||
case TokenAmpersand:
|
case TokenAmpersand:
|
||||||
case TokenIncrement:
|
case TokenIncrement:
|
||||||
case TokenDecrement:
|
case TokenDecrement:
|
||||||
|
case TokenOpenBracket:
|
||||||
*Parser = PreState;
|
*Parser = PreState;
|
||||||
ExpressionParse(Parser, &CValue);
|
ExpressionParse(Parser, &CValue);
|
||||||
if (Parser->Mode == RunModeRun)
|
if (Parser->Mode == RunModeRun)
|
||||||
|
|
|
@ -221,11 +221,13 @@ void print_led(unsigned long x, char *buf)
|
||||||
*buf='\0';
|
*buf='\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
int main()
|
||||||
{
|
{
|
||||||
char buf[5*MAX_DIGITS];
|
char buf[5*MAX_DIGITS];
|
||||||
print_led(1234567, buf);
|
print_led(1234567, buf);
|
||||||
printf("%s\n",buf);
|
printf("%s\n",buf);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NO_MAIN
|
#ifndef NO_MAIN
|
||||||
|
|
21
tests/49_bracket_evaluation.c
Normal file
21
tests/49_bracket_evaluation.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
struct point
|
||||||
|
{
|
||||||
|
double x;
|
||||||
|
double y;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct point point_array[100];
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int my_point = 10;
|
||||||
|
|
||||||
|
point_array[my_point].x = 12.34;
|
||||||
|
point_array[my_point].y = 56.78;
|
||||||
|
|
||||||
|
printf("%f, %f\n", point_array[my_point].x, point_array[my_point].y);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
1
tests/49_bracket_evaluation.expect
Normal file
1
tests/49_bracket_evaluation.expect
Normal file
|
@ -0,0 +1 @@
|
||||||
|
12.340000, 56.780000
|
|
@ -43,7 +43,8 @@ TESTS= 00_assignment.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
|
48_nested_break.test \
|
||||||
|
49_bracket_evaluation.test
|
||||||
|
|
||||||
%.test: %.expect %.c
|
%.test: %.expect %.c
|
||||||
@echo Test: $*...
|
@echo Test: $*...
|
||||||
|
|
Loading…
Reference in a new issue