| 1192 | } |
| 1193 | |
| 1194 | Vector<uint8_t> GDScriptV1TokenizerBufferCompat::parse_code_string(const String &p_code, const GDScriptDecomp *p_decomp, String &error_message) { |
| 1195 | Vector<uint8_t> buf; |
| 1196 | |
| 1197 | RBMap<StringName, int> identifier_map; |
| 1198 | HashMap<Variant, int> constant_map; |
| 1199 | RBMap<uint32_t, int> line_map; |
| 1200 | Vector<uint32_t> token_array; |
| 1201 | |
| 1202 | int variant_ver_major = p_decomp->get_variant_ver_major(); |
| 1203 | |
| 1204 | // compat: from 3.0 - 3.1.1, the tokenizer defaulted to storing full objects |
| 1205 | // e61a074, Mar 28, 2019 |
| 1206 | Ref<GodotVer> NO_FULL_OBJ_VER = GodotVer::create(3, 2, 0, "dev1"); |
| 1207 | Ref<GodotVer> godot_ver = p_decomp->get_godot_ver(); |
| 1208 | bool encode_full_objects = godot_ver->lt(NO_FULL_OBJ_VER) && NO_FULL_OBJ_VER->get_major() == godot_ver->get_major(); |
| 1209 | GDScriptV1TokenizerTextCompat tt(p_decomp); |
| 1210 | tt.set_code(p_code); |
| 1211 | int line = -1; |
| 1212 | |
| 1213 | while (true) { |
| 1214 | if (tt.get_token_line() != line) { |
| 1215 | line = tt.get_token_line(); |
| 1216 | line_map[line] = token_array.size(); |
| 1217 | } |
| 1218 | const Token g_token = tt.get_token(); |
| 1219 | uint32_t local_token = p_decomp->get_local_token_val(g_token); |
| 1220 | switch (g_token) { |
| 1221 | case Token::G_TK_IDENTIFIER: { |
| 1222 | StringName id = tt.get_token_identifier(); |
| 1223 | if (!identifier_map.has(id)) { |
| 1224 | int idx = identifier_map.size(); |
| 1225 | identifier_map[id] = idx; |
| 1226 | } |
| 1227 | local_token |= identifier_map[id] << TOKEN_BITS; |
| 1228 | } break; |
| 1229 | case Token::G_TK_CONSTANT: { |
| 1230 | const Variant &c = tt.get_token_constant(); |
| 1231 | if (!constant_map.has(c)) { |
| 1232 | int idx = constant_map.size(); |
| 1233 | constant_map[c] = idx; |
| 1234 | } |
| 1235 | local_token |= constant_map[c] << TOKEN_BITS; |
| 1236 | } break; |
| 1237 | case Token::G_TK_BUILT_IN_TYPE: { |
| 1238 | int local_type = tt.get_token_constant(); |
| 1239 | local_token |= local_type << TOKEN_BITS; |
| 1240 | } break; |
| 1241 | case Token::G_TK_BUILT_IN_FUNC: { |
| 1242 | // built-in function already has correct value |
| 1243 | local_token |= tt.get_token_built_in_func() << TOKEN_BITS; |
| 1244 | } break; |
| 1245 | case Token::G_TK_NEWLINE: { |
| 1246 | local_token |= tt.get_token_line_indent() << TOKEN_BITS; |
| 1247 | } break; |
| 1248 | case Token::G_TK_ERROR: { |
| 1249 | String err = tt.get_token_error(); |
| 1250 | GDSDECOMP_FAIL_V_MSG(Vector<uint8_t>(), vformat("Compile error, line %d: %s", tt.get_token_line(), err)); |
| 1251 | } break; |
nothing calls this directly
no test coverage detected