2008-02-01 03:34:24 +08:00
|
|
|
//= RValues.cpp - Abstract RValues for Path-Sens. Value Tracking -*- C++ -*-==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This files defines RValue, LValue, and NonLValue, classes that represent
|
|
|
|
// abstract r-values for use with path-sensitive value tracking.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-15 01:30:51 +08:00
|
|
|
#include "clang/Analysis/PathSensitive/RValues.h"
|
2008-02-01 03:34:24 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using llvm::dyn_cast;
|
|
|
|
using llvm::cast;
|
|
|
|
using llvm::APSInt;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SymbolManager.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
SymbolID SymbolManager::getSymbol(ParmVarDecl* D) {
|
2008-02-07 13:48:01 +08:00
|
|
|
SymbolID& X = DataToSymbol[getKey(D)];
|
2008-02-01 03:34:24 +08:00
|
|
|
|
|
|
|
if (!X.isInitialized()) {
|
|
|
|
X = SymbolToData.size();
|
2008-02-07 13:48:01 +08:00
|
|
|
SymbolToData.push_back(SymbolDataParmVar(D));
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2008-02-07 13:48:01 +08:00
|
|
|
SymbolID SymbolManager::getContentsOfSymbol(SymbolID sym) {
|
|
|
|
SymbolID& X = DataToSymbol[getKey(sym)];
|
|
|
|
|
|
|
|
if (!X.isInitialized()) {
|
|
|
|
X = SymbolToData.size();
|
|
|
|
SymbolToData.push_back(SymbolDataContentsOf(sym));
|
|
|
|
}
|
|
|
|
|
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2008-02-07 01:32:17 +08:00
|
|
|
QualType SymbolData::getType() const {
|
|
|
|
switch (getKind()) {
|
|
|
|
default:
|
|
|
|
assert (false && "getType() not implemented for this symbol.");
|
|
|
|
|
|
|
|
case ParmKind:
|
2008-02-07 13:48:01 +08:00
|
|
|
return cast<SymbolDataParmVar>(this)->getDecl()->getType();
|
|
|
|
|
2008-02-07 01:32:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
SymbolManager::SymbolManager() {}
|
|
|
|
SymbolManager::~SymbolManager() {}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-02-06 05:32:43 +08:00
|
|
|
// Values and ValueManager.
|
2008-02-01 03:34:24 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
ValueManager::~ValueManager() {
|
|
|
|
// Note that the dstor for the contents of APSIntSet will never be called,
|
|
|
|
// so we iterate over the set and invoke the dstor for each APSInt. This
|
|
|
|
// frees an aux. memory allocated to represent very large constants.
|
|
|
|
for (APSIntSetTy::iterator I=APSIntSet.begin(), E=APSIntSet.end(); I!=E; ++I)
|
|
|
|
I->getValue().~APSInt();
|
|
|
|
}
|
|
|
|
|
2008-02-06 05:32:43 +08:00
|
|
|
const APSInt& ValueManager::getValue(const APSInt& X) {
|
2008-02-01 03:34:24 +08:00
|
|
|
llvm::FoldingSetNodeID ID;
|
|
|
|
void* InsertPos;
|
|
|
|
typedef llvm::FoldingSetNodeWrapper<APSInt> FoldNodeTy;
|
|
|
|
|
|
|
|
X.Profile(ID);
|
|
|
|
FoldNodeTy* P = APSIntSet.FindNodeOrInsertPos(ID, InsertPos);
|
|
|
|
|
|
|
|
if (!P) {
|
|
|
|
P = (FoldNodeTy*) BPAlloc.Allocate<FoldNodeTy>();
|
|
|
|
new (P) FoldNodeTy(X);
|
|
|
|
APSIntSet.InsertNode(P, InsertPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *P;
|
|
|
|
}
|
|
|
|
|
2008-02-06 05:32:43 +08:00
|
|
|
const APSInt& ValueManager::getValue(uint64_t X, unsigned BitWidth,
|
|
|
|
bool isUnsigned) {
|
2008-02-01 03:34:24 +08:00
|
|
|
APSInt V(BitWidth, isUnsigned);
|
|
|
|
V = X;
|
|
|
|
return getValue(V);
|
|
|
|
}
|
|
|
|
|
2008-02-06 05:32:43 +08:00
|
|
|
const APSInt& ValueManager::getValue(uint64_t X, QualType T,
|
|
|
|
SourceLocation Loc) {
|
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
unsigned bits = Ctx.getTypeSize(T, Loc);
|
|
|
|
APSInt V(bits, T->isUnsignedIntegerType());
|
|
|
|
V = X;
|
|
|
|
return getValue(V);
|
|
|
|
}
|
|
|
|
|
2008-02-06 05:32:43 +08:00
|
|
|
const SymIntConstraint&
|
|
|
|
ValueManager::getConstraint(SymbolID sym, BinaryOperator::Opcode Op,
|
|
|
|
const llvm::APSInt& V) {
|
|
|
|
|
|
|
|
llvm::FoldingSetNodeID ID;
|
|
|
|
SymIntConstraint::Profile(ID, sym, Op, V);
|
|
|
|
void* InsertPos;
|
|
|
|
|
|
|
|
SymIntConstraint* C = SymIntCSet.FindNodeOrInsertPos(ID, InsertPos);
|
|
|
|
|
|
|
|
if (!C) {
|
|
|
|
C = (SymIntConstraint*) BPAlloc.Allocate<SymIntConstraint>();
|
|
|
|
new (C) SymIntConstraint(sym, Op, V);
|
|
|
|
SymIntCSet.InsertNode(C, InsertPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *C;
|
|
|
|
}
|
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2008-02-01 14:36:40 +08:00
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Transfer function dispatch for Non-LValues.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static const
|
|
|
|
llvm::APSInt& EvaluateAPSInt(ValueManager& ValMgr, BinaryOperator::Opcode Op,
|
|
|
|
const llvm::APSInt& V1, const llvm::APSInt& V2) {
|
|
|
|
|
|
|
|
switch (Op) {
|
|
|
|
default:
|
|
|
|
assert (false && "Invalid Opcode.");
|
|
|
|
|
|
|
|
case BinaryOperator::Mul:
|
|
|
|
return ValMgr.getValue( V1 * V2 );
|
|
|
|
|
|
|
|
case BinaryOperator::Div:
|
|
|
|
return ValMgr.getValue( V1 / V2 );
|
|
|
|
|
|
|
|
case BinaryOperator::Rem:
|
|
|
|
return ValMgr.getValue( V1 % V2 );
|
|
|
|
|
|
|
|
case BinaryOperator::Add:
|
|
|
|
return ValMgr.getValue( V1 + V2 );
|
|
|
|
|
|
|
|
case BinaryOperator::Sub:
|
|
|
|
return ValMgr.getValue( V1 - V2 );
|
|
|
|
|
|
|
|
case BinaryOperator::Shl:
|
2008-02-08 15:14:58 +08:00
|
|
|
return ValMgr.getValue( V1.operator<<( (unsigned) V2.getZExtValue() ));
|
2008-02-07 06:50:25 +08:00
|
|
|
|
|
|
|
case BinaryOperator::Shr:
|
2008-02-08 15:14:58 +08:00
|
|
|
return ValMgr.getValue( V1.operator>>( (unsigned) V2.getZExtValue() ));
|
2008-02-07 06:50:25 +08:00
|
|
|
|
|
|
|
case BinaryOperator::LT:
|
|
|
|
return ValMgr.getTruthValue( V1 < V2 );
|
|
|
|
|
|
|
|
case BinaryOperator::GT:
|
|
|
|
return ValMgr.getTruthValue( V1 > V2 );
|
|
|
|
|
|
|
|
case BinaryOperator::LE:
|
|
|
|
return ValMgr.getTruthValue( V1 <= V2 );
|
|
|
|
|
|
|
|
case BinaryOperator::GE:
|
|
|
|
return ValMgr.getTruthValue( V1 >= V2 );
|
|
|
|
|
|
|
|
case BinaryOperator::EQ:
|
|
|
|
return ValMgr.getTruthValue( V1 == V2 );
|
|
|
|
|
|
|
|
case BinaryOperator::NE:
|
|
|
|
return ValMgr.getTruthValue( V1 != V2 );
|
|
|
|
|
|
|
|
// Note: LAnd, LOr, Comma are handled specially by higher-level logic.
|
|
|
|
|
|
|
|
case BinaryOperator::And:
|
|
|
|
return ValMgr.getValue( V1 & V2 );
|
|
|
|
|
|
|
|
case BinaryOperator::Or:
|
|
|
|
return ValMgr.getValue( V1 | V2 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nonlval::ConcreteInt
|
|
|
|
nonlval::ConcreteInt::EvalBinaryOp(ValueManager& ValMgr,
|
|
|
|
BinaryOperator::Opcode Op,
|
|
|
|
const nonlval::ConcreteInt& RHS) const {
|
|
|
|
|
|
|
|
return EvaluateAPSInt(ValMgr, Op, getValue(), RHS.getValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Bitwise-Complement.
|
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
nonlval::ConcreteInt
|
|
|
|
nonlval::ConcreteInt::EvalComplement(ValueManager& ValMgr) const {
|
|
|
|
return ValMgr.getValue(~getValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unary Minus.
|
2008-02-01 14:36:40 +08:00
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
nonlval::ConcreteInt
|
|
|
|
nonlval::ConcreteInt::EvalMinus(ValueManager& ValMgr, UnaryOperator* U) const {
|
|
|
|
assert (U->getType() == U->getSubExpr()->getType());
|
|
|
|
assert (U->getType()->isIntegerType());
|
|
|
|
return ValMgr.getValue(-getValue());
|
2008-02-05 00:58:30 +08:00
|
|
|
}
|
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Transfer function dispatch for LValues.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-02-05 00:58:30 +08:00
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
lval::ConcreteInt
|
|
|
|
lval::ConcreteInt::EvalBinaryOp(ValueManager& ValMgr,
|
|
|
|
BinaryOperator::Opcode Op,
|
|
|
|
const lval::ConcreteInt& RHS) const {
|
|
|
|
|
|
|
|
assert (Op == BinaryOperator::Add || Op == BinaryOperator::Sub ||
|
|
|
|
(Op >= BinaryOperator::LT && Op <= BinaryOperator::NE));
|
|
|
|
|
|
|
|
return EvaluateAPSInt(ValMgr, Op, getValue(), RHS.getValue());
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NonLValue LValue::EQ(ValueManager& ValMgr, const LValue& RHS) const {
|
|
|
|
switch (getSubKind()) {
|
|
|
|
default:
|
|
|
|
assert(false && "EQ not implemented for this LValue.");
|
2008-02-08 10:57:34 +08:00
|
|
|
return cast<NonLValue>(UnknownVal());
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
case lval::ConcreteIntKind:
|
|
|
|
if (isa<lval::ConcreteInt>(RHS)) {
|
|
|
|
bool b = cast<lval::ConcreteInt>(this)->getValue() ==
|
2008-02-07 06:50:25 +08:00
|
|
|
cast<lval::ConcreteInt>(RHS).getValue();
|
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
return NonLValue::GetIntTruthValue(ValMgr, b);
|
|
|
|
}
|
|
|
|
else if (isa<lval::SymbolVal>(RHS)) {
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
const SymIntConstraint& C =
|
2008-02-07 06:50:25 +08:00
|
|
|
ValMgr.getConstraint(cast<lval::SymbolVal>(RHS).getSymbol(),
|
|
|
|
BinaryOperator::EQ,
|
|
|
|
cast<lval::ConcreteInt>(this)->getValue());
|
2008-02-06 07:08:41 +08:00
|
|
|
|
|
|
|
return nonlval::SymIntConstraintVal(C);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
case lval::SymbolValKind: {
|
|
|
|
if (isa<lval::ConcreteInt>(RHS)) {
|
|
|
|
|
|
|
|
const SymIntConstraint& C =
|
2008-02-06 07:08:41 +08:00
|
|
|
ValMgr.getConstraint(cast<lval::SymbolVal>(this)->getSymbol(),
|
|
|
|
BinaryOperator::EQ,
|
|
|
|
cast<lval::ConcreteInt>(RHS).getValue());
|
2008-02-07 06:50:25 +08:00
|
|
|
|
|
|
|
return nonlval::SymIntConstraintVal(C);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (!isa<lval::SymbolVal>(RHS) && "FIXME: Implement unification.");
|
2008-02-06 07:08:41 +08:00
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
break;
|
2008-02-06 07:08:41 +08:00
|
|
|
}
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
case lval::DeclValKind:
|
2008-02-06 07:08:41 +08:00
|
|
|
if (isa<lval::DeclVal>(RHS)) {
|
|
|
|
bool b = cast<lval::DeclVal>(*this) == cast<lval::DeclVal>(RHS);
|
|
|
|
return NonLValue::GetIntTruthValue(ValMgr, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
2008-02-06 07:08:41 +08:00
|
|
|
|
|
|
|
return NonLValue::GetIntTruthValue(ValMgr, false);
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NonLValue LValue::NE(ValueManager& ValMgr, const LValue& RHS) const {
|
|
|
|
switch (getSubKind()) {
|
|
|
|
default:
|
2008-02-06 07:08:41 +08:00
|
|
|
assert(false && "NE not implemented for this LValue.");
|
2008-02-08 10:57:34 +08:00
|
|
|
return cast<NonLValue>(UnknownVal());
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
case lval::ConcreteIntKind:
|
|
|
|
if (isa<lval::ConcreteInt>(RHS)) {
|
|
|
|
bool b = cast<lval::ConcreteInt>(this)->getValue() !=
|
2008-02-07 06:50:25 +08:00
|
|
|
cast<lval::ConcreteInt>(RHS).getValue();
|
2008-02-06 07:08:41 +08:00
|
|
|
|
|
|
|
return NonLValue::GetIntTruthValue(ValMgr, b);
|
|
|
|
}
|
|
|
|
else if (isa<lval::SymbolVal>(RHS)) {
|
|
|
|
|
|
|
|
const SymIntConstraint& C =
|
|
|
|
ValMgr.getConstraint(cast<lval::SymbolVal>(RHS).getSymbol(),
|
|
|
|
BinaryOperator::NE,
|
|
|
|
cast<lval::ConcreteInt>(this)->getValue());
|
|
|
|
|
|
|
|
return nonlval::SymIntConstraintVal(C);
|
|
|
|
}
|
2008-02-01 14:36:40 +08:00
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
break;
|
2008-02-01 14:36:40 +08:00
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
case lval::SymbolValKind: {
|
|
|
|
if (isa<lval::ConcreteInt>(RHS)) {
|
|
|
|
|
|
|
|
const SymIntConstraint& C =
|
|
|
|
ValMgr.getConstraint(cast<lval::SymbolVal>(this)->getSymbol(),
|
|
|
|
BinaryOperator::NE,
|
|
|
|
cast<lval::ConcreteInt>(RHS).getValue());
|
|
|
|
|
|
|
|
return nonlval::SymIntConstraintVal(C);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (!isa<lval::SymbolVal>(RHS) && "FIXME: Implement sym !=.");
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case lval::DeclValKind:
|
|
|
|
if (isa<lval::DeclVal>(RHS)) {
|
|
|
|
bool b = cast<lval::DeclVal>(*this) == cast<lval::DeclVal>(RHS);
|
|
|
|
return NonLValue::GetIntTruthValue(ValMgr, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
2008-02-06 07:08:41 +08:00
|
|
|
|
|
|
|
return NonLValue::GetIntTruthValue(ValMgr, true);
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Utility methods for constructing Non-LValues.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
NonLValue NonLValue::GetValue(ValueManager& ValMgr, uint64_t X, QualType T,
|
|
|
|
SourceLocation Loc) {
|
|
|
|
|
2008-02-06 05:52:21 +08:00
|
|
|
return nonlval::ConcreteInt(ValMgr.getValue(X, T, Loc));
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NonLValue NonLValue::GetValue(ValueManager& ValMgr, IntegerLiteral* I) {
|
2008-02-06 05:52:21 +08:00
|
|
|
return nonlval::ConcreteInt(ValMgr.getValue(APSInt(I->getValue(),
|
|
|
|
I->getType()->isUnsignedIntegerType())));
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
NonLValue NonLValue::GetIntTruthValue(ValueManager& ValMgr, bool b) {
|
|
|
|
return nonlval::ConcreteInt(ValMgr.getTruthValue(b));
|
|
|
|
}
|
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
RValue RValue::GetSymbolValue(SymbolManager& SymMgr, ParmVarDecl* D) {
|
|
|
|
QualType T = D->getType();
|
|
|
|
|
|
|
|
if (T->isPointerType() || T->isReferenceType())
|
2008-02-06 05:52:21 +08:00
|
|
|
return lval::SymbolVal(SymMgr.getSymbol(D));
|
2008-02-01 03:34:24 +08:00
|
|
|
else
|
2008-02-06 05:52:21 +08:00
|
|
|
return nonlval::SymbolVal(SymMgr.getSymbol(D));
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
2008-02-13 05:37:56 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Utility methods for constructing LValues.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
LValue LValue::GetValue(AddrLabelExpr* E) {
|
|
|
|
return lval::GotoLabel(E->getLabel());
|
2008-02-07 09:08:27 +08:00
|
|
|
}
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Pretty-Printing.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-13 05:37:56 +08:00
|
|
|
void RValue::print() const {
|
|
|
|
print(*llvm::cerr.stream());
|
|
|
|
}
|
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
void RValue::print(std::ostream& Out) const {
|
|
|
|
switch (getBaseKind()) {
|
2008-02-08 11:02:48 +08:00
|
|
|
case UnknownKind:
|
2008-02-01 03:34:24 +08:00
|
|
|
Out << "Invalid";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NonLValueKind:
|
|
|
|
cast<NonLValue>(this)->print(Out);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LValueKind:
|
|
|
|
cast<LValue>(this)->print(Out);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UninitializedKind:
|
|
|
|
Out << "Uninitialized";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert (false && "Invalid RValue.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
static void printOpcode(std::ostream& Out, BinaryOperator::Opcode Op) {
|
2008-02-07 23:20:13 +08:00
|
|
|
switch (Op) {
|
|
|
|
case BinaryOperator::Add: Out << "+" ; break;
|
|
|
|
case BinaryOperator::Sub: Out << "-" ; break;
|
2008-02-06 07:08:41 +08:00
|
|
|
case BinaryOperator::EQ: Out << "=="; break;
|
|
|
|
case BinaryOperator::NE: Out << "!="; break;
|
|
|
|
default: assert(false && "Not yet implemented.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
void NonLValue::print(std::ostream& Out) const {
|
|
|
|
switch (getSubKind()) {
|
2008-02-06 05:52:21 +08:00
|
|
|
case nonlval::ConcreteIntKind:
|
|
|
|
Out << cast<nonlval::ConcreteInt>(this)->getValue().toString();
|
2008-02-07 06:50:25 +08:00
|
|
|
|
|
|
|
if (cast<nonlval::ConcreteInt>(this)->getValue().isUnsigned())
|
|
|
|
Out << 'U';
|
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
break;
|
|
|
|
|
2008-02-06 05:52:21 +08:00
|
|
|
case nonlval::SymbolValKind:
|
2008-02-06 07:08:41 +08:00
|
|
|
Out << '$' << cast<nonlval::SymbolVal>(this)->getSymbol();
|
2008-02-01 03:34:24 +08:00
|
|
|
break;
|
2008-02-06 07:08:41 +08:00
|
|
|
|
|
|
|
case nonlval::SymIntConstraintValKind: {
|
|
|
|
const nonlval::SymIntConstraintVal& C =
|
|
|
|
*cast<nonlval::SymIntConstraintVal>(this);
|
|
|
|
|
|
|
|
Out << '$' << C.getConstraint().getSymbol() << ' ';
|
|
|
|
printOpcode(Out, C.getConstraint().getOpcode());
|
|
|
|
Out << ' ' << C.getConstraint().getInt().toString();
|
2008-02-07 06:50:25 +08:00
|
|
|
|
|
|
|
if (C.getConstraint().getInt().isUnsigned())
|
|
|
|
Out << 'U';
|
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-02-01 03:34:24 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
assert (false && "Pretty-printed not implemented for this NonLValue.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-07 13:48:01 +08:00
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
void LValue::print(std::ostream& Out) const {
|
2008-02-01 14:36:40 +08:00
|
|
|
switch (getSubKind()) {
|
2008-02-06 05:52:21 +08:00
|
|
|
case lval::ConcreteIntKind:
|
|
|
|
Out << cast<lval::ConcreteInt>(this)->getValue().toString()
|
2008-02-01 14:36:40 +08:00
|
|
|
<< " (LValue)";
|
|
|
|
break;
|
|
|
|
|
2008-02-06 05:52:21 +08:00
|
|
|
case lval::SymbolValKind:
|
2008-02-06 07:08:41 +08:00
|
|
|
Out << '$' << cast<lval::SymbolVal>(this)->getSymbol();
|
2008-02-01 03:34:24 +08:00
|
|
|
break;
|
2008-02-13 05:37:56 +08:00
|
|
|
|
|
|
|
case lval::GotoLabelKind:
|
|
|
|
Out << "&&"
|
|
|
|
<< cast<lval::GotoLabel>(this)->getLabel()->getID()->getName();
|
|
|
|
break;
|
2008-02-06 12:31:33 +08:00
|
|
|
|
2008-02-06 05:52:21 +08:00
|
|
|
case lval::DeclValKind:
|
2008-02-01 03:34:24 +08:00
|
|
|
Out << '&'
|
2008-02-06 05:52:21 +08:00
|
|
|
<< cast<lval::DeclVal>(this)->getDecl()->getIdentifier()->getName();
|
2008-02-01 03:34:24 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert (false && "Pretty-printed not implemented for this LValue.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-02-07 13:48:01 +08:00
|
|
|
|