Index: trunk/tools/code-utils/check-vars.php |
— | — | @@ -10,6 +10,9 @@ |
11 | 11 | require_once( dirname( __FILE__ ) . "/../../phase3/includes/Defines.php" ); # Faster than parsing |
12 | 12 | require_once( dirname( __FILE__ ) . "/../../phase3/includes/AutoLoader.php" ); |
13 | 13 | |
| 14 | +$mwDeprecatedFunctions = false; |
| 15 | +@include( dirname( __FILE__ ) . "/deprecated.functions" ); |
| 16 | + |
14 | 17 | if ( !extension_loaded( 'sockets' ) ) dl('sockets.so'); |
15 | 18 | if ( !extension_loaded( 'PDO' ) ) dl('pdo.so'); |
16 | 19 | |
— | — | @@ -42,6 +45,7 @@ |
43 | 46 | static $mDefaultSettingsGlobals = null; |
44 | 47 | |
45 | 48 | static $constantIgnorePrefixes = array( "PGSQL_", "OCI_", "SQLT_BLOB", "DB2_", "XMLREADER_" ); # Ignore constants with these prefixes |
| 49 | + protected $generateDeprecatedList = false; |
46 | 50 | |
47 | 51 | /* Values for status */ |
48 | 52 | const WAITING_FUNCTION = 0; |
— | — | @@ -54,7 +58,11 @@ |
55 | 59 | const CLASS_NAME = -4; |
56 | 60 | const CLASS_MEMBER = -5; |
57 | 61 | const FUNCTION_NAME = -6; |
| 62 | + const FUNCTION_DEFINITION = -7; |
58 | 63 | |
| 64 | + /* Function attribute */ |
| 65 | + const FUNCTION_DEPRECATED = -8; |
| 66 | + |
59 | 67 | function __construct() { |
60 | 68 | if ( self::$mDefaultSettingsGlobals == null ) { |
61 | 69 | $this->load( dirname( dirname( dirname( __FILE__ ) ) ) . "/phase3/includes/DefaultSettings.php", false ); |
— | — | @@ -114,6 +122,17 @@ |
115 | 123 | } |
116 | 124 | } |
117 | 125 | |
| 126 | + function setGenerateDeprecatedList( $bool = true ) { |
| 127 | + $this->generateDeprecatedList = $bool; |
| 128 | + } |
| 129 | + function getGenerateDeprecatedList() { |
| 130 | + return $this->generateDeprecatedList; |
| 131 | + } |
| 132 | + function saveDeprecatedList( $filename ) { |
| 133 | + file_put_contents( $filename, "<?php\n\$mwDeprecatedFunctions = array( " . implode( ",\n\t", $this->mDeprecatedFunctionList ) . "\n);\n\n" ); |
| 134 | + } |
| 135 | + |
| 136 | + |
118 | 137 | function load($file, $shortcircuit = true) { |
119 | 138 | $this->mProblemCount = 0; |
120 | 139 | $this->mFilename = $file; |
— | — | @@ -182,6 +201,11 @@ |
183 | 202 | if ( $token == ';' ) |
184 | 203 | $this->mFunctionQualifiers = array(); |
185 | 204 | |
| 205 | + if ( $token[0] == T_DOC_COMMENT ) { |
| 206 | + if ( strpos( $token[1], '@deprecated' ) !== false ) { |
| 207 | + $this->mFunctionQualifiers[] = self::FUNCTION_DEPRECATED; |
| 208 | + } |
| 209 | + } |
186 | 210 | if ( in_array( $token[0], self::$functionQualifiers ) ) { |
187 | 211 | $this->mFunctionQualifiers[] = $token[0]; |
188 | 212 | } |
— | — | @@ -191,6 +215,7 @@ |
192 | 216 | |
193 | 217 | if ( ( $lastMeaningfulToken[0] == T_CLASS ) && ( $token[0] == T_STRING ) ) { |
194 | 218 | $this->mKnownFileClasses[] = $token[1]; |
| 219 | + $this->mClass = $token[1]; |
195 | 220 | } |
196 | 221 | |
197 | 222 | if ($token[0] != T_FUNCTION) |
— | — | @@ -206,7 +231,14 @@ |
207 | 232 | $this->mStatus = self::IN_FUNCTION; |
208 | 233 | $this->mBraces = 0; |
209 | 234 | $this->mFunctionGlobals = array(); |
| 235 | + $currentToken[0] = self::FUNCTION_DEFINITION; |
210 | 236 | |
| 237 | + if ( $this->generateDeprecatedList && in_array( self::FUNCTION_DEPRECATED, $this->mFunctionQualifiers ) ) { |
| 238 | + if ( ( substr( $this->mFunction, 0, 2 ) != "__" ) && $this->mClass != 'Image' ) { |
| 239 | + $this->mDeprecatedFunctionList[] = "/*$this->mClass::*/'$this->mFunction'"; |
| 240 | + } |
| 241 | + } |
| 242 | + |
211 | 243 | $this->debug("Entering into function {$token[1]} at line {$token[2]} "); |
212 | 244 | continue; |
213 | 245 | } |
— | — | @@ -267,7 +299,7 @@ |
268 | 300 | # Bug of r69904 |
269 | 301 | $this->warning("$lastMeaningfulToken[1]:: used in line $lastMeaningfulToken[2] It probably should have been " . substr( $lastMeaningfulToken[1], 1 ) . "::"); |
270 | 302 | } |
271 | | - } elseif ( ( $token[0] == T_STRING ) && ( is_array($lastMeaningfulToken) |
| 303 | + } elseif ( ( $token[0] == T_STRING ) && ( is_array( $lastMeaningfulToken) |
272 | 304 | && in_array( $lastMeaningfulToken[0], array( T_OBJECT_OPERATOR, T_PAAMAYIM_NEKUDOTAYIM ) ) ) ) { |
273 | 305 | # Class member or class constant |
274 | 306 | $currentToken[0] = self::CLASS_MEMBER; |
— | — | @@ -279,8 +311,13 @@ |
280 | 312 | } |
281 | 313 | } |
282 | 314 | |
283 | | - if ( ( $token == '(' ) && is_array( $lastMeaningfulToken ) && ( $lastMeaningfulToken[0] == T_STRING ) ) { |
284 | | - $lastMeaningfulToken[0] = self::FUNCTION_NAME; |
| 315 | + if ( ( $token == '(' ) && is_array( $lastMeaningfulToken ) ) { |
| 316 | + if ( $lastMeaningfulToken[0] == T_STRING ) { |
| 317 | + $lastMeaningfulToken[0] = self::FUNCTION_NAME; |
| 318 | + $this->checkDeprecation($lastMeaningfulToken); |
| 319 | + } else if ( $lastMeaningfulToken[0] == self::CLASS_MEMBER) { |
| 320 | + $this->checkDeprecation($lastMeaningfulToken); |
| 321 | + } |
285 | 322 | } |
286 | 323 | |
287 | 324 | /* Detect constants */ |
— | — | @@ -342,6 +379,13 @@ |
343 | 380 | $this->checkPendingClasses(); |
344 | 381 | } |
345 | 382 | |
| 383 | + function checkDeprecation( $token ) { |
| 384 | + global $mwDeprecatedFunctions; |
| 385 | + if ( $mwDeprecatedFunctions && !in_array( self::FUNCTION_DEPRECATED, $this->mFunctionQualifiers ) && in_array( $token[1], $mwDeprecatedFunctions ) ) { |
| 386 | + $this->warning( "Non deprecated function $this->mFunction calls deprecated function {$token[1]} in line {$token[2]}" ); |
| 387 | + } |
| 388 | + } |
| 389 | + |
346 | 390 | function error( $token ) { |
347 | 391 | $msg = "Unexpected token " . ( is_string( $token ) ? $token : token_name( $token[0] ) ) ; |
348 | 392 | if ( is_array( $token ) && isset( $token[2] ) ) { |
— | — | @@ -458,7 +502,14 @@ |
459 | 503 | //$cv->mDebug = true; |
460 | 504 | |
461 | 505 | array_shift($argv); |
| 506 | +if ( $argv[0] == '--generate-deprecated-list' ) { |
| 507 | + $cv->setGenerateDeprecatedList( true ); |
| 508 | + array_shift( $argv ); |
| 509 | +} |
462 | 510 | foreach ( $argv as $arg ) { |
463 | 511 | $cv->load( $arg ); |
464 | 512 | $cv->execute(); |
465 | 513 | } |
| 514 | +if ( $cv->getGenerateDeprecatedList( ) ) { |
| 515 | + $cv->saveDeprecatedList( dirname( __FILE__ ) . "/deprecated.functions" ); |
| 516 | +} |