Changeset 34593 in webkit for trunk/JavaScriptCore/kjs/nodes.h


Ignore:
Timestamp:
Jun 16, 2008, 1:19:17 AM (17 years ago)
Author:
[email protected]
Message:

2008-06-16 Cameron Zwarich <[email protected]>

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):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/nodes.h

    r34581 r34593  
    11331133    };
    11341134
    1135     class UnaryPlusNode : public ExpressionNode {
     1135    class UnaryOpNode : public ExpressionNode {
     1136    public:
     1137        UnaryOpNode(ExpressionNode* expr)
     1138            : m_expr(expr)
     1139        {
     1140        }
     1141
     1142        UnaryOpNode(JSType type, ExpressionNode* expr)
     1143            : ExpressionNode(type)
     1144            , m_expr(expr)
     1145        {
     1146        }
     1147
     1148        virtual RegisterID* emitCode(CodeGenerator&, RegisterID* = 0) KJS_FAST_CALL;
     1149        virtual OpcodeID opcode() const KJS_FAST_CALL = 0;
     1150
     1151    protected:
     1152        RefPtr<ExpressionNode> m_expr;
     1153    };
     1154
     1155    class UnaryPlusNode : public UnaryOpNode {
    11361156    public:
    11371157        UnaryPlusNode(ExpressionNode* expr) KJS_FAST_CALL
    1138             : ExpressionNode(NumberType)
    1139             , m_expr(expr)
    1140         {
    1141         }
    1142 
    1143         virtual RegisterID* emitCode(CodeGenerator&, RegisterID* = 0) KJS_FAST_CALL;
     1158            : UnaryOpNode(NumberType, expr)
     1159        {
     1160        }
     1161
     1162        virtual OpcodeID opcode() const KJS_FAST_CALL { return op_to_jsnumber; }
    11441163        virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
    11451164        virtual Precedence precedence() const { return PrecUnary; }
    1146 
    1147     private:
    1148         RefPtr<ExpressionNode> m_expr;
    1149     };
    1150 
    1151     class NegateNode : public ExpressionNode {
     1165    };
     1166
     1167    class NegateNode : public UnaryOpNode {
    11521168    public:
    11531169        NegateNode(ExpressionNode* expr) KJS_FAST_CALL
    1154             : ExpressionNode(NumberType)
    1155             , m_expr(expr)
    1156         {
    1157         }
    1158 
    1159         virtual RegisterID* emitCode(CodeGenerator&, RegisterID* = 0) KJS_FAST_CALL;
     1170            : UnaryOpNode(NumberType, expr)
     1171        {
     1172        }
     1173
     1174        virtual OpcodeID opcode() const KJS_FAST_CALL { return op_negate; }
    11601175        virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
    11611176        virtual Precedence precedence() const { return PrecUnary; }
    1162 
    1163     private:
    1164         RefPtr<ExpressionNode> m_expr;
    1165     };
    1166 
    1167     class BitwiseNotNode : public ExpressionNode {
     1177    };
     1178
     1179    class BitwiseNotNode : public UnaryOpNode {
    11681180    public:
    11691181        BitwiseNotNode(ExpressionNode* expr) KJS_FAST_CALL
    1170             : ExpressionNode(NumberType)
    1171             , m_expr(expr)
    1172         {
    1173         }
    1174 
    1175         virtual RegisterID* emitCode(CodeGenerator&, RegisterID* = 0) KJS_FAST_CALL;
     1182            : UnaryOpNode(NumberType, expr)
     1183        {
     1184        }
     1185
     1186        virtual OpcodeID opcode() const KJS_FAST_CALL { return op_bitnot; }
    11761187        virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
    11771188        virtual Precedence precedence() const { return PrecUnary; }
    1178 
    1179     private:
    1180         RefPtr<ExpressionNode> m_expr;
    1181     };
    1182 
    1183     class LogicalNotNode : public ExpressionNode {
     1189    };
     1190
     1191    class LogicalNotNode : public UnaryOpNode {
    11841192    public:
    11851193        LogicalNotNode(ExpressionNode* expr) KJS_FAST_CALL
    1186             : ExpressionNode(BooleanType)
    1187             , m_expr(expr)
    1188         {
    1189         }
    1190 
    1191         virtual RegisterID* emitCode(CodeGenerator&, RegisterID* = 0) KJS_FAST_CALL;
     1194            : UnaryOpNode(BooleanType, expr)
     1195        {
     1196        }
     1197
     1198        virtual OpcodeID opcode() const KJS_FAST_CALL { return op_not; }
    11921199        virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
    11931200        virtual Precedence precedence() const { return PrecUnary; }
    1194 
    1195     private:
    1196         RefPtr<ExpressionNode> m_expr;
    11971201    };
    11981202
Note: See TracChangeset for help on using the changeset viewer.