r81912 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81911‎ | r81912 | r81913 >
Date:19:05, 10 February 2011
Author:platonides
Status:deferred
Tags:
Comment:
Added support to detect functions with wfProfileIn() calls that end without wfProfileOut()
Fixed bug in generated deprecated.functions
Fixed bug recording parents
Fixed bug traversing parents
Modified paths:
  • /trunk/tools/code-utils/check-vars.php (modified) (history)

Diff [purge]

Index: trunk/tools/code-utils/check-vars.php
@@ -13,7 +13,7 @@
1414 require_once( "$IP/includes/Defines.php" ); # Faster than parsing
1515 require_once( "$IP/includes/AutoLoader.php" );
1616 $wgAutoloadClasses = &$wgAutoloadLocalClasses;
17 -require_once( "$IP/tests/TestsAutoLoader.php" );
 17+include_once( "$IP/tests/TestsAutoLoader.php" );
1818
1919 $mwDeprecatedFunctions = false;
2020 @include( dirname( __FILE__ ) . "/deprecated.functions" );
@@ -201,7 +201,7 @@
202202 function saveDeprecatedList( $filename ) {
203203 $data = "<?php\n\$mwDeprecatedFunctions = array(\n";
204204 foreach( $this->mDeprecatedFunctionList as $depre => $classes ) {
205 - $data .= "\t'$depre' => array( " . implode( ", ", $classes ) . " ),\n";
 205+ $data .= "\t'$depre' => array( '" . implode( "', '", $classes ) . "' ),\n";
206206 }
207207 $data .= "\n);\n\n";
208208 file_put_contents( $filename, $data );
@@ -217,7 +217,7 @@
218218 global $mwParentClasses;
219219 $data = "<?php\n\$mwParentClasses = array(\n";
220220 foreach( $mwParentClasses as $class => $parent ) {
221 - $data .= "\t'$class' => '$parent' ),\n";
 221+ $data .= "\t'$class' => '$parent' ,\n";
222222 }
223223 $data .= "\n);\n\n";
224224 file_put_contents( $filename, $data );
@@ -348,6 +348,7 @@
349349 $this->checkClassName( $token );
350350 $this->mParent = $token[1];
351351 if ( $this->getGenerateParentList() ) {
 352+ global $mwParentClasses;
352353 $mwParentClasses[ $this->mClass ] = $this->mParent;
353354 }
354355 }
@@ -371,6 +372,8 @@
372373 $this->mStatus = self::IN_FUNCTION;
373374 $this->mBraces = 0;
374375 $this->mInSwitch = 0;
 376+ $this->mInProfilingFunction = false;
 377+ $this->mAfterProfileOut = 0;
375378 $this->mFunctionGlobals = array();
376379 $currentToken[0] = self::FUNCTION_DEFINITION;
377380 $this->mKnownFunctions[] = $this->mClass ? $this->mClass . "::" . $this->mFunction : $this->mFunction;
@@ -409,9 +412,22 @@
410413
411414 $this->purgeGlobals();
412415 if ( ! $this->mBraces ) {
 416+ if ( $this->mInProfilingFunction && $this->mAfterProfileOut & 1 ) {
 417+ $this->warning( "Reached end of $this->mClass::$this->mFunction with last statement not being wfProfileOut" );
 418+ }
 419+
413420 $this->mStatus = self::WAITING_FUNCTION;
414421 $this->mFunctionQualifiers = array();
415422 }
 423+ } elseif ( $token == ';' && $this->mInProfilingFunction ) {
 424+ // Check that there's just a return after wfProfileOut.
 425+ if ( $this->mAfterProfileOut == 1 ) {
 426+ $this->mAfterProfileOut = 2;
 427+ } elseif ( $this->mAfterProfileOut == 2 ) {
 428+ // Set to 3 in order to bail out at the return.
 429+ // This way we don't complay about missing return in internal wfProfile sections.
 430+ $this->mAfterProfileOut = 3;
 431+ }
416432 } elseif ( is_array ( $token ) ) {
417433 if ( $token[0] == T_GLOBAL ) {
418434 $this->mStatus = self::IN_GLOBAL;
@@ -443,6 +459,12 @@
444460 $this->warning( "{$token[1]} is used as local variable in line $token[2], function {$this->mFunction}" );
445461 }
446462 }
 463+ } elseif ( $token[0] == T_RETURN && $this->mInProfilingFunction ) {
 464+ if ( $this->mAfterProfileOut == 2 ) {
 465+ $this->mAfterProfileOut = 0;
 466+ } else {
 467+ $this->warning( "$token[1] in line $token[2] is not preceded by wfProfileOut" );
 468+ }
447469 } elseif ( $token[0] == T_FUNCTION ) {
448470 $this->warning( "Uh? Function inside function? A lamda function?" );
449471 $this->error( $token );
@@ -472,7 +494,7 @@
473495
474496 if ( self::isMeaningfulToken( $token ) && ( $lastMeaningfulToken[0] == T_THROW ) ) {
475497 if ( $token[0] == T_VARIABLE ) {
476 - // Probbly rethrowing from a catch, skip
 498+ // Probably rethrowing from a catch, skip
477499 } elseif ( $token[0] == T_NEW ) {
478500 // Correct, a new class instance
479501 // TODO: Verify it inherits from Exception
@@ -501,6 +523,19 @@
502524 $lastMeaningfulToken[0] = self::FUNCTION_NAME;
503525 $this->checkDeprecation( $lastMeaningfulToken );
504526 $this->checkFunctionName( $lastMeaningfulToken );
 527+ if ( $lastMeaningfulToken[1] == 'wfProfileIn' ) {
 528+ $this->mInProfilingFunction = true;
 529+ $this->mAfterProfileOut = 0;
 530+ } elseif ( $lastMeaningfulToken[1] == 'wfProfileOut' ) {
 531+ global $mwParentClasses;//echo "wfProfileOut $this->mClass " . ( isset( $mwParentClasses[ $this->mClass ] ) ? $mwParentClasses[ $this->mClass ] : "" ). "\n";
 532+ if ( ( isset( $mwParentClasses[ $this->mClass ] ) && $mwParentClasses[ $this->mClass ] == 'ImageHandler') ||
 533+ ( $this->mClass == 'Hooks' && $this->mFunction == 'run' ) ) {
 534+ // Do not treat as profiling any more. ImageHandler sons have profile sections just for their wfShellExec(). wfRunHooks profiles each hook.
 535+ $this->mInProfilingFunction = false;
 536+ } else {
 537+ $this->mAfterProfileOut = 1;
 538+ }
 539+ }
505540 } else if ( $lastMeaningfulToken[0] == self::CLASS_MEMBER ) {
506541 $this->checkDeprecation( $lastMeaningfulToken );
507542 }
@@ -701,7 +736,7 @@
702737 if ( !isset( $mwParentClasses[ $class ] ) ) {
703738 return;
704739 }
705 - $class = $parentClasses[ $class ];
 740+ $class = $mwParentClasses[ $class ];
706741 } while( true );
707742 } else if ( isset( $token['base'] ) ) { # Avoid false positives for local functions, see maintenance/rebuildInterwiki.inc
708743 $this->warning( "Non deprecated function $this->mFunction may be calling deprecated function " .

Status & tagging log