| 261 | } |
| 262 | |
| 263 | Vector<uint8_t> GDScriptV2TokenizerBufferCompat::parse_code_string(const String &p_code, const GDScriptDecomp *p_decomp, CompressMode p_compress_mode) { |
| 264 | HashMap<StringName, uint32_t> identifier_map; |
| 265 | HashMap<Variant, uint32_t> constant_map; |
| 266 | Vector<uint8_t> token_buffer; |
| 267 | HashMap<uint32_t, uint32_t> token_lines; |
| 268 | HashMap<uint32_t, uint32_t> token_columns; |
| 269 | |
| 270 | GDScriptV2TokenizerCompatText tokenizer(p_decomp); |
| 271 | tokenizer.set_source_code(p_code); |
| 272 | tokenizer.set_multiline_mode(true); // Ignore whitespace tokens. |
| 273 | |
| 274 | Token current = tokenizer.scan(); |
| 275 | Vector<Token> tokens; |
| 276 | while (current.type != Token::Type::G_TK_EOF) { |
| 277 | tokens.push_back(current); |
| 278 | current = tokenizer.scan(); |
| 279 | } |
| 280 | int token_pos = 0; |
| 281 | int last_token_line = 0; |
| 282 | int token_counter = 0; |
| 283 | |
| 284 | for (const Token &token : tokens) { |
| 285 | int token_len = _token_to_binary(token, token_buffer, token_pos, identifier_map, constant_map, p_decomp); |
| 286 | token_pos += token_len; |
| 287 | if (token_counter > 0 && token.start_line > last_token_line) { |
| 288 | token_lines[token_counter] = token.start_line; |
| 289 | token_columns[token_counter] = token.start_column; |
| 290 | } |
| 291 | last_token_line = token.end_line; |
| 292 | |
| 293 | // current = tokenizer.scan(); |
| 294 | token_counter++; |
| 295 | } |
| 296 | |
| 297 | // Reverse maps. |
| 298 | Vector<StringName> rev_identifier_map; |
| 299 | rev_identifier_map.resize(identifier_map.size()); |
| 300 | for (const KeyValue<StringName, uint32_t> &E : identifier_map) { |
| 301 | rev_identifier_map.write[E.value] = E.key; |
| 302 | } |
| 303 | Vector<Variant> rev_constant_map; |
| 304 | rev_constant_map.resize(constant_map.size()); |
| 305 | for (const KeyValue<Variant, uint32_t> &E : constant_map) { |
| 306 | rev_constant_map.write[E.value] = E.key; |
| 307 | } |
| 308 | HashMap<uint32_t, uint32_t> rev_token_lines; |
| 309 | for (const KeyValue<uint32_t, uint32_t> &E : token_lines) { |
| 310 | rev_token_lines[E.value] = E.key; |
| 311 | } |
| 312 | |
| 313 | // Remove continuation lines from map. |
| 314 | for (int line : tokenizer.get_continuation_lines()) { |
| 315 | if (rev_token_lines.has(line)) { |
| 316 | token_lines.erase(rev_token_lines[line]); |
| 317 | token_columns.erase(rev_token_lines[line]); |
| 318 | } |
| 319 | } |
| 320 |
nothing calls this directly
no test coverage detected