Example #1
0
void UnitRepoProxy::GetUnitArraysStmt
                  ::get(UnitEmitter& ue) {
  RepoTxn txn(m_repo);
  if (!prepared()) {
    std::stringstream ssSelect;
    ssSelect << "SELECT arrayId,array FROM "
             << m_repo.table(m_repoId, "UnitArray")
             << " WHERE unitSn == @unitSn ORDER BY arrayId ASC;";
    txn.prepare(*this, ssSelect.str());
  }
  RepoTxnQuery query(txn, *this);
  query.bindInt64("@unitSn", ue.m_sn);
  do {
    query.step();
    if (query.row()) {
      Id arrayId;        /**/ query.getId(0, arrayId);
      std::string key;   /**/ query.getStdString(1, key);
      Variant v = unserialize_from_buffer(key.data(), key.size());
      Id id UNUSED = ue.mergeArray(
        v.asArrRef().get(),
        ArrayData::GetScalarArrayKey(key.c_str(), key.size()));
      assert(id == arrayId);
    }
  } while (!query.done());
  txn.commit();
}
Example #2
0
void UnitRepoProxy::GetUnitArraysStmt
                  ::get(UnitEmitter& ue) {
  RepoTxn txn(m_repo);
  if (!prepared()) {
    std::stringstream ssSelect;
    ssSelect << "SELECT arrayId,array FROM "
             << m_repo.table(m_repoId, "UnitArray")
             << " WHERE unitSn == @unitSn ORDER BY arrayId ASC;";
    txn.prepare(*this, ssSelect.str());
  }
  RepoTxnQuery query(txn, *this);
  query.bindInt64("@unitSn", ue.sn());
  do {
    query.step();
    if (query.row()) {
      Id arrayId;        /**/ query.getId(0, arrayId);
      StringData* array; /**/ query.getStaticString(1, array);
      String s(array);
      Variant v = f_unserialize(s);
      Id id UNUSED = ue.mergeArray(v.asArrRef().get(), array);
      ASSERT(id == arrayId);
    }
  } while (!query.done());
  txn.commit();
}
Example #3
0
// Find a symbol given by string key of the specified symbol type. Context
// information can be specified through ctx, sym, and ar.
//
// StaticRoot, StaticProp
//   * Search for a static property given by key in class ctx
//   * A class name may be encoded with the property as *classname*propname
//     to indicate a class that should be used as the visibility context for
//     loading the property
static Variant xdebug_lookup_symbol(SymbolType type, String key, Class*& ctx,
                                    Variant& sym, ActRec* ar) {
    char* name = key.get()->mutableData();
    char* end = key.get()->mutableData() + key.size();
    assert(name != end);

    switch (type) {
    case SymbolType::StaticRoot:
    case SymbolType::StaticProp: {
        TypedValue* ret = nullptr;
        if (!ctx) return uninit_null();

        Class* newCtx = nullptr;
        char* secStar;
        bool vis, acc;
        if ((ret = ctx->getSProp(ctx, key.get(), vis, acc))) {
            return tvAsVariant(ret);
        }

        for (secStar = name + 1; secStar != end && *secStar != '*'; ++secStar);
        if (secStar != end && *name == '*' && *secStar == '*') {
            String clsKey(name + 1, secStar - name - 1, CopyStringMode());
            String newKey(secStar + 1, end - secStar - 1, CopyStringMode());
            newCtx = Unit::lookupClass(clsKey.get());
            if (newCtx && (ret = ctx->getSProp(newCtx, newKey.get(),
                                               vis, acc))) {
                return tvAsVariant(ret);
            }
        }
        return uninit_null();
    }
    break;

    case SymbolType::Root: {
        const Func* func = ar->func();

        if (key.size() == 4 && strncmp(name, "this", 4) == 0) {
            return ar->hasThis() ? ar->getThis() : nullptr;
        }

        Id localId = func->lookupVarId(key.get());

        if (localId != kInvalidId) {
            TypedValue* tv = frame_local(ar, localId);
            return tv ? tvAsVariant(tv) : uninit_null();
        }

        Class* tmp = Unit::lookupClass(key.get());

        if (tmp) ctx = tmp;
        return uninit_null();
    }
    break;

    case SymbolType::ArrayIndexAssoc: {
        return  sym.isArray()  ? sym.asArrRef().rvalAt(key) :
                sym.isObject() ? sym.asObjRef().o_get(key, false)
                : uninit_null();
    }

    case SymbolType::ArrayIndexNum: {
        int64_t iKey = key.toInt64();

        return  sym.isArray()  ? sym.asArrRef().rvalAt(iKey)
                : uninit_null();
    }

    case SymbolType::ObjProp: {
        char* secStar;
        if (!sym.is(KindOfObject)) return uninit_null();

        Object obj = sym.toObject();
        Variant v = obj->o_get(key, false);
        if(!v.isNull()) return v;

        for (secStar = name + 1; secStar != end && *secStar != '*'; ++secStar);
        if (secStar != end && *name == '*' && *secStar == '*') {
            String clsKey(name + 1, secStar - name - 1, CopyStringMode());
            String newKey(secStar + 1, end - secStar - 1, CopyStringMode());
            v = obj.o_get(key, false, clsKey);
        }

        return v;
    }
    }

    not_reached();
}