Attempt to fix '$this' and '$parent' constructs.
The build was successful. Details

This commit is contained in:
Rafal Kupiec 2019-05-10 23:45:32 +02:00
parent ea5499f8b3
commit 5256dda922
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
2 changed files with 19 additions and 5 deletions

View File

@ -260,13 +260,11 @@ PH7_PRIVATE sxi32 PH7_ClassInherit(ph7_vm *pVm, ph7_class *pSub, ph7_class *pBas
continue; continue;
} }
/* Install the attribute */ /* Install the attribute */
if(pAttr->iProtection != PH7_CLASS_PROT_PRIVATE) {
rc = SyHashInsert(&pSub->hAttr, (const void *)pName->zString, pName->nByte, pAttr); rc = SyHashInsert(&pSub->hAttr, (const void *)pName->zString, pName->nByte, pAttr);
if(rc != SXRET_OK) { if(rc != SXRET_OK) {
return rc; return rc;
} }
} }
}
SyHashResetLoopCursor(&pBase->hMethod); SyHashResetLoopCursor(&pBase->hMethod);
while((pEntry = SyHashGetNextEntry(&pBase->hMethod)) != 0) { while((pEntry = SyHashGetNextEntry(&pBase->hMethod)) != 0) {
/* Make sure the private/final methods are not redeclared in the subclass */ /* Make sure the private/final methods are not redeclared in the subclass */

View File

@ -4548,6 +4548,7 @@ static sxi32 VmByteCodeExec(
if(pEntry) { if(pEntry) {
ph7_vm_func_arg *aFormalArg; ph7_vm_func_arg *aFormalArg;
ph7_class_instance *pThis; ph7_class_instance *pThis;
ph7_class *pClass;
ph7_value *pFrameStack; ph7_value *pFrameStack;
ph7_vm_func *pVmFunc; ph7_vm_func *pVmFunc;
ph7_class *pSelf; ph7_class *pSelf;
@ -4559,6 +4560,7 @@ static sxi32 VmByteCodeExec(
pVmFunc = (ph7_vm_func *)pEntry->pUserData; pVmFunc = (ph7_vm_func *)pEntry->pUserData;
pThis = 0; pThis = 0;
pSelf = 0; pSelf = 0;
pClass = 0;
if(pVmFunc->iFlags & VM_FUNC_CLASS_METHOD) { if(pVmFunc->iFlags & VM_FUNC_CLASS_METHOD) {
ph7_class_method *pMeth; ph7_class_method *pMeth;
/* Class method call */ /* Class method call */
@ -4569,6 +4571,16 @@ static sxi32 VmByteCodeExec(
/* Instance already loaded */ /* Instance already loaded */
pThis = (ph7_class_instance *)pTarget->x.pOther; pThis = (ph7_class_instance *)pTarget->x.pOther;
pThis->iRef += 2; pThis->iRef += 2;
pClass = pThis->pClass;
if(pTarget->iFlags & MEMOBJ_PARENTOBJ) {
/* Parent called */
if(pThis->pClass->pBase == 0) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
"Attempt to call parent class from non-inheritance instance of class '%z'", &pClass->sName);
}
/* Swap to parent class */
pThis->pClass = pThis->pClass->pBase;
}
pSelf = pThis->pClass; pSelf = pThis->pClass;
} }
if(pSelf == 0) { if(pSelf == 0) {
@ -4925,6 +4937,10 @@ static sxi32 VmByteCodeExec(
SyMemBackendFree(&pVm->sAllocator, pFrameStack); SyMemBackendFree(&pVm->sAllocator, pFrameStack);
/* Leave the frame */ /* Leave the frame */
VmLeaveFrame(&(*pVm)); VmLeaveFrame(&(*pVm));
if(pClass != 0) {
/* Restore original class */
pThis->pClass = pClass;
}
if(rc == PH7_ABORT) { if(rc == PH7_ABORT) {
/* Abort processing immediately */ /* Abort processing immediately */
goto Abort; goto Abort;