Allow key and value declaration inside foreach() loop.
The build was successful.
Details
The build was successful.
Details
This commit is contained in:
parent
a726ab795a
commit
1d6822c1e2
|
@ -1811,7 +1811,9 @@ static sxi32 PH7_CompileForeach(ph7_gen_state *pGen) {
|
||||||
ph7_foreach_info *pInfo;
|
ph7_foreach_info *pInfo;
|
||||||
sxu32 nFalseJump;
|
sxu32 nFalseJump;
|
||||||
VmInstr *pInstr;
|
VmInstr *pInstr;
|
||||||
|
char *zName;
|
||||||
sxu32 nLine;
|
sxu32 nLine;
|
||||||
|
sxu32 nKey;
|
||||||
sxi32 rc;
|
sxi32 rc;
|
||||||
nLine = pGen->pIn->nLine;
|
nLine = pGen->pIn->nLine;
|
||||||
/* Jump the 'foreach' keyword */
|
/* Jump the 'foreach' keyword */
|
||||||
|
@ -1851,15 +1853,30 @@ static sxi32 PH7_CompileForeach(ph7_gen_state *pGen) {
|
||||||
}
|
}
|
||||||
pTmp = pGen->pEnd;
|
pTmp = pGen->pEnd;
|
||||||
pGen->pEnd = pCur;
|
pGen->pEnd = pCur;
|
||||||
rc = PH7_CompileExpr(&(*pGen), 0, GenStateForEachNodeValidator);
|
nKey = (sxu32)(SX_PTR_TO_INT(pGen->pIn->pUserData));
|
||||||
if(rc == SXERR_ABORT) {
|
if(nKey & PH7_KEYWORD_TYPEDEF) {
|
||||||
/* Expression handler request an operation abort [i.e: Out-of-memory] */
|
/* Hack to compile variable */
|
||||||
return SXERR_ABORT;
|
pGen->pEnd->nType = PH7_TK_SEMI;
|
||||||
}
|
if(pGen->pIn[3].nType != PH7_TK_SEMI) {
|
||||||
pInstr = PH7_VmPopInstr(pGen->pVm);
|
PH7_GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "foreach: Improper key declaration");
|
||||||
if(pInstr->p3) {
|
}
|
||||||
|
/* Extract variable name */
|
||||||
|
zName = SyMemBackendStrDup(&pGen->pVm->sAllocator, pGen->pIn[2].sData.zString, pGen->pIn[2].sData.nByte);
|
||||||
|
/* Compile variable declaration */
|
||||||
|
PH7_CompileVar(&(*pGen));
|
||||||
/* Record key name */
|
/* Record key name */
|
||||||
SyStringInitFromBuf(&pInfo->sKey, pInstr->p3, SyStrlen((const char *)pInstr->p3));
|
SyStringInitFromBuf(&pInfo->sKey, zName, SyStrlen(zName));
|
||||||
|
} else {
|
||||||
|
rc = PH7_CompileExpr(&(*pGen), 0, GenStateForEachNodeValidator);
|
||||||
|
if(rc == SXERR_ABORT) {
|
||||||
|
/* Expression handler request an operation abort [i.e: Out-of-memory] */
|
||||||
|
return SXERR_ABORT;
|
||||||
|
}
|
||||||
|
pInstr = PH7_VmPopInstr(pGen->pVm);
|
||||||
|
if(pInstr->p3) {
|
||||||
|
/* Record key name */
|
||||||
|
SyStringInitFromBuf(&pInfo->sKey, pInstr->p3, SyStrlen((const char *)pInstr->p3));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pCur++; /* Jump the array operator */
|
pCur++; /* Jump the array operator */
|
||||||
pGen->pIn = pCur;
|
pGen->pIn = pCur;
|
||||||
|
@ -1885,16 +1902,31 @@ static sxi32 PH7_CompileForeach(ph7_gen_state *pGen) {
|
||||||
/* Swap token streams */
|
/* Swap token streams */
|
||||||
pTmp = pGen->pEnd;
|
pTmp = pGen->pEnd;
|
||||||
pGen->pEnd = pCur;
|
pGen->pEnd = pCur;
|
||||||
/* Compile the expression holding the value name */
|
nKey = (sxu32)(SX_PTR_TO_INT(pGen->pIn->pUserData));
|
||||||
rc = PH7_CompileExpr(&(*pGen), 0, GenStateForEachNodeValidator);
|
if(nKey & PH7_KEYWORD_TYPEDEF) {
|
||||||
if(rc == SXERR_ABORT) {
|
/* Hack to compile variable */
|
||||||
/* Expression handler request an operation abort [i.e: Out-of-memory] */
|
pGen->pEnd->nType = PH7_TK_SEMI;
|
||||||
return SXERR_ABORT;
|
if(pGen->pIn[3].nType != PH7_TK_SEMI) {
|
||||||
}
|
PH7_GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "foreach: Improper value declaration");
|
||||||
pInstr = PH7_VmPopInstr(pGen->pVm);
|
}
|
||||||
if(pInstr->p3) {
|
/* Extract variable name */
|
||||||
|
zName = SyMemBackendStrDup(&pGen->pVm->sAllocator, pGen->pIn[2].sData.zString, pGen->pIn[2].sData.nByte);
|
||||||
|
/* Compile variable declaration */
|
||||||
|
PH7_CompileVar(&(*pGen));
|
||||||
/* Record value name */
|
/* Record value name */
|
||||||
SyStringInitFromBuf(&pInfo->sValue, pInstr->p3, SyStrlen((const char *)pInstr->p3));
|
SyStringInitFromBuf(&pInfo->sValue, zName, SyStrlen(zName));
|
||||||
|
} else {
|
||||||
|
/* Compile the expression holding the value name */
|
||||||
|
rc = PH7_CompileExpr(&(*pGen), 0, GenStateForEachNodeValidator);
|
||||||
|
if(rc == SXERR_ABORT) {
|
||||||
|
/* Expression handler request an operation abort [i.e: Out-of-memory] */
|
||||||
|
return SXERR_ABORT;
|
||||||
|
}
|
||||||
|
pInstr = PH7_VmPopInstr(pGen->pVm);
|
||||||
|
if(pInstr->p3) {
|
||||||
|
/* Record value name */
|
||||||
|
SyStringInitFromBuf(&pInfo->sValue, pInstr->p3, SyStrlen((const char *)pInstr->p3));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(pGen->pIn < pCur) {
|
if(pGen->pIn < pCur) {
|
||||||
PH7_GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "foreach: Unexpected token '%z'", &pGen->pIn->sData);
|
PH7_GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "foreach: Unexpected token '%z'", &pGen->pIn->sData);
|
||||||
|
|
Loading…
Reference in New Issue