<commit_before>/*
 * GLSLGenerator.h
 * 
 * This file is part of the XShaderCompiler project (Copyright (c) 2014-2016 by <NAME>)
 * See "LICENSE.txt" for license information.
 */

#ifndef XSC_GLSL_GENERATOR_H
#define XSC_GLSL_GENERATOR_H


#include <Xsc/Xsc.h>
#include "CodeWriter.h"
#include "Visitor.h"
#include "Token.h"

#include <map>
#include <vector>


namespace Xsc
{


// GLSL output code generator.
class GLSLGenerator : private Visitor
{
    
    public:
        
        GLSLGenerator(Log* log = nullptr, const Options& options = {});

        bool GenerateCode(
            Program& program,
            const ShaderInput& inputDesc,
            const ShaderOutput& outputDesc
        );

    private:
        
        /* === Structures === */

        struct SemanticStage
        {
            SemanticStage() = default;
            SemanticStage(const std::string& semantic);
            SemanticStage(
                const std::string& vertex,
                const std::string& geometry,
                const std::string& tessControl,
                const std::string& tessEvaluation,
                const std::string& fragment,
                const std::string& compute
            );

            // \throws std::out_of_range If 'target' is out of range.
            const std::string& operator [] (const ShaderTarget target) const;

            std::string vertex;
            std::string geometry;
            std::string tessControl;
            std::string tessEvaluation;
            std::string fragment;
            std::string compute;
            int         index = 0;      // Semantic index
        };

        /* === Functions === */

        void EstablishMaps();

        void Error(const std::string& msg, const AST* ast = nullptr);
        void ErrorInvalidNumArgs(const std::string& functionName, const AST* ast = nullptr);

        void BeginLn();
        void EndLn();
        
        void Write(const std::string& text);
        void WriteLn(const std::string& text);

        void IncTab();
        void DecTab();
        
        void PushOptions(const CodeWriter::Options& options);
        void PopOptions();

        // Writes a new single line comment.
        void Comment(const std::string& text);
        // Writes a "#version" directive.
        void Version(int versionNumber);
        // Writes a "#line" directive.
        void Line(int lineNumber);
        void Line(const TokenPtr& tkn);
        void Line(const AST* ast);
        // Writes a blank line.
        void Blank();
        // Writes a new extensions
        void Extension(const std::string& extensionName);

        void AppendRequiredExtensions(Program* ast);
        
        void AppendCommonMacros();
        //void AppendInterlockedMacros();

        //void AppendMulIntrinsics();
        void AppendRcpIntrinsics();
        void AppendClipIntrinsics();
        void AppendSinCosIntrinsics();

        // Opens a new scope with '{'.
        void OpenScope();<commit_msg>Formatting.<commit_after>/*
 * GLSLGenerator.h
 * 
 * This file is part of the XShaderCompiler project (Copyright (c) 2014-2016 by <NAME>)
 * See "LICENSE.txt" for license information.
 */

#ifndef XSC_GLSL_GENERATOR_H
#define XSC_GLSL_GENERATOR_H


#include <Xsc/Xsc.h>
#include "CodeWriter.h"
#include "Visitor.h"
#include "Token.h"

#include <map>
#include <vector>


namespace Xsc
{


// GLSL output code generator.
class GLSLGenerator : private Visitor
{
    
    public:
        
        GLSLGenerator(Log* log = nullptr, const Options& options = {});

        bool GenerateCode(
            Program& program,
            const ShaderInput& inputDesc,
            const ShaderOutput& outputDesc
        );

    private:
        
        /* === Structures === */

        struct SemanticStage
        {
            SemanticStage() = default;
            SemanticStage(const std::string& semantic);
            SemanticStage(
                const std::string& vertex,
                const std::string& geometry,
                const std::string& tessControl,
                const std::string& tessEvaluation,
                const std::string& fragment,
                const std::string& compute
            );

            // \throws std::out_of_range If 'target' is out of range.
            const std::string& operator [] (const ShaderTarget target) const;

            std::string vertex;
            std::string geometry;
            std::string tessControl;
            std::string tessEvaluation;
            std::string fragment;
            std::string compute;
            int         index = 0;      // Semantic index
        };

        /* === Functions === */

        void EstablishMaps();

        void Error(const std::string& msg, const AST* ast = nullptr);
        void ErrorInvalidNumArgs(const std::string& functionName, const AST* ast = nullptr);

        void BeginLn();
        void EndLn();
        
        void Write(const std::string& text);
        void WriteLn(const std::string& text);

        void IncTab();
        void DecTab();
        
        void PushOptions(const CodeWriter::Options& options);
        void PopOptions();

        // Writes a new single line comment.
        void Comment(const std::string& text);

        // Writes a "#version" directive.
        void Version(int versionNumber);

        // Writes a "#line" directive.
        void Line(int lineNumber);
        void Line(const TokenPtr& tkn);
        void Line(const AST* ast);

        // Writes a blank line.
        void Blank();

        // Writes a new extensions
        void Extension(const std::string& extensionName);

        void AppendRequiredExtensions(Program* ast);
        
        void AppendCommonMacros();
        //void AppendInterlockedMacros();

        //void AppendMulIntrinsics();
        void AppendRcpIntrinsics();
        void AppendClipIntrinsics();
        void AppendSinCosIntrinsics();

        // Opens a new scope with '{'.
        void OpenScope();

{'fraction_non_alphanumeric': 0.10311510911211061, 'fraction_numerical': 0.0029985007496251873, 'mean_word_length': 1.9302098584675451, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6060340', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1566, 'n_words': 463}