mirror of
https://github.com/php/php-src.git
synced 2024-11-28 20:34:29 +08:00
* start using the source tokenizer
This commit is contained in:
parent
95613086e1
commit
e756a253d9
@ -472,6 +472,13 @@ class PEAR_Common extends PEAR
|
|||||||
$this->pkginfo['configure_options'][] = $attribs;
|
$this->pkginfo['configure_options'][] = $attribs;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'provides':
|
||||||
|
if (empty($attribs['type']) || empty($attribs['name'])) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$attribs['explicit'] = true;
|
||||||
|
$this->pkginfo['provides']["$attribs[type];$attribs[name]"] = $attribs;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -925,6 +932,12 @@ class PEAR_Common extends PEAR
|
|||||||
}
|
}
|
||||||
$ret .= "$indent </configureoptions>\n";
|
$ret .= "$indent </configureoptions>\n";
|
||||||
}
|
}
|
||||||
|
if (isset($pkginfo['provides'])) {
|
||||||
|
foreach ($pkginfo['provides'] as $key => $what) {
|
||||||
|
$ret .= "$indent <provides type=\"$what[type]\" ";
|
||||||
|
$ret .= "name=\"$what[name]\" />\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
if (isset($pkginfo['filelist'])) {
|
if (isset($pkginfo['filelist'])) {
|
||||||
$ret .= "$indent <filelist>\n";
|
$ret .= "$indent <filelist>\n";
|
||||||
foreach ($pkginfo['filelist'] as $file => $fa) {
|
foreach ($pkginfo['filelist'] as $file => $fa) {
|
||||||
@ -1087,17 +1100,101 @@ class PEAR_Common extends PEAR
|
|||||||
foreach ($info['filelist'] as $file => $fa) {
|
foreach ($info['filelist'] as $file => $fa) {
|
||||||
if (empty($fa['role'])) {
|
if (empty($fa['role'])) {
|
||||||
$errors[] = "file $file: missing role";
|
$errors[] = "file $file: missing role";
|
||||||
|
continue;
|
||||||
} elseif (!in_array($fa['role'], $_PEAR_Common_file_roles)) {
|
} elseif (!in_array($fa['role'], $_PEAR_Common_file_roles)) {
|
||||||
$errors[] = "file $file: invalid role, should be one of: ".implode(' ', $_PEAR_Common_file_roles);
|
$errors[] = "file $file: invalid role, should be one of: ".implode(' ', $_PEAR_Common_file_roles);
|
||||||
}
|
}
|
||||||
|
if ($fa['role'] == 'php') {
|
||||||
|
$srcinfo = $this->analyzeSourceCode($file);
|
||||||
|
$this->buildProvidesArray($srcinfo);
|
||||||
|
}
|
||||||
// (ssb) Any checks we can do for baseinstalldir?
|
// (ssb) Any checks we can do for baseinstalldir?
|
||||||
// (cox) Perhaps checks that either the target dir and
|
// (cox) Perhaps checks that either the target dir and
|
||||||
// baseInstall doesn't cointain "../../"
|
// baseInstall doesn't cointain "../../"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$pn = $info['package'];
|
||||||
|
$pnl = strlen($pn);
|
||||||
|
foreach ($this->pkginfo['provides'] as $key => $what) {
|
||||||
|
if (isset($what['explicit'])) {
|
||||||
|
// skip conformance checks if the provides entry is
|
||||||
|
// specified in the package.xml file
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
extract($what);
|
||||||
|
if ($type == 'class') {
|
||||||
|
if (!strncasecmp($name, $pn, $pnl)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$warnings[] = "in $file: class \"$name\" not prefixed with package name \"$pn\"";
|
||||||
|
} elseif ($type == 'function') {
|
||||||
|
if (strstr($name, '::') || !strncasecmp($name, $pn, $pnl)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$warnings[] = "in $file: function \"$name\" not prefixed with package name \"$pn\"";
|
||||||
|
}
|
||||||
|
//print "$file: provides $what[type] $what[name]\n";
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ buildProvidesArray()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a "provides" array from data returned by
|
||||||
|
* analyzeSourceCode(). The format of the built array is like
|
||||||
|
* this:
|
||||||
|
*
|
||||||
|
* array(
|
||||||
|
* 'class;MyClass' => 'array('type' => 'class', 'name' => 'MyClass'),
|
||||||
|
* ...
|
||||||
|
* )
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param array $srcinfo array with information about a source file
|
||||||
|
* as returned by the analyzeSourceCode() method.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function buildProvidesArray($srcinfo)
|
||||||
|
{
|
||||||
|
foreach ($srcinfo['declared_classes'] as $class) {
|
||||||
|
$key = "class;$class";
|
||||||
|
if (isset($this->pkginfo['provides'][$key])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$this->pkginfo['provides'][$key] =
|
||||||
|
array('type' => 'class', 'name' => $class);
|
||||||
|
//var_dump($key, $this->pkginfo['provides'][$key]);
|
||||||
|
}
|
||||||
|
foreach ($srcinfo['declared_methods'] as $class => $methods) {
|
||||||
|
foreach ($methods as $method) {
|
||||||
|
$function = "$class::$method";
|
||||||
|
$key = "function;$function";
|
||||||
|
if ($method{0} == '_' || !strcasecmp($method, $class) ||
|
||||||
|
isset($this->pkginfo['provides'][$key])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$this->pkginfo['provides'][$key] =
|
||||||
|
array('type' => 'function', 'name' => $function);
|
||||||
|
//var_dump($key, $this->pkginfo['provides'][$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($srcinfo['declared_functions'] as $function) {
|
||||||
|
$key = "function;$function";
|
||||||
|
if ($function{0} == '_' || isset($this->pkginfo['provides'][$key])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$this->pkginfo['provides'][$key] =
|
||||||
|
array('type' => 'function', 'name' => $function);
|
||||||
|
//var_dump($key, $this->pkginfo['provides'][$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ analyzeSourceCode()
|
// {{{ analyzeSourceCode()
|
||||||
|
|
||||||
@ -1120,7 +1217,7 @@ class PEAR_Common extends PEAR
|
|||||||
$tokens = token_get_all($contents);
|
$tokens = token_get_all($contents);
|
||||||
/*
|
/*
|
||||||
for ($i = 0; $i < sizeof($tokens); $i++) {
|
for ($i = 0; $i < sizeof($tokens); $i++) {
|
||||||
list($token, $data) = $tokens[$i];
|
@list($token, $data) = $tokens[$i];
|
||||||
if (is_string($token)) {
|
if (is_string($token)) {
|
||||||
var_dump($token);
|
var_dump($token);
|
||||||
} else {
|
} else {
|
||||||
@ -1145,8 +1242,15 @@ class PEAR_Common extends PEAR
|
|||||||
$used_functions = array();
|
$used_functions = array();
|
||||||
$nodeps = array();
|
$nodeps = array();
|
||||||
for ($i = 0; $i < sizeof($tokens); $i++) {
|
for ($i = 0; $i < sizeof($tokens); $i++) {
|
||||||
list($token, $data) = $tokens[$i];
|
if (is_array($tokens[$i])) {
|
||||||
|
list($token, $data) = $tokens[$i];
|
||||||
|
} else {
|
||||||
|
$token = $tokens[$i];
|
||||||
|
$data = '';
|
||||||
|
}
|
||||||
switch ($token) {
|
switch ($token) {
|
||||||
|
case T_CURLY_OPEN:
|
||||||
|
case T_DOLLAR_OPEN_CURLY_BRACES:
|
||||||
case '{': $brace_level++; continue 2;
|
case '{': $brace_level++; continue 2;
|
||||||
case '}':
|
case '}':
|
||||||
$brace_level--;
|
$brace_level--;
|
||||||
|
Loading…
Reference in New Issue
Block a user