Add helper method to BodyFarm for creatinging integral casts.

llvm-svn: 164396
This commit is contained in:
Ted Kremenek 2012-09-21 18:13:23 +00:00
parent f787f171a3
commit 69bcb82c59
1 changed files with 10 additions and 2 deletions

View File

@ -46,8 +46,12 @@ class ASTMaker {
public: public:
ASTMaker(ASTContext &C) : C(C) {} ASTMaker(ASTContext &C) : C(C) {}
/// Create a new DeclRefExpr for the referenced variable.
DeclRefExpr *makeDeclRefExpr(const VarDecl *D); DeclRefExpr *makeDeclRefExpr(const VarDecl *D);
/// Create an implicit cast for an integer conversion.
ImplicitCastExpr *makeIntegralCast(const Expr *Arg, QualType Ty);
private: private:
ASTContext &C; ASTContext &C;
}; };
@ -66,6 +70,11 @@ DeclRefExpr *ASTMaker::makeDeclRefExpr(const VarDecl *D) {
return DR; return DR;
} }
ImplicitCastExpr *ASTMaker::makeIntegralCast(const Expr *Arg, QualType Ty) {
return ImplicitCastExpr::Create(C, Ty, CK_IntegralCast,
const_cast<Expr*>(Arg), 0, VK_RValue);
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Creation functions for faux ASTs. // Creation functions for faux ASTs.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -117,8 +126,7 @@ static Stmt *create_dispatch_once(ASTContext &C, const FunctionDecl *D) {
IntegerLiteral *IL = IntegerLiteral *IL =
IntegerLiteral::Create(C, llvm::APInt(C.getTypeSize(C.IntTy), (uint64_t) 1), IntegerLiteral::Create(C, llvm::APInt(C.getTypeSize(C.IntTy), (uint64_t) 1),
C.IntTy, SourceLocation()); C.IntTy, SourceLocation());
ICE = ImplicitCastExpr::Create(C, PredicateTy, CK_IntegralCast, IL, 0, ICE = M.makeIntegralCast(IL, PredicateTy);
VK_RValue);
DR = M.makeDeclRefExpr(Predicate); DR = M.makeDeclRefExpr(Predicate);
ImplicitCastExpr *LValToRval = ImplicitCastExpr *LValToRval =
ImplicitCastExpr::Create(C, PredicateQPtrTy, CK_LValueToRValue, DR, ImplicitCastExpr::Create(C, PredicateQPtrTy, CK_LValueToRValue, DR,