Ignore:
Timestamp:
Oct 28, 2007, 3:50:59 PM (18 years ago)
Author:
darin
Message:

JavaScriptCore:

Reviewed by Maciej.

This patch removes 4 node types: GroupNode, PropertyNameNode,
FunctionCallParenBracketNode, and FunctionCallParenDotNode.

To remove GroupNode, we add knowledge of precedence to the tree nodes,
and use that when serializing to determine where parentheses are needed.
This means we no longer have to represent parentheses in the tree.

The precedence values are named after productions in the grammar from the
JavaScript standard.

SunSpider says this is an 0.4% speedup.

  • kjs/function.h:
  • kjs/function.cpp: Removed escapeStringForPrettyPrinting -- it's part of serialization, so I moved it to the file that takes care of that.
  • kjs/grammar.y: Changed makeGetterOrSetterPropertyNode to use 0 to indicate failure instead of a separate boolean. Got rid of PropertyNameNode by merging the PropertyName rule into the Property rule (which was easier than figuring out how to pass the Identifier from one node to another). Got rid of GroupNode, nodeInsideAllParens(), FunctionCallParenBracketNode, and FunctionCallParenDotNode.
  • kjs/nodes.h: Removed unused forward declarations and Operator values. Added Precedence enum, and precedence function to all nodes. Removed nodeInsideAllParens. Added streamBinaryOperator function for serialization. Removed GroupNode and PropertyNameNode. Made PropertyNode store an Identifier. Removed FunctionCallParenBracketNode and FunctionCallParenDotNode.
  • kjs/nodes.cpp: Removed Node::nodinsideAllParens, GroupNode, and PropertyNameNode. (KJS::PropertyListNode::evaluate): Changed code to get name directly instead of converting it from an Identifier to a jsString then back to a UString then into an Identifier again!
  • kjs/nodes2string.cpp: Changed special-token implementation to use a separate function for each of Endl, Indent, Unindent, and DotExpr instead of using a single function with a switch. Added a precedence that you can stream in, to cause the next node serialized to add parentheses based on that precedence value. (KJS::operatorString): Moved to the top of the file. (KJS::escapeStringForPrettyPrinting): Moved here from function.cpp. Removed old workaround for snprintf, since StringExtras.h takes care of that. (KJS::operator<<): Made the char and char* versions faster by using UString's character append functions instead of constructing a UString. Added the logic to the Node* version to add parentheses if needed. (KJS::Node::streamLeftAssociativeBinaryOperator): Added helper function. (KJS::ElementNode::streamTo): Use PrecAssignment for the elements. (KJS::BracketAccessorNode::streamTo): Use PrecCall for the expression before the bracket. (KJS::DotAccessorNode::streamTo): Use PrecCall for the expression before the dot. (KJS::ArgumentListNode::streamTo): Use PrecAssignment for the arguments. (KJS::NewExprNode::streamTo): Use PrecMember for the expression. (KJS::FunctionCallValueNode::streamTo): Use PrecCall. (KJS::FunctionCallBracketNode::streamTo): Ditto. (KJS::FunctionCallDotNode::streamTo): Ditto. (KJS::PostfixBracketNode::streamTo): Ditto. (KJS::PostfixDotNode::streamTo): Ditto. (KJS::PostfixErrorNode::streamTo): Use PrecLeftHandSide. (KJS::DeleteBracketNode::streamTo): Use PrecCall. (KJS::DeleteDotNode::streamTo): Ditto. (KJS::DeleteValueNode::streamTo): Use PrecUnary. (KJS::VoidNode::streamTo): Ditto. (KJS::TypeOfValueNode::streamTo): Ditto. (KJS::PrefixBracketNode::streamTo): Use PrecCall. (KJS::PrefixDotNode::streamTo): Ditto. (KJS::PrefixErrorNode::streamTo): Use PrecUnary. (KJS::UnaryPlusNode::streamTo): Ditto. (KJS::NegateNode::streamTo): Ditto. (KJS::BitwiseNotNode::streamTo): Ditto. (KJS::LogicalNotNode::streamTo): Ditto. (KJS::MultNode::streamTo): Use streamLeftAssociativeBinaryOperator. (KJS::DivNode::streamTo): Ditto. (KJS::ModNode::streamTo): Ditto. (KJS::AddNode::streamTo): Ditto. (KJS::SubNode::streamTo): Ditto. (KJS::LeftShiftNode::streamTo): Ditto. (KJS::RightShiftNode::streamTo): Ditto. (KJS::UnsignedRightShiftNode::streamTo): Ditto. (KJS::LessNode::streamTo): Ditto. (KJS::GreaterNode::streamTo): Ditto. (KJS::LessEqNode::streamTo): Ditto. (KJS::GreaterEqNode::streamTo): Ditto. (KJS::InstanceOfNode::streamTo): Ditto. (KJS::InNode::streamTo): Ditto. (KJS::EqualNode::streamTo): Ditto. (KJS::NotEqualNode::streamTo): Ditto. (KJS::StrictEqualNode::streamTo): Ditto. (KJS::NotStrictEqualNode::streamTo): Ditto. (KJS::BitAndNode::streamTo): Ditto. (KJS::BitXOrNode::streamTo): Ditto. (KJS::BitOrNode::streamTo): Ditto. (KJS::LogicalAndNode::streamTo): Ditto. (KJS::LogicalOrNode::streamTo): Ditto. (KJS::ConditionalNode::streamTo): Ditto. (KJS::AssignResolveNode::streamTo): Use PrecAssignment for the right side. (KJS::AssignBracketNode::streamTo): Use PrecCall for the expression before the bracket and PrecAssignment for the right side. (KJS::AssignDotNode::streamTo): Ditto. (KJS::AssignErrorNode::streamTo): Use PrecLeftHandSide for the left side and PrecAssignment for the right side. (KJS::CommaNode::streamTo): Use PrecAssignment for both expressions. (KJS::AssignExprNode::streamTo): Use PrecAssignment.

