- added 'foreach' loop to ZScript.

Syntax:

foreach(variable : array)
{
}

the variable's type is automatically deducted.
This commit is contained in:
Christoph Oelckers 2022-11-15 21:34:45 +01:00
commit 29b4418c3a
8 changed files with 173 additions and 24 deletions

View file

@ -3179,6 +3179,17 @@ FxExpression *ZCCCompiler::ConvertNode(ZCC_TreeNode *ast, bool substitute)
return new FxIfStatement(ConvertNode(iff->Condition), truePath, falsePath, *ast);
}
case AST_ArrayIterationStmt:
{
auto iter = static_cast<ZCC_ArrayIterationStmt*>(ast);
auto var = iter->ItName->Name;
FxExpression* const itArray = ConvertNode(iter->ItArray);
FxExpression* const itArray2 = ConvertNode(iter->ItArray); // the handler needs two copies of this - here's the easiest place to create them.
FxExpression* const body = ConvertImplicitScopeNode(ast, iter->LoopStatement);
return new FxForEachLoop(iter->ItName->Name, itArray, itArray2, body, *ast);
}
case AST_IterationStmt:
{
auto iter = static_cast<ZCC_IterationStmt *>(ast);