From 902a4b839ce6b48533694ad98c8532185605af1e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 9 Dec 2016 23:00:34 +0100 Subject: [PATCH] - fixed: Type determination of multi-dimensional arrays failed, apparently because ZCCCompiler::Simplify is too broken to leave the node's ring list intact. Instead of trying to fix Simplify, which seems to be a lost cause, the ring list now gets unraveled into an array which is immune from this type of problem. --- src/scripting/zscript/zcc_compile.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 856802a97..2b4974bda 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -1583,12 +1583,19 @@ PType *ZCCCompiler::ResolveUserType(ZCC_BasicType *type, PSymbolTable *symt) PType *ZCCCompiler::ResolveArraySize(PType *baseType, ZCC_Expression *arraysize, PSymbolTable *sym) { - // The duplicate Simplify call is necessary because if the head node gets replaced there is no way to detect the end of the list otherwise. - arraysize = Simplify(arraysize, sym, true); - ZCC_Expression *val; + TArray indices; + + // Simplify is too broken to resolve this inside the ring list so unravel the list into an array before starting to simplify its components. + auto node = arraysize; do { - val = Simplify(arraysize, sym, true); + indices.Push(node); + node = static_cast(node->SiblingNext); + } while (node != arraysize); + + for (auto node : indices) + { + auto val = Simplify(node, sym, true); if (val->Operation != PEX_ConstValue || !val->Type->IsA(RUNTIME_CLASS(PInt))) { Error(arraysize, "Array index must be an integer constant"); @@ -1601,8 +1608,7 @@ PType *ZCCCompiler::ResolveArraySize(PType *baseType, ZCC_Expression *arraysize, return TypeError; } baseType = NewArray(baseType, size); - val = static_cast(val->SiblingNext); - } while (val != arraysize); + } return baseType; }