Semantic checks: ES doesn't have unsized arrays or noise*().
authorJohn Kessenich <cepheus@frii.com>
Thu, 13 Jun 2013 20:16:43 +0000 (20:16 +0000)
committerJohn Kessenich <cepheus@frii.com>
Thu, 13 Jun 2013 20:16:43 +0000 (20:16 +0000)
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@21998 e7fa87d3-cd2b-0410-9028-fcbf551c1848

Test/300.vert
Test/300BuiltIns.frag
Test/array100.frag
Test/cppSimple.vert
glslang/MachineIndependent/Initialize.cpp
glslang/MachineIndependent/ParseHelper.cpp
glslang/MachineIndependent/ParseHelper.h
glslang/MachineIndependent/glslang.y

index 96c74b44379ff47d81543077e69986e0d9e71262..19f62d4a123d558d72f9dd195801a0610ba0d474 100644 (file)
@@ -40,3 +40,11 @@ void main()
 #error GL_ES is not set
 #endif
 }
+
+float badsize[];    // ERROR
+float[] badsize2;   // ERROR
+uniform ub {
+    int a[];        // ERROR
+} ubInst[];         // ERROR
+void foo(int a[]);  // ERROR
+float okayA[] = float[](3.0, 4.0);  // Okay
index 0c0844434f3a1a037ecb90fe9f8c7992afa988c5..07cb7186af33197150d555fefe134f12ea92c7ba 100644 (file)
@@ -65,4 +65,7 @@ void main()
     vec2 v16 = unpackUnorm2x16(uy);
     uint u17 = packHalf2x16(v2b);
     vec2 v18 = unpackHalf2x16(uy);
+
+    // not present
+    noise2(v18);
 }
index 87c125b7d31ab961d7a1f57f267838c25cd3ae98..6f0feb420084c9a94db554ba7ce2da399290cace 100644 (file)
@@ -1,6 +1,6 @@
 #version 100
 
-float gu[];
+float gu[];              // ERROR
 float g4[4];
 float g5[5];
 
@@ -21,11 +21,6 @@ void main()
         gu[2] = 4.0;  // ERROR, overflow
     }
 
-    gu[2] = 4.0; // okay
-
-    gu[3] = 3.0;
-    gu[a] = 5.0; // ERROR
-
     g4 = foo(g5);
     g5 = g4;  // ERROR
     gu = g4;  // ERROR
@@ -36,8 +31,6 @@ void main()
     if (float[4](1.0, 2.0, 3.0, 4.0) == g4)  // ERROR
         gu[0] = 2.0;
 
-    float u[];
-    u[2] = 3.0; // okay
     float u[5];
     u[5] = 5.0; // ERROR
     foo(u);     // okay
index 2dd9c35672a5c1223484a5f1996ae3c4a79669c5..4cfa4f4ebd2e1db191fc6a59776f38035d35627d 100644 (file)
@@ -120,3 +120,6 @@ sum += 0.05;
 #if ((AA == BB || (AA == CC))))
 #error bad6
 #endif
+
+#define PASTE(a,b) a ## b
+float PASTE(tod, ay) = 17;
index 4e278e67fbcdf6f3e764c9f161bcca9dd1593289..77f3ff17c1e9f759d483305c00e4fa673875b125 100644 (file)
@@ -594,27 +594,29 @@ void TBuiltIns::initialize(int version, EProfile profile)
         //
         // Noise functions.
         //
