From 3de49842565dbd2710c2c8c7c2c456500a58f2df Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Wed, 5 Jun 2013 18:08:20 -0700 Subject: [PATCH] Find needed classes in catch, instanceof and newv() Test Plan: try {} catch (X $ex) {} $a instanceof X; newv('X'); Linted Phabricator. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D6143 --- scripts/lib/PhutilLibraryMapBuilder.php | 2 +- scripts/phutil_symbols.php | 53 ++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/scripts/lib/PhutilLibraryMapBuilder.php b/scripts/lib/PhutilLibraryMapBuilder.php index dace26a3..88a73946 100755 --- a/scripts/lib/PhutilLibraryMapBuilder.php +++ b/scripts/lib/PhutilLibraryMapBuilder.php @@ -21,7 +21,7 @@ final class PhutilLibraryMapBuilder { const LIBRARY_MAP_VERSION = 2; const SYMBOL_CACHE_VERSION_KEY = '__symbol_cache_version__'; - const SYMBOL_CACHE_VERSION = 10; + const SYMBOL_CACHE_VERSION = 11; /* -( Mapping libphutil Libraries )---------------------------------------- */ diff --git a/scripts/phutil_symbols.php b/scripts/phutil_symbols.php index 72f0b53b..8a7fbeed 100755 --- a/scripts/phutil_symbols.php +++ b/scripts/phutil_symbols.php @@ -225,11 +225,12 @@ foreach ($classes as $class) { // - Static property access // - Use of class constant // - typehints +// - catch +// - instanceof +// - newv() // // TODO: Possibly support these: // -// - instanceof -// - catch // - String literal in ReflectionClass(). @@ -289,6 +290,54 @@ foreach ($parameters as $parameter) { ); } +// This is "catch (Exception $ex)". +$catches = $root->selectDescendantsOfType('n_CATCH'); +foreach ($catches as $catch) { + $need[] = array( + 'type' => 'class/interface', + 'symbol' => $catch->getChildOfType(0, 'n_CLASS_NAME'), + ); +} + +// This is "$x instanceof X". +$instanceofs = $root->selectDescendantsOfType('n_BINARY_EXPRESSION'); +foreach ($instanceofs as $instanceof) { + $operator = $instanceof->getChildOfType(1, 'n_OPERATOR'); + if ($operator->getConcreteString() != 'instanceof') { + continue; + } + $class = $instanceof->getChildByIndex(2); + if ($class->getTypeName() != 'n_CLASS_NAME') { + continue; + } + $need[] = array( + 'type' => 'class/interface', + 'symbol' => $class, + ); +} + +// This is "newv('X')". +$calls = $root->selectDescendantsOfType('n_FUNCTION_CALL'); +foreach ($calls as $call) { + $call_name = $call->getChildByIndex(0)->getConcreteString(); + if ($call_name != 'newv') { + continue; + } + $params = $call->getChildByIndex(1)->getChildren(); + if (!count($params)) { + continue; + } + $symbol = reset($params); + $symbol_value = $symbol->getStringLiteralValue(); + if ($symbol_value && strpos($symbol_value, '$') === false) { + $need[] = array( + 'type' => 'class', + 'name' => $symbol_value, + 'symbol' => $symbol, + ); + } +} + // -( Interfaces )------------------------------------------------------------