Exemplo n.º 1
0
  /** Returns the id for a function name. */
  public int getFunctionId(String name) {
    if (!isStrict()) name = name.toLowerCase(Locale.ENGLISH);

    if (name.startsWith("\\")) {
      // php/0m18
      name = name.substring(1);
    }

    int id = _functionNameMap.get(name);

    if (id >= 0) return id;

    synchronized (_functionNameMap) {
      id = _functionNameMap.get(name);

      if (id >= 0) return id;

      // 0 is used for an undefined function
      // php/1p0g
      id = _functionNameMap.size() + 1;

      _functionNameMap.put(name, id);

      extendFunctionMap(name, id);
    }

    return id;
  }
  private static void addName(String name, int code) {
    names.put(name, code);
    cbNames.put(new CharBuffer(name), code);

    String upper = name.toUpperCase();
    names.put(upper, code);
    cbNames.put(new CharBuffer(upper), code);
  }
Exemplo n.º 3
0
  /** Returns the id for a function name. */
  public int findFunctionId(String name) {
    if (!isStrict()) name = name.toLowerCase(Locale.ENGLISH);

    if (name.startsWith("\\")) name = name.substring(1);

    // IntMap is internally synchronized
    return _functionNameMap.get(name);
  }
Exemplo n.º 4
0
  public ESString toSource(IntMap map, boolean isLoopPass) throws Throwable {
    CharBuffer cb = new CharBuffer();
    Global resin = Global.getGlobalProto();

    int mark = map.get(this);

    if (mark > 0 && isLoopPass) return null;
    else if (mark > 0) {
      cb.append("#" + mark + "=");
      map.put(this, -mark);
    } else if (mark == 0 && isLoopPass) {
      map.put(this, resin.addMark());
      return null;
    } else if (mark < 0 && !isLoopPass) {
      return ESString.create("#" + -mark + "#");
    }

    cb.append("{");

    if (isLoopPass) map.put(this, 0);

    Iterator e = keys();

    boolean isFirst = true;
    while (e.hasNext()) {
      if (!isFirst) cb.append(", ");
      isFirst = false;

      ESString key = (ESString) e.next();

      cb.append(key);
      cb.append(":");
      ESBase value = getProperty(key);
      if (isLoopPass) value.toSource(map, isLoopPass);
      else cb.append(value.toSource(map, isLoopPass));
    }

    cb.append("}");

    return new ESString(cb.toString());
  }
  /**
   * Return the normalized name.
   *
   * @param tag the raw name in the XML file.
   * @return the normalized name.
   */
  QName getName(CharBuffer tag) {
    if (!toLower) return super.getName(tag);

    cb.clear();
    cb.append(tag);
    cb.toLowerCase();

    int name = cbNames.get(cb);

    if (name >= 0) return super.getName(cb);
    else return super.getName(tag);
  }
Exemplo n.º 6
0
  /** Returns the id for a constant */
  public int getConstantId(StringValue name) {
    int id = _constantNameMap.get(name);

    if (id >= 0) return id;

    synchronized (_constantNameMap) {
      id = _constantNameMap.get(name);

      if (id >= 0) return id;

      // php/313j
      id = _constantNameMap.size() + 1;

      if (_classDefMap.length <= id) {
        Value[] constantMap = new Value[id + 256];
        System.arraycopy(_constantMap, 0, constantMap, 0, _constantMap.length);
        _constantMap = constantMap;

        Value[] constantNameList = new Value[id + 256];
        System.arraycopy(_constantNameList, 0, constantNameList, 0, _constantNameList.length);
        _constantNameList = constantNameList;

        int[] constantLowerMap = new int[_constantMap.length];
        System.arraycopy(_constantLowerMap, 0, constantLowerMap, 0, _constantLowerMap.length);
        _constantLowerMap = constantLowerMap;
      }

      // XXX: i18n
      _constantNameList[id] = name;

      // php/1a0g, php/1d06
      _constantNameMap.put(name, id);

      // php/050a - only case-insensitive constants should add lower case,
      // i.e. use addLowerConstantId
    }

    return id;
  }
  QName getAttributeName(CharBuffer eltName, CharBuffer source) {
    if (!toLower) return super.getName(source);

    cb.clear();
    cb.append(eltName);
    cb.toLowerCase();
    int name = cbNames.get(cb);

    if (name < 0) return super.getName(source);
    else {
      source.toLowerCase();
      return super.getName(source);
    }
  }
