PpContext.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
  3. // Copyright (C) 2013 LunarG, Inc.
  4. // Copyright (C) 2015-2018 Google, Inc.
  5. // All rights reserved.
  6. //
  7. // Redistribution and use in source and binary forms, with or without
  8. // modification, are permitted provided that the following conditions
  9. // are met:
  10. //
  11. // Redistributions of source code must retain the above copyright
  12. // notice, this list of conditions and the following disclaimer.
  13. //
  14. // Redistributions in binary form must reproduce the above
  15. // copyright notice, this list of conditions and the following
  16. // disclaimer in the documentation and/or other materials provided
  17. // with the distribution.
  18. //
  19. // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
  20. // contributors may be used to endorse or promote products derived
  21. // from this software without specific prior written permission.
  22. //
  23. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26. // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27. // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29. // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30. // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  33. // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. // POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. /****************************************************************************\
  37. Copyright (c) 2002, NVIDIA Corporation.
  38. NVIDIA Corporation("NVIDIA") supplies this software to you in
  39. consideration of your agreement to the following terms, and your use,
  40. installation, modification or redistribution of this NVIDIA software
  41. constitutes acceptance of these terms. If you do not agree with these
  42. terms, please do not use, install, modify or redistribute this NVIDIA
  43. software.
  44. In consideration of your agreement to abide by the following terms, and
  45. subject to these terms, NVIDIA grants you a personal, non-exclusive
  46. license, under NVIDIA's copyrights in this original NVIDIA software (the
  47. "NVIDIA Software"), to use, reproduce, modify and redistribute the
  48. NVIDIA Software, with or without modifications, in source and/or binary
  49. forms; provided that if you redistribute the NVIDIA Software, you must
  50. retain the copyright notice of NVIDIA, this notice and the following
  51. text and disclaimers in all such redistributions of the NVIDIA Software.
  52. Neither the name, trademarks, service marks nor logos of NVIDIA
  53. Corporation may be used to endorse or promote products derived from the
  54. NVIDIA Software without specific prior written permission from NVIDIA.
  55. Except as expressly stated in this notice, no other rights or licenses
  56. express or implied, are granted by NVIDIA herein, including but not
  57. limited to any patent rights that may be infringed by your derivative
  58. works or by other works in which the NVIDIA Software may be
  59. incorporated. No hardware is licensed hereunder.
  60. THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
  61. WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  62. INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
  63. NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
  64. ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
  65. PRODUCTS.
  66. IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
  67. INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  68. TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  69. USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
  70. OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
  71. NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
  72. TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
  73. NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  74. \****************************************************************************/
  75. #include <cstdlib>
  76. #include <locale>
  77. #include "PpContext.h"
  78. namespace glslang {
  79. TPpContext::TPpContext(TParseContextBase& pc, const std::string& rootFileName, TShader::Includer& inclr) :
  80. preamble(0), strings(0), previous_token('\n'), parseContext(pc), includer(inclr), inComment(false),
  81. rootFileName(rootFileName),
  82. currentSourceFile(rootFileName),
  83. disableEscapeSequences(false)
  84. {
  85. ifdepth = 0;
  86. for (elsetracker = 0; elsetracker < maxIfNesting; elsetracker++)
  87. elseSeen[elsetracker] = false;
  88. elsetracker = 0;
  89. strtodStream.imbue(std::locale::classic());
  90. }
  91. TPpContext::~TPpContext()
  92. {
  93. delete [] preamble;
  94. // free up the inputStack
  95. while (! inputStack.empty())
  96. popInput();
  97. }
  98. void TPpContext::setInput(TInputScanner& input, bool versionWillBeError)
  99. {
  100. assert(inputStack.size() == 0);
  101. pushInput(new tStringInput(this, input));
  102. errorOnVersion = versionWillBeError;
  103. versionSeen = false;
  104. }
  105. } // end namespace glslang