From f78fff94e905bd571491881a5909dc08a3e6e5a2 Mon Sep 17 00:00:00 2001
From: John Kessenich <cepheus@frii.com>
Date: Thu, 13 Jun 2013 23:56:04 +0000
Subject: [PATCH] Implement __VERSION__ macro, make ftransform() non-ES only,
 add more tests.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@22000 e7fa87d3-cd2b-0410-9028-fcbf551c1848
---
 Test/300operations.frag                             | 3 +++
 Test/cppSimple.vert                                 | 4 ++++
 glslang/MachineIndependent/Initialize.cpp           | 3 ++-
 glslang/MachineIndependent/glslang.l                | 7 +++++++
 glslang/MachineIndependent/preprocessor/cpp.c       | 4 ++--
 glslang/MachineIndependent/preprocessor/cpp.h       | 1 +
 glslang/MachineIndependent/preprocessor/slglobals.h | 2 +-
 7 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/Test/300operations.frag b/Test/300operations.frag
index 9657c5926..3e7782c0e 100644
--- a/Test/300operations.frag
+++ b/Test/300operations.frag
@@ -79,6 +79,7 @@ void main()
     f >> i;
     m4 >> i;
     a >> u;
+    iv3 >> iv4;
 
     i & u;
     u ^ uv3;
@@ -86,6 +87,7 @@ void main()
     u & f;
     m2 | m2;
     s ^ s;
+    (f = f) = f;
 
     // These are all okay:
     f * v4;
@@ -118,6 +120,7 @@ void main()
     uv3 <<= i;
     i >> i;
     u << u;
+    iv3 >> iv3;
 
     i & i;
     u | u;
diff --git a/Test/cppSimple.vert b/Test/cppSimple.vert
index 4cfa4f4eb..2b48c0190 100644
--- a/Test/cppSimple.vert
+++ b/Test/cppSimple.vert
@@ -121,5 +121,9 @@ sum += 0.05;
 #error bad6
 #endif
 
+int linenumber = __LINE__;
+int filenumber = __FILE__;
+int version = __VERSION__;
+
 #define PASTE(a,b) a ## b
 float PASTE(tod, ay) = 17;
diff --git a/glslang/MachineIndependent/Initialize.cpp b/glslang/MachineIndependent/Initialize.cpp
index 77f3ff17c..8b7e3fc00 100644
--- a/glslang/MachineIndependent/Initialize.cpp
+++ b/glslang/MachineIndependent/Initialize.cpp
@@ -630,7 +630,8 @@ void TBuiltIns::initialize(int version, EProfile profile)
         //
         // Geometric Functions.
         //
-        s.append(TString("vec4 ftransform();"));
+        if (profile != EEsProfile)
+            s.append(TString("vec4 ftransform();"));
 
         //
         // Original-style texture Functions with lod.
diff --git a/glslang/MachineIndependent/glslang.l b/glslang/MachineIndependent/glslang.l
index 60a2dbad5..8160ae8de 100644
--- a/glslang/MachineIndependent/glslang.l
+++ b/glslang/MachineIndependent/glslang.l
@@ -1128,6 +1128,13 @@ void SetVersion(int version)
     // CPP should still report errors in semantics
 }
 
+int GetVersion(void* cppPc)
+{
+    TParseContext& pc = *((TParseContext *)cppPc);
+
+    return pc.version;
+}
+
 void SetProfile(EProfile profile)
 {
     // called by the CPP, but this functionality is currently
diff --git a/glslang/MachineIndependent/preprocessor/cpp.c b/glslang/MachineIndependent/preprocessor/cpp.c
index efa77bc3a..77416511b 100644
--- a/glslang/MachineIndependent/preprocessor/cpp.c
+++ b/glslang/MachineIndependent/preprocessor/cpp.c
@@ -1027,8 +1027,8 @@ int MacroExpand(int atom, yystypepp* yylvalpp, int expandUndef)
     }
 
 	if (atom == __VERSION__Atom) {
-        strcpy(yylvalpp->symbol_name, "100");
-        yylvalpp->sc_int = atoi(yylvalpp->symbol_name);
+        yylvalpp->sc_int = GetVersion(cpp->pC);
+        sprintf(yylvalpp->symbol_name, "%d", yylvalpp->sc_int);
         UngetToken(CPP_INTCONSTANT, yylvalpp);
 
         return 1;
diff --git a/glslang/MachineIndependent/preprocessor/cpp.h b/glslang/MachineIndependent/preprocessor/cpp.h
index aa8b68582..cdedb62c1 100644
--- a/glslang/MachineIndependent/preprocessor/cpp.h
+++ b/glslang/MachineIndependent/preprocessor/cpp.h
@@ -117,6 +117,7 @@ int   GetStringNumber(void);                // Get the current String Number.
 const char* GetStrfromTStr(void);           // Convert TString to String.  
 void  SetVersion(int);
 void  SetProfile(EProfile);
+int   GetVersion(void*);
 void  updateExtensionBehavior(const char* extName, const char* behavior);
 int   FreeCPP(void);
 
diff --git a/glslang/MachineIndependent/preprocessor/slglobals.h b/glslang/MachineIndependent/preprocessor/slglobals.h
index 88c63773a..3af23862b 100644
--- a/glslang/MachineIndependent/preprocessor/slglobals.h
+++ b/glslang/MachineIndependent/preprocessor/slglobals.h
@@ -83,7 +83,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 typedef struct CPPStruct_Rec CPPStruct;
 
-// Multi-threading note: The existence of this global makes
+// TODO: threading: Multi-threading note: The existence of this global makes
 // this preprocessing single-threaded only.
 extern CPPStruct *cpp;
 
-- 
GitLab