jaxp/src/com/sun/org/apache/xpath/internal/compiler/OpMap.java
author lana
Tue, 18 Mar 2014 17:49:48 -0700
changeset 23377 2af1ddf102a4
parent 12458 d601e4bba306
permissions -rw-r--r--
Merge
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 1999-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: OpMap.java,v 1.1.2.1 2005/08/01 01:30:31 jeffsuttor Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xpath.internal.compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import com.sun.org.apache.xalan.internal.res.XSLMessages;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.xml.internal.utils.ObjectVector;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xpath.internal.patterns.NodeTest;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * This class represents the data structure basics of the XPath
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
public class OpMap
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
   * The current pattern string, for diagnostics purposes
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
  protected String m_currentPattern;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
   * Return the expression as a string for diagnostics.
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
   * @return The expression string.
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
  public String toString()
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
    return m_currentPattern;
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
   * Return the expression as a string for diagnostics.
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
   * @return The expression string.
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
  public String getPatternString()
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
    return m_currentPattern;
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
   * The starting size of the token queue.
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
  static final int MAXTOKENQUEUESIZE = 500;
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
  /*
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
   * Amount to grow token queue when it becomes full
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
  static final int BLOCKTOKENQUEUESIZE = 500;
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
   *  TokenStack is the queue of used tokens. The current token is the token at the
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
   * end of the m_tokenQueue. The idea is that the queue can be marked and a sequence
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
   * of tokens can be reused.
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
  ObjectVector m_tokenQueue = new ObjectVector(MAXTOKENQUEUESIZE, BLOCKTOKENQUEUESIZE);
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
   * Get the XPath as a list of tokens.
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
   * @return ObjectVector of tokens.
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
  public ObjectVector getTokenQueue()
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
    return m_tokenQueue;
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
   * Get the XPath as a list of tokens.
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
   * @param pos index into token queue.
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
   * @return The token, normally a string.
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
  public Object getToken(int pos)
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
    return m_tokenQueue.elementAt(pos);
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
   * The current size of the token queue.
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
//  public int m_tokenQueueSize = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    * Get size of the token queue.
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
   * @return The size of the token queue.
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
  public int getTokenQueueSize()
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
    return m_tokenQueue.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
   * An operations map is used instead of a proper parse tree.  It contains
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
   * operations codes and indexes into the m_tokenQueue.
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
   * I use an array instead of a full parse tree in order to cut down
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
   * on the number of objects created.
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
  OpMapVector m_opMap = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
    * Get the opcode list that describes the XPath operations.  It contains
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
   * operations codes and indexes into the m_tokenQueue.
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
   * I use an array instead of a full parse tree in order to cut down
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
   * on the number of objects created.
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
   * @return An IntVector that is the opcode list that describes the XPath operations.
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
  public OpMapVector getOpMap()
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    return m_opMap;
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
  // Position indexes
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
   * The length is always the opcode position + 1.
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
   * Length is always expressed as the opcode+length bytes,
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
   * so it is always 2 or greater.
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
  public static final int MAPINDEX_LENGTH = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
   * Replace the large arrays
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
   * with a small array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
  void shrink()
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
    int n = m_opMap.elementAt(MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
    m_opMap.setToSize(n + 4);
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
    m_opMap.setElementAt(0,n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
    m_opMap.setElementAt(0,n+1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
    m_opMap.setElementAt(0,n+2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
    n = m_tokenQueue.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
    m_tokenQueue.setToSize(n + 4);
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
    m_tokenQueue.setElementAt(null,n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
    m_tokenQueue.setElementAt(null,n + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
    m_tokenQueue.setElementAt(null,n + 2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
  * Given an operation position, return the current op.
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
   * @param opPos index into op map.
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
   * @return the op that corresponds to the opPos argument.
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
  public int getOp(int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
    return m_opMap.elementAt(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
  * Set the op at index to the given int.
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
   * @param opPos index into op map.
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
   * @param value Value to set
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
  public void setOp(int opPos, int value)
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
     m_opMap.setElementAt(value,opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
   * Given an operation position, return the end position, i.e. the
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
   * beginning of the next operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
   * @param opPos An op position of an operation for which there is a size
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
   *              entry following.
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
   * @return position of next operation in m_opMap.
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
  public int getNextOpPos(int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
    return opPos + m_opMap.elementAt(opPos + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
   * Given a location step position, return the end position, i.e. the
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
   * beginning of the next step.
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
   * @param opPos the position of a location step.
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
   * @return the position of the next location step.
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
  public int getNextStepPos(int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
    int stepType = getOp(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
    if ((stepType >= OpCodes.AXES_START_TYPES)
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
            && (stepType <= OpCodes.AXES_END_TYPES))
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
      return getNextOpPos(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
    else if ((stepType >= OpCodes.FIRST_NODESET_OP)
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
             && (stepType <= OpCodes.LAST_NODESET_OP))
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
      int newOpPos = getNextOpPos(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
      while (OpCodes.OP_PREDICATE == getOp(newOpPos))
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
        newOpPos = getNextOpPos(newOpPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
      stepType = getOp(newOpPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
      if (!((stepType >= OpCodes.AXES_START_TYPES)
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
            && (stepType <= OpCodes.AXES_END_TYPES)))
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
        return OpCodes.ENDOP;
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
      return newOpPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
      throw new RuntimeException(
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   245
        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_UNKNOWN_STEP, new Object[]{String.valueOf(stepType)}));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
      //"Programmer's assertion in getNextStepPos: unknown stepType: " + stepType);
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
   * Given an operation position, return the end position, i.e. the
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
   * beginning of the next operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
   * @param opMap The operations map.
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
   * @param opPos index to operation, for which there is a size entry following.
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
   * @return position of next operation in m_opMap.
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
  public static int getNextOpPos(int[] opMap, int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
    return opPos + opMap[opPos + 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
   * Given an FROM_stepType position, return the position of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
   * first predicate, if there is one, or else this will point
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
   * to the end of the FROM_stepType.
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
   * Example:
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
   *  int posOfPredicate = xpath.getNextOpPos(stepPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
   *  boolean hasPredicates =
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
   *            OpCodes.OP_PREDICATE == xpath.getOp(posOfPredicate);
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
   * @param opPos position of FROM_stepType op.
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
   * @return position of predicate in FROM_stepType structure.
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
  public int getFirstPredicateOpPos(int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
     throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
    int stepType = m_opMap.elementAt(opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
    if ((stepType >= OpCodes.AXES_START_TYPES)
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
            && (stepType <= OpCodes.AXES_END_TYPES))
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
      return opPos + m_opMap.elementAt(opPos + 2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
    else if ((stepType >= OpCodes.FIRST_NODESET_OP)
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
             && (stepType <= OpCodes.LAST_NODESET_OP))
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
      return opPos + m_opMap.elementAt(opPos + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
    else if(-2 == stepType)
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
      return -2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
      error(com.sun.org.apache.xpath.internal.res.XPATHErrorResources.ER_UNKNOWN_OPCODE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
            new Object[]{ String.valueOf(stepType) });  //"ERROR! Unknown op code: "+m_opMap[opPos]);
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
      return -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
   * Tell the user of an error, and probably throw an
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
   * exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
   * @param msg An error msgkey that corresponds to one of the constants found
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
   *            in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
   *            a key for a format string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
   * @param args An array of arguments represented in the format string, which
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
   *             may be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
   * @throws TransformerException if the current ErrorListoner determines to
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
   *                              throw an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
  public void error(String msg, Object[] args) throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
    java.lang.String fmsg = com.sun.org.apache.xalan.internal.res.XSLMessages.createXPATHMessage(msg, args);
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
    throw new javax.xml.transform.TransformerException(fmsg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
   * Go to the first child of a given operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
   * @param opPos position of operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
   * @return The position of the first child of the operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
  public static int getFirstChildPos(int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
    return opPos + 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
   * Get the length of an operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
   * @param opPos The position of the operation in the op map.
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
   * @return The size of the operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
  public int getArgLength(int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
    return m_opMap.elementAt(opPos + MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
   * Given a location step, get the length of that step.
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
   * @param opPos Position of location step in op map.
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
   * @return The length of the step.
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
  public int getArgLengthOfStep(int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
    return m_opMap.elementAt(opPos + MAPINDEX_LENGTH + 1) - 3;
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
   * Get the first child position of a given location step.
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
   * @param opPos Position of location step in the location map.
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
   * @return The first child position of the step.
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
  public static int getFirstChildPosOfStep(int opPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
    return opPos + 3;
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
   * Get the test type of the step, i.e. NODETYPE_XXX value.
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
   * @param opPosOfStep The position of the FROM_XXX step.
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
   * @return NODETYPE_XXX value.
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
  public int getStepTestType(int opPosOfStep)
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
    return m_opMap.elementAt(opPosOfStep + 3);  // skip past op, len, len without predicates
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
   * Get the namespace of the step.
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
   * @param opPosOfStep The position of the FROM_XXX step.
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
   * @return The step's namespace, NodeTest.WILD, or null for null namespace.
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
  public String getStepNS(int opPosOfStep)
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
    int argLenOfStep = getArgLengthOfStep(opPosOfStep);
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
    // System.out.println("getStepNS.argLenOfStep: "+argLenOfStep);
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
    if (argLenOfStep == 3)
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
      int index = m_opMap.elementAt(opPosOfStep + 4);
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
      if (index >= 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
        return (String) m_tokenQueue.elementAt(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
      else if (OpCodes.ELEMWILDCARD == index)
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
        return NodeTest.WILD;
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
      return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
   * Get the local name of the step.
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
   * @param opPosOfStep The position of the FROM_XXX step.
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
   * @return OpCodes.EMPTY, OpCodes.ELEMWILDCARD, or the local name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
  public String getStepLocalName(int opPosOfStep)
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
    int argLenOfStep = getArgLengthOfStep(opPosOfStep);
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
    // System.out.println("getStepLocalName.argLenOfStep: "+argLenOfStep);
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
    int index;
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
    switch (argLenOfStep)
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
    case 0 :
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
      index = OpCodes.EMPTY;
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
    case 1 :
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
      index = OpCodes.ELEMWILDCARD;
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
    case 2 :
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
      index = m_opMap.elementAt(opPosOfStep + 4);
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
    case 3 :
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
      index = m_opMap.elementAt(opPosOfStep + 5);
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
    default :
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
      index = OpCodes.EMPTY;
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
      break;  // Should assert error
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
    // int index = (argLenOfStep == 3) ? m_opMap[opPosOfStep+5]
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
    //                                  : ((argLenOfStep == 1) ? -3 : -2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
    if (index >= 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
      return (String) m_tokenQueue.elementAt(index).toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
    else if (OpCodes.ELEMWILDCARD == index)
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
      return NodeTest.WILD;
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
      return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
}