Resolve __CLASS__ at compile time.
The build was successful. Details

Ticket: #45: __CLASS__ constant must be resolved at compile time, not run time. Otherwise it returns incorrect data.
This commit is contained in:
Rafal Kupiec 2018-08-22 09:59:10 +02:00
parent 3e18a5b8e8
commit dbe373d537
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
2 changed files with 22 additions and 2 deletions

View File

@ -1236,6 +1236,28 @@ static sxi32 PH7_GenStateLoadLiteral(ph7_gen_state *pGen) {
/* Emit the load constant instruction */
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, nIdx, 0, 0);
return SXRET_OK;
} else if(pStr->nByte == sizeof("__CLASS__") - 1 && SyMemcmp(pStr->zString, "__CLASS__", sizeof("__CLASS__") - 1) == 0) {
GenBlock *pBlock = pGen->pCurrent;
while(pBlock && (pBlock->iFlags & GEN_BLOCK_CLASS) == 0) {
/* Point to the upper block */
pBlock = pBlock->pParent;
}
if(pBlock == 0) {
/* Called in the global scope,load NULL */
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, 0, 0, 0);
} else {
/* Extract the target class */
ph7_class_info *pClassInfo = (ph7_class_info *)pBlock->pUserData;
pObj = PH7_ReserveConstObj(pGen->pVm, &nIdx);
if(pObj == 0) {
PH7_GenCompileError(pGen, E_ERROR, pToken->nLine, "Fatal, PH7 engine is running out of memory");
return SXERR_ABORT;
}
PH7_MemObjInitFromString(pGen->pVm, pObj, &pClassInfo->sName);
/* Emit the load constant instruction */
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, nIdx, 0, 0);
}
return SXRET_OK;
} else if((pStr->nByte == sizeof("__FUNCTION__") - 1 &&
SyMemcmp(pStr->zString, "__FUNCTION__", sizeof("__FUNCTION__") - 1) == 0) ||
(pStr->nByte == sizeof("__METHOD__") - 1 &&

View File

@ -1100,7 +1100,6 @@ static void PH7_static_Const(ph7_value *pVal, void *pUserData) {
}
/*
* self
* __CLASS__
* Expand the name of the current class. NULL otherwise.
*/
static void PH7_self_Const(ph7_value *pVal, void *pUserData) {
@ -1274,7 +1273,6 @@ static const ph7_builtin_constant aBuiltIn[] = {
{"EXTR_PREFIX_IF_EXISTS", PH7_EXTR_PREFIX_IF_EXISTS_Const},
{"static", PH7_static_Const },
{"self", PH7_self_Const },
{"__CLASS__", PH7_self_Const },
{"parent", PH7_parent_Const }
};
/*