feat: modules moved and engine moved to submodule

This commit is contained in:
Jan van der Weide 2025-04-12 18:40:44 +02:00
parent dfb5e645cd
commit c33d2130cc
5136 changed files with 225275 additions and 64485 deletions

View file

@ -269,6 +269,9 @@ void GDScriptParser::override_completion_context(const Node *p_for_node, Complet
context.current_argument = p_argument;
context.node = p_node;
context.parser = this;
if (!completion_call_stack.is_empty()) {
context.call = completion_call_stack.back()->get();
}
completion_context = context;
}
@ -288,6 +291,9 @@ void GDScriptParser::make_completion_context(CompletionType p_type, Node *p_node
context.current_argument = p_argument;
context.node = p_node;
context.parser = this;
if (!completion_call_stack.is_empty()) {
context.call = completion_call_stack.back()->get();
}
completion_context = context;
}
@ -306,6 +312,9 @@ void GDScriptParser::make_completion_context(CompletionType p_type, Variant::Typ
context.current_line = tokenizer->get_cursor_line();
context.builtin_type = p_builtin_type;
context.parser = this;
if (!completion_call_stack.is_empty()) {
context.call = completion_call_stack.back()->get();
}
completion_context = context;
}
@ -317,9 +326,6 @@ void GDScriptParser::push_completion_call(Node *p_call) {
call.call = p_call;
call.argument = 0;
completion_call_stack.push_back(call);
if (previous.cursor_place == GDScriptTokenizerText::CURSOR_MIDDLE || previous.cursor_place == GDScriptTokenizerText::CURSOR_END || current.cursor_place == GDScriptTokenizerText::CURSOR_BEGINNING) {
completion_call = call;
}
}
void GDScriptParser::pop_completion_call() {
@ -331,7 +337,7 @@ void GDScriptParser::pop_completion_call() {
}
void GDScriptParser::set_last_completion_call_arg(int p_argument) {
if (!for_completion || passed_cursor) {
if (!for_completion) {
return;
}
ERR_FAIL_COND_MSG(completion_call_stack.is_empty(), "Trying to set argument on empty completion call stack");
@ -477,12 +483,6 @@ GDScriptTokenizer::Token GDScriptParser::advance() {
if (current.type == GDScriptTokenizer::Token::TK_EOF) {
ERR_FAIL_COND_V_MSG(current.type == GDScriptTokenizer::Token::TK_EOF, current, "GDScript parser bug: Trying to advance past the end of stream.");
}
if (for_completion && !completion_call_stack.is_empty()) {
if (completion_call.call == nullptr && tokenizer->is_past_cursor()) {
completion_call = completion_call_stack.back()->get();
passed_cursor = true;
}
}
previous = current;
current = tokenizer->scan();
while (current.type == GDScriptTokenizer::Token::ERROR) {
@ -613,12 +613,12 @@ void GDScriptParser::parse_program() {
current_class = head;
bool can_have_class_or_extends = true;
#define PUSH_PENDING_ANNOTATIONS_TO_HEAD \
if (!annotation_stack.is_empty()) { \
for (AnnotationNode * annot : annotation_stack) { \
head->annotations.push_back(annot); \
} \
annotation_stack.clear(); \
#define PUSH_PENDING_ANNOTATIONS_TO_HEAD \
if (!annotation_stack.is_empty()) { \
for (AnnotationNode *annot : annotation_stack) { \
head->annotations.push_back(annot); \
} \
annotation_stack.clear(); \
}
while (!check(GDScriptTokenizer::Token::TK_EOF)) {
@ -672,14 +672,16 @@ void GDScriptParser::parse_program() {
}
}
if (current.type == GDScriptTokenizer::Token::CLASS_NAME || current.type == GDScriptTokenizer::Token::EXTENDS) {
// Set range of the class to only start at extends or class_name if present.
reset_extents(head, current);
}
while (can_have_class_or_extends) {
// Order here doesn't matter, but there should be only one of each at most.
switch (current.type) {
case GDScriptTokenizer::Token::CLASS_NAME:
PUSH_PENDING_ANNOTATIONS_TO_HEAD;
if (head->start_line == 1) {
reset_extents(head, current);
}
advance();
if (head->identifier != nullptr) {
push_error(R"("class_name" can only be used once.)");
@ -689,9 +691,6 @@ void GDScriptParser::parse_program() {
break;
case GDScriptTokenizer::Token::EXTENDS:
PUSH_PENDING_ANNOTATIONS_TO_HEAD;
if (head->start_line == 1) {
reset_extents(head, current);
}
advance();
if (head->extends_used) {
push_error(R"("extends" can only be used once.)");
@ -2721,16 +2720,16 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_builtin_constant(Expressio
switch (op_type) {
case GDScriptTokenizer::Token::CONST_PI:
constant->value = Math_PI;
constant->value = Math::PI;
break;
case GDScriptTokenizer::Token::CONST_TAU:
constant->value = Math_TAU;
constant->value = Math::TAU;
break;
case GDScriptTokenizer::Token::CONST_INF:
constant->value = INFINITY;
constant->value = Math::INF;
break;
case GDScriptTokenizer::Token::CONST_NAN:
constant->value = NAN;
constant->value = Math::NaN;
break;
default:
return nullptr; // Unreachable.
@ -3302,7 +3301,11 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_call(ExpressionNode *p_pre
IdentifierNode *identifier = parse_identifier();
call->callee = identifier;
call->function_name = identifier->name;
consume(GDScriptTokenizer::Token::PARENTHESIS_OPEN, R"(Expected "(" after function name.)");
if (!consume(GDScriptTokenizer::Token::PARENTHESIS_OPEN, R"(Expected "(" after function name.)")) {
pop_multiline();
complete_extents(call);
return nullptr;
}
}
} else {
call->callee = p_previous_operand;
@ -3337,6 +3340,7 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_call(ExpressionNode *p_pre
int argument_index = 0;
do {
make_completion_context(ct, call, argument_index);
set_last_completion_call_arg(argument_index);
if (check(GDScriptTokenizer::Token::PARENTHESIS_CLOSE)) {
// Allow for trailing comma.
break;
@ -4131,7 +4135,7 @@ GDScriptParser::ParseRule *GDScriptParser::get_rule(GDScriptTokenizer::Token::Ty
};
/* clang-format on */
// Avoid desync.
static_assert(sizeof(rules) / sizeof(rules[0]) == GDScriptTokenizer::Token::TK_MAX, "Amount of parse rules don't match the amount of token types.");
static_assert(std::size(rules) == GDScriptTokenizer::Token::TK_MAX, "Amount of parse rules don't match the amount of token types.");
// Let's assume this is never invalid, since nothing generates a TK_MAX.
return &rules[p_token_type];
@ -4354,7 +4358,7 @@ static StringName _find_narrowest_native_or_global_class(const GDScriptParser::D
}
if (p_type.is_meta_type) {
return script.is_valid() ? script->get_class() : Script::get_class_static();
return script.is_valid() ? script->get_class_name() : Script::get_class_static();
}
if (script.is_null()) {
return p_type.native_type;
@ -5254,7 +5258,7 @@ PropertyInfo GDScriptParser::DataType::to_property_info(const String &p_name) co
case SCRIPT:
result.type = Variant::OBJECT;
if (is_meta_type) {
result.class_name = script_type.is_valid() ? script_type->get_class() : Script::get_class_static();
result.class_name = script_type.is_valid() ? script_type->get_class_name() : Script::get_class_static();
} else if (script_type.is_valid() && script_type->get_global_name() != StringName()) {
result.class_name = script_type->get_global_name();
} else {