当前位置: 首页>>代码示例>>C++>>正文


C++ ArrayType类代码示例

本文整理汇总了C++中ArrayType的典型用法代码示例。如果您正苦于以下问题:C++ ArrayType类的具体用法?C++ ArrayType怎么用?C++ ArrayType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ArrayType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: appendToGlobalArray

static void appendToGlobalArray(const char *Array, 
                                Module &M, Function *F, int Priority) {
  IRBuilder<> IRB(M.getContext());
  FunctionType *FnTy = FunctionType::get(IRB.getVoidTy(), false);

  // Get the current set of static global constructors and add the new ctor
  // to the list.
  SmallVector<Constant *, 16> CurrentCtors;
  StructType *EltTy;
  if (GlobalVariable *GVCtor = M.getNamedGlobal(Array)) {
    // If there is a global_ctors array, use the existing struct type, which can
    // have 2 or 3 fields.
    ArrayType *ATy = cast<ArrayType>(GVCtor->getType()->getElementType());
    EltTy = cast<StructType>(ATy->getElementType());
    if (Constant *Init = GVCtor->getInitializer()) {
      unsigned n = Init->getNumOperands();
      CurrentCtors.reserve(n + 1);
      for (unsigned i = 0; i != n; ++i)
        CurrentCtors.push_back(cast<Constant>(Init->getOperand(i)));
    }
    GVCtor->eraseFromParent();
  } else {
    // Use a simple two-field struct if there isn't one already.
    EltTy = StructType::get(IRB.getInt32Ty(), PointerType::getUnqual(FnTy),
                            nullptr);
  }

  // Build a 2 or 3 field global_ctor entry.  We don't take a comdat key.
  Constant *CSVals[3];
  CSVals[0] = IRB.getInt32(Priority);
  CSVals[1] = F;
  // FIXME: Drop support for the two element form in LLVM 4.0.
  if (EltTy->getNumElements() >= 3)
    CSVals[2] = llvm::Constant::getNullValue(IRB.getInt8PtrTy());
  Constant *RuntimeCtorInit =
      ConstantStruct::get(EltTy, makeArrayRef(CSVals, EltTy->getNumElements()));

  CurrentCtors.push_back(RuntimeCtorInit);

  // Create a new initializer.
  ArrayType *AT = ArrayType::get(EltTy, CurrentCtors.size());
  Constant *NewInit = ConstantArray::get(AT, CurrentCtors);

  // Create the new global variable and replace all uses of
  // the old global variable with the new one.
  (void)new GlobalVariable(M, NewInit->getType(), false,
                           GlobalValue::AppendingLinkage, NewInit, Array);
}
开发者ID:8l,项目名称:SPIRV-LLVM,代码行数:48,代码来源:ModuleUtils.cpp

示例2: getAlignmentInBits

ConstantInt* Variables::getAlignmentInBits(Type *type) {
  ConstantInt *alignment = NULL;
  ArrayType *arrayType = dyn_cast<ArrayType>(type);
  switch (arrayType->getElementType()->getTypeID()) {
  case Type::FloatTyID:
    alignment = getInt64(32);
    break;
  case Type::DoubleTyID:
    alignment = getInt64(64);
    break;
  default:
    errs() << "WARNING: Unhandled type @ getAlignmentInBits\n";
    exit(1);
  }
  return alignment;
}
开发者ID:Sumith1896,项目名称:precimonious,代码行数:16,代码来源:Variables.cpp

示例3: convertLengthToSize

void ArrayUtils::convertLengthToSize(ArrayType const& _arrayType, bool _pad) const
{
	if (_arrayType.getLocation() == ArrayType::Location::Storage)
	{
		if (_arrayType.isByteArray())
			m_context << u256(31) << eth::Instruction::ADD
				<< u256(32) << eth::Instruction::SWAP1 << eth::Instruction::DIV;
		else if (_arrayType.getBaseType()->getStorageSize() <= 1)
		{
			unsigned baseBytes = _arrayType.getBaseType()->getStorageBytes();
			if (baseBytes == 0)
				m_context << eth::Instruction::POP << u256(1);
			else if (baseBytes <= 16)
			{
				unsigned itemsPerSlot = 32 / baseBytes;
				m_context
					<< u256(itemsPerSlot - 1) << eth::Instruction::ADD
					<< u256(itemsPerSlot) << eth::Instruction::SWAP1 << eth::Instruction::DIV;
			}
		}
		else
			m_context << _arrayType.getBaseType()->getStorageSize() << eth::Instruction::MUL;
	}
	else
	{
		if (!_arrayType.isByteArray())
			m_context << _arrayType.getBaseType()->getCalldataEncodedSize() << eth::Instruction::MUL;
		else if (_pad)
			m_context << u256(31) << eth::Instruction::ADD
				<< u256(32) << eth::Instruction::DUP1
				<< eth::Instruction::SWAP2 << eth::Instruction::DIV << eth::Instruction::MUL;
	}
}
开发者ID:gluk256,项目名称:cpp-ethereum,代码行数:33,代码来源:ArrayUtils.cpp

