Fix default precision check for formal parameters; it was one level too deep. This will accept more fragment shaders with no default precision before declaring functions.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@29281 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2014-12-21 20:30:04 +00:00
parent 33a5423f76
commit c311d35500
3 changed files with 48 additions and 46 deletions

View File

@ -2266,27 +2266,27 @@ TPrecisionQualifier TParseContext::getDefaultPrecision(TPublicType& publicType)
return defaultPrecision[publicType.basicType]; return defaultPrecision[publicType.basicType];
} }
void TParseContext::precisionQualifierCheck(TSourceLoc loc, TPublicType& publicType) void TParseContext::precisionQualifierCheck(TSourceLoc loc, TBasicType baseType, TQualifier& qualifier)
{ {
// Built-in symbols are allowed some ambiguous precisions, to be pinned down // Built-in symbols are allowed some ambiguous precisions, to be pinned down
// later by context. // later by context.
if (profile != EEsProfile || parsingBuiltins) if (profile != EEsProfile || parsingBuiltins)
return; return;
if (publicType.basicType == EbtAtomicUint && publicType.qualifier.precision != EpqNone && publicType.qualifier.precision != EpqHigh) if (baseType == EbtAtomicUint && qualifier.precision != EpqNone && qualifier.precision != EpqHigh)
error(loc, "atomic counters can only be highp", "atomic_uint", ""); error(loc, "atomic counters can only be highp", "atomic_uint", "");
if (publicType.basicType == EbtFloat || publicType.basicType == EbtUint || publicType.basicType == EbtInt || publicType.basicType == EbtSampler || publicType.basicType == EbtAtomicUint) { if (baseType == EbtFloat || baseType == EbtUint || baseType == EbtInt || baseType == EbtSampler || baseType == EbtAtomicUint) {
if (publicType.qualifier.precision == EpqNone) { if (qualifier.precision == EpqNone) {
if (messages & EShMsgRelaxedErrors) if (messages & EShMsgRelaxedErrors)
warn(loc, "type requires declaration of default precision qualifier", TType::getBasicString(publicType.basicType), "substituting 'mediump'"); warn(loc, "type requires declaration of default precision qualifier", TType::getBasicString(baseType), "substituting 'mediump'");
else else
error(loc, "type requires declaration of default precision qualifier", TType::getBasicString(publicType.basicType), ""); error(loc, "type requires declaration of default precision qualifier", TType::getBasicString(baseType), "");
publicType.qualifier.precision = EpqMedium; qualifier.precision = EpqMedium;
defaultPrecision[publicType.basicType] = EpqMedium; defaultPrecision[baseType] = EpqMedium;
} }
} else if (publicType.qualifier.precision != EpqNone) } else if (qualifier.precision != EpqNone)
error(loc, "type cannot have precision qualifier", TType::getBasicString(publicType.basicType), ""); error(loc, "type cannot have precision qualifier", TType::getBasicString(baseType), "");
} }
void TParseContext::parameterTypeCheck(TSourceLoc loc, TStorageQualifier qualifier, const TType& type) void TParseContext::parameterTypeCheck(TSourceLoc loc, TStorageQualifier qualifier, const TType& type)

View File

@ -138,7 +138,7 @@ public:
void setDefaultPrecision(TSourceLoc, TPublicType&, TPrecisionQualifier); void setDefaultPrecision(TSourceLoc, TPublicType&, TPrecisionQualifier);
int computeSamplerTypeIndex(TSampler&); int computeSamplerTypeIndex(TSampler&);
TPrecisionQualifier getDefaultPrecision(TPublicType&); TPrecisionQualifier getDefaultPrecision(TPublicType&);
void precisionQualifierCheck(TSourceLoc, TPublicType&); void precisionQualifierCheck(TSourceLoc, TBasicType, TQualifier&);
void parameterTypeCheck(TSourceLoc, TStorageQualifier qualifier, const TType& type); void parameterTypeCheck(TSourceLoc, TStorageQualifier qualifier, const TType& type);
bool containsFieldWithBasicType(const TType& type ,TBasicType basicType); bool containsFieldWithBasicType(const TType& type ,TBasicType basicType);
TSymbol* redeclareBuiltinVariable(TSourceLoc, const TString&, const TQualifier&, const TShaderQualifiers&, bool& newDeclaration); TSymbol* redeclareBuiltinVariable(TSourceLoc, const TString&, const TQualifier&, const TShaderQualifiers&, bool& newDeclaration);

View File

