Front-end: Non-functional: Move return-value handling from .y to .cpp.

This is to make the real change needed in the next commit easier.
This commit is contained in:
John Kessenich 2016-06-28 19:48:43 -06:00
parent 1011971981
commit b10feabc95
4 changed files with 42 additions and 51 deletions

View file

@ -2633,22 +2633,7 @@ jump_statement
parseContext.postMainReturn = true;
}
| RETURN expression SEMICOLON {
parseContext.functionReturnsValue = true;
if (parseContext.currentFunctionType->getBasicType() == EbtVoid) {
parseContext.error($1.loc, "void function cannot return a value", "return", "");
$$ = parseContext.intermediate.addBranch(EOpReturn, $1.loc);
} else if (*(parseContext.currentFunctionType) != $2->getType()) {
TIntermTyped* converted = parseContext.intermediate.addConversion(EOpReturn, *parseContext.currentFunctionType, $2);
if (converted) {
if (parseContext.version < 420)
parseContext.warn($1.loc, "type conversion on return values was not explicitly allowed until version 420", "return", "");
$$ = parseContext.intermediate.addBranch(EOpReturn, converted, $1.loc);
} else {
parseContext.error($1.loc, "type does not match, or is not convertible to, the function's return type", "return", "");
$$ = parseContext.intermediate.addBranch(EOpReturn, $2, $1.loc);
}
} else
$$ = parseContext.intermediate.addBranch(EOpReturn, $2, $1.loc);
$$ = parseContext.handleReturnValue($1.loc, $2);
}
| DISCARD SEMICOLON {
parseContext.requireStage($1.loc, EShLangFragment, "discard");