Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/ArcanistBaseXHPASTLinter.php
<?php | <?php | ||||
/** | /** | ||||
* @task sharing Sharing Parse Trees | * @task sharing Sharing Parse Trees | ||||
*/ | */ | ||||
abstract class ArcanistBaseXHPASTLinter extends ArcanistFutureLinter { | abstract class ArcanistBaseXHPASTLinter extends ArcanistFutureLinter { | ||||
private $futures = array(); | private $futures = array(); | ||||
private $trees = array(); | private $trees = array(); | ||||
private $exceptions = array(); | private $exceptions = array(); | ||||
private $refcount = array(); | |||||
final public function getCacheVersion() { | final public function getCacheVersion() { | ||||
$parts = array(); | $parts = array(); | ||||
$parts[] = $this->getVersion(); | $parts[] = $this->getVersion(); | ||||
$version = PhutilXHPASTBinary::getVersion(); | $version = PhutilXHPASTBinary::getVersion(); | ||||
if ($version) { | if ($version) { | ||||
Show All 28 Lines | return $this->raiseLintAtOffset( | ||||
$node->getConcreteString(), | $node->getConcreteString(), | ||||
$replace); | $replace); | ||||
} | } | ||||
final protected function buildFutures(array $paths) { | final protected function buildFutures(array $paths) { | ||||
return $this->getXHPASTLinter()->buildSharedFutures($paths); | return $this->getXHPASTLinter()->buildSharedFutures($paths); | ||||
} | } | ||||
protected function didResolveLinterFutures(array $futures) { | |||||
$this->getXHPASTLinter()->releaseSharedFutures(array_keys($futures)); | |||||
} | |||||
/* -( Sharing Parse Trees )------------------------------------------------ */ | /* -( Sharing Parse Trees )------------------------------------------------ */ | ||||
/** | /** | ||||
* Get the linter object which is responsible for building parse trees. | * Get the linter object which is responsible for building parse trees. | ||||
* | * | ||||
* When the engine specifies that several XHPAST linters should execute, | * When the engine specifies that several XHPAST linters should execute, | ||||
* we designate one of them as the one which will actually build parse trees. | * we designate one of them as the one which will actually build parse trees. | ||||
Show All 37 Lines | /* -( Sharing Parse Trees )------------------------------------------------ */ | ||||
* @return list<ExecFuture> Futures. | * @return list<ExecFuture> Futures. | ||||
* @task sharing | * @task sharing | ||||
*/ | */ | ||||
final protected function buildSharedFutures(array $paths) { | final protected function buildSharedFutures(array $paths) { | ||||
foreach ($paths as $path) { | foreach ($paths as $path) { | ||||
if (!isset($this->futures[$path])) { | if (!isset($this->futures[$path])) { | ||||
$this->futures[$path] = PhutilXHPASTBinary::getParserFuture( | $this->futures[$path] = PhutilXHPASTBinary::getParserFuture( | ||||
$this->getData($path)); | $this->getData($path)); | ||||
$this->refcount[$path] = 1; | |||||
} else { | |||||
$this->refcount[$path]++; | |||||
} | } | ||||
} | } | ||||
return array_select_keys($this->futures, $paths); | return array_select_keys($this->futures, $paths); | ||||
} | } | ||||
/** | |||||
* Release futures on this linter which are no longer in use elsewhere. | |||||
* | |||||
* @param list<string> Paths to release futures for. | |||||
* @return void | |||||
* @task sharing | |||||
*/ | |||||
final protected function releaseSharedFutures(array $paths) { | |||||
foreach ($paths as $path) { | |||||
if (empty($this->refcount[$path])) { | |||||
throw new Exception( | |||||
pht( | |||||
'Imbalanced calls to shared futures: each call to '. | |||||
'buildSharedFutures() for a path must be paired with a call to '. | |||||
'releaseSharedFutures().')); | |||||
} | |||||
$this->refcount[$path]--; | |||||
if (!$this->refcount[$path]) { | |||||
unset($this->refcount[$path]); | |||||
unset($this->futures[$path]); | |||||
unset($this->trees[$path]); | |||||
unset($this->exceptions[$path]); | |||||
} | |||||
} | |||||
} | |||||
/** | /** | ||||
* Get a path's tree from the responsible linter. | * Get a path's tree from the responsible linter. | ||||
* | * | ||||
* @param string Path to retrieve tree for. | * @param string Path to retrieve tree for. | ||||
* @return XHPASTTree|null Tree, or null if unparseable. | * @return XHPASTTree|null Tree, or null if unparseable. | ||||
* @task sharing | * @task sharing | ||||
*/ | */ | ||||
final protected function getXHPASTTreeForPath($path) { | final protected function getXHPASTTreeForPath($path) { | ||||
Show All 40 Lines |