Skip to content

Commit

Permalink
Merge pull request #2161 from zephir-lang/add-reflection-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNDRmac authored Mar 7, 2021
2 parents f79f50d + 5bd5677 commit 7cb8842
Show file tree
Hide file tree
Showing 19 changed files with 227 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ jobs:
CXXFLAGS="-O0 -ggdb -fprofile-arcs -ftest-coverage"
# Export variables in the subshell to not shadow global variables
( export LDFLAGS CFLAGS CXXFLAGS; zephir compile ) || false
( export LDFLAGS CFLAGS CXXFLAGS; zephir fullclean && zephir generate && cd ext/ && ./install ) || false
- name: Setup Problem Matchers for PHPUnit
run: echo ::add-matcher::${{ runner.tool_cache }}/phpunit.json
Expand Down
124 changes: 72 additions & 52 deletions Library/ClassDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -1447,10 +1447,80 @@ public function setAliasManager(AliasManager $aliasManager)
*
* @return string
*/
public function getClassEntryByClassName($className, CompilationContext $compilationContext, $check = true)
{
public function getClassEntryByClassName(
string $className,
CompilationContext $compilationContext,
bool $check = true
): string {
$this->compiler = $compilationContext->compiler;

/**
* Special treatment for Reflection in 8.0.
* Because in PHP 7.4 param arg info is lighter,
* but also incomplete.
*
* TODO: Leave for future, maybe PHP code devs will make "reflection" ext public...
*/
/*if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
switch (strtolower($className)) {
case 'reflector':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflector_ptr';
break;
case 'reflectionexception':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_exception_ptr';
break;
case 'reflection':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_ptr';
break;
case 'reflectionfunctionabstract':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_function_abstract_ptr';
break;
case 'reflectionfunction':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_function_ptr';
break;
case 'reflectionparameter':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_parameter_ptr';
break;
case 'reflectionclass':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_class_ptr';
break;
case 'reflectionobject':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_object_ptr';
break;
case 'reflectionmethod':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_method_ptr';
break;
case 'reflectionproperty':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_property_ptr';
break;
case 'reflectionextension':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_extension_ptr';
break;
case 'reflectionzendextension':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_zend_extension_ptr';
break;
default:
$classEntry = null;
break;
}
if ($classEntry !== null) {
return $classEntry;
}
}*/

switch (strtolower($className)) {
/**
* Zend exceptions
Expand Down Expand Up @@ -1832,56 +1902,6 @@ public function getClassEntryByClassName($className, CompilationContext $compila
$classEntry = 'php_session_iface_entry';
break;

// Reflection
case 'reflector':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflector_ptr';
break;
case 'reflectionexception':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_exception_ptr';
break;
case 'reflection':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_ptr';
break;
case 'reflectionfunctionabstract':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_function_abstract_ptr';
break;
case 'reflectionfunction':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_function_ptr';
break;
case 'reflectionparameter':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_parameter_ptr';
break;
case 'reflectionclass':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_class_ptr';
break;
case 'reflectionobject':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_object_ptr';
break;
case 'reflectionmethod':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_method_ptr';
break;
case 'reflectionproperty':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_property_ptr';
break;
case 'reflectionextension':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_extension_ptr';
break;
case 'reflectionzendextension':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_zend_extension_ptr';
break;

default:
if (!$check) {
throw new CompilerException('Unknown class entry for "'.$className.'"');
Expand Down
31 changes: 31 additions & 0 deletions Library/ClassMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,26 @@ class ClassMethod
*/
protected $callGathererPass;

/**
* All classes must be in lower case.
*
* @var array|string[]
*/
protected array $excludedClassEntries = [
'reflector',
'reflectionexception',
'reflection',
'reflectionfunctionabstract',
'reflectionfunction',
'reflectionparameter',
'reflectionclass',
'reflectionobject',
'reflectionmethod',
'reflectionproperty',
'reflectionextension',
'reflectionzendextension',
];

/**
* ClassMethod constructor.
*
Expand Down Expand Up @@ -2591,6 +2611,17 @@ private function detectClassNameEntry(string $className, CompilationContext $com
return null;
}

/**
* Excluded classes.
*
* Cases when we can't retrieve class entry.
* For example: php/ext/reflection, as there
* are no PHP_INSTALL_HEADERS.
*/
if (in_array(ltrim(strtolower($className), '\\'), $this->excludedClassEntries)) {
return null;
}

$isAlias = false;
$aliasManager = $this->classDefinition->getAliasManager();
if ($aliasManager->isAlias($className)) {
Expand Down
1 change: 1 addition & 0 deletions ext/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ if test "$PHP_STUB" = "yes"; then
stub/quantum.zep.c
stub/range.zep.c
stub/references.zep.c
stub/reflection.zep.c
stub/regexdna.zep.c
stub/requires.zep.c
stub/requires/external3.zep.c
Expand Down
2 changes: 1 addition & 1 deletion ext/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (PHP_STUB != "no") {
}

ADD_SOURCES(configure_module_dirname + "/stub/invokes", "abstractprotected.zep.c abstractinvoker.zep.c abstractinvokercomplex.zep.c invokeprotected.zep.c invokeprotectedcomplex.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub", "testinterface.zep.c scallparent.zep.c constantsparent.zep.c methodinterface.zep.c arithmetic.zep.c arrayaccessobj.zep.c arrayaccesstest.zep.c arrayiterator.zep.c arrayiteratortest.zep.c arrayobject.zep.c arraysearch.zep.c assign.zep.c bitwise.zep.c branchprediction.zep.c cast.zep.c cblock.zep.c chars.zep.c closures.zep.c compare.zep.c concat.zep.c constants.zep.c constantsinterface.zep.c constantsinterfacea.zep.c constantsinterfaceb.zep.c declaretest.zep.c diinterface.zep.c echoes.zep.c emptytest.zep.c evaltest.zep.c exception.zep.c exceptions.zep.c exists.zep.c exitdie.zep.c extendedinterface.zep.c factorial.zep.c fannkuch.zep.c fasta.zep.c fcall.zep.c fetchtest.zep.c fibonnaci.zep.c flow.zep.c fortytwo.zep.c functional.zep.c functionexists.zep.c functions.zep.c geometry.zep.c globals.zep.c instance.zep.c instanceoff.zep.c internalclasses.zep.c internalinterfaces.zep.c invoke.zep.c issettest.zep.c issue1404.zep.c issue1521.zep.c issues.zep.c json.zep.c logical.zep.c mcall.zep.c mcallchained.zep.c mcalldynamic.zep.c mcallinternal.zep.c methodabstract.zep.c methodargs.zep.c nativearray.zep.c oo.zep.c operator.zep.c pdostatement.zep.c pregmatch.zep.c quantum.zep.c range.zep.c references.zep.c regexdna.zep.c requires.zep.c resourcetest.zep.c returns.zep.c router.zep.c scall.zep.c scalldynamic.zep.c scallexternal.zep.c scalllateconstruct.zep.c scope.zep.c sort.zep.c spectralnorm.zep.c spropertyaccess.zep.c statements.zep.c strings.zep.c stubs.zep.c ternary.zep.c trytest.zep.c typeinstances.zep.c typeoff.zep.c unknownclass.zep.c unsettest.zep.c usetest.zep.c vars.zep.c 0__closure.zep.c 1__closure.zep.c 2__closure.zep.c 3__closure.zep.c 4__closure.zep.c 5__closure.zep.c 6__closure.zep.c 7__closure.zep.c 8__closure.zep.c 9__closure.zep.c 10__closure.zep.c 11__closure.zep.c 12__closure.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub", "testinterface.zep.c scallparent.zep.c constantsparent.zep.c methodinterface.zep.c arithmetic.zep.c arrayaccessobj.zep.c arrayaccesstest.zep.c arrayiterator.zep.c arrayiteratortest.zep.c arrayobject.zep.c arraysearch.zep.c assign.zep.c bitwise.zep.c branchprediction.zep.c cast.zep.c cblock.zep.c chars.zep.c closures.zep.c compare.zep.c concat.zep.c constants.zep.c constantsinterface.zep.c constantsinterfacea.zep.c constantsinterfaceb.zep.c declaretest.zep.c diinterface.zep.c echoes.zep.c emptytest.zep.c evaltest.zep.c exception.zep.c exceptions.zep.c exists.zep.c exitdie.zep.c extendedinterface.zep.c factorial.zep.c fannkuch.zep.c fasta.zep.c fcall.zep.c fetchtest.zep.c fibonnaci.zep.c flow.zep.c fortytwo.zep.c functional.zep.c functionexists.zep.c functions.zep.c geometry.zep.c globals.zep.c instance.zep.c instanceoff.zep.c internalclasses.zep.c internalinterfaces.zep.c invoke.zep.c issettest.zep.c issue1404.zep.c issue1521.zep.c issues.zep.c json.zep.c logical.zep.c mcall.zep.c mcallchained.zep.c mcalldynamic.zep.c mcallinternal.zep.c methodabstract.zep.c methodargs.zep.c nativearray.zep.c oo.zep.c operator.zep.c pdostatement.zep.c pregmatch.zep.c quantum.zep.c range.zep.c references.zep.c reflection.zep.c regexdna.zep.c requires.zep.c resourcetest.zep.c returns.zep.c router.zep.c scall.zep.c scalldynamic.zep.c scallexternal.zep.c scalllateconstruct.zep.c scope.zep.c sort.zep.c spectralnorm.zep.c spropertyaccess.zep.c statements.zep.c strings.zep.c stubs.zep.c ternary.zep.c trytest.zep.c typeinstances.zep.c typeoff.zep.c unknownclass.zep.c unsettest.zep.c usetest.zep.c vars.zep.c 0__closure.zep.c 1__closure.zep.c 2__closure.zep.c 3__closure.zep.c 4__closure.zep.c 5__closure.zep.c 6__closure.zep.c 7__closure.zep.c 8__closure.zep.c 9__closure.zep.c 10__closure.zep.c 11__closure.zep.c 12__closure.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/extend", "exception.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/extend/db", "exception.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/globals/session", "base.zep.c child.zep.c", "stub");
Expand Down
2 changes: 2 additions & 0 deletions ext/stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ zend_class_entry *stub_properties_staticpublicproperties_ce;
zend_class_entry *stub_quantum_ce;
zend_class_entry *stub_range_ce;
zend_class_entry *stub_references_ce;
zend_class_entry *stub_reflection_ce;
zend_class_entry *stub_regexdna_ce;
zend_class_entry *stub_requires_ce;
zend_class_entry *stub_requires_external3_ce;
Expand Down Expand Up @@ -406,6 +407,7 @@ static PHP_MINIT_FUNCTION(stub)
ZEPHIR_INIT(Stub_Quantum);
ZEPHIR_INIT(Stub_Range);
ZEPHIR_INIT(Stub_References);
ZEPHIR_INIT(Stub_Reflection);
ZEPHIR_INIT(Stub_RegexDNA);
ZEPHIR_INIT(Stub_Requires);
ZEPHIR_INIT(Stub_Requires_External3);
Expand Down
1 change: 1 addition & 0 deletions ext/stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
#include "stub/quantum.zep.h"
#include "stub/range.zep.h"
#include "stub/references.zep.h"
#include "stub/reflection.zep.h"
#include "stub/regexdna.zep.h"
#include "stub/requires.zep.h"
#include "stub/requires/external3.zep.h"
Expand Down
2 changes: 1 addition & 1 deletion ext/stub/requires.zep.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ext/stub/requires/external3.zep.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ext/stub/resourcetest.zep.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions ext/stub/router.zep.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions ext/stub/scall.zep.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ext/stub/scope.zep.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions ext/stub/sort.zep.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7cb8842

Please sign in to comment.