Slightly neater and more general way of handling type coercion on parameter passing. Doesn't actually correct the Param->Typ any more but this shouldn't be necessary.

git-svn-id: http://picoc.googlecode.com/svn/trunk@267 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2009-04-23 22:46:32 +00:00
parent 755cbd30b5
commit f2f44b1bf7

View file

@ -894,18 +894,13 @@ void ExpressionParseFunctionCall(struct ParseState *Parser, struct ExpressionSta
{
if (FuncValue->Val->FuncDef.ParamType[ArgCount] != Param->Typ)
{
if (FuncValue->Val->FuncDef.ParamType[ArgCount] == &IntType && Param->Typ == &CharType)
{
/* cast char to int */
Param->Val->Integer = Param->Val->Character;
Param->Typ = &IntType;
}
else if (FuncValue->Val->FuncDef.ParamType[ArgCount] == &CharType && Param->Typ == &IntType)
{
/* cast int to char */
Param->Val->Character = Param->Val->Integer;
Param->Typ = &CharType;
}
/* parameter is the wrong type - can we coerce it to being the type we want? */
if (FuncValue->Val->FuncDef.ParamType[ArgCount] == &IntType && IS_INTEGER_COERCIBLE(Param))
Param->Val->Integer = COERCE_INTEGER(Param); /* cast to int */
else if (FuncValue->Val->FuncDef.ParamType[ArgCount] == &CharType && IS_INTEGER_COERCIBLE(Param))
Param->Val->Character = COERCE_INTEGER(Param); /* cast to char */
else
ProgramFail(Parser, "parameter %d to %s() is the wrong type", ArgCount+1, FuncName);
}