示例4: GetType

Type* IndexExpression::GetType()
{
    Type *containerType =  Container->GetType();
    if (typeid(*containerType) == typeid(ArrayType))
    {
        ArrayType *arrayType = dynamic_cast<ArrayType *>(containerType);
        return arrayType->GetElementType();
    }
    else if (typeid(*containerType) == typeid(PointerType))
    {
        PointerType *pointerType = dynamic_cast<PointerType *>(containerType);
        return pointerType->GetUnderlyingType();
    }
    else
    {
        abort();
    }
}
开发者ID:chetui,项目名称:cc0,代码行数:18,代码来源:IndexExpression.cpp

示例5: getComponentType

int ArrayConv::ToV8Array(JNIEnv *jniEnv, jobject jVal, int expectedType, Handle<Object> *val) {
  int result = conv->UnwrapObject(jniEnv, jVal, val);
  if(result == ErrorNotfound) {
    int componentType = getComponentType(expectedType);
    ArrayType *arr;
    result = GetRefsForComponentType(jniEnv, componentType, &arr);
    if(result == OK) {
      Handle<Object> vInst;
      result = arr->PlatformNew(jniEnv, &vInst);
      if(result == OK) {
        result = conv->BindToJavaObject(jniEnv, jVal, vInst, arr->sHiddenKey);
        if(result == OK)
          *val = vInst;
      }
    }
  }
  return result;
}
开发者ID:CodeFridge,项目名称:anode,代码行数:18,代码来源:ArrayConv.cpp

示例6: RearrangeArraySimple

/** Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’ | Set 1
 *
 * @reference   https://www.geeksforgeeks.org/rearrange-array-arrj-becomes-arri-j/
 *
 * Given an array of size n where all elements are distinct and in range from 0 to n-1,
 * change contents of arr[] so that arr[i] = j is changed to arr[j] = i.
 */
auto RearrangeArraySimple(const ArrayType &elements) {
    auto output = elements;

    for (ArrayType::size_type i = 0; i < elements.size(); ++i) {
        const auto j = elements[i];
        output[j] = i;
    }

    return output;
}
开发者ID:yyang-even,项目名称:algorithms,代码行数:17,代码来源:rearrange_array_arrj_becomes_i_if_arri_j.cpp

示例7: h5_read

 std::c14::enable_if_t<is_amv_value_or_view_class<ArrayType>::value && !has_scalar_or_string_value_type<ArrayType>::value>
 h5_read(h5::group gr, std::string name, ArrayType& a) {
  static_assert(!std::is_const<ArrayType>::value, "Cannot read in const object");
  auto gr2 = gr.open_group(name);
  // TODO checking scheme...
  // load the shape
  auto sha2 = a.shape();
  array<int, 1> sha;
  h5_read(gr2, "shape", sha);
  if (first_dim(sha) != sha2.size())
   TRIQS_RUNTIME_ERROR << " array<array<...>> load : rank mismatch. Expected " << sha2.size()<< " Got " << first_dim(sha);
  for (int u = 0; u < sha2.size(); ++u) sha2[u] = sha(u);
  if (a.shape() != sha2) a.resize(sha2);
#ifndef __cpp_generic_lambdas
  foreach(a, h5_impl::_load_lambda<ArrayType>{a, gr2});
#else
  foreach(a, [&](auto... is) { h5_read(gr2, h5_impl::_h5_name(is...), a(is...)); });
#endif
 }
开发者ID:JaksaVucicevic,项目名称:triqs,代码行数:19,代码来源:array_of_non_basic.hpp

示例8: delete_line

void delete_line(ArrayType & stencil, long line_nb)
{
   for (long ci = 0; ci < stencil.size_2(); ++ci)
   {
      stencil(line_nb, ci) = 0.0;
      if (line_nb == long(ci))
         stencil(line_nb, ci) = 1.0;
         
   }
}
开发者ID:AlexanderToifl,项目名称:viennamesh-dev,代码行数:10,代码来源:utils.hpp

