jaxp/src/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/AbsolutePathPattern.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 6 7f561c08de6b
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 2001-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: AbsolutePathPattern.java,v 1.2.4.1 2005/09/01 09:17:09 pvedula Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
package com.sun.org.apache.xalan.internal.xsltc.compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.bcel.internal.generic.BranchHandle;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.bcel.internal.generic.GOTO_W;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.bcel.internal.generic.IF_ICMPEQ;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.bcel.internal.generic.ILOAD;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.bcel.internal.generic.ISTORE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.bcel.internal.generic.InstructionList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.bcel.internal.generic.PUSH;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
import com.sun.org.apache.xml.internal.dtm.DTM;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 * @author Jacek Ambroziak
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * @author Santiago Pericas-Geertsen
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
final class AbsolutePathPattern extends LocationPathPattern {
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
    private final RelativePathPattern _left; // may be null
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
    public AbsolutePathPattern(RelativePathPattern left) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
        _left = left;
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
        if (left != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
            left.setParent(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
    public void setParser(Parser parser) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
        super.setParser(parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
        if (_left != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
            _left.setParser(parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
    public Type typeCheck(SymbolTable stable) throws TypeCheckError {
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
        return _left == null ? Type.Root : _left.typeCheck(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    public boolean isWildcard() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
        return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    public StepPattern getKernelPattern() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
        return _left != null ? _left.getKernelPattern() : null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    public void reduceKernelPattern() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
        _left.reduceKernelPattern();
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
        if (_left != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
            if (_left instanceof StepPattern) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
                final LocalVariableGen local =
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
                    // absolute path pattern temporary
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
                    methodGen.addLocalVariable2("apptmp",
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
                                                Util.getJCRefType(NODE_SIG),
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
                                                il.getEnd());
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
                il.append(DUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
                il.append(new ISTORE(local.getIndex()));
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
                _left.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
                il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
                local.setEnd(il.append(new ILOAD(local.getIndex())));
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
                methodGen.removeLocalVariable(local);
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
                _left.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
        final int getParent = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
                                                        GET_PARENT,
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
                                                        GET_PARENT_SIG);
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
        final int getType = cpg.addInterfaceMethodref(DOM_INTF,
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
                                                      "getExpandedTypeID",
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
                                                      "(I)I");
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
        InstructionHandle begin = il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
        il.append(SWAP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
        il.append(new INVOKEINTERFACE(getParent, 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
        if (_left instanceof AncestorPattern) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
            il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
            il.append(SWAP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
        }
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.DOCUMENT_NODE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
        final BranchHandle skip = il.append(new IF_ICMPEQ(null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
        _falseList.add(il.append(new GOTO_W(null)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
        skip.setTarget(il.append(NOP));
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
        if (_left != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
            _left.backPatchTrueList(begin);
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
            /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
             * If _left is an ancestor pattern, backpatch this pattern's false
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
             * list to the loop that searches for more ancestors.
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
             */
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
            if (_left instanceof AncestorPattern) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
                final AncestorPattern ancestor = (AncestorPattern) _left;
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
                _falseList.backPatch(ancestor.getLoopHandle());         // clears list
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
            _falseList.append(_left._falseList);
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
    public String toString() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
        return "absolutePathPattern(" + (_left != null ? _left.toString() : ")");
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
}