[cfe-commits] r97942 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/ASTImporter.cpp lib/AST/DeclObjC.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriterDecl.cpp lib/Sema/SemaDeclObjC.cpp test/Index/c-index-getCursor-test.m tools/CIndex/CIndex.cpp
Douglas Gregor
dgregor at apple.com
Mon Mar 8 06:59:44 PST 2010
Author: dgregor
Date: Mon Mar 8 08:59:44 2010
New Revision: 97942
URL: http://llvm.org/viewvc/llvm-project?rev=97942&view=rev
Log:
Keep track of type source information in the return type of an
Objective-C method declaration, e.g., for
- (Foo *)myMethod;
we now have TypeSourceInfo for the Foo*.
Modified:
cfe/trunk/include/clang/AST/DeclObjC.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/DeclObjC.cpp
cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/Index/c-index-getCursor-test.m
cfe/trunk/tools/CIndex/CIndex.cpp
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=97942&r1=97941&r2=97942&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Mon Mar 8 08:59:44 2010
@@ -136,8 +136,12 @@
/// in, inout, etc.
unsigned objcDeclQualifier : 6;
- // Type of this method.
+ // Result type of this method.
QualType MethodDeclType;
+
+ // Type source information for the result type.
+ TypeSourceInfo *ResultTInfo;
+
/// ParamInfo - List of pointers to VarDecls for the formal parameters of this
/// Method.
ObjCList<ParmVarDecl> ParamInfo;
@@ -158,6 +162,7 @@
ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
Selector SelInfo, QualType T,
+ TypeSourceInfo *ResultTInfo,
DeclContext *contextDecl,
bool isInstance = true,
bool isVariadic = false,
@@ -168,7 +173,7 @@
IsInstance(isInstance), IsVariadic(isVariadic),
IsSynthesized(isSynthesized),
DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
- MethodDeclType(T),
+ MethodDeclType(T), ResultTInfo(ResultTInfo),
EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {}
virtual ~ObjCMethodDecl() {}
@@ -186,7 +191,9 @@
static ObjCMethodDecl *Create(ASTContext &C,
SourceLocation beginLoc,
SourceLocation endLoc, Selector SelInfo,
- QualType T, DeclContext *contextDecl,
+ QualType T,
+ TypeSourceInfo *ResultTInfo,
+ DeclContext *contextDecl,
bool isInstance = true,
bool isVariadic = false,
bool isSynthesized = false,
@@ -220,6 +227,9 @@
QualType getResultType() const { return MethodDeclType; }
void setResultType(QualType T) { MethodDeclType = T; }
+ TypeSourceInfo *getResultTypeSourceInfo() const { return ResultTInfo; }
+ void setResultTypeSourceInfo(TypeSourceInfo *TInfo) { ResultTInfo = TInfo; }
+
// Iterator access to formal parameters.
unsigned param_size() const { return ParamInfo.size(); }
typedef ObjCList<ParmVarDecl>::iterator param_iterator;
Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=97942&r1=97941&r2=97942&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Mon Mar 8 08:59:44 2010
@@ -2244,12 +2244,14 @@
if (ResultTy.isNull())
return 0;
+ TypeSourceInfo *ResultTInfo = Importer.Import(D->getResultTypeSourceInfo());
+
ObjCMethodDecl *ToMethod
= ObjCMethodDecl::Create(Importer.getToContext(),
Loc,
Importer.Import(D->getLocEnd()),
Name.getObjCSelector(),
- ResultTy, DC,
+ ResultTy, ResultTInfo, DC,
D->isInstanceMethod(),
D->isVariadic(),
D->isSynthesized(),
Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=97942&r1=97941&r2=97942&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Mon Mar 8 08:59:44 2010
@@ -304,15 +304,16 @@
SourceLocation beginLoc,
SourceLocation endLoc,
Selector SelInfo, QualType T,
+ TypeSourceInfo *ResultTInfo,
DeclContext *contextDecl,
bool isInstance,
bool isVariadic,
bool isSynthesized,
ImplementationControl impControl) {
return new (C) ObjCMethodDecl(beginLoc, endLoc,
- SelInfo, T, contextDecl,
- isInstance,
- isVariadic, isSynthesized, impControl);
+ SelInfo, T, ResultTInfo, contextDecl,
+ isInstance,
+ isVariadic, isSynthesized, impControl);
}
void ObjCMethodDecl::Destroy(ASTContext &C) {
Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=97942&r1=97941&r2=97942&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Mon Mar 8 08:59:44 2010
@@ -211,6 +211,7 @@
MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
MD->setResultType(Reader.GetType(Record[Idx++]));
+ MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
unsigned NumParams = Record[Idx++];
llvm::SmallVector<ParmVarDecl *, 16> Params;
@@ -690,7 +691,7 @@
break;
case pch::DECL_OBJC_METHOD:
D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
- Selector(), QualType(), 0);
+ Selector(), QualType(), 0, 0);
break;
case pch::DECL_OBJC_INTERFACE:
D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=97942&r1=97941&r2=97942&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Mon Mar 8 08:59:44 2010
@@ -210,6 +210,7 @@
// FIXME: stable encoding for in/out/inout/bycopy/byref/oneway
Record.push_back(D->getObjCDeclQualifier());
Writer.AddTypeRef(D->getResultType(), Record);
+ Writer.AddTypeSourceInfo(D->getResultTypeSourceInfo(), Record);
Writer.AddSourceLocation(D->getLocEnd(), Record);
Record.push_back(D->param_size());
for (ObjCMethodDecl::param_iterator P = D->param_begin(),
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=97942&r1=97941&r2=97942&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Mar 8 08:59:44 2010
@@ -1681,7 +1681,7 @@
// for this class.
GetterMethod = ObjCMethodDecl::Create(Context, property->getLocation(),
property->getLocation(), property->getGetterName(),
- property->getType(), CD, true, false, true,
+ property->getType(), 0, CD, true, false, true,
(property->getPropertyImplementation() ==
ObjCPropertyDecl::Optional) ?
ObjCMethodDecl::Optional :
@@ -1703,7 +1703,7 @@
SetterMethod = ObjCMethodDecl::Create(Context, property->getLocation(),
property->getLocation(),
property->getSetterName(),
- Context.VoidTy, CD, true, false, true,
+ Context.VoidTy, 0, CD, true, false, true,
(property->getPropertyImplementation() ==
ObjCPropertyDecl::Optional) ?
ObjCMethodDecl::Optional :
@@ -1992,8 +1992,9 @@
}
QualType resultDeclType;
+ TypeSourceInfo *ResultTInfo = 0;
if (ReturnType) {
- resultDeclType = GetTypeFromParser(ReturnType);
+ resultDeclType = GetTypeFromParser(ReturnType, &ResultTInfo);
// Methods cannot return interface types. All ObjC objects are
// passed by reference.
@@ -2007,6 +2008,7 @@
ObjCMethodDecl* ObjCMethod =
ObjCMethodDecl::Create(Context, MethodLoc, EndLoc, Sel, resultDeclType,
+ ResultTInfo,
cast<DeclContext>(ClassDecl),
MethodType == tok::minus, isVariadic,
false,
Modified: cfe/trunk/test/Index/c-index-getCursor-test.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/c-index-getCursor-test.m?rev=97942&r1=97941&r2=97942&view=diff
==============================================================================
--- cfe/trunk/test/Index/c-index-getCursor-test.m (original)
+++ cfe/trunk/test/Index/c-index-getCursor-test.m Mon Mar 8 08:59:44 2010
@@ -90,7 +90,9 @@
// CHECK: [31:27 - 33:9] ObjCInterfaceDecl=Baz:31:12
// CHECK: [33:9 - 33:16] ObjCIvarDecl=_anIVar:33:9 (Definition)
// CHECK: [33:16 - 36:1] ObjCInterfaceDecl=Baz:31:12
-// CHECK: [36:1 - 36:21] ObjCInstanceMethodDecl=bazMethod:36:1
+// CHECK: [36:1 - 36:4] ObjCInstanceMethodDecl=bazMethod:36:1
+// CHECK: [36:4 - 36:7] ObjCClassRef=Foo:3:12
+// CHECK: [36:7 - 36:21] ObjCInstanceMethodDecl=bazMethod:36:1
// CHECK: [36:21 - 38:5] ObjCInterfaceDecl=Baz:31:12
// CHECK: [38:5 - 40:1] Invalid Cursor => NoDeclFound
// CHECK: [40:1 - 41:3] EnumDecl=:40:1 (Definition)
Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=97942&r1=97941&r2=97942&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Mon Mar 8 08:59:44 2010
@@ -532,9 +532,10 @@
}
bool CursorVisitor::VisitObjCMethodDecl(ObjCMethodDecl *ND) {
- // FIXME: We really need a TypeLoc covering Objective-C method declarations.
- // At the moment, we don't have information about locations in the return
- // type.
+ if (TypeSourceInfo *TSInfo = ND->getResultTypeSourceInfo())
+ if (Visit(TSInfo->getTypeLoc()))
+ return true;
+
for (ObjCMethodDecl::param_iterator P = ND->param_begin(),
PEnd = ND->param_end();
P != PEnd; ++P) {
More information about the cfe-commits
mailing list