This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

IMPLEMENT ALL THE OPERATORS!

  • Loading branch information...
jmalloc committed Aug 15, 2012
1 parent 8258c77 commit 9ad5a921d3204be8e7f171a3d10266c0958a403f
Showing with 404 additions and 76 deletions.
  1. +2 −2 composer.lock
  2. +258 −10 lib/Icecave/Rasta/Renderer.php
  3. +144 −64 test/suite/Icecave/Rasta/RendererTest.php
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -4,20 +4,63 @@
use Icecave\Pasta\AST\ContentBlock;
use Icecave\Pasta\AST\Expr\Assign;
use Icecave\Pasta\AST\Expr\BinaryOperator;
+use Icecave\Pasta\AST\Expr\BitwiseAnd;
+use Icecave\Pasta\AST\Expr\BitwiseAndAssign;
+use Icecave\Pasta\AST\Expr\BitwiseExclusiveOr;
+use Icecave\Pasta\AST\Expr\BitwiseExclusiveOrAssign;
+use Icecave\Pasta\AST\Expr\BitwiseNot;
+use Icecave\Pasta\AST\Expr\BitwiseOr;
+use Icecave\Pasta\AST\Expr\BitwiseOrAssign;
use Icecave\Pasta\AST\Expr\Call;
+use Icecave\Pasta\AST\Expr\CastArray;
+use Icecave\Pasta\AST\Expr\CastBoolean;
+use Icecave\Pasta\AST\Expr\CastFloat;
+use Icecave\Pasta\AST\Expr\CastInteger;
+use Icecave\Pasta\AST\Expr\CastObject;
+use Icecave\Pasta\AST\Expr\CastString;
use Icecave\Pasta\AST\Expr\CloneOperator;
+use Icecave\Pasta\AST\Expr\Concat;
+use Icecave\Pasta\AST\Expr\ConcatAssign;
+use Icecave\Pasta\AST\Expr\Divide;
+use Icecave\Pasta\AST\Expr\DivideAssign;
use Icecave\Pasta\AST\Expr\Equals;
+use Icecave\Pasta\AST\Expr\Greater;
+use Icecave\Pasta\AST\Expr\GreaterEqual;
+use Icecave\Pasta\AST\Expr\IExpression;
+use Icecave\Pasta\AST\Expr\IOperator;
use Icecave\Pasta\AST\Expr\InstanceOfType;
+use Icecave\Pasta\AST\Expr\Less;
+use Icecave\Pasta\AST\Expr\LessEqual;
use Icecave\Pasta\AST\Expr\Literal;
use Icecave\Pasta\AST\Expr\LogicalAnd;
+use Icecave\Pasta\AST\Expr\LogicalExclusiveOr;
+use Icecave\Pasta\AST\Expr\LogicalKeywordAnd;
+use Icecave\Pasta\AST\Expr\LogicalKeywordOr;
use Icecave\Pasta\AST\Expr\LogicalNot;
use Icecave\Pasta\AST\Expr\LogicalOr;
+use Icecave\Pasta\AST\Expr\Modulus;
+use Icecave\Pasta\AST\Expr\ModulusAssign;
+use Icecave\Pasta\AST\Expr\Multiply;
+use Icecave\Pasta\AST\Expr\MultiplyAssign;
use Icecave\Pasta\AST\Expr\NewOperator;
use Icecave\Pasta\AST\Expr\NotEquals;
use Icecave\Pasta\AST\Expr\PolyadicOperator;
+use Icecave\Pasta\AST\Expr\PostfixDecrement;
+use Icecave\Pasta\AST\Expr\PostfixIncrement;
+use Icecave\Pasta\AST\Expr\PrefixDecrement;
+use Icecave\Pasta\AST\Expr\PrefixIncrement;
use Icecave\Pasta\AST\Expr\QualifiedIdentifier;
+use Icecave\Pasta\AST\Expr\ShiftLeft;
+use Icecave\Pasta\AST\Expr\ShiftLeftAssign;
+use Icecave\Pasta\AST\Expr\ShiftRight;
+use Icecave\Pasta\AST\Expr\ShiftRightAssign;
use Icecave\Pasta\AST\Expr\StrictEquals;
use Icecave\Pasta\AST\Expr\StrictNotEquals;
+use Icecave\Pasta\AST\Expr\Subscript;
+use Icecave\Pasta\AST\Expr\Subtract;
+use Icecave\Pasta\AST\Expr\SubtractAssign;
+use Icecave\Pasta\AST\Expr\Sum;
+use Icecave\Pasta\AST\Expr\SumAssign;
use Icecave\Pasta\AST\Expr\UnaryOperator;
use Icecave\Pasta\AST\Expr\Variable;
use Icecave\Pasta\AST\Func\ArrayTypeHint;
@@ -353,41 +396,146 @@ public function visitAssign(Assign $node)
return $this->generateBinaryOperatorCode('=', $node);
}
+ public function visitBitwiseAnd(BitwiseAnd $node)
+ {
+ return $this->generatePolyadicOperatorCode('&', $node);
+ }
+
+ public function visitBitwiseAndAssign(BitwiseAndAssign $node)
+ {
+ return $this->generateBinaryOperatorCode('&=', $node);
+ }
+
+ public function visitBitwiseExclusiveOr(BitwiseExclusiveOr $node)
+ {
+ return $this->generateBinaryOperatorCode('^', $node);
+ }
+
+ public function visitBitwiseExclusiveOrAssign(BitwiseExclusiveOrAssign $node)
+ {
+ return $this->generateBinaryOperatorCode('^=', $node);
+ }
+
+ public function visitBitwiseNot(BitwiseNot $node)
+ {
+ return $this->generateUnaryOperatorCode('~', $node);
+ }
+
+ public function visitBitwiseOr(BitwiseOr $node)
+ {
+ return $this->generatePolyadicOperatorCode('|', $node);
+ }
+
+ public function visitBitwiseOrAssign(BitwiseOrAssign $node)
+ {
+ return $this->generateBinaryOperatorCode('|=', $node);
+ }
+
+ public function visitCastArray(CastArray $node)
+ {
+ return $this->generateUnaryOperatorCode('(array)', $node);
+ }
+
+ public function visitCastBoolean(CastBoolean $node)
+ {
+ return $this->generateUnaryOperatorCode('(boolean)', $node);
+ }
+
+ public function visitCastFloat(CastFloat $node)
+ {
+ return $this->generateUnaryOperatorCode('(float)', $node);
+ }
+
+ public function visitCastInteger(CastInteger $node)
+ {
+ return $this->generateUnaryOperatorCode('(integer)', $node);
+ }
+
+ public function visitCastObject(CastObject $node)
+ {
+ return $this->generateUnaryOperatorCode('(object)', $node);
+ }
+
+ public function visitCastString(CastString $node)
+ {
+ return $this->generateUnaryOperatorCode('(string)', $node);
+ }
+
public function visitCloneOperator(CloneOperator $node)
{
return $this->generateUnaryOperatorCode('clone ', $node);
}
+ public function visitConcat(Concat $node)
+ {
+ return $this->generatePolyadicOperatorCode('.', $node);
+ }
+
+ public function visitConcatAssign(ConcatAssign $node)
+ {
+ return $this->generateBinaryOperatorCode('.=', $node);
+ }
+
+ public function visitDivide(Divide $node)
+ {
+ return $this->generateBinaryOperatorCode('/', $node);
+ }
+
+ public function visitDivideAssign(DivideAssign $node)
+ {
+ return $this->generateBinaryOperatorCode('/=', $node);
+ }
+
public function visitEquals(Equals $node)
{
return $this->generateBinaryOperatorCode('==', $node);
}
- public function visitStrictEquals(StrictEquals $node)
+ public function visitGreater(Greater $node)
{
- return $this->generateBinaryOperatorCode('===', $node);
+ return $this->generateBinaryOperatorCode('>', $node);
}
- public function visitNewOperator(NewOperator $node)
+ public function visitGreaterEqual(GreaterEqual $node)
{
- return $this->generateUnaryOperatorCode('new ', $node);
+ return $this->generateBinaryOperatorCode('>=', $node);
}
- public function visitNotEquals(NotEquals $node)
+ public function visitInstanceOfType(InstanceOfType $node)
{
- return $this->generateBinaryOperatorCode('!=', $node);
+ return $this->generateBinaryOperatorCode('instanceof', $node);
}
- public function visitStrictNotEquals(StrictNotEquals $node)
+ public function visitLess(Less $node)
{
- return $this->generateBinaryOperatorCode('!==', $node);
+ return $this->generateBinaryOperatorCode('<', $node);
+ }
+
+ public function visitLessEqual(LessEqual $node)
+ {
+ return $this->generateBinaryOperatorCode('<=', $node);
}
public function visitLogicalAnd(LogicalAnd $node)
{
return $this->generatePolyadicOperatorCode('&&', $node);
}
+ public function visitLogicalExclusiveOr(LogicalExclusiveOr $node)
+ {
+ return $this->generateBinaryOperatorCode('xor', $node);
+ }
+
+ public function visitLogicalKeywordAnd(LogicalKeywordAnd $node)
+ {
+ return $this->generatePolyadicOperatorCode('and', $node);
+ }
+
+ public function visitLogicalKeywordOr(LogicalKeywordOr $node)
+ {
+ return $this->generatePolyadicOperatorCode('or', $node);
+ }
+
public function visitLogicalOr(LogicalOr $node)
{
return $this->generatePolyadicOperatorCode('||', $node);
@@ -398,9 +546,109 @@ public function visitLogicalNot(LogicalNot $node)
return $this->generateUnaryOperatorCode('!', $node);
}
- public function visitInstanceOfType(InstanceOfType $node)
+ public function visitModulus(Modulus $node)
{
- return $this->generateBinaryOperatorCode('instanceof', $node);
+ return $this->generateBinaryOperatorCode('%', $node);
+ }
+
+ public function visitModulusAssign(ModulusAssign $node)
+ {
+ return $this->generateBinaryOperatorCode('%=', $node);
+ }
+
+ public function visitMultiply(Multiply $node)
+ {
+ return $this->generatePolyadicOperatorCode('*', $node);
+ }
+
+ public function visitMultiplyAssign(MultiplyAssign $node)
+ {
+ return $this->generateBinaryOperatorCode('*=', $node);
+ }
+
+ public function visitNewOperator(NewOperator $node)
+ {
+ return $this->generateUnaryOperatorCode('new ', $node);
+ }
+
+ public function visitNotEquals(NotEquals $node)
+ {
+ return $this->generateBinaryOperatorCode('!=', $node);
+ }
+
+ public function visitPostfixDecrement(PostfixDecrement $node)
+ {
+ return $this->generateUnaryOperatorCode('--', $node, false);
+ }
+
+ public function visitPostfixIncrement(PostfixIncrement $node)
+ {
+ return $this->generateUnaryOperatorCode('++', $node, false);
+ }
+
+ public function visitPrefixDecrement(PrefixDecrement $node)
+ {
+ return $this->generateUnaryOperatorCode('--', $node);
+ }
+
+ public function visitPrefixIncrement(PrefixIncrement $node)
+ {
+ return $this->generateUnaryOperatorCode('++', $node);
+ }
+
+ public function visitShiftLeft(ShiftLeft $node)
+ {
+ return $this->generateBinaryOperatorCode('<<', $node);
+ }
+
+ public function visitShiftLeftAssign(ShiftLeftAssign $node)
+ {
+ return $this->generateBinaryOperatorCode('<<=', $node);
+ }
+
+ public function visitShiftRight(ShiftRight $node)
+ {
+ return $this->generateBinaryOperatorCode('>>', $node);
+ }
+
+ public function visitShiftRightAssign(ShiftRightAssign $node)
+ {
+ return $this->generateBinaryOperatorCode('>>=', $node);
+ }
+
+ public function visitStrictEquals(StrictEquals $node)
+ {
+ return $this->generateBinaryOperatorCode('===', $node);
+ }
+
+ public function visitStrictNotEquals(StrictNotEquals $node)
+ {
+ return $this->generateBinaryOperatorCode('!==', $node);
+ }
+
+ public function visitSubscript(Subscript $node)
+ {
+ return $node->leftExpression()->accept($this) . '[' . $node->rightExpression()->accept($this) . ']';
+ }
+
+ public function visitSubtract(Subtract $node)
+ {
+ return $this->generateBinaryOperatorCode('-', $node);
+ }
+
+ public function visitSubtractAssign(SubtractAssign $node)
+ {
+ return $this->generateBinaryOperatorCode('-=', $node);
+ }
+
+ public function visitSum(Sum $node)
+ {
+ return $this->generatePolyadicOperatorCode('+', $node);
+ }
+
+ public function visitSumAssign(SumAssign $node)
+ {
+ return $this->generateBinaryOperatorCode('+=', $node);
}
// Support ...
Oops, something went wrong.

0 comments on commit 9ad5a92

Please sign in to comment.