Skip to content

Commit

Permalink
Merge pull request #2148 from zephir-lang/fix-late-static-bind
Browse files Browse the repository at this point in the history
#2111 - Add test case to simulate interface argument type
  • Loading branch information
Jeckerson authored Feb 21, 2021
2 parents 46761b0 + 5d38953 commit e3648d2
Show file tree
Hide file tree
Showing 19 changed files with 514 additions and 269 deletions.
91 changes: 0 additions & 91 deletions Library/ArgInfoDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ private function richRenderStart()
$class = escape_class($this->compilationContext->getFullName($class));
}

$this->codePrinter->output('#if PHP_VERSION_ID >= 70200');
$this->codePrinter->output(
sprintf(
'ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(%s, %d, %d, %s, %d)',
Expand All @@ -146,25 +145,11 @@ private function richRenderStart()
(int) $this->functionLike->areReturnTypesNullCompatible()
)
);
$this->codePrinter->output('#else');
$this->codePrinter->output(
sprintf(
'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(%s, %d, %d, IS_OBJECT, "%s", %d)',
$this->name,
(int) $this->returnByRef,
$this->functionLike->getNumberOfRequiredParameters(),
$class,
(int) $this->functionLike->areReturnTypesNullCompatible()
)
);
$this->codePrinter->output('#endif');

return;
}

if ($this->functionLike->isVoid()) {
$this->codePrinter->output('#if PHP_VERSION_ID >= 70100');
$this->codePrinter->output('#if PHP_VERSION_ID >= 70200');
$this->codePrinter->output(
sprintf(
'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(%s, %d, %d, %s, %d)',
Expand All @@ -176,52 +161,15 @@ private function richRenderStart()
)
);

$this->codePrinter->output('#else');

$this->codePrinter->output(
sprintf(
'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(%s, %d, %d, %s, NULL, %d)',
$this->name,
(int) $this->returnByRef,
$this->functionLike->getNumberOfRequiredParameters(),
$this->getReturnType(),
(int) $this->functionLike->areReturnTypesNullCompatible()
)
);

$this->codePrinter->output('#endif');

if (false == $this->hasParameters()) {
$this->codePrinter->output('ZEND_END_ARG_INFO()');
}

$this->codePrinter->output('#else');

if (true == $this->hasParameters()) {
$this->codePrinter->output(
sprintf(
'ZEND_BEGIN_ARG_INFO_EX(%s, 0, %d, %d)',
$this->name,
(int) $this->returnByRef,
$this->functionLike->getNumberOfRequiredParameters()
)
);
}

$this->codePrinter->output(
sprintf(
'#define %s NULL',
$this->name
)
);

$this->codePrinter->output('#endif');
$this->codePrinter->outputBlankLine();

return;
}

$this->codePrinter->output('#if PHP_VERSION_ID >= 70200');
$this->codePrinter->output(
sprintf(
'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(%s, %d, %d, %s, %d)',
Expand All @@ -232,21 +180,6 @@ private function richRenderStart()
(int) $this->functionLike->areReturnTypesNullCompatible()
)
);

$this->codePrinter->output('#else');

$this->codePrinter->output(
sprintf(
'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(%s, %d, %d, %s, NULL, %d)',
$this->name,
(int) $this->returnByRef,
$this->functionLike->getNumberOfRequiredParameters(),
$this->getReturnType(),
(int) $this->functionLike->areReturnTypesNullCompatible()
)
);

$this->codePrinter->output('#endif');
}

private function renderEnd()
Expand Down Expand Up @@ -299,7 +232,6 @@ private function renderEnd()

