ArrayType::ArrayType(const NodePtr& node) { assert_true(node) << "Given node is null!"; // support expressions as input auto type = node.isa<GenericTypePtr>(); if (auto expr = node.isa<ExpressionPtr>()) type = expr->getType().isa<GenericTypePtr>(); // check given node type assert_true(isArrayType(type)) << "Given node " << *node << " is not a array type!"; // process node type if(isInf(type->getTypeParameter(1))) { // unknown sized array *this = ArrayType(type->getTypeParameter(0), ExpressionPtr()); } else if (auto num = type->getTypeParameter(1).isa<NumericTypePtr>()) { // variable or fixed sized array *this = ArrayType(type->getTypeParameter(0), num->getValue()); } else { // check validity auto size = type->getTypeParameter(1).isa<TypeVariablePtr>(); assert_true(size) << "Invalid size parameter: " << *size << " of kind: " << size->getNodeType(); // generic array type *this = ArrayType(type->getTypeParameter(0), size); } }
/** Count Inversions in an array | Set 1 (Using Merge Sort) * * @reference Count Inversions in an array | Set 1 (Using Merge Sort) * https://www.geeksforgeeks.org/counting-inversions/ * * Inversion Count for an array indicates – how far (or close) the array is from being sorted. * If array is already sorted then inversion count is 0. If array is sorted in reverse order * that inversion count is the maximum. * Formally speaking, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j * * Example: * The sequence 2, 4, 1, 3, 5 has three inversions (2, 1), (4, 1), (4, 3). * * @complexity: O(n*lgn) */ auto Merge(const ArrayType::iterator begin, const ArrayType::iterator middle, const ArrayType::iterator end) { const auto L = ArrayType(begin, middle); const auto R = ArrayType(middle, end); auto iter = begin; auto L_iter = L.cbegin(); auto R_iter = R.cbegin(); unsigned inversion_count = 0u; for (; (L_iter != L.cend()) and (R_iter != R.cend()); ++iter) { if (*L_iter <= *R_iter) { *iter = *L_iter; ++L_iter; } else { *iter = *R_iter; ++R_iter; inversion_count += (L.cend() - L_iter); } } while (L_iter != L.cend()) { *iter++ = *L_iter++; } while (R_iter != R.cend()) { *iter++ = *R_iter++; } return inversion_count; }
PTREE DataDtorObjPush( // START OF DTORABLE OBJECT PTREE expr, // - expression to be decorated TYPE type, // - type of object SYMBOL init_sym, // - symbol being initialized target_offset_t offset ) // - offset of object being initialized { TYPE dtor_type; // - type for dtor #ifndef NDEBUG if( PragDbgToggle.dump_data_dtor ) { printf( "DataDtorObjPush -- symbol %s\n" " -- offset %x\n" " -- " , DbgSymNameFull( init_sym ) , offset ); DumpFullType( type ); } #endif dtor_type = type; if( NULL != ArrayType( dtor_type ) ) { dtor_type = ArrayBaseType( dtor_type ); } CDoptDtorBuild( dtor_type ); FunctionHasRegistration(); return PtdObjPush( expr, type, init_sym, offset ); }
void StrucType() { /* StrucType -> ArrayType | RecType | PointerType | ProcType */ if ( debugMode) printf( "In StrucType\n"); switch( sym) { case ARRAY_SYM: ArrayType(); break; case RECORD_SYM: RecType(); break; case POINTER_SYM: PointerType(); break; case PROCEDURE_SYM: ProcType(); break; default: error( invalid_sym, 1); } if ( debugMode) printf( "Out StrucType\n"); }
static CLASSINFO* getClassInfo( // GET CLASS INFO FOR GOOD ELEMENTAL TYPE TYPE type ) // - type { CLASSINFO* info; // - information for class TYPE artype; // - NULL or array type if( type == NULL ) { info = NULL; } else { artype = ArrayType( type ); if( artype != NULL ) { type = ArrayBaseType( artype ); } type = StructType( type ); if( type == NULL ) { info = NULL; } else { info = TypeClassInfo( type ); if( info->corrupted ) { info = NULL; } } } return( info ); }
static TYPE arrayOrStructType // PUT TYPE INTO CONICAL FORM ( TYPE type ) // - the type { TYPE retn = StructType( type ); if( NULL == retn ) { retn = ArrayType( type ); } return retn; }
CBotTypResult TypeParam(CBotToken* &p, CBotCStack* pile) { CBotClass* pClass = nullptr; switch (p->GetType()) { case ID_INT: p = p->GetNext(); return ArrayType(p, pile, CBotTypResult( CBotTypInt )); case ID_FLOAT: p = p->GetNext(); return ArrayType(p, pile, CBotTypResult( CBotTypFloat )); case ID_BOOLEAN: case ID_BOOL: p = p->GetNext(); return ArrayType(p, pile, CBotTypResult( CBotTypBoolean )); case ID_STRING: p = p->GetNext(); return ArrayType(p, pile, CBotTypResult( CBotTypString )); case ID_VOID: p = p->GetNext(); return CBotTypResult( 0 ); case TokenTypVar: pClass = CBotClass::Find(p); if ( pClass != nullptr) { p = p->GetNext(); return ArrayType(p, pile, pClass->IsIntrinsic() ? CBotTypResult( CBotTypIntrinsic, pClass ) : CBotTypResult( CBotTypPointer, pClass ) ); } } return CBotTypResult( -1 ); }
boolean NodeConvertArgument( // CONVERT AN ARGUMENT VALUE PTREE *a_expr, // - addr( argument value ) TYPE proto ) // - prototype type { boolean retn; // - return: TRUE ==> conversion ok if( NULL != ArrayType( proto ) ) { proto = PointerTypeForArray( proto ); } else { // ( const int ) prototype should be ( int ) at this point proto = TypedefModifierRemoveOnly( proto ); } *a_expr = CastImplicit( *a_expr, proto, CNV_FUNC_ARG, &diagArgConv ); retn = (*a_expr)->op != PT_ERROR; return retn; }
llvm::Value *CodeGen::AllocateBuffer(llvm::Type *element_type, uint32_t num_elems, const std::string &name) { // Allocate the array auto *arr_type = ArrayType(element_type, num_elems); auto *alloc = AllocateVariable(arr_type, ""); // The 'alloca' instruction returns a pointer to the allocated type. Since we // are allocating an array of 'element_type' (e.g., i32[4]), we get back a // double pointer (e.g., a i32**). Therefore, we introduce a GEP into the // buffer to strip off the first pointer reference. auto *arr = llvm::GetElementPtrInst::CreateInBounds( arr_type, alloc, {Const32(0), Const32(0)}, name); arr->insertAfter(llvm::cast<llvm::AllocaInst>(alloc)); return arr; }
static ArrayType py2c(PyObject *ob) { import_numpy(); return ArrayType(ob); }
GenericTypePtr ArrayType::create(const TypePtr& elementType, const ExpressionPtr& size) { return static_cast<GenericTypePtr>(ArrayType(elementType, toUIntInf(size))); }