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

Method _token_to_binary

bytecode/gdscript_v2_tokenizer_buffer.cpp:36–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34#include "core/io/marshalls.h"
35
36int GDScriptV2TokenizerBufferCompat::_token_to_binary(const Token &p_token, Vector<uint8_t> &r_buffer, int p_start, HashMap<StringName, uint32_t> &r_identifiers_map, HashMap<Variant, uint32_t> &r_constants_map, const GDScriptDecomp *p_decomp) {
37 int pos = p_start;
38
39 int token_type = p_decomp->get_local_token_val((GDScriptDecomp::GlobalToken)(p_token.type & TOKEN_MASK));
40
41 switch (p_token.type) {
42 case GDScriptV2TokenizerCompat::Token::Type::G_TK_ANNOTATION:
43 case GDScriptV2TokenizerCompat::Token::Type::G_TK_IDENTIFIER: {
44 // Add identifier to map.
45 int identifier_pos;
46 StringName id = p_token.get_identifier();
47 if (r_identifiers_map.has(id)) {
48 identifier_pos = r_identifiers_map[id];
49 } else {
50 identifier_pos = r_identifiers_map.size();
51 r_identifiers_map[id] = identifier_pos;
52 }
53 token_type |= identifier_pos << TOKEN_BITS;
54 } break;
55 case GDScriptV2TokenizerCompat::Token::Type::G_TK_ERROR:
56 case GDScriptV2TokenizerCompat::Token::Type::G_TK_CONSTANT: {
57 // Add literal to map.
58 int constant_pos;
59 if (r_constants_map.has(p_token.literal)) {
60 constant_pos = r_constants_map[p_token.literal];
61 } else {
62 constant_pos = r_constants_map.size();
63 r_constants_map[p_token.literal] = constant_pos;
64 }
65 token_type |= constant_pos << TOKEN_BITS;
66 } break;
67 default:
68 break;
69 }
70
71 // Encode token.
72 int token_len;
73 if (token_type & TOKEN_MASK) {
74 token_len = 8;
75 r_buffer.resize(pos + token_len);
76 encode_uint32(token_type | TOKEN_BYTE_MASK, &r_buffer.write[pos]);
77 pos += 4;
78 } else {
79 token_len = 5;
80 r_buffer.resize(pos + token_len);
81 r_buffer.write[pos] = token_type;
82 pos++;
83 }
84 encode_uint32(p_token.start_line, &r_buffer.write[pos]);
85 return token_len;
86}
87
88int get_token_line(const RBMap<int, int> &lines, int offset) {
89 auto pos_it = lines.find_closest(offset);

Callers

nothing calls this directly

Calls 4

get_identifierMethod · 0.80
get_local_token_valMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected