static void checkTuple(cgn::CodegenState* cs, const DecompMapping& bind, CGResult rhs) { iceAssert(!bind.array); auto rt = rhs.value->getType(); iceAssert(rt->isTupleType()); auto tty = rt->toTupleType(); iceAssert(bind.inner.size() == tty->getElementCount()); for(size_t i = 0; i < tty->getElementCount(); i++) { CGResult v; if(rhs->islorclvalue()) { auto gep = cs->irb.StructGEP(rhs.value, i); v = CGResult(gep); } else { v = CGResult(cs->irb.ExtractValue(rhs.value, { i })); } cs->generateDecompositionBindings(bind.inner[i], v, true); } }
void SelectionMenu::drawMenu(FWRenderer &r, bool top) { const int height = getElementCount() * 9 + 10; int x = _pos.x; int y = _pos.y; if (x + _width > 319) x = 319 - _width; if (y + height > 199) y = 199 - height; const bool isAmiga = (g_cine->getPlatform() == Common::kPlatformAmiga); if (isAmiga) { r.drawTransparentBox(x, y, _width, height); r.drawDoubleBorder(x, y, _width, height, 18); } else { r.drawPlainBox(x, y, _width, height, r._messageBg); r.drawDoubleBorder(x, y, _width, height, 2); } int lineY = y + 4; const int elemCount = getElementCount(); for (int i = 0; i < elemCount; ++i, lineY += 9) { int charX = x + 4; if (i == _selection) { int color; if (isAmiga) { if (top) { color = 2; } else { color = 18; } } else { color = 0; } r.drawPlainBox(x + 2, lineY - 1, _width - 3, 9, color); } const int size = _elements[i].size(); for (int j = 0; j < size; ++j) { if (isAmiga && i == _selection) { charX = r.undrawChar(_elements[i][j], charX, lineY); } else { charX = r.drawChar(_elements[i][j], charX, lineY); } } } }
static void checkTuple(sst::TypecheckState* fs, DecompMapping* bind, fir::Type* rhs, bool immut) { iceAssert(!bind->array); if(!rhs->isTupleType()) error(bind->loc, "expected tuple type in destructuring declaration; found type '%s' instead", rhs); auto tty = rhs->toTupleType(); if(bind->inner.size() != tty->getElementCount()) { error(bind->loc, "too %s bindings in destructuring declaration; expected %d, found %d instead", (bind->inner.size() < tty->getElementCount() ? "few" : "many"), tty->getElementCount(), bind->inner.size()); } for(size_t i = 0; i < tty->getElementCount(); i++) checkAndAddBinding(fs, &bind->inner[i], tty->getElementN(i), immut, true); }
/** * Finalize at most the first 'count' elements of the allocation by applying * the finalizer to each element in turn, from last to first, thus ensuring * that elements of the array are destroyed in the opposite order to that in * which they were created. */ void Header::finalize(count_t count) { if (finalizer_t f = getFinalizer()) // Not yet finalized? { size_t n = getElementSize(); // ...size of element size_t c = std::min(getElementCount(),count); // ...el's to destroy byte_t* p = getPayload(); // ...head of payload byte_t* q = p + c * n; // ...tail of payload /* Clear the 'finalizer' flag to signal that the finalization has been taken care of. We do so *before* invoking 'f', in case 'f' goes and frees the entire allocation in which the header sits, as happens to the underlying pages of class ScopedArena, for example...*/ _flags &= ~finalizer; // ...taken care of /* Finalize each of the elements from the end of the array back toward its beginning, that is, in the opposite order to that in which they were first constructed...*/ for (size_t i=0; i!=c; ++i) // ...for each element { f(q -= n); // ....call finalizer } /* It is now no longer safe to access any of this object's members...*/ } }
void SelectionMenu::setSelection(int selection) { if (selection >= getElementCount() || selection < -1) { warning("Invalid selection %d", selection); selection = -1; } _selection = selection; }
void SelectionMenu::drawMenu(FWRenderer &r, bool top) { const int height = getElementCount() * 9 + 10; int x = _pos.x; int y = _pos.y; if (x + _width > 319) x = 319 - _width; if (y + height > 199) y = 199 - height; const bool isAmiga = (g_cine->getPlatform() == Common::kPlatformAmiga); if (isAmiga) { r.drawTransparentBox(x, y, _width, height); r.drawDoubleBorder(x, y, _width, height, 18); } else { r.drawPlainBox(x, y, _width, height, r._messageBg); r.drawDoubleBorder(x, y, _width, height, 2); } int lineY = y + 4; int charX; const int elemCount = getElementCount(); for (int i = 0; i < elemCount; ++i, lineY += 9) { charX = x + 4; if (i == _selection) { if (isAmiga) { // The original Amiga version is using a different highlight color here, // but with our current code it is not possible to change the text color, // thus we can not use the Amiga's color, since otherwise the text // wouldn't be visible anymore. r.drawPlainBox(charX, lineY, _width - 8, FONT_HEIGHT, top ? r._messageBg/*2*/ : 18); } else { r.drawPlainBox(charX, lineY, _width - 8, 9, 0); } } const int size = _elements[i].size(); for (int j = 0; j < size; ++j) charX = r.drawChar(_elements[i][j], charX, lineY); } }
/** * Return true if the object looks to be in good shape. Centralizes a number * of consistency checks that would otherwise clutter up the code, and, since * only ever called from within assertions, can be eliminated entirely by the * compiler from the release build. */ bool Header::consistent() const { /* A vector finalizer implies having a non-trivial array element count...*/ if (has(vectorFinalizer)) // Vector finalizer? { assert(getElementCount() >= 2); // ...proper count } else { assert(getElementCount() == 1); // ...trivial count } assert(has(finalizer) == (getFinalizer()!=0)); // Check finalizer() assert(aligned(getPayload())); // Check it's aligned return true; // Appears to be good }
void IndexBuffer::render(PrimitiveType type) { glBindBuffer(_bufferType, _handle); glDrawElements( TranslatePrimitiveType(type), getElementCount(), getDataType(), 0 ); glBindBuffer(_bufferType, 0); }
void Shape::draw(RenderContext* renderContext) { drawBegin(renderContext); SAVEGLERROR; for(int i=0;i<getElementCount();i++) drawElement(renderContext, i); SAVEGLERROR; drawEnd(renderContext); SAVEGLERROR; }
/* * This is a qsort() callback. We sort Object* by class, allocation size, * and then by the Object* itself. */ static int compareObject(const void* vobj1, const void* vobj2) { const Object* obj1 = *((Object* const*) vobj1); const Object* obj2 = *((Object* const*) vobj2); // Ensure null references and cleared jweaks appear at the end. if (obj1 == NULL) { if (obj2 == NULL) { return 0; } else { return 1; } } else if (obj2 == NULL) { return -1; } if (obj1 == kClearedJniWeakGlobal) { if (obj2 == kClearedJniWeakGlobal) { return 0; } else { return 1; } } else if (obj2 == kClearedJniWeakGlobal) { return -1; } if (obj1->clazz != obj2->clazz) { return (u1*)obj1->clazz - (u1*)obj2->clazz; } else { size_t count1 = getElementCount(obj1); size_t count2 = getElementCount(obj2); if (count1 != count2) { return count1 - count2; } else { return (u1*)obj1 - (u1*)obj2; } } }
void VertexFormat::set(const VertexAttribute attrib, const int size, const DataType dataType) { if(size >= 0 && size <= 4) { m_attributes[attrib].elementCount = size; m_attributes[attrib].dataType = dataType; m_vertexByteSize = 0; for(int i = 0; i < VERTEX_ATTRIB_MAX; i++) { VertexAttribute at = VertexAttribute(i); if(isAttributeEnabled(at)) { m_attributes[at].offset = m_vertexByteSize; switch(getDataType(at)) { case XD_FLOAT: m_vertexByteSize += sizeof(float)*getElementCount(at); break; case XD_UINT: case XD_INT: m_vertexByteSize += sizeof(int)*getElementCount(at); break; case XD_USHORT: case XD_SHORT: m_vertexByteSize += sizeof(short)*getElementCount(at); break; case XD_UBYTE: case XD_BYTE: m_vertexByteSize += sizeof(char)*getElementCount(at); break; } } } } else { LOG("VertexFormat::set(): Size must be in the range [0, 4]."); } }
// check the integrity of the LFUCache bool isSane() const { bool sane = false; BEGIN_TRANSACTION; sane = true; // Pointers that would otherwise be initialized in the loop rd_ptr<TableEntry> elt; rd_ptr<PriorityHeapNode> heap; rd_ptr<PriorityHeapNode> heap_lr; for (int j = 0; j < getElementCount(); j++) { elt = table[j]; if (elt->get_heapPtr(elt) != NULL) { heap = elt->get_heapPtr(elt); if (heap->get_left(heap) != NULL) { heap_lr = heap->get_left(heap); if (heap_lr->get_frequencyCount(heap_lr) < heap->get_frequencyCount(heap)) { sane = false; break; } } if (heap->get_right(heap) != NULL) { heap_lr = heap->get_right(heap); if (heap_lr->get_frequencyCount(heap_lr) < heap->get_frequencyCount(heap)) { sane = false; break; } } } } END_TRANSACTION; return sane; }
int ReportTableBase::getPageSplitStats(int itemsPerPage, vector<string> &IDs, vector<string> &IDsEnd, vector<string> &fNames, string &fnamePrefix, string &fnameSuffix) { // calculate # of pages int elems = getElementCount(); int nPages = elems / itemsPerPage; int elemsLeft = elems % itemsPerPage; if(elemsLeft > 0) nPages++; int i = 0; for(TableIterator it = begin() ; it != end() ; i++) { string fname = fnamePrefix; fname += parseInt(i); fname += fnameSuffix; fNames.push_back(fname); string start; if(m_idColumn < 0) start = parseInt(i); else { const vector<string> &aux = *(*it); start = parseInt(getInt(aux[m_idColumn].c_str())); } IDs.push_back(start); for(int j = 0 ; it != end() && j < itemsPerPage ; j++ , it++); it--; string end; if(m_idColumn < 0) end = parseInt(i); else { const vector<string> &aux = *(*it); end = parseInt(getInt(aux[m_idColumn].c_str())); } IDsEnd.push_back(end); it++; } return nPages; }
//----------------------------------------------------------------------- const VertexBufferDeclaration & D3D11VertexDeclaration::getVertexBufferDeclaration() { if (mVertexBufferDeclaration.getVertexBufferElementList().empty()) { VertexBufferElementList newList; unsigned short res = 0; for (unsigned short i = 0 ; i < getElementCount() ; i++) { VertexBufferElement newVertexBufferElement; newVertexBufferElement.setVertexElementIndex(getElement(i)->getIndex()); newVertexBufferElement.setVertexElementSemantic(getElement(i)->getSemantic()); newVertexBufferElement.setVertexElementType(getElement(i)->getType()); newList.push_back(newVertexBufferElement); } mVertexBufferDeclaration.setVertexBufferElementList(newList); } return mVertexBufferDeclaration; }
//----------------------------------------------------------------------- ID3D11InputLayout* D3D11VertexDeclaration::getILayoutByShader(D3D11HLSLProgram* boundVertexProgram) { ShaderToILayoutMapIterator foundIter = mShaderToILayoutMap.find(boundVertexProgram); ID3D11InputLayout* pVertexLayout = 0; if (foundIter == mShaderToILayoutMap.end()) { // if not found - create DWORD dwShaderFlags = 0; ID3D10Blob* pVSBuf = boundVertexProgram->getMicroCode(); D3D11_INPUT_ELEMENT_DESC * pVertexDecl=getD3DVertexDeclaration(); HRESULT hr = mlpD3DDevice->CreateInputLayout( pVertexDecl, (UINT)getElementCount(), pVSBuf->GetBufferPointer(), pVSBuf->GetBufferSize(), &pVertexLayout ); if (FAILED(hr)|| mlpD3DDevice.isError()) { String errorDescription = mlpD3DDevice.getErrorDescription(); OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to set D3D11 vertex declaration"+errorDescription , "D3D11VertexDeclaration::getILayoutByShader"); } mShaderToILayoutMap[boundVertexProgram] = pVertexLayout; } else { pVertexLayout = foundIter->second; } return pVertexLayout; }
void Texture::update() { glBindTexture(GL_TEXTURE_2D, _handle); _data.resize(_width * _height * getTypeSize(_type) * getElementCount(_format)); std::generate(_data.begin(), _data.end(), randbyte); glTexImage2D( GL_TEXTURE_2D, 0, _internalFormat, _width, _height, _border, _format, _type, &_data[0]); tpf(GL_TEXTURE_MIN_FILTER, _minFilter); tpf(GL_TEXTURE_MAG_FILTER, _magFilter); tpf(GL_TEXTURE_MIN_LOD, _minLOD); tpf(GL_TEXTURE_MAX_LOD, _maxLOD); tpi(GL_TEXTURE_BASE_LEVEL, _baseLevel); tpi(GL_TEXTURE_MAX_LEVEL, _maxLevel); tpf(GL_TEXTURE_WRAP_S, _wrapS); tpf(GL_TEXTURE_WRAP_T, _wrapT); tpf(GL_TEXTURE_WRAP_R, _wrapR); tpfv(GL_TEXTURE_BORDER_COLOR, _borderColor.getData()); tpf(GL_TEXTURE_PRIORITY, _priority); glBindTexture(GL_TEXTURE_2D, 0); }
BlockInputStreams StorageSystemDictionaries::read( const Names & column_names, const ASTPtr & query, const Context & context, QueryProcessingStage::Enum & processed_stage, const size_t max_block_size, const unsigned) { check(column_names); processed_stage = QueryProcessingStage::FetchColumns; ColumnWithTypeAndName col_name{std::make_shared<ColumnString>(), std::make_shared<DataTypeString>(), "name"}; ColumnWithTypeAndName col_origin{std::make_shared<ColumnString>(), std::make_shared<DataTypeString>(), "origin"}; ColumnWithTypeAndName col_type{std::make_shared<ColumnString>(), std::make_shared<DataTypeString>(), "type"}; ColumnWithTypeAndName col_key{std::make_shared<ColumnString>(), std::make_shared<DataTypeString>(), "key"}; ColumnWithTypeAndName col_attribute_names{ std::make_shared<ColumnArray>(std::make_shared<ColumnString>()), std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>()), "attribute.names" }; ColumnWithTypeAndName col_attribute_types{ std::make_shared<ColumnArray>(std::make_shared<ColumnString>()), std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>()), "attribute.types" }; ColumnWithTypeAndName col_has_hierarchy{std::make_shared<ColumnUInt8>(), std::make_shared<DataTypeUInt8>(), "has_hierarchy"}; ColumnWithTypeAndName col_bytes_allocated{std::make_shared<ColumnUInt64>(), std::make_shared<DataTypeUInt64>(), "bytes_allocated"}; ColumnWithTypeAndName col_query_count{std::make_shared<ColumnUInt64>(), std::make_shared<DataTypeUInt64>(), "query_count"}; ColumnWithTypeAndName col_hit_rate{std::make_shared<ColumnFloat64>(), std::make_shared<DataTypeFloat64>(), "hit_rate"}; ColumnWithTypeAndName col_element_count{std::make_shared<ColumnUInt64>(), std::make_shared<DataTypeUInt64>(), "element_count"}; ColumnWithTypeAndName col_load_factor{std::make_shared<ColumnFloat64>(), std::make_shared<DataTypeFloat64>(), "load_factor"}; ColumnWithTypeAndName col_creation_time{std::make_shared<ColumnUInt32>(), std::make_shared<DataTypeDateTime>(), "creation_time"}; ColumnWithTypeAndName col_last_exception{std::make_shared<ColumnString>(), std::make_shared<DataTypeString>(), "last_exception"}; ColumnWithTypeAndName col_source{std::make_shared<ColumnString>(), std::make_shared<DataTypeString>(), "source"}; const auto & external_dictionaries = context.getExternalDictionaries(); const std::lock_guard<std::mutex> lock{external_dictionaries.dictionaries_mutex}; for (const auto & dict_info : external_dictionaries.dictionaries) { col_name.column->insert(dict_info.first); col_origin.column->insert(dict_info.second.origin); if (dict_info.second.dict) { const auto dict_ptr = dict_info.second.dict->get(); col_type.column->insert(dict_ptr->getTypeName()); const auto & dict_struct = dict_ptr->getStructure(); col_key.column->insert(dict_struct.getKeyDescription()); col_attribute_names.column->insert(ext::map<Array>(dict_struct.attributes, [] (auto & attr) -> decltype(auto) { return attr.name; })); col_attribute_types.column->insert(ext::map<Array>(dict_struct.attributes, [] (auto & attr) -> decltype(auto) { return attr.type->getName(); })); col_bytes_allocated.column->insert(dict_ptr->getBytesAllocated()); col_query_count.column->insert(dict_ptr->getQueryCount()); col_hit_rate.column->insert(dict_ptr->getHitRate()); col_element_count.column->insert(dict_ptr->getElementCount()); col_load_factor.column->insert(dict_ptr->getLoadFactor()); col_creation_time.column->insert(std::chrono::system_clock::to_time_t(dict_ptr->getCreationTime())); col_source.column->insert(dict_ptr->getSource()->toString()); } else { col_type.column->insertDefault(); col_key.column->insertDefault(); col_attribute_names.column->insertDefault(); col_attribute_types.column->insertDefault(); col_bytes_allocated.column->insertDefault(); col_query_count.column->insertDefault(); col_hit_rate.column->insertDefault(); col_element_count.column->insertDefault(); col_load_factor.column->insertDefault(); col_creation_time.column->insertDefault(); col_source.column->insertDefault(); } if (dict_info.second.exception) { try { std::rethrow_exception(dict_info.second.exception); } catch (...) { col_last_exception.column->insert(getCurrentExceptionMessage(false)); } } else col_last_exception.column->insertDefault(); } Block block{ col_name, col_origin, col_type, col_key, col_attribute_names, col_attribute_types, col_bytes_allocated, col_query_count, col_hit_rate, col_element_count, col_load_factor, col_creation_time, col_last_exception, col_source }; return BlockInputStreams{1, std::make_shared<OneBlockInputStream>(block)}; }
/* * Dump a summary of an array of references to the log file. * * This is used to dump the contents of ReferenceTable and IndirectRefTable * structs. */ void dvmDumpReferenceTableContents(Object* const* refs, size_t count, const char* descr) { LOGW("%s reference table (%p) dump:", descr, refs); if (count == 0) { LOGW(" (empty)"); return; } // Dump the most recent N entries. const size_t kLast = 10; int first = count - kLast; if (first < 0) { first = 0; } LOGW(" Last %d entries (of %d):", (count - first), count); for (int idx = count - 1; idx >= first; --idx) { const Object* ref = refs[idx]; if (ref == NULL) { continue; } if (ref == kClearedJniWeakGlobal) { LOGW(" %5d: cleared jweak", idx); continue; } if (ref->clazz == NULL) { // should only be possible right after a plain dvmMalloc(). size_t size = dvmObjectSizeInHeap(ref); LOGW(" %5d: %p (raw) (%zd bytes)", idx, ref, size); continue; } std::string className(dvmHumanReadableType(ref)); std::string extras; size_t elems = getElementCount(ref); if (elems != 0) { StringAppendF(&extras, " (%zd elements)", elems); } else if (ref->clazz == gDvm.classJavaLangString) { const StringObject* str = reinterpret_cast<const StringObject*>(ref); extras += " \""; size_t count = 0; char* s = dvmCreateCstrFromString(str); char* p = s; for (; *p && count < 16; ++p, ++count) { extras += *p; } if (*p == 0) { extras += "\""; } else { StringAppendF(&extras, "... (%d chars)", str->length()); } free(s); } LOGW(" %5d: %p %s%s", idx, ref, className.c_str(), extras.c_str()); } // Make a copy of the table, and sort it. Object** tableCopy = (Object**)malloc(sizeof(Object*) * count); if (tableCopy == NULL) { LOGE("Unable to copy table with %d elements", count); return; } memcpy(tableCopy, refs, sizeof(Object*) * count); qsort(tableCopy, count, sizeof(Object*), compareObject); refs = tableCopy; // use sorted list // Remove any uninteresting stuff from the list. The sort moved them all to the end. while (count > 0 && refs[count-1] == NULL) { --count; } while (count > 0 && refs[count-1] == kClearedJniWeakGlobal) { --count; } if (count == 0) { return; } // Dump a summary of the whole table. LOGW(" Summary:"); size_t equiv, identical; equiv = identical = 0; size_t idx; size_t elems; for (idx = 1; idx < count; idx++) { elems = getElementCount(refs[idx-1]); if (refs[idx] == refs[idx-1]) { // same reference, added more than once. identical++; } else if (refs[idx]->clazz == refs[idx-1]->clazz && getElementCount(refs[idx]) == elems) { // same class / element count, different object. equiv++; } else { // different class. logSummaryLine(refs[idx-1], elems, identical, equiv); equiv = identical = 0; } } // Handle the last entry (everything above outputs refs[i-1]). elems = getElementCount(refs[idx-1]); logSummaryLine(refs[count-1], elems, identical, equiv); free(tableCopy); }
VariableExpression* VariableExpression::clone() const { return o_new(VariableExpression)(m_pVariable, getElementCount() ? getElement(0)->asExpression() : nullptr); }