Home | History | Annotate | Download | only in MachineIndependent
      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 requireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc);
     72     virtual void ppRequireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc);
     73     virtual TExtensionBehavior getExtensionBehavior(const char*);
     74     virtual bool extensionTurnedOn(const char* const extension);
     75     virtual bool extensionsTurnedOn(int numExtensions, const char* const extensions[]);
     76     virtual void updateExtensionBehavior(int line, const char* const extension, const char* behavior);
     77     virtual void fullIntegerCheck(const TSourceLoc&, const char* op);
     78     virtual void doubleCheck(const TSourceLoc&, const char* op);
     79     virtual void int64Check(const TSourceLoc&, const char* op, bool builtIn = false);
     80     virtual void spvRemoved(const TSourceLoc&, const char* op);
     81     virtual void vulkanRemoved(const TSourceLoc&, const char* op);
     82     virtual void requireVulkan(const TSourceLoc&, const char* op);
     83     virtual void requireSpv(const TSourceLoc&, const char* op);
     84     virtual bool checkExtensionsRequested(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc);
     85     virtual void updateExtensionBehavior(const char* const extension, TExtensionBehavior);
     86 
     87     virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken,
     88         const char* szExtraInfoFormat, ...) = 0;
     89     virtual void C_DECL  warn(const TSourceLoc&, const char* szReason, const char* szToken,
     90         const char* szExtraInfoFormat, ...) = 0;
     91     virtual void C_DECL ppError(const TSourceLoc&, const char* szReason, const char* szToken,
     92         const char* szExtraInfoFormat, ...) = 0;
     93     virtual void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken,
     94         const char* szExtraInfoFormat, ...) = 0;
     95 
     96     void addError() { ++numErrors; }
     97     int getNumErrors() const { return numErrors; }
     98 
     99     void setScanner(TInputScanner* scanner) { currentScanner = scanner; }
    100     TInputScanner* getScanner() const { return currentScanner; }
    101     const TSourceLoc& getCurrentLoc() const { return currentScanner->getSourceLoc(); }
    102     void setCurrentLine(int line) { currentScanner->setLine(line); }
    103     void setCurrentColumn(int col) { currentScanner->setColumn(col); }
    104     void setCurrentSourceName(const char* name) { currentScanner->setFile(name); }
    105     void setCurrentString(int string) { currentScanner->setString(string); }
    106 
    107     void getPreamble(std::string&);
    108     bool relaxedErrors()    const { return (messages & EShMsgRelaxedErrors) != 0; }
    109     bool suppressWarnings() const { return (messages & EShMsgSuppressWarnings) != 0; }
    110 
    111     TInfoSink& infoSink;
    112 
    113     // compilation mode
    114     int version;                 // version, updated by #version in the shader
    115     EProfile profile;            // the declared profile in the shader (core by default)
    116     EShLanguage language;        // really the stage
    117     SpvVersion spvVersion;
    118     bool forwardCompatible;      // true if errors are to be given for use of deprecated features
    119     TIntermediate& intermediate; // helper for making and hooking up pieces of the parse tree
    120 
    121 protected:
    122     EShMessages messages;        // errors/warnings/rule-sets
    123     int numErrors;               // number of compile-time errors encountered
    124     TInputScanner* currentScanner;
    125 
    126 private:
    127     TMap<TString, TExtensionBehavior> extensionBehavior;    // for each extension string, what its current behavior is set to
    128     explicit TParseVersions(const TParseVersions&);
    129     TParseVersions& operator=(const TParseVersions&);
    130 };
    131 
    132 } // end namespace glslang
    133 
    134 #endif // _PARSE_VERSIONS_INCLUDED_
    135