LayoutTests:

Reviewed by Maciej.

One test is a start at testing that parentheses are added when needed.
The other test checks some aspects of object literals, since I changed
the way the property names is handled in those. More tests are needed.

  • fast/js/function-toString-object-literals-expected.txt: Added.
  • fast/js/function-toString-object-literals.html: Added.
  • fast/js/function-toString-parentheses-expected.txt: Added.
  • fast/js/function-toString-parentheses.html: Added.
  • fast/js/resources/function-toString-object-literals.js: Added.
  • fast/js/resources/function-toString-parentheses.js: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/function.cpp

    r27178 r27191  
    890890}
    891891
    892 UString escapeStringForPrettyPrinting(const UString& s)
    893 {
    894     UString escapedString;
    895    
    896     for (int i = 0; i < s.size(); i++) {
    897         unsigned short c = s.data()[i].unicode();
    898        
    899         switch (c) {
    900         case '\"':
    901             escapedString += "\\\"";
    902             break;
    903         case '\n':
    904             escapedString += "\\n";
    905             break;
    906         case '\r':
    907             escapedString += "\\r";
    908             break;
    909         case '\t':
    910             escapedString += "\\t";
    911             break;
    912         case '\\':
    913             escapedString += "\\\\";
    914             break;
    915         default:
    916             if (c < 128 && isPrintableChar(c))
    917                 escapedString.append(c);
    918             else {
    919                 char hexValue[7];
    920            
    921 #if PLATFORM(WIN_OS)
    922                 _snprintf(hexValue, 7, "\\u%04x", c);
    923 #else
    924                 snprintf(hexValue, 7, "\\u%04x", c);
    925 #endif
    926                 escapedString += hexValue;
    927             }
    928         }
    929     }
    930    
    931     return escapedString;   
    932 }
    933 
    934892} // namespace
Note: See TracChangeset for help on using the changeset viewer.