return true;
}
+namespace {
+class ASTMaker {
+public:
+ ASTMaker(ASTContext &C) : C(C) {}
+
+ DeclRefExpr *makeDeclRefExpr(const VarDecl *D);
+
+private:
+ ASTContext &C;
+};
+}
+
+DeclRefExpr *ASTMaker::makeDeclRefExpr(const VarDecl *D) {
+ DeclRefExpr *DR =
+ DeclRefExpr::Create(/* Ctx = */ C,
+ /* QualifierLoc = */ NestedNameSpecifierLoc(),
+ /* TemplateKWLoc = */ SourceLocation(),
+ /* D = */ const_cast<VarDecl*>(D),
+ /* isEnclosingLocal = */ false,
+ /* NameLoc = */ SourceLocation(),
+ /* T = */ D->getType(),
+ /* VK = */ VK_LValue);
+ return DR;
+}
+
//===----------------------------------------------------------------------===//
// Creation functions for faux ASTs.
//===----------------------------------------------------------------------===//
// }
// }
+ ASTMaker M(C);
+
// (1) Create the call.
- DeclRefExpr *DR = DeclRefExpr::CreateEmpty(C, false, false, false, false);
- DR->setDecl(const_cast<ParmVarDecl*>(Block));
- DR->setType(Ty);
- DR->setValueKind(VK_LValue);
+ DeclRefExpr *DR = M.makeDeclRefExpr(Block);
ImplicitCastExpr *ICE = ImplicitCastExpr::Create(C, Ty, CK_LValueToRValue,
DR, 0, VK_RValue);
CallExpr *CE = new (C) CallExpr(C, ICE, ArrayRef<Expr*>(), C.VoidTy,
C.IntTy, SourceLocation());
ICE = ImplicitCastExpr::Create(C, PredicateTy, CK_IntegralCast, IL, 0,
VK_RValue);
- DR = DeclRefExpr::CreateEmpty(C, false, false, false, false);
- DR->setDecl(const_cast<ParmVarDecl*>(Predicate));
- DR->setType(PredicateQPtrTy);
- DR->setValueKind(VK_LValue);
+ DR = M.makeDeclRefExpr(Predicate);
ImplicitCastExpr *LValToRval =
ImplicitCastExpr::Create(C, PredicateQPtrTy, CK_LValueToRValue, DR,
0, VK_RValue);
SourceLocation());
// (4) Create the 'if' condition.
- DR = DeclRefExpr::CreateEmpty(C, false, false, false, false);
- DR->setDecl(const_cast<ParmVarDecl*>(Predicate));
- DR->setType(PredicateQPtrTy);
- DR->setValueKind(VK_LValue);
+ DR = M.makeDeclRefExpr(Predicate);
LValToRval = ImplicitCastExpr::Create(C, PredicateQPtrTy, CK_LValueToRValue,
DR, 0, VK_RValue);
UO = new (C) UnaryOperator(LValToRval, UO_Deref, PredicateTy,
return If;
}
-
-
/// Create a fake body for dispatch_sync.
static Stmt *create_dispatch_sync(ASTContext &C, const FunctionDecl *D) {
// Check if we have at least two parameters.
QualType Ty = PV->getType();
if (!isDispatchBlock(Ty))
return 0;
-
+
// Everything checks out. Create a fake body that just calls the block.
// This is basically just an AST dump of:
//
// void dispatch_sync(dispatch_queue_t queue, void (^block)(void)) {
// block();
// }
- //
- DeclRefExpr *DR = DeclRefExpr::CreateEmpty(C, false, false, false, false);
- DR->setDecl(const_cast<ParmVarDecl*>(PV));
- DR->setType(Ty);
- DR->setValueKind(VK_LValue);
+ //
+ ASTMaker M(C);
+ DeclRefExpr *DR = M.makeDeclRefExpr(PV);
ImplicitCastExpr *ICE = ImplicitCastExpr::Create(C, Ty, CK_LValueToRValue,
DR, 0, VK_RValue);
CallExpr *CE = new (C) CallExpr(C, ICE, ArrayRef<Expr*>(), C.VoidTy,