mirror of
https://github.com/godotengine/godot.git
synced 2025-10-30 13:11:13 +00:00
GDScript: Add static typing for for loop variable
This commit is contained in:
parent
0511f9d9a7
commit
6c59ed9485
20 changed files with 177 additions and 17 deletions
|
|
@ -1494,19 +1494,16 @@ void GDScriptByteCodeGenerator::start_for(const GDScriptDataType &p_iterator_typ
|
|||
for_container_variables.push_back(container);
|
||||
}
|
||||
|
||||
void GDScriptByteCodeGenerator::write_for_assignment(const Address &p_variable, const Address &p_list) {
|
||||
void GDScriptByteCodeGenerator::write_for_assignment(const Address &p_list) {
|
||||
const Address &container = for_container_variables.back()->get();
|
||||
|
||||
// Assign container.
|
||||
append_opcode(GDScriptFunction::OPCODE_ASSIGN);
|
||||
append(container);
|
||||
append(p_list);
|
||||
|
||||
for_iterator_variables.push_back(p_variable);
|
||||
}
|
||||
|
||||
void GDScriptByteCodeGenerator::write_for() {
|
||||
const Address &iterator = for_iterator_variables.back()->get();
|
||||
void GDScriptByteCodeGenerator::write_for(const Address &p_variable, bool p_use_conversion) {
|
||||
const Address &counter = for_counter_variables.back()->get();
|
||||
const Address &container = for_container_variables.back()->get();
|
||||
|
||||
|
|
@ -1599,11 +1596,16 @@ void GDScriptByteCodeGenerator::write_for() {
|
|||
}
|
||||
}
|
||||
|
||||
Address temp;
|
||||
if (p_use_conversion) {
|
||||
temp = Address(Address::LOCAL_VARIABLE, add_local("@iterator_temp", GDScriptDataType()));
|
||||
}
|
||||
|
||||
// Begin loop.
|
||||
append_opcode(begin_opcode);
|
||||
append(counter);
|
||||
append(container);
|
||||
append(iterator);
|
||||
append(p_use_conversion ? temp : p_variable);
|
||||
for_jmp_addrs.push_back(opcodes.size());
|
||||
append(0); // End of loop address, will be patched.
|
||||
append_opcode(GDScriptFunction::OPCODE_JUMP);
|
||||
|
|
@ -1615,9 +1617,17 @@ void GDScriptByteCodeGenerator::write_for() {
|
|||
append_opcode(iterate_opcode);
|
||||
append(counter);
|
||||
append(container);
|
||||
append(iterator);
|
||||
append(p_use_conversion ? temp : p_variable);
|
||||
for_jmp_addrs.push_back(opcodes.size());
|
||||
append(0); // Jump destination, will be patched.
|
||||
|
||||
if (p_use_conversion) {
|
||||
write_assign_with_conversion(p_variable, temp);
|
||||
const GDScriptDataType &type = p_variable.type;
|
||||
if (type.kind != GDScriptDataType::BUILTIN || type.builtin_type == Variant::ARRAY || type.builtin_type == Variant::DICTIONARY) {
|
||||
write_assign_false(temp); // Can contain RefCounted, so clear it.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GDScriptByteCodeGenerator::write_endfor() {
|
||||
|
|
@ -1639,7 +1649,6 @@ void GDScriptByteCodeGenerator::write_endfor() {
|
|||
current_breaks_to_patch.pop_back();
|
||||
|
||||
// Pop state.
|
||||
for_iterator_variables.pop_back();
|
||||
for_counter_variables.pop_back();
|
||||
for_container_variables.pop_back();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue