r94757 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94756‎ | r94757 | r94758 >
Date:13:56, 17 August 2011
Author:vasilievvv
Status:deferred
Tags:
Comment:
* Rework addition logic
* Fix *= / /= error reporting
Modified paths:
  • /trunk/extensions/WikiScripts/i18n/Messages.php (modified) (history)
  • /trunk/extensions/WikiScripts/interpreter/Data.php (modified) (history)
  • /trunk/extensions/WikiScripts/interpreter/EvaluationContext.php (modified) (history)
  • /trunk/extensions/WikiScripts/interpreterTests.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiScripts/i18n/Messages.php
@@ -38,6 +38,7 @@
3939 'wikiscripts-exception-unknownfunction' => 'Trying to use an unnknown built-in function $2 $1',
4040 'wikiscripts-exception-notlist' => 'Trying to append an element to the end of \'\'associated\'\' array $1',
4141 'wikiscripts-exception-appendyield' => 'Trying to use append and yield in the same function $1',
 42+ 'wikiscripts-exception-assocbadmerge' => 'Trying to merge an assoicated array with a non-array $1',
4243
4344 'wikiscripts-exception-notenoughargs-user' => 'Not enough arguments for function $2::$3 $1',
4445 'wikiscripts-exception-nonexistent-module' => 'Call to non-existent module $2 $1',
Index: trunk/extensions/WikiScripts/interpreter/Data.php
@@ -217,21 +217,27 @@
218218 return new WSData( $type, $data );
219219 }
220220
221 - public static function sum( $a, $b ) {
222 - if( $a->type == self::DString || $b->type == self::DString )
223 - return new WSData( self::DString, $a->toString() . $b->toString() );
224 - elseif( $a->type == self::DList && $b->type == self::DList )
 221+ public static function sum( $a, $b, $module, $line ) {
 222+ // Lists
 223+ if( $a->type == self::DList && $b->type == self::DList )
225224 return new WSData( self::DList, array_merge( $a->toList(), $b->toList() ) );
226225 elseif( $a->type == self::DList )
227226 return new WSData( self::DList, array_merge( $a->toList(), array( $b ) ) );
228227 elseif( $b->type == self::DList )
229228 return new WSData( self::DList, array_merge( array( $a ), $b->toList() ) );
 229+ // Associated arrays
230230 elseif( $a->type == self::DAssoc && $b->type == self::DAssoc )
231231 return new WSData( self::DAssoc, array_merge( $a->toAssoc(), $b->toAssoc() ) );
232 - elseif( $a->type == self::DInt && $b->type == self::DInt )
 232+ elseif( $a->type == self::DAssoc || $b->type == self::DAssoc )
 233+ throw new WSUserVisibleException( 'assocbadmerge', $module, $line );
 234+ // Strings
 235+ elseif( $a->type == self::DString || $b->type == self::DString )
 236+ return new WSData( self::DString, $a->toString() . $b->toString() );
 237+ // Number, booleans and null
 238+ elseif( $a->type == self::DFloat || $b->type == self::DFloat )
 239+ return new WSData( self::DFloat, $a->toFloat() + $b->toFloat() );
 240+ else
233241 return new WSData( self::DInt, $a->toInt() + $b->toInt() );
234 - else
235 - return new WSData( self::DFloat, $a->toFloat() + $b->toFloat() );
236242 }
237243
238244 public static function sub( $a, $b ) {
Index: trunk/extensions/WikiScripts/interpreter/EvaluationContext.php
@@ -190,7 +190,12 @@
191191 throw new WSUserVisibleException( 'appendyield', $this->mModuleName, $c[0]->line );
192192 }
193193
194 - $this->mOutput = WSData::sum( $this->mOutput, $this->evaluateNode( $c[1], $rec + 1 ) );
 194+ $this->mOutput = WSData::sum(
 195+ $this->mOutput,
 196+ $this->evaluateNode( $c[1], $rec + 1 ),
 197+ $this->mModuleName,
 198+ $c[0]->line
 199+ );
195200 break 2;
196201 case 'yield':
197202 if( $this->mOutput->type != WSData::DNull ) {
@@ -255,7 +260,7 @@
256261 $arg2 = $this->evaluateNode( $c[2], $rec + 1 );
257262 switch( $c[1]->value ) {
258263 case '+':
259 - return WSData::sum( $arg1, $arg2 );
 264+ return WSData::sum( $arg1, $arg2, $this->mModuleName, $c[1]->line );
260265 case '-':
261266 return WSData::sub( $arg1, $arg2 );
262267 }
@@ -573,13 +578,13 @@
574579 protected function getValueForSetting( $old, $new, $set, $line ) {
575580 switch( $set ) {
576581 case '+=':
577 - return WSData::sum( $old, $new );
 582+ return WSData::sum( $old, $new, $this->mModuleName, $line );
578583 case '-=':
579584 return WSData::sub( $old, $new );
580585 case '*=':
581 - return WSData::mulRel( $old, $new, '*', $line );
 586+ return WSData::mulRel( $old, $new, '*', $this->mModuleName, $line );
582587 case '/=':
583 - return WSData::mulRel( $old, $new, '/', $line );
 588+ return WSData::mulRel( $old, $new, '/', $this->mModuleName, $line );
584589 default:
585590 return $new;
586591 }
Index: trunk/extensions/WikiScripts/interpreterTests.txt
@@ -81,6 +81,8 @@
8282 a = 2;
8383 a += 3;
8484 a -= 7;
 85+ a *= 3;
 86+ a /= 5;
8587 return a;
8688 }
8789 !! endarticle
@@ -90,7 +92,7 @@
9193 !! input
9294 {{i:Assigment with arithmetics|run}}
9395 !! result
94 -<p>-2
 96+<p>-1.2
9597 </p>
9698 !! end
9799

Status & tagging log