Changeset 26582 in webkit


Ignore:
Timestamp:
Oct 14, 2007 4:31:58 AM (17 years ago)
Author:
bdash
Message:

2007-10-14 Cameron Zwarich <cwzwarich@uwaterloo.ca>

Reviewed by Darin.

Adds NegateNode optimization from KJS. The relevant revision in KDE
is 666736.

  • kjs/grammar.y:
  • kjs/nodes.cpp: (NumberNode::evaluate):
  • kjs/nodes.h: (KJS::Node::): (KJS::NumberNode::):
  • kjs/nodes2string.cpp: (NumberNode::streamTo):

2007-10-14 Cameron Zwarich <cwzwarich@uwaterloo.ca>

Reviewed by Darin.

Adds serialization test cases for NegateNode optimization from KDE.

  • fast/js/function-decompilation-operators-expected.txt:
  • fast/js/function-decompilation-operators.html:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r26581 r26582  
     12007-10-14  Cameron Zwarich  <cwzwarich@uwaterloo.ca>
     2
     3        Reviewed by Darin.
     4
     5        Adds NegateNode optimization from KJS. The relevant revision in KDE
     6        is 666736.
     7
     8        * kjs/grammar.y:
     9        * kjs/nodes.cpp:
     10        (NumberNode::evaluate):
     11        * kjs/nodes.h:
     12        (KJS::Node::):
     13        (KJS::NumberNode::):
     14        * kjs/nodes2string.cpp:
     15        (NumberNode::streamTo):
     16
    1172007-10-14  Jason Foreman  <jason@threeve.org>
    218
  • trunk/JavaScriptCore/kjs/grammar.y

    r25934 r26582  
    6464static Node *makeTypeOfNode(Node *expr);
    6565static Node *makeDeleteNode(Node *expr);
     66static Node *makeNegateNode(Node *expr);
    6667
    6768#if COMPILER(MSVC)
     
    360361  | AUTOMINUSMINUS UnaryExpr            { $$ = makePrefixNode($2, OpMinusMinus); }
    361362  | '+' UnaryExpr                       { $$ = new UnaryPlusNode($2); }
    362   | '-' UnaryExpr                       { $$ = new NegateNode($2); }
     363  | '-' UnaryExpr                       { $$ = makeNegateNode($2); }
    363364  | '~' UnaryExpr                       { $$ = new BitwiseNotNode($2); }
    364365  | '!' UnaryExpr                       { $$ = new LogicalNotNode($2); }
     
    10041005}
    10051006
     1007static Node* makeNegateNode(Node *n)
     1008{
     1009    if (n->isNumber()) {
     1010        NumberNode* number = static_cast<NumberNode*>(n);
     1011
     1012        if (number->value() > 0.0) {
     1013            number->setValue(-number->value());
     1014            return number;
     1015        }
     1016    }
     1017
     1018    return new NegateNode(n);
     1019}
     1020
    10061021/* called by yyparse on error */
    10071022int yyerror(const char *)
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r24633 r26582  
    350350JSValue *NumberNode::evaluate(ExecState *)
    351351{
    352   return jsNumber(value);
     352  return jsNumber(val);
    353353}
    354354
  • trunk/JavaScriptCore/kjs/nodes.h

    r24532 r26582  
    101101    virtual Node *nodeInsideAllParens() KJS_FAST_CALL;
    102102
     103    virtual bool isNumber() const KJS_FAST_CALL { return false; }
    103104    virtual bool isLocation() const KJS_FAST_CALL { return false; }
    104105    virtual bool isResolveNode() const KJS_FAST_CALL { return false; }
     
    168169  class NumberNode : public Node {
    169170  public:
    170     NumberNode(double v) KJS_FAST_CALL : value(v) {}
    171     JSValue* evaluate(ExecState*) KJS_FAST_CALL;
    172     virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
    173   private:
    174     double value;
     171    NumberNode(double v) KJS_FAST_CALL : val(v) {}
     172    JSValue* evaluate(ExecState*) KJS_FAST_CALL;
     173    virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
     174
     175    virtual bool isNumber() const KJS_FAST_CALL { return true; }
     176    double value() const KJS_FAST_CALL { return val; }
     177    void setValue(double v) KJS_FAST_CALL { val = v; }
     178  private:
     179    double val;
    175180  };
    176181
  • trunk/JavaScriptCore/kjs/nodes2string.cpp

    r24924 r26582  
    141141}
    142142
    143 void NumberNode::streamTo(SourceStream &s) const { s << value; }
     143void NumberNode::streamTo(SourceStream &s) const { s << val; }
    144144
    145145void StringNode::streamTo(SourceStream &s) const
  • trunk/LayoutTests/ChangeLog

    r26581 r26582  
     12007-10-14  Cameron Zwarich  <cwzwarich@uwaterloo.ca>
     2
     3        Reviewed by Darin.
     4
     5        Adds serialization test cases for NegateNode optimization from KDE.
     6
     7        * fast/js/function-decompilation-operators-expected.txt:
     8        * fast/js/function-decompilation-operators.html:
     9
    1102007-10-14  Jason Foreman  <jason@threeve.org>
    211
  • trunk/LayoutTests/fast/js/function-decompilation-operators-expected.txt

    r24924 r26582  
    5050PASS decompiledFunction is 'function () {  - + x;}'
    5151PASS decompiledFunction is 'function () {  - - x;}'
     52PASS decompiledFunction is 'function () {  1;}'
     53PASS decompiledFunction is 'function () {  -1;}'
     54PASS decompiledFunction is 'function () {  - -1;}'
     55PASS decompiledFunction is 'function () {  - - 0;}'
     56PASS decompiledFunction is 'function () {  - - NaN;}'
    5257PASS successfullyParsed is true
    5358
  • trunk/LayoutTests/fast/js/function-decompilation-operators.html

    r24924 r26582  
    5858        "+ - x",
    5959        "- + x",
    60         "- - x"
     60        "- - x",
     61        "1",
     62        "-1",
     63        "- -1",
     64        "- - 0",
     65        "- - NaN"
    6166    ];
    6267
Note: See TracChangeset for help on using the changeset viewer.