From 13ab70ed2afdd5cb11a08c41948b94c57f494360 Mon Sep 17 00:00:00 2001 From: Yuri Rubinsky Date: Mon, 15 Aug 2022 20:20:13 +0300 Subject: Add `elif` directive to shader preprocessor --- servers/rendering/shader_preprocessor.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'servers/rendering/shader_preprocessor.h') diff --git a/servers/rendering/shader_preprocessor.h b/servers/rendering/shader_preprocessor.h index 41b574298d..71dd9a6ca8 100644 --- a/servers/rendering/shader_preprocessor.h +++ b/servers/rendering/shader_preprocessor.h @@ -130,14 +130,23 @@ private: String body; }; - struct SkippedCondition { - int start_line = -1; - int end_line = -1; + struct Branch { + Vector conditions; + Branch *parent = nullptr; + bool else_defined = false; + + Branch() {} + + Branch(bool p_condition, Branch *p_parent) : + parent(p_parent) { + conditions.push_back(p_condition); + } }; struct State { RBMap defines; - Vector skip_stack_else; + List branches; + Branch *current_branch = nullptr; int condition_depth = 0; RBSet includes; List cyclic_include_hashes; // Holds code hash of includes. @@ -149,7 +158,6 @@ private: bool save_regions = false; RBMap> regions; Region *previous_region = nullptr; - RBMap> skipped_conditions; bool disabled = false; CompletionType completion_type = COMPLETION_TYPE_NONE; HashSet> shader_includes; @@ -169,6 +177,7 @@ private: void process_directive(Tokenizer *p_tokenizer); void process_define(Tokenizer *p_tokenizer); + void process_elif(Tokenizer *p_tokenizer); void process_else(Tokenizer *p_tokenizer); void process_endif(Tokenizer *p_tokenizer); void process_if(Tokenizer *p_tokenizer); @@ -179,7 +188,7 @@ private: void process_undef(Tokenizer *p_tokenizer); void add_region(int p_line, bool p_enabled, Region *p_parent_region); - void start_branch_condition(Tokenizer *p_tokenizer, bool p_success); + void start_branch_condition(Tokenizer *p_tokenizer, bool p_success, bool p_continue = false); void expand_output_macros(int p_start, int p_line); Error expand_macros(const String &p_string, int p_line, String &r_result); -- cgit v1.2.3