From b80e5bb7c7c47e06f2ff9c2f9d4b6b138db180e2 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 21 Sep 2012 18:33:54 +0000 Subject: Create helper method in BodyFarm for creating simple assignments. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164400 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/BodyFarm.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'lib/Analysis') diff --git a/lib/Analysis/BodyFarm.cpp b/lib/Analysis/BodyFarm.cpp index 2faacd4ea3..54c8ab4430 100644 --- a/lib/Analysis/BodyFarm.cpp +++ b/lib/Analysis/BodyFarm.cpp @@ -46,6 +46,9 @@ class ASTMaker { public: ASTMaker(ASTContext &C) : C(C) {} + /// Create a new BinaryOperator representing a simple assignment. + BinaryOperator *makeAssignment(const Expr *LHS, const Expr *RHS, QualType Ty); + /// Create a new DeclRefExpr for the referenced variable. DeclRefExpr *makeDeclRefExpr(const VarDecl *D); @@ -63,6 +66,13 @@ private: }; } +BinaryOperator *ASTMaker::makeAssignment(const Expr *LHS, const Expr *RHS, + QualType Ty) { + return new (C) BinaryOperator(const_cast(LHS), const_cast(RHS), + BO_Assign, Ty, VK_RValue, + OK_Ordinary, SourceLocation()); +} + DeclRefExpr *ASTMaker::makeDeclRefExpr(const VarDecl *D) { DeclRefExpr *DR = DeclRefExpr::Create(/* Ctx = */ C, @@ -145,10 +155,8 @@ static Stmt *create_dispatch_once(ASTContext &C, const FunctionDecl *D) { DR = M.makeDeclRefExpr(Predicate); ImplicitCastExpr *LValToRval = M.makeLvalueToRvalue(DR, PredicateQPtrTy); UnaryOperator *UO = M.makeDereference(LValToRval, PredicateTy); - BinaryOperator *B = new (C) BinaryOperator(UO, ICE, BO_Assign, - PredicateTy, VK_RValue, - OK_Ordinary, - SourceLocation()); + BinaryOperator * B = M.makeAssignment(UO, ICE, PredicateTy); + // (3) Create the compound statement. Stmt *Stmts[2]; Stmts[0] = B; -- cgit v1.2.3-18-g5258