Skip to content

Commit

Permalink
Fixes an issue with keywords as constant/method names
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Pichler committed Jan 11, 2017
1 parent 3367b7a commit 8f07ac7
Show file tree
Hide file tree
Showing 8 changed files with 582 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/main/php/PDepend/Source/Language/PHP/AbstractPHPParser.php
Expand Up @@ -3964,10 +3964,8 @@ protected function parseMemberPrimaryPrefix(ASTNode $node)
$tokenType = $this->tokenizer->peek();

switch ($tokenType) {
case Tokens::T_CALLABLE:
/* Fixme */
case Tokens::T_STRING:
$child = $this->parseIdentifier();
case ($this->isMethodName($tokenType)):
$child = $this->parseIdentifier($tokenType);
$child = $this->parseOptionalIndexExpression($child);

// TODO: Move this in a separate method
Expand Down Expand Up @@ -4869,12 +4867,13 @@ protected function parseCompoundExpression()
* Parses a static identifier expression, as it is used for method and
* function names.
*
* @param integer $tokenType
* @return \PDepend\Source\AST\ASTIdentifier
* @since 0.9.12
*/
protected function parseIdentifier()
protected function parseIdentifier($tokenType = Tokens::T_STRING)
{
$token = $this->consumeToken(Tokens::T_STRING);
$token = $this->consumeToken($tokenType);

$node = $this->builder->buildAstIdentifier($token->image);
$node->configureLinesAndColumns(
Expand Down
18 changes: 17 additions & 1 deletion src/main/php/PDepend/Source/Language/PHP/PHPParserVersion70.php
Expand Up @@ -142,7 +142,6 @@ protected function isConstantName($tokenType)
return parent::isConstantName($tokenType);
}


/**
* @param integer $tokenType
* @return bool
Expand All @@ -156,6 +155,23 @@ protected function isMethodName($tokenType)
return $this->isConstantName($tokenType);
}

/**
* @return \PDepend\Source\AST\ASTNode
*/
protected function parsePostfixIdentifier()
{
$tokenType = $this->tokenizer->peek();
switch (true) {
case ($this->isConstantName($tokenType)):
$node = $this->parseLiteral();
break;
default:
$node = parent::parsePostfixIdentifier();
break;
}
return $this->parseOptionalIndexExpression($node);
}

/**
* @param \PDepend\Source\AST\AbstractASTCallable $callable
* @return \PDepend\Source\AST\AbstractASTCallable
Expand Down
Expand Up @@ -495,11 +495,27 @@ public function testClassConstantNames()
$this->assertNotNull($this->parseCodeResourceForTest());
}

/**
* @return void
*/
public function testClassConstantNamesAccessed()
{
$this->assertNotNull($this->parseCodeResourceForTest());
}

/**
* @return void
*/
public function testClassMethodNames()
{
$this->assertNotNull($this->parseCodeResourceForTest());
}

/**
* @return void
*/
public function testClassMethodNamesInvoked()
{
$this->assertNotNull($this->parseCodeResourceForTest());
}
}
Expand Up @@ -499,6 +499,14 @@ public function testClassConstantNames()
$this->assertNotNull($this->parseCodeResourceForTest());
}

/**
* @return void
*/
public function testClassConstantNamesAccessed()
{
$this->assertNotNull($this->parseCodeResourceForTest());
}

/**
* @return void
*/
Expand All @@ -507,6 +515,14 @@ public function testClassMethodNames()
$this->assertNotNull($this->parseCodeResourceForTest());
}

/**
* @return void
*/
public function testClassMethodNamesInvoked()
{
$this->assertNotNull($this->parseCodeResourceForTest());
}

