Changeset View
Changeset View
Standalone View
Standalone View
scripts/phutil_symbols.php
Show First 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | |||||
// The first stage of analysis is to find all the symbols we declare in the | // The first stage of analysis is to find all the symbols we declare in the | ||||
// file (like functions and classes) and all the symbols we use in the file | // file (like functions and classes) and all the symbols we use in the file | ||||
// (like calling functions and invoking classes). Later, we filter this list | // (like calling functions and invoking classes). Later, we filter this list | ||||
// to exclude builtins. | // to exclude builtins. | ||||
$have = array(); // For symbols we declare. | $have = array(); // For symbols we declare. | ||||
$need = array(); // For symbols we use. | $need = array(); // For symbols we use. | ||||
$xmap = array(); // For extended classes and implemented interfaces. | $xmap = array(); // For extended classes. | ||||
$imap = array(); // For implemented interfaces. | |||||
// -( Functions )------------------------------------------------------------- | // -( Functions )------------------------------------------------------------- | ||||
// Find functions declared in this file. | // Find functions declared in this file. | ||||
// This is "function f() { ... }". | // This is "function f() { ... }". | ||||
▲ Show 20 Lines • Show All 242 Lines • ▼ Show 20 Lines | foreach ($classes as $class) { | ||||
$interfaces = $implements->selectDescendantsOfType('n_CLASS_NAME'); | $interfaces = $implements->selectDescendantsOfType('n_CLASS_NAME'); | ||||
foreach ($interfaces as $interface) { | foreach ($interfaces as $interface) { | ||||
$need[] = array( | $need[] = array( | ||||
'type' => 'interface', | 'type' => 'interface', | ||||
'symbol' => $interface, | 'symbol' => $interface, | ||||
); | ); | ||||
// Track 'class ... implements' in the extension map. | // Track 'class ... implements' in the extension map. | ||||
$xmap[$class_name][] = $interface->getConcreteString(); | $imap[$class_name][] = $interface->getConcreteString(); | ||||
} | } | ||||
} | } | ||||
// This is "interface X ... { ... }". | // This is "interface X ... { ... }". | ||||
$interfaces = $root->selectDescendantsOfType('n_INTERFACE_DECLARATION'); | $interfaces = $root->selectDescendantsOfType('n_INTERFACE_DECLARATION'); | ||||
foreach ($interfaces as $interface) { | foreach ($interfaces as $interface) { | ||||
$interface_name = $interface->getChildByIndex(1)->getConcreteString(); | $interface_name = $interface->getChildByIndex(1)->getConcreteString(); | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | foreach ($need as $key => $spec) { | ||||
} | } | ||||
$required_symbols[$type][$name] = $spec['symbol']->getOffset(); | $required_symbols[$type][$name] = $spec['symbol']->getOffset(); | ||||
} | } | ||||
$result = array( | $result = array( | ||||
'have' => $declared_symbols, | 'have' => $declared_symbols, | ||||
'need' => $required_symbols, | 'need' => $required_symbols, | ||||
'xmap' => $xmap, | 'xmap' => $xmap, | ||||
'imap' => $imap, | |||||
); | ); | ||||
// -( Output )---------------------------------------------------------------- | // -( Output )---------------------------------------------------------------- | ||||
if ($args->getArg('ugly')) { | if ($args->getArg('ugly')) { | ||||
echo json_encode($result); | echo json_encode($result); | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |