diff options
Diffstat (limited to 'lib/AST/Stmt.cpp')
-rw-r--r-- | lib/AST/Stmt.cpp | 266 |
1 files changed, 172 insertions, 94 deletions
diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 5b29c07..de85161 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -18,6 +18,7 @@ #include "clang/AST/Stmt.h" #include "clang/AST/StmtCXX.h" #include "clang/AST/StmtObjC.h" +#include "clang/AST/StmtOpenMP.h" #include "clang/AST/Type.h" #include "clang/Basic/CharInfo.h" #include "clang/Basic/TargetInfo.h" @@ -48,16 +49,11 @@ static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) { return StmtClassInfo[E]; } -void *Stmt::operator new(size_t bytes, ASTContext& C, - unsigned alignment) throw() { +void *Stmt::operator new(size_t bytes, const ASTContext& C, + unsigned alignment) { return ::operator new(bytes, C, alignment); } -void *Stmt::operator new(size_t bytes, ASTContext* C, - unsigned alignment) throw() { - return ::operator new(bytes, *C, alignment); -} - const char *Stmt::getStmtClassName() const { return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name; } @@ -139,6 +135,7 @@ namespace { template <class T> good implements_children(children_t T::*) { return good(); } + LLVM_ATTRIBUTE_UNUSED static inline bad implements_children(children_t Stmt::*) { return bad(); } @@ -147,6 +144,7 @@ namespace { template <class T> good implements_getLocStart(getLocStart_t T::*) { return good(); } + LLVM_ATTRIBUTE_UNUSED static inline bad implements_getLocStart(getLocStart_t Stmt::*) { return bad(); } @@ -155,20 +153,22 @@ namespace { template <class T> good implements_getLocEnd(getLocEnd_t T::*) { return good(); } + LLVM_ATTRIBUTE_UNUSED static inline bad implements_getLocEnd(getLocEnd_t Stmt::*) { return bad(); } #define ASSERT_IMPLEMENTS_children(type) \ - (void) sizeof(is_good(implements_children(&type::children))) + (void) is_good(implements_children(&type::children)) #define ASSERT_IMPLEMENTS_getLocStart(type) \ - (void) sizeof(is_good(implements_getLocStart(&type::getLocStart))) + (void) is_good(implements_getLocStart(&type::getLocStart)) #define ASSERT_IMPLEMENTS_getLocEnd(type) \ - (void) sizeof(is_good(implements_getLocEnd(&type::getLocEnd))) + (void) is_good(implements_getLocEnd(&type::getLocEnd)) } /// Check whether the various Stmt classes implement their member /// functions. +LLVM_ATTRIBUTE_UNUSED static inline void check_implementations() { #define ABSTRACT_STMT(type) #define STMT(type, base) \ @@ -252,7 +252,7 @@ SourceLocation Stmt::getLocEnd() const { llvm_unreachable("unknown statement kind"); } -CompoundStmt::CompoundStmt(ASTContext &C, ArrayRef<Stmt*> Stmts, +CompoundStmt::CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts, SourceLocation LB, SourceLocation RB) : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) { CompoundStmtBits.NumStmts = Stmts.size(); @@ -268,7 +268,8 @@ CompoundStmt::CompoundStmt(ASTContext &C, ArrayRef<Stmt*> Stmts, std::copy(Stmts.begin(), Stmts.end(), Body); } -void CompoundStmt::setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts) { +void CompoundStmt::setStmts(const ASTContext &C, Stmt **Stmts, + unsigned NumStmts) { if (this->Body) C.Deallocate(Body); this->CompoundStmtBits.NumStmts = NumStmts; @@ -281,7 +282,7 @@ const char *LabelStmt::getName() const { return getDecl()->getIdentifier()->getNameStart(); } -AttributedStmt *AttributedStmt::Create(ASTContext &C, SourceLocation Loc, +AttributedStmt *AttributedStmt::Create(const ASTContext &C, SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt) { void *Mem = C.Allocate(sizeof(AttributedStmt) + @@ -290,7 +291,8 @@ AttributedStmt *AttributedStmt::Create(ASTContext &C, SourceLocation Loc, return new (Mem) AttributedStmt(Loc, Attrs, SubStmt); } -AttributedStmt *AttributedStmt::CreateEmpty(ASTContext &C, unsigned NumAttrs) { +AttributedStmt *AttributedStmt::CreateEmpty(const ASTContext &C, + unsigned NumAttrs) { assert(NumAttrs > 0 && "NumAttrs should be greater than zero"); void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr*) * (NumAttrs - 1), @@ -298,29 +300,7 @@ AttributedStmt *AttributedStmt::CreateEmpty(ASTContext &C, unsigned NumAttrs) { return new (Mem) AttributedStmt(EmptyShell(), NumAttrs); } -bool Stmt::hasImplicitControlFlow() const { - switch (StmtBits.sClass) { - default: - return false; - - case CallExprClass: - case ConditionalOperatorClass: - case ChooseExprClass: - case StmtExprClass: - case DeclStmtClass: - return true; - - case Stmt::BinaryOperatorClass: { - const BinaryOperator* B = cast<BinaryOperator>(this); - if (B->isLogicalOp() || B->getOpcode() == BO_Comma) - return true; - else - return false; - } - } -} - -std::string AsmStmt::generateAsmString(ASTContext &C) const { +std::string AsmStmt::generateAsmString(const ASTContext &C) const { if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) return gccAsmStmt->generateAsmString(C); if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) @@ -406,14 +386,14 @@ StringRef GCCAsmStmt::getInputConstraint(unsigned i) const { return getInputConstraintLiteral(i)->getString(); } -void GCCAsmStmt::setOutputsAndInputsAndClobbers(ASTContext &C, - IdentifierInfo **Names, - StringLiteral **Constraints, - Stmt **Exprs, - unsigned NumOutputs, - unsigned NumInputs, - StringLiteral **Clobbers, - unsigned NumClobbers) { +void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C, + IdentifierInfo **Names, + StringLiteral **Constraints, + Stmt **Exprs, + unsigned NumOutputs, + unsigned NumInputs, + StringLiteral **Clobbers, + unsigned NumClobbers) { this->NumOutputs = NumOutputs; this->NumInputs = NumInputs; this->NumClobbers = NumClobbers; @@ -461,7 +441,7 @@ int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const { /// it into pieces. If the asm string is erroneous, emit errors and return /// true, otherwise return false. unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces, - ASTContext &C, unsigned &DiagOffs) const { + const ASTContext &C, unsigned &DiagOffs) const { StringRef Str = getAsmString()->getString(); const char *StrStart = Str.begin(); const char *StrEnd = Str.end(); @@ -599,7 +579,7 @@ unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces, } /// Assemble final IR asm string (GCC-style). -std::string GCCAsmStmt::generateAsmString(ASTContext &C) const { +std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const { // Analyze the asm string to decompose it into its pieces. We know that Sema // has already done this, so it is guaranteed to be successful. SmallVector<GCCAsmStmt::AsmStringPiece, 4> Pieces; @@ -620,7 +600,7 @@ std::string GCCAsmStmt::generateAsmString(ASTContext &C) const { } /// Assemble final IR asm string (MS-style). -std::string MSAsmStmt::generateAsmString(ASTContext &C) const { +std::string MSAsmStmt::generateAsmString(const ASTContext &C) const { // FIXME: This needs to be translated into the IR string representation. return AsmStr; } @@ -646,12 +626,12 @@ QualType CXXCatchStmt::getCaughtType() const { // Constructors //===----------------------------------------------------------------------===// -GCCAsmStmt::GCCAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, - bool isvolatile, unsigned numoutputs, unsigned numinputs, - IdentifierInfo **names, StringLiteral **constraints, - Expr **exprs, StringLiteral *asmstr, - unsigned numclobbers, StringLiteral **clobbers, - SourceLocation rparenloc) +GCCAsmStmt::GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, + bool issimple, bool isvolatile, unsigned numoutputs, + unsigned numinputs, IdentifierInfo **names, + StringLiteral **constraints, Expr **exprs, + StringLiteral *asmstr, unsigned numclobbers, + StringLiteral **clobbers, SourceLocation rparenloc) : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, numinputs, numclobbers), RParenLoc(rparenloc), AsmStr(asmstr) { @@ -670,7 +650,7 @@ GCCAsmStmt::GCCAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, std::copy(clobbers, clobbers + NumClobbers, Clobbers); } -MSAsmStmt::MSAsmStmt(ASTContext &C, SourceLocation asmloc, +MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc, bool issimple, bool isvolatile, ArrayRef<Token> asmtoks, unsigned numoutputs, unsigned numinputs, @@ -684,15 +664,14 @@ MSAsmStmt::MSAsmStmt(ASTContext &C, SourceLocation asmloc, initialize(C, asmstr, asmtoks, constraints, exprs, clobbers); } -static StringRef copyIntoContext(ASTContext &C, StringRef str) { +static StringRef copyIntoContext(const ASTContext &C, StringRef str) { size_t size = str.size(); char *buffer = new (C) char[size]; memcpy(buffer, str.data(), size); return StringRef(buffer, size); } -void MSAsmStmt::initialize(ASTContext &C, - StringRef asmstr, +void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr, ArrayRef<Token> asmtoks, ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs, @@ -731,7 +710,7 @@ ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, SourceLocation RPL) : Stmt(ObjCForCollectionStmtClass) { SubExprs[ELEM] = Elem; - SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(Collect); + SubExprs[COLLECTION] = Collect; SubExprs[BODY] = Body; ForLoc = FCL; RParenLoc = RPL; @@ -752,7 +731,7 @@ ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt, Stmts[NumCatchStmts + 1] = atFinallyStmt; } -ObjCAtTryStmt *ObjCAtTryStmt::Create(ASTContext &Context, +ObjCAtTryStmt *ObjCAtTryStmt::Create(const ASTContext &Context, SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, @@ -765,9 +744,9 @@ ObjCAtTryStmt *ObjCAtTryStmt::Create(ASTContext &Context, atFinallyStmt); } -ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(ASTContext &Context, - unsigned NumCatchStmts, - bool HasFinally) { +ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context, + unsigned NumCatchStmts, + bool HasFinally) { unsigned Size = sizeof(ObjCAtTryStmt) + (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *); void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>()); @@ -782,7 +761,7 @@ SourceLocation ObjCAtTryStmt::getLocEnd() const { return getTryBody()->getLocEnd(); } -CXXTryStmt *CXXTryStmt::Create(ASTContext &C, SourceLocation tryLoc, +CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc, Stmt *tryBlock, ArrayRef<Stmt*> handlers) { std::size_t Size = sizeof(CXXTryStmt); Size += ((handlers.size() + 1) * sizeof(Stmt)); @@ -791,7 +770,7 @@ CXXTryStmt *CXXTryStmt::Create(ASTContext &C, SourceLocation tryLoc, return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers); } -CXXTryStmt *CXXTryStmt::Create(ASTContext &C, EmptyShell Empty, +CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty, unsigned numHandlers) { std::size_t Size = sizeof(CXXTryStmt); Size += ((numHandlers + 1) * sizeof(Stmt)); @@ -815,8 +794,8 @@ CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range, DeclStmt *BeginEndStmt, : Stmt(CXXForRangeStmtClass), ForLoc(FL), ColonLoc(CL), RParenLoc(RPL) { SubExprs[RANGE] = Range; SubExprs[BEGINEND] = BeginEndStmt; - SubExprs[COND] = reinterpret_cast<Stmt*>(Cond); - SubExprs[INC] = reinterpret_cast<Stmt*>(Inc); + SubExprs[COND] = Cond; + SubExprs[INC] = Inc; SubExprs[LOOPVAR] = LoopVar; SubExprs[BODY] = Body; } @@ -842,12 +821,12 @@ const VarDecl *CXXForRangeStmt::getLoopVariable() const { return const_cast<CXXForRangeStmt*>(this)->getLoopVariable(); } -IfStmt::IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, +IfStmt::IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, Stmt *then, SourceLocation EL, Stmt *elsev) : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL) { setConditionVariable(C, var); - SubExprs[COND] = reinterpret_cast<Stmt*>(cond); + SubExprs[COND] = cond; SubExprs[THEN] = then; SubExprs[ELSE] = elsev; } @@ -860,7 +839,7 @@ VarDecl *IfStmt::getConditionVariable() const { return cast<VarDecl>(DS->getSingleDecl()); } -void IfStmt::setConditionVariable(ASTContext &C, VarDecl *V) { +void IfStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { if (!V) { SubExprs[VAR] = 0; return; @@ -871,15 +850,15 @@ void IfStmt::setConditionVariable(ASTContext &C, VarDecl *V) { VarRange.getEnd()); } -ForStmt::ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, +ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP) : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP) { SubExprs[INIT] = Init; setConditionVariable(C, condVar); - SubExprs[COND] = reinterpret_cast<Stmt*>(Cond); - SubExprs[INC] = reinterpret_cast<Stmt*>(Inc); + SubExprs[COND] = Cond; + SubExprs[INC] = Inc; SubExprs[BODY] = Body; } @@ -891,7 +870,7 @@ VarDecl *ForStmt::getConditionVariable() const { return cast<VarDecl>(DS->getSingleDecl()); } -void ForStmt::setConditionVariable(ASTContext &C, VarDecl *V) { +void ForStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { if (!V) { SubExprs[CONDVAR] = 0; return; @@ -902,11 +881,11 @@ void ForStmt::setConditionVariable(ASTContext &C, VarDecl *V) { VarRange.getEnd()); } -SwitchStmt::SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond) +SwitchStmt::SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond) : Stmt(SwitchStmtClass), FirstCase(0), AllEnumCasesCovered(0) { setConditionVariable(C, Var); - SubExprs[COND] = reinterpret_cast<Stmt*>(cond); + SubExprs[COND] = cond; SubExprs[BODY] = NULL; } @@ -918,7 +897,7 @@ VarDecl *SwitchStmt::getConditionVariable() const { return cast<VarDecl>(DS->getSingleDecl()); } -void SwitchStmt::setConditionVariable(ASTContext &C, VarDecl *V) { +void SwitchStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { if (!V) { SubExprs[VAR] = 0; return; @@ -935,11 +914,11 @@ Stmt *SwitchCase::getSubStmt() { return cast<DefaultStmt>(this)->getSubStmt(); } -WhileStmt::WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, +WhileStmt::WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, SourceLocation WL) : Stmt(WhileStmtClass) { setConditionVariable(C, Var); - SubExprs[COND] = reinterpret_cast<Stmt*>(cond); + SubExprs[COND] = cond; SubExprs[BODY] = body; WhileLoc = WL; } @@ -952,7 +931,7 @@ VarDecl *WhileStmt::getConditionVariable() const { return cast<VarDecl>(DS->getSingleDecl()); } -void WhileStmt::setConditionVariable(ASTContext &C, VarDecl *V) { +void WhileStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { if (!V) { SubExprs[VAR] = 0; return; @@ -991,10 +970,8 @@ SEHTryStmt::SEHTryStmt(bool IsCXXTry, Children[HANDLER] = Handler; } -SEHTryStmt* SEHTryStmt::Create(ASTContext &C, - bool IsCXXTry, - SourceLocation TryLoc, - Stmt *TryBlock, +SEHTryStmt* SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry, + SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler) { return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler); } @@ -1013,14 +990,12 @@ SEHExceptStmt::SEHExceptStmt(SourceLocation Loc, : Stmt(SEHExceptStmtClass), Loc(Loc) { - Children[FILTER_EXPR] = reinterpret_cast<Stmt*>(FilterExpr); + Children[FILTER_EXPR] = FilterExpr; Children[BLOCK] = Block; } -SEHExceptStmt* SEHExceptStmt::Create(ASTContext &C, - SourceLocation Loc, - Expr *FilterExpr, - Stmt *Block) { +SEHExceptStmt* SEHExceptStmt::Create(const ASTContext &C, SourceLocation Loc, + Expr *FilterExpr, Stmt *Block) { return new(C) SEHExceptStmt(Loc,FilterExpr,Block); } @@ -1031,8 +1006,7 @@ SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc, Block(Block) {} -SEHFinallyStmt* SEHFinallyStmt::Create(ASTContext &C, - SourceLocation Loc, +SEHFinallyStmt* SEHFinallyStmt::Create(const ASTContext &C, SourceLocation Loc, Stmt *Block) { return new(C)SEHFinallyStmt(Loc,Block); } @@ -1079,7 +1053,7 @@ CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures) getStoredStmts()[NumCaptures] = 0; } -CapturedStmt *CapturedStmt::Create(ASTContext &Context, Stmt *S, +CapturedStmt *CapturedStmt::Create(const ASTContext &Context, Stmt *S, CapturedRegionKind Kind, ArrayRef<Capture> Captures, ArrayRef<Expr *> CaptureInits, @@ -1107,7 +1081,7 @@ CapturedStmt *CapturedStmt::Create(ASTContext &Context, Stmt *S, return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD); } -CapturedStmt *CapturedStmt::CreateDeserialized(ASTContext &Context, +CapturedStmt *CapturedStmt::CreateDeserialized(const ASTContext &Context, unsigned NumCaptures) { unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); if (NumCaptures > 0) { @@ -1128,7 +1102,7 @@ Stmt::child_range CapturedStmt::children() { bool CapturedStmt::capturesVariable(const VarDecl *Var) const { for (const_capture_iterator I = capture_begin(), E = capture_end(); I != E; ++I) { - if (I->capturesThis()) + if (!I->capturesVariable()) continue; // This does not handle variable redeclarations. This should be @@ -1140,3 +1114,107 @@ bool CapturedStmt::capturesVariable(const VarDecl *Var) const { return false; } + +StmtRange OMPClause::children() { + switch(getClauseKind()) { + default : break; +#define OPENMP_CLAUSE(Name, Class) \ + case OMPC_ ## Name : return static_cast<Class *>(this)->children(); +#include "clang/Basic/OpenMPKinds.def" + } + llvm_unreachable("unknown OMPClause"); +} + +OMPPrivateClause *OMPPrivateClause::Create(const ASTContext &C, + SourceLocation StartLoc, + SourceLocation LParenLoc, + SourceLocation EndLoc, + ArrayRef<Expr *> VL) { + void *Mem = C.Allocate(sizeof(OMPPrivateClause) + sizeof(Expr *) * VL.size(), + llvm::alignOf<OMPPrivateClause>()); + OMPPrivateClause *Clause = new (Mem) OMPPrivateClause(StartLoc, LParenLoc, + EndLoc, VL.size()); + Clause->setVarRefs(VL); + return Clause; +} + +OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C, + unsigned N) { + void *Mem = C.Allocate(sizeof(OMPPrivateClause) + sizeof(Expr *) * N, + llvm::alignOf<OMPPrivateClause>()); + return new (Mem) OMPPrivateClause(N); +} + +OMPFirstprivateClause *OMPFirstprivateClause::Create(const ASTContext &C, + SourceLocation StartLoc, + SourceLocation LParenLoc, + SourceLocation EndLoc, + ArrayRef<Expr *> VL) { + void *Mem = C.Allocate(sizeof(OMPFirstprivateClause) + + sizeof(Expr *) * VL.size(), + llvm::alignOf<OMPFirstprivateClause>()); + OMPFirstprivateClause *Clause = new (Mem) OMPFirstprivateClause(StartLoc, + LParenLoc, + EndLoc, + VL.size()); + Clause->setVarRefs(VL); + return Clause; +} + +OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C, + unsigned N) { + void *Mem = C.Allocate(sizeof(OMPFirstprivateClause) + sizeof(Expr *) * N, + llvm::alignOf<OMPFirstprivateClause>()); + return new (Mem) OMPFirstprivateClause(N); +} + +OMPSharedClause *OMPSharedClause::Create(const ASTContext &C, + SourceLocation StartLoc, + SourceLocation LParenLoc, + SourceLocation EndLoc, + ArrayRef<Expr *> VL) { + void *Mem = C.Allocate(sizeof(OMPSharedClause) + sizeof(Expr *) * VL.size(), + llvm::alignOf<OMPSharedClause>()); + OMPSharedClause *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc, + EndLoc, VL.size()); + Clause->setVarRefs(VL); + return Clause; +} + +OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, + unsigned N) { + void *Mem = C.Allocate(sizeof(OMPSharedClause) + sizeof(Expr *) * N, + llvm::alignOf<OMPSharedClause>()); + return new (Mem) OMPSharedClause(N); +} + +void OMPExecutableDirective::setClauses(ArrayRef<OMPClause *> Clauses) { + assert(Clauses.size() == this->Clauses.size() && + "Number of clauses is not the same as the preallocated buffer"); + std::copy(Clauses.begin(), Clauses.end(), this->Clauses.begin()); +} + +OMPParallelDirective *OMPParallelDirective::Create( + const ASTContext &C, + SourceLocation StartLoc, + SourceLocation EndLoc, + ArrayRef<OMPClause *> Clauses, + Stmt *AssociatedStmt) { + void *Mem = C.Allocate(sizeof(OMPParallelDirective) + + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *), + llvm::alignOf<OMPParallelDirective>()); + OMPParallelDirective *Dir = new (Mem) OMPParallelDirective(StartLoc, EndLoc, + Clauses.size()); + Dir->setClauses(Clauses); + Dir->setAssociatedStmt(AssociatedStmt); + return Dir; +} + +OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C, + unsigned N, + EmptyShell) { + void *Mem = C.Allocate(sizeof(OMPParallelDirective) + + sizeof(OMPClause *) * N + sizeof(Stmt *), + llvm::alignOf<OMPParallelDirective>()); + return new (Mem) OMPParallelDirective(N); +} |