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


C++ APSInt::toString方法代码示例

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


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

示例1: checkWidth

void LiteralAnalyser::checkWidth(int availableWidth, const Limit* L, const Expr* Right, const char* tname) {
    APSInt Result = checkLiterals(Right);

    assert(Result.isSigned() && "TEMP FOR NOW");
    int64_t value = Result.getSExtValue();
    bool overflow = false;
    if (Result.isNegative()) {
        const int64_t limit = L->minVal;
        if (value < limit) overflow = true;
    } else {
        if (availableWidth == 64) {
            // NOTE: assume for now value always fits in uint64
        } else {
            const int64_t limit = (int64_t)L->maxVal;
            if (value > limit) overflow = true;
        }
    }
    //fprintf(stderr, "VAL=%lld  width=%d signed=%d\n", value, availableWidth, Result.isSigned());
    if (overflow) {
        SmallString<20> ss;
        Result.toString(ss, 10, true);

        Diags.Report(Right->getLocStart(), diag::err_literal_outofbounds)
                << tname << L->minStr << L->maxStr << ss << Right->getSourceRange();
    }
}
开发者ID:,项目名称:,代码行数:26,代码来源:

示例2: checkLiterals

APSInt LiteralAnalyser::checkLiterals(const Expr* Right) {
    if (Right->getCTC() == CTC_NONE) return APSInt(64, false);

    APSInt result(64, false);

    switch (Right->getKind()) {
    case EXPR_INTEGER_LITERAL:
        return checkIntegerLiterals(Right);
    case EXPR_FLOAT_LITERAL:
    case EXPR_BOOL_LITERAL:
        break;
    case EXPR_CHAR_LITERAL:
    {
        const CharacterLiteral* C = cast<CharacterLiteral>(Right);
        result = APInt(64, C->getValue(), true);
        break;
    }
    case EXPR_STRING_LITERAL:
        break;
    case EXPR_NIL:
        break;
    case EXPR_IDENTIFIER:
        return checkDecl(cast<IdentifierExpr>(Right)->getDecl());
    case EXPR_TYPE:
    case EXPR_CALL:
    case EXPR_INITLIST:
        break;
    case EXPR_DESIGNATOR_INIT:
        assert(0 && "TODO");
        break;
    case EXPR_BINOP:
        return checkBinaryLiterals(Right);
    case EXPR_CONDOP:
        break;
    case EXPR_UNARYOP:
        return checkUnaryLiterals(Right);
    case EXPR_BUILTIN:
    {
        const BuiltinExpr* B = cast<BuiltinExpr>(Right);
        return B->getValue();
    }
    case EXPR_ARRAYSUBSCRIPT:
        return checkArraySubscript(Right);
    case EXPR_MEMBER:
    {
        // Q: is this correct for Struct.Member?
        const MemberExpr* M = cast<MemberExpr>(Right);
        return checkDecl(M->getDecl());
    }
    case EXPR_PAREN:
    {
        const ParenExpr* P = cast<ParenExpr>(Right);
        return checkLiterals(P->getExpr());
    }
    case EXPR_BITOFFSET:
        assert(0 && "TODO");
        break;
    case EXPR_CAST:
    {
        // a cast may change the value without warning
        const ExplicitCastExpr* E = cast<ExplicitCastExpr>(Right);
        APSInt Result = checkLiterals(E->getInner());
        SmallString<20> ss;
        Result.toString(ss, 10, true);
        fprintf(stderr, "Original %s\n", ss.c_str());
        return truncateLiteral(E->getDestType(), Right, Result);
    }
    }
    return result;
}
开发者ID:,项目名称:,代码行数:70,代码来源:


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