For an Objective-C @synthesize statement, e.g.,
@synthesize foo = _foo;
keep track of the location of the ivar ("_foo"). Teach libclang to
visit the ivar as a member reference.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119447 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp
index 817f707..5e57cf8 100644
--- a/lib/AST/DeclObjC.cpp
+++ b/lib/AST/DeclObjC.cpp
@@ -896,7 +896,6 @@
return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, T);
}
-
//===----------------------------------------------------------------------===//
// ObjCPropertyImplDecl
//===----------------------------------------------------------------------===//
@@ -907,8 +906,16 @@
SourceLocation L,
ObjCPropertyDecl *property,
Kind PK,
- ObjCIvarDecl *ivar) {
- return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar);
+ ObjCIvarDecl *ivar,
+ SourceLocation ivarLoc) {
+ return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar,
+ ivarLoc);
}
+SourceRange ObjCPropertyImplDecl::getSourceRange() const {
+ SourceLocation EndLoc = getLocation();
+ if (IvarLoc.isValid())
+ EndLoc = IvarLoc;
+ return SourceRange(AtLoc, EndLoc);
+}
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp
index d18efac..c01bea9 100644
--- a/lib/Parse/ParseObjc.cpp
+++ b/lib/Parse/ParseObjc.cpp
@@ -1431,6 +1431,7 @@
IdentifierInfo *propertyIvar = 0;
IdentifierInfo *propertyId = Tok.getIdentifierInfo();
SourceLocation propertyLoc = ConsumeToken(); // consume property name
+ SourceLocation propertyIvarLoc;
if (Tok.is(tok::equal)) {
// property '=' ivar-name
ConsumeToken(); // consume '='
@@ -1446,10 +1447,10 @@
break;
}
propertyIvar = Tok.getIdentifierInfo();
- ConsumeToken(); // consume ivar-name
+ propertyIvarLoc = ConsumeToken(); // consume ivar-name
}
Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, true, ObjCImpDecl,
- propertyId, propertyIvar);
+ propertyId, propertyIvar, propertyIvarLoc);
if (Tok.isNot(tok::comma))
break;
ConsumeToken(); // consume ','
@@ -1489,7 +1490,7 @@
IdentifierInfo *propertyId = Tok.getIdentifierInfo();
SourceLocation propertyLoc = ConsumeToken(); // consume property name
Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, false, ObjCImpDecl,
- propertyId, 0);
+ propertyId, 0, SourceLocation());
if (Tok.isNot(tok::comma))
break;
diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp
index fe2de27..65002f3 100644
--- a/lib/Sema/SemaObjCProperty.cpp
+++ b/lib/Sema/SemaObjCProperty.cpp
@@ -318,7 +318,8 @@
bool Synthesize,
Decl *ClassCatImpDecl,
IdentifierInfo *PropertyId,
- IdentifierInfo *PropertyIvar) {
+ IdentifierInfo *PropertyIvar,
+ SourceLocation PropertyIvarLoc) {
ObjCContainerDecl *ClassImpDecl =
cast_or_null<ObjCContainerDecl>(ClassCatImpDecl);
// Make sure we have a context for the property implementation declaration.
@@ -474,7 +475,7 @@
(Synthesize ?
ObjCPropertyImplDecl::Synthesize
: ObjCPropertyImplDecl::Dynamic),
- Ivar);
+ Ivar, PropertyIvarLoc);
if (ObjCMethodDecl *getterMethod = property->getGetterMethodDecl()) {
getterMethod->createImplicitParams(Context, IDecl);
if (getLangOptions().CPlusPlus && Synthesize &&
@@ -997,7 +998,8 @@
// to help users.
ActOnPropertyImplDecl(S, SourceLocation(), SourceLocation(),
true,IMPDecl,
- Prop->getIdentifier(), Prop->getIdentifier());
+ Prop->getIdentifier(), Prop->getIdentifier(),
+ SourceLocation());
}
}
diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp
index e494470..9f5d0c1 100644
--- a/lib/Serialization/ASTReaderDecl.cpp
+++ b/lib/Serialization/ASTReaderDecl.cpp
@@ -616,8 +616,9 @@
D->setAtLoc(ReadSourceLocation(Record, Idx));
D->setPropertyDecl(
cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
- D->setPropertyIvarDecl(
- cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
+ D->PropertyIvarDecl =
+ cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++]));
+ D->IvarLoc = ReadSourceLocation(Record, Idx);
D->setGetterCXXConstructor(Reader.ReadExpr(F));
D->setSetterCXXAssignment(Reader.ReadExpr(F));
}
@@ -1467,7 +1468,8 @@
case DECL_OBJC_PROPERTY_IMPL:
D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
SourceLocation(), 0,
- ObjCPropertyImplDecl::Dynamic, 0);
+ ObjCPropertyImplDecl::Dynamic, 0,
+ SourceLocation());
break;
case DECL_FIELD:
D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp
index 609a044..f7bb237 100644
--- a/lib/Serialization/ASTWriterDecl.cpp
+++ b/lib/Serialization/ASTWriterDecl.cpp
@@ -511,6 +511,7 @@
Writer.AddSourceLocation(D->getLocStart(), Record);
Writer.AddDeclRef(D->getPropertyDecl(), Record);
Writer.AddDeclRef(D->getPropertyIvarDecl(), Record);
+ Writer.AddSourceLocation(D->getPropertyIvarDeclLoc(), Record);
Writer.AddStmt(D->getGetterCXXConstructor());
Writer.AddStmt(D->getSetterCXXAssignment());
Code = serialization::DECL_OBJC_PROPERTY_IMPL;