@ -35,7 +35,7 @@
// //
/** /**
* This is bison grammar and productions for parsing all versions of the * This is bison grammar and productions for parsing all versions of the
* GLSL shading languages. * GLSL shading languages.
*/ */
%{ %{
@ -228,7 +228,7 @@ primary_expression
| INTCONSTANT { | INTCONSTANT {
$$ = parseContext.intermediate.addConstantUnion($1.i, $1.loc, true); $$ = parseContext.intermediate.addConstantUnion($1.i, $1.loc, true);
} }
| UINTCONSTANT { | UINTCONSTANT {
parseContext.fullIntegerCheck($1.loc, "unsigned literal"); parseContext.fullIntegerCheck($1.loc, "unsigned literal");
$$ = parseContext.intermediate.addConstantUnion($1.u, $1.loc, true); $$ = parseContext.intermediate.addConstantUnion($1.u, $1.loc, true);
} }
@ -243,7 +243,7 @@ primary_expression
$$ = parseContext.intermediate.addConstantUnion($1.b, $1.loc, true); $$ = parseContext.intermediate.addConstantUnion($1.b, $1.loc, true);
} }
| LEFT_PAREN expression RIGHT_PAREN { | LEFT_PAREN expression RIGHT_PAREN {
$$ = $2; $$ = $2;
if ($$->getAsConstantUnion()) if ($$->getAsConstantUnion())
$$->getAsConstantUnion()->setExpression(); $$->getAsConstantUnion()->setExpression();
} }
@ -343,7 +343,7 @@ function_identifier
: type_specifier { : type_specifier {
// Constructor // Constructor
$$.intermNode = 0; $$.intermNode = 0;
$$.function = parseContext.handleConstructorCall($1.loc, $1); $$.function = parseContext.handleConstructorCall($1.loc, $1);
} }
| postfix_expression { | postfix_expression {
// //
@ -602,27 +602,27 @@ assignment_operator
$$.op = EOpAssign; $$.op = EOpAssign;
} }
| MUL_ASSIGN { | MUL_ASSIGN {
$$.loc = $1.loc; $$.loc = $1.loc;
$$.op = EOpMulAssign; $$.op = EOpMulAssign;
} }
| DIV_ASSIGN { | DIV_ASSIGN {
$$.loc = $1.loc; $$.loc = $1.loc;
$$.op = EOpDivAssign; $$.op = EOpDivAssign;
} }
| MOD_ASSIGN { | MOD_ASSIGN {
parseContext.fullIntegerCheck($1.loc, "%="); parseContext.fullIntegerCheck($1.loc, "%=");
$$.loc = $1.loc; $$.loc = $1.loc;
$$.op = EOpModAssign; $$.op = EOpModAssign;
} }
| ADD_ASSIGN { | ADD_ASSIGN {
$$.loc = $1.loc; $$.loc = $1.loc;
$$.op = EOpAddAssign; $$.op = EOpAddAssign;
} }
| SUB_ASSIGN { | SUB_ASSIGN {
$$.loc = $1.loc; $$.loc = $1.loc;
$$.op = EOpSubAssign; $$.op = EOpSubAssign;
} }
| LEFT_ASSIGN { | LEFT_ASSIGN {
parseContext.fullIntegerCheck($1.loc, "bit-shift left assign"); parseContext.fullIntegerCheck($1.loc, "bit-shift left assign");
$$.loc = $1.loc; $$.op = EOpLeftShiftAssign; $$.loc = $1.loc; $$.op = EOpLeftShiftAssign;
} }
@ -630,15 +630,15 @@ assignment_operator
parseContext.fullIntegerCheck($1.loc, "bit-shift right assign"); parseContext.fullIntegerCheck($1.loc, "bit-shift right assign");
$$.loc = $1.loc; $$.op = EOpRightShiftAssign; $$.loc = $1.loc; $$.op = EOpRightShiftAssign;
} }
| AND_ASSIGN { | AND_ASSIGN {
parseContext.fullIntegerCheck($1.loc, "bitwise-and assign"); parseContext.fullIntegerCheck($1.loc, "bitwise-and assign");
$$.loc = $1.loc; $$.op = EOpAndAssign; $$.loc = $1.loc; $$.op = EOpAndAssign;
} }
| XOR_ASSIGN { | XOR_ASSIGN {
parseContext.fullIntegerCheck($1.loc, "bitwise-xor assign"); parseContext.fullIntegerCheck($1.loc, "bitwise-xor assign");
$$.loc = $1.loc; $$.op = EOpExclusiveOrAssign; $$.loc = $1.loc; $$.op = EOpExclusiveOrAssign;
} }
| OR_ASSIGN { | OR_ASSIGN {
parseContext.fullIntegerCheck($1.loc, "bitwise-or assign"); parseContext.fullIntegerCheck($1.loc, "bitwise-or assign");
$$.loc = $1.loc; $$.op = EOpInclusiveOrAssign; $$.loc = $1.loc; $$.op = EOpInclusiveOrAssign;
} }
@ -809,7 +809,6 @@ parameter_declarator
parseContext.error($2.loc, "illegal use of type 'void'", $2.string->c_str(), ""); parseContext.error($2.loc, "illegal use of type 'void'", $2.string->c_str(), "");
} }
parseContext.reservedErrorCheck($2.loc, *$2.string); parseContext.reservedErrorCheck($2.loc, *$2.string);
parseContext.precisionQualifierCheck($1.loc, $1);
TParameter param = {$2.string, new TType($1)}; TParameter param = {$2.string, new TType($1)};
$$.loc = $2.loc; $$.loc = $2.loc;
@ -824,8 +823,7 @@ parameter_declarator
parseContext.arrayDimCheck($2.loc, $1.arraySizes, $3.arraySizes); parseContext.arrayDimCheck($2.loc, $1.arraySizes, $3.arraySizes);
parseContext.arraySizeRequiredCheck($3.loc, $3.arraySizes->getSize()); parseContext.arraySizeRequiredCheck($3.loc, $3.arraySizes->getSize());
parseContext.reservedErrorCheck($2.loc, *$2.string); parseContext.reservedErrorCheck($2.loc, *$2.string);
parseContext.precisionQualifierCheck($1.loc, $1);
$1.arraySizes = $3.arraySizes; $1.arraySizes = $3.arraySizes;
@ -843,16 +841,19 @@ parameter_declaration
$$ = $2; $$ = $2;
if ($1.qualifier.precision != EpqNone) if ($1.qualifier.precision != EpqNone)
$$.param.type->getQualifier().precision = $1.qualifier.precision; $$.param.type->getQualifier().precision = $1.qualifier.precision;
parseContext.precisionQualifierCheck($$.loc, $$.param.type->getBasicType(), $$.param.type->getQualifier());
parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers); parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers);
parseContext.parameterTypeCheck($2.loc, $1.qualifier.storage, *$$.param.type); parseContext.parameterTypeCheck($2.loc, $1.qualifier.storage, *$$.param.type);
parseContext.paramCheckFix($1.loc, $1.qualifier, *$$.param.type); parseContext.paramCheckFix($1.loc, $1.qualifier, *$$.param.type);
} }
| parameter_declarator { | parameter_declarator {
$$ = $1; $$ = $1;
parseContext.parameterTypeCheck($1.loc, EvqIn, *$1.param.type); parseContext.parameterTypeCheck($1.loc, EvqIn, *$1.param.type);
parseContext.paramCheckFix($1.loc, EvqTemporary, *$$.param.type); parseContext.paramCheckFix($1.loc, EvqTemporary, *$$.param.type);
parseContext.precisionQualifierCheck($$.loc, $$.param.type->getBasicType(), $$.param.type->getQualifier());
} }
// //
// Without name // Without name
@ -861,7 +862,8 @@ parameter_declaration
$$ = $2; $$ = $2;
if ($1.qualifier.precision != EpqNone) if ($1.qualifier.precision != EpqNone)
$$.param.type->getQualifier().precision = $1.qualifier.precision; $$.param.type->getQualifier().precision = $1.qualifier.precision;
parseContext.precisionQualifierCheck($1.loc, $$.param.type->getBasicType(), $$.param.type->getQualifier());
parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers); parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers);
parseContext.parameterTypeCheck($2.loc, $1.qualifier.storage, *$$.param.type); parseContext.parameterTypeCheck($2.loc, $1.qualifier.storage, *$$.param.type);
parseContext.paramCheckFix($1.loc, $1.qualifier, *$$.param.type); parseContext.paramCheckFix($1.loc, $1.qualifier, *$$.param.type);
@ -871,6 +873,7 @@ parameter_declaration
parseContext.parameterTypeCheck($1.loc, EvqIn, *$1.param.type); parseContext.parameterTypeCheck($1.loc, EvqIn, *$1.param.type);
parseContext.paramCheckFix($1.loc, EvqTemporary, *$$.param.type); parseContext.paramCheckFix($1.loc, EvqTemporary, *$$.param.type);
parseContext.precisionQualifierCheck($$.loc, $$.param.type->getBasicType(), $$.param.type->getQualifier());
} }
; ;
@ -880,7 +883,6 @@ parameter_type_specifier
$$.param = param; $$.param = param;
if ($1.arraySizes) if ($1.arraySizes)
parseContext.arraySizeRequiredCheck($1.loc, $1.arraySizes->getSize()); parseContext.arraySizeRequiredCheck($1.loc, $1.arraySizes->getSize());
parseContext.precisionQualifierCheck($1.loc, $1);
} }
; ;
@ -947,7 +949,7 @@ fully_specified_type
parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type"); parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type");
} }
parseContext.precisionQualifierCheck($$.loc, $$); parseContext.precisionQualifierCheck($$.loc, $$.basicType, $$.qualifier);
} }
| type_qualifier type_specifier { | type_qualifier type_specifier {
parseContext.globalQualifierFixCheck($1.loc, $1.qualifier); parseContext.globalQualifierFixCheck($1.loc, $1.qualifier);
@ -960,15 +962,15 @@ fully_specified_type
if ($2.arraySizes && parseContext.arrayQualifierError($2.loc, $1.qualifier)) if ($2.arraySizes && parseContext.arrayQualifierError($2.loc, $1.qualifier))
$2.arraySizes = 0; $2.arraySizes = 0;
parseContext.checkNoShaderLayouts($2.loc, $1.shaderQualifiers); parseContext.checkNoShaderLayouts($2.loc, $1.shaderQualifiers);
$2.shaderQualifiers.merge($1.shaderQualifiers); $2.shaderQualifiers.merge($1.shaderQualifiers);
parseContext.mergeQualifiers($2.loc, $2.qualifier, $1.qualifier, true); parseContext.mergeQualifiers($2.loc, $2.qualifier, $1.qualifier, true);
parseContext.precisionQualifierCheck($2.loc, $2); parseContext.precisionQualifierCheck($2.loc, $2.basicType, $2.qualifier);
$$ = $2; $$ = $2;
if (! $$.qualifier.isInterpolation() && if (! $$.qualifier.isInterpolation() &&
((parseContext.language == EShLangVertex && $$.qualifier.storage == EvqVaryingOut) || ((parseContext.language == EShLangVertex && $$.qualifier.storage == EvqVaryingOut) ||
(parseContext.language == EShLangFragment && $$.qualifier.storage == EvqVaryingIn))) (parseContext.language == EShLangFragment && $$.qualifier.storage == EvqVaryingIn)))
$$.qualifier.smooth = true; $$.qualifier.smooth = true;
@ -1215,7 +1217,7 @@ type_specifier
$$ = $1; $$ = $1;
$$.qualifier.precision = parseContext.getDefaultPrecision($$); $$.qualifier.precision = parseContext.getDefaultPrecision($$);
} }
| type_specifier_nonarray array_specifier { | type_specifier_nonarray array_specifier {
parseContext.arrayDimCheck($2.loc, $2.arraySizes, 0); parseContext.arrayDimCheck($2.loc, $2.arraySizes, 0);
$$ = $1; $$ = $1;
$$.qualifier.precision = parseContext.getDefaultPrecision($$); $$.qualifier.precision = parseContext.getDefaultPrecision($$);
@ -1955,7 +1957,7 @@ struct_declaration
$$ = $2; $$ = $2;
parseContext.voidErrorCheck($1.loc, (*$2)[0].type->getFieldName(), $1.basicType); parseContext.voidErrorCheck($1.loc, (*$2)[0].type->getFieldName(), $1.basicType);
parseContext.precisionQualifierCheck($1.loc, $1); parseContext.precisionQualifierCheck($1.loc, $1.basicType, $1.qualifier);
for (unsigned int i = 0; i < $$->size(); ++i) { for (unsigned int i = 0; i < $$->size(); ++i) {
parseContext.arrayDimCheck($1.loc, (*$$)[i].type, $1.arraySizes); parseContext.arrayDimCheck($1.loc, (*$$)[i].type, $1.arraySizes);
@ -1976,7 +1978,7 @@ struct_declaration
parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers); parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers);
parseContext.voidErrorCheck($2.loc, (*$3)[0].type->getFieldName(), $2.basicType); parseContext.voidErrorCheck($2.loc, (*$3)[0].type->getFieldName(), $2.basicType);
parseContext.mergeQualifiers($2.loc, $2.qualifier, $1.qualifier, true); parseContext.mergeQualifiers($2.loc, $2.qualifier, $1.qualifier, true);
parseContext.precisionQualifierCheck($2.loc, $2); parseContext.precisionQualifierCheck($2.loc, $2.basicType, $2.qualifier);
for (unsigned int i = 0; i < $$->size(); ++i) { for (unsigned int i = 0; i < $$->size(); ++i) {
parseContext.arrayDimCheck($1.loc, (*$$)[i].type, $2.arraySizes); parseContext.arrayDimCheck($1.loc, (*$$)[i].type, $2.arraySizes);
@ -2001,7 +2003,7 @@ struct_declarator
$$.loc = $1.loc; $$.loc = $1.loc;
$$.type->setFieldName(*$1.string); $$.type->setFieldName(*$1.string);
} }
| IDENTIFIER array_specifier { | IDENTIFIER array_specifier {
parseContext.arrayDimCheck($1.loc, $2.arraySizes, 0); parseContext.arrayDimCheck($1.loc, $2.arraySizes, 0);
$$.type = new TType(EbtVoid); $$.type = new TType(EbtVoid);
@ -2065,7 +2067,7 @@ compound_statement
parseContext.symbolTable.push(); parseContext.symbolTable.push();
++parseContext.controlFlowNestingLevel; ++parseContext.controlFlowNestingLevel;
} }
statement_list { statement_list {
parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]); parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
--parseContext.controlFlowNestingLevel; --parseContext.controlFlowNestingLevel;
} }
@ -2083,10 +2085,10 @@ statement_no_new_scope
statement_scoped statement_scoped
: compound_statement { $$ = $1; } : compound_statement { $$ = $1; }
| { | {
parseContext.symbolTable.push(); parseContext.symbolTable.push();
++parseContext.controlFlowNestingLevel; ++parseContext.controlFlowNestingLevel;
} }
simple_statement { simple_statement {
parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]); parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
--parseContext.controlFlowNestingLevel; --parseContext.controlFlowNestingLevel;
@ -2115,7 +2117,7 @@ statement_list
} }
} }
| statement_list statement { | statement_list statement {
if ($2 && $2->getAsBranchNode() && ($2->getAsBranchNode()->getFlowOp() == EOpCase || if ($2 && $2->getAsBranchNode() && ($2->getAsBranchNode()->getFlowOp() == EOpCase ||
$2->getAsBranchNode()->getFlowOp() == EOpDefault)) { $2->getAsBranchNode()->getFlowOp() == EOpDefault)) {
parseContext.wrapupSwitchSubsequence($1 ? $1->getAsAggregate() : 0, $2); parseContext.wrapupSwitchSubsequence($1 ? $1->getAsAggregate() : 0, $2);
$$ = 0; // start a fresh subsequence for what's after this case $$ = 0; // start a fresh subsequence for what's after this case
@ -2172,13 +2174,13 @@ switch_statement
parseContext.switchSequenceStack.push_back(new TIntermSequence); parseContext.switchSequenceStack.push_back(new TIntermSequence);
parseContext.switchLevel.push_back(parseContext.controlFlowNestingLevel); parseContext.switchLevel.push_back(parseContext.controlFlowNestingLevel);
parseContext.symbolTable.push(); parseContext.symbolTable.push();
} }
LEFT_BRACE switch_statement_list RIGHT_BRACE { LEFT_BRACE switch_statement_list RIGHT_BRACE {
$$ = parseContext.addSwitch($1.loc, $3, $7 ? $7->getAsAggregate() : 0); $$ = parseContext.addSwitch($1.loc, $3, $7 ? $7->getAsAggregate() : 0);
delete parseContext.switchSequenceStack.back(); delete parseContext.switchSequenceStack.back();
parseContext.switchSequenceStack.pop_back(); parseContext.switchSequenceStack.pop_back();
parseContext.switchLevel.pop_back(); parseContext.switchLevel.pop_back();
parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]); parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
--parseContext.controlFlowNestingLevel; --parseContext.controlFlowNestingLevel;
} }
; ;
@ -2230,10 +2232,10 @@ iteration_statement
--parseContext.loopNestingLevel; --parseContext.loopNestingLevel;
--parseContext.controlFlowNestingLevel; --parseContext.controlFlowNestingLevel;
} }
| DO { | DO {
++parseContext.loopNestingLevel; ++parseContext.loopNestingLevel;
++parseContext.controlFlowNestingLevel; ++parseContext.controlFlowNestingLevel;
} }
statement WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON { statement WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON {
if (! parseContext.limits.whileLoops) if (! parseContext.limits.whileLoops)
parseContext.error($1.loc, "do-while loops not available", "limitation", ""); parseContext.error($1.loc, "do-while loops not available", "limitation", "");