duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

effect_parser.hpp (2990B)


      1 /*
      2  * Copyright (C) 2014 Patrick Mours
      3  * SPDX-License-Identifier: BSD-3-Clause
      4  */
      5 
      6 #pragma once
      7 
      8 #include "effect_symbol_table.hpp"
      9 #include <memory> // std::unique_ptr
     10 
     11 namespace reshadefx
     12 {
     13 	/// <summary>
     14 	/// A parser for the ReShade FX shader language.
     15 	/// </summary>
     16 	class parser : symbol_table
     17 	{
     18 	public:
     19 		// Define constructor explicitly because lexer class is not included here
     20 		parser();
     21 		~parser();
     22 
     23 		/// <summary>
     24 		/// Parses the provided input string.
     25 		/// </summary>
     26 		/// <param name="source">String to analyze.</param>
     27 		/// <param name="backend">Code generation implementation to use.</param>
     28 		/// <returns><see langword="true"/> if parsing was successfull, <see langword="false"/> otherwise.</returns>
     29 		bool parse(std::string source, class codegen *backend);
     30 
     31 		/// <summary>
     32 		/// Gets the list of error messages.
     33 		/// </summary>
     34 		const std::string &errors() const { return _errors; }
     35 
     36 	private:
     37 		void error(const location &location, unsigned int code, const std::string &message);
     38 		void warning(const location &location, unsigned int code, const std::string &message);
     39 
     40 		void backup();
     41 		void restore();
     42 
     43 		bool peek(char tok) const { return _token_next.id == static_cast<tokenid>(tok); }
     44 		bool peek(tokenid tokid) const { return _token_next.id == tokid; }
     45 		void consume();
     46 		void consume_until(char tok) { return consume_until(static_cast<tokenid>(tok)); }
     47 		void consume_until(tokenid tokid);
     48 		bool accept(char tok) { return accept(static_cast<tokenid>(tok)); }
     49 		bool accept(tokenid tokid);
     50 		bool expect(char tok) { return expect(static_cast<tokenid>(tok)); }
     51 		bool expect(tokenid tokid);
     52 
     53 		bool accept_symbol(std::string &identifier, scoped_symbol &symbol);
     54 		bool accept_type_class(type &type);
     55 		bool accept_type_qualifiers(type &type);
     56 		bool accept_unary_op();
     57 		bool accept_postfix_op();
     58 		bool peek_multary_op(unsigned int &precedence) const;
     59 		bool accept_assignment_op();
     60 
     61 		void parse_top(bool &parse_success);
     62 		bool parse_struct();
     63 		bool parse_function(type type, std::string name);
     64 		bool parse_variable(type type, std::string name, bool global = false);
     65 		bool parse_technique();
     66 		bool parse_technique_pass(pass_info &info);
     67 		bool parse_type(type &type);
     68 		bool parse_array_size(type &type);
     69 		bool parse_expression(expression &expression);
     70 		bool parse_expression_unary(expression &expression);
     71 		bool parse_expression_multary(expression &expression, unsigned int precedence = 0);
     72 		bool parse_expression_assignment(expression &expression);
     73 		bool parse_annotations(std::vector<annotation> &annotations);
     74 		bool parse_statement(bool scoped);
     75 		bool parse_statement_block(bool scoped);
     76 
     77 		codegen *_codegen = nullptr;
     78 		std::string _errors;
     79 
     80 		token _token, _token_next, _token_backup;
     81 		std::unique_ptr<class lexer> _lexer;
     82 		size_t _lexer_backup_offset = 0;
     83 
     84 		std::vector<uint32_t> _loop_break_target_stack;
     85 		std::vector<uint32_t> _loop_continue_target_stack;
     86 		reshadefx::function_info *_current_function = nullptr;
     87 	};
     88 }