Skip to content

Commit

Permalink
Removed no longer needed code
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay committed Oct 22, 2018
1 parent de2e570 commit 1c878c3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 160 deletions.
2 changes: 2 additions & 0 deletions Library/ArgInfoDefinition.php
Expand Up @@ -37,6 +37,7 @@ class ArgInfoDefinition
/** @var string */
private $booleanDefinition = '_IS_BOOL';

/** @var bool */
private $rightFormat = true;

public function __construct(
Expand All @@ -52,6 +53,7 @@ public function __construct(

$this->name = $name;
$this->parameters = $this->method->getParameters();

$this->returnByRef = $returnByRef;
}

Expand Down
3 changes: 1 addition & 2 deletions Library/ClassDefinition.php
Expand Up @@ -1247,8 +1247,7 @@ public function compile(CompilationContext $compilationContext)
$method->getArgInfoName($this),
$method,
$codePrinter,
$compilationContext,
false // todo: always?
$compilationContext
);

$argInfo->setBooleanDefinition($this->compiler->backend->isZE3() ? '_IS_BOOL' : 'IS_BOOL');
Expand Down
168 changes: 10 additions & 158 deletions Library/Compiler.php
Expand Up @@ -2094,171 +2094,23 @@ public function generateFunctionInformation()
* Specifying Argument Information
*/
foreach ($this->functionDefinitions as $func) {
$argInfo = new ArgInfoDefinition(
$func->getArgInfoName(),
$func,
$headerPrinter,
$func->getCallGathererPass()->getCompilationContext()
);

$funcName = $func->getInternalName();
$argInfoName = $func->getArgInfoName();

$headerPrinter->output('PHP_FUNCTION(' . $funcName . ');');
$parameters = $func->getParameters();

if ($this->backend->isZE3() && $func->isReturnTypesHintDetermined()) {
if (array_key_exists('object', $func->getReturnTypes())) {
$class = 'NULL';

if (count($func->getReturnClassTypes()) == 1) {
$compilationContext = $func->getCallGathererPass()->getCompilationContext();
$class = Utils::escapeClassName(
$compilationContext->getFullName(key($func->getReturnClassTypes()))
);
}
$argInfo->setBooleanDefinition($this->backend->isZE3() ? '_IS_BOOL' : 'IS_BOOL');
$argInfo->setRightFormat($this->backend->isZE3());

$headerPrinter->output('#ifdef ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX');
$headerPrinter->output(
'ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(' . $argInfoName . ', 0, ' .
$func->getNumberOfRequiredParameters() . ', ' .
$class . ', ' . ($func->areReturnTypesNullCompatible() ? 1 : 0) . ')'
);
$headerPrinter->output('#else');
$headerPrinter->output(
'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(' . $argInfoName . ', 0, ' .
$func->getNumberOfRequiredParameters() . ', ' .
'NULL, "' . $class . '", ' . ($func->areReturnTypesNullCompatible() ? 1 : 0) . ')'
);
$headerPrinter->output('#endif');
} else {
$type = 'IS_NULL';
$argInfo->render();

if ($func->areReturnTypesIntCompatible()) {
$type = 'IS_LONG';
}
if ($func->areReturnTypesDoubleCompatible()) {
$type = 'IS_DOUBLE';
}
if ($func->areReturnTypesBoolCompatible()) {
$type = '_IS_BOOL';
}
if ($func->areReturnTypesStringCompatible()) {
$type = 'IS_STRING';
}

$headerPrinter->output('#ifdef ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX');
$headerPrinter->output(
'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(' . $argInfoName . ', 0, ' .
$func->getNumberOfRequiredParameters() . ', ' .
$type . ', ' . ($func->areReturnTypesNullCompatible() ? 1 : 0) . ')'
);
$headerPrinter->output('#else');
$headerPrinter->output(
'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(' . $argInfoName . ', 0, ' .
$func->getNumberOfRequiredParameters() . ', ' .
$type . ', NULL, ' . ($func->areReturnTypesNullCompatible() ? 1 : 0) . ')'
);
$headerPrinter->output('#endif');
}

if ($parameters == null || !count($parameters->getParameters())) {
$headerPrinter->output('ZEND_END_ARG_INFO()');
$headerPrinter->outputBlankLine();
}
} elseif ($parameters != null && count($parameters->getParameters())) {
$headerPrinter->output(
'ZEND_BEGIN_ARG_INFO_EX(' . $argInfoName . ', 0, 0, ' .
$func->getNumberOfRequiredParameters() . ')'
);
}

if ($parameters != null && count($parameters->getParameters())) {
foreach ($parameters->getParameters() as $parameter) {
switch (($this->backend->isZE3() ? '3:' : '2:') . $parameter['data-type']) {
case '2:array':
case '3:array':
$headerPrinter->output(
"\t" . 'ZEND_ARG_ARRAY_INFO(' .
(isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' .
$parameter['name'] . ', ' .
(isset($parameter['default']) ? 1 : 0) . ')'
);
break;

case '2:variable':
case '3:variable':
if (isset($parameter['cast'])) {
switch ($parameter['cast']['type']) {
case 'variable':
$compilationContext = $func->getCallGathererPass()->getCompilationContext();
$value = $parameter['cast']['value'];

$headerPrinter->output(
"\t" . 'ZEND_ARG_OBJ_INFO(' .
(isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' .
$parameter['name'] . ', ' .
Utils::escapeClassName($compilationContext->getFullName($value)) . ', ' .
(isset($parameter['default']) ? 1 : 0) . ')'
);
break;

default:
throw new Exception('Unexpected exception');
}
} else {
$headerPrinter->output("\t" . 'ZEND_ARG_INFO(' .
(isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' .
$parameter['name'] . ')');
}
break;

case '3:bool':
case '3:boolean':
$headerPrinter->output(
"\t" . 'ZEND_ARG_TYPE_INFO(' .
(isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' .
$parameter['name'] . ', ' .
($this->backend->isZE3() ? '_IS_BOOL' : 'IS_BOOL') . ', ' .
(isset($parameter['default']) ? 1 : 0) . ')'
);
break;

case '3:uchar':
case '3:int':
case '3:uint':
case '3:long':
case '3:ulong':
$headerPrinter->output(
"\t" . 'ZEND_ARG_TYPE_INFO(' .
(isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' .
$parameter['name'] . ', IS_LONG, ' .
(isset($parameter['default']) ? 1 : 0) . ')'
);
break;

case '3:double':
$headerPrinter->output(
"\t" . 'ZEND_ARG_TYPE_INFO(' .
(isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' .
$parameter['name'] . ', IS_DOUBLE, ' .
(isset($parameter['default']) ? 1 : 0) . ')'
);
break;

case '3:char':
case '3:string':
$headerPrinter->output(
"\t" . 'ZEND_ARG_TYPE_INFO(' .
(isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' .
$parameter['name'] . ', IS_STRING, ' .
(isset($parameter['default']) ? 1 : 0) . ')'
);
break;

default:
$headerPrinter->output("\t" . 'ZEND_ARG_INFO(' .
(isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' .
$parameter['name'] . ')');
break;
}
}
$headerPrinter->output('ZEND_END_ARG_INFO()');
$headerPrinter->outputBlankLine();
}
/** Generate FE's */
$paramData = 'NULL';
if (($this->backend->isZE3() && $func->isReturnTypesHintDetermined()) || $func->hasParameters()) {
Expand Down
6 changes: 6 additions & 0 deletions unit-tests/fixtures/typehints/.editorconfig
@@ -0,0 +1,6 @@
# EditorConfig is awesome: http://EditorConfig.org

root = false

[*.{c,h}]
trim_trailing_whitespace = false

0 comments on commit 1c878c3

Please sign in to comment.