Path: blob/master/dep/reshadefx/include/effect_parser.hpp
4246 views
/*1* Copyright (C) 2014 Patrick Mours2* SPDX-License-Identifier: BSD-3-Clause3*/45#pragma once67#include "effect_symbol_table.hpp"8#include <memory> // std::unique_ptr910namespace reshadefx11{12/// <summary>13/// A parser for the ReShade FX shader language.14/// </summary>15class parser : symbol_table16{17public:18// Define constructor explicitly because lexer class is not included here19parser();20~parser();2122/// <summary>23/// Parses the provided input string.24/// </summary>25/// <param name="source">String to analyze.</param>26/// <param name="backend">Code generation implementation to use.</param>27/// <returns><see langword="true"/> if parsing was successfull, <see langword="false"/> otherwise.</returns>28bool parse(std::string source, class codegen *backend);2930/// <summary>31/// Gets the list of error messages.32/// </summary>33const std::string &errors() const { return _errors; }3435private:36void error(const location &location, unsigned int code, const std::string &message);37void warning(const location &location, unsigned int code, const std::string &message);3839void backup();40void restore();4142bool peek(char tok) const { return _token_next.id == static_cast<tokenid>(tok); }43bool peek(tokenid tokid) const { return _token_next.id == tokid; }44void consume();45void consume_until(char tok) { return consume_until(static_cast<tokenid>(tok)); }46void consume_until(tokenid tokid);47bool accept(char tok) { return accept(static_cast<tokenid>(tok)); }48bool accept(tokenid tokid);49bool expect(char tok) { return expect(static_cast<tokenid>(tok)); }50bool expect(tokenid tokid);5152bool accept_symbol(std::string &identifier, scoped_symbol &symbol);53bool accept_type_class(type &type);54bool accept_type_qualifiers(type &type);55bool accept_unary_op();56bool accept_postfix_op();57bool peek_multary_op(unsigned int &precedence) const;58bool accept_assignment_op();5960bool parse_top(bool &parse_success);61bool parse_struct();62bool parse_function(type type, std::string name, shader_type stype, int num_threads[3]);63bool parse_variable(type type, std::string name, bool global = false);64bool parse_technique();65bool parse_technique_pass(pass &info);66bool parse_type(type &type);67bool parse_array_length(type &type);68bool parse_expression(expression &expression);69bool parse_expression_unary(expression &expression);70bool parse_expression_multary(expression &expression, unsigned int precedence = 0);71bool parse_expression_assignment(expression &expression);72bool parse_annotations(std::vector<annotation> &annotations);73bool parse_statement(bool scoped);74bool parse_statement_block(bool scoped);7576std::string _errors;7778std::unique_ptr<class lexer> _lexer;79class codegen *_codegen = nullptr;8081token _token;82token _token_next;83token _token_backup;8485std::vector<uint32_t> _loop_break_target_stack;86std::vector<uint32_t> _loop_continue_target_stack;87};88}899091