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


C++ TypePtr::couldBe方法代码示例

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


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

示例1: Inferred

/* We have inferred type1 and type2 as the actual types for the same
   expression.
   Check that the types are compatible (it cant be both a string and
   an integer, for example), and return the combined type. If they
   are not compatible, return a null pointer.
 */
TypePtr Type::Inferred(AnalysisResultConstPtr ar,
                       TypePtr type1, TypePtr type2) {
  if (!type1) return type2;
  if (!type2) return type1;
  KindOf k1 = type1->m_kindOf;
  KindOf k2 = type2->m_kindOf;

  if (k1 == k2) {
    return k1 == KindOfObject ?
      Type::InferredObject(ar, type1, type2) : type1;
  }

  // If one set is a subset of the other, return the subset.
  if ((k1 & k2) == k1) return type1;
  if ((k1 & k2) == k2) return type2;

  // If one type must be numeric and the other might be, then assume numeric
  if (type1->mustBe(KindOfNumeric) && type2->couldBe(KindOfNumeric)) {
    return type1;
  }
  if (type2->mustBe(KindOfNumeric) && type1->couldBe(KindOfNumeric)) {
    return type2;
  }

  // Otherwise, take the intersection
  int resultKind = type1->m_kindOf & type2->m_kindOf;
  if (resultKind == KindOfObject) {
    return Type::InferredObject(ar, type1, type2);
  }
  return resultKind ? GetType(resultKind) : TypePtr();
}
开发者ID:hashaash,项目名称:hiphop-php,代码行数:37,代码来源:type.cpp

示例2: Inferred

/* We have inferred type1 and type2 as the actual types for the same
   expression.
   Check that the types are compatible (it cant be both a string and
   an integer, for example), and return the combined type. If they
   are not compatible, return a null pointer.
 */
TypePtr Type::Inferred(AnalysisResultConstPtr ar,
                       TypePtr type1, TypePtr type2) {
  if (!type1) return type2;
  if (!type2) return type1;
  KindOf k1 = type1->m_kindOf;
  KindOf k2 = type2->m_kindOf;

  if (k1 == k2) return type1;

  // If one set is a subset of the other, return the subset.
  if ((k1 & k2) == k1) return type1;
  if ((k1 & k2) == k2) return type2;

  // If one type must be numeric and the other might be, then assume numeric
  if (type1->mustBe(KindOfNumeric) && type2->couldBe(KindOfNumeric))
    return type1;
  if (type2->mustBe(KindOfNumeric) && type1->couldBe(KindOfNumeric))
    return type2;

  // Otherwise, take the intersection
  int resultKind = type1->m_kindOf & type2->m_kindOf;
  std::string resultName = "";

  if (resultKind & KindOfObject) {
    // if they're the same, or we don't know one's name, then use
    // the other
    if (type1->m_name == type2->m_name || type1->m_name.empty()) {
      resultName = type2->m_name;
    } else if (type2->m_name.empty()) {
      resultName = type1->m_name;
    } else {
      // take the subclass
      ClassScopePtr cls1 = ar->findClass(type1->m_name);
        ClassScopePtr cls2 = ar->findClass(type2->m_name);
      if (cls1 && !cls1->isRedeclaring()
          && cls1->derivesFrom(ar, type2->m_name, true, false)) {
        resultName = type1->m_name;
      } else if (cls2 && !cls2->isRedeclaring()
                 && cls2->derivesFrom(ar, type1->m_name, true, false)) {
        resultName = type2->m_name;
      } else {
        resultKind &= ~KindOfObject;
      }
    }
  }

  if (resultKind)
    return TypePtr(new Type((KindOf)resultKind, resultName));
  else
    return TypePtr();
}
开发者ID:activeingredient,项目名称:hiphop-php,代码行数:57,代码来源:type.cpp


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