HLSL: Recognize types declared as identifiers as identifiers.
E.g., in
float float;
(float) * float;
The "(float)" is not a type cast, it is an expression.
This commit is contained in:
@@ -107,42 +107,14 @@ bool HlslGrammar::acceptIdentifier(HlslToken& idToken)
|
||||
// valid identifier, nor is "linear". This code special cases the known instances of this, so
|
||||
// e.g, "int sample;" or "float float;" is accepted. Other cases can be added here if needed.
|
||||
|
||||
TString* idString = nullptr;
|
||||
switch (peek()) {
|
||||
case EHTokSample: idString = NewPoolTString("sample"); break;
|
||||
case EHTokHalf: idString = NewPoolTString("half"); break;
|
||||
case EHTokHalf1x1: idString = NewPoolTString("half1x1"); break;
|
||||
case EHTokHalf1x2: idString = NewPoolTString("half1x2"); break;
|
||||
case EHTokHalf1x3: idString = NewPoolTString("half1x3"); break;
|
||||
case EHTokHalf1x4: idString = NewPoolTString("half1x4"); break;
|
||||
case EHTokHalf2x1: idString = NewPoolTString("half2x1"); break;
|
||||
case EHTokHalf2x2: idString = NewPoolTString("half2x2"); break;
|
||||
case EHTokHalf2x3: idString = NewPoolTString("half2x3"); break;
|
||||
case EHTokHalf2x4: idString = NewPoolTString("half2x4"); break;
|
||||
case EHTokHalf3x1: idString = NewPoolTString("half3x1"); break;
|
||||
case EHTokHalf3x2: idString = NewPoolTString("half3x2"); break;
|
||||
case EHTokHalf3x3: idString = NewPoolTString("half3x3"); break;
|
||||
case EHTokHalf3x4: idString = NewPoolTString("half3x4"); break;
|
||||
case EHTokHalf4x1: idString = NewPoolTString("half4x1"); break;
|
||||
case EHTokHalf4x2: idString = NewPoolTString("half4x2"); break;
|
||||
case EHTokHalf4x3: idString = NewPoolTString("half4x3"); break;
|
||||
case EHTokHalf4x4: idString = NewPoolTString("half4x4"); break;
|
||||
case EHTokBool: idString = NewPoolTString("bool"); break;
|
||||
case EHTokFloat: idString = NewPoolTString("float"); break;
|
||||
case EHTokDouble: idString = NewPoolTString("double"); break;
|
||||
case EHTokInt: idString = NewPoolTString("int"); break;
|
||||
case EHTokUint: idString = NewPoolTString("uint"); break;
|
||||
case EHTokMin16float: idString = NewPoolTString("min16float"); break;
|
||||
case EHTokMin10float: idString = NewPoolTString("min10float"); break;
|
||||
case EHTokMin16int: idString = NewPoolTString("min16int"); break;
|
||||
case EHTokMin12int: idString = NewPoolTString("min12int"); break;
|
||||
default:
|
||||
const char* idString = getTypeString(peek());
|
||||
if (idString == nullptr)
|
||||
return false;
|
||||
}
|
||||
|
||||
token.string = idString;
|
||||
token.string = NewPoolTString(idString);
|
||||
token.tokenClass = EHTokIdentifier;
|
||||
idToken = token;
|
||||
idToken = token;
|
||||
typeIdentifiers = true;
|
||||
|
||||
advanceToken();
|
||||
|
||||
@@ -1311,6 +1283,18 @@ bool HlslGrammar::acceptType(TType& type, TIntermNode*& nodeList)
|
||||
static const TBasicType min12int_bt = EbtInt;
|
||||
static const TBasicType min16uint_bt = EbtUint;
|
||||
|
||||
// Some types might have turned into identifiers. Take the hit for checking
|
||||
// when this has happened.
|
||||
if (typeIdentifiers) {
|
||||
const char* identifierString = getTypeString(peek());
|
||||
if (identifierString != nullptr) {
|
||||
TString name = identifierString;
|
||||
// if it's an identifier, it's not a type
|
||||
if (parseContext.symbolTable.find(name) != nullptr)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
switch (peek()) {
|
||||
case EHTokVector:
|
||||
return acceptVectorTemplateType(type);
|
||||
@@ -3840,4 +3824,40 @@ bool HlslGrammar::captureBlockTokens(TVector<HlslToken>& tokens)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Return a string for just the types that can also be declared as an identifier.
|
||||
const char* HlslGrammar::getTypeString(EHlslTokenClass tokenClass) const
|
||||
{
|
||||
switch (tokenClass) {
|
||||
case EHTokSample: return "sample";
|
||||
case EHTokHalf: return "half";
|
||||
case EHTokHalf1x1: return "half1x1";
|
||||
case EHTokHalf1x2: return "half1x2";
|
||||
case EHTokHalf1x3: return "half1x3";
|
||||
case EHTokHalf1x4: return "half1x4";
|
||||
case EHTokHalf2x1: return "half2x1";
|
||||
case EHTokHalf2x2: return "half2x2";
|
||||
case EHTokHalf2x3: return "half2x3";
|
||||
case EHTokHalf2x4: return "half2x4";
|
||||
case EHTokHalf3x1: return "half3x1";
|
||||
case EHTokHalf3x2: return "half3x2";
|
||||
case EHTokHalf3x3: return "half3x3";
|
||||
case EHTokHalf3x4: return "half3x4";
|
||||
case EHTokHalf4x1: return "half4x1";
|
||||
case EHTokHalf4x2: return "half4x2";
|
||||
case EHTokHalf4x3: return "half4x3";
|
||||
case EHTokHalf4x4: return "half4x4";
|
||||
case EHTokBool: return "bool";
|
||||
case EHTokFloat: return "float";
|
||||
case EHTokDouble: return "double";
|
||||
case EHTokInt: return "int";
|
||||
case EHTokUint: return "uint";
|
||||
case EHTokMin16float: return "min16float";
|
||||
case EHTokMin10float: return "min10float";
|
||||
case EHTokMin16int: return "min16int";
|
||||
case EHTokMin12int: return "min12int";
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
Reference in New Issue
Block a user