/**
* @param \PDepend\Source\Tokenizer\Tokenizer $tokenizer
* @param \PDepend\Source\Builder\Builder $builder
Expand Down
@@ -0,0 +1,132 @@
<?php
function foo($o) {
$o::callable;
// $o::class;
$o::trait;
$o::extends;
$o::implements;
$o::static;
$o::abstract;
$o::final;
$o::public;
$o::protected;
$o::private;
$o::const;
$o::enddeclare;
$o::endfor;
$o::endforeach;
$o::endif;
$o::endwhile;
$o::and;
$o::global;
$o::goto;
$o::instanceof;
$o::insteadof;
$o::interface;
$o::namespace;
$o::new;
$o::or;
$o::xor;
$o::try;
$o::use;
$o::var;
$o::exit;
$o::list;
$o::clone;
$o::include;
$o::include_once;
$o::throw;
$o::array;
$o::print;
$o::echo;
$o::require;
$o::require_once;
$o::return;
$o::else;
$o::elseif;
$o::default;
$o::break;
$o::continue;
$o::switch;
$o::yield;
$o::function;
$o::if;
$o::endswitch;
$o::finally;
$o::for;
$o::foreach;
$o::declare;
$o::case;
$o::do;
$o::while;
$o::as;
$o::catch;
$o::die;
$o::self;
$o::parent;

MyClass::callable;
// MyClass::class;
MyClass::trait;
MyClass::extends;
MyClass::implements;
MyClass::static;
MyClass::abstract;
MyClass::final;
MyClass::public;
MyClass::protected;
MyClass::private;
MyClass::const;
MyClass::enddeclare;
MyClass::endfor;
MyClass::endforeach;
MyClass::endif;
MyClass::endwhile;
MyClass::and;
MyClass::global;
MyClass::goto;
MyClass::instanceof;
MyClass::insteadof;
MyClass::interface;
MyClass::namespace;
MyClass::new;
MyClass::or;
MyClass::xor;
MyClass::try;
MyClass::use;
MyClass::var;
MyClass::exit;
MyClass::list;
MyClass::clone;
MyClass::include;
MyClass::include_once;
MyClass::throw;
MyClass::array;
MyClass::print;
MyClass::echo;
MyClass::require;
MyClass::require_once;
MyClass::return;
MyClass::else;
MyClass::elseif;
MyClass::default;
MyClass::break;
MyClass::continue;
MyClass::switch;
MyClass::yield;
MyClass::function;
MyClass::if;
MyClass::endswitch;
MyClass::finally;
MyClass::for;
MyClass::foreach;
MyClass::declare;
MyClass::case;
MyClass::do;
MyClass::while;
MyClass::as;
MyClass::catch;
MyClass::die;
MyClass::self;
MyClass::parent;
}
@@ -0,0 +1,132 @@
<?php
function foo($o) {
$o->callable();
$o->class();
$o->trait();
$o->extends();
$o->implements();
$o->static();
$o->abstract();
$o->final();
$o->public();
$o->protected();
$o->private();
$o->const();
$o->enddeclare();
$o->endfor();
$o->endforeach();
$o->endif();
$o->endwhile();
$o->and();
$o->global();
$o->goto();
$o->instanceof();
$o->insteadof();
$o->interface();
$o->namespace();
$o->new();
$o->or();
$o->xor();
$o->try();
$o->use();
$o->var();
$o->exit();
$o->list();
$o->clone();
$o->include();
$o->include_once();
$o->throw();
$o->array();
$o->print();
$o->echo();
$o->require();
$o->require_once();
$o->return();
$o->else();
$o->elseif();
$o->default();
$o->break();
$o->continue();
$o->switch();
$o->yield();
$o->function();
$o->if();
$o->endswitch();
$o->finally();
$o->for();
$o->foreach();
$o->declare();
$o->case();
$o->do();
$o->while();
$o->as();
$o->catch();
$o->die();
$o->self();
$o->parent();

MyClass::callable();
MyClass::class();
MyClass::trait();
MyClass::extends();
MyClass::implements();
MyClass::static();
MyClass::abstract();
MyClass::final();
MyClass::public();
MyClass::protected();
MyClass::private();
MyClass::const();
MyClass::enddeclare();
MyClass::endfor();
MyClass::endforeach();
MyClass::endif();
MyClass::endwhile();
MyClass::and();
MyClass::global();
MyClass::goto();
MyClass::instanceof();
MyClass::insteadof();
MyClass::interface();
MyClass::namespace();
MyClass::new();
MyClass::or();
MyClass::xor();
MyClass::try();
MyClass::use();
MyClass::var();
MyClass::exit();
MyClass::list();
MyClass::clone();
MyClass::include();
MyClass::include_once();
MyClass::throw();
MyClass::array();
MyClass::print();
MyClass::echo();
MyClass::require();
MyClass::require_once();
MyClass::return();
MyClass::else();
MyClass::elseif();
MyClass::default();
MyClass::break();
MyClass::continue();
MyClass::switch();
MyClass::yield();
MyClass::function();
MyClass::if();
MyClass::endswitch();
MyClass::finally();
MyClass::for();
MyClass::foreach();
MyClass::declare();
MyClass::case();
MyClass::do();
MyClass::while();
MyClass::as();
MyClass::catch();
MyClass::die();
MyClass::self();
MyClass::parent();
}

0 comments on commit 8f07ac7

Please sign in to comment.