|
|
|
|
| 24 |
* -- 19990806 |
24 |
* -- 19990806 |
| 25 |
* - changed constant short declarations in many of the classes |
25 |
* - changed constant short declarations in many of the classes |
| 26 |
* with enumerations, commented with //--LF |
26 |
* with enumerations, commented with //--LF |
|
|
27 |
* Jonas Sicking, sicking@bigfoot.com |
| 28 |
* -- removal of Patterns and some restructuring |
| 29 |
* in the class set |
| 27 |
* |
30 |
* |
| 28 |
* $Id: Expr.h,v 1.10 2001/04/08 14:33:45 peterv%netscape.com Exp $ |
31 |
* $Id: Expr.h,v 1.10 2001/04/08 14:33:45 peterv%netscape.com Exp $ |
| 29 |
*/ |
32 |
*/ |
|
|
| 52 |
//necessary prototypes |
55 |
//necessary prototypes |
| 53 |
class FunctionCall; |
56 |
class FunctionCall; |
| 54 |
|
57 |
|
|
|
58 |
typedef class Expr Pattern; |
| 59 |
typedef class Expr PatternExpr; |
| 60 |
|
| 61 |
|
| 55 |
/** |
62 |
/** |
| 56 |
* The expression context and state class used when evaluating XPath Expressions. |
63 |
* The expression context and state class used when evaluating XPath Expressions. |
| 57 |
**/ |
64 |
**/ |
|
|
| 115 |
/** |
122 |
/** |
| 116 |
* Virtual destructor, important for subclasses |
123 |
* Virtual destructor, important for subclasses |
| 117 |
**/ |
124 |
**/ |
| 118 |
virtual ~Expr() {}; |
125 |
virtual ~Expr(); |
| 119 |
|
126 |
|
| 120 |
/** |
127 |
/** |
| 121 |
* Evaluates this Expr based on the given context node and processor state |
128 |
* Evaluates this Expr based on the given context node and processor state |
|
|
| 127 |
virtual ExprResult* evaluate(Node* context, ContextState* cs) = 0; |
134 |
virtual ExprResult* evaluate(Node* context, ContextState* cs) = 0; |
| 128 |
|
135 |
|
| 129 |
/** |
136 |
/** |
|
|
137 |
* Determines whether this Expr matches the given node within |
| 138 |
* the given context |
| 139 |
**/ |
| 140 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
| 141 |
|
| 142 |
/** |
| 143 |
* Returns the default priority of this Expr based on the given Node, |
| 144 |
* context Node, and ContextState. |
| 145 |
**/ |
| 146 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
| 147 |
|
| 148 |
/** |
| 130 |
* Returns the String representation of this Expr. |
149 |
* Returns the String representation of this Expr. |
| 131 |
* @param dest the String to use when creating the String |
150 |
* @param dest the String to use when creating the String |
| 132 |
* representation. The String representation will be appended to |
151 |
* representation. The String representation will be appended to |
|
|
| 138 |
|
157 |
|
| 139 |
}; //-- Expr |
158 |
}; //-- Expr |
| 140 |
|
159 |
|
| 141 |
|
|
|
| 142 |
/** |
160 |
/** |
| 143 |
* This class represents a FunctionCall as defined by the XPath 1.0 |
161 |
* This class represents a FunctionCall as defined by the XPath 1.0 |
| 144 |
* Recommendation. |
162 |
* Recommendation. |
|
|
| 168 |
virtual ExprResult* evaluate(Node* context, ContextState* cs) = 0; |
186 |
virtual ExprResult* evaluate(Node* context, ContextState* cs) = 0; |
| 169 |
|
187 |
|
| 170 |
/** |
188 |
/** |
|
|
189 |
* Determines whether this FunctionCall matches the given node within |
| 190 |
* the given context |
| 191 |
**/ |
| 192 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
| 193 |
|
| 194 |
/** |
| 195 |
* Returns the default priority of this FunctionCall based on the given Node, |
| 196 |
* context Node, and ContextState. |
| 197 |
**/ |
| 198 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
| 199 |
|
| 200 |
/** |
| 171 |
* Returns the name of this FunctionCall |
201 |
* Returns the name of this FunctionCall |
| 172 |
* @return the name of this FunctionCall |
202 |
* @return the name of this FunctionCall |
| 173 |
**/ |
203 |
**/ |
|
|
| 185 |
**/ |
215 |
**/ |
| 186 |
void setName(const String& name); |
216 |
void setName(const String& name); |
| 187 |
/** |
217 |
/** |
| 188 |
* Returns the String representation of this Pattern. |
218 |
* Returns the String representation of this Expr. |
| 189 |
* @param dest the String to use when creating the String |
219 |
* @param dest the String to use when creating the String |
| 190 |
* representation. The String representation will be appended to |
220 |
* representation. The String representation will be appended to |
| 191 |
* any data in the destination String, to allow cascading calls to |
221 |
* any data in the destination String, to allow cascading calls to |
| 192 |
* other #toString() methods for Expressions. |
222 |
* other #toString() methods for Expressions. |
| 193 |
* @return the String representation of this Pattern. |
223 |
* @return the String representation of this Expr. |
| 194 |
**/ |
224 |
**/ |
| 195 |
virtual void toString(String& dest); |
225 |
virtual void toString(String& dest); |
| 196 |
|
226 |
|
|
|
| 221 |
String name; |
251 |
String name; |
| 222 |
}; //-- FunctionCall |
252 |
}; //-- FunctionCall |
| 223 |
|
253 |
|
| 224 |
/** |
|
|
| 225 |
* A base Pattern class |
| 226 |
**/ |
| 227 |
class Pattern { |
| 228 |
|
| 229 |
public: |
| 230 |
|
| 231 |
/** |
| 232 |
* Virtual destructor, important for subclasses |
| 233 |
**/ |
| 234 |
virtual ~Pattern() {}; |
| 235 |
|
| 236 |
/** |
| 237 |
* Returns the default priority of this Pattern based on the given Node, |
| 238 |
* context Node, and ContextState. |
| 239 |
* If this pattern does not match the given Node under the current context Node and |
| 240 |
* ContextState then Negative Infinity is returned. |
| 241 |
**/ |
| 242 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs) = 0; |
| 243 |
|
| 244 |
/** |
| 245 |
* Determines whether this Pattern matches the given node within |
| 246 |
* the given context |
| 247 |
**/ |
| 248 |
virtual MBool matches(Node* node, Node* context, ContextState* cs) = 0; |
| 249 |
|
| 250 |
|
| 251 |
/** |
| 252 |
* Returns the String representation of this Pattern. |
| 253 |
* @param dest the String to use when creating the String |
| 254 |
* representation. The String representation will be appended to |
| 255 |
* any data in the destination String, to allow cascading calls to |
| 256 |
* other #toString() methods for Expressions. |
| 257 |
* @return the String representation of this Pattern. |
| 258 |
**/ |
| 259 |
virtual void toString(String& dest) = 0; |
| 260 |
|
| 261 |
}; //-- Pattern |
| 262 |
|
254 |
|
| 263 |
|
|
|
| 264 |
/** |
255 |
/** |
| 265 |
* A Base class for all Expressions and Patterns |
|
|
| 266 |
**/ |
| 267 |
class PatternExpr : |
| 268 |
public Expr, |
| 269 |
public Pattern |
| 270 |
{ |
| 271 |
|
| 272 |
public: |
| 273 |
|
| 274 |
/** |
| 275 |
* Virtual destructor, important for subclasses |
| 276 |
**/ |
| 277 |
virtual ~PatternExpr() {}; |
| 278 |
|
| 279 |
/** |
| 280 |
* Evaluates this Expr based on the given context node and processor state |
| 281 |
* @param context the context node for evaluation of this Expr |
| 282 |
* @param ps the ContextState containing the stack information needed |
| 283 |
* for evaluation |
| 284 |
* @return the result of the evaluation |
| 285 |
**/ |
| 286 |
virtual ExprResult* evaluate(Node* context, ContextState* cs) = 0; |
| 287 |
|
| 288 |
/** |
| 289 |
* Returns the default priority of this Pattern based on the given Node, |
| 290 |
* context Node, and ContextState. |
| 291 |
* If this pattern does not match the given Node under the current context Node and |
| 292 |
* ContextState then Negative Infinity is returned. |
| 293 |
**/ |
| 294 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs) = 0; |
| 295 |
|
| 296 |
/** |
| 297 |
* Determines whether this PatternExpr matches the given node within |
| 298 |
* the given context |
| 299 |
**/ |
| 300 |
virtual MBool matches(Node* node, Node* context, ContextState* cs) = 0; |
| 301 |
|
| 302 |
/** |
| 303 |
* Returns the String representation of this PatternExpr. |
| 304 |
* @param dest the String to use when creating the String |
| 305 |
* representation. The String representation will be appended to |
| 306 |
* any data in the destination String, to allow cascading calls to |
| 307 |
* other #toString() methods for Expressions. |
| 308 |
* @return the String representation of this PatternExpr. |
| 309 |
**/ |
| 310 |
virtual void toString(String& dest) = 0; |
| 311 |
|
| 312 |
}; //-- PatternExpr |
| 313 |
|
| 314 |
/** |
| 315 |
* Represents an AttributeValueTemplate |
256 |
* Represents an AttributeValueTemplate |
| 316 |
**/ |
257 |
**/ |
| 317 |
class AttributeValueTemplate: public Expr { |
258 |
class AttributeValueTemplate: public Expr { |
|
|
| 355 |
* This class represents a NodeTestExpr as defined by the XSL |
296 |
* This class represents a NodeTestExpr as defined by the XSL |
| 356 |
* Working Draft |
297 |
* Working Draft |
| 357 |
**/ |
298 |
**/ |
| 358 |
class NodeExpr : public PatternExpr { |
299 |
class NodeExpr : public Expr { |
| 359 |
|
300 |
|
| 360 |
public: |
301 |
public: |
| 361 |
|
302 |
|
|
|
| 379 |
//------------------/ |
320 |
//------------------/ |
| 380 |
|
321 |
|
| 381 |
/** |
322 |
/** |
| 382 |
* Returns the default priority of this Pattern based on the given Node, |
|
|
| 383 |
* context Node, and ContextState. |
| 384 |
* If this pattern does not match the given Node under the current context Node and |
| 385 |
* ContextState then Negative Infinity is returned. |
| 386 |
**/ |
| 387 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs) = 0; |
| 388 |
|
| 389 |
/** |
| 390 |
* Returns the type of this NodeExpr |
323 |
* Returns the type of this NodeExpr |
| 391 |
* @return the type of this NodeExpr |
324 |
* @return the type of this NodeExpr |
| 392 |
**/ |
325 |
**/ |
|
|
| 399 |
virtual MBool matches(Node* node, Node* context, ContextState* cs) = 0; |
332 |
virtual MBool matches(Node* node, Node* context, ContextState* cs) = 0; |
| 400 |
|
333 |
|
| 401 |
/** |
334 |
/** |
| 402 |
* Returns the String representation of this Pattern. |
335 |
* Returns the default priority of this Expr based on the given Node, |
|
|
336 |
* context Node, and ContextState. |
| 337 |
**/ |
| 338 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs) = 0; |
| 339 |
|
| 340 |
/** |
| 341 |
* Returns the String representation of this Expr. |
| 403 |
* @param dest the String to use when creating the String |
342 |
* @param dest the String to use when creating the String |
| 404 |
* representation. The String representation will be appended to |
343 |
* representation. The String representation will be appended to |
| 405 |
* any data in the destination String, to allow cascading calls to |
344 |
* any data in the destination String, to allow cascading calls to |
| 406 |
* other #toString() methods for Expressions. |
345 |
* other #toString() methods for Expressions. |
| 407 |
* @return the String representation of this Pattern. |
346 |
* @return the String representation of this Expr. |
| 408 |
**/ |
347 |
**/ |
| 409 |
virtual void toString(String& dest) = 0; |
348 |
virtual void toString(String& dest) = 0; |
| 410 |
|
349 |
|
|
|
| 445 |
//-----------------------------------/ |
384 |
//-----------------------------------/ |
| 446 |
|
385 |
|
| 447 |
/** |
386 |
/** |
| 448 |
* Returns the default priority of this Pattern based on the given Node, |
|
|
| 449 |
* context Node, and ContextState. |
| 450 |
* If this pattern does not match the given Node under the current context Node and |
| 451 |
* ContextState then Negative Infinity is returned. |
| 452 |
**/ |
| 453 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
| 454 |
|
| 455 |
/** |
| 456 |
* Evaluates this Expr based on the given context node and processor state |
387 |
* Evaluates this Expr based on the given context node and processor state |
| 457 |
* @param context the context node for evaluation of this Expr |
388 |
* @param context the context node for evaluation of this Expr |
| 458 |
* @param ps the ContextState containing the stack information needed |
389 |
* @param ps the ContextState containing the stack information needed |
|
|
| 474 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
405 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
| 475 |
|
406 |
|
| 476 |
/** |
407 |
/** |
|
|
408 |
* Returns the default priority of this Expr based on the given Node, |
| 409 |
* context Node, and ContextState. |
| 410 |
**/ |
| 411 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
| 412 |
|
| 413 |
/** |
| 477 |
* Returns the String representation of this NodeExpr. |
414 |
* Returns the String representation of this NodeExpr. |
| 478 |
* @param dest the String to use when creating the String |
415 |
* @param dest the String to use when creating the String |
| 479 |
* representation. The String representation will be appended to |
416 |
* representation. The String representation will be appended to |
|
|
| 521 |
* Destroys this BasicNodeExpr |
458 |
* Destroys this BasicNodeExpr |
| 522 |
**/ |
459 |
**/ |
| 523 |
virtual ~BasicNodeExpr(); |
460 |
virtual ~BasicNodeExpr(); |
|
|
461 |
|
| 462 |
/** |
| 463 |
* Sets the name of the node to match. Only availible for pi nodes |
| 464 |
**/ |
| 465 |
void setNodeName(const String& name); |
| 524 |
|
466 |
|
| 525 |
//-----------------------------------/ |
467 |
//-----------------------------------/ |
| 526 |
//- Method signatures from NodeExpr -/ |
468 |
//- Method signatures from NodeExpr -/ |
| 527 |
//-----------------------------------/ |
469 |
//-----------------------------------/ |
| 528 |
|
470 |
|
| 529 |
/** |
471 |
/** |
| 530 |
* Returns the default priority of this Pattern based on the given Node, |
|
|
| 531 |
* context Node, and ContextState. |
| 532 |
* If this pattern does not match the given Node under the current context Node and |
| 533 |
* ContextState then Negative Infinity is returned. |
| 534 |
**/ |
| 535 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
| 536 |
|
| 537 |
/** |
| 538 |
* Evaluates this Expr based on the given context node and processor state |
472 |
* Evaluates this Expr based on the given context node and processor state |
| 539 |
* @param context the context node for evaluation of this Expr |
473 |
* @param context the context node for evaluation of this Expr |
| 540 |
* @param ps the ContextState containing the stack information needed |
474 |
* @param ps the ContextState containing the stack information needed |
|
|
| 556 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
490 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
| 557 |
|
491 |
|
| 558 |
/** |
492 |
/** |
|
|
493 |
* Returns the default priority of this Expr based on the given Node, |
| 494 |
* context Node, and ContextState. |
| 495 |
**/ |
| 496 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
| 497 |
|
| 498 |
/** |
| 559 |
* Returns the String representation of this NodeExpr. |
499 |
* Returns the String representation of this NodeExpr. |
| 560 |
* @param dest the String to use when creating the String |
500 |
* @param dest the String to use when creating the String |
| 561 |
* representation. The String representation will be appended to |
501 |
* representation. The String representation will be appended to |
|
|
| 567 |
|
507 |
|
| 568 |
private: |
508 |
private: |
| 569 |
NodeExprType type; |
509 |
NodeExprType type; |
|
|
510 |
String nodeName; |
| 511 |
MBool nodeNameSet; |
| 570 |
}; //-- BasicNodeExpr |
512 |
}; //-- BasicNodeExpr |
| 571 |
|
513 |
|
| 572 |
/** |
514 |
/** |
|
|
| 611 |
virtual ExprResult* evaluate(Node* context, ContextState* cs); |
553 |
virtual ExprResult* evaluate(Node* context, ContextState* cs); |
| 612 |
|
554 |
|
| 613 |
/** |
555 |
/** |
| 614 |
* Returns the default priority of this Pattern based on the given Node, |
556 |
* Returns the default priority of this Expr based on the given Node, |
| 615 |
* context Node, and ContextState. |
557 |
* context Node, and ContextState. |
| 616 |
* If this pattern does not match the given Node under the current context Node and |
|
|
| 617 |
* ContextState then Negative Infinity is returned. |
| 618 |
**/ |
558 |
**/ |
| 619 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
559 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
| 620 |
|
560 |
|
|
|
| 655 |
}; //-- ElementExpr |
595 |
}; //-- ElementExpr |
| 656 |
|
596 |
|
| 657 |
/** |
597 |
/** |
| 658 |
* This class represents a IdentityExpr, which only matches a node |
|
|
| 659 |
* if it is equal to the context node |
| 660 |
**/ |
| 661 |
class IdentityExpr : public Expr { |
| 662 |
|
| 663 |
public: |
| 664 |
|
| 665 |
//------------------/ |
| 666 |
//- Public Methods -/ |
| 667 |
//------------------/ |
| 668 |
|
| 669 |
/** |
| 670 |
* Evaluates this Expr based on the given context node and processor state |
| 671 |
* @param context the context node for evaluation of this Expr |
| 672 |
* @param ps the ContextState containing the stack information needed |
| 673 |
* for evaluation |
| 674 |
* @return the result of the evaluation |
| 675 |
**/ |
| 676 |
virtual ExprResult* evaluate(Node* context, ContextState* cs); |
| 677 |
|
| 678 |
/** |
| 679 |
* Returns the String representation of this NodeExpr. |
| 680 |
* @param dest the String to use when creating the String |
| 681 |
* representation. The String representation will be appended to |
| 682 |
* any data in the destination String, to allow cascading calls to |
| 683 |
* other #toString() methods for Expressions. |
| 684 |
* @return the String representation of this NodeExpr. |
| 685 |
**/ |
| 686 |
virtual void toString(String& dest); |
| 687 |
|
| 688 |
}; //-- IdentityExpr |
| 689 |
|
| 690 |
/** |
| 691 |
* This class represents a ParentExpr, which only selects a node |
| 692 |
* if it is equal to the context node's parent |
| 693 |
**/ |
| 694 |
class ParentExpr : public Expr { |
| 695 |
|
| 696 |
public: |
| 697 |
|
| 698 |
//------------------/ |
| 699 |
//- Public Methods -/ |
| 700 |
//------------------/ |
| 701 |
|
| 702 |
/** |
| 703 |
* Evaluates this Expr based on the given context node and processor state |
| 704 |
* @param context the context node for evaluation of this Expr |
| 705 |
* @param ps the ContextState containing the stack information needed |
| 706 |
* for evaluation |
| 707 |
* @return the result of the evaluation |
| 708 |
**/ |
| 709 |
virtual ExprResult* evaluate(Node* context, ContextState* cs); |
| 710 |
|
| 711 |
|
| 712 |
/** |
| 713 |
* Returns the String representation of this NodeExpr. |
| 714 |
* @param dest the String to use when creating the String |
| 715 |
* representation. The String representation will be appended to |
| 716 |
* any data in the destination String, to allow cascading calls to |
| 717 |
* other #toString() methods for Expressions. |
| 718 |
* @return the String representation of this NodeExpr. |
| 719 |
**/ |
| 720 |
virtual void toString(String& dest); |
| 721 |
|
| 722 |
}; //-- ParentExpr |
| 723 |
|
| 724 |
/** |
| 725 |
* This class represents a TextExpr, which only matches any text node |
598 |
* This class represents a TextExpr, which only matches any text node |
| 726 |
**/ |
599 |
**/ |
| 727 |
class TextExpr : public NodeExpr { |
600 |
class TextExpr : public NodeExpr { |
|
|
| 742 |
virtual ExprResult* evaluate(Node* context, ContextState* cs); |
615 |
virtual ExprResult* evaluate(Node* context, ContextState* cs); |
| 743 |
|
616 |
|
| 744 |
/** |
617 |
/** |
| 745 |
* Returns the default priority of this Pattern based on the given Node, |
|
|
| 746 |
* context Node, and ContextState. |
| 747 |
* If this pattern does not match the given Node under the current context Node and |
| 748 |
* ContextState then Negative Infinity is returned. |
| 749 |
**/ |
| 750 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
| 751 |
|
| 752 |
/** |
| 753 |
* Returns the type of this NodeExpr |
618 |
* Returns the type of this NodeExpr |
| 754 |
* @return the type of this NodeExpr |
619 |
* @return the type of this NodeExpr |
| 755 |
**/ |
620 |
**/ |
|
|
| 761 |
**/ |
626 |
**/ |
| 762 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
627 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
| 763 |
|
628 |
|
|
|
629 |
/** |
| 630 |
* Returns the default priority of this Expr based on the given Node, |
| 631 |
* context Node, and ContextState. |
| 632 |
**/ |
| 633 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
| 764 |
|
634 |
|
| 765 |
/** |
635 |
/** |
| 766 |
* Returns the String representation of this NodeExpr. |
636 |
* Returns the String representation of this NodeExpr. |
|
|
| 827 |
List predicates; |
697 |
List predicates; |
| 828 |
}; //-- PredicateList |
698 |
}; //-- PredicateList |
| 829 |
|
699 |
|
| 830 |
class LocationStep : public PredicateList, public PatternExpr { |
700 |
class LocationStep : public PredicateList, public Expr { |
| 831 |
|
701 |
|
| 832 |
public: |
702 |
public: |
| 833 |
|
703 |
|
|
|
| 887 |
**/ |
757 |
**/ |
| 888 |
void setNodeExpr(NodeExpr* nodeExpr); |
758 |
void setNodeExpr(NodeExpr* nodeExpr); |
| 889 |
|
759 |
|
| 890 |
//------------------------------------/ |
760 |
//-----------------------------/ |
| 891 |
//- Virtual methods from PatternExpr -/ |
761 |
//- Virtual methods from Expr -/ |
| 892 |
//------------------------------------/ |
762 |
//-----------------------------/ |
| 893 |
|
763 |
|
| 894 |
/** |
764 |
/** |
| 895 |
* Evaluates this Expr based on the given context node and processor state |
765 |
* Evaluates this Expr based on the given context node and processor state |
|
|
| 901 |
virtual ExprResult* evaluate(Node* context, ContextState* cs); |
771 |
virtual ExprResult* evaluate(Node* context, ContextState* cs); |
| 902 |
|
772 |
|
| 903 |
/** |
773 |
/** |
| 904 |
* Returns the default priority of this Pattern based on the given Node, |
774 |
* Determines whether this Expr matches the given node within |
| 905 |
* context Node, and ContextState. |
775 |
* the given context |
| 906 |
* If this pattern does not match the given Node under the current context Node and |
|
|
| 907 |
* ContextState then Negative Infinity is returned. |
| 908 |
**/ |
776 |
**/ |
| 909 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
777 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
| 910 |
|
778 |
|
| 911 |
/** |
779 |
/** |
| 912 |
* Determines whether this PatternExpr matches the given node within |
780 |
* Returns the default priority of this Expr based on the given Node, |
| 913 |
* the given context |
781 |
* context Node, and ContextState. |
| 914 |
**/ |
782 |
**/ |
| 915 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
783 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
| 916 |
|
784 |
|
| 917 |
/** |
785 |
/** |
| 918 |
* Returns the String representation of this PatternExpr. |
786 |
* Returns the String representation of this Expr. |
| 919 |
* @param dest the String to use when creating the String |
787 |
* @param dest the String to use when creating the String |
| 920 |
* representation. The String representation will be appended to |
788 |
* representation. The String representation will be appended to |
| 921 |
* any data in the destination String, to allow cascading calls to |
789 |
* any data in the destination String, to allow cascading calls to |
| 922 |
* other #toString() methods for Expressions. |
790 |
* other #toString() methods for Expressions. |
| 923 |
* @return the String representation of this PatternExpr. |
791 |
* @return the String representation of this Expr. |
| 924 |
**/ |
792 |
**/ |
| 925 |
virtual void toString(String& dest); |
793 |
virtual void toString(String& dest); |
| 926 |
|
794 |
|
| 927 |
private: |
795 |
private: |
| 928 |
|
796 |
|
| 929 |
NodeExpr* nodeExpr; |
797 |
NodeExpr* nodeExpr; |
| 930 |
short axisIdentifier; |
798 |
short axisIdentifier; |
| 931 |
|
799 |
|
| 932 |
void fromDescendants(Node* context, ContextState* cs, NodeSet* nodes); |
800 |
void fromDescendants(Node* context, ContextState* cs, NodeSet* nodes); |
|
|
801 |
void fromDescendantsRev(Node* context, ContextState* cs, NodeSet* nodes); |
| 933 |
|
802 |
|
| 934 |
}; //-- LocationStep |
803 |
}; //-- LocationStep |
| 935 |
|
804 |
|
| 936 |
|
805 |
|
| 937 |
class FilterExpr : public PredicateList, public PatternExpr { |
806 |
class FilterExpr : public PredicateList, public Expr { |
| 938 |
|
807 |
|
| 939 |
public: |
808 |
public: |
| 940 |
|
809 |
|
|
|
| 961 |
**/ |
830 |
**/ |
| 962 |
void setExpr(Expr* expr); |
831 |
void setExpr(Expr* expr); |
| 963 |
|
832 |
|
| 964 |
//------------------------------------/ |
833 |
//-----------------------------/ |
| 965 |
//- Virtual methods from PatternExpr -/ |
834 |
//- Virtual methods from Expr -/ |
| 966 |
//------------------------------------/ |
835 |
//-----------------------------/ |
| 967 |
|
836 |
|
| 968 |
/** |
837 |
/** |
| 969 |
* Evaluates this Expr based on the given context node and processor state |
838 |
* Evaluates this Expr based on the given context node and processor state |
|
|
| 975 |
virtual ExprResult* evaluate(Node* context, ContextState* cs); |
844 |
virtual ExprResult* evaluate(Node* context, ContextState* cs); |
| 976 |
|
845 |
|
| 977 |
/** |
846 |
/** |
| 978 |
* Returns the default priority of this Pattern based on the given Node, |
847 |
* Determines whether this Expr matches the given node within |
| 979 |
* context Node, and ContextState. |
848 |
* the given context |
| 980 |
* If this pattern does not match the given Node under the current context Node and |
|
|
| 981 |
* ContextState then Negative Infinity is returned. |
| 982 |
**/ |
849 |
**/ |
| 983 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
850 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
| 984 |
|
851 |
|
| 985 |
/** |
852 |
/** |
| 986 |
* Determines whether this PatternExpr matches the given node within |
853 |
* Returns the default priority of this Expr based on the given Node, |
| 987 |
* the given context |
854 |
* context Node, and ContextState. |
| 988 |
**/ |
855 |
**/ |
| 989 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
856 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
| 990 |
|
857 |
|
| 991 |
/** |
858 |
/** |
| 992 |
* Returns the String representation of this PatternExpr. |
859 |
* Returns the String representation of this Expr. |
| 993 |
* @param dest the String to use when creating the String |
860 |
* @param dest the String to use when creating the String |
| 994 |
* representation. The String representation will be appended to |
861 |
* representation. The String representation will be appended to |
| 995 |
* any data in the destination String, to allow cascading calls to |
862 |
* any data in the destination String, to allow cascading calls to |
| 996 |
* other #toString() methods for Expressions. |
863 |
* other #toString() methods for Expressions. |
| 997 |
* @return the String representation of this PatternExpr. |
864 |
* @return the String representation of this Expr. |
| 998 |
**/ |
865 |
**/ |
| 999 |
virtual void toString(String& dest); |
866 |
virtual void toString(String& dest); |
| 1000 |
|
867 |
|
| 1001 |
private: |
868 |
private: |
| 1002 |
|
869 |
|
| 1003 |
Expr* expr; |
870 |
Expr* expr; |
| 1004 |
|
871 |
|
| 1005 |
}; //-- FilterExpr |
872 |
}; //-- FilterExpr |
| 1006 |
|
873 |
|
|
|
| 1131 |
}; //-- AdditiveExpr |
998 |
}; //-- AdditiveExpr |
| 1132 |
|
999 |
|
| 1133 |
/** |
1000 |
/** |
|
|
1001 |
* Represents an UnaryExpr. |
| 1002 |
**/ |
| 1003 |
class UnaryExpr : public Expr { |
| 1004 |
|
| 1005 |
public: |
| 1006 |
|
| 1007 |
UnaryExpr(); |
| 1008 |
UnaryExpr(Expr* expr); |
| 1009 |
~UnaryExpr(); |
| 1010 |
|
| 1011 |
/** |
| 1012 |
* Sets the expression to negate |
| 1013 |
**/ |
| 1014 |
void setExpr(Expr* expr); |
| 1015 |
|
| 1016 |
/** |
| 1017 |
* Evaluates this Expr based on the given context node and processor state |
| 1018 |
* @param context the context node for evaluation of this Expr |
| 1019 |
* @param ps the ContextState containing the stack information needed |
| 1020 |
* for evaluation |
| 1021 |
* @return the result of the evaluation |
| 1022 |
**/ |
| 1023 |
virtual ExprResult* evaluate(Node* context, ContextState* cs); |
| 1024 |
|
| 1025 |
/** |
| 1026 |
* Returns the String representation of this Expr. |
| 1027 |
* @param dest the String to use when creating the String |
| 1028 |
* representation. The String representation will be appended to |
| 1029 |
* any data in the destination String, to allow cascading calls to |
| 1030 |
* other #toString() methods for Expressions. |
| 1031 |
* @return the String representation of this Expr. |
| 1032 |
**/ |
| 1033 |
virtual void toString(String& str); |
| 1034 |
|
| 1035 |
private: |
| 1036 |
Expr* expr; |
| 1037 |
}; //-- AdditiveExpr |
| 1038 |
|
| 1039 |
/** |
| 1134 |
* Represents a BooleanExpr, a binary expression that |
1040 |
* Represents a BooleanExpr, a binary expression that |
| 1135 |
* performs a boolean operation between it's lvalue and rvalue:<BR/> |
1041 |
* performs a boolean operation between it's lvalue and rvalue:<BR/> |
| 1136 |
**/ |
1042 |
**/ |
|
|
| 1344 |
/** |
1250 |
/** |
| 1345 |
* Represents a PathExpr |
1251 |
* Represents a PathExpr |
| 1346 |
**/ |
1252 |
**/ |
| 1347 |
class PathExpr : public PatternExpr { |
1253 |
class PathExpr : public Expr { |
| 1348 |
|
1254 |
|
| 1349 |
public: |
1255 |
public: |
| 1350 |
|
1256 |
|
|
|
| 1359 |
PathExpr(); |
1265 |
PathExpr(); |
| 1360 |
|
1266 |
|
| 1361 |
/** |
1267 |
/** |
| 1362 |
* Destructor, will delete all Pattern Expressions |
1268 |
* Destructor, will delete all Expressions |
| 1363 |
**/ |
1269 |
**/ |
| 1364 |
virtual ~PathExpr(); |
1270 |
virtual ~PathExpr(); |
| 1365 |
|
1271 |
|
| 1366 |
/** |
1272 |
/** |
| 1367 |
* Adds the PatternExpr to this PathExpr |
1273 |
* Adds the Expr to this PathExpr |
| 1368 |
* @param expr the Expr to add to this PathExpr |
1274 |
* @param expr the Expr to add to this PathExpr |
| 1369 |
* @param index the index at which to add the given Expr |
1275 |
* @param index the index at which to add the given Expr |
| 1370 |
**/ |
1276 |
**/ |
| 1371 |
void addPatternExpr(int index, PatternExpr* expr, short ancestryOp); |
1277 |
void addExpr(int index, Expr* expr, short ancestryOp); |
| 1372 |
|
1278 |
|
| 1373 |
/** |
1279 |
/** |
| 1374 |
* Adds the PatternExpr to this PathExpr |
1280 |
* Adds the Expr to this PathExpr |
| 1375 |
* @param expr the Expr to add to this PathExpr |
1281 |
* @param expr the Expr to add to this PathExpr |
| 1376 |
**/ |
1282 |
**/ |
| 1377 |
void addPatternExpr(PatternExpr* expr, short ancestryOp); |
1283 |
void addExpr(Expr* expr, short ancestryOp); |
| 1378 |
|
1284 |
|
| 1379 |
virtual MBool isAbsolute(); |
1285 |
virtual MBool isAbsolute(); |
| 1380 |
|
1286 |
|
| 1381 |
//------------------------------------/ |
1287 |
//-----------------------------/ |
| 1382 |
//- Virtual methods from PatternExpr -/ |
1288 |
//- Virtual methods from Expr -/ |
| 1383 |
//------------------------------------/ |
1289 |
//-----------------------------/ |
| 1384 |
|
1290 |
|
| 1385 |
/** |
1291 |
/** |
| 1386 |
* Evaluates this Expr based on the given context node and processor state |
1292 |
* Evaluates this Expr based on the given context node and processor state |
|
|
| 1392 |
virtual ExprResult* evaluate(Node* context, ContextState* cs); |
1298 |
virtual ExprResult* evaluate(Node* context, ContextState* cs); |
| 1393 |
|
1299 |
|
| 1394 |
/** |
1300 |
/** |
| 1395 |
* Returns the default priority of this Pattern based on the given Node, |
1301 |
* Determines whether this Expr matches the given node within |
| 1396 |
* context Node, and ContextState. |
1302 |
* the given context |
| 1397 |
* If this pattern does not match the given Node under the current context Node and |
|
|
| 1398 |
* ContextState then Negative Infinity is returned. |
| 1399 |
**/ |
1303 |
**/ |
| 1400 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
1304 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
| 1401 |
|
1305 |
|
| 1402 |
/** |
1306 |
/** |
| 1403 |
* Determines whether this PatternExpr matches the given node within |
1307 |
* Returns the default priority of this Expr based on the given Node, |
| 1404 |
* the given context |
1308 |
* context Node, and ContextState. |
| 1405 |
**/ |
1309 |
**/ |
| 1406 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
1310 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
| 1407 |
|
1311 |
|
| 1408 |
/** |
1312 |
/** |
| 1409 |
* Returns the String representation of this PatternExpr. |
1313 |
* Returns the String representation of this Expr. |
| 1410 |
* @param dest the String to use when creating the String |
1314 |
* @param dest the String to use when creating the String |
| 1411 |
* representation. The String representation will be appended to |
1315 |
* representation. The String representation will be appended to |
| 1412 |
* any data in the destination String, to allow cascading calls to |
1316 |
* any data in the destination String, to allow cascading calls to |
| 1413 |
* other #toString() methods for Expressions. |
1317 |
* other #toString() methods for Expressions. |
| 1414 |
* @return the String representation of this PatternExpr. |
1318 |
* @return the String representation of this Expr. |
| 1415 |
**/ |
1319 |
**/ |
| 1416 |
virtual void toString(String& dest); |
1320 |
virtual void toString(String& dest); |
| 1417 |
|
1321 |
|
| 1418 |
private: |
1322 |
private: |
| 1419 |
|
1323 |
|
| 1420 |
struct PathExprItem { |
1324 |
struct PathExprItem { |
| 1421 |
PatternExpr* pExpr; |
1325 |
Expr* expr; |
| 1422 |
short ancestryOp; |
1326 |
short ancestryOp; |
| 1423 |
}; |
1327 |
}; |
| 1424 |
|
1328 |
|
|
|
| 1426 |
|
1330 |
|
| 1427 |
/** |
1331 |
/** |
| 1428 |
* Selects from the descendants of the context node |
1332 |
* Selects from the descendants of the context node |
| 1429 |
* all nodes that match the PatternExpr |
1333 |
* all nodes that match the Expr |
| 1430 |
* -- this will be moving to a Utility class |
1334 |
* -- this will be moving to a Utility class |
| 1431 |
**/ |
1335 |
**/ |
| 1432 |
void fromDescendants(PatternExpr* pExpr, |
1336 |
void evalDescendants(Expr* expr, |
| 1433 |
Node* context, |
1337 |
Node* context, |
| 1434 |
ContextState* cs, |
1338 |
ContextState* cs, |
| 1435 |
NodeSet* nodes); |
1339 |
NodeSet* resNodes); |
| 1436 |
|
1340 |
|
| 1437 |
}; //-- PathExpr |
1341 |
}; //-- PathExpr |
| 1438 |
|
1342 |
|
|
|
| 1459 |
virtual MBool isAbsolute(); |
1363 |
virtual MBool isAbsolute(); |
| 1460 |
|
1364 |
|
| 1461 |
/** |
1365 |
/** |
| 1462 |
* Returns the default priority of this Pattern based on the given Node, |
|
|
| 1463 |
* context Node, and ContextState. |
| 1464 |
* If this pattern does not match the given Node under the current context Node and |
| 1465 |
* ContextState then Negative Infinity is returned. |
| 1466 |
**/ |
| 1467 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
| 1468 |
|
| 1469 |
/** |
| 1470 |
* Determines whether this NodeExpr matches the given node within |
1366 |
* Determines whether this NodeExpr matches the given node within |
| 1471 |
* the given context |
1367 |
* the given context |
| 1472 |
**/ |
1368 |
**/ |
| 1473 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
1369 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
| 1474 |
|
1370 |
|
|
|
1371 |
/** |
| 1372 |
* Returns the default priority of this Expr based on the given Node, |
| 1373 |
* context Node, and ContextState. |
| 1374 |
**/ |
| 1375 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
| 1376 |
|
| 1475 |
/** |
1377 |
/** |
| 1476 |
* Returns the String representation of this PatternExpr. |
1378 |
* Returns the String representation of this Expr. |
| 1477 |
* @param dest the String to use when creating the String |
1379 |
* @param dest the String to use when creating the String |
| 1478 |
* representation. The String representation will be appended to |
1380 |
* representation. The String representation will be appended to |
| 1479 |
* any data in the destination String, to allow cascading calls to |
1381 |
* any data in the destination String, to allow cascading calls to |
| 1480 |
* other #toString() methods for Expressions. |
1382 |
* other #toString() methods for Expressions. |
| 1481 |
* @return the String representation of this PatternExpr. |
1383 |
* @return the String representation of this Expr. |
| 1482 |
**/ |
1384 |
**/ |
| 1483 |
virtual void toString(String& dest); |
1385 |
virtual void toString(String& dest); |
| 1484 |
|
1386 |
|
|
|
| 1488 |
/** |
1390 |
/** |
| 1489 |
* Represents a UnionExpr |
1391 |
* Represents a UnionExpr |
| 1490 |
**/ |
1392 |
**/ |
| 1491 |
class UnionExpr : public PatternExpr { |
1393 |
class UnionExpr : public Expr { |
| 1492 |
|
1394 |
|
| 1493 |
public: |
1395 |
public: |
| 1494 |
|
1396 |
|
|
|
| 1506 |
* Adds the PathExpr to this UnionExpr |
1408 |
* Adds the PathExpr to this UnionExpr |
| 1507 |
* @param expr the Expr to add to this UnionExpr |
1409 |
* @param expr the Expr to add to this UnionExpr |
| 1508 |
**/ |
1410 |
**/ |
| 1509 |
void addPathExpr(PathExpr* expr); |
1411 |
void addExpr(Expr* expr); |
| 1510 |
|
1412 |
|
| 1511 |
/** |
1413 |
/** |
| 1512 |
* Adds the PathExpr to this UnionExpr at the specified index |
1414 |
* Adds the PathExpr to this UnionExpr at the specified index |
| 1513 |
* @param expr the Expr to add to this UnionExpr |
1415 |
* @param expr the Expr to add to this UnionExpr |
| 1514 |
**/ |
1416 |
**/ |
| 1515 |
void addPathExpr(int index, PathExpr* expr); |
1417 |
void addExpr(int index, Expr* expr); |
| 1516 |
|
1418 |
|
| 1517 |
//------------------------------------/ |
1419 |
//-----------------------------/ |
| 1518 |
//- Virtual methods from PatternExpr -/ |
1420 |
//- Virtual methods from Expr -/ |
| 1519 |
//------------------------------------/ |
1421 |
//-----------------------------/ |
| 1520 |
|
1422 |
|
| 1521 |
/** |
1423 |
/** |
| 1522 |
* Evaluates this Expr based on the given context node and processor state |
1424 |
* Evaluates this Expr based on the given context node and processor state |
|
|
| 1528 |
virtual ExprResult* evaluate(Node* context, ContextState* cs); |
1430 |
virtual ExprResult* evaluate(Node* context, ContextState* cs); |
| 1529 |
|
1431 |
|
| 1530 |
/** |
1432 |
/** |
| 1531 |
* Returns the default priority of this Pattern based on the given Node, |
1433 |
* Determines whether this Expr matches the given node within |
| 1532 |
* context Node, and ContextState. |
1434 |
* the given context |
| 1533 |
* If this pattern does not match the given Node under the current context Node and |
|
|
| 1534 |
* ContextState then Negative Infinity is returned. |
| 1535 |
**/ |
1435 |
**/ |
| 1536 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
1436 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
| 1537 |
|
1437 |
|
| 1538 |
/** |
1438 |
/** |
| 1539 |
* Determines whether this PatternExpr matches the given node within |
1439 |
* Returns the default priority of this Expr based on the given Node, |
| 1540 |
* the given context |
1440 |
* context Node, and ContextState. |
| 1541 |
**/ |
1441 |
**/ |
| 1542 |
virtual MBool matches(Node* node, Node* context, ContextState* cs); |
1442 |
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs); |
| 1543 |
|
1443 |
|
| 1544 |
/** |
1444 |
/** |
| 1545 |
* Returns the String representation of this PatternExpr. |
1445 |
* Returns the String representation of this Expr. |
| 1546 |
* @param dest the String to use when creating the String |
1446 |
* @param dest the String to use when creating the String |
| 1547 |
* representation. The String representation will be appended to |
1447 |
* representation. The String representation will be appended to |
| 1548 |
* any data in the destination String, to allow cascading calls to |
1448 |
* any data in the destination String, to allow cascading calls to |
| 1549 |
* other #toString() methods for Expressions. |
1449 |
* other #toString() methods for Expressions. |
| 1550 |
* @return the String representation of this PatternExpr. |
1450 |
* @return the String representation of this Expr. |
| 1551 |
**/ |
1451 |
**/ |
| 1552 |
virtual void toString(String& dest); |
1452 |
virtual void toString(String& dest); |
| 1553 |
|
1453 |
|