- Revision
- 154745
- Author
- [email protected]
- Date
- 2013-08-28 07:31:16 -0700 (Wed, 28 Aug 2013)
Log Message
Clean up XPathExpressionNode and XPath::Function
https://bugs.webkit.org/show_bug.cgi?id=120411
Reviewed by Antti Koivisto.
Rename the subexpression and function argument getters to be more descriptive,
remove the non-const overloads (they were never used) and change the getters to return
references since they can never be null.
* xml/XPathExpressionNode.cpp:
* xml/XPathExpressionNode.h:
(WebCore::XPath::ParseNode::~ParseNode):
(WebCore::XPath::_expression_::addSubExpression):
(WebCore::XPath::_expression_::isContextNodeSensitive):
(WebCore::XPath::_expression_::setIsContextNodeSensitive):
(WebCore::XPath::_expression_::isContextPositionSensitive):
(WebCore::XPath::_expression_::setIsContextPositionSensitive):
(WebCore::XPath::_expression_::isContextSizeSensitive):
(WebCore::XPath::_expression_::setIsContextSizeSensitive):
(WebCore::XPath::_expression_::subExpressionCount):
(WebCore::XPath::_expression_::subExpression):
* xml/XPathFunctions.cpp:
(WebCore::XPath::Function::setArguments):
(WebCore::XPath::FunId::evaluate):
(WebCore::XPath::FunLocalName::evaluate):
(WebCore::XPath::FunNamespaceURI::evaluate):
(WebCore::XPath::FunName::evaluate):
(WebCore::XPath::FunCount::evaluate):
(WebCore::XPath::FunString::evaluate):
(WebCore::XPath::FunConcat::evaluate):
(WebCore::XPath::FunStartsWith::evaluate):
(WebCore::XPath::FunContains::evaluate):
(WebCore::XPath::FunSubstringBefore::evaluate):
(WebCore::XPath::FunSubstringAfter::evaluate):
(WebCore::XPath::FunSubstring::evaluate):
(WebCore::XPath::FunStringLength::evaluate):
(WebCore::XPath::FunNormalizeSpace::evaluate):
(WebCore::XPath::FunTranslate::evaluate):
(WebCore::XPath::FunBoolean::evaluate):
(WebCore::XPath::FunNot::evaluate):
(WebCore::XPath::FunLang::evaluate):
(WebCore::XPath::FunNumber::evaluate):
(WebCore::XPath::FunSum::evaluate):
(WebCore::XPath::FunFloor::evaluate):
(WebCore::XPath::FunCeiling::evaluate):
(WebCore::XPath::FunRound::evaluate):
* xml/XPathFunctions.h:
(WebCore::XPath::Function::setName):
(WebCore::XPath::Function::argumentCount):
(WebCore::XPath::Function::argument):
(WebCore::XPath::Function::name):
* xml/XPathPredicate.cpp:
(WebCore::XPath::Negative::evaluate):
(WebCore::XPath::NumericOp::evaluate):
(WebCore::XPath::EqTestOp::evaluate):
(WebCore::XPath::LogicalOp::evaluate):
(WebCore::XPath::Union::evaluate):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (154744 => 154745)
--- trunk/Source/WebCore/ChangeLog 2013-08-28 14:25:21 UTC (rev 154744)
+++ trunk/Source/WebCore/ChangeLog 2013-08-28 14:31:16 UTC (rev 154745)
@@ -1,3 +1,63 @@
+2013-08-28 Anders Carlsson <[email protected]>
+
+ Clean up XPathExpressionNode and XPath::Function
+ https://bugs.webkit.org/show_bug.cgi?id=120411
+
+ Reviewed by Antti Koivisto.
+
+ Rename the subexpression and function argument getters to be more descriptive,
+ remove the non-const overloads (they were never used) and change the getters to return
+ references since they can never be null.
+
+ * xml/XPathExpressionNode.cpp:
+ * xml/XPathExpressionNode.h:
+ (WebCore::XPath::ParseNode::~ParseNode):
+ (WebCore::XPath::_expression_::addSubExpression):
+ (WebCore::XPath::_expression_::isContextNodeSensitive):
+ (WebCore::XPath::_expression_::setIsContextNodeSensitive):
+ (WebCore::XPath::_expression_::isContextPositionSensitive):
+ (WebCore::XPath::_expression_::setIsContextPositionSensitive):
+ (WebCore::XPath::_expression_::isContextSizeSensitive):
+ (WebCore::XPath::_expression_::setIsContextSizeSensitive):
+ (WebCore::XPath::_expression_::subExpressionCount):
+ (WebCore::XPath::_expression_::subExpression):
+ * xml/XPathFunctions.cpp:
+ (WebCore::XPath::Function::setArguments):
+ (WebCore::XPath::FunId::evaluate):
+ (WebCore::XPath::FunLocalName::evaluate):
+ (WebCore::XPath::FunNamespaceURI::evaluate):
+ (WebCore::XPath::FunName::evaluate):
+ (WebCore::XPath::FunCount::evaluate):
+ (WebCore::XPath::FunString::evaluate):
+ (WebCore::XPath::FunConcat::evaluate):
+ (WebCore::XPath::FunStartsWith::evaluate):
+ (WebCore::XPath::FunContains::evaluate):
+ (WebCore::XPath::FunSubstringBefore::evaluate):
+ (WebCore::XPath::FunSubstringAfter::evaluate):
+ (WebCore::XPath::FunSubstring::evaluate):
+ (WebCore::XPath::FunStringLength::evaluate):
+ (WebCore::XPath::FunNormalizeSpace::evaluate):
+ (WebCore::XPath::FunTranslate::evaluate):
+ (WebCore::XPath::FunBoolean::evaluate):
+ (WebCore::XPath::FunNot::evaluate):
+ (WebCore::XPath::FunLang::evaluate):
+ (WebCore::XPath::FunNumber::evaluate):
+ (WebCore::XPath::FunSum::evaluate):
+ (WebCore::XPath::FunFloor::evaluate):
+ (WebCore::XPath::FunCeiling::evaluate):
+ (WebCore::XPath::FunRound::evaluate):
+ * xml/XPathFunctions.h:
+ (WebCore::XPath::Function::setName):
+ (WebCore::XPath::Function::argumentCount):
+ (WebCore::XPath::Function::argument):
+ (WebCore::XPath::Function::name):
+ * xml/XPathPredicate.cpp:
+ (WebCore::XPath::Negative::evaluate):
+ (WebCore::XPath::NumericOp::evaluate):
+ (WebCore::XPath::EqTestOp::evaluate):
+ (WebCore::XPath::LogicalOp::evaluate):
+ (WebCore::XPath::Union::evaluate):
+
2013-08-28 Andreas Kling <[email protected]>
Page::pluginData() should return a reference.
Modified: trunk/Source/WebCore/xml/XPathExpressionNode.cpp (154744 => 154745)
--- trunk/Source/WebCore/xml/XPathExpressionNode.cpp 2013-08-28 14:25:21 UTC (rev 154744)
+++ trunk/Source/WebCore/xml/XPathExpressionNode.cpp 2013-08-28 14:31:16 UTC (rev 154745)
@@ -1,6 +1,6 @@
/*
* Copyright 2005 Frerich Raabe <[email protected]>
- * Copyright (C) 2006 Apple Computer, Inc.
+ * Copyright (C) 2006, 2013 Apple Computer, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -51,5 +51,5 @@
deleteAllValues(m_subExpressions);
}
-}
-}
+} // namespace XPath
+} // namespace WebCore
Modified: trunk/Source/WebCore/xml/XPathExpressionNode.h (154744 => 154745)
--- trunk/Source/WebCore/xml/XPathExpressionNode.h 2013-08-28 14:25:21 UTC (rev 154744)
+++ trunk/Source/WebCore/xml/XPathExpressionNode.h 2013-08-28 14:31:16 UTC (rev 154745)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2005 Frerich Raabe <[email protected]>
- * Copyright (C) 2006, 2009 Apple Inc.
+ * Copyright (C) 2006, 2009, 2013 Apple Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -34,68 +34,67 @@
#include <wtf/text/StringHash.h>
namespace WebCore {
+namespace XPath {
- namespace XPath {
-
- struct EvaluationContext {
- WTF_MAKE_FAST_ALLOCATED;
- public:
- RefPtr<Node> node;
- unsigned long size;
- unsigned long position;
- HashMap<String, String> variableBindings;
+struct EvaluationContext {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
+ RefPtr<Node> node;
+ unsigned long size;
+ unsigned long position;
+ HashMap<String, String> variableBindings;
- bool hadTypeConversionError;
- };
+ bool hadTypeConversionError;
+};
- class ParseNode {
- public:
- virtual ~ParseNode() { }
- };
+class ParseNode {
+public:
+ virtual ~ParseNode() { }
+};
- class _expression_ : public ParseNode {
- WTF_MAKE_NONCOPYABLE(_expression_); WTF_MAKE_FAST_ALLOCATED;
- public:
- static EvaluationContext& evaluationContext();
+class _expression_ : public ParseNode {
+ WTF_MAKE_NONCOPYABLE(_expression_); WTF_MAKE_FAST_ALLOCATED;
+public:
+ static EvaluationContext& evaluationContext();
- _expression_();
- virtual ~_expression_();
+ virtual ~_expression_();
- virtual Value evaluate() const = 0;
+ void addSubExpression(_expression_* expr)
+ {
+ m_subExpressions.append(expr);
+ m_isContextNodeSensitive |= expr->m_isContextNodeSensitive;
+ m_isContextPositionSensitive |= expr->m_isContextPositionSensitive;
+ m_isContextSizeSensitive |= expr->m_isContextSizeSensitive;
+ }
- void addSubExpression(_expression_* expr)
- {
- m_subExpressions.append(expr);
- m_isContextNodeSensitive |= expr->m_isContextNodeSensitive;
- m_isContextPositionSensitive |= expr->m_isContextPositionSensitive;
- m_isContextSizeSensitive |= expr->m_isContextSizeSensitive;
- }
+ bool isContextNodeSensitive() const { return m_isContextNodeSensitive; }
+ void setIsContextNodeSensitive(bool value) { m_isContextNodeSensitive = value; }
- bool isContextNodeSensitive() const { return m_isContextNodeSensitive; }
- bool isContextPositionSensitive() const { return m_isContextPositionSensitive; }
- bool isContextSizeSensitive() const { return m_isContextSizeSensitive; }
- void setIsContextNodeSensitive(bool value) { m_isContextNodeSensitive = value; }
- void setIsContextPositionSensitive(bool value) { m_isContextPositionSensitive = value; }
- void setIsContextSizeSensitive(bool value) { m_isContextSizeSensitive = value; }
+ bool isContextPositionSensitive() const { return m_isContextPositionSensitive; }
+ void setIsContextPositionSensitive(bool value) { m_isContextPositionSensitive = value; }
- virtual Value::Type resultType() const = 0;
+ bool isContextSizeSensitive() const { return m_isContextSizeSensitive; }
+ void setIsContextSizeSensitive(bool value) { m_isContextSizeSensitive = value; }
- protected:
- unsigned subExprCount() const { return m_subExpressions.size(); }
- _expression_* subExpr(unsigned i) { return m_subExpressions[i]; }
- const _expression_* subExpr(unsigned i) const { return m_subExpressions[i]; }
+ virtual Value evaluate() const = 0;
+ virtual Value::Type resultType() const = 0;
- private:
- Vector<_expression_*> m_subExpressions;
+protected:
+ _expression_();
- // Evaluation details that can be used for optimization.
- bool m_isContextNodeSensitive;
- bool m_isContextPositionSensitive;
- bool m_isContextSizeSensitive;
- };
+ unsigned subExpressionCount() const { return m_subExpressions.size(); }
+ const _expression_& subExpression(unsigned i) const { return *m_subExpressions[i]; }
- }
+private:
+ Vector<_expression_*> m_subExpressions;
-}
+ // Evaluation details that can be used for optimization.
+ bool m_isContextNodeSensitive;
+ bool m_isContextPositionSensitive;
+ bool m_isContextSizeSensitive;
+};
-#endif // EXPRESSION_H
+} // namespace XPath
+} // namespace WebCore
+
+#endif // XPathExpressionNode_h
Modified: trunk/Source/WebCore/xml/XPathFunctions.cpp (154744 => 154745)
--- trunk/Source/WebCore/xml/XPathFunctions.cpp 2013-08-28 14:25:21 UTC (rev 154744)
+++ trunk/Source/WebCore/xml/XPathFunctions.cpp 2013-08-28 14:31:16 UTC (rev 154745)
@@ -292,7 +292,7 @@
void Function::setArguments(const Vector<_expression_*>& args)
{
- ASSERT(!subExprCount());
+ ASSERT(!subExpressionCount());
// Some functions use context node as implicit argument, so when explicit arguments are added, they may no longer be context node sensitive.
if (m_name != "lang" && !args.isEmpty())
@@ -315,7 +315,7 @@
Value FunId::evaluate() const
{
- Value a = arg(0)->evaluate();
+ Value a = argument(0).evaluate();
StringBuilder idList; // A whitespace-separated list of IDs
if (a.isNodeSet()) {
@@ -378,8 +378,8 @@
Value FunLocalName::evaluate() const
{
- if (argCount() > 0) {
- Value a = arg(0)->evaluate();
+ if (argumentCount() > 0) {
+ Value a = argument(0).evaluate();
if (!a.isNodeSet())
return "";
@@ -392,8 +392,8 @@
Value FunNamespaceURI::evaluate() const
{
- if (argCount() > 0) {
- Value a = arg(0)->evaluate();
+ if (argumentCount() > 0) {
+ Value a = argument(0).evaluate();
if (!a.isNodeSet())
return "";
@@ -406,8 +406,8 @@
Value FunName::evaluate() const
{
- if (argCount() > 0) {
- Value a = arg(0)->evaluate();
+ if (argumentCount() > 0) {
+ Value a = argument(0).evaluate();
if (!a.isNodeSet())
return "";
@@ -420,16 +420,16 @@
Value FunCount::evaluate() const
{
- Value a = arg(0)->evaluate();
+ Value a = argument(0).evaluate();
return double(a.toNodeSet().size());
}
Value FunString::evaluate() const
{
- if (!argCount())
+ if (!argumentCount())
return Value(_expression_::evaluationContext().node.get()).toString();
- return arg(0)->evaluate().toString();
+ return argument(0).evaluate().toString();
}
Value FunConcat::evaluate() const
@@ -437,9 +437,8 @@
StringBuilder result;
result.reserveCapacity(1024);
- unsigned count = argCount();
- for (unsigned i = 0; i < count; ++i) {
- String str(arg(i)->evaluate().toString());
+ for (unsigned i = 0, count = argumentCount(); i < count; ++i) {
+ String str(argument(i).evaluate().toString());
result.append(str);
}
@@ -448,8 +447,8 @@
Value FunStartsWith::evaluate() const
{
- String s1 = arg(0)->evaluate().toString();
- String s2 = arg(1)->evaluate().toString();
+ String s1 = argument(0).evaluate().toString();
+ String s2 = argument(1).evaluate().toString();
if (s2.isEmpty())
return true;
@@ -459,8 +458,8 @@
Value FunContains::evaluate() const
{
- String s1 = arg(0)->evaluate().toString();
- String s2 = arg(1)->evaluate().toString();
+ String s1 = argument(0).evaluate().toString();
+ String s2 = argument(1).evaluate().toString();
if (s2.isEmpty())
return true;
@@ -470,8 +469,8 @@
Value FunSubstringBefore::evaluate() const
{
- String s1 = arg(0)->evaluate().toString();
- String s2 = arg(1)->evaluate().toString();
+ String s1 = argument(0).evaluate().toString();
+ String s2 = argument(1).evaluate().toString();
if (s2.isEmpty())
return "";
@@ -486,8 +485,8 @@
Value FunSubstringAfter::evaluate() const
{
- String s1 = arg(0)->evaluate().toString();
- String s2 = arg(1)->evaluate().toString();
+ String s1 = argument(0).evaluate().toString();
+ String s2 = argument(1).evaluate().toString();
size_t i = s1.find(s2);
if (i == notFound)
@@ -498,15 +497,15 @@
Value FunSubstring::evaluate() const
{
- String s = arg(0)->evaluate().toString();
- double doublePos = arg(1)->evaluate().toNumber();
+ String s = argument(0).evaluate().toString();
+ double doublePos = argument(1).evaluate().toNumber();
if (std::isnan(doublePos))
return "";
long pos = static_cast<long>(FunRound::round(doublePos));
- bool haveLength = argCount() == 3;
+ bool haveLength = argumentCount() == 3;
long len = -1;
if (haveLength) {
- double doubleLen = arg(2)->evaluate().toNumber();
+ double doubleLen = argument(2).evaluate().toNumber();
if (std::isnan(doubleLen))
return "";
len = static_cast<long>(FunRound::round(doubleLen));
@@ -529,27 +528,27 @@
Value FunStringLength::evaluate() const
{
- if (!argCount())
+ if (!argumentCount())
return Value(_expression_::evaluationContext().node.get()).toString().length();
- return arg(0)->evaluate().toString().length();
+ return argument(0).evaluate().toString().length();
}
Value FunNormalizeSpace::evaluate() const
{
- if (!argCount()) {
+ if (!argumentCount()) {
String s = Value(_expression_::evaluationContext().node.get()).toString();
return s.simplifyWhiteSpace();
}
- String s = arg(0)->evaluate().toString();
+ String s = argument(0).evaluate().toString();
return s.simplifyWhiteSpace();
}
Value FunTranslate::evaluate() const
{
- String s1 = arg(0)->evaluate().toString();
- String s2 = arg(1)->evaluate().toString();
- String s3 = arg(2)->evaluate().toString();
+ String s1 = argument(0).evaluate().toString();
+ String s2 = argument(1).evaluate().toString();
+ String s3 = argument(2).evaluate().toString();
StringBuilder result;
for (unsigned i1 = 0; i1 < s1.length(); ++i1) {
@@ -567,12 +566,12 @@
Value FunBoolean::evaluate() const
{
- return arg(0)->evaluate().toBoolean();
+ return argument(0).evaluate().toBoolean();
}
Value FunNot::evaluate() const
{
- return !arg(0)->evaluate().toBoolean();
+ return !argument(0).evaluate().toBoolean();
}
Value FunTrue::evaluate() const
@@ -582,7 +581,7 @@
Value FunLang::evaluate() const
{
- String lang = arg(0)->evaluate().toString();
+ String lang = argument(0).evaluate().toString();
const Attribute* languageAttribute = 0;
Node* node = evaluationContext().node.get();
@@ -622,14 +621,14 @@
Value FunNumber::evaluate() const
{
- if (!argCount())
+ if (!argumentCount())
return Value(_expression_::evaluationContext().node.get()).toNumber();
- return arg(0)->evaluate().toNumber();
+ return argument(0).evaluate().toNumber();
}
Value FunSum::evaluate() const
{
- Value a = arg(0)->evaluate();
+ Value a = argument(0).evaluate();
if (!a.isNodeSet())
return 0.0;
@@ -646,12 +645,12 @@
Value FunFloor::evaluate() const
{
- return floor(arg(0)->evaluate().toNumber());
+ return floor(argument(0).evaluate().toNumber());
}
Value FunCeiling::evaluate() const
{
- return ceil(arg(0)->evaluate().toNumber());
+ return ceil(argument(0).evaluate().toNumber());
}
double FunRound::round(double val)
@@ -667,7 +666,7 @@
Value FunRound::evaluate() const
{
- return round(arg(0)->evaluate().toNumber());
+ return round(argument(0).evaluate().toNumber());
}
struct FunctionMapping {
Modified: trunk/Source/WebCore/xml/XPathFunctions.h (154744 => 154745)
--- trunk/Source/WebCore/xml/XPathFunctions.h 2013-08-28 14:25:21 UTC (rev 154744)
+++ trunk/Source/WebCore/xml/XPathFunctions.h 2013-08-28 14:31:16 UTC (rev 154745)
@@ -30,27 +30,26 @@
#include "XPathExpressionNode.h"
namespace WebCore {
+namespace XPath {
- namespace XPath {
+class Function : public _expression_ {
+public:
+ void setArguments(const Vector<_expression_*>&);
+ void setName(const String& name) { m_name = name; }
- class Function : public _expression_ {
- public:
- void setArguments(const Vector<_expression_*>&);
- void setName(const String& name) { m_name = name; }
- protected:
- _expression_* arg(int pos) { return subExpr(pos); }
- const _expression_* arg(int pos) const { return subExpr(pos); }
- unsigned int argCount() const { return subExprCount(); }
- String name() const { return m_name; }
+protected:
+ unsigned argumentCount() const { return subExpressionCount(); }
+ const _expression_& argument(int pos) const { return subExpression(pos); }
- private:
- String m_name;
- };
+ String name() const { return m_name; }
- Function* createFunction(const String& name, const Vector<_expression_*>& args = Vector<_expression_*>());
+private:
+ String m_name;
+};
- } // namespace XPath
+Function* createFunction(const String& name, const Vector<_expression_*>& args = Vector<_expression_*>());
+} // namespace XPath
} // namespace WebCore
#endif // XPathFunctions_h
Modified: trunk/Source/WebCore/xml/XPathPredicate.cpp (154744 => 154745)
--- trunk/Source/WebCore/xml/XPathPredicate.cpp 2013-08-28 14:25:21 UTC (rev 154744)
+++ trunk/Source/WebCore/xml/XPathPredicate.cpp 2013-08-28 14:31:16 UTC (rev 154745)
@@ -60,7 +60,7 @@
Value Negative::evaluate() const
{
- Value p(subExpr(0)->evaluate());
+ Value p(subExpression(0).evaluate());
return -p.toNumber();
}
@@ -73,8 +73,8 @@
Value NumericOp::evaluate() const
{
- Value lhs(subExpr(0)->evaluate());
- Value rhs(subExpr(1)->evaluate());
+ Value lhs(subExpression(0).evaluate());
+ Value rhs(subExpression(1).evaluate());
double leftVal = lhs.toNumber();
double rightVal = rhs.toNumber();
@@ -192,8 +192,8 @@
Value EqTestOp::evaluate() const
{
- Value lhs(subExpr(0)->evaluate());
- Value rhs(subExpr(1)->evaluate());
+ Value lhs(subExpression(0).evaluate());
+ Value rhs(subExpression(1).evaluate());
return compare(lhs, rhs);
}
@@ -215,7 +215,7 @@
Value LogicalOp::evaluate() const
{
- Value lhs(subExpr(0)->evaluate());
+ Value lhs(subExpression(0).evaluate());
// This is not only an optimization, http://www.w3.org/TR/xpath
// dictates that we must do short-circuit evaluation
@@ -223,13 +223,13 @@
if (lhsBool == shortCircuitOn())
return lhsBool;
- return subExpr(1)->evaluate().toBoolean();
+ return subExpression(1).evaluate().toBoolean();
}
Value Union::evaluate() const
{
- Value lhsResult = subExpr(0)->evaluate();
- Value rhs = subExpr(1)->evaluate();
+ Value lhsResult = subExpression(0).evaluate();
+ Value rhs = subExpression(1).evaluate();
NodeSet& resultSet = lhsResult.modifiableNodeSet();
const NodeSet& rhsNodes = rhs.toNodeSet();