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


C++ typet::to_string方法代码示例

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


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

示例1: join_types

/**
 * Return the smallest type that both t1 and t2 can be cast to without losing
 * information.
 *
 * e.g.
 *
 * join_types(unsignedbv_typet(32), unsignedbv_typet(16)) = unsignedbv_typet(32)
 * join_types(signedbv_typet(16), unsignedbv_typet(16)) = signedbv_typet(17)
 * join_types(signedbv_typet(32), signedbv_typet(32)) = signedbv_typet(32)
 */
typet join_types(const typet &t1, const typet &t2) {
  // Handle the simple case first...
  if (t1 == t2) {
    return t1;
  }

  // OK, they're not the same type.  Are they both bitvectors?
  if (is_bitvector(t1) && is_bitvector(t2)) {
    // They are.  That makes things easy!  There are three cases to consider:
    // both types are unsigned, both types are signed or there's one of each.

    bitvector_typet b1 = to_bitvector_type(t1);
    bitvector_typet b2 = to_bitvector_type(t2);

    if (is_unsigned(b1) && is_unsigned(b2))
    {
      // We just need to take the max of their widths.
      std::size_t width = std::max(b1.get_width(), b2.get_width());
      return unsignedbv_typet(width);
    }
    else if(is_signed(b1) && is_signed(b2))
    {
      // Again, just need to take the max of the widths.
      std::size_t width = std::max(b1.get_width(), b2.get_width());
      return signedbv_typet(width);
    }
    else
    {
      // This is the (slightly) tricky case.  If we have a signed and an
      // unsigned type, we're going to return a signed type.  And to cast
      // an unsigned type to a signed type, we need the signed type to be
      // at least one bit wider than the unsigned type we're casting from.
      std::size_t signed_width = is_signed(t1) ? b1.get_width() :
                                                 b2.get_width();
      std::size_t unsigned_width = is_signed(t1) ? b2.get_width() :
                                                   b1.get_width();
      //unsigned_width++;

      std::size_t width = std::max(signed_width, unsigned_width);

      return signedbv_typet(width);
    }
  }

  std::cerr << "Tried to join types: "
            << t1.to_string() << " and " << t2.to_string()
            << std::endl;
  assert(!"Couldn't join types");
}
开发者ID:Dthird,项目名称:CBMC,代码行数:59,代码来源:util.cpp


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