|
|
@ -4515,20 +4515,41 @@ static sxi32 VmByteCodeExec( |
|
|
|
*/ |
|
|
|
case PH7_OP_CLASS_INIT: |
|
|
|
{ |
|
|
|
ph7_class *pClass = (ph7_class *)pInstr->p3; |
|
|
|
printf("Called by class: '%s'\n", pClass->sName); |
|
|
|
ph7_class *pClassInfo = (ph7_class *)pInstr->p3; |
|
|
|
ph7_class *pBase = 0; |
|
|
|
ph7_class *pClass; |
|
|
|
printf("Called by class: '%s'\n", pClassInfo->sName); |
|
|
|
if(pInstr->iP1) { |
|
|
|
/* This class inherits from other classes */ |
|
|
|
SyString *apExtends; |
|
|
|
while(SySetGetNextEntry(&pClass->sExtends, (void **)&apExtends) == SXRET_OK) { |
|
|
|
printf("Class '%s' inherits from '%s'\n", pClass->sName.zString, apExtends->zString); |
|
|
|
while(SySetGetNextEntry(&pClassInfo->sExtends, (void **)&apExtends) == SXRET_OK) { |
|
|
|
printf("Class '%s' inherits from '%s'\n", pClassInfo->sName.zString, apExtends->zString); |
|
|
|
pBase = PH7_VmExtractClass(pVm, apExtends->zString, apExtends->nByte, FALSE, 0); |
|
|
|
if(pBase == 0) { |
|
|
|
/* Non-existent base class */ |
|
|
|
PH7_VmThrowError(pVm, 0, PH7_CTX_ERR, "Call to non-existent base class"); |
|
|
|
} else if(pBase->iFlags & PH7_CLASS_INTERFACE) { |
|
|
|
/* Trying to inherit from interface */ |
|
|
|
PH7_VmThrowError(pVm, 0, PH7_CTX_ERR, "Class cannot inherit from interface"); |
|
|
|
} else if(pBase->iFlags & PH7_CLASS_FINAL) { |
|
|
|
/* Trying to inherit from final class */ |
|
|
|
PH7_VmThrowError(pVm, 0, PH7_CTX_ERR, "Class cannot inherit from final class"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if(pInstr->iP2) { |
|
|
|
/* This class implements some interfaces */ |
|
|
|
SyString *apImplements; |
|
|
|
while(SySetGetNextEntry(&pClass->sImplements, (void **)&apImplements) == SXRET_OK) { |
|
|
|
printf("Class '%s' implements '%s'\n", pClass->sName.zString, apImplements->zString); |
|
|
|
while(SySetGetNextEntry(&pClassInfo->sImplements, (void **)&apImplements) == SXRET_OK) { |
|
|
|
printf("Class '%s' implements '%s'\n", pClassInfo->sName.zString, apImplements->zString); |
|
|
|
pBase = PH7_VmExtractClass(pVm, apImplements->zString, apImplements->nByte, FALSE, 0); |
|
|
|
if(pBase == 0) { |
|
|
|
/* Non-existent interface */ |
|
|
|
PH7_VmThrowError(pVm, 0, PH7_CTX_ERR, "Call to non-existent interface"); |
|
|
|
} else if((pBase->iFlags & PH7_CLASS_INTERFACE) == 0) { |
|
|
|
/* Trying to extend a class */ |
|
|
|
PH7_VmThrowError(pVm, 0, PH7_CTX_ERR, "Interface cannot inherit from a class"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|