1 // 2 // Copyright (C) 2016 Google, Inc. 3 // 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 // This is implemented in Versions.cpp 37 38 #ifndef _PARSE_VERSIONS_INCLUDED_ 39 #define _PARSE_VERSIONS_INCLUDED_ 40 41 #include "../Public/ShaderLang.h" 42 #include "../Include/InfoSink.h" 43 #include "Scan.h" 44 45 #include <map> 46 47 namespace glslang { 48 49 // 50 // Base class for parse helpers. 51 // This just has version-related information and checking. 52 // This class should be sufficient for preprocessing. 53 // 54 class TParseVersions { 55 public: 56 TParseVersions(TIntermediate& interm, int version, EProfile profile, 57 const SpvVersion& spvVersion, EShLanguage language, TInfoSink& infoSink, 58 bool forwardCompatible, EShMessages messages) 59 : infoSink(infoSink), version(version), profile(profile), language(language), 60 spvVersion(spvVersion), forwardCompatible(forwardCompatible), 61 intermediate(interm), messages(messages), numErrors(0), currentScanner(0) { } 62 virtual ~TParseVersions() { } 63 virtual void initializeExtensionBehavior(); 64 virtual void requireProfile(const TSourceLoc&, int queryProfiles, const char* featureDesc); 65 virtual void profileRequires(const TSourceLoc&, int queryProfiles, int minVersion, int numExtensions, const char* const extensions[], const char* featureDesc); 66 virtual void profileRequires(const TSourceLoc&, int queryProfiles, int minVersion, const char* const extension, const char* featureDesc); 67 virtual void requireStage(const TSourceLoc&, EShLanguageMask, const char* featureDesc); 68 virtual void requireStage(const TSourceLoc&, EShLanguage, const char* featureDesc); 69 virtual void checkDeprecated(const TSourceLoc&, int queryProfiles, int depVersion, const char* featureDesc); 70 virtual void requireNotRemoved(const TSourceLoc&, int queryProfiles, int removedVersion, const char* featureDesc); 71 virtual void unimplemented(const TSourceLoc&, const char* featureDesc); 72 virtual void requireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc); 73 virtual void ppRequireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc); 74 virtual TExtensionBehavior getExtensionBehavior(const char*); 75 virtual bool extensionTurnedOn(const char* const extension); 76 virtual bool extensionsTurnedOn(int numExtensions, const char* const extensions[]); 77 virtual void updateExtensionBehavior(int line, const char* const extension, const char* behavior); 78 virtual void fullIntegerCheck(const TSourceLoc&, const char* op); 79 virtual void doubleCheck(const TSourceLoc&, const char* op); 80 #ifdef AMD_EXTENSIONS 81 virtual void int16Check(const TSourceLoc& loc, const char* op, bool builtIn = false); 82 virtual void float16Check(const TSourceLoc&, const char* op, bool builtIn = false); 83 #endif 84 virtual void int64Check(const TSourceLoc&, const char* op, bool builtIn = false); 85 virtual void spvRemoved(const TSourceLoc&, const char* op); 86 virtual void vulkanRemoved(const TSourceLoc&, const char* op); 87 virtual void requireVulkan(const TSourceLoc&, const char* op); 88 virtual void requireSpv(const TSourceLoc&, const char* op); 89 virtual bool checkExtensionsRequested(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc); 90 virtual void updateExtensionBehavior(const char* const extension, TExtensionBehavior); 91 92 virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken, 93 const char* szExtraInfoFormat, ...) = 0; 94 virtual void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken, 95 const char* szExtraInfoFormat, ...) = 0; 96 virtual void C_DECL ppError(const TSourceLoc&, const char* szReason, const char* szToken, 97 const char* szExtraInfoFormat, ...) = 0; 98 virtual void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken, 99 const char* szExtraInfoFormat, ...) = 0; 100 101 void addError() { ++numErrors; } 102 int getNumErrors() const { return numErrors; } 103 104 void setScanner(TInputScanner* scanner) { currentScanner = scanner; } 105 TInputScanner* getScanner() const { return currentScanner; } 106 const TSourceLoc& getCurrentLoc() const { return currentScanner->getSourceLoc(); } 107 void setCurrentLine(int line) { currentScanner->setLine(line); } 108 void setCurrentColumn(int col) { currentScanner->setColumn(col); } 109 void setCurrentSourceName(const char* name) { currentScanner->setFile(name); } 110 void setCurrentString(int string) { currentScanner->setString(string); } 111 112 void getPreamble(std::string&); 113 bool relaxedErrors() const { return (messages & EShMsgRelaxedErrors) != 0; } 114 bool suppressWarnings() const { return (messages & EShMsgSuppressWarnings) != 0; } 115 bool isReadingHLSL() const { return (messages & EShMsgReadHlsl) == EShMsgReadHlsl; } 116 117 TInfoSink& infoSink; 118 119 // compilation mode 120 int version; // version, updated by #version in the shader 121 EProfile profile; // the declared profile in the shader (core by default) 122 EShLanguage language; // really the stage 123 SpvVersion spvVersion; 124 bool forwardCompatible; // true if errors are to be given for use of deprecated features 125 TIntermediate& intermediate; // helper for making and hooking up pieces of the parse tree 126 127 protected: 128 TMap<TString, TExtensionBehavior> extensionBehavior; // for each extension string, what its current behavior is set to 129 EShMessages messages; // errors/warnings/rule-sets 130 int numErrors; // number of compile-time errors encountered 131 TInputScanner* currentScanner; 132 133 private: 134 explicit TParseVersions(const TParseVersions&); 135 TParseVersions& operator=(const TParseVersions&); 136 }; 137 138 } // end namespace glslang 139 140 #endif // _PARSE_VERSIONS_INCLUDED_ 141