mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 00:13:30 +00:00
GDScript: Reintroduce binary tokenization on export
This adds back a function available in 3.x: exporting the GDScript files in a binary form by converting the tokens recognized by the tokenizer into a data format. It is enabled by default on export but can be manually disabled. The format helps with loading times since, the tokens are easily reconstructed, and with hiding the source code, since recovering it would require a specialized tool. Code comments are not stored in this format. The `--test` command can also include a `--use-binary-tokens` flag which will run the GDScript tests with the binary format instead of the regular source code by converting them in-memory before the test runs.
This commit is contained in:
parent
41564aaf77
commit
b4d0a09f15
26 changed files with 1010 additions and 119 deletions
|
@ -181,14 +181,13 @@ public:
|
|||
bool can_precede_bin_op() const;
|
||||
bool is_identifier() const;
|
||||
bool is_node_name() const;
|
||||
StringName get_identifier() const { return source; }
|
||||
StringName get_identifier() const { return literal; }
|
||||
|
||||
Token(Type p_type) {
|
||||
type = p_type;
|
||||
}
|
||||
|
||||
Token() {
|
||||
}
|
||||
Token() {}
|
||||
};
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
@ -203,12 +202,26 @@ public:
|
|||
new_line = p_new_line;
|
||||
}
|
||||
};
|
||||
const HashMap<int, CommentData> &get_comments() const {
|
||||
return comments;
|
||||
}
|
||||
virtual const HashMap<int, CommentData> &get_comments() const = 0;
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
private:
|
||||
static String get_token_name(Token::Type p_token_type);
|
||||
|
||||
virtual int get_cursor_line() const = 0;
|
||||
virtual int get_cursor_column() const = 0;
|
||||
virtual void set_cursor_position(int p_line, int p_column) = 0;
|
||||
virtual void set_multiline_mode(bool p_state) = 0;
|
||||
virtual bool is_past_cursor() const = 0;
|
||||
virtual void push_expression_indented_block() = 0; // For lambdas, or blocks inside expressions.
|
||||
virtual void pop_expression_indented_block() = 0; // For lambdas, or blocks inside expressions.
|
||||
virtual bool is_text() = 0;
|
||||
|
||||
virtual Token scan() = 0;
|
||||
|
||||
virtual ~GDScriptTokenizer() {}
|
||||
};
|
||||
|
||||
class GDScriptTokenizerText : public GDScriptTokenizer {
|
||||
String source;
|
||||
const char32_t *_source = nullptr;
|
||||
const char32_t *_current = nullptr;
|
||||
|
@ -235,6 +248,7 @@ private:
|
|||
char32_t indent_char = '\0';
|
||||
int position = 0;
|
||||
int length = 0;
|
||||
Vector<int> continuation_lines;
|
||||
#ifdef DEBUG_ENABLED
|
||||
Vector<String> keyword_list;
|
||||
#endif // DEBUG_ENABLED
|
||||
|
@ -275,20 +289,28 @@ private:
|
|||
Token annotation();
|
||||
|
||||
public:
|
||||
Token scan();
|
||||
|
||||
void set_source_code(const String &p_source_code);
|
||||
|
||||
int get_cursor_line() const;
|
||||
int get_cursor_column() const;
|
||||
void set_cursor_position(int p_line, int p_column);
|
||||
void set_multiline_mode(bool p_state);
|
||||
bool is_past_cursor() const;
|
||||
static String get_token_name(Token::Type p_token_type);
|
||||
void push_expression_indented_block(); // For lambdas, or blocks inside expressions.
|
||||
void pop_expression_indented_block(); // For lambdas, or blocks inside expressions.
|
||||
const Vector<int> &get_continuation_lines() const { return continuation_lines; }
|
||||
|
||||
GDScriptTokenizer();
|
||||
virtual int get_cursor_line() const override;
|
||||
virtual int get_cursor_column() const override;
|
||||
virtual void set_cursor_position(int p_line, int p_column) override;
|
||||
virtual void set_multiline_mode(bool p_state) override;
|
||||
virtual bool is_past_cursor() const override;
|
||||
virtual void push_expression_indented_block() override; // For lambdas, or blocks inside expressions.
|
||||
virtual void pop_expression_indented_block() override; // For lambdas, or blocks inside expressions.
|
||||
virtual bool is_text() override { return true; }
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
virtual const HashMap<int, CommentData> &get_comments() const override {
|
||||
return comments;
|
||||
}
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
virtual Token scan() override;
|
||||
|
||||
GDScriptTokenizerText();
|
||||
};
|
||||
|
||||
#endif // GDSCRIPT_TOKENIZER_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue