-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved node compilation in CompileNodeToValue (compile solution) #95
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ab1bac3
Factor out into private methods
asgrim 507a02a
Added some binary operations
asgrim 1c6291f
Prevent exception from bubbling up if we already know defaultValue is…
asgrim 267ddaf
Implemented many binary operators in compilation
asgrim ac4a41e
Reflector is now a required parameter for CompileNodeToValue
asgrim 112caf5
Added testcase for class constant resolution
asgrim b96aaed
Added CompilerContext which enables resolution of self::FOOCONST
asgrim 47de68e
Added a few missing tests
asgrim ac538f1
Also support use of static:: and self:: (but resolves to the same class)
asgrim 25b7555
Test for static:: syntax
asgrim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,65 @@ | ||
<?php | ||
|
||
namespace BetterReflection\NodeCompiler; | ||
|
||
use BetterReflection\Reflection\ReflectionClass; | ||
use BetterReflection\Reflector\Reflector; | ||
|
||
class CompilerContext | ||
{ | ||
/** | ||
* @var Reflector | ||
*/ | ||
private $reflector; | ||
|
||
/** | ||
* @var ReflectionClass|null | ||
*/ | ||
private $self; | ||
|
||
/** | ||
* @param Reflector $reflector | ||
* @param ReflectionClass|null $self | ||
*/ | ||
public function __construct(Reflector $reflector, ReflectionClass $self = null) | ||
{ | ||
$this->reflector = $reflector; | ||
$this->self = $self; | ||
} | ||
|
||
/** | ||
* Does the current context have a "self" or "this" | ||
* | ||
* (e.g. if the context is a function, then no, there will be no self) | ||
* | ||
* @return bool | ||
*/ | ||
public function hasSelf() | ||
{ | ||
return null !== $this->self; | ||
} | ||
|
||
/** | ||
* Get the | ||
* | ||
* @return ReflectionClass|null | ||
*/ | ||
public function getSelf() | ||
{ | ||
if (!$this->hasSelf()) { | ||
throw new \RuntimeException('The current context does not have a class for self'); | ||
} | ||
|
||
return $this->self; | ||
} | ||
|
||
/** | ||
* Get the reflector | ||
* | ||
* @return Reflector | ||
*/ | ||
public function getReflector() | ||
{ | ||
return $this->reflector; | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May want to at least try casting the constant expression to string in here, or else there may be rage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UnableToCompileNode::fromConstFetch($constNode)
maybe?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously it was just returning a string with the const name, (e.g.
FOO
would compile to"FOO"
), but surely this could cause undesired behaviour?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could indeed cause undesired behavior :-(