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.º 2
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.º 3
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;
  }
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());
  }
Exemplo n.º 5
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;
  }