< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Mode.java

Print this page


   1 /*
   2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Oct 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *     http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 /*
  22  * $Id: Mode.java,v 1.2.4.1 2005/09/19 05:18:11 pvedula Exp $
  23  */


 212     }
 213 
 214     public Stylesheet getStylesheet() {
 215         return _stylesheet;
 216     }
 217 
 218     public void addTemplate(Template template) {
 219         _templates.add(template);
 220     }
 221 
 222     private List<Template> quicksort(List<Template> templates, int p, int r) {
 223         if (p < r) {
 224             final int q = partition(templates, p, r);
 225             quicksort(templates, p, q);
 226             quicksort(templates, q + 1, r);
 227         }
 228         return templates;
 229     }
 230 
 231     private int partition(List<Template> templates, int p, int r) {
 232         final Template x = (Template)templates.get(p);
 233         int i = p - 1;
 234         int j = r + 1;
 235         while (true) {
 236             while (x.compareTo((Template)templates.get(--j)) > 0);
 237             while (x.compareTo((Template)templates.get(++i)) < 0);
 238             if (i < j) {
 239                 templates.set(j, templates.set(i, templates.get(j)));
 240             }
 241             else {
 242                 return j;
 243             }
 244         }
 245     }
 246 
 247     /**
 248      * Process all the test patterns in this mode
 249      */
 250     public void processPatterns(Map<String, Key> keys) {
 251         _keys = keys;
 252         _templates = quicksort(_templates, 0, _templates.size() - 1);
 253 
 254         // Traverse all templates
 255         for (Template template : _templates) {
 256             /*
 257              * Add this template to a table of named templates if it has a name.


 349                     (_attribNodeGroup = new ArrayList<>(2)) : _attribNodeGroup;
 350             }
 351             else {
 352                 patterns = (_childNodeGroup == null) ?
 353                     (_childNodeGroup = new ArrayList<>(2)) : _childNodeGroup;
 354             }
 355         }
 356         else {
 357             patterns = (_patternGroups[kernelType] == null) ?
 358                 (_patternGroups[kernelType] = new ArrayList<>(2)) :
 359                 _patternGroups[kernelType];
 360         }
 361 
 362         if (patterns.size() == 0) {
 363             patterns.add(pattern);
 364         }
 365         else {
 366             boolean inserted = false;
 367             for (int i = 0; i < patterns.size(); i++) {
 368                 final LocationPathPattern lppToCompare =
 369                     (LocationPathPattern)patterns.get(i);
 370 
 371                 if (pattern.noSmallerThan(lppToCompare)) {
 372                     inserted = true;
 373                     patterns.add(i, pattern);
 374                     break;
 375                 }
 376             }
 377             if (inserted == false) {
 378                 patterns.add(pattern);
 379             }
 380         }
 381     }
 382 
 383     /**
 384      * Complete test sequences of a given type by adding all patterns
 385      * from a given group.
 386      */
 387     private void completeTestSequences(int nodeType, List<LocationPathPattern> patterns) {
 388         if (patterns != null) {
 389             if (_patternGroups[nodeType] == null) {


1119 
1120         // Compile default handling of elements (traverse children)
1121         InstructionList ilRecurse =
1122             compileDefaultRecursion(classGen, methodGen, ihLoop);
1123         InstructionHandle ihRecurse = ilRecurse.getStart();
1124 
1125         // Compile default handling of text/attribute nodes (output text)
1126         InstructionList ilText =
1127             compileDefaultText(classGen, methodGen, ihLoop);
1128         InstructionHandle ihText = ilText.getStart();
1129 
1130         // Distinguish attribute/element/namespace tests for further processing
1131         final int[] types = new int[DTM.NTYPES + names.size()];
1132         for (int i = 0; i < types.length; i++) {
1133             types[i] = i;
1134         }
1135 
1136         final boolean[] isAttribute = new boolean[types.length];
1137         final boolean[] isNamespace = new boolean[types.length];
1138         for (int i = 0; i < names.size(); i++) {
1139             final String name = (String)names.get(i);
1140             isAttribute[i+DTM.NTYPES] = isAttributeName(name);
1141             isNamespace[i+DTM.NTYPES] = isNamespaceName(name);
1142         }
1143 
1144         // Compile all templates - regardless of pattern type
1145         compileTemplateCalls(classGen, methodGen, ihLoop, min, max);
1146 
1147         // Handle template with explicit "*" pattern
1148         final TestSeq elemTest = _testSeq[DTM.ELEMENT_NODE];
1149         InstructionHandle ihElem = ihRecurse;
1150         if (elemTest != null) {
1151             ihElem = elemTest.compile(classGen, methodGen, ihLoop);
1152         }
1153 
1154         // Handle template with explicit "@*" pattern
1155         final TestSeq attrTest = _testSeq[DTM.ATTRIBUTE_NODE];
1156         InstructionHandle ihAttr = ihLoop;
1157         if (attrTest != null) {
1158             ihAttr = attrTest.compile(classGen, methodGen, ihAttr);
1159         }


   1 /*
   2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Nov 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *     http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 /*
  22  * $Id: Mode.java,v 1.2.4.1 2005/09/19 05:18:11 pvedula Exp $
  23  */


 212     }
 213 
 214     public Stylesheet getStylesheet() {
 215         return _stylesheet;
 216     }
 217 
 218     public void addTemplate(Template template) {
 219         _templates.add(template);
 220     }
 221 
 222     private List<Template> quicksort(List<Template> templates, int p, int r) {
 223         if (p < r) {
 224             final int q = partition(templates, p, r);
 225             quicksort(templates, p, q);
 226             quicksort(templates, q + 1, r);
 227         }
 228         return templates;
 229     }
 230 
 231     private int partition(List<Template> templates, int p, int r) {
 232         final Template x = templates.get(p);
 233         int i = p - 1;
 234         int j = r + 1;
 235         while (true) {
 236             while (x.compareTo(templates.get(--j)) > 0);
 237             while (x.compareTo(templates.get(++i)) < 0);
 238             if (i < j) {
 239                 templates.set(j, templates.set(i, templates.get(j)));
 240             }
 241             else {
 242                 return j;
 243             }
 244         }
 245     }
 246 
 247     /**
 248      * Process all the test patterns in this mode
 249      */
 250     public void processPatterns(Map<String, Key> keys) {
 251         _keys = keys;
 252         _templates = quicksort(_templates, 0, _templates.size() - 1);
 253 
 254         // Traverse all templates
 255         for (Template template : _templates) {
 256             /*
 257              * Add this template to a table of named templates if it has a name.


 349                     (_attribNodeGroup = new ArrayList<>(2)) : _attribNodeGroup;
 350             }
 351             else {
 352                 patterns = (_childNodeGroup == null) ?
 353                     (_childNodeGroup = new ArrayList<>(2)) : _childNodeGroup;
 354             }
 355         }
 356         else {
 357             patterns = (_patternGroups[kernelType] == null) ?
 358                 (_patternGroups[kernelType] = new ArrayList<>(2)) :
 359                 _patternGroups[kernelType];
 360         }
 361 
 362         if (patterns.size() == 0) {
 363             patterns.add(pattern);
 364         }
 365         else {
 366             boolean inserted = false;
 367             for (int i = 0; i < patterns.size(); i++) {
 368                 final LocationPathPattern lppToCompare =
 369                     patterns.get(i);
 370 
 371                 if (pattern.noSmallerThan(lppToCompare)) {
 372                     inserted = true;
 373                     patterns.add(i, pattern);
 374                     break;
 375                 }
 376             }
 377             if (inserted == false) {
 378                 patterns.add(pattern);
 379             }
 380         }
 381     }
 382 
 383     /**
 384      * Complete test sequences of a given type by adding all patterns
 385      * from a given group.
 386      */
 387     private void completeTestSequences(int nodeType, List<LocationPathPattern> patterns) {
 388         if (patterns != null) {
 389             if (_patternGroups[nodeType] == null) {


1119 
1120         // Compile default handling of elements (traverse children)
1121         InstructionList ilRecurse =
1122             compileDefaultRecursion(classGen, methodGen, ihLoop);
1123         InstructionHandle ihRecurse = ilRecurse.getStart();
1124 
1125         // Compile default handling of text/attribute nodes (output text)
1126         InstructionList ilText =
1127             compileDefaultText(classGen, methodGen, ihLoop);
1128         InstructionHandle ihText = ilText.getStart();
1129 
1130         // Distinguish attribute/element/namespace tests for further processing
1131         final int[] types = new int[DTM.NTYPES + names.size()];
1132         for (int i = 0; i < types.length; i++) {
1133             types[i] = i;
1134         }
1135 
1136         final boolean[] isAttribute = new boolean[types.length];
1137         final boolean[] isNamespace = new boolean[types.length];
1138         for (int i = 0; i < names.size(); i++) {
1139             final String name = names.get(i);
1140             isAttribute[i+DTM.NTYPES] = isAttributeName(name);
1141             isNamespace[i+DTM.NTYPES] = isNamespaceName(name);
1142         }
1143 
1144         // Compile all templates - regardless of pattern type
1145         compileTemplateCalls(classGen, methodGen, ihLoop, min, max);
1146 
1147         // Handle template with explicit "*" pattern
1148         final TestSeq elemTest = _testSeq[DTM.ELEMENT_NODE];
1149         InstructionHandle ihElem = ihRecurse;
1150         if (elemTest != null) {
1151             ihElem = elemTest.compile(classGen, methodGen, ihLoop);
1152         }
1153 
1154         // Handle template with explicit "@*" pattern
1155         final TestSeq attrTest = _testSeq[DTM.ATTRIBUTE_NODE];
1156         InstructionHandle ihAttr = ihLoop;
1157         if (attrTest != null) {
1158             ihAttr = attrTest.compile(classGen, methodGen, ihAttr);
1159         }


< prev index next >