示例9: assert

DataType* ExportPass::CloneDataType(DataType* t)
{
  assert(t != NULL) ;
  PointerType* pointerClone = dynamic_cast<PointerType*>(t) ;
  ReferenceType* referenceClone = dynamic_cast<ReferenceType*>(t) ;
  ArrayType* arrayClone = dynamic_cast<ArrayType*>(t) ;
  if (pointerClone != NULL)
  {
    QualifiedType* refType = 
      dynamic_cast<QualifiedType*>(pointerClone->get_reference_type()) ;
    assert(refType != NULL) ;
    DataType* cloneType = CloneDataType(refType->get_base_type()) ;
    assert(cloneType != NULL) ;

    return create_pointer_type(theEnv, 
			       IInteger(32),
			       0,
			       create_qualified_type(theEnv, cloneType)) ;
  }
  if (referenceClone != NULL)
  {
    QualifiedType* refType = 
      dynamic_cast<QualifiedType*>(referenceClone->get_reference_type()) ;
    assert(refType != NULL) ;
    DataType* clonedType = CloneDataType(refType->get_base_type()) ;
    
    return create_reference_type(theEnv,
				 IInteger(32),
				 0,
				 create_qualified_type(theEnv, clonedType)) ;
  }
  if (arrayClone != NULL)
  {
    QualifiedType* elementType = arrayClone->get_element_type() ;
    DataType* internalType = CloneDataType(elementType->get_base_type()) ;
    QualifiedType* finalQual = create_qualified_type(theEnv, internalType) ;
    return create_pointer_type(theEnv,
			       IInteger(32),
			       0, 
			       finalQual) ;    
  }
  return dynamic_cast<DataType*>(t->deep_clone()) ;
}
开发者ID:JehandadKhan,项目名称:roccc-2.0,代码行数:43,代码来源:exportPass.cpp

示例10: strerror

status_t
ArrayValueNodeChild::ResolveLocation(ValueLoader* valueLoader,
	ValueLocation*& _location)
{
	// get the parent (== array) location
	ValueLocation* parentLocation = fParent->Location();
	if (parentLocation == NULL)
		return B_BAD_VALUE;

	// create an array index path
	ArrayType* arrayType = fParent->GetArrayType();
	int32 dimensionCount = arrayType->CountDimensions();

	// add dummy indices first -- we'll replace them on our way back through
	// our ancestors
	ArrayIndexPath indexPath;
	for (int32 i = 0; i < dimensionCount; i++) {
		if (!indexPath.AddIndex(0))
			return B_NO_MEMORY;
	}

	AbstractArrayValueNodeChild* child = this;
	for (int32 i = dimensionCount - 1; i >= 0; i--) {
		indexPath.SetIndexAt(i, child->ElementIndex());

		child = dynamic_cast<AbstractArrayValueNodeChild*>(
			child->ArrayParent()->NodeChild());
	}

	// resolve the element location
	ValueLocation* location;
	status_t error = arrayType->ResolveElementLocation(indexPath,
		*parentLocation, location);
	if (error != B_OK) {
		TRACE_LOCALS("ArrayValueNodeChild::ResolveLocation(): "
			"ResolveElementLocation() failed: %s\n", strerror(error));
		return error;
	}

	_location = location;
	return B_OK;
}
开发者ID:mmadia,项目名称:Haiku-services-branch,代码行数:42,代码来源:ArrayValueNode.cpp

示例11: WriteMembers

void Stream::WriteMembers(const uint8* object, ClassType* pType)
{
	for (uint i = 0; i < pType->m_pScope->m_orderedDecls.size(); i++)
	{
		Declarator* decl = pType->m_pScope->m_orderedDecls[i];

		if (!decl->get_IsStatic() && !decl->get_IsTypedef())
		{
			Type* pType = decl->m_pType->GetStripped();
			Type_type kind = pType->get_Kind();

			if (kind == type_array)
			{
				ArrayType* array = static_cast<ArrayType*>(pType);

				size_t count = array->get_ElemCount();

				for (size_t i = 0; i < count; ++i)
				{
					WriteMember(object + decl->m_offset + i*array->get_ElemType()->get_sizeof(), array->get_ElemType());
				}
			}
			else if (kind != type_function)
			{
				WriteMember(object + decl->m_offset, pType);
				/*
				switch (kind)
				{
				case type_int:
				case type_long:
				case type_unsigned_int:
				case type_unsigned_long:
				case type_float:

				case type_double:
				case type_long_long:
				}
				*/
			}
		}
	}
}
开发者ID:sigurdle,项目名称:FirstProject2,代码行数:42,代码来源:Remoting.cpp

