--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#ifndef _BASICTYPES_INCLUDED_\r
+#define _BASICTYPES_INCLUDED_\r
+\r
+//\r
+// Basic type. Arrays, vectors, etc., are orthogonal to this.\r
+//\r
+enum TBasicType {\r
+ EbtVoid,\r
+ EbtFloat,\r
+ EbtInt,\r
+ EbtBool,\r
+ EbtSampler1D,\r
+ EbtSampler2D,\r
+ EbtSampler3D,\r
+ EbtSamplerCube,\r
+ EbtSampler1DShadow,\r
+ EbtSampler2DShadow,\r
+ EbtStruct,\r
+ EbtAddress,\r
+};\r
+\r
+__inline bool IsSampler(TBasicType type)\r
+{ \r
+ return type >= EbtSampler1D && type <= EbtSampler2DShadow;\r
+}\r
+\r
+//\r
+// Qualifiers and built-ins. These are mainly used to see what can be read\r
+// or written, and by the machine dependent translator to know which registers\r
+// to allocate variables in. Since built-ins tend to go to different registers\r
+// than varying or uniform, it makes sense they are peers, not sub-classes.\r
+//\r
+enum TQualifier {\r
+ EvqTemporary, // For temporaries (within a function), read/write\r
+ EvqGlobal, // For globals read/write\r
+ EvqConst, // User defined constants and non-output parameters in functions\r
+ EvqAttribute, // Readonly \r
+ EvqVaryingIn, // readonly, fragment shaders only\r
+ EvqVaryingOut, // vertex shaders only read/write\r
+ EvqUniform, // Readonly, vertex and fragment\r
+\r
+ // pack/unpack input and output\r
+ EvqInput,\r
+ EvqOutput,\r
+\r
+ // parameters\r
+ EvqIn,\r
+ EvqOut,\r
+ EvqInOut,\r
+ EvqConstReadOnly,\r
+\r
+ // built-ins written by vertex shader\r
+ EvqPosition,\r
+ EvqPointSize,\r
+ EvqClipVertex,\r
+\r
+ // built-ins read by fragment shader\r
+ EvqFace,\r
+ EvqFragCoord,\r
+\r
+ // built-ins written by fragment shader\r
+ EvqFragColor,\r
+ EvqFragDepth,\r
+\r
+ // end of list\r
+ EvqLast,\r
+};\r
+\r
+//\r
+// This is just for debug print out, carried along with the definitions above.\r
+//\r
+__inline const char* getQualifierString(TQualifier q) \r
+{\r
+ switch (q) {\r
+ case EvqTemporary: return "Temporary"; break;\r
+ case EvqGlobal: return "Global"; break;\r
+ case EvqConst: return "const"; break;\r
+ case EvqConstReadOnly: return "const"; break;\r
+ case EvqAttribute: return "attribute"; break;\r
+ case EvqVaryingIn: return "varying"; break;\r
+ case EvqVaryingOut: return "varying"; break;\r
+ case EvqUniform: return "uniform"; break;\r
+ case EvqIn: return "in"; break;\r
+ case EvqOut: return "out"; break;\r
+ case EvqInOut: return "inout"; break;\r
+ case EvqInput: return "input"; break;\r
+ case EvqOutput: return "output"; break;\r
+ case EvqPosition: return "Position"; break;\r
+ case EvqPointSize: return "PointSize"; break;\r
+ case EvqClipVertex: return "ClipVertex"; break;\r
+ case EvqFace: return "Face"; break;\r
+ case EvqFragCoord: return "FragCoord"; break;\r
+ case EvqFragColor: return "FragColor"; break;\r
+ case EvqFragDepth: return "FragDepth"; break;\r
+ default: return "unknown qualifier";\r
+ }\r
+}\r
+\r
+#endif // _BASICTYPES_INCLUDED_\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#ifndef _COMMON_INCLUDED_\r
+#define _COMMON_INCLUDED_\r
+\r
+#ifdef _WIN32\r
+ #include <basetsd.h>\r
+#elif defined (solaris)\r
+ #include <sys/int_types.h>\r
+ #define UINT_PTR uintptr_t\r
+#else\r
+ #include <stdint.h>\r
+ #define UINT_PTR uintptr_t\r
+#endif\r
+\r
+#include <assert.h>\r
+\r
+/* windows only pragma */\r
+#ifdef _MSC_VER\r
+ #pragma warning(disable : 4786) // Don't warn about too long identifiers\r
+ #pragma warning(disable : 4514) // unused inline method\r
+ #pragma warning(disable : 4201) // nameless union\r
+#endif\r
+\r
+//\r
+// Doing the push and pop below for warnings does not leave the warning state\r
+// the way it was. This seems like a defect in the compiler. We would like\r
+// to do this, but since it does not work correctly right now, it is turned\r
+// off.\r
+//\r
+//??#pragma warning(push, 3)\r
+\r
+ #include <set>\r
+ #include <vector>\r
+ #include <map>\r
+ #include <list>\r
+ #include <string>\r
+ #include <stdio.h>\r
+\r
+//??#pragma warning(pop)\r
+\r
+typedef int TSourceLoc;\r
+\r
+#include "PoolAlloc.h"\r
+\r
+//\r
+// Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme.\r
+//\r
+#define POOL_ALLOCATOR_NEW_DELETE(A) \\r
+ void* operator new(size_t s) { return (A).allocate(s); } \\r
+ void* operator new(size_t, void *_Where) { return (_Where); } \\r
+ void operator delete(void*) { } \\r
+ void operator delete(void *, void *) { } \\r
+ void* operator new[](size_t s) { return (A).allocate(s); } \\r
+ void* operator new[](size_t, void *_Where) { return (_Where); } \\r
+ void operator delete[](void*) { } \\r
+ void operator delete[](void *, void *) { }\r
+\r
+#ifdef _M_AMD64\r
+//\r
+// The current version of STL that comes with the PSDK (as required for the AMD64 compiler)\r
+// has a very old version of the STL which is very out of date. As a result, various additions needed\r
+// making to it to get the compilers compiling!\r
+//\r
+\r
+//\r
+// A new version of the Map template class - the operator[] now returns the correct type reference\r
+//\r
+template <class _K, class _Ty, class _Pr = std::less<_K>, class _A = std::allocator<_Ty> >\r
+class TBaseMap : public std::map <_K, _Ty, _Pr, _A >\r
+{\r
+public :\r
+ _Ty& operator[] (const _K& _Kv)\r
+ {\r
+ iterator _P = insert(value_type(_Kv, _Ty())).first;\r
+ return ((*_P).second); \r
+ }\r
+ \r
+ explicit TBaseMap(const _Pr& _Pred = _Pr(), const _A& _Al = _A())\r
+ : std::map<_K, _Ty, _Pr, _A >(_Pred, _Al) {};\r
+\r
+\r
+};\r
+\r
+//\r
+// A new version of the List template class - the begin function now checks for NULL to eliminate access violations\r
+//\r
+template <class _Ty, class _A = std::allocator<_Ty> >\r
+class TBaseList : public std::list <_Ty, _A >\r
+{\r
+public :\r
+ iterator begin()\r
+ {\r
+ return (iterator(_Head == 0 ? 0 : _Acc::_Next(_Head))); \r
+ }\r
+ \r
+ const_iterator begin() const\r
+ {\r
+ return (const_iterator(_Head == 0 ? 0 : _Acc::_Next(_Head))); \r
+ }\r
+ \r
+ // \r
+ // These are required - apparently!\r
+ //\r
+ explicit TBaseList(const _A& _Al = _A()) \r
+ : std::list<_Ty, _A >(_Al) {};\r
+ explicit TBaseList(size_type _N, const _Ty& _V = _Ty(), const _A& _Al = _A())\r
+ : std::list<_Ty, _A >(N, _V, _Al) {};\r
+\r
+};\r
+\r
+//\r
+// A new version of the set class - this defines the required insert method\r
+//\r
+template<class _K, class _Pr = std::less<_K>, class _A = std::allocator<_K> >\r
+class TBaseSet : public std::set <_K, _Pr, _A>\r
+{\r
+public :\r
+\r
+ //\r
+ // This method wasn't defined\r
+ //\r
+ template<class _Iter>\r
+ void insert(_Iter _First, _Iter _Last)\r
+ { // insert [_First, _Last)\r
+ for (; _First != _Last; ++_First)\r
+ this->insert(*_First);\r
+ }\r
+ \r
+ // \r
+ // These methods were not resolved if I declared the previous method??\r
+ //\r
+ _Pairib insert(const value_type& _X)\r
+ {\r
+ _Imp::_Pairib _Ans = _Tr.insert(_X);\r
+ return (_Pairib(_Ans.first, _Ans.second)); \r
+ }\r
+ \r
+ iterator insert(iterator _P, const value_type& _X)\r
+ {\r
+ return (_Tr.insert((_Imp::iterator&)_P, _X)); \r
+ }\r
+ \r
+ void insert(_It _F, _It _L)\r
+ {\r
+ for (; _F != _L; ++_F)\r
+ _Tr.insert(*_F); \r
+ }\r
+\r
+};\r
+\r
+#else\r
+\r
+#define TBaseMap std::map\r
+#define TBaseList std::list\r
+#define TBaseSet std::set\r
+\r
+#endif //_M_AMD64\r
+\r
+//\r
+// Pool version of string.\r
+//\r
+typedef pool_allocator<char> TStringAllocator;\r
+typedef std::basic_string <char, std::char_traits<char>, TStringAllocator > TString;\r
+inline TString* NewPoolTString(char* s)\r
+{\r
+ void* memory = GlobalPoolAllocator.allocate(sizeof(TString));\r
+ return new(memory) TString(s);\r
+}\r
+\r
+//\r
+// Pool allocator versions of vectors, lists, and maps\r
+//\r
+template <class T> class TVector : public std::vector<T, pool_allocator<T> > {\r
+public:\r
+ typedef typename std::vector<T, pool_allocator<T> >::size_type size_type;\r
+ TVector() : std::vector<T, pool_allocator<T> >() {}\r
+ TVector(const pool_allocator<T>& a) : std::vector<T, pool_allocator<T> >(a) {}\r
+ TVector(size_type i): std::vector<T, pool_allocator<T> >(i) {}\r
+};\r
+\r
+template <class T> class TList : public TBaseList <T, pool_allocator<T> > {\r
+public:\r
+ typedef typename TBaseList<T, pool_allocator<T> >::size_type size_type;\r
+ TList() : TBaseList<T, pool_allocator<T> >() {}\r
+ TList(const pool_allocator<T>& a) : TBaseList<T, pool_allocator<T> >(a) {}\r
+ TList(size_type i): TBaseList<T, pool_allocator<T> >(i) {}\r
+};\r
+\r
+// This is called TStlSet, because TSet is taken by an existing compiler class.\r
+template <class T, class CMP> class TStlSet : public std::set<T, CMP, pool_allocator<T> > {\r
+ // No pool allocator versions of constructors in std::set.\r
+};\r
+\r
+\r
+template <class K, class D, class CMP = std::less<K> > class TMap :\r
+ public TBaseMap<K, D, CMP, pool_allocator<std::pair<K, D> > > {\r
+public:\r
+ typedef pool_allocator<std::pair <K, D> > tAllocator;\r
+\r
+ TMap() : TBaseMap<K, D, CMP, tAllocator >() {}\r
+ TMap(const tAllocator& a) : TBaseMap<K, D, CMP, tAllocator >(key_compare(), a) {}\r
+};\r
+\r
+//\r
+// Persistent string memory. Should only be used for strings that survive\r
+// across compiles/links.\r
+//\r
+typedef std::basic_string<char> TPersistString;\r
+\r
+//\r
+// templatized min and max functions.\r
+//\r
+template <class T> T Min(const T a, const T b) { return a < b ? a : b; }\r
+template <class T> T Max(const T a, const T b) { return a > b ? a : b; }\r
+\r
+//\r
+// Create a TString object from an integer.\r
+//\r
+inline const TString String(const int i, const int base = 10)\r
+{\r
+ char text[16]; // 32 bit ints are at most 10 digits in base 10\r
+ \r
+ // we assume base 10 or 16 for all cases\r
+ if (base == 10)\r
+ sprintf(text, "%d", i);\r
+ else if (base == 16)\r
+ sprintf(text, "%x", i);\r
+ else\r
+ assert (!"String(int): unsupported base");\r
+\r
+ return text;\r
+}\r
+\r
+const unsigned int SourceLocLineMask = 0xffff;\r
+const unsigned int SourceLocStringShift = 16;\r
+\r
+__inline TPersistString FormatSourceLoc(const TSourceLoc loc)\r
+{\r
+ char locText[64];\r
+\r
+ int string = loc >> SourceLocStringShift;\r
+ int line = loc & SourceLocLineMask;\r
+\r
+ if (line)\r
+ sprintf(locText, "%d:%d", string, line);\r
+ else\r
+ sprintf(locText, "%d:? ", string, line);\r
+\r
+ return TPersistString(locText);\r
+}\r
+\r
+#endif // _COMMON_INCLUDED_\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#ifndef _CONSTANT_UNION_INCLUDED_\r
+#define _CONSTANT_UNION_INCLUDED_\r
+\r
+\r
+class constUnion {\r
+public:\r
+\r
+ POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator) \r
+ union {\r
+ int iConst; // used for ivec\r
+ bool bConst; // used for bvec\r
+ float fConst; // used for vec, mat\r
+ } ;\r
+};\r
+\r
+#endif // _CONSTANT_UNION_INCLUDED_\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#ifndef _INFOSINK_INCLUDED_\r
+#define _INFOSINK_INCLUDED_\r
+\r
+#include "../Include/Common.h"\r
+#include <math.h>\r
+\r
+//\r
+// TPrefixType is used to centralize how info log messages start.\r
+// See below.\r
+//\r
+enum TPrefixType {\r
+ EPrefixNone,\r
+ EPrefixWarning,\r
+ EPrefixError,\r
+ EPrefixInternalError,\r
+ EPrefixUnimplemented\r
+};\r
+\r
+enum TOutputStream {\r
+ ENull = 0,\r
+ EDebugger = 0x01,\r
+ EStdOut = 0x02,\r
+ EString = 0x04,\r
+};\r
+//\r
+// Encapsulate info logs for all objects that have them.\r
+//\r
+// The methods are a general set of tools for getting a variety of\r
+// messages and types inserted into the log.\r
+//\r
+class TInfoSinkBase {\r
+public:\r
+ TInfoSinkBase() : outputStream(4) {}\r
+ void erase() { sink.erase(); }\r
+ TInfoSinkBase& operator<<(const TPersistString& t) { append(t); return *this; }\r
+ TInfoSinkBase& operator<<(char c) { append(1, c); return *this; }\r
+ TInfoSinkBase& operator<<(const char* s) { append(s); return *this; }\r
+ TInfoSinkBase& operator<<(int n) { append(String(n)); return *this; }\r
+ TInfoSinkBase& operator<<(const unsigned int n) { append(String(n)); return *this; }\r
+ TInfoSinkBase& operator<<(float n) { char buf[40]; \r
+ sprintf(buf, (fabs(n) > 1e-8 && fabs(n) < 1e8) || n == 0.0f ?\r
+ "%f" : "%g", n);\r
+ append(buf); \r
+ return *this; }\r
+ TInfoSinkBase& operator+(const TPersistString& t) { append(t); return *this; }\r
+ TInfoSinkBase& operator+(const TString& t) { append(t); return *this; }\r
+ TInfoSinkBase& operator<<(const TString& t) { append(t); return *this; }\r
+ TInfoSinkBase& operator+(const char* s) { append(s); return *this; }\r
+ const char* c_str() const { return sink.c_str(); }\r
+ void prefix(TPrefixType message) {\r
+ switch(message) {\r
+ case EPrefixNone: break;\r
+ case EPrefixWarning: append("WARNING: "); break;\r
+ case EPrefixError: append("ERROR: "); break;\r
+ case EPrefixInternalError: append("INTERNAL ERROR: "); break;\r
+ case EPrefixUnimplemented: append("UNIMPLEMENTED: "); break;\r
+ default: append("UNKOWN ERROR: "); break;\r
+ }\r
+ }\r
+ void location(TSourceLoc loc) {\r
+ append(FormatSourceLoc(loc).c_str());\r
+ append(": ");\r
+ }\r
+ void message(TPrefixType message, const char* s) {\r
+ prefix(message);\r
+ append(s);\r
+ append("\n");\r
+ }\r
+ void message(TPrefixType message, const char* s, TSourceLoc loc) {\r
+ prefix(message);\r
+ location(loc);\r
+ append(s);\r
+ append("\n");\r
+ }\r
+ \r
+ void setOutputStream(int output = 4)\r
+ {\r
+ outputStream = output;\r
+ }\r
+\r
+protected:\r
+ void append(const char *s); \r
+\r
+ void append(int count, char c);\r
+ void append(const TPersistString& t);\r
+ void append(const TString& t);\r
+\r
+ void checkMem(size_t growth) { if (sink.capacity() < sink.size() + growth + 2) \r
+ sink.reserve(sink.capacity() + sink.capacity() / 2); }\r
+ void appendToStream(const char* s);\r
+ TPersistString sink;\r
+ int outputStream;\r
+};\r
+\r
+class TInfoSink {\r
+public:\r
+ TInfoSinkBase info;\r
+ TInfoSinkBase debug;\r
+};\r
+\r
+#endif // _INFOSINK_INCLUDED_\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#ifndef __INITIALIZE_GLOBALS_INCLUDED_\r
+#define __INITIALIZE_GLOBALS_INCLUDED_\r
+\r
+void InitializeGlobalPools();\r
+void FreeGlobalPools();\r
+bool InitializePoolIndex();\r
+void FreePoolIndex();\r
+\r
+#endif // __INITIALIZE_GLOBALS_INCLUDED_\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#ifndef __INITIALIZE_PARSE_CONTEXT_INCLUDED_\r
+#define __INITIALIZE_PARSE_CONTEXT_INCLUDED_\r
+#include "osinclude.h"\r
+\r
+bool InitializeParseContextIndex();\r
+bool InitializeGlobalParseContext();\r
+bool FreeParseContext();\r
+bool FreeParseContextIndex();\r
+\r
+#endif // __INITIALIZE_PARSE_CONTEXT_INCLUDED_\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#ifndef _POOLALLOC_INCLUDED_\r
+#define _POOLALLOC_INCLUDED_\r
+\r
+#ifdef _DEBUG\r
+# define GUARD_BLOCKS // define to enable guard block sanity checking\r
+#endif\r
+\r
+//\r
+// This header defines an allocator that can be used to efficiently\r
+// allocate a large number of small requests for heap memory, with the \r
+// intention that they are not individually deallocated, but rather \r
+// collectively deallocated at one time.\r
+//\r
+// This simultaneously\r
+//\r
+// * Makes each individual allocation much more efficient; the\r
+// typical allocation is trivial.\r
+// * Completely avoids the cost of doing individual deallocation.\r
+// * Saves the trouble of tracking down and plugging a large class of leaks.\r
+//\r
+// Individual classes can use this allocator by supplying their own\r
+// new and delete methods.\r
+//\r
+// STL containers can use this allocator by using the pool_allocator\r
+// class as the allocator (second) template argument.\r
+//\r
+\r
+#include <stddef.h>\r
+#include <vector>\r
+\r
+// If we are using guard blocks, we must track each indivual\r
+// allocation. If we aren't using guard blocks, these\r
+// never get instantiated, so won't have any impact.\r
+// \r
+\r
+class TAllocation {\r
+public:\r
+ TAllocation(size_t size, unsigned char* mem, TAllocation* prev = 0) :\r
+ size(size), mem(mem), prevAlloc(prev) {\r
+ // Allocations are bracketed:\r
+ // [allocationHeader][initialGuardBlock][userData][finalGuardBlock]\r
+ // This would be cleaner with if (guardBlockSize)..., but that\r
+ // makes the compiler print warnings about 0 length memsets,\r
+ // even with the if() protecting them.\r
+# ifdef GUARD_BLOCKS\r
+ memset(preGuard(), guardBlockBeginVal, guardBlockSize);\r
+ memset(data(), userDataFill, size);\r
+ memset(postGuard(), guardBlockEndVal, guardBlockSize);\r
+# endif\r
+ }\r
+ \r
+ void check() const {\r
+ checkGuardBlock(preGuard(), (unsigned char) (guardBlockBeginVal), "before");\r
+ checkGuardBlock(postGuard(), (unsigned char) (guardBlockEndVal), "after");\r
+ }\r
+\r
+ void checkAllocList() const;\r
+\r
+ // Return total size needed to accomodate user buffer of 'size',\r
+ // plus our tracking data.\r
+ inline static size_t allocationSize(size_t size) {\r
+ return size + 2 * guardBlockSize + headerSize();\r
+ }\r
+ \r
+ // Offset from surrounding buffer to get to user data buffer.\r
+ inline static unsigned char* offsetAllocation(unsigned char* m) {\r
+ return m + guardBlockSize + headerSize();\r
+ }\r
+\r
+private:\r
+ void checkGuardBlock(unsigned char* blockMem, unsigned char val, char* locText) const;\r
+\r
+ // Find offsets to pre and post guard blocks, and user data buffer\r
+ unsigned char* preGuard() const { return mem + headerSize(); }\r
+ unsigned char* data() const { return preGuard() + guardBlockSize; }\r
+ unsigned char* postGuard() const { return data() + size; }\r
+\r
+ size_t size; // size of the user data area\r
+ unsigned char* mem; // beginning of our allocation (pts to header)\r
+ TAllocation* prevAlloc; // prior allocation in the chain\r
+\r
+ enum {\r
+ guardBlockBeginVal = 0xfb,\r
+ guardBlockEndVal = 0xfe,\r
+ userDataFill = 0xcd\r
+ };\r
+\r
+# ifdef GUARD_BLOCKS\r
+ enum {\r
+ guardBlockSize = 16\r
+ };\r
+ inline static size_t headerSize() { return sizeof(TAllocation); }\r
+# else\r
+ enum {\r
+ guardBlockSize = 0\r
+ };\r
+ inline static size_t headerSize() { return 0; }\r
+# endif\r
+};\r
+ \r
+//\r
+// There are several stacks. One is to track the pushing and popping\r
+// of the user, and not yet implemented. The others are simply a \r
+// repositories of free pages or used pages.\r
+//\r
+// Page stacks are linked together with a simple header at the beginning\r
+// of each allocation obtained from the underlying OS. Multi-page allocations\r
+// are returned to the OS. Individual page allocations are kept for future\r
+// re-use.\r
+//\r
+// The "page size" used is not, nor must it match, the underlying OS\r
+// page size. But, having it be about that size or equal to a set of \r
+// pages is likely most optimal.\r
+//\r
+class TPoolAllocator {\r
+public:\r
+ TPoolAllocator(bool global = false, int growthIncrement = 8*1024, int allocationAlignment = 16);\r
+\r
+ //\r
+ // Don't call the destructor just to free up the memory, call pop()\r
+ //\r
+ ~TPoolAllocator();\r
+\r
+ //\r
+ // Call push() to establish a new place to pop memory too. Does not\r
+ // have to be called to get things started.\r
+ //\r
+ void push();\r
+\r
+ //\r
+ // Call pop() to free all memory allocated since the last call to push(),\r
+ // or if no last call to push, frees all memory since first allocation.\r
+ //\r
+ void pop();\r
+\r
+ //\r
+ // Call popAll() to free all memory allocated.\r
+ //\r
+ void popAll();\r
+\r
+ //\r
+ // Call allocate() to actually acquire memory. Returns 0 if no memory\r
+ // available, otherwise a properly aligned pointer to 'numBytes' of memory.\r
+ //\r
+ void* allocate(size_t numBytes);\r
+\r
+ //\r
+ // There is no deallocate. The point of this class is that\r
+ // deallocation can be skipped by the user of it, as the model\r
+ // of use is to simultaneously deallocate everything at once\r
+ // by calling pop(), and to not have to solve memory leak problems.\r
+ //\r
+\r
+protected:\r
+ friend struct tHeader;\r
+ \r
+ struct tHeader {\r
+ tHeader(tHeader* nextPage, size_t pageCount) :\r
+#ifdef GUARD_BLOCKS\r
+ lastAllocation(0),\r
+#endif\r
+ nextPage(nextPage), pageCount(pageCount) { }\r
+\r
+ ~tHeader() {\r
+#ifdef GUARD_BLOCKS\r
+ if (lastAllocation)\r
+ lastAllocation->checkAllocList();\r
+#endif\r
+ }\r
+\r
+ tHeader* nextPage;\r
+ size_t pageCount;\r
+#ifdef GUARD_BLOCKS\r
+ TAllocation* lastAllocation;\r
+#endif\r
+ };\r
+\r
+ struct tAllocState {\r
+ size_t offset;\r
+ tHeader* page;\r
+ };\r
+ typedef std::vector<tAllocState> tAllocStack;\r
+\r
+ // Track allocations if and only if we're using guard blocks\r
+ void* initializeAllocation(tHeader* block, unsigned char* memory, size_t numBytes) {\r
+# ifdef GUARD_BLOCKS\r
+ new(memory) TAllocation(numBytes, memory, block->lastAllocation);\r
+ block->lastAllocation = reinterpret_cast<TAllocation*>(memory);\r
+# endif\r
+\r
+ // This is optimized entirely away if GUARD_BLOCKS is not defined.\r
+ return TAllocation::offsetAllocation(memory);\r
+ }\r
+\r
+ bool global; // should be true if this object is globally scoped\r
+ size_t pageSize; // granularity of allocation from the OS\r
+ size_t alignment; // all returned allocations will be aligned at \r
+ // this granularity, which will be a power of 2\r
+ size_t alignmentMask;\r
+ size_t headerSkip; // amount of memory to skip to make room for the\r
+ // header (basically, size of header, rounded\r
+ // up to make it aligned\r
+ size_t currentPageOffset; // next offset in top of inUseList to allocate from\r
+ tHeader* freeList; // list of popped memory\r
+ tHeader* inUseList; // list of all memory currently being used\r
+ tAllocStack stack; // stack of where to allocate from, to partition pool\r
+\r
+ int numCalls; // just an interesting statistic\r
+ size_t totalBytes; // just an interesting statistic\r
+private:\r
+ TPoolAllocator& operator=(const TPoolAllocator&); // dont allow assignment operator\r
+ TPoolAllocator(const TPoolAllocator&); // dont allow default copy constructor\r
+};\r
+\r
+\r
+//\r
+// There could potentially be many pools with pops happening at\r
+// different times. But a simple use is to have a global pop\r
+// with everyone using the same global allocator.\r
+//\r
+typedef TPoolAllocator* PoolAllocatorPointer;\r
+extern TPoolAllocator& GetGlobalPoolAllocator();\r
+extern PoolAllocatorPointer& GetCompilerPoolAllocator();\r
+#define GlobalPoolAllocator GetGlobalPoolAllocator()\r
+#define CompilerPoolAllocator GetCompilerPoolAllocator()\r
+struct TThreadGlobalPools\r
+{\r
+ TPoolAllocator* globalPoolAllocator;\r
+ TPoolAllocator* compilerPoolAllocator;\r
+};\r
+\r
+//\r
+// This STL compatible allocator is intended to be used as the allocator\r
+// parameter to templatized STL containers, like vector and map.\r
+//\r
+// It will use the pools for allocation, and not\r
+// do any deallocation, but will still do destruction.\r
+//\r
+template<class T>\r
+class pool_allocator {\r
+public:\r
+ typedef size_t size_type;\r
+ typedef ptrdiff_t difference_type;\r
+ typedef T *pointer;\r
+ typedef const T *const_pointer;\r
+ typedef T& reference;\r
+ typedef const T& const_reference;\r
+ typedef T value_type;\r
+ template<class Other> \r
+ struct rebind {\r
+ typedef pool_allocator<Other> other;\r
+ };\r
+ pointer address(reference x) const { return &x; }\r
+ const_pointer address(const_reference x) const { return &x; }\r
+\r
+#ifdef USING_SGI_STL\r
+ pool_allocator() { }\r
+#else\r
+ pool_allocator() : allocator(GlobalPoolAllocator) { }\r
+ pool_allocator(TPoolAllocator& a) : allocator(a) { }\r
+ pool_allocator(const pool_allocator<T>& p) : allocator(p.allocator) { }\r
+#endif\r
+\r
+#if _MSC_VER >= 1300\r
+ template<class Other>\r
+#ifdef USING_SGI_STL\r
+ pool_allocator(const pool_allocator<Other>& p) /*: allocator(p.getAllocator())*/ { }\r
+#else\r
+ pool_allocator(const pool_allocator<Other>& p) : allocator(p.getAllocator()) { }\r
+#endif\r
+#endif\r
+\r
+#ifndef _WIN32\r
+ template<class Other>\r
+ pool_allocator(const pool_allocator<Other>& p) : allocator(p.getAllocator()) { }\r
+#endif\r
+\r
+#ifdef USING_SGI_STL\r
+ static pointer allocate(size_type n) { \r
+ return reinterpret_cast<pointer>(getAllocator().allocate(n)); }\r
+ pointer allocate(size_type n, const void*) { \r
+ return reinterpret_cast<pointer>(getAllocator().allocate(n)); }\r
+\r
+ static void deallocate(void*, size_type) { }\r
+ static void deallocate(pointer, size_type) { }\r
+#else\r
+ pointer allocate(size_type n) { \r
+ return reinterpret_cast<pointer>(getAllocator().allocate(n * sizeof(T))); }\r
+ pointer allocate(size_type n, const void*) { \r
+ return reinterpret_cast<pointer>(getAllocator().allocate(n * sizeof(T))); }\r
+\r
+ void deallocate(void*, size_type) { }\r
+ void deallocate(pointer, size_type) { }\r
+#endif\r
+\r
+ pointer _Charalloc(size_t n) {\r
+ return reinterpret_cast<pointer>(getAllocator().allocate(n)); }\r
+\r
+ void construct(pointer p, const T& val) { new ((void *)p) T(val); }\r
+ void destroy(pointer p) { p->T::~T(); }\r
+\r
+ bool operator==(const pool_allocator& rhs) const { return &getAllocator() == &rhs.getAllocator(); }\r
+ bool operator!=(const pool_allocator& rhs) const { return &getAllocator() != &rhs.getAllocator(); }\r
+\r
+ size_type max_size() const { return static_cast<size_type>(-1) / sizeof(T); }\r
+ size_type max_size(int size) const { return static_cast<size_type>(-1) / size; }\r
+\r
+#ifdef USING_SGI_STL\r
+ //void setAllocator(TPoolAllocator* a) { allocator = a; }\r
+ static TPoolAllocator& getAllocator() { return GlobalPoolAllocator; }\r
+#else\r
+ void setAllocator(TPoolAllocator* a) { allocator = *a; }\r
+ TPoolAllocator& getAllocator() const { return allocator; }\r
+\r
+protected:\r
+ TPoolAllocator& allocator;\r
+#endif\r
+};\r
+\r
+#endif // _POOLALLOC_INCLUDED_\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#ifndef _RESOURCE_LIMITS_INCLUDED_\r
+#define _RESOURCE_LIMITS_INCLUDED_\r
+\r
+struct TBuiltInResource {\r
+ int maxLights;\r
+ int maxClipPlanes;\r
+ int maxTextureUnits;\r
+ int maxTextureCoords;\r
+ int maxVertexAttribs;\r
+ int maxVertexUniformComponents;\r
+ int maxVaryingFloats;\r
+ int maxVertexTextureImageUnits;\r
+ int maxCombinedTextureImageUnits;\r
+ int maxTextureImageUnits;\r
+ int maxFragmentUniformComponents;\r
+ int maxDrawBuffers;\r
+};\r
+#endif // _RESOURCE_LIMITS_INCLUDED_\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#ifndef _SHHANDLE_INCLUDED_\r
+#define _SHHANDLE_INCLUDED_\r
+\r
+//\r
+// Machine independent part of the compiler private objects\r
+// sent as ShHandle to the driver.\r
+//\r
+// This should not be included by driver code.\r
+//\r
+\r
+#define SH_EXPORTING\r
+#include "../Public/ShaderLangExt.h"\r
+#include "InfoSink.h"\r
+\r
+class TCompiler;\r
+class TLinker;\r
+class TUniformMap;\r
+namespace Lf {\r
+ class TBindingList;\r
+ class TLinker;\r
+ class TLibrary;\r
+};\r
+\r
+//\r
+// The base class used to back handles returned to the driver.\r
+//\r
+class TShHandleBase {\r
+public:\r
+ TShHandleBase() { }\r
+ virtual ~TShHandleBase() { }\r
+ virtual TCompiler* getAsCompiler() { return 0; }\r
+ virtual TLinker* getAsLinker() { return 0; }\r
+ virtual Lf::TLinker* getAsNewLinker() { return 0; }\r
+ virtual TUniformMap* getAsUniformMap() { return 0; }\r
+ virtual Lf::TBindingList* getAsBindingList() { return 0; }\r
+ virtual Lf::TLibrary* getAsLibrary() { return 0; }\r
+};\r
+//\r
+// The base class for the machine dependent linker to derive from\r
+// for managing where uniforms live.\r
+//\r
+class TUniformMap : public TShHandleBase {\r
+public:\r
+ TUniformMap() { }\r
+ virtual ~TUniformMap() { }\r
+ virtual TUniformMap* getAsUniformMap() { return this; }\r
+ virtual int getLocation(const char* name) = 0; \r
+ virtual TInfoSink& getInfoSink() { return infoSink; }\r
+ TInfoSink infoSink;\r
+};\r
+\r
+class TIntermNode;\r
+\r
+//\r
+// The base class for the machine dependent compiler to derive from\r
+// for managing object code from the compile.\r
+//\r
+class TCompiler : public TShHandleBase {\r
+public:\r
+ TCompiler(EShLanguage l, TInfoSink& sink) : infoSink(sink) , language(l), haveValidObjectCode(false) { }\r
+ virtual ~TCompiler() { }\r
+ EShLanguage getLanguage() { return language; }\r
+ virtual TInfoSink& getInfoSink() { return infoSink; }\r
+\r
+ virtual bool compile(TIntermNode* root) = 0;\r
+\r
+ virtual TCompiler* getAsCompiler() { return this; }\r
+ virtual bool linkable() { return haveValidObjectCode; }\r
+ \r
+ // Initialize our private pool for a new compilation, and\r
+ // return it.\r
+ virtual TPoolAllocator& getNewCompilationAllocator()\r
+ {\r
+ // We do a pop and push on the compiler pool, because compile can\r
+ // be called repeatedly on the same compiler handle. Each time,\r
+ // we want to pop away the results of any previous compile. We\r
+ // could do that with popAll, but this is a somewhat smaller\r
+ // hammer.\r
+ compilerPool.pop();\r
+ compilerPool.push();\r
+ \r
+ return compilerPool;\r
+ }\r
+\r
+ TPoolAllocator& getCompilerPoolAllocator() { return compilerPool; }\r
+\r
+ TInfoSink& infoSink;\r
+protected:\r
+ EShLanguage language;\r
+ bool haveValidObjectCode;\r
+ \r
+ // This is a per-compiler-object pool allocator. Allocations\r
+ // who's lifetime need not extend beyond the lifetime of the\r
+ // compiler itself can use this private pool.\r
+ TPoolAllocator compilerPool; \r
+};\r
+\r
+//\r
+// Link operations are base on a list of compile results...\r
+//\r
+typedef TVector<TCompiler*> TCompilerList;\r
+typedef TVector<TShHandleBase*> THandleList;\r
+\r
+//\r
+// The base class for the machine dependent linker to derive from\r
+// to manage the resulting executable.\r
+//\r
+\r
+class TLinker : public TShHandleBase {\r
+public:\r
+ TLinker(EShExecutable e, TInfoSink& iSink) : \r
+ infoSink(iSink),\r
+ executable(e), \r
+ haveReturnableObjectCode(false),\r
+ appAttributeBindings(0),\r
+ fixedAttributeBindings(0),\r
+ excludedAttributes(0),\r
+ excludedCount(0),\r
+ uniformBindings(0) { }\r
+ virtual TLinker* getAsLinker() { return this; }\r
+ virtual ~TLinker() { }\r
+ virtual bool link(TCompilerList&, TUniformMap*) = 0;\r
+ virtual bool link(THandleList&) { return false; }\r
+ virtual void setAppAttributeBindings(const ShBindingTable* t) { appAttributeBindings = t; }\r
+ virtual void setFixedAttributeBindings(const ShBindingTable* t) { fixedAttributeBindings = t; }\r
+ virtual void getAttributeBindings(ShBindingTable const **t) const = 0;\r
+ virtual void setExcludedAttributes(const int* attributes, int count) { excludedAttributes = attributes; excludedCount = count; }\r
+ virtual ShBindingTable* getUniformBindings() const { return uniformBindings; }\r
+ virtual const void* getObjectCode() const { return 0; } // a real compiler would be returning object code here\r
+ virtual TInfoSink& getInfoSink() { return infoSink; }\r
+ TInfoSink& infoSink;\r
+protected:\r
+ EShExecutable executable;\r
+ bool haveReturnableObjectCode; // true when objectCode is acceptable to send to driver\r
+\r
+ const ShBindingTable* appAttributeBindings;\r
+ const ShBindingTable* fixedAttributeBindings;\r
+ const int* excludedAttributes;\r
+ int excludedCount;\r
+ ShBindingTable* uniformBindings; // created by the linker \r
+};\r
+\r
+//\r
+// This is the interface between the machine independent code\r
+// and the machine dependent code.\r
+//\r
+// The machine dependent code should derive from the classes\r
+// above. Then Construct*() and Delete*() will create and \r
+// destroy the machine dependent objects, which contain the\r
+// above machine independent information.\r
+//\r
+TCompiler* ConstructCompiler(EShLanguage, int);\r
+\r
+TShHandleBase* ConstructLinker(EShExecutable, int);\r
+TShHandleBase* ConstructBindings();\r
+TShHandleBase* ConstructLibrary();\r
+void DeleteLinker(TShHandleBase*);\r
+ \r
+TUniformMap* ConstructUniformMap();\r
+void DeleteCompiler(TCompiler*);\r
+\r
+void DeleteUniformMap(TUniformMap*);\r
+void freeTargetDependentData(void*);\r
+\r
+#endif // _SHHANDLE_INCLUDED_\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#ifndef _TYPES_INCLUDED\r
+#define _TYPES_INCLUDED\r
+\r
+#include "../Include/Common.h"\r
+#include "../Include/BaseTypes.h"\r
+\r
+//\r
+// Need to have association of line numbers to types in a list for building structs.\r
+//\r
+class TType;\r
+struct TTypeLine {\r
+ TType* type;\r
+ int line;\r
+};\r
+typedef TVector<TTypeLine> TTypeList;\r
+\r
+inline TTypeList* NewPoolTTypeList()\r
+{\r
+ void* memory = GlobalPoolAllocator.allocate(sizeof(TTypeList));\r
+ return new(memory) TTypeList;\r
+}\r
+\r
+//\r
+// This is a workaround for a problem with the yacc stack, It can't have\r
+// types that the compiler thinks non-trivial constructors. It should \r
+// just be used while recognizing the grammar, not anything else. Pointers\r
+// could be used, but also trying to avoid lots of memory management overhead.\r
+//\r
+// Not as bad as it looks, there is no actual assumption that the fields\r
+// match up or are name the same or anything like that.\r
+//\r
+class TPublicType {\r
+public:\r
+ TBasicType type;\r
+ TQualifier qualifier;\r
+ int size; // size of vector or matrix, not size of array\r
+ bool matrix;\r
+ bool array;\r
+ TType* userDef;\r
+ int line;\r
+};\r
+\r
+//\r
+// Base class for things that have a type.\r
+//\r
+class TType {\r
+public:\r
+ POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)\r
+ explicit TType(TBasicType t, TQualifier q = EvqTemporary, int s = 1, bool m = false, bool a = false) :\r
+ type(t), qualifier(q), size(s), matrix(m), array(a), arraySize(0),\r
+ structure(0), structureSize(0), maxArraySize(0), arrayInformationType(0)\r
+ { }\r
+ explicit TType(TPublicType p) : \r
+ type(p.type), qualifier(p.qualifier), size(p.size), matrix(p.matrix), array(p.array), arraySize(0), \r
+ structure(0), structureSize(0), maxArraySize(0), arrayInformationType(0)\r
+ {\r
+ if (p.userDef) {\r
+ structure = p.userDef->getStruct();\r
+ structureSize = setStructSize(p.userDef->getStruct());\r
+ typeName = p.userDef->getTypeName();\r
+ }\r
+ }\r
+ explicit TType(TTypeList* userDef, TString n) : \r
+ type(EbtStruct), qualifier(EvqTemporary), size(1), matrix(false), array(false), arraySize(0),\r
+ structure(userDef), typeName(n), maxArraySize(0), arrayInformationType(0) {\r
+ structureSize = setStructSize(userDef);\r
+ }\r
+ \r
+ virtual ~TType() {}\r
+ TType (const TType& type) { *this = type; }\r
+ \r
+ int setStructSize(TTypeList* userDef)\r
+ {\r
+ int stSize = 0;\r
+ for (TTypeList::iterator tl = userDef->begin(); tl != userDef->end(); tl++) {\r
+ if (((*tl).type)->isArray()) { \r
+ stSize += ((*tl).type)->getInstanceSize() * ((*tl).type)->getArraySize();\r
+ } else if (((*tl).type)->isMatrix() || ((*tl).type)->isVector()){\r
+ stSize += ((*tl).type)->getInstanceSize();\r
+ } else if (((*tl).type)->getStruct()) {\r
+ //?? We should actually be calling getStructSize() function and not setStructSize. This problem occurs in case\r
+ // of nested/embedded structs.\r
+ stSize += setStructSize(((*tl).type)->getStruct());\r
+ } else \r
+ stSize += 1;\r
+ }\r
+ structureSize = stSize;\r
+ return stSize;\r
+ }\r
+\r
+ virtual void setType(TBasicType t, int s, bool m, bool a, int aS = 0)\r
+ { type = t; size = s; matrix = m; array = a; arraySize = aS; }\r
+ virtual void setType(TBasicType t, int s, bool m, TType* userDef = 0)\r
+ { type = t; \r
+ size = s; \r
+ matrix = m; \r
+ if (userDef)\r
+ structure = userDef->getStruct(); \r
+ // leave array information intact.\r
+ }\r
+ virtual void setTypeName(const TString& n) { typeName = n; }\r
+ virtual void setFieldName(const TString& n) { fieldName = n; }\r
+ virtual const TString& getTypeName() const { return typeName; }\r
+ virtual const TString& getFieldName() const { return fieldName; }\r
+ virtual TBasicType getBasicType() const { return type; }\r
+ virtual TQualifier getQualifier() const { return qualifier; }\r
+ virtual void changeQualifier(TQualifier q) { qualifier = q; }\r
+\r
+ // One-dimensional size of single instance type\r
+ virtual int getNominalSize() const { return size; } \r
+ \r
+ // Full-dimensional size of single instance of type\r
+ virtual int getInstanceSize() const \r
+ {\r
+ if (matrix)\r
+ return size * size;\r
+ else\r
+ return size;\r
+ }\r
+ \r
+ virtual bool isMatrix() const { return matrix; }\r
+ virtual bool isArray() const { return array; }\r
+ int getArraySize() const { return arraySize; }\r
+ void setArraySize(int s) { array = true; arraySize = s; }\r
+ void setMaxArraySize (int s) { maxArraySize = s; }\r
+ int getMaxArraySize () const { return maxArraySize; }\r
+ void setArrayInformationType(TType* t) { arrayInformationType = t; }\r
+ TType* getArrayInformationType() { return arrayInformationType; }\r
+ virtual bool isVector() const { return size > 1 && !matrix; }\r
+ static char* getBasicString(TBasicType t) {\r
+ switch (t) {\r
+ case EbtVoid: return "void"; break;\r
+ case EbtFloat: return "float"; break;\r
+ case EbtInt: return "int"; break;\r
+ case EbtBool: return "bool"; break;\r
+ case EbtSampler1D: return "sampler1D"; break;\r
+ case EbtSampler2D: return "sampler2D"; break;\r
+ case EbtSampler3D: return "sampler3D"; break;\r
+ case EbtSamplerCube: return "samplerCube"; break;\r
+ case EbtSampler1DShadow: return "sampler1DShadow"; break;\r
+ case EbtSampler2DShadow: return "sampler2DShadow"; break;\r
+ case EbtStruct: return "structure"; break;\r
+ default: return "unknown type";\r
+ }\r
+ }\r
+ const char* getBasicString() const { return TType::getBasicString(type); }\r
+ const char* getQualifierString() const { return ::getQualifierString(qualifier); }\r
+ TTypeList* getStruct() { return structure; }\r
+ int getStructSize() { return structureSize; }\r
+ TTypeList* getStruct() const { return structure; }\r
+ TString& getMangledName() {\r
+ if (mangled.size() == 0) {\r
+ buildMangledName(mangled); \r
+ mangled+=';';\r
+ }\r
+ return mangled;\r
+ }\r
+ bool operator==(const TType& right) const {\r
+ return type == right.type &&\r
+ size == right.size &&\r
+ matrix == right.matrix &&\r
+ array == right.array &&\r
+ structure == right.structure;\r
+ // don't check the qualifier, it's not ever what's being sought after\r
+ }\r
+ bool operator!=(const TType& right) const {\r
+ return !operator==(right);\r
+ }\r
+ TString getCompleteString() const;\r
+ \r
+protected:\r
+ TBasicType type;\r
+ TQualifier qualifier;\r
+ int size; // size of vector or matrix, not size of array\r
+ bool matrix;\r
+ bool array;\r
+ int arraySize;\r
+ TTypeList* structure; // 0 unless this is a struct\r
+ TString fieldName; // for structure field names\r
+ TString typeName; // for structure field type name\r
+ TString mangled;\r
+ int structureSize;\r
+ int maxArraySize;\r
+ TType* arrayInformationType;\r
+\r
+ void buildMangledName(TString&);\r
+};\r
+\r
+#endif // _TYPES_INCLUDED_\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+//\r
+// Definition of the in-memory high-level intermediate representation\r
+// of shaders. This is a tree that parser creates.\r
+//\r
+// Nodes in the tree are defined as a hierarchy of classes derived from \r
+// TIntermNode. Each is a node in a tree. There is no preset branching factor;\r
+// each node can have it's own type of list of children.\r
+//\r
+\r
+#ifndef __INTERMEDIATE_H\r
+#define __INTERMEDIATE_H\r
+\r
+#include "../Include/Common.h"\r
+#include "../Include/Types.h"\r
+#include "../Include/ConstantUnion.h"\r
+\r
+//\r
+// Operators used by the high-level (parse tree) representation.\r
+//\r
+\r
+enum TOperator {\r
+ EOpNull, // if in a node, should only mean a node is still being built\r
+ EOpSequence, // denotes a list of statements, or parameters, etc.\r
+ EOpFunctionCall, \r
+ EOpFunction, // For function definition\r
+ EOpParameters, // an aggregate listing the parameters to a function\r
+\r
+ //\r
+ // Unary operators\r
+ //\r
+ \r
+ EOpNegative,\r
+ EOpLogicalNot,\r
+ EOpVectorLogicalNot,\r
+ EOpBitwiseNot,\r
+\r
+ EOpPostIncrement,\r
+ EOpPostDecrement,\r
+ EOpPreIncrement,\r
+ EOpPreDecrement,\r
+\r
+ EOpConvIntToBool,\r
+ EOpConvFloatToBool,\r
+ EOpConvBoolToFloat,\r
+ EOpConvIntToFloat,\r
+ EOpConvFloatToInt,\r
+ EOpConvBoolToInt,\r
+\r
+ //\r
+ // binary operations\r
+ //\r
+\r
+ EOpAdd,\r
+ EOpSub,\r
+ EOpMul,\r
+ EOpDiv,\r
+ EOpMod,\r
+ EOpRightShift,\r
+ EOpLeftShift,\r
+ EOpAnd,\r
+ EOpInclusiveOr,\r
+ EOpExclusiveOr,\r
+ EOpEqual,\r
+ EOpNotEqual,\r
+ EOpVectorEqual,\r
+ EOpVectorNotEqual,\r
+ EOpLessThan,\r
+ EOpGreaterThan,\r
+ EOpLessThanEqual,\r
+ EOpGreaterThanEqual,\r
+ EOpComma,\r
+\r
+ EOpVectorTimesScalar,\r
+ EOpVectorTimesMatrix,\r
+ EOpMatrixTimesVector,\r
+ EOpMatrixTimesScalar,\r
+\r
+ EOpLogicalOr,\r
+ EOpLogicalXor,\r
+ EOpLogicalAnd,\r
+\r
+ EOpIndexDirect,\r
+ EOpIndexIndirect,\r
+ EOpIndexDirectStruct,\r
+\r
+ EOpVectorSwizzle,\r
+\r
+ //\r
+ // Built-in functions potentially mapped to operators\r
+ //\r
+\r
+ EOpRadians,\r
+ EOpDegrees,\r
+ EOpSin,\r
+ EOpCos,\r
+ EOpTan,\r
+ EOpAsin,\r
+ EOpAcos,\r
+ EOpAtan,\r
+\r
+ EOpPow,\r
+ EOpExp,\r
+ EOpLog,\r
+ EOpExp2,\r
+ EOpLog2,\r
+ EOpSqrt,\r
+ EOpInverseSqrt,\r
+\r
+ EOpAbs,\r
+ EOpSign,\r
+ EOpFloor,\r
+ EOpCeil,\r
+ EOpFract,\r
+ EOpMin,\r
+ EOpMax,\r
+ EOpClamp,\r
+ EOpMix,\r
+ EOpStep,\r
+ EOpSmoothStep,\r
+\r
+ EOpLength,\r
+ EOpDistance,\r
+ EOpDot,\r
+ EOpCross,\r
+ EOpNormalize,\r
+ EOpFaceForward,\r
+ EOpReflect,\r
+ EOpRefract,\r
+\r
+ EOpDPdx, // Fragment only\r
+ EOpDPdy, // Fragment only\r
+ EOpFwidth, // Fragment only\r
+\r
+ EOpMatrixTimesMatrix,\r
+\r
+ EOpAny,\r
+ EOpAll,\r
+ \r
+ EOpItof, // pack/unpack only\r
+ EOpFtoi, // pack/unpack only \r
+ EOpSkipPixels, // pack/unpack only\r
+ EOpReadInput, // unpack only\r
+ EOpWritePixel, // unpack only\r
+ EOpBitmapLsb, // unpack only\r
+ EOpBitmapMsb, // unpack only\r
+ EOpWriteOutput, // pack only\r
+ EOpReadPixel, // pack only\r
+ \r
+ //\r
+ // Branch\r
+ //\r
+\r
+ EOpKill, // Fragment only\r
+ EOpReturn,\r
+ EOpBreak,\r
+ EOpContinue,\r
+\r
+ //\r
+ // Constructors\r
+ //\r
+\r
+ EOpConstructInt,\r
+ EOpConstructBool,\r
+ EOpConstructFloat,\r
+ EOpConstructVec2,\r
+ EOpConstructVec3,\r
+ EOpConstructVec4,\r
+ EOpConstructBVec2,\r
+ EOpConstructBVec3,\r
+ EOpConstructBVec4,\r
+ EOpConstructIVec2,\r
+ EOpConstructIVec3,\r
+ EOpConstructIVec4,\r
+ EOpConstructMat2,\r
+ EOpConstructMat3,\r
+ EOpConstructMat4,\r
+ EOpConstructStruct,\r
+\r
+ //\r
+ // moves\r
+ //\r
+ \r
+ EOpAssign,\r
+ EOpAddAssign,\r
+ EOpSubAssign,\r
+ EOpMulAssign,\r
+ EOpVectorTimesMatrixAssign,\r
+ EOpVectorTimesScalarAssign,\r
+ EOpMatrixTimesScalarAssign,\r
+ EOpMatrixTimesMatrixAssign,\r
+ EOpDivAssign,\r
+ EOpModAssign,\r
+ EOpAndAssign,\r
+ EOpInclusiveOrAssign,\r
+ EOpExclusiveOrAssign,\r
+ EOpLeftShiftAssign,\r
+ EOpRightShiftAssign,\r
+};\r
+\r
+class TIntermTraverser;\r
+class TIntermAggregate;\r
+class TIntermBinary;\r
+class TIntermConstantUnion;\r
+class TIntermSelection;\r
+class TIntermTyped;\r
+class TIntermSymbol;\r
+class TInfoSink;\r
+\r
+//\r
+// Base class for the tree nodes\r
+//\r
+class TIntermNode {\r
+public:\r
+ POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)\r
+\r
+ TIntermNode() : line(0) {}\r
+ virtual TSourceLoc getLine() const { return line; }\r
+ virtual void setLine(TSourceLoc l) { line = l; }\r
+ virtual void traverse(TIntermTraverser*) = 0;\r
+ virtual TIntermTyped* getAsTyped() { return 0; }\r
+ virtual TIntermConstantUnion* getAsConstantUnion() { return 0; }\r
+ virtual TIntermAggregate* getAsAggregate() { return 0; }\r
+ virtual TIntermBinary* getAsBinaryNode() { return 0; }\r
+ virtual TIntermSelection* getAsSelectionNode() { return 0; }\r
+ virtual TIntermSymbol* getAsSymbolNode() { return 0; }\r
+ virtual ~TIntermNode() { }\r
+protected:\r
+ TSourceLoc line;\r
+};\r
+\r
+//\r
+// This is just to help yacc.\r
+//\r
+struct TIntermNodePair {\r
+ TIntermNode* node1;\r
+ TIntermNode* node2;\r
+};\r
+\r
+class TIntermSymbol;\r
+class TIntermBinary;\r
+\r
+//\r
+// Intermediate class for nodes that have a type.\r
+//\r
+class TIntermTyped : public TIntermNode {\r
+public:\r
+ TIntermTyped(const TType& t) : type(t) { }\r
+ virtual TIntermTyped* getAsTyped() { return this; }\r
+ virtual void setType(const TType& t) { type = t; }\r
+ virtual TType getType() const { return type; }\r
+ virtual TType* getTypePointer() { return &type; }\r
+ \r
+ virtual TBasicType getBasicType() const { return type.getBasicType(); }\r
+ virtual TQualifier getQualifier() const { return type.getQualifier(); }\r
+ virtual int getNominalSize() const { return type.getNominalSize(); }\r
+ virtual int getSize() const { return type.getInstanceSize(); }\r
+ virtual bool isMatrix() const { return type.isMatrix(); }\r
+ virtual bool isArray() const { return type.isArray(); }\r
+ virtual bool isVector() const { return type.isVector(); }\r
+ const char* getBasicString() const { return type.getBasicString(); }\r
+ const char* getQualifierString() const { return type.getQualifierString(); }\r
+ TString getCompleteString() const { return type.getCompleteString(); }\r
+\r
+protected:\r
+ TType type;\r
+};\r
+\r
+//\r
+// Handle for, do-while, and while loops.\r
+//\r
+class TIntermLoop : public TIntermNode {\r
+public:\r
+ TIntermLoop(TIntermNode* aBody, TIntermTyped* aTest, TIntermTyped* aTerminal, bool testFirst) : \r
+ body(aBody),\r
+ test(aTest),\r
+ terminal(aTerminal),\r
+ first(testFirst) { }\r
+ virtual void traverse(TIntermTraverser*);\r
+ TIntermNode* getBody() { return body; }\r
+ TIntermTyped* getTest() { return test; }\r
+ TIntermTyped* getTerminal() { return terminal; }\r
+ bool testFirst() { return first; }\r
+protected:\r
+ TIntermNode* body; // code to loop over\r
+ TIntermTyped* test; // exit condition associated with loop, could be 0 for 'for' loops\r
+ TIntermTyped* terminal; // exists for for-loops\r
+ bool first; // true for while and for, not for do-while\r
+};\r
+\r
+//\r
+// Handle break, continue, return, and kill.\r
+//\r
+class TIntermBranch : public TIntermNode {\r
+public:\r
+ TIntermBranch(TOperator op, TIntermTyped* e) :\r
+ flowOp(op),\r
+ expression(e) { }\r
+ virtual void traverse(TIntermTraverser*);\r
+ TOperator getFlowOp() { return flowOp; }\r
+ TIntermTyped* getExpression() { return expression; }\r
+protected:\r
+ TOperator flowOp;\r
+ TIntermTyped* expression; // non-zero except for "return exp;" statements\r
+};\r
+\r
+//\r
+// Nodes that correspond to symbols or constants in the source code.\r
+//\r
+class TIntermSymbol : public TIntermTyped {\r
+public:\r
+ // if symbol is initialized as symbol(sym), the memory comes from the poolallocator of sym. If sym comes from\r
+ // per process globalpoolallocator, then it causes increased memory usage per compile\r
+ // it is essential to use "symbol = sym" to assign to symbol\r
+ TIntermSymbol(int i, const TString& sym, const TType& t) : \r
+ TIntermTyped(t), id(i) { symbol = sym;} \r
+ virtual int getId() const { return id; }\r
+ virtual const TString& getSymbol() const { return symbol; }\r
+ virtual void traverse(TIntermTraverser*);\r
+ virtual TIntermSymbol* getAsSymbolNode() { return this; }\r
+protected:\r
+ int id;\r
+ TString symbol;\r
+};\r
+\r
+class TIntermConstantUnion : public TIntermTyped {\r
+public:\r
+ TIntermConstantUnion(constUnion *unionPointer, const TType& t) : TIntermTyped(t), unionArrayPointer(unionPointer) { }\r
+ constUnion* getUnionArrayPointer() const { return unionArrayPointer; }\r
+ void setUnionArrayPointer(constUnion *c) { unionArrayPointer = c; }\r
+ virtual TIntermConstantUnion* getAsConstantUnion() { return this; }\r
+ virtual void traverse(TIntermTraverser* );\r
+ virtual TIntermTyped* fold(TOperator, TIntermTyped*, TInfoSink&, bool);\r
+protected:\r
+ constUnion *unionArrayPointer;\r
+};\r
+\r
+//\r
+// Intermediate class for node types that hold operators.\r
+//\r
+class TIntermOperator : public TIntermTyped {\r
+public:\r
+ TOperator getOp() { return op; }\r
+ bool modifiesState() const;\r
+ bool isConstructor() const;\r
+ virtual bool promote(TInfoSink&) { return true; }\r
+protected:\r
+ TIntermOperator(TOperator o) : TIntermTyped(TType(EbtFloat)), op(o) {}\r
+ TIntermOperator(TOperator o, TType t) : TIntermTyped(t), op(o) {} \r
+ TOperator op;\r
+};\r
+\r
+//\r
+// Nodes for all the basic binary math operators.\r
+//\r
+class TIntermBinary : public TIntermOperator {\r
+public:\r
+ TIntermBinary(TOperator o) : TIntermOperator(o) {}\r
+ virtual void traverse(TIntermTraverser*);\r
+ virtual void setLeft(TIntermTyped* n) { left = n; }\r
+ virtual void setRight(TIntermTyped* n) { right = n; }\r
+ virtual TIntermTyped* getLeft() const { return left; }\r
+ virtual TIntermTyped* getRight() const { return right; }\r
+ virtual TIntermBinary* getAsBinaryNode() { return this; }\r
+ virtual bool promote(TInfoSink&);\r
+protected:\r
+ TIntermTyped* left;\r
+ TIntermTyped* right;\r
+};\r
+\r
+//\r
+// Nodes for unary math operators.\r
+//\r
+class TIntermUnary : public TIntermOperator {\r
+public:\r
+ TIntermUnary(TOperator o, TType t) : TIntermOperator(o, t), operand(0) {}\r
+ TIntermUnary(TOperator o) : TIntermOperator(o), operand(0) {}\r
+ virtual void traverse(TIntermTraverser*);\r
+ virtual void setOperand(TIntermTyped* o) { operand = o; }\r
+ virtual TIntermTyped* getOperand() { return operand; }\r
+ virtual bool promote(TInfoSink&);\r
+protected:\r
+ TIntermTyped* operand;\r
+};\r
+\r
+typedef TVector<TIntermNode*> TIntermSequence;\r
+typedef TVector<int> TQualifierList;\r
+//\r
+// Nodes that operate on an arbitrary sized set of children.\r
+//\r
+class TIntermAggregate : public TIntermOperator {\r
+public:\r
+ TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false) { }\r
+ TIntermAggregate(TOperator o) : TIntermOperator(o) { }\r
+ virtual TIntermAggregate* getAsAggregate() { return this; }\r
+ virtual void setOperator(TOperator o) { op = o; }\r
+ virtual TIntermSequence& getSequence() { return sequence; }\r
+ virtual void setName(const TString& n) { name = n; }\r
+ virtual const TString& getName() const { return name; }\r
+ virtual void traverse(TIntermTraverser*);\r
+ virtual void setUserDefined() { userDefined = true; }\r
+ virtual bool isUserDefined() { return userDefined; }\r
+ virtual TQualifierList& getQualifier() { return qualifier; }\r
+protected:\r
+ TIntermSequence sequence;\r
+ TQualifierList qualifier;\r
+ TString name;\r
+ bool userDefined; // used for user defined function names\r
+};\r
+\r
+//\r
+// For if tests. Simplified since there is no switch statement.\r
+//\r
+class TIntermSelection : public TIntermTyped {\r
+public:\r
+ TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB) :\r
+ TIntermTyped(TType(EbtVoid)), condition(cond), trueBlock(trueB), falseBlock(falseB) {}\r
+ TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, TType type) :\r
+ TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB) {}\r
+ virtual void traverse(TIntermTraverser*);\r
+ virtual TIntermNode* getCondition() const { return condition; }\r
+ virtual TIntermNode* getTrueBlock() const { return trueBlock; }\r
+ virtual TIntermNode* getFalseBlock() const { return falseBlock; }\r
+ virtual TIntermSelection* getAsSelectionNode() { return this; }\r
+protected:\r
+ TIntermTyped* condition;\r
+ TIntermNode* trueBlock;\r
+ TIntermNode* falseBlock;\r
+};\r
+\r
+//\r
+// For traversing the tree. User should derive from this, \r
+// put their traversal specific data in it, and then pass\r
+// it to a Traverse method.\r
+//\r
+// When using this, just fill in the methods for nodes you want visited.\r
+// Return false from a pre-visit to skip visiting that node's subtree.\r
+//\r
+class TIntermTraverser {\r
+public:\r
+ POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)\r
+\r
+ TIntermTraverser() : \r
+ visitSymbol(0), \r
+ visitConstantUnion(0),\r
+ visitBinary(0),\r
+ visitUnary(0),\r
+ visitSelection(0),\r
+ visitAggregate(0),\r
+ visitLoop(0),\r
+ visitBranch(0),\r
+ depth(0),\r
+ preVisit(true),\r
+ postVisit(false),\r
+ rightToLeft(false) {}\r
+\r
+ void (*visitSymbol)(TIntermSymbol*, TIntermTraverser*);\r
+ void (*visitConstantUnion)(TIntermConstantUnion*, TIntermTraverser*);\r
+ bool (*visitBinary)(bool preVisit, TIntermBinary*, TIntermTraverser*);\r
+ bool (*visitUnary)(bool preVisit, TIntermUnary*, TIntermTraverser*);\r
+ bool (*visitSelection)(bool preVisit, TIntermSelection*, TIntermTraverser*);\r
+ bool (*visitAggregate)(bool preVisit, TIntermAggregate*, TIntermTraverser*);\r
+ bool (*visitLoop)(bool preVisit, TIntermLoop*, TIntermTraverser*);\r
+ bool (*visitBranch)(bool preVisit, TIntermBranch*, TIntermTraverser*);\r
+\r
+ int depth;\r
+ bool preVisit;\r
+ bool postVisit;\r
+ bool rightToLeft;\r
+};\r
+\r
+#endif // __INTERMEDIATE_H\r
--- /dev/null
+#line 2 "Gen_glslang.cpp"\r
+/* A lexical scanner generated by flex */\r
+\r
+/* Scanner skeleton version:\r
+ * $Header: /home/krh/git/sync/mesa-cvs-repo/Mesa/src/mesa/shader/slang/MachineIndependent/Gen_glslang.cpp,v 1.1 2005/01/17 16:01:49 michal Exp $\r
+ */\r
+\r
+#define FLEX_SCANNER\r
+#define YY_FLEX_MAJOR_VERSION 2\r
+#define YY_FLEX_MINOR_VERSION 5\r
+\r
+#include <stdio.h>\r
+\r
+\r
+/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */\r
+#ifdef c_plusplus\r
+#ifndef __cplusplus\r
+#define __cplusplus\r
+#endif\r
+#endif\r
+\r
+\r
+#ifdef __cplusplus\r
+\r
+#include <stdlib.h>\r
+#include <unistd.h>\r
+\r
+/* Use prototypes in function declarations. */\r
+#define YY_USE_PROTOS\r
+\r
+/* The "const" storage-class-modifier is valid. */\r
+#define YY_USE_CONST\r
+\r
+#else /* ! __cplusplus */\r
+\r
+#if __STDC__\r
+\r
+#define YY_USE_PROTOS\r
+#define YY_USE_CONST\r
+\r
+#endif /* __STDC__ */\r
+#endif /* ! __cplusplus */\r
+\r
+#ifdef __TURBOC__\r
+ #pragma warn -rch\r
+ #pragma warn -use\r
+#include <io.h>\r
+#include <stdlib.h>\r
+#define YY_USE_CONST\r
+#define YY_USE_PROTOS\r
+#endif\r
+\r
+#ifdef YY_USE_CONST\r
+#define yyconst const\r
+#else\r
+#define yyconst\r
+#endif\r
+\r
+\r
+#ifdef YY_USE_PROTOS\r
+#define YY_PROTO(proto) proto\r
+#else\r
+#define YY_PROTO(proto) ()\r
+#endif\r
+\r
+/* Returned upon end-of-file. */\r
+#define YY_NULL 0\r
+\r
+/* Promotes a possibly negative, possibly signed char to an unsigned\r
+ * integer for use as an array index. If the signed char is negative,\r
+ * we want to instead treat it as an 8-bit unsigned char, hence the\r
+ * double cast.\r
+ */\r
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)\r
+\r
+/* Enter a start condition. This macro really ought to take a parameter,\r
+ * but we do it the disgusting crufty way forced on us by the ()-less\r
+ * definition of BEGIN.\r
+ */\r
+#define BEGIN yy_start = 1 + 2 *\r
+\r
+/* Translate the current start state into a value that can be later handed\r
+ * to BEGIN to return to the state. The YYSTATE alias is for lex\r
+ * compatibility.\r
+ */\r
+#define YY_START ((yy_start - 1) / 2)\r
+#define YYSTATE YY_START\r
+\r
+/* Action number for EOF rule of a given start state. */\r
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)\r
+\r
+/* Special action meaning "start processing a new file". */\r
+#define YY_NEW_FILE yyrestart( yyin )\r
+\r
+#define YY_END_OF_BUFFER_CHAR 0\r
+\r
+/* Size of default input buffer. */\r
+#define YY_BUF_SIZE 16384\r
+\r
+typedef struct yy_buffer_state *YY_BUFFER_STATE;\r
+\r
+extern int yyleng;\r
+extern FILE *yyin, *yyout;\r
+\r
+#define EOB_ACT_CONTINUE_SCAN 0\r
+#define EOB_ACT_END_OF_FILE 1\r
+#define EOB_ACT_LAST_MATCH 2\r
+\r
+/* The funky do-while in the following #define is used to turn the definition\r
+ * int a single C statement (which needs a semi-colon terminator). This\r
+ * avoids problems with code like:\r
+ *\r
+ * if ( condition_holds )\r
+ * yyless( 5 );\r
+ * else\r
+ * do_something_else();\r
+ *\r
+ * Prior to using the do-while the compiler would get upset at the\r
+ * "else" because it interpreted the "if" statement as being all\r
+ * done when it reached the ';' after the yyless() call.\r
+ */\r
+\r
+/* Return all but the first 'n' matched characters back to the input stream. */\r
+\r
+#define yyless(n) \\r
+ do \\r
+ { \\r
+ /* Undo effects of setting up yytext. */ \\r
+ *yy_cp = yy_hold_char; \\r
+ yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \\r
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \\r
+ } \\r
+ while ( 0 )\r
+\r
+#define unput(c) yyunput( c, yytext_ptr )\r
+\r
+/* The following is because we cannot portably get our hands on size_t\r
+ * (without autoconf's help, which isn't available because we want\r
+ * flex-generated scanners to compile on their own).\r
+ */\r
+typedef unsigned int yy_size_t;\r
+\r
+\r
+struct yy_buffer_state\r
+ {\r
+ FILE *yy_input_file;\r
+\r
+ char *yy_ch_buf; /* input buffer */\r
+ char *yy_buf_pos; /* current position in input buffer */\r
+\r
+ /* Size of input buffer in bytes, not including room for EOB\r
+ * characters.\r
+ */\r
+ yy_size_t yy_buf_size;\r
+\r
+ /* Number of characters read into yy_ch_buf, not including EOB\r
+ * characters.\r
+ */\r
+ int yy_n_chars;\r
+\r
+ /* Whether we "own" the buffer - i.e., we know we created it,\r
+ * and can realloc() it to grow it, and should free() it to\r
+ * delete it.\r
+ */\r
+ int yy_is_our_buffer;\r
+\r
+ /* Whether this is an "interactive" input source; if so, and\r
+ * if we're using stdio for input, then we want to use getc()\r
+ * instead of fread(), to make sure we stop fetching input after\r
+ * each newline.\r
+ */\r
+ int yy_is_interactive;\r
+\r
+ /* Whether we're considered to be at the beginning of a line.\r
+ * If so, '^' rules will be active on the next match, otherwise\r
+ * not.\r
+ */\r
+ int yy_at_bol;\r
+\r
+ /* Whether to try to fill the input buffer when we reach the\r
+ * end of it.\r
+ */\r
+ int yy_fill_buffer;\r
+\r
+ int yy_buffer_status;\r
+#define YY_BUFFER_NEW 0\r
+#define YY_BUFFER_NORMAL 1\r
+ /* When an EOF's been seen but there's still some text to process\r
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we\r
+ * shouldn't try reading from the input source any more. We might\r
+ * still have a bunch of tokens to match, though, because of\r
+ * possible backing-up.\r
+ *\r
+ * When we actually see the EOF, we change the status to "new"\r
+ * (via yyrestart()), so that the user can continue scanning by\r
+ * just pointing yyin at a new input file.\r
+ */\r
+#define YY_BUFFER_EOF_PENDING 2\r
+ };\r
+\r
+static YY_BUFFER_STATE yy_current_buffer = 0;\r
+\r
+/* We provide macros for accessing buffer states in case in the\r
+ * future we want to put the buffer states in a more general\r
+ * "scanner state".\r
+ */\r
+#define YY_CURRENT_BUFFER yy_current_buffer\r
+\r
+\r
+/* yy_hold_char holds the character lost when yytext is formed. */\r
+static char yy_hold_char;\r
+\r
+static int yy_n_chars; /* number of characters read into yy_ch_buf */\r
+\r
+\r
+int yyleng;\r
+\r
+/* Points to current character in buffer. */\r
+static char *yy_c_buf_p = (char *) 0;\r
+static int yy_init = 1; /* whether we need to initialize */\r
+static int yy_start = 0; /* start state number */\r
+\r
+/* Flag which is used to allow yywrap()'s to do buffer switches\r
+ * instead of setting up a fresh yyin. A bit of a hack ...\r
+ */\r
+static int yy_did_buffer_switch_on_eof;\r
+\r
+void yyrestart YY_PROTO(( FILE *input_file ));\r
+\r
+void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));\r
+void yy_load_buffer_state YY_PROTO(( void ));\r
+YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));\r
+void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));\r
+void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));\r
+void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b ));\r
+#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )\r
+\r
+YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size ));\r
+YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *str ));\r
+YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len ));\r
+\r
+static void *yy_flex_alloc YY_PROTO(( yy_size_t ));\r
+static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));\r
+static void yy_flex_free YY_PROTO(( void * ));\r
+\r
+#define yy_new_buffer yy_create_buffer\r
+\r
+#define yy_set_interactive(is_interactive) \\r
+ { \\r
+ if ( ! yy_current_buffer ) \\r
+ yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \\r
+ yy_current_buffer->yy_is_interactive = is_interactive; \\r
+ }\r
+\r
+#define yy_set_bol(at_bol) \\r
+ { \\r
+ if ( ! yy_current_buffer ) \\r
+ yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \\r
+ yy_current_buffer->yy_at_bol = at_bol; \\r
+ }\r
+\r
+#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)\r
+\r
+\r
+#define yywrap() 1\r
+#define YY_SKIP_YYWRAP\r
+typedef unsigned char YY_CHAR;\r
+FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;\r
+typedef int yy_state_type;\r
+extern char *yytext;\r
+#define yytext_ptr yytext\r
+\r
+static yy_state_type yy_get_previous_state YY_PROTO(( void ));\r
+static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));\r
+static int yy_get_next_buffer YY_PROTO(( void ));\r
+static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));\r
+\r
+/* Done after the current pattern has been matched and before the\r
+ * corresponding action - sets up yytext.\r
+ */\r
+#define YY_DO_BEFORE_ACTION \\r
+ yytext_ptr = yy_bp; \\r
+ yyleng = (int) (yy_cp - yy_bp); \\r
+ yy_hold_char = *yy_cp; \\r
+ *yy_cp = '\0'; \\r
+ yy_c_buf_p = yy_cp;\r
+\r
+#define YY_NUM_RULES 144\r
+#define YY_END_OF_BUFFER 145\r
+static yyconst short int yy_accept[410] =\r
+ { 0,\r
+ 0, 0, 0, 0, 145, 143, 142, 142, 127, 133,\r
+ 138, 122, 123, 131, 130, 119, 128, 126, 132, 90,\r
+ 90, 120, 116, 134, 121, 135, 139, 86, 124, 125,\r
+ 137, 86, 86, 86, 86, 86, 86, 86, 86, 86,\r
+ 86, 86, 86, 86, 86, 86, 86, 86, 86, 86,\r
+ 86, 117, 136, 118, 129, 141, 144, 143, 140, 113,\r
+ 99, 118, 107, 102, 97, 105, 95, 106, 96, 93,\r
+ 94, 0, 98, 92, 88, 89, 0, 0, 90, 125,\r
+ 117, 124, 114, 110, 112, 111, 115, 86, 103, 109,\r
+ 86, 86, 86, 86, 86, 86, 86, 86, 86, 86,\r
+\r
+ 8, 86, 86, 86, 86, 86, 86, 86, 86, 86,\r
+ 86, 86, 86, 11, 13, 86, 86, 86, 86, 86,\r
+ 86, 86, 86, 86, 86, 86, 86, 86, 86, 86,\r
+ 86, 86, 86, 86, 86, 86, 86, 86, 86, 104,\r
+ 108, 140, 0, 0, 1, 92, 0, 0, 91, 87,\r
+ 100, 101, 43, 86, 86, 86, 86, 86, 86, 86,\r
+ 86, 86, 86, 86, 86, 86, 86, 86, 86, 86,\r
+ 9, 86, 86, 86, 86, 86, 86, 86, 17, 86,\r
+ 86, 86, 86, 86, 14, 86, 86, 86, 86, 86,\r
+ 86, 86, 86, 86, 86, 86, 86, 86, 86, 86,\r
+\r
+ 86, 86, 86, 86, 86, 86, 0, 93, 0, 92,\r
+ 86, 19, 86, 86, 83, 86, 86, 86, 86, 86,\r
+ 86, 86, 12, 46, 86, 86, 86, 86, 86, 51,\r
+ 65, 86, 86, 86, 86, 86, 86, 62, 24, 25,\r
+ 26, 86, 86, 86, 86, 86, 86, 86, 86, 86,\r
+ 86, 86, 86, 86, 49, 20, 86, 86, 86, 86,\r
+ 86, 86, 27, 28, 29, 18, 86, 86, 86, 6,\r
+ 33, 34, 35, 44, 3, 86, 86, 86, 86, 76,\r
+ 77, 78, 86, 21, 66, 16, 73, 74, 75, 70,\r
+ 71, 72, 86, 15, 68, 86, 30, 31, 32, 86,\r
+\r
+ 86, 86, 86, 86, 86, 86, 63, 86, 86, 86,\r
+ 86, 86, 86, 86, 45, 86, 85, 86, 86, 10,\r
+ 86, 86, 86, 86, 64, 59, 54, 86, 86, 86,\r
+ 69, 50, 57, 23, 86, 82, 58, 42, 52, 86,\r
+ 86, 86, 86, 86, 86, 86, 86, 53, 22, 86,\r
+ 86, 86, 86, 86, 86, 47, 4, 86, 5, 86,\r
+ 86, 7, 60, 86, 86, 55, 86, 86, 86, 86,\r
+ 48, 67, 56, 2, 61, 84, 36, 37, 38, 86,\r
+ 86, 86, 86, 86, 86, 86, 86, 86, 86, 39,\r
+ 86, 86, 86, 86, 86, 79, 86, 80, 86, 86,\r
+\r
+ 86, 40, 86, 41, 86, 86, 86, 81, 0\r
+ } ;\r
+\r
+static yyconst int yy_ec[256] =\r
+ { 0,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,\r
+ 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 2, 4, 1, 1, 1, 5, 6, 1, 7,\r
+ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,\r
+ 18, 19, 20, 20, 20, 21, 21, 22, 23, 24,\r
+ 25, 26, 27, 1, 28, 28, 29, 30, 31, 28,\r
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,\r
+ 32, 33, 34, 32, 32, 32, 32, 35, 32, 32,\r
+ 36, 1, 37, 38, 32, 1, 39, 40, 41, 42,\r
+\r
+ 43, 44, 45, 46, 47, 32, 48, 49, 50, 51,\r
+ 52, 53, 32, 54, 55, 56, 57, 58, 59, 60,\r
+ 61, 62, 63, 64, 65, 66, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1\r
+ } ;\r
+\r
+static yyconst int yy_meta[67] =\r
+ { 0,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 2, 1, 3, 3, 3, 3, 3, 3,\r
+ 3, 1, 1, 1, 1, 1, 1, 4, 4, 4,\r
+ 3, 5, 5, 5, 5, 1, 1, 1, 4, 4,\r
+ 4, 4, 3, 4, 5, 5, 5, 5, 5, 5,\r
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,\r
+ 5, 5, 1, 1, 1, 1\r
+ } ;\r
+\r
+static yyconst short int yy_base[416] =\r
+ { 0,\r
+ 0, 0, 66, 0, 607, 608, 608, 608, 581, 108,\r
+ 129, 608, 608, 580, 126, 608, 125, 123, 138, 151,\r
+ 142, 578, 608, 152, 578, 120, 608, 0, 608, 608,\r
+ 123, 103, 126, 140, 144, 139, 154, 550, 117, 156,\r
+ 549, 561, 110, 542, 126, 555, 169, 175, 154, 174,\r
+ 551, 608, 156, 608, 608, 608, 608, 582, 0, 608,\r
+ 608, 608, 608, 608, 608, 608, 608, 608, 608, 222,\r
+ 608, 592, 608, 229, 162, 220, 258, 0, 221, 608,\r
+ 608, 608, 569, 608, 608, 608, 568, 0, 608, 608,\r
+ 542, 535, 538, 546, 545, 532, 547, 534, 540, 528,\r
+\r
+ 525, 538, 525, 522, 522, 528, 516, 523, 520, 530,\r
+ 516, 522, 527, 0, 205, 526, 517, 511, 516, 518,\r
+ 508, 522, 522, 505, 510, 507, 496, 156, 510, 506,\r
+ 508, 497, 500, 172, 505, 497, 509, 183, 502, 608,\r
+ 608, 0, 270, 545, 608, 277, 294, 306, 313, 0,\r
+ 608, 608, 0, 493, 497, 506, 503, 487, 487, 168,\r
+ 502, 499, 499, 497, 494, 486, 492, 479, 490, 493,\r
+ 0, 490, 478, 485, 487, 480, 469, 468, 481, 482,\r
+ 477, 282, 478, 469, 466, 470, 468, 459, 462, 460,\r
+ 470, 456, 454, 454, 456, 453, 464, 463, 215, 458,\r
+\r
+ 453, 442, 299, 460, 462, 451, 320, 327, 334, 341,\r
+ 452, 0, 450, 346, 0, 442, 440, 448, 437, 454,\r
+ 443, 349, 0, 0, 437, 447, 447, 432, 352, 0,\r
+ 0, 355, 436, 430, 429, 430, 358, 0, 0, 0,\r
+ 0, 428, 433, 424, 437, 432, 424, 428, 420, 423,\r
+ 427, 432, 431, 422, 0, 0, 428, 417, 417, 422,\r
+ 421, 418, 0, 0, 0, 0, 408, 420, 422, 0,\r
+ 0, 0, 0, 0, 0, 410, 411, 405, 415, 0,\r
+ 0, 0, 406, 0, 0, 0, 0, 0, 0, 0,\r
+ 0, 0, 413, 0, 0, 411, 0, 0, 0, 401,\r
+\r
+ 406, 396, 409, 409, 398, 405, 0, 403, 405, 389,\r
+ 398, 404, 399, 387, 0, 389, 0, 388, 391, 0,\r
+ 380, 379, 379, 392, 0, 394, 0, 393, 392, 379,\r
+ 0, 0, 0, 0, 375, 0, 0, 0, 0, 372,\r
+ 383, 376, 382, 379, 374, 366, 378, 0, 0, 371,\r
+ 378, 377, 374, 362, 373, 0, 0, 373, 0, 371,\r
+ 370, 0, 0, 369, 368, 0, 380, 379, 360, 332,\r
+ 0, 0, 0, 0, 0, 0, 354, 222, 354, 346,\r
+ 339, 341, 337, 339, 338, 280, 266, 266, 262, 0,\r
+ 260, 228, 241, 225, 219, 235, 214, 0, 203, 189,\r
+\r
+ 172, 0, 165, 0, 156, 108, 94, 0, 608, 390,\r
+ 391, 394, 399, 403, 404\r
+ } ;\r
+\r
+static yyconst short int yy_def[416] =\r
+ { 0,\r
+ 409, 1, 409, 3, 409, 409, 409, 409, 409, 409,\r
+ 409, 409, 409, 409, 409, 409, 409, 409, 409, 409,\r
+ 410, 409, 409, 409, 409, 409, 409, 411, 409, 409,\r
+ 409, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 409, 409, 409, 409, 409, 409, 409, 412, 409,\r
+ 409, 409, 409, 409, 409, 409, 409, 409, 409, 409,\r
+ 409, 413, 409, 409, 20, 414, 409, 415, 410, 409,\r
+ 409, 409, 409, 409, 409, 409, 409, 411, 409, 409,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 409,\r
+ 409, 412, 409, 413, 409, 409, 409, 409, 409, 415,\r
+ 409, 409, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+\r
+ 411, 411, 411, 411, 411, 411, 409, 409, 409, 409,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 411, 411,\r
+\r
+ 411, 411, 411, 411, 411, 411, 411, 411, 0, 409,\r
+ 409, 409, 409, 409, 409\r
+ } ;\r
+\r
+static yyconst short int yy_nxt[675] =\r
+ { 0,\r
+ 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,\r
+ 16, 17, 18, 19, 20, 21, 21, 21, 21, 21,\r
+ 21, 22, 23, 24, 25, 26, 27, 28, 28, 28,\r
+ 28, 28, 28, 28, 28, 29, 30, 31, 32, 33,\r
+ 34, 35, 36, 37, 38, 39, 40, 28, 41, 42,\r
+ 43, 44, 45, 46, 47, 48, 49, 50, 51, 28,\r
+ 28, 28, 52, 53, 54, 55, 6, 56, 57, 6,\r
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 58,\r
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,\r
+ 6, 6, 6, 59, 59, 59, 59, 59, 59, 59,\r
+\r
+ 59, 6, 6, 6, 59, 59, 59, 59, 59, 59,\r
+ 59, 59, 59, 59, 59, 59, 59, 59, 59, 59,\r
+ 59, 59, 59, 59, 59, 59, 59, 59, 6, 6,\r
+ 6, 6, 61, 62, 63, 66, 68, 70, 70, 70,\r
+ 70, 70, 70, 70, 86, 87, 71, 89, 119, 69,\r
+ 67, 72, 408, 64, 74, 112, 81, 91, 92, 407,\r
+ 90, 120, 73, 74, 122, 75, 75, 75, 75, 75,\r
+ 75, 76, 77, 82, 113, 83, 84, 93, 96, 94,\r
+ 140, 77, 123, 95, 77, 78, 99, 103, 97, 104,\r
+ 100, 98, 106, 77, 192, 101, 409, 406, 105, 114,\r
+\r
+ 107, 102, 108, 405, 134, 109, 115, 125, 135, 193,\r
+ 78, 110, 136, 116, 126, 127, 137, 130, 199, 141,\r
+ 131, 409, 217, 218, 128, 138, 200, 129, 132, 204,\r
+ 404, 205, 74, 74, 403, 133, 70, 70, 70, 70,\r
+ 70, 70, 70, 146, 146, 146, 146, 146, 146, 146,\r
+ 77, 77, 143, 176, 382, 383, 177, 178, 258, 147,\r
+ 179, 402, 77, 77, 143, 401, 259, 148, 400, 148,\r
+ 399, 147, 149, 149, 149, 149, 149, 149, 149, 207,\r
+ 398, 207, 397, 396, 208, 208, 208, 208, 208, 208,\r
+ 208, 146, 146, 146, 146, 146, 146, 146, 239, 240,\r
+\r
+ 241, 395, 394, 209, 393, 209, 392, 147, 210, 210,\r
+ 210, 210, 210, 210, 210, 263, 264, 265, 391, 147,\r
+ 149, 149, 149, 149, 149, 149, 149, 149, 149, 149,\r
+ 149, 149, 149, 149, 208, 208, 208, 208, 208, 208,\r
+ 208, 208, 208, 208, 208, 208, 208, 208, 210, 210,\r
+ 210, 210, 210, 210, 210, 210, 210, 210, 210, 210,\r
+ 210, 210, 271, 272, 273, 280, 281, 282, 287, 288,\r
+ 289, 290, 291, 292, 297, 298, 299, 367, 368, 369,\r
+ 390, 389, 388, 387, 386, 385, 384, 381, 380, 379,\r
+ 370, 79, 79, 88, 88, 88, 142, 142, 142, 144,\r
+\r
+ 144, 144, 144, 144, 76, 76, 150, 150, 378, 377,\r
+ 376, 375, 374, 373, 372, 371, 366, 365, 364, 363,\r
+ 362, 361, 360, 359, 358, 357, 356, 355, 354, 353,\r
+ 352, 351, 350, 349, 348, 347, 346, 345, 344, 343,\r
+ 342, 341, 340, 339, 338, 337, 336, 335, 334, 333,\r
+ 332, 331, 330, 329, 328, 327, 326, 325, 324, 323,\r
+ 322, 321, 320, 319, 318, 317, 316, 315, 314, 313,\r
+ 312, 311, 310, 309, 308, 307, 306, 305, 304, 303,\r
+ 302, 301, 300, 296, 295, 294, 293, 286, 285, 284,\r
+ 283, 279, 278, 277, 276, 275, 274, 270, 269, 268,\r
+\r
+ 267, 266, 262, 261, 260, 257, 256, 255, 254, 253,\r
+ 252, 251, 250, 249, 248, 247, 246, 245, 244, 243,\r
+ 242, 238, 237, 236, 235, 234, 233, 232, 231, 230,\r
+ 229, 228, 227, 226, 225, 224, 223, 222, 221, 220,\r
+ 219, 216, 215, 214, 213, 212, 211, 145, 206, 203,\r
+ 202, 201, 198, 197, 196, 195, 194, 191, 190, 189,\r
+ 188, 187, 186, 185, 184, 183, 182, 181, 180, 175,\r
+ 174, 173, 172, 171, 170, 169, 168, 167, 166, 165,\r
+ 164, 163, 162, 161, 160, 159, 158, 157, 156, 155,\r
+ 154, 153, 152, 151, 145, 72, 139, 124, 121, 118,\r
+\r
+ 117, 111, 85, 80, 65, 60, 409, 5, 409, 409,\r
+ 409, 409, 409, 409, 409, 409, 409, 409, 409, 409,\r
+ 409, 409, 409, 409, 409, 409, 409, 409, 409, 409,\r
+ 409, 409, 409, 409, 409, 409, 409, 409, 409, 409,\r
+ 409, 409, 409, 409, 409, 409, 409, 409, 409, 409,\r
+ 409, 409, 409, 409, 409, 409, 409, 409, 409, 409,\r
+ 409, 409, 409, 409, 409, 409, 409, 409, 409, 409,\r
+ 409, 409, 409, 409\r
+ } ;\r
+\r
+static yyconst short int yy_chk[675] =\r
+ { 0,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 3, 3, 3, 3,\r
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,\r
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,\r
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,\r
+\r
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,\r
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,\r
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,\r
+ 3, 3, 10, 10, 11, 15, 17, 18, 18, 18,\r
+ 18, 18, 18, 18, 26, 26, 19, 31, 43, 17,\r
+ 15, 19, 407, 11, 21, 39, 24, 32, 32, 406,\r
+ 31, 43, 19, 20, 45, 20, 20, 20, 20, 20,\r
+ 20, 20, 21, 24, 39, 24, 24, 33, 34, 33,\r
+ 53, 20, 45, 33, 21, 20, 35, 36, 34, 36,\r
+ 35, 34, 37, 20, 128, 35, 75, 405, 36, 40,\r
+\r
+ 37, 35, 37, 403, 49, 37, 40, 47, 49, 128,\r
+ 20, 37, 50, 40, 47, 47, 50, 48, 134, 53,\r
+ 48, 75, 160, 160, 47, 50, 134, 47, 48, 138,\r
+ 401, 138, 76, 79, 400, 48, 70, 70, 70, 70,\r
+ 70, 70, 70, 74, 74, 74, 74, 74, 74, 74,\r
+ 76, 79, 70, 115, 378, 378, 115, 115, 199, 74,\r
+ 115, 399, 76, 79, 70, 397, 199, 77, 396, 77,\r
+ 395, 74, 77, 77, 77, 77, 77, 77, 77, 143,\r
+ 394, 143, 393, 392, 143, 143, 143, 143, 143, 143,\r
+ 143, 146, 146, 146, 146, 146, 146, 146, 182, 182,\r
+\r
+ 182, 391, 389, 147, 388, 147, 387, 146, 147, 147,\r
+ 147, 147, 147, 147, 147, 203, 203, 203, 386, 146,\r
+ 148, 148, 148, 148, 148, 148, 148, 149, 149, 149,\r
+ 149, 149, 149, 149, 207, 207, 207, 207, 207, 207,\r
+ 207, 208, 208, 208, 208, 208, 208, 208, 209, 209,\r
+ 209, 209, 209, 209, 209, 210, 210, 210, 210, 210,\r
+ 210, 210, 214, 214, 214, 222, 222, 222, 229, 229,\r
+ 229, 232, 232, 232, 237, 237, 237, 354, 354, 354,\r
+ 385, 384, 383, 382, 381, 380, 379, 377, 370, 369,\r
+ 354, 410, 410, 411, 411, 411, 412, 412, 412, 413,\r
+\r
+ 413, 413, 413, 413, 414, 414, 415, 415, 368, 367,\r
+ 365, 364, 361, 360, 358, 355, 353, 352, 351, 350,\r
+ 347, 346, 345, 344, 343, 342, 341, 340, 335, 330,\r
+ 329, 328, 326, 324, 323, 322, 321, 319, 318, 316,\r
+ 314, 313, 312, 311, 310, 309, 308, 306, 305, 304,\r
+ 303, 302, 301, 300, 296, 293, 283, 279, 278, 277,\r
+ 276, 269, 268, 267, 262, 261, 260, 259, 258, 257,\r
+ 254, 253, 252, 251, 250, 249, 248, 247, 246, 245,\r
+ 244, 243, 242, 236, 235, 234, 233, 228, 227, 226,\r
+ 225, 221, 220, 219, 218, 217, 216, 213, 211, 206,\r
+\r
+ 205, 204, 202, 201, 200, 198, 197, 196, 195, 194,\r
+ 193, 192, 191, 190, 189, 188, 187, 186, 185, 184,\r
+ 183, 181, 180, 179, 178, 177, 176, 175, 174, 173,\r
+ 172, 170, 169, 168, 167, 166, 165, 164, 163, 162,\r
+ 161, 159, 158, 157, 156, 155, 154, 144, 139, 137,\r
+ 136, 135, 133, 132, 131, 130, 129, 127, 126, 125,\r
+ 124, 123, 122, 121, 120, 119, 118, 117, 116, 113,\r
+ 112, 111, 110, 109, 108, 107, 106, 105, 104, 103,\r
+ 102, 101, 100, 99, 98, 97, 96, 95, 94, 93,\r
+ 92, 91, 87, 83, 72, 58, 51, 46, 44, 42,\r
+\r
+ 41, 38, 25, 22, 14, 9, 5, 409, 409, 409,\r
+ 409, 409, 409, 409, 409, 409, 409, 409, 409, 409,\r
+ 409, 409, 409, 409, 409, 409, 409, 409, 409, 409,\r
+ 409, 409, 409, 409, 409, 409, 409, 409, 409, 409,\r
+ 409, 409, 409, 409, 409, 409, 409, 409, 409, 409,\r
+ 409, 409, 409, 409, 409, 409, 409, 409, 409, 409,\r
+ 409, 409, 409, 409, 409, 409, 409, 409, 409, 409,\r
+ 409, 409, 409, 409\r
+ } ;\r
+\r
+static yy_state_type yy_last_accepting_state;\r
+static char *yy_last_accepting_cpos;\r
+\r
+/* The intent behind this definition is that it'll catch\r
+ * any uses of REJECT which flex missed.\r
+ */\r
+#define REJECT reject_used_but_not_detected\r
+#define yymore() yymore_used_but_not_detected\r
+#define YY_MORE_ADJ 0\r
+char *yytext;\r
+#line 1 ".\\glslang\\MachineIndependent\\glslang.l"\r
+#define INITIAL 0\r
+/*\r
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+*/\r
+/* Based on\r
+ANSI C grammar, Lex specification\r
+\r
+In 1985, Jeff Lee published this Lex specification together with a Yacc \r
+grammar for the April 30, 1985 ANSI C draft. Tom Stockfisch reposted \r
+both to net.sources in 1987; that original, as mentioned in the answer \r
+to question 17.25 of the comp.lang.c FAQ, can be ftp'ed from ftp.uu.net, \r
+file usenet/net.sources/ansi.c.grammar.Z. \r
+\r
+I intend to keep this version as close to the current C Standard grammar \r
+as possible; please let me know if you discover discrepancies. \r
+\r
+Jutta Degener, 1995 \r
+*/\r
+#define YY_NO_UNPUT 1\r
+#line 59 ".\\glslang\\MachineIndependent\\glslang.l"\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include "ParseHelper.h"\r
+#include "glslang_tab.h"\r
+\r
+/* windows only pragma */\r
+#ifdef _MSC_VER\r
+#pragma warning(disable : 4102)\r
+#endif\r
+\r
+int yy_input(char* buf, int max_size);\r
+\r
+#ifdef _WIN32\r
+ extern int yyparse(TParseContext&);\r
+ #define YY_DECL int yylex(YYSTYPE* pyylval, TParseContext& parseContext) \r
+ TSourceLoc yylineno; \r
+#else\r
+ extern int yyparse(void*);\r
+ #define YY_DECL int yylex(YYSTYPE* pyylval, void* parseContextLocal)\r
+ #define parseContext (*((TParseContext*)(parseContextLocal)))\r
+#endif\r
+ \r
+#define YY_INPUT(buf,result,max_size) (result = yy_input(buf, max_size))\r
+\r
+#define YY_NEVER_INTERACTIVE 1\r
+#define FIELDS 1\r
+\r
+#line 729 "Gen_glslang.cpp"\r
+\r
+/* Macros after this point can all be overridden by user definitions in\r
+ * section 1.\r
+ */\r
+\r
+#ifndef YY_SKIP_YYWRAP\r
+#ifdef __cplusplus\r
+extern "C" int yywrap YY_PROTO(( void ));\r
+#else\r
+extern int yywrap YY_PROTO(( void ));\r
+#endif\r
+#endif\r
+\r
+#ifndef YY_NO_UNPUT\r
+static void yyunput YY_PROTO(( int c, char *buf_ptr ));\r
+#endif\r
+\r
+#ifndef yytext_ptr\r
+static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));\r
+#endif\r
+\r
+#ifndef YY_NO_INPUT\r
+#ifdef __cplusplus\r
+static int yyinput YY_PROTO(( void ));\r
+#else\r
+static int input YY_PROTO(( void ));\r
+#endif\r
+#endif\r
+\r
+#if YY_STACK_USED\r
+static int yy_start_stack_ptr = 0;\r
+static int yy_start_stack_depth = 0;\r
+static int *yy_start_stack = 0;\r
+#ifndef YY_NO_PUSH_STATE\r
+static void yy_push_state YY_PROTO(( int new_state ));\r
+#endif\r
+#ifndef YY_NO_POP_STATE\r
+static void yy_pop_state YY_PROTO(( void ));\r
+#endif\r
+#ifndef YY_NO_TOP_STATE\r
+static int yy_top_state YY_PROTO(( void ));\r
+#endif\r
+\r
+#else\r
+#define YY_NO_PUSH_STATE 1\r
+#define YY_NO_POP_STATE 1\r
+#define YY_NO_TOP_STATE 1\r
+#endif\r
+\r
+#ifdef YY_MALLOC_DECL\r
+YY_MALLOC_DECL\r
+#else\r
+#if __STDC__\r
+#ifndef __cplusplus\r
+#include <stdlib.h>\r
+#endif\r
+#else\r
+/* Just try to get by without declaring the routines. This will fail\r
+ * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)\r
+ * or sizeof(void*) != sizeof(int).\r
+ */\r
+#endif\r
+#endif\r
+\r
+/* Amount of stuff to slurp up with each read. */\r
+#ifndef YY_READ_BUF_SIZE\r
+#define YY_READ_BUF_SIZE 8192\r
+#endif\r
+\r
+/* Copy whatever the last rule matched to the standard output. */\r
+\r
+#ifndef ECHO\r
+/* This used to be an fputs(), but since the string might contain NUL's,\r
+ * we now use fwrite().\r
+ */\r
+#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )\r
+#endif\r
+\r
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,\r
+ * is returned in "result".\r
+ */\r
+#ifndef YY_INPUT\r
+#define YY_INPUT(buf,result,max_size) \\r
+ if ( yy_current_buffer->yy_is_interactive ) \\r
+ { \\r
+ int c = '*', n; \\r
+ for ( n = 0; n < max_size && \\r
+ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \\r
+ buf[n] = (char) c; \\r
+ if ( c == '\n' ) \\r
+ buf[n++] = (char) c; \\r
+ if ( c == EOF && ferror( yyin ) ) \\r
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \\r
+ result = n; \\r
+ } \\r
+ else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \\r
+ && ferror( yyin ) ) \\r
+ YY_FATAL_ERROR( "input in flex scanner failed" );\r
+#endif\r
+\r
+/* No semi-colon after return; correct usage is to write "yyterminate();" -\r
+ * we don't want an extra ';' after the "return" because that will cause\r
+ * some compilers to complain about unreachable statements.\r
+ */\r
+#ifndef yyterminate\r
+#define yyterminate() return YY_NULL\r
+#endif\r
+\r
+/* Number of entries by which start-condition stack grows. */\r
+#ifndef YY_START_STACK_INCR\r
+#define YY_START_STACK_INCR 25\r
+#endif\r
+\r
+/* Report a fatal error. */\r
+#ifndef YY_FATAL_ERROR\r
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )\r
+#endif\r
+\r
+/* Default declaration of generated scanner - a define so the user can\r
+ * easily add parameters.\r
+ */\r
+#ifndef YY_DECL\r
+#define YY_DECL int yylex YY_PROTO(( void ))\r
+#endif\r
+\r
+/* Code executed at the beginning of each rule, after yytext and yyleng\r
+ * have been set up.\r
+ */\r
+#ifndef YY_USER_ACTION\r
+#define YY_USER_ACTION\r
+#endif\r
+\r
+/* Code executed at the end of each rule. */\r
+#ifndef YY_BREAK\r
+#define YY_BREAK break;\r
+#endif\r
+\r
+#define YY_RULE_SETUP \\r
+ YY_USER_ACTION\r
+\r
+YY_DECL\r
+ {\r
+ register yy_state_type yy_current_state;\r
+ register char *yy_cp, *yy_bp;\r
+ register int yy_act;\r
+\r
+#line 91 ".\\glslang\\MachineIndependent\\glslang.l"\r
+\r
+#line 878 "Gen_glslang.cpp"\r
+\r
+ if ( yy_init )\r
+ {\r
+ yy_init = 0;\r
+\r
+#ifdef YY_USER_INIT\r
+ YY_USER_INIT;\r
+#endif\r
+\r
+ if ( ! yy_start )\r
+ yy_start = 1; /* first start state */\r
+\r
+ if ( ! yyin )\r
+ yyin = stdin;\r
+\r
+ if ( ! yyout )\r
+ yyout = stdout;\r
+\r
+ if ( ! yy_current_buffer )\r
+ yy_current_buffer =\r
+ yy_create_buffer( yyin, YY_BUF_SIZE );\r
+\r
+ yy_load_buffer_state();\r
+ }\r
+\r
+ while ( 1 ) /* loops until end-of-file is reached */\r
+ {\r
+ yy_cp = yy_c_buf_p;\r
+\r
+ /* Support of yytext. */\r
+ *yy_cp = yy_hold_char;\r
+\r
+ /* yy_bp points to the position in yy_ch_buf of the start of\r
+ * the current run.\r
+ */\r
+ yy_bp = yy_cp;\r
+\r
+ yy_current_state = yy_start;\r
+yy_match:\r
+ do\r
+ {\r
+ register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];\r
+ if ( yy_accept[yy_current_state] )\r
+ {\r
+ yy_last_accepting_state = yy_current_state;\r
+ yy_last_accepting_cpos = yy_cp;\r
+ }\r
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )\r
+ {\r
+ yy_current_state = (int) yy_def[yy_current_state];\r
+ if ( yy_current_state >= 410 )\r
+ yy_c = yy_meta[(unsigned int) yy_c];\r
+ }\r
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];\r
+ ++yy_cp;\r
+ }\r
+ while ( yy_base[yy_current_state] != 608 );\r
+\r
+yy_find_action:\r
+ yy_act = yy_accept[yy_current_state];\r
+ if ( yy_act == 0 )\r
+ { /* have to back up */\r
+ yy_cp = yy_last_accepting_cpos;\r
+ yy_current_state = yy_last_accepting_state;\r
+ yy_act = yy_accept[yy_current_state];\r
+ }\r
+\r
+ YY_DO_BEFORE_ACTION;\r
+\r
+\r
+do_action: /* This label is used only to access EOF actions. */\r
+\r
+\r
+ switch ( yy_act )\r
+ { /* beginning of action switch */\r
+ case 0: /* must back up */\r
+ /* undo the effects of YY_DO_BEFORE_ACTION */\r
+ *yy_cp = yy_hold_char;\r
+ yy_cp = yy_last_accepting_cpos;\r
+ yy_current_state = yy_last_accepting_state;\r
+ goto yy_find_action;\r
+\r
+case 1:\r
+YY_RULE_SETUP\r
+#line 92 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ /* ?? carriage and/or line-feed? */ };\r
+ YY_BREAK\r
+case 2:\r
+YY_RULE_SETUP\r
+#line 94 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(ATTRIBUTE); }\r
+ YY_BREAK\r
+case 3:\r
+YY_RULE_SETUP\r
+#line 95 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(CONST_QUAL); }\r
+ YY_BREAK\r
+case 4:\r
+YY_RULE_SETUP\r
+#line 96 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(UNIFORM); }\r
+ YY_BREAK\r
+case 5:\r
+YY_RULE_SETUP\r
+#line 97 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(VARYING); }\r
+ YY_BREAK\r
+case 6:\r
+YY_RULE_SETUP\r
+#line 99 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(BREAK); }\r
+ YY_BREAK\r
+case 7:\r
+YY_RULE_SETUP\r
+#line 100 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(CONTINUE); }\r
+ YY_BREAK\r
+case 8:\r
+YY_RULE_SETUP\r
+#line 101 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(DO); }\r
+ YY_BREAK\r
+case 9:\r
+YY_RULE_SETUP\r
+#line 102 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(FOR); }\r
+ YY_BREAK\r
+case 10:\r
+YY_RULE_SETUP\r
+#line 103 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(WHILE); }\r
+ YY_BREAK\r
+case 11:\r
+YY_RULE_SETUP\r
+#line 105 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(IF); }\r
+ YY_BREAK\r
+case 12:\r
+YY_RULE_SETUP\r
+#line 106 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(ELSE); }\r
+ YY_BREAK\r
+case 13:\r
+YY_RULE_SETUP\r
+#line 108 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(IN_QUAL); }\r
+ YY_BREAK\r
+case 14:\r
+YY_RULE_SETUP\r
+#line 109 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(OUT_QUAL); }\r
+ YY_BREAK\r
+case 15:\r
+YY_RULE_SETUP\r
+#line 110 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(INOUT_QUAL); }\r
+ YY_BREAK\r
+case 16:\r
+YY_RULE_SETUP\r
+#line 112 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(FLOAT_TYPE); }\r
+ YY_BREAK\r
+case 17:\r
+YY_RULE_SETUP\r
+#line 113 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(INT_TYPE); }\r
+ YY_BREAK\r
+case 18:\r
+YY_RULE_SETUP\r
+#line 114 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(VOID_TYPE); }\r
+ YY_BREAK\r
+case 19:\r
+YY_RULE_SETUP\r
+#line 115 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(BOOL_TYPE); }\r
+ YY_BREAK\r
+case 20:\r
+YY_RULE_SETUP\r
+#line 116 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; pyylval->lex.b = true; return(BOOLCONSTANT); }\r
+ YY_BREAK\r
+case 21:\r
+YY_RULE_SETUP\r
+#line 117 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; pyylval->lex.b = false; return(BOOLCONSTANT); }\r
+ YY_BREAK\r
+case 22:\r
+YY_RULE_SETUP\r
+#line 119 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(DISCARD); }\r
+ YY_BREAK\r
+case 23:\r
+YY_RULE_SETUP\r
+#line 120 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(RETURN); }\r
+ YY_BREAK\r
+case 24:\r
+YY_RULE_SETUP\r
+#line 122 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MATRIX2); }\r
+ YY_BREAK\r
+case 25:\r
+YY_RULE_SETUP\r
+#line 123 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MATRIX3); }\r
+ YY_BREAK\r
+case 26:\r
+YY_RULE_SETUP\r
+#line 124 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MATRIX4); }\r
+ YY_BREAK\r
+case 27:\r
+YY_RULE_SETUP\r
+#line 126 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return (VEC2); }\r
+ YY_BREAK\r
+case 28:\r
+YY_RULE_SETUP\r
+#line 127 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return (VEC3); }\r
+ YY_BREAK\r
+case 29:\r
+YY_RULE_SETUP\r
+#line 128 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return (VEC4); }\r
+ YY_BREAK\r
+case 30:\r
+YY_RULE_SETUP\r
+#line 129 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return (IVEC2); }\r
+ YY_BREAK\r
+case 31:\r
+YY_RULE_SETUP\r
+#line 130 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return (IVEC3); }\r
+ YY_BREAK\r
+case 32:\r
+YY_RULE_SETUP\r
+#line 131 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return (IVEC4); }\r
+ YY_BREAK\r
+case 33:\r
+YY_RULE_SETUP\r
+#line 132 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return (BVEC2); }\r
+ YY_BREAK\r
+case 34:\r
+YY_RULE_SETUP\r
+#line 133 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return (BVEC3); }\r
+ YY_BREAK\r
+case 35:\r
+YY_RULE_SETUP\r
+#line 134 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return (BVEC4); }\r
+ YY_BREAK\r
+case 36:\r
+YY_RULE_SETUP\r
+#line 136 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return SAMPLER1D; }\r
+ YY_BREAK\r
+case 37:\r
+YY_RULE_SETUP\r
+#line 137 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return SAMPLER2D; }\r
+ YY_BREAK\r
+case 38:\r
+YY_RULE_SETUP\r
+#line 138 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return SAMPLER3D; }\r
+ YY_BREAK\r
+case 39:\r
+YY_RULE_SETUP\r
+#line 139 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return SAMPLERCUBE; }\r
+ YY_BREAK\r
+case 40:\r
+YY_RULE_SETUP\r
+#line 140 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return SAMPLER1DSHADOW; }\r
+ YY_BREAK\r
+case 41:\r
+YY_RULE_SETUP\r
+#line 141 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return SAMPLER2DSHADOW; }\r
+ YY_BREAK\r
+case 42:\r
+YY_RULE_SETUP\r
+#line 143 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(STRUCT); }\r
+ YY_BREAK\r
+case 43:\r
+YY_RULE_SETUP\r
+#line 145 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 44:\r
+YY_RULE_SETUP\r
+#line 147 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 45:\r
+YY_RULE_SETUP\r
+#line 148 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 46:\r
+YY_RULE_SETUP\r
+#line 149 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 47:\r
+YY_RULE_SETUP\r
+#line 150 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 48:\r
+YY_RULE_SETUP\r
+#line 151 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 49:\r
+YY_RULE_SETUP\r
+#line 152 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 50:\r
+YY_RULE_SETUP\r
+#line 153 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 51:\r
+YY_RULE_SETUP\r
+#line 155 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 52:\r
+YY_RULE_SETUP\r
+#line 156 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 53:\r
+YY_RULE_SETUP\r
+#line 157 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 54:\r
+YY_RULE_SETUP\r
+#line 159 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 55:\r
+YY_RULE_SETUP\r
+#line 160 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 56:\r
+YY_RULE_SETUP\r
+#line 161 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 57:\r
+YY_RULE_SETUP\r
+#line 162 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 58:\r
+YY_RULE_SETUP\r
+#line 163 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 59:\r
+YY_RULE_SETUP\r
+#line 164 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 60:\r
+YY_RULE_SETUP\r
+#line 165 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 61:\r
+YY_RULE_SETUP\r
+#line 166 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 62:\r
+YY_RULE_SETUP\r
+#line 168 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 63:\r
+YY_RULE_SETUP\r
+#line 169 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 64:\r
+YY_RULE_SETUP\r
+#line 170 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 65:\r
+YY_RULE_SETUP\r
+#line 171 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 66:\r
+YY_RULE_SETUP\r
+#line 172 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 67:\r
+YY_RULE_SETUP\r
+#line 173 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 68:\r
+YY_RULE_SETUP\r
+#line 175 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 69:\r
+YY_RULE_SETUP\r
+#line 176 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 70:\r
+YY_RULE_SETUP\r
+#line 178 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 71:\r
+YY_RULE_SETUP\r
+#line 179 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 72:\r
+YY_RULE_SETUP\r
+#line 180 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 73:\r
+YY_RULE_SETUP\r
+#line 181 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 74:\r
+YY_RULE_SETUP\r
+#line 182 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 75:\r
+YY_RULE_SETUP\r
+#line 183 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 76:\r
+YY_RULE_SETUP\r
+#line 184 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 77:\r
+YY_RULE_SETUP\r
+#line 185 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 78:\r
+YY_RULE_SETUP\r
+#line 186 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 79:\r
+YY_RULE_SETUP\r
+#line 188 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 80:\r
+YY_RULE_SETUP\r
+#line 189 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 81:\r
+YY_RULE_SETUP\r
+#line 190 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 82:\r
+YY_RULE_SETUP\r
+#line 192 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 83:\r
+YY_RULE_SETUP\r
+#line 193 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 84:\r
+YY_RULE_SETUP\r
+#line 195 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 85:\r
+YY_RULE_SETUP\r
+#line 196 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ PaReservedWord(); return 0; }\r
+ YY_BREAK\r
+case 86:\r
+YY_RULE_SETUP\r
+#line 198 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ \r
+ pyylval->lex.line = yylineno; \r
+ pyylval->lex.string = NewPoolTString(yytext); \r
+ return PaIdentOrType(*pyylval->lex.string, parseContext, pyylval->lex.symbol); \r
+}\r
+ YY_BREAK\r
+case 87:\r
+YY_RULE_SETUP\r
+#line 204 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; pyylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); }\r
+ YY_BREAK\r
+case 88:\r
+YY_RULE_SETUP\r
+#line 205 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; pyylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); }\r
+ YY_BREAK\r
+case 89:\r
+YY_RULE_SETUP\r
+#line 206 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.error(yylineno, "Invalid Octal number.", yytext, "", ""); parseContext.recover(); return 0;}\r
+ YY_BREAK\r
+case 90:\r
+YY_RULE_SETUP\r
+#line 207 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; pyylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); }\r
+ YY_BREAK\r
+case 91:\r
+YY_RULE_SETUP\r
+#line 209 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; pyylval->lex.f = static_cast<float>(atof(yytext)); return(FLOATCONSTANT); }\r
+ YY_BREAK\r
+case 92:\r
+YY_RULE_SETUP\r
+#line 210 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; pyylval->lex.f = static_cast<float>(atof(yytext)); return(FLOATCONSTANT); }\r
+ YY_BREAK\r
+case 93:\r
+YY_RULE_SETUP\r
+#line 211 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; pyylval->lex.f = static_cast<float>(atof(yytext)); return(FLOATCONSTANT); }\r
+ YY_BREAK\r
+case 94:\r
+YY_RULE_SETUP\r
+#line 213 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ int ret = PaParseComment(pyylval->lex.line, parseContext); if (!ret) return ret; } \r
+ YY_BREAK\r
+case 95:\r
+YY_RULE_SETUP\r
+#line 215 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(ADD_ASSIGN); }\r
+ YY_BREAK\r
+case 96:\r
+YY_RULE_SETUP\r
+#line 216 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(SUB_ASSIGN); }\r
+ YY_BREAK\r
+case 97:\r
+YY_RULE_SETUP\r
+#line 217 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(MUL_ASSIGN); }\r
+ YY_BREAK\r
+case 98:\r
+YY_RULE_SETUP\r
+#line 218 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(DIV_ASSIGN); }\r
+ YY_BREAK\r
+case 99:\r
+YY_RULE_SETUP\r
+#line 219 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(MOD_ASSIGN); }\r
+ YY_BREAK\r
+case 100:\r
+YY_RULE_SETUP\r
+#line 220 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(LEFT_ASSIGN); }\r
+ YY_BREAK\r
+case 101:\r
+YY_RULE_SETUP\r
+#line 221 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(RIGHT_ASSIGN); }\r
+ YY_BREAK\r
+case 102:\r
+YY_RULE_SETUP\r
+#line 222 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(AND_ASSIGN); }\r
+ YY_BREAK\r
+case 103:\r
+YY_RULE_SETUP\r
+#line 223 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(XOR_ASSIGN); }\r
+ YY_BREAK\r
+case 104:\r
+YY_RULE_SETUP\r
+#line 224 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(OR_ASSIGN); }\r
+ YY_BREAK\r
+case 105:\r
+YY_RULE_SETUP\r
+#line 226 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(INC_OP); }\r
+ YY_BREAK\r
+case 106:\r
+YY_RULE_SETUP\r
+#line 227 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(DEC_OP); }\r
+ YY_BREAK\r
+case 107:\r
+YY_RULE_SETUP\r
+#line 228 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(AND_OP); }\r
+ YY_BREAK\r
+case 108:\r
+YY_RULE_SETUP\r
+#line 229 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(OR_OP); }\r
+ YY_BREAK\r
+case 109:\r
+YY_RULE_SETUP\r
+#line 230 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(XOR_OP); }\r
+ YY_BREAK\r
+case 110:\r
+YY_RULE_SETUP\r
+#line 231 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(LE_OP); }\r
+ YY_BREAK\r
+case 111:\r
+YY_RULE_SETUP\r
+#line 232 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(GE_OP); }\r
+ YY_BREAK\r
+case 112:\r
+YY_RULE_SETUP\r
+#line 233 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(EQ_OP); }\r
+ YY_BREAK\r
+case 113:\r
+YY_RULE_SETUP\r
+#line 234 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(NE_OP); }\r
+ YY_BREAK\r
+case 114:\r
+YY_RULE_SETUP\r
+#line 235 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(LEFT_OP); }\r
+ YY_BREAK\r
+case 115:\r
+YY_RULE_SETUP\r
+#line 236 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(RIGHT_OP); }\r
+ YY_BREAK\r
+case 116:\r
+YY_RULE_SETUP\r
+#line 237 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = false; return(SEMICOLON); }\r
+ YY_BREAK\r
+case 117:\r
+YY_RULE_SETUP\r
+#line 238 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = false; return(LEFT_BRACE); }\r
+ YY_BREAK\r
+case 118:\r
+YY_RULE_SETUP\r
+#line 239 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(RIGHT_BRACE); }\r
+ YY_BREAK\r
+case 119:\r
+YY_RULE_SETUP\r
+#line 240 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; if (parseContext.inTypeParen) parseContext.lexAfterType = false; return(COMMA); }\r
+ YY_BREAK\r
+case 120:\r
+YY_RULE_SETUP\r
+#line 241 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(COLON); }\r
+ YY_BREAK\r
+case 121:\r
+YY_RULE_SETUP\r
+#line 242 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = false; return(EQUAL); }\r
+ YY_BREAK\r
+case 122:\r
+YY_RULE_SETUP\r
+#line 243 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.lexAfterType = false; parseContext.inTypeParen = true; return(LEFT_PAREN); }\r
+ YY_BREAK\r
+case 123:\r
+YY_RULE_SETUP\r
+#line 244 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; parseContext.inTypeParen = false; return(RIGHT_PAREN); }\r
+ YY_BREAK\r
+case 124:\r
+YY_RULE_SETUP\r
+#line 245 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(LEFT_BRACKET); }\r
+ YY_BREAK\r
+case 125:\r
+YY_RULE_SETUP\r
+#line 246 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(RIGHT_BRACKET); }\r
+ YY_BREAK\r
+case 126:\r
+YY_RULE_SETUP\r
+#line 247 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ BEGIN(FIELDS); return(DOT); }\r
+ YY_BREAK\r
+case 127:\r
+YY_RULE_SETUP\r
+#line 248 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(BANG); }\r
+ YY_BREAK\r
+case 128:\r
+YY_RULE_SETUP\r
+#line 249 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(DASH); }\r
+ YY_BREAK\r
+case 129:\r
+YY_RULE_SETUP\r
+#line 250 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(TILDE); }\r
+ YY_BREAK\r
+case 130:\r
+YY_RULE_SETUP\r
+#line 251 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(PLUS); }\r
+ YY_BREAK\r
+case 131:\r
+YY_RULE_SETUP\r
+#line 252 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(STAR); }\r
+ YY_BREAK\r
+case 132:\r
+YY_RULE_SETUP\r
+#line 253 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(SLASH); }\r
+ YY_BREAK\r
+case 133:\r
+YY_RULE_SETUP\r
+#line 254 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(PERCENT); }\r
+ YY_BREAK\r
+case 134:\r
+YY_RULE_SETUP\r
+#line 255 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(LEFT_ANGLE); }\r
+ YY_BREAK\r
+case 135:\r
+YY_RULE_SETUP\r
+#line 256 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(RIGHT_ANGLE); }\r
+ YY_BREAK\r
+case 136:\r
+YY_RULE_SETUP\r
+#line 257 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(VERTICAL_BAR); }\r
+ YY_BREAK\r
+case 137:\r
+YY_RULE_SETUP\r
+#line 258 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(CARET); }\r
+ YY_BREAK\r
+case 138:\r
+YY_RULE_SETUP\r
+#line 259 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(AMPERSAND); }\r
+ YY_BREAK\r
+case 139:\r
+YY_RULE_SETUP\r
+#line 260 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ pyylval->lex.line = yylineno; return(QUESTION); }\r
+ YY_BREAK\r
+case 140:\r
+YY_RULE_SETUP\r
+#line 262 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ \r
+BEGIN(INITIAL); \r
+ pyylval->lex.line = yylineno; \r
+ pyylval->lex.string = NewPoolTString(yytext); \r
+ return FIELD_SELECTION; }\r
+ YY_BREAK\r
+case 141:\r
+YY_RULE_SETUP\r
+#line 267 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{}\r
+ YY_BREAK\r
+case 142:\r
+YY_RULE_SETUP\r
+#line 269 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ }\r
+ YY_BREAK\r
+case YY_STATE_EOF(INITIAL):\r
+case YY_STATE_EOF(FIELDS):\r
+#line 270 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ (&parseContext)->AfterEOF = true; yy_delete_buffer(YY_CURRENT_BUFFER); yyterminate();}\r
+ YY_BREAK\r
+case 143:\r
+YY_RULE_SETUP\r
+#line 271 ".\\glslang\\MachineIndependent\\glslang.l"\r
+{ parseContext.infoSink.info << "FLEX: Unknown char " << yytext << "\n";\r
+ return 0; }\r
+ YY_BREAK\r
+case 144:\r
+YY_RULE_SETUP\r
+#line 274 ".\\glslang\\MachineIndependent\\glslang.l"\r
+ECHO;\r
+ YY_BREAK\r
+#line 1695 "Gen_glslang.cpp"\r
+\r
+ case YY_END_OF_BUFFER:\r
+ {\r
+ /* Amount of text matched not including the EOB char. */\r
+ int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1;\r
+\r
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */\r
+ *yy_cp = yy_hold_char;\r
+\r
+ if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW )\r
+ {\r
+ /* We're scanning a new file or input source. It's\r
+ * possible that this happened because the user\r
+ * just pointed yyin at a new source and called\r
+ * yylex(). If so, then we have to assure\r
+ * consistency between yy_current_buffer and our\r
+ * globals. Here is the right place to do so, because\r
+ * this is the first action (other than possibly a\r
+ * back-up) that will match for the new input source.\r
+ */\r
+ yy_n_chars = yy_current_buffer->yy_n_chars;\r
+ yy_current_buffer->yy_input_file = yyin;\r
+ yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;\r
+ }\r
+\r
+ /* Note that here we test for yy_c_buf_p "<=" to the position\r
+ * of the first EOB in the buffer, since yy_c_buf_p will\r
+ * already have been incremented past the NUL character\r
+ * (since all states make transitions on EOB to the\r
+ * end-of-buffer state). Contrast this with the test\r
+ * in input().\r
+ */\r
+ if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )\r
+ { /* This was really a NUL. */\r
+ yy_state_type yy_next_state;\r
+\r
+ yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;\r
+\r
+ yy_current_state = yy_get_previous_state();\r
+\r
+ /* Okay, we're now positioned to make the NUL\r
+ * transition. We couldn't have\r
+ * yy_get_previous_state() go ahead and do it\r
+ * for us because it doesn't know how to deal\r
+ * with the possibility of jamming (and we don't\r
+ * want to build jamming into it because then it\r
+ * will run more slowly).\r
+ */\r
+\r
+ yy_next_state = yy_try_NUL_trans( yy_current_state );\r
+\r
+ yy_bp = yytext_ptr + YY_MORE_ADJ;\r
+\r
+ if ( yy_next_state )\r
+ {\r
+ /* Consume the NUL. */\r
+ yy_cp = ++yy_c_buf_p;\r
+ yy_current_state = yy_next_state;\r
+ goto yy_match;\r
+ }\r
+\r
+ else\r
+ {\r
+ yy_cp = yy_c_buf_p;\r
+ goto yy_find_action;\r
+ }\r
+ }\r
+\r
+ else switch ( yy_get_next_buffer() )\r
+ {\r
+ case EOB_ACT_END_OF_FILE:\r
+ {\r
+ yy_did_buffer_switch_on_eof = 0;\r
+\r
+ if ( yywrap() )\r
+ {\r
+ /* Note: because we've taken care in\r
+ * yy_get_next_buffer() to have set up\r
+ * yytext, we can now set up\r
+ * yy_c_buf_p so that if some total\r
+ * hoser (like flex itself) wants to\r
+ * call the scanner after we return the\r
+ * YY_NULL, it'll still work - another\r
+ * YY_NULL will get returned.\r
+ */\r
+ yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;\r
+\r
+ yy_act = YY_STATE_EOF(YY_START);\r
+ goto do_action;\r
+ }\r
+\r
+ else\r
+ {\r
+ if ( ! yy_did_buffer_switch_on_eof )\r
+ YY_NEW_FILE;\r
+ }\r
+ break;\r
+ }\r
+\r
+ case EOB_ACT_CONTINUE_SCAN:\r
+ yy_c_buf_p =\r
+ yytext_ptr + yy_amount_of_matched_text;\r
+\r
+ yy_current_state = yy_get_previous_state();\r
+\r
+ yy_cp = yy_c_buf_p;\r
+ yy_bp = yytext_ptr + YY_MORE_ADJ;\r
+ goto yy_match;\r
+\r
+ case EOB_ACT_LAST_MATCH:\r
+ yy_c_buf_p =\r
+ &yy_current_buffer->yy_ch_buf[yy_n_chars];\r
+\r
+ yy_current_state = yy_get_previous_state();\r
+\r
+ yy_cp = yy_c_buf_p;\r
+ yy_bp = yytext_ptr + YY_MORE_ADJ;\r
+ goto yy_find_action;\r
+ }\r
+ break;\r
+ }\r
+\r
+ default:\r
+ YY_FATAL_ERROR(\r
+ "fatal flex scanner internal error--no action found" );\r
+ } /* end of action switch */\r
+ } /* end of scanning one token */\r
+ } /* end of yylex */\r
+\r
+\r
+/* yy_get_next_buffer - try to read in a new buffer\r
+ *\r
+ * Returns a code representing an action:\r
+ * EOB_ACT_LAST_MATCH -\r
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position\r
+ * EOB_ACT_END_OF_FILE - end of file\r
+ */\r
+\r
+static int yy_get_next_buffer()\r
+ {\r
+ register char *dest = yy_current_buffer->yy_ch_buf;\r
+ register char *source = yytext_ptr;\r
+ register int number_to_move, i;\r
+ int ret_val;\r
+\r
+ if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )\r
+ YY_FATAL_ERROR(\r
+ "fatal flex scanner internal error--end of buffer missed" );\r
+\r
+ if ( yy_current_buffer->yy_fill_buffer == 0 )\r
+ { /* Don't try to fill the buffer, so this is an EOF. */\r
+ if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )\r
+ {\r
+ /* We matched a singled characater, the EOB, so\r
+ * treat this as a final EOF.\r
+ */\r
+ return EOB_ACT_END_OF_FILE;\r
+ }\r
+\r
+ else\r
+ {\r
+ /* We matched some text prior to the EOB, first\r
+ * process it.\r
+ */\r
+ return EOB_ACT_LAST_MATCH;\r
+ }\r
+ }\r
+\r
+ /* Try to read more data. */\r
+\r
+ /* First move last chars to start of buffer. */\r
+ number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;\r
+\r
+ for ( i = 0; i < number_to_move; ++i )\r
+ *(dest++) = *(source++);\r
+\r
+ if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING )\r
+ /* don't do the read, it's not guaranteed to return an EOF,\r
+ * just force an EOF\r
+ */\r
+ yy_n_chars = 0;\r
+\r
+ else\r
+ {\r
+ int num_to_read =\r
+ yy_current_buffer->yy_buf_size - number_to_move - 1;\r
+\r
+ while ( num_to_read <= 0 )\r
+ { /* Not enough room in the buffer - grow it. */\r
+#ifdef YY_USES_REJECT\r
+ YY_FATAL_ERROR(\r
+"input buffer overflow, can't enlarge buffer because scanner uses REJECT" );\r
+#else\r
+\r
+ /* just a shorter name for the current buffer */\r
+ YY_BUFFER_STATE b = yy_current_buffer;\r
+\r
+ int yy_c_buf_p_offset =\r
+ (int) (yy_c_buf_p - b->yy_ch_buf);\r
+\r
+ if ( b->yy_is_our_buffer )\r
+ {\r
+ int new_size = b->yy_buf_size * 2;\r
+\r
+ if ( new_size <= 0 )\r
+ b->yy_buf_size += b->yy_buf_size / 8;\r
+ else\r
+ b->yy_buf_size *= 2;\r
+\r
+ b->yy_ch_buf = (char *)\r
+ /* Include room in for 2 EOB chars. */\r
+ yy_flex_realloc( (void *) b->yy_ch_buf,\r
+ b->yy_buf_size + 2 );\r
+ }\r
+ else\r
+ /* Can't grow it, we don't own it. */\r
+ b->yy_ch_buf = 0;\r
+\r
+ if ( ! b->yy_ch_buf )\r
+ YY_FATAL_ERROR(\r
+ "fatal error - scanner input buffer overflow" );\r
+\r
+ yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];\r
+\r
+ num_to_read = yy_current_buffer->yy_buf_size -\r
+ number_to_move - 1;\r
+#endif\r
+ }\r
+\r
+ if ( num_to_read > YY_READ_BUF_SIZE )\r
+ num_to_read = YY_READ_BUF_SIZE;\r
+\r
+ /* Read in more data. */\r
+ YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),\r
+ yy_n_chars, num_to_read );\r
+ }\r
+\r
+ if ( yy_n_chars == 0 )\r
+ {\r
+ if ( number_to_move == YY_MORE_ADJ )\r
+ {\r
+ ret_val = EOB_ACT_END_OF_FILE;\r
+ yyrestart( yyin );\r
+ }\r
+\r
+ else\r
+ {\r
+ ret_val = EOB_ACT_LAST_MATCH;\r
+ yy_current_buffer->yy_buffer_status =\r
+ YY_BUFFER_EOF_PENDING;\r
+ }\r
+ }\r
+\r
+ else\r
+ ret_val = EOB_ACT_CONTINUE_SCAN;\r
+\r
+ yy_n_chars += number_to_move;\r
+ yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;\r
+ yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;\r
+\r
+ yytext_ptr = &yy_current_buffer->yy_ch_buf[0];\r
+\r
+ return ret_val;\r
+ }\r
+\r
+\r
+/* yy_get_previous_state - get the state just before the EOB char was reached */\r
+\r
+static yy_state_type yy_get_previous_state()\r
+ {\r
+ register yy_state_type yy_current_state;\r
+ register char *yy_cp;\r
+\r
+ yy_current_state = yy_start;\r
+\r
+ for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )\r
+ {\r
+ register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);\r
+ if ( yy_accept[yy_current_state] )\r
+ {\r
+ yy_last_accepting_state = yy_current_state;\r
+ yy_last_accepting_cpos = yy_cp;\r
+ }\r
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )\r
+ {\r
+ yy_current_state = (int) yy_def[yy_current_state];\r
+ if ( yy_current_state >= 410 )\r
+ yy_c = yy_meta[(unsigned int) yy_c];\r
+ }\r
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];\r
+ }\r
+\r
+ return yy_current_state;\r
+ }\r
+\r
+\r
+/* yy_try_NUL_trans - try to make a transition on the NUL character\r
+ *\r
+ * synopsis\r
+ * next_state = yy_try_NUL_trans( current_state );\r
+ */\r
+\r
+#ifdef YY_USE_PROTOS\r
+static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state )\r
+#else\r
+static yy_state_type yy_try_NUL_trans( yy_current_state )\r
+yy_state_type yy_current_state;\r
+#endif\r
+ {\r
+ register int yy_is_jam;\r
+ register char *yy_cp = yy_c_buf_p;\r
+\r
+ register YY_CHAR yy_c = 1;\r
+ if ( yy_accept[yy_current_state] )\r
+ {\r
+ yy_last_accepting_state = yy_current_state;\r
+ yy_last_accepting_cpos = yy_cp;\r
+ }\r
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )\r
+ {\r
+ yy_current_state = (int) yy_def[yy_current_state];\r
+ if ( yy_current_state >= 410 )\r
+ yy_c = yy_meta[(unsigned int) yy_c];\r
+ }\r
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];\r
+ yy_is_jam = (yy_current_state == 409);\r
+\r
+ return yy_is_jam ? 0 : yy_current_state;\r
+ }\r
+\r
+\r
+#ifndef YY_NO_UNPUT\r
+#ifdef YY_USE_PROTOS\r
+static void yyunput( int c, register char *yy_bp )\r
+#else\r
+static void yyunput( c, yy_bp )\r
+int c;\r
+register char *yy_bp;\r
+#endif\r
+ {\r
+ register char *yy_cp = yy_c_buf_p;\r
+\r
+ /* undo effects of setting up yytext */\r
+ *yy_cp = yy_hold_char;\r
+\r
+ if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )\r
+ { /* need to shift things up to make room */\r
+ /* +2 for EOB chars. */\r
+ register int number_to_move = yy_n_chars + 2;\r
+ register char *dest = &yy_current_buffer->yy_ch_buf[\r
+ yy_current_buffer->yy_buf_size + 2];\r
+ register char *source =\r
+ &yy_current_buffer->yy_ch_buf[number_to_move];\r
+\r
+ while ( source > yy_current_buffer->yy_ch_buf )\r
+ *--dest = *--source;\r
+\r
+ yy_cp += (int) (dest - source);\r
+ yy_bp += (int) (dest - source);\r
+ yy_n_chars = yy_current_buffer->yy_buf_size;\r
+\r
+ if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )\r
+ YY_FATAL_ERROR( "flex scanner push-back overflow" );\r
+ }\r
+\r
+ *--yy_cp = (char) c;\r
+\r
+\r
+ yytext_ptr = yy_bp;\r
+ yy_hold_char = *yy_cp;\r
+ yy_c_buf_p = yy_cp;\r
+ }\r
+#endif /* ifndef YY_NO_UNPUT */\r
+\r
+\r
+#ifdef __cplusplus\r
+static int yyinput()\r
+#else\r
+static int input()\r
+#endif\r
+ {\r
+ int c;\r
+\r
+ *yy_c_buf_p = yy_hold_char;\r
+\r
+ if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )\r
+ {\r
+ /* yy_c_buf_p now points to the character we want to return.\r
+ * If this occurs *before* the EOB characters, then it's a\r
+ * valid NUL; if not, then we've hit the end of the buffer.\r
+ */\r
+ if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )\r
+ /* This was really a NUL. */\r
+ *yy_c_buf_p = '\0';\r
+\r
+ else\r
+ { /* need more input */\r
+ yytext_ptr = yy_c_buf_p;\r
+ ++yy_c_buf_p;\r
+\r
+ switch ( yy_get_next_buffer() )\r
+ {\r
+ case EOB_ACT_END_OF_FILE:\r
+ {\r
+ if ( yywrap() )\r
+ {\r
+ yy_c_buf_p =\r
+ yytext_ptr + YY_MORE_ADJ;\r
+ return EOF;\r
+ }\r
+\r
+ if ( ! yy_did_buffer_switch_on_eof )\r
+ YY_NEW_FILE;\r
+#ifdef __cplusplus\r
+ return yyinput();\r
+#else\r
+ return input();\r
+#endif\r
+ }\r
+\r
+ case EOB_ACT_CONTINUE_SCAN:\r
+ yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;\r
+ break;\r
+\r
+ case EOB_ACT_LAST_MATCH:\r
+#ifdef __cplusplus\r
+ YY_FATAL_ERROR(\r
+ "unexpected last match in yyinput()" );\r
+#else\r
+ YY_FATAL_ERROR(\r
+ "unexpected last match in input()" );\r
+#endif\r
+ }\r
+ }\r
+ }\r
+\r
+ c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */\r
+ *yy_c_buf_p = '\0'; /* preserve yytext */\r
+ yy_hold_char = *++yy_c_buf_p;\r
+\r
+\r
+ return c;\r
+ }\r
+\r
+\r
+#ifdef YY_USE_PROTOS\r
+void yyrestart( FILE *input_file )\r
+#else\r
+void yyrestart( input_file )\r
+FILE *input_file;\r
+#endif\r
+ {\r
+ if ( ! yy_current_buffer )\r
+ yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );\r
+\r
+ yy_init_buffer( yy_current_buffer, input_file );\r
+ yy_load_buffer_state();\r
+ }\r
+\r
+\r
+#ifdef YY_USE_PROTOS\r
+void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )\r
+#else\r
+void yy_switch_to_buffer( new_buffer )\r
+YY_BUFFER_STATE new_buffer;\r
+#endif\r
+ {\r
+ if ( yy_current_buffer == new_buffer )\r
+ return;\r
+\r
+ if ( yy_current_buffer )\r
+ {\r
+ /* Flush out information for old buffer. */\r
+ *yy_c_buf_p = yy_hold_char;\r
+ yy_current_buffer->yy_buf_pos = yy_c_buf_p;\r
+ yy_current_buffer->yy_n_chars = yy_n_chars;\r
+ }\r
+\r
+ yy_current_buffer = new_buffer;\r
+ yy_load_buffer_state();\r
+\r
+ /* We don't actually know whether we did this switch during\r
+ * EOF (yywrap()) processing, but the only time this flag\r
+ * is looked at is after yywrap() is called, so it's safe\r
+ * to go ahead and always set it.\r
+ */\r
+ yy_did_buffer_switch_on_eof = 1;\r
+ }\r
+\r
+\r
+#ifdef YY_USE_PROTOS\r
+void yy_load_buffer_state( void )\r
+#else\r
+void yy_load_buffer_state()\r
+#endif\r
+ {\r
+ yy_n_chars = yy_current_buffer->yy_n_chars;\r
+ yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;\r
+ yyin = yy_current_buffer->yy_input_file;\r
+ yy_hold_char = *yy_c_buf_p;\r
+ }\r
+\r
+\r
+#ifdef YY_USE_PROTOS\r
+YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )\r
+#else\r
+YY_BUFFER_STATE yy_create_buffer( file, size )\r
+FILE *file;\r
+int size;\r
+#endif\r
+ {\r
+ YY_BUFFER_STATE b;\r
+\r
+ b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );\r
+ if ( ! b )\r
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );\r
+\r
+ b->yy_buf_size = size;\r
+\r
+ /* yy_ch_buf has to be 2 characters longer than the size given because\r
+ * we need to put in 2 end-of-buffer characters.\r
+ */\r
+ b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 );\r
+ if ( ! b->yy_ch_buf )\r
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );\r
+\r
+ b->yy_is_our_buffer = 1;\r
+\r
+ yy_init_buffer( b, file );\r
+\r
+ return b;\r
+ }\r
+\r
+\r
+#ifdef YY_USE_PROTOS\r
+void yy_delete_buffer( YY_BUFFER_STATE b )\r
+#else\r
+void yy_delete_buffer( b )\r
+YY_BUFFER_STATE b;\r
+#endif\r
+ {\r
+ if ( ! b )\r
+ return;\r
+\r
+ if ( b == yy_current_buffer )\r
+ yy_current_buffer = (YY_BUFFER_STATE) 0;\r
+\r
+ if ( b->yy_is_our_buffer )\r
+ yy_flex_free( (void *) b->yy_ch_buf );\r
+\r
+ yy_flex_free( (void *) b );\r
+ }\r
+\r
+\r
+#ifndef YY_ALWAYS_INTERACTIVE\r
+#ifndef YY_NEVER_INTERACTIVE\r
+extern int isatty YY_PROTO(( int ));\r
+#endif\r
+#endif\r
+\r
+#ifdef YY_USE_PROTOS\r
+void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )\r
+#else\r
+void yy_init_buffer( b, file )\r
+YY_BUFFER_STATE b;\r
+FILE *file;\r
+#endif\r
+\r
+\r
+ {\r
+ yy_flush_buffer( b );\r
+\r
+ b->yy_input_file = file;\r
+ b->yy_fill_buffer = 1;\r
+\r
+#if YY_ALWAYS_INTERACTIVE\r
+ b->yy_is_interactive = 1;\r
+#else\r
+#if YY_NEVER_INTERACTIVE\r
+ b->yy_is_interactive = 0;\r
+#else\r
+ b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;\r
+#endif\r
+#endif\r
+ }\r
+\r
+\r
+#ifdef YY_USE_PROTOS\r
+void yy_flush_buffer( YY_BUFFER_STATE b )\r
+#else\r
+void yy_flush_buffer( b )\r
+YY_BUFFER_STATE b;\r
+#endif\r
+\r
+ {\r
+ b->yy_n_chars = 0;\r
+\r
+ /* We always need two end-of-buffer characters. The first causes\r
+ * a transition to the end-of-buffer state. The second causes\r
+ * a jam in that state.\r
+ */\r
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;\r
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;\r
+\r
+ b->yy_buf_pos = &b->yy_ch_buf[0];\r
+\r
+ b->yy_at_bol = 1;\r
+ b->yy_buffer_status = YY_BUFFER_NEW;\r
+\r
+ if ( b == yy_current_buffer )\r
+ yy_load_buffer_state();\r
+ }\r
+\r
+\r
+#ifndef YY_NO_SCAN_BUFFER\r
+#ifdef YY_USE_PROTOS\r
+YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size )\r
+#else\r
+YY_BUFFER_STATE yy_scan_buffer( base, size )\r
+char *base;\r
+yy_size_t size;\r
+#endif\r
+ {\r
+ YY_BUFFER_STATE b;\r
+\r
+ if ( size < 2 ||\r
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||\r
+ base[size-1] != YY_END_OF_BUFFER_CHAR )\r
+ /* They forgot to leave room for the EOB's. */\r
+ return 0;\r
+\r
+ b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );\r
+ if ( ! b )\r
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );\r
+\r
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */\r
+ b->yy_buf_pos = b->yy_ch_buf = base;\r
+ b->yy_is_our_buffer = 0;\r
+ b->yy_input_file = 0;\r
+ b->yy_n_chars = b->yy_buf_size;\r
+ b->yy_is_interactive = 0;\r
+ b->yy_at_bol = 1;\r
+ b->yy_fill_buffer = 0;\r
+ b->yy_buffer_status = YY_BUFFER_NEW;\r
+\r
+ yy_switch_to_buffer( b );\r
+\r
+ return b;\r
+ }\r
+#endif\r
+\r
+\r
+#ifndef YY_NO_SCAN_STRING\r
+#ifdef YY_USE_PROTOS\r
+YY_BUFFER_STATE yy_scan_string( yyconst char *str )\r
+#else\r
+YY_BUFFER_STATE yy_scan_string( str )\r
+yyconst char *str;\r
+#endif\r
+ {\r
+ int len;\r
+ for ( len = 0; str[len]; ++len )\r
+ ;\r
+\r
+ return yy_scan_bytes( str, len );\r
+ }\r
+#endif\r
+\r
+\r
+#ifndef YY_NO_SCAN_BYTES\r
+#ifdef YY_USE_PROTOS\r
+YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len )\r
+#else\r
+YY_BUFFER_STATE yy_scan_bytes( bytes, len )\r
+yyconst char *bytes;\r
+int len;\r
+#endif\r
+ {\r
+ YY_BUFFER_STATE b;\r
+ char *buf;\r
+ yy_size_t n;\r
+ int i;\r
+\r
+ /* Get memory for full buffer, including space for trailing EOB's. */\r
+ n = len + 2;\r
+ buf = (char *) yy_flex_alloc( n );\r
+ if ( ! buf )\r
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );\r
+\r
+ for ( i = 0; i < len; ++i )\r
+ buf[i] = bytes[i];\r
+\r
+ buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;\r
+\r
+ b = yy_scan_buffer( buf, n );\r
+ if ( ! b )\r
+ YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );\r
+\r
+ /* It's okay to grow etc. this buffer, and we should throw it\r
+ * away when we're done.\r
+ */\r
+ b->yy_is_our_buffer = 1;\r
+\r
+ return b;\r
+ }\r
+#endif\r
+\r
+\r
+#ifndef YY_NO_PUSH_STATE\r
+#ifdef YY_USE_PROTOS\r
+static void yy_push_state( int new_state )\r
+#else\r
+static void yy_push_state( new_state )\r
+int new_state;\r
+#endif\r
+ {\r
+ if ( yy_start_stack_ptr >= yy_start_stack_depth )\r
+ {\r
+ yy_size_t new_size;\r
+\r
+ yy_start_stack_depth += YY_START_STACK_INCR;\r
+ new_size = yy_start_stack_depth * sizeof( int );\r
+\r
+ if ( ! yy_start_stack )\r
+ yy_start_stack = (int *) yy_flex_alloc( new_size );\r
+\r
+ else\r
+ yy_start_stack = (int *) yy_flex_realloc(\r
+ (void *) yy_start_stack, new_size );\r
+\r
+ if ( ! yy_start_stack )\r
+ YY_FATAL_ERROR(\r
+ "out of memory expanding start-condition stack" );\r
+ }\r
+\r
+ yy_start_stack[yy_start_stack_ptr++] = YY_START;\r
+\r
+ BEGIN(new_state);\r
+ }\r
+#endif\r
+\r
+\r
+#ifndef YY_NO_POP_STATE\r
+static void yy_pop_state()\r
+ {\r
+ if ( --yy_start_stack_ptr < 0 )\r
+ YY_FATAL_ERROR( "start-condition stack underflow" );\r
+\r
+ BEGIN(yy_start_stack[yy_start_stack_ptr]);\r
+ }\r
+#endif\r
+\r
+\r
+#ifndef YY_NO_TOP_STATE\r
+static int yy_top_state()\r
+ {\r
+ return yy_start_stack[yy_start_stack_ptr - 1];\r
+ }\r
+#endif\r
+\r
+#ifndef YY_EXIT_FAILURE\r
+#define YY_EXIT_FAILURE 2\r
+#endif\r
+\r
+#ifdef YY_USE_PROTOS\r
+static void yy_fatal_error( yyconst char msg[] )\r
+#else\r
+static void yy_fatal_error( msg )\r
+char msg[];\r
+#endif\r
+ {\r
+ (void) fprintf( stderr, "%s\n", msg );\r
+ exit( YY_EXIT_FAILURE );\r
+ }\r
+\r
+\r
+\r
+/* Redefine yyless() so it works in section 3 code. */\r
+\r
+#undef yyless\r
+#define yyless(n) \\r
+ do \\r
+ { \\r
+ /* Undo effects of setting up yytext. */ \\r
+ yytext[yyleng] = yy_hold_char; \\r
+ yy_c_buf_p = yytext + n - YY_MORE_ADJ; \\r
+ yy_hold_char = *yy_c_buf_p; \\r
+ *yy_c_buf_p = '\0'; \\r
+ yyleng = n; \\r
+ } \\r
+ while ( 0 )\r
+\r
+\r
+/* Internal utility routines. */\r
+\r
+#ifndef yytext_ptr\r
+#ifdef YY_USE_PROTOS\r
+static void yy_flex_strncpy( char *s1, yyconst char *s2, int n )\r
+#else\r
+static void yy_flex_strncpy( s1, s2, n )\r
+char *s1;\r
+yyconst char *s2;\r
+int n;\r
+#endif\r
+ {\r
+ register int i;\r
+ for ( i = 0; i < n; ++i )\r
+ s1[i] = s2[i];\r
+ }\r
+#endif\r
+\r
+\r
+#ifdef YY_USE_PROTOS\r
+static void *yy_flex_alloc( yy_size_t size )\r
+#else\r
+static void *yy_flex_alloc( size )\r
+yy_size_t size;\r
+#endif\r
+ {\r
+ return (void *) malloc( size );\r
+ }\r
+\r
+#ifdef YY_USE_PROTOS\r
+static void *yy_flex_realloc( void *ptr, yy_size_t size )\r
+#else\r
+static void *yy_flex_realloc( ptr, size )\r
+void *ptr;\r
+yy_size_t size;\r
+#endif\r
+ {\r
+ /* The cast to (char *) in the following accommodates both\r
+ * implementations that use char* generic pointers, and those\r
+ * that use void* generic pointers. It works with the latter\r
+ * because both ANSI C and C++ allow castless assignment from\r
+ * any pointer type to void*, and deal with argument conversions\r
+ * as though doing an assignment.\r
+ */\r
+ return (void *) realloc( (char *) ptr, size );\r
+ }\r
+\r
+#ifdef YY_USE_PROTOS\r
+static void yy_flex_free( void *ptr )\r
+#else\r
+static void yy_flex_free( ptr )\r
+void *ptr;\r
+#endif\r
+ {\r
+ free( ptr );\r
+ }\r
+\r
+#if YY_MAIN\r
+int main()\r
+ {\r
+ yylex();\r
+ return 0;\r
+ }\r
+#endif\r
+#line 274 ".\\glslang\\MachineIndependent\\glslang.l"\r
+\r
+\r
+\r
+//Including Pre-processor.\r
+extern "C" {\r
+ #include "./preprocessor/preprocess.h"\r
+} \r
+\r
+//\r
+// The YY_INPUT macro just calls this. Maybe this could be just put into\r
+// the macro directly.\r
+//\r
+\r
+int yy_input(char* buf, int max_size)\r
+{\r
+ char *char_token =NULL;\r
+ int len;\r
+\r
+ if ((len = yylex_CPP(buf, max_size)) == 0)\r
+ return 0;\r
+ if (len >= max_size) \r
+ YY_FATAL_ERROR( "input buffer overflow, can't enlarge buffer because scanner uses REJECT" );\r
+\r
+ buf[len] = ' ';\r
+ return len+1;\r
+}\r
+\r
+\r
+//\r
+// Parse an array of strings using yyparse. We set up globals used by\r
+// yywrap.\r
+//\r
+// Returns 0 for success, as per yyparse().\r
+//\r
+int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext& parseContextLocal)\r
+{\r
+ int argv0len;\r
+ ScanFromString(argv[0]); \r
+ \r
+ //Storing the Current Compiler Parse context into the cpp structure.\r
+ cpp->pC = (void*)&parseContextLocal;\r
+ \r
+ if (!argv || argc == 0 || !argv[0])\r
+ return 1;\r
+ \r
+ if (!strLen) {\r
+ argv0len = (int) strlen(argv[0]);\r
+ strLen = &argv0len;\r
+ }\r
+ yyrestart(0);\r
+ (&parseContextLocal)->AfterEOF = false;\r
+ cpp->PaWhichStr = 0;\r
+ cpp->PaArgv = argv;\r
+ cpp->PaArgc = argc;\r
+ cpp->PaStrLen = strLen;\r
+ yylineno = 1;\r
+ \r
+ if (*cpp->PaStrLen > 0) { \r
+ int ret;\r
+ #ifdef _WIN32\r
+ ret = yyparse(parseContextLocal);\r
+ #else\r
+ ret = yyparse((void*)(&parseContextLocal));\r
+ #endif\r
+ if (cpp->CompileError == 1)\r
+ return 1;\r
+ else\r
+ return ret;\r
+ }\r
+ else\r
+ return 0;\r
+}\r
+\r
+void yyerror(char *s) \r
+{\r
+ if (((TParseContext *)cpp->pC)->AfterEOF) \r
+ GlobalParseContext->error(yylineno, "syntax error", "pre-mature EOF", s, "");\r
+ else\r
+ GlobalParseContext->error(yylineno, "syntax error", yytext, s, "");\r
+ \r
+ GlobalParseContext->recover();\r
+}\r
+\r
+void PaReservedWord()\r
+{\r
+ GlobalParseContext->error(yylineno, "Reserved word.", yytext, "", "");\r
+ GlobalParseContext->recover();\r
+}\r
+\r
+int PaIdentOrType(TString& id, TParseContext& parseContextLocal, TSymbol*& symbol)\r
+{\r
+ symbol = parseContextLocal.symbolTable.find(id);\r
+ if (parseContextLocal.lexAfterType == false && symbol && symbol->isVariable()) {\r
+ TVariable* variable = static_cast<TVariable*>(symbol);\r
+ if (variable->isUserType()) {\r
+ parseContextLocal.lexAfterType = true;\r
+ return TYPE_NAME;\r
+ }\r
+ }\r
+ \r
+ return IDENTIFIER;\r
+}\r
+\r
+int PaParseComment(int &lineno, TParseContext& parseContextLocal)\r
+{\r
+ int transitionFlag = 0;\r
+ int nextChar;\r
+ \r
+ while (transitionFlag != 2) {\r
+ nextChar = yyinput();\r
+ if (nextChar == '\n')\r
+ lineno++;\r
+ switch (nextChar) {\r
+ case '*' :\r
+ transitionFlag = 1;\r
+ break;\r
+ case '/' : /* if star is the previous character, then it is the end of comment */\r
+ if (transitionFlag == 1) {\r
+ return 1 ;\r
+ }\r
+ break;\r
+ case EOF :\r
+ /* Raise error message here */\r
+ parseContextLocal.error(yylineno, "End of shader found before end of comment.", "", "", "");\r
+ GlobalParseContext->recover();\r
+ return YY_NULL; \r
+ default : /* Any other character will be a part of the comment */\r
+ transitionFlag = 0;\r
+ }\r
+ }\r
+ return 1;\r
+}\r
+\r
+extern "C" {\r
+\r
+void CPPDebugLogMsg(const char *msg)\r
+{\r
+ ((TParseContext *)cpp->pC)->infoSink.debug.message(EPrefixNone, msg);\r
+}\r
+\r
+void CPPShInfoLogMsg(const char *msg)\r
+{\r
+ ((TParseContext *)cpp->pC)->error(yylineno,"", "",msg,"");\r
+ GlobalParseContext->recover();\r
+}\r
+\r
+void CPPErrorToInfoLog(char *msg)\r
+{\r
+ ((TParseContext *)cpp->pC)->error(yylineno,"syntax error", "",msg,"");\r
+ GlobalParseContext->recover();\r
+}\r
+\r
+void SetLineNumber(int line)\r
+{\r
+ yylineno &= ~SourceLocLineMask;\r
+ yylineno |= line;\r
+}\r
+\r
+void SetStringNumber(int string)\r
+{\r
+ yylineno = (string << SourceLocStringShift) | (yylineno & SourceLocLineMask);\r
+}\r
+\r
+int GetStringNumber(void)\r
+{\r
+ return yylineno >> 16;\r
+}\r
+\r
+int GetLineNumber(void)\r
+{\r
+ return yylineno & SourceLocLineMask;\r
+}\r
+\r
+void IncLineNumber(void)\r
+{\r
+ if ((yylineno & SourceLocLineMask) <= SourceLocLineMask)\r
+ ++yylineno;\r
+}\r
+\r
+void DecLineNumber(void)\r
+{\r
+ if ((yylineno & SourceLocLineMask) > 0)\r
+ --yylineno;\r
+}\r
+\r
+void MapStrings(const char *string1, const char *string2)\r
+{\r
+ TString strSrc, strDest;\r
+ strSrc = TString(string1);\r
+ strDest = TString(string2);\r
+\r
+ ((TParseContext *)cpp->pC)->PragmaTable[strSrc] = strDest;\r
+}\r
+\r
+void StoreStr(char *string)\r
+{\r
+ TString strSrc;\r
+ strSrc = TString(string);\r
+\r
+ ((TParseContext *)cpp->pC)->HashErrMsg = ((TParseContext *)cpp->pC)->HashErrMsg + " " + strSrc;\r
+}\r
+\r
+const char* GetStrfromTStr(void)\r
+{\r
+ cpp->ErrMsg = (((TParseContext *)cpp->pC)->HashErrMsg).c_str();\r
+ return cpp->ErrMsg;\r
+}\r
+\r
+void ResetTString(void)\r
+{\r
+ ((TParseContext *)cpp->pC)->HashErrMsg = "";\r
+}\r
+\r
+TBehavior GetBehavior(const char* behavior)\r
+{\r
+ if (!strcmp("require", behavior))\r
+ return EBhRequire;\r
+ else if (!strcmp("enable", behavior))\r
+ return EBhEnable;\r
+ else if (!strcmp("disable", behavior))\r
+ return EBhDisable;\r
+ else if (!strcmp("warn", behavior))\r
+ return EBhWarn;\r
+ else {\r
+ CPPShInfoLogMsg((TString("behavior '") + behavior + "' is not supported").c_str());\r
+ return EBhDisable;\r
+ } \r
+}\r
+\r
+void updateExtensionBehavior(const char* extName, const char* behavior)\r
+{\r
+ TBehavior behaviorVal = GetBehavior(behavior);\r
+ TMap<TString, TBehavior>:: iterator iter;\r
+ TString msg;\r
+ \r
+ // special cased for all extension\r
+ if (!strcmp(extName, "all")) {\r
+ if (behaviorVal == EBhRequire || behaviorVal == EBhEnable) {\r
+ CPPShInfoLogMsg("extension 'all' cannot have 'require' or 'enable' behavior"); \r
+ return;\r
+ } else {\r
+ for (iter = ((TParseContext *)cpp->pC)->extensionBehavior.begin(); iter != ((TParseContext *)cpp->pC)->extensionBehavior.end(); ++iter)\r
+ iter->second = behaviorVal;\r
+ } \r
+ } else {\r
+ iter = ((TParseContext *)cpp->pC)->extensionBehavior.find(TString(extName));\r
+ if (iter == ((TParseContext *)cpp->pC)->extensionBehavior.end()) {\r
+ switch (behaviorVal) {\r
+ case EBhRequire:\r
+ CPPShInfoLogMsg((TString("extension '") + extName + "' is not supported").c_str()); \r
+ break;\r
+ case EBhEnable:\r
+ case EBhWarn:\r
+ case EBhDisable:\r
+ msg = TString("extension '") + extName + "' is not supported";\r
+ ((TParseContext *)cpp->pC)->infoSink.info.message(EPrefixWarning, msg.c_str(), yylineno); \r
+ break;\r
+ }\r
+ return;\r
+ } else\r
+ iter->second = behaviorVal;\r
+ }\r
+}\r
+ \r
+}\r
+\r
+void setInitialState()\r
+{\r
+ yy_start = 1;\r
+}\r
--- /dev/null
+\r
+/* A Bison parser, made from glslang.y with Bison version GNU Bison version 1.24\r
+ */\r
+\r
+#define YYBISON 1 /* Identify Bison output. */\r
+\r
+#define ATTRIBUTE 258\r
+#define CONST_QUAL 259\r
+#define BOOL_TYPE 260\r
+#define FLOAT_TYPE 261\r
+#define INT_TYPE 262\r
+#define BREAK 263\r
+#define CONTINUE 264\r
+#define DO 265\r
+#define ELSE 266\r
+#define FOR 267\r
+#define IF 268\r
+#define DISCARD 269\r
+#define RETURN 270\r
+#define BVEC2 271\r
+#define BVEC3 272\r
+#define BVEC4 273\r
+#define IVEC2 274\r
+#define IVEC3 275\r
+#define IVEC4 276\r
+#define VEC2 277\r
+#define VEC3 278\r
+#define VEC4 279\r
+#define MATRIX2 280\r
+#define MATRIX3 281\r
+#define MATRIX4 282\r
+#define IN_QUAL 283\r
+#define OUT_QUAL 284\r
+#define INOUT_QUAL 285\r
+#define UNIFORM 286\r
+#define VARYING 287\r
+#define STRUCT 288\r
+#define VOID_TYPE 289\r
+#define WHILE 290\r
+#define SAMPLER1D 291\r
+#define SAMPLER2D 292\r
+#define SAMPLER3D 293\r
+#define SAMPLERCUBE 294\r
+#define SAMPLER1DSHADOW 295\r
+#define SAMPLER2DSHADOW 296\r
+#define IDENTIFIER 297\r
+#define TYPE_NAME 298\r
+#define FLOATCONSTANT 299\r
+#define INTCONSTANT 300\r
+#define BOOLCONSTANT 301\r
+#define FIELD_SELECTION 302\r
+#define LEFT_OP 303\r
+#define RIGHT_OP 304\r
+#define INC_OP 305\r
+#define DEC_OP 306\r
+#define LE_OP 307\r
+#define GE_OP 308\r
+#define EQ_OP 309\r
+#define NE_OP 310\r
+#define AND_OP 311\r
+#define OR_OP 312\r
+#define XOR_OP 313\r
+#define MUL_ASSIGN 314\r
+#define DIV_ASSIGN 315\r
+#define ADD_ASSIGN 316\r
+#define MOD_ASSIGN 317\r
+#define LEFT_ASSIGN 318\r
+#define RIGHT_ASSIGN 319\r
+#define AND_ASSIGN 320\r
+#define XOR_ASSIGN 321\r
+#define OR_ASSIGN 322\r
+#define SUB_ASSIGN 323\r
+#define LEFT_PAREN 324\r
+#define RIGHT_PAREN 325\r
+#define LEFT_BRACKET 326\r
+#define RIGHT_BRACKET 327\r
+#define LEFT_BRACE 328\r
+#define RIGHT_BRACE 329\r
+#define DOT 330\r
+#define COMMA 331\r
+#define COLON 332\r
+#define EQUAL 333\r
+#define SEMICOLON 334\r
+#define BANG 335\r
+#define DASH 336\r
+#define TILDE 337\r
+#define PLUS 338\r
+#define STAR 339\r
+#define SLASH 340\r
+#define PERCENT 341\r
+#define LEFT_ANGLE 342\r
+#define RIGHT_ANGLE 343\r
+#define VERTICAL_BAR 344\r
+#define CARET 345\r
+#define AMPERSAND 346\r
+#define QUESTION 347\r
+\r
+#line 39 "glslang.y"\r
+\r
+\r
+/* Based on:\r
+ANSI C Yacc grammar\r
+\r
+In 1985, Jeff Lee published his Yacc grammar (which is accompanied by a \r
+matching Lex specification) for the April 30, 1985 draft version of the \r
+ANSI C standard. Tom Stockfisch reposted it to net.sources in 1987; that\r
+original, as mentioned in the answer to question 17.25 of the comp.lang.c\r
+FAQ, can be ftp'ed from ftp.uu.net, file usenet/net.sources/ansi.c.grammar.Z.\r
+ \r
+I intend to keep this version as close to the current C Standard grammar as \r
+possible; please let me know if you discover discrepancies. \r
+\r
+Jutta Degener, 1995 \r
+*/\r
+\r
+#include "SymbolTable.h"\r
+#include "ParseHelper.h"\r
+#include "../Public/ShaderLang.h"\r
+\r
+#ifdef _WIN32\r
+ #define YYPARSE_PARAM parseContext\r
+ #define YYPARSE_PARAM_DECL TParseContext&\r
+ #define YY_DECL int yylex(YYSTYPE* pyylval, TParseContext& parseContext)\r
+ #define YYLEX_PARAM parseContext\r
+#else\r
+ #define YYPARSE_PARAM parseContextLocal\r
+ #define parseContext (*((TParseContext*)(parseContextLocal)))\r
+ #define YY_DECL int yylex(YYSTYPE* pyylval, void* parseContextLocal)\r
+ #define YYLEX_PARAM (void*)(parseContextLocal)\r
+ extern void yyerror(char*); \r
+#endif\r
+\r
+#define FRAG_VERT_ONLY(S, L) { \\r
+ if (parseContext.language != EShLangFragment && \\r
+ parseContext.language != EShLangVertex) { \\r
+ parseContext.error(L, " supported in vertex/fragment shaders only ", S, "", ""); \\r
+ parseContext.recover(); \\r
+ } \\r
+}\r
+\r
+#define VERTEX_ONLY(S, L) { \\r
+ if (parseContext.language != EShLangVertex) { \\r
+ parseContext.error(L, " supported in vertex shaders only ", S, "", ""); \\r
+ parseContext.recover(); \\r
+ } \\r
+}\r
+\r
+#define FRAG_ONLY(S, L) { \\r
+ if (parseContext.language != EShLangFragment) { \\r
+ parseContext.error(L, " supported in fragment shaders only ", S, "", ""); \\r
+ parseContext.recover(); \\r
+ } \\r
+}\r
+\r
+#define PACK_ONLY(S, L) { \\r
+ if (parseContext.language != EShLangPack) { \\r
+ parseContext.error(L, " supported in pack shaders only ", S, "", ""); \\r
+ parseContext.recover(); \\r
+ } \\r
+}\r
+\r
+#define UNPACK_ONLY(S, L) { \\r
+ if (parseContext.language != EShLangUnpack) { \\r
+ parseContext.error(L, " supported in unpack shaders only ", S, "", ""); \\r
+ parseContext.recover(); \\r
+ } \\r
+}\r
+\r
+#define PACK_UNPACK_ONLY(S, L) { \\r
+ if (parseContext.language != EShLangUnpack && \\r
+ parseContext.language != EShLangPack) { \\r
+ parseContext.error(L, " supported in pack/unpack shaders only ", S, "", ""); \\r
+ parseContext.recover(); \\r
+ } \\r
+}\r
+\r
+#line 117 "glslang.y"\r
+typedef union {\r
+ struct {\r
+ TSourceLoc line;\r
+ union {\r
+ TString *string;\r
+ float f;\r
+ int i;\r
+ bool b;\r
+ };\r
+ TSymbol* symbol;\r
+ } lex;\r
+ struct {\r
+ TSourceLoc line;\r
+ TOperator op;\r
+ union {\r
+ TIntermNode* intermNode;\r
+ TIntermNodePair nodePair;\r
+ TIntermTyped* intermTypedNode;\r
+ TIntermAggregate* intermAggregate;\r
+ };\r
+ union {\r
+ TPublicType type;\r
+ TQualifier qualifier;\r
+ TFunction* function;\r
+ TParameter param;\r
+ TTypeLine typeLine;\r
+ TTypeList* typeList;\r
+ };\r
+ } interm;\r
+} YYSTYPE;\r
+#line 148 "glslang.y"\r
+\r
+#ifndef _WIN32\r
+ extern int yylex(YYSTYPE*, void*);\r
+#endif\r
+\r
+#ifndef YYLTYPE\r
+typedef\r
+ struct yyltype\r
+ {\r
+ int timestamp;\r
+ int first_line;\r
+ int first_column;\r
+ int last_line;\r
+ int last_column;\r
+ char *text;\r
+ }\r
+ yyltype;\r
+\r
+#define YYLTYPE yyltype\r
+#endif\r
+\r
+#ifndef YYDEBUG\r
+#define YYDEBUG 1\r
+#endif\r
+\r
+#include <stdio.h>\r
+\r
+#ifndef __cplusplus\r
+#ifndef __STDC__\r
+#define const\r
+#endif\r
+#endif\r
+\r
+\r
+\r
+#define YYFINAL 331\r
+#define YYFLAG -32768\r
+#define YYNTBASE 93\r
+\r
+#define YYTRANSLATE(x) ((unsigned)(x) <= 347 ? yytranslate[x] : 167)\r
+\r
+static const char yytranslate[] = { 0,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+ 2, 2, 2, 2, 2, 1, 2, 3, 4, 5,\r
+ 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,\r
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,\r
+ 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,\r
+ 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,\r
+ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,\r
+ 56, 57, 58, 59, 60, 61, 62, 63, 64, 65,\r
+ 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,\r
+ 76, 77, 78, 79, 80, 81, 82, 83, 84, 85,\r
+ 86, 87, 88, 89, 90, 91, 92\r
+};\r
+\r
+#if YYDEBUG != 0\r
+static const short yyprhs[] = { 0,\r
+ 0, 2, 4, 6, 8, 10, 14, 16, 21, 23,\r
+ 27, 30, 33, 35, 37, 40, 43, 46, 48, 51,\r
+ 55, 58, 60, 62, 64, 66, 68, 70, 72, 74,\r
+ 76, 78, 80, 82, 84, 86, 88, 90, 92, 94,\r
+ 96, 99, 102, 105, 107, 109, 111, 113, 115, 119,\r
+ 123, 127, 129, 133, 137, 139, 143, 147, 149, 153,\r
+ 157, 161, 165, 167, 171, 175, 177, 181, 183, 187,\r
+ 189, 193, 195, 199, 201, 205, 207, 211, 213, 219,\r
+ 221, 225, 227, 229, 231, 233, 235, 237, 239, 241,\r
+ 243, 245, 247, 249, 253, 255, 258, 261, 264, 266,\r
+ 268, 271, 275, 279, 282, 288, 292, 295, 299, 302,\r
+ 303, 305, 307, 309, 311, 316, 318, 322, 328, 335,\r
+ 341, 343, 346, 351, 357, 362, 364, 367, 369, 371,\r
+ 373, 375, 377, 379, 381, 383, 385, 387, 389, 391,\r
+ 393, 395, 397, 399, 401, 403, 405, 407, 409, 411,\r
+ 413, 415, 417, 419, 421, 423, 429, 434, 436, 439,\r
+ 443, 445, 449, 451, 456, 458, 460, 462, 464, 466,\r
+ 468, 470, 472, 474, 477, 478, 479, 485, 487, 489,\r
+ 492, 496, 498, 501, 503, 506, 512, 516, 518, 520,\r
+ 525, 526, 533, 534, 543, 544, 552, 554, 556, 558,\r
+ 559, 562, 566, 569, 572, 575, 579, 582, 584, 587,\r
+ 589, 591, 592\r
+};\r
+\r
+static const short yyrhs[] = { 42,\r
+ 0, 93, 0, 45, 0, 44, 0, 46, 0, 69,\r
+ 120, 70, 0, 94, 0, 95, 71, 96, 72, 0,\r
+ 97, 0, 95, 75, 47, 0, 95, 50, 0, 95,\r
+ 51, 0, 120, 0, 98, 0, 100, 70, 0, 99,\r
+ 70, 0, 101, 34, 0, 101, 0, 101, 118, 0,\r
+ 100, 76, 118, 0, 102, 69, 0, 103, 0, 42,\r
+ 0, 6, 0, 7, 0, 5, 0, 22, 0, 23,\r
+ 0, 24, 0, 16, 0, 17, 0, 18, 0, 19,\r
+ 0, 20, 0, 21, 0, 25, 0, 26, 0, 27,\r
+ 0, 43, 0, 95, 0, 50, 104, 0, 51, 104,\r
+ 0, 105, 104, 0, 83, 0, 81, 0, 80, 0,\r
+ 82, 0, 104, 0, 106, 84, 104, 0, 106, 85,\r
+ 104, 0, 106, 86, 104, 0, 106, 0, 107, 83,\r
+ 106, 0, 107, 81, 106, 0, 107, 0, 108, 48,\r
+ 107, 0, 108, 49, 107, 0, 108, 0, 109, 87,\r
+ 108, 0, 109, 88, 108, 0, 109, 52, 108, 0,\r
+ 109, 53, 108, 0, 109, 0, 110, 54, 109, 0,\r
+ 110, 55, 109, 0, 110, 0, 111, 91, 110, 0,\r
+ 111, 0, 112, 90, 111, 0, 112, 0, 113, 89,\r
+ 112, 0, 113, 0, 114, 56, 113, 0, 114, 0,\r
+ 115, 58, 114, 0, 115, 0, 116, 57, 115, 0,\r
+ 116, 0, 116, 92, 120, 77, 117, 0, 117, 0,\r
+ 104, 119, 118, 0, 78, 0, 59, 0, 60, 0,\r
+ 62, 0, 61, 0, 68, 0, 63, 0, 64, 0,\r
+ 65, 0, 66, 0, 67, 0, 118, 0, 120, 76,\r
+ 118, 0, 117, 0, 123, 79, 0, 131, 79, 0,\r
+ 124, 70, 0, 126, 0, 125, 0, 126, 128, 0,\r
+ 125, 76, 128, 0, 133, 42, 69, 0, 135, 42,\r
+ 0, 135, 42, 71, 121, 72, 0, 134, 129, 127,\r
+ 0, 129, 127, 0, 134, 129, 130, 0, 129, 130,\r
+ 0, 0, 28, 0, 29, 0, 30, 0, 135, 0,\r
+ 135, 71, 121, 72, 0, 132, 0, 131, 76, 42,\r
+ 0, 131, 76, 42, 71, 72, 0, 131, 76, 42,\r
+ 71, 121, 72, 0, 131, 76, 42, 78, 141, 0,\r
+ 133, 0, 133, 42, 0, 133, 42, 71, 72, 0,\r
+ 133, 42, 71, 121, 72, 0, 133, 42, 78, 141,\r
+ 0, 135, 0, 134, 135, 0, 4, 0, 3, 0,\r
+ 32, 0, 31, 0, 34, 0, 6, 0, 7, 0,\r
+ 5, 0, 22, 0, 23, 0, 24, 0, 16, 0,\r
+ 17, 0, 18, 0, 19, 0, 20, 0, 21, 0,\r
+ 25, 0, 26, 0, 27, 0, 36, 0, 37, 0,\r
+ 38, 0, 39, 0, 40, 0, 41, 0, 136, 0,\r
+ 43, 0, 33, 42, 73, 137, 74, 0, 33, 73,\r
+ 137, 74, 0, 138, 0, 137, 138, 0, 135, 139,\r
+ 79, 0, 140, 0, 139, 76, 140, 0, 42, 0,\r
+ 42, 71, 121, 72, 0, 118, 0, 122, 0, 145,\r
+ 0, 144, 0, 142, 0, 151, 0, 152, 0, 155,\r
+ 0, 162, 0, 73, 74, 0, 0, 0, 73, 146,\r
+ 150, 147, 74, 0, 149, 0, 144, 0, 73, 74,\r
+ 0, 73, 150, 74, 0, 143, 0, 150, 143, 0,\r
+ 79, 0, 120, 79, 0, 13, 69, 120, 70, 153,\r
+ 0, 143, 11, 143, 0, 143, 0, 120, 0, 133,\r
+ 42, 78, 141, 0, 0, 35, 69, 156, 154, 70,\r
+ 148, 0, 0, 10, 157, 143, 35, 69, 120, 70,\r
+ 79, 0, 0, 12, 69, 158, 159, 161, 70, 148,\r
+ 0, 151, 0, 142, 0, 154, 0, 0, 160, 79,\r
+ 0, 160, 79, 120, 0, 9, 79, 0, 8, 79,\r
+ 0, 15, 79, 0, 15, 120, 79, 0, 14, 79,\r
+ 0, 164, 0, 163, 164, 0, 165, 0, 122, 0,\r
+ 0, 123, 166, 149, 0\r
+};\r
+\r
+#endif\r
+\r
+#if YYDEBUG != 0\r
+static const short yyrline[] = { 0,\r
+ 210, 244, 247, 260, 265, 270, 276, 279, 347, 350,\r
+ 459, 469, 482, 490, 585, 589, 596, 600, 607, 613,\r
+ 622, 628, 639, 654, 655, 656, 657, 658, 659, 660,\r
+ 661, 662, 663, 664, 665, 666, 667, 668, 669, 680,\r
+ 683, 693, 703, 725, 726, 727, 728, 734, 735, 744,\r
+ 753, 765, 766, 774, 785, 786, 795, 807, 808, 818,\r
+ 828, 838, 851, 852, 862, 875, 876, 888, 889, 901,\r
+ 902, 914, 915, 928, 929, 942, 943, 956, 957, 971,\r
+ 972, 985, 986, 987, 988, 989, 990, 991, 992, 993,\r
+ 994, 995, 999, 1002, 1010, 1018, 1019, 1027, 1063, 1066,\r
+ 1073, 1081, 1102, 1120, 1131, 1158, 1163, 1173, 1178, 1188,\r
+ 1191, 1194, 1197, 1203, 1208, 1226, 1229, 1237, 1245, 1253,\r
+ 1275, 1279, 1288, 1297, 1306, 1396, 1399, 1416, 1420, 1427,\r
+ 1435, 1444, 1449, 1454, 1459, 1470, 1475, 1480, 1485, 1490,\r
+ 1495, 1500, 1505, 1510, 1515, 1521, 1527, 1533, 1539, 1545,\r
+ 1551, 1557, 1563, 1569, 1574, 1587, 1597, 1605, 1608, 1623,\r
+ 1641, 1645, 1651, 1656, 1672, 1676, 1680, 1681, 1687, 1688,\r
+ 1689, 1690, 1691, 1695, 1696, 1696, 1696, 1704, 1705, 1710,\r
+ 1713, 1721, 1724, 1730, 1731, 1735, 1743, 1747, 1757, 1762,\r
+ 1779, 1779, 1784, 1784, 1791, 1791, 1804, 1807, 1813, 1816,\r
+ 1822, 1826, 1833, 1840, 1847, 1854, 1865, 1874, 1878, 1885,\r
+ 1888, 1894, 1979\r
+};\r
+\r
+static const char * const yytname[] = { "$","error","$undefined.","ATTRIBUTE",\r
+"CONST_QUAL","BOOL_TYPE","FLOAT_TYPE","INT_TYPE","BREAK","CONTINUE","DO","ELSE",\r
+"FOR","IF","DISCARD","RETURN","BVEC2","BVEC3","BVEC4","IVEC2","IVEC3","IVEC4",\r
+"VEC2","VEC3","VEC4","MATRIX2","MATRIX3","MATRIX4","IN_QUAL","OUT_QUAL","INOUT_QUAL",\r
+"UNIFORM","VARYING","STRUCT","VOID_TYPE","WHILE","SAMPLER1D","SAMPLER2D","SAMPLER3D",\r
+"SAMPLERCUBE","SAMPLER1DSHADOW","SAMPLER2DSHADOW","IDENTIFIER","TYPE_NAME","FLOATCONSTANT",\r
+"INTCONSTANT","BOOLCONSTANT","FIELD_SELECTION","LEFT_OP","RIGHT_OP","INC_OP",\r
+"DEC_OP","LE_OP","GE_OP","EQ_OP","NE_OP","AND_OP","OR_OP","XOR_OP","MUL_ASSIGN",\r
+"DIV_ASSIGN","ADD_ASSIGN","MOD_ASSIGN","LEFT_ASSIGN","RIGHT_ASSIGN","AND_ASSIGN",\r
+"XOR_ASSIGN","OR_ASSIGN","SUB_ASSIGN","LEFT_PAREN","RIGHT_PAREN","LEFT_BRACKET",\r
+"RIGHT_BRACKET","LEFT_BRACE","RIGHT_BRACE","DOT","COMMA","COLON","EQUAL","SEMICOLON",\r
+"BANG","DASH","TILDE","PLUS","STAR","SLASH","PERCENT","LEFT_ANGLE","RIGHT_ANGLE",\r
+"VERTICAL_BAR","CARET","AMPERSAND","QUESTION","variable_identifier","primary_expression",\r
+"postfix_expression","integer_expression","function_call","function_call_generic",\r
+"function_call_header_no_parameters","function_call_header_with_parameters",\r
+"function_call_header","function_identifier","constructor_identifier","unary_expression",\r
+"unary_operator","multiplicative_expression","additive_expression","shift_expression",\r
+"relational_expression","equality_expression","and_expression","exclusive_or_expression",\r
+"inclusive_or_expression","logical_and_expression","logical_xor_expression",\r
+"logical_or_expression","conditional_expression","assignment_expression","assignment_operator",\r
+"expression","constant_expression","declaration","function_prototype","function_declarator",\r
+"function_header_with_parameters","function_header","parameter_declarator","parameter_declaration",\r
+"parameter_qualifier","parameter_type_specifier","init_declarator_list","single_declaration",\r
+"fully_specified_type","type_qualifier","type_specifier","struct_specifier",\r
+"struct_declaration_list","struct_declaration","struct_declarator_list","struct_declarator",\r
+"initializer","declaration_statement","statement","simple_statement","compound_statement",\r
+"@1","@2","statement_no_new_scope","compound_statement_no_new_scope","statement_list",\r
+"expression_statement","selection_statement","selection_rest_statement","condition",\r
+"iteration_statement","@3","@4","@5","for_init_statement","conditionopt","for_rest_statement",\r
+"jump_statement","translation_unit","external_declaration","function_definition",\r
+"@6",""\r
+};\r
+#endif\r
+\r
+static const short yyr1[] = { 0,\r
+ 93, 94, 94, 94, 94, 94, 95, 95, 95, 95,\r
+ 95, 95, 96, 97, 98, 98, 99, 99, 100, 100,\r
+ 101, 102, 102, 103, 103, 103, 103, 103, 103, 103,\r
+ 103, 103, 103, 103, 103, 103, 103, 103, 103, 104,\r
+ 104, 104, 104, 105, 105, 105, 105, 106, 106, 106,\r
+ 106, 107, 107, 107, 108, 108, 108, 109, 109, 109,\r
+ 109, 109, 110, 110, 110, 111, 111, 112, 112, 113,\r
+ 113, 114, 114, 115, 115, 116, 116, 117, 117, 118,\r
+ 118, 119, 119, 119, 119, 119, 119, 119, 119, 119,\r
+ 119, 119, 120, 120, 121, 122, 122, 123, 124, 124,\r
+ 125, 125, 126, 127, 127, 128, 128, 128, 128, 129,\r
+ 129, 129, 129, 130, 130, 131, 131, 131, 131, 131,\r
+ 132, 132, 132, 132, 132, 133, 133, 134, 134, 134,\r
+ 134, 135, 135, 135, 135, 135, 135, 135, 135, 135,\r
+ 135, 135, 135, 135, 135, 135, 135, 135, 135, 135,\r
+ 135, 135, 135, 135, 135, 136, 136, 137, 137, 138,\r
+ 139, 139, 140, 140, 141, 142, 143, 143, 144, 144,\r
+ 144, 144, 144, 145, 146, 147, 145, 148, 148, 149,\r
+ 149, 150, 150, 151, 151, 152, 153, 153, 154, 154,\r
+ 156, 155, 157, 155, 158, 155, 159, 159, 160, 160,\r
+ 161, 161, 162, 162, 162, 162, 162, 163, 163, 164,\r
+ 164, 166, 165\r
+};\r
+\r
+static const short yyr2[] = { 0,\r
+ 1, 1, 1, 1, 1, 3, 1, 4, 1, 3,\r
+ 2, 2, 1, 1, 2, 2, 2, 1, 2, 3,\r
+ 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 2, 2, 2, 1, 1, 1, 1, 1, 3, 3,\r
+ 3, 1, 3, 3, 1, 3, 3, 1, 3, 3,\r
+ 3, 3, 1, 3, 3, 1, 3, 1, 3, 1,\r
+ 3, 1, 3, 1, 3, 1, 3, 1, 5, 1,\r
+ 3, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 3, 1, 2, 2, 2, 1, 1,\r
+ 2, 3, 3, 2, 5, 3, 2, 3, 2, 0,\r
+ 1, 1, 1, 1, 4, 1, 3, 5, 6, 5,\r
+ 1, 2, 4, 5, 4, 1, 2, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 1, 1, 5, 4, 1, 2, 3,\r
+ 1, 3, 1, 4, 1, 1, 1, 1, 1, 1,\r
+ 1, 1, 1, 2, 0, 0, 5, 1, 1, 2,\r
+ 3, 1, 2, 1, 2, 5, 3, 1, 1, 4,\r
+ 0, 6, 0, 8, 0, 7, 1, 1, 1, 0,\r
+ 2, 3, 2, 2, 2, 3, 2, 1, 2, 1,\r
+ 1, 0, 3\r
+};\r
+\r
+static const short yydefact[] = { 0,\r
+ 129, 128, 135, 133, 134, 139, 140, 141, 142, 143,\r
+ 144, 136, 137, 138, 145, 146, 147, 131, 130, 0,\r
+ 132, 148, 149, 150, 151, 152, 153, 155, 211, 212,\r
+ 0, 100, 110, 0, 116, 121, 0, 126, 154, 0,\r
+ 208, 210, 0, 0, 96, 0, 98, 110, 111, 112,\r
+ 113, 101, 0, 110, 0, 97, 122, 127, 209, 0,\r
+ 0, 0, 158, 0, 213, 102, 107, 109, 114, 0,\r
+ 117, 103, 0, 0, 0, 163, 0, 161, 157, 159,\r
+ 135, 133, 134, 0, 0, 193, 0, 0, 0, 0,\r
+ 139, 140, 141, 142, 143, 144, 136, 137, 138, 145,\r
+ 146, 147, 0, 1, 155, 4, 3, 5, 0, 0,\r
+ 0, 175, 180, 184, 46, 45, 47, 44, 2, 7,\r
+ 40, 9, 14, 0, 0, 18, 0, 22, 48, 0,\r
+ 52, 55, 58, 63, 66, 68, 70, 72, 74, 76,\r
+ 78, 80, 93, 0, 166, 0, 169, 182, 168, 167,\r
+ 0, 170, 171, 172, 173, 104, 0, 106, 108, 0,\r
+ 0, 26, 24, 25, 30, 31, 32, 33, 34, 35,\r
+ 27, 28, 29, 36, 37, 38, 39, 123, 48, 95,\r
+ 0, 165, 125, 156, 0, 0, 160, 204, 203, 0,\r
+ 195, 0, 207, 205, 0, 191, 41, 42, 0, 174,\r
+ 0, 11, 12, 0, 0, 16, 15, 0, 17, 19,\r
+ 21, 83, 84, 86, 85, 88, 89, 90, 91, 92,\r
+ 87, 82, 0, 43, 0, 0, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 185, 181, 183, 0, 0,\r
+ 118, 0, 120, 124, 0, 162, 0, 0, 0, 206,\r
+ 0, 6, 176, 0, 13, 10, 20, 81, 49, 50,\r
+ 51, 54, 53, 56, 57, 61, 62, 59, 60, 64,\r
+ 65, 67, 69, 71, 73, 75, 77, 0, 94, 0,\r
+ 115, 119, 164, 0, 198, 197, 200, 0, 189, 0,\r
+ 0, 0, 8, 0, 105, 0, 199, 0, 0, 188,\r
+ 186, 0, 0, 177, 79, 0, 201, 0, 0, 0,\r
+ 179, 192, 178, 0, 202, 196, 187, 190, 194, 0,\r
+ 0\r
+};\r
+\r
+static const short yydefgoto[] = { 119,\r
+ 120, 121, 264, 122, 123, 124, 125, 126, 127, 128,\r
+ 129, 130, 131, 132, 133, 134, 135, 136, 137, 138,\r
+ 139, 140, 141, 142, 143, 223, 144, 181, 145, 146,\r
+ 31, 32, 33, 67, 52, 53, 68, 34, 35, 36,\r
+ 37, 38, 39, 62, 63, 77, 78, 183, 147, 148,\r
+ 149, 150, 201, 302, 322, 323, 151, 152, 153, 311,\r
+ 301, 154, 261, 190, 258, 297, 308, 309, 155, 40,\r
+ 41, 42, 46\r
+};\r
+\r
+static const short yypact[] = { 1130,\r
+-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,\r
+-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, -31,\r
+-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, -36,\r
+ -43, 8, 4, -50,-32768, 38, 1169,-32768,-32768, 197,\r
+-32768,-32768, 21, 1169,-32768, 58,-32768, 35,-32768,-32768,\r
+-32768,-32768, 1169, 69, 93,-32768, -54,-32768,-32768, 1169,\r
+ 94, 1047,-32768, 257,-32768,-32768,-32768,-32768, -20, 1169,\r
+ -3,-32768, 707, 979, 1086, 66, -21,-32768,-32768,-32768,\r
+ 70, 71, 72, 59, 63,-32768, 75, 76, 67, 775,\r
+ 78, 81, 82, 83, 84, 85, 87, 88, 89, 90,\r
+ 91, 95, 96, 97, 98,-32768,-32768,-32768, 979, 979,\r
+ 979, 117,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,\r
+ 10,-32768,-32768, 92, 0, 843, 99,-32768, 55, 979,\r
+ 24, -12, 53, -40, 51, 79, 73, 104, 138, 140,\r
+ -39,-32768,-32768, 7,-32768, -36,-32768,-32768,-32768,-32768,\r
+ 338,-32768,-32768,-32768,-32768, 128, 979,-32768,-32768, 911,\r
+ 979,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,\r
+-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,\r
+ 133,-32768,-32768,-32768, 979, 94,-32768,-32768,-32768, 419,\r
+-32768, 979,-32768,-32768, 17,-32768,-32768,-32768, 2,-32768,\r
+ 419,-32768,-32768, 979, 159,-32768,-32768, 979,-32768,-32768,\r
+-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,\r
+-32768,-32768, 979,-32768, 979, 979, 979, 979, 979, 979,\r
+ 979, 979, 979, 979, 979, 979, 979, 979, 979, 979,\r
+ 979, 979, 979, 979, 979,-32768,-32768,-32768, 979, 135,\r
+-32768, 136,-32768,-32768, 137,-32768, 175, 571, 3,-32768,\r
+ 639,-32768, 419, 139, 149,-32768,-32768,-32768,-32768,-32768,\r
+-32768, 24, 24, -12, -12, 53, 53, 53, 53, -40,\r
+ -40, 51, 79, 73, 104, 138, 140, 48,-32768, 154,\r
+-32768,-32768,-32768, 158,-32768,-32768, 639, 419, 149, 190,\r
+ 169, 167,-32768, 979,-32768, 979,-32768, 163, 173, 233,\r
+-32768, 171, 500,-32768,-32768, 12, 979, 500, 419, 979,\r
+-32768,-32768,-32768, 166, 149,-32768,-32768,-32768,-32768, 250,\r
+-32768\r
+};\r
+\r
+static const short yypgoto[] = {-32768,\r
+-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,\r
+ -53,-32768, -117, -104, -143, -107, 14, 15, 13, 18,\r
+ 16, 42,-32768, -57, -74,-32768, -49, -154, 5, 9,\r
+-32768,-32768,-32768, 185, 208, 232, 217,-32768,-32768, -247,\r
+ -29, -16,-32768, 244, -52,-32768, 119, -159, 52, -150,\r
+ -288,-32768,-32768,-32768, -9, 260, 110, 54,-32768,-32768,\r
+ 19,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,\r
+ 273,-32768,-32768\r
+};\r
+\r
+\r
+#define YYLAST 1212\r
+\r
+\r
+static const short yytable[] = { 182,\r
+ 248, 253, 250, 54, 29, 252, 1, 2, 30, 80,\r
+ 43, 232, 233, 300, 72, 180, 73, 243, 54, 179,\r
+ 58, 156, 80, 74, 321, 55, 47, 61, 56, 321,\r
+ 255, 49, 50, 51, 18, 19, 69, 1, 2, 257,\r
+ 195, 44, 45, 61, 29, 61, 234, 235, 30, 300,\r
+ 157, 210, 244, 69, 186, 197, 198, 187, 61, 202,\r
+ 203, 199, 49, 50, 51, 18, 19, 160, 228, 207,\r
+ 229, 262, 298, -99, 161, 208, 224, 245, 245, 57,\r
+ 204, 324, 245, 48, 205, 246, 182, 245, 276, 277,\r
+ 278, 279, 245, 60, 290, 260, 49, 50, 51, 180,\r
+ 230, 231, 180, 179, 236, 237, 179, 225, 226, 227,\r
+ 272, 273, 248, 212, 213, 214, 215, 216, 217, 218,\r
+ 219, 220, 221, 245, 304, 274, 275, 180, 280, 281,\r
+ 64, 179, 222, 267, 71, 76, 185, 188, -26, -24,\r
+ -25, 189, 259, 191, 192, 193, -30, 310, 268, -31,\r
+ -32, -33, -34, -35, 265, -27, -28, -29, -36, -37,\r
+ 328, 206, 239, -38, 196, -23, -39, 211, 327, 238,\r
+ 289, 269, 270, 271, 179, 179, 179, 179, 179, 179,\r
+ 179, 179, 179, 179, 179, 179, 179, 179, 179, 179,\r
+ 200, 180, 240, 241, 288, 179, 330, 242, 249, 1,\r
+ 2, 3, 4, 5, 254, 266, 291, 292, 293, 294,\r
+ 303, 299, 6, 7, 8, 9, 10, 11, 12, 13,\r
+ 14, 15, 16, 17, 245, 305, 306, 18, 19, 20,\r
+ 21, 312, 22, 23, 24, 25, 26, 27, 313, 28,\r
+ 314, 317, 318, 319, 329, 182, 315, 299, 320, 331,\r
+ 179, 282, 284, 283, 158, 66, 316, 286, 285, 1,\r
+ 2, 81, 82, 83, 84, 85, 86, 325, 87, 88,\r
+ 89, 90, 91, 92, 93, 94, 95, 96, 97, 98,\r
+ 99, 100, 101, 102, 287, 70, 159, 18, 19, 20,\r
+ 21, 103, 22, 23, 24, 25, 26, 27, 104, 105,\r
+ 106, 107, 108, 75, 256, 65, 109, 110, 326, 295,\r
+ 263, 296, 59, 0, 0, 307, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 111, 0, 0, 0, 112,\r
+ 113, 0, 0, 0, 0, 114, 115, 116, 117, 118,\r
+ 1, 2, 81, 82, 83, 84, 85, 86, 0, 87,\r
+ 88, 89, 90, 91, 92, 93, 94, 95, 96, 97,\r
+ 98, 99, 100, 101, 102, 0, 0, 0, 18, 19,\r
+ 20, 21, 103, 22, 23, 24, 25, 26, 27, 104,\r
+ 105, 106, 107, 108, 0, 0, 0, 109, 110, 0,\r
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 0, 111, 0, 0, 0,\r
+ 112, 247, 0, 0, 0, 0, 114, 115, 116, 117,\r
+ 118, 1, 2, 81, 82, 83, 84, 85, 86, 0,\r
+ 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,\r
+ 97, 98, 99, 100, 101, 102, 0, 0, 0, 18,\r
+ 19, 20, 21, 103, 22, 23, 24, 25, 26, 27,\r
+ 104, 105, 106, 107, 108, 0, 0, 0, 109, 110,\r
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 0, 0, 111, 0, 0,\r
+ 0, 112, 0, 0, 0, 0, 0, 114, 115, 116,\r
+ 117, 118, 1, 2, 81, 82, 83, 84, 85, 86,\r
+ 0, 87, 88, 89, 90, 91, 92, 93, 94, 95,\r
+ 96, 97, 98, 99, 100, 101, 102, 0, 0, 0,\r
+ 18, 19, 20, 21, 103, 22, 23, 24, 25, 26,\r
+ 27, 104, 105, 106, 107, 108, 0, 0, 0, 109,\r
+ 110, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 0, 0, 0, 111, 0,\r
+ 0, 0, 64, 1, 2, 81, 82, 83, 114, 115,\r
+ 116, 117, 118, 0, 0, 0, 91, 92, 93, 94,\r
+ 95, 96, 97, 98, 99, 100, 101, 102, 0, 0,\r
+ 0, 18, 19, 20, 21, 0, 22, 23, 24, 25,\r
+ 26, 27, 104, 105, 106, 107, 108, 0, 0, 0,\r
+ 109, 110, 0, 0, 0, 0, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 111,\r
+ 0, 1, 2, 81, 82, 83, 0, 0, 0, 114,\r
+ 115, 116, 117, 118, 91, 92, 93, 94, 95, 96,\r
+ 97, 98, 99, 100, 101, 102, 0, 0, 0, 18,\r
+ 19, 20, 21, 0, 22, 23, 24, 25, 26, 27,\r
+ 104, 105, 106, 107, 108, 0, 0, 0, 109, 110,\r
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 0, 0, 111, 0, 0,\r
+ 0, 162, 163, 164, 0, 0, 0, 0, 115, 116,\r
+ 117, 118, 165, 166, 167, 168, 169, 170, 171, 172,\r
+ 173, 174, 175, 176, 0, 0, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 0, 0, 0, 104, 177,\r
+ 106, 107, 108, 0, 0, 0, 109, 110, 0, 0,\r
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 111, 0, 0, 178, 162,\r
+ 163, 164, 0, 0, 0, 0, 115, 116, 117, 118,\r
+ 165, 166, 167, 168, 169, 170, 171, 172, 173, 174,\r
+ 175, 176, 0, 0, 0, 0, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 0, 104, 177, 106, 107,\r
+ 108, 0, 0, 0, 109, 110, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+ 0, 0, 0, 111, 0, 0, 0, 162, 163, 164,\r
+ 0, 0, 0, 194, 115, 116, 117, 118, 165, 166,\r
+ 167, 168, 169, 170, 171, 172, 173, 174, 175, 176,\r
+ 0, 0, 0, 0, 0, 0, 209, 0, 0, 0,\r
+ 0, 0, 0, 0, 104, 177, 106, 107, 108, 0,\r
+ 0, 0, 109, 110, 0, 0, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+ 0, 111, 0, 0, 0, 162, 163, 164, 0, 0,\r
+ 0, 0, 115, 116, 117, 118, 165, 166, 167, 168,\r
+ 169, 170, 171, 172, 173, 174, 175, 176, 0, 0,\r
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+ 0, 0, 104, 177, 106, 107, 108, 0, 0, 0,\r
+ 109, 110, 0, 0, 0, 0, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 111,\r
+ 0, 0, 251, 162, 163, 164, 0, 0, 0, 0,\r
+ 115, 116, 117, 118, 165, 166, 167, 168, 169, 170,\r
+ 171, 172, 173, 174, 175, 176, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+ 104, 177, 106, 107, 108, 0, 0, 0, 109, 110,\r
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 0, 0, 111, 0, 0,\r
+ 0, 3, 4, 5, 0, 0, 0, 0, 115, 116,\r
+ 117, 118, 6, 7, 8, 9, 10, 11, 12, 13,\r
+ 14, 15, 16, 17, 0, 0, 0, 0, 0, 20,\r
+ 21, 0, 22, 23, 24, 25, 26, 27, 0, 28,\r
+ 3, 4, 5, 0, 0, 0, 0, 0, 0, 0,\r
+ 0, 6, 7, 8, 9, 10, 11, 12, 13, 14,\r
+ 15, 16, 17, 0, 0, 0, 0, 0, 20, 21,\r
+ 79, 22, 23, 24, 25, 26, 27, 0, 28, 0,\r
+ 0, 0, 1, 2, 3, 4, 5, 0, 0, 0,\r
+ 0, 0, 0, 0, 0, 6, 7, 8, 9, 10,\r
+ 11, 12, 13, 14, 15, 16, 17, 0, 0, 184,\r
+ 18, 19, 20, 21, 0, 22, 23, 24, 25, 26,\r
+ 27, 0, 28, 3, 4, 5, 0, 0, 0, 0,\r
+ 0, 0, 0, 0, 6, 7, 8, 9, 10, 11,\r
+ 12, 13, 14, 15, 16, 17, 0, 0, 0, 0,\r
+ 0, 20, 21, 0, 22, 23, 24, 25, 26, 27,\r
+ 0, 28\r
+};\r
+\r
+static const short yycheck[] = { 74,\r
+ 151, 161, 157, 33, 0, 160, 3, 4, 0, 62,\r
+ 42, 52, 53, 261, 69, 73, 71, 57, 48, 73,\r
+ 37, 42, 75, 78, 313, 76, 70, 44, 79, 318,\r
+ 185, 28, 29, 30, 31, 32, 53, 3, 4, 190,\r
+ 90, 73, 79, 60, 40, 62, 87, 88, 40, 297,\r
+ 71, 126, 92, 70, 76, 109, 110, 79, 75, 50,\r
+ 51, 111, 28, 29, 30, 31, 32, 71, 81, 70,\r
+ 83, 70, 70, 70, 78, 76, 130, 76, 76, 42,\r
+ 71, 70, 76, 76, 75, 79, 161, 76, 232, 233,\r
+ 234, 235, 76, 73, 249, 79, 28, 29, 30, 157,\r
+ 48, 49, 160, 157, 54, 55, 160, 84, 85, 86,\r
+ 228, 229, 263, 59, 60, 61, 62, 63, 64, 65,\r
+ 66, 67, 68, 76, 77, 230, 231, 185, 236, 237,\r
+ 73, 185, 78, 208, 42, 42, 71, 79, 69, 69,\r
+ 69, 79, 192, 69, 69, 79, 69, 298, 223, 69,\r
+ 69, 69, 69, 69, 204, 69, 69, 69, 69, 69,\r
+ 320, 70, 90, 69, 69, 69, 69, 69, 319, 91,\r
+ 245, 225, 226, 227, 228, 229, 230, 231, 232, 233,\r
+ 234, 235, 236, 237, 238, 239, 240, 241, 242, 243,\r
+ 74, 249, 89, 56, 244, 249, 0, 58, 71, 3,\r
+ 4, 5, 6, 7, 72, 47, 72, 72, 72, 35,\r
+ 72, 261, 16, 17, 18, 19, 20, 21, 22, 23,\r
+ 24, 25, 26, 27, 76, 72, 69, 31, 32, 33,\r
+ 34, 42, 36, 37, 38, 39, 40, 41, 70, 43,\r
+ 74, 79, 70, 11, 79, 320, 304, 297, 78, 0,\r
+ 304, 238, 240, 239, 70, 48, 306, 242, 241, 3,\r
+ 4, 5, 6, 7, 8, 9, 10, 317, 12, 13,\r
+ 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,\r
+ 24, 25, 26, 27, 243, 54, 70, 31, 32, 33,\r
+ 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,\r
+ 44, 45, 46, 60, 186, 46, 50, 51, 318, 258,\r
+ 201, 258, 40, -1, -1, 297, -1, -1, -1, -1,\r
+ -1, -1, -1, -1, -1, 69, -1, -1, -1, 73,\r
+ 74, -1, -1, -1, -1, 79, 80, 81, 82, 83,\r
+ 3, 4, 5, 6, 7, 8, 9, 10, -1, 12,\r
+ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,\r
+ 23, 24, 25, 26, 27, -1, -1, -1, 31, 32,\r
+ 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,\r
+ 43, 44, 45, 46, -1, -1, -1, 50, 51, -1,\r
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ -1, -1, -1, -1, -1, -1, 69, -1, -1, -1,\r
+ 73, 74, -1, -1, -1, -1, 79, 80, 81, 82,\r
+ 83, 3, 4, 5, 6, 7, 8, 9, 10, -1,\r
+ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,\r
+ 22, 23, 24, 25, 26, 27, -1, -1, -1, 31,\r
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,\r
+ 42, 43, 44, 45, 46, -1, -1, -1, 50, 51,\r
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ -1, -1, -1, -1, -1, -1, -1, 69, -1, -1,\r
+ -1, 73, -1, -1, -1, -1, -1, 79, 80, 81,\r
+ 82, 83, 3, 4, 5, 6, 7, 8, 9, 10,\r
+ -1, 12, 13, 14, 15, 16, 17, 18, 19, 20,\r
+ 21, 22, 23, 24, 25, 26, 27, -1, -1, -1,\r
+ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,\r
+ 41, 42, 43, 44, 45, 46, -1, -1, -1, 50,\r
+ 51, -1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ -1, -1, -1, -1, -1, -1, -1, -1, 69, -1,\r
+ -1, -1, 73, 3, 4, 5, 6, 7, 79, 80,\r
+ 81, 82, 83, -1, -1, -1, 16, 17, 18, 19,\r
+ 20, 21, 22, 23, 24, 25, 26, 27, -1, -1,\r
+ -1, 31, 32, 33, 34, -1, 36, 37, 38, 39,\r
+ 40, 41, 42, 43, 44, 45, 46, -1, -1, -1,\r
+ 50, 51, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, 69,\r
+ -1, 3, 4, 5, 6, 7, -1, -1, -1, 79,\r
+ 80, 81, 82, 83, 16, 17, 18, 19, 20, 21,\r
+ 22, 23, 24, 25, 26, 27, -1, -1, -1, 31,\r
+ 32, 33, 34, -1, 36, 37, 38, 39, 40, 41,\r
+ 42, 43, 44, 45, 46, -1, -1, -1, 50, 51,\r
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ -1, -1, -1, -1, -1, -1, -1, 69, -1, -1,\r
+ -1, 5, 6, 7, -1, -1, -1, -1, 80, 81,\r
+ 82, 83, 16, 17, 18, 19, 20, 21, 22, 23,\r
+ 24, 25, 26, 27, -1, -1, -1, -1, -1, -1,\r
+ -1, -1, -1, -1, -1, -1, -1, -1, 42, 43,\r
+ 44, 45, 46, -1, -1, -1, 50, 51, -1, -1,\r
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ -1, -1, -1, -1, -1, 69, -1, -1, 72, 5,\r
+ 6, 7, -1, -1, -1, -1, 80, 81, 82, 83,\r
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,\r
+ 26, 27, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ -1, -1, -1, -1, -1, -1, 42, 43, 44, 45,\r
+ 46, -1, -1, -1, 50, 51, -1, -1, -1, -1,\r
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ -1, -1, -1, 69, -1, -1, -1, 5, 6, 7,\r
+ -1, -1, -1, 79, 80, 81, 82, 83, 16, 17,\r
+ 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,\r
+ -1, -1, -1, -1, -1, -1, 34, -1, -1, -1,\r
+ -1, -1, -1, -1, 42, 43, 44, 45, 46, -1,\r
+ -1, -1, 50, 51, -1, -1, -1, -1, -1, -1,\r
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ -1, 69, -1, -1, -1, 5, 6, 7, -1, -1,\r
+ -1, -1, 80, 81, 82, 83, 16, 17, 18, 19,\r
+ 20, 21, 22, 23, 24, 25, 26, 27, -1, -1,\r
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ -1, -1, 42, 43, 44, 45, 46, -1, -1, -1,\r
+ 50, 51, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, 69,\r
+ -1, -1, 72, 5, 6, 7, -1, -1, -1, -1,\r
+ 80, 81, 82, 83, 16, 17, 18, 19, 20, 21,\r
+ 22, 23, 24, 25, 26, 27, -1, -1, -1, -1,\r
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ 42, 43, 44, 45, 46, -1, -1, -1, 50, 51,\r
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\r
+ -1, -1, -1, -1, -1, -1, -1, 69, -1, -1,\r
+ -1, 5, 6, 7, -1, -1, -1, -1, 80, 81,\r
+ 82, 83, 16, 17, 18, 19, 20, 21, 22, 23,\r
+ 24, 25, 26, 27, -1, -1, -1, -1, -1, 33,\r
+ 34, -1, 36, 37, 38, 39, 40, 41, -1, 43,\r
+ 5, 6, 7, -1, -1, -1, -1, -1, -1, -1,\r
+ -1, 16, 17, 18, 19, 20, 21, 22, 23, 24,\r
+ 25, 26, 27, -1, -1, -1, -1, -1, 33, 34,\r
+ 74, 36, 37, 38, 39, 40, 41, -1, 43, -1,\r
+ -1, -1, 3, 4, 5, 6, 7, -1, -1, -1,\r
+ -1, -1, -1, -1, -1, 16, 17, 18, 19, 20,\r
+ 21, 22, 23, 24, 25, 26, 27, -1, -1, 74,\r
+ 31, 32, 33, 34, -1, 36, 37, 38, 39, 40,\r
+ 41, -1, 43, 5, 6, 7, -1, -1, -1, -1,\r
+ -1, -1, -1, -1, 16, 17, 18, 19, 20, 21,\r
+ 22, 23, 24, 25, 26, 27, -1, -1, -1, -1,\r
+ -1, 33, 34, -1, 36, 37, 38, 39, 40, 41,\r
+ -1, 43\r
+};\r
+#define YYPURE 1\r
+\r
+/* -*-C-*- Note some compilers choke on comments on `#line' lines. */\r
+\r
+/* Skeleton output parser for bison,\r
+ Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.\r
+\r
+ This program is free software; you can redistribute it and/or modify\r
+ it under the terms of the GNU General Public License as published by\r
+ the Free Software Foundation; either version 2, or (at your option)\r
+ any later version.\r
+\r
+ This program is distributed in the hope that it will be useful,\r
+ but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ GNU General Public License for more details.\r
+\r
+ You should have received a copy of the GNU General Public License\r
+ along with this program; if not, write to the Free Software\r
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */\r
+\r
+/* As a special exception, when this file is copied by Bison into a\r
+ Bison output file, you may use that output file without restriction.\r
+ This special exception was added by the Free Software Foundation\r
+ in version 1.24 of Bison. */\r
+\r
+#ifdef __GNUC__\r
+#define alloca __builtin_alloca\r
+#else /* not __GNUC__ */\r
+#if HAVE_ALLOCA_H\r
+#include <alloca.h>\r
+#else /* not HAVE_ALLOCA_H */\r
+#ifdef _AIX\r
+ #pragma alloca\r
+#else /* not _AIX */\r
+char *alloca ();\r
+#endif /* not _AIX */\r
+#endif /* not HAVE_ALLOCA_H */\r
+#endif /* not __GNUC__ */\r
+\r
+extern void yyerror(char* s);\r
+\r
+#ifndef alloca\r
+#ifdef __GNUC__\r
+#define alloca __builtin_alloca\r
+#else /* not GNU C. */\r
+#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)\r
+#include <alloca.h>\r
+#else /* not sparc */\r
+#if (defined (MSDOS) && !defined (__TURBOC__)) || defined (WIN32)\r
+#include <malloc.h>\r
+#else /* not MSDOS, or __TURBOC__ */\r
+#if defined(_AIX)\r
+#include <malloc.h>\r
+ #pragma alloca\r
+#else /* not MSDOS, __TURBOC__, or _AIX */\r
+#ifdef __hpux\r
+#ifdef __cplusplus\r
+extern "C" {\r
+void *alloca (unsigned int);\r
+};\r
+#else /* not __cplusplus */\r
+void *alloca ();\r
+#endif /* not __cplusplus */\r
+#endif /* __hpux */\r
+#endif /* not _AIX */\r
+#endif /* not MSDOS, or __TURBOC__ */\r
+#endif /* not sparc. */\r
+#endif /* not GNU C. */\r
+#endif /* alloca not defined. */\r
+\r
+/* This is the parser code that is written into each bison parser\r
+ when the %semantic_parser declaration is not specified in the grammar.\r
+ It was written by Richard Stallman by simplifying the hairy parser\r
+ used when %semantic_parser is specified. */\r
+\r
+/* Note: there must be only one dollar sign in this file.\r
+ It is replaced by the list of actions, each action\r
+ as one case of the switch. */\r
+\r
+#define yyerrok (yyerrstatus = 0)\r
+#define yyclearin (yychar = YYEMPTY)\r
+#define YYEMPTY -2\r
+#define YYEOF 0\r
+#define YYACCEPT return(0)\r
+#define YYABORT return(1)\r
+#define YYERROR goto yyerrlab1\r
+/* Like YYERROR except do call yyerror.\r
+ This remains here temporarily to ease the\r
+ transition to the new meaning of YYERROR, for GCC.\r
+ Once GCC version 2 has supplanted version 1, this can go. */\r
+#define YYFAIL goto yyerrlab\r
+#define YYRECOVERING() (!!yyerrstatus)\r
+#define YYBACKUP(token, value) \\r
+do \\r
+ if (yychar == YYEMPTY && yylen == 1) \\r
+ { yychar = (token), yylval = (value); \\r
+ yychar1 = YYTRANSLATE (yychar); \\r
+ YYPOPSTACK; \\r
+ goto yybackup; \\r
+ } \\r
+ else \\r
+ { yyerror ("syntax error: cannot back up"); YYERROR; } \\r
+while (0)\r
+\r
+#define YYTERROR 1\r
+#define YYERRCODE 256\r
+\r
+#ifndef YYPURE\r
+#define YYLEX yylex()\r
+#endif\r
+\r
+#ifdef YYPURE\r
+#ifdef YYLSP_NEEDED\r
+#ifdef YYLEX_PARAM\r
+#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)\r
+#else\r
+#define YYLEX yylex(&yylval, &yylloc)\r
+#endif\r
+#else /* not YYLSP_NEEDED */\r
+#ifdef YYLEX_PARAM\r
+#define YYLEX yylex(&yylval, YYLEX_PARAM)\r
+#else\r
+#define YYLEX yylex(&yylval)\r
+#endif\r
+#endif /* not YYLSP_NEEDED */\r
+#endif\r
+\r
+/* If nonreentrant, generate the variables here */\r
+\r
+#ifndef YYPURE\r
+\r
+int yychar; /* the lookahead symbol */\r
+YYSTYPE yylval; /* the semantic value of the */\r
+ /* lookahead symbol */\r
+\r
+#ifdef YYLSP_NEEDED\r
+YYLTYPE yylloc; /* location data for the lookahead */\r
+ /* symbol */\r
+#endif\r
+\r
+int yynerrs; /* number of parse errors so far */\r
+#endif /* not YYPURE */\r
+\r
+#if YYDEBUG != 0\r
+int yydebug; /* nonzero means print parse trace */\r
+/* Since this is uninitialized, it does not stop multiple parsers\r
+ from coexisting. */\r
+#endif\r
+\r
+/* YYINITDEPTH indicates the initial size of the parser's stacks */\r
+\r
+#ifndef YYINITDEPTH\r
+#define YYINITDEPTH 200\r
+#endif\r
+\r
+/* YYMAXDEPTH is the maximum size the stacks can grow to\r
+ (effective only if the built-in stack extension method is used). */\r
+\r
+#if YYMAXDEPTH == 0\r
+#undef YYMAXDEPTH\r
+#endif\r
+\r
+#ifndef YYMAXDEPTH\r
+#define YYMAXDEPTH 10000\r
+#endif\r
+\r
+/* Prevent warning if -Wstrict-prototypes. */\r
+#ifdef __GNUC__\r
+int yyparse (void);\r
+#endif\r
+\f\r
+#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */\r
+#define __yy_memcpy(FROM,TO,COUNT) __builtin_memcpy(TO,FROM,COUNT)\r
+#else /* not GNU C or C++ */\r
+#ifndef __cplusplus\r
+\r
+/* This is the most reliable way to avoid incompatibilities\r
+ in available built-in functions on various systems. */\r
+static void\r
+__yy_memcpy (from, to, count)\r
+ char *from;\r
+ char *to;\r
+ size_t count;\r
+{\r
+ register char *f = from;\r
+ register char *t = to;\r
+ register size_t i = count;\r
+\r
+ while (i-- > 0)\r
+ *t++ = *f++;\r
+}\r
+\r
+#else /* __cplusplus */\r
+\r
+/* This is the most reliable way to avoid incompatibilities\r
+ in available built-in functions on various systems. */\r
+static void\r
+__yy_memcpy (char *from, char *to, size_t count)\r
+{\r
+ register char *f = from;\r
+ register char *t = to;\r
+ register size_t i = count;\r
+\r
+ while (i-- > 0)\r
+ *t++ = *f++;\r
+}\r
+\r
+#endif\r
+#endif\r
+\r
+/* The user can define YYPARSE_PARAM as the name of an argument to be passed\r
+ into yyparse. The argument should have type void *.\r
+ It should actually point to an object.\r
+ Grammar actions can access the variable by casting it\r
+ to the proper pointer type. */\r
+\r
+#ifdef YYPARSE_PARAM\r
+#ifndef YYPARSE_PARAM_DECL\r
+#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;\r
+#endif \r
+#else\r
+#define YYPARSE_PARAM\r
+#define YYPARSE_PARAM_DECL\r
+#endif\r
+\r
+extern YY_DECL;\r
+\r
+int\r
+yyparse(YYPARSE_PARAM_DECL YYPARSE_PARAM) {\r
+ register int yystate;\r
+ register int yyn;\r
+ register short *yyssp;\r
+ register YYSTYPE *yyvsp;\r
+ int yyerrstatus; /* number of tokens to shift before error messages enabled */\r
+ int yychar1 = 0; /* lookahead token as an internal (translated) token number */\r
+\r
+ short yyssa[YYINITDEPTH]; /* the state stack */\r
+ YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */\r
+\r
+ short *yyss = yyssa; /* refer to the stacks thru separate pointers */\r
+ YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */\r
+\r
+#ifdef YYLSP_NEEDED\r
+ YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */\r
+ YYLTYPE *yyls = yylsa;\r
+ YYLTYPE *yylsp;\r
+\r
+#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)\r
+#else\r
+#define YYPOPSTACK (yyvsp--, yyssp--)\r
+#endif\r
+\r
+ size_t yystacksize = YYINITDEPTH;\r
+\r
+#ifdef YYPURE\r
+ int yychar;\r
+ YYSTYPE yylval;\r
+ int yynerrs;\r
+#ifdef YYLSP_NEEDED\r
+ YYLTYPE yylloc;\r
+#endif\r
+#endif\r
+\r
+ YYSTYPE yyval; /* the variable used to return */\r
+ /* semantic values from the action */\r
+ /* routines */\r
+\r
+ int yylen;\r
+\r
+#if YYDEBUG != 0\r
+ if (yydebug)\r
+ fprintf(stderr, "Starting parse\n");\r
+#endif\r
+\r
+ yystate = 0;\r
+ yyerrstatus = 0;\r
+ yynerrs = 0;\r
+ yychar = YYEMPTY; /* Cause a token to be read. */\r
+\r
+ /* Initialize stack pointers.\r
+ Waste one element of value and location stack\r
+ so that they stay on the same level as the state stack.\r
+ The wasted elements are never initialized. */\r
+\r
+ yyssp = yyss - 1;\r
+ yyvsp = yyvs;\r
+#ifdef YYLSP_NEEDED\r
+ yylsp = yyls;\r
+#endif\r
+\r
+/* Push a new state, which is found in yystate . */\r
+/* In all cases, when you get here, the value and location stacks\r
+ have just been pushed. so pushing a state here evens the stacks. */\r
+yynewstate:\r
+\r
+ *++yyssp = yystate;\r
+\r
+ if (yyssp >= yyss + yystacksize - 1)\r
+ {\r
+ /* Give user a chance to reallocate the stack */\r
+ /* Use copies of these so that the &'s don't force the real ones into memory. */\r
+ YYSTYPE *yyvs1 = yyvs;\r
+ short *yyss1 = yyss;\r
+#ifdef YYLSP_NEEDED\r
+ YYLTYPE *yyls1 = yyls;\r
+#endif\r
+\r
+ /* Get the current used size of the three stacks, in elements. */\r
+ size_t size = yyssp - yyss + 1;\r
+\r
+#ifdef yyoverflow\r
+ /* Each stack pointer address is followed by the size of\r
+ the data in use in that stack, in bytes. */\r
+#ifdef YYLSP_NEEDED\r
+ /* This used to be a conditional around just the two extra args,\r
+ but that might be undefined if yyoverflow is a macro. */\r
+ yyoverflow("parser stack overflow",\r
+ &yyss1, size * sizeof (*yyssp),\r
+ &yyvs1, size * sizeof (*yyvsp),\r
+ &yyls1, size * sizeof (*yylsp),\r
+ &yystacksize);\r
+#else\r
+ yyoverflow("parser stack overflow",\r
+ &yyss1, size * sizeof (*yyssp),\r
+ &yyvs1, size * sizeof (*yyvsp),\r
+ &yystacksize);\r
+#endif\r
+\r
+ yyss = yyss1; yyvs = yyvs1;\r
+#ifdef YYLSP_NEEDED\r
+ yyls = yyls1;\r
+#endif\r
+#else /* no yyoverflow */\r
+ /* Extend the stack our own way. */\r
+ if (yystacksize >= YYMAXDEPTH)\r
+ {\r
+ yyerror("parser stack overflow");\r
+ return 2;\r
+ }\r
+ yystacksize *= 2;\r
+ if (yystacksize > YYMAXDEPTH)\r
+ yystacksize = YYMAXDEPTH;\r
+ yyss = (short *) alloca (yystacksize * sizeof (*yyssp));\r
+ __yy_memcpy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));\r
+ yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));\r
+ __yy_memcpy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));\r
+#ifdef YYLSP_NEEDED\r
+ yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));\r
+ __yy_memcpy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));\r
+#endif\r
+#endif /* no yyoverflow */\r
+\r
+ yyssp = yyss + size - 1;\r
+ yyvsp = yyvs + size - 1;\r
+#ifdef YYLSP_NEEDED\r
+ yylsp = yyls + size - 1;\r
+#endif\r
+\r
+#if YYDEBUG != 0\r
+ if (yydebug)\r
+ fprintf(stderr, "Stack size increased to %d\n", yystacksize);\r
+#endif\r
+\r
+ if (yyssp >= yyss + yystacksize - 1)\r
+ YYABORT;\r
+ }\r
+\r
+#if YYDEBUG != 0\r
+ if (yydebug)\r
+ fprintf(stderr, "Entering state %d\n", yystate);\r
+#endif\r
+\r
+ goto yybackup;\r
+ yybackup:\r
+\r
+/* Do appropriate processing given the current state. */\r
+/* Read a lookahead token if we need one and don't already have one. */\r
+/* yyresume: */\r
+\r
+ /* First try to decide what to do without reference to lookahead token. */\r
+\r
+ yyn = yypact[yystate];\r
+ if (yyn == YYFLAG)\r
+ goto yydefault;\r
+\r
+ /* Not known => get a lookahead token if don't already have one. */\r
+\r
+ /* yychar is either YYEMPTY or YYEOF\r
+ or a valid token in external form. */\r
+\r
+ if (yychar == YYEMPTY)\r
+ {\r
+#if YYDEBUG != 0\r
+ if (yydebug)\r
+ fprintf(stderr, "Reading a token: ");\r
+#endif\r
+ yychar = YYLEX;\r
+ }\r
+\r
+ /* Convert token to internal form (in yychar1) for indexing tables with */\r
+\r
+ if (yychar <= 0) /* This means end of input. */\r
+ {\r
+ yychar1 = 0;\r
+ yychar = YYEOF; /* Don't call YYLEX any more */\r
+\r
+#if YYDEBUG != 0\r
+ if (yydebug)\r
+ fprintf(stderr, "Now at end of input.\n");\r
+#endif\r
+ }\r
+ else\r
+ {\r
+ yychar1 = YYTRANSLATE(yychar);\r
+\r
+#if YYDEBUG != 0\r
+ if (yydebug)\r
+ {\r
+ fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);\r
+ /* Give the individual parser a way to print the precise meaning\r
+ of a token, for further debugging info. */\r
+#ifdef YYPRINT\r
+ YYPRINT (stderr, yychar, yylval);\r
+#endif\r
+ fprintf (stderr, ")\n");\r
+ }\r
+#endif\r
+ }\r
+\r
+ yyn += yychar1;\r
+ if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)\r
+ goto yydefault;\r
+\r
+ yyn = yytable[yyn];\r
+\r
+ /* yyn is what to do for this token type in this state.\r
+ Negative => reduce, -yyn is rule number.\r
+ Positive => shift, yyn is new state.\r
+ New state is final state => don't bother to shift,\r
+ just return success.\r
+ 0, or most negative number => error. */\r
+\r
+ if (yyn < 0)\r
+ {\r
+ if (yyn == YYFLAG)\r
+ goto yyerrlab;\r
+ yyn = -yyn;\r
+ goto yyreduce;\r
+ }\r
+ else if (yyn == 0)\r
+ goto yyerrlab;\r
+\r
+ if (yyn == YYFINAL)\r
+ YYACCEPT;\r
+\r
+ /* Shift the lookahead token. */\r
+\r
+#if YYDEBUG != 0\r
+ if (yydebug)\r
+ fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);\r
+#endif\r
+\r
+ /* Discard the token being shifted unless it is eof. */\r
+ if (yychar != YYEOF)\r
+ yychar = YYEMPTY;\r
+\r
+ *++yyvsp = yylval;\r
+#ifdef YYLSP_NEEDED\r
+ *++yylsp = yylloc;\r
+#endif\r
+\r
+ /* count tokens shifted since error; after three, turn off error status. */\r
+ if (yyerrstatus) yyerrstatus--;\r
+\r
+ yystate = yyn;\r
+ goto yynewstate;\r
+\r
+/* Do the default action for the current state. */\r
+yydefault:\r
+\r
+ yyn = yydefact[yystate];\r
+ if (yyn == 0)\r
+ goto yyerrlab;\r
+\r
+/* Do a reduction. yyn is the number of a rule to reduce with. */\r
+yyreduce:\r
+ yylen = yyr2[yyn];\r
+ if (yylen > 0)\r
+ yyval = yyvsp[1-yylen]; /* implement default value of the action */\r
+\r
+#if YYDEBUG != 0\r
+ if (yydebug)\r
+ {\r
+ int i;\r
+\r
+ fprintf (stderr, "Reducing via rule %d (line %d), ",\r
+ yyn, yyrline[yyn]);\r
+\r
+ /* Print the symbols being reduced, and their result. */\r
+ for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)\r
+ fprintf (stderr, "%s ", yytname[yyrhs[i]]);\r
+ fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);\r
+ }\r
+#endif\r
+\r
+\r
+ switch (yyn) {\r
+\r
+case 1:\r
+#line 210 "glslang.y"\r
+{\r
+ // The symbol table search was done in the lexical phase\r
+ const TSymbol* symbol = yyvsp[0].lex.symbol;\r
+ const TVariable* variable;\r
+ if (symbol == 0) {\r
+ parseContext.error(yyvsp[0].lex.line, "undeclared identifier", yyvsp[0].lex.string->c_str(), "");\r
+ parseContext.recover();\r
+ TVariable* fakeVariable = new TVariable(yyvsp[0].lex.string, TType(EbtFloat));\r
+ parseContext.symbolTable.insert(*fakeVariable);\r
+ variable = fakeVariable;\r
+ } else {\r
+ // This identifier can only be a variable type symbol \r
+ if (! symbol->isVariable()) {\r
+ parseContext.error(yyvsp[0].lex.line, "variable expected", yyvsp[0].lex.string->c_str(), "");\r
+ parseContext.recover();\r
+ }\r
+ variable = static_cast<const TVariable*>(symbol);\r
+ }\r
+\r
+ // don't delete $1.string, it's used by error recovery, and the pool\r
+ // pop will reclaim the memory\r
+\r
+ if (variable->getType().getQualifier() == EvqConst ) {\r
+ constUnion* constArray = variable->getConstPointer();\r
+ TType t = TType(variable->getType());\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addConstantUnion(constArray, t, yyvsp[0].lex.line); \r
+ } else\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addSymbol(variable->getUniqueId(), \r
+ variable->getName(), \r
+ variable->getType(), yyvsp[0].lex.line);\r
+ ;\r
+ break;}\r
+case 2:\r
+#line 244 "glslang.y"\r
+{\r
+ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode;\r
+ ;\r
+ break;}\r
+case 3:\r
+#line 247 "glslang.y"\r
+{\r
+ //\r
+ // INT_TYPE is only 16-bit plus sign bit for vertex/fragment shaders, \r
+ // check for overflow for constants\r
+ //\r
+ if (abs(yyvsp[0].lex.i) >= (1 << 16)) {\r
+ parseContext.error(yyvsp[0].lex.line, " integer constant overflow", "", "");\r
+ parseContext.recover();\r
+ }\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->iConst = yyvsp[0].lex.i;\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtInt, EvqConst), yyvsp[0].lex.line);\r
+ ;\r
+ break;}\r
+case 4:\r
+#line 260 "glslang.y"\r
+{\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->fConst = yyvsp[0].lex.f;\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtFloat, EvqConst), yyvsp[0].lex.line);\r
+ ;\r
+ break;}\r
+case 5:\r
+#line 265 "glslang.y"\r
+{\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->bConst = yyvsp[0].lex.b;\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), yyvsp[0].lex.line);\r
+ ;\r
+ break;}\r
+case 6:\r
+#line 270 "glslang.y"\r
+{\r
+ yyval.interm.intermTypedNode = yyvsp[-1].interm.intermTypedNode;\r
+ ;\r
+ break;}\r
+case 7:\r
+#line 276 "glslang.y"\r
+{ \r
+ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode;\r
+ ;\r
+ break;}\r
+case 8:\r
+#line 279 "glslang.y"\r
+{\r
+ if (!yyvsp[-3].interm.intermTypedNode->isArray() && !yyvsp[-3].interm.intermTypedNode->isMatrix() && !yyvsp[-3].interm.intermTypedNode->isVector()) {\r
+ if (yyvsp[-3].interm.intermTypedNode->getAsSymbolNode())\r
+ parseContext.error(yyvsp[-2].lex.line, " left of '[' is not of type array, matrix, or vector ", yyvsp[-3].interm.intermTypedNode->getAsSymbolNode()->getSymbol().c_str(), "");\r
+ else\r
+ parseContext.error(yyvsp[-2].lex.line, " left of '[' is not of type array, matrix, or vector ", "expression", "");\r
+ parseContext.recover();\r
+ }\r
+ if (yyvsp[-3].interm.intermTypedNode->getType().getQualifier() == EvqConst && !yyvsp[-3].interm.intermTypedNode->isArray() && yyvsp[-1].interm.intermTypedNode->getQualifier() == EvqConst) {\r
+ if (yyvsp[-3].interm.intermTypedNode->isVector()) { // constant folding for vectors\r
+ TVectorFields fields;\r
+ fields.num = 1;\r
+ fields.offsets[0] = yyvsp[-1].interm.intermTypedNode->getAsConstantUnion()->getUnionArrayPointer()->iConst; // need to do it this way because v.xy sends fields integer array\r
+ yyval.interm.intermTypedNode = parseContext.addConstVectorNode(fields, yyvsp[-3].interm.intermTypedNode, yyvsp[-2].lex.line);\r
+ } else if (yyvsp[-3].interm.intermTypedNode->isMatrix()) { // constant folding for matrices\r
+ yyval.interm.intermTypedNode = parseContext.addConstMatrixNode(yyvsp[-1].interm.intermTypedNode->getAsConstantUnion()->getUnionArrayPointer()->iConst, yyvsp[-3].interm.intermTypedNode, yyvsp[-2].lex.line);\r
+ }\r
+ } else {\r
+ if (yyvsp[-1].interm.intermTypedNode->getQualifier() == EvqConst) {\r
+ if ((yyvsp[-3].interm.intermTypedNode->isVector() || yyvsp[-3].interm.intermTypedNode->isMatrix()) && yyvsp[-3].interm.intermTypedNode->getType().getNominalSize() <= yyvsp[-1].interm.intermTypedNode->getAsConstantUnion()->getUnionArrayPointer()->iConst && !yyvsp[-3].interm.intermTypedNode->isArray() ) {\r
+ parseContext.error(yyvsp[-2].lex.line, "", "[", "field selection out of range '%d'", yyvsp[-1].interm.intermTypedNode->getAsConstantUnion()->getUnionArrayPointer()->iConst);\r
+ parseContext.recover();\r
+ } else {\r
+ if (yyvsp[-3].interm.intermTypedNode->isArray()) {\r
+ if (yyvsp[-3].interm.intermTypedNode->getType().getArraySize() == 0) {\r
+ if (yyvsp[-3].interm.intermTypedNode->getType().getMaxArraySize() <= yyvsp[-1].interm.intermTypedNode->getAsConstantUnion()->getUnionArrayPointer()->iConst) {\r
+ if (parseContext.arraySetMaxSize(yyvsp[-3].interm.intermTypedNode->getAsSymbolNode(), yyvsp[-3].interm.intermTypedNode->getTypePointer(), yyvsp[-1].interm.intermTypedNode->getAsConstantUnion()->getUnionArrayPointer()->iConst, true, yyvsp[-2].lex.line))\r
+ parseContext.recover(); \r
+ } else {\r
+ if (parseContext.arraySetMaxSize(yyvsp[-3].interm.intermTypedNode->getAsSymbolNode(), yyvsp[-3].interm.intermTypedNode->getTypePointer(), 0, false, yyvsp[-2].lex.line))\r
+ parseContext.recover(); \r
+ }\r
+ } else if ( yyvsp[-1].interm.intermTypedNode->getAsConstantUnion()->getUnionArrayPointer()->iConst >= yyvsp[-3].interm.intermTypedNode->getType().getArraySize()) {\r
+ parseContext.error(yyvsp[-2].lex.line, "", "[", "array index out of range '%d'", yyvsp[-1].interm.intermTypedNode->getAsConstantUnion()->getUnionArrayPointer()->iConst);\r
+ parseContext.recover();\r
+ }\r
+ }\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addIndex(EOpIndexDirect, yyvsp[-3].interm.intermTypedNode, yyvsp[-1].interm.intermTypedNode, yyvsp[-2].lex.line);\r
+ }\r
+ } else {\r
+ if (yyvsp[-3].interm.intermTypedNode->isArray() && yyvsp[-3].interm.intermTypedNode->getType().getArraySize() == 0) {\r
+ parseContext.error(yyvsp[-2].lex.line, "", "[", "array must be redeclared with a size before being indexed with a variable");\r
+ parseContext.recover();\r
+ }\r
+ \r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addIndex(EOpIndexIndirect, yyvsp[-3].interm.intermTypedNode, yyvsp[-1].interm.intermTypedNode, yyvsp[-2].lex.line);\r
+ }\r
+ } \r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->fConst = 0.0;\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtFloat, EvqConst), yyvsp[-2].lex.line);\r
+ } else if (yyvsp[-3].interm.intermTypedNode->isArray()) {\r
+ if (yyvsp[-3].interm.intermTypedNode->getType().getStruct())\r
+ yyval.interm.intermTypedNode->setType(TType(yyvsp[-3].interm.intermTypedNode->getType().getStruct(), yyvsp[-3].interm.intermTypedNode->getType().getTypeName()));\r
+ else\r
+ yyval.interm.intermTypedNode->setType(TType(yyvsp[-3].interm.intermTypedNode->getBasicType(), EvqTemporary, yyvsp[-3].interm.intermTypedNode->getNominalSize(), yyvsp[-3].interm.intermTypedNode->isMatrix()));\r
+ } else if (yyvsp[-3].interm.intermTypedNode->isMatrix() && yyvsp[-3].interm.intermTypedNode->getType().getQualifier() == EvqConst) \r
+ yyval.interm.intermTypedNode->setType(TType(yyvsp[-3].interm.intermTypedNode->getBasicType(), EvqConst, yyvsp[-3].interm.intermTypedNode->getNominalSize())); \r
+ else if (yyvsp[-3].interm.intermTypedNode->isMatrix()) \r
+ yyval.interm.intermTypedNode->setType(TType(yyvsp[-3].interm.intermTypedNode->getBasicType(), EvqTemporary, yyvsp[-3].interm.intermTypedNode->getNominalSize())); \r
+ else if (yyvsp[-3].interm.intermTypedNode->isVector() && yyvsp[-3].interm.intermTypedNode->getType().getQualifier() == EvqConst) \r
+ yyval.interm.intermTypedNode->setType(TType(yyvsp[-3].interm.intermTypedNode->getBasicType(), EvqConst)); \r
+ else if (yyvsp[-3].interm.intermTypedNode->isVector()) \r
+ yyval.interm.intermTypedNode->setType(TType(yyvsp[-3].interm.intermTypedNode->getBasicType(), EvqTemporary));\r
+ else\r
+ yyval.interm.intermTypedNode->setType(yyvsp[-3].interm.intermTypedNode->getType()); \r
+ ;\r
+ break;}\r
+case 9:\r
+#line 347 "glslang.y"\r
+{\r
+ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode;\r
+ ;\r
+ break;}\r
+case 10:\r
+#line 350 "glslang.y"\r
+{ \r
+ if (yyvsp[-2].interm.intermTypedNode->isArray()) {\r
+ parseContext.error(yyvsp[0].lex.line, "cannot apply dot operator to an array", ".", "");\r
+ parseContext.recover();\r
+ }\r
+\r
+ if (yyvsp[-2].interm.intermTypedNode->isVector()) {\r
+ TVectorFields fields;\r
+ if (! parseContext.parseVectorFields(*yyvsp[0].lex.string, yyvsp[-2].interm.intermTypedNode->getNominalSize(), fields, yyvsp[0].lex.line)) {\r
+ fields.num = 1;\r
+ fields.offsets[0] = 0;\r
+ parseContext.recover();\r
+ }\r
+\r
+ if (yyvsp[-2].interm.intermTypedNode->getType().getQualifier() == EvqConst) { // constant folding for vector fields\r
+ yyval.interm.intermTypedNode = parseContext.addConstVectorNode(fields, yyvsp[-2].interm.intermTypedNode, yyvsp[0].lex.line);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-2].interm.intermTypedNode;\r
+ }\r
+ else\r
+ yyval.interm.intermTypedNode->setType(TType(yyvsp[-2].interm.intermTypedNode->getBasicType(), EvqConst, (int) (*yyvsp[0].lex.string).size()));\r
+ } else {\r
+ if (fields.num == 1) {\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->iConst = fields.offsets[0];\r
+ TIntermTyped* index = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtInt, EvqConst), yyvsp[0].lex.line);\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addIndex(EOpIndexDirect, yyvsp[-2].interm.intermTypedNode, index, yyvsp[-1].lex.line);\r
+ yyval.interm.intermTypedNode->setType(TType(yyvsp[-2].interm.intermTypedNode->getBasicType()));\r
+ } else {\r
+ TString vectorString = *yyvsp[0].lex.string;\r
+ TIntermTyped* index = parseContext.intermediate.addSwizzle(fields, yyvsp[0].lex.line); \r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addIndex(EOpVectorSwizzle, yyvsp[-2].interm.intermTypedNode, index, yyvsp[-1].lex.line);\r
+ yyval.interm.intermTypedNode->setType(TType(yyvsp[-2].interm.intermTypedNode->getBasicType(),EvqTemporary, (int) vectorString.size())); \r
+ }\r
+ }\r
+ } else if (yyvsp[-2].interm.intermTypedNode->isMatrix()) {\r
+ TMatrixFields fields;\r
+ if (! parseContext.parseMatrixFields(*yyvsp[0].lex.string, yyvsp[-2].interm.intermTypedNode->getNominalSize(), fields, yyvsp[0].lex.line)) {\r
+ fields.wholeRow = false;\r
+ fields.wholeCol = false;\r
+ fields.row = 0;\r
+ fields.col = 0;\r
+ parseContext.recover();\r
+ }\r
+\r
+ if (fields.wholeRow || fields.wholeCol) {\r
+ parseContext.error(yyvsp[-1].lex.line, " non-scalar fields not implemented yet", ".", "");\r
+ parseContext.recover();\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->iConst = 0;\r
+ TIntermTyped* index = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtInt, EvqConst), yyvsp[0].lex.line);\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addIndex(EOpIndexDirect, yyvsp[-2].interm.intermTypedNode, index, yyvsp[-1].lex.line); \r
+ yyval.interm.intermTypedNode->setType(TType(yyvsp[-2].interm.intermTypedNode->getBasicType(), EvqTemporary, yyvsp[-2].interm.intermTypedNode->getNominalSize()));\r
+ } else {\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->iConst = fields.col * yyvsp[-2].interm.intermTypedNode->getNominalSize() + fields.row;\r
+ TIntermTyped* index = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtInt, EvqConst), yyvsp[0].lex.line);\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addIndex(EOpIndexDirect, yyvsp[-2].interm.intermTypedNode, index, yyvsp[-1].lex.line); \r
+ yyval.interm.intermTypedNode->setType(TType(yyvsp[-2].interm.intermTypedNode->getBasicType()));\r
+ }\r
+ } else if (yyvsp[-2].interm.intermTypedNode->getBasicType() == EbtStruct) {\r
+ bool fieldFound = false;\r
+ TTypeList* fields = yyvsp[-2].interm.intermTypedNode->getType().getStruct();\r
+ if (fields == 0) {\r
+ parseContext.error(yyvsp[-1].lex.line, "structure has no fields", "Internal Error", "");\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-2].interm.intermTypedNode;\r
+ } else {\r
+ unsigned int i;\r
+ for (i = 0; i < fields->size(); ++i) {\r
+ if ((*fields)[i].type->getFieldName() == *yyvsp[0].lex.string) {\r
+ fieldFound = true;\r
+ break;\r
+ } \r
+ }\r
+ if (fieldFound) {\r
+ if (yyvsp[-2].interm.intermTypedNode->getType().getQualifier() == EvqConst) {\r
+ yyval.interm.intermTypedNode = parseContext.addConstStruct(*yyvsp[0].lex.string, yyvsp[-2].interm.intermTypedNode, yyvsp[-1].lex.line);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-2].interm.intermTypedNode;\r
+ }\r
+ else {\r
+ yyval.interm.intermTypedNode->setType(*(*fields)[i].type);\r
+ // change the qualifier of the return type, not of the structure field\r
+ // as the structure definition is shared between various structures.\r
+ yyval.interm.intermTypedNode->getTypePointer()->changeQualifier(EvqConst);\r
+ }\r
+ } else {\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->iConst = i;\r
+ TIntermTyped* index = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtInt, EvqConst), yyvsp[0].lex.line);\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addIndex(EOpIndexDirectStruct, yyvsp[-2].interm.intermTypedNode, index, yyvsp[-1].lex.line); \r
+ yyval.interm.intermTypedNode->setType(*(*fields)[i].type);\r
+ }\r
+ } else {\r
+ parseContext.error(yyvsp[-1].lex.line, " no such field in structure", yyvsp[0].lex.string->c_str(), "");\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-2].interm.intermTypedNode;\r
+ }\r
+ }\r
+ } else {\r
+ parseContext.error(yyvsp[-1].lex.line, " field selection requires structure, vector, or matrix on left hand side", yyvsp[0].lex.string->c_str(), "");\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-2].interm.intermTypedNode;\r
+ }\r
+ // don't delete $3.string, it's from the pool\r
+ ;\r
+ break;}\r
+case 11:\r
+#line 459 "glslang.y"\r
+{\r
+ if (parseContext.lValueErrorCheck(yyvsp[0].lex.line, "++", yyvsp[-1].interm.intermTypedNode))\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addUnaryMath(EOpPostIncrement, yyvsp[-1].interm.intermTypedNode, yyvsp[0].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.unaryOpError(yyvsp[0].lex.line, "++", yyvsp[-1].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-1].interm.intermTypedNode;\r
+ }\r
+ ;\r
+ break;}\r
+case 12:\r
+#line 469 "glslang.y"\r
+{\r
+ if (parseContext.lValueErrorCheck(yyvsp[0].lex.line, "--", yyvsp[-1].interm.intermTypedNode))\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addUnaryMath(EOpPostDecrement, yyvsp[-1].interm.intermTypedNode, yyvsp[0].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.unaryOpError(yyvsp[0].lex.line, "--", yyvsp[-1].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-1].interm.intermTypedNode;\r
+ }\r
+ ;\r
+ break;}\r
+case 13:\r
+#line 482 "glslang.y"\r
+{\r
+ if (parseContext.integerErrorCheck(yyvsp[0].interm.intermTypedNode, "[]"))\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode; \r
+ ;\r
+ break;}\r
+case 14:\r
+#line 490 "glslang.y"\r
+{\r
+ TFunction* fnCall = yyvsp[0].interm.function;\r
+ TOperator op = fnCall->getBuiltInOp();\r
+ \r
+ if (op != EOpNull) {\r
+ //\r
+ // Then this should be a constructor.\r
+ //\r
+ TType type(EbtVoid); // use this to get the type back\r
+ if (parseContext.constructorErrorCheck(yyvsp[0].interm.line, yyvsp[0].interm.intermNode, *fnCall, op, &type)) {\r
+ yyval.interm.intermTypedNode = 0;\r
+ } else {\r
+ //\r
+ // It's a constructor, of type 'type'.\r
+ //\r
+ yyval.interm.intermTypedNode = parseContext.addConstructor(yyvsp[0].interm.intermNode, &type, op, fnCall, yyvsp[0].interm.line);\r
+ }\r
+ \r
+ if (yyval.interm.intermTypedNode == 0) { \r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.setAggregateOperator(0, op, yyvsp[0].interm.line);\r
+ }\r
+ yyval.interm.intermTypedNode->setType(type);\r
+ } else {\r
+ //\r
+ // Not a constructor. Find it in the symbol table.\r
+ //\r
+ const TFunction* fnCandidate;\r
+ bool builtIn;\r
+ fnCandidate = parseContext.findFunction(yyvsp[0].interm.line, fnCall, &builtIn);\r
+ if (fnCandidate) {\r
+ //\r
+ // A declared function. But, it might still map to a built-in\r
+ // operation.\r
+ //\r
+ op = fnCandidate->getBuiltInOp();\r
+ if (builtIn && op != EOpNull) {\r
+ //\r
+ // A function call mapped to a built-in operation.\r
+ //\r
+ if (fnCandidate->getParamCount() == 1) {\r
+ //\r
+ // Treat it like a built-in unary operator.\r
+ //\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addUnaryMath(op, yyvsp[0].interm.intermNode, 0, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.error(yyvsp[0].interm.intermNode->getLine(), " wrong operand type", "Internal Error", \r
+ "built in unary operator function. Type: %s",\r
+ static_cast<TIntermTyped*>(yyvsp[0].interm.intermNode)->getCompleteString().c_str());\r
+ YYERROR;\r
+ }\r
+ } else {\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.setAggregateOperator(yyvsp[0].interm.intermAggregate, op, yyvsp[0].interm.line);\r
+ }\r
+ } else {\r
+ // This is a real function call\r
+ \r
+ yyval.interm.intermTypedNode = parseContext.intermediate.setAggregateOperator(yyvsp[0].interm.intermAggregate, EOpFunctionCall, yyvsp[0].interm.line);\r
+ yyval.interm.intermTypedNode->setType(fnCandidate->getReturnType()); \r
+ \r
+ // this is how we know whether the given function is a builtIn function or a user defined function\r
+ // if builtIn == false, it's a userDefined -> could be an overloaded builtIn function also\r
+ // if builtIn == true, it's definitely a builtIn function with EOpNull\r
+ if (!builtIn) \r
+ yyval.interm.intermTypedNode->getAsAggregate()->setUserDefined(); \r
+ yyval.interm.intermTypedNode->getAsAggregate()->setName(fnCandidate->getMangledName());\r
+\r
+ TQualifier qual;\r
+ TQualifierList& qualifierList = yyval.interm.intermTypedNode->getAsAggregate()->getQualifier();\r
+ for (int i = 0; i < fnCandidate->getParamCount(); ++i) {\r
+ qual = (*fnCandidate)[i].type->getQualifier();\r
+ if (qual == EvqOut || qual == EvqInOut) {\r
+ if (parseContext.lValueErrorCheck(yyval.interm.intermTypedNode->getLine(), "assign", yyval.interm.intermTypedNode->getAsAggregate()->getSequence()[i]->getAsTyped())) {\r
+ parseContext.error(yyvsp[0].interm.intermNode->getLine(), "Constant value cannot be passed for 'out' or 'inout' parameters.", "Error", "");\r
+ parseContext.recover();\r
+ }\r
+ }\r
+ qualifierList.push_back(qual);\r
+ }\r
+ }\r
+ yyval.interm.intermTypedNode->setType(fnCandidate->getReturnType());\r
+ } else {\r
+ // error message was put out by PaFindFunction()\r
+ // Put on a dummy node for error recovery\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->fConst = 0.0;\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtFloat, EvqConst), yyvsp[0].interm.line);\r
+ parseContext.recover();\r
+ }\r
+ }\r
+ delete fnCall;\r
+ ;\r
+ break;}\r
+case 15:\r
+#line 585 "glslang.y"\r
+{\r
+ yyval.interm = yyvsp[-1].interm;\r
+ yyval.interm.line = yyvsp[0].lex.line;\r
+ ;\r
+ break;}\r
+case 16:\r
+#line 589 "glslang.y"\r
+{\r
+ yyval.interm = yyvsp[-1].interm;\r
+ yyval.interm.line = yyvsp[0].lex.line;\r
+ ;\r
+ break;}\r
+case 17:\r
+#line 596 "glslang.y"\r
+{\r
+ yyval.interm.function = yyvsp[-1].interm.function;\r
+ yyval.interm.intermNode = 0;\r
+ ;\r
+ break;}\r
+case 18:\r
+#line 600 "glslang.y"\r
+{\r
+ yyval.interm.function = yyvsp[0].interm.function;\r
+ yyval.interm.intermNode = 0;\r
+ ;\r
+ break;}\r
+case 19:\r
+#line 607 "glslang.y"\r
+{\r
+ TParameter param = { 0, new TType(yyvsp[0].interm.intermTypedNode->getType()) };\r
+ yyvsp[-1].interm.function->addParameter(param);\r
+ yyval.interm.function = yyvsp[-1].interm.function;\r
+ yyval.interm.intermNode = yyvsp[0].interm.intermTypedNode;\r
+ ;\r
+ break;}\r
+case 20:\r
+#line 613 "glslang.y"\r
+{\r
+ TParameter param = { 0, new TType(yyvsp[0].interm.intermTypedNode->getType()) };\r
+ yyvsp[-2].interm.function->addParameter(param);\r
+ yyval.interm.function = yyvsp[-2].interm.function;\r
+ yyval.interm.intermNode = parseContext.intermediate.growAggregate(yyvsp[-2].interm.intermNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line);\r
+ ;\r
+ break;}\r
+case 21:\r
+#line 622 "glslang.y"\r
+{\r
+ yyval.interm.function = yyvsp[-1].interm.function;\r
+ ;\r
+ break;}\r
+case 22:\r
+#line 628 "glslang.y"\r
+{\r
+ if (yyvsp[0].interm.op == EOpConstructStruct) {\r
+ TString tempString = "";\r
+ TFunction *function = new TFunction(&tempString, *(yyvsp[0].interm.type.userDef), yyvsp[0].interm.op);\r
+ yyval.interm.function = function;\r
+ }\r
+ else {\r
+ TFunction *function = new TFunction(yyvsp[0].interm.op);\r
+ yyval.interm.function = function;\r
+ }\r
+ ;\r
+ break;}\r
+case 23:\r
+#line 639 "glslang.y"\r
+{\r
+ if (parseContext.reservedErrorCheck(yyvsp[0].lex.line, *yyvsp[0].lex.string)) \r
+ parseContext.recover();\r
+ TFunction *function = new TFunction(yyvsp[0].lex.string, TType(EbtVoid));\r
+ yyval.interm.function = function; \r
+ ;\r
+ break;}\r
+case 24:\r
+#line 654 "glslang.y"\r
+{ yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpConstructFloat; ;\r
+ break;}\r
+case 25:\r
+#line 655 "glslang.y"\r
+{ yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpConstructInt; ;\r
+ break;}\r
+case 26:\r
+#line 656 "glslang.y"\r
+{ yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpConstructBool; ;\r
+ break;}\r
+case 27:\r
+#line 657 "glslang.y"\r
+{ yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpConstructVec2; ;\r
+ break;}\r
+case 28:\r
+#line 658 "glslang.y"\r
+{ yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpConstructVec3; ;\r
+ break;}\r
+case 29:\r
+#line 659 "glslang.y"\r
+{ yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpConstructVec4; ;\r
+ break;}\r
+case 30:\r
+#line 660 "glslang.y"\r
+{ FRAG_VERT_ONLY("bvec2", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpConstructBVec2; ;\r
+ break;}\r
+case 31:\r
+#line 661 "glslang.y"\r
+{ FRAG_VERT_ONLY("bvec3", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpConstructBVec3; ;\r
+ break;}\r
+case 32:\r
+#line 662 "glslang.y"\r
+{ FRAG_VERT_ONLY("bvec4", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpConstructBVec4; ;\r
+ break;}\r
+case 33:\r
+#line 663 "glslang.y"\r
+{ FRAG_VERT_ONLY("ivec2", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpConstructIVec2; ;\r
+ break;}\r
+case 34:\r
+#line 664 "glslang.y"\r
+{ FRAG_VERT_ONLY("ivec3", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpConstructIVec3; ;\r
+ break;}\r
+case 35:\r
+#line 665 "glslang.y"\r
+{ FRAG_VERT_ONLY("ivec4", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpConstructIVec4; ;\r
+ break;}\r
+case 36:\r
+#line 666 "glslang.y"\r
+{ FRAG_VERT_ONLY("mat2", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpConstructMat2; ;\r
+ break;}\r
+case 37:\r
+#line 667 "glslang.y"\r
+{ FRAG_VERT_ONLY("mat3", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpConstructMat3; ;\r
+ break;}\r
+case 38:\r
+#line 668 "glslang.y"\r
+{ FRAG_VERT_ONLY("mat4", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpConstructMat4; ;\r
+ break;}\r
+case 39:\r
+#line 669 "glslang.y"\r
+{ \r
+ TType& structure = static_cast<TVariable*>(yyvsp[0].lex.symbol)->getType();\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtStruct, qual, 1, false, false, &structure, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t;\r
+ yyval.interm.line = yyvsp[0].lex.line; \r
+ yyval.interm.op = EOpConstructStruct; \r
+ ;\r
+ break;}\r
+case 40:\r
+#line 680 "glslang.y"\r
+{\r
+ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode;\r
+ ;\r
+ break;}\r
+case 41:\r
+#line 683 "glslang.y"\r
+{\r
+ if (parseContext.lValueErrorCheck(yyvsp[-1].lex.line, "++", yyvsp[0].interm.intermTypedNode))\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addUnaryMath(EOpPreIncrement, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.unaryOpError(yyvsp[-1].lex.line, "++", yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode;\r
+ }\r
+ ;\r
+ break;}\r
+case 42:\r
+#line 693 "glslang.y"\r
+{\r
+ if (parseContext.lValueErrorCheck(yyvsp[-1].lex.line, "--", yyvsp[0].interm.intermTypedNode))\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addUnaryMath(EOpPreDecrement, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.unaryOpError(yyvsp[-1].lex.line, "--", yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode;\r
+ }\r
+ ;\r
+ break;}\r
+case 43:\r
+#line 703 "glslang.y"\r
+{\r
+ if (yyvsp[-1].interm.op != EOpNull) {\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addUnaryMath(yyvsp[-1].interm.op, yyvsp[0].interm.intermTypedNode, yyvsp[-1].interm.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ char* errorOp = "";\r
+ switch(yyvsp[-1].interm.op) {\r
+ case EOpNegative: errorOp = "-"; break;\r
+ case EOpLogicalNot: errorOp = "!"; break;\r
+ case EOpBitwiseNot: errorOp = "~"; break;\r
+ default: break;\r
+ }\r
+ parseContext.unaryOpError(yyvsp[-1].interm.line, errorOp, yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode;\r
+ }\r
+ } else\r
+ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode;\r
+ ;\r
+ break;}\r
+case 44:\r
+#line 725 "glslang.y"\r
+{ yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpNull; ;\r
+ break;}\r
+case 45:\r
+#line 726 "glslang.y"\r
+{ yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpNegative; ;\r
+ break;}\r
+case 46:\r
+#line 727 "glslang.y"\r
+{ yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpLogicalNot; ;\r
+ break;}\r
+case 47:\r
+#line 728 "glslang.y"\r
+{ PACK_UNPACK_ONLY("~", yyvsp[0].lex.line); \r
+ yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpBitwiseNot; ;\r
+ break;}\r
+case 48:\r
+#line 734 "glslang.y"\r
+{ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode; ;\r
+ break;}\r
+case 49:\r
+#line 735 "glslang.y"\r
+{\r
+ FRAG_VERT_ONLY("*", yyvsp[-1].lex.line);\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpMul, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, "*", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-2].interm.intermTypedNode;\r
+ }\r
+ ;\r
+ break;}\r
+case 50:\r
+#line 744 "glslang.y"\r
+{\r
+ FRAG_VERT_ONLY("/", yyvsp[-1].lex.line); \r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpDiv, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, "/", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-2].interm.intermTypedNode;\r
+ }\r
+ ;\r
+ break;}\r
+case 51:\r
+#line 753 "glslang.y"\r
+{\r
+ PACK_UNPACK_ONLY("%", yyvsp[-1].lex.line);\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpMod, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, "%", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-2].interm.intermTypedNode;\r
+ }\r
+ ;\r
+ break;}\r
+case 52:\r
+#line 765 "glslang.y"\r
+{ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode; ;\r
+ break;}\r
+case 53:\r
+#line 766 "glslang.y"\r
+{ \r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpAdd, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, "+", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-2].interm.intermTypedNode;\r
+ }\r
+ ;\r
+ break;}\r
+case 54:\r
+#line 774 "glslang.y"\r
+{\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpSub, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, "-", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-2].interm.intermTypedNode;\r
+ } \r
+ ;\r
+ break;}\r
+case 55:\r
+#line 785 "glslang.y"\r
+{ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode; ;\r
+ break;}\r
+case 56:\r
+#line 786 "glslang.y"\r
+{\r
+ PACK_UNPACK_ONLY("<<", yyvsp[-1].lex.line);\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpLeftShift, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, "<<", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-2].interm.intermTypedNode;\r
+ }\r
+ ;\r
+ break;}\r
+case 57:\r
+#line 795 "glslang.y"\r
+{\r
+ PACK_UNPACK_ONLY(">>", yyvsp[-1].lex.line);\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpRightShift, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, ">>", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-2].interm.intermTypedNode;\r
+ }\r
+ ;\r
+ break;}\r
+case 58:\r
+#line 807 "glslang.y"\r
+{ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode; ;\r
+ break;}\r
+case 59:\r
+#line 808 "glslang.y"\r
+{ \r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpLessThan, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, "<", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->bConst = false;\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), yyvsp[-1].lex.line);\r
+ }\r
+ ;\r
+ break;}\r
+case 60:\r
+#line 818 "glslang.y"\r
+{ \r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpGreaterThan, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, ">", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->bConst = false;\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), yyvsp[-1].lex.line);\r
+ }\r
+ ;\r
+ break;}\r
+case 61:\r
+#line 828 "glslang.y"\r
+{ \r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpLessThanEqual, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, "<=", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->bConst = false;\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), yyvsp[-1].lex.line);\r
+ }\r
+ ;\r
+ break;}\r
+case 62:\r
+#line 838 "glslang.y"\r
+{ \r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpGreaterThanEqual, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, ">=", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->bConst = false;\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), yyvsp[-1].lex.line);\r
+ }\r
+ ;\r
+ break;}\r
+case 63:\r
+#line 851 "glslang.y"\r
+{ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode; ;\r
+ break;}\r
+case 64:\r
+#line 852 "glslang.y"\r
+{ \r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpEqual, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, "==", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->bConst = false;\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), yyvsp[-1].lex.line);\r
+ }\r
+ ;\r
+ break;}\r
+case 65:\r
+#line 862 "glslang.y"\r
+{ \r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpNotEqual, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, "!=", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->bConst = false;\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), yyvsp[-1].lex.line);\r
+ }\r
+ ;\r
+ break;}\r
+case 66:\r
+#line 875 "glslang.y"\r
+{ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode; ;\r
+ break;}\r
+case 67:\r
+#line 876 "glslang.y"\r
+{\r
+ PACK_UNPACK_ONLY("&", yyvsp[-1].lex.line);\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpAnd, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, "&", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-2].interm.intermTypedNode;\r
+ }\r
+ ;\r
+ break;}\r
+case 68:\r
+#line 888 "glslang.y"\r
+{ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode; ;\r
+ break;}\r
+case 69:\r
+#line 889 "glslang.y"\r
+{\r
+ PACK_UNPACK_ONLY("^", yyvsp[-1].lex.line);\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpExclusiveOr, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, "^", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-2].interm.intermTypedNode;\r
+ }\r
+ ;\r
+ break;}\r
+case 70:\r
+#line 901 "glslang.y"\r
+{ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode; ;\r
+ break;}\r
+case 71:\r
+#line 902 "glslang.y"\r
+{\r
+ PACK_UNPACK_ONLY("|", yyvsp[-1].lex.line);\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpInclusiveOr, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, "|", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-2].interm.intermTypedNode;\r
+ }\r
+ ;\r
+ break;}\r
+case 72:\r
+#line 914 "glslang.y"\r
+{ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode; ;\r
+ break;}\r
+case 73:\r
+#line 915 "glslang.y"\r
+{\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpLogicalAnd, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, "&&", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->bConst = false;\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), yyvsp[-1].lex.line);\r
+ }\r
+ ;\r
+ break;}\r
+case 74:\r
+#line 928 "glslang.y"\r
+{ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode; ;\r
+ break;}\r
+case 75:\r
+#line 929 "glslang.y"\r
+{ \r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpLogicalXor, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, "^^", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->bConst = false;\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), yyvsp[-1].lex.line);\r
+ }\r
+ ;\r
+ break;}\r
+case 76:\r
+#line 942 "glslang.y"\r
+{ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode; ;\r
+ break;}\r
+case 77:\r
+#line 943 "glslang.y"\r
+{ \r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addBinaryMath(EOpLogicalOr, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line, parseContext.symbolTable);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-1].lex.line, "||", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ constUnion *unionArray = new constUnion[1];\r
+ unionArray->bConst = false;\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), yyvsp[-1].lex.line);\r
+ }\r
+ ;\r
+ break;}\r
+case 78:\r
+#line 956 "glslang.y"\r
+{ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode; ;\r
+ break;}\r
+case 79:\r
+#line 957 "glslang.y"\r
+{\r
+ if (parseContext.boolErrorCheck(yyvsp[-3].lex.line, yyvsp[-4].interm.intermTypedNode))\r
+ parseContext.recover();\r
+ \r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addSelection(yyvsp[-4].interm.intermTypedNode, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-3].lex.line);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.binaryOpError(yyvsp[-3].lex.line, ":", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode;\r
+ }\r
+ ;\r
+ break;}\r
+case 80:\r
+#line 971 "glslang.y"\r
+{ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode; ;\r
+ break;}\r
+case 81:\r
+#line 972 "glslang.y"\r
+{\r
+ if (parseContext.lValueErrorCheck(yyvsp[-1].interm.line, "assign", yyvsp[-2].interm.intermTypedNode))\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.addAssign(yyvsp[-1].interm.op, yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].interm.line);\r
+ if (yyval.interm.intermTypedNode == 0) {\r
+ parseContext.assignError(yyvsp[-1].interm.line, "assign", yyvsp[-2].interm.intermTypedNode->getCompleteString(), yyvsp[0].interm.intermTypedNode->getCompleteString());\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[-2].interm.intermTypedNode;\r
+ }\r
+ ;\r
+ break;}\r
+case 82:\r
+#line 985 "glslang.y"\r
+{ yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpAssign; ;\r
+ break;}\r
+case 83:\r
+#line 986 "glslang.y"\r
+{ FRAG_VERT_ONLY("*=", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpMulAssign; ;\r
+ break;}\r
+case 84:\r
+#line 987 "glslang.y"\r
+{ FRAG_VERT_ONLY("/=", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpDivAssign; ;\r
+ break;}\r
+case 85:\r
+#line 988 "glslang.y"\r
+{ PACK_UNPACK_ONLY("%=", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpModAssign; ;\r
+ break;}\r
+case 86:\r
+#line 989 "glslang.y"\r
+{ yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpAddAssign; ;\r
+ break;}\r
+case 87:\r
+#line 990 "glslang.y"\r
+{ yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpSubAssign; ;\r
+ break;}\r
+case 88:\r
+#line 991 "glslang.y"\r
+{ PACK_UNPACK_ONLY("<<=", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpLeftShiftAssign; ;\r
+ break;}\r
+case 89:\r
+#line 992 "glslang.y"\r
+{ PACK_UNPACK_ONLY("<<=", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpRightShiftAssign; ;\r
+ break;}\r
+case 90:\r
+#line 993 "glslang.y"\r
+{ PACK_UNPACK_ONLY("&=", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpAndAssign; ;\r
+ break;}\r
+case 91:\r
+#line 994 "glslang.y"\r
+{ PACK_UNPACK_ONLY("^=", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpExclusiveOrAssign; ;\r
+ break;}\r
+case 92:\r
+#line 995 "glslang.y"\r
+{ PACK_UNPACK_ONLY("|=", yyvsp[0].lex.line); yyval.interm.line = yyvsp[0].lex.line; yyval.interm.op = EOpInclusiveOrAssign; ;\r
+ break;}\r
+case 93:\r
+#line 999 "glslang.y"\r
+{\r
+ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode;\r
+ ;\r
+ break;}\r
+case 94:\r
+#line 1002 "glslang.y"\r
+{\r
+ yyval.interm.intermTypedNode = parseContext.intermediate.growAggregate(yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.intermTypedNode, yyvsp[-1].lex.line);\r
+ yyval.interm.intermTypedNode->getAsAggregate()->setOperator(EOpComma); \r
+ yyval.interm.intermTypedNode->setType(yyvsp[0].interm.intermTypedNode->getType());\r
+ ;\r
+ break;}\r
+case 95:\r
+#line 1010 "glslang.y"\r
+{\r
+ if (parseContext.constErrorCheck(yyvsp[0].interm.intermTypedNode))\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode;\r
+ ;\r
+ break;}\r
+case 96:\r
+#line 1018 "glslang.y"\r
+{ yyval.interm.intermNode = 0; ;\r
+ break;}\r
+case 97:\r
+#line 1019 "glslang.y"\r
+{ \r
+ if (yyvsp[-1].interm.intermAggregate)\r
+ yyvsp[-1].interm.intermAggregate->setOperator(EOpSequence); \r
+ yyval.interm.intermNode = yyvsp[-1].interm.intermAggregate; \r
+ ;\r
+ break;}\r
+case 98:\r
+#line 1027 "glslang.y"\r
+{\r
+ //\r
+ // Multiple declarations of the same function are allowed.\r
+ //\r
+ // If this is a definition, the definition production code will check for redefinitions \r
+ // (we don't know at this point if it's a definition or not).\r
+ //\r
+ // Redeclarations are allowed. But, return types and parameter qualifiers must match.\r
+ // \r
+ TFunction* prevDec = static_cast<TFunction*>(parseContext.symbolTable.find(yyvsp[-1].interm.function->getMangledName()));\r
+ if (prevDec) {\r
+ if (prevDec->getReturnType() != yyvsp[-1].interm.function->getReturnType()) {\r
+ parseContext.error(yyvsp[0].lex.line, "overloaded functions must have the same return type", yyvsp[-1].interm.function->getReturnType().getBasicString(), "");\r
+ parseContext.recover();\r
+ }\r
+ for (int i = 0; i < prevDec->getParamCount(); ++i) {\r
+ if ((*prevDec)[i].type->getQualifier() != (*yyvsp[-1].interm.function)[i].type->getQualifier()) {\r
+ parseContext.error(yyvsp[0].lex.line, "overloaded functions must have the same parameter qualifiers", (*yyvsp[-1].interm.function)[i].type->getQualifierString(), "");\r
+ parseContext.recover();\r
+ }\r
+ }\r
+ }\r
+ \r
+ //\r
+ // If this is a redeclaration, it could also be a definition,\r
+ // in which case, we want to use the variable names from this one, and not the one that's\r
+ // being redeclared. So, pass back up this declaration, not the one in the symbol table.\r
+ //\r
+ yyval.interm.function = yyvsp[-1].interm.function;\r
+ yyval.interm.line = yyvsp[0].lex.line;\r
+\r
+ parseContext.symbolTable.insert(*yyval.interm.function);\r
+ ;\r
+ break;}\r
+case 99:\r
+#line 1063 "glslang.y"\r
+{\r
+ yyval.interm.function = yyvsp[0].interm.function;\r
+ ;\r
+ break;}\r
+case 100:\r
+#line 1066 "glslang.y"\r
+{ \r
+ yyval.interm.function = yyvsp[0].interm.function; \r
+ ;\r
+ break;}\r
+case 101:\r
+#line 1073 "glslang.y"\r
+{\r
+ // Add the parameter \r
+ yyval.interm.function = yyvsp[-1].interm.function;\r
+ if (yyvsp[0].interm.param.type->getBasicType() != EbtVoid)\r
+ yyvsp[-1].interm.function->addParameter(yyvsp[0].interm.param);\r
+ else\r
+ delete yyvsp[0].interm.param.type;\r
+ ;\r
+ break;}\r
+case 102:\r
+#line 1081 "glslang.y"\r
+{ \r
+ //\r
+ // Only first parameter of one-parameter functions can be void\r
+ // The check for named parameters not being void is done in parameter_declarator \r
+ //\r
+ if (yyvsp[0].interm.param.type->getBasicType() == EbtVoid) {\r
+ //\r
+ // This parameter > first is void\r
+ //\r
+ parseContext.error(yyvsp[-1].lex.line, "cannot be an argument type except for '(void)'", "void", "");\r
+ parseContext.recover();\r
+ delete yyvsp[0].interm.param.type;\r
+ } else {\r
+ // Add the parameter \r
+ yyval.interm.function = yyvsp[-2].interm.function; \r
+ yyvsp[-2].interm.function->addParameter(yyvsp[0].interm.param);\r
+ }\r
+ ;\r
+ break;}\r
+case 103:\r
+#line 1102 "glslang.y"\r
+{\r
+ if (yyvsp[-2].interm.type.qualifier != EvqGlobal && yyvsp[-2].interm.type.qualifier != EvqTemporary) {\r
+ parseContext.error(yyvsp[-1].lex.line, "no qualifiers allowed for function return", getQualifierString(yyvsp[-2].interm.type.qualifier), "");\r
+ parseContext.recover();\r
+ }\r
+ // make sure a sampler is not involved as well...\r
+ if (parseContext.structQualifierErrorCheck(yyvsp[-1].lex.line, yyvsp[-2].interm.type))\r
+ parseContext.recover();\r
+ \r
+ // Add the function as a prototype after parsing it (we do not support recursion) \r
+ TFunction *function;\r
+ function = new TFunction(yyvsp[-1].lex.string, TType(yyvsp[-2].interm.type));\r
+ yyval.interm.function = function;\r
+ ;\r
+ break;}\r
+case 104:\r
+#line 1120 "glslang.y"\r
+{\r
+ if (yyvsp[-1].interm.type.type == EbtVoid) {\r
+ parseContext.error(yyvsp[0].lex.line, "illegal use of type 'void'", yyvsp[0].lex.string->c_str(), "");\r
+ parseContext.recover();\r
+ }\r
+ if (parseContext.reservedErrorCheck(yyvsp[0].lex.line, *yyvsp[0].lex.string))\r
+ parseContext.recover();\r
+ TParameter param = {yyvsp[0].lex.string, new TType(yyvsp[-1].interm.type)};\r
+ yyval.interm.line = yyvsp[0].lex.line;\r
+ yyval.interm.param = param;\r
+ ;\r
+ break;}\r
+case 105:\r
+#line 1131 "glslang.y"\r
+{\r
+ // Check that we can make an array out of this type\r
+ if (yyvsp[-4].interm.type.array) {\r
+ parseContext.error(yyvsp[-2].lex.line, "cannot declare arrays of this type", TType(yyvsp[-4].interm.type).getCompleteString().c_str(), "");\r
+ parseContext.recover();\r
+ }\r
+ if (parseContext.reservedErrorCheck(yyvsp[-3].lex.line, *yyvsp[-3].lex.string))\r
+ parseContext.recover();\r
+ yyvsp[-4].interm.type.array = true;\r
+ TType* type = new TType(yyvsp[-4].interm.type); \r
+ if (yyvsp[-1].interm.intermTypedNode->getAsConstantUnion())\r
+ type->setArraySize(yyvsp[-1].interm.intermTypedNode->getAsConstantUnion()->getUnionArrayPointer()->iConst);\r
+ TParameter param = { yyvsp[-3].lex.string, type };\r
+ yyval.interm.line = yyvsp[-3].lex.line;\r
+ yyval.interm.param = param;\r
+ ;\r
+ break;}\r
+case 106:\r
+#line 1158 "glslang.y"\r
+{\r
+ yyval.interm = yyvsp[0].interm;\r
+ if (parseContext.paramErrorCheck(yyvsp[0].interm.line, yyvsp[-2].interm.type.qualifier, yyvsp[-1].interm.qualifier, yyval.interm.param.type))\r
+ parseContext.recover();\r
+ ;\r
+ break;}\r
+case 107:\r
+#line 1163 "glslang.y"\r
+{\r
+ yyval.interm = yyvsp[0].interm;\r
+ if (parseContext.parameterSamplerErrorCheck(yyvsp[0].interm.line, yyvsp[-1].interm.qualifier, *yyvsp[0].interm.param.type))\r
+ parseContext.recover();\r
+ if (parseContext.paramErrorCheck(yyvsp[0].interm.line, EvqTemporary, yyvsp[-1].interm.qualifier, yyval.interm.param.type))\r
+ parseContext.recover();\r
+ ;\r
+ break;}\r
+case 108:\r
+#line 1173 "glslang.y"\r
+{\r
+ yyval.interm = yyvsp[0].interm;\r
+ if (parseContext.paramErrorCheck(yyvsp[0].interm.line, yyvsp[-2].interm.type.qualifier, yyvsp[-1].interm.qualifier, yyval.interm.param.type))\r
+ parseContext.recover();\r
+ ;\r
+ break;}\r
+case 109:\r
+#line 1178 "glslang.y"\r
+{\r
+ yyval.interm = yyvsp[0].interm;\r
+ if (parseContext.parameterSamplerErrorCheck(yyvsp[0].interm.line, yyvsp[-1].interm.qualifier, *yyvsp[0].interm.param.type))\r
+ parseContext.recover();\r
+ if (parseContext.paramErrorCheck(yyvsp[0].interm.line, EvqTemporary, yyvsp[-1].interm.qualifier, yyval.interm.param.type))\r
+ parseContext.recover();\r
+ ;\r
+ break;}\r
+case 110:\r
+#line 1188 "glslang.y"\r
+{\r
+ yyval.interm.qualifier = EvqIn;\r
+ ;\r
+ break;}\r
+case 111:\r
+#line 1191 "glslang.y"\r
+{\r
+ yyval.interm.qualifier = EvqIn;\r
+ ;\r
+ break;}\r
+case 112:\r
+#line 1194 "glslang.y"\r
+{\r
+ yyval.interm.qualifier = EvqOut;\r
+ ;\r
+ break;}\r
+case 113:\r
+#line 1197 "glslang.y"\r
+{\r
+ yyval.interm.qualifier = EvqInOut;\r
+ ;\r
+ break;}\r
+case 114:\r
+#line 1203 "glslang.y"\r
+{\r
+ TParameter param = { 0, new TType(yyvsp[0].interm.type) };\r
+ yyval.interm.param = param;\r
+ \r
+ ;\r
+ break;}\r
+case 115:\r
+#line 1208 "glslang.y"\r
+{\r
+ // Check that we can make an array out of this type \r
+ if (yyvsp[-3].interm.type.array) {\r
+ parseContext.error(yyvsp[-2].lex.line, "cannot declare arrays of this type", TType(yyvsp[-3].interm.type).getCompleteString().c_str(), "");\r
+ parseContext.recover();\r
+ }\r
+ yyvsp[-3].interm.type.array = true;\r
+ TType* type = new TType(yyvsp[-3].interm.type); \r
+ if (yyvsp[-1].interm.intermTypedNode->getAsConstantUnion())\r
+ type->setArraySize(yyvsp[-1].interm.intermTypedNode->getAsConstantUnion()->getUnionArrayPointer()->iConst);\r
+\r
+ TParameter param = { 0, type };\r
+ yyval.interm.line = yyvsp[-2].lex.line;\r
+ yyval.interm.param = param;\r
+ ;\r
+ break;}\r
+case 116:\r
+#line 1226 "glslang.y"\r
+{\r
+ yyval.interm = yyvsp[0].interm;\r
+ ;\r
+ break;}\r
+case 117:\r
+#line 1229 "glslang.y"\r
+{\r
+ yyval.interm = yyvsp[-2].interm;\r
+ if (parseContext.structQualifierErrorCheck(yyvsp[0].lex.line, yyvsp[-2].interm.type))\r
+ parseContext.recover();\r
+ \r
+ if (parseContext.nonInitErrorCheck(yyvsp[0].lex.line, *yyvsp[0].lex.string, yyval.interm.type))\r
+ parseContext.recover();\r
+ ;\r
+ break;}\r
+case 118:\r
+#line 1237 "glslang.y"\r
+{\r
+ yyval.interm = yyvsp[-4].interm;\r
+ if (parseContext.structQualifierErrorCheck(yyvsp[-2].lex.line, yyvsp[-4].interm.type))\r
+ parseContext.recover();\r
+ \r
+ if (parseContext.arrayErrorCheck(yyvsp[-1].lex.line, *yyvsp[-2].lex.string, yyval.interm.type, 0))\r
+ parseContext.recover();\r
+ ;\r
+ break;}\r
+case 119:\r
+#line 1245 "glslang.y"\r
+{\r
+ yyval.interm = yyvsp[-5].interm;\r
+ if (parseContext.structQualifierErrorCheck(yyvsp[-3].lex.line, yyvsp[-5].interm.type))\r
+ parseContext.recover();\r
+ \r
+ if (parseContext.arrayErrorCheck(yyvsp[-2].lex.line, *yyvsp[-3].lex.string, yyval.interm.type, yyvsp[-1].interm.intermTypedNode))\r
+ parseContext.recover();\r
+ ;\r
+ break;}\r
+case 120:\r
+#line 1253 "glslang.y"\r
+{\r
+ yyval.interm = yyvsp[-4].interm;\r
+ if (parseContext.structQualifierErrorCheck(yyvsp[-2].lex.line, yyvsp[-4].interm.type))\r
+ parseContext.recover();\r
+ \r
+ TIntermNode* intermNode;\r
+ if (!parseContext.executeInitializer(yyvsp[-2].lex.line, *yyvsp[-2].lex.string, yyvsp[-4].interm.type, yyvsp[0].interm.intermTypedNode, intermNode)) {\r
+ //\r
+ // build the intermediate representation\r
+ //\r
+ if (intermNode)\r
+ yyval.interm.intermAggregate = parseContext.intermediate.growAggregate(yyvsp[-4].interm.intermNode, intermNode, yyvsp[-1].lex.line);\r
+ else\r
+ yyval.interm.intermAggregate = yyvsp[-4].interm.intermAggregate;\r
+ } else {\r
+ parseContext.recover();\r
+ yyval.interm.intermAggregate = 0;\r
+ }\r
+ ;\r
+ break;}\r
+case 121:\r
+#line 1275 "glslang.y"\r
+{\r
+ yyval.interm.type = yyvsp[0].interm.type;\r
+ yyval.interm.intermAggregate = 0;\r
+ ;\r
+ break;}\r
+case 122:\r
+#line 1279 "glslang.y"\r
+{\r
+ yyval.interm.intermAggregate = 0;\r
+ yyval.interm.type = yyvsp[-1].interm.type;\r
+ if (parseContext.structQualifierErrorCheck(yyvsp[0].lex.line, yyvsp[-1].interm.type))\r
+ parseContext.recover();\r
+ \r
+ if (parseContext.nonInitErrorCheck(yyvsp[0].lex.line, *yyvsp[0].lex.string, yyval.interm.type))\r
+ parseContext.recover();\r
+ ;\r
+ break;}\r
+case 123:\r
+#line 1288 "glslang.y"\r
+{\r
+ yyval.interm.intermAggregate = 0;\r
+ yyval.interm.type = yyvsp[-3].interm.type;\r
+ if (parseContext.structQualifierErrorCheck(yyvsp[-2].lex.line, yyvsp[-3].interm.type))\r
+ parseContext.recover();\r
+ \r
+ if (parseContext.arrayErrorCheck(yyvsp[-1].lex.line, *yyvsp[-2].lex.string, yyval.interm.type, 0))\r
+ parseContext.recover();\r
+ ;\r
+ break;}\r
+case 124:\r
+#line 1297 "glslang.y"\r
+{\r
+ yyval.interm.intermAggregate = 0;\r
+ yyval.interm.type = yyvsp[-4].interm.type;\r
+ if (parseContext.structQualifierErrorCheck(yyvsp[-3].lex.line, yyvsp[-4].interm.type))\r
+ parseContext.recover();\r
+ \r
+ if (parseContext.arrayErrorCheck(yyvsp[-2].lex.line, *yyvsp[-3].lex.string, yyval.interm.type, yyvsp[-1].interm.intermTypedNode))\r
+ parseContext.recover();\r
+ ;\r
+ break;}\r
+case 125:\r
+#line 1306 "glslang.y"\r
+{\r
+ yyval.interm.type = yyvsp[-3].interm.type;\r
+ if (parseContext.structQualifierErrorCheck(yyvsp[-2].lex.line, yyvsp[-3].interm.type))\r
+ parseContext.recover();\r
+ \r
+ TIntermNode* intermNode;\r
+ if (!parseContext.executeInitializer(yyvsp[-2].lex.line, *yyvsp[-2].lex.string, yyvsp[-3].interm.type, yyvsp[0].interm.intermTypedNode, intermNode)) {\r
+ //\r
+ // Build intermediate representation\r
+ //\r
+ if (intermNode)\r
+ yyval.interm.intermAggregate = parseContext.intermediate.makeAggregate(intermNode, yyvsp[-1].lex.line);\r
+ else\r
+ yyval.interm.intermAggregate = 0;\r
+ } else {\r
+ parseContext.recover();\r
+ yyval.interm.intermAggregate = 0;\r
+ }\r
+ ;\r
+ break;}\r
+case 126:\r
+#line 1396 "glslang.y"\r
+{\r
+ yyval.interm.type = yyvsp[0].interm.type;\r
+ ;\r
+ break;}\r
+case 127:\r
+#line 1399 "glslang.y"\r
+{ \r
+ TPublicType t = { yyvsp[0].interm.type.type, yyvsp[-1].interm.type.qualifier, yyvsp[0].interm.type.size, yyvsp[0].interm.type.matrix, false, yyvsp[0].interm.type.userDef, 0 };\r
+ if (yyvsp[-1].interm.type.qualifier == EvqAttribute &&\r
+ (yyvsp[0].interm.type.type == EbtBool || yyvsp[0].interm.type.type == EbtInt)) {\r
+ parseContext.error(yyvsp[0].interm.type.line, "cannot be bool or int", getQualifierString(yyvsp[-1].interm.type.qualifier), "");\r
+ parseContext.recover();\r
+ }\r
+ if ((yyvsp[-1].interm.type.qualifier == EvqVaryingIn || yyvsp[-1].interm.type.qualifier == EvqVaryingOut) &&\r
+ (yyvsp[0].interm.type.type == EbtBool || yyvsp[0].interm.type.type == EbtInt)) {\r
+ parseContext.error(yyvsp[0].interm.type.line, "cannot be bool or int", getQualifierString(yyvsp[-1].interm.type.qualifier), "");\r
+ parseContext.recover();\r
+ }\r
+ yyval.interm.type = t;\r
+ ;\r
+ break;}\r
+case 128:\r
+#line 1416 "glslang.y"\r
+{ \r
+ TPublicType t = { EbtVoid, EvqConst, 1, false, false, 0 }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 129:\r
+#line 1420 "glslang.y"\r
+{ \r
+ VERTEX_ONLY("attribute", yyvsp[0].lex.line);\r
+ if (parseContext.globalErrorCheck(yyvsp[0].lex.line, parseContext.symbolTable.atGlobalLevel(), "attribute"))\r
+ parseContext.recover();\r
+ TPublicType t = { EbtVoid, EvqAttribute, 1, false, false, 0 }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 130:\r
+#line 1427 "glslang.y"\r
+{\r
+ if (parseContext.globalErrorCheck(yyvsp[0].lex.line, parseContext.symbolTable.atGlobalLevel(), "varying"))\r
+ parseContext.recover();\r
+ TPublicType t = { EbtVoid, EvqVaryingIn, 1, false, false, 0 };\r
+ if (parseContext.language == EShLangVertex)\r
+ t.qualifier = EvqVaryingOut;\r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 131:\r
+#line 1435 "glslang.y"\r
+{\r
+ if (parseContext.globalErrorCheck(yyvsp[0].lex.line, parseContext.symbolTable.atGlobalLevel(), "uniform"))\r
+ parseContext.recover();\r
+ TPublicType t = { EbtVoid, EvqUniform, 1, false, false, 0 }; \r
+ yyval.interm.type = t;\r
+ ;\r
+ break;}\r
+case 132:\r
+#line 1444 "glslang.y"\r
+{\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtVoid, qual, 1, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 133:\r
+#line 1449 "glslang.y"\r
+{\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtFloat, qual, 1, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 134:\r
+#line 1454 "glslang.y"\r
+{\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtInt, qual, 1, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 135:\r
+#line 1459 "glslang.y"\r
+{\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtBool, qual, 1, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 136:\r
+#line 1470 "glslang.y"\r
+{\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtFloat, qual, 2, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 137:\r
+#line 1475 "glslang.y"\r
+{\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtFloat, qual, 3, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 138:\r
+#line 1480 "glslang.y"\r
+{\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtFloat, qual, 4, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 139:\r
+#line 1485 "glslang.y"\r
+{\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtBool, qual, 2, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 140:\r
+#line 1490 "glslang.y"\r
+{\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtBool, qual, 3, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 141:\r
+#line 1495 "glslang.y"\r
+{\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtBool, qual, 4, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 142:\r
+#line 1500 "glslang.y"\r
+{\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtInt, qual, 2, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 143:\r
+#line 1505 "glslang.y"\r
+{\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtInt, qual, 3, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 144:\r
+#line 1510 "glslang.y"\r
+{\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtInt, qual, 4, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 145:\r
+#line 1515 "glslang.y"\r
+{\r
+ FRAG_VERT_ONLY("mat2", yyvsp[0].lex.line); \r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtFloat, qual, 2, true, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 146:\r
+#line 1521 "glslang.y"\r
+{ \r
+ FRAG_VERT_ONLY("mat3", yyvsp[0].lex.line); \r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtFloat, qual, 3, true, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 147:\r
+#line 1527 "glslang.y"\r
+{ \r
+ FRAG_VERT_ONLY("mat4", yyvsp[0].lex.line);\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtFloat, qual, 4, true, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t; \r
+ ;\r
+ break;}\r
+case 148:\r
+#line 1533 "glslang.y"\r
+{\r
+ FRAG_VERT_ONLY("sampler1D", yyvsp[0].lex.line);\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtSampler1D, qual, 1, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t;\r
+ ;\r
+ break;}\r
+case 149:\r
+#line 1539 "glslang.y"\r
+{\r
+ FRAG_VERT_ONLY("sampler2D", yyvsp[0].lex.line);\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtSampler2D, qual, 1, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t;\r
+ ;\r
+ break;}\r
+case 150:\r
+#line 1545 "glslang.y"\r
+{\r
+ FRAG_VERT_ONLY("sampler3D", yyvsp[0].lex.line);\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtSampler3D, qual, 1, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t;\r
+ ;\r
+ break;}\r
+case 151:\r
+#line 1551 "glslang.y"\r
+{\r
+ FRAG_VERT_ONLY("samplerCube", yyvsp[0].lex.line);\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtSamplerCube, qual, 1, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t;\r
+ ;\r
+ break;}\r
+case 152:\r
+#line 1557 "glslang.y"\r
+{\r
+ FRAG_VERT_ONLY("sampler1DShadow", yyvsp[0].lex.line);\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtSampler1DShadow, qual, 1, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t;\r
+ ;\r
+ break;}\r
+case 153:\r
+#line 1563 "glslang.y"\r
+{\r
+ FRAG_VERT_ONLY("sampler2DShadow", yyvsp[0].lex.line);\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtSampler2DShadow, qual, 1, false, false, 0, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t;\r
+ ;\r
+ break;}\r
+case 154:\r
+#line 1569 "glslang.y"\r
+{\r
+ FRAG_VERT_ONLY("struct", yyvsp[0].interm.type.line);\r
+ yyval.interm.type = yyvsp[0].interm.type;\r
+ yyval.interm.type.qualifier = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ ;\r
+ break;}\r
+case 155:\r
+#line 1574 "glslang.y"\r
+{ \r
+ //\r
+ // This is for user defined type names. The lexical phase looked up the \r
+ // type.\r
+ //\r
+ TType& structure = static_cast<TVariable*>(yyvsp[0].lex.symbol)->getType();\r
+ TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;\r
+ TPublicType t = { EbtStruct, qual, 1, false, false, &structure, yyvsp[0].lex.line }; \r
+ yyval.interm.type = t;\r
+ ;\r
+ break;}\r
+case 156:\r
+#line 1587 "glslang.y"\r
+{\r
+ TType* structure = new TType(yyvsp[-1].interm.typeList, *yyvsp[-3].lex.string);\r
+ TVariable* userTypeDef = new TVariable(yyvsp[-3].lex.string, *structure, true);\r
+ if (! parseContext.symbolTable.insert(*userTypeDef)) {\r
+ parseContext.error(yyvsp[-3].lex.line, "redefinition", yyvsp[-3].lex.string->c_str(), "struct");\r
+ parseContext.recover();\r
+ }\r
+ TPublicType t = { EbtStruct, EvqTemporary, 1, false, false, structure, yyvsp[-4].lex.line };\r
+ yyval.interm.type = t;\r
+ ;\r
+ break;}\r
+case 157:\r
+#line 1597 "glslang.y"\r
+{\r
+ TType* structure = new TType(yyvsp[-1].interm.typeList, TString(""));\r
+ TPublicType t = { EbtStruct, EvqTemporary, 1, false, false, structure, yyvsp[-3].lex.line };\r
+ yyval.interm.type = t;\r
+ ;\r
+ break;}\r
+case 158:\r
+#line 1605 "glslang.y"\r
+{\r
+ yyval.interm.typeList = yyvsp[0].interm.typeList;\r
+ ;\r
+ break;}\r
+case 159:\r
+#line 1608 "glslang.y"\r
+{\r
+ yyval.interm.typeList = yyvsp[-1].interm.typeList;\r
+ for (unsigned int i = 0; i < yyvsp[0].interm.typeList->size(); ++i) {\r
+ for (unsigned int j = 0; j < yyval.interm.typeList->size(); ++j) {\r
+ if ((*yyval.interm.typeList)[j].type->getFieldName() == (*yyvsp[0].interm.typeList)[i].type->getFieldName()) {\r
+ parseContext.error((*yyvsp[0].interm.typeList)[i].line, "duplicate field name in structure:", "struct", (*yyvsp[0].interm.typeList)[i].type->getFieldName().c_str());\r
+ parseContext.recover();\r
+ }\r
+ }\r
+ yyval.interm.typeList->push_back((*yyvsp[0].interm.typeList)[i]);\r
+ }\r
+ ;\r
+ break;}\r
+case 160:\r
+#line 1623 "glslang.y"\r
+{\r
+ yyval.interm.typeList = yyvsp[-1].interm.typeList;\r
+ \r
+ if (parseContext.voidErrorCheck(yyvsp[-2].interm.type.line, (*yyvsp[-1].interm.typeList)[0].type->getFieldName(), yyvsp[-2].interm.type)) {\r
+ parseContext.recover();\r
+ }\r
+ for (unsigned int i = 0; i < yyval.interm.typeList->size(); ++i) {\r
+ //\r
+ // Careful not to replace already know aspects of type, like array-ness\r
+ //\r
+ (*yyval.interm.typeList)[i].type->setType(yyvsp[-2].interm.type.type, yyvsp[-2].interm.type.size, yyvsp[-2].interm.type.matrix, yyvsp[-2].interm.type.userDef);\r
+ if (yyvsp[-2].interm.type.userDef)\r
+ (*yyval.interm.typeList)[i].type->setTypeName(yyvsp[-2].interm.type.userDef->getTypeName());\r
+ }\r
+ ;\r
+ break;}\r
+case 161:\r
+#line 1641 "glslang.y"\r
+{\r
+ yyval.interm.typeList = NewPoolTTypeList();\r
+ yyval.interm.typeList->push_back(yyvsp[0].interm.typeLine);\r
+ ;\r
+ break;}\r
+case 162:\r
+#line 1645 "glslang.y"\r
+{\r
+ yyval.interm.typeList->push_back(yyvsp[0].interm.typeLine);\r
+ ;\r
+ break;}\r
+case 163:\r
+#line 1651 "glslang.y"\r
+{\r
+ yyval.interm.typeLine.type = new TType(EbtVoid);\r
+ yyval.interm.typeLine.line = yyvsp[0].lex.line;\r
+ yyval.interm.typeLine.type->setFieldName(*yyvsp[0].lex.string);\r
+ ;\r
+ break;}\r
+case 164:\r
+#line 1656 "glslang.y"\r
+{\r
+ yyval.interm.typeLine.type = new TType(EbtVoid);\r
+ yyval.interm.typeLine.line = yyvsp[-3].lex.line;\r
+ yyval.interm.typeLine.type->setFieldName(*yyvsp[-3].lex.string);\r
+ \r
+ if (yyvsp[-1].interm.intermTypedNode->getAsConstantUnion() == 0 || yyvsp[-1].interm.intermTypedNode->getAsConstantUnion()->getBasicType() != EbtInt ||\r
+ yyvsp[-1].interm.intermTypedNode->getAsConstantUnion()->getUnionArrayPointer()->iConst <= 0) {\r
+ parseContext.error(yyvsp[-2].lex.line, "structure field array size must be a positive integer", yyvsp[-3].lex.string->c_str(), "");\r
+ parseContext.recover();\r
+ } else { \r
+ yyval.interm.typeLine.type->setArraySize(yyvsp[-1].interm.intermTypedNode->getAsConstantUnion()->getUnionArrayPointer()->iConst);\r
+ }\r
+ ;\r
+ break;}\r
+case 165:\r
+#line 1672 "glslang.y"\r
+{ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode; ;\r
+ break;}\r
+case 166:\r
+#line 1676 "glslang.y"\r
+{ yyval.interm.intermNode = yyvsp[0].interm.intermNode; ;\r
+ break;}\r
+case 167:\r
+#line 1680 "glslang.y"\r
+{ yyval.interm.intermNode = yyvsp[0].interm.intermAggregate; ;\r
+ break;}\r
+case 168:\r
+#line 1681 "glslang.y"\r
+{ yyval.interm.intermNode = yyvsp[0].interm.intermNode; ;\r
+ break;}\r
+case 169:\r
+#line 1687 "glslang.y"\r
+{ yyval.interm.intermNode = yyvsp[0].interm.intermNode; ;\r
+ break;}\r
+case 170:\r
+#line 1688 "glslang.y"\r
+{ yyval.interm.intermNode = yyvsp[0].interm.intermNode; ;\r
+ break;}\r
+case 171:\r
+#line 1689 "glslang.y"\r
+{ yyval.interm.intermNode = yyvsp[0].interm.intermNode; ;\r
+ break;}\r
+case 172:\r
+#line 1690 "glslang.y"\r
+{ yyval.interm.intermNode = yyvsp[0].interm.intermNode; ;\r
+ break;}\r
+case 173:\r
+#line 1691 "glslang.y"\r
+{ yyval.interm.intermNode = yyvsp[0].interm.intermNode; ;\r
+ break;}\r
+case 174:\r
+#line 1695 "glslang.y"\r
+{ yyval.interm.intermAggregate = 0; ;\r
+ break;}\r
+case 175:\r
+#line 1696 "glslang.y"\r
+{ parseContext.symbolTable.push(); ;\r
+ break;}\r
+case 176:\r
+#line 1696 "glslang.y"\r
+{ parseContext.symbolTable.pop(); ;\r
+ break;}\r
+case 177:\r
+#line 1696 "glslang.y"\r
+{\r
+ if (yyvsp[-2].interm.intermAggregate != 0) \r
+ yyvsp[-2].interm.intermAggregate->setOperator(EOpSequence); \r
+ yyval.interm.intermAggregate = yyvsp[-2].interm.intermAggregate;\r
+ ;\r
+ break;}\r
+case 178:\r
+#line 1704 "glslang.y"\r
+{ yyval.interm.intermNode = yyvsp[0].interm.intermNode; ;\r
+ break;}\r
+case 179:\r
+#line 1705 "glslang.y"\r
+{ yyval.interm.intermNode = yyvsp[0].interm.intermNode; ;\r
+ break;}\r
+case 180:\r
+#line 1710 "glslang.y"\r
+{ \r
+ yyval.interm.intermNode = 0; \r
+ ;\r
+ break;}\r
+case 181:\r
+#line 1713 "glslang.y"\r
+{ \r
+ if (yyvsp[-1].interm.intermAggregate)\r
+ yyvsp[-1].interm.intermAggregate->setOperator(EOpSequence); \r
+ yyval.interm.intermNode = yyvsp[-1].interm.intermAggregate; \r
+ ;\r
+ break;}\r
+case 182:\r
+#line 1721 "glslang.y"\r
+{\r
+ yyval.interm.intermAggregate = parseContext.intermediate.makeAggregate(yyvsp[0].interm.intermNode, 0); \r
+ ;\r
+ break;}\r
+case 183:\r
+#line 1724 "glslang.y"\r
+{ \r
+ yyval.interm.intermAggregate = parseContext.intermediate.growAggregate(yyvsp[-1].interm.intermAggregate, yyvsp[0].interm.intermNode, 0);\r
+ ;\r
+ break;}\r
+case 184:\r
+#line 1730 "glslang.y"\r
+{ yyval.interm.intermNode = 0; ;\r
+ break;}\r
+case 185:\r
+#line 1731 "glslang.y"\r
+{ yyval.interm.intermNode = static_cast<TIntermNode*>(yyvsp[-1].interm.intermTypedNode); ;\r
+ break;}\r
+case 186:\r
+#line 1735 "glslang.y"\r
+{ \r
+ if (parseContext.boolErrorCheck(yyvsp[-4].lex.line, yyvsp[-2].interm.intermTypedNode))\r
+ parseContext.recover();\r
+ yyval.interm.intermNode = parseContext.intermediate.addSelection(yyvsp[-2].interm.intermTypedNode, yyvsp[0].interm.nodePair, yyvsp[-4].lex.line);\r
+ ;\r
+ break;}\r
+case 187:\r
+#line 1743 "glslang.y"\r
+{\r
+ yyval.interm.nodePair.node1 = yyvsp[-2].interm.intermNode;\r
+ yyval.interm.nodePair.node2 = yyvsp[0].interm.intermNode;\r
+ ;\r
+ break;}\r
+case 188:\r
+#line 1747 "glslang.y"\r
+{ \r
+ yyval.interm.nodePair.node1 = yyvsp[0].interm.intermNode;\r
+ yyval.interm.nodePair.node2 = 0;\r
+ ;\r
+ break;}\r
+case 189:\r
+#line 1757 "glslang.y"\r
+{\r
+ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode;\r
+ if (parseContext.boolErrorCheck(yyvsp[0].interm.intermTypedNode->getLine(), yyvsp[0].interm.intermTypedNode))\r
+ parseContext.recover(); \r
+ ;\r
+ break;}\r
+case 190:\r
+#line 1762 "glslang.y"\r
+{\r
+ TIntermNode* intermNode;\r
+ if (parseContext.structQualifierErrorCheck(yyvsp[-2].lex.line, yyvsp[-3].interm.type))\r
+ parseContext.recover();\r
+ if (parseContext.boolErrorCheck(yyvsp[-2].lex.line, yyvsp[-3].interm.type))\r
+ parseContext.recover();\r
+ \r
+ if (!parseContext.executeInitializer(yyvsp[-2].lex.line, *yyvsp[-2].lex.string, yyvsp[-3].interm.type, yyvsp[0].interm.intermTypedNode, intermNode))\r
+ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode;\r
+ else {\r
+ parseContext.recover();\r
+ yyval.interm.intermTypedNode = 0;\r
+ }\r
+ ;\r
+ break;}\r
+case 191:\r
+#line 1779 "glslang.y"\r
+{ parseContext.symbolTable.push(); ++parseContext.loopNestingLevel; ;\r
+ break;}\r
+case 192:\r
+#line 1779 "glslang.y"\r
+{ \r
+ parseContext.symbolTable.pop();\r
+ yyval.interm.intermNode = parseContext.intermediate.addLoop(yyvsp[0].interm.intermNode, yyvsp[-2].interm.intermTypedNode, 0, true, yyvsp[-5].lex.line);\r
+ --parseContext.loopNestingLevel;\r
+ ;\r
+ break;}\r
+case 193:\r
+#line 1784 "glslang.y"\r
+{ ++parseContext.loopNestingLevel; ;\r
+ break;}\r
+case 194:\r
+#line 1784 "glslang.y"\r
+{\r
+ if (parseContext.boolErrorCheck(yyvsp[0].lex.line, yyvsp[-2].interm.intermTypedNode))\r
+ parseContext.recover();\r
+ \r
+ yyval.interm.intermNode = parseContext.intermediate.addLoop(yyvsp[-5].interm.intermNode, yyvsp[-2].interm.intermTypedNode, 0, false, yyvsp[-4].lex.line);\r
+ --parseContext.loopNestingLevel;\r
+ ;\r
+ break;}\r
+case 195:\r
+#line 1791 "glslang.y"\r
+{ parseContext.symbolTable.push(); ++parseContext.loopNestingLevel; ;\r
+ break;}\r
+case 196:\r
+#line 1791 "glslang.y"\r
+{\r
+ parseContext.symbolTable.pop();\r
+ yyval.interm.intermNode = parseContext.intermediate.makeAggregate(yyvsp[-3].interm.intermNode, yyvsp[-5].lex.line);\r
+ yyval.interm.intermNode = parseContext.intermediate.growAggregate(\r
+ yyval.interm.intermNode,\r
+ parseContext.intermediate.addLoop(yyvsp[0].interm.intermNode, reinterpret_cast<TIntermTyped*>(yyvsp[-2].interm.nodePair.node1), reinterpret_cast<TIntermTyped*>(yyvsp[-2].interm.nodePair.node2), true, yyvsp[-6].lex.line),\r
+ yyvsp[-6].lex.line);\r
+ yyval.interm.intermNode->getAsAggregate()->setOperator(EOpSequence);\r
+ --parseContext.loopNestingLevel;\r
+ ;\r
+ break;}\r
+case 197:\r
+#line 1804 "glslang.y"\r
+{\r
+ yyval.interm.intermNode = yyvsp[0].interm.intermNode; \r
+ ;\r
+ break;}\r
+case 198:\r
+#line 1807 "glslang.y"\r
+{\r
+ yyval.interm.intermNode = yyvsp[0].interm.intermNode;\r
+ ;\r
+ break;}\r
+case 199:\r
+#line 1813 "glslang.y"\r
+{ \r
+ yyval.interm.intermTypedNode = yyvsp[0].interm.intermTypedNode; \r
+ ;\r
+ break;}\r
+case 200:\r
+#line 1816 "glslang.y"\r
+{ \r
+ yyval.interm.intermTypedNode = 0; \r
+ ;\r
+ break;}\r
+case 201:\r
+#line 1822 "glslang.y"\r
+{ \r
+ yyval.interm.nodePair.node1 = yyvsp[-1].interm.intermTypedNode;\r
+ yyval.interm.nodePair.node2 = 0;\r
+ ;\r
+ break;}\r
+case 202:\r
+#line 1826 "glslang.y"\r
+{\r
+ yyval.interm.nodePair.node1 = yyvsp[-2].interm.intermTypedNode;\r
+ yyval.interm.nodePair.node2 = yyvsp[0].interm.intermTypedNode;\r
+ ;\r
+ break;}\r
+case 203:\r
+#line 1833 "glslang.y"\r
+{\r
+ if (parseContext.loopNestingLevel <= 0) {\r
+ parseContext.error(yyvsp[-1].lex.line, "continue statement only allowed in loops", "", "");\r
+ parseContext.recover();\r
+ } \r
+ yyval.interm.intermNode = parseContext.intermediate.addBranch(EOpContinue, yyvsp[-1].lex.line);\r
+ ;\r
+ break;}\r
+case 204:\r
+#line 1840 "glslang.y"\r
+{\r
+ if (parseContext.loopNestingLevel <= 0) {\r
+ parseContext.error(yyvsp[-1].lex.line, "break statement only allowed in loops", "", "");\r
+ parseContext.recover();\r
+ } \r
+ yyval.interm.intermNode = parseContext.intermediate.addBranch(EOpBreak, yyvsp[-1].lex.line);\r
+ ;\r
+ break;}\r
+case 205:\r
+#line 1847 "glslang.y"\r
+{\r
+ yyval.interm.intermNode = parseContext.intermediate.addBranch(EOpReturn, yyvsp[-1].lex.line);\r
+ if (parseContext.currentFunctionType->getBasicType() != EbtVoid) {\r
+ parseContext.error(yyvsp[-1].lex.line, "non-void function must return a value", "return", "");\r
+ parseContext.recover();\r
+ }\r
+ ;\r
+ break;}\r
+case 206:\r
+#line 1854 "glslang.y"\r
+{ \r
+ yyval.interm.intermNode = parseContext.intermediate.addBranch(EOpReturn, yyvsp[-1].interm.intermTypedNode, yyvsp[-2].lex.line);\r
+ parseContext.functionReturnsValue = true;\r
+ if (parseContext.currentFunctionType->getBasicType() == EbtVoid) {\r
+ parseContext.error(yyvsp[-2].lex.line, "void function cannot return a value", "return", "");\r
+ parseContext.recover();\r
+ } else if (*(parseContext.currentFunctionType) != yyvsp[-1].interm.intermTypedNode->getType()) {\r
+ parseContext.error(yyvsp[-2].lex.line, "function return is not matching type:", "return", "");\r
+ parseContext.recover();\r
+ }\r
+ ;\r
+ break;}\r
+case 207:\r
+#line 1865 "glslang.y"\r
+{\r
+ FRAG_ONLY("discard", yyvsp[-1].lex.line);\r
+ yyval.interm.intermNode = parseContext.intermediate.addBranch(EOpKill, yyvsp[-1].lex.line);\r
+ ;\r
+ break;}\r
+case 208:\r
+#line 1874 "glslang.y"\r
+{ \r
+ yyval.interm.intermNode = yyvsp[0].interm.intermNode; \r
+ parseContext.treeRoot = yyval.interm.intermNode; \r
+ ;\r
+ break;}\r
+case 209:\r
+#line 1878 "glslang.y"\r
+{\r
+ yyval.interm.intermNode = parseContext.intermediate.growAggregate(yyvsp[-1].interm.intermNode, yyvsp[0].interm.intermNode, 0);\r
+ parseContext.treeRoot = yyval.interm.intermNode;\r
+ ;\r
+ break;}\r
+case 210:\r
+#line 1885 "glslang.y"\r
+{ \r
+ yyval.interm.intermNode = yyvsp[0].interm.intermNode; \r
+ ;\r
+ break;}\r
+case 211:\r
+#line 1888 "glslang.y"\r
+{ \r
+ yyval.interm.intermNode = yyvsp[0].interm.intermNode; \r
+ ;\r
+ break;}\r
+case 212:\r
+#line 1894 "glslang.y"\r
+{\r
+ TFunction& function = *(yyvsp[0].interm.function);\r
+ TFunction* prevDec = static_cast<TFunction*>(parseContext.symbolTable.find(function.getMangledName()));\r
+ //\r
+ // Note: 'prevDec' could be 'function' if this is the first time we've seen function\r
+ // as it would have just been put in the symbol table. Otherwise, we're looking up\r
+ // an earlier occurance.\r
+ //\r
+ if (prevDec->isDefined()) {\r
+ //\r
+ // Then this function already has a body.\r
+ //\r
+ parseContext.error(yyvsp[0].interm.line, "function already has a body", function.getName().c_str(), "");\r
+ parseContext.recover();\r
+ }\r
+ prevDec->setDefined();\r
+ \r
+ //\r
+ // Raise error message if main function takes any parameters or return anything other than void\r
+ //\r
+ if (function.getName() == "main") {\r
+ if (function.getParamCount() > 0) {\r
+ parseContext.error(yyvsp[0].interm.line, "function cannot take any parameter(s)", function.getName().c_str(), "");\r
+ parseContext.recover();\r
+ }\r
+ if (function.getReturnType().getBasicType() != EbtVoid) {\r
+ parseContext.error(yyvsp[0].interm.line, "", function.getReturnType().getBasicString(), "main function cannot return a value" );\r
+ parseContext.recover();\r
+ } \r
+ }\r
+ \r
+ //\r
+ // New symbol table scope for body of function plus its arguments\r
+ //\r
+ parseContext.symbolTable.push();\r
+ \r
+ //\r
+ // Remember the return type for later checking for RETURN statements.\r
+ //\r
+ parseContext.currentFunctionType = &(prevDec->getReturnType());\r
+ parseContext.functionReturnsValue = false;\r
+ \r
+ // \r
+ // Insert parameters into the symbol table.\r
+ // If the parameter has no name, it's not an error, just don't insert it \r
+ // (could be used for unused args).\r
+ //\r
+ // Also, accumulate the list of parameters into the HIL, so lower level code\r
+ // knows where to find parameters.\r
+ //\r
+ TIntermAggregate* paramNodes = new TIntermAggregate;\r
+ for (int i = 0; i < function.getParamCount(); i++) {\r
+ TParameter& param = function[i];\r
+ if (param.name != 0) {\r
+ TVariable *variable = new TVariable(param.name, *param.type);\r
+ // \r
+ // Insert the parameters with name in the symbol table.\r
+ //\r
+ if (! parseContext.symbolTable.insert(*variable)) {\r
+ parseContext.error(yyvsp[0].interm.line, "redefinition", variable->getName().c_str(), "");\r
+ parseContext.recover();\r
+ delete variable;\r
+ }\r
+ //\r
+ // Transfer ownership of name pointer to symbol table.\r
+ //\r
+ param.name = 0;\r
+ \r
+ //\r
+ // Add the parameter to the HIL\r
+ // \r
+ paramNodes = parseContext.intermediate.growAggregate(\r
+ paramNodes, \r
+ parseContext.intermediate.addSymbol(variable->getUniqueId(),\r
+ variable->getName(),\r
+ variable->getType(), yyvsp[0].interm.line), \r
+ yyvsp[0].interm.line);\r
+ } else {\r
+ paramNodes = parseContext.intermediate.growAggregate(paramNodes, parseContext.intermediate.addSymbol(0, "", *param.type, yyvsp[0].interm.line), yyvsp[0].interm.line);\r
+ }\r
+ }\r
+ parseContext.intermediate.setAggregateOperator(paramNodes, EOpParameters, yyvsp[0].interm.line);\r
+ yyvsp[0].interm.intermAggregate = paramNodes;\r
+ parseContext.loopNestingLevel = 0;\r
+ ;\r
+ break;}\r
+case 213:\r
+#line 1979 "glslang.y"\r
+{\r
+ //?? Check that all paths return a value if return type != void ?\r
+ // May be best done as post process phase on intermediate code\r
+ if (parseContext.currentFunctionType->getBasicType() != EbtVoid && ! parseContext.functionReturnsValue) {\r
+ parseContext.error(yyvsp[-2].interm.line, "function does not return a value:", "", yyvsp[-2].interm.function->getName().c_str());\r
+ parseContext.recover();\r
+ }\r
+ parseContext.symbolTable.pop();\r
+ yyval.interm.intermNode = parseContext.intermediate.growAggregate(yyvsp[-2].interm.intermAggregate, yyvsp[0].interm.intermNode, 0);\r
+ parseContext.intermediate.setAggregateOperator(yyval.interm.intermNode, EOpFunction, yyvsp[-2].interm.line);\r
+ yyval.interm.intermNode->getAsAggregate()->setName(yyvsp[-2].interm.function->getMangledName().c_str());\r
+ yyval.interm.intermNode->getAsAggregate()->setType(yyvsp[-2].interm.function->getReturnType());\r
+ ;\r
+ break;}\r
+}\r
+ /* the action file gets copied in in place of this dollarsign */\r
+ yyvsp -= yylen;\r
+ yyssp -= yylen;\r
+#ifdef YYLSP_NEEDED\r
+ yylsp -= yylen;\r
+#endif\r
+\r
+#if YYDEBUG != 0\r
+ if (yydebug)\r
+ {\r
+ short *ssp1 = yyss - 1;\r
+ fprintf (stderr, "state stack now");\r
+ while (ssp1 != yyssp)\r
+ fprintf (stderr, " %d", *++ssp1);\r
+ fprintf (stderr, "\n");\r
+ }\r
+#endif\r
+\r
+ *++yyvsp = yyval;\r
+\r
+#ifdef YYLSP_NEEDED\r
+ yylsp++;\r
+ if (yylen == 0)\r
+ {\r
+ yylsp->first_line = yylloc.first_line;\r
+ yylsp->first_column = yylloc.first_column;\r
+ yylsp->last_line = (yylsp-1)->last_line;\r
+ yylsp->last_column = (yylsp-1)->last_column;\r
+ yylsp->text = 0;\r
+ }\r
+ else\r
+ {\r
+ yylsp->last_line = (yylsp+yylen-1)->last_line;\r
+ yylsp->last_column = (yylsp+yylen-1)->last_column;\r
+ }\r
+#endif\r
+\r
+ /* Now "shift" the result of the reduction.\r
+ Determine what state that goes to,\r
+ based on the state we popped back to\r
+ and the rule number reduced by. */\r
+\r
+ yyn = yyr1[yyn];\r
+\r
+ yystate = yypgoto[yyn - YYNTBASE] + *yyssp;\r
+ if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)\r
+ yystate = yytable[yystate];\r
+ else\r
+ yystate = yydefgoto[yyn - YYNTBASE];\r
+\r
+ goto yynewstate;\r
+\r
+yyerrlab: /* here on detecting error */\r
+\r
+ if (! yyerrstatus)\r
+ /* If not already recovering from an error, report this error. */\r
+ {\r
+ ++yynerrs;\r
+\r
+#ifdef YYERROR_VERBOSE\r
+ yyn = yypact[yystate];\r
+\r
+ if (yyn > YYFLAG && yyn < YYLAST)\r
+ {\r
+ int size = 0;\r
+ char *msg;\r
+ int x, count;\r
+\r
+ count = 0;\r
+ /* Start X at -yyn if nec to avoid negative indexes in yycheck. */\r
+ for (x = (yyn < 0 ? -yyn : 0);\r
+ x < (sizeof(yytname) / sizeof(char *)); x++)\r
+ if (yycheck[x + yyn] == x)\r
+ size += strlen(yytname[x]) + 15, count++;\r
+ msg = (char *) malloc(size + 15);\r
+ if (msg != 0)\r
+ {\r
+ strcpy(msg, "parse error");\r
+\r
+ if (count < 5)\r
+ {\r
+ count = 0;\r
+ for (x = (yyn < 0 ? -yyn : 0);\r
+ x < (sizeof(yytname) / sizeof(char *)); x++)\r
+ if (yycheck[x + yyn] == x)\r
+ {\r
+ strcat(msg, count == 0 ? ", expecting `" : " or `");\r
+ strcat(msg, yytname[x]);\r
+ strcat(msg, "'");\r
+ count++;\r
+ }\r
+ }\r
+ yyerror(msg);\r
+ free(msg);\r
+ }\r
+ else\r
+ yyerror ("parse error; also virtual memory exceeded");\r
+ }\r
+ else\r
+#endif /* YYERROR_VERBOSE */\r
+ yyerror("parse error");\r
+ }\r
+\r
+ goto yyerrlab1;\r
+yyerrlab1: /* here on error raised explicitly by an action */\r
+\r
+ if (yyerrstatus == 3)\r
+ {\r
+ /* if just tried and failed to reuse lookahead token after an error, discard it. */\r
+\r
+ /* return failure if at end of input */\r
+ if (yychar == YYEOF)\r
+ YYABORT;\r
+\r
+#if YYDEBUG != 0\r
+ if (yydebug)\r
+ fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);\r
+#endif\r
+\r
+ yychar = YYEMPTY;\r
+ }\r
+\r
+ /* Else will try to reuse lookahead token\r
+ after shifting the error token. */\r
+\r
+ yyerrstatus = 3; /* Each real token shifted decrements this */\r
+\r
+ goto yyerrhandle;\r
+\r
+yyerrdefault: /* current state does not do anything special for the error token. */\r
+\r
+#if 0\r
+ /* This is wrong; only states that explicitly want error tokens\r
+ should shift them. */\r
+ yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/\r
+ if (yyn) goto yydefault;\r
+#endif\r
+\r
+yyerrpop: /* pop the current state because it cannot handle the error token */\r
+\r
+ if (yyssp == yyss) YYABORT;\r
+ yyvsp--;\r
+ yystate = *--yyssp;\r
+#ifdef YYLSP_NEEDED\r
+ yylsp--;\r
+#endif\r
+\r
+#if YYDEBUG != 0\r
+ if (yydebug)\r
+ {\r
+ short *ssp1 = yyss - 1;\r
+ fprintf (stderr, "Error: state stack now");\r
+ while (ssp1 != yyssp)\r
+ fprintf (stderr, " %d", *++ssp1);\r
+ fprintf (stderr, "\n");\r
+ }\r
+#endif\r
+\r
+yyerrhandle:\r
+\r
+ yyn = yypact[yystate];\r
+ if (yyn == YYFLAG)\r
+ goto yyerrdefault;\r
+\r
+ yyn += YYTERROR;\r
+ if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)\r
+ goto yyerrdefault;\r
+\r
+ yyn = yytable[yyn];\r
+ if (yyn < 0)\r
+ {\r
+ if (yyn == YYFLAG)\r
+ goto yyerrpop;\r
+ yyn = -yyn;\r
+ goto yyreduce;\r
+ }\r
+ else if (yyn == 0)\r
+ goto yyerrpop;\r
+\r
+ if (yyn == YYFINAL)\r
+ YYACCEPT;\r
+\r
+#if YYDEBUG != 0\r
+ if (yydebug)\r
+ fprintf(stderr, "Shifting error token, ");\r
+#endif\r
+\r
+ *++yyvsp = yylval;\r
+#ifdef YYLSP_NEEDED\r
+ *++yylsp = yylloc;\r
+#endif\r
+\r
+ yystate = yyn;\r
+ goto yynewstate;\r
+}\r
+#line 1994 "glslang.y"\r
+\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#include "Include/InfoSink.h"\r
+\r
+#ifdef _WIN32\r
+ #include <windows.h>\r
+#endif\r
+\r
+void TInfoSinkBase::append(const char *s) \r
+{\r
+ if (outputStream & EString) {\r
+ checkMem(strlen(s)); \r
+ sink.append(s); \r
+ }\r
+\r
+#ifdef _WIN32\r
+ if (outputStream & EDebugger)\r
+ OutputDebugString(s);\r
+#endif\r
+\r
+ if (outputStream & EStdOut)\r
+ fprintf(stdout, "%s", s);\r
+}\r
+\r
+void TInfoSinkBase::append(int count, char c) \r
+{ \r
+ if (outputStream & EString) {\r
+ checkMem(1); \r
+ sink.append(count, c); \r
+ }\r
+\r
+#ifdef _WIN32\r
+ if (outputStream & EDebugger) {\r
+ char str[2];\r
+ str[0] = c;\r
+ str[1] = '\0';\r
+ OutputDebugString(str);\r
+ }\r
+#endif\r
+\r
+ if (outputStream & EStdOut)\r
+ fprintf(stdout, "%c", c);\r
+}\r
+\r
+void TInfoSinkBase::append(const TPersistString& t) \r
+{ \r
+ if (outputStream & EString) {\r
+ checkMem(t.size()); \r
+ sink.append(t); \r
+ }\r
+\r
+#ifdef _WIN32\r
+ if (outputStream & EDebugger)\r
+ OutputDebugString(t.c_str());\r
+#endif\r
+\r
+ if (outputStream & EStdOut)\r
+ fprintf(stdout, "%s", t.c_str());\r
+}\r
+\r
+void TInfoSinkBase::append(const TString& t)\r
+{ \r
+ if (outputStream & EString) {\r
+ checkMem(t.size()); \r
+ sink.append(t.c_str()); \r
+ }\r
+\r
+#ifdef _WIN32\r
+ if (outputStream & EDebugger)\r
+ OutputDebugString(t.c_str());\r
+#endif\r
+\r
+ if (outputStream & EStdOut)\r
+ fprintf(stdout, "%s", t.c_str());\r
+}\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+//\r
+// Create strings that declare built-in definitions, add built-ins that\r
+// cannot be expressed in the files, and establish mappings between \r
+// built-in functions and operators.\r
+//\r
+\r
+#include "../Include/intermediate.h"\r
+#include "Initialize.h"\r
+#include <assert.h>\r
+\r
+void TBuiltIns::initialize(TBuiltInResource &resources)\r
+{\r
+ //\r
+ // Initialize all the built-in strings for parsing.\r
+ //\r
+ TString BuiltInFunctions;\r
+ TString BuiltInFunctionsVertex;\r
+ TString BuiltInFunctionsFragment;\r
+ TString StandardVertexVaryings;\r
+ TString StandardFragmentVaryings;\r
+ TString StandardVertexAttributes;\r
+ TString StandardUniforms;\r
+\r
+ {\r
+ //============================================================================\r
+ //\r
+ // Prototypes for built-in functions seen by both vertex and fragment shaders.\r
+ //\r
+ //============================================================================\r
+\r
+ TString& s = BuiltInFunctions;\r
+\r
+ //\r
+ // Angle and Trigonometric Functions.\r
+ //\r
+ s.append(TString("float radians(float degrees);"));\r
+ s.append(TString("vec2 radians(vec2 degrees);"));\r
+ s.append(TString("vec3 radians(vec3 degrees);"));\r
+ s.append(TString("vec4 radians(vec4 degrees);"));\r
+\r
+ s.append(TString("float degrees(float radians);"));\r
+ s.append(TString("vec2 degrees(vec2 radians);"));\r
+ s.append(TString("vec3 degrees(vec3 radians);"));\r
+ s.append(TString("vec4 degrees(vec4 radians);"));\r
+\r
+ s.append(TString("float sin(float angle);"));\r
+ s.append(TString("vec2 sin(vec2 angle);"));\r
+ s.append(TString("vec3 sin(vec3 angle);"));\r
+ s.append(TString("vec4 sin(vec4 angle);"));\r
+\r
+ s.append(TString("float cos(float angle);"));\r
+ s.append(TString("vec2 cos(vec2 angle);"));\r
+ s.append(TString("vec3 cos(vec3 angle);"));\r
+ s.append(TString("vec4 cos(vec4 angle);"));\r
+\r
+ s.append(TString("float tan(float angle);"));\r
+ s.append(TString("vec2 tan(vec2 angle);"));\r
+ s.append(TString("vec3 tan(vec3 angle);"));\r
+ s.append(TString("vec4 tan(vec4 angle);"));\r
+\r
+ s.append(TString("float asin(float x);"));\r
+ s.append(TString("vec2 asin(vec2 x);"));\r
+ s.append(TString("vec3 asin(vec3 x);"));\r
+ s.append(TString("vec4 asin(vec4 x);"));\r
+\r
+ s.append(TString("float acos(float x);"));\r
+ s.append(TString("vec2 acos(vec2 x);"));\r
+ s.append(TString("vec3 acos(vec3 x);"));\r
+ s.append(TString("vec4 acos(vec4 x);"));\r
+\r
+ s.append(TString("float atan(float y, float x);"));\r
+ s.append(TString("vec2 atan(vec2 y, vec2 x);"));\r
+ s.append(TString("vec3 atan(vec3 y, vec3 x);"));\r
+ s.append(TString("vec4 atan(vec4 y, vec4 x);"));\r
+\r
+ s.append(TString("float atan(float y_over_x);"));\r
+ s.append(TString("vec2 atan(vec2 y_over_x);"));\r
+ s.append(TString("vec3 atan(vec3 y_over_x);"));\r
+ s.append(TString("vec4 atan(vec4 y_over_x);"));\r
+\r
+ //\r
+ // Exponential Functions.\r
+ //\r
+ s.append(TString("float pow(float x, float y);"));\r
+ s.append(TString("vec2 pow(vec2 x, vec2 y);"));\r
+ s.append(TString("vec3 pow(vec3 x, vec3 y);"));\r
+ s.append(TString("vec4 pow(vec4 x, vec4 y);"));\r
+\r
+ s.append(TString("float exp(float x);"));\r
+ s.append(TString("vec2 exp(vec2 x);"));\r
+ s.append(TString("vec3 exp(vec3 x);"));\r
+ s.append(TString("vec4 exp(vec4 x);"));\r
+\r
+ s.append(TString("float log(float x);"));\r
+ s.append(TString("vec2 log(vec2 x);"));\r
+ s.append(TString("vec3 log(vec3 x);"));\r
+ s.append(TString("vec4 log(vec4 x);"));\r
+\r
+ s.append(TString("float exp2(float x);"));\r
+ s.append(TString("vec2 exp2(vec2 x);"));\r
+ s.append(TString("vec3 exp2(vec3 x);"));\r
+ s.append(TString("vec4 exp2(vec4 x);"));\r
+\r
+ s.append(TString("float log2(float x);"));\r
+ s.append(TString("vec2 log2(vec2 x);"));\r
+ s.append(TString("vec3 log2(vec3 x);"));\r
+ s.append(TString("vec4 log2(vec4 x);"));\r
+\r
+ s.append(TString("float sqrt(float x);"));\r
+ s.append(TString("vec2 sqrt(vec2 x);"));\r
+ s.append(TString("vec3 sqrt(vec3 x);"));\r
+ s.append(TString("vec4 sqrt(vec4 x);"));\r
+\r
+ s.append(TString("float inversesqrt(float x);"));\r
+ s.append(TString("vec2 inversesqrt(vec2 x);"));\r
+ s.append(TString("vec3 inversesqrt(vec3 x);"));\r
+ s.append(TString("vec4 inversesqrt(vec4 x);"));\r
+\r
+ //\r
+ // Common Functions.\r
+ //\r
+ s.append(TString("float abs(float x);"));\r
+ s.append(TString("vec2 abs(vec2 x);"));\r
+ s.append(TString("vec3 abs(vec3 x);"));\r
+ s.append(TString("vec4 abs(vec4 x);"));\r
+\r
+ s.append(TString("float sign(float x);"));\r
+ s.append(TString("vec2 sign(vec2 x);"));\r
+ s.append(TString("vec3 sign(vec3 x);"));\r
+ s.append(TString("vec4 sign(vec4 x);"));\r
+\r
+ s.append(TString("float floor(float x);"));\r
+ s.append(TString("vec2 floor(vec2 x);"));\r
+ s.append(TString("vec3 floor(vec3 x);"));\r
+ s.append(TString("vec4 floor(vec4 x);"));\r
+\r
+ s.append(TString("float ceil(float x);"));\r
+ s.append(TString("vec2 ceil(vec2 x);"));\r
+ s.append(TString("vec3 ceil(vec3 x);"));\r
+ s.append(TString("vec4 ceil(vec4 x);"));\r
+\r
+ s.append(TString("float fract(float x);"));\r
+ s.append(TString("vec2 fract(vec2 x);"));\r
+ s.append(TString("vec3 fract(vec3 x);"));\r
+ s.append(TString("vec4 fract(vec4 x);"));\r
+\r
+ s.append(TString("float mod(float x, float y);"));\r
+ s.append(TString("vec2 mod(vec2 x, float y);"));\r
+ s.append(TString("vec3 mod(vec3 x, float y);"));\r
+ s.append(TString("vec4 mod(vec4 x, float y);"));\r
+ s.append(TString("vec2 mod(vec2 x, vec2 y);"));\r
+ s.append(TString("vec3 mod(vec3 x, vec3 y);"));\r
+ s.append(TString("vec4 mod(vec4 x, vec4 y);"));\r
+\r
+ s.append(TString("float min(float x, float y);"));\r
+ s.append(TString("vec2 min(vec2 x, float y);"));\r
+ s.append(TString("vec3 min(vec3 x, float y);"));\r
+ s.append(TString("vec4 min(vec4 x, float y);"));\r
+ s.append(TString("vec2 min(vec2 x, vec2 y);"));\r
+ s.append(TString("vec3 min(vec3 x, vec3 y);"));\r
+ s.append(TString("vec4 min(vec4 x, vec4 y);"));\r
+\r
+ s.append(TString("float max(float x, float y);"));\r
+ s.append(TString("vec2 max(vec2 x, float y);"));\r
+ s.append(TString("vec3 max(vec3 x, float y);"));\r
+ s.append(TString("vec4 max(vec4 x, float y);"));\r
+ s.append(TString("vec2 max(vec2 x, vec2 y);"));\r
+ s.append(TString("vec3 max(vec3 x, vec3 y);"));\r
+ s.append(TString("vec4 max(vec4 x, vec4 y);"));\r
+\r
+ s.append(TString("float clamp(float x, float minVal, float maxVal);"));\r
+ s.append(TString("vec2 clamp(vec2 x, float minVal, float maxVal);"));\r
+ s.append(TString("vec3 clamp(vec3 x, float minVal, float maxVal);"));\r
+ s.append(TString("vec4 clamp(vec4 x, float minVal, float maxVal);"));\r
+ s.append(TString("vec2 clamp(vec2 x, vec2 minVal, vec2 maxVal);"));\r
+ s.append(TString("vec3 clamp(vec3 x, vec3 minVal, vec3 maxVal);"));\r
+ s.append(TString("vec4 clamp(vec4 x, vec4 minVal, vec4 maxVal);"));\r
+\r
+ s.append(TString("float mix(float x, float y, float a);"));\r
+ s.append(TString("vec2 mix(vec2 x, vec2 y, float a);"));\r
+ s.append(TString("vec3 mix(vec3 x, vec3 y, float a);"));\r
+ s.append(TString("vec4 mix(vec4 x, vec4 y, float a);"));\r
+ s.append(TString("vec2 mix(vec2 x, vec2 y, vec2 a);"));\r
+ s.append(TString("vec3 mix(vec3 x, vec3 y, vec3 a);"));\r
+ s.append(TString("vec4 mix(vec4 x, vec4 y, vec4 a);"));\r
+\r
+ s.append(TString("float step(float edge, float x);"));\r
+ s.append(TString("vec2 step(vec2 edge, vec2 x);"));\r
+ s.append(TString("vec3 step(vec3 edge, vec3 x);"));\r
+ s.append(TString("vec4 step(vec4 edge, vec4 x);"));\r
+ s.append(TString("vec2 step(float edge, vec2 x);"));\r
+ s.append(TString("vec3 step(float edge, vec3 x);"));\r
+ s.append(TString("vec4 step(float edge, vec4 x);"));\r
+\r
+ s.append(TString("float smoothstep(float edge0, float edge1, float x);"));\r
+ s.append(TString("vec2 smoothstep(vec2 edge0, vec2 edge1, vec2 x);"));\r
+ s.append(TString("vec3 smoothstep(vec3 edge0, vec3 edge1, vec3 x);"));\r
+ s.append(TString("vec4 smoothstep(vec4 edge0, vec4 edge1, vec4 x);"));\r
+ s.append(TString("vec2 smoothstep(float edge0, float edge1, vec2 x);"));\r
+ s.append(TString("vec3 smoothstep(float edge0, float edge1, vec3 x);"));\r
+ s.append(TString("vec4 smoothstep(float edge0, float edge1, vec4 x);"));\r
+\r
+ //\r
+ // Geometric Functions.\r
+ //\r
+ s.append(TString("float length(float x);"));\r
+ s.append(TString("float length(vec2 x);"));\r
+ s.append(TString("float length(vec3 x);"));\r
+ s.append(TString("float length(vec4 x);"));\r
+\r
+ s.append(TString("float distance(float p0, float p1);"));\r
+ s.append(TString("float distance(vec2 p0, vec2 p1);"));\r
+ s.append(TString("float distance(vec3 p0, vec3 p1);"));\r
+ s.append(TString("float distance(vec4 p0, vec4 p1);"));\r
+\r
+ s.append(TString("float dot(float x, float y);"));\r
+ s.append(TString("float dot(vec2 x, vec2 y);"));\r
+ s.append(TString("float dot(vec3 x, vec3 y);"));\r
+ s.append(TString("float dot(vec4 x, vec4 y);"));\r
+\r
+ s.append(TString("vec3 cross(vec3 x, vec3 y);"));\r
+ s.append(TString("float normalize(float x);"));\r
+ s.append(TString("vec2 normalize(vec2 x);"));\r
+ s.append(TString("vec3 normalize(vec3 x);"));\r
+ s.append(TString("vec4 normalize(vec4 x);"));\r
+\r
+ s.append(TString("float faceforward(float N, float I, float Nref);"));\r
+ s.append(TString("vec2 faceforward(vec2 N, vec2 I, vec2 Nref);"));\r
+ s.append(TString("vec3 faceforward(vec3 N, vec3 I, vec3 Nref);"));\r
+ s.append(TString("vec4 faceforward(vec4 N, vec4 I, vec4 Nref);"));\r
+\r
+ s.append(TString("float reflect(float I, float N);"));\r
+ s.append(TString("vec2 reflect(vec2 I, vec2 N);"));\r
+ s.append(TString("vec3 reflect(vec3 I, vec3 N);"));\r
+ s.append(TString("vec4 reflect(vec4 I, vec4 N);"));\r
+\r
+ s.append(TString("float refract(float I, float N, float eta);"));\r
+ s.append(TString("vec2 refract(vec2 I, vec2 N, float eta);"));\r
+ s.append(TString("vec3 refract(vec3 I, vec3 N, float eta);"));\r
+ s.append(TString("vec4 refract(vec4 I, vec4 N, float eta);"));\r
+\r
+ //\r
+ // Matrix Functions.\r
+ //\r
+ s.append(TString("mat2 matrixCompMult(mat2 x, mat2 y);"));\r
+ s.append(TString("mat3 matrixCompMult(mat3 x, mat3 y);"));\r
+ s.append(TString("mat4 matrixCompMult(mat4 x, mat4 y);"));\r
+\r
+ //\r
+ // Vector relational functions.\r
+ //\r
+ s.append(TString("bvec2 lessThan(vec2 x, vec2 y);"));\r
+ s.append(TString("bvec3 lessThan(vec3 x, vec3 y);"));\r
+ s.append(TString("bvec4 lessThan(vec4 x, vec4 y);"));\r
+\r
+ s.append(TString("bvec2 lessThan(ivec2 x, ivec2 y);"));\r
+ s.append(TString("bvec3 lessThan(ivec3 x, ivec3 y);"));\r
+ s.append(TString("bvec4 lessThan(ivec4 x, ivec4 y);"));\r
+\r
+ s.append(TString("bvec2 lessThanEqual(vec2 x, vec2 y);"));\r
+ s.append(TString("bvec3 lessThanEqual(vec3 x, vec3 y);"));\r
+ s.append(TString("bvec4 lessThanEqual(vec4 x, vec4 y);"));\r
+\r
+ s.append(TString("bvec2 lessThanEqual(ivec2 x, ivec2 y);"));\r
+ s.append(TString("bvec3 lessThanEqual(ivec3 x, ivec3 y);"));\r
+ s.append(TString("bvec4 lessThanEqual(ivec4 x, ivec4 y);"));\r
+\r
+ s.append(TString("bvec2 greaterThan(vec2 x, vec2 y);"));\r
+ s.append(TString("bvec3 greaterThan(vec3 x, vec3 y);"));\r
+ s.append(TString("bvec4 greaterThan(vec4 x, vec4 y);"));\r
+\r
+ s.append(TString("bvec2 greaterThan(ivec2 x, ivec2 y);"));\r
+ s.append(TString("bvec3 greaterThan(ivec3 x, ivec3 y);"));\r
+ s.append(TString("bvec4 greaterThan(ivec4 x, ivec4 y);"));\r
+\r
+ s.append(TString("bvec2 greaterThanEqual(vec2 x, vec2 y);"));\r
+ s.append(TString("bvec3 greaterThanEqual(vec3 x, vec3 y);"));\r
+ s.append(TString("bvec4 greaterThanEqual(vec4 x, vec4 y);"));\r
+\r
+ s.append(TString("bvec2 greaterThanEqual(ivec2 x, ivec2 y);"));\r
+ s.append(TString("bvec3 greaterThanEqual(ivec3 x, ivec3 y);"));\r
+ s.append(TString("bvec4 greaterThanEqual(ivec4 x, ivec4 y);"));\r
+\r
+ s.append(TString("bvec2 equal(vec2 x, vec2 y);"));\r
+ s.append(TString("bvec3 equal(vec3 x, vec3 y);"));\r
+ s.append(TString("bvec4 equal(vec4 x, vec4 y);"));\r
+\r
+ s.append(TString("bvec2 equal(ivec2 x, ivec2 y);"));\r
+ s.append(TString("bvec3 equal(ivec3 x, ivec3 y);"));\r
+ s.append(TString("bvec4 equal(ivec4 x, ivec4 y);"));\r
+\r
+ s.append(TString("bvec2 equal(bvec2 x, bvec2 y);"));\r
+ s.append(TString("bvec3 equal(bvec3 x, bvec3 y);"));\r
+ s.append(TString("bvec4 equal(bvec4 x, bvec4 y);"));\r
+\r
+ s.append(TString("bvec2 notEqual(vec2 x, vec2 y);"));\r
+ s.append(TString("bvec3 notEqual(vec3 x, vec3 y);"));\r
+ s.append(TString("bvec4 notEqual(vec4 x, vec4 y);"));\r
+\r
+ s.append(TString("bvec2 notEqual(ivec2 x, ivec2 y);"));\r
+ s.append(TString("bvec3 notEqual(ivec3 x, ivec3 y);"));\r
+ s.append(TString("bvec4 notEqual(ivec4 x, ivec4 y);"));\r
+\r
+ s.append(TString("bvec2 notEqual(bvec2 x, bvec2 y);"));\r
+ s.append(TString("bvec3 notEqual(bvec3 x, bvec3 y);"));\r
+ s.append(TString("bvec4 notEqual(bvec4 x, bvec4 y);"));\r
+\r
+ s.append(TString("bool any(bvec2 x);"));\r
+ s.append(TString("bool any(bvec3 x);"));\r
+ s.append(TString("bool any(bvec4 x);"));\r
+\r
+ s.append(TString("bool all(bvec2 x);"));\r
+ s.append(TString("bool all(bvec3 x);"));\r
+ s.append(TString("bool all(bvec4 x);"));\r
+\r
+ s.append(TString("bvec2 not(bvec2 x);"));\r
+ s.append(TString("bvec3 not(bvec3 x);"));\r
+ s.append(TString("bvec4 not(bvec4 x);"));\r
+\r
+ //\r
+ // Texture Functions.\r
+ //\r
+ s.append(TString("vec4 texture1D(sampler1D sampler, float coord);"));\r
+ s.append(TString("vec4 texture1D(sampler1D sampler, float coord, float bias);"));\r
+ s.append(TString("vec4 texture1DProj(sampler1D sampler, vec2 coord);"));\r
+ s.append(TString("vec4 texture1DProj(sampler1D sampler, vec2 coord, float bias);"));\r
+ s.append(TString("vec4 texture1DProj(sampler1D sampler, vec4 coord);"));\r
+ s.append(TString("vec4 texture1DProj(sampler1D sampler, vec4 coord, float bias);"));\r
+ s.append(TString("vec4 texture1DLod(sampler1D sampler, float coord, float lod);"));\r
+ s.append(TString("vec4 texture1DProjLod(sampler1D sampler, vec2 coord, float lod);"));\r
+ s.append(TString("vec4 texture1DProjLod(sampler1D sampler, vec4 coord, float lod);"));\r
+\r
+ s.append(TString("vec4 texture2D(sampler2D sampler, vec2 coord);"));\r
+ s.append(TString("vec4 texture2D(sampler2D sampler, vec2 coord, float bias);"));\r
+ s.append(TString("vec4 texture2DProj(sampler2D sampler, vec3 coord);"));\r
+ s.append(TString("vec4 texture2DProj(sampler2D sampler, vec3 coord, float bias);"));\r
+ s.append(TString("vec4 texture2DProj(sampler2D sampler, vec4 coord);"));\r
+ s.append(TString("vec4 texture2DProj(sampler2D sampler, vec4 coord, float bias);"));\r
+ s.append(TString("vec4 texture2DLod(sampler2D sampler, vec2 coord, float lod);"));\r
+ s.append(TString("vec4 texture2DProjLod(sampler2D sampler, vec3 coord, float lod);"));\r
+ s.append(TString("vec4 texture2DProjLod(sampler2D sampler, vec4 coord, float lod);"));\r
+\r
+ s.append(TString("vec4 texture3D(sampler3D sampler, vec3 coord);"));\r
+ s.append(TString("vec4 texture3D(sampler3D sampler, vec3 coord, float bias);"));\r
+ s.append(TString("vec4 texture3DProj(sampler3D sampler, vec4 coord);"));\r
+ s.append(TString("vec4 texture3DProj(sampler3D sampler, vec4 coord, float bias);"));\r
+ s.append(TString("vec4 texture3DLod(sampler3D sampler, vec3 coord, float lod);"));\r
+ s.append(TString("vec4 texture3DProjLod(sampler3D sampler, vec4 coord, float lod);"));\r
+\r
+ s.append(TString("vec4 textureCube(samplerCube sampler, vec3 coord);"));\r
+ s.append(TString("vec4 textureCube(samplerCube sampler, vec3 coord, float bias);"));\r
+ s.append(TString("vec4 textureCubeLod(samplerCube sampler, vec3 coord, float lod);"));\r
+\r
+ s.append(TString("vec4 shadow1D(sampler1DShadow sampler, vec3 coord);"));\r
+ s.append(TString("vec4 shadow1D(sampler1DShadow sampler, vec3 coord, float bias);"));\r
+\r
+ s.append(TString("vec4 shadow2D(sampler2DShadow sampler, vec3 coord);"));\r
+ s.append(TString("vec4 shadow2D(sampler2DShadow sampler, vec3 coord, float bias);"));\r
+\r
+ s.append(TString("vec4 shadow1DProj(sampler1DShadow sampler, vec4 coord);"));\r
+ s.append(TString("vec4 shadow1DProj(sampler1DShadow sampler, vec4 coord, float bias);"));\r
+\r
+ s.append(TString("vec4 shadow2DProj(sampler2DShadow sampler, vec4 coord);"));\r
+ s.append(TString("vec4 shadow2DProj(sampler2DShadow sampler, vec4 coord, float bias);"));\r
+\r
+ s.append(TString("vec4 shadow1DLod(sampler1DShadow sampler, vec3 coord, float lod);"));\r
+ s.append(TString("vec4 shadow2DLod(sampler2DShadow sampler, vec3 coord, float lod);"));\r
+\r
+ s.append(TString("vec4 shadow1DProjLod(sampler1DShadow sampler, vec4 coord, float lod);"));\r
+ s.append(TString("vec4 shadow2DProjLod(sampler2DShadow sampler, vec4 coord, float lod);"));\r
+\r
+ //\r
+ // Noise functions.\r
+ //\r
+ s.append(TString("float noise1(float x);"));\r
+ s.append(TString("float noise1(vec2 x);"));\r
+ s.append(TString("float noise1(vec3 x);"));\r
+ s.append(TString("float noise1(vec4 x);"));\r
+\r
+ s.append(TString("vec2 noise2(float x);"));\r
+ s.append(TString("vec2 noise2(vec2 x);"));\r
+ s.append(TString("vec2 noise2(vec3 x);"));\r
+ s.append(TString("vec2 noise2(vec4 x);"));\r
+\r
+ s.append(TString("vec3 noise3(float x);"));\r
+ s.append(TString("vec3 noise3(vec2 x);"));\r
+ s.append(TString("vec3 noise3(vec3 x);"));\r
+ s.append(TString("vec3 noise3(vec4 x);"));\r
+\r
+ s.append(TString("vec4 noise4(float x);"));\r
+ s.append(TString("vec4 noise4(vec2 x);"));\r
+ s.append(TString("vec4 noise4(vec3 x);"));\r
+ s.append(TString("vec4 noise4(vec4 x);"));\r
+\r
+ s.append(TString("\n"));\r
+ }\r
+ {\r
+ //============================================================================\r
+ //\r
+ // Prototypes for built-in functions seen by vertex shaders only.\r
+ //\r
+ //============================================================================\r
+\r
+ TString& s = BuiltInFunctionsVertex;\r
+\r
+ //\r
+ // Geometric Functions.\r
+ //\r
+ s.append(TString("vec4 ftransform();"));\r
+\r
+ s.append(TString("\n"));\r
+ }\r
+ {\r
+ //============================================================================\r
+ //\r
+ // Prototypes for built-in functions seen by fragment shaders only.\r
+ //\r
+ //============================================================================\r
+\r
+ TString& s = BuiltInFunctionsFragment;\r
+\r
+ s.append(TString("float dFdx(float p);"));\r
+ s.append(TString("vec2 dFdx(vec2 p);"));\r
+ s.append(TString("vec3 dFdx(vec3 p);"));\r
+ s.append(TString("vec4 dFdx(vec4 p);"));\r
+\r
+ s.append(TString("float dFdy(float p);"));\r
+ s.append(TString("vec2 dFdy(vec2 p);"));\r
+ s.append(TString("vec3 dFdy(vec3 p);"));\r
+ s.append(TString("vec4 dFdy(vec4 p);"));\r
+\r
+ s.append(TString("float fwidth(float p);"));\r
+ s.append(TString("vec2 fwidth(vec2 p);"));\r
+ s.append(TString("vec3 fwidth(vec3 p);"));\r
+ s.append(TString("vec4 fwidth(vec4 p);"));\r
+\r
+ s.append(TString("\n"));\r
+ }\r
+ {\r
+ //============================================================================\r
+ //\r
+ // Standard Uniforms\r
+ //\r
+ //============================================================================\r
+\r
+ TString& s = StandardUniforms;\r
+ \r
+ //\r
+ // Implementation dependent constants. The example values below\r
+ // are the minimum values allowed for these maximums.\r
+ //\r
+ char builtInConstant[80];\r
+ sprintf(builtInConstant, "const int gl_MaxLights = %d;", resources.maxLights); // GL 1.0\r
+ s.append(TString(builtInConstant)); \r
+ \r
+ sprintf(builtInConstant, "const int gl_MaxClipPlanes = %d;", resources.maxClipPlanes); // GL 1.0\r
+ s.append(TString(builtInConstant));\r
+ \r
+ sprintf(builtInConstant, "const int gl_MaxTextureUnits = %d;", resources.maxTextureUnits); // GL 1.2\r
+ s.append(TString(builtInConstant));\r
+ \r
+ sprintf(builtInConstant, "const int gl_MaxTextureCoords = %d;", resources.maxTextureCoords); // ARB_fragment_program\r
+ s.append(TString(builtInConstant));\r
+ \r
+ sprintf(builtInConstant, "const int gl_MaxVertexAttribs = %d;", resources.maxVertexAttribs); // ARB_vertex_shader\r
+ s.append(TString(builtInConstant));\r
+ \r
+ sprintf(builtInConstant, "const int gl_MaxVertexUniformComponents = %d;", resources.maxVertexUniformComponents); // ARB_vertex_shader\r
+ s.append(TString(builtInConstant)); \r
+ \r
+ sprintf(builtInConstant, "const int gl_MaxVaryingFloats = %d;", resources.maxVaryingFloats); // ARB_vertex_shader\r
+ s.append(TString(builtInConstant)); \r
+ \r
+ sprintf(builtInConstant, "const int gl_MaxVertexTextureImageUnits = %d;", resources.maxVertexTextureImageUnits); // ARB_vertex_shader\r
+ s.append(TString(builtInConstant)); \r
+ \r
+ sprintf(builtInConstant, "const int gl_MaxCombinedTextureImageUnits = %d;", resources.maxCombinedTextureImageUnits); // ARB_vertex_shader\r
+ s.append(TString(builtInConstant)); \r
+ \r
+ sprintf(builtInConstant, "const int gl_MaxTextureImageUnits = %d;", resources.maxTextureImageUnits); // ARB_fragment_shader\r
+ s.append(TString(builtInConstant)); \r
+ \r
+ sprintf(builtInConstant, "const int gl_MaxFragmentUniformComponents = %d;", resources.maxFragmentUniformComponents); // ARB_fragment_shader\r
+ s.append(TString(builtInConstant)); \r
+ \r
+ sprintf(builtInConstant, "const int gl_MaxDrawBuffers = %d;", resources.maxDrawBuffers); // proposed ARB_draw_buffers\r
+ s.append(TString(builtInConstant));\r
+\r
+ //\r
+ // OpenGL'uniform' state. Page numbers are in reference to version\r
+ // 1.4 of the OpenGL specification.\r
+ //\r
+\r
+ //\r
+ // Matrix state. p. 31, 32, 37, 39, 40.\r
+ //\r
+ s.append(TString("uniform mat4 gl_ModelViewMatrix;"));\r
+ s.append(TString("uniform mat4 gl_ProjectionMatrix;"));\r
+ s.append(TString("uniform mat4 gl_ModelViewProjectionMatrix;"));\r
+ s.append(TString("uniform mat4 gl_TextureMatrix[gl_MaxTextureCoords];"));\r
+\r
+ //\r
+ // Derived matrix state that provides inverse and transposed versions\r
+ // of the matrices above.\r
+ //\r
+ s.append(TString("uniform mat3 gl_NormalMatrix;"));\r
+\r
+ s.append(TString("uniform mat4 gl_ModelViewMatrixInverse;"));\r
+ s.append(TString("uniform mat4 gl_ProjectionMatrixInverse;"));\r
+ s.append(TString("uniform mat4 gl_ModelViewProjectionMatrixInverse;"));\r
+ s.append(TString("uniform mat4 gl_TextureMatrixInverse[gl_MaxTextureCoords];"));\r
+\r
+ s.append(TString("uniform mat4 gl_ModelViewMatrixTranspose;"));\r
+ s.append(TString("uniform mat4 gl_ProjectionMatrixTranspose;"));\r
+ s.append(TString("uniform mat4 gl_ModelViewProjectionMatrixTranspose;"));\r
+ s.append(TString("uniform mat4 gl_TextureMatrixTranspose[gl_MaxTextureCoords];"));\r
+\r
+ s.append(TString("uniform mat4 gl_ModelViewMatrixInverseTranspose;"));\r
+ s.append(TString("uniform mat4 gl_ProjectionMatrixInverseTranspose;"));\r
+ s.append(TString("uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose;"));\r
+ s.append(TString("uniform mat4 gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords];"));\r
+\r
+ //\r
+ // Normal scaling p. 39.\r
+ //\r
+ s.append(TString("uniform float gl_NormalScale;"));\r
+\r
+ //\r
+ // Depth range in window coordinates, p. 33\r
+ //\r
+ s.append(TString("struct gl_DepthRangeParameters {"));\r
+ s.append(TString(" float near;")); // n\r
+ s.append(TString(" float far;")); // f\r
+ s.append(TString(" float diff;")); // f - n\r
+ s.append(TString("};"));\r
+ s.append(TString("uniform gl_DepthRangeParameters gl_DepthRange;"));\r
+\r
+ //\r
+ // Clip planes p. 42.\r
+ //\r
+ s.append(TString("uniform vec4 gl_ClipPlane[gl_MaxClipPlanes];"));\r
+\r
+ //\r
+ // Point Size, p. 66, 67.\r
+ //\r
+ s.append(TString("struct gl_PointParameters {"));\r
+ s.append(TString(" float size;"));\r
+ s.append(TString(" float sizeMin;"));\r
+ s.append(TString(" float sizeMax;"));\r
+ s.append(TString(" float fadeThresholdSize;"));\r
+ s.append(TString(" float distanceConstantAttenuation;"));\r
+ s.append(TString(" float distanceLinearAttenuation;"));\r
+ s.append(TString(" float distanceQuadraticAttenuation;"));\r
+ s.append(TString("};"));\r
+ \r
+ s.append(TString("uniform gl_PointParameters gl_Point;"));\r
+\r
+ //\r
+ // Material State p. 50, 55.\r
+ //\r
+ s.append(TString("struct gl_MaterialParameters {"));\r
+ s.append(TString(" vec4 emission;")); // Ecm\r
+ s.append(TString(" vec4 ambient;")); // Acm\r
+ s.append(TString(" vec4 diffuse;")); // Dcm\r
+ s.append(TString(" vec4 specular;")); // Scm\r
+ s.append(TString(" float shininess;")); // Srm\r
+ s.append(TString("};"));\r
+ s.append(TString("uniform gl_MaterialParameters gl_FrontMaterial;"));\r
+ s.append(TString("uniform gl_MaterialParameters gl_BackMaterial;"));\r
+\r
+ //\r
+ // Light State p 50, 53, 55.\r
+ //\r
+\r
+ s.append(TString("struct gl_LightSourceParameters {"));\r
+ s.append(TString(" vec4 ambient;")); // Acli\r
+ s.append(TString(" vec4 diffuse;")); // Dcli\r
+ s.append(TString(" vec4 specular;")); // Scli\r
+ s.append(TString(" vec4 position;")); // Ppli\r
+ s.append(TString(" vec4 halfVector;")); // Derived: Hi\r
+ s.append(TString(" vec3 spotDirection;")); // Sdli\r
+ s.append(TString(" float spotExponent;")); // Srli\r
+ s.append(TString(" float spotCutoff;")); // Crli\r
+ // (range: [0.0,90.0], 180.0)\r
+ s.append(TString(" float spotCosCutoff;")); // Derived: cos(Crli)\r
+ // (range: [1.0,0.0],-1.0)\r
+ s.append(TString(" float constantAttenuation;")); // K0\r
+ s.append(TString(" float linearAttenuation;")); // K1\r
+ s.append(TString(" float quadraticAttenuation;"));// K2\r
+ s.append(TString("};"));\r
+\r
+ s.append(TString("uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights];"));\r
+\r
+ s.append(TString("struct gl_LightModelParameters {"));\r
+ s.append(TString(" vec4 ambient;")); // Acs\r
+ s.append(TString("};"));\r
+\r
+ s.append(TString("uniform gl_LightModelParameters gl_LightModel;"));\r
+\r
+ //\r
+ // Derived state from products of light and material.\r
+ //\r
+\r
+ s.append(TString("struct gl_LightModelProducts {"));\r
+ s.append(TString(" vec4 sceneColor;")); // Derived. Ecm + Acm * Acs\r
+ s.append(TString("};"));\r
+\r
+ s.append(TString("uniform gl_LightModelProducts gl_FrontLightModelProduct;"));\r
+ s.append(TString("uniform gl_LightModelProducts gl_BackLightModelProduct;"));\r
+\r
+ s.append(TString("struct gl_LightProducts {"));\r
+ s.append(TString(" vec4 ambient;")); // Acm * Acli\r
+ s.append(TString(" vec4 diffuse;")); // Dcm * Dcli\r
+ s.append(TString(" vec4 specular;")); // Scm * Scli\r
+ s.append(TString("};"));\r
+\r
+ s.append(TString("uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];"));\r
+ s.append(TString("uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];"));\r
+\r
+ //\r
+ // Textureg Environment and Generation, p. 152, p. 40-42.\r
+ //\r
+ s.append(TString("uniform vec4 gl_TextureEnvColor[gl_MaxTextureImageUnits];"));\r
+ s.append(TString("uniform vec4 gl_EyePlaneS[gl_MaxTextureCoords];"));\r
+ s.append(TString("uniform vec4 gl_EyePlaneT[gl_MaxTextureCoords];"));\r
+ s.append(TString("uniform vec4 gl_EyePlaneR[gl_MaxTextureCoords];"));\r
+ s.append(TString("uniform vec4 gl_EyePlaneQ[gl_MaxTextureCoords];"));\r
+ s.append(TString("uniform vec4 gl_ObjectPlaneS[gl_MaxTextureCoords];"));\r
+ s.append(TString("uniform vec4 gl_ObjectPlaneT[gl_MaxTextureCoords];"));\r
+ s.append(TString("uniform vec4 gl_ObjectPlaneR[gl_MaxTextureCoords];"));\r
+ s.append(TString("uniform vec4 gl_ObjectPlaneQ[gl_MaxTextureCoords];"));\r
+\r
+ //\r
+ // Fog p. 161\r
+ //\r
+ s.append(TString("struct gl_FogParameters {"));\r
+ s.append(TString(" vec4 color;"));\r
+ s.append(TString(" float density;"));\r
+ s.append(TString(" float start;"));\r
+ s.append(TString(" float end;"));\r
+ s.append(TString(" float scale;")); // 1 / (gl_FogEnd - gl_FogStart)\r
+ s.append(TString("};"));\r
+ \r
+ s.append(TString("uniform gl_FogParameters gl_Fog;"));\r
+\r
+ s.append(TString("\n"));\r
+ }\r
+ {\r
+ //============================================================================\r
+ //\r
+ // Vertex attributes, p. 19.\r
+ //\r
+ //============================================================================\r
+\r
+ TString& s = StandardVertexAttributes;\r
+\r
+ s.append(TString("attribute vec4 gl_Color;"));\r
+ s.append(TString("attribute vec4 gl_SecondaryColor;"));\r
+ s.append(TString("attribute vec3 gl_Normal;"));\r
+ s.append(TString("attribute vec4 gl_Vertex;"));\r
+ s.append(TString("attribute vec4 gl_MultiTexCoord0;"));\r
+ s.append(TString("attribute vec4 gl_MultiTexCoord1;"));\r
+ s.append(TString("attribute vec4 gl_MultiTexCoord2;"));\r
+ s.append(TString("attribute vec4 gl_MultiTexCoord3;"));\r
+ s.append(TString("attribute vec4 gl_MultiTexCoord4;"));\r
+ s.append(TString("attribute vec4 gl_MultiTexCoord5;"));\r
+ s.append(TString("attribute vec4 gl_MultiTexCoord6;"));\r
+ s.append(TString("attribute vec4 gl_MultiTexCoord7;"));\r
+ s.append(TString("attribute float gl_FogCoord;"));\r
+\r
+ s.append(TString("\n"));\r
+ }\r
+ {\r
+ //============================================================================\r
+ //\r
+ // Define the output varying interface from the vertex shader.\r
+ //\r
+ //============================================================================\r
+\r
+ TString& s = StandardVertexVaryings;\r
+\r
+ s.append(TString("varying vec4 gl_FrontColor;"));\r
+ s.append(TString("varying vec4 gl_BackColor;"));\r
+ s.append(TString("varying vec4 gl_FrontSecondaryColor;"));\r
+ s.append(TString("varying vec4 gl_BackSecondaryColor;"));\r
+ s.append(TString("varying vec4 gl_TexCoord[];"));\r
+ s.append(TString("varying float gl_FogFragCoord;"));\r
+\r
+ s.append(TString("\n"));\r
+ }\r
+ {\r
+ //============================================================================\r
+ //\r
+ // Define the input varying interface to the fragment shader.\r
+ //\r
+ //============================================================================\r
+\r
+ TString& s = StandardFragmentVaryings;\r
+\r
+ s.append(TString("varying vec4 gl_Color;"));\r
+ s.append(TString("varying vec4 gl_SecondaryColor;"));\r
+ s.append(TString("varying vec4 gl_TexCoord[];"));\r
+ s.append(TString("varying float gl_FogFragCoord;"));\r
+\r
+ s.append(TString("\n"));\r
+ }\r
+\r
+ builtInStrings[EShLangFragment].push_back(BuiltInFunctions.c_str());\r
+ builtInStrings[EShLangFragment].push_back(BuiltInFunctionsFragment);\r
+ builtInStrings[EShLangFragment].push_back(StandardUniforms);\r
+ builtInStrings[EShLangFragment].push_back(StandardFragmentVaryings);\r
+\r
+ builtInStrings[EShLangVertex].push_back(BuiltInFunctions);\r
+ builtInStrings[EShLangVertex].push_back(BuiltInFunctionsVertex);\r
+ builtInStrings[EShLangVertex].push_back(StandardVertexVaryings);\r
+ builtInStrings[EShLangVertex].push_back(StandardVertexAttributes);\r
+ builtInStrings[EShLangVertex].push_back(StandardUniforms);\r
+}\r
+\r
+void IdentifyBuiltIns(EShLanguage language, TSymbolTable& symbolTable, TBuiltInResource &resources)\r
+{\r
+ //\r
+ // First, insert some special built-in variables that are not in \r
+ // the built-in header files.\r
+ //\r
+ switch(language) {\r
+\r
+ case EShLangFragment: {\r
+ symbolTable.insert(*new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EvqFace, 1)));\r
+ symbolTable.insert(*new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EvqFragCoord, 4)));\r
+ symbolTable.insert(*new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EvqFragColor, 4)));\r
+ symbolTable.insert(*new TVariable(NewPoolTString("gl_FragDepth"), TType(EbtFloat, EvqFragDepth, 1)));\r
+\r
+ // Set up gl_FragData. The array size.\r
+ TType fragData(EbtFloat, EvqFragColor, 4, false, true);\r
+ fragData.setArraySize(resources.maxDrawBuffers);\r
+ symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData));\r
+ }\r
+ break;\r
+\r
+ case EShLangVertex:\r
+ symbolTable.insert(*new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EvqPosition, 4)));\r
+ symbolTable.insert(*new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EvqPointSize, 1)));\r
+ symbolTable.insert(*new TVariable(NewPoolTString("gl_ClipVertex"), TType(EbtFloat, EvqClipVertex, 4)));\r
+ break;\r
+ default: break;\r
+ }\r
+\r
+ //\r
+ // Next, identify which built-ins from the already loaded headers have\r
+ // a mapping to an operator. Those that are not identified as such are\r
+ // expected to be resolved through a library of functions, versus as\r
+ // operations.\r
+ //\r
+ symbolTable.relateToOperator("not", EOpVectorLogicalNot);\r
+\r
+ symbolTable.relateToOperator("matrixCompMult", EOpMul);\r
+ symbolTable.relateToOperator("mod", EOpMod);\r
+\r
+ symbolTable.relateToOperator("equal", EOpVectorEqual);\r
+ symbolTable.relateToOperator("notEqual", EOpVectorNotEqual);\r
+ symbolTable.relateToOperator("lessThan", EOpLessThan);\r
+ symbolTable.relateToOperator("greaterThan", EOpGreaterThan);\r
+ symbolTable.relateToOperator("lessThanEqual", EOpLessThanEqual);\r
+ symbolTable.relateToOperator("greaterThanEqual", EOpGreaterThanEqual);\r
+ \r
+ symbolTable.relateToOperator("radians", EOpRadians);\r
+ symbolTable.relateToOperator("degrees", EOpDegrees);\r
+ symbolTable.relateToOperator("sin", EOpSin);\r
+ symbolTable.relateToOperator("cos", EOpCos);\r
+ symbolTable.relateToOperator("tan", EOpTan);\r
+ symbolTable.relateToOperator("asin", EOpAsin);\r
+ symbolTable.relateToOperator("acos", EOpAcos);\r
+ symbolTable.relateToOperator("atan", EOpAtan);\r
+\r
+ symbolTable.relateToOperator("pow", EOpPow);\r
+ symbolTable.relateToOperator("exp2", EOpExp2);\r
+ symbolTable.relateToOperator("log", EOpLog);\r
+ symbolTable.relateToOperator("exp", EOpExp);\r
+ symbolTable.relateToOperator("log2", EOpLog2);\r
+ symbolTable.relateToOperator("sqrt", EOpSqrt);\r
+ symbolTable.relateToOperator("inversesqrt", EOpInverseSqrt);\r
+\r
+ symbolTable.relateToOperator("abs", EOpAbs);\r
+ symbolTable.relateToOperator("sign", EOpSign);\r
+ symbolTable.relateToOperator("floor", EOpFloor);\r
+ symbolTable.relateToOperator("ceil", EOpCeil);\r
+ symbolTable.relateToOperator("fract", EOpFract);\r
+ symbolTable.relateToOperator("min", EOpMin);\r
+ symbolTable.relateToOperator("max", EOpMax);\r
+ symbolTable.relateToOperator("clamp", EOpClamp);\r
+ symbolTable.relateToOperator("mix", EOpMix);\r
+ symbolTable.relateToOperator("step", EOpStep);\r
+ symbolTable.relateToOperator("smoothstep", EOpSmoothStep);\r
+\r
+ symbolTable.relateToOperator("length", EOpLength);\r
+ symbolTable.relateToOperator("distance", EOpDistance);\r
+ symbolTable.relateToOperator("dot", EOpDot);\r
+ symbolTable.relateToOperator("cross", EOpCross);\r
+ symbolTable.relateToOperator("normalize", EOpNormalize);\r
+ symbolTable.relateToOperator("forward", EOpFaceForward);\r
+ symbolTable.relateToOperator("reflect", EOpReflect);\r
+ symbolTable.relateToOperator("refract", EOpRefract);\r
+ \r
+ symbolTable.relateToOperator("any", EOpAny);\r
+ symbolTable.relateToOperator("all", EOpAll);\r
+\r
+ switch(language) {\r
+\r
+ case EShLangVertex:\r
+ break;\r
+ \r
+ case EShLangFragment:\r
+ symbolTable.relateToOperator("dFdx", EOpDPdx); \r
+ symbolTable.relateToOperator("dFdy", EOpDPdy); \r
+ symbolTable.relateToOperator("fwidth", EOpFwidth);\r
+\r
+ break;\r
+\r
+ case EShLangPack:\r
+ case EShLangUnpack:\r
+ symbolTable.relateToOperator("itof", EOpItof);\r
+ symbolTable.relateToOperator("ftoi", EOpFtoi);\r
+ symbolTable.relateToOperator("skipPixels", EOpSkipPixels);\r
+ symbolTable.relateToOperator("readInput", EOpReadInput);\r
+ symbolTable.relateToOperator("writePixel", EOpWritePixel);\r
+ symbolTable.relateToOperator("bitmapLSB", EOpBitmapLsb);\r
+ symbolTable.relateToOperator("bitmapMSB", EOpBitmapMsb);\r
+ symbolTable.relateToOperator("writeOutput", EOpWriteOutput);\r
+ symbolTable.relateToOperator("readPixel", EOpReadPixel);\r
+ break;\r
+ default: assert (true && "Language not supported");\r
+ }\r
+}\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#ifndef _INITIALIZE_INCLUDED_\r
+#define _INITIALIZE_INCLUDED_\r
+\r
+#include "Include/ResourceLimits.h"\r
+#include "../Include/Common.h"\r
+#include "../Include/ShHandle.h"\r
+#include "SymbolTable.h"\r
+\r
+typedef TVector<TString> TBuiltInStrings;\r
+\r
+class TBuiltIns {\r
+public:\r
+ POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)\r
+ void initialize(TBuiltInResource &resources);\r
+ TBuiltInStrings* getBuiltInStrings() { return builtInStrings; }\r
+protected:\r
+ TBuiltInStrings builtInStrings[EShLangCount];\r
+};\r
+\r
+void IdentifyBuiltIns(EShLanguage, TSymbolTable&, TBuiltInResource &resources);\r
+\r
+#endif // _INITIALIZE_INCLUDED_\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#include "../Include/intermediate.h"\r
+\r
+//\r
+// Traverse the intermediate representation tree, and\r
+// call a node type specific function for each node.\r
+// Done recursively through the member function Traverse().\r
+// Node types can be skipped if their function to call is 0,\r
+// but their subtree will still be traversed.\r
+// Nodes with children can have their whole subtree skipped\r
+// if preVisit is turned on and the type specific function\r
+// returns false.\r
+//\r
+// preVisit, postVisit, and rightToLeft control what order\r
+// nodes are visited in.\r
+//\r
+\r
+//\r
+// Traversal functions for terminals are straighforward....\r
+//\r
+void TIntermSymbol::traverse(TIntermTraverser* it)\r
+{\r
+ if (it->visitSymbol)\r
+ it->visitSymbol(this, it);\r
+}\r
+\r
+void TIntermConstantUnion::traverse(TIntermTraverser* it)\r
+{\r
+ if (it->visitConstantUnion)\r
+ it->visitConstantUnion(this, it);\r
+}\r
+\r
+//\r
+// Traverse a binary node.\r
+//\r
+void TIntermBinary::traverse(TIntermTraverser* it)\r
+{\r
+ bool visit = true;\r
+\r
+ //\r
+ // visit the node before children if pre-visiting.\r
+ //\r
+ if (it->preVisit && it->visitBinary)\r
+ visit = it->visitBinary(true, this, it);\r
+ \r
+ //\r
+ // Visit the children, in the right order.\r
+ //\r
+ if (visit) {\r
+ ++it->depth;\r
+ if (it->rightToLeft) {\r
+ if (right)\r
+ right->traverse(it);\r
+ if (left)\r
+ left->traverse(it);\r
+ } else {\r
+ if (left)\r
+ left->traverse(it);\r
+ if (right)\r
+ right->traverse(it);\r
+ }\r
+ --it->depth;\r
+ }\r
+\r
+ //\r
+ // Visit the node after the children, if requested and the traversal\r
+ // hasn't been cancelled yet.\r
+ //\r
+ if (visit && it->postVisit && it->visitBinary)\r
+ it->visitBinary(false, this, it);\r
+}\r
+\r
+//\r
+// Traverse a unary node. Same comments in binary node apply here.\r
+//\r
+void TIntermUnary::traverse(TIntermTraverser* it)\r
+{\r
+ bool visit = true;\r
+\r
+ if (it->preVisit && it->visitUnary)\r
+ visit = it->visitUnary(true, this, it);\r
+\r
+ if (visit) {\r
+ ++it->depth;\r
+ operand->traverse(it);\r
+ --it->depth;\r
+ }\r
+ \r
+ if (visit && it->postVisit && it->visitUnary)\r
+ it->visitUnary(false, this, it);\r
+}\r
+\r
+//\r
+// Traverse an aggregate node. Same comments in binary node apply here.\r
+//\r
+void TIntermAggregate::traverse(TIntermTraverser* it)\r
+{\r
+ bool visit = true;\r
+ \r
+ if (it->preVisit && it->visitAggregate)\r
+ visit = it->visitAggregate(true, this, it);\r
+ \r
+ if (visit) {\r
+ ++it->depth;\r
+\r
+ TIntermSequence::iterator sit;\r
+ if (it->rightToLeft) {\r
+ sit = sequence.end();\r
+ while (sit != sequence.begin()) {\r
+ --sit;\r
+ (*sit)->traverse(it);\r
+ }\r
+ } else {\r
+ for (sit = sequence.begin(); sit != sequence.end(); ++sit)\r
+ (*sit)->traverse(it);\r
+ }\r
+ \r
+ --it->depth;\r
+ }\r
+\r
+ if (visit && it->postVisit && it->visitAggregate)\r
+ it->visitAggregate(false, this, it);\r
+}\r
+\r
+//\r
+// Traverse a selection node. Same comments in binary node apply here.\r
+//\r
+void TIntermSelection::traverse(TIntermTraverser* it)\r
+{\r
+ bool visit = true;\r
+\r
+ if (it->preVisit && it->visitSelection)\r
+ visit = it->visitSelection(true, this, it);\r
+ \r
+ if (visit) {\r
+ ++it->depth;\r
+ if (it->rightToLeft) {\r
+ if (falseBlock)\r
+ falseBlock->traverse(it);\r
+ if (trueBlock)\r
+ trueBlock->traverse(it);\r
+ condition->traverse(it);\r
+ } else {\r
+ condition->traverse(it);\r
+ if (trueBlock)\r
+ trueBlock->traverse(it);\r
+ if (falseBlock)\r
+ falseBlock->traverse(it);\r
+ }\r
+ --it->depth;\r
+ }\r
+\r
+ if (visit && it->postVisit && it->visitSelection)\r
+ it->visitSelection(false, this, it);\r
+}\r
+\r
+//\r
+// Traverse a loop node. Same comments in binary node apply here.\r
+//\r
+void TIntermLoop::traverse(TIntermTraverser* it)\r
+{\r
+ bool visit = true;\r
+\r
+ if (it->preVisit && it->visitLoop)\r
+ visit = it->visitLoop(true, this, it);\r
+ \r
+ if (visit) {\r
+ ++it->depth;\r
+ if (it->rightToLeft) {\r
+ if (terminal)\r
+ terminal->traverse(it);\r
+ if (body)\r
+ body->traverse(it);\r
+ if (test)\r
+ test->traverse(it);\r
+ } else {\r
+ if (test)\r
+ test->traverse(it);\r
+ if (body)\r
+ body->traverse(it);\r
+ if (terminal)\r
+ terminal->traverse(it);\r
+ }\r
+ --it->depth;\r
+ }\r
+\r
+ if (visit && it->postVisit && it->visitLoop)\r
+ it->visitLoop(false, this, it);\r
+}\r
+\r
+//\r
+// Traverse a branch node. Same comments in binary node apply here.\r
+//\r
+void TIntermBranch::traverse(TIntermTraverser* it)\r
+{\r
+ bool visit = true;\r
+\r
+ if (it->preVisit && it->visitBranch)\r
+ visit = it->visitBranch(true, this, it);\r
+ \r
+ if (visit && expression) {\r
+ ++it->depth;\r
+ expression->traverse(it);\r
+ --it->depth;\r
+ }\r
+\r
+ if (visit && it->postVisit && it->visitBranch)\r
+ it->visitBranch(false, this, it);\r
+}\r
+\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+//\r
+// Build the intermediate representation.\r
+//\r
+\r
+#include "../Include/ShHandle.h"\r
+#include "localintermediate.h"\r
+#include "QualifierAlive.h"\r
+#include "RemoveTree.h"\r
+#include <assert.h>\r
+#include <float.h>\r
+\r
+////////////////////////////////////////////////////////////////////////////\r
+//\r
+// First set of functions are to help build the intermediate representation.\r
+// These functions are not member functions of the nodes.\r
+// They are called from parser productions.\r
+//\r
+/////////////////////////////////////////////////////////////////////////////\r
+\r
+//\r
+// Add a terminal node for an identifier in an expression.\r
+//\r
+// Returns the added node.\r
+//\r
+TIntermSymbol* TIntermediate::addSymbol(int id, const TString& name, const TType& type, TSourceLoc line)\r
+{\r
+ TIntermSymbol* node = new TIntermSymbol(id, name, type);\r
+ node->setLine(line);\r
+\r
+ return node;\r
+}\r
+\r
+//\r
+// Connect two nodes with a new parent that does a binary operation on the nodes.\r
+//\r
+// Returns the added node.\r
+//\r
+TIntermTyped* TIntermediate::addBinaryMath(TOperator op, TIntermTyped* left, TIntermTyped* right, TSourceLoc line, TSymbolTable& symbolTable)\r
+{\r
+ switch (op) {\r
+ case EOpLessThan:\r
+ case EOpGreaterThan:\r
+ case EOpLessThanEqual:\r
+ case EOpGreaterThanEqual:\r
+ if (left->getType().isMatrix() || left->getType().isArray() || left->getType().isVector() || left->getType().getBasicType() == EbtStruct) {\r
+ return 0;\r
+ }\r
+ break;\r
+ case EOpLogicalOr:\r
+ case EOpLogicalXor:\r
+ case EOpLogicalAnd:\r
+ if (left->getType().getBasicType() != EbtBool || left->getType().isMatrix() || left->getType().isArray() || left->getType().isVector()) {\r
+ return 0;\r
+ }\r
+ break;\r
+ case EOpAdd:\r
+ case EOpSub:\r
+ case EOpDiv:\r
+ case EOpMul:\r
+ if (left->getType().getBasicType() == EbtStruct || left->getType().getBasicType() == EbtBool)\r
+ return 0;\r
+ default: break; \r
+ }\r
+\r
+ // \r
+ // First try converting the children to compatible types.\r
+ //\r
+\r
+ if (!(left->getType().getStruct() && right->getType().getStruct())) {\r
+ TIntermTyped* child = addConversion(op, left->getType(), right);\r
+ if (child)\r
+ right = child;\r
+ else {\r
+ child = addConversion(op, right->getType(), left);\r
+ if (child)\r
+ left = child;\r
+ else\r
+ return 0;\r
+ }\r
+ } else {\r
+ if (left->getType() != right->getType())\r
+ return 0;\r
+ }\r
+\r
+\r
+ //\r
+ // Need a new node holding things together then. Make\r
+ // one and promote it to the right type.\r
+ //\r
+ TIntermBinary* node = new TIntermBinary(op);\r
+ if (line == 0)\r
+ line = right->getLine();\r
+ node->setLine(line);\r
+\r
+ node->setLeft(left);\r
+ node->setRight(right);\r
+ if (! node->promote(infoSink))\r
+ return 0;\r
+\r
+ TIntermConstantUnion *leftTempConstant = left->getAsConstantUnion();\r
+ TIntermConstantUnion *rightTempConstant = right->getAsConstantUnion();\r
+ \r
+ if (leftTempConstant)\r
+ leftTempConstant = copyConstUnion(left->getAsConstantUnion())->getAsConstantUnion();\r
+ \r
+ if (rightTempConstant)\r
+ rightTempConstant = copyConstUnion(right->getAsConstantUnion())->getAsConstantUnion();\r
+ \r
+ if (right->getType().getQualifier() == EvqConst && left->getType().getQualifier() == EvqConst) {\r
+ if (right->getAsAggregate()) {\r
+ rightTempConstant = changeAggrToTempConst(right->getAsAggregate(), symbolTable, line); \r
+ if (rightTempConstant->getUnionArrayPointer() == 0)\r
+ return 0; \r
+ }\r
+\r
+ if (left->getAsAggregate()) {\r
+ leftTempConstant = changeAggrToTempConst(left->getAsAggregate(), symbolTable, line); \r
+ if (leftTempConstant->getUnionArrayPointer() == 0)\r
+ return 0;\r
+ }\r
+ }\r
+\r
+ //\r
+ // See if we can fold constants.\r
+ //\r
+\r
+ TIntermTyped* typedReturnNode = 0;\r
+ if ( leftTempConstant && rightTempConstant) {\r
+ if (leftTempConstant->getSize() == 1 && rightTempConstant->getSize() > 1)\r
+ typedReturnNode = rightTempConstant->fold(node->getOp(), leftTempConstant, infoSink, false);\r
+ else\r
+ typedReturnNode = leftTempConstant->fold(node->getOp(), rightTempConstant, infoSink, true);\r
+\r
+ if (typedReturnNode)\r
+ return typedReturnNode;\r
+ else {\r
+ node->setLeft(leftTempConstant);\r
+ node->setRight(rightTempConstant);\r
+ }\r
+ } else if (leftTempConstant) {\r
+ node->setLeft(copyConstUnion(leftTempConstant));\r
+ } else if (rightTempConstant) {\r
+ node->setRight(rightTempConstant);\r
+ }\r
+\r
+ return node;\r
+}\r
+\r
+//\r
+// Connect two nodes through an assignment.\r
+//\r
+// Returns the added node.\r
+//\r
+TIntermTyped* TIntermediate::addAssign(TOperator op, TIntermTyped* left, TIntermTyped* right, TSourceLoc line)\r
+{\r
+ //\r
+ // Like adding binary math, except the conversion can only go\r
+ // from right to left.\r
+ //\r
+ TIntermBinary* node = new TIntermBinary(op);\r
+ if (line == 0)\r
+ line = left->getLine();\r
+ node->setLine(line);\r
+\r
+ if (right->getAsConstantUnion()) { // if the right node of assignment is a TempConstant node, allocate its own new space and remove the pointer to the symbol table value\r
+ right = copyConstUnion(right->getAsConstantUnion()) ;\r
+ if (right == 0)\r
+ return 0;\r
+ }\r
+\r
+ TIntermTyped* child = addConversion(op, left->getType(), right);\r
+ if (child == 0)\r
+ return 0;\r
+\r
+ node->setLeft(left);\r
+ node->setRight(child);\r
+ if (! node->promote(infoSink))\r
+ return 0;\r
+\r
+ return node;\r
+}\r
+\r
+//\r
+// Connect two nodes through an index operator, where the left node is the base\r
+// of an array or struct, and the right node is a direct or indirect offset.\r
+//\r
+// Returns the added node.\r
+// The caller should set the type of the returned node.\r
+//\r
+TIntermTyped* TIntermediate::addIndex(TOperator op, TIntermTyped* base, TIntermTyped* index, TSourceLoc line)\r
+{\r
+ TIntermBinary* node = new TIntermBinary(op);\r
+ if (line == 0)\r
+ line = index->getLine();\r
+ node->setLine(line);\r
+ node->setLeft(base);\r
+ node->setRight(index);\r
+\r
+ // caller should set the type\r
+\r
+ return node;\r
+}\r
+\r
+//\r
+// Add one node as the parent of another that it operates on.\r
+//\r
+// Returns the added node.\r
+//\r
+TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermNode* childNode, TSourceLoc line, TSymbolTable& symbolTable)\r
+{\r
+ TIntermUnary* node;\r
+ TIntermTyped* child = childNode->getAsTyped();\r
+\r
+ if (child == 0) {\r
+ infoSink.info.message(EPrefixInternalError, "Bad type in AddUnaryMath", line);\r
+ return 0;\r
+ }\r
+\r
+ switch (op) {\r
+ case EOpLogicalNot:\r
+ if (child->getType().getBasicType() != EbtBool || child->getType().isMatrix() || child->getType().isArray() || child->getType().isVector()) {\r
+ return 0;\r
+ }\r
+ break;\r
+\r
+ case EOpPostIncrement:\r
+ case EOpPreIncrement:\r
+ case EOpPostDecrement:\r
+ case EOpPreDecrement:\r
+ case EOpNegative:\r
+ if (child->getType().getBasicType() == EbtStruct)\r
+ return 0;\r
+ default: break;\r
+ }\r
+ \r
+ //\r
+ // Do we need to promote the operand?\r
+ //\r
+ // Note: Implicit promotions were removed from the language.\r
+ //\r
+ TBasicType newType = EbtVoid;\r
+ switch (op) {\r
+ case EOpConstructInt: newType = EbtInt; break;\r
+ case EOpConstructBool: newType = EbtBool; break;\r
+ case EOpConstructFloat: newType = EbtFloat; break;\r
+ default: break;\r
+ }\r
+\r
+ if (newType != EbtVoid) {\r
+ child = addConversion(op, TType(newType, EvqTemporary, child->getNominalSize(), \r
+ child->isMatrix(), \r
+ child->isArray()),\r
+ child);\r
+ if (child == 0)\r
+ return 0;\r
+ }\r
+\r
+ //\r
+ // For constructors, we are now done, it's all in the conversion.\r
+ //\r
+ switch (op) {\r
+ case EOpConstructInt:\r
+ case EOpConstructBool:\r
+ case EOpConstructFloat:\r
+ return child;\r
+ default: break;\r
+ }\r
+ \r
+ if (child->getAsConstantUnion())\r
+ child = copyConstUnion(child->getAsConstantUnion());\r
+\r
+ if (child->getAsAggregate() && child->getType().getQualifier() == EvqConst) {\r
+ child = changeAggrToTempConst(child->getAsAggregate(), symbolTable, line); \r
+ if (child->getAsConstantUnion()->getUnionArrayPointer() == 0)\r
+ return 0; \r
+ }\r
+ \r
+ TIntermConstantUnion *childTempConstant = child->getAsConstantUnion();\r
+ \r
+ //\r
+ // Make a new node for the operator.\r
+ //\r
+ node = new TIntermUnary(op);\r
+ if (line == 0)\r
+ line = child->getLine();\r
+ node->setLine(line);\r
+ node->setOperand(child);\r
+ \r
+ if (! node->promote(infoSink))\r
+ return 0;\r
+\r
+ if (childTempConstant) {\r
+ TIntermTyped* newChild = childTempConstant->fold(op, 0, infoSink, true);\r
+ \r
+ if (newChild) {\r
+ return newChild;\r
+ } \r
+ } \r
+\r
+ return node;\r
+}\r
+\r
+//\r
+// This is the safe way to change the operator on an aggregate, as it\r
+// does lots of error checking and fixing. Especially for establishing\r
+// a function call's operation on it's set of parameters. Sequences\r
+// of instructions are also aggregates, but they just direnctly set\r
+// their operator to EOpSequence.\r
+//\r
+// Returns an aggregate node, which could be the one passed in if\r
+// it was already an aggregate.\r
+//\r
+TIntermAggregate* TIntermediate::setAggregateOperator(TIntermNode* node, TOperator op, TSourceLoc line)\r
+{\r
+ TIntermAggregate* aggNode;\r
+\r
+ //\r
+ // Make sure we have an aggregate. If not turn it into one.\r
+ //\r
+ if (node) {\r
+ aggNode = node->getAsAggregate();\r
+ if (aggNode == 0 || aggNode->getOp() != EOpNull) {\r
+ //\r
+ // Make an aggregate containing this node.\r
+ //\r
+ aggNode = new TIntermAggregate();\r
+ aggNode->getSequence().push_back(node);\r
+ if (line == 0)\r
+ line = node->getLine();\r
+ }\r
+ } else\r
+ aggNode = new TIntermAggregate();\r
+\r
+ //\r
+ // Set the operator.\r
+ //\r
+ aggNode->setOperator(op);\r
+ if (line != 0)\r
+ aggNode->setLine(line);\r
+\r
+ return aggNode;\r
+}\r
+\r
+//\r
+// Convert one type to another.\r
+//\r
+// Returns the node representing the conversion, which could be the same\r
+// node passed in if no conversion was needed.\r
+//\r
+// Return 0 if a conversion can't be done.\r
+//\r
+TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TIntermTyped* node)\r
+{\r
+ //\r
+ // Does the base type allow operation?\r
+ //\r
+ switch (node->getBasicType()) {\r
+ case EbtVoid:\r
+ case EbtSampler1D:\r
+ case EbtSampler2D:\r
+ case EbtSampler3D:\r
+ case EbtSamplerCube:\r
+ case EbtSampler1DShadow:\r
+ case EbtSampler2DShadow:\r
+ return 0;\r
+ default: break;\r
+ }\r
+\r
+ //\r
+ // Otherwise, if types are identical, no problem\r
+ //\r
+ if (type == node->getType())\r
+ return node;\r
+\r
+ //\r
+ // If one's a structure, then no conversions.\r
+ //\r
+ if (type.getStruct() || node->getType().getStruct())\r
+ return 0;\r
+\r
+ TBasicType promoteTo;\r
+ \r
+ switch (op) {\r
+ //\r
+ // Explicit conversions\r
+ //\r
+ case EOpConstructBool:\r
+ promoteTo = EbtBool;\r
+ break;\r
+ case EOpConstructFloat:\r
+ promoteTo = EbtFloat;\r
+ break;\r
+ case EOpConstructInt:\r
+ promoteTo = EbtInt;\r
+ break;\r
+ default:\r
+ //\r
+ // implicit conversions were removed from the language.\r
+ //\r
+ if (type.getBasicType() != node->getType().getBasicType())\r
+ return 0;\r
+ //\r
+ // Size and structure could still differ, but that's\r
+ // handled by operator promotion.\r
+ //\r
+ return node;\r
+ }\r
+ \r
+ //\r
+ // Do conversion.\r
+ //\r
+ bool allConstant = true;\r
+ // check to see if there is an aggregate node\r
+ if (node->getAsAggregate()) {\r
+ TIntermSequence &sequenceVector = node->getAsAggregate()->getSequence() ;\r
+ for (TIntermSequence::iterator p = sequenceVector.begin(); \r
+ p != sequenceVector.end(); p++) {\r
+ if (!(*p)->getAsTyped()->getAsConstantUnion())\r
+ allConstant = false;\r
+ }\r
+ }\r
+ if (allConstant && node->getAsAggregate()) { // we can do the constant folding here as all the nodes of the aggregate are const\r
+ TIntermSequence &sequenceVector = node->getAsAggregate()->getSequence() ;\r
+ for (TIntermSequence::iterator p = sequenceVector.begin(); \r
+ p != sequenceVector.end(); p++) {\r
+ TIntermTyped* newNode = 0;\r
+ constUnion *unionArray = new constUnion[1];\r
+\r
+ switch (promoteTo) {\r
+ case EbtFloat:\r
+ switch ((*p)->getAsTyped()->getType().getBasicType()) {\r
+ \r
+ case EbtInt: \r
+ unionArray->fConst = static_cast<float>((*p)->getAsTyped()->getAsConstantUnion()->getUnionArrayPointer()->iConst);\r
+ newNode = addConstantUnion(unionArray, TType(EbtFloat, EvqConst), node->getLine()); break;\r
+ case EbtBool: \r
+ unionArray->fConst = static_cast<float>((*p)->getAsTyped()->getAsConstantUnion()->getUnionArrayPointer()->bConst);\r
+ newNode = newNode = addConstantUnion(unionArray, TType(EbtFloat, EvqConst), node->getLine()); break;\r
+ default:\r
+ infoSink.info.message(EPrefixInternalError, "Bad promotion node", node->getLine());\r
+ return 0;\r
+ }\r
+ break;\r
+ case EbtInt:\r
+ switch ((*p)->getAsTyped()->getType().getBasicType()) {\r
+ case EbtFloat:\r
+ unionArray->iConst = static_cast<int>((*p)->getAsTyped()->getAsConstantUnion()->getUnionArrayPointer()->fConst);\r
+ newNode = addConstantUnion(unionArray, TType(EbtInt, EvqConst), node->getLine()); \r
+ break;\r
+ case EbtBool:\r
+ unionArray->iConst = static_cast<int>((*p)->getAsTyped()->getAsConstantUnion()->getUnionArrayPointer()->bConst);\r
+ newNode = addConstantUnion(unionArray, TType(EbtInt, EvqConst), node->getLine()); \r
+ break;\r
+ default:\r
+ infoSink.info.message(EPrefixInternalError, "Bad promotion node", node->getLine());\r
+ return 0;\r
+ }\r
+ break;\r
+ case EbtBool:\r
+ switch ((*p)->getAsTyped()->getType().getBasicType()) {\r
+ case EbtFloat:\r
+ unionArray->bConst = (*p)->getAsTyped()->getAsConstantUnion()->getUnionArrayPointer()->fConst != 0.0 ;\r
+ newNode = addConstantUnion(unionArray, TType(EbtBool, EvqConst), node->getLine()); \r
+ break;\r
+ case EbtInt:\r
+ unionArray->bConst = (*p)->getAsTyped()->getAsConstantUnion()->getUnionArrayPointer()->iConst != 0 ;\r
+ newNode = addConstantUnion(unionArray, TType(EbtBool, EvqConst), node->getLine()); \r
+ break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Bad promotion node", node->getLine());\r
+ return 0;\r
+ } \r
+ break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Bad promotion node", node->getLine());\r
+ return 0;\r
+ }\r
+ if (newNode) {\r
+ sequenceVector.erase(p); \r
+ sequenceVector.insert(p, newNode);\r
+ }\r
+ }\r
+ return node->getAsAggregate();\r
+ } else if (node->getAsConstantUnion()) {\r
+\r
+ return (promoteConstantUnion(promoteTo, node->getAsConstantUnion()));\r
+ } else {\r
+ \r
+ //\r
+ // Add a new newNode for the conversion.\r
+ //\r
+ TIntermUnary* newNode = 0;\r
+\r
+ TOperator newOp = EOpNull;\r
+ switch (promoteTo) {\r
+ case EbtFloat:\r
+ switch (node->getBasicType()) {\r
+ case EbtInt: newOp = EOpConvIntToFloat; break;\r
+ case EbtBool: newOp = EOpConvBoolToFloat; break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Bad promotion node", node->getLine());\r
+ return 0;\r
+ }\r
+ break;\r
+ case EbtBool:\r
+ switch (node->getBasicType()) {\r
+ case EbtInt: newOp = EOpConvIntToBool; break;\r
+ case EbtFloat: newOp = EOpConvFloatToBool; break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Bad promotion node", node->getLine());\r
+ return 0;\r
+ }\r
+ break;\r
+ case EbtInt:\r
+ switch (node->getBasicType()) {\r
+ case EbtBool: newOp = EOpConvBoolToInt; break;\r
+ case EbtFloat: newOp = EOpConvFloatToInt; break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Bad promotion node", node->getLine());\r
+ return 0;\r
+ }\r
+ break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Bad promotion type", node->getLine());\r
+ return 0;\r
+ }\r
+\r
+ newNode = new TIntermUnary(newOp, TType(promoteTo, EvqTemporary,\r
+ node->getNominalSize(), \r
+ node->isMatrix(), \r
+ node->isArray()));\r
+ newNode->setLine(node->getLine());\r
+ newNode->setOperand(node);\r
+\r
+ return newNode;\r
+ }\r
+}\r
+\r
+//\r
+// Safe way to combine two nodes into an aggregate. Works with null pointers, \r
+// a node that's not a aggregate yet, etc.\r
+//\r
+// Returns the resulting aggregate, unless 0 was passed in for \r
+// both existing nodes.\r
+//\r
+TIntermAggregate* TIntermediate::growAggregate(TIntermNode* left, TIntermNode* right, TSourceLoc line)\r
+{\r
+ if (left == 0 && right == 0)\r
+ return 0;\r
+\r
+ TIntermAggregate* aggNode = 0;\r
+ if (left)\r
+ aggNode = left->getAsAggregate();\r
+ if (!aggNode || aggNode->getOp() != EOpNull) {\r
+ aggNode = new TIntermAggregate;\r
+ if (left)\r
+ aggNode->getSequence().push_back(left);\r
+ }\r
+\r
+ if (right)\r
+ aggNode->getSequence().push_back(right);\r
+\r
+ if (line != 0)\r
+ aggNode->setLine(line);\r
+\r
+ return aggNode;\r
+}\r
+\r
+//\r
+// Turn an existing node into an aggregate.\r
+//\r
+// Returns an aggregate, unless 0 was passed in for the existing node.\r
+//\r
+TIntermAggregate* TIntermediate::makeAggregate(TIntermNode* node, TSourceLoc line)\r
+{\r
+ if (node == 0)\r
+ return 0;\r
+\r
+ TIntermAggregate* aggNode = new TIntermAggregate;\r
+ aggNode->getSequence().push_back(node);\r
+\r
+ if (line != 0)\r
+ aggNode->setLine(line);\r
+ else\r
+ aggNode->setLine(node->getLine());\r
+\r
+ return aggNode;\r
+}\r
+\r
+//\r
+// For "if" test nodes. There are three children; a condition,\r
+// a true path, and a false path. The two paths are in the\r
+// nodePair.\r
+//\r
+// Returns the selection node created.\r
+//\r
+TIntermNode* TIntermediate::addSelection(TIntermTyped* cond, TIntermNodePair nodePair, TSourceLoc line)\r
+{\r
+ //\r
+ // For compile time constant selections, prune the code and \r
+ // test now.\r
+ //\r
+ \r
+ if (cond->getAsTyped() && cond->getAsTyped()->getAsConstantUnion()) {\r
+ if (cond->getAsTyped()->getAsConstantUnion()->getUnionArrayPointer()->bConst)\r
+ return nodePair.node1;\r
+ else\r
+ return nodePair.node2;\r
+ }\r
+\r
+ TIntermSelection* node = new TIntermSelection(cond, nodePair.node1, nodePair.node2);\r
+ node->setLine(line);\r
+\r
+ return node;\r
+}\r
+\r
+//\r
+// For "?:" test nodes. There are three children; a condition,\r
+// a true path, and a false path. The two paths are specified\r
+// as separate parameters.\r
+//\r
+// Returns the selection node created, or 0 if one could not be.\r
+//\r
+TIntermTyped* TIntermediate::addSelection(TIntermTyped* cond, TIntermTyped* trueBlock, TIntermTyped* falseBlock, TSourceLoc line)\r
+{\r
+ //\r
+ // Get compatible types.\r
+ //\r
+ TIntermTyped* child = addConversion(EOpSequence, trueBlock->getType(), falseBlock);\r
+ if (child)\r
+ falseBlock = child;\r
+ else {\r
+ child = addConversion(EOpSequence, falseBlock->getType(), trueBlock);\r
+ if (child)\r
+ trueBlock = child;\r
+ else\r
+ return 0;\r
+ }\r
+\r
+ //\r
+ // See if condition is constant, and select now.\r
+ //\r
+\r
+ if (cond->getAsConstantUnion()) {\r
+ if (cond->getAsConstantUnion()->getUnionArrayPointer()->bConst)\r
+ return trueBlock;\r
+ else\r
+ return falseBlock;\r
+ }\r
+\r
+ //\r
+ // Make a selection node.\r
+ //\r
+ TIntermSelection* node = new TIntermSelection(cond, trueBlock, falseBlock, trueBlock->getType());\r
+ node->setLine(line);\r
+\r
+ return node;\r
+}\r
+\r
+//\r
+// Constant terminal nodes. Has a union that contains bool, float or int constants\r
+//\r
+// Returns the constant union node created.\r
+//\r
+\r
+TIntermConstantUnion* TIntermediate::addConstantUnion(constUnion* unionArrayPointer, const TType& t, TSourceLoc line)\r
+{\r
+ TIntermConstantUnion* node = new TIntermConstantUnion(unionArrayPointer, t);\r
+ node->setLine(line);\r
+\r
+ return node;\r
+}\r
+\r
+TIntermTyped* TIntermediate::addSwizzle(TVectorFields& fields, TSourceLoc line)\r
+{\r
+ \r
+ TIntermAggregate* node = new TIntermAggregate(EOpSequence);\r
+\r
+ node->setLine(line);\r
+ TIntermConstantUnion* constIntNode;\r
+ TIntermSequence &sequenceVector = node->getSequence();\r
+ constUnion* unionArray;\r
+\r
+ for (int i = 0; i < fields.num; i++) {\r
+ unionArray = new constUnion[1];\r
+ unionArray->iConst = fields.offsets[i];\r
+ constIntNode = addConstantUnion(unionArray, TType(EbtInt, EvqConst), line);\r
+ sequenceVector.push_back(constIntNode);\r
+ }\r
+\r
+ return node;\r
+}\r
+\r
+//\r
+// Create loop nodes.\r
+//\r
+TIntermNode* TIntermediate::addLoop(TIntermNode* body, TIntermTyped* test, TIntermTyped* terminal, bool testFirst, TSourceLoc line)\r
+{\r
+ TIntermNode* node = new TIntermLoop(body, test, terminal, testFirst);\r
+ node->setLine(line);\r
+ \r
+ return node;\r
+}\r
+\r
+//\r
+// Add branches.\r
+//\r
+TIntermBranch* TIntermediate::addBranch(TOperator branchOp, TSourceLoc line)\r
+{\r
+ return addBranch(branchOp, 0, line);\r
+}\r
+\r
+TIntermBranch* TIntermediate::addBranch(TOperator branchOp, TIntermTyped* expression, TSourceLoc line)\r
+{\r
+ TIntermBranch* node = new TIntermBranch(branchOp, expression);\r
+ node->setLine(line);\r
+\r
+ return node;\r
+}\r
+\r
+//\r
+// This is to be executed once the final root is put on top by the parsing\r
+// process.\r
+//\r
+bool TIntermediate::postProcess(TIntermNode* root, EShLanguage language)\r
+{\r
+ if (root == 0)\r
+ return true;\r
+\r
+ //\r
+ // First, finish off the top level sequence, if any\r
+ //\r
+ TIntermAggregate* aggRoot = root->getAsAggregate();\r
+ if (aggRoot && aggRoot->getOp() == EOpNull)\r
+ aggRoot->setOperator(EOpSequence);\r
+\r
+ //\r
+ // Other things...\r
+ //\r
+\r
+ if (language == EShLangVertex && !QualifierWritten(root, EvqPosition)) {\r
+ infoSink.info.message(EPrefixError, "gl_Position must be written by all paths through a vertex shader.");\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+//\r
+// This deletes the tree.\r
+//\r
+void TIntermediate::remove(TIntermNode* root)\r
+{\r
+ if (root)\r
+ RemoveAllTreeNodes(root);\r
+}\r
+\r
+////////////////////////////////////////////////////////////////\r
+//\r
+// Member functions of the nodes used for building the tree.\r
+//\r
+////////////////////////////////////////////////////////////////\r
+\r
+//\r
+// Say whether or not an operation node changes the value of a variable.\r
+//\r
+// Returns true if state is modified.\r
+//\r
+bool TIntermOperator::modifiesState() const\r
+{\r
+ switch (op) { \r
+ case EOpPostIncrement: \r
+ case EOpPostDecrement: \r
+ case EOpPreIncrement: \r
+ case EOpPreDecrement: \r
+ case EOpAssign: \r
+ case EOpAddAssign: \r
+ case EOpSubAssign: \r
+ case EOpMulAssign: \r
+ case EOpVectorTimesMatrixAssign:\r
+ case EOpVectorTimesScalarAssign:\r
+ case EOpMatrixTimesScalarAssign:\r
+ case EOpMatrixTimesMatrixAssign:\r
+ case EOpDivAssign: \r
+ case EOpModAssign: \r
+ case EOpAndAssign: \r
+ case EOpInclusiveOrAssign: \r
+ case EOpExclusiveOrAssign: \r
+ case EOpLeftShiftAssign: \r
+ case EOpRightShiftAssign: \r
+ return true;\r
+ default:\r
+ return false;\r
+ }\r
+}\r
+\r
+//\r
+// returns true if the operator is for one of the constructors\r
+//\r
+bool TIntermOperator::isConstructor() const\r
+{\r
+ switch (op) {\r
+ case EOpConstructVec2:\r
+ case EOpConstructVec3:\r
+ case EOpConstructVec4:\r
+ case EOpConstructMat2:\r
+ case EOpConstructMat3:\r
+ case EOpConstructMat4:\r
+ case EOpConstructFloat:\r
+ case EOpConstructIVec2:\r
+ case EOpConstructIVec3:\r
+ case EOpConstructIVec4:\r
+ case EOpConstructInt:\r
+ case EOpConstructBVec2:\r
+ case EOpConstructBVec3:\r
+ case EOpConstructBVec4:\r
+ case EOpConstructBool:\r
+ case EOpConstructStruct:\r
+ return true;\r
+ default:\r
+ return false;\r
+ }\r
+}\r
+//\r
+// Make sure the type of a unary operator is appropriate for its \r
+// combination of operation and operand type.\r
+//\r
+// Returns false in nothing makes sense.\r
+//\r
+bool TIntermUnary::promote(TInfoSink&)\r
+{\r
+ switch (op) {\r
+ case EOpLogicalNot:\r
+ if (operand->getBasicType() != EbtBool)\r
+ return false;\r
+ break;\r
+ case EOpBitwiseNot:\r
+ if (operand->getBasicType() != EbtInt)\r
+ return false;\r
+ break;\r
+ case EOpNegative:\r
+ case EOpPostIncrement:\r
+ case EOpPostDecrement:\r
+ case EOpPreIncrement:\r
+ case EOpPreDecrement:\r
+ if (operand->getBasicType() == EbtBool)\r
+ return false;\r
+ break;\r
+\r
+ // operators for built-ins are already type checked against their prototype\r
+ case EOpAny:\r
+ case EOpAll:\r
+ case EOpVectorLogicalNot:\r
+ return true;\r
+\r
+ default:\r
+ if (operand->getBasicType() != EbtFloat)\r
+ return false;\r
+ }\r
+ \r
+ setType(operand->getType());\r
+\r
+ return true;\r
+}\r
+\r
+//\r
+// Establishes the type of the resultant operation, as well as\r
+// makes the operator the correct one for the operands.\r
+//\r
+// Returns false if operator can't work on operands.\r
+//\r
+bool TIntermBinary::promote(TInfoSink& infoSink)\r
+{\r
+ int size = left->getNominalSize();\r
+ if (right->getNominalSize() > size)\r
+ size = right->getNominalSize();\r
+\r
+ TBasicType type = left->getBasicType();\r
+\r
+ //\r
+ // Don't operate on arrays.\r
+ //\r
+ if (left->isArray() || right->isArray())\r
+ return false;\r
+\r
+ //\r
+ // Base assumption: just make the type the same as the left\r
+ // operand. Then only deviations from this need be coded.\r
+ //\r
+ setType(TType(type, EvqTemporary, left->getNominalSize(), left->isMatrix()));\r
+ \r
+ //\r
+ // All scalars. Code after this test assumes this case is removed!\r
+ //\r
+ if (size == 1) {\r
+\r
+ switch (op) {\r
+\r
+ //\r
+ // Promote to conditional\r
+ //\r
+ case EOpEqual:\r
+ case EOpNotEqual:\r
+ case EOpLessThan:\r
+ case EOpGreaterThan:\r
+ case EOpLessThanEqual:\r
+ case EOpGreaterThanEqual:\r
+ setType(TType(EbtBool));\r
+ break;\r
+\r
+ //\r
+ // And and Or operate on conditionals\r
+ //\r
+ case EOpLogicalAnd:\r
+ case EOpLogicalOr:\r
+ if (left->getBasicType() != EbtBool || right->getBasicType() != EbtBool)\r
+ return false; \r
+ setType(TType(EbtBool));\r
+ break;\r
+\r
+ //\r
+ // Check for integer only operands.\r
+ //\r
+ case EOpMod:\r
+ case EOpRightShift:\r
+ case EOpLeftShift:\r
+ case EOpAnd:\r
+ case EOpInclusiveOr:\r
+ case EOpExclusiveOr:\r
+ if (left->getBasicType() != EbtInt || right->getBasicType() != EbtInt)\r
+ return false;\r
+ break;\r
+ case EOpModAssign:\r
+ case EOpAndAssign:\r
+ case EOpInclusiveOrAssign:\r
+ case EOpExclusiveOrAssign:\r
+ case EOpLeftShiftAssign:\r
+ case EOpRightShiftAssign:\r
+ if (left->getBasicType() != EbtInt || right->getBasicType() != EbtInt)\r
+ return false;\r
+ // fall through\r
+\r
+ //\r
+ // Everything else should have matching types\r
+ //\r
+ default:\r
+ if (left->getBasicType() != right->getBasicType() ||\r
+ left->isMatrix() != right->isMatrix())\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+ }\r
+\r
+ //\r
+ // Are the sizes compatible?\r
+ //\r
+ if ( left->getNominalSize() != size && left->getNominalSize() != 1 ||\r
+ right->getNominalSize() != size && right->getNominalSize() != 1)\r
+ return false;\r
+\r
+ //\r
+ // Can these two operands be combined?\r
+ //\r
+ switch (op) {\r
+ case EOpMul:\r
+ if (!left->isMatrix() && right->isMatrix()) {\r
+ if (left->isVector())\r
+ op = EOpVectorTimesMatrix;\r
+ else {\r
+ op = EOpMatrixTimesScalar;\r
+ setType(TType(type, EvqTemporary, size, true));\r
+ }\r
+ } else if (left->isMatrix() && !right->isMatrix()) {\r
+ if (right->isVector()) {\r
+ op = EOpMatrixTimesVector;\r
+ setType(TType(type, EvqTemporary, size, false));\r
+ } else {\r
+ op = EOpMatrixTimesScalar;\r
+ }\r
+ } else if (left->isMatrix() && right->isMatrix()) {\r
+ op = EOpMatrixTimesMatrix;\r
+ } else if (!left->isMatrix() && !right->isMatrix()) {\r
+ if (left->isVector() && right->isVector()) {\r
+ // leave as component product\r
+ } else if (left->isVector() || right->isVector()) {\r
+ op = EOpVectorTimesScalar;\r
+ setType(TType(type, EvqTemporary, size, false));\r
+ }\r
+ } else {\r
+ infoSink.info.message(EPrefixInternalError, "Missing elses", getLine());\r
+ return false;\r
+ }\r
+ break;\r
+ case EOpMulAssign:\r
+ if (!left->isMatrix() && right->isMatrix()) {\r
+ if (left->isVector())\r
+ op = EOpVectorTimesMatrixAssign;\r
+ else {\r
+ return false;\r
+ }\r
+ } else if (left->isMatrix() && !right->isMatrix()) {\r
+ if (right->isVector()) {\r
+ return false;\r
+ } else {\r
+ op = EOpMatrixTimesScalarAssign;\r
+ }\r
+ } else if (left->isMatrix() && right->isMatrix()) {\r
+ op = EOpMatrixTimesMatrixAssign;\r
+ } else if (!left->isMatrix() && !right->isMatrix()) {\r
+ if (left->isVector() && right->isVector()) {\r
+ // leave as component product\r
+ } else if (left->isVector() || right->isVector()) {\r
+ if (! left->isVector())\r
+ return false;\r
+ op = EOpVectorTimesScalarAssign;\r
+ setType(TType(type, EvqTemporary, size, false));\r
+ }\r
+ } else {\r
+ infoSink.info.message(EPrefixInternalError, "Missing elses", getLine());\r
+ return false;\r
+ }\r
+ break; \r
+ case EOpAssign:\r
+ if (left->getNominalSize() != right->getNominalSize())\r
+ return false;\r
+ // fall through\r
+ case EOpAdd:\r
+ case EOpSub:\r
+ case EOpDiv:\r
+ case EOpMod:\r
+ case EOpAddAssign:\r
+ case EOpSubAssign:\r
+ case EOpDivAssign:\r
+ case EOpModAssign:\r
+ if (left->isMatrix() && right->isVector() ||\r
+ left->isVector() && right->isMatrix() ||\r
+ left->getBasicType() != right->getBasicType())\r
+ return false;\r
+ setType(TType(type, EvqTemporary, size, left->isMatrix() || right->isMatrix()));\r
+ break;\r
+ \r
+ case EOpEqual:\r
+ case EOpNotEqual:\r
+ case EOpLessThan:\r
+ case EOpGreaterThan:\r
+ case EOpLessThanEqual:\r
+ case EOpGreaterThanEqual:\r
+ if (left->isMatrix() && right->isVector() ||\r
+ left->isVector() && right->isMatrix() ||\r
+ left->getBasicType() != right->getBasicType())\r
+ return false;\r
+ setType(TType(EbtBool));\r
+ break;\r
+\r
+default:\r
+ return false;\r
+ }\r
+\r
+ //\r
+ // One more check for assignment. The Resulting type has to match the left operand.\r
+ //\r
+ switch (op) {\r
+ case EOpAssign:\r
+ case EOpAddAssign:\r
+ case EOpSubAssign:\r
+ case EOpMulAssign:\r
+ case EOpDivAssign:\r
+ case EOpModAssign:\r
+ case EOpAndAssign:\r
+ case EOpInclusiveOrAssign:\r
+ case EOpExclusiveOrAssign:\r
+ case EOpLeftShiftAssign:\r
+ case EOpRightShiftAssign:\r
+ if (getType() != left->getType())\r
+ return false;\r
+ break;\r
+ default: \r
+ break;\r
+ }\r
+ \r
+ return true;\r
+}\r
+\r
+bool compareStructure(TType leftNodeType, constUnion* rightUnionArray, constUnion* leftUnionArray, int& index)\r
+{\r
+ TTypeList* fields = leftNodeType.getStruct();\r
+\r
+ size_t structSize = fields->size();\r
+\r
+ for (size_t j = 0; j < structSize; j++) {\r
+ int size = (*fields)[j].type->getInstanceSize();\r
+ for (int i = 0; i < size; i++) {\r
+ switch ((*fields)[j].type->getBasicType()) {\r
+ case EbtFloat:\r
+ if (leftUnionArray[index].fConst != rightUnionArray[index].fConst)\r
+ return false;\r
+ index++;\r
+ break;\r
+ case EbtInt:\r
+ if (leftUnionArray[index].iConst != rightUnionArray[index].iConst)\r
+ return false;\r
+ index++;\r
+ break;\r
+ case EbtBool:\r
+ if (leftUnionArray[index].bConst != rightUnionArray[index].bConst)\r
+ return false;\r
+ index++;\r
+ break;\r
+ case EbtStruct:\r
+ if (!compareStructure(*(*fields)[j].type, rightUnionArray, leftUnionArray, index))\r
+ return false;\r
+ break;\r
+ default: \r
+ assert(true && "Cannot compare");\r
+ break;\r
+ } \r
+ \r
+ }\r
+ }\r
+ return true;\r
+} \r
+\r
+//\r
+// The fold functions see if an operation on a constant can be done in place,\r
+// without generating run-time code.\r
+//\r
+// Returns the node to keep using, which may or may not be the node passed in.\r
+//\r
+\r
+TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNode, TInfoSink& infoSink, bool leftOperand)\r
+{ \r
+ constUnion *unionArray = this->getUnionArrayPointer(); \r
+\r
+ if (constantNode) {\r
+ if (constantNode->getAsConstantUnion() && constantNode->getSize() == 1 && constantNode->getType().getBasicType() != EbtStruct\r
+ && this->getSize() > 1) {\r
+ TIntermConstantUnion *node = constantNode->getAsConstantUnion();\r
+ TIntermConstantUnion *newNode;\r
+ constUnion* tempConstArray;\r
+ int i;\r
+ switch(op) {\r
+ case EOpAdd: \r
+ tempConstArray = new constUnion[this->getSize()];\r
+ for (i = 0; i < this->getSize(); i++) {\r
+ switch (this->getType().getBasicType()) {\r
+ case EbtFloat: tempConstArray[i].fConst = unionArray[i].fConst + node->getUnionArrayPointer()->fConst; break;\r
+ case EbtInt: tempConstArray[i].iConst = unionArray[i].iConst + node->getUnionArrayPointer()->iConst; break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"+\"", this->getLine());\r
+ return 0;\r
+ }\r
+ }\r
+ break;\r
+ case EOpMatrixTimesScalar: \r
+ case EOpVectorTimesScalar:\r
+ tempConstArray = new constUnion[this->getSize()];\r
+ for (i = 0; i < this->getSize(); i++) {\r
+ switch (this->getType().getBasicType()) {\r
+ case EbtFloat: tempConstArray[i].fConst = unionArray[i].fConst * node->getUnionArrayPointer()->fConst; break;\r
+ case EbtInt: tempConstArray[i].iConst = unionArray[i].iConst * node->getUnionArrayPointer()->iConst; break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"*\"", this->getLine());\r
+ return 0;\r
+ }\r
+ }\r
+ break;\r
+ case EOpSub:\r
+ tempConstArray = new constUnion[this->getSize()];\r
+ for (i = 0; i < this->getSize(); i++) {\r
+ switch (this->getType().getBasicType()) {\r
+ case EbtFloat: \r
+ if (leftOperand)\r
+ tempConstArray[i].fConst = unionArray[i].fConst - node->getUnionArrayPointer()->fConst; \r
+ else\r
+ tempConstArray[i].fConst = node->getUnionArrayPointer()->fConst - unionArray[i].fConst; \r
+ break;\r
+\r
+ case EbtInt: \r
+ if (leftOperand) \r
+ tempConstArray[i].iConst = unionArray[i].iConst - node->getUnionArrayPointer()->iConst; \r
+ else\r
+ tempConstArray[i].iConst = node->getUnionArrayPointer()->iConst - unionArray[i].iConst; \r
+ break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"-\"", this->getLine());\r
+ return 0;\r
+ }\r
+ }\r
+ break;\r
+\r
+ case EOpDiv:\r
+ tempConstArray = new constUnion[this->getSize()];\r
+ for (i = 0; i < this->getSize(); i++) {\r
+ switch (this->getType().getBasicType()) {\r
+ case EbtFloat: \r
+ if (leftOperand) {\r
+ if (node->getUnionArrayPointer()->fConst == 0.0) {\r
+ infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", this->getLine());\r
+ tempConstArray[i].fConst = FLT_MAX;\r
+ } else\r
+ tempConstArray[i].fConst = unionArray[i].fConst / node->getUnionArrayPointer()->fConst; \r
+ } else {\r
+ if (unionArray[i].fConst == 0.0) {\r
+ infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", this->getLine());\r
+ tempConstArray[i].fConst = FLT_MAX;\r
+ } else\r
+ tempConstArray[i].fConst = node->getUnionArrayPointer()->fConst / unionArray[i].fConst; \r
+ }\r
+ break;\r
+\r
+ case EbtInt: \r
+ if (leftOperand) {\r
+ if (node->getUnionArrayPointer()->iConst == 0) {\r
+ infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", this->getLine());\r
+ tempConstArray[i].iConst = INT_MAX;\r
+ } else\r
+ tempConstArray[i].iConst = unionArray[i].iConst / node->getUnionArrayPointer()->iConst; \r
+ } else {\r
+ if (unionArray[i].iConst == 0) {\r
+ infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", this->getLine());\r
+ tempConstArray[i].iConst = INT_MAX;\r
+ } else\r
+ tempConstArray[i].iConst = node->getUnionArrayPointer()->iConst / unionArray[i].iConst; \r
+ }\r
+ break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"/\"", this->getLine());\r
+ return 0;\r
+ }\r
+ }\r
+ break;\r
+\r
+ case EOpLogicalAnd: // this code is written for possible future use, will not get executed currently\r
+ tempConstArray = new constUnion[this->getSize()];\r
+ for (i = 0; i < this->getSize(); i++) {\r
+ switch (this->getType().getBasicType()) {\r
+ case EbtBool: tempConstArray[i].bConst = unionArray[i].bConst && node->getUnionArrayPointer()->bConst; break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"&&\"", this->getLine());\r
+ return 0;\r
+ }\r
+ }\r
+ break;\r
+ \r
+ case EOpLogicalXor: // this code is written for possible future use, will not get executed currently\r
+ tempConstArray = new constUnion[this->getSize()];\r
+ for (i = 0; i < this->getSize(); i++) {\r
+ switch (this->getType().getBasicType()) {\r
+ case EbtBool: tempConstArray[i].bConst = unionArray[i].bConst ^ node->getUnionArrayPointer()->bConst; break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"^^\"", this->getLine());\r
+ return 0;\r
+ }\r
+ }\r
+ break;\r
+\r
+ case EOpLogicalOr: // this code is written for possible future use, will not get executed currently\r
+ tempConstArray = new constUnion[this->getSize()];\r
+ for (i = 0; i < this->getSize(); i++) {\r
+ switch (this->getType().getBasicType()) {\r
+ case EbtBool: tempConstArray[i].bConst = unionArray[i].bConst || node->getUnionArrayPointer()->bConst; break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"||\"", this->getLine());\r
+ return 0;\r
+ }\r
+ }\r
+ break;\r
+\r
+ default:\r
+ infoSink.info.message(EPrefixInternalError, "Invalid operator for constant folding", this->getLine());\r
+ return 0;\r
+ }\r
+ newNode = new TIntermConstantUnion(tempConstArray, this->getType());\r
+ newNode->setLine(this->getLine());\r
+ \r
+ return newNode;\r
+ } else if (constantNode->getAsConstantUnion() && (this->getSize() > 1 || this->getType().getBasicType() == EbtStruct)) {\r
+ TIntermConstantUnion *node = constantNode->getAsConstantUnion();\r
+ constUnion *rightUnionArray = node->getUnionArrayPointer(); \r
+ constUnion* tempConstArray = 0;\r
+ TIntermConstantUnion *tempNode;\r
+ int index = 0;\r
+ bool boolNodeFlag = false;\r
+ int i;\r
+ switch(op) {\r
+ case EOpAdd: \r
+ tempConstArray = new constUnion[this->getSize()];\r
+ for (i = 0; i < this->getSize(); i++) { \r
+ switch (this->getType().getBasicType()) {\r
+ case EbtFloat: tempConstArray[i].fConst = unionArray[i].fConst + rightUnionArray[i].fConst; break;\r
+ case EbtInt: tempConstArray[i].iConst = unionArray[i].iConst + rightUnionArray[i].iConst; break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"+\"", this->getLine());\r
+ return 0;\r
+ }\r
+ }\r
+ break;\r
+ case EOpSub: \r
+ tempConstArray = new constUnion[this->getSize()];\r
+ for (i = 0; i < this->getSize(); i++) { \r
+ switch (this->getType().getBasicType()) { \r
+ case EbtFloat: \r
+ if (leftOperand)\r
+ tempConstArray[i].fConst = unionArray[i].fConst - rightUnionArray[i].fConst; \r
+ else\r
+ tempConstArray[i].fConst = rightUnionArray[i].fConst - unionArray[i].fConst; \r
+ break;\r
+\r
+ case EbtInt: \r
+ if (leftOperand) \r
+ tempConstArray[i].iConst = unionArray[i].iConst - rightUnionArray[i].iConst;\r
+ else\r
+ tempConstArray[i].iConst = rightUnionArray[i].iConst - unionArray[i].iConst; \r
+ break;\r
+ \r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"-\"", this->getLine());\r
+ return 0;\r
+ }\r
+ }\r
+ break;\r
+ case EOpMul: \r
+ {\r
+ if (this->isVector()) { // two vectors multiplied together\r
+ int size = this->getSize();\r
+ tempConstArray = new constUnion[size];\r
+ \r
+ for (int i = 0; i < size; i++) { \r
+ switch (this->getType().getBasicType()) {\r
+ case EbtFloat: tempConstArray[i].fConst = unionArray[i].fConst * rightUnionArray[i].fConst; break;\r
+ case EbtInt: tempConstArray[i].iConst = unionArray[i].iConst * rightUnionArray[i].iConst; break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for vector multiply", this->getLine());\r
+ return 0;\r
+ }\r
+ }\r
+ } \r
+ }\r
+ break;\r
+ case EOpMatrixTimesMatrix: \r
+ {\r
+ if (this->getType().getBasicType() != EbtFloat || node->getBasicType() != EbtFloat) {\r
+ infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for matrix multiply", this->getLine());\r
+ return 0;\r
+ }\r
+ int size = this->getNominalSize();\r
+ tempConstArray = new constUnion[size*size];\r
+ for (int row = 0; row < size; row++) {\r
+ for (int column = 0; column < size; column++) {\r
+ tempConstArray[size * column + row].fConst = 0.0;\r
+ for (int i = 0; i < size; i++) {\r
+ tempConstArray[size * column + row].fConst += unionArray[i * size + row].fConst * (rightUnionArray[column * size + i].fConst); \r
+ }\r
+ }\r
+ }\r
+ }\r
+ break;\r
+ case EOpDiv: \r
+ tempConstArray = new constUnion[this->getSize()];\r
+ for (i = 0; i < this->getSize(); i++) { \r
+ switch (this->getType().getBasicType()) {\r
+ case EbtFloat: \r
+ if (leftOperand) {\r
+ if (rightUnionArray[i].fConst == 0.0) {\r
+ infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", this->getLine());\r
+ tempConstArray[i].fConst = FLT_MAX;\r
+ } else\r
+ tempConstArray[i].fConst = unionArray[i].fConst / rightUnionArray[i].fConst; \r
+ } else {\r
+ if (unionArray[i].fConst == 0.0) {\r
+ infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", this->getLine());\r
+ tempConstArray[i].fConst = FLT_MAX;\r
+ } else\r
+ tempConstArray[i].fConst = rightUnionArray[i].fConst / unionArray[i].fConst; \r
+ }\r
+ break;\r
+\r
+ case EbtInt: \r
+ if (leftOperand) {\r
+ if (rightUnionArray[i].iConst == 0) {\r
+ infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", this->getLine());\r
+ tempConstArray[i].iConst = INT_MAX;\r
+ } else\r
+ tempConstArray[i].iConst = unionArray[i].iConst / rightUnionArray[i].iConst; \r
+ } else {\r
+ if (unionArray[i].iConst == 0) {\r
+ infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", this->getLine());\r
+ tempConstArray[i].iConst = INT_MAX;\r
+ } else\r
+ tempConstArray[i].iConst = rightUnionArray[i].iConst / unionArray[i].iConst; \r
+ }\r
+ break; \r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"/\"", this->getLine());\r
+ return 0;\r
+ }\r
+ }\r
+ break;\r
+\r
+ case EOpMatrixTimesVector: \r
+ if (node->getBasicType() != EbtFloat) {\r
+ infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for matrix times vector", this->getLine());\r
+ return 0;\r
+ } \r
+ tempConstArray = new constUnion[this->getNominalSize()];\r
+ {\r
+ for (int size = this->getNominalSize(), i = 0; i < size; i++) {\r
+ tempConstArray[i].fConst = 0.0;\r
+ for (int j = 0; j < size; j++) {\r
+ tempConstArray[i].fConst += ((unionArray[j*size + i].fConst) * rightUnionArray[j].fConst); \r
+ }\r
+ }\r
+ }\r
+ \r
+ tempNode = new TIntermConstantUnion(tempConstArray, node->getType());\r
+ tempNode->setLine(this->getLine());\r
+\r
+ return tempNode; \r
+ \r
+ case EOpVectorTimesMatrix:\r
+ if (this->getType().getBasicType() != EbtFloat) {\r
+ infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for vector times matrix", this->getLine());\r
+ return 0;\r
+ } \r
+\r
+ tempConstArray = new constUnion[this->getNominalSize()];\r
+ {\r
+ for (int size = this->getNominalSize(), i = 0; i < size; i++) {\r
+ tempConstArray[i].fConst = 0.0;\r
+ for (int j = 0; j < size; j++) {\r
+ tempConstArray[i].fConst += ((unionArray[j].fConst) * rightUnionArray[i*size + j].fConst); \r
+ }\r
+ }\r
+ }\r
+ break;\r
+\r
+ case EOpLogicalAnd: // this code is written for possible future use, will not get executed currently\r
+ tempConstArray = new constUnion[this->getSize()];\r
+ for (i = 0; i < this->getSize(); i++) { \r
+ switch (this->getType().getBasicType()) {\r
+ case EbtBool: tempConstArray[i].bConst = unionArray[i].bConst && rightUnionArray[i].bConst; break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"&&\"", this->getLine());\r
+ return 0;\r
+ }\r
+ }\r
+ break;\r
+\r
+ case EOpLogicalXor: // this code is written for possible future use, will not get executed currently\r
+ tempConstArray = new constUnion[this->getSize()];\r
+ for (i = 0; i < this->getSize(); i++) { \r
+ switch (this->getType().getBasicType()) {\r
+ case EbtBool: tempConstArray[i].bConst = unionArray[i].bConst ^ rightUnionArray[i].bConst; break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"^^\"", this->getLine());\r
+ return 0;\r
+ }\r
+ }\r
+ break;\r
+\r
+ case EOpLogicalOr: // this code is written for possible future use, will not get executed currently\r
+ tempConstArray = new constUnion[this->getSize()];\r
+ for (i = 0; i < this->getSize(); i++) { \r
+ switch (this->getType().getBasicType()) {\r
+ case EbtBool: tempConstArray[i].bConst = unionArray[i].bConst || rightUnionArray[i].bConst; break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"||\"", this->getLine());\r
+ return 0;\r
+ }\r
+ }\r
+ break;\r
+\r
+ case EOpEqual: \r
+ \r
+ switch (this->getType().getBasicType()) {\r
+ case EbtFloat: \r
+ for (i = 0; i < this->getSize(); i++) { \r
+ if (unionArray[i].fConst != rightUnionArray[i].fConst) {\r
+ boolNodeFlag = true;\r
+ break; // break out of for loop\r
+ }\r
+ }\r
+ break;\r
+\r
+ case EbtInt: \r
+ for (i = 0; i < this->getSize(); i++) { \r
+ if (unionArray[i].iConst != rightUnionArray[i].iConst) {\r
+ boolNodeFlag = true;\r
+ break; // break out of for loop\r
+ }\r
+ }\r
+ break;\r
+ case EbtBool: \r
+ for (i = 0; i < this->getSize(); i++) { \r
+ if (unionArray[i].bConst != rightUnionArray[i].bConst) {\r
+ boolNodeFlag = true;\r
+ break; // break out of for loop\r
+ }\r
+ }\r
+ break;\r
+ case EbtStruct:\r
+ if (!compareStructure(node->getType(), node->getUnionArrayPointer(), unionArray, index))\r
+ boolNodeFlag = true;\r
+ break;\r
+ \r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"==\"", this->getLine());\r
+ return 0;\r
+ }\r
+\r
+ tempConstArray = new constUnion[1];\r
+ if (!boolNodeFlag) {\r
+ tempConstArray->bConst = true;\r
+ }\r
+ else {\r
+ tempConstArray->bConst = false;\r
+ }\r
+ \r
+ tempNode = new TIntermConstantUnion(tempConstArray, TType(EbtBool, EvqConst));\r
+ tempNode->setLine(this->getLine());\r
+ \r
+ return tempNode; \r
+\r
+ case EOpNotEqual: \r
+ switch (this->getType().getBasicType()) {\r
+ case EbtFloat: \r
+ for (i = 0; i < this->getSize(); i++) { \r
+ if (unionArray[i].fConst == rightUnionArray[i].fConst) {\r
+ boolNodeFlag = true;\r
+ break; // break out of for loop\r
+ }\r
+ }\r
+ break;\r
+\r
+ case EbtInt: \r
+ for (i = 0; i < this->getSize(); i++) { \r
+ if (unionArray[i].iConst == rightUnionArray[i].iConst) {\r
+ boolNodeFlag = true;\r
+ break; // break out of for loop\r
+ }\r
+ }\r
+ break;\r
+ case EbtBool: \r
+ for (i = 0; i < this->getSize(); i++) { \r
+ if (unionArray[i].bConst == rightUnionArray[i].bConst) {\r
+ boolNodeFlag = true;\r
+ break; // break out of for loop\r
+ }\r
+ }\r
+ break;\r
+ case EbtStruct:\r
+ if (compareStructure(node->getType(), node->getUnionArrayPointer(), unionArray, index))\r
+ boolNodeFlag = true;\r
+ break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"!=\"", this->getLine());\r
+ return 0;\r
+ }\r
+\r
+ tempConstArray = new constUnion[1];\r
+ if (!boolNodeFlag) {\r
+ tempConstArray->bConst = true;\r
+ }\r
+ else {\r
+ tempConstArray->bConst = false;\r
+ }\r
+ \r
+ tempNode = new TIntermConstantUnion(tempConstArray, TType(EbtBool, EvqConst));\r
+ tempNode->setLine(this->getLine());\r
+ \r
+ return tempNode; \r
+ \r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Invalid operator for constant folding", this->getLine());\r
+ return 0;\r
+ }\r
+ tempNode = new TIntermConstantUnion(tempConstArray, this->getType());\r
+ tempNode->setLine(this->getLine());\r
+\r
+ return tempNode; \r
+ } else if (this->getSize() == 1 && this->getType().getBasicType() != EbtStruct \r
+ && constantNode->getSize() == 1 && constantNode->getType().getBasicType() != EbtStruct ) { // scalar constant folding\r
+ constUnion *unionArray = new constUnion[1];\r
+ TIntermConstantUnion* newNode = 0;\r
+\r
+ switch (this->getType().getBasicType()) {\r
+ case EbtInt:\r
+ {\r
+ //\r
+ // Dealing with two operands, us and constant.\r
+ //\r
+ // Do Binary operations.\r
+ //\r
+ int rightValue = constantNode->getAsConstantUnion()->getUnionArrayPointer()->iConst;\r
+ int leftValue = this->getUnionArrayPointer()->iConst;\r
+ int line = this->getLine();\r
+\r
+ switch(op) {\r
+ //?? add constant intrinsics\r
+ case EOpAdd: unionArray->iConst = leftValue + rightValue; break;\r
+ case EOpSub: unionArray->iConst = leftValue - rightValue; break;\r
+ case EOpMul: unionArray->iConst = leftValue * rightValue; break;\r
+ case EOpDiv: \r
+ if (rightValue == 0) {\r
+ infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", this->getLine());\r
+ unionArray->iConst = INT_MAX;\r
+ } else\r
+ unionArray->iConst = leftValue / rightValue; break;\r
+ \r
+ case EOpMod: unionArray->iConst = leftValue % rightValue; break;\r
+ \r
+ case EOpRightShift: unionArray->iConst = leftValue >> rightValue; break;\r
+ case EOpLeftShift: unionArray->iConst = leftValue << rightValue; break;\r
+ \r
+ case EOpAnd: unionArray->iConst = leftValue & rightValue; break;\r
+ case EOpInclusiveOr: unionArray->iConst = leftValue | rightValue; break;\r
+ case EOpExclusiveOr: unionArray->iConst = leftValue ^ rightValue; break;\r
+\r
+ // the following assume it's okay to have memory leaks\r
+ case EOpEqual: \r
+ unionArray->bConst = leftValue == rightValue;\r
+ newNode = new TIntermConstantUnion(unionArray, TType(EbtBool, EvqConst)); \r
+ break;\r
+ case EOpNotEqual: \r
+ unionArray->bConst = leftValue != rightValue;\r
+ newNode = new TIntermConstantUnion(unionArray, TType(EbtBool, EvqConst)); \r
+ break;\r
+ case EOpLessThan: \r
+ unionArray->bConst = leftValue < rightValue;\r
+ newNode = new TIntermConstantUnion(unionArray, TType(EbtBool, EvqConst)); \r
+ break;\r
+ case EOpGreaterThan: \r
+ unionArray->bConst = leftValue > rightValue;\r
+ newNode = new TIntermConstantUnion(unionArray, TType(EbtBool, EvqConst)); \r
+ break;\r
+ case EOpLessThanEqual: \r
+ unionArray->bConst = leftValue <= rightValue;\r
+ newNode = new TIntermConstantUnion(unionArray, TType(EbtBool, EvqConst)); \r
+ break;\r
+ case EOpGreaterThanEqual: \r
+ unionArray->bConst = leftValue >= rightValue;\r
+ newNode = new TIntermConstantUnion(unionArray, TType(EbtBool, EvqConst)); \r
+ break;\r
+\r
+ default:\r
+ //infoSink.info.message(EPrefixInternalError, "Binary operation not folded into constant int", line);\r
+ return 0;\r
+ }\r
+ if (!newNode) {\r
+ newNode = new TIntermConstantUnion(unionArray, TType(EbtInt, EvqConst)); \r
+ }\r
+ newNode->setLine(constantNode->getLine());\r
+ return newNode;\r
+ }\r
+ case EbtFloat:\r
+ {\r
+ float rightValue = constantNode->getAsConstantUnion()->getUnionArrayPointer()->fConst;\r
+ float leftValue = this->getUnionArrayPointer()->fConst;\r
+\r
+ switch(op) {\r
+ //?? add constant intrinsics\r
+ case EOpAdd: unionArray->fConst = leftValue + rightValue; break;\r
+ case EOpSub: unionArray->fConst = leftValue - rightValue; break;\r
+ case EOpMul: unionArray->fConst = leftValue * rightValue; break;\r
+ case EOpDiv: \r
+ if (rightValue == 0.0) {\r
+ infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", this->getLine());\r
+ unionArray->fConst = FLT_MAX;\r
+ } else\r
+ unionArray->fConst = leftValue / rightValue; break;\r
+\r
+ // the following assume it's okay to have memory leaks (cleaned up by pool allocator)\r
+ case EOpEqual: \r
+ unionArray->bConst = leftValue == rightValue;\r
+ newNode = new TIntermConstantUnion(unionArray, TType(EbtBool, EvqConst)); \r
+ break;\r
+ case EOpNotEqual: \r
+ unionArray->bConst = leftValue != rightValue;\r
+ newNode = new TIntermConstantUnion(unionArray, TType(EbtBool, EvqConst)); \r
+ break;\r
+ case EOpLessThan: \r
+ unionArray->bConst = leftValue < rightValue;\r
+ newNode = new TIntermConstantUnion(unionArray, TType(EbtBool, EvqConst)); \r
+ break;\r
+ case EOpGreaterThan: \r
+ unionArray->bConst = leftValue > rightValue;\r
+ newNode = new TIntermConstantUnion(unionArray, TType(EbtBool, EvqConst)); \r
+ break;\r
+ case EOpLessThanEqual: \r
+ unionArray->bConst = leftValue <= rightValue;\r
+ newNode = new TIntermConstantUnion(unionArray, TType(EbtBool, EvqConst)); \r
+ break;\r
+ case EOpGreaterThanEqual: \r
+ unionArray->bConst = leftValue >= rightValue;\r
+ newNode = new TIntermConstantUnion(unionArray, TType(EbtBool, EvqConst)); \r
+ break;\r
+\r
+ default: \r
+ //infoSink.info.message(EPrefixInternalError, "Binary operation not folded into constant float", line);\r
+ return 0;\r
+ }\r
+ if (!newNode) {\r
+ newNode = new TIntermConstantUnion(unionArray, TType(EbtFloat, EvqConst)); \r
+ }\r
+ newNode->setLine(constantNode->getLine());\r
+ return newNode;\r
+ }\r
+ case EbtBool:\r
+ {\r
+ bool rightValue = constantNode->getAsConstantUnion()->getUnionArrayPointer()->bConst;\r
+ bool leftValue = this->getUnionArrayPointer()->bConst;\r
+\r
+ switch(op) {\r
+ //?? add constant intrinsics\r
+ case EOpLogicalAnd: unionArray->bConst = leftValue & rightValue; break;\r
+ case EOpLogicalXor: unionArray->bConst = leftValue ^ rightValue; break;\r
+ case EOpLogicalOr: unionArray->bConst = leftValue | rightValue; break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Binary operator cannot be folded into constant bool", line);\r
+ return 0;\r
+ }\r
+ newNode = new TIntermConstantUnion(unionArray, TType(EbtBool, EvqConst)); \r
+ newNode->setLine(constantNode->getLine());\r
+ return newNode;\r
+ }\r
+ default:\r
+ infoSink.info.message(EPrefixInternalError, "Cannot fold constant", this->getLine());\r
+ return 0;\r
+ }\r
+ }\r
+ } else { \r
+ //\r
+ // Do unary operations\r
+ //\r
+ TIntermConstantUnion *newNode = 0;\r
+ constUnion* tempConstArray = new constUnion[this->getSize()];\r
+ if (this->getSize() > 1) {\r
+ for (int i = 0; i < this->getSize(); i++) {\r
+ switch(op) {\r
+ case EOpNegative: \r
+ switch (this->getType().getBasicType()) {\r
+ case EbtFloat: tempConstArray[i].fConst = -(unionArray[i].fConst); break;\r
+ case EbtInt: tempConstArray[i].iConst = -(unionArray[i].iConst); break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Unary operation not folded into constant", this->getLine());\r
+ return 0;\r
+ }\r
+ break;\r
+ case EOpLogicalNot: // this code is written for possible future use, will not get executed currently \r
+ switch (this->getType().getBasicType()) {\r
+ case EbtBool: tempConstArray[i].bConst = !(unionArray[i].bConst); break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Unary operation not folded into constant", this->getLine());\r
+ return 0;\r
+ }\r
+ break;\r
+ default: \r
+ return 0;\r
+ }\r
+ }\r
+ newNode = new TIntermConstantUnion(tempConstArray, this->getType());\r
+ newNode->setLine(this->getLine());\r
+ return newNode; \r
+ } else {\r
+ switch(op) {\r
+ //?? add constant intrinsics\r
+ case EOpNegative: \r
+ switch (this->getType().getBasicType()) {\r
+ case EbtInt:\r
+ tempConstArray->iConst = -(this->getUnionArrayPointer()->iConst);\r
+ newNode = new TIntermConstantUnion(tempConstArray, TType(EbtInt, EvqConst));\r
+ break;\r
+ case EbtFloat:\r
+ tempConstArray->fConst = -(this->getUnionArrayPointer()->fConst);\r
+ newNode = new TIntermConstantUnion(tempConstArray, TType(EbtFloat, EvqConst));\r
+ break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Unary operation not folded into constant", line);\r
+ return 0;\r
+ }\r
+ break;\r
+ case EOpLogicalNot: \r
+ switch (this->getType().getBasicType()) {\r
+ case EbtBool:\r
+ tempConstArray->bConst = !this->getUnionArrayPointer()->bConst;\r
+ newNode = new TIntermConstantUnion(tempConstArray, TType(EbtBool, EvqConst));\r
+ break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Unary operation not folded into constant", line);\r
+ return 0;\r
+ }\r
+ break;\r
+ default: \r
+ return 0;\r
+ }\r
+ newNode->setLine(this->getLine());\r
+ return newNode;\r
+ \r
+ }\r
+ }\r
+\r
+ return this;\r
+}\r
+\r
+TIntermConstantUnion* TIntermediate::changeAggrToTempConst(TIntermAggregate* node, TSymbolTable& symbolTable, TSourceLoc line) \r
+{\r
+ constUnion* unionArray = new constUnion[node->getType().getInstanceSize()]; \r
+ bool returnVal;\r
+\r
+ if (node->getSequence().size() == 1 && node->getSequence()[0]->getAsTyped()->getAsConstantUnion()) {\r
+ returnVal = parseConstTree(line, node, unionArray, node->getOp(), symbolTable, node->getType(), true);\r
+ }\r
+ else {\r
+ returnVal = parseConstTree(line, node, unionArray, node->getOp(), symbolTable, node->getType());\r
+ }\r
+\r
+ if (returnVal)\r
+ unionArray = 0;\r
+\r
+ return (addConstantUnion(unionArray, node->getType(), node->getLine())); \r
+}\r
+\r
+TIntermTyped* TIntermediate::copyConstUnion(TIntermConstantUnion* node) \r
+{\r
+ constUnion *unionArray = node->getUnionArrayPointer();\r
+\r
+ if (!unionArray)\r
+ return 0;\r
+ \r
+ int size;\r
+ if (node->getType().getBasicType() == EbtStruct)\r
+ //?? We should actually be calling getStructSize() function and not setStructSize. This problem occurs in case\r
+ // of nested/embedded structs.\r
+ size = node->getType().setStructSize(node->getType().getStruct());\r
+ //size = node->getType().getStructSize();\r
+ else\r
+ size = node->getType().getInstanceSize();\r
+ \r
+ constUnion *newSpace = new constUnion[size];\r
+\r
+ for (int i = 0; i < size; i++)\r
+ newSpace[i] = unionArray[i];\r
+\r
+ node->setUnionArrayPointer(newSpace);\r
+ return node;\r
+}\r
+\r
+TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermConstantUnion* node) \r
+{\r
+ constUnion *rightUnionArray = node->getUnionArrayPointer();\r
+ int size = node->getType().getInstanceSize();\r
+\r
+ constUnion *leftUnionArray = new constUnion[size];\r
+\r
+ for (int i=0; i < size; i++) {\r
+ \r
+ switch (promoteTo) {\r
+ case EbtFloat:\r
+ switch (node->getType().getBasicType()) {\r
+ case EbtInt:\r
+ (leftUnionArray[i]).fConst = static_cast<float>(rightUnionArray[i].iConst);\r
+ break;\r
+ case EbtBool:\r
+ (leftUnionArray[i]).fConst = static_cast<float>(rightUnionArray[i].bConst);\r
+ break;\r
+ case EbtFloat:\r
+ (leftUnionArray[i]).fConst = rightUnionArray[i].fConst;\r
+ break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Cannot promote", node->getLine());\r
+ return 0;\r
+ } \r
+ break;\r
+ case EbtInt:\r
+ switch (node->getType().getBasicType()) {\r
+ case EbtInt:\r
+ (leftUnionArray[i]).iConst = rightUnionArray[i].iConst;\r
+ break;\r
+ case EbtBool:\r
+ (leftUnionArray[i]).iConst = static_cast<int>(rightUnionArray[i].bConst);\r
+ break;\r
+ case EbtFloat:\r
+ (leftUnionArray[i]).iConst = static_cast<int>(rightUnionArray[i].fConst);\r
+ break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Cannot promote", node->getLine());\r
+ return 0;\r
+ } \r
+ break;\r
+ case EbtBool:\r
+ switch (node->getType().getBasicType()) {\r
+ case EbtInt:\r
+ (leftUnionArray[i]).bConst = rightUnionArray[i].iConst != 0;\r
+ break;\r
+ case EbtBool:\r
+ (leftUnionArray[i]).bConst = rightUnionArray[i].bConst;\r
+ break;\r
+ case EbtFloat:\r
+ (leftUnionArray[i]).bConst = rightUnionArray[i].fConst != 0.0;\r
+ break;\r
+ default: \r
+ infoSink.info.message(EPrefixInternalError, "Cannot promote", node->getLine());\r
+ return 0;\r
+ } \r
+ \r
+ break;\r
+ default:\r
+ infoSink.info.message(EPrefixInternalError, "Incorrect data type found", node->getLine());\r
+ return 0;\r
+ }\r
+ \r
+ }\r
+ TType t = node->getType();\r
+ \r
+ return addConstantUnion(leftUnionArray, TType(promoteTo, t.getQualifier(), t.getNominalSize(), t.isMatrix(), t.isArray()), node->getLine());\r
+}\r
+\r
+//\r
+// This method inserts the child nodes into the parent node at the given location specified\r
+// by parentNodeIter. offset tells the integer offset into the parent vector that points to \r
+// the child node. sequenceVector is the parent vector.\r
+// Returns reference to the last inserted child node\r
+// increments the offset based on the number of child nodes added\r
+//\r
+void TIntermediate::removeChildNode(TIntermSequence &parentSequence, TType& parentType, int& offset, TIntermSequence::iterator& parentNodeIter, TIntermAggregate* child)\r
+{\r
+ if (!child)\r
+ return;\r
+\r
+ parentNodeIter = parentSequence.begin() + offset;\r
+\r
+ TIntermSequence& childSequence = child->getSequence();\r
+ int oldSize = static_cast<int>(parentSequence.size());\r
+ if (childSequence.size() == 1) {\r
+ if (!removeMatrixConstNode(parentSequence, parentType, child, offset)) {\r
+ for (int i = 0; i < child->getType().getInstanceSize(); i++) {\r
+ constUnion* constantUnion = new constUnion[1];\r
+ *constantUnion = *(childSequence[0]->getAsConstantUnion()->getUnionArrayPointer());\r
+ TIntermConstantUnion *constant = new TIntermConstantUnion(constantUnion,\r
+ childSequence[0]->getAsConstantUnion()->getType());\r
+ constant->setLine(child->getLine());\r
+ parentNodeIter = parentSequence.begin() + offset;\r
+ parentSequence.insert(parentNodeIter, constant);\r
+ }\r
+ }\r
+ } else \r
+ parentSequence.insert(parentNodeIter, childSequence.begin(), childSequence.end());\r
+\r
+ int newSize = static_cast<int>(parentSequence.size());\r
+ offset = offset + newSize - oldSize;\r
+ parentNodeIter = parentSequence.begin() + offset;\r
+ parentNodeIter = parentSequence.erase(parentNodeIter);\r
+ offset--;\r
+ parentNodeIter--;\r
+}\r
+\r
+//\r
+// The parent has only one child node. This method is not implemented\r
+// for parent that is a structure\r
+//\r
+TIntermTyped* TIntermediate::removeChildNode(TIntermTyped* parent, TType* parentType, TIntermAggregate* child)\r
+{\r
+ TIntermTyped* resultNode = 0;\r
+\r
+ if (parentType->getInstanceSize() == 1) {\r
+ resultNode = child->getSequence()[0]->getAsTyped(); \r
+ } else {\r
+ int size = parentType->getInstanceSize();\r
+ TIntermSequence& parentSequence = parent->getAsAggregate()->getSequence();\r
+ TIntermSequence& childSequence = child->getSequence();\r
+\r
+ if (childSequence.size() == 1) {\r
+ if (!removeMatrixConstNode(parentSequence, *parentType, child, 1))\r
+ parentSequence.push_back(child->getSequence()[0]);\r
+ } else {\r
+ for (int i = 0; i < size; i++) {\r
+ parentSequence.push_back(child->getSequence()[i]);\r
+ }\r
+ }\r
+ parentSequence.erase(parentSequence.begin());\r
+\r
+ return parent;\r
+ }\r
+\r
+ return resultNode;\r
+}\r
+\r
+bool TIntermediate::removeMatrixConstNode(TIntermSequence &parentSequence, TType& parentType, TIntermAggregate* child, int offset)\r
+{\r
+ if (!child)\r
+ return false;\r
+\r
+ TIntermSequence::iterator parentNodeIter;\r
+ TIntermSequence &childSequence = child->getSequence();\r
+ int i;\r
+\r
+ switch (child->getOp()) {\r
+ case EOpConstructMat2:\r
+ case EOpConstructMat3:\r
+ case EOpConstructMat4:\r
+ for (i = 0; i < child->getType().getInstanceSize(); i++) {\r
+ constUnion* constantUnion = new constUnion[1];\r
+ if (i % (child->getType().getNominalSize() + 1) == 0) {\r
+ *constantUnion = *(childSequence[0]->getAsConstantUnion()->getUnionArrayPointer());\r
+ } else {\r
+ switch (parentType.getBasicType()) {\r
+ case EbtInt: constantUnion->iConst = 0; break;\r
+ case EbtFloat: constantUnion->fConst = 0.0; break;\r
+ case EbtBool: constantUnion->bConst = false; break;\r
+ }\r
+ }\r
+ TIntermConstantUnion *constant = new TIntermConstantUnion(constantUnion,\r
+ childSequence[0]->getAsConstantUnion()->getType());\r
+ constant->setLine(child->getLine());\r
+ parentNodeIter = parentSequence.begin() + offset + i;\r
+ parentSequence.insert(parentNodeIter, constant);\r
+ }\r
+ return true;\r
+ default:\r
+ return false;\r
+ }\r
+}\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#ifndef _MMAP_INCLUDED_\r
+#define _MMAP_INCLUDED_\r
+\r
+//\r
+// Encapsulate memory mapped files\r
+//\r
+\r
+class TMMap {\r
+public:\r
+ TMMap(const char* fileName) : \r
+ fSize(-1), // -1 is the error value returned by GetFileSize()\r
+ fp(NULL),\r
+ fBuff(0) // 0 is the error value returned by MapViewOfFile()\r
+ {\r
+ if ((fp = fopen(fileName, "r")) == NULL)\r
+ return;\r
+ char c = getc(fp);\r
+ fSize = 0;\r
+ while (c != EOF) {\r
+ fSize++;\r
+ c = getc(fp);\r
+ }\r
+ if (c == EOF)\r
+ fSize++;\r
+ rewind(fp);\r
+ fBuff = (char*)malloc(sizeof(char) * fSize);\r
+ int count = 0;\r
+ c = getc(fp);\r
+ while (c != EOF) {\r
+ fBuff[count++] = c;\r
+ c = getc(fp);\r
+ }\r
+ fBuff[count++] = c;\r
+ }\r
+\r
+ char* getData() { return fBuff; }\r
+ int getSize() { return fSize; }\r
+\r
+ ~TMMap() {\r
+ if (fp != NULL)\r
+ fclose(fp);\r
+ }\r
+ \r
+private:\r
+ int fSize; // size of file to map in\r
+ FILE *fp;\r
+ char* fBuff; // the actual data;\r
+};\r
+\r
+#endif // _MMAP_INCLUDED_\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#include "ParseHelper.h"\r
+#include "Include/InitializeParseContext.h"\r
+#include "osinclude.h"\r
+#include <stdarg.h>\r
+///////////////////////////////////////////////////////////////////////\r
+//\r
+// Sub- vector and matrix fields\r
+//\r
+////////////////////////////////////////////////////////////////////////\r
+\r
+//\r
+// Look at a '.' field selector string and change it into offsets\r
+// for a vector.\r
+//\r
+bool TParseContext::parseVectorFields(const TString& compString, int vecSize, TVectorFields& fields, int line)\r
+{\r
+ fields.num = (int) compString.size();\r
+ if (fields.num > 4) {\r
+ error(line, "illegal vector field selection", compString.c_str(), "");\r
+ return false;\r
+ }\r
+\r
+ bool tooBig = false;\r
+\r
+ for (int i = 0; i < fields.num; ++i) {\r
+ switch (compString[i]) {\r
+ case 'x': case 'r': case 's': case '0':\r
+ fields.offsets[i] = 0;\r
+ break;\r
+ case 'y': case 'g': case 't': case '1':\r
+ fields.offsets[i] = 1;\r
+ break;\r
+ case 'z': case 'b': case 'p': case '2':\r
+ if (vecSize < 3)\r
+ tooBig = true;\r
+ fields.offsets[i] = 2;\r
+ break;\r
+ case 'w': case 'a': case 'q': case '3':\r
+ if (vecSize < 4)\r
+ tooBig = true;\r
+ fields.offsets[i] = 3;\r
+ break;\r
+ default:\r
+ error(line, "illegal vector field selection", compString.c_str(), "");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ if (tooBig) {\r
+ error(line, "vector field selection out of range", compString.c_str(), "");\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+\r
+//\r
+// Look at a '.' field selector string and change it into offsets\r
+// for a matrix.\r
+//\r
+bool TParseContext::parseMatrixFields(const TString& compString, int matSize, TMatrixFields& fields, int line)\r
+{\r
+ fields.wholeRow = false;\r
+ fields.wholeCol = false;\r
+ fields.row = -1;\r
+ fields.col = -1;\r
+\r
+ if (compString.size() != 2) {\r
+ error(line, "illegal length of matrix field selection", compString.c_str(), "");\r
+ return false;\r
+ }\r
+\r
+ if (compString[0] == '_') {\r
+ if (compString[1] < '0' || compString[1] > '3') {\r
+ error(line, "illegal matrix field selection", compString.c_str(), "");\r
+ return false;\r
+ }\r
+ fields.wholeCol = true;\r
+ fields.col = compString[1] - '0';\r
+ } else if (compString[1] == '_') {\r
+ if (compString[0] < '0' || compString[0] > '3') {\r
+ error(line, "illegal matrix field selection", compString.c_str(), "");\r
+ return false;\r
+ }\r
+ fields.wholeRow = true;\r
+ fields.row = compString[0] - '0';\r
+ } else {\r
+ if (compString[0] < '0' || compString[0] > '3' ||\r
+ compString[1] < '0' || compString[1] > '3') {\r
+ error(line, "illegal matrix field selection", compString.c_str(), "");\r
+ return false;\r
+ }\r
+ fields.row = compString[0] - '0';\r
+ fields.col = compString[1] - '0';\r
+ }\r
+\r
+ if (fields.row >= matSize || fields.col >= matSize) {\r
+ error(line, "matrix field selection out of range", compString.c_str(), "");\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////\r
+//\r
+// Errors\r
+//\r
+////////////////////////////////////////////////////////////////////////\r
+\r
+//\r
+// Track whether errors have occurred.\r
+//\r
+void TParseContext::recover()\r
+{\r
+ recoveredFromError = true;\r
+}\r
+\r
+//\r
+// Used by flex/bison to output all syntax and parsing errors.\r
+//\r
+void C_DECL TParseContext::error(TSourceLoc nLine, const char *szReason, const char *szToken, \r
+ const char *szExtraInfoFormat, ...)\r
+{\r
+ char szExtraInfo[400];\r
+ va_list marker;\r
+ \r
+ va_start(marker, szExtraInfoFormat);\r
+ \r
+ _vsnprintf(szExtraInfo, sizeof(szExtraInfo), szExtraInfoFormat, marker);\r
+ \r
+ /* VC++ format: file(linenum) : error #: 'token' : extrainfo */\r
+ infoSink.info.prefix(EPrefixError);\r
+ infoSink.info.location(nLine);\r
+ infoSink.info << "'" << szToken << "' : " << szReason << " " << szExtraInfo << "\n";\r
+ \r
+ va_end(marker);\r
+\r
+ ++numErrors;\r
+}\r
+\r
+//\r
+// Same error message for all places assignments don't work.\r
+//\r
+void TParseContext::assignError(int line, const char* op, TString left, TString right)\r
+{\r
+ error(line, "", op, "cannot convert from '%s' to '%s'",\r
+ right.c_str(), left.c_str());\r
+}\r
+\r
+//\r
+// Same error message for all places unary operations don't work.\r
+//\r
+void TParseContext::unaryOpError(int line, char* op, TString operand)\r
+{\r
+ error(line, " wrong operand type", op, \r
+ "no operation '%s' exists that takes an operand of type %s (or there is no acceptable conversion)",\r
+ op, operand.c_str());\r
+}\r
+\r
+//\r
+// Same error message for all binary operations don't work.\r
+//\r
+void TParseContext::binaryOpError(int line, char* op, TString left, TString right)\r
+{\r
+ error(line, " wrong operand types ", op, \r
+ "no operation '%s' exists that takes a left-hand operand of type '%s' and "\r
+ "a right operand of type '%s' (or there is no acceptable conversion)", \r
+ op, left.c_str(), right.c_str());\r
+}\r
+\r
+//\r
+// Both test and if necessary, spit out an error, to see if the node is really\r
+// an l-value that can be operated on this way.\r
+//\r
+// Returns true if the was an error.\r
+//\r
+bool TParseContext::lValueErrorCheck(int line, char* op, TIntermTyped* node)\r
+{\r
+ TIntermSymbol* symNode = node->getAsSymbolNode();\r
+ TIntermBinary* binaryNode = node->getAsBinaryNode();\r
+\r
+ if (binaryNode) {\r
+ bool errorReturn;\r
+\r
+ switch(binaryNode->getOp()) {\r
+ case EOpIndexDirect:\r
+ case EOpIndexIndirect:\r
+ case EOpIndexDirectStruct:\r
+ return lValueErrorCheck(line, op, binaryNode->getLeft());\r
+ case EOpVectorSwizzle:\r
+ errorReturn = lValueErrorCheck(line, op, binaryNode->getLeft());\r
+ if (!errorReturn) {\r
+ int offset[4] = {0,0,0,0};\r
+\r
+ TIntermTyped* rightNode = binaryNode->getRight();\r
+ TIntermAggregate *aggrNode = rightNode->getAsAggregate();\r
+ \r
+ for (TIntermSequence::iterator p = aggrNode->getSequence().begin(); \r
+ p != aggrNode->getSequence().end(); p++) {\r
+ int value = (*p)->getAsTyped()->getAsConstantUnion()->getUnionArrayPointer()->iConst;\r
+ offset[value]++; \r
+ if (offset[value] > 1) {\r
+ error(line, " l-value of swizzle cannot have duplicate components", op, "", "");\r
+\r
+ return true;\r
+ }\r
+ }\r
+ } \r
+\r
+ return errorReturn;\r
+ default: \r
+ break;\r
+ }\r
+ error(line, " l-value required", op, "", "");\r
+\r
+ return true;\r
+ }\r
+\r
+\r
+ const char* symbol = 0;\r
+ if (symNode != 0)\r
+ symbol = symNode->getSymbol().c_str();\r
+\r
+ char* message = 0;\r
+ switch (node->getQualifier()) {\r
+ case EvqConst: message = "can't modify a const"; break;\r
+ case EvqConstReadOnly: message = "can't modify a const"; break;\r
+ case EvqAttribute: message = "can't modify an attribute"; break;\r
+ case EvqUniform: message = "can't modify a uniform"; break;\r
+ case EvqVaryingIn: message = "can't modify a varying"; break;\r
+ case EvqInput: message = "can't modify an input"; break;\r
+ case EvqFace: message = "can't modify gl_FrontFace"; break;\r
+ case EvqFragCoord: message = "can't modify gl_FragCoord"; break;\r
+ default:\r
+\r
+ //\r
+ // Type that can't be written to?\r
+ //\r
+ switch (node->getBasicType()) {\r
+ case EbtSampler1D:\r
+ case EbtSampler2D:\r
+ case EbtSampler3D:\r
+ case EbtSamplerCube:\r
+ case EbtSampler1DShadow:\r
+ case EbtSampler2DShadow:\r
+ message = "can't modify a sampler";\r
+ break;\r
+ case EbtVoid:\r
+ message = "can't modify void";\r
+ break;\r
+ default: \r
+ break;\r
+ }\r
+ }\r
+\r
+ if (message == 0 && binaryNode == 0 && symNode == 0) {\r
+ error(line, " l-value required", op, "", "");\r
+\r
+ return true;\r
+ }\r
+\r
+\r
+ //\r
+ // Everything else is okay, no error.\r
+ //\r
+ if (message == 0)\r
+ return false;\r
+\r
+ //\r
+ // If we get here, we have an error and a message.\r
+ //\r
+ if (symNode)\r
+ error(line, " l-value required", op, "\"%s\" (%s)", symbol, message);\r
+ else\r
+ error(line, " l-value required", op, "(%s)", message);\r
+\r
+ return true;\r
+}\r
+\r
+//\r
+// Both test, and if necessary spit out an error, to see if the node is really\r
+// a constant.\r
+//\r
+// Returns true if the was an error.\r
+//\r
+bool TParseContext::constErrorCheck(TIntermTyped* node)\r
+{\r
+ if (node->getQualifier() == EvqConst)\r
+ return false;\r
+\r
+ error(node->getLine(), "constant expression required", "", "");\r
+\r
+ return true;\r
+}\r
+\r
+//\r
+// Both test, and if necessary spit out an error, to see if the node is really\r
+// an integer.\r
+//\r
+// Returns true if the was an error.\r
+//\r
+bool TParseContext::integerErrorCheck(TIntermTyped* node, char* token)\r
+{\r
+ if (node->getBasicType() == EbtInt && node->getNominalSize() == 1)\r
+ return false;\r
+\r
+ error(node->getLine(), "integer expression required", token, "");\r
+\r
+ return true;\r
+}\r
+\r
+//\r
+// Both test, and if necessary spit out an error, to see if we are currently\r
+// globally scoped.\r
+//\r
+// Returns true if the was an error.\r
+//\r
+bool TParseContext::globalErrorCheck(int line, bool global, char* token)\r
+{\r
+ if (global)\r
+ return false;\r
+\r
+ error(line, "only allowed at global scope", token, "");\r
+\r
+ return true;\r
+}\r
+\r
+//\r
+// For now, keep it simple: if it starts "gl_", it's reserved, independent\r
+// of scope. Except, if the symbol table is at the built-in push-level,\r
+// which is when we are parsing built-ins.\r
+//\r
+// Returns true if there was an error.\r
+//\r
+bool TParseContext::reservedErrorCheck(int line, const TString& identifier)\r
+{\r
+ if (symbolTable.atBuiltInLevel() ||\r
+ identifier.substr(0, 3) != TString("gl_"))\r
+ return false;\r
+\r
+ error(line, "reserved built-in name", "gl_", "");\r
+\r
+ return true; \r
+}\r
+\r
+//\r
+// Make sure there is enough data provided to the constructor to build\r
+// something of the type of the constructor. Also returns the type of\r
+// the constructor.\r
+//\r
+// Returns true if there was an error in construction.\r
+//\r
+bool TParseContext::constructorErrorCheck(int line, TIntermNode* node, TFunction& function, TOperator op, TType* type)\r
+{\r
+ switch(op) {\r
+ case EOpConstructInt: *type = TType(EbtInt); break;\r
+ case EOpConstructBool: *type = TType(EbtBool); break;\r
+ case EOpConstructFloat: *type = TType(EbtFloat); break;\r
+ case EOpConstructVec2: *type = TType(EbtFloat, EvqTemporary, 2); break;\r
+ case EOpConstructVec3: *type = TType(EbtFloat, EvqTemporary, 3); break;\r
+ case EOpConstructVec4: *type = TType(EbtFloat, EvqTemporary, 4); break;\r
+ case EOpConstructBVec2: *type = TType(EbtBool, EvqTemporary, 2); break;\r
+ case EOpConstructBVec3: *type = TType(EbtBool, EvqTemporary, 3); break;\r
+ case EOpConstructBVec4: *type = TType(EbtBool, EvqTemporary, 4); break;\r
+ case EOpConstructIVec2: *type = TType(EbtInt, EvqTemporary, 2); break;\r
+ case EOpConstructIVec3: *type = TType(EbtInt, EvqTemporary, 3); break;\r
+ case EOpConstructIVec4: *type = TType(EbtInt, EvqTemporary, 4); break;\r
+ case EOpConstructMat2: *type = TType(EbtFloat, EvqTemporary, 2, true); break;\r
+ case EOpConstructMat3: *type = TType(EbtFloat, EvqTemporary, 3, true); break;\r
+ case EOpConstructMat4: *type = TType(EbtFloat, EvqTemporary, 4, true); break;\r
+ case EOpConstructStruct: *type = TType(function.getReturnType().getStruct(), function.getReturnType().getTypeName()); break;\r
+ default:\r
+ error(line, "expected constructor", "Internal Error", "");\r
+ return true;\r
+ }\r
+\r
+ bool constructingMatrix = false;\r
+ switch(op) {\r
+ case EOpConstructMat2:\r
+ case EOpConstructMat3:\r
+ case EOpConstructMat4:\r
+ constructingMatrix = true;\r
+ break;\r
+ default: \r
+ break;\r
+ }\r
+\r
+ //\r
+ // Note: It's okay to have too many components available, but not okay to have unused\r
+ // arguments. 'full' will go to true when enough args have been seen. If we loop\r
+ // again, there is an extra argument, so 'overfull' will become true.\r
+ //\r
+\r
+ int size = 0;\r
+ bool constType = true;\r
+ bool full = false;\r
+ bool overFull = false;\r
+ bool matrixInMatrix = false;\r
+ for (int i = 0; i < function.getParamCount(); ++i) {\r
+ size += function[i].type->getInstanceSize();\r
+ if (constructingMatrix && function[i].type->isMatrix())\r
+ matrixInMatrix = true;\r
+ if (full)\r
+ overFull = true;\r
+ if (op != EOpConstructStruct && size >= type->getInstanceSize())\r
+ full = true;\r
+ if (function[i].type->getQualifier() != EvqConst)\r
+ constType = false;\r
+ }\r
+ \r
+ if (constType)\r
+ type->changeQualifier(EvqConst);\r
+\r
+ if (matrixInMatrix) {\r
+ error(line, "constructing matrix from matrix", "constructor", "(reserved)");\r
+ return true;\r
+ }\r
+\r
+ if (overFull) {\r
+ error(line, "too many arguments", "constructor", "");\r
+ return true;\r
+ }\r
+\r
+ if (size != 1 && size < type->getInstanceSize() || (size < 1) && op == EOpConstructStruct) {\r
+ error(line, "not enough data provided for construction", "constructor", "");\r
+ return true;\r
+ }\r
+\r
+ TIntermTyped* typed = node->getAsTyped();\r
+ if (typed == 0) {\r
+ error(line, "constructor argument does not have a type", "constructor", "");\r
+ return true;\r
+ }\r
+ if (op != EOpConstructStruct && IsSampler(typed->getBasicType())) {\r
+ error(line, "cannot convert a sampler", "constructor", "");\r
+ return true;\r
+ }\r
+ if (typed->getBasicType() == EbtVoid) {\r
+ error(line, "cannot convert a void", "constructor", "");\r
+ return true;\r
+ }\r
+\r
+ return false;\r
+}\r
+\r
+// This function checks to see if a void variable has been declared and raise an error message for such a case\r
+//\r
+// returns true in case of an error\r
+//\r
+bool TParseContext::voidErrorCheck(int line, const TString& identifier, const TPublicType& pubType)\r
+{\r
+ if (pubType.type == EbtVoid) {\r
+ error(line, "illegal use of type 'void'", identifier.c_str(), "");\r
+ return true;\r
+ } \r
+\r
+ return false;\r
+}\r
+\r
+// This function checks to see if the node (for the expression) contains a scalar boolean expression or not\r
+//\r
+// returns true in case of an error\r
+//\r
+bool TParseContext::boolErrorCheck(int line, const TIntermTyped* type)\r
+{\r
+ if (type->getBasicType() != EbtBool || type->isArray() || type->isMatrix() || type->isVector()) {\r
+ error(line, "boolean expression expected", "", "");\r
+ return true;\r
+ } \r
+\r
+ return false;\r
+}\r
+\r
+// This function checks to see if the node (for the expression) contains a scalar boolean expression or not\r
+//\r
+// returns true in case of an error\r
+//\r
+bool TParseContext::boolErrorCheck(int line, const TPublicType& pType)\r
+{\r
+ if (pType.type != EbtBool || pType.array || pType.matrix || (pType.size > 1)) {\r
+ error(line, "boolean expression expected", "", "");\r
+ return true;\r
+ } \r
+\r
+ return false;\r
+}\r
+\r
+bool TParseContext::samplerErrorCheck(int line, const TPublicType& pType, const char* reason)\r
+{\r
+ if (pType.type == EbtStruct) {\r
+ if (containsSampler(*pType.userDef)) {\r
+ error(line, reason, TType::getBasicString(pType.type), "(structure contains a sampler)");\r
+ \r
+ return true;\r
+ }\r
+ \r
+ return false;\r
+ } else if (IsSampler(pType.type)) {\r
+ error(line, reason, TType::getBasicString(pType.type), "");\r
+\r
+ return true;\r
+ }\r
+\r
+ return false;\r
+}\r
+\r
+bool TParseContext::structQualifierErrorCheck(int line, const TPublicType& pType)\r
+{\r
+ if ((pType.qualifier == EvqVaryingIn || pType.qualifier == EvqVaryingOut || pType.qualifier == EvqAttribute) &&\r
+ pType.type == EbtStruct) {\r
+ error(line, "cannot be used with a structure", getQualifierString(pType.qualifier), "");\r
+ \r
+ return true;\r
+ }\r
+\r
+ if (pType.qualifier != EvqUniform && samplerErrorCheck(line, pType, "samplers must be uniform"))\r
+ return true;\r
+\r
+ return false;\r
+}\r
+\r
+bool TParseContext::parameterSamplerErrorCheck(int line, TQualifier qualifier, const TType& type)\r
+{\r
+ if ((qualifier == EvqOut || qualifier == EvqInOut) && \r
+ type.getBasicType() != EbtStruct && IsSampler(type.getBasicType())) {\r
+ error(line, "samplers cannot be output parameters", type.getBasicString(), "");\r
+ return true;\r
+ }\r
+\r
+ return false;\r
+}\r
+\r
+bool TParseContext::containsSampler(TType& type)\r
+{\r
+ if (IsSampler(type.getBasicType()))\r
+ return true;\r
+\r
+ if (type.getBasicType() == EbtStruct) {\r
+ TTypeList& structure = *type.getStruct();\r
+ for (unsigned int i = 0; i < structure.size(); ++i) {\r
+ if (containsSampler(*structure[i].type))\r
+ return true;\r
+ }\r
+ }\r
+\r
+ return false;\r
+}\r
+\r
+bool TParseContext::insertBuiltInArrayAtGlobalLevel()\r
+{\r
+ TString *name = NewPoolTString("gl_TexCoord");\r
+ TSymbol* symbol = symbolTable.find(*name);\r
+ if (!symbol) {\r
+ error(0, "INTERNAL ERROR finding symbol", name->c_str(), "");\r
+ return true;\r
+ }\r
+ TVariable* variable = static_cast<TVariable*>(symbol);\r
+\r
+ TVariable* newVariable = new TVariable(name, variable->getType());\r
+\r
+ if (! symbolTable.insert(*newVariable)) {\r
+ delete newVariable;\r
+ error(0, "INTERNAL ERROR inserting new symbol", name->c_str(), "");\r
+ return true;\r
+ }\r
+\r
+ return false;\r
+}\r
+\r
+//\r
+// Do all the semantic checking for declaring an array, with and \r
+// without a size, and make the right changes to the symbol table.\r
+//\r
+// size == 0 means no specified size.\r
+//\r
+// Returns true if there was an error.\r
+//\r
+bool TParseContext::arrayErrorCheck(int line, TString& identifier, TPublicType type, TIntermTyped* size)\r
+{\r
+ //\r
+ // Don't check for reserved word use until after we know it's not in the symbol table,\r
+ // because reserved arrays can be redeclared.\r
+ //\r
+\r
+ //\r
+ // Can the type be an array?\r
+ //\r
+ if (type.array || type.qualifier == EvqAttribute || type.qualifier == EvqConst) {\r
+ error(line, "cannot declare arrays of this type", TType(type).getCompleteString().c_str(), "");\r
+ return true;\r
+ }\r
+ type.array = true;\r
+\r
+ //\r
+ // size will be 0 if there is no size declared, otherwise it contains the size\r
+ // declared.\r
+ //\r
+ TIntermConstantUnion* constant = 0;\r
+ if (size) {\r
+ constant = size->getAsConstantUnion();\r
+ if (constant == 0 || constant->getBasicType() != EbtInt || constant->getUnionArrayPointer()->iConst <= 0) {\r
+ error(line, "array size must be a positive integer", identifier.c_str(), "");\r
+ return true;\r
+ }\r
+ }\r
+\r
+ bool builtIn = false; \r
+ bool sameScope = false;\r
+ TSymbol* symbol = symbolTable.find(identifier, &builtIn, &sameScope);\r
+ if (symbol == 0 || !sameScope) {\r
+ if (reservedErrorCheck(line, identifier))\r
+ return true;\r
+ \r
+ TVariable* variable = new TVariable(&identifier, TType(type));\r
+\r
+ if (size)\r
+ variable->getType().setArraySize(constant->getUnionArrayPointer()->iConst);\r
+\r
+ if (! symbolTable.insert(*variable)) {\r
+ delete variable;\r
+ error(line, "INTERNAL ERROR inserting new symbol", identifier.c_str(), "");\r
+ return true;\r
+ }\r
+ } else {\r
+ if (! symbol->isVariable()) {\r
+ error(line, "variable expected", identifier.c_str(), "");\r
+ return true;\r
+ }\r
+\r
+ TVariable* variable = static_cast<TVariable*>(symbol);\r
+ if (! variable->getType().isArray()) {\r
+ error(line, "redeclaring non-array as array", identifier.c_str(), "");\r
+ return true;\r
+ }\r
+ if (variable->getType().getArraySize() > 0) {\r
+ error(line, "redeclaration of array with size", identifier.c_str(), "");\r
+ return true;\r
+ }\r
+ \r
+ if (variable->getType() != TType(type)) {\r
+ error(line, "redeclaration of array with a different type", identifier.c_str(), "");\r
+ return true;\r
+ }\r
+\r
+ TType* t = variable->getArrayInformationType();\r
+ while (t != 0) {\r
+ if (t->getMaxArraySize() > constant->getUnionArrayPointer()->iConst) {\r
+ error(line, "higher index value already used for the array", identifier.c_str(), "");\r
+ return true;\r
+ }\r
+ t->setArraySize(constant->getUnionArrayPointer()->iConst);\r
+ t = t->getArrayInformationType();\r
+ }\r
+\r
+ if (size)\r
+ variable->getType().setArraySize(constant->getUnionArrayPointer()->iConst);\r
+ } \r
+\r
+ if (voidErrorCheck(line, identifier, type))\r
+ return true;\r
+\r
+ return false;\r
+}\r
+\r
+bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size, bool updateFlag, TSourceLoc line)\r
+{\r
+ bool builtIn = false;\r
+ TSymbol* symbol = symbolTable.find(node->getSymbol(), &builtIn);\r
+ if (symbol == 0) {\r
+ error(line, " undeclared identifier", node->getSymbol().c_str(), "");\r
+ return true;\r
+ }\r
+ TVariable* variable = static_cast<TVariable*>(symbol);\r
+\r
+ type->setArrayInformationType(variable->getArrayInformationType());\r
+ variable->updateArrayInformationType(type);\r
+\r
+ // we dont want to update the maxArraySize when this flag is not set, we just want to include this \r
+ // node type in the chain of node types so that its updated when a higher maxArraySize comes in.\r
+ if (!updateFlag)\r
+ return false;\r
+\r
+ size++;\r
+ variable->getType().setMaxArraySize(size);\r
+ type->setMaxArraySize(size);\r
+ TType* tt = type;\r
+\r
+ while(tt->getArrayInformationType() != 0) {\r
+ tt = tt->getArrayInformationType();\r
+ tt->setMaxArraySize(size);\r
+ }\r
+\r
+ return false;\r
+}\r
+\r
+//\r
+// Do semantic checking for a variable declaration that has no initializer,\r
+// and update the symbol table.\r
+//\r
+// Returns true if there was an error.\r
+//\r
+bool TParseContext::nonInitErrorCheck(int line, TString& identifier, TPublicType& type)\r
+{\r
+ if (reservedErrorCheck(line, identifier))\r
+ recover();\r
+\r
+ //\r
+ // Make the qualifier make sense, error is issued in a little bit.\r
+ //\r
+ bool constError = false;\r
+ if (type.qualifier == EvqConst) {\r
+ type.qualifier = EvqTemporary;\r
+ constError = true;\r
+ }\r
+\r
+ TVariable* variable = new TVariable(&identifier, TType(type));\r
+\r
+ if (! symbolTable.insert(*variable)) {\r
+ error(line, "redefinition", variable->getName().c_str(), "");\r
+ delete variable;\r
+ return true;\r
+ }\r
+ if (constError) {\r
+ error(line, "variables with qualifier 'const' must be initialized", identifier.c_str(), "");\r
+ return true;\r
+ }\r
+\r
+ if (voidErrorCheck(line, identifier, type))\r
+ return true;\r
+\r
+ return false;\r
+}\r
+\r
+bool TParseContext::paramErrorCheck(int line, TQualifier qualifier, TQualifier paramQualifier, TType* type)\r
+{ \r
+ if (qualifier != EvqConst && qualifier != EvqTemporary) {\r
+ error(line, "qualifier not allowed on function parameter", getQualifierString(qualifier), "");\r
+ return true;\r
+ }\r
+ if (qualifier == EvqConst && paramQualifier != EvqIn) {\r
+ error(line, "qualifier not allowed with ", getQualifierString(qualifier), getQualifierString(paramQualifier));\r
+ return true;\r
+ }\r
+\r
+ if (qualifier == EvqConst)\r
+ type->changeQualifier(EvqConstReadOnly);\r
+ else\r
+ type->changeQualifier(paramQualifier);\r
+\r
+ return false;\r
+}\r
+\r
+/////////////////////////////////////////////////////////////////////////////////\r
+//\r
+// Non-Errors.\r
+//\r
+/////////////////////////////////////////////////////////////////////////////////\r
+\r
+//\r
+// Look up a function name in the symbol table, and make sure it is a function.\r
+//\r
+// Return the function symbol if found, otherwise 0.\r
+//\r
+const TFunction* TParseContext::findFunction(int line, TFunction* call, bool *builtIn)\r
+{\r
+ const TSymbol* symbol = symbolTable.find(call->getMangledName(), builtIn);\r
+\r
+ if (symbol == 0) { \r
+ error(line, "no matching overloaded function found", call->getName().c_str(), "");\r
+ return 0;\r
+ }\r
+\r
+ if (! symbol->isFunction()) {\r
+ error(line, "function name expected", call->getName().c_str(), "");\r
+ return 0;\r
+ }\r
+ \r
+ const TFunction* function = static_cast<const TFunction*>(symbol);\r
+ \r
+ return function;\r
+}\r
+//\r
+// Initializers show up in several places in the grammar. Have one set of\r
+// code to handle them here.\r
+//\r
+bool TParseContext::executeInitializer(TSourceLoc line, TString& identifier, TPublicType& pType, \r
+ TIntermTyped* initializer, TIntermNode*& intermNode)\r
+{\r
+ if (reservedErrorCheck(line, identifier))\r
+ return true;\r
+\r
+ if (voidErrorCheck(line, identifier, pType))\r
+ return true;\r
+\r
+ //\r
+ // add variable to symbol table\r
+ //\r
+ TVariable* variable = new TVariable(&identifier, TType(pType));\r
+ if (! symbolTable.insert(*variable)) {\r
+ error(line, "redefinition", variable->getName().c_str(), "");\r
+ return true;\r
+ // don't delete variable, it's used by error recovery, and the pool \r
+ // pop will take care of the memory\r
+ }\r
+\r
+ //\r
+ // identifier must be of type constant, a global, or a temporary\r
+ //\r
+ TQualifier qualifier = variable->getType().getQualifier();\r
+ if ((qualifier != EvqTemporary) && (qualifier != EvqGlobal) && (qualifier != EvqConst)) {\r
+ error(line, " cannot initialize this type of qualifier ", variable->getType().getQualifierString(), "");\r
+ return true;\r
+ }\r
+ //\r
+ // test for and propagate constant\r
+ //\r
+\r
+ if (qualifier == EvqConst) {\r
+ if (qualifier != initializer->getType().getQualifier()) {\r
+ error(line, " assigning non-constant to", "=", "'%s'", variable->getType().getCompleteString().c_str());\r
+ variable->getType().changeQualifier(EvqTemporary);\r
+ return true;\r
+ }\r
+ if (TType(pType) != initializer->getType()) {\r
+ error(line, " non-matching types for const initializer ", \r
+ variable->getType().getQualifierString(), "");\r
+ variable->getType().changeQualifier(EvqTemporary);\r
+ return true;\r
+ }\r
+ if (initializer->getAsConstantUnion()) { \r
+ constUnion* unionArray = variable->getConstPointer(); \r
+\r
+ if (pType.size == 1 && TType(pType).getBasicType() != EbtStruct) {\r
+ switch (pType.type ) {\r
+ case EbtInt:\r
+ unionArray->iConst = (initializer->getAsConstantUnion()->getUnionArrayPointer())[0].iConst;\r
+ break;\r
+ case EbtFloat:\r
+ unionArray->fConst = (initializer->getAsConstantUnion()->getUnionArrayPointer())[0].fConst;\r
+ break;\r
+ case EbtBool:\r
+ unionArray->bConst = (initializer->getAsConstantUnion()->getUnionArrayPointer())[0].bConst;\r
+ break;\r
+ default:\r
+ error(line, " cannot initialize constant of this type", "", "");\r
+ return true;\r
+ }\r
+ } else {\r
+ variable->shareConstPointer(initializer->getAsConstantUnion()->getUnionArrayPointer());\r
+ }\r
+ } else if (initializer->getAsAggregate()) {\r
+ bool returnVal = false;\r
+ constUnion* unionArray = variable->getConstPointer();\r
+ if (initializer->getAsAggregate()->getSequence().size() == 1 && initializer->getAsAggregate()->getSequence()[0]->getAsTyped()->getAsConstantUnion()) {\r
+ returnVal = intermediate.parseConstTree(line, initializer, unionArray, initializer->getAsAggregate()->getOp(), symbolTable, variable->getType(), true);\r
+ }\r
+ else {\r
+ returnVal = intermediate.parseConstTree(line, initializer, unionArray, initializer->getAsAggregate()->getOp(), symbolTable, variable->getType());\r
+ }\r
+ intermNode = 0;\r
+ constUnion *arrayUnion = unionArray;\r
+ if (returnVal) {\r
+ arrayUnion = 0;\r
+ variable->getType().changeQualifier(EvqTemporary);\r
+ } \r
+ return returnVal;\r
+ } else if (initializer->getAsSymbolNode()) {\r
+ const TSymbol* symbol = symbolTable.find(initializer->getAsSymbolNode()->getSymbol());\r
+ const TVariable* tVar = static_cast<const TVariable*>(symbol);\r
+\r
+ constUnion* constArray = tVar->getConstPointer();\r
+ variable->shareConstPointer(constArray);\r
+ } else {\r
+ error(line, " assigning non-constant to", "=", "'%s'", variable->getType().getCompleteString().c_str());\r
+ variable->getType().changeQualifier(EvqTemporary);\r
+ return true;\r
+ }\r
+ }\r
+ \r
+ if (qualifier != EvqConst) {\r
+ TIntermSymbol* intermSymbol = intermediate.addSymbol(variable->getUniqueId(), variable->getName(), variable->getType(), line);\r
+ intermNode = intermediate.addAssign(EOpAssign, intermSymbol, initializer, line);\r
+ if (intermNode == 0) {\r
+ assignError(line, "=", intermSymbol->getCompleteString(), initializer->getCompleteString());\r
+ return true;\r
+ }\r
+ } else \r
+ intermNode = 0;\r
+\r
+ return false;\r
+}\r
+\r
+//\r
+// This method checks to see if the given aggregate node has all its children nodes as constants\r
+// This method does not test if structure members are constant\r
+//\r
+bool TParseContext::canNodeBeRemoved(TIntermNode* childNode)\r
+{\r
+ TIntermAggregate *aggrNode = childNode->getAsAggregate();\r
+ if (!aggrNode)\r
+ return false;\r
+\r
+ if (!aggrNode->isConstructor() || aggrNode->getOp() == EOpConstructStruct)\r
+ return false;\r
+\r
+ bool allConstant = true;\r
+\r
+ // check if all the child nodes are constants so that they can be inserted into \r
+ // the parent node\r
+ if (aggrNode) {\r
+ TIntermSequence &childSequenceVector = aggrNode->getSequence() ;\r
+ for (TIntermSequence::iterator p = childSequenceVector.begin(); \r
+ p != childSequenceVector.end(); p++) {\r
+ if (!(*p)->getAsTyped()->getAsConstantUnion())\r
+ return false;\r
+ }\r
+ }\r
+\r
+ return allConstant;\r
+}\r
+\r
+// This function is used to test for the correctness of the parameters passed to various constructor functions\r
+// and also convert them to the right datatype if it is allowed and required. \r
+//\r
+// Returns 0 for an error or the constructed node (aggregate or typed) for no error.\r
+//\r
+TIntermTyped* TParseContext::addConstructor(TIntermNode* node, TType* type, TOperator op, TFunction* fnCall, TSourceLoc line)\r
+{\r
+ if (node == 0)\r
+ return 0;\r
+\r
+ TIntermAggregate* aggrNode = node->getAsAggregate();\r
+ \r
+ TTypeList::iterator list;\r
+ TTypeList* structure = 0; // Store the information (vector) about the return type of the structure.\r
+ if (op == EOpConstructStruct) {\r
+ TType ttype = fnCall->getReturnType();\r
+ structure = ttype.getStruct();\r
+ list = (*structure).begin();\r
+ }\r
+\r
+ bool singleArg;\r
+ if (aggrNode) {\r
+ if (aggrNode->getOp() != EOpNull || aggrNode->getSequence().size() == 1)\r
+ singleArg = true;\r
+ else\r
+ singleArg = false;\r
+ } else\r
+ singleArg = true;\r
+\r
+ TIntermTyped *newNode;\r
+ if (singleArg) {\r
+ if (op == EOpConstructStruct) { \r
+ // If structure constructor is being called for only one parameter inside the structure,\r
+ // we need to call constructStruct function once.\r
+ if (structure->size() != 1) {\r
+ error(line, "Number of constructor parameters does not match the number of structure fields", "constructor", "");\r
+ \r
+ return 0;\r
+ } else\r
+ return constructStruct(node, (*list).type, 1, node->getLine(), false);\r
+ } else {\r
+ newNode = constructBuiltIn(type, op, node, node->getLine(), false);\r
+ if (newNode && newNode->getAsAggregate()) {\r
+ if (canNodeBeRemoved(newNode->getAsAggregate()->getSequence()[0])) {\r
+ TIntermAggregate* returnAggNode = newNode->getAsAggregate()->getSequence()[0]->getAsAggregate();\r
+ newNode = intermediate.removeChildNode(newNode, type, returnAggNode);\r
+ }\r
+ }\r
+ return newNode;\r
+ }\r
+ }\r
+ \r
+ //\r
+ // Handle list of arguments.\r
+ //\r
+ TIntermSequence &sequenceVector = aggrNode->getSequence() ; // Stores the information about the parameter to the constructor\r
+ // if the structure constructor contains more than one parameter, then construct\r
+ // each parameter\r
+ if (op == EOpConstructStruct) {\r
+ if (structure->size() != sequenceVector.size()) { // If the number of parameters to the constructor does not match the expected number of parameters\r
+ error(line, "Number of constructor parameters does not match the number of structure fields", "constructor", "");\r
+ \r
+ return 0;\r
+ }\r
+ }\r
+ \r
+ int paramCount = 0; // keeps a track of the constructor parameter number being checked \r
+ \r
+ // for each parameter to the constructor call, check to see if the right type is passed or convert them \r
+ // to the right type if possible (and allowed).\r
+ // for structure constructors, just check if the right type is passed, no conversion is allowed.\r
+ \r
+ for (TIntermSequence::iterator p = sequenceVector.begin(); \r
+ p != sequenceVector.end(); p++, paramCount++) {\r
+ bool move = false;\r
+ if (op == EOpConstructStruct) {\r
+ newNode = constructStruct(*p, (list[paramCount]).type, paramCount+1, node->getLine(), true);\r
+ if (newNode)\r
+ move = true;\r
+ } else {\r
+ newNode = constructBuiltIn(type, op, *p, node->getLine(), true);\r
+\r
+ if (newNode) {\r
+ if (canNodeBeRemoved(newNode))\r
+ intermediate.removeChildNode(sequenceVector, *type, paramCount, p, newNode->getAsAggregate());\r
+ else\r
+ move = true; \r
+ } \r
+ }\r
+ if (move) {\r
+ sequenceVector.erase(p); \r
+ sequenceVector.insert(p, newNode);\r
+ }\r
+ }\r
+\r
+ return intermediate.setAggregateOperator(aggrNode, op, line);\r
+}\r
+\r
+// Function for constructor implementation. Calls addUnaryMath with appropriate EOp value\r
+// for the parameter to the constructor (passed to this function). Essentially, it converts\r
+// the parameter types correctly. If a constructor expects an int (like ivec2) and is passed a \r
+// float, then float is converted to int.\r
+//\r
+// Returns 0 for an error or the constructed node.\r
+//\r
+TIntermTyped* TParseContext::constructBuiltIn(TType* type, TOperator op, TIntermNode* node, TSourceLoc line, bool subset)\r
+{\r
+ TIntermTyped* newNode;\r
+ TOperator basicOp;\r
+\r
+ //\r
+ // First, convert types as needed.\r
+ //\r
+ switch (op) {\r
+ case EOpConstructVec2:\r
+ case EOpConstructVec3:\r
+ case EOpConstructVec4:\r
+ case EOpConstructMat2:\r
+ case EOpConstructMat3:\r
+ case EOpConstructMat4:\r
+ case EOpConstructFloat:\r
+ basicOp = EOpConstructFloat;\r
+ break;\r
+\r
+ case EOpConstructIVec2:\r
+ case EOpConstructIVec3:\r
+ case EOpConstructIVec4:\r
+ case EOpConstructInt:\r
+ basicOp = EOpConstructInt;\r
+ break;\r
+\r
+ case EOpConstructBVec2:\r
+ case EOpConstructBVec3:\r
+ case EOpConstructBVec4:\r
+ case EOpConstructBool:\r
+ basicOp = EOpConstructBool;\r
+ break;\r
+\r
+ default:\r
+ error(line, "unsupported construction", "", "");\r
+ recover();\r
+\r
+ return 0;\r
+ }\r
+ newNode = intermediate.addUnaryMath(basicOp, node, node->getLine(), symbolTable);\r
+ if (newNode == 0) {\r
+ error(line, "can't convert", "constructor", "");\r
+ return 0;\r
+ }\r
+\r
+ //\r
+ // Now, if there still isn't an operation to do the construction, and we need one, add one.\r
+ //\r
+ \r
+ // Otherwise, skip out early.\r
+ if (subset || newNode != node && newNode->getType() == *type)\r
+ return newNode;\r
+\r
+ // setAggregateOperator will insert a new node for the constructor, as needed.\r
+ return intermediate.setAggregateOperator(newNode, op, line);\r
+}\r
+\r
+// This function tests for the type of the parameters to the structures constructors. Raises\r
+// an error message if the expected type does not match the parameter passed to the constructor.\r
+//\r
+// Returns 0 for an error or the input node itself if the expected and the given parameter types match.\r
+//\r
+TIntermTyped* TParseContext::constructStruct(TIntermNode* node, TType* type, int paramCount, TSourceLoc line, bool subset)\r
+{\r
+ if (*type == node->getAsTyped()->getType()) {\r
+ if (subset)\r
+ return node->getAsTyped();\r
+ else\r
+ return intermediate.setAggregateOperator(node->getAsTyped(), EOpConstructStruct, line);\r
+ } else {\r
+ error(line, "", "constructor", "cannot convert parameter %d from '%s' to '%s'", paramCount,\r
+ node->getAsTyped()->getType().getBasicString(), type->getBasicString());\r
+ recover();\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+//\r
+// This function returns the tree representation for the vector field(s) being accessed from contant vector.\r
+// If only one component of vector is accessed (v.x or v[0] where v is a contant vector), then a contant node is\r
+// returned, else an aggregate node is returned (for v.xy). The input to this function could either be the symbol\r
+// node or it could be the intermediate tree representation of accessing fields in a constant structure or column of \r
+// a constant matrix.\r
+//\r
+TIntermTyped* TParseContext::addConstVectorNode(TVectorFields& fields, TIntermTyped* node, TSourceLoc line)\r
+{\r
+ TIntermTyped* typedNode;\r
+ TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion();\r
+ TIntermAggregate* aggregateNode = node->getAsAggregate();\r
+\r
+ constUnion *unionArray;\r
+ if (tempConstantNode) {\r
+ unionArray = tempConstantNode->getUnionArrayPointer();\r
+\r
+ if (!unionArray) { // this error message should never be raised\r
+ infoSink.info.message(EPrefixInternalError, "constUnion not initialized in addConstVectorNode function", line);\r
+ recover();\r
+\r
+ return node;\r
+ }\r
+ } else if (aggregateNode) { // if an aggregate node is present, the value has to be taken from the parse tree \r
+ // for a case like vec(4).xz\r
+ unionArray = new constUnion[aggregateNode->getType().getInstanceSize()]; \r
+ \r
+ bool returnVal = false;\r
+ if (aggregateNode->getAsAggregate()->getSequence().size() == 1 && aggregateNode->getAsAggregate()->getSequence()[0]->getAsTyped()->getAsConstantUnion()) {\r
+ returnVal = intermediate.parseConstTree(line, aggregateNode, unionArray, aggregateNode->getOp(), symbolTable, aggregateNode->getType(), true);\r
+ }\r
+ else {\r
+ returnVal = intermediate.parseConstTree(line, aggregateNode, unionArray, aggregateNode->getOp(), symbolTable, aggregateNode->getType());\r
+ }\r
+\r
+ if (returnVal)\r
+ return 0;\r
+\r
+ } else { // The node has to be either a symbol node or an aggregate node or a tempConstant node, else, its an error\r
+ error(line, "No aggregate or constant union node available", "Internal Error", "");\r
+ recover();\r
+\r
+ return 0;\r
+ }\r
+\r
+ constUnion* constArray = new constUnion[fields.num];\r
+\r
+ for (int i = 0; i < fields.num; i++) {\r
+ if (fields.offsets[i] >= node->getType().getInstanceSize()) {\r
+ error(line, "", "[", "vector field selection out of range '%d'", fields.offsets[i]);\r
+ recover();\r
+ fields.offsets[i] = 0;\r
+ }\r
+ \r
+ constArray[i] = unionArray[fields.offsets[i]];\r
+\r
+ } \r
+ typedNode = intermediate.addConstantUnion(constArray, node->getType(), line);\r
+ return typedNode;\r
+}\r
+\r
+//\r
+// This function returns the column being accessed from a constant matrix. The values are retrieved from\r
+// the symbol table and parse-tree is built for a vector (each column of a matrix is a vector). The input \r
+// to the function could either be a symbol node (m[0] where m is a constant matrix)that represents a \r
+// constant matrix or it could be the tree representation of the constant matrix (s.m1[0] where s is a constant structure)\r
+//\r
+TIntermTyped* TParseContext::addConstMatrixNode(int index, TIntermTyped* node, TSourceLoc line)\r
+{\r
+ TIntermTyped* typedNode;\r
+ TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion();\r
+ TIntermAggregate* aggregateNode = node->getAsAggregate();\r
+\r
+ if (index >= node->getType().getNominalSize()) {\r
+ error(line, "", "[", "matrix field selection out of range '%d'", index);\r
+ recover();\r
+ index = 0;\r
+ }\r
+\r
+ if (tempConstantNode) {\r
+ constUnion* unionArray = tempConstantNode->getUnionArrayPointer();\r
+ int size = tempConstantNode->getType().getNominalSize();\r
+ typedNode = intermediate.addConstantUnion(&unionArray[size*index], tempConstantNode->getType(), line);\r
+ } else if (aggregateNode) {\r
+ // for a case like mat4(5)[0]\r
+ constUnion* unionArray = new constUnion[aggregateNode->getType().getInstanceSize()]; \r
+ int size = aggregateNode->getType().getNominalSize();\r
+ \r
+ bool returnVal = false;\r
+ if (aggregateNode->getAsAggregate()->getSequence().size() == 1 && aggregateNode->getAsAggregate()->getSequence()[0]->getAsTyped()->getAsConstantUnion()) {\r
+ returnVal = intermediate.parseConstTree(line, aggregateNode, unionArray, aggregateNode->getOp(), symbolTable, aggregateNode->getType(), true);\r
+ }\r
+ else {\r
+ returnVal = intermediate.parseConstTree(line, aggregateNode, unionArray, aggregateNode->getOp(), symbolTable, aggregateNode->getType());\r
+ }\r
+\r
+ if (!returnVal)\r
+ typedNode = intermediate.addConstantUnion(&unionArray[size*index], aggregateNode->getType(), line);\r
+ else \r
+ return 0;\r
+\r
+ } else {\r
+ error(line, "No Aggregate or Constant Union node available", "Internal Error", "");\r
+ recover();\r
+\r
+ return 0;\r
+ }\r
+\r
+ return typedNode;\r
+}\r
+\r
+//\r
+// This function returns the value of a particular field inside a constant structure from the symbol table. \r
+// If there is an embedded/nested struct, it appropriately calls addConstStructNested or addConstStructFromAggr\r
+// function and returns the parse-tree with the values of the embedded/nested struct.\r
+//\r
+TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* node, TSourceLoc line)\r
+{\r
+ TTypeList* fields = node->getType().getStruct();\r
+ TIntermTyped *typedNode;\r
+ int instanceSize = 0;\r
+ unsigned int index = 0;\r
+ TIntermConstantUnion *tempConstantNode = node->getAsConstantUnion();\r
+ TIntermAggregate* aggregateNode = node->getAsAggregate();\r
+\r
+ for ( index = 0; index < fields->size(); ++index) {\r
+ if ((*fields)[index].type->getFieldName() == identifier) {\r
+ break;\r
+ } else {\r
+ if ((*fields)[index].type->getStruct())\r
+ //?? We should actually be calling getStructSize() function and not setStructSize. This problem occurs in case\r
+ // of nested/embedded structs. \r
+ instanceSize += (*fields)[index].type->setStructSize((*fields)[index].type->getStruct());\r
+ else\r
+ instanceSize += (*fields)[index].type->getInstanceSize();\r
+ }\r
+ }\r
+\r
+ if (tempConstantNode) {\r
+ constUnion* constArray = tempConstantNode->getUnionArrayPointer();\r
+\r
+ typedNode = intermediate.addConstantUnion(constArray+instanceSize, tempConstantNode->getType(), line); // type will be changed in the calling function\r
+ } else if (aggregateNode) {\r
+ // for a case like constStruct(1,v3).i where structure fields is int i and vec3 v3.\r
+\r
+ constUnion* unionArray = new constUnion[aggregateNode->getType().getStructSize()]; \r
+ \r
+ bool returnVal = false;\r
+ if (aggregateNode->getAsAggregate()->getSequence().size() == 1 && aggregateNode->getAsAggregate()->getSequence()[0]->getAsTyped()->getAsConstantUnion()) {\r
+ returnVal = intermediate.parseConstTree(line, aggregateNode, unionArray, aggregateNode->getOp(), symbolTable, aggregateNode->getType(), true);\r
+ }\r
+ else {\r
+ returnVal = intermediate.parseConstTree(line, aggregateNode, unionArray, aggregateNode->getOp(), symbolTable, aggregateNode->getType());\r
+ }\r
+\r
+ if (!returnVal)\r
+ typedNode = intermediate.addConstantUnion(unionArray+instanceSize, aggregateNode->getType(), line);\r
+ else\r
+ return 0;\r
+\r
+ } else {\r
+ error(line, "No Aggregate or Constant Union node available", "Internal Error", "");\r
+ recover();\r
+\r
+ return 0;\r
+ }\r
+\r
+ return typedNode;\r
+}\r
+\r
+//\r
+// Initialize all supported extensions to disable\r
+//\r
+void TParseContext::initializeExtensionBehavior()\r
+{\r
+ //\r
+ // example code: extensionBehavior["test"] = EDisable; // where "test" is the name of \r
+ // supported extension\r
+ //\r
+}\r
+\r
+OS_TLSIndex GlobalParseContextIndex = OS_INVALID_TLS_INDEX;\r
+\r
+bool InitializeParseContextIndex()\r
+{\r
+ if (GlobalParseContextIndex != OS_INVALID_TLS_INDEX) {\r
+ assert(0 && "InitializeParseContextIndex(): Parse Context already initalised");\r
+ return false;\r
+ }\r
+\r
+ //\r
+ // Allocate a TLS index.\r
+ //\r
+ GlobalParseContextIndex = OS_AllocTLSIndex();\r
+ \r
+ if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) {\r
+ assert(0 && "InitializeParseContextIndex(): Parse Context already initalised");\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+bool InitializeGlobalParseContext()\r
+{\r
+ if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) {\r
+ assert(0 && "InitializeGlobalParseContext(): Parse Context index not initalised");\r
+ return false;\r
+ }\r
+\r
+ TThreadParseContext *lpParseContext = static_cast<TThreadParseContext *>(OS_GetTLSValue(GlobalParseContextIndex));\r
+ if (lpParseContext != 0) {\r
+ assert(0 && "InitializeParseContextIndex(): Parse Context already initalised");\r
+ return false;\r
+ }\r
+\r
+ TThreadParseContext *lpThreadData = new TThreadParseContext();\r
+ if (lpThreadData == 0) {\r
+ assert(0 && "InitializeGlobalParseContext(): Unable to create thread parse context");\r
+ return false;\r
+ }\r
+\r
+ lpThreadData->lpGlobalParseContext = 0;\r
+ OS_SetTLSValue(GlobalParseContextIndex, lpThreadData);\r
+\r
+ return true;\r
+}\r
+\r
+TParseContextPointer& GetGlobalParseContext()\r
+{\r
+ //\r
+ // Minimal error checking for speed\r
+ //\r
+\r
+ TThreadParseContext *lpParseContext = static_cast<TThreadParseContext *>(OS_GetTLSValue(GlobalParseContextIndex));\r
+\r
+ return lpParseContext->lpGlobalParseContext;\r
+}\r
+\r
+bool FreeParseContext()\r
+{\r
+ if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) {\r
+ assert(0 && "FreeParseContext(): Parse Context index not initalised");\r
+ return false;\r
+ }\r
+\r
+ TThreadParseContext *lpParseContext = static_cast<TThreadParseContext *>(OS_GetTLSValue(GlobalParseContextIndex));\r
+ if (lpParseContext)\r
+ delete lpParseContext;\r
+\r
+ return true;\r
+}\r
+\r
+bool FreeParseContextIndex()\r
+{\r
+ OS_TLSIndex tlsiIndex = GlobalParseContextIndex;\r
+\r
+ if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) {\r
+ assert(0 && "FreeParseContextIndex(): Parse Context index not initalised");\r
+ return false;\r
+ }\r
+\r
+ GlobalParseContextIndex = OS_INVALID_TLS_INDEX;\r
+\r
+ return OS_FreeTLSIndex(tlsiIndex);\r
+}\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+#ifndef _PARSER_HELPER_INCLUDED_\r
+#define _PARSER_HELPER_INCLUDED_\r
+\r
+#include "../Include/ShHandle.h"\r
+#include "SymbolTable.h"\r
+#include "localintermediate.h"\r
+\r
+struct TMatrixFields {\r
+ bool wholeRow;\r
+ bool wholeCol;\r
+ int row;\r
+ int col; \r
+};\r
+\r
+typedef enum {\r
+ EBhRequire,\r
+ EBhEnable,\r
+ EBhWarn,\r
+ EBhDisable\r
+} TBehavior;\r
+\r
+//\r
+// The following are extra variables needed during parsing, grouped together so\r
+// they can be passed to the parser without needing a global.\r
+//\r
+struct TParseContext {\r
+ TParseContext(TSymbolTable& symt, TIntermediate& interm, EShLanguage L, TInfoSink& is) : \r
+ intermediate(interm), symbolTable(symt), infoSink(is), language(L), treeRoot(0),\r
+ recoveredFromError(false), numErrors(0), lexAfterType(false), loopNestingLevel(0), \r
+ inTypeParen(false) { }\r
+ TIntermediate& intermediate; // to hold and build a parse tree\r
+ TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed\r
+ TInfoSink& infoSink;\r
+ EShLanguage language; // vertex or fragment language (future: pack or unpack)\r
+ TIntermNode* treeRoot; // root of parse tree being created\r
+ bool recoveredFromError; // true if a parse error has occurred, but we continue to parse\r
+ int numErrors;\r
+ bool lexAfterType; // true if we've recognized a type, so can only be looking for an identifier\r
+ int loopNestingLevel; // 0 if outside all loops\r
+ bool inTypeParen; // true if in parentheses, looking only for an identifier\r
+ const TType* currentFunctionType; // the return type of the function that's currently being parsed\r
+ bool functionReturnsValue; // true if a non-void function has a return\r
+ TMap<TString, TBehavior> extensionBehavior;\r
+ void initializeExtensionBehavior();\r
+\r
+ void C_DECL error(TSourceLoc, const char *szReason, const char *szToken, \r
+ const char *szExtraInfoFormat, ...);\r
+ bool reservedErrorCheck(int line, const TString& identifier);\r
+ void recover();\r
+ \r
+ bool parseVectorFields(const TString&, int vecSize, TVectorFields&, int line);\r
+ bool parseMatrixFields(const TString&, int matSize, TMatrixFields&, int line);\r
+ void assignError(int line, const char* op, TString left, TString right);\r
+ void unaryOpError(int line, char* op, TString operand);\r
+ void binaryOpError(int line, char* op, TString left, TString right);\r
+ bool lValueErrorCheck(int line, char* op, TIntermTyped*);\r
+ bool constErrorCheck(TIntermTyped* node);\r
+ bool integerErrorCheck(TIntermTyped* node, char* token);\r
+ bool globalErrorCheck(int line, bool global, char* token);\r
+ bool constructorErrorCheck(int line, TIntermNode*, TFunction&, TOperator, TType*);\r
+ bool arrayErrorCheck(int line, TString& identifier, TPublicType type, TIntermTyped* size);\r
+ bool insertBuiltInArrayAtGlobalLevel();\r
+ bool voidErrorCheck(int, const TString&, const TPublicType&);\r
+ bool boolErrorCheck(int, const TIntermTyped*);\r
+ bool boolErrorCheck(int, const TPublicType&);\r
+ bool samplerErrorCheck(int line, const TPublicType& pType, const char* reason);\r
+ bool structQualifierErrorCheck(int line, const TPublicType& pType);\r
+ bool parameterSamplerErrorCheck(int line, TQualifier qualifier, const TType& type);\r
+ bool containsSampler(TType& type);\r
+ bool nonInitErrorCheck(int line, TString& identifier, TPublicType& type);\r
+ bool paramErrorCheck(int line, TQualifier qualifier, TQualifier paramQualifier, TType* type);\r
+ const TFunction* findFunction(int line, TFunction* pfnCall, bool *builtIn = 0);\r
+ bool executeInitializer(TSourceLoc line, TString& identifier, TPublicType& pType, \r
+ TIntermTyped* initializer, TIntermNode*& intermNode);\r
+ bool TParseContext::canNodeBeRemoved(TIntermNode*);\r
+ TIntermTyped* addConstructor(TIntermNode*, TType*, TOperator, TFunction*, TSourceLoc);\r
+ TIntermTyped* constructStruct(TIntermNode*, TType*, int, TSourceLoc, bool subset);\r
+ TIntermTyped* constructBuiltIn(TType*, TOperator, TIntermNode*, TSourceLoc, bool subset);\r
+ TIntermTyped* addConstVectorNode(TVectorFields&, TIntermTyped*, TSourceLoc);\r
+ TIntermTyped* addConstMatrixNode(int , TIntermTyped*, TSourceLoc);\r
+ TIntermTyped* addConstStruct(TString& , TIntermTyped*, TSourceLoc);\r
+ bool arraySetMaxSize(TIntermSymbol*, TType*, int, bool, TSourceLoc);\r
+ typedef std::map<TString, TString> PragmaStringMap;\r
+ PragmaStringMap PragmaTable;\r
+ TString HashErrMsg; \r
+ bool AfterEOF;\r
+};\r
+\r
+int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext&);\r
+void PaReservedWord();\r
+int PaIdentOrType(TString& id, TParseContext&, TSymbol*&);\r
+int PaParseComment(int &lineno, TParseContext&);\r
+void setInitialState();\r
+\r
+typedef TParseContext* TParseContextPointer;\r
+extern TParseContextPointer& GetGlobalParseContext();\r
+#define GlobalParseContext GetGlobalParseContext()\r
+\r
+typedef struct TThreadParseContextRec\r
+{\r
+ TParseContext *lpGlobalParseContext;\r
+} TThreadParseContext;\r
+\r
+#endif // _PARSER_HELPER_INCLUDED_\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#include "../Include/PoolAlloc.h"\r
+#include "../Include/Common.h"\r
+#include <assert.h>\r
+\r
+#include "Include/InitializeGlobals.h"\r
+#include "osinclude.h"\r
+\r
+OS_TLSIndex PoolIndex;\r
+\r
+void InitializeGlobalPools()\r
+{\r
+ TThreadGlobalPools* globalPools= static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex)); \r
+ if (globalPools)\r
+ return;\r
+\r
+ TPoolAllocator *globalPoolAllocator = new TPoolAllocator(true);\r
+\r
+ TThreadGlobalPools* threadData = new TThreadGlobalPools();\r
+ \r
+ threadData->globalPoolAllocator = globalPoolAllocator;\r
+ threadData->compilerPoolAllocator = 0;\r
+ \r
+ OS_SetTLSValue(PoolIndex, threadData); \r
+ globalPoolAllocator->push();\r
+}\r
+\r
+void FreeGlobalPools()\r
+{\r
+ // Release the allocated memory for this thread.\r
+ TThreadGlobalPools* globalPools= static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex)); \r
+ if (!globalPools)\r
+ return;\r
+ \r
+ GlobalPoolAllocator.popAll();\r
+ delete &GlobalPoolAllocator; \r
+ delete globalPools;\r
+}\r
+\r
+bool InitializePoolIndex()\r
+{\r
+ // Allocate a TLS index.\r
+ if ((PoolIndex = OS_AllocTLSIndex()) == OS_INVALID_TLS_INDEX)\r
+ return false;\r
+\r
+ return true;\r
+}\r
+\r
+void FreePoolIndex()\r
+{\r
+ // Release the TLS index.\r
+ OS_FreeTLSIndex(PoolIndex);\r
+}\r
+\r
+TPoolAllocator& GetGlobalPoolAllocator()\r
+{\r
+ TThreadGlobalPools* threadData = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));\r
+\r
+ return *threadData->globalPoolAllocator;\r
+}\r
+\r
+void SetGlobalPoolAllocatorPtr(TPoolAllocator* poolAllocator)\r
+{\r
+ TThreadGlobalPools* threadData = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));\r
+\r
+ threadData->globalPoolAllocator = poolAllocator;\r
+}\r
+\r
+PoolAllocatorPointer& GetCompilerPoolAllocator()\r
+{\r
+ TThreadGlobalPools* threadData = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));\r
+\r
+ return threadData->compilerPoolAllocator;\r
+}\r
+\r
+//\r
+// Implement the functionality of the TPoolAllocator class, which\r
+// is documented in PoolAlloc.h.\r
+//\r
+TPoolAllocator::TPoolAllocator(bool g, int growthIncrement, int allocationAlignment) : \r
+ global(g),\r
+ pageSize(growthIncrement),\r
+ alignment(allocationAlignment),\r
+ freeList(0),\r
+ inUseList(0),\r
+ numCalls(0)\r
+{\r
+ //\r
+ // Don't allow page sizes we know are smaller than all common\r
+ // OS page sizes.\r
+ //\r
+ if (pageSize < 4*1024)\r
+ pageSize = 4*1024;\r
+\r
+ //\r
+ // A large currentPageOffset indicates a new page needs to\r
+ // be obtained to allocate memory.\r
+ //\r
+ currentPageOffset = pageSize;\r
+\r
+ //\r
+ // Adjust alignment to be at least pointer aligned and\r
+ // power of 2.\r
+ //\r
+ size_t minAlign = sizeof(void*);\r
+ alignment &= ~(minAlign - 1);\r
+ if (alignment < minAlign)\r
+ alignment = minAlign;\r
+ size_t a = 1;\r
+ while (a < alignment)\r
+ a <<= 1;\r
+ alignment = a;\r
+ alignmentMask = a - 1;\r
+\r
+ //\r
+ // Align header skip\r
+ //\r
+ headerSkip = minAlign;\r
+ if (headerSkip < sizeof(tHeader)) {\r
+ headerSkip = (sizeof(tHeader) + alignmentMask) & ~alignmentMask;\r
+ }\r
+\r
+ //\r
+ // Put a marker at the beginning of the stack. We won't \r
+ // pop() past this.\r
+ //\r
+ tAllocState start = { currentPageOffset, 0 };\r
+ stack.push_back(start);\r
+}\r
+\r
+TPoolAllocator::~TPoolAllocator()\r
+{\r
+ if (!global) {\r
+ //\r
+ // Then we know that this object is not being \r
+ // allocated after other, globally scoped objects\r
+ // that depend on it. So we can delete the "in use" memory.\r
+ //\r
+ while (inUseList) {\r
+ tHeader* next = inUseList->nextPage;\r
+ inUseList->~tHeader();\r
+ delete [] reinterpret_cast<char*>(inUseList);\r
+ inUseList = next;\r
+ }\r
+ }\r
+\r
+ //\r
+ // Always delete the free list memory - it can't be being\r
+ // (correctly) referenced, whether the pool allocator was\r
+ // global or not. We should not check the guard blocks\r
+ // here, because we did it already when the block was\r
+ // placed into the free list.\r
+ //\r
+ while (freeList) {\r
+ tHeader* next = freeList->nextPage;\r
+ delete [] reinterpret_cast<char*>(freeList);\r
+ freeList = next;\r
+ }\r
+}\r
+\r
+\r
+//\r
+// Check a single guard block for damage\r
+//\r
+void TAllocation::checkGuardBlock(unsigned char* blockMem, unsigned char val, char* locText) const\r
+{\r
+ for (int x = 0; x < guardBlockSize; x++) {\r
+ if (blockMem[x] != val) {\r
+ char assertMsg[80];\r
+\r
+ // We don't print the assert message. It's here just to be helpful.\r
+ sprintf(assertMsg, "PoolAlloc: Damage %s %lu byte allocation at 0x%p\n",\r
+ locText, size, data());\r
+ assert(0 && "PoolAlloc: Damage in guard block");\r
+ }\r
+ }\r
+}\r
+\r
+\r
+void TPoolAllocator::push()\r
+{\r
+ tAllocState state = { currentPageOffset, inUseList };\r
+\r
+ stack.push_back(state);\r
+ \r
+ //\r
+ // Indicate there is no current page to allocate from.\r
+ //\r
+ currentPageOffset = pageSize;\r
+}\r
+\r
+//\r
+// Do a mass-deallocation of all the individual allocations\r
+// that have occurred since the last push(), or since the\r
+// last pop(), or since the object's creation.\r
+//\r
+// The deallocated pages are saved for future allocations.\r
+//\r
+void TPoolAllocator::pop()\r
+{\r
+ if (stack.size() < 1)\r
+ return;\r
+\r
+ tHeader* page = stack.back().page;\r
+ currentPageOffset = stack.back().offset;\r
+\r
+ while (inUseList != page) {\r
+ // invoke destructor to free allocation list\r
+ inUseList->~tHeader();\r
+ \r
+ tHeader* nextInUse = inUseList->nextPage;\r
+ if (inUseList->pageCount > 1)\r
+ delete [] reinterpret_cast<char*>(inUseList);\r
+ else {\r
+ inUseList->nextPage = freeList;\r
+ freeList = inUseList;\r
+ }\r
+ inUseList = nextInUse;\r
+ }\r
+\r
+ stack.pop_back();\r
+}\r
+\r
+//\r
+// Do a mass-deallocation of all the individual allocations\r
+// that have occurred.\r
+//\r
+void TPoolAllocator::popAll()\r
+{\r
+ while (stack.size() > 0)\r
+ pop();\r
+}\r
+\r
+void* TPoolAllocator::allocate(size_t numBytes)\r
+{\r
+ // If we are using guard blocks, all allocations are bracketed by\r
+ // them: [guardblock][allocation][guardblock]. numBytes is how\r
+ // much memory the caller asked for. allocationSize is the total\r
+ // size including guard blocks. In release build,\r
+ // guardBlockSize=0 and this all gets optimized away.\r
+ size_t allocationSize = TAllocation::allocationSize(numBytes);\r
+ \r
+ //\r
+ // Just keep some interesting statistics.\r
+ //\r
+ ++numCalls;\r
+ totalBytes += numBytes;\r
+\r
+ //\r
+ // Do the allocation, most likely case first, for efficiency.\r
+ // This step could be moved to be inline sometime.\r
+ //\r
+ if (currentPageOffset + allocationSize <= pageSize) {\r
+ //\r
+ // Safe to allocate from currentPageOffset.\r
+ //\r
+ unsigned char* memory = reinterpret_cast<unsigned char *>(inUseList) + currentPageOffset;\r
+ currentPageOffset += allocationSize;\r
+ currentPageOffset = (currentPageOffset + alignmentMask) & ~alignmentMask;\r
+\r
+ return initializeAllocation(inUseList, memory, numBytes);\r
+ }\r
+\r
+ if (allocationSize + headerSkip > pageSize) {\r
+ //\r
+ // Do a multi-page allocation. Don't mix these with the others.\r
+ // The OS is efficient and allocating and free-ing multiple pages.\r
+ //\r
+ size_t numBytesToAlloc = allocationSize + headerSkip;\r
+ tHeader* memory = reinterpret_cast<tHeader*>(::new char[numBytesToAlloc]);\r
+ if (memory == 0)\r
+ return 0;\r
+\r
+ // Use placement-new to initialize header\r
+ new(memory) tHeader(inUseList, (numBytesToAlloc + pageSize - 1) / pageSize);\r
+ inUseList = memory;\r
+\r
+ currentPageOffset = pageSize; // make next allocation come from a new page\r
+\r
+ // No guard blocks for multi-page allocations (yet)\r
+ return reinterpret_cast<void*>(reinterpret_cast<UINT_PTR>(memory) + headerSkip);\r
+ }\r
+\r
+ //\r
+ // Need a simple page to allocate from.\r
+ //\r
+ tHeader* memory;\r
+ if (freeList) {\r
+ memory = freeList;\r
+ freeList = freeList->nextPage;\r
+ } else {\r
+ memory = reinterpret_cast<tHeader*>(::new char[pageSize]);\r
+ if (memory == 0)\r
+ return 0;\r
+ }\r
+\r
+ // Use placement-new to initialize header\r
+ new(memory) tHeader(inUseList, 1);\r
+ inUseList = memory;\r
+ \r
+ unsigned char* ret = reinterpret_cast<unsigned char *>(inUseList) + headerSkip;\r
+ currentPageOffset = (headerSkip + allocationSize + alignmentMask) & ~alignmentMask;\r
+\r
+ return initializeAllocation(inUseList, ret, numBytes);\r
+}\r
+\r
+\r
+//\r
+// Check all allocations in a list for damage by calling check on each.\r
+//\r
+void TAllocation::checkAllocList() const\r
+{\r
+ for (const TAllocation* alloc = this; alloc != 0; alloc = alloc->prevAlloc)\r
+ alloc->check();\r
+}\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#include "../Include/intermediate.h"\r
+\r
+class TAliveTraverser : public TIntermTraverser {\r
+public:\r
+ TAliveTraverser(TQualifier q) : TIntermTraverser(), found(false), qualifier(q)\r
+ {\r
+ visitSymbol = AliveSymbol;\r
+ visitSelection = AliveSelection;\r
+ rightToLeft = true;\r
+ }\r
+ bool wasFound() { return found; }\r
+protected:\r
+ bool found;\r
+ TQualifier qualifier;\r
+\r
+ friend void AliveSymbol(TIntermSymbol*, TIntermTraverser*);\r
+ friend bool AliveSelection(bool, TIntermSelection*, TIntermTraverser*);\r
+};\r
+\r
+//\r
+// Report whether or not a variable of the given qualifier type\r
+// is guaranteed written. Not always possible to determine if\r
+// it is written conditionally.\r
+//\r
+// ?? It does not do this well yet, this is just a place holder\r
+// that simply determines if it was reference at all, anywhere.\r
+//\r
+bool QualifierWritten(TIntermNode* node, TQualifier qualifier)\r
+{\r
+ TAliveTraverser it(qualifier);\r
+\r
+ if (node)\r
+ node->traverse(&it);\r
+\r
+ return it.wasFound();\r
+}\r
+\r
+void AliveSymbol(TIntermSymbol* node, TIntermTraverser* it)\r
+{\r
+ TAliveTraverser* lit = static_cast<TAliveTraverser*>(it);\r
+\r
+ //\r
+ // If it's what we're looking for, record it.\r
+ //\r
+ if (node->getQualifier() == lit->qualifier)\r
+ lit->found = true;\r
+}\r
+\r
+bool AliveSelection(bool preVisit, TIntermSelection* node, TIntermTraverser* it)\r
+{\r
+ TAliveTraverser* lit = static_cast<TAliveTraverser*>(it);\r
+\r
+ if (lit->wasFound())\r
+ return false;\r
+\r
+ return true;\r
+}\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+bool QualifierWritten(TIntermNode* root, TQualifier);\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#include "../Include/intermediate.h"\r
+#include "RemoveTree.h"\r
+//\r
+// Code to recursively delete the intermediate tree.\r
+//\r
+\r
+void RemoveSymbol(TIntermSymbol* node, TIntermTraverser* it)\r
+{\r
+ delete node;\r
+}\r
+\r
+bool RemoveBinary(bool /*preVisit*/ , TIntermBinary* node, TIntermTraverser*)\r
+{\r
+ delete node;\r
+\r
+ return true;\r
+}\r
+\r
+bool RemoveUnary(bool /*preVisit */, TIntermUnary* node, TIntermTraverser*)\r
+{\r
+ delete node;\r
+\r
+ return true;\r
+}\r
+\r
+bool RemoveAggregate(bool /*preVisit*/ , TIntermAggregate* node, TIntermTraverser*)\r
+{\r
+ delete node;\r
+\r
+ return true;\r
+}\r
+\r
+bool RemoveSelection(bool /*preVisit*/ , TIntermSelection* node, TIntermTraverser*)\r
+{\r
+ delete node;\r
+\r
+ return true;\r
+}\r
+\r
+void RemoveConstantUnion(TIntermConstantUnion* node, TIntermTraverser*)\r
+{\r
+ delete node;\r
+}\r
+\r
+//\r
+// Entry point.\r
+//\r
+void RemoveAllTreeNodes(TIntermNode* root)\r
+{\r
+ TIntermTraverser it;\r
+\r
+ it.visitAggregate = RemoveAggregate;\r
+ it.visitBinary = RemoveBinary;\r
+ it.visitConstantUnion = RemoveConstantUnion;\r
+ it.visitSelection = RemoveSelection;\r
+ it.visitSymbol = RemoveSymbol;\r
+ it.visitUnary = RemoveUnary;\r
+\r
+ it.preVisit = false;\r
+ it.postVisit = true;\r
+\r
+ root->traverse(&it);\r
+}\r
+\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+void RemoveAllTreeNodes(TIntermNode*);\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+//\r
+// Implement the top-level of interface to the compiler/linker,\r
+// as defined in ShaderLang.h\r
+//\r
+#include "SymbolTable.h"\r
+#include "ParseHelper.h"\r
+#include "../Include/ShHandle.h"\r
+#include "Initialisation.h"\r
+\r
+#define SH_EXPORTING\r
+#include "../Public/ShaderLangExt.h"\r
+\r
+#include "Include/ResourceLimits.h"\r
+#include "Initialize.h"\r
+\r
+extern "C" int InitPreprocessor(void);\r
+extern "C" int FinalizePreprocessor(void);\r
+extern void SetGlobalPoolAllocatorPtr(TPoolAllocator* poolAllocator);\r
+\r
+bool generateBuiltInSymbolTable(TBuiltInResource& resources, TInfoSink&);\r
+bool initializeSymbolTable(TBuiltInStrings* BuiltInStrings, EShLanguage language, TInfoSink& infoSink, TBuiltInResource &resources);\r
+void GenerateResources(TBuiltInResource& resources);\r
+\r
+TPoolAllocator* PerProcessGPA = 0;\r
+//\r
+// This is the platform independent interface between an OGL driver\r
+// and the shading language compiler/linker.\r
+//\r
+\r
+//\r
+// Driver must call this first, once, before doing any other\r
+// compiler/linker operations.\r
+//\r
+int ShInitialize()\r
+{\r
+ TInfoSink infoSink;\r
+ TBuiltInResource resources;\r
+ GenerateResources(resources);\r
+ bool ret = true;\r
+\r
+ if (!InitProcess())\r
+ return 0;\r
+\r
+ // This method should be called once per process. If its called by multiple threads, then \r
+ // we need to have thread synchronization code around the initialization of per process\r
+ // global pool allocator\r
+ if (!PerProcessGPA) { \r
+ PerProcessGPA = new TPoolAllocator(true);\r
+ PerProcessGPA->push();\r
+ \r
+ TPoolAllocator* gPoolAllocator = &GlobalPoolAllocator;\r
+ SetGlobalPoolAllocatorPtr(PerProcessGPA); \r
+ ret = generateBuiltInSymbolTable(resources, infoSink);\r
+ SetGlobalPoolAllocatorPtr(gPoolAllocator);\r
+ }\r
+\r
+ return ret ? 1 : 0;\r
+}\r
+\r
+//\r
+// Driver calls these to create and destroy compiler/linker\r
+// objects.\r
+//\r
+\r
+ShHandle ShConstructCompiler(const EShLanguage language, int debugOptions)\r
+{\r
+ if (!InitThread())\r
+ return 0;\r
+\r
+ TShHandleBase* base = static_cast<TShHandleBase*>(ConstructCompiler(language, debugOptions));\r
+ \r
+ return reinterpret_cast<void*>(base);\r
+}\r
+\r
+ShHandle ShConstructLinker(const EShExecutable executable, int debugOptions)\r
+{\r
+ if (!InitThread())\r
+ return 0;\r
+\r
+ TShHandleBase* base = static_cast<TShHandleBase*>(ConstructLinker(executable, debugOptions));\r
+\r
+ return reinterpret_cast<void*>(base);\r
+}\r
+\r
+ShHandle ShConstructUniformMap()\r
+{\r
+ if (!InitThread())\r
+ return 0;\r
+\r
+ TShHandleBase* base = static_cast<TShHandleBase*>(ConstructUniformMap());\r
+\r
+ return reinterpret_cast<void*>(base);\r
+}\r
+\r
+void ShDestruct(ShHandle handle)\r
+{\r
+ if (handle == 0)\r
+ return;\r
+\r
+ TShHandleBase* base = static_cast<TShHandleBase*>(handle);\r
+\r
+ if (base->getAsCompiler())\r
+ DeleteCompiler(base->getAsCompiler());\r
+ else if (base->getAsLinker())\r
+ DeleteLinker(base->getAsLinker());\r
+ else if (base->getAsUniformMap())\r
+ DeleteUniformMap(base->getAsUniformMap());\r
+}\r
+\r
+//\r
+// A symbol table for each language. Each has a different\r
+// set of built-ins, and we want to preserve that from\r
+// compile to compile.\r
+//\r
+TSymbolTable SymbolTables[EShLangCount];\r
+\r
+//\r
+// Cleanup symbol tables\r
+//\r
+int __fastcall ShFinalize()\r
+{ \r
+ if (PerProcessGPA) {\r
+ PerProcessGPA->popAll();\r
+ delete PerProcessGPA;\r
+ }\r
+ return 1;\r
+}\r
+\r
+//\r
+// This method is required only for Sh interface, not for OGLC interface\r
+//\r
+void GenerateResources(TBuiltInResource& resources)\r
+{ \r
+ resources.maxLights = 32;\r
+ resources.maxClipPlanes = 6;\r
+ resources.maxTextureUnits = 32;\r
+ resources.maxTextureCoords = 32;\r
+ resources.maxVertexAttribs = 64;\r
+ resources.maxVertexUniformComponents = 4096;\r
+ resources.maxVaryingFloats = 64;\r
+ resources.maxVertexTextureImageUnits = 32;\r
+ resources.maxCombinedTextureImageUnits = 32;\r
+ resources.maxTextureImageUnits = 32;\r
+ resources.maxFragmentUniformComponents = 4096;\r
+ resources.maxDrawBuffers = 32;\r
+}\r
+\r
+//\r
+// This function should be called only once by the Master Dll. Currently, this is being called for each thread \r
+// which is incorrect. This is required to keep the Sh interface working for now and will eventually be called \r
+// from master dll once.\r
+//\r
+bool generateBuiltInSymbolTable(TBuiltInResource& resources, TInfoSink& infoSink)\r
+{\r
+ TBuiltIns builtIns;\r
+ builtIns.initialize(resources);\r
+ initializeSymbolTable(builtIns.getBuiltInStrings(), EShLangVertex, infoSink, resources);\r
+ initializeSymbolTable(builtIns.getBuiltInStrings(), EShLangFragment, infoSink, resources);\r
+ return true;\r
+}\r
+\r
+bool initializeSymbolTable(TBuiltInStrings* BuiltInStrings, EShLanguage language, TInfoSink& infoSink, TBuiltInResource &resources)\r
+{\r
+ TIntermediate intermediate(infoSink);\r
+ TSymbolTable& symbolTable = SymbolTables[language];\r
+ TParseContext parseContext(symbolTable, intermediate, language, infoSink);\r
+\r
+ GlobalParseContext = &parseContext;\r
+ \r
+ setInitialState();\r
+\r
+ if (symbolTable.isEmpty()) {\r
+ \r
+ //\r
+ // Parse the built-ins. This should only happen once per\r
+ // language symbol table.\r
+ //\r
+ // Push the symbol table to give it an initial scope. This\r
+ // push should not have a corresponding pop, so that built-ins\r
+ // are preserved, and the test for an empty table fails.\r
+ //\r
+\r
+ symbolTable.push();\r
+ \r
+ //Initialize the Preprocessor\r
+ int ret = InitPreprocessor();\r
+ if (ret) {\r
+ infoSink.info.message(EPrefixInternalError, "Unable to intialize the Preprocessor");\r
+ return false;\r
+ }\r
+ \r
+ for (TBuiltInStrings::iterator i = BuiltInStrings[parseContext.language].begin();\r
+ i != BuiltInStrings[parseContext.language].end();\r
+ ++i) {\r
+ const char* builtInShaders[1];\r
+ int builtInLengths[1];\r
+\r
+ builtInShaders[0] = (*i).c_str();\r
+ builtInLengths[0] = (int) (*i).size();\r
+\r
+ if (PaParseStrings(const_cast<char**>(builtInShaders), builtInLengths, 1, parseContext) != 0) {\r
+ infoSink.info.message(EPrefixInternalError, "Unable to parse built-ins");\r
+ return false;\r
+ }\r
+ }\r
+\r
+ IdentifyBuiltIns(parseContext.language, symbolTable, resources);\r
+ FinalizePreprocessor();\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+\r
+//\r
+// Do an actual compile on the given strings. The result is left \r
+// in the given compile object.\r
+//\r
+// Return: The return value of ShCompile is really boolean, indicating\r
+// success or failure.\r
+//\r
+int ShCompile(\r
+ const ShHandle handle,\r
+ const char* const shaderStrings[],\r
+ const int numStrings,\r
+ const EShOptimizationLevel optLevel,\r
+ int debugOptions\r
+ )\r
+{\r
+ if (!InitThread())\r
+ return 0;\r
+\r
+ if (handle == 0)\r
+ return 0;\r
+\r
+ TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);\r
+ TCompiler* compiler = base->getAsCompiler();\r
+ if (compiler == 0)\r
+ return 0;\r
+\r
+ compiler->infoSink.info.erase();\r
+ compiler->infoSink.debug.erase();\r
+\r
+ if (numStrings == 0)\r
+ return 1;\r
+\r
+ TIntermediate intermediate(compiler->infoSink);\r
+ TSymbolTable symbolTable(SymbolTables[compiler->getLanguage()]);\r
+ TParseContext parseContext(symbolTable, intermediate, compiler->getLanguage(), compiler->infoSink);\r
+ parseContext.initializeExtensionBehavior();\r
+\r
+ GlobalParseContext = &parseContext;\r
+ \r
+ setInitialState();\r
+\r
+ InitPreprocessor(); \r
+ //\r
+ // Parse the application's shaders. All the following symbol table\r
+ // work will be throw-away, so push a new allocation scope that can\r
+ // be thrown away, then push a scope for the current shader's globals.\r
+ //\r
+ bool success = true;\r
+ GlobalPoolAllocator.push();\r
+ symbolTable.push();\r
+ if (!symbolTable.atGlobalLevel())\r
+ parseContext.infoSink.info.message(EPrefixInternalError, "Wrong symbol table level");\r
+\r
+ if (parseContext.insertBuiltInArrayAtGlobalLevel())\r
+ success = false;\r
+\r
+ int ret = PaParseStrings(const_cast<char**>(shaderStrings), 0, numStrings, parseContext);\r
+ if (ret)\r
+ success = false;\r
+\r
+ if (! ret && parseContext.treeRoot) {\r
+ if (parseContext.recoveredFromError) {\r
+ parseContext.infoSink.info.prefix(EPrefixError);\r
+ parseContext.infoSink.info << parseContext.numErrors << " compilation errors. No code generated.\n\n";\r
+ success = false;\r
+ if (debugOptions & EDebugOpIntermediate)\r
+ intermediate.outputTree(parseContext.treeRoot);\r
+ } else {\r
+ if (optLevel == EShOptNoGeneration)\r
+ parseContext.infoSink.info.message(EPrefixNone, "No errors. No code generation or linking was requested.");\r
+ else {\r
+ success = intermediate.postProcess(parseContext.treeRoot, parseContext.language);\r
+\r
+ if (success) {\r
+\r
+ if (debugOptions & EDebugOpIntermediate)\r
+ intermediate.outputTree(parseContext.treeRoot);\r
+\r
+ //\r
+ // Call the machine dependent compiler\r
+ //\r
+ if (! compiler->compile(parseContext.treeRoot))\r
+ success = false;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ intermediate.remove(parseContext.treeRoot);\r
+\r
+ //\r
+ // Ensure symbol table is returned to the built-in level,\r
+ // throwing away all but the built-ins.\r
+ //\r
+ while (! symbolTable.atBuiltInLevel())\r
+ symbolTable.pop();\r
+\r
+ FinalizePreprocessor();\r
+ //\r
+ // Throw away all the temporary memory used by the compilation process.\r
+ //\r
+ GlobalPoolAllocator.pop();\r
+\r
+ return success ? 1 : 0;\r
+}\r
+\r
+//\r
+// Do an actual link on the given compile objects.\r
+//\r
+// Return: The return value of is really boolean, indicating\r
+// success or failure.\r
+//\r
+int ShLink(\r
+ const ShHandle linkHandle,\r
+ const ShHandle compHandles[],\r
+ const int numHandles,\r
+ ShHandle uniformMapHandle,\r
+ short int** uniformsAccessed,\r
+ int* numUniformsAccessed)\r
+\r
+{\r
+ if (!InitThread())\r
+ return 0;\r
+\r
+ TShHandleBase* base = reinterpret_cast<TShHandleBase*>(linkHandle);\r
+ TLinker* linker = static_cast<TLinker*>(base->getAsLinker());\r
+ if (linker == 0)\r
+ return 0;\r
+\r
+ int returnValue;\r
+ GlobalPoolAllocator.push();\r
+ returnValue = ShLinkExt(linkHandle, compHandles, numHandles);\r
+ GlobalPoolAllocator.pop();\r
+\r
+ if (returnValue)\r
+ return 1;\r
+\r
+ return 0;\r
+}\r
+//\r
+// This link method will be eventually used once the ICD supports the new linker interface\r
+//\r
+int ShLinkExt(\r
+ const ShHandle linkHandle,\r
+ const ShHandle compHandles[],\r
+ const int numHandles)\r
+{\r
+ if (linkHandle == 0 || numHandles == 0)\r
+ return 0;\r
+\r
+ THandleList cObjects;\r
+ int i;\r
+\r
+ for (i = 0; i < numHandles; ++i) {\r
+ if (compHandles[i] == 0)\r
+ return 0;\r
+ TShHandleBase* base = reinterpret_cast<TShHandleBase*>(compHandles[i]);\r
+ if (base->getAsLinker()) {\r
+ cObjects.push_back(base->getAsLinker());\r
+ }\r
+ if (base->getAsCompiler())\r
+ cObjects.push_back(base->getAsCompiler());\r
+\r
+\r
+ if (cObjects[i] == 0)\r
+ return 0;\r
+ }\r
+\r
+ TShHandleBase* base = reinterpret_cast<TShHandleBase*>(linkHandle);\r
+ TLinker* linker = static_cast<TLinker*>(base->getAsLinker());\r
+\r
+ if (linker == 0)\r
+ return 0;\r
+\r
+ linker->infoSink.info.erase();\r
+\r
+ for (i = 0; i < numHandles; ++i) {\r
+ if (cObjects[i]->getAsCompiler()) {\r
+ if (! cObjects[i]->getAsCompiler()->linkable()) {\r
+ linker->infoSink.info.message(EPrefixError, "Not all shaders have valid object code."); \r
+ return 0;\r
+ }\r
+ }\r
+ }\r
+\r
+ bool ret = linker->link(cObjects);\r
+\r
+ return ret ? 1 : 0;\r
+}\r
+\r
+//\r
+// ShSetEncrpytionMethod is a place-holder for specifying\r
+// how source code is encrypted.\r
+//\r
+void ShSetEncryptionMethod(ShHandle handle)\r
+{\r
+ if (handle == 0)\r
+ return;\r
+}\r
+\r
+//\r
+// Return any compiler/linker/uniformmap log of messages for the application.\r
+//\r
+const char* ShGetInfoLog(const ShHandle handle)\r
+{\r
+ if (!InitThread())\r
+ return 0;\r
+\r
+ if (handle == 0)\r
+ return 0;\r
+\r
+ TShHandleBase* base = static_cast<TShHandleBase*>(handle);\r
+ TInfoSink* infoSink;\r
+\r
+ if (base->getAsCompiler())\r
+ infoSink = &(base->getAsCompiler()->getInfoSink());\r
+ else if (base->getAsLinker())\r
+ infoSink = &(base->getAsLinker()->getInfoSink());\r
+\r
+ infoSink->info << infoSink->debug.c_str();\r
+ return infoSink->info.c_str();\r
+}\r
+\r
+//\r
+// Return the resulting binary code from the link process. Structure\r
+// is machine dependent.\r
+//\r
+const void* ShGetExecutable(const ShHandle handle)\r
+{\r
+ if (!InitThread())\r
+ return 0;\r
+\r
+ if (handle == 0)\r
+ return 0;\r
+\r
+ TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);\r
+ \r
+ TLinker* linker = static_cast<TLinker*>(base->getAsLinker());\r
+ if (linker == 0)\r
+ return 0;\r
+\r
+ return linker->getObjectCode();\r
+}\r
+\r
+//\r
+// Let the linker know where the application said it's attributes are bound.\r
+// The linker does not use these values, they are remapped by the ICD or\r
+// hardware. It just needs them to know what's aliased.\r
+//\r
+// Return: The return value of is really boolean, indicating\r
+// success or failure.\r
+//\r
+// This is to preserve the old linker API, P20 code can use the generic \r
+// ShConstructBinding() and ShAddBinding() APIs\r
+//\r
+int ShSetVirtualAttributeBindings(const ShHandle handle, const ShBindingTable* table)\r
+{ \r
+ if (!InitThread())\r
+ return 0;\r
+\r
+ if (handle == 0)\r
+ return 0;\r
+\r
+ TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);\r
+ TLinker* linker = static_cast<TLinker*>(base->getAsLinker());\r
+\r
+ if (linker == 0)\r
+ return 0;\r
+ \r
+ linker->setAppAttributeBindings(table);\r
+\r
+ return 1;\r
+}\r
+\r
+//\r
+// Let the linker know where the predefined attributes have to live.\r
+// This is to preserve the old linker API, P20 code can use the generic \r
+// ShConstructBinding() and ShAddBinding() APIs\r
+//\r
+int ShSetFixedAttributeBindings(const ShHandle handle, const ShBindingTable* table)\r
+{\r
+ if (!InitThread())\r
+ return 0;\r
+\r
+ if (handle == 0)\r
+ return 0;\r
+\r
+ TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);\r
+ TLinker* linker = static_cast<TLinker*>(base->getAsLinker());\r
+\r
+ if (linker == 0)\r
+ return 0;\r
+\r
+ linker->setFixedAttributeBindings(table);\r
+ return 1;\r
+}\r
+\r
+//\r
+// Some attribute locations are off-limits to the linker...\r
+//\r
+int ShExcludeAttributes(const ShHandle handle, int *attributes, int count)\r
+{\r
+ if (!InitThread())\r
+ return 0;\r
+\r
+ if (handle == 0)\r
+ return 0;\r
+\r
+ TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);\r
+ TLinker* linker = static_cast<TLinker*>(base->getAsLinker());\r
+ if (linker == 0)\r
+ return 0;\r
+\r
+ linker->setExcludedAttributes(attributes, count);\r
+\r
+ return 1;\r
+}\r
+\r
+//\r
+// Return the index for OpenGL to use for knowing where a uniform lives.\r
+//\r
+// Return: The return value of is really boolean, indicating\r
+// success or failure.\r
+//\r
+// We dont have to change this code for now since the TUniformMap being\r
+// passed back to ICD by the linker is the same as being used for the old P10 linker\r
+//\r
+int ShGetUniformLocation(const ShHandle handle, const char* name)\r
+{\r
+ if (!InitThread())\r
+ return 0;\r
+\r
+ if (handle == 0)\r
+ return -1;\r
+\r
+ TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);\r
+ TUniformMap* uniformMap= base->getAsUniformMap();\r
+ if (uniformMap == 0)\r
+ return -1;\r
+\r
+ return uniformMap->getLocation(name);\r
+}\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+//\r
+// Symbol table for parsing. Most functionaliy and main ideas \r
+// are documented in the header file.\r
+//\r
+\r
+#include "SymbolTable.h"\r
+\r
+//\r
+// TType helper function needs a place to live.\r
+//\r
+\r
+//\r
+// Recursively generate mangled names.\r
+//\r
+void TType::buildMangledName(TString& mangledName)\r
+{\r
+ if (isMatrix())\r
+ mangledName += 'm';\r
+ else if (isVector())\r
+ mangledName += 'v';\r
+\r
+ unsigned int i;\r
+\r
+ switch (type) {\r
+ case EbtFloat: mangledName += 'f'; break;\r
+ case EbtInt: mangledName += 'i'; break;\r
+ case EbtBool: mangledName += 'b'; break;\r
+ case EbtSampler1D: mangledName += "s1"; break;\r
+ case EbtSampler2D: mangledName += "s2"; break;\r
+ case EbtSampler3D: mangledName += "s3"; break;\r
+ case EbtSamplerCube: mangledName += "sC"; break;\r
+ case EbtSampler1DShadow: mangledName += "sS1"; break;\r
+ case EbtSampler2DShadow: mangledName += "sS2"; break;\r
+ case EbtStruct:\r
+ mangledName += "struct-";\r
+ mangledName += typeName;\r
+ for (i = 0; i < structure->size(); ++i) {\r
+ mangledName += '-';\r
+ (*structure)[i].type->buildMangledName(mangledName);\r
+ }\r
+ default: \r
+ break;\r
+ }\r
+\r
+ mangledName += static_cast<char>('0' + getNominalSize());\r
+ if (isArray()) {\r
+ char buf[10];\r
+ sprintf(buf, "%d", arraySize);\r
+ mangledName += '[';\r
+ mangledName += buf;\r
+ mangledName += ']';\r
+ }\r
+}\r
+\r
+//\r
+// Dump functions.\r
+//\r
+\r
+void TVariable::dump(TInfoSink& infoSink) const \r
+{\r
+ infoSink.debug << getName().c_str() << ": " << type.getQualifierString() << " " << type.getBasicString();\r
+ if (type.isArray()) {\r
+ infoSink.debug << "[0]";\r
+ }\r
+ infoSink.debug << "\n";\r
+}\r
+\r
+void TFunction::dump(TInfoSink &infoSink) const\r
+{\r
+ infoSink.debug << getName().c_str() << ": " << returnType.getBasicString() << " " << getMangledName().c_str() << "\n";\r
+}\r
+\r
+void TSymbolTableLevel::dump(TInfoSink &infoSink) const \r
+{\r
+ tLevel::const_iterator it;\r
+ for (it = level.begin(); it != level.end(); ++it)\r
+ (*it).second->dump(infoSink);\r
+}\r
+\r
+void TSymbolTable::dump(TInfoSink &infoSink) const\r
+{\r
+ for (int level = currentLevel(); level >= 0; --level) {\r
+ infoSink.debug << "LEVEL " << level << "\n";\r
+ table[level]->dump(infoSink);\r
+ }\r
+}\r
+\r
+//\r
+// Functions have buried pointers to delete.\r
+//\r
+TFunction::~TFunction()\r
+{\r
+ for (TParamList::iterator i = parameters.begin(); i != parameters.end(); ++i)\r
+ delete (*i).type;\r
+}\r
+\r
+//\r
+// Symbol table levels are a map of pointers to symbols that have to be deleted.\r
+//\r
+TSymbolTableLevel::~TSymbolTableLevel()\r
+{\r
+ for (tLevel::iterator it = level.begin(); it != level.end(); ++it)\r
+ delete (*it).second;\r
+}\r
+\r
+//\r
+// Change all function entries in the table with the non-mangled name\r
+// to be related to the provided built-in operation. This is a low\r
+// performance operation, and only intended for symbol tables that\r
+// live across a large number of compiles.\r
+//\r
+void TSymbolTableLevel::relateToOperator(const char* name, TOperator op) \r
+{\r
+ tLevel::iterator it;\r
+ for (it = level.begin(); it != level.end(); ++it) {\r
+ if ((*it).second->isFunction()) {\r
+ TFunction* function = static_cast<TFunction*>((*it).second);\r
+ if (function->getName() == name)\r
+ function->relateToOperator(op);\r
+ }\r
+ }\r
+} \r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#ifndef _SYMBOL_TABLE_INCLUDED_\r
+#define _SYMBOL_TABLE_INCLUDED_\r
+\r
+//\r
+// Symbol table for parsing. Has these design characteristics:\r
+//\r
+// * Same symbol table can be used to compile many shaders, to preserve\r
+// effort of creating and loading with the large numbers of built-in\r
+// symbols.\r
+//\r
+// * Name mangling will be used to give each function a unique name\r
+// so that symbol table lookups are never ambiguous. This allows\r
+// a simpler symbol table structure.\r
+//\r
+// * Pushing and popping of scope, so symbol table will really be a stack \r
+// of symbol tables. Searched from the top, with new inserts going into\r
+// the top.\r
+//\r
+// * Constants: Compile time constant symbols will keep their values\r
+// in the symbol table. The parser can substitute constants at parse\r
+// time, including doing constant folding and constant propagation.\r
+//\r
+// * No temporaries: Temporaries made from operations (+, --, .xy, etc.)\r
+// are tracked in the intermediate representation, not the symbol table.\r
+//\r
+\r
+#include "Include/Common.h"\r
+#include "Include/intermediate.h"\r
+#include "Include/InfoSink.h"\r
+ \r
+//\r
+// Symbol base class. (Can build functions or variables out of these...)\r
+//\r
+class TSymbol { \r
+public:\r
+ POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)\r
+ TSymbol(const TString *n) : name(n) { }\r
+ virtual ~TSymbol() { /* don't delete name, it's from the pool */ }\r
+ const TString& getName() const { return *name; }\r
+ virtual const TString& getMangledName() const { return getName(); }\r
+ virtual bool isFunction() const { return false; }\r
+ virtual bool isVariable() const { return false; }\r
+ void setUniqueId(int id) { uniqueId = id; }\r
+ int getUniqueId() const { return uniqueId; }\r
+ virtual void dump(TInfoSink &infoSink) const = 0;\r
+\r
+protected:\r
+ const TString *name;\r
+ unsigned int uniqueId; // For real comparing during code generation\r
+};\r
+\r
+//\r
+// Variable class, meaning a symbol that's not a function.\r
+// \r
+// There could be a separate class heirarchy for Constant variables;\r
+// Only one of int, bool, or float, (or none) is correct for\r
+// any particular use, but it's easy to do this way, and doesn't\r
+// seem worth having separate classes, and "getConst" can't simply return\r
+// different values for different types polymorphically, so this is \r
+// just simple and pragmatic.\r
+//\r
+class TVariable : public TSymbol {\r
+public:\r
+ TVariable(const TString *name, TType t, bool uT = false ) : TSymbol(name), type(t), userType(uT), unionArray(0), arrayInformationType(0) { }\r
+ virtual ~TVariable() { }\r
+ virtual bool isVariable() const { return true; } \r
+ TType& getType() { return type; } \r
+ const TType getType() const { return type; }\r
+ bool isUserType() const { return userType; }\r
+ void changeQualifier(TQualifier qualifier) { type.changeQualifier(qualifier); }\r
+ void updateArrayInformationType(TType *t) { arrayInformationType = t; }\r
+ TType* getArrayInformationType() { return arrayInformationType; }\r
+\r
+ virtual void dump(TInfoSink &infoSink) const;\r
+\r
+ constUnion* getConstPointer() { \r
+ if (!unionArray) {\r
+ if (!type.getStruct())\r
+ unionArray = new constUnion[type.getInstanceSize()];\r
+ else\r
+ unionArray = new constUnion[type.getStructSize()];\r
+ }\r
+ return unionArray;\r
+ }\r
+\r
+ constUnion* getConstPointer() const { return unionArray; }\r
+\r
+ void shareConstPointer( constUnion *constArray)\r
+ {\r
+ delete unionArray;\r
+ unionArray = constArray; \r
+ }\r
+ \r
+protected:\r
+ TType type;\r
+ bool userType;\r
+ // we are assuming that Pool Allocator will free the memory allocated to unionArray\r
+ // when this object is destroyed\r
+ constUnion *unionArray;\r
+ TType *arrayInformationType; // this is used for updating maxArraySize in all the references to a given symbol\r
+};\r
+\r
+//\r
+// The function sub-class of symbols and the parser will need to\r
+// share this definition of a function parameter.\r
+//\r
+struct TParameter {\r
+ TString *name;\r
+ TType* type;\r
+};\r
+\r
+//\r
+// The function sub-class of a symbol. \r
+//\r
+class TFunction : public TSymbol {\r
+public:\r
+ TFunction(TOperator o) :\r
+ TSymbol(0),\r
+ returnType(TType(EbtVoid)),\r
+ op(o),\r
+ defined(false) { }\r
+ TFunction(const TString *name, TType retType, TOperator tOp = EOpNull) : \r
+ TSymbol(name), \r
+ returnType(retType),\r
+ mangledName(*name + '('),\r
+ op(tOp),\r
+ defined(false) { }\r
+ virtual ~TFunction();\r
+ virtual bool isFunction() const { return true; } \r
+ \r
+ void addParameter(TParameter& p) \r
+ { \r
+ parameters.push_back(p);\r
+ mangledName = mangledName + p.type->getMangledName();\r
+ }\r
+ \r
+ const TString& getMangledName() const { return mangledName; }\r
+ const TType& getReturnType() const { return returnType; }\r
+ void relateToOperator(TOperator o) { op = o; }\r
+ TOperator getBuiltInOp() const { return op; }\r
+ void setDefined() { defined = true; }\r
+ bool isDefined() { return defined; }\r
+\r
+ int getParamCount() const { return static_cast<int>(parameters.size()); } \r
+ TParameter& operator [](int i) { return parameters[i]; }\r
+ const TParameter& operator [](int i) const { return parameters[i]; }\r
+ \r
+ virtual void dump(TInfoSink &infoSink) const;\r
+ \r
+protected:\r
+ typedef TVector<TParameter> TParamList;\r
+ TParamList parameters;\r
+ TType returnType;\r
+ TString mangledName;\r
+ TOperator op;\r
+ bool defined;\r
+};\r
+\r
+\r
+class TSymbolTableLevel {\r
+public:\r
+ POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)\r
+ TSymbolTableLevel() { }\r
+ ~TSymbolTableLevel();\r
+ \r
+ bool insert(TSymbol& symbol) \r
+ {\r
+ //\r
+ // returning true means symbol was added to the table\r
+ //\r
+ tInsertResult result;\r
+ result = level.insert(tLevelPair(symbol.getMangledName(), &symbol));\r
+ \r
+ return result.second;\r
+ }\r
+\r
+ TSymbol* find(const TString& name) const\r
+ {\r
+ tLevel::const_iterator it = level.find(name);\r
+ if (it == level.end())\r
+ return 0;\r
+ else\r
+ return (*it).second;\r
+ }\r
+\r
+ void relateToOperator(const char* name, TOperator op);\r
+ void dump(TInfoSink &infoSink) const; \r
+ \r
+protected:\r
+ typedef std::map<TString, TSymbol*, std::less<TString>, pool_allocator<std::pair<const TString, TSymbol*> > > tLevel;\r
+ typedef const tLevel::value_type tLevelPair;\r
+ typedef std::pair<tLevel::iterator, bool> tInsertResult;\r
+\r
+ tLevel level;\r
+};\r
+\r
+class TSymbolTable {\r
+public:\r
+ TSymbolTable() : uniqueId(0)\r
+ {\r
+ //\r
+ // The symbol table cannot be used until push() is called, but\r
+ // the lack of an initial call to push() can be used to detect\r
+ // that the symbol table has not been preloaded with built-ins.\r
+ //\r
+ }\r
+\r
+ TSymbolTable(TSymbolTable& symTable)\r
+ {\r
+ table.push_back(symTable.table[0]);\r
+ uniqueId = symTable.uniqueId;\r
+ }\r
+\r
+ ~TSymbolTable()\r
+ {\r
+ // level 0 is always built In symbols, so we never pop that out\r
+ while (table.size() > 1)\r
+ pop();\r
+ }\r
+\r
+ //\r
+ // When the symbol table is initialized with the built-ins, there should\r
+ // 'push' calls, so that built-ins are at level 0 and the shader\r
+ // globals are at level 1.\r
+ //\r
+ bool isEmpty() { return table.size() == 0; }\r
+ bool atBuiltInLevel() { return table.size() == 1; }\r
+ bool atGlobalLevel() { return table.size() <= 2; }\r
+ void push() { \r
+ table.push_back(new TSymbolTableLevel);\r
+ }\r
+\r
+ void pop() { \r
+ delete table[currentLevel()]; \r
+ table.pop_back(); \r
+ }\r
+\r
+ bool insert(TSymbol& symbol)\r
+ {\r
+ symbol.setUniqueId(++uniqueId);\r
+ return table[currentLevel()]->insert(symbol);\r
+ }\r
+ \r
+ TSymbol* find(const TString& name, bool* builtIn = 0, bool *sameScope = 0) \r
+ {\r
+ int level = currentLevel();\r
+ TSymbol* symbol;\r
+ do {\r
+ symbol = table[level]->find(name);\r
+ --level;\r
+ } while (symbol == 0 && level >= 0);\r
+ level++;\r
+ if (builtIn)\r
+ *builtIn = level == 0;\r
+ if (sameScope)\r
+ *sameScope = level == currentLevel();\r
+ return symbol;\r
+ }\r
+\r
+ void relateToOperator(const char* name, TOperator op) { table[0]->relateToOperator(name, op); }\r
+ int getMaxSymbolId() { return uniqueId; }\r
+ void dump(TInfoSink &infoSink) const; \r
+\r
+protected: \r
+ int currentLevel() const { return static_cast<int>(table.size()) - 1; }\r
+\r
+ std::vector<TSymbolTableLevel*> table;\r
+ int uniqueId; // for unique identification in code generation\r
+};\r
+\r
+#endif // _SYMBOL_TABLE_INCLUDED_\r
--- /dev/null
+typedef union {\r
+ struct {\r
+ TSourceLoc line;\r
+ union {\r
+ TString *string;\r
+ float f;\r
+ int i;\r
+ bool b;\r
+ };\r
+ TSymbol* symbol;\r
+ } lex;\r
+ struct {\r
+ TSourceLoc line;\r
+ TOperator op;\r
+ union {\r
+ TIntermNode* intermNode;\r
+ TIntermNodePair nodePair;\r
+ TIntermTyped* intermTypedNode;\r
+ TIntermAggregate* intermAggregate;\r
+ };\r
+ union {\r
+ TPublicType type;\r
+ TQualifier qualifier;\r
+ TFunction* function;\r
+ TParameter param;\r
+ TTypeLine typeLine;\r
+ TTypeList* typeList;\r
+ };\r
+ } interm;\r
+} YYSTYPE;\r
+#define ATTRIBUTE 258\r
+#define CONST_QUAL 259\r
+#define BOOL_TYPE 260\r
+#define FLOAT_TYPE 261\r
+#define INT_TYPE 262\r
+#define BREAK 263\r
+#define CONTINUE 264\r
+#define DO 265\r
+#define ELSE 266\r
+#define FOR 267\r
+#define IF 268\r
+#define DISCARD 269\r
+#define RETURN 270\r
+#define BVEC2 271\r
+#define BVEC3 272\r
+#define BVEC4 273\r
+#define IVEC2 274\r
+#define IVEC3 275\r
+#define IVEC4 276\r
+#define VEC2 277\r
+#define VEC3 278\r
+#define VEC4 279\r
+#define MATRIX2 280\r
+#define MATRIX3 281\r
+#define MATRIX4 282\r
+#define IN_QUAL 283\r
+#define OUT_QUAL 284\r
+#define INOUT_QUAL 285\r
+#define UNIFORM 286\r
+#define VARYING 287\r
+#define STRUCT 288\r
+#define VOID_TYPE 289\r
+#define WHILE 290\r
+#define SAMPLER1D 291\r
+#define SAMPLER2D 292\r
+#define SAMPLER3D 293\r
+#define SAMPLERCUBE 294\r
+#define SAMPLER1DSHADOW 295\r
+#define SAMPLER2DSHADOW 296\r
+#define IDENTIFIER 297\r
+#define TYPE_NAME 298\r
+#define FLOATCONSTANT 299\r
+#define INTCONSTANT 300\r
+#define BOOLCONSTANT 301\r
+#define FIELD_SELECTION 302\r
+#define LEFT_OP 303\r
+#define RIGHT_OP 304\r
+#define INC_OP 305\r
+#define DEC_OP 306\r
+#define LE_OP 307\r
+#define GE_OP 308\r
+#define EQ_OP 309\r
+#define NE_OP 310\r
+#define AND_OP 311\r
+#define OR_OP 312\r
+#define XOR_OP 313\r
+#define MUL_ASSIGN 314\r
+#define DIV_ASSIGN 315\r
+#define ADD_ASSIGN 316\r
+#define MOD_ASSIGN 317\r
+#define LEFT_ASSIGN 318\r
+#define RIGHT_ASSIGN 319\r
+#define AND_ASSIGN 320\r
+#define XOR_ASSIGN 321\r
+#define OR_ASSIGN 322\r
+#define SUB_ASSIGN 323\r
+#define LEFT_PAREN 324\r
+#define RIGHT_PAREN 325\r
+#define LEFT_BRACKET 326\r
+#define RIGHT_BRACKET 327\r
+#define LEFT_BRACE 328\r
+#define RIGHT_BRACE 329\r
+#define DOT 330\r
+#define COMMA 331\r
+#define COLON 332\r
+#define EQUAL 333\r
+#define SEMICOLON 334\r
+#define BANG 335\r
+#define DASH 336\r
+#define TILDE 337\r
+#define PLUS 338\r
+#define STAR 339\r
+#define SLASH 340\r
+#define PERCENT 341\r
+#define LEFT_ANGLE 342\r
+#define RIGHT_ANGLE 343\r
+#define VERTICAL_BAR 344\r
+#define CARET 345\r
+#define AMPERSAND 346\r
+#define QUESTION 347\r
+\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#include "localintermediate.h"\r
+#include "../Include/ShHandle.h"\r
+\r
+//\r
+// Two purposes:\r
+// 1. Show an example of how to iterate tree. Functions can\r
+// also directly call Traverse() on children themselves to\r
+// have finer grained control over the process than shown here.\r
+// See the last function for how to get started.\r
+// 2. Print out a text based description of the tree.\r
+//\r
+\r
+//\r
+// Use this class to carry along data from node to node in \r
+// the traversal\r
+//\r
+class TOutputTraverser : public TIntermTraverser {\r
+public:\r
+ TOutputTraverser(TInfoSink& i) : infoSink(i) { }\r
+ TInfoSink& infoSink;\r
+};\r
+\r
+TString TType::getCompleteString() const\r
+{\r
+ char buf[100];\r
+ char *p = &buf[0];\r
+\r
+ if (qualifier != EvqTemporary && qualifier != EvqGlobal)\r
+ p += sprintf(p, "%s ", getQualifierString());\r
+ if (array)\r
+ p += sprintf(p, "array of ");\r
+ if (matrix)\r
+ p += sprintf(p, "%dX%d matrix of ", size, size);\r
+ else if (size > 1)\r
+ p += sprintf(p, "%d-component vector of ", size);\r
+\r
+ sprintf(p, "%s", getBasicString());\r
+\r
+ return TString(buf);\r
+} \r
+\r
+//\r
+// Helper functions for printing, not part of traversing.\r
+//\r
+\r
+void OutputTreeText(TInfoSink& infoSink, TIntermNode* node, const int depth)\r
+{\r
+ int i;\r
+\r
+ infoSink.debug << FormatSourceLoc(node->getLine());\r
+ \r
+ for (i = 0; i < depth; ++i)\r
+ infoSink.debug << " ";\r
+}\r
+\r
+//\r
+// The rest of the file are the traversal functions. The last one\r
+// is the one that starts the traversal.\r
+//\r
+// Return true from interior nodes to have the external traversal\r
+// continue on to children. If you process children yourself,\r
+// return false.\r
+//\r
+\r
+void OutputSymbol(TIntermSymbol* node, TIntermTraverser* it)\r
+{\r
+ TOutputTraverser* oit = static_cast<TOutputTraverser*>(it);\r
+\r
+ OutputTreeText(oit->infoSink, node, oit->depth);\r
+\r
+ char buf[100];\r
+ sprintf(buf, "'%s' (%s)\n",\r
+ node->getSymbol().c_str(),\r
+ node->getCompleteString().c_str());\r
+\r
+ oit->infoSink.debug << buf;\r
+}\r
+\r
+bool OutputBinary(bool /* preVisit */, TIntermBinary* node, TIntermTraverser* it)\r
+{\r
+ TOutputTraverser* oit = static_cast<TOutputTraverser*>(it);\r
+ TInfoSink& out = oit->infoSink;\r
+\r
+ OutputTreeText(out, node, oit->depth);\r
+\r
+ switch (node->getOp()) {\r
+ case EOpAssign: out.debug << "move second child to first child"; break;\r
+ case EOpAddAssign: out.debug << "add second child into first child"; break;\r
+ case EOpSubAssign: out.debug << "subtract second child into first child"; break;\r
+ case EOpMulAssign: out.debug << "multiply second child into first child"; break;\r
+ case EOpVectorTimesMatrixAssign: out.debug << "matrix mult second child into first child"; break;\r
+ case EOpVectorTimesScalarAssign: out.debug << "vector scale second child into first child"; break;\r
+ case EOpMatrixTimesScalarAssign: out.debug << "matrix scale second child into first child"; break;\r
+ case EOpMatrixTimesMatrixAssign: out.debug << "matrix mult second child into first child"; break;\r
+ case EOpDivAssign: out.debug << "divide second child into first child"; break;\r
+ case EOpModAssign: out.debug << "mod second child into first child"; break;\r
+ case EOpAndAssign: out.debug << "and second child into first child"; break;\r
+ case EOpInclusiveOrAssign: out.debug << "or second child into first child"; break;\r
+ case EOpExclusiveOrAssign: out.debug << "exclusive or second child into first child"; break;\r
+ case EOpLeftShiftAssign: out.debug << "left shift second child into first child"; break;\r
+ case EOpRightShiftAssign: out.debug << "right shift second child into first child"; break;\r
+\r
+ case EOpIndexDirect: out.debug << "direct index"; break;\r
+ case EOpIndexIndirect: out.debug << "indirect index"; break;\r
+ case EOpIndexDirectStruct: out.debug << "direct index for structure"; break;\r
+ case EOpVectorSwizzle: out.debug << "vector swizzle"; break;\r
+\r
+ case EOpAdd: out.debug << "add"; break;\r
+ case EOpSub: out.debug << "subtract"; break;\r
+ case EOpMul: out.debug << "component-wise multiply"; break;\r
+ case EOpDiv: out.debug << "divide"; break;\r
+ case EOpMod: out.debug << "mod"; break;\r
+ case EOpRightShift: out.debug << "right-shift"; break;\r
+ case EOpLeftShift: out.debug << "left-shift"; break;\r
+ case EOpAnd: out.debug << "bitwise and"; break;\r
+ case EOpInclusiveOr: out.debug << "inclusive-or"; break;\r
+ case EOpExclusiveOr: out.debug << "exclusive-or"; break;\r
+ case EOpEqual: out.debug << "Compare Equal"; break;\r
+ case EOpNotEqual: out.debug << "Compare Not Equal"; break;\r
+ case EOpLessThan: out.debug << "Compare Less Than"; break;\r
+ case EOpGreaterThan: out.debug << "Compare Greater Than"; break;\r
+ case EOpLessThanEqual: out.debug << "Compare Less Than or Equal"; break;\r
+ case EOpGreaterThanEqual: out.debug << "Compare Greater Than or Equal"; break;\r
+\r
+ case EOpVectorTimesScalar: out.debug << "vector-scale"; break;\r
+ case EOpVectorTimesMatrix: out.debug << "vector-times-matrix"; break;\r
+ case EOpMatrixTimesVector: out.debug << "matrix-times-vector"; break;\r
+ case EOpMatrixTimesScalar: out.debug << "matrix-scale"; break;\r
+ case EOpMatrixTimesMatrix: out.debug << "matrix-multiply"; break;\r
+\r
+ case EOpLogicalOr: out.debug << "logical-or"; break;\r
+ case EOpLogicalXor: out.debug << "logical-xor"; break;\r
+ case EOpLogicalAnd: out.debug << "logical-and"; break;\r
+ default: out.debug << "<unknown op>";\r
+ }\r
+\r
+ out.debug << " (" << node->getCompleteString() << ")";\r
+\r
+ out.debug << "\n";\r
+\r
+ return true;\r
+}\r
+\r
+bool OutputUnary(bool /* preVisit */, TIntermUnary* node, TIntermTraverser* it)\r
+{\r
+ TOutputTraverser* oit = static_cast<TOutputTraverser*>(it);\r
+ TInfoSink& out = oit->infoSink;\r
+\r
+ OutputTreeText(out, node, oit->depth);\r
+\r
+ switch (node->getOp()) { \r
+ case EOpNegative: out.debug << "Negate value"; break;\r
+ case EOpVectorLogicalNot:\r
+ case EOpLogicalNot: out.debug << "Negate conditional"; break;\r
+ case EOpBitwiseNot: out.debug << "Bitwise not"; break;\r
+\r
+ case EOpPostIncrement: out.debug << "Post-Increment"; break;\r
+ case EOpPostDecrement: out.debug << "Post-Decrement"; break;\r
+ case EOpPreIncrement: out.debug << "Pre-Increment"; break;\r
+ case EOpPreDecrement: out.debug << "Pre-Decrement"; break;\r
+\r
+ case EOpConvIntToBool: out.debug << "Convert int to bool"; break;\r
+ case EOpConvFloatToBool:out.debug << "Convert float to bool";break;\r
+ case EOpConvBoolToFloat:out.debug << "Convert bool to float";break;\r
+ case EOpConvIntToFloat: out.debug << "Convert int to float"; break;\r
+ case EOpConvFloatToInt: out.debug << "Convert float to int"; break;\r
+ case EOpConvBoolToInt: out.debug << "Convert bool to int"; break;\r
+\r
+ case EOpRadians: out.debug << "radians"; break;\r
+ case EOpDegrees: out.debug << "degrees"; break;\r
+ case EOpSin: out.debug << "sine"; break;\r
+ case EOpCos: out.debug << "cosine"; break;\r
+ case EOpTan: out.debug << "tangent"; break;\r
+ case EOpAsin: out.debug << "arc sine"; break;\r
+ case EOpAcos: out.debug << "arc cosine"; break;\r
+ case EOpAtan: out.debug << "arc tangent"; break;\r
+\r
+ case EOpExp: out.debug << "exp"; break;\r
+ case EOpLog: out.debug << "log"; break;\r
+ case EOpExp2: out.debug << "exp2"; break;\r
+ case EOpLog2: out.debug << "log2"; break;\r
+ case EOpSqrt: out.debug << "sqrt"; break;\r
+ case EOpInverseSqrt: out.debug << "inverse sqrt"; break;\r
+\r
+ case EOpAbs: out.debug << "Absolute value"; break;\r
+ case EOpSign: out.debug << "Sign"; break;\r
+ case EOpFloor: out.debug << "Floor"; break;\r
+ case EOpCeil: out.debug << "Ceiling"; break;\r
+ case EOpFract: out.debug << "Fraction"; break;\r
+\r
+ case EOpLength: out.debug << "length"; break;\r
+ case EOpNormalize: out.debug << "normalize"; break;\r
+ case EOpDPdx: out.debug << "dPdx"; break; \r
+ case EOpDPdy: out.debug << "dPdy"; break; \r
+ case EOpFwidth: out.debug << "fwidth"; break; \r
+ \r
+ case EOpAny: out.debug << "any"; break;\r
+ case EOpAll: out.debug << "all"; break;\r
+\r
+ default: out.debug.message(EPrefixError, "Bad unary op");\r
+ }\r
+\r
+ out.debug << " (" << node->getCompleteString() << ")";\r
+\r
+ out.debug << "\n";\r
+\r
+ return true;\r
+}\r
+\r
+bool OutputAggregate(bool /* preVisit */, TIntermAggregate* node, TIntermTraverser* it)\r
+{\r
+ TOutputTraverser* oit = static_cast<TOutputTraverser*>(it);\r
+ TInfoSink& out = oit->infoSink;\r
+\r
+ if (node->getOp() == EOpNull) {\r
+ out.debug.message(EPrefixError, "node is still EOpNull!");\r
+ return true;\r
+ }\r
+\r
+ OutputTreeText(out, node, oit->depth);\r
+\r
+ switch (node->getOp()) {\r
+ case EOpSequence: out.debug << "Sequence\n"; return true;\r
+ case EOpComma: out.debug << "Comma\n"; return true;\r
+ case EOpFunction: out.debug << "Function Definition: " << node->getName(); break;\r
+ case EOpFunctionCall: out.debug << "Function Call: " << node->getName(); break;\r
+ case EOpParameters: out.debug << "Function Parameters: "; break;\r
+ \r
+ case EOpConstructFloat: out.debug << "Construct float"; break;\r
+ case EOpConstructVec2: out.debug << "Construct vec2"; break;\r
+ case EOpConstructVec3: out.debug << "Construct vec3"; break;\r
+ case EOpConstructVec4: out.debug << "Construct vec4"; break;\r
+ case EOpConstructBool: out.debug << "Construct bool"; break;\r
+ case EOpConstructBVec2: out.debug << "Construct bvec2"; break;\r
+ case EOpConstructBVec3: out.debug << "Construct bvec3"; break;\r
+ case EOpConstructBVec4: out.debug << "Construct bvec4"; break;\r
+ case EOpConstructInt: out.debug << "Construct int"; break;\r
+ case EOpConstructIVec2: out.debug << "Construct ivec2"; break;\r
+ case EOpConstructIVec3: out.debug << "Construct ivec3"; break;\r
+ case EOpConstructIVec4: out.debug << "Construct ivec4"; break;\r
+ case EOpConstructMat2: out.debug << "Construct mat2"; break;\r
+ case EOpConstructMat3: out.debug << "Construct mat3"; break;\r
+ case EOpConstructMat4: out.debug << "Construct mat4"; break;\r
+ case EOpConstructStruct: out.debug << "Construct structure"; break;\r
+ \r
+ case EOpLessThan: out.debug << "Compare Less Than"; break;\r
+ case EOpGreaterThan: out.debug << "Compare Greater Than"; break;\r
+ case EOpLessThanEqual: out.debug << "Compare Less Than or Equal"; break;\r
+ case EOpGreaterThanEqual: out.debug << "Compare Greater Than or Equal"; break;\r
+ case EOpVectorEqual: out.debug << "Equal"; break;\r
+ case EOpVectorNotEqual: out.debug << "NotEqual"; break;\r
+\r
+ case EOpMod: out.debug << "mod"; break;\r
+ case EOpPow: out.debug << "pow"; break;\r
+\r
+ case EOpAtan: out.debug << "arc tangent"; break;\r
+\r
+ case EOpMin: out.debug << "min"; break;\r
+ case EOpMax: out.debug << "max"; break;\r
+ case EOpClamp: out.debug << "clamp"; break;\r
+ case EOpMix: out.debug << "mix"; break;\r
+ case EOpStep: out.debug << "step"; break;\r
+ case EOpSmoothStep: out.debug << "smoothstep"; break;\r
+\r
+ case EOpDistance: out.debug << "distance"; break;\r
+ case EOpDot: out.debug << "dot-product"; break;\r
+ case EOpCross: out.debug << "cross-product"; break;\r
+ case EOpFaceForward: out.debug << "face-forward"; break;\r
+ case EOpReflect: out.debug << "reflect"; break;\r
+ case EOpRefract: out.debug << "refract"; break;\r
+ case EOpMul: out.debug << "component-wise multiply"; break;\r
+\r
+ case EOpItof: out.debug << "itof"; break;\r
+ case EOpFtoi: out.debug << "ftoi"; break;\r
+ case EOpSkipPixels: out.debug << "skipPixels"; break;\r
+ case EOpReadInput: out.debug << "readInput"; break;\r
+ case EOpWritePixel: out.debug << "writePixel"; break;\r
+ case EOpBitmapLsb: out.debug << "bitmapLSB"; break;\r
+ case EOpBitmapMsb: out.debug << "bitmapMSB"; break;\r
+ case EOpWriteOutput: out.debug << "writeOutput"; break;\r
+ case EOpReadPixel: out.debug << "readPixel"; break;\r
+\r
+ default: out.debug.message(EPrefixError, "Bad aggregation op");\r
+ }\r
+\r
+ if (node->getOp() != EOpSequence && node->getOp() != EOpParameters)\r
+ out.debug << " (" << node->getCompleteString() << ")";\r
+ \r
+ out.debug << "\n";\r
+\r
+ return true;\r
+}\r
+\r
+bool OutputSelection(bool /* preVisit */, TIntermSelection* node, TIntermTraverser* it)\r
+{\r
+ TOutputTraverser* oit = static_cast<TOutputTraverser*>(it);\r
+ TInfoSink& out = oit->infoSink;\r
+\r
+ OutputTreeText(out, node, oit->depth);\r
+\r
+ out.debug << "Test condition and select";\r
+ out.debug << " (" << node->getCompleteString() << ")\n";\r
+ \r
+ ++oit->depth;\r
+ \r
+ OutputTreeText(oit->infoSink, node, oit->depth);\r
+ out.debug << "Condition\n";\r
+ node->getCondition()->traverse(it);\r
+\r
+ OutputTreeText(oit->infoSink, node, oit->depth);\r
+ if (node->getTrueBlock()) {\r
+ out.debug << "true case\n";\r
+ node->getTrueBlock()->traverse(it);\r
+ } else\r
+ out.debug << "true case is null\n";\r
+ \r
+ if (node->getFalseBlock()) {\r
+ OutputTreeText(oit->infoSink, node, oit->depth);\r
+ out.debug << "false case\n";\r
+ node->getFalseBlock()->traverse(it);\r
+ }\r
+ \r
+ --oit->depth;\r
+\r
+ return false;\r
+}\r
+\r
+void OutputConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)\r
+{\r
+ TOutputTraverser* oit = static_cast<TOutputTraverser*>(it);\r
+ TInfoSink& out = oit->infoSink;\r
+ \r
+ int size = 0;\r
+ if (node->getType().getBasicType() == EbtStruct)\r
+ size = node->getType().getStructSize();\r
+ else\r
+ size = node->getType().getInstanceSize();\r
+\r
+ for (int i = 0; i < size; i++) {\r
+ OutputTreeText(out, node, oit->depth);\r
+ switch (node->getType().getBasicType()) {\r
+ case EbtBool:\r
+ if (node->getUnionArrayPointer()[i].bConst)\r
+ out.debug << "true";\r
+ else\r
+ out.debug << "false";\r
+\r
+ out.debug << " (" << "const bool" << ")";\r
+\r
+ out.debug << "\n";\r
+ break;\r
+ case EbtFloat:\r
+ {\r
+ char buf[300];\r
+ sprintf(buf, "%f (%s)", node->getUnionArrayPointer()[i].fConst, "const float");\r
+\r
+ out.debug << buf << "\n"; \r
+ }\r
+ break;\r
+ case EbtInt:\r
+ {\r
+ char buf[300];\r
+ sprintf(buf, "%d (%s)", node->getUnionArrayPointer()[i].iConst, "const int");\r
+\r
+ out.debug << buf << "\n";\r
+ break;\r
+ }\r
+ default: \r
+ out.info.message(EPrefixInternalError, "Unknown constant", node->getLine());\r
+ break;\r
+ }\r
+ }\r
+}\r
+\r
+bool OutputLoop(bool /* preVisit */, TIntermLoop* node, TIntermTraverser* it)\r
+{\r
+ TOutputTraverser* oit = static_cast<TOutputTraverser*>(it);\r
+ TInfoSink& out = oit->infoSink;\r
+\r
+ OutputTreeText(out, node, oit->depth);\r
+ \r
+ out.debug << "Loop with condition ";\r
+ if (! node->testFirst())\r
+ out.debug << "not ";\r
+ out.debug << "tested first\n";\r
+ \r
+ ++oit->depth;\r
+ \r
+ OutputTreeText(oit->infoSink, node, oit->depth);\r
+ if (node->getTest()) {\r
+ out.debug << "Loop Condition\n";\r
+ node->getTest()->traverse(it);\r
+ } else\r
+ out.debug << "No loop condition\n";\r
+ \r
+ OutputTreeText(oit->infoSink, node, oit->depth);\r
+ if (node->getBody()) {\r
+ out.debug << "Loop Body\n";\r
+ node->getBody()->traverse(it);\r
+ } else\r
+ out.debug << "No loop body\n";\r
+\r
+ if (node->getTerminal()) {\r
+ OutputTreeText(oit->infoSink, node, oit->depth);\r
+ out.debug << "Loop Terminal Expression\n";\r
+ node->getTerminal()->traverse(it);\r
+ }\r
+\r
+ --oit->depth;\r
+\r
+ return false;\r
+}\r
+\r
+bool OutputBranch(bool /* previsit*/, TIntermBranch* node, TIntermTraverser* it)\r
+{\r
+ TOutputTraverser* oit = static_cast<TOutputTraverser*>(it);\r
+ TInfoSink& out = oit->infoSink;\r
+\r
+ OutputTreeText(out, node, oit->depth);\r
+\r
+ switch (node->getFlowOp()) {\r
+ case EOpKill: out.debug << "Branch: Kill"; break;\r
+ case EOpBreak: out.debug << "Branch: Break"; break;\r
+ case EOpContinue: out.debug << "Branch: Continue"; break;\r
+ case EOpReturn: out.debug << "Branch: Return"; break;\r
+ default: out.debug << "Branch: Unknown Branch"; break;\r
+ }\r
+\r
+ if (node->getExpression()) {\r
+ out.debug << " with expression\n";\r
+ ++oit->depth;\r
+ node->getExpression()->traverse(it);\r
+ --oit->depth;\r
+ } else\r
+ out.debug << "\n";\r
+\r
+ return false;\r
+}\r
+\r
+//\r
+// This function is the one to call externally to start the traversal.\r
+// Individual functions can be initialized to 0 to skip processing of that\r
+// type of node. It's children will still be processed.\r
+//\r
+void TIntermediate::outputTree(TIntermNode* root)\r
+{\r
+ if (root == 0)\r
+ return;\r
+\r
+ TOutputTraverser it(infoSink);\r
+\r
+ it.visitAggregate = OutputAggregate;\r
+ it.visitBinary = OutputBinary;\r
+ it.visitConstantUnion = OutputConstantUnion;\r
+ it.visitSelection = OutputSelection;\r
+ it.visitSymbol = OutputSymbol;\r
+ it.visitUnary = OutputUnary;\r
+ it.visitLoop = OutputLoop;\r
+ it.visitBranch = OutputBranch;\r
+\r
+ root->traverse(&it);\r
+}\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#ifndef _LOCAL_INTERMEDIATE_INCLUDED_\r
+#define _LOCAL_INTERMEDIATE_INCLUDED_\r
+\r
+#include "../Include/intermediate.h"\r
+#include "../Public/ShaderLang.h"\r
+#include "SymbolTable.h"\r
+\r
+struct TVectorFields {\r
+ int offsets[4];\r
+ int num;\r
+};\r
+\r
+//\r
+// Set of helper functions to help parse and build the tree.\r
+//\r
+class TInfoSink;\r
+class TIntermediate {\r
+public: \r
+ POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)\r
+\r
+ TIntermediate(TInfoSink& i) : infoSink(i) { }\r
+ TIntermSymbol* addSymbol(int Id, const TString&, const TType&, TSourceLoc);\r
+ TIntermTyped* addConversion(TOperator, const TType&, TIntermTyped*);\r
+ TIntermTyped* addBinaryMath(TOperator op, TIntermTyped* left, TIntermTyped* right, TSourceLoc, TSymbolTable&);\r
+ TIntermTyped* addAssign(TOperator op, TIntermTyped* left, TIntermTyped* right, TSourceLoc);\r
+ TIntermTyped* addIndex(TOperator op, TIntermTyped* base, TIntermTyped* index, TSourceLoc);\r
+ TIntermTyped* addUnaryMath(TOperator op, TIntermNode* child, TSourceLoc, TSymbolTable&);\r
+ TIntermAggregate* growAggregate(TIntermNode* left, TIntermNode* right, TSourceLoc);\r
+ TIntermAggregate* makeAggregate(TIntermNode* node, TSourceLoc);\r
+ TIntermAggregate* setAggregateOperator(TIntermNode*, TOperator, TSourceLoc);\r
+ TIntermNode* addSelection(TIntermTyped* cond, TIntermNodePair code, TSourceLoc);\r
+ TIntermTyped* addSelection(TIntermTyped* cond, TIntermTyped* trueBlock, TIntermTyped* falseBlock, TSourceLoc);\r
+ TIntermConstantUnion* addConstantUnion(constUnion*, const TType&, TSourceLoc);\r
+ TIntermTyped* promoteConstantUnion(TBasicType, TIntermConstantUnion*) ;\r
+ TIntermTyped* copyConstUnion(TIntermConstantUnion*) ;\r
+ TIntermConstantUnion* changeAggrToTempConst(TIntermAggregate*, TSymbolTable&, TSourceLoc ); \r
+ bool parseConstTree(TSourceLoc, TIntermNode*, constUnion*, TOperator, TSymbolTable&, TType, bool singleConstantParam = false); \r
+ TIntermNode* addLoop(TIntermNode*, TIntermTyped*, TIntermTyped*, bool testFirst, TSourceLoc);\r
+ TIntermBranch* addBranch(TOperator, TSourceLoc);\r
+ TIntermBranch* addBranch(TOperator, TIntermTyped*, TSourceLoc);\r
+ TIntermTyped* addSwizzle(TVectorFields&, TSourceLoc);\r
+ bool postProcess(TIntermNode*, EShLanguage);\r
+ void remove(TIntermNode*);\r
+ void outputTree(TIntermNode*);\r
+ void removeChildNode(TIntermSequence&, TType&, int&, TIntermSequence::iterator&, TIntermAggregate*);\r
+ TIntermTyped* removeChildNode(TIntermTyped*, TType*, TIntermAggregate*);\r
+ bool removeMatrixConstNode(TIntermSequence&, TType&, TIntermAggregate*, int);\r
+ \r
+protected:\r
+ TInfoSink& infoSink;\r
+\r
+private:\r
+ void operator=(TIntermediate&); // prevent assignments\r
+};\r
+\r
+#endif // _LOCAL_INTERMEDIATE_INCLUDED_\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#include "ParseHelper.h"\r
+\r
+//\r
+// Use this class to carry along data from node to node in \r
+// the traversal\r
+//\r
+class TConstTraverser : public TIntermTraverser {\r
+public:\r
+ TConstTraverser(constUnion* cUnion, bool singleConstParam, TOperator constructType, TInfoSink& sink, TSymbolTable& symTable, TType t) : unionArray(cUnion), type(t),\r
+ constructorType(constructType), singleConstantParam(singleConstParam), infoSink(sink), symbolTable(symTable), error(false), isMatrix(false), matrixSize(0) { index = 0; tOp = EOpNull;}\r
+ int index ;\r
+ constUnion *unionArray;\r
+ TOperator tOp;\r
+ TType type;\r
+ TOperator constructorType;\r
+ bool singleConstantParam;\r
+ TInfoSink& infoSink;\r
+ TSymbolTable& symbolTable;\r
+ bool error;\r
+ int size; // size of the constructor ( 4 for vec4)\r
+ bool isMatrix;\r
+ int matrixSize; // dimension of the matrix (nominal size and not the instance size)\r
+};\r
+\r
+//\r
+// The rest of the file are the traversal functions. The last one\r
+// is the one that starts the traversal.\r
+//\r
+// Return true from interior nodes to have the external traversal\r
+// continue on to children. If you process children yourself,\r
+// return false.\r
+//\r
+\r
+void ParseSymbol(TIntermSymbol* node, TIntermTraverser* it)\r
+{\r
+ TConstTraverser* oit = static_cast<TConstTraverser*>(it);\r
+ TQualifier qualifier = node->getType().getQualifier();\r
+ constUnion* unionArray = oit->unionArray;\r
+ int instanceSize;\r
+ if (oit->type.getBasicType() == EbtStruct)\r
+ instanceSize = oit->type.getStructSize();\r
+ else\r
+ instanceSize = oit->type.getInstanceSize();\r
+\r
+ if (oit->index >= instanceSize)\r
+ return;\r
+\r
+ if (qualifier != EvqConst) {\r
+ char buf[200];\r
+ sprintf(buf, "'constructor' : assigning non-constant to %s", oit->type.getCompleteString().c_str());\r
+ oit->infoSink.info.message(EPrefixError, buf, node->getLine());\r
+ oit->error = true;\r
+ return ; \r
+ }\r
+ TSymbol* symbol = oit->symbolTable.find(node->getSymbol());\r
+ TVariable* tVar = static_cast<TVariable*>(symbol);\r
+\r
+ constUnion* constArray = tVar->getConstPointer();\r
+ if (!constArray) {\r
+ char buf[200];\r
+ sprintf(buf, "'constructor' : constant '%s' has not been initialized correctly", node->getSymbol().c_str());\r
+ oit->infoSink.info.message(EPrefixError, buf, node->getLine());\r
+ oit->error = true;\r
+ return;\r
+ }\r
+ int symbolSize;\r
+\r
+ if (tVar->getType().getBasicType() == EbtStruct)\r
+ symbolSize = tVar->getType().getStructSize();\r
+ else \r
+ symbolSize = tVar->getType().getInstanceSize();\r
+ \r
+ // for constructors such as ivec4(vec4), if vec4 is a symbol node, then the appropriate conversion is required as the\r
+ // types do not match\r
+ for (int i = 0; i < symbolSize; i++) {\r
+ if (oit->index >= instanceSize)\r
+ return;\r
+ if (tVar->getType().getBasicType() == oit->type.getBasicType() || oit->type.getBasicType() == EbtStruct)\r
+ (unionArray[oit->index]) = constArray[i];\r
+ else {\r
+ switch (tVar->getType().getBasicType()) {\r
+ case EbtFloat:\r
+ switch (oit->type.getBasicType()) {\r
+ case EbtInt: unionArray[oit->index].iConst = static_cast<int> (constArray[i].fConst); break;\r
+ case EbtBool: unionArray[oit->index].bConst = constArray[i].fConst != 0.0; break; \r
+ default: oit->infoSink.info.message(EPrefixInternalError, "Incorrect type, cannot parse symbol", node->getLine()); break;\r
+ }\r
+ break;\r
+ case EbtInt:\r
+ switch (oit->type.getBasicType()) {\r
+ case EbtFloat: unionArray[oit->index].fConst = static_cast<float>(constArray[i].iConst); break;\r
+ case EbtBool: unionArray[oit->index].bConst = constArray[i].iConst != 0 ; break; \r
+ default: oit->infoSink.info.message(EPrefixInternalError, "Incorrect type, cannot parse symbol", node->getLine()); break;\r
+ }\r
+ break;\r
+ case EbtBool:\r
+ switch (oit->type.getBasicType()) {\r
+ case EbtFloat: unionArray[oit->index].fConst = static_cast<float>(constArray[i].bConst); break;\r
+ case EbtInt: unionArray[oit->index].iConst = static_cast<int> (constArray[i].bConst); break; \r
+ default: oit->infoSink.info.message(EPrefixInternalError, "Incorrect type, cannot parse symbol", node->getLine()); break;\r
+ }\r
+ break;\r
+ default: oit->infoSink.info.message(EPrefixInternalError, "Incorrect type, cannot parse symbol", node->getLine()); break;\r
+ } \r
+ }\r
+ (oit->index)++;\r
+ }\r
+}\r
+\r
+bool ParseBinary(bool /* preVisit */, TIntermBinary* node, TIntermTraverser* it)\r
+{\r
+ TConstTraverser* oit = static_cast<TConstTraverser*>(it);\r
+ \r
+ TQualifier qualifier = node->getType().getQualifier();\r
+ \r
+ if (qualifier != EvqConst) {\r
+ char buf[200];\r
+ sprintf(buf, "'constructor' : assigning non-constant to %s", oit->type.getCompleteString().c_str());\r
+ oit->infoSink.info.message(EPrefixError, buf, node->getLine());\r
+ oit->error = true;\r
+ return false; \r
+ }\r
+\r
+ oit->infoSink.info.message(EPrefixInternalError, "Binary Node found in constant constructor", node->getLine());\r
+ \r
+ return false;\r
+}\r
+\r
+bool ParseUnary(bool /* preVisit */, TIntermUnary* node, TIntermTraverser* it)\r
+{\r
+ TConstTraverser* oit = static_cast<TConstTraverser*>(it);\r
+\r
+ char buf[200];\r
+ sprintf(buf, "'constructor' : assigning non-constant to '%s'", oit->type.getCompleteString().c_str());\r
+ oit->infoSink.info.message(EPrefixError, buf, node->getLine());\r
+ oit->error = true;\r
+ return false; \r
+}\r
+\r
+bool ParseAggregate(bool /* preVisit */, TIntermAggregate* node, TIntermTraverser* it)\r
+{\r
+ TConstTraverser* oit = static_cast<TConstTraverser*>(it);\r
+ TType tt = node->getType();\r
+\r
+ if (!node->isConstructor() && node->getOp() != EOpComma) {\r
+ char buf[200];\r
+ sprintf(buf, "'constructor' : assigning non-constant to '%s'", oit->type.getCompleteString().c_str());\r
+ oit->infoSink.info.message(EPrefixError, buf, node->getLine());\r
+ oit->error = true;\r
+ return false; \r
+ }\r
+\r
+ if (node->getSequence().size() == 0) {\r
+ oit->error = true;\r
+ return false;\r
+ }\r
+\r
+ bool flag = node->getSequence().size() == 1 && node->getSequence()[0]->getAsTyped()->getAsConstantUnion();\r
+ if (flag) \r
+ {\r
+ oit->singleConstantParam = true; \r
+ oit->constructorType = node->getOp();\r
+ if (node->getType().getBasicType() == EbtStruct)\r
+ oit->size = node->getType().getStructSize();\r
+ else\r
+ oit->size = node->getType().getInstanceSize();\r
+ if (node->getType().isMatrix()) {\r
+ oit->isMatrix = true;\r
+ oit->matrixSize = node->getType().getNominalSize();\r
+ }\r
+ } \r
+\r
+ for (TIntermSequence::iterator p = node->getSequence().begin(); \r
+ p != node->getSequence().end(); p++) {\r
+\r
+ if (node->getOp() == EOpComma)\r
+ oit->index = 0; \r
+\r
+ (*p)->traverse(oit);\r
+ } \r
+ if (flag) \r
+ {\r
+ oit->singleConstantParam = false; \r
+ oit->constructorType = EOpNull;\r
+ oit->size = 0;\r
+ oit->isMatrix = false;\r
+ oit->matrixSize = 0;\r
+ }\r
+ return false;\r
+}\r
+\r
+bool ParseSelection(bool /* preVisit */, TIntermSelection* node, TIntermTraverser* it)\r
+{\r
+ TConstTraverser* oit = static_cast<TConstTraverser*>(it);\r
+ oit->infoSink.info.message(EPrefixInternalError, "Selection Node found in constant constructor", node->getLine());\r
+ oit->error = true;\r
+ return false;\r
+}\r
+\r
+void ParseConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)\r
+{\r
+ TConstTraverser* oit = static_cast<TConstTraverser*>(it);\r
+ constUnion* leftUnionArray = oit->unionArray;\r
+ int instanceSize;\r
+ if (oit->type.getBasicType() == EbtStruct)\r
+ instanceSize = oit->type.getStructSize();\r
+ else\r
+ instanceSize = oit->type.getInstanceSize();\r
+\r
+ if (oit->index >= instanceSize)\r
+ return;\r
+\r
+ if (!oit->singleConstantParam) {\r
+ int size;\r
+ if (node->getType().getBasicType() == EbtStruct)\r
+ size = node->getType().getStructSize();\r
+ else\r
+ size = node->getType().getInstanceSize();\r
+ \r
+ constUnion *rightUnionArray = node->getUnionArrayPointer();\r
+ for (int i=0; i < size; i++) {\r
+ if (oit->index >= instanceSize)\r
+ return;\r
+ leftUnionArray[oit->index] = rightUnionArray[i];\r
+\r
+ (oit->index)++;\r
+ }\r
+ } else {\r
+ int size, totalSize, matrixSize;\r
+ bool isMatrix = false;\r
+ size = oit->size;\r
+ matrixSize = oit->matrixSize;\r
+ isMatrix = oit->isMatrix;\r
+ totalSize = oit->index + size ;\r
+ constUnion *rightUnionArray = node->getUnionArrayPointer();\r
+ if (!isMatrix) {\r
+ int count = 0;\r
+ for (int i = oit->index; i < totalSize; i++) {\r
+ if (i >= instanceSize)\r
+ return;\r
+\r
+ leftUnionArray[i] = rightUnionArray[count];\r
+\r
+ (oit->index)++;\r
+ if (node->getType().getBasicType() == EbtStruct && node->getType().getStructSize() > 1 ||\r
+ node->getType().getBasicType() != EbtStruct && node->getType().getInstanceSize() > 1)\r
+ count++; \r
+ }\r
+ } else { // for matrix constructors\r
+ int count = 0;\r
+ int index = oit->index;\r
+ for (int i = index; i < totalSize; i++) {\r
+ if (i >= instanceSize)\r
+ return;\r
+ if (index - i == 0 || (i - index) % (matrixSize + 1) == 0 )\r
+ leftUnionArray[i] = rightUnionArray[count];\r
+ else \r
+ leftUnionArray[i].fConst = 0.0;\r
+\r
+ (oit->index)++;\r
+ if (node->getType().getBasicType() == EbtStruct && node->getType().getStructSize() > 1 ||\r
+ node->getType().getBasicType() != EbtStruct && node->getType().getInstanceSize() > 1)\r
+ count++; \r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+bool ParseLoop(bool /* preVisit */, TIntermLoop* node, TIntermTraverser* it)\r
+{\r
+ TConstTraverser* oit = static_cast<TConstTraverser*>(it);\r
+ oit->infoSink.info.message(EPrefixInternalError, "Loop Node found in constant constructor", node->getLine());\r
+ oit->error = true;\r
+ return false;\r
+}\r
+\r
+bool ParseBranch(bool /* previsit*/, TIntermBranch* node, TIntermTraverser* it)\r
+{\r
+ TConstTraverser* oit = static_cast<TConstTraverser*>(it);\r
+ oit->infoSink.info.message(EPrefixInternalError, "Branch Node found in constant constructor", node->getLine());\r
+ oit->error = true;\r
+ return false;\r
+}\r
+\r
+//\r
+// This function is the one to call externally to start the traversal.\r
+// Individual functions can be initialized to 0 to skip processing of that\r
+// type of node. It's children will still be processed.\r
+//\r
+bool TIntermediate::parseConstTree(TSourceLoc line, TIntermNode* root, constUnion* unionArray, TOperator constructorType, TSymbolTable& symbolTable, TType t, bool singleConstantParam)\r
+{\r
+ if (root == 0)\r
+ return false;\r
+\r
+ TConstTraverser it(unionArray, singleConstantParam, constructorType, infoSink, symbolTable, t);\r
+ \r
+ it.visitAggregate = ParseAggregate;\r
+ it.visitBinary = ParseBinary;\r
+ it.visitConstantUnion = ParseConstantUnion;\r
+ it.visitSelection = ParseSelection;\r
+ it.visitSymbol = ParseSymbol;\r
+ it.visitUnary = ParseUnary;\r
+ it.visitLoop = ParseLoop;\r
+ it.visitBranch = ParseBranch;\r
+\r
+ root->traverse(&it);\r
+ if (it.error)\r
+ return true;\r
+ else\r
+ return false;\r
+}\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+\r
+//\r
+// atom.c\r
+//\r
+\r
+#include <assert.h>\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+\r
+#include "slglobals.h"\r
+\r
+#undef malloc\r
+#undef realloc\r
+#undef free\r
+\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+////////////////////////////////////////// String table: //////////////////////////////////////\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+\r
+static const struct {\r
+ int val;\r
+ const char *str;\r
+} tokens[] = {\r
+ { CPP_AND_OP, "&&" },\r
+ { CPP_AND_ASSIGN, "&=" },\r
+ { CPP_SUB_ASSIGN, "-=" },\r
+ { CPP_MOD_ASSIGN, "%=" },\r
+ { CPP_ADD_ASSIGN, "+=" },\r
+ { CPP_DIV_ASSIGN, "/=" },\r
+ { CPP_MUL_ASSIGN, "*=" },\r
+ { CPP_RIGHT_BRACKET, ":>" },\r
+ { CPP_EQ_OP, "==" },\r
+ { CPP_XOR_OP, "^^" }, \r
+ { CPP_XOR_ASSIGN, "^=" }, \r
+ { CPP_FLOATCONSTANT, "<float-const>" },\r
+ { CPP_GE_OP, ">=" },\r
+ { CPP_RIGHT_OP, ">>" },\r
+ { CPP_RIGHT_ASSIGN, ">>=" }, \r
+ { CPP_IDENTIFIER, "<ident>" },\r
+ { CPP_INTCONSTANT, "<int-const>" },\r
+ { CPP_LE_OP, "<=" },\r
+ { CPP_LEFT_OP, "<<" },\r
+ { CPP_LEFT_ASSIGN, "<<=" },\r
+ { CPP_LEFT_BRACKET, "<:" },\r
+ { CPP_LEFT_BRACE, "<%" }, \r
+ { CPP_DEC_OP, "--" },\r
+ { CPP_RIGHT_BRACE, "%>" }, \r
+ { CPP_NE_OP, "!=" },\r
+ { CPP_OR_OP, "||" },\r
+ { CPP_OR_ASSIGN, "|=" }, \r
+ { CPP_INC_OP, "++" },\r
+ { CPP_STRCONSTANT, "<string-const>" },\r
+ { CPP_TYPEIDENTIFIER, "<type-ident>" },\r
+};\r
+\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+////////////////////////////////////////// String table: //////////////////////////////////////\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+\r
+#define INIT_STRING_TABLE_SIZE 16384\r
+\r
+typedef struct StringTable_Rec {\r
+ char *strings;\r
+ int nextFree;\r
+ int size;\r
+} StringTable;\r
+\r
+/*\r
+ * InitStringTable() - Initialize the string table.\r
+ *\r
+ */\r
+\r
+static int InitStringTable(StringTable *stable)\r
+{\r
+ stable->strings = (char *) malloc(INIT_STRING_TABLE_SIZE);\r
+ if (!stable->strings)\r
+ return 0;\r
+ // Zero-th offset means "empty" so don't use it.\r
+ stable->nextFree = 1;\r
+ stable->size = INIT_STRING_TABLE_SIZE;\r
+ return 1;\r
+} // InitStringTable\r
+\r
+/*\r
+ * FreeStringTable() - Free the string table.\r
+ *\r
+ */\r
+\r
+static void FreeStringTable(StringTable *stable)\r
+{\r
+ if (stable->strings)\r
+ free(stable->strings);\r
+ stable->strings = NULL;\r
+ stable->nextFree = 0;\r
+ stable->size = 0;\r
+} // FreeStringTable\r
+\r
+/*\r
+ * HashString() - Hash a string with the base hash function.\r
+ *\r
+ */\r
+\r
+static int HashString(const char *s)\r
+{\r
+ int hval = 0;\r
+\r
+ while (*s) {\r
+ hval = (hval*13507 + *s*197) ^ (hval >> 2);\r
+ s++;\r
+ }\r
+ return hval & 0x7fffffff;\r
+} // HashString\r
+\r
+/*\r
+ * HashString2() - Hash a string with the incrimenting hash function.\r
+ *\r
+ */\r
+\r
+static int HashString2(const char *s)\r
+{\r
+ int hval = 0;\r
+\r
+ while (*s) {\r
+ hval = (hval*729 + *s*37) ^ (hval >> 1);\r
+ s++;\r
+ }\r
+ return hval;\r
+} // HashString2\r
+\r
+/*\r
+ * AddString() - Add a string to a string table. Return it's offset.\r
+ *\r
+ */\r
+\r
+static int AddString(StringTable *stable, const char *s)\r
+{\r
+ int len, loc;\r
+ char *str;\r
+\r
+ len = (int) strlen(s);\r
+ if (stable->nextFree + len + 1 >= stable->size) {\r
+ assert(stable->size < 1000000);\r
+ str = (char *) malloc(stable->size*2);\r
+ memcpy(str, stable->strings, stable->size);\r
+ free(stable->strings);\r
+ stable->strings = str;\r
+ }\r
+ loc = stable->nextFree;\r
+ strcpy(&stable->strings[loc], s);\r
+ stable->nextFree += len + 1;\r
+ return loc;\r
+} // AddString\r
+\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+/////////////////////////////////////////// Hash table: ///////////////////////////////////////\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+\r
+#define INIT_HASH_TABLE_SIZE 2047\r
+#define HASH_TABLE_MAX_COLLISIONS 3\r
+\r
+typedef struct HashEntry_Rec {\r
+ int index; // String table offset of string representation\r
+ int value; // Atom (symbol) value\r
+} HashEntry;\r
+\r
+typedef struct HashTable_Rec {\r
+ HashEntry *entry;\r
+ int size;\r
+ int entries;\r
+ int counts[HASH_TABLE_MAX_COLLISIONS + 1];\r
+} HashTable;\r
+\r
+/*\r
+ * InitHashTable() - Initialize the hash table.\r
+ *\r
+ */\r
+\r
+static int InitHashTable(HashTable *htable, int fsize)\r
+{\r
+ int ii;\r
+\r
+ htable->entry = (HashEntry *) malloc(sizeof(HashEntry)*fsize);\r
+ if (!htable->entry)\r
+ return 0;\r
+ htable->size = fsize;\r
+ for (ii = 0; ii < fsize; ii++) {\r
+ htable->entry[ii].index = 0;\r
+ htable->entry[ii].value = 0;\r
+ }\r
+ htable->entries = 0;\r
+ for (ii = 0; ii <= HASH_TABLE_MAX_COLLISIONS; ii++)\r
+ htable->counts[ii] = 0;\r
+ return 1;\r
+} // InitHashTable\r
+\r
+/*\r
+ * FreeHashTable() - Free the hash table.\r
+ *\r
+ */\r
+\r
+static void FreeHashTable(HashTable *htable)\r
+{\r
+ if (htable->entry)\r
+ free(htable->entry);\r
+ htable->entry = NULL;\r
+ htable->size = 0;\r
+ htable->entries = 0;\r
+} // FreeHashTable\r
+\r
+/*\r
+ * Empty() - See if a hash table entry is empty.\r
+ *\r
+ */\r
+\r
+static int Empty(HashTable *htable, int hashloc)\r
+{\r
+ assert(hashloc >= 0 && hashloc < htable->size);\r
+ if (htable->entry[hashloc].index == 0) {\r
+ return 1;\r
+ } else {\r
+ return 0;\r
+ }\r
+} // Empty\r
+\r
+/*\r
+ * Match() - See if a hash table entry is matches a string.\r
+ *\r
+ */\r
+\r
+static int Match(HashTable *htable, StringTable *stable, const char *s, int hashloc)\r
+{\r
+ int strloc;\r
+\r
+ strloc = htable->entry[hashloc].index;\r
+ if (!strcmp(s, &stable->strings[strloc])) {\r
+ return 1;\r
+ } else {\r
+ return 0;\r
+ }\r
+} // Match\r
+\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+/////////////////////////////////////////// Atom table: ///////////////////////////////////////\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+\r
+#define INIT_ATOM_TABLE_SIZE 1024\r
+\r
+\r
+struct AtomTable_Rec {\r
+ StringTable stable; // String table.\r
+ HashTable htable; // Hashes string to atom number and token value. Multiple strings can\r
+ // have the same token value but each unique string is a unique atom.\r
+ int *amap; // Maps atom value to offset in string table. Atoms all map to unique\r
+ // strings except for some undefined values in the lower, fixed part\r
+ // of the atom table that map to "<undefined>". The lowest 256 atoms\r
+ // correspond to single character ASCII values except for alphanumeric\r
+ // characters and '_', which can be other tokens. Next come the\r
+ // language tokens with their atom values equal to the token value.\r
+ // Then come predefined atoms, followed by user specified identifiers.\r
+ int *arev; // Reversed atom for symbol table use.\r
+ int nextFree;\r
+ int size;\r
+};\r
+\r
+static AtomTable latable = { { 0 } };\r
+AtomTable *atable = &latable;\r
+\r
+static int AddAtomFixed(AtomTable *atable, const char *s, int atom);\r
+\r
+/*\r
+ * GrowAtomTable() - Grow the atom table to at least "size" if it's smaller.\r
+ *\r
+ */\r
+\r
+static int GrowAtomTable(AtomTable *atable, int size)\r
+{\r
+ int *newmap, *newrev;\r
+\r
+ if (atable->size < size) {\r
+ if (atable->amap) {\r
+ newmap = realloc(atable->amap, sizeof(int)*size);\r
+ newrev = realloc(atable->arev, sizeof(int)*size);\r
+ } else {\r
+ newmap = malloc(sizeof(int)*size);\r
+ newrev = malloc(sizeof(int)*size);\r
+ atable->size = 0;\r
+ }\r
+ if (!newmap || !newrev) {\r
+ /* failed to grow -- error */\r
+ if (newmap)\r
+ atable->amap = newmap;\r
+ if (newrev)\r
+ atable->amap = newrev;\r
+ return -1;\r
+ }\r
+ memset(&newmap[atable->size], 0, (size - atable->size) * sizeof(int));\r
+ memset(&newrev[atable->size], 0, (size - atable->size) * sizeof(int));\r
+ atable->amap = newmap;\r
+ atable->arev = newrev;\r
+ atable->size = size;\r
+ }\r
+ return 0;\r
+} // GrowAtomTable\r
+\r
+/*\r
+ * lReverse() - Reverse the bottom 20 bits of a 32 bit int.\r
+ *\r
+ */\r
+\r
+static int lReverse(int fval)\r
+{\r
+ unsigned int in = fval;\r
+ int result = 0, cnt = 0;\r
+\r
+ while(in) {\r
+ result <<= 1;\r
+ result |= in&1;\r
+ in >>= 1;\r
+ cnt++;\r
+ }\r
+\r
+ // Don't use all 31 bits. One million atoms is plenty and sometimes the\r
+ // upper bits are used for other things.\r
+\r
+ if (cnt < 20)\r
+ result <<= 20 - cnt;\r
+ return result;\r
+} // lReverse\r
+\r
+/*\r
+ * AllocateAtom() - Allocate a new atom. Associated with the "undefined" value of -1.\r
+ *\r
+ */\r
+\r
+static int AllocateAtom(AtomTable *atable)\r
+{\r
+ if (atable->nextFree >= atable->size)\r
+ GrowAtomTable(atable, atable->nextFree*2);\r
+ atable->amap[atable->nextFree] = -1;\r
+ atable->arev[atable->nextFree] = lReverse(atable->nextFree);\r
+ atable->nextFree++;\r
+ return atable->nextFree - 1;\r
+} // AllocateAtom\r
+\r
+/*\r
+ * SetAtomValue() - Allocate a new atom associated with "hashindex".\r
+ *\r
+ */\r
+\r
+static void SetAtomValue(AtomTable *atable, int atomnumber, int hashindex)\r
+{\r
+ atable->amap[atomnumber] = atable->htable.entry[hashindex].index;\r
+ atable->htable.entry[hashindex].value = atomnumber;\r
+} // SetAtomValue\r
+\r
+/*\r
+ * FindHashLoc() - Find the hash location for this string. Return -1 it hash table is full.\r
+ *\r
+ */\r
+\r
+static int FindHashLoc(AtomTable *atable, const char *s)\r
+{\r
+ int hashloc, hashdelta, count;\r
+ int FoundEmptySlot = 0;\r
+ int collision[HASH_TABLE_MAX_COLLISIONS + 1];\r
+\r
+ hashloc = HashString(s) % atable->htable.size;\r
+ if (!Empty(&atable->htable, hashloc)) {\r
+ if (Match(&atable->htable, &atable->stable, s, hashloc))\r
+ return hashloc;\r
+ collision[0] = hashloc;\r
+ hashdelta = HashString2(s);\r
+ count = 0;\r
+ while (count < HASH_TABLE_MAX_COLLISIONS) {\r
+ hashloc = ((hashloc + hashdelta) & 0x7fffffff) % atable->htable.size;\r
+ if (!Empty(&atable->htable, hashloc)) {\r
+ if (Match(&atable->htable, &atable->stable, s, hashloc)) {\r
+ return hashloc;\r
+ }\r
+ } else {\r
+ FoundEmptySlot = 1;\r
+ break;\r
+ }\r
+ count++;\r
+ collision[count] = hashloc;\r
+ }\r
+\r
+ if (!FoundEmptySlot) {\r
+ if (cpp->options.DumpAtomTable) {\r
+ int ii;\r
+ char str[200];\r
+ sprintf(str, "*** Hash failed with more than %d collisions. Must increase hash table size. ***",\r
+ HASH_TABLE_MAX_COLLISIONS);\r
+ CPPShInfoLogMsg(str);\r
+\r
+ sprintf(str, "*** New string \"%s\", hash=%04x, delta=%04x", s, collision[0], hashdelta);\r
+ CPPShInfoLogMsg(str);\r
+ for (ii = 0; ii <= HASH_TABLE_MAX_COLLISIONS; ii++) {\r
+ sprintf(str, "*** Collides on try %d at hash entry %04x with \"%s\"",\r
+ ii + 1, collision[ii], GetAtomString(atable, atable->htable.entry[collision[ii]].value));\r
+ CPPShInfoLogMsg(str);\r
+ }\r
+ }\r
+ return -1;\r
+ } else {\r
+ atable->htable.counts[count]++;\r
+ }\r
+ }\r
+ return hashloc;\r
+} // FindHashLoc\r
+\r
+/*\r
+ * IncreaseHashTableSize()\r
+ *\r
+ */\r
+\r
+static int IncreaseHashTableSize(AtomTable *atable)\r
+{\r
+ int ii, strloc, oldhashloc, value, size;\r
+ AtomTable oldtable;\r
+ char *s;\r
+\r
+ // Save the old atom table and create a new one:\r
+\r
+ oldtable = *atable;\r
+ size = oldtable.htable.size*2 + 1;\r
+ if (!InitAtomTable(atable, size))\r
+ return 0;\r
+\r
+ // Add all the existing values to the new atom table preserving their atom values:\r
+\r
+ for (ii = atable->nextFree; ii < oldtable.nextFree; ii++) {\r
+ strloc = oldtable.amap[ii];\r
+ s = &oldtable.stable.strings[strloc];\r
+ oldhashloc = FindHashLoc(&oldtable, s);\r
+ assert(oldhashloc >= 0);\r
+ value = oldtable.htable.entry[oldhashloc].value;\r
+ AddAtomFixed(atable, s, value);\r
+ }\r
+ FreeAtomTable(&oldtable);\r
+ return 1;\r
+} // IncreaseHashTableSize\r
+\r
+/*\r
+ * LookUpAddStringHash() - Lookup a string in the hash table. If it's not there, add it and\r
+ * initialize the atom value in the hash table to 0. Return the hash table index.\r
+ */\r
+\r
+static int LookUpAddStringHash(AtomTable *atable, const char *s)\r
+{\r
+ int hashloc, strloc;\r
+\r
+ while(1) {\r
+ hashloc = FindHashLoc(atable, s);\r
+ if (hashloc >= 0)\r
+ break;\r
+ IncreaseHashTableSize(atable);\r
+ }\r
+\r
+ if (Empty(&atable->htable, hashloc)) {\r
+ atable->htable.entries++;\r
+ strloc = AddString(&atable->stable, s);\r
+ atable->htable.entry[hashloc].index = strloc;\r
+ atable->htable.entry[hashloc].value = 0;\r
+ }\r
+ return hashloc;\r
+} // LookUpAddStringHash\r
+\r
+/*\r
+ * LookUpAddString() - Lookup a string in the hash table. If it's not there, add it and\r
+ * initialize the atom value in the hash table to the next atom number.\r
+ * Return the atom value of string.\r
+ */\r
+\r
+int LookUpAddString(AtomTable *atable, const char *s)\r
+{\r
+ int hashindex, atom;\r
+\r
+ hashindex = LookUpAddStringHash(atable, s);\r
+ atom = atable->htable.entry[hashindex].value;\r
+ if (atom == 0) {\r
+ atom = AllocateAtom(atable);\r
+ SetAtomValue(atable, atom, hashindex);\r
+ }\r
+ return atom;\r
+} // LookUpAddString\r
+\r
+/*\r
+ * GetAtomString()\r
+ *\r
+ */\r
+\r
+const char *GetAtomString(AtomTable *atable, int atom)\r
+{\r
+ int soffset;\r
+\r
+ if (atom > 0 && atom < atable->nextFree) {\r
+ soffset = atable->amap[atom];\r
+ if (soffset > 0 && soffset < atable->stable.nextFree) {\r
+ return &atable->stable.strings[soffset];\r
+ } else {\r
+ return "<internal error: bad soffset>";\r
+ }\r
+ } else {\r
+ if (atom == 0) {\r
+ return "<null atom>";\r
+ } else {\r
+ if (atom == EOF) {\r
+ return "<EOF>";\r
+ } else {\r
+ return "<invalid atom>";\r
+ }\r
+ }\r
+ }\r
+} // GetAtomString\r
+\r
+/*\r
+ * GetReversedAtom()\r
+ *\r
+ */\r
+\r
+int GetReversedAtom(AtomTable *atable, int atom)\r
+{\r
+ if (atom > 0 && atom < atable->nextFree) {\r
+ return atable->arev[atom];\r
+ } else {\r
+ return 0;\r
+ }\r
+} // GetReversedAtom\r
+\r
+/*\r
+ * AddAtom() - Add a string to the atom, hash and string tables if it isn't already there.\r
+ * Return it's atom index.\r
+ */\r
+\r
+int AddAtom(AtomTable *atable, const char *s)\r
+{\r
+ int atom;\r
+\r
+ atom = LookUpAddString(atable, s);\r
+ return atom;\r
+} // AddAtom\r
+\r
+/*\r
+ * AddAtomFixed() - Add an atom to the hash and string tables if it isn't already there.\r
+ * Assign it the atom value of "atom".\r
+ */\r
+\r
+static int AddAtomFixed(AtomTable *atable, const char *s, int atom)\r
+{\r
+ int hashindex, lsize;\r
+\r
+ hashindex = LookUpAddStringHash(atable, s);\r
+ if (atable->nextFree >= atable->size || atom >= atable->size) {\r
+ lsize = atable->size*2;\r
+ if (lsize <= atom)\r
+ lsize = atom + 1;\r
+ GrowAtomTable(atable, lsize);\r
+ }\r
+ atable->amap[atom] = atable->htable.entry[hashindex].index;\r
+ atable->htable.entry[hashindex].value = atom;\r
+ //if (atom >= atable->nextFree)\r
+ // atable->nextFree = atom + 1;\r
+ while (atom >= atable->nextFree) {\r
+ atable->arev[atable->nextFree] = lReverse(atable->nextFree);\r
+ atable->nextFree++;\r
+ }\r
+ return atom;\r
+} // AddAtomFixed\r
+\r
+/*\r
+ * InitAtomTable() - Initialize the atom table.\r
+ *\r
+ */\r
+\r
+int InitAtomTable(AtomTable *atable, int htsize)\r
+{\r
+ int ii;\r
+\r
+ htsize = htsize <= 0 ? INIT_HASH_TABLE_SIZE : htsize;\r
+ if (!InitStringTable(&atable->stable))\r
+ return 0;\r
+ if (!InitHashTable(&atable->htable, htsize))\r
+ return 0;\r
+\r
+ atable->nextFree = 0;\r
+ atable->amap = NULL;\r
+ atable->size = 0;\r
+ GrowAtomTable(atable, INIT_ATOM_TABLE_SIZE);\r
+ if (!atable->amap)\r
+ return 0;\r
+\r
+ // Initialize lower part of atom table to "<undefined>" atom:\r
+\r
+ AddAtomFixed(atable, "<undefined>", 0);\r
+ for (ii = 0; ii < FIRST_USER_TOKEN_SY; ii++)\r
+ atable->amap[ii] = atable->amap[0];\r
+\r
+ // Add single character tokens to the atom table:\r
+\r
+ {\r
+ const char *s = "~!%^&*()-+=|,.<>/?;:[]{}#";\r
+ char t[2];\r
+\r
+ t[1] = '\0';\r
+ while (*s) {\r
+ t[0] = *s;\r
+ AddAtomFixed(atable, t, s[0]);\r
+ s++;\r
+ }\r
+ }\r
+\r
+ // Add multiple character scanner tokens :\r
+\r
+ for (ii = 0; ii < sizeof(tokens)/sizeof(tokens[0]); ii++)\r
+ AddAtomFixed(atable, tokens[ii].str, tokens[ii].val);\r
+\r
+ // Add error symbol if running in error mode:\r
+\r
+ if (cpp->options.ErrorMode)\r
+ AddAtomFixed(atable, "error", ERROR_SY);\r
+\r
+ AddAtom(atable, "<*** end fixed atoms ***>");\r
+\r
+ return 1;\r
+} // InitAtomTable\r
+\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+////////////////////////////////// Debug Printing Functions: //////////////////////////////////\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+\r
+/*\r
+ * PrintAtomTable()\r
+ *\r
+ */\r
+\r
+void PrintAtomTable(AtomTable *atable)\r
+{\r
+ int ii;\r
+ char str[200];\r
+\r
+ for (ii = 0; ii < atable->nextFree; ii++) {\r
+ sprintf(str, "%d: \"%s\"", ii, &atable->stable.strings[atable->amap[ii]]);\r
+ CPPDebugLogMsg(str);\r
+ }\r
+ sprintf(str, "Hash table: size=%d, entries=%d, collisions=",\r
+ atable->htable.size, atable->htable.entries);\r
+ CPPDebugLogMsg(str);\r
+ for (ii = 0; ii < HASH_TABLE_MAX_COLLISIONS; ii++) {\r
+ sprintf(str, " %d", atable->htable.counts[ii]);\r
+ CPPDebugLogMsg(str);\r
+ }\r
+\r
+} // PrintAtomTable\r
+\r
+\r
+/*\r
+ * GetStringOfAtom()\r
+ *\r
+ */\r
+\r
+char* GetStringOfAtom(AtomTable *atable, int atom)\r
+{\r
+ char* chr_str;\r
+ chr_str=&atable->stable.strings[atable->amap[atom]];\r
+ return chr_str;\r
+} // GetStringOfAtom\r
+\r
+/*\r
+ * FreeAtomTable() - Free the atom table and associated memory\r
+ *\r
+ */\r
+\r
+void FreeAtomTable(AtomTable *atable)\r
+{\r
+ FreeStringTable(&atable->stable);\r
+ FreeHashTable(&atable->htable);\r
+ if (atable->amap)\r
+ free(atable->amap);\r
+ if (atable->arev)\r
+ free(atable->arev);\r
+ atable->amap = NULL;\r
+ atable->arev = NULL;\r
+ atable->nextFree = 0;\r
+ atable->size = 0;\r
+} // FreeAtomTable\r
+\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+///////////////////////////////////////// End of atom.c ///////////////////////////////////////\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+//\r
+// atom.h\r
+//\r
+\r
+#if !defined(__ATOM_H)\r
+#define __ATOM_H 1\r
+\r
+typedef struct AtomTable_Rec AtomTable;\r
+\r
+extern AtomTable *atable;\r
+\r
+int InitAtomTable(AtomTable *atable, int htsize);\r
+void FreeAtomTable(AtomTable *atable);\r
+int AddAtom(AtomTable *atable, const char *s);\r
+void PrintAtomTable(AtomTable *atable);\r
+int LookUpAddString(AtomTable *atable, const char *s);\r
+const char *GetAtomString(AtomTable *atable, int atom);\r
+int GetReversedAtom(AtomTable *atable, int atom);\r
+char* GetStringOfAtom(AtomTable *atable, int atom);\r
+#endif // !defined(__ATOM_H)\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+//\r
+// compile.h\r
+//\r
+\r
+#if !defined(__COMPILE_H)\r
+#define __COMPILE_H 1\r
+\r
+int InitCPPStruct(void);\r
+\r
+typedef struct Options_Rec{\r
+ const char *profileString;\r
+ int ErrorMode;\r
+ int Quiet;\r
+ \r
+ // Debug The Compiler options:\r
+ int DumpAtomTable;\r
+} Options;\r
+\r
+struct CPPStruct_Rec {\r
+ // Public members\r
+ SourceLoc *pLastSourceLoc; // Set at the start of each statement by the tree walkers\r
+ Options options; // Compile options and parameters\r
+\r
+ // Private members\r
+ SourceLoc lastSourceLoc;\r
+\r
+ // Scanner data:\r
+\r
+ SourceLoc *tokenLoc; // Source location of most recent token seen by the scanner\r
+ int mostRecentToken; // Most recent token seen by the scanner\r
+ InputSrc *currentInput;\r
+ int previous_token;\r
+ int notAVersionToken; // used to make sure that #version is the first token seen in the file, if present\r
+ \r
+ void *pC; // storing the parseContext of the compile object in cpp. \r
+ \r
+ // Private members:\r
+ SourceLoc ltokenLoc;\r
+ int ifdepth; //current #if-#else-#endif nesting in the cpp.c file (pre-processor) \r
+ int elsedepth[64]; //Keep a track of #if depth..Max allowed is 64. \r
+ int elsetracker; //#if-#else and #endif constructs...Counter.\r
+ const char *ErrMsg;\r
+ int CompileError; //Indicate compile error when #error, #else,#elif mismatch.\r
+\r
+ //\r
+ // Globals used to communicate between PaParseStrings() and yy_input()and \r
+ // also across the files.(gen_glslang.cpp and scanner.c)\r
+ //\r
+ int PaWhichStr; // which string we're parsing\r
+ int* PaStrLen; // array of lengths of the PaArgv strings\r
+ int PaArgc; // count of strings in the array\r
+ char** PaArgv; // our array of strings to parse \r
+};\r
+\r
+#endif // !defined(__COMPILE_H)\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+//\r
+// cpp.c\r
+//\r
+\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <ctype.h>\r
+\r
+#include "slglobals.h"\r
+\r
+#include "slang_mesa.h"\r
+\r
+static int CPPif(yystypepp * yylvalpp);\r
+\r
+/* Don't use memory.c's replacements, as we clean up properly here */\r
+#undef malloc\r
+#undef free\r
+\r
+static int bindAtom = 0;\r
+static int constAtom = 0;\r
+static int defaultAtom = 0;\r
+static int defineAtom = 0;\r
+static int definedAtom = 0;\r
+static int elseAtom = 0;\r
+static int elifAtom = 0;\r
+static int endifAtom = 0;\r
+static int ifAtom = 0;\r
+static int ifdefAtom = 0;\r
+static int ifndefAtom = 0;\r
+static int includeAtom = 0;\r
+static int lineAtom = 0;\r
+static int pragmaAtom = 0;\r
+static int texunitAtom = 0;\r
+static int undefAtom = 0;\r
+static int errorAtom = 0;\r
+static int __LINE__Atom = 0;\r
+static int __FILE__Atom = 0;\r
+static int __VERSION__Atom = 0;\r
+static int versionAtom = 0;\r
+static int extensionAtom = 0;\r
+\r
+static Scope *macros = 0;\r
+#define MAX_MACRO_ARGS 64\r
+#define MAX_IF_NESTING 64\r
+\r
+static SourceLoc ifloc; /* outermost #if */\r
+\r
+int InitCPP(void)\r
+{\r
+ char buffer[64], *t;\r
+ const char *f;\r
+ // Add various atoms needed by the CPP line scanner:\r
+ bindAtom = LookUpAddString(atable, "bind");\r
+ constAtom = LookUpAddString(atable, "const");\r
+ defaultAtom = LookUpAddString(atable, "default");\r
+ defineAtom = LookUpAddString(atable, "define");\r
+ definedAtom = LookUpAddString(atable, "defined");\r
+ elifAtom = LookUpAddString(atable, "elif");\r
+ elseAtom = LookUpAddString(atable, "else");\r
+ endifAtom = LookUpAddString(atable, "endif");\r
+ ifAtom = LookUpAddString(atable, "if");\r
+ ifdefAtom = LookUpAddString(atable, "ifdef");\r
+ ifndefAtom = LookUpAddString(atable, "ifndef");\r
+ includeAtom = LookUpAddString(atable, "include");\r
+ lineAtom = LookUpAddString(atable, "line");\r
+ pragmaAtom = LookUpAddString(atable, "pragma");\r
+ texunitAtom = LookUpAddString(atable, "texunit");\r
+ undefAtom = LookUpAddString(atable, "undef");\r
+ errorAtom = LookUpAddString(atable, "error");\r
+ __LINE__Atom = LookUpAddString(atable, "__LINE__");\r
+ __FILE__Atom = LookUpAddString(atable, "__FILE__");\r
+ __VERSION__Atom = LookUpAddString(atable, "__VERSION__");\r
+ versionAtom = LookUpAddString(atable, "version");\r
+ extensionAtom = LookUpAddString(atable, "extension");\r
+ macros = NewScopeInPool(mem_CreatePool(0, 0));\r
+ strcpy(buffer, "PROFILE_");\r
+ t = buffer + strlen(buffer);\r
+ f = cpp->options.profileString;\r
+ while ((_mesa_isalnum(*f) || *f == '_') && t < buffer + sizeof(buffer) - 1)\r
+ *t++ = toupper(*f++);\r
+ *t = 0;\r
+ return 1;\r
+} // InitCPP\r
+\r
+int FreeCPP(void)\r
+{\r
+ if (macros)\r
+ {\r
+ mem_FreePool(macros->pool);\r
+ macros = 0;\r
+ }\r
+\r
+ return 1;\r
+}\r
+\r
+int FinalCPP(void)\r
+{\r
+ if (cpp->ifdepth)\r
+ CPPErrorToInfoLog("#if mismatch");\r
+ return 1;\r
+}\r
+\r
+static int CPPdefine(yystypepp * yylvalpp)\r
+{\r
+ int token, name, args[MAX_MACRO_ARGS], argc;\r
+ const char *message;\r
+ MacroSymbol mac;\r
+ Symbol *symb;\r
+ SourceLoc dummyLoc;\r
+ memset(&mac, 0, sizeof(mac));\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if (token != CPP_IDENTIFIER) {\r
+ CPPErrorToInfoLog("#define");\r
+ return token;\r
+ }\r
+ name = yylvalpp->sc_ident;\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if (token == '(' && !yylvalpp->sc_int) {\r
+ // gather arguments\r
+ argc = 0;\r
+ do {\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if (argc == 0 && token == ')') break;\r
+ if (token != CPP_IDENTIFIER) {\r
+ CPPErrorToInfoLog("#define");\r
+ return token;\r
+ }\r
+ if (argc < MAX_MACRO_ARGS)\r
+ args[argc++] = yylvalpp->sc_ident;\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ } while (token == ',');\r
+ if (token != ')') {\r
+ CPPErrorToInfoLog("#define");\r
+ return token;\r
+ }\r
+ mac.argc = argc;\r
+ mac.args = mem_Alloc(macros->pool, argc * sizeof(int));\r
+ memcpy(mac.args, args, argc * sizeof(int));\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ }\r
+ mac.body = NewTokenStream(GetAtomString(atable, name));\r
+ while (token != '\n') {\r
+ while (token == '\\') {\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if (token == '\n')\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ else\r
+ RecordToken(mac.body, '\\', yylvalpp);\r
+ }\r
+ RecordToken(mac.body, token, yylvalpp);\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ };\r
+\r
+ symb = LookUpSymbol(macros, name);\r
+ if (symb) {\r
+ if (!symb->details.mac.undef) {\r
+ // already defined -- need to make sure they are identical\r
+ if (symb->details.mac.argc != mac.argc) goto error;\r
+ for (argc=0; argc < mac.argc; argc++)\r
+ if (symb->details.mac.args[argc] != mac.args[argc])\r
+ goto error;\r
+ RewindTokenStream(symb->details.mac.body);\r
+ RewindTokenStream(mac.body);\r
+ do {\r
+ int old_lval, old_token;\r
+ old_token = ReadToken(symb->details.mac.body, yylvalpp);\r
+ old_lval = yylvalpp->sc_int;\r
+ token = ReadToken(mac.body, yylvalpp);\r
+ if (token != old_token || yylvalpp->sc_int != old_lval) { \r
+ error:\r
+ StoreStr("Macro Redefined");\r
+ StoreStr(GetStringOfAtom(atable,name));\r
+ message=GetStrfromTStr();\r
+ DecLineNumber();\r
+ CPPShInfoLogMsg(message);\r
+ IncLineNumber();\r
+ ResetTString();\r
+ break; }\r
+ } while (token > 0);\r
+ }\r
+ FreeMacro(&symb->details.mac);\r
+ } else {\r
+ dummyLoc.file = 0;\r
+ dummyLoc.line = 0;\r
+ symb = AddSymbol(&dummyLoc, macros, name, MACRO_S);\r
+ }\r
+ symb->details.mac = mac;\r
+ return '\n';\r
+} // CPPdefine\r
+\r
+static int CPPundef(yystypepp * yylvalpp)\r
+{\r
+ int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ Symbol *symb;\r
+ if(token == '\n'){\r
+ CPPErrorToInfoLog("#undef");\r
+ return token;\r
+ }\r
+ if (token != CPP_IDENTIFIER)\r
+ goto error;\r
+ symb = LookUpSymbol(macros, yylvalpp->sc_ident);\r
+ if (symb) {\r
+ symb->details.mac.undef = 1;\r
+ }\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if (token != '\n') {\r
+ error:\r
+ CPPErrorToInfoLog("#undef");\r
+ }\r
+ return token;\r
+} // CPPundef\r
+\r
+/* CPPelse -- skip forward to appropriate spot. This is actually used\r
+** to skip to and #endif after seeing an #else, AND to skip to a #else,\r
+** #elif, or #endif after a #if/#ifdef/#ifndef/#elif test was false\r
+*/\r
+\r
+static int CPPelse(int matchelse, yystypepp * yylvalpp)\r
+{\r
+ int atom,depth=0;\r
+ int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ \r
+ while (token > 0) {\r
+ while (token != '\n')\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if ((token = cpp->currentInput->scan(cpp->currentInput, yylvalpp)) != '#')\r
+ continue;\r
+ if ((token = cpp->currentInput->scan(cpp->currentInput, yylvalpp)) != CPP_IDENTIFIER)\r
+ continue;\r
+ atom = yylvalpp->sc_ident;\r
+ if (atom == ifAtom || atom == ifdefAtom || atom == ifndefAtom){\r
+ depth++; cpp->ifdepth++; cpp->elsetracker++;\r
+ }\r
+ else if (atom == endifAtom) {\r
+ if(--depth<=0){\r
+ cpp->elsedepth[cpp->elsetracker]=0;\r
+ --cpp->elsetracker;\r
+ if (cpp->ifdepth) \r
+ --cpp->ifdepth;\r
+ break;\r
+ } \r
+ --cpp->elsetracker;\r
+ --cpp->ifdepth;\r
+ }\r
+ else if (((int)(matchelse) != 0)&& depth==0) {\r
+ if (atom == elseAtom ){\r
+ break;\r
+ } \r
+ else if (atom == elifAtom) {\r
+ /* we decrement cpp->ifdepth here, because CPPif will increment\r
+ * it and we really want to leave it alone */\r
+ if (cpp->ifdepth){\r
+ --cpp->ifdepth;\r
+ --cpp->elsetracker;\r
+ }\r
+ return CPPif(yylvalpp);\r
+ }\r
+ }\r
+ else if((atom==elseAtom) && (!ChkCorrectElseNesting())){\r
+ CPPErrorToInfoLog("#else after a #else");\r
+ cpp->CompileError=1;\r
+ }\r
+ };\r
+ return token;\r
+}\r
+\r
+enum eval_prec {\r
+ MIN_PREC,\r
+ COND, LOGOR, LOGAND, OR, XOR, AND, EQUAL, RELATION, SHIFT, ADD, MUL, UNARY,\r
+ MAX_PREC\r
+};\r
+\r
+static int op_logor(int a, int b) { return a || b; }\r
+static int op_logand(int a, int b) { return a && b; }\r
+static int op_or(int a, int b) { return a | b; }\r
+static int op_xor(int a, int b) { return a ^ b; }\r
+static int op_and(int a, int b) { return a & b; }\r
+static int op_eq(int a, int b) { return a == b; }\r
+static int op_ne(int a, int b) { return a != b; }\r
+static int op_ge(int a, int b) { return a >= b; }\r
+static int op_le(int a, int b) { return a <= b; }\r
+static int op_gt(int a, int b) { return a > b; }\r
+static int op_lt(int a, int b) { return a < b; }\r
+static int op_shl(int a, int b) { return a << b; }\r
+static int op_shr(int a, int b) { return a >> b; }\r
+static int op_add(int a, int b) { return a + b; }\r
+static int op_sub(int a, int b) { return a - b; }\r
+static int op_mul(int a, int b) { return a * b; }\r
+static int op_div(int a, int b) { return a / b; }\r
+static int op_mod(int a, int b) { return a % b; }\r
+static int op_pos(int a) { return a; }\r
+static int op_neg(int a) { return -a; }\r
+static int op_cmpl(int a) { return ~a; }\r
+static int op_not(int a) { return !a; }\r
+\r
+struct {\r
+ int token, prec, (*op)(int, int);\r
+} binop[] = {\r
+ { CPP_OR_OP, LOGOR, op_logor },\r
+ { CPP_AND_OP, LOGAND, op_logand },\r
+ { '|', OR, op_or },\r
+ { '^', XOR, op_xor },\r
+ { '&', AND, op_and },\r
+ { CPP_EQ_OP, EQUAL, op_eq },\r
+ { CPP_NE_OP, EQUAL, op_ne },\r
+ { '>', RELATION, op_gt },\r
+ { CPP_GE_OP, RELATION, op_ge },\r
+ { '<', RELATION, op_lt },\r
+ { CPP_LE_OP, RELATION, op_le },\r
+ { CPP_LEFT_OP, SHIFT, op_shl },\r
+ { CPP_RIGHT_OP, SHIFT, op_shr },\r
+ { '+', ADD, op_add },\r
+ { '-', ADD, op_sub },\r
+ { '*', MUL, op_mul },\r
+ { '/', MUL, op_div },\r
+ { '%', MUL, op_mod },\r
+};\r
+\r
+struct {\r
+ int token, (*op)(int);\r
+} unop[] = {\r
+ { '+', op_pos },\r
+ { '-', op_neg },\r
+ { '~', op_cmpl },\r
+ { '!', op_not },\r
+};\r
+\r
+#define ALEN(A) (sizeof(A)/sizeof(A[0]))\r
+\r
+static int eval(int token, int prec, int *res, int *err, yystypepp * yylvalpp)\r
+{\r
+ int i, val;\r
+ Symbol *s;\r
+ if (token == CPP_IDENTIFIER) {\r
+ if (yylvalpp->sc_ident == definedAtom) {\r
+ int needclose = 0;\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if (token == '(') {\r
+ needclose = 1;\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ }\r
+ if (token != CPP_IDENTIFIER)\r
+ goto error;\r
+ *res = (s = LookUpSymbol(macros, yylvalpp->sc_ident))\r
+ ? !s->details.mac.undef : 0;\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if (needclose) {\r
+ if (token != ')')\r
+ goto error;\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ }\r
+ } else if (MacroExpand(yylvalpp->sc_ident, yylvalpp)) {\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ return eval(token, prec, res, err, yylvalpp);\r
+ } else {\r
+ goto error;\r
+ }\r
+ } else if (token == CPP_INTCONSTANT) {\r
+ *res = yylvalpp->sc_int;\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ } else if (token == '(') {\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ token = eval(token, MIN_PREC, res, err, yylvalpp);\r
+ if (!*err) {\r
+ if (token != ')')\r
+ goto error;\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ }\r
+ } else {\r
+ for (i = ALEN(unop) - 1; i >= 0; i--) {\r
+ if (unop[i].token == token)\r
+ break;\r
+ }\r
+ if (i >= 0) {\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ token = eval(token, UNARY, res, err, yylvalpp);\r
+ *res = unop[i].op(*res);\r
+ } else {\r
+ goto error;\r
+ }\r
+ }\r
+ while (!*err) {\r
+ if (token == ')' || token == '\n') break;\r
+ for (i = ALEN(binop) - 1; i >= 0; i--) {\r
+ if (binop[i].token == token)\r
+ break;\r
+ }\r
+ if (i < 0 || binop[i].prec <= prec)\r
+ break;\r
+ val = *res;\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ token = eval(token, binop[i].prec, res, err, yylvalpp);\r
+ *res = binop[i].op(val, *res);\r
+ }\r
+ return token;\r
+error:\r
+ CPPErrorToInfoLog("#if");;\r
+ *err = 1;\r
+ *res = 0;\r
+ return token;\r
+} // eval\r
+\r
+static int CPPif(yystypepp * yylvalpp) {\r
+ int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ int res = 0, err = 0;\r
+ cpp->elsetracker++;\r
+ if (!cpp->ifdepth++)\r
+ ifloc = *cpp->tokenLoc;\r
+ if(cpp->ifdepth >MAX_IF_NESTING){\r
+ CPPErrorToInfoLog("max #if nesting depth exceeded");\r
+ return 0;\r
+ }\r
+ token = eval(token, MIN_PREC, &res, &err, yylvalpp);\r
+ if (token != '\n') {\r
+ CPPErrorToInfoLog("#if");\r
+ } else if (!res && !err) {\r
+ token = CPPelse(1, yylvalpp);\r
+ }\r
+ return token;\r
+} // CPPif\r
+\r
+static int CPPifdef(int defined, yystypepp * yylvalpp)\r
+{\r
+ int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ int name = yylvalpp->sc_ident;\r
+ if(++cpp->ifdepth >MAX_IF_NESTING){\r
+ CPPErrorToInfoLog("max #if nesting depth exceeded");\r
+ return 0;\r
+ }\r
+ cpp->elsetracker++;\r
+ if (token != CPP_IDENTIFIER) {\r
+ defined ? CPPErrorToInfoLog("ifdef"):CPPErrorToInfoLog("ifndef");\r
+ } else {\r
+ Symbol *s = LookUpSymbol(macros, name);\r
+ if (((s && !s->details.mac.undef) ? 1 : 0) != defined)\r
+ token = CPPelse(1, yylvalpp);\r
+ }\r
+ return token;\r
+} // CPPifdef\r
+\r
+static int CPPline(yystypepp * yylvalpp) \r
+{\r
+ int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if(token=='\n'){\r
+ DecLineNumber();\r
+ CPPErrorToInfoLog("#line");\r
+ IncLineNumber();\r
+ return token;\r
+ }\r
+ else if (token == CPP_INTCONSTANT) {\r
+ yylvalpp->sc_int=atoi(yylvalpp->symbol_name);\r
+ SetLineNumber(yylvalpp->sc_int);\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ \r
+ if (token == CPP_INTCONSTANT) {\r
+ yylvalpp->sc_int=atoi(yylvalpp->symbol_name);\r
+ SetStringNumber(yylvalpp->sc_int);\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if(token!='\n')\r
+ CPPErrorToInfoLog("#line");\r
+ }\r
+ else if (token == '\n'){\r
+ return token;\r
+ }\r
+ else{\r
+ CPPErrorToInfoLog("#line");\r
+ }\r
+ }\r
+ else{\r
+ CPPErrorToInfoLog("#line");\r
+ }\r
+ return token;\r
+}\r
+\r
+static int CPPerror(yystypepp * yylvalpp) {\r
+\r
+ int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ const char *message;\r
+ \r
+ while (token != '\n') {\r
+ if (token == CPP_FLOATCONSTANT || token == CPP_INTCONSTANT){\r
+ StoreStr(yylvalpp->symbol_name);\r
+ }else if(token == CPP_IDENTIFIER || token == CPP_STRCONSTANT){\r
+ StoreStr(GetStringOfAtom(atable,yylvalpp->sc_ident));\r
+ }else {\r
+ StoreStr(GetStringOfAtom(atable,token));\r
+ }\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ }\r
+ DecLineNumber();\r
+ //store this msg into the shader's information log..set the Compile Error flag!!!!\r
+ message=GetStrfromTStr();\r
+ CPPShInfoLogMsg(message);\r
+ ResetTString();\r
+ cpp->CompileError=1;\r
+ IncLineNumber();\r
+ return '\n';\r
+}//CPPerror\r
+\r
+static int CPPpragma(yystypepp * yylvalpp)\r
+{\r
+ const char *SrcStr;\r
+ const char *DestStr;\r
+ int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ \r
+ if(token=='\n'){\r
+ DecLineNumber();\r
+ CPPErrorToInfoLog("#pragma");\r
+ IncLineNumber();\r
+ return token;\r
+ }\r
+ if (token != CPP_IDENTIFIER)goto error;\r
+ SrcStr = GetAtomString(atable, yylvalpp->sc_ident);\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if (token == '(') {\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if (token != CPP_IDENTIFIER) goto error;\r
+ DestStr = GetAtomString(atable, yylvalpp->sc_ident);\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if (token != ')') goto error;\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if(token!='\n')goto error;\r
+ //make a call to CPP function MapStrings with SrcStr and DestStr.\r
+ MapStrings(SrcStr,DestStr);\r
+ }else{\r
+error:\r
+ CPPErrorToInfoLog("#pragma");\r
+ return token;\r
+ }\r
+\r
+ return token;\r
+} // CPPpragma\r
+\r
+#define GL2_VERSION_NUMBER 110\r
+\r
+static int CPPversion(yystypepp * yylvalpp)\r
+{\r
+\r
+ int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+\r
+ if (cpp->notAVersionToken == 1)\r
+ CPPShInfoLogMsg("#version must occur before any other statement in the program");\r
+\r
+ if(token=='\n'){\r
+ DecLineNumber();\r
+ CPPErrorToInfoLog("#version");\r
+ IncLineNumber();\r
+ return token;\r
+ }\r
+ if (token != CPP_INTCONSTANT)\r
+ CPPErrorToInfoLog("#version");\r
+ \r
+ yylvalpp->sc_int=atoi(yylvalpp->symbol_name);\r
+ //SetVersionNumber(yylvalpp->sc_int);\r
+ \r
+ if (yylvalpp->sc_int != GL2_VERSION_NUMBER)\r
+ CPPShInfoLogMsg("Version number not supported by GL2");\r
+\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ \r
+ if (token == '\n'){\r
+ return token;\r
+ }\r
+ else{\r
+ CPPErrorToInfoLog("#version");\r
+ }\r
+ return token;\r
+} // CPPversion\r
+\r
+static int CPPextension(yystypepp * yylvalpp)\r
+{\r
+\r
+ int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ char extensionName[80];\r
+\r
+ if(token=='\n'){\r
+ DecLineNumber();\r
+ CPPShInfoLogMsg("extension name not specified");\r
+ IncLineNumber();\r
+ return token;\r
+ }\r
+\r
+ if (token != CPP_IDENTIFIER)\r
+ CPPErrorToInfoLog("#extension");\r
+ \r
+ strcpy(extensionName, GetAtomString(atable, yylvalpp->sc_ident));\r
+ \r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if (token != ':') {\r
+ CPPShInfoLogMsg("':' missing after extension name");\r
+ return token;\r
+ }\r
+ \r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if (token != CPP_IDENTIFIER) {\r
+ CPPShInfoLogMsg("behavior for extension not specified");\r
+ return token;\r
+ }\r
+\r
+ updateExtensionBehavior(extensionName, GetAtomString(atable, yylvalpp->sc_ident));\r
+\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if (token == '\n'){\r
+ return token;\r
+ }\r
+ else{\r
+ CPPErrorToInfoLog("#extension");\r
+ }\r
+ return token;\r
+} // CPPextension\r
+\r
+int readCPPline(yystypepp * yylvalpp)\r
+{\r
+ int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ const char *message;\r
+ int isVersion = 0;\r
+\r
+ if (token == CPP_IDENTIFIER) {\r
+ if (yylvalpp->sc_ident == defineAtom) {\r
+ token = CPPdefine(yylvalpp);\r
+ } else if (yylvalpp->sc_ident == elseAtom) {\r
+ if(ChkCorrectElseNesting()){\r
+ if (!cpp->ifdepth ){\r
+ CPPErrorToInfoLog("#else mismatch");\r
+ cpp->CompileError=1;\r
+ }\r
+ token = CPPelse(0, yylvalpp);\r
+ }else{\r
+ CPPErrorToInfoLog("#else after a #else");\r
+ cpp->ifdepth=0;\r
+ cpp->notAVersionToken = 1;\r
+ return 0;\r
+ }\r
+ } else if (yylvalpp->sc_ident == elifAtom) {\r
+ if (!cpp->ifdepth){\r
+ CPPErrorToInfoLog("#elif mismatch");\r
+ cpp->CompileError=1;\r
+ } \r
+ token = CPPelse(0, yylvalpp);\r
+ } else if (yylvalpp->sc_ident == endifAtom) {\r
+ cpp->elsedepth[cpp->elsetracker]=0;\r
+ --cpp->elsetracker;\r
+ if (!cpp->ifdepth){\r
+ CPPErrorToInfoLog("#endif mismatch");\r
+ cpp->CompileError=1;\r
+ }\r
+ else\r
+ --cpp->ifdepth;\r
+ } else if (yylvalpp->sc_ident == ifAtom) {\r
+ token = CPPif(yylvalpp);\r
+ } else if (yylvalpp->sc_ident == ifdefAtom) {\r
+ token = CPPifdef(1, yylvalpp);\r
+ } else if (yylvalpp->sc_ident == ifndefAtom) {\r
+ token = CPPifdef(0, yylvalpp);\r
+ } else if (yylvalpp->sc_ident == lineAtom) {\r
+ token = CPPline(yylvalpp);\r
+ } else if (yylvalpp->sc_ident == pragmaAtom) {\r
+ token = CPPpragma(yylvalpp);\r
+ } else if (yylvalpp->sc_ident == undefAtom) {\r
+ token = CPPundef(yylvalpp);\r
+ } else if (yylvalpp->sc_ident == errorAtom) {\r
+ token = CPPerror(yylvalpp);\r
+ } else if (yylvalpp->sc_ident == versionAtom) {\r
+ token = CPPversion(yylvalpp);\r
+ isVersion = 1;\r
+ } else if (yylvalpp->sc_ident == extensionAtom) {\r
+ token = CPPextension(yylvalpp);\r
+ } else {\r
+ StoreStr("Invalid Directive");\r
+ StoreStr(GetStringOfAtom(atable,yylvalpp->sc_ident));\r
+ message=GetStrfromTStr();\r
+ CPPShInfoLogMsg(message);\r
+ ResetTString();\r
+ }\r
+ }\r
+ while (token != '\n' && token != 0 && token != EOF) {\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ }\r
+ \r
+ cpp->notAVersionToken = !isVersion;\r
+\r
+ return token;\r
+} // readCPPline\r
+\r
+void FreeMacro(MacroSymbol *s) {\r
+ DeleteTokenStream(s->body);\r
+}\r
+\r
+static int eof_scan(InputSrc *in, yystypepp * yylvalpp) { return -1; }\r
+static void noop(InputSrc *in, int ch, yystypepp * yylvalpp) { }\r
+\r
+static void PushEofSrc() {\r
+ InputSrc *in = malloc(sizeof(InputSrc));\r
+ memset(in, 0, sizeof(InputSrc));\r
+ in->scan = eof_scan;\r
+ in->getch = eof_scan;\r
+ in->ungetch = noop;\r
+ in->prev = cpp->currentInput;\r
+ cpp->currentInput = in;\r
+}\r
+\r
+static void PopEofSrc() {\r
+ if (cpp->currentInput->scan == eof_scan) {\r
+ InputSrc *in = cpp->currentInput;\r
+ cpp->currentInput = in->prev;\r
+ free(in);\r
+ }\r
+}\r
+\r
+static TokenStream *PrescanMacroArg(TokenStream *a, yystypepp * yylvalpp) {\r
+ int token;\r
+ TokenStream *n;\r
+ RewindTokenStream(a);\r
+ do {\r
+ token = ReadToken(a, yylvalpp);\r
+ if (token == CPP_IDENTIFIER && LookUpSymbol(macros, yylvalpp->sc_ident))\r
+ break;\r
+ } while (token > 0);\r
+ if (token <= 0) return a;\r
+ n = NewTokenStream("macro arg");\r
+ PushEofSrc();\r
+ ReadFromTokenStream(a, 0, 0);\r
+ while ((token = cpp->currentInput->scan(cpp->currentInput, yylvalpp)) > 0) {\r
+ if (token == CPP_IDENTIFIER && MacroExpand(yylvalpp->sc_ident, yylvalpp))\r
+ continue;\r
+ RecordToken(n, token, yylvalpp);\r
+ }\r
+ PopEofSrc();\r
+ DeleteTokenStream(a);\r
+ return n;\r
+} // PrescanMacroArg\r
+\r
+typedef struct MacroInputSrc {\r
+ InputSrc base;\r
+ MacroSymbol *mac;\r
+ TokenStream **args;\r
+} MacroInputSrc;\r
+\r
+/* macro_scan ---\r
+** return the next token for a macro expanion, handling macro args \r
+*/\r
+static int macro_scan(MacroInputSrc *in, yystypepp * yylvalpp) {\r
+ int i;\r
+ int token = ReadToken(in->mac->body, yylvalpp);\r
+ if (token == CPP_IDENTIFIER) {\r
+ for (i = in->mac->argc-1; i>=0; i--)\r
+ if (in->mac->args[i] == yylvalpp->sc_ident) break;\r
+ if (i >= 0) {\r
+ ReadFromTokenStream(in->args[i], yylvalpp->sc_ident, 0);\r
+ return cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ }\r
+ }\r
+ if (token > 0) return token;\r
+ in->mac->busy = 0;\r
+ cpp->currentInput = in->base.prev;\r
+ if (in->args) {\r
+ for (i=in->mac->argc-1; i>=0; i--)\r
+ DeleteTokenStream(in->args[i]);\r
+ free(in->args);\r
+ }\r
+ free(in);\r
+ return cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+} // macro_scan\r
+\r
+/* MacroExpand\r
+** check an identifier (atom) to see if it a macro that should be expanded.\r
+** If it is, push an InputSrc that will produce the appropriate expansion\r
+** and return TRUE. If not, return FALSE.\r
+*/\r
+\r
+int MacroExpand(int atom, yystypepp * yylvalpp)\r
+{\r
+ Symbol *sym = LookUpSymbol(macros, atom);\r
+ MacroInputSrc *in;\r
+ int i,j, token, depth=0;\r
+ const char *message;\r
+ if (atom == __LINE__Atom) {\r
+ yylvalpp->sc_int = GetLineNumber();\r
+ sprintf(yylvalpp->symbol_name,"%d",yylvalpp->sc_int);\r
+ UngetToken(CPP_INTCONSTANT, yylvalpp);\r
+ return 1;\r
+ }\r
+ if (atom == __FILE__Atom) {\r
+ yylvalpp->sc_int = GetStringNumber();\r
+ sprintf(yylvalpp->symbol_name,"%d",yylvalpp->sc_int);\r
+ UngetToken(CPP_INTCONSTANT, yylvalpp);\r
+ return 1;\r
+ }\r
+ if (atom == __VERSION__Atom) {\r
+ strcpy(yylvalpp->symbol_name,"100");\r
+ yylvalpp->sc_int = atoi(yylvalpp->symbol_name);\r
+ UngetToken(CPP_INTCONSTANT, yylvalpp);\r
+ return 1;\r
+ }\r
+ if (!sym || sym->details.mac.undef) return 0;\r
+ if (sym->details.mac.busy) return 0; // no recursive expansions\r
+ in = malloc(sizeof(*in));\r
+ memset(in, 0, sizeof(*in));\r
+ in->base.scan = (void *)macro_scan;\r
+ in->base.line = cpp->currentInput->line;\r
+ in->base.name = cpp->currentInput->name;\r
+ in->mac = &sym->details.mac;\r
+ if (sym->details.mac.args) {\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if (token != '(') {\r
+ UngetToken(token, yylvalpp);\r
+ yylvalpp->sc_ident = atom;\r
+ return 0;\r
+ }\r
+ in->args = malloc(in->mac->argc * sizeof(TokenStream *));\r
+ for (i=0; i<in->mac->argc; i++)\r
+ in->args[i] = NewTokenStream("macro arg");\r
+ i=0;j=0;\r
+ do{\r
+ depth = 0;\r
+ while(1) {\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if (token <= 0) {\r
+ StoreStr("EOF in Macro ");\r
+ StoreStr(GetStringOfAtom(atable,atom));\r
+ message=GetStrfromTStr();\r
+ CPPShInfoLogMsg(message);\r
+ ResetTString();\r
+ return 1;\r
+ }\r
+ if((in->mac->argc==0) && (token!=')')) break;\r
+ if (depth == 0 && (token == ',' || token == ')')) break;\r
+ if (token == '(') depth++;\r
+ if (token == ')') depth--;\r
+ RecordToken(in->args[i], token, yylvalpp);\r
+ j=1;\r
+ }\r
+ if (token == ')') {\r
+ if((in->mac->argc==1) &&j==0)\r
+ break;\r
+ i++;\r
+ break;\r
+ }\r
+ i++;\r
+ }while(i < in->mac->argc);\r
+\r
+ if (i < in->mac->argc) {\r
+ StoreStr("Too few args in Macro ");\r
+ StoreStr(GetStringOfAtom(atable,atom));\r
+ message=GetStrfromTStr();\r
+ CPPShInfoLogMsg(message);\r
+ ResetTString();\r
+ } else if (token != ')') {\r
+ depth=0;\r
+ while (token >= 0 && (depth > 0 || token != ')')) {\r
+ if (token == ')') depth--;\r
+ token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+ if (token == '(') depth++;\r
+ }\r
+ \r
+ if (token <= 0) {\r
+ StoreStr("EOF in Macro ");\r
+ StoreStr(GetStringOfAtom(atable,atom));\r
+ message=GetStrfromTStr();\r
+ CPPShInfoLogMsg(message);\r
+ ResetTString();\r
+ return 1;\r
+ }\r
+ StoreStr("Too many args in Macro ");\r
+ StoreStr(GetStringOfAtom(atable,atom));\r
+ message=GetStrfromTStr();\r
+ CPPShInfoLogMsg(message);\r
+ ResetTString();\r
+ }\r
+ for (i=0; i<in->mac->argc; i++) {\r
+ in->args[i] = PrescanMacroArg(in->args[i], yylvalpp);\r
+ }\r
+ }\r
+#if 0\r
+ printf(" <%s:%d>found macro %s\n", GetAtomString(atable, loc.file),\r
+ loc.line, GetAtomString(atable, atom));\r
+ for (i=0; i<in->mac->argc; i++) {\r
+ printf("\targ %s = '", GetAtomString(atable, in->mac->args[i]));\r
+ DumpTokenStream(stdout, in->args[i]);\r
+ printf("'\n");\r
+ }\r
+#endif\r
+ /*retain the input source*/\r
+ in->base.prev = cpp->currentInput;\r
+ sym->details.mac.busy = 1;\r
+ RewindTokenStream(sym->details.mac.body);\r
+ cpp->currentInput = &in->base;\r
+ return 1;\r
+} // MacroExpand\r
+\r
+int ChkCorrectElseNesting(void)\r
+{\r
+ if(cpp->elsedepth[cpp->elsetracker]==0){\r
+ cpp->elsedepth[cpp->elsetracker]=1;\r
+ return 1; \r
+ }\r
+ return 0;\r
+}\r
+\r
+\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+//\r
+// cpp.h\r
+//\r
+\r
+#if !defined(__CPP_H)\r
+#define __CPP_H 1\r
+\r
+#include "parser.h"\r
+#include "tokens.h"\r
+\r
+int InitCPP(void);\r
+int FinalCPP(void);\r
+int readCPPline(yystypepp * yylvalpp);\r
+int MacroExpand(int atom, yystypepp * yylvalpp);\r
+int ChkCorrectElseNesting(void);\r
+\r
+typedef struct MacroSymbol {\r
+ int argc;\r
+ int *args;\r
+ TokenStream *body;\r
+ unsigned busy:1;\r
+ unsigned undef:1;\r
+} MacroSymbol;\r
+\r
+void FreeMacro(MacroSymbol *);\r
+int PredefineMacro(char *);\r
+\r
+void CPPDebugLogMsg(const char *msg); // Prints information into debug log\r
+void CPPShInfoLogMsg(const char*); // Store cpp Err Msg into Sh.Info.Log\r
+void MapStrings(const char*,const char*); // #pragma directive container.\r
+void ResetTString(void); // #error Message as TString.\r
+void CPPErrorToInfoLog(char*); // Stick all cpp errors into Sh.Info.log .\r
+void StoreStr(char*); // Store the TString in Parse Context.\r
+void SetLineNumber(int); // Set line number. \r
+void SetStringNumber(int); // Set string number. \r
+int GetLineNumber(void); // Get the current String Number. \r
+int GetStringNumber(void); // Get the current String Number. \r
+const char* GetStrfromTStr(void); // Convert TString to String. \r
+void updateExtensionBehavior(const char* extName, const char* behavior);\r
+int FreeCPP(void);\r
+\r
+#endif // !(defined(__CPP_H)\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+//\r
+// cppstruct.c\r
+//\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+\r
+#include "slglobals.h"\r
+\r
+CPPStruct *cpp = NULL;\r
+static int refCount = 0;\r
+\r
+int InitPreprocessor(void);\r
+int ResetPreprocessor(void);\r
+int FreeCPPStruct(void);\r
+int FinalizePreprocessor(void);\r
+\r
+/*\r
+ * InitCPPStruct() - Initilaize the CPP structure.\r
+ *\r
+ */\r
+\r
+int InitCPPStruct(void)\r
+{\r
+ int len;\r
+ char *p;\r
+\r
+ cpp = (CPPStruct *) malloc(sizeof(CPPStruct));\r
+ if (cpp == NULL)\r
+ return 0;\r
+\r
+ refCount++;\r
+\r
+ // Initialize public members:\r
+ cpp->pLastSourceLoc = &cpp->lastSourceLoc;\r
+ \r
+ p = (char *) &cpp->options;\r
+ len = sizeof(cpp->options);\r
+ while (--len >= 0)\r
+ p[len] = 0;\r
+ \r
+ ResetPreprocessor();\r
+ return 1;\r
+} // InitCPPStruct\r
+\r
+int ResetPreprocessor(void)\r
+{\r
+ // Initialize private members:\r
+\r
+ cpp->lastSourceLoc.file = 0;\r
+ cpp->lastSourceLoc.line = 0;\r
+ cpp->pC=0;\r
+ cpp->CompileError=0; \r
+ cpp->ifdepth=0;\r
+ for(cpp->elsetracker=0; cpp->elsetracker<64; cpp->elsetracker++)\r
+ cpp->elsedepth[cpp->elsetracker]=0; \r
+ cpp->elsetracker=0;\r
+ return 1;\r
+}\r
+\r
+//Intializing the Preprocessor.\r
+\r
+int InitPreprocessor(void)\r
+{\r
+ # define CPP_STUFF true\r
+ # ifdef CPP_STUFF\r
+ FreeCPPStruct();\r
+ InitCPPStruct();\r
+ cpp->options.Quiet = 1;\r
+ cpp->options.profileString = "generic";\r
+ if (!InitAtomTable(atable, 0))\r
+ return 1;\r
+ if (!InitScanner(cpp))\r
+ return 1;\r
+ # endif\r
+ return 0; \r
+}\r
+\r
+//FreeCPPStruct() - Free the CPP structure.\r
+\r
+int FreeCPPStruct(void)\r
+{\r
+ if (refCount)\r
+ {\r
+ free(cpp);\r
+ refCount--;\r
+ }\r
+ \r
+ return 1;\r
+}\r
+\r
+//Finalizing the Preprocessor.\r
+\r
+int FinalizePreprocessor(void)\r
+{\r
+ # define CPP_STUFF true\r
+ # ifdef CPP_STUFF\r
+ FreeAtomTable(atable);\r
+ FreeCPPStruct();\r
+ FreeScanner();\r
+ # endif\r
+ return 0; \r
+}\r
+\r
+\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+////////////////////////////////////// End of cppstruct.c //////////////////////////////////////\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+//\r
+#include <stddef.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+#ifdef __STDC99__\r
+#include <stdint.h>\r
+#elif defined (_WIN64)\r
+typedef unsigned __int64 uintptr_t;\r
+#else \r
+typedef unsigned int uintptr_t;\r
+#endif\r
+\r
+#include "memory.h"\r
+\r
+// default alignment and chunksize, if called with 0 arguments\r
+#define CHUNKSIZE (64*1024)\r
+#define ALIGN 8\r
+\r
+// we need to call the `real' malloc and free, not our replacements\r
+#undef malloc\r
+#undef free\r
+\r
+struct chunk {\r
+ struct chunk *next;\r
+};\r
+\r
+struct cleanup {\r
+ struct cleanup *next;\r
+ void (*fn)(void *);\r
+ void *arg;\r
+};\r
+\r
+struct MemoryPool_rec {\r
+ struct chunk *next;\r
+ uintptr_t free, end;\r
+ size_t chunksize;\r
+ uintptr_t alignmask;\r
+ struct cleanup *cleanup;\r
+};\r
+\r
+MemoryPool *mem_CreatePool(size_t chunksize, unsigned int align)\r
+{\r
+ MemoryPool *pool;\r
+\r
+ if (align == 0) align = ALIGN;\r
+ if (chunksize == 0) chunksize = CHUNKSIZE;\r
+ if (align & (align-1)) return 0;\r
+ if (chunksize < sizeof(MemoryPool)) return 0;\r
+ if (chunksize & (align-1)) return 0;\r
+ if (!(pool = malloc(chunksize))) return 0;\r
+ pool->next = 0;\r
+ pool->chunksize = chunksize;\r
+ pool->alignmask = (uintptr_t)(align)-1; \r
+ pool->free = ((uintptr_t)(pool + 1) + pool->alignmask) & ~pool->alignmask;\r
+ pool->end = (uintptr_t)pool + chunksize;\r
+ pool->cleanup = 0;\r
+ return pool;\r
+}\r
+\r
+void mem_FreePool(MemoryPool *pool)\r
+{\r
+ struct cleanup *cleanup;\r
+ struct chunk *p, *next;\r
+\r
+ for (cleanup = pool->cleanup; cleanup; cleanup = cleanup->next) {\r
+ cleanup->fn(cleanup->arg);\r
+ }\r
+ for (p = (struct chunk *)pool; p; p = next) {\r
+ next = p->next;\r
+ free(p);\r
+ }\r
+}\r
+\r
+void *mem_Alloc(MemoryPool *pool, size_t size)\r
+{\r
+ struct chunk *ch;\r
+ void *rv = (void *)pool->free;\r
+ size = (size + pool->alignmask) & ~pool->alignmask;\r
+ if (size <= 0) size = pool->alignmask;\r
+ pool->free += size;\r
+ if (pool->free > pool->end || pool->free < (uintptr_t)rv) {\r
+ size_t minreq = (size + sizeof(struct chunk) + pool->alignmask)\r
+ & ~pool->alignmask;\r
+ pool->free = (uintptr_t)rv;\r
+ if (minreq >= pool->chunksize) {\r
+ // request size is too big for the chunksize, so allocate it as\r
+ // a single chunk of the right size\r
+ ch = malloc(minreq);\r
+ if (!ch) return 0;\r
+ } else {\r
+ ch = malloc(pool->chunksize);\r
+ if (!ch) return 0;\r
+ pool->free = (uintptr_t)ch + minreq;\r
+ pool->end = (uintptr_t)ch + pool->chunksize;\r
+ }\r
+ ch->next = pool->next;\r
+ pool->next = ch;\r
+ rv = (void *)(((uintptr_t)(ch+1) + pool->alignmask) & ~pool->alignmask);\r
+ }\r
+ return rv;\r
+}\r
+\r
+int mem_AddCleanup(MemoryPool *pool, void (*fn)(void *), void *arg) {\r
+ struct cleanup *cleanup;\r
+\r
+ pool->free = (pool->free + sizeof(void *) - 1) & ~(sizeof(void *)-1);\r
+ cleanup = mem_Alloc(pool, sizeof(struct cleanup));\r
+ if (!cleanup) return -1;\r
+ cleanup->next = pool->cleanup;\r
+ cleanup->fn = fn;\r
+ cleanup->arg = arg;\r
+ pool->cleanup = cleanup;\r
+ return 0;\r
+}\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+//\r
+#ifndef __MEMORY_H\r
+#define __MEMORY_H\r
+\r
+typedef struct MemoryPool_rec MemoryPool;\r
+\r
+extern MemoryPool *mem_CreatePool(size_t chunksize, unsigned align);\r
+extern void mem_FreePool(MemoryPool *);\r
+extern void *mem_Alloc(MemoryPool *p, size_t size);\r
+extern void *mem_Realloc(MemoryPool *p, void *old, size_t oldsize, size_t newsize);\r
+extern int mem_AddCleanup(MemoryPool *p, void (*fn)(void *), void *arg);\r
+\r
+#endif /* __MEMORY_H */\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+\r
+#ifndef BISON_PARSER_H\r
+# define BISON_PARSER_H\r
+\r
+#ifndef yystypepp\r
+typedef struct {\r
+ int sc_int;\r
+ float sc_fval;\r
+ int sc_ident;\r
+ char symbol_name[MAX_SYMBOL_NAME_LEN+1];\r
+} yystypepp;\r
+\r
+# define YYSTYPE_IS_TRIVIAL 1\r
+#endif\r
+# define CPP_AND_OP 257\r
+# define CPP_SUB_ASSIGN 259\r
+# define CPP_MOD_ASSIGN 260\r
+# define CPP_ADD_ASSIGN 261\r
+# define CPP_DIV_ASSIGN 262\r
+# define CPP_MUL_ASSIGN 263\r
+# define CPP_EQ_OP 264\r
+# define CPP_XOR_OP 265 \r
+# define ERROR_SY 266\r
+# define CPP_FLOATCONSTANT 267\r
+# define CPP_GE_OP 268\r
+# define CPP_RIGHT_OP 269\r
+# define CPP_IDENTIFIER 270\r
+# define CPP_INTCONSTANT 271\r
+# define CPP_LE_OP 272\r
+# define CPP_LEFT_OP 273\r
+# define CPP_DEC_OP 274\r
+# define CPP_NE_OP 275\r
+# define CPP_OR_OP 276\r
+# define CPP_INC_OP 277\r
+# define CPP_STRCONSTANT 278\r
+# define CPP_TYPEIDENTIFIER 279\r
+\r
+# define FIRST_USER_TOKEN_SY 289\r
+\r
+# define CPP_RIGHT_ASSIGN 280\r
+# define CPP_LEFT_ASSIGN 281\r
+# define CPP_AND_ASSIGN 282\r
+# define CPP_OR_ASSIGN 283\r
+# define CPP_XOR_ASSIGN 284\r
+# define CPP_LEFT_BRACKET 285\r
+# define CPP_RIGHT_BRACKET 286\r
+# define CPP_LEFT_BRACE 287\r
+# define CPP_RIGHT_BRACE 288\r
+\r
+#endif /* not BISON_PARSER_H */\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+\r
+# include "slglobals.h"\r
+extern CPPStruct *cpp;\r
+int InitCPPStruct(void);\r
+int InitScanner(CPPStruct *cpp);\r
+int InitAtomTable(AtomTable *atable, int htsize);\r
+int ScanFromString(char *s);\r
+char* GetStringOfAtom(AtomTable *atable, int atom);\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+//\r
+// scanner.c\r
+//\r
+\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+#if 0\r
+ #include <ieeefp.h>\r
+ #else\r
+ #define isinff(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && \\r
+ ((*(long *)&(x) & 0x007fffffL)==0000000000L))\r
+#endif\r
+\r
+#include "slglobals.h"\r
+\r
+\r
+typedef struct StringInputSrc {\r
+ InputSrc base;\r
+ char *p;\r
+} StringInputSrc;\r
+\r
+static int eof_scan(InputSrc *is, yystypepp * yylvalpp)\r
+{\r
+ return EOF;\r
+} // eof_scan\r
+\r
+static void noop(InputSrc *in, int ch, yystypepp * yylvalpp) {}\r
+\r
+static InputSrc eof_inputsrc = { 0, &eof_scan, &eof_scan, &noop };\r
+\r
+static int byte_scan(InputSrc *, yystypepp * yylvalpp);\r
+\r
+#define EOL_SY '\n'\r
+\r
+#if defined(_WIN32)\r
+ #define DBG_BREAKPOINT() __asm int 3\r
+ #elif defined(_M_AMD64)\r
+ #define DBG_BREAKPOINT() assert(!"Dbg_Breakpoint");\r
+ #else\r
+ #define DBG_BREAKPOINT()\r
+ #endif\r
+\r
+ #if defined(_WIN32) && !defined(_M_AMD64)\r
+ __int64 RDTSC ( void ) {\r
+\r
+ __int64 v;\r
+ \r
+ __asm __emit 0x0f\r
+ __asm __emit 0x31\r
+ __asm mov dword ptr v, eax\r
+ __asm mov dword ptr v+4, edx\r
+ \r
+ return v;\r
+ }\r
+#endif\r
+\r
+\r
+int InitScanner(CPPStruct *cpp)\r
+{\r
+ // Add various atoms needed by the CPP line scanner:\r
+ if (!InitCPP())\r
+ return 0;\r
+\r
+ cpp->mostRecentToken = 0;\r
+ cpp->tokenLoc = &cpp->ltokenLoc;\r
+\r
+ cpp->ltokenLoc.file = 0;\r
+ cpp->ltokenLoc.line = 0;\r
+\r
+ cpp->currentInput = &eof_inputsrc;\r
+ cpp->previous_token = '\n';\r
+ cpp->notAVersionToken = 0;\r
+\r
+ return 1;\r
+} // InitScanner\r
+\r
+int FreeScanner(void)\r
+{\r
+ return (FreeCPP());\r
+}\r
+\r
+/*\r
+ * str_getch()\r
+ * takes care of reading from multiple strings.\r
+ * returns the next-char from the input stream.\r
+ * returns EOF when the complete shader is parsed.\r
+ */\r
+static int str_getch(StringInputSrc *in)\r
+{\r
+ for(;;){\r
+ if (*in->p){\r
+ if (*in->p == '\n') {\r
+ in->base.line++;\r
+ IncLineNumber();\r
+ }\r
+ return *in->p++;\r
+ }\r
+ if(++(cpp->PaWhichStr) < cpp->PaArgc){\r
+ free(in);\r
+ SetStringNumber(cpp->PaWhichStr);\r
+ SetLineNumber(1);\r
+ ScanFromString(cpp->PaArgv[cpp->PaWhichStr]);\r
+ in=(StringInputSrc*)cpp->currentInput;\r
+ continue; \r
+ }\r
+ else{\r
+ cpp->currentInput = in->base.prev;\r
+ cpp->PaWhichStr=0;\r
+ free(in);\r
+ return EOF;\r
+ } \r
+ }\r
+} // str_getch\r
+\r
+static void str_ungetch(StringInputSrc *in, int ch, yystypepp *type) {\r
+ if (in->p[-1] == ch)in->p--;\r
+ else {\r
+ *(in->p)='\0'; //this would take care of shifting to the previous string.\r
+ cpp->PaWhichStr--;\r
+ } \r
+ if (ch == '\n') {\r
+ in->base.line--;\r
+ DecLineNumber();\r
+ }\r
+} // str_ungetch\r
+\r
+int ScanFromString(char *s)\r
+{\r
+ \r
+ StringInputSrc *in = malloc(sizeof(StringInputSrc));\r
+ memset(in, 0, sizeof(StringInputSrc));\r
+ in->p = s;\r
+ in->base.line = 1;\r
+ in->base.scan = byte_scan;\r
+ in->base.getch = (int (*)(InputSrc *, yystypepp *))str_getch;\r
+ in->base.ungetch = (void (*)(InputSrc *, int, yystypepp *))str_ungetch;\r
+ in->base.prev = cpp->currentInput;\r
+ cpp->currentInput = &in->base;\r
+\r
+ return 1;\r
+} // ScanFromString;\r
+\r
+\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+/////////////////////////////////// Floating point constants: /////////////////////////////////\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+/*\r
+ * lBuildFloatValue() - Quick and dirty conversion to floating point. Since all\r
+ * we need is single precision this should be quite precise.\r
+ */\r
+\r
+static float lBuildFloatValue(const char *str, int len, int exp)\r
+{\r
+ double val, expval, ten;\r
+ int ii, llen, absexp;\r
+ float rv;\r
+\r
+ val = 0.0;\r
+ llen = len;\r
+ for (ii = 0; ii < len; ii++)\r
+ val = val*10.0 + (str[ii] - '0');\r
+ if (exp != 0) {\r
+ absexp = exp > 0 ? exp : -exp;\r
+ expval = 1.0f;\r
+ ten = 10.0;\r
+ while (absexp) {\r
+ if (absexp & 1)\r
+ expval *= ten;\r
+ ten *= ten;\r
+ absexp >>= 1;\r
+ }\r
+ if (exp >= 0) {\r
+ val *= expval;\r
+ } else {\r
+ val /= expval;\r
+ }\r
+ }\r
+ rv = (float)val;\r
+ if (isinff(rv)) {\r
+ CPPErrorToInfoLog(" ERROR___FP_CONST_OVERFLOW");\r
+ }\r
+ return rv;\r
+} // lBuildFloatValue\r
+\r
+\r
+/*\r
+ * lFloatConst() - Scan a floating point constant. Assumes that the scanner\r
+ * has seen at least one digit, followed by either a decimal '.' or the\r
+ * letter 'e'.\r
+ */\r
+\r
+static int lFloatConst(char *str, int len, int ch, yystypepp * yylvalpp)\r
+{\r
+ int HasDecimal, declen, exp, ExpSign;\r
+ int str_len;\r
+ float lval;\r
+ \r
+ HasDecimal = 0;\r
+ declen = 0;\r
+ exp = 0;\r
+ \r
+ str_len=len;\r
+ if (ch == '.') {\r
+ str[len++]=ch;\r
+ HasDecimal = 1;\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ while (ch >= '0' && ch <= '9') {\r
+ if (len < MAX_SYMBOL_NAME_LEN) {\r
+ declen++;\r
+ if (len > 0 || ch != '0') {\r
+ str[len] = ch;\r
+ len++;str_len++;\r
+ }\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ } else {\r
+ CPPErrorToInfoLog("ERROR___FP_CONST_TOO_LONG");\r
+ len = 1,str_len=1;\r
+ }\r
+ }\r
+ }\r
+\r
+ // Exponent:\r
+\r
+ if (ch == 'e' || ch == 'E') {\r
+ ExpSign = 1;\r
+ str[len++]=ch;\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == '+') {\r
+ str[len++]=ch; \r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ } else if (ch == '-') {\r
+ ExpSign = -1;\r
+ str[len++]=ch;\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ }\r
+ if (ch >= '0' && ch <= '9') {\r
+ while (ch >= '0' && ch <= '9') {\r
+ exp = exp*10 + ch - '0';\r
+ str[len++]=ch;\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ }\r
+ } else {\r
+ CPPErrorToInfoLog("ERROR___ERROR_IN_EXPONENT");\r
+ }\r
+ exp *= ExpSign;\r
+ }\r
+ \r
+ if (len == 0) {\r
+ lval = 0.0f;\r
+ strcpy(str,"0.0");\r
+ } else {\r
+ str[len]='\0'; \r
+ lval = lBuildFloatValue(str, str_len, exp - declen);\r
+ }\r
+ // Suffix:\r
+ \r
+ yylvalpp->sc_fval = lval;\r
+ strcpy(yylvalpp->symbol_name,str);\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp); \r
+ return CPP_FLOATCONSTANT;\r
+} // lFloatConst\r
+\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+///////////////////////////////////////// Normal Scanner //////////////////////////////////////\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+ \r
+static int byte_scan(InputSrc *in, yystypepp * yylvalpp)\r
+{\r
+ char symbol_name[MAX_SYMBOL_NAME_LEN + 1];\r
+ char string_val[MAX_STRING_LEN + 1];\r
+ int AlreadyComplained;\r
+ int len, ch, ii, ival = 0;\r
+\r
+ for (;;) {\r
+ yylvalpp->sc_int = 0;\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ \r
+ while (ch == ' ' || ch == '\t' || ch == '\r') {\r
+ yylvalpp->sc_int = 1;\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ }\r
+ \r
+ cpp->ltokenLoc.file = cpp->currentInput->name;\r
+ cpp->ltokenLoc.line = cpp->currentInput->line;\r
+ len = 0;\r
+ switch (ch) {\r
+ default:\r
+ return ch; // Single character token\r
+ case EOF:\r
+ return -1;\r
+ case 'A': case 'B': case 'C': case 'D': case 'E':\r
+ case 'F': case 'G': case 'H': case 'I': case 'J':\r
+ case 'K': case 'L': case 'M': case 'N': case 'O':\r
+ case 'P': case 'Q': case 'R': case 'S': case 'T':\r
+ case 'U': case 'V': case 'W': case 'X': case 'Y':\r
+ case 'Z': case '_':\r
+ case 'a': case 'b': case 'c': case 'd': case 'e':\r
+ case 'f': case 'g': case 'h': case 'i': case 'j':\r
+ case 'k': case 'l': case 'm': case 'n': case 'o':\r
+ case 'p': case 'q': case 'r': case 's': case 't':\r
+ case 'u': case 'v': case 'w': case 'x': case 'y':\r
+ case 'z': \r
+ do {\r
+ if (len < MAX_SYMBOL_NAME_LEN) {\r
+ symbol_name[len] = ch;\r
+ len++;\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ } else {\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ }\r
+ } while ((ch >= 'a' && ch <= 'z') ||\r
+ (ch >= 'A' && ch <= 'Z') ||\r
+ (ch >= '0' && ch <= '9') ||\r
+ ch == '_');\r
+ if (len >= MAX_SYMBOL_NAME_LEN)\r
+ len = MAX_SYMBOL_NAME_LEN - 1;\r
+ symbol_name[len] = '\0';\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ yylvalpp->sc_ident = LookUpAddString(atable, symbol_name);\r
+ return CPP_IDENTIFIER;\r
+ break;\r
+ case '0':\r
+ yylvalpp->symbol_name[len++] = ch;\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == 'x' || ch == 'X') {\r
+ yylvalpp->symbol_name[len++] = ch;\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if ((ch >= '0' && ch <= '9') ||\r
+ (ch >= 'A' && ch <= 'F') ||\r
+ (ch >= 'a' && ch <= 'f'))\r
+ {\r
+ AlreadyComplained = 0;\r
+ ival = 0;\r
+ do {\r
+ yylvalpp->symbol_name[len++] = ch;\r
+ if (ival <= 0x0fffffff) {\r
+ if (ch >= '0' && ch <= '9') {\r
+ ii = ch - '0';\r
+ } else if (ch >= 'A' && ch <= 'F') {\r
+ ii = ch - 'A' + 10;\r
+ } else {\r
+ ii = ch - 'a' + 10;\r
+ }\r
+ ival = (ival << 4) | ii;\r
+ } else {\r
+ if (!AlreadyComplained)\r
+ CPPErrorToInfoLog("ERROR___HEX_CONST_OVERFLOW");\r
+ AlreadyComplained = 1;\r
+ }\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ } while ((ch >= '0' && ch <= '9') ||\r
+ (ch >= 'A' && ch <= 'F') ||\r
+ (ch >= 'a' && ch <= 'f'));\r
+ } else {\r
+ CPPErrorToInfoLog("ERROR___ERROR_IN_HEX_CONSTANT");\r
+ }\r
+ yylvalpp->symbol_name[len] = '\0';\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ yylvalpp->sc_int = ival;\r
+ return CPP_INTCONSTANT;\r
+ } else if (ch >= '0' && ch <= '7') { // octal integer constants\r
+ AlreadyComplained = 0;\r
+ ival = 0;\r
+ do {\r
+ yylvalpp->symbol_name[len++] = ch;\r
+ if (ival <= 0x1fffffff) {\r
+ ii = ch - '0';\r
+ ival = (ival << 3) | ii;\r
+ } else {\r
+ if (!AlreadyComplained)\r
+ CPPErrorToInfoLog("ERROR___OCT_CONST_OVERFLOW");\r
+ AlreadyComplained = 1;\r
+ }\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ } while (ch >= '0' && ch <= '7');\r
+ if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'h' || ch == 'x'|| ch == 'E') \r
+ return lFloatConst(yylvalpp->symbol_name, len, ch, yylvalpp);\r
+ yylvalpp->symbol_name[len] = '\0';\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ yylvalpp->sc_int = ival;\r
+ return CPP_INTCONSTANT;\r
+ } else {\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ ch = '0';\r
+ }\r
+ // Fall through...\r
+ case '1': case '2': case '3': case '4':\r
+ case '5': case '6': case '7': case '8': case '9':\r
+ do {\r
+ if (len < MAX_SYMBOL_NAME_LEN) {\r
+ if (len > 0 || ch != '0') {\r
+ yylvalpp->symbol_name[len] = ch;\r
+ len++;\r
+ }\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ }\r
+ } while (ch >= '0' && ch <= '9');\r
+ if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'h' || ch == 'x'|| ch == 'E') {\r
+ return lFloatConst(yylvalpp->symbol_name, len, ch, yylvalpp);\r
+ } else {\r
+ yylvalpp->symbol_name[len] = '\0';\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ ival = 0;\r
+ AlreadyComplained = 0;\r
+ for (ii = 0; ii < len; ii++) {\r
+ ch = yylvalpp->symbol_name[ii] - '0';\r
+ if ((ival > 214748364) || (ival == 214748364 && ch >= 8)) {\r
+ if (!AlreadyComplained)\r
+ CPPErrorToInfoLog("ERROR___INTEGER_CONST_OVERFLOW");\r
+ AlreadyComplained = 1;\r
+ }\r
+ ival = ival*10 + ch;\r
+ }\r
+ yylvalpp->sc_int = ival;\r
+ if(ival==0)\r
+ strcpy(yylvalpp->symbol_name,"0");\r
+ return CPP_INTCONSTANT;\r
+ }\r
+ break;\r
+ case '-':\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == '-') {\r
+ return CPP_DEC_OP;\r
+ } else if (ch == '=') {\r
+ return CPP_SUB_ASSIGN;\r
+ } else {\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return '-';\r
+ }\r
+ case '+':\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == '+') {\r
+ return CPP_INC_OP;\r
+ } else if (ch == '=') {\r
+ return CPP_ADD_ASSIGN;\r
+ } else {\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return '+';\r
+ }\r
+ case '*':\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == '=') {\r
+ return CPP_MUL_ASSIGN;\r
+ } else {\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return '*';\r
+ }\r
+ case '%':\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == '=') {\r
+ return CPP_MOD_ASSIGN;\r
+ } else if (ch == '>'){\r
+ return CPP_RIGHT_BRACE;\r
+ } else {\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return '%';\r
+ }\r
+ case ':':\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == '>') {\r
+ return CPP_RIGHT_BRACKET;\r
+ } else {\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return ':';\r
+ }\r
+ case '^':\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == '^') {\r
+ return CPP_XOR_OP;\r
+ } else {\r
+ if (ch == '=')\r
+ return CPP_XOR_ASSIGN;\r
+ else{\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return '^';\r
+ }\r
+ }\r
+ \r
+ case '=':\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == '=') {\r
+ return CPP_EQ_OP;\r
+ } else {\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return '=';\r
+ }\r
+ case '!':\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == '=') {\r
+ return CPP_NE_OP;\r
+ } else {\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return '!';\r
+ }\r
+ case '|':\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == '|') {\r
+ return CPP_OR_OP;\r
+ } else {\r
+ if (ch == '=')\r
+ return CPP_OR_ASSIGN;\r
+ else{\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return '|';\r
+ }\r
+ }\r
+ case '&':\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == '&') {\r
+ return CPP_AND_OP;\r
+ } else {\r
+ if (ch == '=')\r
+ return CPP_AND_ASSIGN;\r
+ else{\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return '&';\r
+ }\r
+ }\r
+ case '<':\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == '<') {\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if(ch == '=')\r
+ return CPP_LEFT_ASSIGN;\r
+ else{\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return CPP_LEFT_OP;\r
+ }\r
+ } else {\r
+ if (ch == '=') {\r
+ return CPP_LE_OP;\r
+ } else {\r
+ if (ch == '%')\r
+ return CPP_LEFT_BRACE;\r
+ else if (ch == ':')\r
+ return CPP_LEFT_BRACKET;\r
+ else{\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return '<';\r
+ }\r
+ }\r
+ }\r
+ case '>':\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == '>') {\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if(ch == '=')\r
+ return CPP_RIGHT_ASSIGN;\r
+ else{\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return CPP_RIGHT_OP;\r
+ }\r
+ } else {\r
+ if (ch == '=') {\r
+ return CPP_GE_OP;\r
+ } else {\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return '>';\r
+ }\r
+ }\r
+ case '.':\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch >= '0' && ch <= '9') {\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return lFloatConst(yylvalpp->symbol_name, 0, '.', yylvalpp);\r
+ } else {\r
+ if (ch == '.') {\r
+ return -1; // Special EOF hack\r
+ } else {\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return '.';\r
+ }\r
+ }\r
+ case '/':\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == '/') {\r
+ do {\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ } while (ch != '\n' && ch != EOF);\r
+ if (ch == EOF)\r
+ return -1;\r
+ return '\n';\r
+ } else if (ch == '*') {\r
+ int nlcount = 0;\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ do {\r
+ while (ch != '*') {\r
+ if (ch == '\n') nlcount++;\r
+ if (ch == EOF) {\r
+ CPPErrorToInfoLog("ERROR___EOF_IN_COMMENT");\r
+ return -1;\r
+ }\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ }\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == EOF) {\r
+ CPPErrorToInfoLog("ERROR___EOF_IN_COMMENT");\r
+ return -1;\r
+ }\r
+ } while (ch != '/');\r
+ if (nlcount) {\r
+ return '\n';\r
+ }\r
+ // Go try it again...\r
+ } else if (ch == '=') {\r
+ return CPP_DIV_ASSIGN;\r
+ } else {\r
+ cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);\r
+ return '/';\r
+ }\r
+ break;\r
+ case '"':\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ while (ch != '"' && ch != '\n' && ch != EOF) {\r
+ if (ch == '\\') {\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ if (ch == '\n' || ch == EOF) {\r
+ break;\r
+ }\r
+ }\r
+ if (len < MAX_STRING_LEN) {\r
+ string_val[len] = ch;\r
+ len++;\r
+ ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);\r
+ }\r
+ };\r
+ string_val[len] = '\0';\r
+ if (ch == '"') {\r
+ yylvalpp->sc_ident = LookUpAddString(atable, string_val);\r
+ return CPP_STRCONSTANT;\r
+ } else {\r
+ CPPErrorToInfoLog("ERROR___CPP_EOL_IN_STRING");\r
+ return ERROR_SY;\r
+ }\r
+ }\r
+ }\r
+} // byte_scan\r
+\r
+int yylex_CPP(char* buf, int maxSize)\r
+{ \r
+ yystypepp yylvalpp;\r
+ int token = '\n';\r
+\r
+ for(;;) {\r
+ \r
+ char* tokenString = 0;\r
+ token = cpp->currentInput->scan(cpp->currentInput, &yylvalpp);\r
+ if(check_EOF(token))\r
+ return 0;\r
+ if (token == '#' && (cpp->previous_token == '\n'||cpp->previous_token==0)) {\r
+ token = readCPPline(&yylvalpp);\r
+ if(check_EOF(token))\r
+ return 0;\r
+ continue;\r
+ }\r
+ cpp->previous_token = token;\r
+ // expand macros\r
+ if (token == CPP_IDENTIFIER && MacroExpand(yylvalpp.sc_ident, &yylvalpp)) {\r
+ cpp->notAVersionToken = 1;\r
+ continue;\r
+ }\r
+ \r
+ if (token == '\n')\r
+ continue;\r
+ \r
+ if (token == CPP_IDENTIFIER) {\r
+ cpp->notAVersionToken = 1;\r
+ tokenString = GetStringOfAtom(atable,yylvalpp.sc_ident);\r
+ } else if (token == CPP_FLOATCONSTANT||token == CPP_INTCONSTANT){ \r
+ cpp->notAVersionToken = 1;\r
+ tokenString = yylvalpp.symbol_name;\r
+ } else {\r
+ cpp->notAVersionToken = 1;\r
+ tokenString = GetStringOfAtom(atable,token);\r
+ }\r
+ \r
+ if (tokenString) {\r
+ if ((signed)strlen(tokenString) >= maxSize) {\r
+ return maxSize;\r
+ } else if (strlen(tokenString) > 0) {\r
+ strcpy(buf, tokenString);\r
+ return (int)strlen(tokenString);\r
+ }\r
+\r
+ return 0;\r
+ }\r
+ }\r
+\r
+ return 0;\r
+} // yylex\r
+\r
+//Checks if the token just read is EOF or not.\r
+int check_EOF(int token)\r
+{\r
+ if(token==-1){\r
+ if(cpp->ifdepth >0){\r
+ CPPErrorToInfoLog("#endif missing!! Compilation stopped");\r
+ cpp->CompileError=1;\r
+ }\r
+ return 1;\r
+ }\r
+ return 0;\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+/////////////////////////////////////// End of scanner.c //////////////////////////////////////\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+//\r
+// scanner.h\r
+//\r
+\r
+#if !defined(__SCANNER_H)\r
+#define __SCANNER_H 1\r
+\r
+#define MAX_SYMBOL_NAME_LEN 128\r
+#define MAX_STRING_LEN 512\r
+\r
+#include "parser.h"\r
+\r
+// Not really atom table stuff but needed first...\r
+\r
+typedef struct SourceLoc_Rec {\r
+ unsigned short file, line;\r
+} SourceLoc;\r
+\r
+int yyparse (void);\r
+\r
+int yylex_CPP(char* buf, int maxSize);\r
+\r
+typedef struct InputSrc {\r
+ struct InputSrc *prev;\r
+ int (*scan)(struct InputSrc *, yystypepp *);\r
+ int (*getch)(struct InputSrc *, yystypepp *);\r
+ void (*ungetch)(struct InputSrc *, int, yystypepp *);\r
+ int name; /* atom */\r
+ int line;\r
+} InputSrc;\r
+\r
+int InitScanner(CPPStruct *cpp); // Intialise the cpp scanner. \r
+int ScanFromString(char *); // Start scanning the input from the string mentioned.\r
+int check_EOF(int); // check if we hit a EOF abruptly \r
+void CPPErrorToInfoLog(char *); // sticking the msg,line into the Shader's.Info.log\r
+void SetLineNumber(int);\r
+void SetStringNumber(int);\r
+void IncLineNumber(void);\r
+void DecLineNumber(void);\r
+int FreeScanner(void); // Free the cpp scanner\r
+#endif // !(defined(__SCANNER_H)\r
+\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+//\r
+// slglobals.h\r
+//\r
+\r
+#if !defined(__SLGLOBALS_H)\r
+#define __SLGLOBALS_H 1\r
+\r
+typedef struct CPPStruct_Rec CPPStruct;\r
+\r
+extern CPPStruct *cpp;\r
+\r
+#undef CPPC_DEBUG_THE_COMPILER\r
+#if defined(_DEBUG)\r
+#define CPPC_DEBUG_THE_COMPILER 1\r
+#endif\r
+\r
+#undef CPPC_ENABLE_TOOLS\r
+#define CPPC_ENABLE_TOOLS 1\r
+\r
+#include "memory.h"\r
+#include "atom.h"\r
+#include "scanner.h"\r
+#include "cpp.h"\r
+#include "tokens.h"\r
+#include "symbols.h"\r
+#include "compile.h"\r
+#if !defined(NO_PARSER)\r
+#include "parser.h"\r
+#endif\r
+\r
+#if !defined(NULL)\r
+#define NULL 0\r
+#endif\r
+\r
+#endif // !(defined(__SLGLOBALS_H)\r
+\r
+\r
+ \r
+\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+//\r
+// symbols.c\r
+//\r
+\r
+#include <assert.h>\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+\r
+#include "slglobals.h"\r
+\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+/////////////////////////////////// Symbol Table Variables: ///////////////////////////////////\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+\r
+Scope *ScopeList = NULL;\r
+Scope *CurrentScope = NULL;\r
+Scope *GlobalScope = NULL;\r
+\r
+static void unlinkScope(void *_scope) {\r
+ Scope *scope = _scope;\r
+\r
+ if (scope->next)\r
+ scope->next->prev = scope->prev;\r
+ if (scope->prev)\r
+ scope->prev->next = scope->next;\r
+ else\r
+ ScopeList = scope->next;\r
+}\r
+\r
+/*\r
+ * NewScope()\r
+ *\r
+ */\r
+Scope *NewScopeInPool(MemoryPool *pool)\r
+{\r
+ Scope *lScope;\r
+\r
+ lScope = mem_Alloc(pool, sizeof(Scope));\r
+ lScope->pool = pool;\r
+ lScope->parent = NULL;\r
+ lScope->funScope = NULL;\r
+ lScope->symbols = NULL;\r
+ \r
+ lScope->level = 0;\r
+\r
+ lScope->programs = NULL;\r
+ if ((lScope->next = ScopeList))\r
+ ScopeList->prev = lScope;\r
+ lScope->prev = 0;\r
+ ScopeList = lScope;\r
+ mem_AddCleanup(pool, unlinkScope, lScope);\r
+ return lScope;\r
+} // NewScope\r
+\r
+/*\r
+ * PushScope()\r
+ *\r
+ */\r
+\r
+void PushScope(Scope *fScope)\r
+{\r
+ Scope *lScope;\r
+\r
+ if (CurrentScope) {\r
+ fScope->level = CurrentScope->level + 1;\r
+ if (fScope->level == 1) {\r
+ if (!GlobalScope) {\r
+ /* HACK - CTD -- if GlobalScope==NULL and level==1, we're\r
+ * defining a function in the superglobal scope. Things\r
+ * will break if we leave the level as 1, so we arbitrarily\r
+ * set it to 2 */\r
+ fScope->level = 2;\r
+ }\r
+ }\r
+ if (fScope->level >= 2) {\r
+ lScope = fScope;\r
+ while (lScope->level > 2)\r
+ lScope = lScope->next;\r
+ fScope->funScope = lScope;\r
+ }\r
+ } else {\r
+ fScope->level = 0;\r
+ }\r
+ fScope->parent = CurrentScope;\r
+ CurrentScope = fScope;\r
+} // PushScope\r
+\r
+/*\r
+ * PopScope()\r
+ *\r
+ */\r
+\r
+Scope *PopScope(void)\r
+{\r
+ Scope *lScope;\r
+\r
+ lScope = CurrentScope;\r
+ if (CurrentScope)\r
+ CurrentScope = CurrentScope->parent;\r
+ return lScope;\r
+} // PopScope\r
+\r
+/*\r
+ * NewSymbol() - Allocate a new symbol node;\r
+ *\r
+ */\r
+\r
+Symbol *NewSymbol(SourceLoc *loc, Scope *fScope, int name, symbolkind kind)\r
+{\r
+ Symbol *lSymb;\r
+ char *pch;\r
+ int ii;\r
+\r
+ lSymb = (Symbol *) mem_Alloc(fScope->pool, sizeof(Symbol));\r
+ lSymb->left = NULL;\r
+ lSymb->right = NULL;\r
+ lSymb->next = NULL;\r
+ lSymb->name = name;\r
+ lSymb->loc = *loc;\r
+ lSymb->kind = kind;\r
+ \r
+ // Clear union area:\r
+\r
+ pch = (char *) &lSymb->details;\r
+ for (ii = 0; ii < sizeof(lSymb->details); ii++)\r
+ *pch++ = 0;\r
+ return lSymb;\r
+} // NewSymbol\r
+\r
+/*\r
+ * lAddToTree() - Using a binary tree is not a good idea for basic atom values because they\r
+ * are generated in order. We'll fix this later (by reversing the bit pattern).\r
+ */\r
+\r
+static void lAddToTree(Symbol **fSymbols, Symbol *fSymb)\r
+{\r
+ Symbol *lSymb;\r
+ int lrev, frev;\r
+\r
+ lSymb = *fSymbols;\r
+ if (lSymb) {\r
+ frev = GetReversedAtom(atable, fSymb->name);\r
+ while (lSymb) {\r
+ lrev = GetReversedAtom(atable, lSymb->name);\r
+ if (lrev == frev) {\r
+ CPPErrorToInfoLog("GetAtomString(atable, fSymb->name)");\r
+ break;\r
+ } else {\r
+ if (lrev > frev) {\r
+ if (lSymb->left) {\r
+ lSymb = lSymb->left;\r
+ } else {\r
+ lSymb->left = fSymb;\r
+ break;\r
+ }\r
+ } else {\r
+ if (lSymb->right) {\r
+ lSymb = lSymb->right;\r
+ } else {\r
+ lSymb->right = fSymb;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ } else {\r
+ *fSymbols = fSymb;\r
+ }\r
+} // lAddToTree\r
+\r
+\r
+/*\r
+ * AddSymbol() - Add a variable, type, or function name to a scope.\r
+ *\r
+ */\r
+\r
+Symbol *AddSymbol(SourceLoc *loc, Scope *fScope, int atom, symbolkind kind)\r
+{\r
+ Symbol *lSymb;\r
+\r
+ if (!fScope)\r
+ fScope = CurrentScope;\r
+ lSymb = NewSymbol(loc, fScope, atom, kind);\r
+ lAddToTree(&fScope->symbols, lSymb);\r
+ return lSymb;\r
+} // AddSymbol\r
+\r
+\r
+/*********************************************************************************************/\r
+/************************************ Symbol Semantic Functions ******************************/\r
+/*********************************************************************************************/\r
+\r
+/*\r
+ * LookUpLocalSymbol()\r
+ *\r
+ */\r
+\r
+Symbol *LookUpLocalSymbol(Scope *fScope, int atom)\r
+{\r
+ Symbol *lSymb;\r
+ int rname, ratom;\r
+\r
+ ratom = GetReversedAtom(atable, atom);\r
+ if (!fScope)\r
+ fScope = CurrentScope;\r
+ lSymb = fScope->symbols;\r
+ while (lSymb) {\r
+ rname = GetReversedAtom(atable, lSymb->name);\r
+ if (rname == ratom) {\r
+ return lSymb;\r
+ } else {\r
+ if (rname > ratom) {\r
+ lSymb = lSymb->left;\r
+ } else {\r
+ lSymb = lSymb->right;\r
+ }\r
+ }\r
+ }\r
+ return NULL;\r
+} // LookUpLocalSymbol\r
+\r
+/*\r
+ * LookUpSymbol()\r
+ *\r
+ */\r
+\r
+Symbol *LookUpSymbol(Scope *fScope, int atom)\r
+{\r
+ Symbol *lSymb;\r
+\r
+ if (!fScope)\r
+ fScope = CurrentScope;\r
+ while (fScope) {\r
+ lSymb = LookUpLocalSymbol(fScope, atom);\r
+ if (lSymb)\r
+ return lSymb;\r
+ fScope = fScope->parent;\r
+ }\r
+ return NULL;\r
+} // LookUpSymbol\r
+\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+//\r
+// symbols.h\r
+//\r
+\r
+#if !defined(__SYMBOLS_H)\r
+#define __SYMBOLS_H 1\r
+\r
+#include "memory.h"\r
+\r
+typedef enum symbolkind {\r
+ MACRO_S\r
+} symbolkind;\r
+\r
+// Typedefs for things defined here in "symbols.h":\r
+\r
+typedef struct Scope_Rec Scope;\r
+typedef struct Symbol_Rec Symbol;\r
+\r
+typedef struct SymbolList_Rec {\r
+ struct SymbolList_Rec *next;\r
+ Symbol *symb;\r
+} SymbolList;\r
+\r
+struct Scope_Rec {\r
+ Scope *next, *prev; // doubly-linked list of all scopes\r
+ Scope *parent;\r
+ Scope *funScope; // Points to base scope of enclosing function\r
+ MemoryPool *pool; // pool used for allocation in this scope\r
+ Symbol *symbols;\r
+ \r
+ int level; // 0 = super globals, 1 = globals, etc.\r
+\r
+ // Only used at global scope (level 1):\r
+ SymbolList *programs; // List of programs for this compilation.\r
+};\r
+\r
+\r
+// Symbol table is a simple binary tree.\r
+\r
+#include "cpp.h" // to get MacroSymbol def\r
+\r
+struct Symbol_Rec {\r
+ Symbol *left, *right;\r
+ Symbol *next;\r
+ int name; // Name atom\r
+ SourceLoc loc;\r
+ symbolkind kind;\r
+ union {\r
+ MacroSymbol mac;\r
+ } details;\r
+};\r
+\r
+extern Scope *CurrentScope;\r
+extern Scope *GlobalScope;\r
+extern Scope *ScopeList;\r
+\r
+Scope *NewScopeInPool(MemoryPool *);\r
+#define NewScope() NewScopeInPool(CurrentScope->pool)\r
+void PushScope(Scope *fScope);\r
+Scope *PopScope(void);\r
+Symbol *NewSymbol(SourceLoc *loc, Scope *fScope, int name, symbolkind kind);\r
+Symbol *AddSymbol(SourceLoc *loc, Scope *fScope, int atom, symbolkind kind);\r
+Symbol *LookUpLocalSymbol(Scope *fScope, int atom);\r
+Symbol *LookUpSymbol(Scope *fScope, int atom);\r
+void CPPErrorToInfoLog(char *);\r
+\r
+\r
+#endif // !defined(__SYMBOLS_H)\r
+\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+//\r
+// tokens.c\r
+//\r
+\r
+#include <assert.h>\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include <ctype.h>\r
+\r
+#include "slglobals.h"\r
+\r
+#include "slang_mesa.h"\r
+\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+//////////////////////// Preprocessor and Token Recorder and Playback: ////////////////////////\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+\r
+/*\r
+ * idstr()\r
+ * Copy a string to a malloc'ed block and convert it into something suitable\r
+ * for an ID\r
+ *\r
+ */\r
+\r
+static char *idstr(const char *fstr)\r
+{\r
+ size_t len;\r
+ char *str, *t;\r
+ const char *f;\r
+\r
+ len = strlen(fstr);\r
+ str = (char *) malloc(len + 1);\r
+ for (f=fstr, t=str; *f; f++) {\r
+ if (_mesa_isalnum(*f)) *t++ = *f;\r
+ else if (*f == '.' || *f == '/') *t++ = '_';\r
+ }\r
+ *t = 0;\r
+ return str;\r
+} // idstr\r
+\r
+\r
+/*\r
+ * lNewBlock()\r
+ *\r
+ */\r
+\r
+static TokenBlock *lNewBlock(TokenStream *fTok)\r
+{\r
+ TokenBlock *lBlock;\r
+\r
+ lBlock = (TokenBlock *) malloc(sizeof(TokenBlock) + 256);\r
+ lBlock->count = 0;\r
+ lBlock->current = 0;\r
+ lBlock->data = (unsigned char *) lBlock + sizeof(TokenBlock);\r
+ lBlock->max = 256;\r
+ lBlock->next = NULL;\r
+ if (fTok->head) {\r
+ fTok->current->next = lBlock;\r
+ } else {\r
+ fTok->head = lBlock;\r
+ }\r
+ fTok->current = lBlock;\r
+ return lBlock;\r
+} // lNewBlock\r
+\r
+/*\r
+ * lAddByte()\r
+ *\r
+ */\r
+\r
+static void lAddByte(TokenStream *fTok, unsigned char fVal)\r
+{\r
+ TokenBlock *lBlock;\r
+ lBlock = fTok->current;\r
+ if (lBlock->count >= lBlock->max)\r
+ lBlock = lNewBlock(fTok);\r
+ lBlock->data[lBlock->count++] = fVal;\r
+} // lAddByte\r
+\r
+\r
+\r
+/*\r
+ * lReadByte() - Get the next byte from a stream.\r
+ *\r
+ */\r
+\r
+static int lReadByte(TokenStream *pTok)\r
+{\r
+ TokenBlock *lBlock;\r
+ int lval = -1;\r
+\r
+ lBlock = pTok->current;\r
+ if (lBlock) {\r
+ if (lBlock->current >= lBlock->count) {\r
+ lBlock = lBlock->next;\r
+ if (lBlock)\r
+ lBlock->current = 0;\r
+ pTok->current = lBlock;\r
+ }\r
+ if (lBlock)\r
+ lval = lBlock->data[lBlock->current++];\r
+ }\r
+ return lval;\r
+} // lReadByte\r
+\r
+/////////////////////////////////////// Global Functions://////////////////////////////////////\r
+\r
+/*\r
+ * NewTokenStream()\r
+ *\r
+ */\r
+\r
+TokenStream *NewTokenStream(const char *name)\r
+{\r
+ TokenStream *pTok;\r
+\r
+ pTok = (TokenStream *) malloc(sizeof(TokenStream));\r
+ pTok->next = NULL;\r
+ pTok->name = idstr(name);\r
+ pTok->head = NULL;\r
+ pTok->current = NULL;\r
+ lNewBlock(pTok);\r
+ return pTok;\r
+} // NewTokenStream\r
+\r
+/*\r
+ * DeleteTokenStream()\r
+ *\r
+ */\r
+\r
+void DeleteTokenStream(TokenStream *pTok)\r
+{\r
+ TokenBlock *pBlock, *nBlock;\r
+\r
+ if (pTok) {\r
+ pBlock = pTok->head;\r
+ while (pBlock) {\r
+ nBlock = pBlock->next;\r
+ free(pBlock);\r
+ pBlock = nBlock;\r
+ }\r
+ if (pTok->name)\r
+ free(pTok->name);\r
+ free(pTok);\r
+ }\r
+} // DeleteTokenStream\r
+\r
+/*\r
+ * RecordToken() - Add a token to the end of a list for later playback or printout.\r
+ *\r
+ */\r
+\r
+void RecordToken(TokenStream *pTok, int token, yystypepp * yylvalpp)\r
+{\r
+ const char *s;\r
+ unsigned char *str=NULL;\r
+\r
+ if (token > 256)\r
+ lAddByte(pTok, (unsigned char)((token & 0x7f) + 0x80));\r
+ else\r
+ lAddByte(pTok, (unsigned char)(token & 0x7f));\r
+ switch (token) {\r
+ case CPP_IDENTIFIER:\r
+ case CPP_TYPEIDENTIFIER:\r
+ case CPP_STRCONSTANT:\r
+ s = GetAtomString(atable, yylvalpp->sc_ident);\r
+ while (*s)\r
+ lAddByte(pTok, (unsigned char) *s++);\r
+ lAddByte(pTok, 0);\r
+ break;\r
+ case CPP_FLOATCONSTANT:\r
+ case CPP_INTCONSTANT:\r
+ str=yylvalpp->symbol_name;\r
+ while (*str){\r
+ lAddByte(pTok,(unsigned char) *str);\r
+ *str++;\r
+ }\r
+ lAddByte(pTok, 0);\r
+ break;\r
+ case '(':\r
+ lAddByte(pTok, (unsigned char)(yylvalpp->sc_int ? 1 : 0));\r
+ default:\r
+ break;\r
+ }\r
+} // RecordToken\r
+\r
+/*\r
+ * RewindTokenStream() - Reset a token stream in preperation for reading.\r
+ *\r
+ */\r
+\r
+void RewindTokenStream(TokenStream *pTok)\r
+{\r
+ if (pTok->head) {\r
+ pTok->current = pTok->head;\r
+ pTok->current->current = 0;\r
+ }\r
+} // RewindTokenStream\r
+\r
+/*\r
+ * ReadToken() - Read the next token from a stream.\r
+ *\r
+ */\r
+\r
+int ReadToken(TokenStream *pTok, yystypepp * yylvalpp)\r
+{\r
+ char symbol_name[MAX_SYMBOL_NAME_LEN + 1];\r
+ char string_val[MAX_STRING_LEN + 1];\r
+ int ltoken, len;\r
+ char ch;\r
+\r
+ ltoken = lReadByte(pTok);\r
+ if (ltoken >= 0) {\r
+ if (ltoken > 127)\r
+ ltoken += 128;\r
+ switch (ltoken) {\r
+ case CPP_IDENTIFIER:\r
+ case CPP_TYPEIDENTIFIER:\r
+ len = 0;\r
+ ch = lReadByte(pTok);\r
+ while ((ch >= 'a' && ch <= 'z') ||\r
+ (ch >= 'A' && ch <= 'Z') ||\r
+ (ch >= '0' && ch <= '9') ||\r
+ ch == '_')\r
+ {\r
+ if (len < MAX_SYMBOL_NAME_LEN) {\r
+ symbol_name[len] = ch;\r
+ len++;\r
+ ch = lReadByte(pTok);\r
+ }\r
+ }\r
+ symbol_name[len] = '\0';\r
+ assert(ch == '\0');\r
+ yylvalpp->sc_ident = LookUpAddString(atable, symbol_name);\r
+ return CPP_IDENTIFIER;\r
+ break;\r
+ case CPP_STRCONSTANT:\r
+ len = 0;\r
+ while ((ch = lReadByte(pTok)) != 0)\r
+ if (len < MAX_STRING_LEN)\r
+ string_val[len++] = ch;\r
+ string_val[len] = 0;\r
+ yylvalpp->sc_ident = LookUpAddString(atable, string_val);\r
+ break;\r
+ case CPP_FLOATCONSTANT:\r
+ len = 0;\r
+ ch = lReadByte(pTok);\r
+ while ((ch >= '0' && ch <= '9')||(ch=='e'||ch=='E'||ch=='.')||(ch=='+'||ch=='-'))\r
+ {\r
+ if (len < MAX_SYMBOL_NAME_LEN) {\r
+ symbol_name[len] = ch;\r
+ len++;\r
+ ch = lReadByte(pTok);\r
+ }\r
+ }\r
+ symbol_name[len] = '\0';\r
+ assert(ch == '\0');\r
+ strcpy(yylvalpp->symbol_name,symbol_name);\r
+ yylvalpp->sc_fval=(float)atof(yylvalpp->symbol_name);\r
+ break;\r
+ case CPP_INTCONSTANT:\r
+ len = 0;\r
+ ch = lReadByte(pTok);\r
+ while ((ch >= '0' && ch <= '9'))\r
+ {\r
+ if (len < MAX_SYMBOL_NAME_LEN) {\r
+ symbol_name[len] = ch;\r
+ len++;\r
+ ch = lReadByte(pTok);\r
+ }\r
+ }\r
+ symbol_name[len] = '\0';\r
+ assert(ch == '\0');\r
+ strcpy(yylvalpp->symbol_name,symbol_name);\r
+ yylvalpp->sc_int=atoi(yylvalpp->symbol_name);\r
+ break;\r
+ case '(':\r
+ yylvalpp->sc_int = lReadByte(pTok);\r
+ break;\r
+ }\r
+ return ltoken;\r
+ }\r
+ return EOF_SY;\r
+} // ReadToken\r
+\r
+typedef struct TokenInputSrc {\r
+ InputSrc base;\r
+ TokenStream *tokens;\r
+ int (*final)(CPPStruct *);\r
+} TokenInputSrc;\r
+\r
+static int scan_token(TokenInputSrc *in, yystypepp * yylvalpp)\r
+{\r
+ int token = ReadToken(in->tokens, yylvalpp);\r
+ int (*final)(CPPStruct *);\r
+ cpp->tokenLoc->file = cpp->currentInput->name;\r
+ cpp->tokenLoc->line = cpp->currentInput->line;\r
+ if (token == '\n') {\r
+ in->base.line++;\r
+ return token;\r
+ }\r
+ if (token > 0) return token;\r
+ cpp->currentInput = in->base.prev;\r
+ final = in->final;\r
+ free(in);\r
+ if (final && !final(cpp)) return -1;\r
+ return cpp->currentInput->scan(cpp->currentInput, yylvalpp);\r
+}\r
+\r
+int ReadFromTokenStream(TokenStream *ts, int name, int (*final)(CPPStruct *))\r
+{\r
+ TokenInputSrc *in = malloc(sizeof(TokenInputSrc));\r
+ memset(in, 0, sizeof(TokenInputSrc));\r
+ in->base.name = name;\r
+ in->base.prev = cpp->currentInput;\r
+ in->base.scan = (int (*)(InputSrc *, yystypepp *))scan_token;\r
+ in->base.line = 1;\r
+ in->tokens = ts;\r
+ in->final = final;\r
+ RewindTokenStream(ts);\r
+ cpp->currentInput = &in->base;\r
+ return 1;\r
+}\r
+\r
+typedef struct UngotToken {\r
+ InputSrc base;\r
+ int token;\r
+ yystypepp lval;\r
+} UngotToken;\r
+\r
+static int reget_token(UngotToken *t, yystypepp * yylvalpp)\r
+{\r
+ int token = t->token;\r
+ *yylvalpp = t->lval;\r
+ cpp->currentInput = t->base.prev;\r
+ free(t);\r
+ return token;\r
+}\r
+\r
+void UngetToken(int token, yystypepp * yylvalpp) {\r
+ UngotToken *t = malloc(sizeof(UngotToken));\r
+ memset(t, 0, sizeof(UngotToken));\r
+ t->token = token;\r
+ t->lval = *yylvalpp;\r
+ t->base.scan = (void *)reget_token;\r
+ t->base.prev = cpp->currentInput;\r
+ t->base.name = cpp->currentInput->name;\r
+ t->base.line = cpp->currentInput->line;\r
+ cpp->currentInput = &t->base;\r
+}\r
+\r
+\r
+void DumpTokenStream(FILE *fp, TokenStream *s, yystypepp * yylvalpp) {\r
+ int token;\r
+ char str[100];\r
+\r
+ if (fp == 0) fp = stdout;\r
+ RewindTokenStream(s);\r
+ while ((token = ReadToken(s, yylvalpp)) > 0) {\r
+ switch (token) {\r
+ case CPP_IDENTIFIER:\r
+ case CPP_TYPEIDENTIFIER:\r
+ sprintf(str, "%s ", GetAtomString(atable, yylvalpp->sc_ident));\r
+ break;\r
+ case CPP_STRCONSTANT:\r
+ sprintf(str, "\"%s\"", GetAtomString(atable, yylvalpp->sc_ident));\r
+ break;\r
+ case CPP_FLOATCONSTANT:\r
+ //printf("%g9.6 ", yylvalpp->sc_fval);\r
+ break;\r
+ case CPP_INTCONSTANT:\r
+ //printf("%d ", yylvalpp->sc_int);\r
+ break;\r
+ default:\r
+ if (token >= 127)\r
+ sprintf(str, "%s ", GetAtomString(atable, token));\r
+ else\r
+ sprintf(str, "%c", token);\r
+ break;\r
+ }\r
+ CPPDebugLogMsg(str);\r
+ }\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
+/////////////////////////////////////// End of tokens.c ///////////////////////////////////////\r
+///////////////////////////////////////////////////////////////////////////////////////////////\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+/****************************************************************************\\r
+Copyright (c) 2002, NVIDIA Corporation.\r
+\r
+NVIDIA Corporation("NVIDIA") supplies this software to you in\r
+consideration of your agreement to the following terms, and your use,\r
+installation, modification or redistribution of this NVIDIA software\r
+constitutes acceptance of these terms. If you do not agree with these\r
+terms, please do not use, install, modify or redistribute this NVIDIA\r
+software.\r
+\r
+In consideration of your agreement to abide by the following terms, and\r
+subject to these terms, NVIDIA grants you a personal, non-exclusive\r
+license, under NVIDIA's copyrights in this original NVIDIA software (the\r
+"NVIDIA Software"), to use, reproduce, modify and redistribute the\r
+NVIDIA Software, with or without modifications, in source and/or binary\r
+forms; provided that if you redistribute the NVIDIA Software, you must\r
+retain the copyright notice of NVIDIA, this notice and the following\r
+text and disclaimers in all such redistributions of the NVIDIA Software.\r
+Neither the name, trademarks, service marks nor logos of NVIDIA\r
+Corporation may be used to endorse or promote products derived from the\r
+NVIDIA Software without specific prior written permission from NVIDIA.\r
+Except as expressly stated in this notice, no other rights or licenses\r
+express or implied, are granted by NVIDIA herein, including but not\r
+limited to any patent rights that may be infringed by your derivative\r
+works or by other works in which the NVIDIA Software may be\r
+incorporated. No hardware is licensed hereunder. \r
+\r
+THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT\r
+WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,\r
+INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,\r
+NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\r
+ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER\r
+PRODUCTS.\r
+\r
+IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,\r
+INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\r
+TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY\r
+OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE\r
+NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,\r
+TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF\r
+NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\****************************************************************************/\r
+//\r
+// tokens.h\r
+//\r
+\r
+#if !defined(__TOKENS_H)\r
+#define __TOKENS_H 1\r
+\r
+#include "parser.h"\r
+\r
+#define EOF_SY (-1)\r
+\r
+typedef struct TokenBlock_Rec TokenBlock;\r
+\r
+typedef struct TokenStream_Rec {\r
+ struct TokenStream_Rec *next;\r
+ char *name;\r
+ TokenBlock *head;\r
+ TokenBlock *current;\r
+} TokenStream;\r
+\r
+struct TokenBlock_Rec {\r
+ TokenBlock *next;\r
+ int current;\r
+ int count;\r
+ int max;\r
+ unsigned char *data;\r
+};\r
+\r
+extern TokenStream stdlib_cpp_stream;\r
+\r
+\r
+TokenStream *NewTokenStream(const char *name);\r
+void DeleteTokenStream(TokenStream *pTok); \r
+void RecordToken(TokenStream *pTok, int token, yystypepp * yylvalpp);\r
+void RewindTokenStream(TokenStream *pTok);\r
+int ReadToken(TokenStream *pTok, yystypepp * yylvalpp);\r
+int ReadFromTokenStream(TokenStream *pTok, int name, int (*final)(CPPStruct *));\r
+void UngetToken(int, yystypepp * yylvalpp);\r
+\r
+#if defined(CPPC_ENABLE_TOOLS)\r
+\r
+void DumpTokenStream(FILE *, TokenStream *, yystypepp * yylvalpp);\r
+\r
+#endif // defined(CPPC_ENABLE_TOOLS)\r
+\r
+#endif // !defined(__TOKENS_H)\r
--- /dev/null
+// This is a NULL file and is meant to be empty\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#define SH_EXPORTING\r
+#include "Initialisation.h"\r
+#include "Include/InitializeGlobals.h"\r
+#include "Include/InitializeParseContext.h"\r
+#include "Public/ShaderLang.h"\r
+\r
+OS_TLSIndex GlobalProcessFlag = OS_INVALID_TLS_INDEX;\r
+\r
+bool InitProcess()\r
+{\r
+ if (GlobalProcessFlag != OS_INVALID_TLS_INDEX) {\r
+ //\r
+ // Function is re-entrant.\r
+ //\r
+ return true;\r
+ }\r
+\r
+ GlobalProcessFlag = OS_AllocTLSIndex();\r
+\r
+ if (GlobalProcessFlag == OS_INVALID_TLS_INDEX) {\r
+ assert (0 && "InitProcess(): Failed to allocate TLS area for init flag");\r
+ return false;\r
+ }\r
+\r
+ if (!InitializePoolIndex()) {\r
+ assert (0 && "InitProcess(): Failed to initalize global pool");\r
+ return false;\r
+ }\r
+\r
+ if (!InitializeParseContextIndex()) {\r
+ assert (0 && "InitProcess(): Failed to initalize parse context");\r
+ return false;\r
+ }\r
+\r
+ InitThread();\r
+ return true;\r
+}\r
+\r
+\r
+bool InitThread()\r
+{\r
+ //\r
+ // This function is re-entrant\r
+ //\r
+ if (GlobalProcessFlag == OS_INVALID_TLS_INDEX) {\r
+ assert(0 && "InitThread(): Process hasn't been initalised.");\r
+ return false;\r
+ }\r
+\r
+ if (OS_GetTLSValue(GlobalProcessFlag) != 0) {\r
+ return true;\r
+ }\r
+\r
+ InitializeGlobalPools();\r
+\r
+ if(!InitializeGlobalParseContext()) \r
+ return false;\r
+\r
+ if(!OS_SetTLSValue(GlobalProcessFlag, (void *)1)) {\r
+ assert(0 && "InitThread(): Unable to set init flag.");\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+\r
+bool DetachThread()\r
+{\r
+ bool retFlag = true;\r
+\r
+ if (GlobalProcessFlag == OS_INVALID_TLS_INDEX) {\r
+ assert(0 && "DetachThread(): Process hasn't been initalised.");\r
+ return false;\r
+ }\r
+\r
+ //\r
+ // Function is re-entrant and this thread may not have been initalised.\r
+ //\r
+ if (OS_GetTLSValue(GlobalProcessFlag) != 0)\r
+ {\r
+ if(!OS_SetTLSValue(GlobalProcessFlag, (void *)0)) {\r
+ assert(0 && "DetachThread(): Unable to clear init flag.");\r
+ retFlag = false;\r
+ }\r
+\r
+ FreeGlobalPools();\r
+\r
+ if (!FreeParseContext())\r
+ retFlag = false;\r
+ }\r
+\r
+ return retFlag;\r
+}\r
+\r
+bool DetachProcess()\r
+{\r
+ bool retFlag = true;\r
+\r
+ if (GlobalProcessFlag == OS_INVALID_TLS_INDEX)\r
+ return true;\r
+ \r
+ ShFinalize();\r
+\r
+ retFlag = DetachThread();\r
+\r
+ FreePoolIndex();\r
+\r
+ if(!FreeParseContextIndex())\r
+ retFlag = false;\r
+\r
+ OS_FreeTLSIndex(GlobalProcessFlag);\r
+ GlobalProcessFlag = OS_INVALID_TLS_INDEX;\r
+\r
+ return retFlag;\r
+}\r
+\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+#ifndef __INITIALISATION_H\r
+#define __INITIALISATION_H\r
+\r
+\r
+#include "osinclude.h"\r
+\r
+\r
+bool InitProcess();\r
+bool InitThread();\r
+bool DetachThread();\r
+bool DetachProcess();\r
+\r
+#endif // __INITIALISATION_H\r
+\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#ifndef __OSINCLUDE_H\r
+#define __OSINCLUDE_H\r
+\r
+//\r
+// This file contains any Linux specific functions.\r
+//\r
+\r
+#if !(defined(linux))\r
+#error Trying to include a Linux specific file in a non-Linux build.\r
+#endif\r
+\r
+#include <pthread.h>\r
+#include <semaphore.h>\r
+#include <assert.h>\r
+#include <errno.h>\r
+#include "Include/InitializeGlobals.h"\r
+#include "Include/PoolAlloc.h"\r
+\r
+#define _vsnprintf vsnprintf\r
+\r
+void DetachThreadLinux(void *);\r
+\r
+//\r
+// Thread Local Storage Operations\r
+//\r
+typedef unsigned int OS_TLSIndex;\r
+#define OS_INVALID_TLS_INDEX 0xFFFFFFFF\r
+\r
+OS_TLSIndex OS_AllocTLSIndex();\r
+bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue);\r
+bool OS_FreeTLSIndex(OS_TLSIndex nIndex); \r
+\r
+\r
+inline void * OS_GetTLSValue(OS_TLSIndex nIndex)\r
+{\r
+ //\r
+ // This function should return 0 if nIndex is invalid.\r
+ //\r
+ assert(nIndex != OS_INVALID_TLS_INDEX);\r
+ return (pthread_getspecific(nIndex)); \r
+}\r
+\r
+#endif // __OSINCLUDE_H\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+//\r
+// This file contains the Linux specific functions\r
+//\r
+#include "osinclude.h"\r
+#include "Initialisation.h"\r
+\r
+#if !(defined(linux))\r
+#error Trying to build a Linux specific file in a non-Linux build.\r
+#endif\r
+\r
+//\r
+// Thread cleanup\r
+//\r
+\r
+//\r
+// Wrapper for Linux call to DetachThread. This is required as pthread_cleanup_push() expects \r
+// the cleanup routine to return void.\r
+// \r
+void DetachThreadLinux(void *)\r
+{\r
+ DetachThread();\r
+}\r
+\r
+\r
+//\r
+// Registers cleanup handler, sets cancel type and state, and excecutes the thread specific\r
+// cleanup handler. This function will be called in the Standalone.cpp for regression \r
+// testing. When OpenGL applications are run with the driver code, Linux OS does the \r
+// thread cleanup.\r
+// \r
+void OS_CleanupThreadData(void)\r
+{\r
+ int old_cancel_state, old_cancel_type;\r
+ void *cleanupArg = NULL;\r
+\r
+ //\r
+ // Set thread cancel state and push cleanup handler.\r
+ //\r
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old_cancel_state);\r
+ pthread_cleanup_push(DetachThreadLinux, (void *) cleanupArg);\r
+\r
+ //\r
+ // Put the thread in deferred cancellation mode.\r
+ //\r
+ pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &old_cancel_type);\r
+\r
+ //\r
+ // Pop cleanup handler and execute it prior to unregistering the cleanup handler.\r
+ //\r
+ pthread_cleanup_pop(1);\r
+\r
+ //\r
+ // Restore the thread's previous cancellation mode.\r
+ //\r
+ pthread_setcanceltype(old_cancel_state, NULL);\r
+}\r
+\r
+\r
+//\r
+// Thread Local Storage Operations\r
+//\r
+OS_TLSIndex OS_AllocTLSIndex()\r
+{\r
+ pthread_key_t pPoolIndex;\r
+\r
+ //\r
+ // Create global pool key.\r
+ //\r
+ if ((pthread_key_create(&pPoolIndex, NULL)) != 0) {\r
+ assert(0 && "OS_AllocTLSIndex(): Unable to allocate Thread Local Storage");\r
+ return false;\r
+ }\r
+ else\r
+ return pPoolIndex;\r
+}\r
+\r
+\r
+bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue)\r
+{\r
+ if (nIndex == OS_INVALID_TLS_INDEX) {\r
+ assert(0 && "OS_SetTLSValue(): Invalid TLS Index");\r
+ return false;\r
+ }\r
+\r
+ if (pthread_setspecific(nIndex, lpvValue) == 0)\r
+ return true;\r
+ else\r
+ return false;\r
+}\r
+\r
+\r
+bool OS_FreeTLSIndex(OS_TLSIndex nIndex)\r
+{\r
+ if (nIndex == OS_INVALID_TLS_INDEX) {\r
+ assert(0 && "OS_SetTLSValue(): Invalid TLS Index");\r
+ return false;\r
+ }\r
+\r
+ //\r
+ // Delete the global pool key.\r
+ //\r
+ if (pthread_key_delete(nIndex) == 0)\r
+ return true;\r
+ else\r
+ return false;\r
+}\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#ifndef __OSINCLUDE_H\r
+#define __OSINCLUDE_H\r
+\r
+//\r
+// This file contains contains the window's specific datatypes and\r
+// declares any windows specific functions.\r
+//\r
+\r
+#if !(defined(_WIN32) || defined(_WIN64))\r
+#error Trying to include a windows specific file in a non windows build.\r
+#endif\r
+\r
+#define STRICT 1\r
+#define VC_EXTRALEAN 1\r
+#include <windows.h>\r
+#include <assert.h>\r
+\r
+//\r
+// Thread Local Storage Operations\r
+//\r
+typedef DWORD OS_TLSIndex;\r
+#define OS_INVALID_TLS_INDEX (TLS_OUT_OF_INDEXES)\r
+\r
+OS_TLSIndex OS_AllocTLSIndex();\r
+bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue);\r
+bool OS_FreeTLSIndex(OS_TLSIndex nIndex);\r
+\r
+inline void* OS_GetTLSValue(OS_TLSIndex nIndex) \r
+{\r
+ assert(nIndex != OS_INVALID_TLS_INDEX);\r
+ return TlsGetValue(nIndex);\r
+}\r
+\r
+#endif // __OSINCLUDE_H\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+\r
+#include "Initialisation.h"\r
+\r
+//\r
+// This file contains contains the window's specific functions\r
+//\r
+\r
+#if !(defined(_WIN32) || defined(_WIN64))\r
+#error Trying to build a windows specific file in a non windows build.\r
+#endif\r
+\r
+//\r
+// disable DllMain on Mesa-3D builds, call appropriate Init* and Detach*\r
+// routines manually in context initialization\r
+//\r
+/*BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)\r
+{\r
+ switch (fdwReason)\r
+ {\r
+ case DLL_PROCESS_ATTACH:\r
+ if (!InitProcess())\r
+ return false;\r
+ break;\r
+ case DLL_THREAD_ATTACH:\r
+ if (!InitThread())\r
+ return false;\r
+ break;\r
+\r
+ case DLL_THREAD_DETACH:\r
+\r
+ if (!DetachThread())\r
+ return false;\r
+ break;\r
+\r
+ case DLL_PROCESS_DETACH:\r
+\r
+ DetachProcess();\r
+ break;\r
+\r
+ default:\r
+ assert(0 && "DllMain(): Reason for calling DLL Main is unknown");\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+}*/\r
+\r
+//\r
+// Thread Local Storage Operations\r
+//\r
+OS_TLSIndex OS_AllocTLSIndex()\r
+{\r
+ DWORD dwIndex = TlsAlloc();\r
+ if (dwIndex == TLS_OUT_OF_INDEXES) {\r
+ assert(0 && "OS_AllocTLSIndex(): Unable to allocate Thread Local Storage");\r
+ return (OS_INVALID_TLS_INDEX);\r
+ }\r
+\r
+ return dwIndex;\r
+}\r
+\r
+\r
+bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue)\r
+{\r
+ if (nIndex == OS_INVALID_TLS_INDEX)\r
+ {\r
+ assert(0 && "OS_SetTLSValue(): Invalid TLS Index");\r
+ return false;\r
+ }\r
+\r
+ if (TlsSetValue(nIndex, lpvValue))\r
+ return true;\r
+ else\r
+ return false;\r
+}\r
+\r
+\r
+bool OS_FreeTLSIndex(OS_TLSIndex nIndex)\r
+{\r
+ if (nIndex == OS_INVALID_TLS_INDEX) {\r
+ assert(0 && "OS_SetTLSValue(): Invalid TLS Index");\r
+ return false;\r
+ }\r
+\r
+ if (TlsFree(nIndex))\r
+ return true;\r
+ else\r
+ return false;\r
+}\r
+\r
--- /dev/null
+/*\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+*/\r
+#ifndef _COMPILER_INTERFACE_INCLUDED_\r
+#define _COMPILER_INTERFACE_INCLUDED_\r
+\r
+\r
+#ifdef _WIN32\r
+#define C_DECL __cdecl\r
+#define SH_IMPORT_EXPORT\r
+#else\r
+#define SH_IMPORT_EXPORT\r
+#define __fastcall\r
+#define C_DECL\r
+#endif\r
+\r
+/*\r
+// This is the platform independent interface between an OGL driver\r
+// and the shading language compiler/linker.\r
+*/\r
+\r
+#ifdef __cplusplus\r
+ extern "C" {\r
+#endif\r
+\r
+/*\r
+// Driver must call this first, once, before doing any other\r
+// compiler/linker operations.\r
+*/\r
+SH_IMPORT_EXPORT int ShInitialize();\r
+/*\r
+// Driver should call this at shutdown.\r
+*/\r
+SH_IMPORT_EXPORT int __fastcall ShFinalize();\r
+/*\r
+// to be used for hardwareDataType and userDataType by ICD\r
+*/\r
+typedef enum {\r
+ EFloat,\r
+ EInt,\r
+ EBool,\r
+ EFloat_Vec2,\r
+ EFloat_Vec3,\r
+ EFloat_Vec4,\r
+ EInt_Vec2,\r
+ EInt_Vec3,\r
+ EInt_Vec4,\r
+ EBool_Vec2,\r
+ EBool_Vec3,\r
+ EBool_Vec4,\r
+ EFloat_Mat2,\r
+ EFloat_Mat3,\r
+ EFloat_Mat4,\r
+ ESampler_1D,\r
+ ESampler_2D,\r
+ ESampler_3D,\r
+ ESampler_Cube,\r
+ ESampler_1D_Shadow,\r
+ ESampler_2D_Shadow,\r
+ EStruct\r
+} ShBasicType;\r
+\r
+/*\r
+// Types of languages the compiler can consume.\r
+*/\r
+typedef enum {\r
+ EShLangVertex,\r
+ EShLangFragment,\r
+ EShLangPack,\r
+ EShLangUnpack,\r
+ EShLangCount,\r
+} EShLanguage;\r
+\r
+/*\r
+// Types of output the linker will create.\r
+*/\r
+typedef enum {\r
+ EShExVertexFragment,\r
+ EShExPackFragment,\r
+ EShExUnpackFragment,\r
+ EShExFragment\r
+} EShExecutable;\r
+\r
+/*\r
+// Optimization level for the compiler.\r
+*/\r
+typedef enum {\r
+ EShOptNoGeneration,\r
+ EShOptNone,\r
+ EShOptSimple, /* Optimizations that can be done quickly */\r
+ EShOptFull, /* Optimizations that will take more time */\r
+} EShOptimizationLevel;\r
+\r
+/*\r
+// Build a table for bindings. This can be used for locating\r
+// attributes, uniforms, globals, etc., as needed.\r
+*/\r
+typedef struct {\r
+ char* name;\r
+ int binding;\r
+} ShBinding;\r
+\r
+typedef struct {\r
+ int numBindings;\r
+ ShBinding* bindings; /* array of bindings */\r
+} ShBindingTable;\r
+\r
+/*\r
+// ShHandle held by but opaque to the driver. It is allocated,\r
+// managed, and de-allocated by the compiler/linker. It's contents \r
+// are defined by and used by the compiler and linker. For example,\r
+// symbol table information and object code passed from the compiler \r
+// to the linker can be stored where ShHandle points.\r
+//\r
+// If handle creation fails, 0 will be returned.\r
+*/\r
+typedef void* ShHandle;\r
+\r
+/*\r
+// Driver calls these to create and destroy compiler/linker\r
+// objects.\r
+*/\r
+SH_IMPORT_EXPORT ShHandle ShConstructCompiler(const EShLanguage, int debugOptions); /* one per shader */\r
+SH_IMPORT_EXPORT ShHandle ShConstructLinker(const EShExecutable, int debugOptions); /* one per shader pair */\r
+SH_IMPORT_EXPORT ShHandle ShConstructUniformMap(); /* one per uniform namespace (currently entire program object) */\r
+SH_IMPORT_EXPORT void ShDestruct(ShHandle);\r
+\r
+/*\r
+// The return value of ShCompile is boolean, indicating\r
+// success or failure.\r
+//\r
+// The info-log should be written by ShCompile into \r
+// ShHandle, so it can answer future queries.\r
+*/\r
+SH_IMPORT_EXPORT int ShCompile(\r
+ const ShHandle,\r
+ const char* const shaderStrings[],\r
+ const int numStrings,\r
+ const EShOptimizationLevel,\r
+ int debugOptions\r
+ );\r
+\r
+\r
+/*\r
+// Similar to ShCompile, but accepts an opaque handle to an\r
+// intermediate language structure.\r
+*/\r
+SH_IMPORT_EXPORT int ShCompileIntermediate(\r
+ ShHandle compiler,\r
+ ShHandle intermediate,\r
+ const EShOptimizationLevel,\r
+ int debuggable /* boolean */\r
+ );\r
+\r
+SH_IMPORT_EXPORT int ShLink(\r
+ const ShHandle, /* linker object */\r
+ const ShHandle h[], /* compiler objects to link together */\r
+ const int numHandles,\r
+ ShHandle uniformMap, /* updated with new uniforms */\r
+ short int** uniformsAccessed, /* returned with indexes of uniforms accessed */\r
+ int* numUniformsAccessed); \r
+\r
+/*\r
+// ShSetEncrpytionMethod is a place-holder for specifying\r
+// how source code is encrypted.\r
+*/\r
+SH_IMPORT_EXPORT void ShSetEncryptionMethod(ShHandle);\r
+\r
+/*\r
+// All the following return 0 if the information is not\r
+// available in the object passed down, or the object is bad.\r
+*/\r
+SH_IMPORT_EXPORT const char* ShGetInfoLog(const ShHandle);\r
+SH_IMPORT_EXPORT const void* ShGetExecutable(const ShHandle);\r
+SH_IMPORT_EXPORT int ShSetVirtualAttributeBindings(const ShHandle, const ShBindingTable*); /* to detect user aliasing */\r
+SH_IMPORT_EXPORT int ShSetFixedAttributeBindings(const ShHandle, const ShBindingTable*); /* to force any physical mappings */\r
+SH_IMPORT_EXPORT int ShGetPhysicalAttributeBindings(const ShHandle, const ShBindingTable**); /* for all attributes */\r
+/*\r
+// Tell the linker to never assign a vertex attribute to this list of physical attributes\r
+*/\r
+SH_IMPORT_EXPORT int ShExcludeAttributes(const ShHandle, int *attributes, int count);\r
+\r
+/*\r
+// Returns the location ID of the named uniform.\r
+// Returns -1 if error.\r
+*/\r
+SH_IMPORT_EXPORT int ShGetUniformLocation(const ShHandle uniformMap, const char* name);\r
+SH_IMPORT_EXPORT char* ShGetUniformName(const ShHandle linker, int virtualLocation);\r
+\r
+enum TDebugOptions {\r
+ EDebugOpNone = 0x000,\r
+ EDebugOpIntermediate = 0x001,\r
+ EDebugOpAssembly = 0x002,\r
+ EDebugOpObjectCode = 0x004,\r
+ EDebugOpLinkMaps = 0x008\r
+};\r
+\r
+#ifdef __cplusplus\r
+ }\r
+#endif\r
+\r
+#endif /* _COMPILER_INTERFACE_INCLUDED_ */\r
--- /dev/null
+//\r
+//Copyright (C) 2002-2004 3Dlabs Inc. Ltd.\r
+//All rights reserved.\r
+//\r
+//Redistribution and use in source and binary forms, with or without\r
+//modification, are permitted provided that the following conditions\r
+//are met:\r
+//\r
+// Redistributions of source code must retain the above copyright\r
+// notice, this list of conditions and the following disclaimer.\r
+//\r
+// Redistributions in binary form must reproduce the above\r
+// copyright notice, this list of conditions and the following\r
+// disclaimer in the documentation and/or other materials provided\r
+// with the distribution.\r
+//\r
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its\r
+// contributors may be used to endorse or promote products derived\r
+// from this software without specific prior written permission.\r
+//\r
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
+//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+//POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+#ifndef _SHADERLANG_EXTENSION_INCLUDED_\r
+#define _SHADERLANG_EXTENSION_INCLUDED_\r
+\r
+#include "ShaderLang.h"\r
+\r
+//\r
+// This is the platform independent interface between an OGL driver\r
+// and the shading language compiler/linker.\r
+//\r
+\r
+#ifdef __cplusplus\r
+ extern "C" {\r
+#endif\r
+\r
+typedef enum {\r
+ EReserved = 0,\r
+ EFixed,\r
+ ERecommended,\r
+ EFloating\r
+} ShPriority;\r
+\r
+typedef enum {\r
+ ESymbol = 0,\r
+ EFloatConst, \r
+ EFloatConstPtr, \r
+ EIntConst, \r
+ EIntConstPtr, \r
+ EBoolConst, \r
+ EBoolConstPtr \r
+} ShDataType;\r
+\r
+// this definition will eventually go once we move to the new linker interface in the driver\r
+typedef enum {\r
+ EVirtualBinding,\r
+ EPhysicalBinding\r
+} ShVirtualPhysicalBinding;\r
+\r
+typedef struct {\r
+ int size; // out - total physical size for the binding in floats - P10\r
+ int location; // in-out - virtualLocation for all cases\r
+ int functionPriority; // out - used for giving priorities to function bindings\r
+ int proEpilogue; // out - essentially a bool defining whether its a prologue/epilogue or not, 1 means it is\r
+ int builtInName; // out - basically a bool value, 0 means not a builtInName, 1 means its a builtInName\r
+ int arraySize; // out - size of the array in units of its type - if the binding is for an array\r
+ ShPriority bindingPriority; // in-out - EFixed, ERecommended, EFloating\r
+ ShDataType bindingDataType; // in-out - whether its a symbol name or a constant value\r
+ ShBasicType hardwareDataType; // out - bool are loaded as floats on the hardware\r
+ ShBasicType userDataType; // out - mat3 -> mat3, ivec2 -> ivec2, vec2 -> vec2\r
+ ShBasicType basicUserType; // out - mat3 -> float, ivec2 ->int, vec2 -> float\r
+ int sizeOfType; // out - for vec3 -> 3, for float -> 1, for mat3 -> 3, mat3[10] -> 3\r
+ int matrix; // out - essentially a boolean, 0 means vector, 1 means matrix\r
+ union { // in-out\r
+ char* name; \r
+ float floatVal;\r
+ float* floatValPtr;\r
+ int intVal;\r
+ int* intValPtr; \r
+ };\r
+ // A pointer to ShP10PhysicalBinding or ShP20PhysicalBinding\r
+ void* targetDependentData; // in-out\r
+} ShBindingExt;\r
+\r
+//\r
+// to specify the type of binding\r
+//\r
+typedef enum { \r
+ EAttribute, \r
+ EUniform, \r
+ EVarying, \r
+ EFunction, \r
+ EConstant, \r
+ EFunctionRelocation, \r
+ EArbVertexLocal,\r
+ EArbVertexEnv,\r
+ EArbFragmentLocal,\r
+ EArbFragmentEnv,\r
+ EState,\r
+ ENoBindingType } ShBindingType;\r
+\r
+typedef struct {\r
+ // a pointer to ShBindingExt\r
+ ShBindingExt* pBinding;\r
+ int numOfBindings;\r
+ ShBindingType type;\r
+} ShBindingTableExt;\r
+\r
+typedef struct {\r
+ ShBindingTableExt *bindingTable;\r
+ int numOfBindingTables;\r
+} ShBindingList;\r
+\r
+SH_IMPORT_EXPORT ShHandle ShConstructBindings();\r
+SH_IMPORT_EXPORT ShHandle ShConstructLibrary();\r
+\r
+SH_IMPORT_EXPORT ShHandle ShAddBinding(ShHandle bindingHandle, \r
+ ShBindingExt* binding, \r
+ ShBindingType type);\r
+SH_IMPORT_EXPORT ShHandle ShAddBindingTable(ShHandle bindingHandle, \r
+ ShBindingTableExt *bindingTable, \r
+ ShBindingType type);\r
+\r
+SH_IMPORT_EXPORT int ShLinkExt(\r
+ const ShHandle, // linker object\r
+ const ShHandle h[], // compiler objects to link together\r
+ const int numHandles);\r
+\r
+SH_IMPORT_EXPORT ShBindingList* ShGetBindingList(const ShHandle linkerHandle); \r
+SH_IMPORT_EXPORT ShBindingTableExt* ShGetBindingTable(const ShHandle linkerHandle, ShBindingType type); \r
+SH_IMPORT_EXPORT int ShGetUniformLocationExt(const ShHandle linkerHandle, const char* name);\r
+SH_IMPORT_EXPORT int ShSetFixedAttributeBindingsExt(const ShHandle, const ShBindingTableExt*);\r
+SH_IMPORT_EXPORT int ShGetUniformLocationExt2(const ShHandle handle, const char* name, int* location, int* offset);\r
+SH_IMPORT_EXPORT int ShSetVirtualLocation(const ShHandle handle, ShBindingType type, int bindingIndex, int virtualLocation);\r
+SH_IMPORT_EXPORT int ShGetVirtualLocation(const ShHandle handle, ShBindingType type, int bindingIndex, int *virtualLocation);\r
+// \r
+// To get the bindings object from the linker object (after the link is done so that \r
+// bindings can be added to the list)\r
+//\r
+SH_IMPORT_EXPORT ShHandle ShGetBindings(const ShHandle linkerHandle);\r
+SH_IMPORT_EXPORT int ShAddLibraryCode(ShHandle library, const char* name, const ShHandle objectCodes[], const int numHandles);\r
+\r
+/*****************************************************************************\r
+ This code is used by the new shared linker\r
+ *****************************************************************************/\r
+//\r
+// Each programmable unit has a UnitExecutable. Targets may subclass\r
+// and append to this as desired.\r
+//\r
+typedef struct {\r
+ int name; // name of unit to which executable is targeted\r
+ int entry; // a target specific entry point\r
+ int count; // size of executable\r
+ const void* code; // read-only code\r
+} ShUnitExecutable;\r
+\r
+//\r
+// The "void*" returned from ShGetExecutable() will be an ShExecutable\r
+//\r
+typedef struct {\r
+ int count; // count of unit executables\r
+ ShUnitExecutable* executables;\r
+} ShExecutable;\r
+\r
+SH_IMPORT_EXPORT ShExecutable* ShGetExecutableExt(const ShHandle linkerHandle);\r
+\r
+typedef struct {\r
+ int numThread;\r
+ int stackSpacePerThread;\r
+ int visBufferValidity; // essenatially a boolean\r
+ int shaderFragTerminationStatus; // essentially a boolean\r
+} ShDeviceInfo;\r
+\r
+#ifdef __cplusplus\r
+ }\r
+#endif\r
+\r
+#endif // _SHADERLANG_EXTENSION_INCLUDED_\r