| 104 | } |
| 105 | |
| 106 | GDScriptV2TokenizerCompat::Token GDScriptV2TokenizerBufferCompat::_binary_to_token(const uint8_t *p_buffer, int p_token_index) { |
| 107 | Token token; |
| 108 | const uint8_t *b = p_buffer; |
| 109 | |
| 110 | uint32_t token_type = decode_uint32(b); |
| 111 | token.type = decomp->get_global_token((token_type & TOKEN_MASK)); |
| 112 | if (token_type & TOKEN_BYTE_MASK) { |
| 113 | b += 4; |
| 114 | } else { |
| 115 | b++; |
| 116 | } |
| 117 | // token.start_line = decode_uint32(b); |
| 118 | token.start_line = get_token_line(token_lines, p_token_index); |
| 119 | token.end_line = decode_uint32(b); |
| 120 | token.start_column = get_token_line(token_columns, p_token_index); |
| 121 | token.end_column = token.start_column; |
| 122 | |
| 123 | token.literal = token.get_name(); |
| 124 | if (token.type == Token::Type::G_TK_CONST_NAN) { |
| 125 | token.literal = String("NAN"); // Special case since name and notation are different. |
| 126 | } |
| 127 | |
| 128 | switch (token.type) { |
| 129 | case GDScriptV2TokenizerCompat::Token::Type::G_TK_ANNOTATION: |
| 130 | case GDScriptV2TokenizerCompat::Token::Type::G_TK_IDENTIFIER: { |
| 131 | // Get name from map. |
| 132 | int identifier_pos = token_type >> TOKEN_BITS; |
| 133 | if (unlikely(identifier_pos >= identifiers.size())) { |
| 134 | Token error; |
| 135 | error.type = Token::Type::G_TK_ERROR; |
| 136 | error.literal = "Identifier index out of bounds."; |
| 137 | return error; |
| 138 | } |
| 139 | token.literal = identifiers[identifier_pos]; |
| 140 | } break; |
| 141 | case GDScriptV2TokenizerCompat::Token::Type::G_TK_ERROR: |
| 142 | case GDScriptV2TokenizerCompat::Token::Type::G_TK_CONSTANT: { |
| 143 | // Get literal from map. |
| 144 | int constant_pos = token_type >> TOKEN_BITS; |
| 145 | if (unlikely(constant_pos >= constants.size())) { |
| 146 | Token error; |
| 147 | error.type = Token::Type::G_TK_ERROR; |
| 148 | error.literal = "Constant index out of bounds."; |
| 149 | return error; |
| 150 | } |
| 151 | token.literal = constants[constant_pos]; |
| 152 | } break; |
| 153 | default: |
| 154 | break; |
| 155 | } |
| 156 | |
| 157 | return token; |
| 158 | } |
| 159 | |
| 160 | Error GDScriptV2TokenizerBufferCompat::set_code_buffer(const Vector<uint8_t> &p_buffer) { |
| 161 | const uint8_t *buf = p_buffer.ptr(); |
nothing calls this directly
no test coverage detected