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


C++ Errors::Swallowed方法代码示例

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


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

示例1: Unify

bool TypeInference::Unify(Tree *t1, Tree *t2, unify_mode mode)
// ----------------------------------------------------------------------------
//   Unify two type forms
// ----------------------------------------------------------------------------
//  A type form in XL can be:
//   - A type name              integer
//   - A generic type name      #ABC
//   - A litteral value         0       1.5             "Hello"
//   - A range of values        0..4    1.3..8.9        "A".."Z"
//   - A union of types         0,3,5   integer|real
//   - A block for precedence   (real)
//   - A rewrite specifier      integer => real
//   - The type of a pattern    type (X:integer, Y:integer)
//
// Unification happens almost as "usual" for Algorithm W, except for how
// we deal with XL "shape-based" type constructors, e.g. type(P)
{
    // Make sure we have the canonical form
    t1 = Base(t1);
    t2 = Base(t2);
    if (t1 == t2)
        return true;            // Already unified

    // Strip out blocks in type specification
    if (Block *b1 = t1->AsBlock())
        if (Unify(b1->child, t2))
            return Join(b1, t2);
    if (Block *b2 = t2->AsBlock())
        if (Unify(t1, b2->child))
            return Join(t1, b2);

    // Lookup type names, replace them with their value
    t1 = LookupTypeName(t1);
    t2 = LookupTypeName(t2);
    if (t1 == t2)
        return true;            // This may have been enough for unifiation

    // Special case of constants
    if (t1->IsConstant())
        if (Name *t2n = t2->AsName())
            return JoinConstant(t1, t2n);
    if (t2->IsConstant())
        if (Name *t1n = t1->AsName())
            return JoinConstant(t2, t1n);

    // If either is a generic, unify with the other
    if (IsGeneric(t1))
        return Join(t1, t2);
    if (IsGeneric(t2))
        return Join(t1, t2);

    // Check if t1 is one of the infix constructor types
    if (Infix *i1 = t1->AsInfix())
    {
        // Function types: Unifies only with a function type
        if (i1->name == "=>")
        {
            if (Infix *i2 = t2->AsInfix())
                if (i2->name == "=>")
                    return
                        Unify(i1->left, i2->left, i1, i2) &&
                        Unify(i1->right, i2->right, i1, i2);
            
            return TypeError(i1, t2);
        }
        
        // Union types: Unify with either side
        if (i1->name == "|" || i1->name == ",")
        {
            if (mode != DECLARATION)
            {
                Errors errors;
                if (Unify(i1->left, t2))
                    return true;
                errors.Swallowed();
                if (Unify(i1->right, t2))
                    return true;
            }
            return TypeError(t1, t2);
        }
        
        Ooops("Malformed type definition $2 for $1", left, i1);
        return false;
    }

    if (Infix *i2 = t2->AsInfix())
    {
        // Union types: Unify with either side
        if (i2->name == "|" || i2->name == ",")
        {
            Errors errors;
            if (Unify(t1, i2->left))
                return true;
            errors.Swallowed();
            if (Unify(t1, i2->right))
                return true;
            return false;
        }

        Ooops("Malformed type definition $2 for $1", right, i2);
//.........这里部分代码省略.........
开发者ID:trustifier,项目名称:xlr,代码行数:101,代码来源:types.cpp


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