Merge pull request #76479 from bitsawer/fix_preprocessor_line_number

Fix Shader Preprocessor line numbering when disabled
This commit is contained in:
Rémi Verschelde 2023-04-27 08:19:30 +02:00
commit 5a1d4bd8ab
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 8 additions and 12 deletions

View File

@ -54,9 +54,9 @@ int ShaderPreprocessor::Tokenizer::get_index() const {
return index; return index;
} }
void ShaderPreprocessor::Tokenizer::get_and_clear_generated(Vector<ShaderPreprocessor::Token> *r_out) { void ShaderPreprocessor::Tokenizer::get_and_clear_generated(LocalVector<char32_t> *r_out) {
for (int i = 0; i < generated.size(); i++) { for (uint32_t i = 0; i < generated.size(); i++) {
r_out->push_back(generated[i]); r_out->push_back(generated[i].text);
} }
generated.clear(); generated.clear();
} }
@ -1206,18 +1206,14 @@ Error ShaderPreprocessor::preprocess(State *p_state, const String &p_code, Strin
break; break;
} }
// Add autogenerated tokens if there are any.
p_tokenizer.get_and_clear_generated(&output);
if (state->disabled) { if (state->disabled) {
// Preprocessor was disabled. // Preprocessor was disabled.
// Read the rest of the file into the output. // Read the rest of the file into the output.
output.push_back(t.text); output.push_back(t.text);
continue; continue;
} else {
// Add autogenerated tokens.
Vector<Token> generated;
p_tokenizer.get_and_clear_generated(&generated);
for (int i = 0; i < generated.size(); i++) {
output.push_back(generated[i].text);
}
} }
if (t.text == '#') { if (t.text == '#') {

View File

@ -83,7 +83,7 @@ private:
int line; int line;
int index; int index;
int size; int size;
Vector<Token> generated; LocalVector<Token> generated;
private: private:
void add_generated(const Token &p_t); void add_generated(const Token &p_t);
@ -95,7 +95,7 @@ private:
char32_t peek(); char32_t peek();
int consume_line_continuations(int p_offset); int consume_line_continuations(int p_offset);
void get_and_clear_generated(Vector<Token> *r_out); void get_and_clear_generated(LocalVector<char32_t> *r_out);
void backtrack(char32_t p_what); void backtrack(char32_t p_what);
LocalVector<Token> advance(char32_t p_what); LocalVector<Token> advance(char32_t p_what);
void skip_whitespace(); void skip_whitespace();