JSONValue JSONValue::CreateChild(JSONValueType valueType) { assert(IsArray()); if (!IsArray()) return JSONValue::EMPTY; Value value(ToRapidJsonType(valueType)); value_->PushBack(value, file_->GetDocument()->GetAllocator()); return GetChild(GetSize() - 1, valueType); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int AggregateCopyPropagation::ExtractCopySetInfo(CallInstr* instr, Operand*& destOp) { DebugValidator::IsNotNull(instr); // Check if we have a call to 'copyMemory' or // 'setMemory' that targets records or arrays. if(auto intrinsic = instr->GetIntrinsic()) { bool valid = false; bool isCopy; destOp = WithoutPointerCasts(CopyMemoryIntr::GetDestination(instr)); if(intrinsic->Is<CopyMemoryIntr>()) { // The copy is valid only if the whole object // is copied using a constant size argument. auto destType = destOp->GetType()->As<PointerType>()->PointeeType(); if(destType->IsRecord() || destType->IsArray()) { if(auto intConst = CopyMemoryIntr::GetLength(instr)->As<IntConstant>()) { int size = TI::GetSize(destType, GetTarget()); valid = intConst->Value() == size; } } isCopy = true; } else if(intrinsic->Is<SetMemoryIntr>()) { // The copy is valid only if the whole object // is set using a constant size argument and a constant value. auto destType = destOp->GetType()->As<PointerType>()->PointeeType(); if(destType->IsRecord() || destType->IsArray()) { if(auto intConst = SetMemoryIntr::GetLength(instr)->As<IntConstant>()) { int size = TI::GetSize(destType, GetTarget()); // Check that the value that is set is a constant. valid = (intConst->Value() == size) && (SetMemoryIntr::GetSource(instr)->IsIntConstant()); } } isCopy = false; } if(valid) { return AddInfo(instr, isCopy); } } return -1; }
TITANIUM_FUNCTION(ListView, replaceSectionAt) { const auto js_context = this_object.get_context(); if (arguments.size() >= 2) { JSObject animation = js_context.CreateObject(); std::vector<std::shared_ptr<ListSection>> sections; const auto _0 = arguments.at(0); TITANIUM_ASSERT(_0.IsNumber()); const auto sectionIndex = static_cast<uint32_t>(_0); const auto _1 = arguments.at(1); TITANIUM_ASSERT(_1.IsObject()); const auto js_sections = static_cast<JSObject>(_1); if (js_sections.IsArray()) { sections = static_cast<JSArray>(js_sections).GetPrivateItems<ListSection>(); } else { sections.push_back(js_sections.GetPrivate<ListSection>()); } if (arguments.size() >= 3) { const auto _2 = arguments.at(2); if (_2.IsObject()) { animation = listviewAnimationProperties_ctor__.CallAsConstructor({_2}); } } replaceSectionAt(sectionIndex, sections, animation.GetPrivate<ListViewAnimationProperties>()); } return this_object.get_context().CreateUndefined(); }
Qt::ItemFlags JSON_Model::flags(QModelIndex const& index) const { // std::lock_guard<std::recursive_mutex> sm(mTreeMutex); if (!index.isValid()) { return 0; } uint32_t default_flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable; auto* ti = (Tree_Item*)index.internalPointer(); if (!ti || !ti->m_json) { return Qt::ItemFlags(default_flags); } auto json = ti->m_json; if (json->IsObject() || json->IsArray()) { return Qt::ItemFlags(default_flags); } return Qt::ItemFlags((index.column() == 0) ? default_flags : default_flags | Qt::ItemIsEditable); }
nsresult KeyPath::ExtractKey(JSContext* aCx, const JS::Value& aValue, Key& aKey) const { uint32_t len = mStrings.Length(); JS::Rooted<JS::Value> value(aCx); aKey.Unset(); for (uint32_t i = 0; i < len; ++i) { nsresult rv = GetJSValFromKeyPathString(aCx, aValue, mStrings[i], value.address(), DoNotCreateProperties, nullptr, nullptr); if (NS_FAILED(rv)) { return rv; } if (NS_FAILED(aKey.AppendItem(aCx, IsArray() && i == 0, value))) { NS_ASSERTION(aKey.IsUnset(), "Encoding error should unset"); return NS_ERROR_DOM_INDEXEDDB_DATA_ERR; } } aKey.FinishArray(); return NS_OK; }
const Array &Node::AsArray() const { if (IsArray()) return static_cast<const Array&>(*this); else throw TypeException(); }
int WindDataParser::GetStrItemIndexOfSafeArray(const VARIANT& safeArray, const wstring& itemNameStr) { if(!IsArray(safeArray)) { return -1; } int length = GetCountOfSafeArray(safeArray); HRESULT hr ; BSTR *pbItems; hr = SafeArrayAccessData(safeArray.parray, (void HUGEP**)&pbItems); if (FAILED(hr)) { return -1; } int nRetIndex = -1; for(int index = 0; index < length; index++) { if (0 == itemNameStr.compare(pbItems[index])) { nRetIndex = index; break; } } SafeArrayUnaccessData(safeArray.parray); return nRetIndex; }
wstring WindDataParser::GetStrItemByIndex(const VARIANT& safeArray, int index) { if(!IsArray(safeArray)) { return L""; } if (VT_BSTR != (safeArray.vt & VT_BSTR_BLOB)) { return L""; } HRESULT hr ; BSTR *pbItems; if (index >= GetCountOfSafeArray(safeArray)) { return L""; } hr = SafeArrayAccessData(safeArray.parray, (void HUGEP**)&pbItems); if (FAILED(hr)) { return L""; } wstring itemStr = pbItems[index]; SafeArrayUnaccessData(safeArray.parray); return itemStr; }
int WindDataParser::GetDoubleItemIndexOfSafeArray(const VARIANT& safeArray, DOUBLE dbl) { if(!IsArray(safeArray)) { return -1; } int length = GetCountOfSafeArray(safeArray); HRESULT hr; DOUBLE *pbItems; hr = SafeArrayAccessData(safeArray.parray, (void HUGEP**)&pbItems); if (FAILED(hr)) { return -1; } int nRetIndex = -1; for(int index = 0; index < length; index++) { if (dbl == pbItems[index]) { nRetIndex = index; break; } } SafeArrayUnaccessData(safeArray.parray); return nRetIndex; }
template<typename VALUE_T>uint32_t Document_t<VALUE_T>::Locate(uint32_t pos, const char *path) const { char *cur, *next, *_path = strdup(path); for (cur = _path; cur != NULL; cur = next) { if ((next = strchr(cur, '.')) != NULL) *next++ = 0; if (strlen(cur) == strspn(cur, "0123456789")) { if (!IsArray(pos)) { pos = UINT32_MAX; goto quit0; } uint32_t idx = atol(cur); if (idx >= GetArraySpace(pos)) { pos = UINT32_MAX; goto quit0; } pos = GetArray(pos, idx); } else { if (!IsObject(pos)) { pos = UINT32_MAX; goto quit0; } if ((pos = ObjectSearch(pos, cur)) == UINT32_MAX) { pos = UINT32_MAX; goto quit0; } } } quit0: free(_path); return pos; }
void KeyPath::SerializeToString(nsAString& aString) const { NS_ASSERTION(IsValid(), "Check to see if I'm valid first!"); if (IsString()) { aString = mStrings[0]; return; } if (IsArray()) { // We use a comma in the beginning to indicate that it's an array of // key paths. This is to be able to tell a string-keypath from an // array-keypath which contains only one item. // It also makes serializing easier :-) uint32_t len = mStrings.Length(); for (uint32_t i = 0; i < len; ++i) { aString.Append(','); aString.Append(mStrings[i]); } return; } NS_NOTREACHED("What?"); }
// fix arrays -- i.e. replace a tuple containing ALL unnamed elements // with the corresponding array // ( gdb evaluator array data is returned as tuple with {} instead []= void MIValue::FixArrays(void) { bool named = false; if(IsTuple()) { for(int iVal = 0; iVal < tuple.GetCount(); iVal++) if(tuple.GetKey(iVal) != "<UNNAMED>") { named = true; break; } if(!named) { array.Clear(); for(int iVal = 0; iVal < tuple.GetCount(); iVal++) array.Add() = pick(tuple[iVal]); tuple.Clear(); type = MIArray; } } if(IsTuple() || IsArray()) for(int i = 0; i < GetCount(); i++) Get(i).FixArrays(); }
Type GetType(JSValueRef value) { if (JSValueIsNull(g_ctx, value)) return VTYPE_NULL; if (JSValueIsBoolean(g_ctx, value)) return VTYPE_BOOL; if (JSValueIsNumber(g_ctx, value)) return VTYPE_DOUBLE; if (JSValueIsString(g_ctx, value)) return VTYPE_STRING; if (JSValueIsObject(g_ctx, value)) { JSObjectRef obj = JSValueToObject(g_ctx, value, NULL); if (JSObjectIsFunction(g_ctx, obj)) return VTYPE_FUNCTION; if (IsArray(obj)) return VTYPE_LIST; return VTYPE_DICTIONARY; } return VTYPE_INVALID; }
void CVisProp::SetObjFromPv(const void *pvObj, const CVisDimIndex& refdimindex) { assert(IsArray()); PropTypeInfo().AssignObjToObj(pvObj, PRefCntArray()->PvObj(refdimindex)); }
void CVisProp::SetObjFromPv(const void *pvObj, bool fShared) { assert(pvObj != 0); assert(!IsValid() || !FPointerToObject() || PvRefCntObj() != 0); const CVisPropTypeInfoBase *pproptypeinfo = &PropTypeInfo(); if (IsValid() && (IsObjReference() || IsArray())) ReleaseObj(); SetFObjReference(false); if ((IsValid()) && (IsShared() == fShared)) { pproptypeinfo->AssignObjToObj(pvObj, PvObj()); } else { if (IsValid()) ReleaseObj(); SetFShared(fShared); SetFPointerToObject(fShared || !pproptypeinfo->CanCopyObjectBytes()); if (!FPointerToObject()) { SetFInitialized(true); pproptypeinfo->AssignObjToObj(pvObj, PvObj()); } else { SetPvRefCntObj(pproptypeinfo->PvRefCntObjMakePvObj(pvObj)); SetFInitialized(true); } } }
void CVisProp::SetObjReferenceFromPv(void *pvObj, bool fShared) { if (IsValid() && IsArray()) ReleaseObj(); assert(!IsValid() || !FPointerToObject() || PvRefCntObj() != 0); if ((IsValid()) && (IsShared() == fShared) && (IsObjReference())) { ((CVisRefCntObj<void *> *) PvRefCntObj())->Obj() = pvObj; } else { ReleaseObj(); SetFShared(fShared); SetFPointerToObject(fShared); if (fShared) { SetPvRefCntObj(new CVisRefCntObj<void *>(pvObj)); } else { *((void * *) (void *) &m_llData) = pvObj; } SetFObjReference(true); SetFInitialized(true); } }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void VariableAnalysis::MarkAddressTaken(Instruction* instr) { if(auto loadInstr = instr->As<LoadInstr>()) { // Volatile loads should not be eliminated. if(loadInstr->IsVolatile()) { if(auto variableRef = loadInstr->SourceOp()->As<VariableReference>()) { auto localVar = variableRef->GetVariable(); if(localVar == nullptr) { return; } localVar->SetIsAddresTaken(true); } } return; // We're done with this instruction. } else if(auto storeInstr = instr->As<StoreInstr>()) { // Volatile stores should not be eliminated. if(storeInstr->IsVolatile()) { if(auto variableRef = storeInstr->DestinationOp()->As<VariableReference>()) { auto localVar = variableRef->GetVariable(); if(localVar == nullptr) { return; } localVar->SetIsAddresTaken(true); } } // If the stored operand is a local variable we can't eliminate it. if(storeInstr->SourceOp()->IsLocalVariableRef()) { auto variableRef = storeInstr->SourceOp()->As<VariableReference>(); variableRef->GetVariable()->SetIsAddresTaken(true); } return; // We're done with this instruction. } // Any other instruction that has a variable reference as it's operand // is considered to take it's address. for(int i = 0; i < instr->SourceOpCount(); i++) { if(auto variableRef = instr->GetSourceOp(i)->As<VariableReference>()) { auto localVar = variableRef->GetVariable(); if(localVar == nullptr) { continue; } // We don't set the flag for pointers, arrays and records because // we have a separate step that takes care of this. if((localVar->IsPointer() || localVar->IsRecord() || localVar->IsArray()) == false) { localVar->SetIsAddresTaken(true); } } } }
const char *CVisProp::TypeName(void) const { const char *szTypeName = 0; assert(PropTypeInfo().TypeInfo() != typeid(CVisProp)); if (PropTypeInfo().TypeInfo() == typeid(CVisPropList)) { const CVisPropList *pproplist; if (IsArray()) { pproplist = (const CVisPropList *) (PRefCntArray()->PvObjFirst()); } else { pproplist = (const CVisPropList *) PvObj(); } assert(pproplist != 0); szTypeName = pproplist->TypeName(); } if (szTypeName == 0) szTypeName = PropTypeInfo().Name(); assert(szTypeName != 0); return szTypeName; }
TITANIUM_FUNCTION(MusicPlayer, setQueue) { ENSURE_OBJECT_AT_INDEX(js_queue, 0); std::vector<std::shared_ptr<Item>> queues; const auto queue = js_queue.GetPrivate<Item>(); if (queue != nullptr) { queues.push_back(queue); } else if (js_queue.IsArray()) { const auto js_array = static_cast<std::vector<JSValue>>(static_cast<JSArray>(js_queue)); for (const auto v : js_array) { queues.push_back(static_cast<JSObject>(v).GetPrivate<Item>()); } } else if (js_queue.HasProperty("items")) { // PlayerQueue const auto js_playerQueue = static_cast<JSObject>(js_queue.GetProperty("items")); if (js_playerQueue.IsArray()) { const auto js_array = static_cast<std::vector<JSValue>>(static_cast<JSArray>(js_playerQueue)); for (const auto v : js_array) { queues.push_back(static_cast<JSObject>(v).GetPrivate<Item>()); } } } setQueue(queues); return get_context().CreateUndefined(); }
size_t Json::size() const { if (IsNull()) return 0; if (IsObject()) return object().size(); if (IsArray()) return array().size(); if (IsString()) return string().size(); return 1; }
void CVisProp::SDOFindTypes(CVisSDOStream& refsdostream, const void *pvReferenceOffset) const { assert(IsValid()); assert((pvReferenceOffset == 0) || (IsObjReference())); if (IsArray()) { void *pvObjFirst = PRefCntArray()->PvObjFirst(); if ((pvReferenceOffset != 0) && (IsObjReference())) { pvObjFirst = (void *) (((BYTE *) pvObjFirst) + ((int) pvReferenceOffset)); } m_pproptypeinfo->SDOFindTypes(refsdostream, pvObjFirst, PRefCntArray()->Dim()); } else { void *pvObj = PvObj(); if ((pvReferenceOffset != 0) && (IsObjReference())) { pvObj = (void *) (((BYTE *) pvObj) + ((int) pvReferenceOffset)); } m_pproptypeinfo->SDOFindTypes(refsdostream, pvObj); } }
unsigned JSONValue::GetSize() const { if (IsArray()) return (unsigned)value_->Size(); else return 0; }
void _Check(const String& name, CIMConstProperty& p, T* tag) { if (p.getName() == name) { if (IsArray(tag) != p.isArray() || GetType(tag) != p.getType()) throw CIMException(CIM_ERR_TYPE_MISMATCH, name); } }
void CVisProp::SetSharing(bool f) { assert(IsValid()); if (f != IsShared()) { if (!IsShared()) { if ((FPointerToObject()) || (IsArray())) { // Just need to change the flag. m_fShared = f; } else { if (IsObjReference()) { // Make a temporary copy of the pointer to the object SetObjReferenceFromPv(PvObj(), true); } else { __int64 llDataT = m_llData; SetObjFromPv((void *) &llDataT, true); } } } else { // LATER: Have a special case for a shared object with only // one reference. (In that case, we only need to change m_fShared.) CVisProp propT = *this; if (propT.IsArray()) { if (propT.IsObjReference()) { SetObjReferenceFromPv(propT.PRefCntArray()->PvObjFirst(), false, propT.Dim()); } else { SetObjFromPv(propT.PRefCntArray()->PvObjFirst(), false, propT.Dim()); } } else { if (propT.IsObjReference()) { SetObjReferenceFromPv(propT.PvObj(), false); } else { SetObjFromPv(propT.PvObj(), false); } } } } }
CFX_Matrix CPDF_Array::GetMatrix() { CFX_Matrix matrix; if (!IsArray() || m_Objects.size() != 6) return matrix; matrix.Set(GetNumberAt(0), GetNumberAt(1), GetNumberAt(2), GetNumberAt(3), GetNumberAt(4), GetNumberAt(5)); return matrix; }
//------------------------------------------------------------------------------ void ReflectedPropertyStruct::ResizeArrayOfStruct( void * object, size_t newSize ) const { // sanity checks ASSERT( IsArray() ); ASSERT( GetType() == PT_STRUCT ); const ReflectionInfo * structRI = m_StructReflectionInfo; void * arrayBase = (void *)( (size_t)object + m_Offset ); structRI->SetArraySize( arrayBase, newSize ); }
uint32_t CalculateObjectSize(const VMValue object, uint8_t *memoryArea) { auto typeField = GetTypeField(object, memoryArea); if (IsArray(typeField)) { return AlignSize(GetArrayLengthUnchecked(object, memoryArea)*TypeSize(GetArrayValueType(typeField)) + ArrayHeaderSize()); } else { throw std::logic_error("Size calculation not implemented for non-arrays"); } }
TITANIUM_FUNCTION(View, showAnnotations) { TITANIUM_ASSERT(arguments.size() > 0); auto _0 = arguments.at(0); TITANIUM_ASSERT(_0.IsObject()); const auto _0Obj = static_cast<JSObject>(_0); TITANIUM_ASSERT(_0Obj.IsArray()); const auto annotations = static_cast<JSArray>(_0Obj); showAnnotations(annotations.GetPrivateItems<Annotation>()); return get_context().CreateUndefined(); }
CFX_FloatRect CPDF_Array::GetRect() { CFX_FloatRect rect; if (!IsArray() || m_Objects.size() != 4) return rect; rect.left = GetNumberAt(0); rect.bottom = GetNumberAt(1); rect.right = GetNumberAt(2); rect.top = GetNumberAt(3); return rect; }
TITANIUM_PROPERTY_SETTER(View, annotations) { if (!argument.IsObject()) { return false; } const auto annotations = static_cast<JSObject>(argument); if (!annotations.IsArray()) { return false; } set_annotations(static_cast<JSArray>(annotations).GetPrivateItems<Annotation>()); return true; }