HLSL: add implicit promotions for assignments and function returns.
This commit is contained in:
@@ -2446,7 +2446,7 @@ bool HlslGrammar::acceptJumpStatement(TIntermNode*& statement)
|
||||
TIntermTyped* node;
|
||||
if (acceptExpression(node)) {
|
||||
// hook it up
|
||||
statement = intermediate.addBranch(EOpReturn, node, token.loc);
|
||||
statement = parseContext.handleReturnValue(token.loc, node);
|
||||
} else
|
||||
statement = intermediate.addBranch(EOpReturn, token.loc);
|
||||
break;
|
||||
|
||||
@@ -796,6 +796,25 @@ TIntermAggregate* HlslParseContext::handleFunctionDefinition(const TSourceLoc& l
|
||||
return paramNodes;
|
||||
}
|
||||
|
||||
// Handle function returns, including type conversions to the function return type
|
||||
// if necessary.
|
||||
TIntermNode* HlslParseContext::handleReturnValue(const TSourceLoc& loc, TIntermTyped* value)
|
||||
{
|
||||
if (currentFunctionType->getBasicType() == EbtVoid) {
|
||||
error(loc, "void function cannot return a value", "return", "");
|
||||
return intermediate.addBranch(EOpReturn, loc);
|
||||
} else if (*currentFunctionType != value->getType()) {
|
||||
TIntermTyped* converted = intermediate.addConversion(EOpReturn, *currentFunctionType, value);
|
||||
if (converted) {
|
||||
return intermediate.addBranch(EOpReturn, converted, loc);
|
||||
} else {
|
||||
error(loc, "type does not match, or is not convertible to, the function's return type", "return", "");
|
||||
return intermediate.addBranch(EOpReturn, value, loc);
|
||||
}
|
||||
} else
|
||||
return intermediate.addBranch(EOpReturn, value, loc);
|
||||
}
|
||||
|
||||
void HlslParseContext::handleFunctionArgument(TFunction* function, TIntermTyped*& arguments, TIntermTyped* newArg)
|
||||
{
|
||||
TParameter param = { 0, new TType };
|
||||
|
||||
@@ -85,6 +85,7 @@ public:
|
||||
TIntermTyped* handleDotDereference(const TSourceLoc&, TIntermTyped* base, const TString& field);
|
||||
TFunction* handleFunctionDeclarator(const TSourceLoc&, TFunction& function, bool prototype);
|
||||
TIntermAggregate* handleFunctionDefinition(const TSourceLoc&, TFunction&);
|
||||
TIntermNode* handleReturnValue(const TSourceLoc&, TIntermTyped*);
|
||||
void handleFunctionArgument(TFunction*, TIntermTyped*& arguments, TIntermTyped* newArg);
|
||||
TIntermTyped* handleFunctionCall(const TSourceLoc&, TFunction*, TIntermNode*);
|
||||
void decomposeIntrinsic(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
|
||||
|
||||
Reference in New Issue
Block a user