Пример #1
0
Variant f_constant(CStrRef name) {
  if (!name.get()) return uninit_null();
  const char *data = name.data();
  int len = name.length();
  char *colon;
  if ((colon = (char*)memchr(data, ':', len)) && colon[1] == ':') {
    // class constant
    int classNameLen = colon - data;
    char *constantName = colon + 2;
    VM::Class* cls = getClassByName(data, classNameLen);
    if (cls) {
      String cnsName(constantName, data + len - constantName, CopyString);
      TypedValue* tv = cls->clsCnsGet(cnsName.get());
      if (tv) {
        return tvAsCVarRef(tv);
      }
    }
    raise_warning("Couldn't find constant %s", data);
    return uninit_null();
  } else {
    TypedValue* cns = VM::Unit::loadCns(name.get());
    if (cns) return tvAsVariant(cns);
    return uninit_null();
  }
}
Пример #2
0
Variant f_constant(CStrRef name) {
  if (!name.get()) return null;
  const char *data = name.data();
  int len = name.length();
  char *colon;
  if ((colon = (char*)memchr(data, ':', len)) && colon[1] == ':') {
    // class constant
    int classNameLen = colon - data;
    char *constantName = colon + 2;
    String className(data, classNameLen, CopyString);

    // translate "self" or "parent"
    if (className == "self") {
      String this_class = g_vmContext->getContextClassName();
      if (this_class.empty()) {
        throw FatalErrorException("Cannot access self:: "
                                  "when no class scope is active");
      } else {
        className = this_class;
      }
    } else if (className == "parent") {
      String parent_class =g_vmContext->getParentContextClassName();
      if (parent_class.empty()) {
        throw FatalErrorException("Cannot access parent");
      } else {
        className = parent_class;
      }
    }
    VM::Class* cls = VM::Unit::loadClass(className.get());
    if (cls) {
      String cnsName(constantName, data + len - constantName, CopyString);
      TypedValue* tv = cls->clsCnsGet(cnsName.get());
      if (tv) {
        return tvAsCVarRef(tv);
      }
    }
    raise_warning("Couldn't find constant %s", data);
    return null;
  } else {
    TypedValue* cns = g_vmContext->getCns(name.get());
    if (cns == NULL) {
      if (AutoloadHandler::s_instance->autoloadConstant(name)) {
        cns = g_vmContext->getCns(name.get());
      }
    }
    if (cns) return tvAsVariant(cns);
    return null;
  }
}
Пример #3
0
static Variant f_hphp_get_iterator(VRefParam iterable, bool isMutable) {
  if (iterable.isArray()) {
    if (isMutable) {
      return create_object(s_MutableArrayIterator,
                           CREATE_VECTOR1(ref(iterable)));
    }
    return create_object(s_ArrayIterator,
                         CREATE_VECTOR1(iterable));
  }
  if (iterable.isObject()) {
    ObjectData *obj = iterable.getObjectData();
    Variant iterator;
    while (obj->instanceof(SystemLib::s_IteratorAggregateClass)) {
      iterator = obj->o_invoke(s_getIterator, Array());
      if (!iterator.isObject()) break;
      obj = iterator.getObjectData();
    }
    VM::Class* ctx = g_vmContext->getContextClass();
    CStrRef context = ctx ? ctx->nameRef() : empty_string;
    if (isMutable) {
      if (obj->instanceof(SystemLib::s_IteratorClass)) {
        throw FatalErrorException("An iterator cannot be used for "
                                  "iteration by reference");
      }
      Array properties = obj->o_toIterArray(context, true);
      return create_object(s_MutableArrayIterator,
                           CREATE_VECTOR1(ref(properties)));
    } else {
      if (obj->instanceof(SystemLib::s_IteratorClass)) {
        return obj;
      }
      return create_object(s_ArrayIterator,
                           CREATE_VECTOR1(obj->o_toIterArray(context)));
    }
  }
  raise_warning("Invalid argument supplied for iteration");
  if (isMutable) {
    return create_object(s_MutableArrayIterator,
                         CREATE_VECTOR1(Array::Create()));
  }
  return create_object(s_ArrayIterator,
                       CREATE_VECTOR1(Array::Create()));
}
Пример #4
0
bool f_defined(CStrRef name, bool autoload /* = true */) {
  if (!name.get()) return false;
  const char *data = name.data();
  int len = name.length();
  char *colon;
  if ((colon = (char*)memchr(data, ':', len)) && colon[1] == ':') {
    // class constant
    int classNameLen = colon - data;
    char *constantName = colon + 2;
    VM::Class* cls = getClassByName(data, classNameLen);
    if (cls) {
      String cnsName(constantName, data + len - constantName, CopyString);
      return cls->clsCnsGet(cnsName.get());
    }
    return false;
  } else {
    return autoload ?
      VM::Unit::loadCns(name.get()) :
      VM::Unit::lookupCns(name.get());
  }
}
Пример #5
0
String c_Continuation::t_getorigfuncname() {
  INSTANCE_METHOD_INJECTION_BUILTIN(Continuation, Continuation::getorigfuncname);
  if (hhvm) {
    c_GenericContinuation* self = static_cast<c_GenericContinuation*>(this);
    VM::Class* vmClass = self->getVMCalledClass();
    if (vmClass != NULL && m_called_class.size() == 0) {
      m_called_class = vmClass->name()->data();
    }
  }
  if (m_called_class.size() == 0) {
    return m_origFuncName;
  }

  /*
    Replace the class name in m_origFuncName with the LSB class.  This
    produces more useful traces.
   */
  size_t method_pos = m_origFuncName.find("::");
  if (method_pos != std::string::npos) {
    return concat3(m_called_class, "::", m_origFuncName.substr(method_pos+2));
  } else {
    return m_origFuncName;
  }
}