case '1:bool':
case '1:boolean':
$this->codePrinter->output('#if PHP_VERSION_ID >= 70200');
$this->codePrinter->output(
sprintf(
"\tZEND_ARG_TYPE_INFO(%d, %s, %s, %d)",
Expand All @@ -309,18 +241,12 @@ private function renderEnd()
(int) $this->allowNull($parameter)
)
);
$this->codePrinter->output('#else');
$this->codePrinter->output(
sprintf("\tZEND_ARG_INFO(%d, %s)", $this->passByReference($parameter), $parameter['name'])
);
$this->codePrinter->output('#endif');
break;
case '1:uchar':
case '1:int':
case '1:uint':
case '1:long':
case '1:ulong':
$this->codePrinter->output('#if PHP_VERSION_ID >= 70200');
$this->codePrinter->output(
sprintf(
"\tZEND_ARG_TYPE_INFO(%d, %s, IS_LONG, %d)",
Expand All @@ -329,14 +255,8 @@ private function renderEnd()
(int) $this->allowNull($parameter)
)
);
$this->codePrinter->output('#else');
$this->codePrinter->output(
sprintf("\tZEND_ARG_INFO(%d, %s)", $this->passByReference($parameter), $parameter['name'])
);
$this->codePrinter->output('#endif');
break;
case '1:double':
$this->codePrinter->output('#if PHP_VERSION_ID >= 70200');
$this->codePrinter->output(
sprintf(
"\tZEND_ARG_TYPE_INFO(%d, %s, IS_DOUBLE, %d)",
Expand All @@ -345,15 +265,9 @@ private function renderEnd()
(int) $this->allowNull($parameter)
)
);
$this->codePrinter->output('#else');
$this->codePrinter->output(
sprintf("\tZEND_ARG_INFO(%d, %s)", $this->passByReference($parameter), $parameter['name'])
);
$this->codePrinter->output('#endif');
break;
case '1:char':
case '1:string':
$this->codePrinter->output('#if PHP_VERSION_ID >= 70200');
$this->codePrinter->output(
sprintf(
"\tZEND_ARG_TYPE_INFO(%d, %s, IS_STRING, %d)",
Expand All @@ -362,11 +276,6 @@ private function renderEnd()
(int) $this->allowNull($parameter)
)
);
$this->codePrinter->output('#else');
$this->codePrinter->output(
sprintf("\tZEND_ARG_INFO(%d, %s)", $this->passByReference($parameter), $parameter['name'])
);
$this->codePrinter->output('#endif');
break;
default:
$this->codePrinter->output(
Expand Down
75 changes: 69 additions & 6 deletions Library/ClassDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,6 @@ public function compile(CompilationContext $compilationContext)
$codePrinter->outputBlankLine();
} else {
$codePrinter->output('ZEPHIR_DOC_METHOD('.$this->getCNamespace().'_'.$this->getName().', '.$method->getName().');');
$codePrinter->outputBlankLine();
}
}

Expand Down Expand Up @@ -1439,16 +1438,68 @@ public function getClassEntryByClassName($className, CompilationContext $compila
$this->compiler = $compilationContext->compiler;

switch (strtolower($className)) {
/*
* Zend classes
/**
* Zend exceptions
*/
case 'throwable':
$classEntry = 'zend_ce_throwable';
break;

case 'exception':
$classEntry = 'zend_exception_get_default()';
$classEntry = 'zend_ce_exception';
break;

case 'errorexception':
$classEntry = 'zend_ce_error_exception';
break;

case 'error':
$classEntry = 'zend_ce_error';
break;

case 'compileerror':
$classEntry = 'zend_ce_compile_error';
break;

case 'parseerror':
$classEntry = 'zend_ce_parse_error';
break;

case 'typeerror':
$classEntry = 'zend_ce_type_error';
break;

case 'argumentcounterror':
$classEntry = 'zend_ce_argument_count_error';
break;

case 'valueerror':
$classEntry = 'zend_ce_value_error';
break;

case 'arithmeticerror':
$classEntry = 'zend_ce_arithmetic_error';
break;

case 'divisionbyzeroerror':
$classEntry = 'zend_ce_division_by_zero_error';
break;

case 'unhandledmatcherror':
$classEntry = 'zend_ce_unhandled_match_error';
break;

/*
* Zend interfaces (Zend/zend_interfaces.h)
*/
case 'traversable':
$classEntry = 'zend_ce_traversable';
break;

case 'aggregate':
$classEntry = 'zend_ce_aggregate';
break;

case 'iterator':
$classEntry = 'zend_ce_iterator';
break;
Expand All @@ -1461,8 +1512,12 @@ public function getClassEntryByClassName($className, CompilationContext $compila
$classEntry = 'zend_ce_serializable';
break;

case 'iteratoraggregate':
$classEntry = 'zend_ce_aggregate';
case 'countable':
$classEntry = 'zend_ce_countable';
break;

case 'stringable':
$classEntry = 'zend_ce_stringable';
break;

/*
Expand Down Expand Up @@ -1755,6 +1810,14 @@ public function getClassEntryByClassName($className, CompilationContext $compila
$classEntry = 'php_date_get_timezone_ce()';
break;

/**
* PHP Ext session
*/
case 'sessionhandlerinterface':
$compilationContext->headersManager->add('ext/session/php_session');
$classEntry = 'php_session_iface_entry';
break;

// Reflection
/*case 'reflector':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
Expand Down
Loading

0 comments on commit e3648d2

Please sign in to comment.