Page MenuHomePhabricator

D14504.diff
No OneTemporary

D14504.diff

diff --git a/src/parser/aast/api/AASTNode.php b/src/parser/aast/api/AASTNode.php
--- a/src/parser/aast/api/AASTNode.php
+++ b/src/parser/aast/api/AASTNode.php
@@ -2,19 +2,17 @@
abstract class AASTNode extends Phobject {
- protected $id;
+ private $id;
protected $l;
protected $r;
- protected $typeID;
- protected $typeName;
+ private $typeID;
+ private $typeName;
protected $tree;
- // These are public only as a microoptimization to make tree construction
- // faster; do not access them directly.
- public $children = array();
- public $parentNode;
- public $previousSibling = null;
- public $nextSibling = null;
+ private $children = array();
+ private $parentNode = null;
+ private $previousSibling = null;
+ private $nextSibling = null;
private $selectCache;
@@ -43,14 +41,29 @@
return $this->parentNode;
}
+ final public function setParentNode(AASTNode $node = null) {
+ $this->parentNode = $node;
+ return $this;
+ }
+
final public function getPreviousSibling() {
return $this->previousSibling;
}
+ final public function setPreviousSibling(AASTNode $node = null) {
+ $this->previousSibling = $node;
+ return $this;
+ }
+
final public function getNextSibling() {
return $this->nextSibling;
}
+ final public function setNextSibling(AASTNode $node = null) {
+ $this->nextSibling = $node;
+ return $this;
+ }
+
final public function getID() {
return $this->id;
}
@@ -75,6 +88,13 @@
return $this->children;
}
+ final public function setChildren(array $children) {
+ // We don't call `assert_instances_of($children, 'AASTNode')` because doing
+ // so would incur a significant performance penalty.
+ $this->children = $children;
+ return $this;
+ }
+
public function getChildrenOfType($type) {
$nodes = array();
diff --git a/src/parser/aast/api/AASTTree.php b/src/parser/aast/api/AASTTree.php
--- a/src/parser/aast/api/AASTTree.php
+++ b/src/parser/aast/api/AASTTree.php
@@ -144,21 +144,21 @@
$previous_child = null;
foreach ($children as $ii => $child) {
- $child->parentNode = $this->tree[$node_id];
- $child->previousSibling = $previous_child;
+ $child->setParentNode($this->tree[$node_id]);
+ $child->setPreviousSibling($previous_child);
if ($previous_child) {
- $previous_child->nextSibling = $child;
+ $previous_child->setNextSibling($child);
}
$previous_child = $child;
}
if ($previous_child) {
- $previous_child->nextSibling = $child;
+ $previous_child->setNextSibling($child);
}
- $this->tree[$node_id]->children = $children;
+ $this->tree[$node_id]->setChildren($children);
}
}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 9, 1:43 AM (5 d, 14 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6731511
Default Alt Text
D14504.diff (2 KB)

Event Timeline