Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: Source/core/xml/XPathPredicate.cpp

Issue 26763004: Vector stores Expression object as OwnPtr instead of raw pointer in XPath. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Change XPathGrammar.y also Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2005 Frerich Raabe <raabe@kde.org> 2 * Copyright 2005 Frerich Raabe <raabe@kde.org>
3 * Copyright (C) 2006 Apple Computer, Inc. 3 * Copyright (C) 2006 Apple Computer, Inc.
4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 { 56 {
57 return m_value; 57 return m_value;
58 } 58 }
59 59
60 Value Negative::evaluate() const 60 Value Negative::evaluate() const
61 { 61 {
62 Value p(subExpr(0)->evaluate()); 62 Value p(subExpr(0)->evaluate());
63 return -p.toNumber(); 63 return -p.toNumber();
64 } 64 }
65 65
66 NumericOp::NumericOp(Opcode opcode, Expression* lhs, Expression* rhs) 66 NumericOp::NumericOp(Opcode opcode, PassOwnPtr<Expression> lhs, PassOwnPtr<Expre ssion> rhs)
67 : m_opcode(opcode) 67 : m_opcode(opcode)
68 { 68 {
69 addSubExpression(lhs); 69 addSubExpression(lhs);
70 addSubExpression(rhs); 70 addSubExpression(rhs);
71 } 71 }
72 72
73 Value NumericOp::evaluate() const 73 Value NumericOp::evaluate() const
74 { 74 {
75 Value lhs(subExpr(0)->evaluate()); 75 Value lhs(subExpr(0)->evaluate());
76 Value rhs(subExpr(1)->evaluate()); 76 Value rhs(subExpr(1)->evaluate());
(...skipping 10 matching lines...) Expand all
87 return leftVal * rightVal; 87 return leftVal * rightVal;
88 case OP_Div: 88 case OP_Div:
89 return leftVal / rightVal; 89 return leftVal / rightVal;
90 case OP_Mod: 90 case OP_Mod:
91 return fmod(leftVal, rightVal); 91 return fmod(leftVal, rightVal);
92 } 92 }
93 ASSERT_NOT_REACHED(); 93 ASSERT_NOT_REACHED();
94 return 0.0; 94 return 0.0;
95 } 95 }
96 96
97 EqTestOp::EqTestOp(Opcode opcode, Expression* lhs, Expression* rhs) 97 EqTestOp::EqTestOp(Opcode opcode, PassOwnPtr<Expression> lhs, PassOwnPtr<Express ion> rhs)
98 : m_opcode(opcode) 98 : m_opcode(opcode)
99 { 99 {
100 addSubExpression(lhs); 100 addSubExpression(lhs);
101 addSubExpression(rhs); 101 addSubExpression(rhs);
102 } 102 }
103 103
104 bool EqTestOp::compare(const Value& lhs, const Value& rhs) const 104 bool EqTestOp::compare(const Value& lhs, const Value& rhs) const
105 { 105 {
106 if (lhs.isNodeSet()) { 106 if (lhs.isNodeSet()) {
107 const NodeSet& lhsSet = lhs.toNodeSet(); 107 const NodeSet& lhsSet = lhs.toNodeSet();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 190 }
191 191
192 Value EqTestOp::evaluate() const 192 Value EqTestOp::evaluate() const
193 { 193 {
194 Value lhs(subExpr(0)->evaluate()); 194 Value lhs(subExpr(0)->evaluate());
195 Value rhs(subExpr(1)->evaluate()); 195 Value rhs(subExpr(1)->evaluate());
196 196
197 return compare(lhs, rhs); 197 return compare(lhs, rhs);
198 } 198 }
199 199
200 LogicalOp::LogicalOp(Opcode opcode, Expression* lhs, Expression* rhs) 200 LogicalOp::LogicalOp(Opcode opcode, PassOwnPtr<Expression> lhs, PassOwnPtr<Expre ssion> rhs)
201 : m_opcode(opcode) 201 : m_opcode(opcode)
202 { 202 {
203 addSubExpression(lhs); 203 addSubExpression(lhs);
204 addSubExpression(rhs); 204 addSubExpression(rhs);
205 } 205 }
206 206
207 bool LogicalOp::shortCircuitOn() const 207 bool LogicalOp::shortCircuitOn() const
208 { 208 {
209 if (m_opcode == OP_And) 209 if (m_opcode == OP_And)
210 return false; //false and foo 210 return false; //false and foo
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 if (nodes.add(node).isNewEntry) 242 if (nodes.add(node).isNewEntry)
243 resultSet.append(node); 243 resultSet.append(node);
244 } 244 }
245 245
246 // It is also possible to use merge sort to avoid making the result unsorted ; 246 // It is also possible to use merge sort to avoid making the result unsorted ;
247 // but this would waste the time in cases when order is not important. 247 // but this would waste the time in cases when order is not important.
248 resultSet.markSorted(false); 248 resultSet.markSorted(false);
249 return lhsResult; 249 return lhsResult;
250 } 250 }
251 251
252 Predicate::Predicate(Expression* expr) 252 Predicate::Predicate(PassOwnPtr<Expression> expr)
253 : m_expr(expr) 253 : m_expr(expr)
254 { 254 {
255 } 255 }
256 256
257 Predicate::~Predicate() 257 Predicate::~Predicate()
258 { 258 {
259 delete m_expr;
260 } 259 }
261 260
262 bool Predicate::evaluate() const 261 bool Predicate::evaluate() const
263 { 262 {
264 ASSERT(m_expr != 0); 263 ASSERT(m_expr);
265 264
266 Value result(m_expr->evaluate()); 265 Value result(m_expr->evaluate());
267 266
268 // foo[3] means foo[position()=3] 267 // foo[3] means foo[position()=3]
269 if (result.isNumber()) 268 if (result.isNumber())
270 return EqTestOp(EqTestOp::OP_EQ, createFunction("position"), new Number( result.toNumber())).evaluate().toBoolean(); 269 return EqTestOp(EqTestOp::OP_EQ, adoptPtr(createFunction("position")), a doptPtr(new Number(result.toNumber()))).evaluate().toBoolean();
271 270
272 return result.toBoolean(); 271 return result.toBoolean();
273 } 272 }
274 273
275 } 274 }
276 } 275 }
OLDNEW
« Source/core/xml/XPathPath.cpp ('K') | « Source/core/xml/XPathPredicate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698