Make the resolve type of a name a normal subnode (type)

This commit is contained in:
nikic 2011-08-04 13:59:56 +02:00
parent 9c53838b1f
commit 664be2871a
4 changed files with 14 additions and 19 deletions

View File

@ -113,7 +113,7 @@ top_statement_list:
;
namespace_name:
namespace_name_sub { $$ = Name[parts: $1]; }
namespace_name_sub { $$ = Name[parts: $1, type: Name::NORMAL]; }
;
namespace_name_sub:
@ -570,8 +570,8 @@ class_name:
name:
namespace_name { $$ = $1; }
| T_NAMESPACE T_NS_SEPARATOR namespace_name { $3->setResolveType(Name::RELATIVE); $$ = $3; }
| T_NS_SEPARATOR namespace_name { $2->setResolveType(Name::FULLY_QUALIFIED); $$ = $2; }
| T_NAMESPACE T_NS_SEPARATOR namespace_name { $3->type = Name::RELATIVE; $$ = $3; }
| T_NS_SEPARATOR namespace_name { $2->type = Name::FULLY_QUALIFIED; $$ = $2; }
;
class_name_reference:

View File

@ -2,6 +2,7 @@
/**
* @property array $parts Parts of the name
* @property int $type Resolve type (self::NORMAL, self::FULLY_QUALIFIED or self::RELATIVE)
*/
class PHPParser_Node_Name extends PHPParser_NodeAbstract
{
@ -9,12 +10,6 @@ class PHPParser_Node_Name extends PHPParser_NodeAbstract
const FULLY_QUALIFIED = 1;
const RELATIVE = 2;
protected $resolveType = self::NORMAL;
public function setResolveType($type) {
$this->resolveType = $type;
}
/**
* Gets the first part of the name, i.e. everything before the first namespace separator.
*
@ -39,7 +34,7 @@ class PHPParser_Node_Name extends PHPParser_NodeAbstract
* @return bool Whether the name is unqualified
*/
public function isUnqualified() {
return self::NORMAL == $this->resolveType && 1 == count($this->parts);
return self::NORMAL == $this->type && 1 == count($this->parts);
}
/**
@ -48,7 +43,7 @@ class PHPParser_Node_Name extends PHPParser_NodeAbstract
* @return bool Whether the name is qualified
*/
public function isQualified() {
return self::NORMAL == $this->resolveType && 1 < count($this->parts);
return self::NORMAL == $this->type && 1 < count($this->parts);
}
/**
@ -57,7 +52,7 @@ class PHPParser_Node_Name extends PHPParser_NodeAbstract
* @return bool Whether the name is fully qualified
*/
public function isFullyQualified() {
return self::FULLY_QUALIFIED == $this->resolveType;
return self::FULLY_QUALIFIED == $this->type;
}
/**
@ -66,7 +61,7 @@ class PHPParser_Node_Name extends PHPParser_NodeAbstract
* @return bool Whether the name is fully qualified
*/
public function isRelative() {
return self::RELATIVE == $this->resolveType;
return self::RELATIVE == $this->type;
}
/**

View File

@ -1016,7 +1016,7 @@ class PHPParser_Parser
}
private function yyn4($line, $docComment) {
$this->yyval = new PHPParser_Node_Name(array('parts' => $this->yyastk[$this->yysp-(1-1)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Name(array('parts' => $this->yyastk[$this->yysp-(1-1)], 'type' => PHPParser_Node_Name::NORMAL), $line, $docComment);
}
private function yyn5($line, $docComment) {
@ -1998,11 +1998,11 @@ class PHPParser_Parser
}
private function yyn246($line, $docComment) {
$this->yyastk[$this->yysp-(3-3)]->setResolveType(PHPParser_Node_Name::RELATIVE); $this->yyval = $this->yyastk[$this->yysp-(3-3)];
$this->yyastk[$this->yysp-(3-3)]->type = PHPParser_Node_Name::RELATIVE; $this->yyval = $this->yyastk[$this->yysp-(3-3)];
}
private function yyn247($line, $docComment) {
$this->yyastk[$this->yysp-(2-2)]->setResolveType(PHPParser_Node_Name::FULLY_QUALIFIED); $this->yyval = $this->yyastk[$this->yysp-(2-2)];
$this->yyastk[$this->yysp-(2-2)]->type = PHPParser_Node_Name::FULLY_QUALIFIED; $this->yyval = $this->yyastk[$this->yysp-(2-2)];
}
private function yyn248($line, $docComment) {

View File

@ -1415,7 +1415,7 @@ class PHPParser_ParserDebug
}
private function yyn4($line, $docComment) {
$this->yyval = new PHPParser_Node_Name(array('parts' => $this->yyastk[$this->yysp-(1-1)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Name(array('parts' => $this->yyastk[$this->yysp-(1-1)], 'type' => PHPParser_Node_Name::NORMAL), $line, $docComment);
}
private function yyn5($line, $docComment) {
@ -2397,11 +2397,11 @@ class PHPParser_ParserDebug
}
private function yyn246($line, $docComment) {
$this->yyastk[$this->yysp-(3-3)]->setResolveType(PHPParser_Node_Name::RELATIVE); $this->yyval = $this->yyastk[$this->yysp-(3-3)];
$this->yyastk[$this->yysp-(3-3)]->type = PHPParser_Node_Name::RELATIVE; $this->yyval = $this->yyastk[$this->yysp-(3-3)];
}
private function yyn247($line, $docComment) {
$this->yyastk[$this->yysp-(2-2)]->setResolveType(PHPParser_Node_Name::FULLY_QUALIFIED); $this->yyval = $this->yyastk[$this->yysp-(2-2)];
$this->yyastk[$this->yysp-(2-2)]->type = PHPParser_Node_Name::FULLY_QUALIFIED; $this->yyval = $this->yyastk[$this->yysp-(2-2)];
}
private function yyn248($line, $docComment) {