2008-06-16 Cameron Zwarich <cwzwarich@uwaterloo.ca>
authorcwzwarich@webkit.org <cwzwarich@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Jun 2008 08:19:17 +0000 (08:19 +0000)
committercwzwarich@webkit.org <cwzwarich@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Jun 2008 08:19:17 +0000 (08:19 +0000)
        Reviewed by Maciej.

        Make a UnaryOpNode class to reduce boilerplate code for UnaryPlusNode,
        NegateNode, BitwiseNotNode, and LogicalNotNode.

        * VM/CodeGenerator.h:
        (KJS::CodeGenerator::emitToJSNumber):
        * kjs/nodes.cpp:
        (KJS::UnaryOpNode::emitCode):
        * kjs/nodes.h:
        (KJS::UnaryOpNode::UnaryOpNode):
        (KJS::UnaryPlusNode::):
        (KJS::NegateNode::):
        (KJS::NegateNode::precedence):
        (KJS::BitwiseNotNode::):
        (KJS::BitwiseNotNode::precedence):
        (KJS::LogicalNotNode::):
        (KJS::LogicalNotNode::precedence):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@34593 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/VM/CodeGenerator.h
JavaScriptCore/kjs/nodes.cpp
JavaScriptCore/kjs/nodes.h

index 4a19f11..c98bc97 100644 (file)
@@ -1,3 +1,24 @@
+2008-06-16  Cameron Zwarich  <cwzwarich@uwaterloo.ca>
+
+        Reviewed by Maciej.
+
+        Make a UnaryOpNode class to reduce boilerplate code for UnaryPlusNode,
+        NegateNode, BitwiseNotNode, and LogicalNotNode.
+
+        * VM/CodeGenerator.h:
+        (KJS::CodeGenerator::emitToJSNumber):
+        * kjs/nodes.cpp:
+        (KJS::UnaryOpNode::emitCode):
+        * kjs/nodes.h:
+        (KJS::UnaryOpNode::UnaryOpNode):
+        (KJS::UnaryPlusNode::):
+        (KJS::NegateNode::):
+        (KJS::NegateNode::precedence):
+        (KJS::BitwiseNotNode::):
+        (KJS::BitwiseNotNode::precedence):
+        (KJS::LogicalNotNode::):
+        (KJS::LogicalNotNode::precedence):
+
 2008-06-16  Jan Michael Alonzo  <jmalonzo@webkit.org>
 
         Gtk build fix
