void tvCastToBooleanInPlace(TypedValue* tv) { assert(tvIsPlausible(*tv)); tvUnboxIfNeeded(tv); bool b; switch (tv->m_type) { case KindOfUninit: case KindOfNull: b = false; break; case KindOfBoolean: return; case KindOfInt64: b = (tv->m_data.num != 0LL); break; case KindOfDouble: b = (tv->m_data.dbl != 0); break; case KindOfStaticString: b = tv->m_data.pstr->toBoolean(); break; case KindOfString: b = tv->m_data.pstr->toBoolean(); tvDecRefStr(tv); break; // Note that this is intentionally incorrect for NameValueTableWrapper, for // which getSize() will always return -1, empty or not. case KindOfArray: b = !!tv->m_data.parr->getSize(); tvDecRefArr(tv); break; case KindOfObject: b = tv->m_data.pobj->o_toBoolean(); tvDecRefObj(tv); break; case KindOfResource: b = tv->m_data.pres->o_toBoolean(); tvDecRefRes(tv); break; default: assert(false); b = false; break; } tv->m_data.num = b; tv->m_type = KindOfBoolean; }
void tvCastToArrayInPlace(TypedValue* tv) { assert(tvIsPlausible(*tv)); tvUnboxIfNeeded(tv); ArrayData * a; switch (tv->m_type) { case KindOfUninit: case KindOfNull: a = ArrayData::Create(); break; case KindOfBoolean: case KindOfInt64: case KindOfDouble: case KindOfStaticString: a = ArrayData::Create(tvAsVariant(tv)); break; case KindOfString: { a = ArrayData::Create(tvAsVariant(tv)); tvDecRefStr(tv); break; } case KindOfArray: return; case KindOfObject: { // For objects, we fall back on the Variant machinery tvAsVariant(tv) = tv->m_data.pobj->o_toArray(); return; } case KindOfResource: { a = ArrayData::Create(tvAsVariant(tv)); tvDecRefRes(tv); break; } default: assert(false); a = ArrayData::Create(); break; } tv->m_data.parr = a; tv->m_type = KindOfArray; tv->m_data.parr->incRefCount(); }
void tvCastToDoubleInPlace(TypedValue* tv) { assert(tvIsPlausible(*tv)); tvUnboxIfNeeded(tv); double d; switch (tv->m_type) { case KindOfUninit: case KindOfNull: d = 0.0; break; case KindOfBoolean: assert(tv->m_data.num == 0LL || tv->m_data.num == 1LL); case KindOfInt64: d = (double)(tv->m_data.num); break; case KindOfDouble: return; case KindOfStaticString: d = tv->m_data.pstr->toDouble(); break; case KindOfString: d = tv->m_data.pstr->toDouble(); tvDecRefStr(tv); break; case KindOfArray: { d = (double)(tv->m_data.parr->empty() ? 0LL : 1LL); tvDecRefArr(tv); break; } case KindOfObject: { d = tv->m_data.pobj->o_toDouble(); tvDecRefObj(tv); break; } case KindOfResource: { d = tv->m_data.pres->o_toDouble(); tvDecRefRes(tv); break; } default: assert(false); d = 0.0; break; } tv->m_data.dbl = d; tv->m_type = KindOfDouble; }
void tvCastToDoubleInPlace(TypedValue* tv) { assert(tvIsPlausible(*tv)); tvUnboxIfNeeded(tv); double d; do { switch (tv->m_type) { case KindOfUninit: case KindOfNull: d = 0.0; continue; case KindOfBoolean: assert(tv->m_data.num == 0LL || tv->m_data.num == 1LL); // fallthru case KindOfInt64: d = (double)(tv->m_data.num); continue; case KindOfDouble: return; case KindOfPersistentString: d = tv->m_data.pstr->toDouble(); continue; case KindOfString: d = tv->m_data.pstr->toDouble(); tvDecRefStr(tv); continue; case KindOfPersistentArray: d = tv->m_data.parr->empty() ? 0 : 1; continue; case KindOfArray: d = tv->m_data.parr->empty() ? 0 : 1; tvDecRefArr(tv); continue; case KindOfObject: d = tv->m_data.pobj->toDouble(); tvDecRefObj(tv); continue; case KindOfResource: d = tv->m_data.pres->data()->o_toDouble(); tvDecRefRes(tv); continue; case KindOfRef: case KindOfClass: break; } not_reached(); } while (0); tv->m_data.dbl = d; tv->m_type = KindOfDouble; }
void tvCastToArrayInPlace(TypedValue* tv) { assert(tvIsPlausible(*tv)); tvUnboxIfNeeded(tv); ArrayData* a; do { switch (tv->m_type) { case KindOfUninit: case KindOfNull: a = ArrayData::Create(); continue; case KindOfBoolean: case KindOfInt64: case KindOfDouble: case KindOfPersistentString: a = ArrayData::Create(tvAsVariant(tv)); continue; case KindOfString: a = ArrayData::Create(tvAsVariant(tv)); tvDecRefStr(tv); continue; case KindOfPersistentArray: case KindOfArray: { ArrayData* adIn = tv->m_data.parr; if (adIn->isVecArray()) { tv->m_data.parr = PackedArray::MakeFromVec(adIn, adIn->cowCheck()); tv->m_type = KindOfArray; } else if (adIn->isDict()) { tv->m_data.parr = MixedArray::MakeFromDict(adIn, adIn->cowCheck()); tv->m_type = KindOfArray; } return; } case KindOfObject: // For objects, we fall back on the Variant machinery tvAsVariant(tv) = tv->m_data.pobj->toArray(); return; case KindOfResource: a = ArrayData::Create(tvAsVariant(tv)); tvDecRefRes(tv); continue; case KindOfRef: case KindOfClass: break; } not_reached(); } while (0); assert(!a->isRefCounted() || a->hasExactlyOneRef()); tv->m_data.parr = a; tv->m_type = KindOfArray; }
void cellCastToInt64InPlace(Cell* cell) { assert(cellIsPlausible(*cell)); int64_t i; do { switch (cell->m_type) { case KindOfUninit: case KindOfNull: cell->m_data.num = 0LL; // fallthru case KindOfBoolean: assert(cell->m_data.num == 0LL || cell->m_data.num == 1LL); cell->m_type = KindOfInt64; // fallthru case KindOfInt64: return; case KindOfDouble: i = toInt64(cell->m_data.dbl); continue; case KindOfPersistentString: i = cell->m_data.pstr->toInt64(); continue; case KindOfString: i = cell->m_data.pstr->toInt64(); tvDecRefStr(cell); continue; case KindOfPersistentArray: i = cell->m_data.parr->empty() ? 0 : 1; continue; case KindOfArray: i = cell->m_data.parr->empty() ? 0 : 1; tvDecRefArr(cell); continue; case KindOfObject: i = cell->m_data.pobj->toInt64(); tvDecRefObj(cell); continue; case KindOfResource: i = cell->m_data.pres->data()->o_toInt64(); tvDecRefRes(cell); continue; case KindOfRef: case KindOfClass: break; } not_reached(); } while (0); cell->m_data.num = i; cell->m_type = KindOfInt64; }
void tvCastToBooleanInPlace(TypedValue* tv) { assert(tvIsPlausible(*tv)); tvUnboxIfNeeded(tv); bool b; do { switch (tv->m_type) { case KindOfUninit: case KindOfNull: b = false; continue; case KindOfBoolean: return; case KindOfInt64: b = (tv->m_data.num != 0LL); continue; case KindOfDouble: b = (tv->m_data.dbl != 0); continue; case KindOfStaticString: b = tv->m_data.pstr->toBoolean(); continue; case KindOfString: b = tv->m_data.pstr->toBoolean(); tvDecRefStr(tv); continue; case KindOfArray: b = !!tv->m_data.parr->size(); tvDecRefArr(tv); continue; case KindOfObject: b = tv->m_data.pobj->toBoolean(); tvDecRefObj(tv); continue; case KindOfResource: b = tv->m_data.pres->o_toBoolean(); tvDecRefRes(tv); continue; case KindOfRef: case KindOfClass: break; } not_reached(); } while (0); tv->m_data.num = b; tv->m_type = KindOfBoolean; }
void tvCastToArrayInPlace(TypedValue* tv) { assert(tvIsPlausible(*tv)); tvUnboxIfNeeded(tv); ArrayData* a; do { switch (tv->m_type) { case KindOfUninit: case KindOfNull: a = ArrayData::Create(); continue; case KindOfBoolean: case KindOfInt64: case KindOfDouble: case KindOfStaticString: a = ArrayData::Create(tvAsVariant(tv)); continue; case KindOfString: a = ArrayData::Create(tvAsVariant(tv)); tvDecRefStr(tv); continue; case KindOfArray: return; case KindOfObject: // For objects, we fall back on the Variant machinery tvAsVariant(tv) = tv->m_data.pobj->toArray(); return; case KindOfResource: a = ArrayData::Create(tvAsVariant(tv)); tvDecRefRes(tv); continue; case KindOfRef: case KindOfClass: break; } not_reached(); } while (0); assert(a->isStatic() || a->hasExactlyOneRef()); tv->m_data.parr = a; tv->m_type = KindOfArray; }
void cellCastToInt64InPlace(Cell* cell) { assert(cellIsPlausible(*cell)); int64_t i; switch (cell->m_type) { case KindOfUninit: case KindOfNull: cell->m_data.num = 0LL; // Fall through case KindOfBoolean: assert(cell->m_data.num == 0LL || cell->m_data.num == 1LL); cell->m_type = KindOfInt64; // Fall through case KindOfInt64: return; case KindOfDouble: { i = toInt64(cell->m_data.dbl); break; } case KindOfStaticString: i = (cell->m_data.pstr->toInt64()); break; case KindOfString: { i = cell->m_data.pstr->toInt64(); tvDecRefStr(cell); break; } case KindOfArray: i = cell->m_data.parr->empty() ? 0 : 1; tvDecRefArr(cell); break; case KindOfObject: i = cell->m_data.pobj->o_toInt64(); tvDecRefObj(cell); break; case KindOfResource: i = cell->m_data.pres->o_toInt64(); tvDecRefRes(cell); break; default: not_reached(); } cell->m_data.num = i; cell->m_type = KindOfInt64; }
void tvCastToBooleanInPlace(TypedValue* tv) { assert(tvIsPlausible(*tv)); tvUnboxIfNeeded(tv); bool b; switch (tv->m_type) { case KindOfUninit: case KindOfNull: b = false; break; case KindOfBoolean: return; case KindOfInt64: b = (tv->m_data.num != 0LL); break; case KindOfDouble: b = (tv->m_data.dbl != 0); break; case KindOfStaticString: b = tv->m_data.pstr->toBoolean(); break; case KindOfString: b = tv->m_data.pstr->toBoolean(); tvDecRefStr(tv); break; case KindOfArray: b = (!tv->m_data.parr->empty()); tvDecRefArr(tv); break; case KindOfObject: b = tv->m_data.pobj->o_toBoolean(); tvDecRefObj(tv); break; case KindOfResource: b = tv->m_data.pres->o_toBoolean(); tvDecRefRes(tv); break; default: assert(false); b = false; break; } tv->m_data.num = b; tv->m_type = KindOfBoolean; }