PpAtom.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //
  2. // Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
  3. // Copyright (C) 2013 LunarG, Inc.
  4. // All rights reserved.
  5. //
  6. // Redistribution and use in source and binary forms, with or without
  7. // modification, are permitted provided that the following conditions
  8. // are met:
  9. //
  10. // Redistributions of source code must retain the above copyright
  11. // notice, this list of conditions and the following disclaimer.
  12. //
  13. // Redistributions in binary form must reproduce the above
  14. // copyright notice, this list of conditions and the following
  15. // disclaimer in the documentation and/or other materials provided
  16. // with the distribution.
  17. //
  18. // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
  19. // contributors may be used to endorse or promote products derived
  20. // from this software without specific prior written permission.
  21. //
  22. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  30. // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32. // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. // POSSIBILITY OF SUCH DAMAGE.
  34. //
  35. /****************************************************************************\
  36. Copyright (c) 2002, NVIDIA Corporation.
  37. NVIDIA Corporation("NVIDIA") supplies this software to you in
  38. consideration of your agreement to the following terms, and your use,
  39. installation, modification or redistribution of this NVIDIA software
  40. constitutes acceptance of these terms. If you do not agree with these
  41. terms, please do not use, install, modify or redistribute this NVIDIA
  42. software.
  43. In consideration of your agreement to abide by the following terms, and
  44. subject to these terms, NVIDIA grants you a personal, non-exclusive
  45. license, under NVIDIA's copyrights in this original NVIDIA software (the
  46. "NVIDIA Software"), to use, reproduce, modify and redistribute the
  47. NVIDIA Software, with or without modifications, in source and/or binary
  48. forms; provided that if you redistribute the NVIDIA Software, you must
  49. retain the copyright notice of NVIDIA, this notice and the following
  50. text and disclaimers in all such redistributions of the NVIDIA Software.
  51. Neither the name, trademarks, service marks nor logos of NVIDIA
  52. Corporation may be used to endorse or promote products derived from the
  53. NVIDIA Software without specific prior written permission from NVIDIA.
  54. Except as expressly stated in this notice, no other rights or licenses
  55. express or implied, are granted by NVIDIA herein, including but not
  56. limited to any patent rights that may be infringed by your derivative
  57. works or by other works in which the NVIDIA Software may be
  58. incorporated. No hardware is licensed hereunder.
  59. THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
  60. WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  61. INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
  62. NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
  63. ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
  64. PRODUCTS.
  65. IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
  66. INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  67. TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  68. USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
  69. OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
  70. NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
  71. TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
  72. NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  73. \****************************************************************************/
  74. #ifndef _CRT_SECURE_NO_WARNINGS
  75. #define _CRT_SECURE_NO_WARNINGS
  76. #endif
  77. #include <cassert>
  78. #include <cstdlib>
  79. #include <cstring>
  80. #include "PpContext.h"
  81. #include "PpTokens.h"
  82. namespace {
  83. using namespace glslang;
  84. const struct {
  85. int val;
  86. const char* str;
  87. } tokens[] = {
  88. { PPAtomAddAssign, "+=" },
  89. { PPAtomSubAssign, "-=" },
  90. { PPAtomMulAssign, "*=" },
  91. { PPAtomDivAssign, "/=" },
  92. { PPAtomModAssign, "%=" },
  93. { PpAtomRight, ">>" },
  94. { PpAtomLeft, "<<" },
  95. { PpAtomAnd, "&&" },
  96. { PpAtomOr, "||" },
  97. { PpAtomXor, "^^" },
  98. { PpAtomRightAssign, ">>=" },
  99. { PpAtomLeftAssign, "<<=" },
  100. { PpAtomAndAssign, "&=" },
  101. { PpAtomOrAssign, "|=" },
  102. { PpAtomXorAssign, "^=" },
  103. { PpAtomEQ, "==" },
  104. { PpAtomNE, "!=" },
  105. { PpAtomGE, ">=" },
  106. { PpAtomLE, "<=" },
  107. { PpAtomDecrement, "--" },
  108. { PpAtomIncrement, "++" },
  109. { PpAtomColonColon, "::" },
  110. { PpAtomDefine, "define" },
  111. { PpAtomUndef, "undef" },
  112. { PpAtomIf, "if" },
  113. { PpAtomElif, "elif" },
  114. { PpAtomElse, "else" },
  115. { PpAtomEndif, "endif" },
  116. { PpAtomIfdef, "ifdef" },
  117. { PpAtomIfndef, "ifndef" },
  118. { PpAtomLine, "line" },
  119. { PpAtomPragma, "pragma" },
  120. { PpAtomError, "error" },
  121. { PpAtomVersion, "version" },
  122. { PpAtomCore, "core" },
  123. { PpAtomCompatibility, "compatibility" },
  124. { PpAtomEs, "es" },
  125. { PpAtomExtension, "extension" },
  126. { PpAtomLineMacro, "__LINE__" },
  127. { PpAtomFileMacro, "__FILE__" },
  128. { PpAtomVersionMacro, "__VERSION__" },
  129. { PpAtomInclude, "include" },
  130. };
  131. } // end anonymous namespace
  132. namespace glslang {
  133. //
  134. // Initialize the atom table.
  135. //
  136. TStringAtomMap::TStringAtomMap()
  137. {
  138. badToken.assign("<bad token>");
  139. // Add single character tokens to the atom table:
  140. const char* s = "~!%^&*()-+=|,.<>/?;:[]{}#\\";
  141. char t[2];
  142. t[1] = '\0';
  143. while (*s) {
  144. t[0] = *s;
  145. addAtomFixed(t, s[0]);
  146. s++;
  147. }
  148. // Add multiple character scanner tokens :
  149. for (size_t ii = 0; ii < sizeof(tokens)/sizeof(tokens[0]); ii++)
  150. addAtomFixed(tokens[ii].str, tokens[ii].val);
  151. nextAtom = PpAtomLast;
  152. }
  153. } // end namespace glslang