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


C++ ArrayType::hasFixedLength方法代码示例

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


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

示例1:

int32_t
sp::ComputeSizeOfType(ReportingContext &cc, Type *aType, size_t level)
{
  if (aType->isUnresolvedTypedef()) {
    cc.report(rmsg::recursive_type);
    return 0;
  }
  if (!aType->isArray()) {
    cc.report(rmsg::sizeof_needs_array);
    return 0;
  }

  ArrayType *type = aType->toArray();
  for (size_t i = 1; i <= level; i++) {
    if (!type->contained()->isArray()) {
      cc.report(rmsg::sizeof_invalid_rank);
      return 0;
    }
    type = type->contained()->toArray();
  }

  if (!type->hasFixedLength()) {
    cc.report(rmsg::sizeof_indeterminate);
    return 0;
  }

  return type->fixedLength();
}
开发者ID:collinsmith,项目名称:sourcepawn,代码行数:28,代码来源:types.cpp

示例2: AreFunctionTypesEqual

// Since const is transitive, we require it to be threaded through type
// equivalence tests.
bool
sp::AreTypesEquivalent(Type *a, Type *b, Qualifiers context)
{
  Qualifiers qa = (a->qualifiers() | context);
  Qualifiers qb = (b->qualifiers() | context);
  if (qa != qb)
    return false;

  a = a->canonical();
  b = b->canonical();
  if (a == b)
    return true;

  switch (a->canonicalKind()) {
    case Type::Kind::Primitive:
      // Either |b| is not primitive, or they should not have the same
      // primitive type since each type is a singleton.
      assert(!b->isPrimitive() || a->primitive() != b->primitive());
      return false;
    case Type::Kind::Function:
    {
      if (!b->isFunction())
        return false;

      // const is not transitive through function signatures.
      return AreFunctionTypesEqual(a->toFunction(), b->toFunction());
    }
    case Type::Kind::Array:
    {
      if (!b->isArray())
        return false;

      ArrayType *aa = a->toArray();
      ArrayType *ba = b->toArray();
      while (true) {
        // Both arrays must be either dynamic or have the same fixed size.
        if (aa->hasFixedLength() != ba->hasFixedLength())
          return false;
        if (aa->hasFixedLength() && aa->fixedLength() != ba->fixedLength())
          return false;

        // Both contained types must be the same type.
        Type *innerA = aa->contained();
        Type *innerB = ba->contained();
        if (innerA->isArray() != innerB->isArray())
          return false;
        if (!innerA->isArray()) {
          // const is transitive through arrays.
          if (!AreTypesEquivalent(innerA, innerB, context))
            return false;

          // If neither contained type is an array, we're done.
          break;
        }

        // Re-check qualifiers.
        Qualifiers qa = (innerA->qualifiers() | context);
        Qualifiers qb = (innerB->qualifiers() | context);
        if (qa != qb)
          return false;
      }
      return true;
    }
    // These types have unique instances.
    case Type::Kind::Void:
    case Type::Kind::Unchecked:
    case Type::Kind::MetaFunction:
    // These types are named and must have the same identity.
    case Type::Kind::Struct:
    case Type::Kind::Typeset:
    case Type::Kind::Enum:
      // Handled by a == b check earlier.
      return false;
    default:
      // Should not get Unresolvable, Typedef, or Qualifier here.
      assert(false);
      return false;
  }
}
开发者ID:collinsmith,项目名称:sourcepawn,代码行数:81,代码来源:types.cpp


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