src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/ProcessingInstructionPattern.java
author joehw
Wed, 18 Oct 2017 13:25:49 -0700
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 48409 5ab69533994b
permissions -rw-r--r--
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked Reviewed-by: lancea, rriggs, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Oct 2017
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xalan.internal.xsltc.compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import com.sun.org.apache.bcel.internal.generic.BranchHandle;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.bcel.internal.generic.GOTO;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.bcel.internal.generic.IFEQ;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.bcel.internal.generic.IF_ICMPEQ;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.bcel.internal.generic.InstructionList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.bcel.internal.generic.PUSH;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.xml.internal.dtm.Axis;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.xml.internal.dtm.DTM;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * @author Morten Jorgensen
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
final class ProcessingInstructionPattern extends StepPattern {
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
    private String _name = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
    private boolean _typeChecked = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
     * Handles calls with no parameter (current node is implicit parameter).
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
    public ProcessingInstructionPattern(String name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
        super(Axis.CHILD, DTM.PROCESSING_INSTRUCTION_NODE, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
        _name = name;
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
        //if (_name.equals("*")) _typeChecked = true; no wildcard allowed!
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
     public double getDefaultPriority() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
        return (_name != null) ? 0.0 : -0.5;
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
     }
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
    public String toString() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
        if (_predicates == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
            return "processing-instruction("+_name+")";
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
            return "processing-instruction("+_name+")"+_predicates;
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    public void reduceKernelPattern() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
        _typeChecked = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    public boolean isWildcard() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
        return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
        if (hasPredicates()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
            // Type check all the predicates (e -> position() = e)
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
            final int n = _predicates.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
            for (int i = 0; i < n; i++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    84
                final Predicate pred = _predicates.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
                pred.typeCheck(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
        return Type.NodeSet;
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
        // context node is on the stack
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
        int gname = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
                                              "getNodeName",
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
                                              "(I)Ljava/lang/String;");
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
        int cmp = cpg.addMethodref(STRING_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
                                   "equals", "(Ljava/lang/Object;)Z");
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
        // Push current node on the stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
        il.append(methodGen.loadCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
        il.append(SWAP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
        // Overwrite current node with matching node
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
        il.append(methodGen.storeCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
        // If pattern not reduced then check kernel
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
        if (!_typeChecked) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
            il.append(methodGen.loadCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
            final int getType = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
                                                          "getExpandedTypeID",
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
                                                          "(I)I");
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
            il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
            il.append(methodGen.loadCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
            il.append(new INVOKEINTERFACE(getType, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
            il.append(new PUSH(cpg, DTM.PROCESSING_INSTRUCTION_NODE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
            _falseList.add(il.append(new IF_ICMPEQ(null)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
        // Load the requested processing instruction name
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
        il.append(new PUSH(cpg, _name));
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
        // Load the current processing instruction's name
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
        il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
        il.append(methodGen.loadCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
        il.append(new INVOKEINTERFACE(gname, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
        // Compare the two strings
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
        il.append(new INVOKEVIRTUAL(cmp));
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
        _falseList.add(il.append(new IFEQ(null)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
        // Compile the expressions within the predicates
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
        if (hasPredicates()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
            final int n = _predicates.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
            for (int i = 0; i < n; i++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   136
                Predicate pred = _predicates.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
                Expression exp = pred.getExpr();
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
                exp.translateDesynthesized(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
                _trueList.append(exp._trueList);
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
                _falseList.append(exp._falseList);
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
        // Backpatch true list and restore current iterator/node
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
        InstructionHandle restore;
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
        restore = il.append(methodGen.storeCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
        backPatchTrueList(restore);
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
        BranchHandle skipFalse = il.append(new GOTO(null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
        // Backpatch false list and restore current iterator/node
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
        restore = il.append(methodGen.storeCurrentNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
        backPatchFalseList(restore);
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
        _falseList.add(il.append(new GOTO(null)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
        // True list falls through
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
        skipFalse.setTarget(il.append(NOP));
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
}