本文整理汇总了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();
}
}
示例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;
}