Exemplo n.º 8
0
  /** Returns the id for a class name. */
  public int getClassId(String className) {
    int id = _classNameMap.get(className);

    if (id >= 0) return id;

    if (className.startsWith("\\")) className = className.substring(1);

    id = _classNameMap.get(className);

    if (id >= 0) return id;

    synchronized (_classNameMap) {
      String name = className.toLowerCase(Locale.ENGLISH);

      id = _classNameMap.get(name);

      if (id >= 0) {
        _classNameMap.put(className, id);

        return id;
      }

      id = _classNameMap.size();

      if (_classDefMap.length <= id) {
        String[] classNames = new String[id + 256];
        System.arraycopy(_classNames, 0, classNames, 0, _classNames.length);
        _classNames = classNames;

        ClassDef[] classDefMap = new ClassDef[_classNames.length];
        System.arraycopy(_classDefMap, 0, classDefMap, 0, _classDefMap.length);
        _classDefMap = classDefMap;

        QuercusClass[] classCacheMap = new QuercusClass[_classNames.length];
        System.arraycopy(_classCacheMap, 0, classCacheMap, 0, _classCacheMap.length);
        _classCacheMap = classCacheMap;
      }

      _classNames[id] = className;

      // _classMap[id] = new UndefinedClass(name);

      _classNameMap.put(className, id);
      _classNameMap.put(name, id);
    }

    return id;
  }
Exemplo n.º 9
0
 /** Returns the number of defined constants */
 public int getConstantIdCount() {
   return _constantNameMap.size();
 }
Exemplo n.º 10
0
 /** Returns the number of classes */
 public int getClassIdCount() {
   return _classNameMap.size();
 }
Exemplo n.º 11
0
 /** Returns the id for a function name. */
 public int findClassId(String name) {
   return _classNameMap.get(name);
 }
