MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / _binary_to_token

Method _binary_to_token

bytecode/gdscript_v2_tokenizer_buffer.cpp:106–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104}
105
106GDScriptV2TokenizerCompat::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
160Error GDScriptV2TokenizerBufferCompat::set_code_buffer(const Vector<uint8_t> &p_buffer) {
161 const uint8_t *buf = p_buffer.ptr();

Callers

nothing calls this directly

Calls 4

get_token_lineFunction · 0.85
get_global_tokenMethod · 0.45
get_nameMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected