From dbd39be5ed103818715c3f597ecd1998a3862c8a Mon Sep 17 00:00:00 2001 From: belliash Date: Fri, 7 Jun 2019 09:43:11 +0200 Subject: [PATCH] Allow the array typedef constructs to be used not only when declaring a variable. --- engine/parser.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/engine/parser.c b/engine/parser.c index 0e90fe5..e5866a7 100644 --- a/engine/parser.c +++ b/engine/parser.c @@ -832,8 +832,14 @@ static sxi32 ExprMakeTree(ph7_gen_state *pGen, ph7_expr_node **apNode, sxi32 nTo if(iLeft < 0 || apNode[iLeft] == 0 || (apNode[iLeft]->pOp == 0 && (apNode[iLeft]->xCode != PH7_CompileVariable && apNode[iLeft]->xCode != PH7_CompileSimpleString && apNode[iLeft]->xCode != PH7_CompileString)) || (apNode[iLeft]->pOp && apNode[iLeft]->pOp->iPrec != 2 /* postfix */)) { - /* Syntax error */ - PH7_GenCompileError(pGen, E_ERROR, pNode->pStart->nLine, "Invalid array name"); + sxu32 nId = 0; + if(apNode[iLeft]->xCode == PH7_CompileLiteral && apNode[iLeft]->pStart->nType & PH7_TK_KEYWORD) { + nId = SX_PTR_TO_INT(apNode[iLeft]->pStart->pUserData); + } + if(!nId || (nId & PH7_KEYWORD_TYPEDEF) == 0) { + /* Syntax error */ + PH7_GenCompileError(pGen, E_ERROR, pNode->pStart->nLine, "Invalid array name"); + } } /* Collect index tokens */ while(iArrTok < nToken) { @@ -852,6 +858,9 @@ static sxi32 ExprMakeTree(ph7_gen_state *pGen, ph7_expr_node **apNode, sxi32 nTo ++iArrTok; } if(iArrTok > iCur + 1) { + if(apNode[iLeft]->xCode == PH7_CompileLiteral) { + PH7_GenCompileError(pGen, E_ERROR, pNode->pStart->nLine, "Array index cannot be specified in a variable declaration"); + } /* Recurse and process this expression */ rc = ExprMakeTree(&(*pGen), &apNode[iCur + 1], iArrTok - iCur - 1); if(rc != SXRET_OK) {