r214983 - Objective-C ARC. First patch toward generating new APIs
Fariborz Jahanian
fjahanian at apple.com
Wed Aug 6 11:13:46 PDT 2014
Author: fjahanian
Date: Wed Aug 6 13:13:46 2014
New Revision: 214983
URL: http://llvm.org/viewvc/llvm-project?rev=214983&view=rev
Log:
Objective-C ARC. First patch toward generating new APIs
for Objective-C's array and dictionary literals.
rdar://17554063. This is wip.
Modified:
cfe/trunk/include/clang/AST/ExprObjC.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/tools/libclang/IndexBody.cpp
Modified: cfe/trunk/include/clang/AST/ExprObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprObjC.h?rev=214983&r1=214982&r2=214983&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprObjC.h (original)
+++ cfe/trunk/include/clang/AST/ExprObjC.h Wed Aug 6 13:13:46 2014
@@ -134,9 +134,13 @@ class ObjCArrayLiteral : public Expr {
unsigned NumElements;
SourceRange Range;
ObjCMethodDecl *ArrayWithObjectsMethod;
+ /// \brief in arc mode, this field holds array allocation method declaration.
+ /// In MRR mode, it is null
+ ObjCMethodDecl *ArrayAllocMethod;
ObjCArrayLiteral(ArrayRef<Expr *> Elements,
QualType T, ObjCMethodDecl * Method,
+ ObjCMethodDecl *allocMethod,
SourceRange SR);
explicit ObjCArrayLiteral(EmptyShell Empty, unsigned NumElements)
@@ -146,6 +150,7 @@ public:
static ObjCArrayLiteral *Create(const ASTContext &C,
ArrayRef<Expr *> Elements,
QualType T, ObjCMethodDecl * Method,
+ ObjCMethodDecl *allocMethod,
SourceRange SR);
static ObjCArrayLiteral *CreateEmpty(const ASTContext &C,
@@ -184,6 +189,10 @@ public:
return ArrayWithObjectsMethod;
}
+ ObjCMethodDecl *getArrayAllocMethod() const {
+ return ArrayAllocMethod;
+ }
+
// Iterators
child_range children() {
return child_range((Stmt **)getElements(),
@@ -256,10 +265,15 @@ class ObjCDictionaryLiteral : public Exp
SourceRange Range;
ObjCMethodDecl *DictWithObjectsMethod;
+
+ /// \brief for arc-specific dictionary literals, this field is used to store
+ /// NSDictionary allocation method declaration. It is null for MRR mode.
+ ObjCMethodDecl *DictAllocMethod;
ObjCDictionaryLiteral(ArrayRef<ObjCDictionaryElement> VK,
bool HasPackExpansions,
QualType T, ObjCMethodDecl *method,
+ ObjCMethodDecl *allocMethod,
SourceRange SR);
explicit ObjCDictionaryLiteral(EmptyShell Empty, unsigned NumElements,
@@ -294,6 +308,7 @@ public:
ArrayRef<ObjCDictionaryElement> VK,
bool HasPackExpansions,
QualType T, ObjCMethodDecl *method,
+ ObjCMethodDecl *allocMethod,
SourceRange SR);
static ObjCDictionaryLiteral *CreateEmpty(const ASTContext &C,
@@ -320,6 +335,9 @@ public:
ObjCMethodDecl *getDictWithObjectsMethod() const
{ return DictWithObjectsMethod; }
+ ObjCMethodDecl *getDictAllocMethod() const
+ { return DictAllocMethod; }
+
SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
SourceRange getSourceRange() const LLVM_READONLY { return Range; }
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=214983&r1=214982&r2=214983&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed Aug 6 13:13:46 2014
@@ -4041,10 +4041,12 @@ Stmt::child_range ObjCMessageExpr::child
ObjCArrayLiteral::ObjCArrayLiteral(ArrayRef<Expr *> Elements,
QualType T, ObjCMethodDecl *Method,
+ ObjCMethodDecl *AllocMethod,
SourceRange SR)
: Expr(ObjCArrayLiteralClass, T, VK_RValue, OK_Ordinary,
false, false, false, false),
- NumElements(Elements.size()), Range(SR), ArrayWithObjectsMethod(Method)
+ NumElements(Elements.size()), Range(SR), ArrayWithObjectsMethod(Method),
+ ArrayAllocMethod(AllocMethod)
{
Expr **SaveElements = getElements();
for (unsigned I = 0, N = Elements.size(); I != N; ++I) {
@@ -4062,10 +4064,11 @@ ObjCArrayLiteral::ObjCArrayLiteral(Array
ObjCArrayLiteral *ObjCArrayLiteral::Create(const ASTContext &C,
ArrayRef<Expr *> Elements,
QualType T, ObjCMethodDecl * Method,
+ ObjCMethodDecl *allocMethod,
SourceRange SR) {
void *Mem = C.Allocate(sizeof(ObjCArrayLiteral)
+ Elements.size() * sizeof(Expr *));
- return new (Mem) ObjCArrayLiteral(Elements, T, Method, SR);
+ return new (Mem) ObjCArrayLiteral(Elements, T, Method, allocMethod, SR);
}
ObjCArrayLiteral *ObjCArrayLiteral::CreateEmpty(const ASTContext &C,
@@ -4080,11 +4083,13 @@ ObjCDictionaryLiteral::ObjCDictionaryLit
ArrayRef<ObjCDictionaryElement> VK,
bool HasPackExpansions,
QualType T, ObjCMethodDecl *method,
+ ObjCMethodDecl *allocMethod,
SourceRange SR)
: Expr(ObjCDictionaryLiteralClass, T, VK_RValue, OK_Ordinary, false, false,
false, false),
NumElements(VK.size()), HasPackExpansions(HasPackExpansions), Range(SR),
- DictWithObjectsMethod(method)
+ DictWithObjectsMethod(method),
+ DictAllocMethod(allocMethod)
{
KeyValuePair *KeyValues = getKeyValues();
ExpansionData *Expansions = getExpansionData();
@@ -4117,6 +4122,7 @@ ObjCDictionaryLiteral::Create(const ASTC
ArrayRef<ObjCDictionaryElement> VK,
bool HasPackExpansions,
QualType T, ObjCMethodDecl *method,
+ ObjCMethodDecl *allocMethod,
SourceRange SR) {
unsigned ExpansionsSize = 0;
if (HasPackExpansions)
@@ -4124,7 +4130,8 @@ ObjCDictionaryLiteral::Create(const ASTC
void *Mem = C.Allocate(sizeof(ObjCDictionaryLiteral) +
sizeof(KeyValuePair) * VK.size() + ExpansionsSize);
- return new (Mem) ObjCDictionaryLiteral(VK, HasPackExpansions, T, method, SR);
+ return new (Mem) ObjCDictionaryLiteral(VK, HasPackExpansions, T,
+ method, allocMethod, SR);
}
ObjCDictionaryLiteral *
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=214983&r1=214982&r2=214983&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Wed Aug 6 13:13:46 2014
@@ -88,7 +88,8 @@ CodeGenFunction::EmitObjCBoxedExpr(const
}
llvm::Value *CodeGenFunction::EmitObjCCollectionLiteral(const Expr *E,
- const ObjCMethodDecl *MethodWithObjects) {
+ const ObjCMethodDecl *MethodWithObjects,
+ const ObjCMethodDecl *AllocMethod) {
ASTContext &Context = CGM.getContext();
const ObjCDictionaryLiteral *DLE = nullptr;
const ObjCArrayLiteral *ALE = dyn_cast<ObjCArrayLiteral>(E);
@@ -203,12 +204,14 @@ llvm::Value *CodeGenFunction::EmitObjCCo
}
llvm::Value *CodeGenFunction::EmitObjCArrayLiteral(const ObjCArrayLiteral *E) {
- return EmitObjCCollectionLiteral(E, E->getArrayWithObjectsMethod());
+ return EmitObjCCollectionLiteral(E, E->getArrayWithObjectsMethod(),
+ E->getArrayAllocMethod());
}
llvm::Value *CodeGenFunction::EmitObjCDictionaryLiteral(
const ObjCDictionaryLiteral *E) {
- return EmitObjCCollectionLiteral(E, E->getDictWithObjectsMethod());
+ return EmitObjCCollectionLiteral(E, E->getDictWithObjectsMethod(),
+ E->getDictAllocMethod());
}
/// Emit a selector.
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=214983&r1=214982&r2=214983&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Aug 6 13:13:46 2014
@@ -2304,7 +2304,8 @@ public:
llvm::Value *EmitObjCArrayLiteral(const ObjCArrayLiteral *E);
llvm::Value *EmitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E);
llvm::Value *EmitObjCCollectionLiteral(const Expr *E,
- const ObjCMethodDecl *MethodWithObjects);
+ const ObjCMethodDecl *MethodWithObjects,
+ const ObjCMethodDecl *AllocMethod);
llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E);
RValue EmitObjCMessageExpr(const ObjCMessageExpr *E,
ReturnValueSlot Return = ReturnValueSlot());
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=214983&r1=214982&r2=214983&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Aug 6 13:13:46 2014
@@ -740,7 +740,7 @@ ExprResult Sema::BuildObjCArrayLiteral(S
return MaybeBindToTemporary(
ObjCArrayLiteral::Create(Context, Elements, Ty,
- ArrayWithObjectsMethod, SR));
+ ArrayWithObjectsMethod, nullptr, SR));
}
ExprResult Sema::BuildObjCDictionaryLiteral(SourceRange SR,
@@ -925,7 +925,7 @@ ExprResult Sema::BuildObjCDictionaryLite
Context.getObjCInterfaceType(NSDictionaryDecl));
return MaybeBindToTemporary(ObjCDictionaryLiteral::Create(
Context, makeArrayRef(Elements, NumElements), HasPackExpansions, Ty,
- DictionaryWithObjectsMethod, SR));
+ DictionaryWithObjectsMethod, nullptr, SR));
}
ExprResult Sema::BuildObjCEncodeExpression(SourceLocation AtLoc,
Modified: cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderStmt.cpp?rev=214983&r1=214982&r2=214983&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderStmt.cpp Wed Aug 6 13:13:46 2014
@@ -935,6 +935,7 @@ void ASTStmtReader::VisitObjCArrayLitera
for (unsigned I = 0, N = NumElements; I != N; ++I)
Elements[I] = Reader.ReadSubExpr();
E->ArrayWithObjectsMethod = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
+ E->ArrayAllocMethod = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
E->Range = ReadSourceRange(Record, Idx);
}
@@ -955,6 +956,7 @@ void ASTStmtReader::VisitObjCDictionaryL
}
}
E->DictWithObjectsMethod = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
+ E->DictAllocMethod = ReadDeclAs<ObjCMethodDecl>(Record, Idx);
E->Range = ReadSourceRange(Record, Idx);
}
Modified: cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterStmt.cpp?rev=214983&r1=214982&r2=214983&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterStmt.cpp Wed Aug 6 13:13:46 2014
@@ -878,6 +878,7 @@ void ASTStmtWriter::VisitObjCArrayLitera
for (unsigned i = 0; i < E->getNumElements(); i++)
Writer.AddStmt(E->getElement(i));
Writer.AddDeclRef(E->getArrayWithObjectsMethod(), Record);
+ Writer.AddDeclRef(E->getArrayAllocMethod(), Record);
Writer.AddSourceRange(E->getSourceRange(), Record);
Code = serialization::EXPR_OBJC_ARRAY_LITERAL;
}
@@ -900,6 +901,7 @@ void ASTStmtWriter::VisitObjCDictionaryL
}
Writer.AddDeclRef(E->getDictWithObjectsMethod(), Record);
+ Writer.AddDeclRef(E->getDictAllocMethod(), Record);
Writer.AddSourceRange(E->getSourceRange(), Record);
Code = serialization::EXPR_OBJC_DICTIONARY_LITERAL;
}
Modified: cfe/trunk/tools/libclang/IndexBody.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexBody.cpp?rev=214983&r1=214982&r2=214983&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexBody.cpp (original)
+++ cfe/trunk/tools/libclang/IndexBody.cpp Wed Aug 6 13:13:46 2014
@@ -109,6 +109,9 @@ public:
if (ObjCMethodDecl *MD = E->getDictWithObjectsMethod())
IndexCtx.handleReference(MD, E->getLocStart(),
Parent, ParentDC, E, CXIdxEntityRef_Implicit);
+ if (ObjCMethodDecl *MD = E->getDictAllocMethod())
+ IndexCtx.handleReference(MD, E->getLocStart(),
+ Parent, ParentDC, E, CXIdxEntityRef_Implicit);
return true;
}
@@ -116,6 +119,9 @@ public:
if (ObjCMethodDecl *MD = E->getArrayWithObjectsMethod())
IndexCtx.handleReference(MD, E->getLocStart(),
Parent, ParentDC, E, CXIdxEntityRef_Implicit);
+ if (ObjCMethodDecl *MD = E->getArrayAllocMethod())
+ IndexCtx.handleReference(MD, E->getLocStart(),
+ Parent, ParentDC, E, CXIdxEntityRef_Implicit);
return true;
}
More information about the cfe-commits
mailing list