1 16 19 package org.apache.xpath.axes; 20 21 import org.apache.xalan.res.XSLMessages; 22 import org.apache.xml.dtm.Axis; 23 import org.apache.xml.dtm.DTMFilter; 24 import org.apache.xml.dtm.DTMIterator; 25 import org.apache.xpath.Expression; 26 import org.apache.xpath.compiler.Compiler; 27 import org.apache.xpath.compiler.FunctionTable; 28 import org.apache.xpath.compiler.OpCodes; 29 import org.apache.xpath.objects.XNumber; 30 import org.apache.xpath.patterns.ContextMatchStepPattern; 31 import org.apache.xpath.patterns.FunctionPattern; 32 import org.apache.xpath.patterns.NodeTest; 33 import org.apache.xpath.patterns.StepPattern; 34 import org.apache.xpath.res.XPATHErrorResources; 35 36 41 public class WalkerFactory 42 { 43 44 60 static AxesWalker loadOneWalker( 61 WalkingIterator lpi, Compiler compiler, int stepOpCodePos) 62 throws javax.xml.transform.TransformerException 63 { 64 65 AxesWalker firstWalker = null; 66 int stepType = compiler.getOp(stepOpCodePos); 67 68 if (stepType != OpCodes.ENDOP) 69 { 70 71 firstWalker = createDefaultWalker(compiler, stepType, lpi, 0); 74 75 firstWalker.init(compiler, stepOpCodePos, stepType); 76 } 77 78 return firstWalker; 79 } 80 81 98 static AxesWalker loadWalkers( 99 WalkingIterator lpi, Compiler compiler, int stepOpCodePos, int stepIndex) 100 throws javax.xml.transform.TransformerException 101 { 102 103 int stepType; 104 AxesWalker firstWalker = null; 105 AxesWalker walker, prevWalker = null; 106 107 int analysis = analyze(compiler, stepOpCodePos, stepIndex); 108 109 while (OpCodes.ENDOP != (stepType = compiler.getOp(stepOpCodePos))) 110 { 111 walker = createDefaultWalker(compiler, stepOpCodePos, lpi, analysis); 112 113 walker.init(compiler, stepOpCodePos, stepType); 114 walker.exprSetParent(lpi); 115 116 if (null == firstWalker) 118 { 119 firstWalker = walker; 120 } 121 else 122 { 123 prevWalker.setNextWalker(walker); 124 walker.setPrevWalker(prevWalker); 125 } 126 127 prevWalker = walker; 128 stepOpCodePos = compiler.getNextStepPos(stepOpCodePos); 129 130 if (stepOpCodePos < 0) 131 break; 132 } 133 134 return firstWalker; 135 } 136 137 public static boolean isSet(int analysis, int bits) 138 { 139 return (0 != (analysis & bits)); 140 } 141 142 public static void diagnoseIterator(String name, int analysis, Compiler compiler) 143 { 144 System.out.println(compiler.toString()+", "+name+", " 145 + Integer.toBinaryString(analysis) + ", " 146 + getAnalysisString(analysis)); 147 } 148 149 161 public static DTMIterator newDTMIterator( 162 Compiler compiler, int opPos, 163 boolean isTopLevel) 164 throws javax.xml.transform.TransformerException 165 { 166 167 int firstStepPos = compiler.getFirstChildPos(opPos); 168 int analysis = analyze(compiler, firstStepPos, 0); 169 boolean isOneStep = isOneStep(analysis); 170 DTMIterator iter; 171 172 if (isOneStep && walksSelfOnly(analysis) && 174 isWild(analysis) && !hasPredicate(analysis)) 175 { 176 if (DEBUG_ITERATOR_CREATION) 177 diagnoseIterator("SelfIteratorNoPredicate", analysis, compiler); 178 179 iter = new SelfIteratorNoPredicate(compiler, opPos, analysis); 182 } 183 else if (walksChildrenOnly(analysis) && isOneStep) 185 { 186 187 if (isWild(analysis) && !hasPredicate(analysis)) 189 { 190 if (DEBUG_ITERATOR_CREATION) 191 diagnoseIterator("ChildIterator", analysis, compiler); 192 193 iter = new ChildIterator(compiler, opPos, analysis); 195 } 196 else 197 { 198 if (DEBUG_ITERATOR_CREATION) 199 diagnoseIterator("ChildTestIterator", analysis, compiler); 200 201 iter = new ChildTestIterator(compiler, opPos, analysis); 203 } 204 } 205 else if (isOneStep && walksAttributes(analysis)) 207 { 208 if (DEBUG_ITERATOR_CREATION) 209 diagnoseIterator("AttributeIterator", analysis, compiler); 210 211 iter = new AttributeIterator(compiler, opPos, analysis); 214 } 215 else if(isOneStep && !walksFilteredList(analysis)) 216 { 217 if( !walksNamespaces(analysis) 218 && (walksInDocOrder(analysis) || isSet(analysis, BIT_PARENT))) 219 { 220 if (false || DEBUG_ITERATOR_CREATION) 221 diagnoseIterator("OneStepIteratorForward", analysis, compiler); 222 223 iter = new OneStepIteratorForward(compiler, opPos, analysis); 226 } 227 else 228 { 229 if (false || DEBUG_ITERATOR_CREATION) 230 diagnoseIterator("OneStepIterator", analysis, compiler); 231 232 iter = new OneStepIterator(compiler, opPos, analysis); 235 } 236 } 237 238 else if (isOptimizableForDescendantIterator(compiler, firstStepPos, 0) 251 ) 255 { 256 if (DEBUG_ITERATOR_CREATION) 257 diagnoseIterator("DescendantIterator", analysis, compiler); 258 259 iter = new DescendantIterator(compiler, opPos, analysis); 260 } 261 else 262 { 263 if(isNaturalDocOrder(compiler, firstStepPos, 0, analysis)) 264 { 265 if (false || DEBUG_ITERATOR_CREATION) 266 { 267 diagnoseIterator("WalkingIterator", analysis, compiler); 268 } 269 270 iter = new WalkingIterator(compiler, opPos, analysis, true); 271 } 272 else 273 { 274 if (DEBUG_ITERATOR_CREATION) 279 diagnoseIterator("WalkingIteratorSorted", analysis, compiler); 280 281 iter = new WalkingIteratorSorted(compiler, opPos, analysis, true); 282 } 283 } 284 if(iter instanceof LocPathIterator) 285 ((LocPathIterator)iter).setIsTopLevel(isTopLevel); 286 287 return iter; 288 } 289 290 304 public static int getAxisFromStep( 305 Compiler compiler, int stepOpCodePos) 306 throws javax.xml.transform.TransformerException 307 { 308 309 int stepType = compiler.getOp(stepOpCodePos); 310 311 switch (stepType) 312 { 313 case OpCodes.FROM_FOLLOWING : 314 return Axis.FOLLOWING; 315 case OpCodes.FROM_FOLLOWING_SIBLINGS : 316 return Axis.FOLLOWINGSIBLING; 317 case OpCodes.FROM_PRECEDING : 318 return Axis.PRECEDING; 319 case OpCodes.FROM_PRECEDING_SIBLINGS : 320 return Axis.PRECEDINGSIBLING; 321 case OpCodes.FROM_PARENT : 322 return Axis.PARENT; 323 case OpCodes.FROM_NAMESPACE : 324 return Axis.NAMESPACE; 325 case OpCodes.FROM_ANCESTORS : 326 return Axis.ANCESTOR; 327 case OpCodes.FROM_ANCESTORS_OR_SELF : 328 return Axis.ANCESTORORSELF; 329 case OpCodes.FROM_ATTRIBUTES : 330 return Axis.ATTRIBUTE; 331 case OpCodes.FROM_ROOT : 332 return Axis.ROOT; 333 case OpCodes.FROM_CHILDREN : 334 return Axis.CHILD; 335 case OpCodes.FROM_DESCENDANTS_OR_SELF : 336 return Axis.DESCENDANTORSELF; 337 case OpCodes.FROM_DESCENDANTS : 338 return Axis.DESCENDANT; 339 case OpCodes.FROM_SELF : 340 return Axis.SELF; 341 case OpCodes.OP_EXTFUNCTION : 342 case OpCodes.OP_FUNCTION : 343 case OpCodes.OP_GROUP : 344 case OpCodes.OP_VARIABLE : 345 return Axis.FILTEREDLIST; 346 } 347 348 throw new RuntimeException (XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object []{Integer.toString(stepType)})); } 351 352 357 static public int getAnalysisBitFromAxes(int axis) 358 { 359 switch (axis) { 361 case Axis.ANCESTOR : 362 return BIT_ANCESTOR; 363 case Axis.ANCESTORORSELF : 364 return BIT_ANCESTOR_OR_SELF; 365 case Axis.ATTRIBUTE : 366 return BIT_ATTRIBUTE; 367 case Axis.CHILD : 368 return BIT_CHILD; 369 case Axis.DESCENDANT : 370 return BIT_DESCENDANT; 371 case Axis.DESCENDANTORSELF : 372 return BIT_DESCENDANT_OR_SELF; 373 case Axis.FOLLOWING : 374 return BIT_FOLLOWING; 375 case Axis.FOLLOWINGSIBLING : 376 return BIT_FOLLOWING_SIBLING; 377 case Axis.NAMESPACE : 378 case Axis.NAMESPACEDECLS : 379 return BIT_NAMESPACE; 380 case Axis.PARENT : 381 return BIT_PARENT; 382 case Axis.PRECEDING : 383 return BIT_PRECEDING; 384 case Axis.PRECEDINGSIBLING : 385 return BIT_PRECEDING_SIBLING; 386 case Axis.SELF : 387 return BIT_SELF; 388 case Axis.ALLFROMNODE : 389 return BIT_DESCENDANT_OR_SELF; 390 case Axis.DESCENDANTSFROMROOT : 392 case Axis.ALL : 393 case Axis.DESCENDANTSORSELFFROMROOT : 394 return BIT_ANY_DESCENDANT_FROM_ROOT; 395 case Axis.ROOT : 396 return BIT_ROOT; 397 case Axis.FILTEREDLIST : 398 return BIT_FILTER; 399 default : 400 return BIT_FILTER; 401 } 402 } 403 404 static boolean functionProximateOrContainsProximate(Compiler compiler, 405 int opPos) 406 { 407 int endFunc = opPos + compiler.getOp(opPos + 1) - 1; 408 opPos = compiler.getFirstChildPos(opPos); 409 int funcID = compiler.getOp(opPos); 410 switch(funcID) 414 { 415 case FunctionTable.FUNC_LAST: 416 case FunctionTable.FUNC_POSITION: 417 return true; 418 default: 419 opPos++; 420 int i = 0; 421 for (int p = opPos; p < endFunc; p = compiler.getNextOpPos(p), i++) 422 { 423 int innerExprOpPos = p+2; 424 int argOp = compiler.getOp(innerExprOpPos); 425 boolean prox = isProximateInnerExpr(compiler, innerExprOpPos); 426 if(prox) 427 return true; 428 } 429 430 } 431 return false; 432 } 433 434 static boolean isProximateInnerExpr(Compiler compiler, int opPos) 435 { 436 int op = compiler.getOp(opPos); 437 int innerExprOpPos = opPos+2; 438 switch(op) 439 { 440 case OpCodes.OP_ARGUMENT: 441 if(isProximateInnerExpr(compiler, innerExprOpPos)) 442 return true; 443 break; 444 case OpCodes.OP_VARIABLE: 445 case OpCodes.OP_NUMBERLIT: 446 case OpCodes.OP_LITERAL: 447 case OpCodes.OP_LOCATIONPATH: 448 break; case OpCodes.OP_FUNCTION: 450 boolean isProx = functionProximateOrContainsProximate(compiler, opPos); 451 if(isProx) 452 return true; 453 break; 454 case OpCodes.OP_GT: 455 case OpCodes.OP_GTE: 456 case OpCodes.OP_LT: 457 case OpCodes.OP_LTE: 458 case OpCodes.OP_EQUALS: 459 int leftPos = compiler.getFirstChildPos(op); 460 int rightPos = compiler.getNextOpPos(leftPos); 461 isProx = isProximateInnerExpr(compiler, leftPos); 462 if(isProx) 463 return true; 464 isProx = isProximateInnerExpr(compiler, rightPos); 465 if(isProx) 466 return true; 467 break; 468 default: 469 return true; } 471 return false; 472 } 473 474 477 public static boolean mightBeProximate(Compiler compiler, int opPos, int stepType) 478 throws javax.xml.transform.TransformerException 479 { 480 481 boolean mightBeProximate = false; 482 int argLen; 483 484 switch (stepType) 485 { 486 case OpCodes.OP_VARIABLE : 487 case OpCodes.OP_EXTFUNCTION : 488 case OpCodes.OP_FUNCTION : 489 case OpCodes.OP_GROUP : 490 argLen = compiler.getArgLength(opPos); 491 break; 492 default : 493 argLen = compiler.getArgLengthOfStep(opPos); 494 } 495 496 int predPos = compiler.getFirstPredicateOpPos(opPos); 497 int count = 0; 498 499 while (OpCodes.OP_PREDICATE == compiler.getOp(predPos)) 500 { 501 count++; 502 503 int innerExprOpPos = predPos+2; 504 int predOp = compiler.getOp(innerExprOpPos); 505 506 switch(predOp) 507 { 508 case OpCodes.OP_VARIABLE: 509 return true; case OpCodes.OP_LOCATIONPATH: 511 break; 513 case OpCodes.OP_NUMBER: 514 case OpCodes.OP_NUMBERLIT: 515 return true; case OpCodes.OP_FUNCTION: 517 boolean isProx 518 = functionProximateOrContainsProximate(compiler, innerExprOpPos); 519 if(isProx) 520 return true; 521 break; 522 case OpCodes.OP_GT: 523 case OpCodes.OP_GTE: 524 case OpCodes.OP_LT: 525 case OpCodes.OP_LTE: 526 case OpCodes.OP_EQUALS: 527 int leftPos = compiler.getFirstChildPos(innerExprOpPos); 528 int rightPos = compiler.getNextOpPos(leftPos); 529 isProx = isProximateInnerExpr(compiler, leftPos); 530 if(isProx) 531 return true; 532 isProx = isProximateInnerExpr(compiler, rightPos); 533 if(isProx) 534 return true; 535 break; 536 default: 537 return true; } 539 540 predPos = compiler.getNextOpPos(predPos); 541 } 542 543 return mightBeProximate; 544 } 545 546 560 private static boolean isOptimizableForDescendantIterator( 561 Compiler compiler, int stepOpCodePos, int stepIndex) 562 throws javax.xml.transform.TransformerException 563 { 564 565 int stepType; 566 int stepCount = 0; 567 boolean foundDorDS = false; 568 boolean foundSelf = false; 569 boolean foundDS = false; 570 571 int nodeTestType = OpCodes.NODETYPE_NODE; 572 573 while (OpCodes.ENDOP != (stepType = compiler.getOp(stepOpCodePos))) 574 { 575 if(nodeTestType != OpCodes.NODETYPE_NODE && nodeTestType != OpCodes.NODETYPE_ROOT) 578 return false; 579 580 stepCount++; 581 if(stepCount > 3) 582 return false; 583 584 boolean mightBeProximate = mightBeProximate(compiler, stepOpCodePos, stepType); 585 if(mightBeProximate) 586 return false; 587 588 switch (stepType) 589 { 590 case OpCodes.FROM_FOLLOWING : 591 case OpCodes.FROM_FOLLOWING_SIBLINGS : 592 case OpCodes.FROM_PRECEDING : 593 case OpCodes.FROM_PRECEDING_SIBLINGS : 594 case OpCodes.FROM_PARENT : 595 case OpCodes.OP_VARIABLE : 596 case OpCodes.OP_EXTFUNCTION : 597 case OpCodes.OP_FUNCTION : 598 case OpCodes.OP_GROUP : 599 case OpCodes.FROM_NAMESPACE : 600 case OpCodes.FROM_ANCESTORS : 601 case OpCodes.FROM_ANCESTORS_OR_SELF : 602 case OpCodes.FROM_ATTRIBUTES : 603 case OpCodes.MATCH_ATTRIBUTE : 604 case OpCodes.MATCH_ANY_ANCESTOR : 605 case OpCodes.MATCH_IMMEDIATE_ANCESTOR : 606 return false; 607 case OpCodes.FROM_ROOT : 608 if(1 != stepCount) 609 return false; 610 break; 611 case OpCodes.FROM_CHILDREN : 612 if(!foundDS && !(foundDorDS && foundSelf)) 613 return false; 614 break; 615 case OpCodes.FROM_DESCENDANTS_OR_SELF : 616 foundDS = true; 617 case OpCodes.FROM_DESCENDANTS : 618 if(3 == stepCount) 619 return false; 620 foundDorDS = true; 621 break; 622 case OpCodes.FROM_SELF : 623 if(1 != stepCount) 624 return false; 625 foundSelf = true; 626 break; 627 default : 628 throw new RuntimeException (XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object []{Integer.toString(stepType)})); } 631 632 nodeTestType = compiler.getStepTestType(stepOpCodePos); 633 634 int nextStepOpCodePos = compiler.getNextStepPos(stepOpCodePos); 635 636 if (nextStepOpCodePos < 0) 637 break; 638 639 if(OpCodes.ENDOP != compiler.getOp(nextStepOpCodePos)) 640 { 641 if(compiler.countPredicates(stepOpCodePos) > 0) 642 { 643 return false; 644 } 645 } 646 647 stepOpCodePos = nextStepOpCodePos; 648 } 649 650 return true; 651 } 652 653 668 private static int analyze( 669 Compiler compiler, int stepOpCodePos, int stepIndex) 670 throws javax.xml.transform.TransformerException 671 { 672 673 int stepType; 674 int stepCount = 0; 675 int analysisResult = 0x00000000; 677 while (OpCodes.ENDOP != (stepType = compiler.getOp(stepOpCodePos))) 678 { 679 stepCount++; 680 681 boolean predAnalysis = analyzePredicate(compiler, stepOpCodePos, 687 stepType); 688 689 if (predAnalysis) 690 analysisResult |= BIT_PREDICATE; 691 692 switch (stepType) 693 { 694 case OpCodes.OP_VARIABLE : 695 case OpCodes.OP_EXTFUNCTION : 696 case OpCodes.OP_FUNCTION : 697 case OpCodes.OP_GROUP : 698 analysisResult |= BIT_FILTER; 699 break; 700 case OpCodes.FROM_ROOT : 701 analysisResult |= BIT_ROOT; 702 break; 703 case OpCodes.FROM_ANCESTORS : 704 analysisResult |= BIT_ANCESTOR; 705 break; 706 case OpCodes.FROM_ANCESTORS_OR_SELF : 707 analysisResult |= BIT_ANCESTOR_OR_SELF; 708 break; 709 case OpCodes.FROM_ATTRIBUTES : 710 analysisResult |= BIT_ATTRIBUTE; 711 break; 712 case OpCodes.FROM_NAMESPACE : 713 analysisResult |= BIT_NAMESPACE; 714 break; 715 case OpCodes.FROM_CHILDREN : 716 analysisResult |= BIT_CHILD; 717 break; 718 case OpCodes.FROM_DESCENDANTS : 719 analysisResult |= BIT_DESCENDANT; 720 break; 721 case OpCodes.FROM_DESCENDANTS_OR_SELF : 722 723 if (2 == stepCount && BIT_ROOT == analysisResult) 725 { 726 analysisResult |= BIT_ANY_DESCENDANT_FROM_ROOT; 727 } 728 729 analysisResult |= BIT_DESCENDANT_OR_SELF; 730 break; 731 case OpCodes.FROM_FOLLOWING : 732 analysisResult |= BIT_FOLLOWING; 733 break; 734 case OpCodes.FROM_FOLLOWING_SIBLINGS : 735 analysisResult |= BIT_FOLLOWING_SIBLING; 736 break; 737 case OpCodes.FROM_PRECEDING : 738 analysisResult |= BIT_PRECEDING; 739 break; 740 case OpCodes.FROM_PRECEDING_SIBLINGS : 741 analysisResult |= BIT_PRECEDING_SIBLING; 742 break; 743 case OpCodes.FROM_PARENT : 744 analysisResult |= BIT_PARENT; 745 break; 746 case OpCodes.FROM_SELF : 747 analysisResult |= BIT_SELF; 748 break; 749 case OpCodes.MATCH_ATTRIBUTE : 750 analysisResult |= (BIT_MATCH_PATTERN | BIT_ATTRIBUTE); 751 break; 752 case OpCodes.MATCH_ANY_ANCESTOR : 753 analysisResult |= (BIT_MATCH_PATTERN | BIT_ANCESTOR); 754 break; 755 case OpCodes.MATCH_IMMEDIATE_ANCESTOR : 756 analysisResult |= (BIT_MATCH_PATTERN | BIT_PARENT); 757 break; 758 default : 759 throw new RuntimeException (XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object []{Integer.toString(stepType)})); } 762 763 if (OpCodes.NODETYPE_NODE == compiler.getOp(stepOpCodePos + 3)) { 765 analysisResult |= BIT_NODETEST_ANY; 766 } 767 768 stepOpCodePos = compiler.getNextStepPos(stepOpCodePos); 769 770 if (stepOpCodePos < 0) 771 break; 772 } 773 774 analysisResult |= (stepCount & BITS_COUNT); 775 776 return analysisResult; 777 } 778 779 787 public static boolean isDownwardAxisOfMany(int axis) 788 { 789 return ((Axis.DESCENDANTORSELF == axis) || 790 (Axis.DESCENDANT == axis) 791 || (Axis.FOLLOWING == axis) 792 || (Axis.PRECEDING == axis) 794 ); 796 } 797 798 823 static StepPattern loadSteps( 824 MatchPatternIterator mpi, Compiler compiler, int stepOpCodePos, 825 int stepIndex) 826 throws javax.xml.transform.TransformerException 827 { 828 if (DEBUG_PATTERN_CREATION) 829 { 830 System.out.println("================"); 831 System.out.println("loadSteps for: "+compiler.getPatternString()); 832 } 833 int stepType; 834 StepPattern step = null; 835 StepPattern firstStep = null, prevStep = null; 836 int analysis = analyze(compiler, stepOpCodePos, stepIndex); 837 838 while (OpCodes.ENDOP != (stepType = compiler.getOp(stepOpCodePos))) 839 { 840 step = createDefaultStepPattern(compiler, stepOpCodePos, mpi, analysis, 841 firstStep, prevStep); 842 843 if (null == firstStep) 844 { 845 firstStep = step; 846 } 847 else 848 { 849 850 step.setRelativePathPattern(prevStep); 852 } 853 854 prevStep = step; 855 stepOpCodePos = compiler.getNextStepPos(stepOpCodePos); 856 857 if (stepOpCodePos < 0) 858 break; 859 } 860 861 int axis = Axis.SELF; 862 int paxis = Axis.SELF; 863 StepPattern tail = step; 864 for (StepPattern pat = step; null != pat; 865 pat = pat.getRelativePathPattern()) 866 { 867 int nextAxis = pat.getAxis(); 868 pat.setAxis(axis); 870 871 874 int whatToShow = pat.getWhatToShow(); 895 if(whatToShow == DTMFilter.SHOW_ATTRIBUTE || 896 whatToShow == DTMFilter.SHOW_NAMESPACE) 897 { 898 int newAxis = (whatToShow == DTMFilter.SHOW_ATTRIBUTE) ? 899 Axis.ATTRIBUTE : Axis.NAMESPACE; 900 if(isDownwardAxisOfMany(axis)) 901 { 902 StepPattern attrPat = new StepPattern(whatToShow, 903 pat.getNamespace(), 904 pat.getLocalName(), 905 newAxis, 0); XNumber score = pat.getStaticScore(); 908 pat.setNamespace(null); 909 pat.setLocalName(NodeTest.WILD); 910 attrPat.setPredicates(pat.getPredicates()); 911 pat.setPredicates(null); 912 pat.setWhatToShow(DTMFilter.SHOW_ELEMENT); 913 StepPattern rel = pat.getRelativePathPattern(); 914 pat.setRelativePathPattern(attrPat); 915 attrPat.setRelativePathPattern(rel); 916 attrPat.setStaticScore(score); 917 918 if(Axis.PRECEDING == pat.getAxis()) 923 pat.setAxis(Axis.PRECEDINGANDANCESTOR); 924 925 else if(Axis.DESCENDANT == pat.getAxis()) 926 pat.setAxis(Axis.DESCENDANTORSELF); 927 928 pat = attrPat; 929 } 930 else if(Axis.CHILD == pat.getAxis()) 931 { 932 pat.setAxis(Axis.ATTRIBUTE); 935 } 936 } 937 axis = nextAxis; 938 tail = pat; 940 } 941 942 if(axis < Axis.ALL) 943 { 944 StepPattern selfPattern = new ContextMatchStepPattern(axis, paxis); 945 XNumber score = tail.getStaticScore(); 947 tail.setRelativePathPattern(selfPattern); 948 tail.setStaticScore(score); 949 selfPattern.setStaticScore(score); 950 } 951 952 if (DEBUG_PATTERN_CREATION) 953 { 954 System.out.println("Done loading steps: "+step.toString()); 955 956 System.out.println(""); 957 } 958 return step; } 960 961 982 private static StepPattern createDefaultStepPattern( 983 Compiler compiler, int opPos, MatchPatternIterator mpi, 984 int analysis, StepPattern tail, StepPattern head) 985 throws javax.xml.transform.TransformerException 986 { 987 988 int stepType = compiler.getOp(opPos); 989 boolean simpleInit = false; 990 int totalNumberWalkers = (analysis & BITS_COUNT); 991 boolean prevIsOneStepDown = true; 992 int firstStepPos = compiler.getFirstChildPos(opPos); 993 994 int whatToShow = compiler.getWhatToShow(opPos); 995 StepPattern ai = null; 996 int axis, predicateAxis; 997 998 switch (stepType) 999 { 1000 case OpCodes.OP_VARIABLE : 1001 case OpCodes.OP_EXTFUNCTION : 1002 case OpCodes.OP_FUNCTION : 1003 case OpCodes.OP_GROUP : 1004 prevIsOneStepDown = false; 1005 1006 Expression expr; 1007 1008 switch (stepType) 1009 { 1010 case OpCodes.OP_VARIABLE : 1011 case OpCodes.OP_EXTFUNCTION : 1012 case OpCodes.OP_FUNCTION : 1013 case OpCodes.OP_GROUP : 1014 expr = compiler.compile(opPos); 1015 break; 1016 default : 1017 expr = compiler.compile(opPos + 2); 1018 } 1019 1020 axis = Axis.FILTEREDLIST; 1021 predicateAxis = Axis.FILTEREDLIST; 1022 ai = new FunctionPattern(expr, axis, predicateAxis); 1023 simpleInit = true; 1024 break; 1025 case OpCodes.FROM_ROOT : 1026 whatToShow = DTMFilter.SHOW_DOCUMENT 1027 | DTMFilter.SHOW_DOCUMENT_FRAGMENT; 1028 1029 axis = Axis.ROOT; 1030 predicateAxis = Axis.ROOT; 1031 ai = new StepPattern(DTMFilter.SHOW_DOCUMENT | 1032 DTMFilter.SHOW_DOCUMENT_FRAGMENT, 1033 axis, predicateAxis); 1034 break; 1035 case OpCodes.FROM_ATTRIBUTES : 1036 whatToShow = DTMFilter.SHOW_ATTRIBUTE; 1037 axis = Axis.PARENT; 1038 predicateAxis = Axis.ATTRIBUTE; 1039 break; 1041 case OpCodes.FROM_NAMESPACE : 1042 whatToShow = DTMFilter.SHOW_NAMESPACE; 1043 axis = Axis.PARENT; 1044 predicateAxis = Axis.NAMESPACE; 1045 break; 1047 case OpCodes.FROM_ANCESTORS : 1048 axis = Axis.DESCENDANT; 1049 predicateAxis = Axis.ANCESTOR; 1050 break; 1051 case OpCodes.FROM_CHILDREN : 1052 axis = Axis.PARENT; 1053 predicateAxis = Axis.CHILD; 1054 break; 1055 case OpCodes.FROM_ANCESTORS_OR_SELF : 1056 axis = Axis.DESCENDANTORSELF; 1057 predicateAxis = Axis.ANCESTORORSELF; 1058 break; 1059 case OpCodes.FROM_SELF : 1060 axis = Axis.SELF; 1061 predicateAxis = Axis.SELF; 1062 break; 1063 case OpCodes.FROM_PARENT : 1064 axis = Axis.CHILD; 1065 predicateAxis = Axis.PARENT; 1066 break; 1067 case OpCodes.FROM_PRECEDING_SIBLINGS : 1068 axis = Axis.FOLLOWINGSIBLING; 1069 predicateAxis = Axis.PRECEDINGSIBLING; 1070 break; 1071 case OpCodes.FROM_PRECEDING : 1072 axis = Axis.FOLLOWING; 1073 predicateAxis = Axis.PRECEDING; 1074 break; 1075 case OpCodes.FROM_FOLLOWING_SIBLINGS : 1076 axis = Axis.PRECEDINGSIBLING; 1077 predicateAxis = Axis.FOLLOWINGSIBLING; 1078 break; 1079 case OpCodes.FROM_FOLLOWING : 1080 axis = Axis.PRECEDING; 1081 predicateAxis = Axis.FOLLOWING; 1082 break; 1083 case OpCodes.FROM_DESCENDANTS_OR_SELF : 1084 axis = Axis.ANCESTORORSELF; 1085 predicateAxis = Axis.DESCENDANTORSELF; 1086 break; 1087 case OpCodes.FROM_DESCENDANTS : 1088 axis = Axis.ANCESTOR; 1089 predicateAxis = Axis.DESCENDANT; 1090 break; 1091 default : 1092 throw new RuntimeException (XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object []{Integer.toString(stepType)})); } 1095 if(null == ai) 1096 { 1097 whatToShow = compiler.getWhatToShow(opPos); ai = new StepPattern(whatToShow, compiler.getStepNS(opPos), 1099 compiler.getStepLocalName(opPos), 1100 axis, predicateAxis); 1101 } 1102 1103 if (false || DEBUG_PATTERN_CREATION) 1104 { 1105 System.out.print("new step: "+ ai); 1106 System.out.print(", axis: " + Axis.names[ai.getAxis()]); 1107 System.out.print(", predAxis: " + Axis.names[ai.getAxis()]); 1108 System.out.print(", what: "); 1109 System.out.print(" "); 1110 ai.debugWhatToShow(ai.getWhatToShow()); 1111 } 1112 1113 int argLen = compiler.getFirstPredicateOpPos(opPos); 1114 1115 ai.setPredicates(compiler.getCompiledPredicates(argLen)); 1116 1117 return ai; 1118 } 1119 1120 1133 static boolean analyzePredicate(Compiler compiler, int opPos, int stepType) 1134 throws javax.xml.transform.TransformerException 1135 { 1136 1137 int argLen; 1138 1139 switch (stepType) 1140 { 1141 case OpCodes.OP_VARIABLE : 1142 case OpCodes.OP_EXTFUNCTION : 1143 case OpCodes.OP_FUNCTION : 1144 case OpCodes.OP_GROUP : 1145 argLen = compiler.getArgLength(opPos); 1146 break; 1147 default : 1148 argLen = compiler.getArgLengthOfStep(opPos); 1149 } 1150 1151 int pos = compiler.getFirstPredicateOpPos(opPos); 1152 int nPredicates = compiler.countPredicates(pos); 1153 1154 return (nPredicates > 0) ? true : false; 1155 } 1156 1157 1170 private static AxesWalker createDefaultWalker(Compiler compiler, int opPos, 1171 WalkingIterator lpi, int analysis) 1172 { 1173 1174 AxesWalker ai = null; 1175 int stepType = compiler.getOp(opPos); 1176 1177 1185 boolean simpleInit = false; 1186 int totalNumberWalkers = (analysis & BITS_COUNT); 1187 boolean prevIsOneStepDown = true; 1188 1189 switch (stepType) 1190 { 1191 case OpCodes.OP_VARIABLE : 1192 case OpCodes.OP_EXTFUNCTION : 1193 case OpCodes.OP_FUNCTION : 1194 case OpCodes.OP_GROUP : 1195 prevIsOneStepDown = false; 1196 1197 if (DEBUG_WALKER_CREATION) 1198 System.out.println("new walker: FilterExprWalker: " + analysis 1199 + ", " + compiler.toString()); 1200 1201 ai = new FilterExprWalker(lpi); 1202 simpleInit = true; 1203 break; 1204 case OpCodes.FROM_ROOT : 1205 ai = new AxesWalker(lpi, Axis.ROOT); 1206 break; 1207 case OpCodes.FROM_ANCESTORS : 1208 prevIsOneStepDown = false; 1209 ai = new ReverseAxesWalker(lpi, Axis.ANCESTOR); 1210 break; 1211 case OpCodes.FROM_ANCESTORS_OR_SELF : 1212 prevIsOneStepDown = false; 1213 ai = new ReverseAxesWalker(lpi, Axis.ANCESTORORSELF); 1214 break; 1215 case OpCodes.FROM_ATTRIBUTES : 1216 ai = new AxesWalker(lpi, Axis.ATTRIBUTE); 1217 break; 1218 case OpCodes.FROM_NAMESPACE : 1219 ai = new AxesWalker(lpi, Axis.NAMESPACE); 1220 break; 1221 case OpCodes.FROM_CHILDREN : 1222 ai = new AxesWalker(lpi, Axis.CHILD); 1223 break; 1224 case OpCodes.FROM_DESCENDANTS : 1225 prevIsOneStepDown = false; 1226 ai = new AxesWalker(lpi, Axis.DESCENDANT); 1227 break; 1228 case OpCodes.FROM_DESCENDANTS_OR_SELF : 1229 prevIsOneStepDown = false; 1230 ai = new AxesWalker(lpi, Axis.DESCENDANTORSELF); 1231 break; 1232 case OpCodes.FROM_FOLLOWING : 1233 prevIsOneStepDown = false; 1234 ai = new AxesWalker(lpi, Axis.FOLLOWING); 1235 break; 1236 case OpCodes.FROM_FOLLOWING_SIBLINGS : 1237 prevIsOneStepDown = false; 1238 ai = new AxesWalker(lpi, Axis.FOLLOWINGSIBLING); 1239 break; 1240 case OpCodes.FROM_PRECEDING : 1241 prevIsOneStepDown = false; 1242 ai = new ReverseAxesWalker(lpi, Axis.PRECEDING); 1243 break; 1244 case OpCodes.FROM_PRECEDING_SIBLINGS : 1245 prevIsOneStepDown = false; 1246 ai = new ReverseAxesWalker(lpi, Axis.PRECEDINGSIBLING); 1247 break; 1248 case OpCodes.FROM_PARENT : 1249 prevIsOneStepDown = false; 1250 ai = new ReverseAxesWalker(lpi, Axis.PARENT); 1251 break; 1252 case OpCodes.FROM_SELF : 1253 ai = new AxesWalker(lpi, Axis.SELF); 1254 break; 1255 default : 1256 throw new RuntimeException (XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object []{Integer.toString(stepType)})); } 1259 1260 if (simpleInit) 1261 { 1262 ai.initNodeTest(DTMFilter.SHOW_ALL); 1263 } 1264 else 1265 { 1266 int whatToShow = compiler.getWhatToShow(opPos); 1267 1268 1275 if ((0 == (whatToShow 1276 & (DTMFilter.SHOW_ATTRIBUTE | DTMFilter.SHOW_NAMESPACE | DTMFilter.SHOW_ELEMENT 1277 | DTMFilter.SHOW_PROCESSING_INSTRUCTION))) || (whatToShow == DTMFilter.SHOW_ALL)) 1278 ai.initNodeTest(whatToShow); 1279 else 1280 { 1281 ai.initNodeTest(whatToShow, compiler.getStepNS(opPos), 1282 compiler.getStepLocalName(opPos)); 1283 } 1284 } 1285 1286 return ai; 1287 } 1288 1289 public static String getAnalysisString(int analysis) 1290 { 1291 StringBuffer buf = new StringBuffer (); 1292 buf.append("count: "+getStepCount(analysis)+" "); 1293 if((analysis & BIT_NODETEST_ANY) != 0) 1294 { 1295 buf.append("NTANY|"); 1296 } 1297 if((analysis & BIT_PREDICATE) != 0) 1298 { 1299 buf.append("PRED|"); 1300 } 1301 if((analysis & BIT_ANCESTOR) != 0) 1302 { 1303 buf.append("ANC|"); 1304 } 1305 if((analysis & BIT_ANCESTOR_OR_SELF) != 0) 1306 { 1307 buf.append("ANCOS|"); 1308 } 1309 if((analysis & BIT_ATTRIBUTE) != 0) 1310 { 1311 buf.append("ATTR|"); 1312 } 1313 if((analysis & BIT_CHILD) != 0) 1314 { 1315 buf.append("CH|"); 1316 } 1317 if((analysis & BIT_DESCENDANT) != 0) 1318 { 1319 buf.append("DESC|"); 1320 } 1321 if((analysis & BIT_DESCENDANT_OR_SELF) != 0) 1322 { 1323 buf.append("DESCOS|"); 1324 } 1325 if((analysis & BIT_FOLLOWING) != 0) 1326 { 1327 buf.append("FOL|"); 1328 } 1329 if((analysis & BIT_FOLLOWING_SIBLING) != 0) 1330 { 1331 buf.append("FOLS|"); 1332 } 1333 if((analysis & BIT_NAMESPACE) != 0) 1334 { 1335 buf.append("NS|"); 1336 } 1337 if((analysis & BIT_PARENT) != 0) 1338 { 1339 buf.append("P|"); 1340 } 1341 if((analysis & BIT_PRECEDING) != 0) 1342 { 1343 buf.append("PREC|"); 1344 } 1345 if((analysis & BIT_PRECEDING_SIBLING) != 0) 1346 { 1347 buf.append("PRECS|"); 1348 } 1349 if((analysis & BIT_SELF) != 0) 1350 { 1351 buf.append(".|"); 1352 } 1353 if((analysis & BIT_FILTER) != 0) 1354 { 1355 buf.append("FLT|"); 1356 } 1357 if((analysis & BIT_ROOT) != 0) 1358 { 1359 buf.append("R|"); 1360 } 1361 return buf.toString(); 1362 } 1363 1364 1365 static final boolean DEBUG_PATTERN_CREATION = false; 1366 1367 1368 static final boolean DEBUG_WALKER_CREATION = false; 1369 1370 1371 static final boolean DEBUG_ITERATOR_CREATION = false; 1372 1373 public static boolean hasPredicate(int analysis) 1374 { 1375 return (0 != (analysis & BIT_PREDICATE)); 1376 } 1377 1378 public static boolean isWild(int analysis) 1379 { 1380 return (0 != (analysis & BIT_NODETEST_ANY)); 1381 } 1382 1383 public static boolean walksAncestors(int analysis) 1384 { 1385 return isSet(analysis, BIT_ANCESTOR | BIT_ANCESTOR_OR_SELF); 1386 } 1387 1388 public static boolean walksAttributes(int analysis) 1389 { 1390 return (0 != (analysis & BIT_ATTRIBUTE)); 1391 } 1392 1393 public static boolean walksNamespaces(int analysis) 1394 { 1395 return (0 != (analysis & BIT_NAMESPACE)); 1396 } 1397 1398 public static boolean walksChildren(int analysis) 1399 { 1400 return (0 != (analysis & BIT_CHILD)); 1401 } 1402 1403 public static boolean walksDescendants(int analysis) 1404 { 1405 return isSet(analysis, BIT_DESCENDANT | BIT_DESCENDANT_OR_SELF); 1406 } 1407 1408 public static boolean walksSubtree(int analysis) 1409 { 1410 return isSet(analysis, BIT_DESCENDANT | BIT_DESCENDANT_OR_SELF | BIT_CHILD); 1411 } 1412 1413 public static boolean walksSubtreeOnlyMaybeAbsolute(int analysis) 1414 { 1415 return walksSubtree(analysis) 1416 && !walksExtraNodes(analysis) 1417 && !walksUp(analysis) 1418 && !walksSideways(analysis) 1419 ; 1420 } 1421 1422 public static boolean walksSubtreeOnly(int analysis) 1423 { 1424 return walksSubtreeOnlyMaybeAbsolute(analysis) 1425 && !isAbsolute(analysis) 1426 ; 1427 } 1428 1429 public static boolean walksFilteredList(int analysis) 1430 { 1431 return isSet(analysis, BIT_FILTER); 1432 } 1433 1434 public static boolean walksSubtreeOnlyFromRootOrContext(int analysis) 1435 { 1436 return walksSubtree(analysis) 1437 && !walksExtraNodes(analysis) 1438 && !walksUp(analysis) 1439 && !walksSideways(analysis) 1440 && !isSet(analysis, BIT_FILTER) 1441 ; 1442 } 1443 1444 public static boolean walksInDocOrder(int analysis) 1445 { 1446 return (walksSubtreeOnlyMaybeAbsolute(analysis) 1447 || walksExtraNodesOnly(analysis) 1448 || walksFollowingOnlyMaybeAbsolute(analysis)) 1449 && !isSet(analysis, BIT_FILTER) 1450 ; 1451 } 1452 1453 public static boolean walksFollowingOnlyMaybeAbsolute(int analysis) 1454 { 1455 return isSet(analysis, BIT_SELF | BIT_FOLLOWING_SIBLING | BIT_FOLLOWING) 1456 && !walksSubtree(analysis) 1457 && !walksUp(analysis) 1458 && !walksSideways(analysis) 1459 ; 1460 } 1461 1462 public static boolean walksUp(int analysis) 1463 { 1464 return isSet(analysis, BIT_PARENT | BIT_ANCESTOR | BIT_ANCESTOR_OR_SELF); 1465 } 1466 1467 public static boolean walksSideways(int analysis) 1468 { 1469 return isSet(analysis, BIT_FOLLOWING | BIT_FOLLOWING_SIBLING | 1470 BIT_PRECEDING | BIT_PRECEDING_SIBLING); 1471 } 1472 1473 public static boolean walksExtraNodes(int analysis) 1474 { 1475 return isSet(analysis, BIT_NAMESPACE | BIT_ATTRIBUTE); 1476 } 1477 1478 public static boolean walksExtraNodesOnly(int analysis) 1479 { 1480 return walksExtraNodes(analysis) 1481 && !isSet(analysis, BIT_SELF) 1482 && !walksSubtree(analysis) 1483 && !walksUp(analysis) 1484 && !walksSideways(analysis) 1485 && !isAbsolute(analysis) 1486 ; 1487 } 1488 1489 public static boolean isAbsolute(int analysis) 1490 { 1491 return isSet(analysis, BIT_ROOT | BIT_FILTER); 1492 } 1493 1494 public static boolean walksChildrenOnly(int analysis) 1495 { 1496 return walksChildren(analysis) 1497 && !isSet(analysis, BIT_SELF) 1498 && !walksExtraNodes(analysis) 1499 && !walksDescendants(analysis) 1500 && !walksUp(analysis) 1501 && !walksSideways(analysis) 1502 && (!isAbsolute(analysis) || isSet(analysis, BIT_ROOT)) 1503 ; 1504 } 1505 1506 public static boolean walksChildrenAndExtraAndSelfOnly(int analysis) 1507 { 1508 return walksChildren(analysis) 1509 && !walksDescendants(analysis) 1510 && !walksUp(analysis) 1511 && !walksSideways(analysis) 1512 && (!isAbsolute(analysis) || isSet(analysis, BIT_ROOT)) 1513 ; 1514 } 1515 1516 public static boolean walksDescendantsAndExtraAndSelfOnly(int analysis) 1517 { 1518 return !walksChildren(analysis) 1519 && walksDescendants(analysis) 1520 && !walksUp(analysis) 1521 && !walksSideways(analysis) 1522 && (!isAbsolute(analysis) || isSet(analysis, BIT_ROOT)) 1523 ; 1524 } 1525 1526 public static boolean walksSelfOnly(int analysis) 1527 { 1528 return isSet(analysis, BIT_SELF) 1529 && !walksSubtree(analysis) 1530 && !walksUp(analysis) 1531 && !walksSideways(analysis) 1532 && !isAbsolute(analysis) 1533 ; 1534 } 1535 1536 1537 public static boolean walksUpOnly(int analysis) 1538 { 1539 return !walksSubtree(analysis) 1540 && walksUp(analysis) 1541 && !walksSideways(analysis) 1542 && !isAbsolute(analysis) 1543 ; 1544 } 1545 1546 public static boolean walksDownOnly(int analysis) 1547 { 1548 return walksSubtree(analysis) 1549 && !walksUp(analysis) 1550 && !walksSideways(analysis) 1551 && !isAbsolute(analysis) 1552 ; 1553 } 1554 1555 public static boolean walksDownExtraOnly(int analysis) 1556 { 1557 return walksSubtree(analysis) && walksExtraNodes(analysis) 1558 && !walksUp(analysis) 1559 && !walksSideways(analysis) 1560 && !isAbsolute(analysis) 1561 ; 1562 } 1563 1564 public static boolean canSkipSubtrees(int analysis) 1565 { 1566 return isSet(analysis, BIT_CHILD) | walksSideways(analysis); 1567 } 1568 1569 public static boolean canCrissCross(int analysis) 1570 { 1571 if(walksSelfOnly(analysis)) 1573 return false; 1574 else if(walksDownOnly(analysis) && !canSkipSubtrees(analysis)) 1575 return false; 1576 else if(walksChildrenAndExtraAndSelfOnly(analysis)) 1577 return false; 1578 else if(walksDescendantsAndExtraAndSelfOnly(analysis)) 1579 return false; 1580 else if(walksUpOnly(analysis)) 1581 return false; 1582 else if(walksExtraNodesOnly(analysis)) 1583 return false; 1584 else if(walksSubtree(analysis) 1585 && (walksSideways(analysis) 1586 || walksUp(analysis) 1587 || canSkipSubtrees(analysis))) 1588 return true; 1589 else 1590 return false; 1591 } 1592 1593 1603 static public boolean isNaturalDocOrder(int analysis) 1604 { 1605 if(canCrissCross(analysis) || isSet(analysis, BIT_NAMESPACE) || 1606 walksFilteredList(analysis)) 1607 return false; 1608 1609 if(walksInDocOrder(analysis)) 1610 return true; 1611 1612 return false; 1613 } 1614 1615 1629 private static boolean isNaturalDocOrder( 1630 Compiler compiler, int stepOpCodePos, int stepIndex, int analysis) 1631 throws javax.xml.transform.TransformerException 1632 { 1633 if(canCrissCross(analysis)) 1634 return false; 1635 1636 if(isSet(analysis, BIT_NAMESPACE)) 1639 return false; 1640 1641 if(isSet(analysis, BIT_FOLLOWING | BIT_FOLLOWING_SIBLING) && 1648 isSet(analysis, BIT_PRECEDING | BIT_PRECEDING_SIBLING)) 1649 return false; 1650 1651 1656 int stepType; 1657 int stepCount = 0; 1658 boolean foundWildAttribute = false; 1659 1660 int potentialDuplicateMakingStepCount = 0; 1664 1665 while (OpCodes.ENDOP != (stepType = compiler.getOp(stepOpCodePos))) 1666 { 1667 stepCount++; 1668 1669 switch (stepType) 1670 { 1671 case OpCodes.FROM_ATTRIBUTES : 1672 case OpCodes.MATCH_ATTRIBUTE : 1673 if(foundWildAttribute) return false; 1675 1676 1679 String localName = compiler.getStepLocalName(stepOpCodePos); 1680 if(localName.equals("*")) 1682 { 1683 foundWildAttribute = true; 1684 } 1685 break; 1686 case OpCodes.FROM_FOLLOWING : 1687 case OpCodes.FROM_FOLLOWING_SIBLINGS : 1688 case OpCodes.FROM_PRECEDING : 1689 case OpCodes.FROM_PRECEDING_SIBLINGS : 1690 case OpCodes.FROM_PARENT : 1691 case OpCodes.OP_VARIABLE : 1692 case OpCodes.OP_EXTFUNCTION : 1693 case OpCodes.OP_FUNCTION : 1694 case OpCodes.OP_GROUP : 1695 case OpCodes.FROM_NAMESPACE : 1696 case OpCodes.FROM_ANCESTORS : 1697 case OpCodes.FROM_ANCESTORS_OR_SELF : 1698 case OpCodes.MATCH_ANY_ANCESTOR : 1699 case OpCodes.MATCH_IMMEDIATE_ANCESTOR : 1700 case OpCodes.FROM_DESCENDANTS_OR_SELF : 1701 case OpCodes.FROM_DESCENDANTS : 1702 if(potentialDuplicateMakingStepCount > 0) 1703 return false; 1704 potentialDuplicateMakingStepCount++; 1705 case OpCodes.FROM_ROOT : 1706 case OpCodes.FROM_CHILDREN : 1707 case OpCodes.FROM_SELF : 1708 if(foundWildAttribute) 1709 return false; 1710 break; 1711 default : 1712 throw new RuntimeException (XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object []{Integer.toString(stepType)})); } 1715 1716 int nextStepOpCodePos = compiler.getNextStepPos(stepOpCodePos); 1717 1718 if (nextStepOpCodePos < 0) 1719 break; 1720 1721 stepOpCodePos = nextStepOpCodePos; 1722 } 1723 1724 return true; 1725 } 1726 1727 public static boolean isOneStep(int analysis) 1728 { 1729 return (analysis & BITS_COUNT) == 0x00000001; 1730 } 1731 1732 public static int getStepCount(int analysis) 1733 { 1734 return (analysis & BITS_COUNT); 1735 } 1736 1737 1741 public static final int BITS_COUNT = 0x000000FF; 1742 1743 1744 public static final int BITS_RESERVED = 0x00000F00; 1745 1746 1747 public static final int BIT_PREDICATE = (0x00001000); 1748 1749 1750 public static final int BIT_ANCESTOR = (0x00001000 << 1); 1751 1752 1753 public static final int BIT_ANCESTOR_OR_SELF = (0x00001000 << 2); 1754 1755 1756 public static final int BIT_ATTRIBUTE = (0x00001000 << 3); 1757 1758 1759 public static final int BIT_CHILD = (0x00001000 << 4); 1760 1761 1762 public static final int BIT_DESCENDANT = (0x00001000 << 5); 1763 1764 1765 public static final int BIT_DESCENDANT_OR_SELF = (0x00001000 << 6); 1766 1767 1768 public static final int BIT_FOLLOWING = (0x00001000 << 7); 1769 1770 1771 public static final int BIT_FOLLOWING_SIBLING = (0x00001000 << 8); 1772 1773 1774 public static final int BIT_NAMESPACE = (0x00001000 << 9); 1775 1776 1777 public static final int BIT_PARENT = (0x00001000 << 10); 1778 1779 1780 public static final int BIT_PRECEDING = (0x00001000 << 11); 1781 1782 1783 public static final int BIT_PRECEDING_SIBLING = (0x00001000 << 12); 1784 1785 1786 public static final int BIT_SELF = (0x00001000 << 13); 1787 1788 1792 public static final int BIT_FILTER = (0x00001000 << 14); 1793 1794 1795 public static final int BIT_ROOT = (0x00001000 << 15); 1796 1797 1801 public static final int BITMASK_TRAVERSES_OUTSIDE_SUBTREE = (BIT_NAMESPACE | BIT_PRECEDING_SIBLING 1803 | BIT_PRECEDING 1804 | BIT_FOLLOWING_SIBLING 1805 | BIT_FOLLOWING 1806 | BIT_PARENT | BIT_ANCESTOR_OR_SELF 1808 | BIT_ANCESTOR 1809 | BIT_FILTER 1810 | BIT_ROOT); 1811 1812 1816 public static final int BIT_BACKWARDS_SELF = (0x00001000 << 16); 1817 1818 1819 public static final int BIT_ANY_DESCENDANT_FROM_ROOT = (0x00001000 << 17); 1820 1821 1825 public static final int BIT_NODETEST_ANY = (0x00001000 << 18); 1826 1827 1829 1830 public static final int BIT_MATCH_PATTERN = (0x00001000 << 19); 1831} 1832 | Popular Tags |