-        s.append(TString("float noise1(float x);"));
-        s.append(TString("float noise1(vec2  x);"));
-        s.append(TString("float noise1(vec3  x);"));
-        s.append(TString("float noise1(vec4  x);"));
-
-        s.append(TString("vec2 noise2(float x);"));
-        s.append(TString("vec2 noise2(vec2  x);"));
-        s.append(TString("vec2 noise2(vec3  x);"));
-        s.append(TString("vec2 noise2(vec4  x);"));
-
-        s.append(TString("vec3 noise3(float x);"));
-        s.append(TString("vec3 noise3(vec2  x);"));
-        s.append(TString("vec3 noise3(vec3  x);"));
-        s.append(TString("vec3 noise3(vec4  x);"));
-
-        s.append(TString("vec4 noise4(float x);"));
-        s.append(TString("vec4 noise4(vec2  x);"));
-        s.append(TString("vec4 noise4(vec3  x);"));
-        s.append(TString("vec4 noise4(vec4  x);"));
+        if (profile != EEsProfile) {
+            s.append(TString("float noise1(float x);"));
+            s.append(TString("float noise1(vec2  x);"));
+            s.append(TString("float noise1(vec3  x);"));
+            s.append(TString("float noise1(vec4  x);"));
+
+            s.append(TString("vec2 noise2(float x);"));
+            s.append(TString("vec2 noise2(vec2  x);"));
+            s.append(TString("vec2 noise2(vec3  x);"));
+            s.append(TString("vec2 noise2(vec4  x);"));
+
+            s.append(TString("vec3 noise3(float x);"));
+            s.append(TString("vec3 noise3(vec2  x);"));
+            s.append(TString("vec3 noise3(vec3  x);"));
+            s.append(TString("vec3 noise3(vec4  x);"));
+
+            s.append(TString("vec4 noise4(float x);"));
+            s.append(TString("vec4 noise4(vec2  x);"));
+            s.append(TString("vec4 noise4(vec3  x);"));
+            s.append(TString("vec4 noise4(vec4  x);"));
 
-        s.append(TString("\n"));
+            s.append(TString("\n"));
+        }
     }
     {
         //============================================================================
index 01f3a9f264a1b4928b78d630237564a3cce72996..a2b89070cecc998759e87b6882f50400ecb749e4 100644 (file)
@@ -486,9 +486,9 @@ bool TParseContext::reservedErrorCheck(int line, const TString& identifier)
 //
 // Returns true if there was an error in construction.
 //
-bool TParseContext::constructorError(int line, TIntermNode* node, TFunction& function, TOperator op, TType* type)
+bool TParseContext::constructorError(int line, TIntermNode* node, TFunction& function, TOperator op, TType& type)
 {
-    *type = function.getReturnType();
+    type = function.getReturnType();
 
     bool constructingMatrix = false;
     switch(op) {
@@ -535,7 +535,7 @@ bool TParseContext::constructorError(int line, TIntermNode* node, TFunction& fun
             matrixInMatrix = true;
         if (full)
             overFull = true;
-        if (op != EOpConstructStruct && !type->isArray() && size >= type->getObjectSize())
+        if (op != EOpConstructStruct && ! type.isArray() && size >= type.getObjectSize())
             full = true;
         if (function[i].type->getQualifier().storage != EvqConst)
             constType = false;
@@ -544,13 +544,13 @@ bool TParseContext::constructorError(int line, TIntermNode* node, TFunction& fun
     }
     
     if (constType)
-        type->getQualifier().storage = EvqConst;
+        type.getQualifier().storage = EvqConst;
 
-    if (type->isArray()) {
-        if (type->getArraySize() == 0) {
+    if (type.isArray()) {
+        if (type.getArraySize() == 0) {
             // auto adapt the constructor type to the number of arguments
-            type->changeArraySize(function.getParamCount());
-        } else if (type->getArraySize() != function.getParamCount()) {
+            type.changeArraySize(function.getParamCount());
+        } else if (type.getArraySize() != function.getParamCount()) {
             error(line, "array constructor needs one argument per array element", "constructor", "");
             return true;
         }
@@ -561,7 +561,7 @@ bool TParseContext::constructorError(int line, TIntermNode* node, TFunction& fun
         return true;
     }
 
-    if (matrixInMatrix && !type->isArray()) {
+    if (matrixInMatrix && ! type.isArray()) {
         profileRequires(line, ENoProfile, 120, 0, "constructing matrix from matrix");
         return false;
     }
@@ -571,13 +571,13 @@ bool TParseContext::constructorError(int line, TIntermNode* node, TFunction& fun
         return true;
     }
     
-    if (op == EOpConstructStruct && !type->isArray() && type->getStruct()->size() != function.getParamCount()) {
+    if (op == EOpConstructStruct && ! type.isArray() && type.getStruct()->size() != function.getParamCount()) {
         error(line, "Number of constructor parameters does not match the number of structure fields", "constructor", "");
         return true;
     }
 
-    if ((op != EOpConstructStruct && size != 1 && size < type->getObjectSize()) ||
-        (op == EOpConstructStruct && size < type->getObjectSize())) {
+    if ((op != EOpConstructStruct && size != 1 && size < type.getObjectSize()) ||
+        (op == EOpConstructStruct && size < type.getObjectSize())) {
         error(line, "not enough data provided for construction", "constructor", "");
         return true;
     }
@@ -1473,6 +1473,9 @@ void TParseContext::addBlock(int line, TTypeList& typeList, const TString* insta
     if (instanceName && reservedErrorCheck(line, *instanceName))
         return;
 
+    if (profile == EEsProfile && arraySizes)
+        arraySizeRequiredCheck(line, arraySizes->front());        
+
     if (blockType.basicType != EbtVoid) {
         error(line, "interface blocks cannot be declared with a type", blockName->c_str(), "");
 
index e776a4adf14961ad6cc488033977f43b66a21a0f..70ba6a0d7a1312d4715f6741696d0b868ae462db 100644 (file)
@@ -114,7 +114,7 @@ struct TParseContext {
     void constCheck(TIntermTyped* node);
     void integerCheck(TIntermTyped* node, const char* token);
     void globalCheck(int line, bool global, const char* token);
-    bool constructorError(int line, TIntermNode*, TFunction&, TOperator, TType*);
+    bool constructorError(int line, TIntermNode*, TFunction&, TOperator, TType&);
     void arraySizeCheck(int line, TIntermTyped* expr, int& size);
     bool arrayQualifierError(int line, const TPublicType&);
     void arraySizeRequiredCheck(int line, int& size);
index 0dc84055ff15302d5219ccf9f55e344046d9e6bb..7efbbbfa993362faf310c1839127f1cce7ea0456 100644 (file)
@@ -464,7 +464,7 @@ function_call
             // Their parameters will be verified algorithmically.\r
             //\r
             TType type(EbtVoid);  // use this to get the type back\r
-            if (parseContext.constructorError($1.line, $1.intermNode, *fnCall, op, &type)) {\r
+            if (parseContext.constructorError($1.line, $1.intermNode, *fnCall, op, type)) {\r
                 $$ = 0;\r
             } else {\r
                 //\r
@@ -1120,11 +1120,13 @@ declaration
         $$ = 0;\r
     }\r
     | type_qualifier IDENTIFIER SEMICOLON {\r
+        // TODO: functionality: track what variables are declared with INVARIANT\r
         // precise foo;\r
         // invariant foo;\r
         $$ = 0;\r
     }\r
     | type_qualifier IDENTIFIER identifier_list SEMICOLON {\r
+        // TODO: functionality: track what variables are declared with INVARIANT\r
         // precise foo, bar;\r
         // invariant foo, bar;\r
         $$ = 0;\r
@@ -1250,6 +1252,7 @@ parameter_declarator
         if ($1.arraySizes) {\r
             parseContext.profileRequires($1.line, ENoProfile, 120, "GL_3DL_array_objects", "arrayed type");\r
             parseContext.profileRequires($1.line, EEsProfile, 300, 0, "arrayed type");\r
+            parseContext.arraySizeRequiredCheck($1.line, $1.arraySizes->front());\r
         }\r
         if ($1.basicType == EbtVoid) {\r
             parseContext.error($2.line, "illegal use of type 'void'", $2.string->c_str(), "");\r
@@ -1264,6 +1267,7 @@ parameter_declarator
         if ($1.arraySizes) {\r
             parseContext.profileRequires($1.line, ENoProfile, 120, "GL_3DL_array_objects", "arrayed type");\r
             parseContext.profileRequires($1.line, EEsProfile, 300, 0, "arrayed type");\r
+            parseContext.arraySizeRequiredCheck($1.line, $1.arraySizes->front());\r
         }\r
 \r
         parseContext.arraySizeRequiredCheck($3.line, $3.arraySizes->front());\r
@@ -1332,7 +1336,9 @@ init_declarator_list
     }\r
     | init_declarator_list COMMA IDENTIFIER array_specifier {\r
         parseContext.nonInitConstCheck($3.line, *$3.string, $1.type);\r
-\r
+        if (parseContext.profile == EEsProfile)\r
+            parseContext.arraySizeRequiredCheck($4.line, $4.arraySizes->front());\r
+        \r
         $$ = $1;\r
 \r
         if (! parseContext.arrayQualifierError($4.line, $1.type)) {\r
@@ -1398,7 +1404,9 @@ single_declaration
     }\r
     | fully_specified_type IDENTIFIER array_specifier {\r
         $$.intermAggregate = 0;\r
-        parseContext.nonInitConstCheck($2.line, *$2.string, $1);\r
+        parseContext.nonInitConstCheck($2.line, *$2.string, $1);        \r
+        if (parseContext.profile == EEsProfile)\r
+            parseContext.arraySizeRequiredCheck($3.line, $3.arraySizes->front());\r
 \r
         $$.type = $1;\r
 \r
@@ -1458,6 +1466,8 @@ fully_specified_type
         if ($1.arraySizes) {\r
             parseContext.profileRequires($1.line, ENoProfile, 120, "GL_3DL_array_objects", "arrayed type");\r
             parseContext.profileRequires($1.line, EEsProfile, 300, 0, "arrayed type");\r
+            if (parseContext.profile == EEsProfile)\r
+                parseContext.arraySizeRequiredCheck($1.line, $1.arraySizes->front());\r
         }\r
     }\r
     | type_qualifier type_specifier  {\r
@@ -1466,6 +1476,8 @@ fully_specified_type
         if ($2.arraySizes) {\r
             parseContext.profileRequires($2.line, ENoProfile, 120, "GL_3DL_array_objects", "arrayed type");\r
             parseContext.profileRequires($2.line, EEsProfile, 300, 0, "arrayed type");\r
+            if (parseContext.profile == EEsProfile)\r
+                parseContext.arraySizeRequiredCheck($2.line, $2.arraySizes->front());\r
         }\r
 \r
         if ($2.arraySizes && parseContext.arrayQualifierError($2.line, $1))\r
@@ -1714,7 +1726,7 @@ type_specifier
         $$ = $1;\r
         $$.qualifier.precision = parseContext.defaultPrecision[$$.basicType];\r
     }\r
-    | type_specifier_nonarray array_specifier {\r
+    | type_specifier_nonarray array_specifier {        \r
         $$ = $1;\r
         $$.qualifier.precision = parseContext.defaultPrecision[$$.basicType];\r
         $$.arraySizes = $2.arraySizes;\r
@@ -2447,6 +2459,8 @@ struct_declaration
         if ($1.arraySizes) {\r
             parseContext.profileRequires($1.line, ENoProfile, 120, "GL_3DL_array_objects", "arrayed type");\r
             parseContext.profileRequires($1.line, EEsProfile, 300, 0, "arrayed type");\r
+            if (parseContext.profile == EEsProfile)\r
+                parseContext.arraySizeRequiredCheck($1.line, $1.arraySizes->front());\r
         }\r
 \r
         $$ = $2;\r
@@ -2460,6 +2474,8 @@ struct_declaration
         if ($2.arraySizes) {\r
             parseContext.profileRequires($2.line, ENoProfile, 120, "GL_3DL_array_objects", "arrayed type");\r
             parseContext.profileRequires($2.line, EEsProfile, 300, 0, "arrayed type");\r
+            if (parseContext.profile == EEsProfile)\r
+                parseContext.arraySizeRequiredCheck($2.line, $2.arraySizes->front());\r
         }\r
 \r
         $$ = $3;\r
@@ -2488,7 +2504,9 @@ struct_declarator
         $$.line = $1.line;\r
         $$.type->setFieldName(*$1.string);\r
     }\r
-    | IDENTIFIER array_specifier {\r
+    | IDENTIFIER array_specifier {        \r
+        if (parseContext.profile == EEsProfile)\r
+            parseContext.arraySizeRequiredCheck($2.line, $2.arraySizes->front());\r
         $$.type = new TType(EbtVoid);\r
         $$.line = $1.line;\r
         $$.type->setFieldName(*$1.string);\r