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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-03-06 18:40:09 +08:00
|
|
|
// This file defines RVal, LVal, and NonLVal, classes that represent
|
2008-02-01 03:34:24 +08:00
|
|
|
// 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-08-11 13:35:13 +08:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
2008-02-16 09:12:31 +08:00
|
|
|
#include "llvm/Support/Streams.h"
|
2008-02-01 03:34:24 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using llvm::dyn_cast;
|
|
|
|
using llvm::cast;
|
|
|
|
using llvm::APSInt;
|
|
|
|
|
2008-02-15 07:25:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Symbol Iteration.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
RVal::symbol_iterator RVal::symbol_begin() const {
|
2008-04-30 06:17:41 +08:00
|
|
|
|
|
|
|
// FIXME: This is a rat's nest. Cleanup.
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
if (isa<lval::SymbolVal>(this))
|
|
|
|
return (symbol_iterator) (&Data);
|
|
|
|
else if (isa<nonlval::SymbolVal>(this))
|
|
|
|
return (symbol_iterator) (&Data);
|
|
|
|
else if (isa<nonlval::SymIntConstraintVal>(this)) {
|
|
|
|
const SymIntConstraint& C =
|
|
|
|
cast<nonlval::SymIntConstraintVal>(this)->getConstraint();
|
|
|
|
|
|
|
|
return (symbol_iterator) &C.getSymbol();
|
2008-02-15 07:25:54 +08:00
|
|
|
}
|
2008-04-23 05:10:18 +08:00
|
|
|
else if (isa<nonlval::LValAsInteger>(this)) {
|
|
|
|
const nonlval::LValAsInteger& V = cast<nonlval::LValAsInteger>(*this);
|
|
|
|
return V.getPersistentLVal().symbol_begin();
|
|
|
|
}
|
2008-04-30 06:17:41 +08:00
|
|
|
else if (isa<lval::FieldOffset>(this)) {
|
|
|
|
const lval::FieldOffset& V = cast<lval::FieldOffset>(*this);
|
|
|
|
return V.getPersistentBase().symbol_begin();
|
|
|
|
}
|
2008-02-15 07:25:54 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
RVal::symbol_iterator RVal::symbol_end() const {
|
2008-02-15 07:25:54 +08:00
|
|
|
symbol_iterator X = symbol_begin();
|
|
|
|
return X ? X+1 : NULL;
|
|
|
|
}
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-07-18 23:54:51 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Useful predicates.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
bool RVal::isZeroConstant() const {
|
|
|
|
if (isa<lval::ConcreteInt>(*this))
|
|
|
|
return cast<lval::ConcreteInt>(*this).getValue() == 0;
|
|
|
|
else if (isa<nonlval::ConcreteInt>(*this))
|
|
|
|
return cast<nonlval::ConcreteInt>(*this).getValue() == 0;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-02-22 02:02:17 +08:00
|
|
|
// Transfer function dispatch for Non-LVals.
|
2008-02-07 06:50:25 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-07-18 23:59:33 +08:00
|
|
|
RVal nonlval::ConcreteInt::EvalBinOp(BasicValueFactory& BasicVals,
|
|
|
|
BinaryOperator::Opcode Op,
|
|
|
|
const nonlval::ConcreteInt& R) const {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-07-18 23:59:33 +08:00
|
|
|
const llvm::APSInt* X =
|
|
|
|
BasicVals.EvaluateAPSInt(Op, getValue(), R.getValue());
|
2008-02-29 04:32:03 +08:00
|
|
|
|
|
|
|
if (X)
|
|
|
|
return nonlval::ConcreteInt(*X);
|
|
|
|
else
|
|
|
|
return UndefinedVal();
|
2008-02-07 06:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bitwise-Complement.
|
|
|
|
|
|
|
|
nonlval::ConcreteInt
|
2008-03-08 04:13:31 +08:00
|
|
|
nonlval::ConcreteInt::EvalComplement(BasicValueFactory& BasicVals) const {
|
|
|
|
return BasicVals.getValue(~getValue());
|
2008-02-07 06:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unary Minus.
|
2008-02-01 14:36:40 +08:00
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
nonlval::ConcreteInt
|
2008-03-08 04:13:31 +08:00
|
|
|
nonlval::ConcreteInt::EvalMinus(BasicValueFactory& BasicVals, UnaryOperator* U) const {
|
2008-02-07 06:50:25 +08:00
|
|
|
assert (U->getType() == U->getSubExpr()->getType());
|
|
|
|
assert (U->getType()->isIntegerType());
|
2008-03-08 04:13:31 +08:00
|
|
|
return BasicVals.getValue(-getValue());
|
2008-02-05 00:58:30 +08:00
|
|
|
}
|
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-02-22 02:02:17 +08:00
|
|
|
// Transfer function dispatch for LVals.
|
2008-02-07 06:50:25 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-02-05 00:58:30 +08:00
|
|
|
|
2008-02-29 04:32:03 +08:00
|
|
|
RVal
|
2008-03-08 04:13:31 +08:00
|
|
|
lval::ConcreteInt::EvalBinOp(BasicValueFactory& BasicVals, BinaryOperator::Opcode Op,
|
2008-02-22 02:02:17 +08:00
|
|
|
const lval::ConcreteInt& R) const {
|
2008-02-07 06:50:25 +08:00
|
|
|
|
|
|
|
assert (Op == BinaryOperator::Add || Op == BinaryOperator::Sub ||
|
|
|
|
(Op >= BinaryOperator::LT && Op <= BinaryOperator::NE));
|
|
|
|
|
2008-03-08 04:13:31 +08:00
|
|
|
const llvm::APSInt* X = BasicVals.EvaluateAPSInt(Op, getValue(), R.getValue());
|
2008-02-29 04:32:03 +08:00
|
|
|
|
|
|
|
if (X)
|
|
|
|
return lval::ConcreteInt(*X);
|
|
|
|
else
|
|
|
|
return UndefinedVal();
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
2008-03-08 04:13:31 +08:00
|
|
|
NonLVal LVal::EQ(BasicValueFactory& BasicVals, const LVal& R) const {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
switch (getSubKind()) {
|
|
|
|
default:
|
2008-02-22 02:02:17 +08:00
|
|
|
assert(false && "EQ not implemented for this LVal.");
|
|
|
|
break;
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
case lval::ConcreteIntKind:
|
2008-02-22 02:02:17 +08:00
|
|
|
if (isa<lval::ConcreteInt>(R)) {
|
2008-02-06 07:08:41 +08:00
|
|
|
bool b = cast<lval::ConcreteInt>(this)->getValue() ==
|
2008-02-22 02:02:17 +08:00
|
|
|
cast<lval::ConcreteInt>(R).getValue();
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-03-08 04:13:31 +08:00
|
|
|
return NonLVal::MakeIntTruthVal(BasicVals, b);
|
2008-02-06 07:08:41 +08:00
|
|
|
}
|
2008-02-22 02:02:17 +08:00
|
|
|
else if (isa<lval::SymbolVal>(R)) {
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
const SymIntConstraint& C =
|
2008-03-08 04:13:31 +08:00
|
|
|
BasicVals.getConstraint(cast<lval::SymbolVal>(R).getSymbol(),
|
2008-02-22 02:02:17 +08:00
|
|
|
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: {
|
2008-02-22 02:02:17 +08:00
|
|
|
if (isa<lval::ConcreteInt>(R)) {
|
2008-02-07 06:50:25 +08:00
|
|
|
|
|
|
|
const SymIntConstraint& C =
|
2008-03-08 04:13:31 +08:00
|
|
|
BasicVals.getConstraint(cast<lval::SymbolVal>(this)->getSymbol(),
|
2008-02-22 02:02:17 +08:00
|
|
|
BinaryOperator::EQ,
|
|
|
|
cast<lval::ConcreteInt>(R).getValue());
|
2008-02-07 06:50:25 +08:00
|
|
|
|
|
|
|
return nonlval::SymIntConstraintVal(C);
|
|
|
|
}
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
assert (!isa<lval::SymbolVal>(R) && "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-22 02:02:17 +08:00
|
|
|
if (isa<lval::DeclVal>(R)) {
|
|
|
|
bool b = cast<lval::DeclVal>(*this) == cast<lval::DeclVal>(R);
|
2008-03-08 04:13:31 +08:00
|
|
|
return NonLVal::MakeIntTruthVal(BasicVals, b);
|
2008-02-06 07:08:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
2008-02-06 07:08:41 +08:00
|
|
|
|
2008-03-08 04:13:31 +08:00
|
|
|
return NonLVal::MakeIntTruthVal(BasicVals, false);
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
2008-03-08 04:13:31 +08:00
|
|
|
NonLVal LVal::NE(BasicValueFactory& BasicVals, const LVal& R) const {
|
2008-02-01 03:34:24 +08:00
|
|
|
switch (getSubKind()) {
|
|
|
|
default:
|
2008-02-22 02:02:17 +08:00
|
|
|
assert(false && "NE not implemented for this LVal.");
|
|
|
|
break;
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
case lval::ConcreteIntKind:
|
2008-02-22 02:02:17 +08:00
|
|
|
if (isa<lval::ConcreteInt>(R)) {
|
2008-02-06 07:08:41 +08:00
|
|
|
bool b = cast<lval::ConcreteInt>(this)->getValue() !=
|
2008-02-22 02:02:17 +08:00
|
|
|
cast<lval::ConcreteInt>(R).getValue();
|
2008-02-06 07:08:41 +08:00
|
|
|
|
2008-03-08 04:13:31 +08:00
|
|
|
return NonLVal::MakeIntTruthVal(BasicVals, b);
|
2008-02-06 07:08:41 +08:00
|
|
|
}
|
2008-02-22 02:02:17 +08:00
|
|
|
else if (isa<lval::SymbolVal>(R)) {
|
2008-02-06 07:08:41 +08:00
|
|
|
|
|
|
|
const SymIntConstraint& C =
|
2008-03-08 04:13:31 +08:00
|
|
|
BasicVals.getConstraint(cast<lval::SymbolVal>(R).getSymbol(),
|
2008-02-06 07:08:41 +08:00
|
|
|
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: {
|
2008-02-22 02:02:17 +08:00
|
|
|
if (isa<lval::ConcreteInt>(R)) {
|
2008-02-06 07:08:41 +08:00
|
|
|
|
|
|
|
const SymIntConstraint& C =
|
2008-03-08 04:13:31 +08:00
|
|
|
BasicVals.getConstraint(cast<lval::SymbolVal>(this)->getSymbol(),
|
2008-02-06 07:08:41 +08:00
|
|
|
BinaryOperator::NE,
|
2008-02-22 02:02:17 +08:00
|
|
|
cast<lval::ConcreteInt>(R).getValue());
|
2008-02-06 07:08:41 +08:00
|
|
|
|
|
|
|
return nonlval::SymIntConstraintVal(C);
|
|
|
|
}
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
assert (!isa<lval::SymbolVal>(R) && "FIXME: Implement sym !=.");
|
2008-02-06 07:08:41 +08:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case lval::DeclValKind:
|
2008-02-22 02:02:17 +08:00
|
|
|
if (isa<lval::DeclVal>(R)) {
|
|
|
|
bool b = cast<lval::DeclVal>(*this) == cast<lval::DeclVal>(R);
|
2008-03-08 04:13:31 +08:00
|
|
|
return NonLVal::MakeIntTruthVal(BasicVals, b);
|
2008-02-22 02:02:17 +08:00
|
|
|
}
|
2008-02-06 07:08:41 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
break;
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
2008-02-06 07:08:41 +08:00
|
|
|
|
2008-03-08 04:13:31 +08:00
|
|
|
return NonLVal::MakeIntTruthVal(BasicVals, true);
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-02-22 02:02:17 +08:00
|
|
|
// Utility methods for constructing Non-LVals.
|
2008-02-01 03:34:24 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-03-08 04:13:31 +08:00
|
|
|
NonLVal NonLVal::MakeVal(BasicValueFactory& BasicVals, uint64_t X, QualType T) {
|
|
|
|
return nonlval::ConcreteInt(BasicVals.getValue(X, T));
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
2008-03-08 04:13:31 +08:00
|
|
|
NonLVal NonLVal::MakeVal(BasicValueFactory& BasicVals, IntegerLiteral* I) {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-03-08 04:13:31 +08:00
|
|
|
return nonlval::ConcreteInt(BasicVals.getValue(APSInt(I->getValue(),
|
2008-02-22 02:02:17 +08:00
|
|
|
I->getType()->isUnsignedIntegerType())));
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
2008-03-08 04:13:31 +08:00
|
|
|
NonLVal NonLVal::MakeIntTruthVal(BasicValueFactory& BasicVals, bool b) {
|
|
|
|
return nonlval::ConcreteInt(BasicVals.getTruthValue(b));
|
2008-02-07 06:50:25 +08:00
|
|
|
}
|
|
|
|
|
2008-02-26 10:15:56 +08:00
|
|
|
RVal RVal::GetSymbolValue(SymbolManager& SymMgr, VarDecl* D) {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
QualType T = D->getType();
|
|
|
|
|
2008-05-01 06:48:21 +08:00
|
|
|
if (T->isPointerLikeType() || T->isObjCQualifiedIdType())
|
2008-02-06 05:52:21 +08:00
|
|
|
return lval::SymbolVal(SymMgr.getSymbol(D));
|
2008-05-01 06:48:21 +08:00
|
|
|
|
2008-04-03 01:45:06 +08:00
|
|
|
return nonlval::SymbolVal(SymMgr.getSymbol(D));
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
2008-02-13 05:37:56 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-02-22 02:02:17 +08:00
|
|
|
// Utility methods for constructing LVals.
|
2008-02-13 05:37:56 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
LVal LVal::MakeVal(AddrLabelExpr* E) { return lval::GotoLabel(E->getLabel()); }
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-04-23 05:39:21 +08:00
|
|
|
LVal LVal::MakeVal(StringLiteral* S) {
|
|
|
|
return lval::StringLiteralVal(S);
|
|
|
|
}
|
|
|
|
|
2008-03-09 11:30:59 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Utility methods for constructing RVals (both NonLVals and LVals).
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
RVal RVal::MakeVal(BasicValueFactory& BasicVals, DeclRefExpr* E) {
|
|
|
|
|
|
|
|
ValueDecl* D = cast<DeclRefExpr>(E)->getDecl();
|
|
|
|
|
|
|
|
if (VarDecl* VD = dyn_cast<VarDecl>(D)) {
|
|
|
|
return lval::DeclVal(VD);
|
|
|
|
}
|
|
|
|
else if (EnumConstantDecl* ED = dyn_cast<EnumConstantDecl>(D)) {
|
|
|
|
|
|
|
|
// FIXME: Do we need to cache a copy of this enum, since it
|
|
|
|
// already has persistent storage? We do this because we
|
|
|
|
// are comparing states using pointer equality. Perhaps there is
|
|
|
|
// a better way, since APInts are fairly lightweight.
|
|
|
|
|
|
|
|
return nonlval::ConcreteInt(BasicVals.getValue(ED->getInitVal()));
|
|
|
|
}
|
|
|
|
else if (FunctionDecl* FD = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
return lval::FuncVal(FD);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (false &&
|
|
|
|
"ValueDecl support for this ValueDecl not implemented.");
|
|
|
|
|
|
|
|
return UnknownVal();
|
|
|
|
}
|
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Pretty-Printing.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
void RVal::printStdErr() const { print(*llvm::cerr.stream()); }
|
|
|
|
|
|
|
|
void RVal::print(std::ostream& Out) const {
|
2008-02-13 05:37:56 +08:00
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
switch (getBaseKind()) {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-02-08 11:02:48 +08:00
|
|
|
case UnknownKind:
|
2008-02-22 02:02:17 +08:00
|
|
|
Out << "Invalid"; break;
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
case NonLValKind:
|
|
|
|
cast<NonLVal>(this)->print(Out); break;
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
case LValKind:
|
|
|
|
cast<LVal>(this)->print(Out); break;
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
case UndefinedKind:
|
|
|
|
Out << "Undefined"; break;
|
2008-02-01 03:34:24 +08:00
|
|
|
|
|
|
|
default:
|
2008-02-22 02:02:17 +08:00
|
|
|
assert (false && "Invalid RVal.");
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
static void printOpcode(std::ostream& Out, BinaryOperator::Opcode Op) {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
|
|
|
switch (Op) {
|
|
|
|
case BinaryOperator::Mul: Out << '*' ; break;
|
|
|
|
case BinaryOperator::Div: Out << '/' ; break;
|
|
|
|
case BinaryOperator::Rem: Out << '%' ; break;
|
|
|
|
case BinaryOperator::Add: Out << '+' ; break;
|
|
|
|
case BinaryOperator::Sub: Out << '-' ; break;
|
2008-02-16 06:09:30 +08:00
|
|
|
case BinaryOperator::Shl: Out << "<<" ; break;
|
|
|
|
case BinaryOperator::Shr: Out << ">>" ; break;
|
2008-02-22 02:02:17 +08:00
|
|
|
case BinaryOperator::LT: Out << "<" ; break;
|
|
|
|
case BinaryOperator::GT: Out << '>' ; break;
|
|
|
|
case BinaryOperator::LE: Out << "<=" ; break;
|
|
|
|
case BinaryOperator::GE: Out << ">=" ; break;
|
|
|
|
case BinaryOperator::EQ: Out << "==" ; break;
|
|
|
|
case BinaryOperator::NE: Out << "!=" ; break;
|
|
|
|
case BinaryOperator::And: Out << '&' ; break;
|
|
|
|
case BinaryOperator::Xor: Out << '^' ; break;
|
|
|
|
case BinaryOperator::Or: Out << '|' ; break;
|
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
default: assert(false && "Not yet implemented.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
void NonLVal::print(std::ostream& Out) const {
|
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
switch (getSubKind()) {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-02-06 05:52:21 +08:00
|
|
|
case nonlval::ConcreteIntKind:
|
2008-08-24 06:23:37 +08:00
|
|
|
Out << cast<nonlval::ConcreteInt>(this)->getValue().getZExtValue();
|
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());
|
2008-08-24 06:23:37 +08:00
|
|
|
Out << ' ' << C.getConstraint().getInt().getZExtValue();
|
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-04-23 05:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case nonlval::LValAsIntegerKind: {
|
|
|
|
const nonlval::LValAsInteger& C = *cast<nonlval::LValAsInteger>(this);
|
|
|
|
C.getLVal().print(Out);
|
|
|
|
Out << " [as " << C.getNumBits() << " bit integer]";
|
|
|
|
break;
|
|
|
|
}
|
2008-02-01 03:34:24 +08:00
|
|
|
|
|
|
|
default:
|
2008-02-22 02:02:17 +08:00
|
|
|
assert (false && "Pretty-printed not implemented for this NonLVal.");
|
2008-02-01 03:34:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
void LVal::print(std::ostream& Out) const {
|
|
|
|
|
2008-02-01 14:36:40 +08:00
|
|
|
switch (getSubKind()) {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-02-06 05:52:21 +08:00
|
|
|
case lval::ConcreteIntKind:
|
2008-08-24 06:23:37 +08:00
|
|
|
Out << cast<lval::ConcreteInt>(this)->getValue().getZExtValue()
|
|
|
|
<< " (LVal)";
|
2008-02-01 14:36:40 +08:00
|
|
|
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-19 09:44:53 +08:00
|
|
|
<< cast<lval::DeclVal>(this)->getDecl()->getIdentifier()->getName();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case lval::FuncValKind:
|
|
|
|
Out << "function "
|
|
|
|
<< cast<lval::FuncVal>(this)->getDecl()->getIdentifier()->getName();
|
2008-02-01 03:34:24 +08:00
|
|
|
break;
|
|
|
|
|
2008-04-23 05:39:21 +08:00
|
|
|
case lval::StringLiteralValKind:
|
|
|
|
Out << "literal \""
|
|
|
|
<< cast<lval::StringLiteralVal>(this)->getLiteral()->getStrData()
|
|
|
|
<< "\"";
|
|
|
|
break;
|
|
|
|
|
2008-04-30 06:17:41 +08:00
|
|
|
case lval::FieldOffsetKind: {
|
|
|
|
const lval::FieldOffset& C = *cast<lval::FieldOffset>(this);
|
|
|
|
C.getBase().print(Out);
|
|
|
|
Out << "." << C.getFieldDecl()->getName() << " (field LVal)";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-30 07:24:44 +08:00
|
|
|
case lval::ArrayOffsetKind: {
|
|
|
|
const lval::ArrayOffset& C = *cast<lval::ArrayOffset>(this);
|
|
|
|
C.getBase().print(Out);
|
|
|
|
Out << "[";
|
|
|
|
C.getOffset().print(Out);
|
|
|
|
Out << "] (lval array entry)";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
default:
|
2008-02-22 02:02:17 +08:00
|
|
|
assert (false && "Pretty-printing not implemented for this LVal.");
|
2008-02-01 03:34:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|