Exemplo n.º 12
0
 /** Returns the number of functions */
 public int getFunctionIdCount() {
   return _functionNameMap.size();
 }
  int elementCloseAction(XmlParser parser, QName node, String tagEnd) throws XmlParseException {
    String nodeName = node.getName();
    if (nodeName.equals(tagEnd)) return POP;

    if (nodeName == "#document" && tagEnd.equals("")) {
      /*
      Document doc = (Document) node;

      // If JSP, move any text into the body element
      if (isJsp && doc.getDocumentElement() == null &&
          node.getFirstChild() instanceof Text) {
        Element html = doc.createElement("html");
        doc.appendChild(html);
        Element body = doc.createElement("body");
        html.appendChild(body);
        Node child;
        while ((child = doc.getFirstChild()) instanceof Text ||
        child instanceof Comment) {
          body.appendChild(child);
        }
      }
      */
      return POP;
    }
    switch (names.get(tagEnd)) {
      case BASEFONT:
      case BR:
      case AREA:
      case LINK:
      case IMG:
      case PARAM:
      case HR:
      case INPUT:
      case COL:
      case FRAME:
      case ISINDEX:
      case BASE:
      case META:
        String errorTagEnd;
        if (tagEnd.equals("")) errorTagEnd = L.l("end of file");
        else errorTagEnd = "`<" + tagEnd + ">'";

        throw parser.error(L.l("{0} expects to be empty", errorTagEnd));
    }

    switch (names.get(nodeName)) {
      case BODY:
      case P:
      case DT:
      case DD:
      case LI:
      case OPTION:
      case THEAD:
      case TFOOT:
      case TBODY:
      case COLGROUP:
      case TR:
      case TH:
      case TD:
        return POP_AND_LOOP;

      case HTML:
      case HEAD:
        // If JSP and missing a body, move any text into the body element
        /*
        if (isJsp && node.getLastChild() instanceof Text) {
          Node child;

          for (child = node.getLastChild();
               child != null;
               child = child.getPreviousSibling()) {
            if (child.getNodeName().equals("body"))
              return POP_AND_LOOP;
          }

          Document doc = node.getOwnerDocument();
          Element body = doc.createElement("body");

          while ((child = node.getLastChild()) instanceof Text ||
                 child instanceof Comment) {
            body.insertBefore(child, body.getFirstChild());
          }

          doc.getDocumentElement().appendChild(body);
        }
        */
        return POP_AND_LOOP;

      default:
        if (forgiving) {
          /*
          Node parent = node;
          for (; parent != null; parent = parent.getParentNode()) {
            if (parent.getNodeName().equals(tagEnd))
              return POP_AND_LOOP;
          }
          return IGNORE;
                 */
          return POP_AND_LOOP;
        }

        String errorTagEnd;
        if (tagEnd.equals("")) errorTagEnd = L.l("end of file");
        else errorTagEnd = "`</" + tagEnd + ">'";

        String expect;
        if (nodeName.equals("#document")) {
          throw parser.error(L.l("expected {0} at {1}", L.l("end of document"), errorTagEnd));
        } else expect = "`</" + nodeName + ">'";

        throw parser.error(
            L.l(
                "expected {0} at {1} (open at {2})",
                expect, errorTagEnd, "" + parser.getNodeLine()));
    }
  }
  /**
   * Returns the appropriate action when opening a HTML tag.
   *
   * @param parser the XML parser
   * @param node the parent node
   * @param next the next child
   * @return the action code
   */
  int openAction(XmlParser parser, QName node, QName next) throws XmlParseException {
    String nodeName = node == null ? "#document" : node.getName();
    String nextName = next.getName();

    int nextCode = names.get(nextName);

    switch (names.get(nodeName)) {
      case DOCUMENT:
        switch (nextCode) {
          case HTML:
            return PUSH;

          case COMMENT:
            return PUSH;

          case HEAD:
          case TITLE:
          case ISINDEX:
          case BASE:
          case SCRIPT:
          case STYLE:
          case META:
          case LINK:
          case OBJECT:
            opt = htmlName;
            return PUSH_OPT;

          case WHITESPACE:
            return IGNORE;

          case JSP:
            return PUSH;

          default:
            if (autoHtml) return PUSH;

            autoHtml = true;
            opt = htmlName;
            return PUSH_OPT;
        }

      case HTML:
        switch (nextCode) {
          case HTML:
            return ERROR;

          case HEAD:
          case COMMENT:
          case FRAMESET:
            return PUSH;

          case BODY:
            hasBody = true;
            return PUSH;

          case TITLE:
          case ISINDEX:
          case BASE:
          case SCRIPT:
          case STYLE:
          case META:
          case LINK:
          case OBJECT:
            opt = headName;
            autoHead = true;
            return PUSH_OPT;

          case WHITESPACE:
            return PUSH;

          case JSP:
            return PUSH;

          default:
            if (hasBody) return PUSH;

            hasBody = true;
            opt = bodyName;
            return PUSH_OPT;
        }

      case HEAD:
        switch (nextCode) {
          case META:
            // checkMetaEncoding((Element) next);
            return PUSH_EMPTY;

          case LINK:
          case ISINDEX:
          case BASE:
            return PUSH_EMPTY;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          case TITLE:
          case OBJECT:
            return PUSH;

          case WHITESPACE:
            return PUSH;

          case JSP:
          case TEXT:
            if (autoHead) return POP;
            else return PUSH;

          default:
            return POP;
        }

      case LI:
        switch (nextCode) {
          case LI:
            return POP;

          case BASEFONT:
          case BR:
          case AREA:
          case LINK:
          case IMG:
          case PARAM:
          case HR:
          case INPUT:
          case COL:
          case FRAME:
          case ISINDEX:
          case BASE:
          case META:
            return PUSH_EMPTY;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          default:
            return PUSH;
        }

      case OPTION:
        switch (nextCode) {
          case WHITESPACE:
          case TEXT:
            return PUSH;

          default:
            return POP;
        }

      case DD:
        switch (nextCode) {
          case DD:
          case DT:
            return POP;

          case BASEFONT:
          case BR:
          case AREA:
          case LINK:
          case IMG:
          case PARAM:
          case HR:
          case INPUT:
          case COL:
          case FRAME:
          case ISINDEX:
          case BASE:
          case META:
            return PUSH_EMPTY;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          default:
            return PUSH;
        }

      case THEAD:
      case TFOOT:
      case COLGROUP:
        switch (nextCode) {
          case THEAD:
          case TFOOT:
          case TBODY:
          case COLGROUP:
          case COL:
            return POP;

          case BASEFONT:
          case BR:
          case AREA:
          case LINK:
          case IMG:
          case PARAM:
          case HR:
          case INPUT:
          case FRAME:
          case ISINDEX:
          case BASE:
          case META:
            return PUSH_EMPTY;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          default:
            return PUSH;
        }

      case TR:
        switch (nextCode) {
          case THEAD:
          case TFOOT:
          case TBODY:
          case COLGROUP:
          case COL:
          case TR:
            return POP;

          case BASEFONT:
          case BR:
          case AREA:
          case LINK:
          case IMG:
          case PARAM:
          case HR:
          case INPUT:
          case FRAME:
          case ISINDEX:
          case BASE:
          case META:
            return PUSH_EMPTY;

          case TD:
          case TH:
            return PUSH;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          default:
            return PUSH;
        }

      case TD:
      case TH:
        switch (nextCode) {
          case THEAD:
          case TFOOT:
          case TBODY:
          case COLGROUP:
          case COL:
          case TR:
          case TD:
          case TH:
            return POP;

          case BASEFONT:
          case BR:
          case AREA:
          case LINK:
          case IMG:
          case PARAM:
          case HR:
          case INPUT:
          case FRAME:
          case ISINDEX:
          case BASE:
          case META:
            return PUSH_EMPTY;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          default:
            return PUSH;
        }

      case P:
      case DT:
        switch (nextCode) {
          case BLOCK:
          case P:
          case TABLE:
          case CAPTION:
          case THEAD:
          case TFOOT:
          case COLGROUP:
          case TBODY:
          case TR:
          case TD:
          case TH:
          case DT:
          case LI:
            return POP;

          case BASEFONT:
          case BR:
          case AREA:
          case LINK:
          case IMG:
          case PARAM:
          case HR:
          case INPUT:
          case COL:
          case FRAME:
          case ISINDEX:
          case BASE:
          case META:
            return PUSH_EMPTY;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          default:
            return PUSH;
        }

      case TABLE:
        switch (nextCode) {
          case CAPTION:
          case THEAD:
          case TFOOT:
          case COL:
          case COLGROUP:
          case TBODY:
          case TR:
            return PUSH;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          default:
            /*
            opt = "tr";
            return PUSH_OPT;
                   */
            return PUSH;
        }

      default:
        switch (nextCode) {
          case BASEFONT:
          case BR:
          case AREA:
          case LINK:
          case IMG:
          case PARAM:
          case HR:
          case INPUT:
          case COL:
          case FRAME:
          case ISINDEX:
          case BASE:
          case META:
            return PUSH_EMPTY;

          case SCRIPT:
          case STYLE:
            return PUSH_VERBATIM;

          default:
            return PUSH;
        }
    }
  }