compiler.java

来自「java jdk 1.4的源码」· Java 代码 · 共 1,269 行 · 第 1/3 页

JAVA
1,269
字号
  {    return compileOperation(new Mult(), opPos);  }  /**   * Compile a 'div' operation.   *    * @param opPos The current position in the m_opMap array.   *   * @return reference to {@link org.apache.xpath.operations.Div} instance.   *   * @throws TransformerException if a error occurs creating the Expression.   */  protected Expression div(int opPos) throws TransformerException  {    return compileOperation(new Div(), opPos);  }  /**   * Compile a 'mod' operation.   *    * @param opPos The current position in the m_opMap array.   *   * @return reference to {@link org.apache.xpath.operations.Mod} instance.   *   * @throws TransformerException if a error occurs creating the Expression.   */  protected Expression mod(int opPos) throws TransformerException  {    return compileOperation(new Mod(), opPos);  }  /*   * Compile a 'quo' operation.   *    * @param opPos The current position in the m_opMap array.   *   * @return reference to {@link org.apache.xpath.operations.Quo} instance.   *   * @throws TransformerException if a error occurs creating the Expression.   *///  protected Expression quo(int opPos) throws TransformerException//  {//    return compileOperation(new Quo(), opPos);//  }  /**   * Compile a unary '-' operation.   *    * @param opPos The current position in the m_opMap array.   *   * @return reference to {@link org.apache.xpath.operations.Neg} instance.   *   * @throws TransformerException if a error occurs creating the Expression.   */  protected Expression neg(int opPos) throws TransformerException  {    return compileUnary(new Neg(), opPos);  }  /**   * Compile a 'string(...)' operation.   *    * @param opPos The current position in the m_opMap array.   *   * @return reference to {@link org.apache.xpath.operations.String} instance.   *   * @throws TransformerException if a error occurs creating the Expression.   */  protected Expression string(int opPos) throws TransformerException  {    return compileUnary(new org.apache.xpath.operations.String(), opPos);  }  /**   * Compile a 'boolean(...)' operation.   *    * @param opPos The current position in the m_opMap array.   *   * @return reference to {@link org.apache.xpath.operations.Bool} instance.   *   * @throws TransformerException if a error occurs creating the Expression.   */  protected Expression bool(int opPos) throws TransformerException  {    return compileUnary(new org.apache.xpath.operations.Bool(), opPos);  }  /**   * Compile a 'number(...)' operation.   *    * @param opPos The current position in the m_opMap array.   *   * @return reference to {@link org.apache.xpath.operations.Number} instance.   *   * @throws TransformerException if a error occurs creating the Expression.   */  protected Expression number(int opPos) throws TransformerException  {    return compileUnary(new org.apache.xpath.operations.Number(), opPos);  }  /**   * Compile a literal string value.   *    * @param opPos The current position in the m_opMap array.   *   * @return reference to {@link org.apache.xpath.objects.XString} instance.   *   * @throws TransformerException if a error occurs creating the Expression.   */  protected Expression literal(int opPos)  {    opPos = getFirstChildPos(opPos);    return (XString) getTokenQueue().elementAt(getOp(opPos));  }  /**   * Compile a literal number value.   *    * @param opPos The current position in the m_opMap array.   *   * @return reference to {@link org.apache.xpath.objects.XNumber} instance.   *   * @throws TransformerException if a error occurs creating the Expression.   */  protected Expression numberlit(int opPos)  {    opPos = getFirstChildPos(opPos);    return (XNumber) getTokenQueue().elementAt(getOp(opPos));  }  /**   * Compile a variable reference.   *    * @param opPos The current position in the m_opMap array.   *   * @return reference to {@link org.apache.xpath.operations.Variable} instance.   *   * @throws TransformerException if a error occurs creating the Expression.   */  protected Expression variable(int opPos) throws TransformerException  {    Variable var = new Variable();    opPos = getFirstChildPos(opPos);    int nsPos = getOp(opPos);    java.lang.String namespace       = (OpCodes.EMPTY == nsPos) ? null                                    : (java.lang.String) getTokenQueue().elementAt(nsPos);    java.lang.String localname       = (java.lang.String) getTokenQueue().elementAt(getOp(opPos+1));    QName qname = new QName(namespace, localname);    var.setQName(qname);    return var;  }  /**   * Compile an expression group.   *    * @param opPos The current position in the m_opMap array.   *   * @return reference to the contained expression.   *   * @throws TransformerException if a error occurs creating the Expression.   */  protected Expression group(int opPos) throws TransformerException  {    // no-op    return compile(opPos + 2);  }  /**   * Compile a function argument.   *    * @param opPos The current position in the m_opMap array.   *   * @return reference to the argument expression.   *   * @throws TransformerException if a error occurs creating the Expression.   */  protected Expression arg(int opPos) throws TransformerException  {    // no-op    return compile(opPos + 2);  }  /**   * Compile a location path union. The UnionPathIterator itself may create   * {@link org.apache.xpath.axes.LocPathIterator} children.   *    * @param opPos The current position in the m_opMap array.   *   * @return reference to {@link org.apache.xpath.axes.LocPathIterator} instance.   *   * @throws TransformerException if a error occurs creating the Expression.   */  protected Expression union(int opPos) throws TransformerException  {    locPathDepth++;    try    {      return UnionPathIterator.createUnionIterator(this, opPos);    }    finally    {      locPathDepth--;    }  }    private int locPathDepth = -1;    /**   * Get the level of the location path or union being constructed.     * @return 0 if it is a top-level path.   */  public int getLocationPathDepth()  {    return locPathDepth;  }  /**   * Compile a location path.  The LocPathIterator itself may create   * {@link org.apache.xpath.axes.AxesWalker} children.   *    * @param opPos The current position in the m_opMap array.   *   * @return reference to {@link org.apache.xpath.axes.LocPathIterator} instance.   *   * @throws TransformerException if a error occurs creating the Expression.   */  public Expression locationPath(int opPos) throws TransformerException  {    locPathDepth++;    try    {      DTMIterator iter = WalkerFactory.newDTMIterator(this, opPos, (locPathDepth == 0));      return (Expression)iter; // cast OK, I guess.    }    finally    {      locPathDepth--;    }  }  /**   * Compile a location step predicate expression.   *    * @param opPos The current position in the m_opMap array.   *   * @return the contained predicate expression.   *   * @throws TransformerException if a error occurs creating the Expression.   */  public Expression predicate(int opPos) throws TransformerException  {    return compile(opPos + 2);  }  /**   * Compile an entire match pattern expression.   *    * @param opPos The current position in the m_opMap array.   *   * @return reference to {@link org.apache.xpath.patterns.UnionPattern} instance.   *   * @throws TransformerException if a error occurs creating the Expression.   */  protected Expression matchPattern(int opPos) throws TransformerException  {    locPathDepth++;    try    {      // First, count...      int nextOpPos = opPos;      int i;      for (i = 0; getOp(nextOpPos) == OpCodes.OP_LOCATIONPATHPATTERN; i++)      {        nextOpPos = getNextOpPos(nextOpPos);      }      if (i == 1)        return compile(opPos);      UnionPattern up = new UnionPattern();      StepPattern[] patterns = new StepPattern[i];      for (i = 0; getOp(opPos) == OpCodes.OP_LOCATIONPATHPATTERN; i++)      {        nextOpPos = getNextOpPos(opPos);        patterns[i] = (StepPattern) compile(opPos);        opPos = nextOpPos;      }      up.setPatterns(patterns);      return up;    }    finally    {      locPathDepth--;    }  }  /**   * Compile a location match pattern unit expression.   *    * @param opPos The current position in the m_opMap array.   *   * @return reference to {@link org.apache.xpath.patterns.StepPattern} instance.   *   * @throws TransformerException if a error occurs creating the Expression.   */  public Expression locationPathPattern(int opPos)          throws TransformerException  {    opPos = getFirstChildPos(opPos);    return stepPattern(opPos, 0, null);  }  /**   * Get a {@link org.w3c.dom.traversal.NodeFilter} bit set that tells what    * to show for a given node test.   *   * @param opPos the op map position for the location step.   *   * @return {@link org.w3c.dom.traversal.NodeFilter} bit set that tells what    *         to show for a given node test.   */  public int getWhatToShow(int opPos)  {    int axesType = getOp(opPos);    int testType = getOp(opPos + 3);    // System.out.println("testType: "+testType);    switch (testType)    {    case OpCodes.NODETYPE_COMMENT :      return DTMFilter.SHOW_COMMENT;    case OpCodes.NODETYPE_TEXT ://      return DTMFilter.SHOW_TEXT | DTMFilter.SHOW_COMMENT;      return DTMFilter.SHOW_TEXT | DTMFilter.SHOW_CDATA_SECTION ;    case OpCodes.NODETYPE_PI :      return DTMFilter.SHOW_PROCESSING_INSTRUCTION;    case OpCodes.NODETYPE_NODE ://      return DTMFilter.SHOW_ALL;      switch (axesType)      {      case OpCodes.FROM_NAMESPACE:        return DTMFilter.SHOW_NAMESPACE;      case OpCodes.FROM_ATTRIBUTES :      case OpCodes.MATCH_ATTRIBUTE :        return DTMFilter.SHOW_ATTRIBUTE;      case OpCodes.FROM_SELF:      case OpCodes.FROM_ANCESTORS_OR_SELF:      case OpCodes.FROM_DESCENDANTS_OR_SELF:        return DTMFilter.SHOW_ALL;      default:        if (getOp(0) == OpCodes.OP_MATCHPATTERN)          return ~DTMFilter.SHOW_ATTRIBUTE                  & ~DTMFilter.SHOW_DOCUMENT                  & ~DTMFilter.SHOW_DOCUMENT_FRAGMENT;        else          return ~DTMFilter.SHOW_ATTRIBUTE;      }    case OpCodes.NODETYPE_ROOT :      return DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT;    case OpCodes.NODETYPE_FUNCTEST :      return NodeTest.SHOW_BYFUNCTION;    case OpCodes.NODENAME :      switch (axesType)      {      case OpCodes.FROM_NAMESPACE :        return DTMFilter.SHOW_NAMESPACE;      case OpCodes.FROM_ATTRIBUTES :      case OpCodes.MATCH_ATTRIBUTE :        return DTMFilter.SHOW_ATTRIBUTE;      // break;      case OpCodes.MATCH_ANY_ANCESTOR :      case OpCodes.MATCH_IMMEDIATE_ANCESTOR :        return DTMFilter.SHOW_ELEMENT;      // break;      default :        return DTMFilter.SHOW_ELEMENT;      }    default :      // System.err.println("We should never reach here.");      return DTMFilter.SHOW_ALL;    }  }  private static final boolean DEBUG = false;  /**   * Compile a step pattern unit expression, used for both location paths    * and match patterns.   *    * @param opPos The current position in the m_opMap array.   * @param stepCount The number of steps to expect.   * @param ancestorPattern The owning StepPattern, which may be null.   *   * @return reference to {@link org.apache.xpath.patterns.StepPattern} instance.   *   * @throws TransformerException if a error occurs creating the Expression.   */  protected StepPattern stepPattern(          int opPos, int stepCount, StepPattern ancestorPattern)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?