[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Fri Aug 17 01:54:04 2007 UTC Modified files: /phpdoc/scripts check-references.php Log: Conditional incrementation of $counts[refs] http://cvs.php.net/viewvc.cgi/phpdoc/scripts/check-references.php?r1=1.24&r2=1.25&diff_format=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.24 phpdoc/scripts/check-references.php:1.25 --- phpdoc/scripts/check-references.php:1.24Fri Jun 15 15:53:49 2007 +++ phpdoc/scripts/check-references.php Fri Aug 17 01:54:04 2007 @@ -391,7 +391,7 @@ ) { echo (isset($source_ref[0]) ? "Parameter(s) " . (is_int($source_ref[0]) ? "$source_ref[0] and rest" : implode(", ", $source_ref[0])) : "Nothing") . " should be passed by reference in $filename on line $lineno" . (isset($source_ref[1]) ? "\n: source in $source_ref[1] on line $source_ref[2]" : "") . ".\n"; } - if (isset($source_ref)) { + if (isset($source_refs[$function_name])) { $counts["refs"]++; }
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Fri Jun 15 15:53:50 2007 UTC Modified files: /phpdoc/scripts check-references.php Log: Enable output http://cvs.php.net/viewvc.cgi/phpdoc/scripts/check-references.php?r1=1.23&r2=1.24&diff_format=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.23 phpdoc/scripts/check-references.php:1.24 --- phpdoc/scripts/check-references.php:1.23Fri Jun 15 15:49:31 2007 +++ phpdoc/scripts/check-references.php Fri Jun 15 15:53:49 2007 @@ -370,11 +370,11 @@ $counts["return"]++; $modifier = (preg_match('~::__construct$~', $function_name) ? "i" : ""); if (!preg_match("~(" . $return_types[$function_name][0] . ")~$modifier", $return_type) && ($return_types[$function_name][0] != "object" || preg_match("~($valid_types|$invalid_types)~", $return_type))) { - //~ echo "Wrong return type in $filename on line $lineno.\n"; - //~ echo ": (" . $return_types[$function_name][0] . ") in " . $return_types[$function_name][1] . " on line " . $return_types[$function_name][2] . ".\n"; + echo "Wrong return type in $filename on line $lineno.\n"; + echo ": (" . $return_types[$function_name][0] . ") in " . $return_types[$function_name][1] . " on line " . $return_types[$function_name][2] . ".\n"; } } elseif (preg_match("~(callback|$invalid_types)~", $return_type)) { - //~ echo "Wrong return type in $filename on line $lineno.\n"; + echo "Wrong return type in $filename on line $lineno.\n"; } // references @@ -446,14 +446,14 @@ $count = count($matches[3]); if (!$matches[3] || substr($matches[3][$count - 1], -3) != "...") { if ($count > $max_args) { - //~ echo "Warning: Too much parameters in $function_name.\n"; + echo "Warning: Too much parameters in $function_name.\n"; } elseif ($count < $max_args) { $disallowed += array_fill($count + 1, $max_args - $count, true); } } if ($source_arg_count[0] != $disallowed) { - //~ echo "Wrong arguments count in $filename on line $lineno.\n"; - //~ echo ": source in $source_arg_count[1] on line $source_arg_count[2].\n"; + echo "Wrong arguments count in $filename on line $lineno.\n"; + echo ": source in $source_arg_count[1] on line $source_arg_count[2].\n"; } } }
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Fri Jun 15 15:49:32 2007 UTC Modified files: /phpdoc/scripts check-references.php Log: Local refs Optional single extension Unicode return types Constructor return types http://cvs.php.net/viewvc.cgi/phpdoc/scripts/check-references.php?r1=1.22&r2=1.23&diff_format=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.22 phpdoc/scripts/check-references.php:1.23 --- phpdoc/scripts/check-references.php:1.22Fri Jun 15 11:45:17 2007 +++ phpdoc/scripts/check-references.php Fri Jun 15 15:49:31 2007 @@ -29,7 +29,7 @@ if (!isset($_SERVER["argv"][1]) || !is_dir($phpdoc_dir)) { echo "Purpose: Check parameters (types, optional, reference, count) and return types.\n"; - echo "Usage: check-references.php language\n"; + echo "Usage: check-references.php language [path_to_extension]\n"; echo "Notes:\n"; echo "- Compares documentation with PHP sources (Zend, extensions, PECL, SAPI).\n"; echo "- Functions not found in sources are checked as without references.\n"; @@ -37,51 +37,23 @@ exit(); } +$extension = $_SERVER["argv"][2]; + // various names for parameters passed by reference // array() means list of parameters, number is position from which all parameters are passed by reference $number_refs = array( + "first_arg_force_ref" => array(1), "second_arg_force_ref" => array(2), "second_args_force_ref" => array(2), - "second_argument_force_ref" => array(2), - "exif_thumbnail_force_ref" => array(2, 3, 4), - "third_and_rest_force_ref" => 3, "third_arg_force_ref" => array(3), - "third_args_force_ref" => array(3), - "third_argument_force_ref" => array(3), - "third_arg_force_by_ref_rest" => 3, - "second_arg_force_by_ref_rest" => 2, - "arg3to6of6_force_ref" => array(3, 4, 5, 6), - "second_thru_fourth_args_force_ref" => array(2, 3, 4), - "secondandthird_args_force_ref" => array(2, 3), - "first_arg_force_ref" => array(1), - "first_args_force_ref" => array(1), - "first_argument_force_ref" => array(1), - "firstandsecond_args_force_ref" => array(1, 2), - "arg2and3_force_ref" => array(2, 3), - "first_through_third_args_force_ref" => array(1, 2, 3), "fourth_arg_force_ref" => array(4), - "second_and_third_args_force_ref" => array(2, 3), - "second_fifth_and_sixth_args_force_ref" => array(2, 5, 6), - "first_and_second__args_force_ref" => array(1, 2), - "third_and_fourth_args_force_ref" => array(3, 4), - "sixth_arg_force_ref" => array(6), - "msg_receive_args_force_ref" => array(3, 5, 8), - "all_args_force_by_ref" => 1, + "fifth_arg_force_ref" => array(5), "all_args_by_ref" => 1, - "http_request_info_ref_3" => array(3), - "http_request_info_ref_4" => array(4), - "http_arg_pass_ref_3" => array(3), - "http_arg_pass_ref_4" => array(4), - "http_arg_pass_ref_5" => array(5), - "secondandthird_arg_force_ref" => array(2, 3), - "fifthandsixth_arg_force_ref" => array(5, 6), - "seventh_arg_force_ref" => array(7), - "eighth_arg_force_ref" => array(8), ); $valid_types = "int|float|string|bool|resource|array|object|mixed|number"; $invalid_types = "integer|long|double|boolean|class"; // objects are written as appropriate class name so there is no complete list of valid types -$retval_mapping = array("TRUE" => "bool", "BOOL" => "bool", "LONG" => "int", "DOUBLE" => "float", "STRING" => "string", "STRINGL" => "string", "ARRAY" => "array", "OBJECT" => "object", "RESOURCE" => "resource", "ZVAL" => "mixed"); // FALSE and NULL omitted because they are used for errors +$retval_mapping = array("TRUE" => "bool", "BOOL" => "bool", "LONG" => "int", "DOUBLE" => "float", "STRING" => "string", "STRINGL" => "string", "TEXT" => "string", "TEXTL" => "string", "UNICODE" => "unicode", "UNICODEL" => "unicode", "ASCII_STRING" => "unicode", "ASCII_STRINGL" => "unicode", "ARRAY" => "array", "OBJECT" => "object", "RESOURCE" => "resource", "ZVAL" => "mixed"); // FALSE and NULL omitted because they are used for errors $retval_types = implode('|', array_keys($retval_mapping)); $operators = "!=|<=?|>=?|=="; $max_args = 12; // maximum number of regular function arguments @@ -190,7 +162,7 @@ $source_types = array(); // array("function_name" => array("type_spec", filename, lineno), ...) $return_types = array(); // array("function_name" => array("doc_type", filename, lineno), ...) $source_arg_counts = array(); // array("function_name" => array(disallowed_count => true, ...), ...) -foreach (array_merge(array($zend_dir), glob("$phpsrc_dir/ext/*", GLOB_ONLYDIR), glob("$pecl_dir/*", GLOB_ONLYDIR), glob("$phpsrc_dir/sapi/*", GLOB_ONLYDIR)) as $dirname) { +foreach ((isset($extension) ? array($extension) : array_merge(array($zend_dir), glob("$phpsrc_dir/ext/*", GLOB_ONLYDIR)
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Fri Jun 15 11:45:17 2007 UTC Modified files: /phpdoc/scripts check-references.php Log: More numer_refs New Zend params http://cvs.php.net/viewvc.cgi/phpdoc/scripts/check-references.php?r1=1.21&r2=1.22&diff_format=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.21 phpdoc/scripts/check-references.php:1.22 --- phpdoc/scripts/check-references.php:1.21Thu Nov 17 23:04:23 2005 +++ phpdoc/scripts/check-references.php Fri Jun 15 11:45:17 2007 @@ -73,6 +73,10 @@ "http_arg_pass_ref_3" => array(3), "http_arg_pass_ref_4" => array(4), "http_arg_pass_ref_5" => array(5), + "secondandthird_arg_force_ref" => array(2, 3), + "fifthandsixth_arg_force_ref" => array(5, 6), + "seventh_arg_force_ref" => array(7), + "eighth_arg_force_ref" => array(8), ); $valid_types = "int|float|string|bool|resource|array|object|mixed|number"; @@ -96,12 +100,22 @@ "O" => "object", "z" => "mixed", "Z" => "mixed", + "t" => "string", + "u" => "unicode", + "C" => "class", + "h" => "array", + "U" => "unicode", + "S" => "string", + "f" => "callback", + "x" => "string", + "T" => "unicode", + "|" => "optional" ); $return = array(); for ($i=0; $i < strlen($type_spec); $i++) { $ch = $type_spec[$i]; - if ($ch != "/" && $ch != "!") { + if ($ch != "/" && $ch != "!" && $ch != "&" && $ch != "^" && $ch != "*" && $ch != "+") { if (!isset($zend_params[$ch])) { echo "! Unknown formatting specifier '$ch' in '$type_spec'.\n"; $zend_params[$ch] = "unknown"; @@ -176,7 +190,6 @@ $source_types = array(); // array("function_name" => array("type_spec", filename, lineno), ...) $return_types = array(); // array("function_name" => array("doc_type", filename, lineno), ...) $source_arg_counts = array(); // array("function_name" => array(disallowed_count => true, ...), ...) -//~ foreach (array("$phpsrc_dir/ext/standard") as $dirname) { foreach (array_merge(array($zend_dir), glob("$phpsrc_dir/ext/*", GLOB_ONLYDIR), glob("$pecl_dir/*", GLOB_ONLYDIR), glob("$phpsrc_dir/sapi/*", GLOB_ONLYDIR)) as $dirname) { if (dirname($dirname) == $pecl_dir && !file_exists("$phpdoc_dir/reference/" . strtolower(basename($dirname { continue; // skip undocumented PECL extensions @@ -225,7 +238,7 @@ } // read parameters - preg_match_all('~^(?:ZEND|PHP)(_NAMED)?_(?:FUNCTION|METHOD)\\(([^)]+)\\)(.*)^\\}~msU', $file, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE); // }}} is not in all sources so ^} is used instead + preg_match_all('~^(?:static )?(?:ZEND|PHP)(_NAMED)?_(?:FUNCTION|METHOD)\\(([^)]+)\\)(.*)^\\}~msU', $file, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE); // }}} is not in all sources so ^} is used instead foreach ($matches as $val) { $function_name = strtolower(trim(preg_replace('~\\s*,\\s*~', '::', ($val[1][0] ? $aliases[$val[2][0]] : $val[2][0]; $function_body = $val[3][0];
[PHP-DOC] cvs: phpdoc /scripts check-references.php file-entities.php.in process.php spell-checker.php zendapi_protos.php
nlopess Thu Nov 17 18:04:30 2005 EDT Modified files: /phpdoc/scripts check-references.php file-entities.php.in process.php spell-checker.php zendapi_protos.php Log: PHP 6 compat http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.20&r2=1.21&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.20 phpdoc/scripts/check-references.php:1.21 --- phpdoc/scripts/check-references.php:1.20Fri Jun 24 10:52:58 2005 +++ phpdoc/scripts/check-references.php Thu Nov 17 18:04:23 2005 @@ -100,7 +100,7 @@ ); $return = array(); for ($i=0; $i < strlen($type_spec); $i++) { - $ch = $type_spec{$i}; + $ch = $type_spec[$i]; if ($ch != "/" && $ch != "!") { if (!isset($zend_params[$ch])) { echo "! Unknown formatting specifier '$ch' in '$type_spec'.\n"; @@ -297,7 +297,7 @@ foreach ($matches2 as $val) { $number = $val[1] . $val[4]; $operator = strtr($val[2], "><", "<>") . $val[3]; // unify to $zend_num_args $operator $number - switch ($operator{0}) { + switch ($operator[0]) { case "=": case "!": if (!$source_arg_count) { http://cvs.php.net/diff.php/phpdoc/scripts/file-entities.php.in?r1=1.40&r2=1.41&ty=u Index: phpdoc/scripts/file-entities.php.in diff -u phpdoc/scripts/file-entities.php.in:1.40 phpdoc/scripts/file-entities.php.in:1.41 --- phpdoc/scripts/file-entities.php.in:1.40Sat Sep 24 19:28:42 2005 +++ phpdoc/scripts/file-entities.php.in Thu Nov 17 18:04:24 2005 @@ -17,7 +17,7 @@ | Gabor Hojtsy <[EMAIL PROTECTED]> | +--+ - $Id: file-entities.php.in,v 1.40 2005/09/24 23:28:42 nlopess Exp $ + $Id: file-entities.php.in,v 1.41 2005/11/17 23:04:24 nlopess Exp $ */ /** @@ -73,7 +73,7 @@ $refdir = "$out_dir/en/reference"; $dh = opendir($refdir); while ($dir = readdir($dh)) { - if ($dir{0} === ".") continue; // ignore system dir entries and hidden files + if ($dir[0] === ".") continue; // ignore system dir entries and hidden files if (is_file("$refdir/$dir/reference.xml") && !is_file("$refdir/$dir/EXCLUDE")) { $dirent = str_replace("_","-",$dir); @@ -95,7 +95,7 @@ $pecl_dirs = array(); while($dir = readdir()) { -if($dir{0} === ".") continue; // ignore system dir entries and hidden files +if($dir[0] === ".") continue; // ignore system dir entries and hidden files $pecl_dirs[] = $dir; } @@ -250,7 +250,7 @@ // While we can read that directory while (($file = readdir($dh)) !== FALSE) { // If file name begins with . skip it -if ($file{0} == ".") { continue; } +if ($file[0] == ".") { continue; } // If we found a directory, and it's name is not // CVS, recursively go into it, and generate entities @@ -315,7 +315,7 @@ if ($dh) { while (($file = readdir($dh)) !== FALSE) { -if ($file{0} =="." || $file == "CVS") { continue; } +if ($file[0] =="." || $file == "CVS") { continue; } if (is_dir($trans_path."/".$file)) { continue; } // If this is an XML file http://cvs.php.net/diff.php/phpdoc/scripts/process.php?r1=1.9&r2=1.10&ty=u Index: phpdoc/scripts/process.php diff -u phpdoc/scripts/process.php:1.9 phpdoc/scripts/process.php:1.10 --- phpdoc/scripts/process.php:1.9 Wed Aug 25 04:36:32 2004 +++ phpdoc/scripts/process.php Thu Nov 17 18:04:24 2005 @@ -105,7 +105,7 @@ //echo "$file\n"; if (ereg('\.xml$',$file)) $entries[] = $ffile; -if ($file{0} != '.' && is_dir($ffile)) +if ($file[0] != '.' && is_dir($ffile)) $entries = array_merge($entries,all_xml_files($ffile)); } closedir($handle); http://cvs.php.net/diff.php/phpdoc/scripts/spell-checker.php?r1=1.2&r2=1.3&ty=u Index: phpdoc/scripts/spell-checker.php diff -u phpdoc/scripts/spell-checker.php:1.2 phpdoc/scripts/spell-checker.php:1.3 --- phpdoc/scripts/spell-checker.php:1.2Fri Aug 13 18:33:03 2004 +++ phpdoc/scripts/spell-checker.phpThu Nov 17 18:04:25 2005 @@ -102,13 +102,13 @@ echo "$current_file:" . xml_get_current_line_number($xml) . ": $word (in element $element)\n"; do { $response = read_line("Add this word to personal wordlist? (yes/no/sa
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Fri Jun 24 10:53:00 2005 EDT Modified files: /phpdoc/scripts check-references.php Log: Expand macros only if available http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.19&r2=1.20&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.19 phpdoc/scripts/check-references.php:1.20 --- phpdoc/scripts/check-references.php:1.19Fri Jun 24 09:50:20 2005 +++ phpdoc/scripts/check-references.php Fri Jun 24 10:52:58 2005 @@ -176,7 +176,7 @@ $source_types = array(); // array("function_name" => array("type_spec", filename, lineno), ...) $return_types = array(); // array("function_name" => array("doc_type", filename, lineno), ...) $source_arg_counts = array(); // array("function_name" => array(disallowed_count => true, ...), ...) -//~ foreach (array("$pecl_dir/standard") as $dirname) { +//~ foreach (array("$phpsrc_dir/ext/standard") as $dirname) { foreach (array_merge(array($zend_dir), glob("$phpsrc_dir/ext/*", GLOB_ONLYDIR), glob("$pecl_dir/*", GLOB_ONLYDIR), glob("$phpsrc_dir/sapi/*", GLOB_ONLYDIR)) as $dirname) { if (dirname($dirname) == $pecl_dir && !file_exists("$phpdoc_dir/reference/" . strtolower(basename($dirname { continue; // skip undocumented PECL extensions @@ -208,7 +208,9 @@ } foreach ($files as $filename => $file) { - $file = preg_replace_callback('~\\b(' . implode('|', array_keys($macros)) . ')\\b(\\(.*\\))?~', 'expand_macros', $file); + if ($macros) { + $file = preg_replace_callback('~\\b(' . implode('|', array_keys($macros)) . ')\\b(\\(.*\\))?~', 'expand_macros', $file); + } // references preg_match_all("~^[ \t]*(?:ZEND|PHP)_FE\\((\\w+)\\s*,\\s*(\\w+)\\s*[,)]~m", $file, $matches, PREG_SET_ORDER);
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Fri Jun 24 09:50:21 2005 EDT Modified files: /phpdoc/scripts check-references.php Log: Expand macros, return type void, skip undocumented PECL extensions http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.18&r2=1.19&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.18 phpdoc/scripts/check-references.php:1.19 --- phpdoc/scripts/check-references.php:1.18Fri Jun 24 05:14:10 2005 +++ phpdoc/scripts/check-references.php Fri Jun 24 09:50:20 2005 @@ -28,9 +28,10 @@ } if (!isset($_SERVER["argv"][1]) || !is_dir($phpdoc_dir)) { - echo "Purpose: Check parameters (types, optional, reference, count) from PHP sources.\n"; + echo "Purpose: Check parameters (types, optional, reference, count) and return types.\n"; echo "Usage: check-references.php language\n"; echo "Notes:\n"; + echo "- Compares documentation with PHP sources (Zend, extensions, PECL, SAPI).\n"; echo "- Functions not found in sources are checked as without references.\n"; echo "- Types and optional params are checked only in some functions.\n"; exit(); @@ -76,7 +77,7 @@ $valid_types = "int|float|string|bool|resource|array|object|mixed|number"; $invalid_types = "integer|long|double|boolean|class"; // objects are written as appropriate class name so there is no complete list of valid types -$retval_mapping = array("TRUE" => "bool", "BOOL" => "bool", "LONG" => "int", "DOUBLE" => "float", "STRING" => "string", "STRINGL" => "string", "ARRAY" => "array", "OBJECT" => "object", "RESOURCE" => "resource"); // FALSE and NULL omitted because they are used for errors +$retval_mapping = array("TRUE" => "bool", "BOOL" => "bool", "LONG" => "int", "DOUBLE" => "float", "STRING" => "string", "STRINGL" => "string", "ARRAY" => "array", "OBJECT" => "object", "RESOURCE" => "resource", "ZVAL" => "mixed"); // FALSE and NULL omitted because they are used for errors $retval_types = implode('|', array_keys($retval_mapping)); $operators = "!=|<=?|>=?|=="; $max_args = 12; // maximum number of regular function arguments @@ -111,6 +112,17 @@ return $return; } +// expand macros defined in $GLOBALS['macros'] (callback for preg_replace_callback) +function expand_macros($matches) +{ + $macro = $GLOBALS['macros'][$matches[1]]; + if ($matches[2]) { + $params = explode(",", trim($matches[2], '()'), count($macro[1])); + return str_replace($macro[1], $params, $macro[0]); + } + return $macro[0]; +} + // some parameters should be passed only by reference but they are not forced to $wrong_refs = array( "dbplus_curr", "dbplus_first", "dbplus_info", "dbplus_last", "dbplus_next", "dbplus_prev", "dbplus_tremove", @@ -122,6 +134,7 @@ $difficult_retvals = array( "set_error_handler", "set_exception_handler", "highlight_file", "highlight_string", "pg_cancel_query", "pg_connection_busy", "mysqli_query", + "mb_send_mail", // better to fix in sources: "debug_print_backtrace", // array instead of void "dbmopen", // int instead of resource @@ -163,21 +176,40 @@ $source_types = array(); // array("function_name" => array("type_spec", filename, lineno), ...) $return_types = array(); // array("function_name" => array("doc_type", filename, lineno), ...) $source_arg_counts = array(); // array("function_name" => array(disallowed_count => true, ...), ...) -//~ foreach (array("$phpsrc_dir/ext/dbx") as $dirname) { -foreach (array_merge(array($zend_dir), glob("$phpsrc_dir/ext/*"), glob("$phpsrc_dir/sapi/*"), glob("$pecl_dir/*")) as $dirname) { +//~ foreach (array("$pecl_dir/standard") as $dirname) { +foreach (array_merge(array($zend_dir), glob("$phpsrc_dir/ext/*", GLOB_ONLYDIR), glob("$pecl_dir/*", GLOB_ONLYDIR), glob("$phpsrc_dir/sapi/*", GLOB_ONLYDIR)) as $dirname) { + if (dirname($dirname) == $pecl_dir && !file_exists("$phpdoc_dir/reference/" . strtolower(basename($dirname { + continue; // skip undocumented PECL extensions + } $files = array(); $aliases = array(); // php_function => sources_function - foreach ((array) glob("$dirname/*.c*") as $filename) { - $files[$filename] = file_get_contents($filename); + $macros = array(); // MACRO => array(body, array(params)) + $largedir = ($dirname == $zend_dir || $dirname == "$phpsrc_dir/ext/standard"); + foreach (array_merge((array) glob("$dirname/*.c*"), (array) glob("$dirname/*.h")) as $filename) { + $file = file_get_contents($filename); + // macros + if (!$largedir) { + preg_match_all("~^#define[ \t]+(\\w+)(\\([^)]+\\))?([ \t]+.+[^])\$~msU", $file, $matches, PREG_SET_ORDER); + foreach ($matches as $val) { + $params = preg_split('~,\\s*~', trim($val[2],
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Fri Jun 24 05:14:10 2005 EDT Modified files: /phpdoc/scripts check-references.php Log: Check return types http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.17&r2=1.18&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.17 phpdoc/scripts/check-references.php:1.18 --- phpdoc/scripts/check-references.php:1.17Wed Jun 22 06:38:05 2005 +++ phpdoc/scripts/check-references.php Fri Jun 24 05:14:10 2005 @@ -76,6 +76,8 @@ $valid_types = "int|float|string|bool|resource|array|object|mixed|number"; $invalid_types = "integer|long|double|boolean|class"; // objects are written as appropriate class name so there is no complete list of valid types +$retval_mapping = array("TRUE" => "bool", "BOOL" => "bool", "LONG" => "int", "DOUBLE" => "float", "STRING" => "string", "STRINGL" => "string", "ARRAY" => "array", "OBJECT" => "object", "RESOURCE" => "resource"); // FALSE and NULL omitted because they are used for errors +$retval_types = implode('|', array_keys($retval_mapping)); $operators = "!=|<=?|>=?|=="; $max_args = 12; // maximum number of regular function arguments @@ -118,6 +120,17 @@ "soapclient::__soapcall", ); +$difficult_retvals = array( + "set_error_handler", "set_exception_handler", "highlight_file", "highlight_string", "pg_cancel_query", "pg_connection_busy", "mysqli_query", + // better to fix in sources: + "debug_print_backtrace", // array instead of void + "dbmopen", // int instead of resource + "pg_lo_open", // int instead of resource + "ircg_pconnect", // int instead of resource + "notes_search", // RETURN_LONG commented out + "exif_tagname", // RETURN_BOOL(FALSE) instead of RETURN_FALSE +); + $difficult_params = array( "ibase_blob_import", "ibase_execute", "imagefilter", @@ -132,8 +145,9 @@ "snmp_set_quick_print", "apd_echo", "easter_date", - "mysql_pconnect", + "tidy_repair_string", ); + $difficult_arg_count = array( "getdate", "min", "max", "implode", "strtok", "sybase_fetch_object", "cpdf_text", "pdf_get_parameter", "pg_fetch_assoc", "odbc_exec", "odbc_result_all", "yaz_wait", @@ -147,7 +161,9 @@ // read referenced parameters from sources $source_refs = array(); // array("function_name" => number_ref, ...) $source_types = array(); // array("function_name" => array("type_spec", filename, lineno), ...) +$return_types = array(); // array("function_name" => array("doc_type", filename, lineno), ...) $source_arg_counts = array(); // array("function_name" => array(disallowed_count => true, ...), ...) +//~ foreach (array("$phpsrc_dir/ext/dbx") as $dirname) { foreach (array_merge(array($zend_dir), glob("$phpsrc_dir/ext/*"), glob("$phpsrc_dir/sapi/*"), glob("$pecl_dir/*")) as $dirname) { $files = array(); $aliases = array(); // php_function => sources_function @@ -155,7 +171,7 @@ $files[$filename] = file_get_contents($filename); // named functions - preg_match_all('~PHP_NAMED_FE\\((\\w*)\\s*,\\s*(\\w*)~', $files[$filename], $matches, PREG_SET_ORDER); + preg_match_all('~(?:PHP|ZEND)_NAMED_FE\\((\\w*)\\s*,\\s*(\\w*)~', $files[$filename], $matches, PREG_SET_ORDER); foreach ($matches as $val) { $aliases[$val[2]] = $val[1]; } @@ -178,17 +194,45 @@ preg_match_all('~^(?:ZEND|PHP)(_NAMED)?_(?:FUNCTION|METHOD)\\(([^)]+)\\)(.*)^\\}~msU', $file, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE); // }}} is not in all sources so ^} is used instead foreach ($matches as $val) { $function_name = strtolower(trim(preg_replace('~\\s*,\\s*~', '::', ($val[1][0] ? $aliases[$val[2][0]] : $val[2][0]; + $function_body = $val[3][0]; + $lineno = substr_count(substr($file, 0, $val[3][1]), "\n") + 1; + + // return type + if (!in_array($function_name, $difficult_retvals)) { + preg_match_all("~\\b(?:RETURN|RETVAL|(?:return_value->type|Z_TYPE_P\\(return_value\\))\\s*=\\s*IS)_($retval_types)|(?:ZVAL_|convert_to_)((?i)$retval_types)(?:_ex)?\\(return_value~", $function_body, $types, PREG_SET_ORDER); + if (preg_match_all('~()(array|object)(?:_and_properties)?_init\\(return_value~', $function_body, $matches, PREG_SET_ORDER)) { + $types = array_merge($types, $matches); + } + if (preg_match('~(?:ZEND_REGISTER_RESOURCE\\(|php_stream_to_zval.*)return_value~', $function_body)) { + $types[] = array("", "RESOURCE", ""); + } +
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Wed Jun 22 06:38:06 2005 EDT Modified files: /phpdoc/scripts check-references.php Log: Check named functions, split sources reading to 3 steps http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.16&r2=1.17&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.16 phpdoc/scripts/check-references.php:1.17 --- phpdoc/scripts/check-references.php:1.16Tue Jun 21 19:40:55 2005 +++ phpdoc/scripts/check-references.php Wed Jun 22 06:38:05 2005 @@ -112,7 +112,10 @@ // some parameters should be passed only by reference but they are not forced to $wrong_refs = array( "dbplus_curr", "dbplus_first", "dbplus_info", "dbplus_last", "dbplus_next", "dbplus_prev", "dbplus_tremove", - "preg_replace", + "php_check_syntax", + "pdostatement::bindcolumn", "pdostatement::bindparam", + "preg_replace", "preg_replace_callback", + "soapclient::__soapcall", ); $difficult_params = array( @@ -145,98 +148,118 @@ $source_refs = array(); // array("function_name" => number_ref, ...) $source_types = array(); // array("function_name" => array("type_spec", filename, lineno), ...) $source_arg_counts = array(); // array("function_name" => array(disallowed_count => true, ...), ...) -foreach (array_merge(glob("$zend_dir/*.c*"), glob("$phpsrc_dir/ext/*/*.c*"), glob("$phpsrc_dir/sapi/*/*.c*"), glob("$pecl_dir/*/*.c*")) as $filename) { - $file = file_get_contents($filename); - - // references - preg_match_all("~^[ \t]*(?:ZEND|PHP)_FE\\((\\w+)\\s*,\\s*(\\w+)\\s*[,)]~m", $file, $matches, PREG_SET_ORDER); - preg_match_all("~^[ \t]*(?:ZEND|PHP)_FALIAS\\((\\w+)\\s*,[^,]+,\\s*(\\w+)\\s*[,)]~m", $file, $matches2, PREG_SET_ORDER); - foreach (array_merge($matches, $matches2) as $val) { - if ($val[2] != "NULL") { - if (empty($number_refs[$val[2]])) { - echo "! $val[2] from $filename is not defined.\n"; - } - $source_refs[strtolower($val[1])] = $number_refs[$val[2]]; +foreach (array_merge(array($zend_dir), glob("$phpsrc_dir/ext/*"), glob("$phpsrc_dir/sapi/*"), glob("$pecl_dir/*")) as $dirname) { + $files = array(); + $aliases = array(); // php_function => sources_function + foreach ((array) glob("$dirname/*.c*") as $filename) { + $files[$filename] = file_get_contents($filename); + + // named functions + preg_match_all('~PHP_NAMED_FE\\((\\w*)\\s*,\\s*(\\w*)~', $files[$filename], $matches, PREG_SET_ORDER); + foreach ($matches as $val) { + $aliases[$val[2]] = $val[1]; } } - // read parameters - preg_match_all('~^(?:ZEND|PHP)(?:_NAMED)?_(?:FUNCTION|METHOD)\\(([^)]+)\\)(.*)^\\}~msU', $file, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE); // }}} is not in all sources so ^} is used instead - foreach ($matches as $val) { - $function_name = strtolower(trim(preg_replace('~\\s*,\\s*~', '::', $val[1][0]))); - if (preg_match('~(\\w+)\\(INTERNAL_FUNCTION_PARAM_PASSTHRU~', $val[2][0], $matches2)) { - preg_match('~(' . preg_quote($matches2[1], '~') . ')\\(INTERNAL_FUNCTION_PARAMETERS(.*)^\\}~msU', $file, $val, PREG_OFFSET_CAPTURE); + foreach ($files as $filename => $file) { + // references + preg_match_all("~^[ \t]*(?:ZEND|PHP)_FE\\((\\w+)\\s*,\\s*(\\w+)\\s*[,)]~m", $file, $matches, PREG_SET_ORDER); + preg_match_all("~^[ \t]*(?:ZEND|PHP)_FALIAS\\((\\w+)\\s*,[^,]+,\\s*(\\w+)\\s*[,)]~m", $file, $matches2, PREG_SET_ORDER); + foreach (array_merge($matches, $matches2) as $val) { + if ($val[2] != "NULL") { + if (empty($number_refs[$val[2]])) { + echo "! $val[2] from $filename is not defined.\n"; + } + $source_refs[strtolower($val[1])] = $number_refs[$val[2]]; + } } - $lineno = substr_count(substr($file, 0, $val[2][1]), "\n") + 1; - $function_body = $val[2][0]; - - // types and optional - if (!in_array($function_name, $difficult_params) - && strpos($function_body, 'zend_parse_parameters_ex') === false // indicate difficulty - && preg_match('~.*zend_parse(_method)?_parameters\\([^,]*,\\s*"([^"]*)"~s', $function_body, $matches2) // .* to catch last occurence - ) { - $source_types[$function_name] = array(($matches2[1] ? substr($matches2[2], 1) : $matches2[2]), $filename, $lineno); - } elseif (!in_array($function_name, $difficult_arg_count)) { -
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Tue Jun 21 19:40:56 2005 EDT Modified files: /phpdoc/scripts check-references.php Log: Remove old stuff http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.15&r2=1.16&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.15 phpdoc/scripts/check-references.php:1.16 --- phpdoc/scripts/check-references.php:1.15Tue Jun 21 09:59:33 2005 +++ phpdoc/scripts/check-references.php Tue Jun 21 19:40:55 2005 @@ -121,25 +121,15 @@ "maxdb_stmt_bind_result", "mt_rand", "rand", "mcrypt_get_block_size", "mcrypt_get_key_size", "mcrypt_get_cipher_name", // inverse order - "mysql_ping", "pdf_get_parameter", - "tidy_getopt", // uses zend_parse_method_parameters + "tidy_get_opt_doc", "tidy_getopt", // better to fix in sources: - "imagepstext", "ncurses_keyok", "ncurses_use_env", "ncurses_use_extended_names", "openssl_x509_export_to_file", "openssl_x509_export", "snmp_set_quick_print", - "tcpwrap_check", - "get_headers", - "wddx_packet_end", "apd_echo", - "fdf_set_on_import_javascript", "easter_date", - "fbsql_fetch_assoc", "fbsql_fetch_row", - "msql_fetch_object", "msql_fetch_row", - "mssql_fetch_assoc", "mssql_fetch_object", "mssql_fetch_row", "mysql_pconnect", - "pg_fetch_assoc", "pg_fetch_row", ); $difficult_arg_count = array( "getdate", "min", "max", "implode", "strtok", "sybase_fetch_object", @@ -217,11 +207,6 @@ } unset($source_arg_count[$number]); break; - /* old version - case "=": - $source_arg_count[$number] = true; - break; - */ case "<": for ($i=0; $i < $number; $i++) { $source_arg_count[$i] = true;
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Tue Jun 21 09:59:34 2005 EDT Modified files: /phpdoc/scripts check-references.php Log: Support for methods and PARAM_PASSTHRU # generates a lot of false warnings yet http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.14&r2=1.15&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.14 phpdoc/scripts/check-references.php:1.15 --- phpdoc/scripts/check-references.php:1.14Thu Jun 16 10:41:37 2005 +++ phpdoc/scripts/check-references.php Tue Jun 21 09:59:33 2005 @@ -134,6 +134,12 @@ "wddx_packet_end", "apd_echo", "fdf_set_on_import_javascript", + "easter_date", + "fbsql_fetch_assoc", "fbsql_fetch_row", + "msql_fetch_object", "msql_fetch_row", + "mssql_fetch_assoc", "mssql_fetch_object", "mssql_fetch_row", + "mysql_pconnect", + "pg_fetch_assoc", "pg_fetch_row", ); $difficult_arg_count = array( "getdate", "min", "max", "implode", "strtok", "sybase_fetch_object", @@ -165,19 +171,22 @@ } // read parameters - preg_match_all('~^(?:ZEND|PHP)(?:_NAMED)?_FUNCTION\\(([^)]+)\\)(.*)^\\}~msU', $file, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE); // }}} is not in all sources so ^} is used instead + preg_match_all('~^(?:ZEND|PHP)(?:_NAMED)?_(?:FUNCTION|METHOD)\\(([^)]+)\\)(.*)^\\}~msU', $file, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE); // }}} is not in all sources so ^} is used instead foreach ($matches as $val) { - $function_name = strtolower(trim($val[1][0])); + $function_name = strtolower(trim(preg_replace('~\\s*,\\s*~', '::', $val[1][0]))); + if (preg_match('~(\\w+)\\(INTERNAL_FUNCTION_PARAM_PASSTHRU~', $val[2][0], $matches2)) { + preg_match('~(' . preg_quote($matches2[1], '~') . ')\\(INTERNAL_FUNCTION_PARAMETERS(.*)^\\}~msU', $file, $val, PREG_OFFSET_CAPTURE); + } + $lineno = substr_count(substr($file, 0, $val[2][1]), "\n") + 1; $function_body = $val[2][0]; // types and optional if (!in_array($function_name, $difficult_params) && strpos($function_body, 'zend_parse_parameters_ex') === false // indicate difficulty - && preg_match('~.*zend_parse_parameters\\([^,]*,\\s*"([^"]*)"~s', $function_body, $matches2) // .* to catch last occurence - // zend_parse_method_parameters is not yet supported + && preg_match('~.*zend_parse(_method)?_parameters\\([^,]*,\\s*"([^"]*)"~s', $function_body, $matches2) // .* to catch last occurence ) { - $source_types[$function_name] = array($matches2[1], $filename, $lineno); + $source_types[$function_name] = array(($matches2[1] ? substr($matches2[2], 1) : $matches2[2]), $filename, $lineno); } elseif (!in_array($function_name, $difficult_arg_count)) { // arguments count @@ -231,20 +240,33 @@ } } } + preg_match_all('~INIT(?:_OVERLOADED)?_CLASS_ENTRY\\(.*"([^"]+)"\\s*,\\s*([^)]+)~', $file, $matches, PREG_SET_ORDER); + foreach ($matches as $val) { + if (preg_match('~' . preg_quote($val[2], '~') . '\\[\\](.*)\\}~sU', $file, $matches2)) { + preg_match_all('~PHP_FALIAS\\((\\w+)\\s*,\\s*(\\w+)~', $matches2[1], $matches2, PREG_SET_ORDER); + foreach ($matches2 as $val2) { + $function_name = strtolower($val2[2]); + $method_name = strtolower("$val[1]::$val2[1]"); + if (isset($source_types[$function_name])) { + $source_types[$method_name] = $source_types[$function_name]; + } + if ($source_arg_counts[$function_name]) { + $source_arg_counts[$method_name] = $source_arg_counts[$function_name]; + } + } + } + } } echo "Sources were read.\n"; // compare with documentation $counts = array("refs" => 0, "types" => 0, "arg_counts" => 0); foreach (glob("$phpdoc_dir/reference/*/functions/*.xml") as $filename) { - if (preg_match('~^(.*(.*))([^<]+)<(.*)~sU', file_get_contents($filename), $matches)) { + if (preg_match('~^(.*(?:(\\w+)\\s*)?(.*))([^<]+)<(.*)~sU', file_get_contents($filename), $matches)) { $lineno = substr_count($matches[1], "\n") + 1; - $return_type = $matches[2]; - $function_name = strtolower(trim($matches[3])); - if (strpos($function_name, '-') || strpos($function_name, ':')) { - continue; // methods ar
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Thu Jun 16 10:41:38 2005 EDT Modified files: /phpdoc/scripts check-references.php Log: More exceptions http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.13&r2=1.14&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.13 phpdoc/scripts/check-references.php:1.14 --- phpdoc/scripts/check-references.php:1.13Tue Apr 5 04:36:51 2005 +++ phpdoc/scripts/check-references.php Thu Jun 16 10:41:37 2005 @@ -69,6 +69,9 @@ "all_args_by_ref" => 1, "http_request_info_ref_3" => array(3), "http_request_info_ref_4" => array(4), + "http_arg_pass_ref_3" => array(3), + "http_arg_pass_ref_4" => array(4), + "http_arg_pass_ref_5" => array(5), ); $valid_types = "int|float|string|bool|resource|array|object|mixed|number"; @@ -107,10 +110,15 @@ } // some parameters should be passed only by reference but they are not forced to -$wrong_refs = array("dbplus_info", "dbplus_next"); +$wrong_refs = array( + "dbplus_curr", "dbplus_first", "dbplus_info", "dbplus_last", "dbplus_next", "dbplus_prev", "dbplus_tremove", + "preg_replace", +); + $difficult_params = array( "ibase_blob_import", "ibase_execute", "imagefilter", + "maxdb_stmt_bind_result", "mt_rand", "rand", "mcrypt_get_block_size", "mcrypt_get_key_size", "mcrypt_get_cipher_name", // inverse order "mysql_ping", @@ -131,7 +139,10 @@ "getdate", "min", "max", "implode", "strtok", "sybase_fetch_object", "cpdf_text", "pdf_get_parameter", "pg_fetch_assoc", "odbc_exec", "odbc_result_all", "yaz_wait", // take account of multiple methodsynopsis: - "crack_check", "ibase_prepare", "mysqli_stmt_bind_param", "pg_fetch_result", "pg_put_line", "pg_query", "pg_set_client_encoding", "strtr", "yaz_set_option", + "crack_check", "ibase_prepare", "maxdb_stmt_bind_param", "mysqli_stmt_bind_param", "strtr", "yaz_set_option", + "pg_fetch_result", "pg_put_line", "pg_query", "pg_set_client_encoding", "pg_execute", "pg_query_params", "pg_prepare", "pg_set_error_verbosity", + // better to fix in sources: + "ora_error", "ora_errorcode", ); // read referenced parameters from sources
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Tue Apr 5 04:36:55 2005 EDT Modified files: /phpdoc/scripts check-references.php Log: Remove slow ~S http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.12&r2=1.13&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.12 phpdoc/scripts/check-references.php:1.13 --- phpdoc/scripts/check-references.php:1.12Mon Apr 4 12:20:00 2005 +++ phpdoc/scripts/check-references.php Tue Apr 5 04:36:51 2005 @@ -142,8 +142,8 @@ $file = file_get_contents($filename); // references - preg_match_all("~^[ \t]*(?:ZEND|PHP)_FE\\((\\w+)\\s*,\\s*(\\w+)\\s*[,)]~mS", $file, $matches, PREG_SET_ORDER); - preg_match_all("~^[ \t]*(?:ZEND|PHP)_FALIAS\\((\\w+)\\s*,[^,]+,\\s*(\\w+)\\s*[,)]~mS", $file, $matches2, PREG_SET_ORDER); + preg_match_all("~^[ \t]*(?:ZEND|PHP)_FE\\((\\w+)\\s*,\\s*(\\w+)\\s*[,)]~m", $file, $matches, PREG_SET_ORDER); + preg_match_all("~^[ \t]*(?:ZEND|PHP)_FALIAS\\((\\w+)\\s*,[^,]+,\\s*(\\w+)\\s*[,)]~m", $file, $matches2, PREG_SET_ORDER); foreach (array_merge($matches, $matches2) as $val) { if ($val[2] != "NULL") { if (empty($number_refs[$val[2]])) { @@ -154,7 +154,7 @@ } // read parameters - preg_match_all('~^(?:ZEND|PHP)(?:_NAMED)?_FUNCTION\\(([^)]+)\\)(.*)^\\}~msSU', $file, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE); // }}} is not in all sources so ^} is used instead + preg_match_all('~^(?:ZEND|PHP)(?:_NAMED)?_FUNCTION\\(([^)]+)\\)(.*)^\\}~msU', $file, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE); // }}} is not in all sources so ^} is used instead foreach ($matches as $val) { $function_name = strtolower(trim($val[1][0])); $lineno = substr_count(substr($file, 0, $val[2][1]), "\n") + 1; @@ -163,7 +163,7 @@ // types and optional if (!in_array($function_name, $difficult_params) && strpos($function_body, 'zend_parse_parameters_ex') === false // indicate difficulty - && preg_match('~.*zend_parse_parameters\\([^,]*,\\s*"([^"]*)"~sS', $function_body, $matches2) // .* to catch last occurence + && preg_match('~.*zend_parse_parameters\\([^,]*,\\s*"([^"]*)"~s', $function_body, $matches2) // .* to catch last occurence // zend_parse_method_parameters is not yet supported ) { $source_types[$function_name] = array($matches2[1], $filename, $lineno); @@ -171,19 +171,19 @@ // arguments count $zend_num_args = "ZEND_NUM_ARGS()"; - if (preg_match('~([a-zA-Z0-9_.]+)\\s*=\\s*ZEND_NUM_ARGS()~S', $function_body, $matches2)) { // int argc = ZEND_NUM_ARGS(); + if (preg_match('~([a-zA-Z0-9_.]+)\\s*=\\s*ZEND_NUM_ARGS()~', $function_body, $matches2)) { // int argc = ZEND_NUM_ARGS(); $zend_num_args = $matches2[1]; } $zend_num_args = preg_quote($zend_num_args, "~"); - if (preg_match("~^([ \t]+)switch\\s*\\(\\s*$zend_num_args\\s*\\)(.*)^\\1\\}~msSU", $function_body, $matches2) && preg_match('~\\bdefault\\s*:.*WRONG_PARAM_COUNT~sS', $matches2[2])) { + if (preg_match("~^([ \t]+)switch\\s*\\(\\s*$zend_num_args\\s*\\)(.*)^\\1\\}~msU", $function_body, $matches2) && preg_match('~\\bdefault\\s*:.*WRONG_PARAM_COUNT~s', $matches2[2])) { $source_arg_counts[$function_name] = array(array_fill(0, $max_args+1, true), $filename, $lineno); $source_arg_count =& $source_arg_counts[$function_name][0]; $switch = $matches2[2]; - preg_match_all('~\\bcase\\s+([0-9]+)\\s*:~S', $switch, $matches2); + preg_match_all('~\\bcase\\s+([0-9]+)\\s*:~', $switch, $matches2); foreach ($matches2[1] as $val) { unset($source_arg_count[$val]); } - } elseif (preg_match_all("~(?:([0-9]+)\\s*($operators)\\s*$zend_num_args|$zend_num_args\\s*($operators)\\s*([0-9]+))(?=[^}]+WRONG_PARAM_COUNT)~S", $function_body, $matches2, PREG_SET_ORDER)) { //! should differentiate between || and && + } elseif (preg_match_all("~(?:([0-9]+)\\s*($operators)\\s*$zend_num_args|$zend_num_args\\s*($operators)\\s*([0-9]+))(?=[^}]+WRONG_PARAM_COUNT)~", $function_body, $matches2, PREG_SET_ORDER)) { //! should differentiate between || and && $source_arg_counts[$function_name] = array(array(), $filename, $lineno); $source_arg_count =& $source_arg_counts[$function_name][0]
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Mon Apr 4 12:20:00 2005 EDT Modified files: /phpdoc/scripts check-references.php Log: & is obsolete http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.11&r2=1.12&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.11 phpdoc/scripts/check-references.php:1.12 --- phpdoc/scripts/check-references.php:1.11Fri Nov 19 05:17:56 2004 +++ phpdoc/scripts/check-references.php Mon Apr 4 12:20:00 2005 @@ -67,6 +67,8 @@ "msg_receive_args_force_ref" => array(3, 5, 8), "all_args_force_by_ref" => 1, "all_args_by_ref" => 1, + "http_request_info_ref_3" => array(3), + "http_request_info_ref_4" => array(4), ); $valid_types = "int|float|string|bool|resource|array|object|mixed|number"; @@ -240,10 +242,10 @@ // references $source_ref = (isset($source_refs[$function_name]) ? $source_refs[$function_name] : null); - preg_match_all('~(&)?~S', $methodsynopsis, $matches); + preg_match_all('~~S', $methodsynopsis, $matches); $byref = array(); foreach ($matches[1] as $key => $val) { - if ($val || $matches[2][$key]) { + if ($val) { $byref[] = $key + 1; } }
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Fri Nov 19 05:17:57 2004 EDT Modified files: /phpdoc/scripts check-references.php Log: Objects are written as appropriate class name http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.10&r2=1.11&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.10 phpdoc/scripts/check-references.php:1.11 --- phpdoc/scripts/check-references.php:1.10Thu Nov 11 09:55:24 2004 +++ phpdoc/scripts/check-references.php Fri Nov 19 05:17:56 2004 @@ -70,6 +70,7 @@ ); $valid_types = "int|float|string|bool|resource|array|object|mixed|number"; +$invalid_types = "integer|long|double|boolean|class"; // objects are written as appropriate class name so there is no complete list of valid types $operators = "!=|<=?|>=?|=="; $max_args = 12; // maximum number of regular function arguments @@ -233,7 +234,7 @@ $methodsynopsis = $matches[4]; // return type - if (!preg_match("~(void|$valid_types)~", $return_type)) { + if (preg_match("~(callback|$invalid_types)~", $return_type)) { echo "Wrong return type in $filename on line $lineno.\n"; } @@ -258,7 +259,7 @@ // parameter types and optional preg_match_all('~\\s*([^<]+)\\s*([^<]+)~i', $methodsynopsis, $matches); // (PREG_OFFSET_CAPTURE can be used to get precise line numbers) foreach ($matches[2] as $i => $val) { - if (!preg_match("~callback|$valid_types~", $val)) { + if (preg_match("~^(void|$invalid_types)\$~", $val)) { echo "Parameter #" . ($i+1) . " has wrong type '$val' in $filename on line " . ($lineno + $i + 1) . ".\n"; } } @@ -274,7 +275,7 @@ $optional_source = true; continue; } elseif (isset($matches[2][$i])) { // sufficient number of parameters in the documentation - if ($matches[2][$i] != $param && $param != "mixed") { + if ($matches[2][$i] != $param && $param != "mixed" && ($param != "object" || preg_match("~$valid_types~", $matches[2][$i]))) { $error .= "Parameter #" . ($i+1) . " should be of type $param (is " . $matches[2][$i] . ") in $filename on line " . ($lineno + $i + 1) . ".\n"; } if (!empty($matches[1][$i])) {
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Thu Nov 11 09:55:25 2004 EDT Modified files: /phpdoc/scripts check-references.php Log: Make current http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.9&r2=1.10&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.9 phpdoc/scripts/check-references.php:1.10 --- phpdoc/scripts/check-references.php:1.9 Fri Sep 10 09:39:06 2004 +++ phpdoc/scripts/check-references.php Thu Nov 11 09:55:24 2004 @@ -66,6 +66,7 @@ "sixth_arg_force_ref" => array(6), "msg_receive_args_force_ref" => array(3, 5, 8), "all_args_force_by_ref" => 1, + "all_args_by_ref" => 1, ); $valid_types = "int|float|string|bool|resource|array|object|mixed|number"; @@ -105,7 +106,7 @@ // some parameters should be passed only by reference but they are not forced to $wrong_refs = array("dbplus_info", "dbplus_next"); $difficult_params = array( - "ibase_blob_import", + "ibase_blob_import", "ibase_execute", "imagefilter", "mt_rand", "rand", "mcrypt_get_block_size", "mcrypt_get_key_size", "mcrypt_get_cipher_name", // inverse order
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Fri Sep 10 09:39:06 2004 EDT Modified files: /phpdoc/scripts check-references.php Log: Use role="reference" together with & http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.8&r2=1.9&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.8 phpdoc/scripts/check-references.php:1.9 --- phpdoc/scripts/check-references.php:1.8 Thu Aug 19 07:05:13 2004 +++ phpdoc/scripts/check-references.php Fri Sep 10 09:39:06 2004 @@ -134,7 +134,7 @@ $source_refs = array(); // array("function_name" => number_ref, ...) $source_types = array(); // array("function_name" => array("type_spec", filename, lineno), ...) $source_arg_counts = array(); // array("function_name" => array(disallowed_count => true, ...), ...) -foreach (array_merge(glob("$zend_dir/*.c*"), glob("$phpsrc_dir/ext/*/*.c*"), glob("$pecl_dir/*/*.c*")) as $filename) { +foreach (array_merge(glob("$zend_dir/*.c*"), glob("$phpsrc_dir/ext/*/*.c*"), glob("$phpsrc_dir/sapi/*/*.c*"), glob("$pecl_dir/*/*.c*")) as $filename) { $file = file_get_contents($filename); // references @@ -238,10 +238,10 @@ // references $source_ref = (isset($source_refs[$function_name]) ? $source_refs[$function_name] : null); - preg_match_all('~(&)?~S', $methodsynopsis, $matches); + preg_match_all('~(&)?~S', $methodsynopsis, $matches); $byref = array(); foreach ($matches[1] as $key => $val) { - if ($val) { + if ($val || $matches[2][$key]) { $byref[] = $key + 1; } } @@ -255,7 +255,7 @@ } // parameter types and optional - preg_match_all('~\\s*([^<]+)\\s*([^<]+)~i', $methodsynopsis, $matches); // (PREG_OFFSET_CAPTURE can be used to get precise line numbers) + preg_match_all('~\\s*([^<]+)\\s*([^<]+)~i', $methodsynopsis, $matches); // (PREG_OFFSET_CAPTURE can be used to get precise line numbers) foreach ($matches[2] as $i => $val) { if (!preg_match("~callback|$valid_types~", $val)) { echo "Parameter #" . ($i+1) . " has wrong type '$val' in $filename on line " . ($lineno + $i + 1) . ".\n";
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Thu Aug 19 07:05:13 2004 EDT Modified files: /phpdoc/scripts check-references.php Log: Print counts http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.7&r2=1.8&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.7 phpdoc/scripts/check-references.php:1.8 --- phpdoc/scripts/check-references.php:1.7 Wed Aug 18 11:30:24 2004 +++ phpdoc/scripts/check-references.php Thu Aug 19 07:05:13 2004 @@ -28,7 +28,7 @@ } if (!isset($_SERVER["argv"][1]) || !is_dir($phpdoc_dir)) { - echo "Purpose: Check parameters (types, optional, reference) from PHP sources.\n"; + echo "Purpose: Check parameters (types, optional, reference, count) from PHP sources.\n"; echo "Usage: check-references.php language\n"; echo "Notes:\n"; echo "- Functions not found in sources are checked as without references.\n"; @@ -125,7 +125,7 @@ ); $difficult_arg_count = array( "getdate", "min", "max", "implode", "strtok", "sybase_fetch_object", - "cpdf_text", "pdf_get_parameter", "odbc_exec", "odbc_result_all", "yaz_wait", + "cpdf_text", "pdf_get_parameter", "pg_fetch_assoc", "odbc_exec", "odbc_result_all", "yaz_wait", // take account of multiple methodsynopsis: "crack_check", "ibase_prepare", "mysqli_stmt_bind_param", "pg_fetch_result", "pg_put_line", "pg_query", "pg_set_client_encoding", "strtr", "yaz_set_option", ); @@ -179,7 +179,7 @@ foreach ($matches2[1] as $val) { unset($source_arg_count[$val]); } - } elseif (preg_match_all("~(?:([0-9]+)\\s*($operators)\\s*$zend_num_args|$zend_num_args\\s*($operators)\\s*([0-9]+))(?=[^{]+\\{[^}]+WRONG_PARAM_COUNT)~S", $function_body, $matches2, PREG_SET_ORDER)) { //! should differentiate between || and && + } elseif (preg_match_all("~(?:([0-9]+)\\s*($operators)\\s*$zend_num_args|$zend_num_args\\s*($operators)\\s*([0-9]+))(?=[^}]+WRONG_PARAM_COUNT)~S", $function_body, $matches2, PREG_SET_ORDER)) { //! should differentiate between || and && $source_arg_counts[$function_name] = array(array(), $filename, $lineno); $source_arg_count =& $source_arg_counts[$function_name][0]; foreach ($matches2 as $val) { @@ -220,6 +220,7 @@ echo "Sources were read.\n"; // compare with documentation +$counts = array("refs" => 0, "types" => 0, "arg_counts" => 0); foreach (glob("$phpdoc_dir/reference/*/functions/*.xml") as $filename) { if (preg_match('~^(.*(.*))([^<]+)<(.*)~sSU', file_get_contents($filename), $matches)) { $lineno = substr_count($matches[1], "\n") + 1; @@ -236,7 +237,7 @@ } // references - $source_ref =& $source_refs[$function_name]; + $source_ref = (isset($source_refs[$function_name]) ? $source_refs[$function_name] : null); preg_match_all('~(&)?~S', $methodsynopsis, $matches); $byref = array(); foreach ($matches[1] as $key => $val) { @@ -249,8 +250,9 @@ ) { echo (isset($source_ref) ? "Parameter(s) " . (is_int($source_ref) ? "$source_ref and rest" : implode(", ", $source_ref)) : "Nothing") . " should be passed by reference in $filename on line $lineno.\n"; } - $source_type =& $source_types[$function_name]; - $source_arg_count =& $source_arg_counts[$function_name]; + if (isset($source_ref)) { + $counts["refs"]++; + } // parameter types and optional preg_match_all('~\\s*([^<]+)\\s*([^<]+)~i', $methodsynopsis, $matches); // (PREG_OFFSET_CAPTURE can be used to get precise line numbers) @@ -259,7 +261,9 @@ echo "Parameter #" . ($i+1) . " has wrong type '$val' in $filename on line " . ($lineno + $i + 1) . ".\n"; } } - if (isset($source_type)) { + if (isset($source_types[$function_name])) { + $source_type =& $source_types[$function_name]; + $counts["types"]++; $optional_source = false; $optional_doc = false; $i = 0; @@ -289,7 +293,9 @@ } // arguments count - } elseif (isset($source_arg_count)) { + } elseif (isset($source_arg_counts[$function_name])) { + $source_arg_count =& $source_arg_counts[$function_name]; + $counts["arg_counts"]++; $disallowed = array(); foreach ($
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Wed Aug 18 11:30:24 2004 EDT Modified files: /phpdoc/scripts check-references.php Log: Recognize switch (ZEND_NUM_ARGS()) http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.6&r2=1.7&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.6 phpdoc/scripts/check-references.php:1.7 --- phpdoc/scripts/check-references.php:1.6 Wed Aug 18 10:25:39 2004 +++ phpdoc/scripts/check-references.php Wed Aug 18 11:30:24 2004 @@ -124,8 +124,10 @@ "fdf_set_on_import_javascript", ); $difficult_arg_count = array( - "getdate", "min", "max", "mysqli_stmt_bind_param", "pg_fetch_result", "implode", "strtok", "strtr", "sybase_fetch_object", - "cpdf_text", "muscat_setup", "pdf_get_parameter", "odbc_exec", "odbc_result_all", "yaz_set_option", "yaz_wait", + "getdate", "min", "max", "implode", "strtok", "sybase_fetch_object", + "cpdf_text", "pdf_get_parameter", "odbc_exec", "odbc_result_all", "yaz_wait", + // take account of multiple methodsynopsis: + "crack_check", "ibase_prepare", "mysqli_stmt_bind_param", "pg_fetch_result", "pg_put_line", "pg_query", "pg_set_client_encoding", "strtr", "yaz_set_option", ); // read referenced parameters from sources @@ -152,11 +154,12 @@ foreach ($matches as $val) { $function_name = strtolower(trim($val[1][0])); $lineno = substr_count(substr($file, 0, $val[2][1]), "\n") + 1; + $function_body = $val[2][0]; // types and optional if (!in_array($function_name, $difficult_params) - && strpos($val[2][0], 'zend_parse_parameters_ex') === false // indicate difficulty - && preg_match('~.*zend_parse_parameters\\([^,]*,\\s*"([^"]*)"~sS', $val[2][0], $matches2) // .* to catch last occurence + && strpos($function_body, 'zend_parse_parameters_ex') === false // indicate difficulty + && preg_match('~.*zend_parse_parameters\\([^,]*,\\s*"([^"]*)"~sS', $function_body, $matches2) // .* to catch last occurence // zend_parse_method_parameters is not yet supported ) { $source_types[$function_name] = array($matches2[1], $filename, $lineno); @@ -164,12 +167,19 @@ // arguments count $zend_num_args = "ZEND_NUM_ARGS()"; - if (preg_match('~([a-zA-Z0-9_.]+)\\s*=\\s*ZEND_NUM_ARGS()~', $val[2][0], $matches2)) { // int argc = ZEND_NUM_ARGS(); + if (preg_match('~([a-zA-Z0-9_.]+)\\s*=\\s*ZEND_NUM_ARGS()~S', $function_body, $matches2)) { // int argc = ZEND_NUM_ARGS(); $zend_num_args = $matches2[1]; } $zend_num_args = preg_quote($zend_num_args, "~"); - //! should differentiate between || and && - if (preg_match_all("~(?:([0-9]+)\\s*($operators)\\s*$zend_num_args|$zend_num_args\\s*($operators)\\s*([0-9]+))(?=[^{]+\\{[^}]+WRONG_PARAM_COUNT)~S", $val[2][0], $matches2, PREG_SET_ORDER)) { + if (preg_match("~^([ \t]+)switch\\s*\\(\\s*$zend_num_args\\s*\\)(.*)^\\1\\}~msSU", $function_body, $matches2) && preg_match('~\\bdefault\\s*:.*WRONG_PARAM_COUNT~sS', $matches2[2])) { + $source_arg_counts[$function_name] = array(array_fill(0, $max_args+1, true), $filename, $lineno); + $source_arg_count =& $source_arg_counts[$function_name][0]; + $switch = $matches2[2]; + preg_match_all('~\\bcase\\s+([0-9]+)\\s*:~S', $switch, $matches2); + foreach ($matches2[1] as $val) { + unset($source_arg_count[$val]); + } + } elseif (preg_match_all("~(?:([0-9]+)\\s*($operators)\\s*$zend_num_args|$zend_num_args\\s*($operators)\\s*([0-9]+))(?=[^{]+\\{[^}]+WRONG_PARAM_COUNT)~S", $function_body, $matches2, PREG_SET_ORDER)) { //! should differentiate between || and && $source_arg_counts[$function_name] = array(array(), $filename, $lineno); $source_arg_count =& $source_arg_counts[$function_name][0]; foreach ($matches2 as $val) { @@ -183,9 +193,11 @@ } unset($source_arg_count[$number]); break; - case "=": // old version + /* old version + case "=": $source_arg_count[$number] = true;
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Fri Aug 13 12:08:52 2004 EDT Modified files: /phpdoc/scripts check-references.php Log: Check return and parameter types http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.4&r2=1.5&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.4 phpdoc/scripts/check-references.php:1.5 --- phpdoc/scripts/check-references.php:1.4 Fri Aug 13 08:05:16 2004 +++ phpdoc/scripts/check-references.php Fri Aug 13 12:08:52 2004 @@ -68,6 +68,8 @@ "all_args_force_by_ref" => 1, ); +$valid_types = "int|float|string|bool|resource|array|object|mixed|number"; + // convert source formatting to document types, built from ZendAPI/zend.arguments.retrieval and howto/chapter-conventions function params_source_to_doc($type_spec) { @@ -99,7 +101,7 @@ } // some parameters should be passed only by reference but they are not forced to -$wrong_source = array("dbplus_info", "dbplus_next", "xdiff_string_merge3", "xdiff_string_patch"); +$wrong_source = array("dbplus_info", "dbplus_next"); $difficult_params = array( "ibase_blob_import", "imagefilter", @@ -152,14 +154,21 @@ // compare with documentation foreach (glob("$phpdoc_dir/reference/*/functions/*.xml") as $filename) { - if (preg_match('~^(.*.*)([^<]+)<(.*)~sSU', file_get_contents($filename), $matches)) { + if (preg_match('~^(.*(.*))([^<]+)<(.*)~sSU', file_get_contents($filename), $matches)) { $lineno = substr_count($matches[1], "\n") + 1; - $function_name = strtolower(trim($matches[2])); + $return_type = $matches[2]; + $function_name = strtolower(trim($matches[3])); if (strpos($function_name, '-') || strpos($function_name, ':')) { continue; // methods are not supported } - $methodsynopsis = $matches[3]; + $methodsynopsis = $matches[4]; + + // return type + if (!preg_match("~(void|$valid_types)~", $return_type)) { + echo "Wrong return type in $filename on line $lineno.\n"; + } + // references $source_ref =& $source_refs[$function_name]; preg_match_all('~(&)?~S', $methodsynopsis, $matches); $byref = array(); @@ -174,9 +183,15 @@ echo (isset($source_ref) ? "Parameter(s) " . (is_int($source_ref) ? "$source_ref and rest" : implode(", ", $source_ref)) : "Nothing") . " should be passed by reference in $filename on line $lineno.\n"; } + // parameter types and optional + preg_match_all('~\\s*([^<]+)~i', $methodsynopsis, $matches); // (PREG_OFFSET_CAPTURE can be used to get precise line numbers) + foreach ($matches[2] as $i => $val) { + if (!preg_match("~callback|$valid_types~", $val)) { + echo "Parameter #" . ($i+1) . " has wrong type '$val' in $filename on line " . ($lineno + $i + 1) . ".\n"; + } + } $source_type =& $source_types[$function_name]; if (isset($source_type)) { - preg_match_all('~\\s*([^<]+)~i', $methodsynopsis, $matches); // (PREG_OFFSET_CAPTURE can be used to get precise line numbers) $optional_source = false; $optional_doc = false; $i = 0;
Re: [PHP-DOC] cvs: phpdoc /scripts check-references.php
New version checking parameters (types, optional) in functions using zend_parse_parameters() I wrote a new version of the script comparing documentation with the sources. It now checks the types of parameters and which parameters are optional. It checks majority of functions which use zend_parse_parameters(). I run the script and adjusted documentation where possible. There are some TODOs: Document cwd, env, other_options and when they appeared in proc_open(). Document class_name and when it appeared in simplexml*(). Document phones and when it appeared in metaphone(). So if anybody is interested... Great! It would be nice to merge this with the other checking scripts. Goba
Re: [PHP-DOC] cvs: phpdoc /scripts check-references.php
Jakub Vrana wrote: > New version checking parameters (types, optional) in functions using > zend_parse_parameters() I wrote a new version of the script comparing documentation with the sources. It now checks the types of parameters and which parameters are optional. It checks majority of functions which use zend_parse_parameters(). I run the script and adjusted documentation where possible. There are some TODOs: Document cwd, env, other_options and when they appeared in proc_open(). Document class_name and when it appeared in simplexml*(). Document phones and when it appeared in metaphone(). So if anybody is interested... Jakub Vrana
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Thu Aug 12 14:10:52 2004 EDT Modified files: /phpdoc/scripts check-references.php Log: New version checking parameters (types, optional) in functions using zend_parse_parameters() http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.2&r2=1.3&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.2 phpdoc/scripts/check-references.php:1.3 --- phpdoc/scripts/check-references.php:1.2 Wed Aug 4 03:46:36 2004 +++ phpdoc/scripts/check-references.php Thu Aug 12 14:10:51 2004 @@ -28,9 +28,11 @@ } if (!isset($_SERVER["argv"][1]) || !is_dir($phpdoc_dir)) { - echo "Purpose: Check parameters passed by reference from PHP sources.\n"; + echo "Purpose: Check parameters (types, optional, reference) from PHP sources.\n"; echo "Usage: check-references.php language\n"; - echo "Note: Functions not found in sources are not checked.\n"; + echo "Notes:\n"; + echo "- Functions not found in sources are checked as without references.\n"; + echo "- Types and optional params are checked only in some functions.\n"; exit(); } @@ -52,6 +54,7 @@ "secondandthird_args_force_ref" => array(2, 3), "first_arg_force_ref" => array(1), "first_args_force_ref" => array(1), + "first_argument_force_ref" => array(1), "firstandsecond_args_force_ref" => array(1, 2), "arg2and3_force_ref" => array(2, 3), "first_through_third_args_force_ref" => array(1, 2, 3), @@ -65,11 +68,62 @@ "all_args_force_by_ref" => 1, ); +// convert source formatting to document types, built from ZendAPI/zend.arguments.retrieval and howto/chapter-conventions +function params_source_to_doc($type_spec) +{ + static $zend_params = array( + "l" => "int", + "d" => "float", + "s" => "string", + "b" => "bool", + "r" => "resource", + "a" => "array", + "o" => "object", + "O" => "object", + "z" => "mixed", + "Z" => "mixed", + "|" => "optional" + ); + $return = array(); + for ($i=0; $i < strlen($type_spec); $i++) { + $ch = $type_spec{$i}; + if ($ch != "/" && $ch != "!") { + if (!isset($zend_params[$ch])) { + echo "! Unknown formatting specifier '$ch' in '$type_spec'.\n"; + $zend_params[$ch] = "unknown"; + } + $return[] = $zend_params[$ch]; + } + } + return $return; +} + // some parameters should be passed only by reference but they are not forced to -$wrong_source = array("dbplus_info", "dbplus_next", "php_check_syntax", "xdiff_string_merge3", "xdiff_string_patch"); +$wrong_source = array("dbplus_info", "dbplus_next", "xdiff_string_merge3", "xdiff_string_patch"); +$difficult_params = array( + "ibase_blob_import", + "imagefilter", + "mt_rand", "rand", + "mcrypt_get_block_size", "mcrypt_get_key_size", "mcrypt_get_cipher_name", // inverse order + "mysql_ping", + "pdf_get_parameter", + "tidy_getopt", // uses zend_parse_method_parameters + // better to fix in sources: + "imagepstext", + "ncurses_keyok", "ncurses_use_env", "ncurses_use_extended_names", + "openssl_x509_export_to_file", "openssl_x509_export", + "snmp_set_quick_print", + "tcpwrap_check", + "get_headers", + "wddx_packet_end", + "pdf_add_bookmark", "pdf_findfont", "pdf_get_value", "pdf_open_file", "pdf_open_image_file", "pdf_setcolor", "pdf_show_boxed", "pdf_stringwidth", + "apd_echo", + "fdf_set_on_import_javascript", +); // read referenced parameters from sources -$source_refs = array(); +$source_refs = array(); // array("function_name" => number_ref, ...) +$source_types = array(); // array("function_name" => array("type_spec", filename, lineno), ...) foreach (array_merge(glob("$zend_dir/*.c*"), glob("$phpsrc_dir/ext/*/*.c*"), glob("$pecl_dir/*/*.c*")) as $filename) { $file = file_get_contents($filename); preg_match_all("~^[ \t]*(?:ZEND|PHP)_FE\\((\\w+)\\s*,\\s*(\\w+)\\s*[,)]~mS", $file, $matches, PREG_SET_ORDER); @@ -82,17 +136,31 @@ $source_refs[strtolower($val[1])] = $number_refs[$val[2]]; } } + // read parameters + preg_match_all('~^(?:ZEND|PHP)(?:_NAMED)?_FUNCTION\\(([^)]+)\\)(.*)^\\}~msSU', $file, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE); // }}} is not in all sources so ^} is used instead + foreach ($matches as $val) { + $function_name = strtolower(trim($val[1][0])); + if (!in_array($function_name, $difficult_params) + && strpos($val[2][0], 'zend_parse_parameters_ex') === false // indicate difficul
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Wed Aug 4 03:46:36 2004 EDT Modified files: /phpdoc/scripts check-references.php Log: Parse only first synopsis, ignore methods http://cvs.php.net/diff.php/phpdoc/scripts/check-references.php?r1=1.1&r2=1.2&ty=u Index: phpdoc/scripts/check-references.php diff -u phpdoc/scripts/check-references.php:1.1 phpdoc/scripts/check-references.php:1.2 --- phpdoc/scripts/check-references.php:1.1 Tue Aug 3 13:29:22 2004 +++ phpdoc/scripts/check-references.php Wed Aug 4 03:46:36 2004 @@ -72,12 +72,12 @@ $source_refs = array(); foreach (array_merge(glob("$zend_dir/*.c*"), glob("$phpsrc_dir/ext/*/*.c*"), glob("$pecl_dir/*/*.c*")) as $filename) { $file = file_get_contents($filename); - preg_match_all('~^\\s*(?:ZEND|PHP)_FE\\((\\w+)\\s*,\\s*(\\w+)\\s*[,)]~mS', $file, $matches, PREG_SET_ORDER); - preg_match_all('~^\\s*(?:ZEND|PHP)_FALIAS\\((\\w+)\\s*,[^,]+,\\s*(\\w+)\\s*[,)]~mS', $file, $matches2, PREG_SET_ORDER); + preg_match_all("~^[ \t]*(?:ZEND|PHP)_FE\\((\\w+)\\s*,\\s*(\\w+)\\s*[,)]~mS", $file, $matches, PREG_SET_ORDER); + preg_match_all("~^[ \t]*(?:ZEND|PHP)_FALIAS\\((\\w+)\\s*,[^,]+,\\s*(\\w+)\\s*[,)]~mS", $file, $matches2, PREG_SET_ORDER); foreach (array_merge($matches, $matches2) as $val) { if ($val[2] != "NULL") { if (empty($number_refs[$val[2]])) { - echo "! $val[2] in $filename is not defined.\n"; + echo "! $val[2] from $filename is not defined.\n"; } $source_refs[strtolower($val[1])] = $number_refs[$val[2]]; } @@ -86,9 +86,12 @@ // compare with documentation foreach (glob("$phpdoc_dir/reference/*/functions/*.xml") as $filename) { - if (preg_match('~^(.*.*)([^<]*)(.*)~sS', file_get_contents($filename), $matches)) { + if (preg_match('~^(.*.*)([^<]+)<(.*)~sSU', file_get_contents($filename), $matches)) { $lineno = substr_count($matches[1], "\n"); $function_name = strtolower($matches[2]); + if (strpos($function_name, '-') || strpos($function_name, ':')) { + continue; // methods are not supported + } $methodsynopsis = $matches[3]; $source_ref =& $source_refs[$function_name]; preg_match_all('~(&)?~S', $methodsynopsis, $matches);
[PHP-DOC] cvs: phpdoc /scripts check-references.php
vrana Tue Aug 3 13:29:22 2004 EDT Added files: /phpdoc/scripts check-references.php Log: Check parameters passed by reference from PHP sources http://cvs.php.net/co.php/phpdoc/scripts/check-references.php?r=1.1&p=1 Index: phpdoc/scripts/check-references.php +++ phpdoc/scripts/check-references.php #!/usr/bin/php http://www.php.net/license/3_0.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [EMAIL PROTECTED] so we can mail you a copy immediately. | +--+ | Authors:Jakub Vrána <[EMAIL PROTECTED]> | +--+ */ if (isset($_SERVER["argv"][1])) { $lang = $_SERVER["argv"][1]; $scripts_dir = dirname(__FILE__); $phpsrc_dir = realpath("$scripts_dir/../../php-src"); $pecl_dir = realpath("$scripts_dir/../../pecl"); $zend_dir = realpath("$scripts_dir/../../ZendEngine2"); $phpdoc_dir = realpath("$scripts_dir/../$lang"); } if (!isset($_SERVER["argv"][1]) || !is_dir($phpdoc_dir)) { echo "Purpose: Check parameters passed by reference from PHP sources.\n"; echo "Usage: check-references.php language\n"; echo "Note: Functions not found in sources are not checked.\n"; exit(); } // various names for parameters passed by reference // array() means list of parameters, number is position from which all parameters are passed by reference $number_refs = array( "second_arg_force_ref" => array(2), "second_args_force_ref" => array(2), "second_argument_force_ref" => array(2), "exif_thumbnail_force_ref" => array(2, 3, 4), "third_and_rest_force_ref" => 3, "third_arg_force_ref" => array(3), "third_args_force_ref" => array(3), "third_argument_force_ref" => array(3), "third_arg_force_by_ref_rest" => 3, "second_arg_force_by_ref_rest" => 2, "arg3to6of6_force_ref" => array(3, 4, 5, 6), "second_thru_fourth_args_force_ref" => array(2, 3, 4), "secondandthird_args_force_ref" => array(2, 3), "first_arg_force_ref" => array(1), "first_args_force_ref" => array(1), "firstandsecond_args_force_ref" => array(1, 2), "arg2and3_force_ref" => array(2, 3), "first_through_third_args_force_ref" => array(1, 2, 3), "fourth_arg_force_ref" => array(4), "second_and_third_args_force_ref" => array(2, 3), "second_fifth_and_sixth_args_force_ref" => array(2, 5, 6), "first_and_second__args_force_ref" => array(1, 2), "third_and_fourth_args_force_ref" => array(3, 4), "sixth_arg_force_ref" => array(6), "msg_receive_args_force_ref" => array(3, 5, 8), "all_args_force_by_ref" => 1, ); // some parameters should be passed only by reference but they are not forced to $wrong_source = array("dbplus_info", "dbplus_next", "php_check_syntax", "xdiff_string_merge3", "xdiff_string_patch"); // read referenced parameters from sources $source_refs = array(); foreach (array_merge(glob("$zend_dir/*.c*"), glob("$phpsrc_dir/ext/*/*.c*"), glob("$pecl_dir/*/*.c*")) as $filename) { $file = file_get_contents($filename); preg_match_all('~^\\s*(?:ZEND|PHP)_FE\\((\\w+)\\s*,\\s*(\\w+)\\s*[,)]~mS', $file, $matches, PREG_SET_ORDER); preg_match_all('~^\\s*(?:ZEND|PHP)_FALIAS\\((\\w+)\\s*,[^,]+,\\s*(\\w+)\\s*[,)]~mS', $file, $matches2, PREG_SET_ORDER); foreach (array_merge($matches, $matches2) as $val) { if ($val[2] != "NULL") { if (empty($number_refs[$val[2]])) { echo "! $val[2] in $filename is not defined.\n"; } $source_refs[strtolower($val[1])] = $number_refs[$val[2]]; } } } // compare with documentation foreach (glob("$phpdoc_dir/reference/*/functions/*.xml") as $filename) { if (preg_match('~^(.*.*)([^<]*)(.*)~sS', file_get_contents($filename), $matches)) { $lineno = substr_count($matches[1], "\n"); $function_name = strtolower($matches[2]); $methodsynopsis = $matches[3]; $source_ref =& $source_refs[$function_name]; preg_match_all('~(&)?~S', $methodsynopsis, $matches); $byref = array(); foreach ($matches[1] as $key => $val) { if ($val) { $byref[] = $key + 1; } } if (is_int($source_ref) && $byref[0] == $source_ref && count($byref) == count($matches[1]) - $source_ref + 1) { $byref = $source_ref; }