Changeset 27191 in webkit for trunk/JavaScriptCore/kjs/nodes.cpp


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/nodes.cpp

    r27177 r27191  
    291291}
    292292
    293 Node *Node::nodeInsideAllParens()
    294 {
    295     return this;
    296 }
    297 
    298293// ------------------------------ StatementNode --------------------------------
    299294
     
    397392
    398393  return throwUndefinedVariableError(exec, ident);
    399 }
    400 
    401 // ------------------------------ GroupNode ------------------------------------
    402 
    403 // ECMA 11.1.6
    404 JSValue *GroupNode::evaluate(ExecState *exec)
    405 {
    406   return group->evaluate(exec);
    407 }
    408 
    409 Node *GroupNode::nodeInsideAllParens()
    410 {
    411     Node *n = this;
    412     do
    413         n = static_cast<GroupNode *>(n)->group.get();
    414     while (n->isGroupNode());
    415     return n;
    416394}
    417395
     
    480458 
    481459  for (PropertyListNode *p = this; p; p = p->next.get()) {
    482     JSValue *n = p->node->name->evaluate(exec);
    483     KJS_CHECKEXCEPTIONVALUE
    484460    JSValue *v = p->node->assign->evaluate(exec);
    485461    KJS_CHECKEXCEPTIONVALUE
    486462   
    487     Identifier propertyName = Identifier(n->toString(exec));
    488463    switch (p->node->type) {
    489464      case PropertyNode::Getter:
    490465        ASSERT(v->isObject());
    491         obj->defineGetter(exec, propertyName, static_cast<JSObject *>(v));
     466        obj->defineGetter(exec, p->node->name(), static_cast<JSObject *>(v));
    492467        break;
    493468      case PropertyNode::Setter:
    494469        ASSERT(v->isObject());
    495         obj->defineSetter(exec, propertyName, static_cast<JSObject *>(v));
     470        obj->defineSetter(exec, p->node->name(), static_cast<JSObject *>(v));
    496471        break;
    497472      case PropertyNode::Constant:
    498         obj->put(exec, propertyName, v);
     473        obj->put(exec, p->node->name(), v);
    499474        break;
    500475    }
     
    515490  ASSERT(false);
    516491  return jsNull();
    517 }
    518 
    519 // ---------------------------- PropertyNameNode -------------------------------
    520 
    521 // ECMA 11.1.5
    522 JSValue *PropertyNameNode::evaluate(ExecState*)
    523 {
    524   JSValue *s;
    525 
    526   if (str.isNull()) {
    527     s = jsString(UString::from(numeric));
    528   } else {
    529     s = jsOwnedString(str.ustring());
    530   }
    531 
    532   return s;
    533492}
    534493
Note: See TracChangeset for help on using the changeset viewer.