Changeset 154745 in webkit
- Timestamp:
- Aug 28, 2013 7:31:16 AM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r154743 r154745 1 2013-08-28 Anders Carlsson <andersca@apple.com> 2 3 Clean up XPathExpressionNode and XPath::Function 4 https://bugs.webkit.org/show_bug.cgi?id=120411 5 6 Reviewed by Antti Koivisto. 7 8 Rename the subexpression and function argument getters to be more descriptive, 9 remove the non-const overloads (they were never used) and change the getters to return 10 references since they can never be null. 11 12 * xml/XPathExpressionNode.cpp: 13 * xml/XPathExpressionNode.h: 14 (WebCore::XPath::ParseNode::~ParseNode): 15 (WebCore::XPath::Expression::addSubExpression): 16 (WebCore::XPath::Expression::isContextNodeSensitive): 17 (WebCore::XPath::Expression::setIsContextNodeSensitive): 18 (WebCore::XPath::Expression::isContextPositionSensitive): 19 (WebCore::XPath::Expression::setIsContextPositionSensitive): 20 (WebCore::XPath::Expression::isContextSizeSensitive): 21 (WebCore::XPath::Expression::setIsContextSizeSensitive): 22 (WebCore::XPath::Expression::subExpressionCount): 23 (WebCore::XPath::Expression::subExpression): 24 * xml/XPathFunctions.cpp: 25 (WebCore::XPath::Function::setArguments): 26 (WebCore::XPath::FunId::evaluate): 27 (WebCore::XPath::FunLocalName::evaluate): 28 (WebCore::XPath::FunNamespaceURI::evaluate): 29 (WebCore::XPath::FunName::evaluate): 30 (WebCore::XPath::FunCount::evaluate): 31 (WebCore::XPath::FunString::evaluate): 32 (WebCore::XPath::FunConcat::evaluate): 33 (WebCore::XPath::FunStartsWith::evaluate): 34 (WebCore::XPath::FunContains::evaluate): 35 (WebCore::XPath::FunSubstringBefore::evaluate): 36 (WebCore::XPath::FunSubstringAfter::evaluate): 37 (WebCore::XPath::FunSubstring::evaluate): 38 (WebCore::XPath::FunStringLength::evaluate): 39 (WebCore::XPath::FunNormalizeSpace::evaluate): 40 (WebCore::XPath::FunTranslate::evaluate): 41 (WebCore::XPath::FunBoolean::evaluate): 42 (WebCore::XPath::FunNot::evaluate): 43 (WebCore::XPath::FunLang::evaluate): 44 (WebCore::XPath::FunNumber::evaluate): 45 (WebCore::XPath::FunSum::evaluate): 46 (WebCore::XPath::FunFloor::evaluate): 47 (WebCore::XPath::FunCeiling::evaluate): 48 (WebCore::XPath::FunRound::evaluate): 49 * xml/XPathFunctions.h: 50 (WebCore::XPath::Function::setName): 51 (WebCore::XPath::Function::argumentCount): 52 (WebCore::XPath::Function::argument): 53 (WebCore::XPath::Function::name): 54 * xml/XPathPredicate.cpp: 55 (WebCore::XPath::Negative::evaluate): 56 (WebCore::XPath::NumericOp::evaluate): 57 (WebCore::XPath::EqTestOp::evaluate): 58 (WebCore::XPath::LogicalOp::evaluate): 59 (WebCore::XPath::Union::evaluate): 60 1 61 2013-08-28 Andreas Kling <akling@apple.com> 2 62 -
trunk/Source/WebCore/xml/XPathExpressionNode.cpp
r97771 r154745 1 1 /* 2 2 * Copyright 2005 Frerich Raabe <raabe@kde.org> 3 * Copyright (C) 2006 Apple Computer, Inc.3 * Copyright (C) 2006, 2013 Apple Computer, Inc. 4 4 * 5 5 * Redistribution and use in source and binary forms, with or without … … 52 52 } 53 53 54 } 55 } 54 } // namespace XPath 55 } // namespace WebCore -
trunk/Source/WebCore/xml/XPathExpressionNode.h
r97771 r154745 1 1 /* 2 2 * Copyright (C) 2005 Frerich Raabe <raabe@kde.org> 3 * Copyright (C) 2006, 2009 Apple Inc.3 * Copyright (C) 2006, 2009, 2013 Apple Inc. 4 4 * 5 5 * Redistribution and use in source and binary forms, with or without … … 35 35 36 36 namespace WebCore { 37 namespace XPath { 37 38 38 namespace XPath { 39 40 struct EvaluationContext { 41 WTF_MAKE_FAST_ALLOCATED; 42 public: 43 RefPtr<Node> node; 44 unsigned long size; 45 unsigned long position; 46 HashMap<String, String> variableBindings; 39 struct EvaluationContext { 40 WTF_MAKE_FAST_ALLOCATED; 41 public: 42 RefPtr<Node> node; 43 unsigned long size; 44 unsigned long position; 45 HashMap<String, String> variableBindings; 47 46 48 49 47 bool hadTypeConversionError; 48 }; 50 49 51 52 53 54 50 class ParseNode { 51 public: 52 virtual ~ParseNode() { } 53 }; 55 54 56 57 58 59 55 class Expression : public ParseNode { 56 WTF_MAKE_NONCOPYABLE(Expression); WTF_MAKE_FAST_ALLOCATED; 57 public: 58 static EvaluationContext& evaluationContext(); 60 59 61 Expression(); 62 virtual ~Expression(); 60 virtual ~Expression(); 63 61 64 virtual Value evaluate() const = 0; 65 66 void addSubExpression(Expression* expr) 67 { 68 m_subExpressions.append(expr); 69 m_isContextNodeSensitive |= expr->m_isContextNodeSensitive; 70 m_isContextPositionSensitive |= expr->m_isContextPositionSensitive; 71 m_isContextSizeSensitive |= expr->m_isContextSizeSensitive; 72 } 73 74 bool isContextNodeSensitive() const { return m_isContextNodeSensitive; } 75 bool isContextPositionSensitive() const { return m_isContextPositionSensitive; } 76 bool isContextSizeSensitive() const { return m_isContextSizeSensitive; } 77 void setIsContextNodeSensitive(bool value) { m_isContextNodeSensitive = value; } 78 void setIsContextPositionSensitive(bool value) { m_isContextPositionSensitive = value; } 79 void setIsContextSizeSensitive(bool value) { m_isContextSizeSensitive = value; } 80 81 virtual Value::Type resultType() const = 0; 82 83 protected: 84 unsigned subExprCount() const { return m_subExpressions.size(); } 85 Expression* subExpr(unsigned i) { return m_subExpressions[i]; } 86 const Expression* subExpr(unsigned i) const { return m_subExpressions[i]; } 87 88 private: 89 Vector<Expression*> m_subExpressions; 90 91 // Evaluation details that can be used for optimization. 92 bool m_isContextNodeSensitive; 93 bool m_isContextPositionSensitive; 94 bool m_isContextSizeSensitive; 95 }; 96 62 void addSubExpression(Expression* expr) 63 { 64 m_subExpressions.append(expr); 65 m_isContextNodeSensitive |= expr->m_isContextNodeSensitive; 66 m_isContextPositionSensitive |= expr->m_isContextPositionSensitive; 67 m_isContextSizeSensitive |= expr->m_isContextSizeSensitive; 97 68 } 98 69 99 } 70 bool isContextNodeSensitive() const { return m_isContextNodeSensitive; } 71 void setIsContextNodeSensitive(bool value) { m_isContextNodeSensitive = value; } 100 72 101 #endif // EXPRESSION_H 73 bool isContextPositionSensitive() const { return m_isContextPositionSensitive; } 74 void setIsContextPositionSensitive(bool value) { m_isContextPositionSensitive = value; } 75 76 bool isContextSizeSensitive() const { return m_isContextSizeSensitive; } 77 void setIsContextSizeSensitive(bool value) { m_isContextSizeSensitive = value; } 78 79 virtual Value evaluate() const = 0; 80 virtual Value::Type resultType() const = 0; 81 82 protected: 83 Expression(); 84 85 unsigned subExpressionCount() const { return m_subExpressions.size(); } 86 const Expression& subExpression(unsigned i) const { return *m_subExpressions[i]; } 87 88 private: 89 Vector<Expression*> m_subExpressions; 90 91 // Evaluation details that can be used for optimization. 92 bool m_isContextNodeSensitive; 93 bool m_isContextPositionSensitive; 94 bool m_isContextSizeSensitive; 95 }; 96 97 } // namespace XPath 98 } // namespace WebCore 99 100 #endif // XPathExpressionNode_h -
trunk/Source/WebCore/xml/XPathFunctions.cpp
r153826 r154745 293 293 void Function::setArguments(const Vector<Expression*>& args) 294 294 { 295 ASSERT(!subExpr Count());295 ASSERT(!subExpressionCount()); 296 296 297 297 // Some functions use context node as implicit argument, so when explicit arguments are added, they may no longer be context node sensitive. … … 316 316 Value FunId::evaluate() const 317 317 { 318 Value a = arg (0)->evaluate();318 Value a = argument(0).evaluate(); 319 319 StringBuilder idList; // A whitespace-separated list of IDs 320 320 … … 379 379 Value FunLocalName::evaluate() const 380 380 { 381 if (arg Count() > 0) {382 Value a = arg (0)->evaluate();381 if (argumentCount() > 0) { 382 Value a = argument(0).evaluate(); 383 383 if (!a.isNodeSet()) 384 384 return ""; … … 393 393 Value FunNamespaceURI::evaluate() const 394 394 { 395 if (arg Count() > 0) {396 Value a = arg (0)->evaluate();395 if (argumentCount() > 0) { 396 Value a = argument(0).evaluate(); 397 397 if (!a.isNodeSet()) 398 398 return ""; … … 407 407 Value FunName::evaluate() const 408 408 { 409 if (arg Count() > 0) {410 Value a = arg (0)->evaluate();409 if (argumentCount() > 0) { 410 Value a = argument(0).evaluate(); 411 411 if (!a.isNodeSet()) 412 412 return ""; … … 421 421 Value FunCount::evaluate() const 422 422 { 423 Value a = arg (0)->evaluate();423 Value a = argument(0).evaluate(); 424 424 425 425 return double(a.toNodeSet().size()); … … 428 428 Value FunString::evaluate() const 429 429 { 430 if (!arg Count())430 if (!argumentCount()) 431 431 return Value(Expression::evaluationContext().node.get()).toString(); 432 return arg (0)->evaluate().toString();432 return argument(0).evaluate().toString(); 433 433 } 434 434 … … 438 438 result.reserveCapacity(1024); 439 439 440 unsigned count = argCount(); 441 for (unsigned i = 0; i < count; ++i) { 442 String str(arg(i)->evaluate().toString()); 440 for (unsigned i = 0, count = argumentCount(); i < count; ++i) { 441 String str(argument(i).evaluate().toString()); 443 442 result.append(str); 444 443 } … … 449 448 Value FunStartsWith::evaluate() const 450 449 { 451 String s1 = arg (0)->evaluate().toString();452 String s2 = arg (1)->evaluate().toString();450 String s1 = argument(0).evaluate().toString(); 451 String s2 = argument(1).evaluate().toString(); 453 452 454 453 if (s2.isEmpty()) … … 460 459 Value FunContains::evaluate() const 461 460 { 462 String s1 = arg (0)->evaluate().toString();463 String s2 = arg (1)->evaluate().toString();461 String s1 = argument(0).evaluate().toString(); 462 String s2 = argument(1).evaluate().toString(); 464 463 465 464 if (s2.isEmpty()) … … 471 470 Value FunSubstringBefore::evaluate() const 472 471 { 473 String s1 = arg (0)->evaluate().toString();474 String s2 = arg (1)->evaluate().toString();472 String s1 = argument(0).evaluate().toString(); 473 String s2 = argument(1).evaluate().toString(); 475 474 476 475 if (s2.isEmpty()) … … 487 486 Value FunSubstringAfter::evaluate() const 488 487 { 489 String s1 = arg (0)->evaluate().toString();490 String s2 = arg (1)->evaluate().toString();488 String s1 = argument(0).evaluate().toString(); 489 String s2 = argument(1).evaluate().toString(); 491 490 492 491 size_t i = s1.find(s2); … … 499 498 Value FunSubstring::evaluate() const 500 499 { 501 String s = arg (0)->evaluate().toString();502 double doublePos = arg (1)->evaluate().toNumber();500 String s = argument(0).evaluate().toString(); 501 double doublePos = argument(1).evaluate().toNumber(); 503 502 if (std::isnan(doublePos)) 504 503 return ""; 505 504 long pos = static_cast<long>(FunRound::round(doublePos)); 506 bool haveLength = arg Count() == 3;505 bool haveLength = argumentCount() == 3; 507 506 long len = -1; 508 507 if (haveLength) { 509 double doubleLen = arg (2)->evaluate().toNumber();508 double doubleLen = argument(2).evaluate().toNumber(); 510 509 if (std::isnan(doubleLen)) 511 510 return ""; … … 530 529 Value FunStringLength::evaluate() const 531 530 { 532 if (!arg Count())531 if (!argumentCount()) 533 532 return Value(Expression::evaluationContext().node.get()).toString().length(); 534 return arg (0)->evaluate().toString().length();533 return argument(0).evaluate().toString().length(); 535 534 } 536 535 537 536 Value FunNormalizeSpace::evaluate() const 538 537 { 539 if (!arg Count()) {538 if (!argumentCount()) { 540 539 String s = Value(Expression::evaluationContext().node.get()).toString(); 541 540 return s.simplifyWhiteSpace(); 542 541 } 543 542 544 String s = arg (0)->evaluate().toString();543 String s = argument(0).evaluate().toString(); 545 544 return s.simplifyWhiteSpace(); 546 545 } … … 548 547 Value FunTranslate::evaluate() const 549 548 { 550 String s1 = arg (0)->evaluate().toString();551 String s2 = arg (1)->evaluate().toString();552 String s3 = arg (2)->evaluate().toString();549 String s1 = argument(0).evaluate().toString(); 550 String s2 = argument(1).evaluate().toString(); 551 String s3 = argument(2).evaluate().toString(); 553 552 StringBuilder result; 554 553 … … 568 567 Value FunBoolean::evaluate() const 569 568 { 570 return arg (0)->evaluate().toBoolean();569 return argument(0).evaluate().toBoolean(); 571 570 } 572 571 573 572 Value FunNot::evaluate() const 574 573 { 575 return !arg (0)->evaluate().toBoolean();574 return !argument(0).evaluate().toBoolean(); 576 575 } 577 576 … … 583 582 Value FunLang::evaluate() const 584 583 { 585 String lang = arg (0)->evaluate().toString();584 String lang = argument(0).evaluate().toString(); 586 585 587 586 const Attribute* languageAttribute = 0; … … 623 622 Value FunNumber::evaluate() const 624 623 { 625 if (!arg Count())624 if (!argumentCount()) 626 625 return Value(Expression::evaluationContext().node.get()).toNumber(); 627 return arg (0)->evaluate().toNumber();626 return argument(0).evaluate().toNumber(); 628 627 } 629 628 630 629 Value FunSum::evaluate() const 631 630 { 632 Value a = arg (0)->evaluate();631 Value a = argument(0).evaluate(); 633 632 if (!a.isNodeSet()) 634 633 return 0.0; … … 647 646 Value FunFloor::evaluate() const 648 647 { 649 return floor(arg (0)->evaluate().toNumber());648 return floor(argument(0).evaluate().toNumber()); 650 649 } 651 650 652 651 Value FunCeiling::evaluate() const 653 652 { 654 return ceil(arg (0)->evaluate().toNumber());653 return ceil(argument(0).evaluate().toNumber()); 655 654 } 656 655 … … 668 667 Value FunRound::evaluate() const 669 668 { 670 return round(arg (0)->evaluate().toNumber());669 return round(argument(0).evaluate().toNumber()); 671 670 } 672 671 -
trunk/Source/WebCore/xml/XPathFunctions.h
r97771 r154745 31 31 32 32 namespace WebCore { 33 namespace XPath { 33 34 34 namespace XPath { 35 class Function : public Expression { 36 public: 37 void setArguments(const Vector<Expression*>&); 38 void setName(const String& name) { m_name = name; } 35 39 36 class Function : public Expression { 37 public: 38 void setArguments(const Vector<Expression*>&); 39 void setName(const String& name) { m_name = name; } 40 protected: 41 Expression* arg(int pos) { return subExpr(pos); } 42 const Expression* arg(int pos) const { return subExpr(pos); } 43 unsigned int argCount() const { return subExprCount(); } 44 String name() const { return m_name; } 40 protected: 41 unsigned argumentCount() const { return subExpressionCount(); } 42 const Expression& argument(int pos) const { return subExpression(pos); } 45 43 46 private: 47 String m_name; 48 }; 44 String name() const { return m_name; } 49 45 50 Function* createFunction(const String& name, const Vector<Expression*>& args = Vector<Expression*>()); 46 private: 47 String m_name; 48 }; 51 49 52 } // namespace XPath 50 Function* createFunction(const String& name, const Vector<Expression*>& args = Vector<Expression*>()); 53 51 52 } // namespace XPath 54 53 } // namespace WebCore 55 54 -
trunk/Source/WebCore/xml/XPathPredicate.cpp
r112555 r154745 61 61 Value Negative::evaluate() const 62 62 { 63 Value p(subExpr (0)->evaluate());63 Value p(subExpression(0).evaluate()); 64 64 return -p.toNumber(); 65 65 } … … 74 74 Value NumericOp::evaluate() const 75 75 { 76 Value lhs(subExpr (0)->evaluate());77 Value rhs(subExpr (1)->evaluate());76 Value lhs(subExpression(0).evaluate()); 77 Value rhs(subExpression(1).evaluate()); 78 78 79 79 double leftVal = lhs.toNumber(); … … 193 193 Value EqTestOp::evaluate() const 194 194 { 195 Value lhs(subExpr (0)->evaluate());196 Value rhs(subExpr (1)->evaluate());195 Value lhs(subExpression(0).evaluate()); 196 Value rhs(subExpression(1).evaluate()); 197 197 198 198 return compare(lhs, rhs); … … 216 216 Value LogicalOp::evaluate() const 217 217 { 218 Value lhs(subExpr (0)->evaluate());218 Value lhs(subExpression(0).evaluate()); 219 219 220 220 // This is not only an optimization, http://www.w3.org/TR/xpath … … 224 224 return lhsBool; 225 225 226 return subExpr (1)->evaluate().toBoolean();226 return subExpression(1).evaluate().toBoolean(); 227 227 } 228 228 229 229 Value Union::evaluate() const 230 230 { 231 Value lhsResult = subExpr (0)->evaluate();232 Value rhs = subExpr (1)->evaluate();231 Value lhsResult = subExpression(0).evaluate(); 232 Value rhs = subExpression(1).evaluate(); 233 233 234 234 NodeSet& resultSet = lhsResult.modifiableNodeSet();
Note: See TracChangeset
for help on using the changeset viewer.