HLSL: allow keyword-identifiers as cbuffer/struct names.

Issue #791 was partially fixed by PR #1161 (the mat mul implicit
truncations were its main point), but it still wouldn't compile due to
the use of ConstantBuffer as an identifier.  Apparently those fall into
the same class as "float float", where float is both a type and an
identifier.

This allows struct definitions with such keyword-identifiers,
and adds ConstantBuffer to the set.  'cbuffer int' is legal in HLSL,
and 'struct int' appears to only be rejected due to the redefinition
of the 'int' type.

Fixes #791
This commit is contained in:
LoopDawg
2017-11-27 14:45:36 -07:00
parent 792a94809b
commit 7ee29ba730
4 changed files with 460 additions and 3 deletions

View File

@@ -2029,10 +2029,18 @@ bool HlslGrammar::acceptStruct(TType& type, TIntermNode*& nodeList)
// Now known to be one of CBUFFER, TBUFFER, CLASS, or STRUCT
// IDENTIFIER
// IDENTIFIER. It might also be a keyword which can double as an identifier.
// For example: 'cbuffer ConstantBuffer' or 'struct ConstantBuffer' is legal.
// 'cbuffer int' is also legal, and 'struct int' appears rejected only because
// it attempts to redefine the 'int' type.
const char* idString = getTypeString(peek());
TString structName = "";
if (peekTokenClass(EHTokIdentifier)) {
structName = *token.string;
if (peekTokenClass(EHTokIdentifier) || idString != nullptr) {
if (idString != nullptr)
structName = *idString;
else
structName = *token.string;
advanceToken();
}
@@ -4056,6 +4064,7 @@ const char* HlslGrammar::getTypeString(EHlslTokenClass tokenClass) const
case EHTokMin10float: return "min10float";
case EHTokMin16int: return "min16int";
case EHTokMin12int: return "min12int";
case EHTokConstantBuffer: return "ConstantBuffer";
default:
return nullptr;
}