-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from LioTree/master
support trait use
- Loading branch information
Showing
8 changed files
with
374 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of PHP-CFG, a Control flow graph implementation for PHP | ||
* | ||
* @copyright 2015 Anthony Ferrara. All rights reserved | ||
* @license MIT See LICENSE at the root of the project for more info | ||
*/ | ||
|
||
namespace PHPCfg\Op\Stmt; | ||
|
||
use PHPCfg\Op\Stmt; | ||
use PhpCfg\Operand; | ||
use PHPCfg\TraitUseAdaptation; | ||
|
||
class TraitUse extends Stmt | ||
{ | ||
/** | ||
* @var Operand[] | ||
*/ | ||
public array $traits; | ||
|
||
/** | ||
* @var TraitUseAdaptation[] | ||
*/ | ||
public array $adaptations; | ||
|
||
public function __construct(array $traits,array $adaptations, array $attributes = []) | ||
{ | ||
parent::__construct($attributes); | ||
$this->traits = $traits; | ||
$this->adaptations = $adaptations; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
/** | ||
* This file is part of PHP-CFG, a Control flow graph implementation for PHP | ||
* | ||
* @copyright 2015 Anthony Ferrara. All rights reserved | ||
* @license MIT See LICENSE at the root of the project for more info | ||
*/ | ||
|
||
namespace PHPCfg\Op; | ||
|
||
use PHPCfg\Op; | ||
use PHPCfg\Operand; | ||
|
||
abstract class TraitUseAdaptation extends Op | ||
{ | ||
public ?Operand $trait; | ||
|
||
public Operand $method; | ||
|
||
public function __construct(?Operand $trait,Operand $method,array $attributes = []) | ||
{ | ||
parent::__construct($attributes); | ||
$this->trait = $trait; | ||
$this->method = $method; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of PHP-CFG, a Control flow graph implementation for PHP | ||
* | ||
* @copyright 2015 Anthony Ferrara. All rights reserved | ||
* @license MIT See LICENSE at the root of the project for more info | ||
*/ | ||
|
||
namespace PHPCfg\Op\TraitUseAdaptation; | ||
|
||
use PhpParser\Node; | ||
use PHPCfg\Operand; | ||
use PHPCfg\Op\TraitUseAdaptation; | ||
|
||
class Alias extends TraitUseAdaptation | ||
{ | ||
public ?Operand $newName; | ||
|
||
public ?int $newModifier; | ||
|
||
public function __construct(?Operand $trait,Operand $method,?Operand $newName,?int $newModifier,array $attributes = []) | ||
{ | ||
parent::__construct($trait,$method,$attributes); | ||
$this->newName = $newName; | ||
$this->newModifier = $newModifier; | ||
} | ||
|
||
public function isPublic() : bool | ||
{ | ||
return (bool) ($this->newModifier & Node\Stmt\Class_::MODIFIER_PUBLIC); | ||
} | ||
|
||
public function isProtected() : bool | ||
{ | ||
return (bool) ($this->newModifier & Node\Stmt\Class_::MODIFIER_PROTECTED); | ||
} | ||
|
||
public function isPrivate() : bool | ||
{ | ||
return (bool) ($this->newModifier & Node\Stmt\Class_::MODIFIER_PRIVATE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of PHP-CFG, a Control flow graph implementation for PHP | ||
* | ||
* @copyright 2015 Anthony Ferrara. All rights reserved | ||
* @license MIT See LICENSE at the root of the project for more info | ||
*/ | ||
|
||
namespace PHPCfg\Op\TraitUseAdaptation; | ||
|
||
use PHPCfg\Operand; | ||
use PHPCfg\Op\TraitUseAdaptation; | ||
|
||
class Precedence extends TraitUseAdaptation | ||
{ | ||
public array $insteadof; | ||
|
||
public function __construct(?Operand $trait,Operand $method,array $insteadof,array $attributes = []) | ||
{ | ||
parent::__construct($trait,$method,$attributes); | ||
$this->insteadof = $insteadof; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
trait A { | ||
public function smallTalk() { | ||
echo 'a'; | ||
} | ||
public function bigTalk() { | ||
echo 'A'; | ||
} | ||
} | ||
|
||
trait B { | ||
public function smallTalk() { | ||
echo 'b'; | ||
} | ||
public function bigTalk() { | ||
echo 'B'; | ||
} | ||
} | ||
|
||
class Talker { | ||
use A, B { | ||
B::smallTalk insteadof A; | ||
A::bigTalk insteadof B; | ||
} | ||
} | ||
|
||
class Aliased_Talker { | ||
use A, B { | ||
B::smallTalk insteadof A; | ||
A::bigTalk insteadof B; | ||
B::bigTalk as private talk; | ||
} | ||
} | ||
----- | ||
Block#1 | ||
Stmt_Trait | ||
name: LITERAL('A') | ||
stmts: Block#2 | ||
Stmt_Trait | ||
name: LITERAL('B') | ||
stmts: Block#3 | ||
Stmt_Class | ||
name: LITERAL('Talker') | ||
stmts: Block#4 | ||
Stmt_Class | ||
name: LITERAL('Aliased_Talker') | ||
stmts: Block#5 | ||
Terminal_Return | ||
|
||
Block#2 | ||
Stmt_ClassMethod<'smallTalk'> | ||
flags: public | ||
Stmt_ClassMethod<'bigTalk'> | ||
flags: public | ||
|
||
Block#3 | ||
Stmt_ClassMethod<'smallTalk'> | ||
flags: public | ||
Stmt_ClassMethod<'bigTalk'> | ||
flags: public | ||
|
||
Block#4 | ||
Stmt_TraitUse | ||
use[0]: LITERAL('\\A') | ||
use[1]: LITERAL('\\B') | ||
adaptation[0]: Insteadof | ||
trait:LITERAL('\\B') | ||
method:LITERAL('smallTalk') | ||
insteadof[0]: LITERAL('\\A') | ||
adaptation[1]: Insteadof | ||
trait:LITERAL('\\A') | ||
method:LITERAL('bigTalk') | ||
insteadof[0]: LITERAL('\\B') | ||
|
||
Block#5 | ||
Stmt_TraitUse | ||
use[0]: LITERAL('\\A') | ||
use[1]: LITERAL('\\B') | ||
adaptation[0]: Insteadof | ||
trait:LITERAL('\\B') | ||
method:LITERAL('smallTalk') | ||
insteadof[0]: LITERAL('\\A') | ||
adaptation[1]: Insteadof | ||
trait:LITERAL('\\A') | ||
method:LITERAL('bigTalk') | ||
insteadof[0]: LITERAL('\\B') | ||
adaptation[2]: Alias | ||
trait:LITERAL('\\B') | ||
method:LITERAL('bigTalk') | ||
newName:LITERAL('talk') | ||
newModifier:private | ||
|
||
Function 'A::smallTalk': mixed | ||
Block#1 | ||
Terminal_Echo | ||
expr: LITERAL('a') | ||
Terminal_Return | ||
|
||
Function 'A::bigTalk': mixed | ||
Block#1 | ||
Terminal_Echo | ||
expr: LITERAL('A') | ||
Terminal_Return | ||
|
||
Function 'B::smallTalk': mixed | ||
Block#1 | ||
Terminal_Echo | ||
expr: LITERAL('b') | ||
Terminal_Return | ||
|
||
Function 'B::bigTalk': mixed | ||
Block#1 | ||
Terminal_Echo | ||
expr: LITERAL('B') | ||
Terminal_Return |
Oops, something went wrong.