// // Copyright (C) 2016 Google, Inc. // Copyright (C) 2016 LunarG, Inc. // // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // Neither the name of Google, Inc., nor the names of its // contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. // // // HLSL scanning, leveraging the scanning done by the preprocessor. // #include <cstring> #include <unordered_map> #include <unordered_set> #include "../Include/Types.h" #include "../MachineIndependent/SymbolTable.h" #include "../MachineIndependent/ParseHelper.h" #include "hlslScanContext.h" #include "hlslTokens.h" // preprocessor includes #include "../MachineIndependent/preprocessor/PpContext.h" #include "../MachineIndependent/preprocessor/PpTokens.h" namespace { struct str_eq { … }; struct str_hash { … }; // A single global usable by all threads, by all versions, by all languages. // After a single process-level initialization, this is read only and thread safe std::unordered_map<const char*, glslang::EHlslTokenClass, str_hash, str_eq>* KeywordMap = …; std::unordered_set<const char*, str_hash, str_eq>* ReservedSet = …; std::unordered_map<const char*, glslang::TBuiltInVariable, str_hash, str_eq>* SemanticMap = …; }; namespace glslang { void HlslScanContext::fillInKeywordMap() { … } void HlslScanContext::deleteKeywordMap() { … } // Wrapper for tokenizeClass() to get everything inside the token. void HlslScanContext::tokenize(HlslToken& token) { … } glslang::TBuiltInVariable HlslScanContext::mapSemantic(const char* upperCase) { … } // // Fill in token information for the next token, except for the token class. // Returns the enum value of the token class of the next token found. // Return 0 (EndOfTokens) on end of input. // EHlslTokenClass HlslScanContext::tokenizeClass(HlslToken& token) { … } EHlslTokenClass HlslScanContext::tokenizeIdentifier() { … } EHlslTokenClass HlslScanContext::identifierOrType() { … } // Give an error for use of a reserved symbol. // However, allow built-in declarations to use reserved words, to allow // extension support before the extension is enabled. EHlslTokenClass HlslScanContext::reservedWord() { … } } // end namespace glslang