diff options
Diffstat (limited to 'lib/AST/ExprObjC.cpp')
-rw-r--r-- | lib/AST/ExprObjC.cpp | 43 |
1 files changed, 12 insertions, 31 deletions
diff --git a/lib/AST/ExprObjC.cpp b/lib/AST/ExprObjC.cpp index 46298c7..0936a81 100644 --- a/lib/AST/ExprObjC.cpp +++ b/lib/AST/ExprObjC.cpp @@ -39,16 +39,14 @@ ObjCArrayLiteral *ObjCArrayLiteral::Create(const ASTContext &C, ArrayRef<Expr *> Elements, QualType T, ObjCMethodDecl *Method, SourceRange SR) { - void *Mem = - C.Allocate(sizeof(ObjCArrayLiteral) + Elements.size() * sizeof(Expr *)); + void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(Elements.size())); return new (Mem) ObjCArrayLiteral(Elements, T, Method, SR); } ObjCArrayLiteral *ObjCArrayLiteral::CreateEmpty(const ASTContext &C, unsigned NumElements) { - void *Mem = - C.Allocate(sizeof(ObjCArrayLiteral) + NumElements * sizeof(Expr *)); + void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumElements)); return new (Mem) ObjCArrayLiteral(EmptyShell(), NumElements); } @@ -60,8 +58,9 @@ ObjCDictionaryLiteral::ObjCDictionaryLiteral(ArrayRef<ObjCDictionaryElement> VK, false, false), NumElements(VK.size()), HasPackExpansions(HasPackExpansions), Range(SR), DictWithObjectsMethod(method) { - KeyValuePair *KeyValues = getKeyValues(); - ExpansionData *Expansions = getExpansionData(); + KeyValuePair *KeyValues = getTrailingObjects<KeyValuePair>(); + ExpansionData *Expansions = + HasPackExpansions ? getTrailingObjects<ExpansionData>() : nullptr; for (unsigned I = 0; I < NumElements; I++) { if (VK[I].Key->isTypeDependent() || VK[I].Key->isValueDependent() || VK[I].Value->isTypeDependent() || VK[I].Value->isValueDependent()) @@ -91,23 +90,16 @@ ObjCDictionaryLiteral::Create(const ASTContext &C, ArrayRef<ObjCDictionaryElement> VK, bool HasPackExpansions, QualType T, ObjCMethodDecl *method, SourceRange SR) { - unsigned ExpansionsSize = 0; - if (HasPackExpansions) - ExpansionsSize = sizeof(ExpansionData) * VK.size(); - - void *Mem = C.Allocate(sizeof(ObjCDictionaryLiteral) + - sizeof(KeyValuePair) * VK.size() + ExpansionsSize); + void *Mem = C.Allocate(totalSizeToAlloc<KeyValuePair, ExpansionData>( + VK.size(), HasPackExpansions ? VK.size() : 0)); return new (Mem) ObjCDictionaryLiteral(VK, HasPackExpansions, T, method, SR); } ObjCDictionaryLiteral * ObjCDictionaryLiteral::CreateEmpty(const ASTContext &C, unsigned NumElements, bool HasPackExpansions) { - unsigned ExpansionsSize = 0; - if (HasPackExpansions) - ExpansionsSize = sizeof(ExpansionData) * NumElements; - void *Mem = C.Allocate(sizeof(ObjCDictionaryLiteral) + - sizeof(KeyValuePair) * NumElements + ExpansionsSize); + void *Mem = C.Allocate(totalSizeToAlloc<KeyValuePair, ExpansionData>( + NumElements, HasPackExpansions ? NumElements : 0)); return new (Mem) ObjCDictionaryLiteral(EmptyShell(), NumElements, HasPackExpansions); } @@ -122,15 +114,6 @@ QualType ObjCPropertyRefExpr::getReceiverType(const ASTContext &ctx) const { return getBase()->getType(); } -ObjCSubscriptRefExpr * -ObjCSubscriptRefExpr::Create(const ASTContext &C, Expr *base, Expr *key, - QualType T, ObjCMethodDecl *getMethod, - ObjCMethodDecl *setMethod, SourceLocation RB) { - void *Mem = C.Allocate(sizeof(ObjCSubscriptRefExpr)); - return new (Mem) ObjCSubscriptRefExpr( - base, key, T, VK_LValue, OK_ObjCSubscript, getMethod, setMethod, RB); -} - ObjCMessageExpr::ObjCMessageExpr(QualType T, ExprValueKind VK, SourceLocation LBracLoc, SourceLocation SuperLoc, bool IsInstanceSuper, @@ -293,11 +276,9 @@ ObjCMessageExpr *ObjCMessageExpr::alloc(const ASTContext &C, ObjCMessageExpr *ObjCMessageExpr::alloc(const ASTContext &C, unsigned NumArgs, unsigned NumStoredSelLocs) { - unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + - NumArgs * sizeof(Expr *) + - NumStoredSelLocs * sizeof(SourceLocation); return (ObjCMessageExpr *)C.Allocate( - Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); + totalSizeToAlloc<void *, SourceLocation>(NumArgs + 1, NumStoredSelLocs), + llvm::AlignOf<ObjCMessageExpr>::Alignment); } void ObjCMessageExpr::getSelectorLocs( @@ -358,7 +339,7 @@ ObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const { Stmt::child_range ObjCMessageExpr::children() { Stmt **begin; if (getReceiverKind() == Instance) - begin = reinterpret_cast<Stmt **>(this + 1); + begin = reinterpret_cast<Stmt **>(getTrailingObjects<void *>()); else begin = reinterpret_cast<Stmt **>(getArgs()); return child_range(begin, |