Exemplo n.º 1
0
static AstExpression CheckFunctionCall(AstExpression expr)
{
	AstExpression arg;
	Type ty;
	AstNode *tail;
	int argNo, argFull;

	if (expr->kids[0]->op == OP_ID && LookupID(expr->kids[0]->val.p) == NULL)
	{
		expr->kids[0]->ty = DefaultFunctionType;
		expr->kids[0]->val.p = AddFunction(expr->kids[0]->val.p, DefaultFunctionType, TK_EXTERN);
	}
	else
	{
		expr->kids[0] = CheckExpression(expr->kids[0]);
	}
	expr->kids[0] = Adjust(expr->kids[0], 1);
	ty = expr->kids[0]->ty;

	if (! (IsPtrType(ty) && IsFunctionType(ty->bty)))
	{
		Error(&expr->coord, "The left operand must be function or function pointer");
	    ty = DefaultFunctionType;
	}
	else
	{
		ty = ty->bty;
	}

	tail = (AstNode *)&expr->kids[1];
	arg = expr->kids[1];
	argNo = 1;
	argFull = 0;
	while (arg != NULL && ! argFull)
	{
		*tail = (AstNode)CheckArgument((FunctionType)ty, arg, argNo, &argFull);
		tail = &(*tail)->next;
		arg = (AstExpression)arg->next;
		argNo++;
	}
	*tail = NULL;

	if (arg != NULL)
	{
		while (arg != NULL)
		{
			CheckExpression(arg);
			arg = (AstExpression)arg->next;
		}
		Error(&expr->coord, "Too many arguments");
	}
	else if (argNo < LEN(((FunctionType)ty)->sig->params))
	{
		Error(&expr->coord, "Too few arguments");
	}
	expr->ty = ty->bty;

	return expr;
}
Exemplo n.º 2
0
void ParamElement::ReadValue(const DOMNode* node)
{
	_ASSERTE(node != NULL);

	DOMNode* value = node->getFirstChild();
	if( value == NULL ) { return; }

	BaseRefVectorOf<XMLCh>* vecValue = XMLString::tokenizeString( value->getNodeValue() );

	unsigned int sizeValue = vecValue->size();
	if( sizeValue == 0 ) { return; }

	if( IsFloatType() )
	{
		valFloat.reserve( sizeValue );
		for( unsigned int i = 0; i < sizeValue; i++ )
		{
			valFloat.push_back( XMLChToFloat( vecValue->elementAt( i ) ) );
		}
	}
	else if( IsBoolType() )
	{
		valBool.reserve( sizeValue );
		for( unsigned int i = 0; i < sizeValue; i++ )
		{
			valBool.push_back( XMLChToBool( vecValue->elementAt( i ) ) );
		}
	}
	else if( IsBlendType() )
	{
		// 未実装
	}
	else if( IsFunctionType() )
	{
		// 未実装
	}
	else { _ASSERTE(!"UnknownType"); }

	SAFE_DELETE(vecValue);
}
Exemplo n.º 3
0
static AstExpression CheckUnaryExpression(AstExpression expr)
{
	Type ty;

	switch (expr->op)
	{
	case OP_PREINC:
	case OP_PREDEC:
		return TransformIncrement(expr);

	case OP_ADDRESS:
		expr->kids[0] = CheckExpression(expr->kids[0]);
		ty = expr->kids[0]->ty;
		if (expr->kids[0]->op == OP_DEREF)
		{
			expr->kids[0]->kids[0]->lvalue = 0;
			return expr->kids[0]->kids[0];
		}
		else if (expr->kids[0]->op == OP_INDEX)
		{
			expr->kids[0]->op = OP_ADD;
			expr->kids[0]->ty = PointerTo(ty);
			expr->kids[0]->lvalue = 0;
			return expr->kids[0];
		}
		else if (IsFunctionType(ty) || 
			     (expr->kids[0]->lvalue && ! expr->kids[0]->bitfld && ! expr->kids[0]->inreg))
		{
			expr->ty = PointerTo(ty);
			return expr;
		}
		break;

	case OP_DEREF:
		expr->kids[0] = Adjust(CheckExpression(expr->kids[0]), 1);
		ty = expr->kids[0]->ty;
		if (expr->kids[0]->op == OP_ADDRESS)
		{
			expr->kids[0]->kids[0]->ty = ty->bty;
			return expr->kids[0]->kids[0];
		}
		else if (expr->kids[0]->op == OP_ADD && expr->kids[0]->kids[0]->isarray)
		{
			expr->kids[0]->op = OP_INDEX;
			expr->kids[0]->ty = ty->bty;
			expr->kids[0]->lvalue = 1;
			return expr->kids[0];
		}
		if (IsPtrType(ty))
		{
			expr->ty = ty->bty;
			if (IsFunctionType(expr->ty))
			{
				return expr->kids[0];
			}
			expr->lvalue = 1;
			return expr;
		}
		break;

	case OP_POS:
	case OP_NEG:
		expr->kids[0] = Adjust(CheckExpression(expr->kids[0]), 1);
		if (IsArithType(expr->kids[0]->ty))
		{
			expr->kids[0] = DoIntegerPromotion(expr->kids[0]);
			expr->ty = expr->kids[0]->ty;
			return expr->op == OP_POS ? expr->kids[0] : FoldConstant(expr);
		}
		break;

	case OP_COMP:
		expr->kids[0] = Adjust(CheckExpression(expr->kids[0]), 1);
		if (IsIntegType(expr->kids[0]->ty))
		{
			expr->kids[0] = DoIntegerPromotion(expr->kids[0]);
			expr->ty = expr->kids[0]->ty;
			return FoldConstant(expr);
		}
		break;

	case OP_NOT:
		expr->kids[0] = Adjust(CheckExpression(expr->kids[0]), 1);
		if (IsScalarType(expr->kids[0]->ty))
		{
			expr->ty = T(INT);
			return FoldConstant(expr);
		}
		break;

	case OP_SIZEOF:
		if (expr->kids[0]->kind == NK_Expression)
		{
			expr->kids[0] = CheckExpression(expr->kids[0]);
			if (expr->kids[0]->bitfld)
				goto err;
			ty = expr->kids[0]->ty;
		}
		else
		{
			ty = CheckTypeName((AstTypeName)expr->kids[0]);
		}
		if (IsFunctionType(ty) || ty->size == 0)
			goto err;

		expr->ty = T(UINT);
		expr->op = OP_CONST;
		expr->val.i[0] = ty->size;
		return expr;

	case OP_CAST:
		return CheckTypeCast(expr);

	default:
		assert(0);
	}

err:
	REPORT_OP_ERROR;

}