index 64b07d8..efd724e 100644 (file)
@@ -197,7 +197,6 @@ namespace KJS {
         RegisterID* emitBinaryOp(OpcodeID, RegisterID* dst, RegisterID* src1, RegisterID* src2);
         RegisterID* emitUnaryNoDstOp(OpcodeID, RegisterID* src);
 
-
         RegisterID* emitNewObject(RegisterID* dst) { return emitNullaryOp(op_new_object, dst); }
         RegisterID* emitNewArray(RegisterID* dst) { return emitNullaryOp(op_new_array, dst); }
 
@@ -207,12 +206,7 @@ namespace KJS {
 
         RegisterID* emitMove(RegisterID* dst, RegisterID* src);
 
-
-        RegisterID* emitNot(RegisterID* dst, RegisterID* src) { return emitUnaryOp(op_not, dst, src); }
-        RegisterID* emitBitNot(RegisterID* dst, RegisterID* src) { return emitUnaryOp(op_bitnot, dst, src); }
-
         RegisterID* emitToJSNumber(RegisterID* dst, RegisterID* src) { return emitUnaryOp(op_to_jsnumber, dst, src); }
-        RegisterID* emitNegate(RegisterID* dst, RegisterID* src) { return emitUnaryOp(op_negate, dst, src); }
         RegisterID* emitPreInc(RegisterID* srcDst);
         RegisterID* emitPreDec(RegisterID* srcDst);
         RegisterID* emitPostInc(RegisterID* dst, RegisterID* srcDst);
index 8027c10..02c5fc4 100644 (file)
@@ -741,36 +741,12 @@ RegisterID* PrefixErrorNode::emitCode(CodeGenerator& generator, RegisterID*)
     return emitThrowError(generator, ReferenceError, m_operator == OpPlusPlus ? "Prefix ++ operator applied to value that is not a reference." : "Prefix -- operator applied to value that is not a reference.");
 }
 
-// ------------------------------ UnaryPlusNode --------------------------------
+// ------------------------------ Unary Operation Nodes -----------------------------------
 
-RegisterID* UnaryPlusNode::emitCode(CodeGenerator& generator, RegisterID* dst)
+RegisterID* UnaryOpNode::emitCode(CodeGenerator& generator, RegisterID* dst)
 {
     RegisterID* src = generator.emitNode(m_expr.get());
-    return generator.emitToJSNumber(generator.finalDestination(dst), src);
-}
-
-// ------------------------------ NegateNode -----------------------------------
-
-RegisterID* NegateNode::emitCode(CodeGenerator& generator, RegisterID* dst)
-{
-    RegisterID* src = generator.emitNode(m_expr.get());
-    return generator.emitNegate(generator.finalDestination(dst), src);
-}
-
-// ------------------------------ BitwiseNotNode -------------------------------
-
-RegisterID* BitwiseNotNode::emitCode(CodeGenerator& generator, RegisterID* dst)
-{
-    RegisterID* src = generator.emitNode(m_expr.get());
-    return generator.emitBitNot(generator.finalDestination(dst), src);
-}
-
-// ------------------------------ LogicalNotNode -------------------------------
-
-RegisterID* LogicalNotNode::emitCode(CodeGenerator& generator, RegisterID* dst)
-{
-    RegisterID* src = generator.emitNode(m_expr.get());
-    return generator.emitNot(generator.finalDestination(dst), src);
+    return generator.emitUnaryOp(opcode(), generator.finalDestination(dst), src);
 }
 
 // ------------------------------ Binary Operation Nodes -----------------------------------
index a4fa711..eddb6a6 100644 (file)
@@ -1132,68 +1132,72 @@ namespace KJS {
         Operator m_operator;
     };
 
-    class UnaryPlusNode : public ExpressionNode {
+    class UnaryOpNode : public ExpressionNode {
     public:
-        UnaryPlusNode(ExpressionNode* expr) KJS_FAST_CALL
-            : ExpressionNode(NumberType)
+        UnaryOpNode(ExpressionNode* expr)
+            : m_expr(expr)
+        {
+        }
+
+        UnaryOpNode(JSType type, ExpressionNode* expr)
+            : ExpressionNode(type)
             , m_expr(expr)
         {
         }
 
         virtual RegisterID* emitCode(CodeGenerator&, RegisterID* = 0) KJS_FAST_CALL;
-        virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
-        virtual Precedence precedence() const { return PrecUnary; }
+        virtual OpcodeID opcode() const KJS_FAST_CALL = 0;
 
-    private:
+    protected:
         RefPtr<ExpressionNode> m_expr;
     };
 
-    class NegateNode : public ExpressionNode {
+    class UnaryPlusNode : public UnaryOpNode {
     public:
-        NegateNode(ExpressionNode* expr) KJS_FAST_CALL
-            : ExpressionNode(NumberType)
-            , m_expr(expr)
+        UnaryPlusNode(ExpressionNode* expr) KJS_FAST_CALL
+            : UnaryOpNode(NumberType, expr)
         {
         }
 
-        virtual RegisterID* emitCode(CodeGenerator&, RegisterID* = 0) KJS_FAST_CALL;
+        virtual OpcodeID opcode() const KJS_FAST_CALL { return op_to_jsnumber; }
         virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
         virtual Precedence precedence() const { return PrecUnary; }
+    };
 
-    private:
-        RefPtr<ExpressionNode> m_expr;
+    class NegateNode : public UnaryOpNode {
+    public:
+        NegateNode(ExpressionNode* expr) KJS_FAST_CALL
+            : UnaryOpNode(NumberType, expr)
+        {
+        }
+
+        virtual OpcodeID opcode() const KJS_FAST_CALL { return op_negate; }
+        virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
+        virtual Precedence precedence() const { return PrecUnary; }
     };
 
-    class BitwiseNotNode : public ExpressionNode {
+    class BitwiseNotNode : public UnaryOpNode {
     public:
         BitwiseNotNode(ExpressionNode* expr) KJS_FAST_CALL
-            : ExpressionNode(NumberType)
-            , m_expr(expr)
+            : UnaryOpNode(NumberType, expr)
         {
         }
 
-        virtual RegisterID* emitCode(CodeGenerator&, RegisterID* = 0) KJS_FAST_CALL;
+        virtual OpcodeID opcode() const KJS_FAST_CALL { return op_bitnot; }
         virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
         virtual Precedence precedence() const { return PrecUnary; }
-
-    private:
-        RefPtr<ExpressionNode> m_expr;
     };
 
-    class LogicalNotNode : public ExpressionNode {
+    class LogicalNotNode : public UnaryOpNode {
     public:
         LogicalNotNode(ExpressionNode* expr) KJS_FAST_CALL
-            : ExpressionNode(BooleanType)
-            , m_expr(expr)
+            : UnaryOpNode(BooleanType, expr)
         {
         }
 
-        virtual RegisterID* emitCode(CodeGenerator&, RegisterID* = 0) KJS_FAST_CALL;
+        virtual OpcodeID opcode() const KJS_FAST_CALL { return op_not; }
         virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
         virtual Precedence precedence() const { return PrecUnary; }
-
-    private:
-        RefPtr<ExpressionNode> m_expr;
     };
 
     class BinaryOpNode : public ExpressionNode {