示例12: while

MultiDimArrayType* OneDimArrayConverter::array_type2multi_array_type(ArrayType* at){
    suif_vector<ArrayType*> array_types;

    suif_map<ArrayType*, MultiDimArrayType*>::iterator type_iter =
            type_map->find(to<ArrayType>(at));

    if (type_iter == type_map->end()) {
        suif_vector<Expression*> lower_bounds;
        suif_vector<Expression*> upper_bounds;
        suif_vector<ArrayType*> array_types;
        Type *type = at->get_element_type()->get_base_type();

        array_types.push_back(at);                      // sub-types for this array type
        all_array_types->push_back(at);                 // all array types

        while (is_kind_of<ArrayType>(type)) {           // unwrap array access
            ArrayType *atyp = to<ArrayType>(type);
            array_types.push_back(atyp);
            type = atyp->get_element_type()->get_base_type();
        }

        // save lower and upper bounds
        for (int i = array_types.size()-1;i >=0;i--) {
            ArrayType *atyp = array_types[i];
            lower_bounds.push_back(deep_suif_clone(atyp->get_lower_bound()));
            upper_bounds.push_back(deep_suif_clone(atyp->get_upper_bound()));
        }

        IInteger bit_size = to<DataType>(type)->get_bit_size();
        IInteger bit_alignment = to<DataType>(type)->get_bit_alignment();

        MultiDimArrayType* multi_type = tb->get_multi_dim_array_type(
                bit_size, bit_alignment.c_int(), 
                tb->get_qualified_type(type),
                lower_bounds, upper_bounds);

        // save the translation in the map
        type_map->enter_value(at, multi_type);
        return multi_type;
    }else
        return (*type_iter).second;
}
开发者ID:JehandadKhan,项目名称:roccc-2.0,代码行数:42,代码来源:array_dismantlers.cpp

示例13: FindSubarrayWithGivenSum

std::pair<int, int> FindSubarrayWithGivenSum(const ArrayType &integers,
        const ArrayType::value_type SUM) {
    assert(not integers.empty());

    auto start = integers.cbegin();
    auto current_sum = *start;
    for (auto i = start + 1; i != integers.cend(); ++i) {
        while (current_sum > SUM and start < i - 1) {
            current_sum -= *start++;
        }

        if (current_sum == SUM) {
            return std::make_pair(start - integers.cbegin(), i - integers.cbegin() - 1);
        }

        current_sum += *i;
    }

    return NOT_FOUND;
}
开发者ID:yyang-even,项目名称:algorithms,代码行数:20,代码来源:subarray_with_given_sum.cpp

示例14: getSizeInBits

ConstantInt* Variables::getSizeInBits(Type *type) {
  ConstantInt *size = NULL;
  ArrayType *arrayType = dyn_cast<ArrayType>(type);
  switch (arrayType->getElementType()->getTypeID()) {
  case Type::FloatTyID: {
    int isize = arrayType->getNumElements() * 32;
    size = getInt64(isize);
    break;
  }
  case Type::DoubleTyID: {
    int isize = arrayType->getNumElements() * 64;
    size = getInt64(isize);
    break;
  }
  default:
    errs() << "WARNING: Unhandled type @ getSizeInBits\n";
    exit(1);
  }
  return size;
}
开发者ID:Sumith1896,项目名称:precimonious,代码行数:20,代码来源:Variables.cpp

示例15: switch

void ArrayUtils::retrieveLength(ArrayType const& _arrayType) const
{
	if (!_arrayType.isDynamicallySized())
		m_context << _arrayType.getLength();
	else
	{
		m_context << eth::Instruction::DUP1;
		switch (_arrayType.getLocation())
		{
		case ArrayType::Location::CallData:
			// length is stored on the stack
			break;
		case ArrayType::Location::Memory:
			m_context << eth::Instruction::MLOAD;
			break;
		case ArrayType::Location::Storage:
			m_context << eth::Instruction::SLOAD;
			break;
		}
	}
}
开发者ID:gluk256,项目名称:cpp-ethereum,代码行数:21,代码来源:ArrayUtils.cpp


注:本文中的ArrayType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。