HLSL: Add string basic type and recognize string declaration grammar.

This includes the "< decl ; decl ; >" syntax which has its own namespace.
This functionality is not implemented, just silently accepted.
This commit is contained in:
John Kessenich
2016-09-19 20:23:18 -06:00
parent eee9d536bc
commit 86f7138706
10 changed files with 146 additions and 1 deletions

View File

@@ -721,6 +721,54 @@ bool HlslGrammar::acceptMatrixTemplateType(TType& type)
return true;
}
// string_template_type
// : STRING
// | STRING identifier LEFT_ANGLE declaration SEMI_COLON ... declaration SEMICOLON RIGHT_ANGLE
//
bool HlslGrammar::acceptStringTemplateType(TType& type)
{
// STRING
if (! acceptTokenClass(EHTokString))
return false;
// no matter what happens next, we recognized a string type
new(&type) TType(EbtString);
// identifier LEFT_ANGLE, or not?
if (! acceptTokenClass(EHTokIdentifier)) {
expected("identifier following 'string'");
return false;
}
if (! peekTokenClass(EHTokLeftAngle)) {
// then it must be the non-template version, back up and let
// normal declaration code handle it
// recede the identifier
recedeToken();
return true;
}
// move past the LEFT_ANGLE
advanceToken();
// declaration SEMI_COLON ... declaration SEMICOLON RIGHT_ANGLE
do {
// eat any extra SEMI_COLON; don't know if the grammar calls for this or not
while (acceptTokenClass(EHTokSemicolon))
;
if (acceptTokenClass(EHTokRightAngle))
return true;
// declaration
TIntermNode* node;
if (! acceptDeclaration(node)) {
expected("declaration in string list");
return false;
}
} while (true);
}
// sampler_type
// : SAMPLER
@@ -894,6 +942,10 @@ bool HlslGrammar::acceptType(TType& type)
return acceptMatrixTemplateType(type);
break;
case EHTokString:
return acceptStringTemplateType(type);
break;
case EHTokSampler: // fall through
case EHTokSampler1d: // ...
case EHTokSampler2d: // ...
@@ -2062,6 +2114,9 @@ bool HlslGrammar::acceptLiteral(TIntermTyped*& node)
case EHTokBoolConstant:
node = intermediate.addConstantUnion(token.b, token.loc, true);
break;
case EHTokStringConstant:
node = nullptr;
break;
default:
return false;

View File

@@ -73,6 +73,7 @@ namespace glslang {
bool acceptTemplateType(TBasicType&);
bool acceptVectorTemplateType(TType&);
bool acceptMatrixTemplateType(TType&);
bool acceptStringTemplateType(TType&);
bool acceptSamplerType(TType&);
bool acceptTextureType(TType&);
bool acceptStruct(TType&);

View File

@@ -4052,6 +4052,11 @@ void HlslParseContext::declareTypedef(const TSourceLoc& loc, TString& identifier
//
TIntermNode* HlslParseContext::declareVariable(const TSourceLoc& loc, TString& identifier, const TType& parseType, TArraySizes* arraySizes, TIntermTyped* initializer)
{
// string identifiers can nest inside < ... >, apparently with their own namespace,
// which is not implemented
if (parseType.getBasicType() == EbtString)
return nullptr;
TType type;
type.shallowCopy(parseType);
if (type.isImplicitlySizedArray()) {

View File

@@ -122,6 +122,7 @@ void HlslScanContext::fillInKeywordMap()
(*KeywordMap)["Buffer"] = EHTokBuffer;
(*KeywordMap)["vector"] = EHTokVector;
(*KeywordMap)["matrix"] = EHTokMatrix;
(*KeywordMap)["string"] = EHTokString;
(*KeywordMap)["void"] = EHTokVoid;
(*KeywordMap)["bool"] = EHTokBool;
@@ -471,6 +472,7 @@ EHlslTokenClass HlslScanContext::tokenizeIdentifier()
case EHTokBuffer:
case EHTokVector:
case EHTokMatrix:
case EHTokString:
return keyword;
// scalar types

View File

@@ -70,6 +70,7 @@ enum EHlslTokenClass {
EHTokBuffer,
EHTokVector,
EHTokMatrix,
EHTokString,
// scalar types
EHTokVoid,