HLSL: allow trailing commas in initializer lists & scalar initialization

This commit is contained in:
steve-lunarg
2016-07-30 10:36:09 -06:00
parent b38f071605
commit fe5a3ff2f3
5 changed files with 199 additions and 5 deletions

View File

@@ -1549,8 +1549,11 @@ bool HlslGrammar::acceptInitializer(TIntermTyped*& node)
node = intermediate.growAggregate(node, expr, loc);
// COMMA
if (acceptTokenClass(EHTokComma))
if (acceptTokenClass(EHTokComma)) {
if (acceptTokenClass(EHTokRightBrace)) // allow trailing comma
return true;
continue;
}
// RIGHT_BRACE
if (acceptTokenClass(EHTokRightBrace))

View File

@@ -3727,7 +3727,12 @@ TIntermTyped* HlslParseContext::convertInitializerList(const TSourceLoc& loc, co
error(loc, "wrong vector size (or rows in a matrix column):", "initializer list", type.getCompleteString().c_str());
return nullptr;
}
} else {
} else if (type.isScalar()) {
if ((int)initList->getSequence().size() != 1) {
error(loc, "scalar expected one element:", "initializer list", type.getCompleteString().c_str());
return nullptr;
}
} else {
error(loc, "unexpected initializer-list type:", "initializer list", type.getCompleteString().c_str());
return nullptr;
}