| OLD | NEW |
| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 { | 68 { |
| 69 return m_value; | 69 return m_value; |
| 70 } | 70 } |
| 71 | 71 |
| 72 Value Negative::evaluate(EvaluationContext& context) const | 72 Value Negative::evaluate(EvaluationContext& context) const |
| 73 { | 73 { |
| 74 Value p(subExpr(0)->evaluate(context)); | 74 Value p(subExpr(0)->evaluate(context)); |
| 75 return -p.toNumber(); | 75 return -p.toNumber(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 NumericOp::NumericOp(Opcode opcode, PassOwnPtrWillBeRawPtr<Expression> lhs, Pass
OwnPtrWillBeRawPtr<Expression> rhs) | 78 NumericOp::NumericOp(Opcode opcode, Expression* lhs, Expression* rhs) |
| 79 : m_opcode(opcode) | 79 : m_opcode(opcode) |
| 80 { | 80 { |
| 81 addSubExpression(lhs); | 81 addSubExpression(lhs); |
| 82 addSubExpression(rhs); | 82 addSubExpression(rhs); |
| 83 } | 83 } |
| 84 | 84 |
| 85 Value NumericOp::evaluate(EvaluationContext& context) const | 85 Value NumericOp::evaluate(EvaluationContext& context) const |
| 86 { | 86 { |
| 87 Value lhs(subExpr(0)->evaluate(context)); | 87 Value lhs(subExpr(0)->evaluate(context)); |
| 88 Value rhs(subExpr(1)->evaluate(context)); | 88 Value rhs(subExpr(1)->evaluate(context)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 99 return leftVal * rightVal; | 99 return leftVal * rightVal; |
| 100 case OP_Div: | 100 case OP_Div: |
| 101 return leftVal / rightVal; | 101 return leftVal / rightVal; |
| 102 case OP_Mod: | 102 case OP_Mod: |
| 103 return fmod(leftVal, rightVal); | 103 return fmod(leftVal, rightVal); |
| 104 } | 104 } |
| 105 ASSERT_NOT_REACHED(); | 105 ASSERT_NOT_REACHED(); |
| 106 return 0.0; | 106 return 0.0; |
| 107 } | 107 } |
| 108 | 108 |
| 109 EqTestOp::EqTestOp(Opcode opcode, PassOwnPtrWillBeRawPtr<Expression> lhs, PassOw
nPtrWillBeRawPtr<Expression> rhs) | 109 EqTestOp::EqTestOp(Opcode opcode, Expression* lhs, Expression* rhs) |
| 110 : m_opcode(opcode) | 110 : m_opcode(opcode) |
| 111 { | 111 { |
| 112 addSubExpression(lhs); | 112 addSubExpression(lhs); |
| 113 addSubExpression(rhs); | 113 addSubExpression(rhs); |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool EqTestOp::compare(EvaluationContext& context, const Value& lhs, const Value
& rhs) const | 116 bool EqTestOp::compare(EvaluationContext& context, const Value& lhs, const Value
& rhs) const |
| 117 { | 117 { |
| 118 if (lhs.isNodeSet()) { | 118 if (lhs.isNodeSet()) { |
| 119 const NodeSet& lhsSet = lhs.toNodeSet(&context); | 119 const NodeSet& lhsSet = lhs.toNodeSet(&context); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 217 } |
| 218 | 218 |
| 219 Value EqTestOp::evaluate(EvaluationContext& context) const | 219 Value EqTestOp::evaluate(EvaluationContext& context) const |
| 220 { | 220 { |
| 221 Value lhs(subExpr(0)->evaluate(context)); | 221 Value lhs(subExpr(0)->evaluate(context)); |
| 222 Value rhs(subExpr(1)->evaluate(context)); | 222 Value rhs(subExpr(1)->evaluate(context)); |
| 223 | 223 |
| 224 return compare(context, lhs, rhs); | 224 return compare(context, lhs, rhs); |
| 225 } | 225 } |
| 226 | 226 |
| 227 LogicalOp::LogicalOp(Opcode opcode, PassOwnPtrWillBeRawPtr<Expression> lhs, Pass
OwnPtrWillBeRawPtr<Expression> rhs) | 227 LogicalOp::LogicalOp(Opcode opcode, Expression* lhs, Expression* rhs) |
| 228 : m_opcode(opcode) | 228 : m_opcode(opcode) |
| 229 { | 229 { |
| 230 addSubExpression(lhs); | 230 addSubExpression(lhs); |
| 231 addSubExpression(rhs); | 231 addSubExpression(rhs); |
| 232 } | 232 } |
| 233 | 233 |
| 234 bool LogicalOp::shortCircuitOn() const | 234 bool LogicalOp::shortCircuitOn() const |
| 235 { | 235 { |
| 236 return m_opcode != OP_And; | 236 return m_opcode != OP_And; |
| 237 } | 237 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 267 resultSet.append(node); | 267 resultSet.append(node); |
| 268 } | 268 } |
| 269 | 269 |
| 270 // It is also possible to use merge sort to avoid making the result | 270 // It is also possible to use merge sort to avoid making the result |
| 271 // unsorted; but this would waste the time in cases when order is not | 271 // unsorted; but this would waste the time in cases when order is not |
| 272 // important. | 272 // important. |
| 273 resultSet.markSorted(false); | 273 resultSet.markSorted(false); |
| 274 return lhsResult; | 274 return lhsResult; |
| 275 } | 275 } |
| 276 | 276 |
| 277 Predicate::Predicate(PassOwnPtrWillBeRawPtr<Expression> expr) | 277 Predicate::Predicate(Expression* expr) |
| 278 : m_expr(expr) | 278 : m_expr(expr) |
| 279 { | 279 { |
| 280 } | 280 } |
| 281 | 281 |
| 282 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(Predicate); | |
| 283 | |
| 284 void Predicate::trace(Visitor* visitor) | 282 void Predicate::trace(Visitor* visitor) |
| 285 { | 283 { |
| 286 visitor->trace(m_expr); | 284 visitor->trace(m_expr); |
| 287 } | 285 } |
| 288 | 286 |
| 289 bool Predicate::evaluate(EvaluationContext& context) const | 287 bool Predicate::evaluate(EvaluationContext& context) const |
| 290 { | 288 { |
| 291 ASSERT(m_expr); | 289 ASSERT(m_expr); |
| 292 | 290 |
| 293 Value result(m_expr->evaluate(context)); | 291 Value result(m_expr->evaluate(context)); |
| 294 | 292 |
| 295 // foo[3] means foo[position()=3] | 293 // foo[3] means foo[position()=3] |
| 296 if (result.isNumber()) | 294 if (result.isNumber()) |
| 297 return EqTestOp(EqTestOp::OpcodeEqual, adoptPtrWillBeNoop(createFunction
("position")), adoptPtrWillBeNoop(new Number(result.toNumber()))).evaluate(conte
xt).toBoolean(); | 295 return EqTestOp(EqTestOp::OpcodeEqual, createFunction("position"), new N
umber(result.toNumber())).evaluate(context).toBoolean(); |
| 298 | 296 |
| 299 return result.toBoolean(); | 297 return result.toBoolean(); |
| 300 } | 298 } |
| 301 | 299 |
| 302 } | 300 } // namespace XPath |
| 303 } | 301 |
| 302 } // namespace blink |
| OLD | NEW |