Merge pull request #63338 from Chaosus/fix_shader_preprocessor_errors

Fix some errors after shader preprocessor PR
This commit is contained in:
Rémi Verschelde 2022-07-23 09:38:07 +02:00 committed by GitHub
commit 7c225f5bfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 40 deletions

View File

@ -381,7 +381,7 @@ void ShaderTextEditor::_validate_script() {
//preprocessor error //preprocessor error
ERR_FAIL_COND(err_positions.size() == 0); ERR_FAIL_COND(err_positions.size() == 0);
String error_text; String error_text = error_pp;
int error_line = err_positions.front()->get().line; int error_line = err_positions.front()->get().line;
if (err_positions.size() == 1) { if (err_positions.size() == 1) {
// Error in main file // Error in main file
@ -1198,12 +1198,12 @@ void ShaderEditorPlugin::edit(Object *p_object) {
Ref<VisualShader> vs = es.shader; Ref<VisualShader> vs = es.shader;
if (vs.is_valid()) { if (vs.is_valid()) {
es.visual_shader_editor = memnew(VisualShaderEditor); es.visual_shader_editor = memnew(VisualShaderEditor);
es.visual_shader_editor->edit(vs.ptr());
shader_tabs->add_child(es.visual_shader_editor); shader_tabs->add_child(es.visual_shader_editor);
es.visual_shader_editor->edit(vs.ptr());
} else { } else {
es.shader_editor = memnew(ShaderEditor); es.shader_editor = memnew(ShaderEditor);
es.shader_editor->edit(s);
shader_tabs->add_child(es.shader_editor); shader_tabs->add_child(es.shader_editor);
es.shader_editor->edit(s);
es.shader_editor->connect("validation_changed", callable_mp(this, &ShaderEditorPlugin::_update_shader_list_status)); es.shader_editor->connect("validation_changed", callable_mp(this, &ShaderEditorPlugin::_update_shader_list_status));
} }
} }

View File

@ -344,41 +344,23 @@ void ShaderPreprocessor::process_directive(Tokenizer *p_tokenizer) {
} }
if (directive == "if") { if (directive == "if") {
if (check_directive_before_type(p_tokenizer, directive)) { process_if(p_tokenizer);
process_if(p_tokenizer);
}
} else if (directive == "ifdef") { } else if (directive == "ifdef") {
if (check_directive_before_type(p_tokenizer, directive)) { process_ifdef(p_tokenizer);
process_ifdef(p_tokenizer);
}
} else if (directive == "ifndef") { } else if (directive == "ifndef") {
if (check_directive_before_type(p_tokenizer, directive)) { process_ifndef(p_tokenizer);
process_ifndef(p_tokenizer);
}
} else if (directive == "else") { } else if (directive == "else") {
if (check_directive_before_type(p_tokenizer, directive)) { process_else(p_tokenizer);
process_else(p_tokenizer);
}
} else if (directive == "endif") { } else if (directive == "endif") {
if (check_directive_before_type(p_tokenizer, directive)) { process_endif(p_tokenizer);
process_endif(p_tokenizer);
}
} else if (directive == "define") { } else if (directive == "define") {
if (check_directive_before_type(p_tokenizer, directive)) { process_define(p_tokenizer);
process_define(p_tokenizer);
}
} else if (directive == "undef") { } else if (directive == "undef") {
if (check_directive_before_type(p_tokenizer, directive)) { process_undef(p_tokenizer);
process_undef(p_tokenizer);
}
} else if (directive == "include") { } else if (directive == "include") {
if (check_directive_before_type(p_tokenizer, directive)) { process_include(p_tokenizer);
process_include(p_tokenizer);
}
} else if (directive == "pragma") { } else if (directive == "pragma") {
if (check_directive_before_type(p_tokenizer, directive)) { process_pragma(p_tokenizer);
process_pragma(p_tokenizer);
}
} else { } else {
set_error(RTR("Unknown directive."), p_tokenizer->get_line()); set_error(RTR("Unknown directive."), p_tokenizer->get_line());
} }
@ -880,14 +862,6 @@ void ShaderPreprocessor::set_error(const String &p_error, int p_line) {
} }
} }
bool ShaderPreprocessor::check_directive_before_type(Tokenizer *p_tokenizer, const String &p_directive) {
if (p_tokenizer->get_index() < state->shader_type_pos) {
set_error(vformat(RTR("`#%s` may not be defined before `shader_type`."), p_directive), p_tokenizer->get_line());
return false;
}
return true;
}
ShaderPreprocessor::Define *ShaderPreprocessor::create_define(const String &p_body) { ShaderPreprocessor::Define *ShaderPreprocessor::create_define(const String &p_body) {
ShaderPreprocessor::Define *define = memnew(Define); ShaderPreprocessor::Define *define = memnew(Define);
define->body = p_body; define->body = p_body;

View File

@ -136,7 +136,6 @@ private:
int include_depth = 0; int include_depth = 0;
String current_include; String current_include;
String current_shader_type; String current_shader_type;
int shader_type_pos = -1;
String error; String error;
List<FilePosition> include_positions; List<FilePosition> include_positions;
RBMap<String, Vector<SkippedCondition *>> skipped_conditions; RBMap<String, Vector<SkippedCondition *>> skipped_conditions;
@ -179,7 +178,6 @@ private:
String next_directive(Tokenizer *p_tokenizer, const Vector<String> &p_directives); String next_directive(Tokenizer *p_tokenizer, const Vector<String> &p_directives);
void add_to_output(const String &p_str); void add_to_output(const String &p_str);
void set_error(const String &p_error, int p_line); void set_error(const String &p_error, int p_line);
bool check_directive_before_type(Tokenizer *p_tokenizer, const String &p_directive);
static Define *create_define(const String &p_body); static Define *create_define(const String &p_body);