HLSL: Add string basic type and recognize string declaration grammar.
authorJohn Kessenich <cepheus@frii.com>
Tue, 20 Sep 2016 02:23:18 +0000 (20:23 -0600)
committerJohn Kessenich <cepheus@frii.com>
Tue, 20 Sep 2016 02:29:45 +0000 (20:29 -0600)
This includes the "< decl ; decl ; >" syntax which has its own namespace.
This functionality is not implemented, just silently accepted.

Test/baseResults/hlsl.string.frag.out [new file with mode: 0755]
Test/hlsl.string.frag [new file with mode: 0755]
glslang/Include/BaseTypes.h
glslang/Include/revision.h
gtests/Hlsl.FromFile.cpp
hlsl/hlslGrammar.cpp
hlsl/hlslGrammar.h
hlsl/hlslParseHelper.cpp
hlsl/hlslScanContext.cpp
hlsl/hlslTokens.h

diff --git a/Test/baseResults/hlsl.string.frag.out b/Test/baseResults/hlsl.string.frag.out
new file mode 100755 (executable)
index 0000000..6016f52
--- /dev/null
@@ -0,0 +1,64 @@
+hlsl.string.frag
+Shader version: 450
+gl_FragCoord origin is upper left
+0:? Sequence
+0:10  Function Definition: main(f1; (global float)
+0:10    Function Parameters: 
+0:10      'f' (layout(location=0 ) in float)
+0:?     Sequence
+0:11      Sequence
+0:11        move second child to first child (temp float)
+0:?           '@entryPointOutput' (layout(location=0 ) out float)
+0:11          'f' (layout(location=0 ) in float)
+0:11        Branch: Return
+0:?   Linker Objects
+0:?     '@entryPointOutput' (layout(location=0 ) out float)
+0:?     'f' (layout(location=0 ) in float)
+
+
+Linked fragment stage:
+
+
+Shader version: 450
+gl_FragCoord origin is upper left
+0:? Sequence
+0:10  Function Definition: main(f1; (global float)
+0:10    Function Parameters: 
+0:10      'f' (layout(location=0 ) in float)
+0:?     Sequence
+0:11      Sequence
+0:11        move second child to first child (temp float)
+0:?           '@entryPointOutput' (layout(location=0 ) out float)
+0:11          'f' (layout(location=0 ) in float)
+0:11        Branch: Return
+0:?   Linker Objects
+0:?     '@entryPointOutput' (layout(location=0 ) out float)
+0:?     'f' (layout(location=0 ) in float)
+
+// Module Version 10000
+// Generated by (magic number): 80001
+// Id's are bound by 13
+
+                              Capability Shader
+               1:             ExtInstImport  "GLSL.std.450"
+                              MemoryModel Logical GLSL450
+                              EntryPoint Fragment 4  "main" 8 10
+                              ExecutionMode 4 OriginUpperLeft
+                              Name 4  "main"
+                              Name 8  "@entryPointOutput"
+                              Name 10  "f"
+                              Decorate 8(@entryPointOutput) Location 0
+                              Decorate 10(f) Location 0
+               2:             TypeVoid
+               3:             TypeFunction 2
+               6:             TypeFloat 32
+               7:             TypePointer Output 6(float)
+8(@entryPointOutput):      7(ptr) Variable Output
+               9:             TypePointer Input 6(float)
+           10(f):      9(ptr) Variable Input
+         4(main):           2 Function None 3
+               5:             Label
+              11:    6(float) Load 10(f)
+                              Store 8(@entryPointOutput) 11
+                              Return
+                              FunctionEnd
diff --git a/Test/hlsl.string.frag b/Test/hlsl.string.frag
new file mode 100755 (executable)
index 0000000..09885ff
--- /dev/null
@@ -0,0 +1,12 @@
+string s = "string1";
+string e = "";
+string bracket < string a = "nested" ; > ; 
+string brackets < string b = "nest1" ; string c = "nest2" ; string d = "nest3" ; > ;
+string brackete1 <  > ;
+string brackete2 < ; > ;
+string brackete3 < ; ; > ;
+
+float main(float f)
+{
+    return f;
+}
\ No newline at end of file
index bc8f110..64ef80c 100644 (file)
@@ -55,6 +55,10 @@ enum TBasicType {
     EbtSampler,
     EbtStruct,
     EbtBlock,
+
+    // HLSL types that live only temporarily.
+    EbtString,
+
     EbtNumTypes
 };
 
index a496025..bf8f228 100644 (file)
@@ -2,5 +2,5 @@
 // For the version, it uses the latest git tag followed by the number of commits.
 // For the date, it uses the current date (when then script is run).
 
-#define GLSLANG_REVISION "Overload400-PrecQual.1499"
+#define GLSLANG_REVISION "Overload400-PrecQual.1501"
 #define GLSLANG_DATE "19-Sep-2016"
index 06660c7..01cc032 100644 (file)
@@ -160,6 +160,7 @@ INSTANTIATE_TEST_CASE_P(
         {"hlsl.semicolons.frag", "main"},
         {"hlsl.shapeConv.frag", "main"},
         {"hlsl.stringtoken.frag", "main"},
+        {"hlsl.string.frag", "main"},
         {"hlsl.structin.vert", "main"},
         {"hlsl.intrinsics.vert", "VertexShaderFunction"},
         {"hlsl.matType.frag", "PixelShaderFunction"},
index cc7e901..0762514 100755 (executable)
@@ -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;
index 4e93f09..f5c7d4d 100755 (executable)
@@ -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&);
index 4e43bff..e506e29 100755 (executable)
@@ -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()) {
index 29a2255..edeee64 100755 (executable)
@@ -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
index db3b097..9e23cc7 100755 (executable)
@@ -70,6 +70,7 @@ enum EHlslTokenClass {
     EHTokBuffer,
     EHTokVector,
     EHTokMatrix,
+    EHTokString,
 
     // scalar types
     EHTokVoid,