[cfe-commits] r94200 - in /cfe/trunk: include/clang/Lex/Preprocessor.h lib/AST/Decl.cpp lib/Lex/Lexer.cpp lib/Lex/Preprocessor.cpp test/Index/TestClassDecl.m test/Index/TestClassForwardDecl.m test/Index/c-index-api-fn-scan.m test/Index/c-index-api-loadTU-test.m test/Index/c-index-getCursor-test.m test/Index/find-decls.c test/Index/find-defs.c tools/CIndex/CIndex.cpp

Douglas Gregor dgregor at apple.com
Fri Jan 22 11:50:00 PST 2010


Author: dgregor
Date: Fri Jan 22 13:49:59 2010
New Revision: 94200

URL: http://llvm.org/viewvc/llvm-project?rev=94200&view=rev
Log:
Teach CIndex's cursor visitor to restrict its traversal to a specific
region of interest (if provided). Implement clang_getCursor() in terms
of this traversal rather than using the Index library; the unified
cursor visitor is more complete, and will be The Way Forward.

Minor other tweaks needed to make this work:
  - Extend Preprocessor::getLocForEndOfToken() to accept an offset
  from the end, making it easy to move to the last character in the
  token (rather than just past the end of the token).
  - In Lexer::MeasureTokenLength(), the length of whitespace is zero.


Removed:
    cfe/trunk/test/Index/c-index-api-fn-scan.m
    cfe/trunk/test/Index/find-decls.c
    cfe/trunk/test/Index/find-defs.c
Modified:
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/Lex/Lexer.cpp
    cfe/trunk/lib/Lex/Preprocessor.cpp
    cfe/trunk/test/Index/TestClassDecl.m
    cfe/trunk/test/Index/TestClassForwardDecl.m
    cfe/trunk/test/Index/c-index-api-loadTU-test.m
    cfe/trunk/test/Index/c-index-getCursor-test.m
    cfe/trunk/tools/CIndex/CIndex.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=94200&r1=94199&r2=94200&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri Jan 22 13:49:59 2010
@@ -602,7 +602,12 @@
   /// the returned source location would not be meaningful (e.g., if
   /// it points into a macro), this routine returns an invalid
   /// source location.
-  SourceLocation getLocForEndOfToken(SourceLocation Loc);
+  ///
+  /// \param Offset an offset from the end of the token, where the source
+  /// location should refer to. The default offset (0) produces a source
+  /// location pointing just past the end of the token; an offset of 1 produces
+  /// a source location pointing to the last character in the token, etc.
+  SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0);
 
   /// DumpToken - Print the token to stderr, used for debugging.
   ///

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=94200&r1=94199&r2=94200&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Fri Jan 22 13:49:59 2010
@@ -629,9 +629,13 @@
 }
 
 SourceRange VarDecl::getSourceRange() const {
+  SourceLocation Start = getTypeSpecStartLoc();
+  if (Start.isInvalid())
+    Start = getLocation();
+  
   if (getInit())
-    return SourceRange(getLocation(), getInit()->getLocEnd());
-  return SourceRange(getLocation(), getLocation());
+    return SourceRange(Start, getInit()->getLocEnd());
+  return SourceRange(Start, getLocation());
 }
 
 bool VarDecl::isOutOfLine() const {

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=94200&r1=94199&r2=94200&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Fri Jan 22 13:49:59 2010
@@ -210,6 +210,7 @@
   }
 }
 
+static bool isWhitespace(unsigned char c);
 
 /// MeasureTokenLength - Relex the token at the specified location and return
 /// its length in bytes in the input file.  If the token needs cleaning (e.g.
@@ -231,6 +232,9 @@
   std::pair<const char *,const char *> Buffer = SM.getBufferData(LocInfo.first);
   const char *StrData = Buffer.first+LocInfo.second;
 
+  if (isWhitespace(StrData[0]))
+    return 0;
+
   // Create a lexer starting at the beginning of this token.
   Lexer TheLexer(Loc, LangOpts, Buffer.first, StrData, Buffer.second);
   TheLexer.SetCommentRetentionState(true);

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=94200&r1=94199&r2=94200&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Fri Jan 22 13:49:59 2010
@@ -429,21 +429,17 @@
   return TokStart.getFileLocWithOffset(PhysOffset);
 }
 
-/// \brief Computes the source location just past the end of the
-/// token at this source location.
-///
-/// This routine can be used to produce a source location that
-/// points just past the end of the token referenced by \p Loc, and
-/// is generally used when a diagnostic needs to point just after a
-/// token where it expected something different that it received. If
-/// the returned source location would not be meaningful (e.g., if
-/// it points into a macro), this routine returns an invalid
-/// source location.
-SourceLocation Preprocessor::getLocForEndOfToken(SourceLocation Loc) {
+SourceLocation Preprocessor::getLocForEndOfToken(SourceLocation Loc, 
+                                                 unsigned Offset) {
   if (Loc.isInvalid() || !Loc.isFileID())
     return SourceLocation();
 
   unsigned Len = Lexer::MeasureTokenLength(Loc, getSourceManager(), Features);
+  if (Len > Offset)
+    Len = Len - Offset;
+  else
+    return Loc;
+  
   return AdvanceToTokenCharacter(Loc, Len);
 }
 

Modified: cfe/trunk/test/Index/TestClassDecl.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/TestClassDecl.m?rev=94200&r1=94199&r2=94200&view=diff

==============================================================================
--- cfe/trunk/test/Index/TestClassDecl.m (original)
+++ cfe/trunk/test/Index/TestClassDecl.m Fri Jan 22 13:49:59 2010
@@ -17,22 +17,17 @@
 
 // CHECK-scan: {start_line=1 start_col=1 end_line=7 end_col=1} Invalid Cursor => NoDeclFound
 // CHECK-scan: {start_line=8 start_col=1 end_line=8 end_col=7} UnexposedDecl=:8:1
-// CHECK-scan: {start_line=8 start_col=8 end_line=8 end_col=10} ObjCClassRef=Foo:10:1
+// CHECK-scan: {start_line=8 start_col=8 end_line=8 end_col=10} ObjCClassRef=Foo:10:12
 // CHECK-scan: {start_line=8 start_col=11 end_line=9 end_col=1} Invalid Cursor => NoDeclFound
-// CHECK-scan: {start_line=10 start_col=1 end_line=11 end_col=4} ObjCInterfaceDecl=Foo:10:1
-// CHECK-scan: {start_line=11 start_col=5 end_line=12 end_col=1} Invalid Cursor => NoDeclFound
-// CHECK-scan: {start_line=13 start_col=1 end_line=13 end_col=4} FunctionDecl=function:13:6 (Definition)
-// CHECK-scan: {start_line=13 start_col=5 end_line=13 end_col=5} Invalid Cursor => NoDeclFound
+// CHECK-scan: {start_line=10 start_col=1 end_line=11 end_col=4} ObjCInterfaceDecl=Foo:10:12
+// CHECK-scan: {start_line=11 start_col=5 end_line=13 end_col=5} Invalid Cursor => NoDeclFound
 // CHECK-scan: {start_line=13 start_col=6 end_line=13 end_col=14} FunctionDecl=function:13:6 (Definition)
-// CHECK-scan: {start_line=13 start_col=15 end_line=13 end_col=17} ObjCClassRef=Foo:10:1
-// CHECK-scan: {start_line=13 start_col=18 end_line=13 end_col=18} FunctionDecl=function:13:6 (Definition)
-// CHECK-scan: {start_line=13 start_col=19 end_line=13 end_col=19} ParmDecl=arg:13:21
-// CHECK-scan: {start_line=13 start_col=20 end_line=13 end_col=20} FunctionDecl=function:13:6 (Definition)
-// CHECK-scan: {start_line=13 start_col=21 end_line=13 end_col=23} ParmDecl=arg:13:21
+// CHECK-scan: {start_line=13 start_col=15 end_line=13 end_col=17} ObjCClassRef=Foo:10:12
+// CHECK-scan: {start_line=13 start_col=18 end_line=13 end_col=23} ParmDecl=arg:13:21 (Definition)
+// CHECK-scan: {start_line=13 start_col=24 end_line=13 end_col=25} FunctionDecl=function:13:6 (Definition)
 // CHECK-scan: {start_line=14 start_col=1 end_line=16 end_col=1} UnexposedStmt=function
-// CHECK-scan: {start_line=16 start_col=2 end_line=38 end_col=1} Invalid Cursor => NoDeclFound
 
 // CHECK-load: TestClassDecl.m:10:12: ObjCInterfaceDecl=Foo:10:12 [Extent=10:1:11:4]
 // CHECK-load: TestClassDecl.m:13:6: FunctionDecl=function:13:6 (Definition) [Extent=13:6:16:1]
-// CHECK-load: TestClassDecl.m:13:21: ParmDecl=arg:13:21 (Definition) [Extent=13:21:13:23]
+// CHECK-load: TestClassDecl.m:13:21: ParmDecl=arg:13:21 (Definition) [Extent=13:15:13:23]
 

Modified: cfe/trunk/test/Index/TestClassForwardDecl.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/TestClassForwardDecl.m?rev=94200&r1=94199&r2=94200&view=diff

==============================================================================
--- cfe/trunk/test/Index/TestClassForwardDecl.m (original)
+++ cfe/trunk/test/Index/TestClassForwardDecl.m Fri Jan 22 13:49:59 2010
@@ -15,17 +15,12 @@
 // CHECK-scan: {start_line=1 start_col=1 end_line=7 end_col=1} Invalid Cursor => NoDeclFound
 // CHECK-scan: {start_line=8 start_col=1 end_line=8 end_col=7} UnexposedDecl=:8:1
 // CHECK-scan: {start_line=8 start_col=8 end_line=8 end_col=10} ObjCClassRef=Foo:8:8
-// CHECK-scan: {start_line=8 start_col=11 end_line=9 end_col=1} Invalid Cursor => NoDeclFound
-// CHECK-scan: {start_line=10 start_col=1 end_line=10 end_col=4} FunctionDecl=function:10:6 (Definition)
-// CHECK-scan: {start_line=10 start_col=5 end_line=10 end_col=5} Invalid Cursor => NoDeclFound
+// CHECK-scan: {start_line=8 start_col=11 end_line=10 end_col=5} Invalid Cursor => NoDeclFound
 // CHECK-scan: {start_line=10 start_col=6 end_line=10 end_col=14} FunctionDecl=function:10:6 (Definition)
 // CHECK-scan: {start_line=10 start_col=15 end_line=10 end_col=17} ObjCClassRef=Foo:8:8
-// CHECK-scan: {start_line=10 start_col=18 end_line=10 end_col=18} FunctionDecl=function:10:6 (Definition)
-// CHECK-scan: {start_line=10 start_col=19 end_line=10 end_col=19} ParmDecl=arg:10:21
-// CHECK-scan: {start_line=10 start_col=20 end_line=10 end_col=20} FunctionDecl=function:10:6 (Definition)
-// CHECK-scan: {start_line=10 start_col=21 end_line=10 end_col=23} ParmDecl=arg:10:21
+// CHECK-scan: {start_line=10 start_col=18 end_line=10 end_col=23} ParmDecl=arg:10:21 (Definition)
+// CHECK-scan: {start_line=10 start_col=24 end_line=10 end_col=25} FunctionDecl=function:10:6 (Definition)
 // CHECK-scan: {start_line=11 start_col=1 end_line=13 end_col=1} UnexposedStmt=function
-// CHECK-scan: {start_line=13 start_col=2 end_line=46 end_col=1} Invalid Cursor => NoDeclFound
 
 
 

Removed: cfe/trunk/test/Index/c-index-api-fn-scan.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/c-index-api-fn-scan.m?rev=94199&view=auto

==============================================================================
--- cfe/trunk/test/Index/c-index-api-fn-scan.m (original)
+++ cfe/trunk/test/Index/c-index-api-fn-scan.m (removed)
@@ -1,217 +0,0 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fblocks -emit-pch -x objective-c %s -o %t.ast
-// RUN: c-index-test -test-load-tu %t.ast scan-function | FileCheck %s
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- at interface Foo 
-{
-}
-
-- foo;
-+ fooC;
-
- at end
-
- at interface Bar : Foo 
-{
-}
-
- at end
-
- at interface Foo (FooCat)
-- (int) catMethodWithFloat:(float) fArg;
-- (float) floatMethod;
- at end
-
- at protocol Proto
-- pMethod;
- at end
-
- at protocol SubP <Proto>
-- spMethod;
- at end
-
- at interface Baz : Bar <SubP>
-{
-    int _anIVar;
-}
-
-- (Foo *) bazMethod;
-
- at end
-
-enum {
-  someEnum
-};
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-int main (int argc, const char * argv[]) {
-	Baz * bee;
-	id a = [bee foo];
-	id <SubP> c = [Foo fooC];
-	id <Proto> d;
-	d = c;
-	[d pMethod];
-	[bee catMethodWithFloat:[bee floatMethod]];
-  main(someEnum, (const char **)bee);
-}
-
-// CHECK: c-index-api-fn-scan.m:84:2: ObjCClassRef=Baz:48:1
-// CHECK: c-index-api-fn-scan.m:84:3: ObjCClassRef=Baz:48:1
-// CHECK: c-index-api-fn-scan.m:84:4: ObjCClassRef=Baz:48:1
-// CHECK: c-index-api-fn-scan.m:84:6: VarDecl=bee:84:8
-// CHECK: c-index-api-fn-scan.m:84:8: VarDecl=bee:84:8
-// CHECK: c-index-api-fn-scan.m:84:9: VarDecl=bee:84:8
-// CHECK: c-index-api-fn-scan.m:84:10: VarDecl=bee:84:8
-// CHECK: <invalid loc>:85:2: TypedefDecl=id:0:0
-// CHECK: <invalid loc>:85:3: TypedefDecl=id:0:0
-// CHECK: c-index-api-fn-scan.m:85:5: VarDecl=a:85:5
-// CHECK: c-index-api-fn-scan.m:85:6: VarDecl=a:85:5
-// CHECK: c-index-api-fn-scan.m:85:7: VarDecl=a:85:5
-// CHECK: c-index-api-fn-scan.m:85:8: VarDecl=a:85:5
-// CHECK: c-index-api-fn-scan.m:85:9: ObjCMessageExpr=foo:24:1
-// CHECK: c-index-api-fn-scan.m:85:10: DeclRefExpr=bee:84:8
-// CHECK: c-index-api-fn-scan.m:85:11: DeclRefExpr=bee:84:8
-// CHECK: c-index-api-fn-scan.m:85:12: DeclRefExpr=bee:84:8
-// CHECK: c-index-api-fn-scan.m:85:13: ObjCMessageExpr=foo:24:1
-// CHECK: c-index-api-fn-scan.m:85:14: ObjCMessageExpr=foo:24:1
-// CHECK: c-index-api-fn-scan.m:85:15: ObjCMessageExpr=foo:24:1
-// CHECK: c-index-api-fn-scan.m:85:16: ObjCMessageExpr=foo:24:1
-// CHECK: c-index-api-fn-scan.m:85:17: ObjCMessageExpr=foo:24:1
-// CHECK: <invalid loc>:86:2: TypedefDecl=id:0:0
-// CHECK: <invalid loc>:86:3: TypedefDecl=id:0:0
-// CHECK: c-index-api-fn-scan.m:86:5: VarDecl=c:86:12
-// CHECK: c-index-api-fn-scan.m:86:6: ObjCProtocolRef=SubP:44:1
-// CHECK: c-index-api-fn-scan.m:86:7: ObjCProtocolRef=SubP:44:1
-// CHECK: c-index-api-fn-scan.m:86:8: ObjCProtocolRef=SubP:44:1
-// CHECK: c-index-api-fn-scan.m:86:9: ObjCProtocolRef=SubP:44:1
-// CHECK: c-index-api-fn-scan.m:86:10: VarDecl=c:86:12
-// CHECK: c-index-api-fn-scan.m:86:12: VarDecl=c:86:12
-// CHECK: c-index-api-fn-scan.m:86:13: VarDecl=c:86:12
-// CHECK: c-index-api-fn-scan.m:86:14: VarDecl=c:86:12
-// CHECK: c-index-api-fn-scan.m:86:15: VarDecl=c:86:12
-// CHECK: c-index-api-fn-scan.m:86:16: ObjCMessageExpr=fooC:25:1
-// CHECK: c-index-api-fn-scan.m:86:17: ObjCMessageExpr=fooC:25:1
-// CHECK: c-index-api-fn-scan.m:86:18: ObjCMessageExpr=fooC:25:1
-// CHECK: c-index-api-fn-scan.m:86:19: ObjCMessageExpr=fooC:25:1
-// CHECK: c-index-api-fn-scan.m:86:20: ObjCMessageExpr=fooC:25:1
-// CHECK: c-index-api-fn-scan.m:86:21: ObjCMessageExpr=fooC:25:1
-// CHECK: c-index-api-fn-scan.m:86:22: ObjCMessageExpr=fooC:25:1
-// CHECK: c-index-api-fn-scan.m:86:23: ObjCMessageExpr=fooC:25:1
-// CHECK: c-index-api-fn-scan.m:86:24: ObjCMessageExpr=fooC:25:1
-// CHECK: c-index-api-fn-scan.m:86:25: ObjCMessageExpr=fooC:25:1
-// CHECK: <invalid loc>:87:2: TypedefDecl=id:0:0
-// CHECK: <invalid loc>:87:3: TypedefDecl=id:0:0
-// CHECK: c-index-api-fn-scan.m:87:5: VarDecl=d:87:13
-// CHECK: c-index-api-fn-scan.m:87:6: ObjCProtocolRef=Proto:40:1
-// CHECK: c-index-api-fn-scan.m:87:7: ObjCProtocolRef=Proto:40:1
-// CHECK: c-index-api-fn-scan.m:87:8: ObjCProtocolRef=Proto:40:1
-// CHECK: c-index-api-fn-scan.m:87:9: ObjCProtocolRef=Proto:40:1
-// CHECK: c-index-api-fn-scan.m:87:10: ObjCProtocolRef=Proto:40:1
-// CHECK: c-index-api-fn-scan.m:87:11: VarDecl=d:87:13
-// CHECK: c-index-api-fn-scan.m:87:13: VarDecl=d:87:13
-// CHECK: c-index-api-fn-scan.m:88:2: DeclRefExpr=d:87:13
-// CHECK: c-index-api-fn-scan.m:88:6: DeclRefExpr=c:86:12
-// CHECK: c-index-api-fn-scan.m:89:2: ObjCMessageExpr=pMethod:41:1
-// CHECK: c-index-api-fn-scan.m:89:3: DeclRefExpr=d:87:13
-// CHECK: c-index-api-fn-scan.m:89:4: ObjCMessageExpr=pMethod:41:1
-// CHECK: c-index-api-fn-scan.m:89:5: ObjCMessageExpr=pMethod:41:1
-// CHECK: c-index-api-fn-scan.m:89:6: ObjCMessageExpr=pMethod:41:1
-// CHECK: c-index-api-fn-scan.m:89:7: ObjCMessageExpr=pMethod:41:1
-// CHECK: c-index-api-fn-scan.m:89:8: ObjCMessageExpr=pMethod:41:1
-// CHECK: c-index-api-fn-scan.m:89:9: ObjCMessageExpr=pMethod:41:1
-// CHECK: c-index-api-fn-scan.m:89:10: ObjCMessageExpr=pMethod:41:1
-// CHECK: c-index-api-fn-scan.m:89:11: ObjCMessageExpr=pMethod:41:1
-// CHECK: c-index-api-fn-scan.m:89:12: ObjCMessageExpr=pMethod:41:1
-// CHECK: c-index-api-fn-scan.m:90:2: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:3: DeclRefExpr=bee:84:8
-// CHECK: c-index-api-fn-scan.m:90:4: DeclRefExpr=bee:84:8
-// CHECK: c-index-api-fn-scan.m:90:5: DeclRefExpr=bee:84:8
-// CHECK: c-index-api-fn-scan.m:90:6: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:7: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:8: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:9: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:10: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:11: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:12: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:13: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:14: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:15: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:16: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:17: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:18: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:19: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:20: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:21: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:22: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:23: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:24: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:25: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:90:26: ObjCMessageExpr=floatMethod:37:1
-// CHECK: c-index-api-fn-scan.m:90:27: DeclRefExpr=bee:84:8
-// CHECK: c-index-api-fn-scan.m:90:28: DeclRefExpr=bee:84:8
-// CHECK: c-index-api-fn-scan.m:90:29: DeclRefExpr=bee:84:8
-// CHECK: c-index-api-fn-scan.m:90:30: ObjCMessageExpr=floatMethod:37:1
-// CHECK: c-index-api-fn-scan.m:90:31: ObjCMessageExpr=floatMethod:37:1
-// CHECK: c-index-api-fn-scan.m:90:32: ObjCMessageExpr=floatMethod:37:1
-// CHECK: c-index-api-fn-scan.m:90:33: ObjCMessageExpr=floatMethod:37:1
-// CHECK: c-index-api-fn-scan.m:90:34: ObjCMessageExpr=floatMethod:37:1
-// CHECK: c-index-api-fn-scan.m:90:35: ObjCMessageExpr=floatMethod:37:1
-// CHECK: c-index-api-fn-scan.m:90:36: ObjCMessageExpr=floatMethod:37:1
-// CHECK: c-index-api-fn-scan.m:90:37: ObjCMessageExpr=floatMethod:37:1
-// CHECK: c-index-api-fn-scan.m:90:38: ObjCMessageExpr=floatMethod:37:1
-// CHECK: c-index-api-fn-scan.m:90:39: ObjCMessageExpr=floatMethod:37:1
-// CHECK: c-index-api-fn-scan.m:90:40: ObjCMessageExpr=floatMethod:37:1
-// CHECK: c-index-api-fn-scan.m:90:41: ObjCMessageExpr=floatMethod:37:1
-// CHECK: c-index-api-fn-scan.m:90:42: ObjCMessageExpr=floatMethod:37:1
-// CHECK: c-index-api-fn-scan.m:90:43: ObjCMessageExpr=catMethodWithFloat::36:1
-// CHECK: c-index-api-fn-scan.m:91:3: DeclRefExpr=main:83:5
-// CHECK: c-index-api-fn-scan.m:91:4: DeclRefExpr=main:83:5
-// CHECK: c-index-api-fn-scan.m:91:5: DeclRefExpr=main:83:5
-// CHECK: c-index-api-fn-scan.m:91:6: DeclRefExpr=main:83:5
-// CHECK: c-index-api-fn-scan.m:91:8: DeclRefExpr=someEnum:58:3
-// CHECK: c-index-api-fn-scan.m:91:9: DeclRefExpr=someEnum:58:3
-// CHECK: c-index-api-fn-scan.m:91:10: DeclRefExpr=someEnum:58:3
-// CHECK: c-index-api-fn-scan.m:91:11: DeclRefExpr=someEnum:58:3
-// CHECK: c-index-api-fn-scan.m:91:12: DeclRefExpr=someEnum:58:3
-// CHECK: c-index-api-fn-scan.m:91:13: DeclRefExpr=someEnum:58:3
-// CHECK: c-index-api-fn-scan.m:91:14: DeclRefExpr=someEnum:58:3
-// CHECK: c-index-api-fn-scan.m:91:15: DeclRefExpr=someEnum:58:3
-// CHECK: c-index-api-fn-scan.m:91:33: DeclRefExpr=bee:84:8
-// CHECK: c-index-api-fn-scan.m:91:34: DeclRefExpr=bee:84:8
-// CHECK: c-index-api-fn-scan.m:91:35: DeclRefExpr=bee:84:8

Modified: cfe/trunk/test/Index/c-index-api-loadTU-test.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/c-index-api-loadTU-test.m?rev=94200&r1=94199&r2=94200&view=diff

==============================================================================
--- cfe/trunk/test/Index/c-index-api-loadTU-test.m (original)
+++ cfe/trunk/test/Index/c-index-api-loadTU-test.m Fri Jan 22 13:49:59 2010
@@ -53,6 +53,22 @@
   main(someEnum, (const char **)bee);
 }
 
+// CHECK: <invalid loc>:0:0: TypedefDecl=__int128_t:0:0 (Definition)
+// CHECK: <invalid loc>:0:0: TypedefDecl=__uint128_t:0:0 (Definition)
+// CHECK: <invalid loc>:0:0: TypedefDecl=SEL:0:0 (Definition)
+// CHECK: <invalid loc>:0:0: TypeRef=SEL:0:0
+// CHECK: <invalid loc>:0:0: TypedefDecl=id:0:0 (Definition)
+// CHECK: <invalid loc>:0:0: TypedefDecl=Class:0:0 (Definition)
+// CHECK: <invalid loc>:87:16: StructDecl=__va_list_tag:87:16 (Definition)
+// CHECK: <invalid loc>:87:42: FieldDecl=gp_offset:87:42 (Definition)
+// CHECK: <invalid loc>:87:63: FieldDecl=fp_offset:87:63 (Definition)
+// CHECK: <invalid loc>:87:81: FieldDecl=overflow_arg_area:87:81 (Definition)
+// CHECK: <invalid loc>:87:107: FieldDecl=reg_save_area:87:107 (Definition)
+// CHECK: <invalid loc>:87:123: TypedefDecl=__va_list_tag:87:123 (Definition)
+// CHECK: <invalid loc>:87:9: TypeRef=struct __va_list_tag:87:16
+// CHECK: <invalid loc>:87:159: TypedefDecl=__builtin_va_list:87:159 (Definition)
+// CHECK: <invalid loc>:87:145: TypeRef=__va_list_tag:87:123
+// CHECK: <invalid loc>:87:177: UnexposedExpr=
 // CHECK: c-index-api-loadTU-test.m:4:12: ObjCInterfaceDecl=Foo:4:12 [Extent=4:1:11:4]
 // CHECK: c-index-api-loadTU-test.m:8:1: ObjCInstanceMethodDecl=foo:8:1 [Extent=8:1:8:6]
 // CHECK: c-index-api-loadTU-test.m:9:1: ObjCClassMethodDecl=fooC:9:1 [Extent=9:1:9:7]
@@ -61,6 +77,7 @@
 // CHECK: c-index-api-loadTU-test.m:19:12: ObjCCategoryDecl=FooCat:19:12 [Extent=19:1:22:4]
 // CHECK: c-index-api-loadTU-test.m:19:12: ObjCClassRef=Foo:4:12 [Extent=19:12:19:14]
 // CHECK: c-index-api-loadTU-test.m:20:1: ObjCInstanceMethodDecl=catMethodWithFloat::20:1 [Extent=20:1:20:40]
+// CHECK: c-index-api-loadTU-test.m:20:36: ParmDecl=fArg:20:36 (Definition) [Extent=20:29:20:39]
 // CHECK: c-index-api-loadTU-test.m:21:1: ObjCInstanceMethodDecl=floatMethod:21:1 [Extent=21:1:21:22]
 // CHECK: c-index-api-loadTU-test.m:24:1: ObjCProtocolDecl=Proto:24:1 (Definition) [Extent=24:1:26:4]
 // CHECK: c-index-api-loadTU-test.m:25:1: ObjCInstanceMethodDecl=pMethod:25:1 [Extent=25:1:25:10]
@@ -75,25 +92,25 @@
 // CHECK: c-index-api-loadTU-test.m:41:1: EnumDecl=:41:1 (Definition) [Extent=41:1:43:1]
 // CHECK: c-index-api-loadTU-test.m:42:3: EnumConstantDecl=someEnum:42:3 (Definition) [Extent=42:3:42:10]
 // CHECK: c-index-api-loadTU-test.m:45:5: FunctionDecl=main:45:5 (Definition) [Extent=45:5:54:1]
-// CHECK: c-index-api-loadTU-test.m:45:15: ParmDecl=argc:45:15 (Definition) [Extent=45:15:45:18]
-// CHECK: c-index-api-loadTU-test.m:45:34: ParmDecl=argv:45:34 (Definition) [Extent=45:34:45:37]
-// CHECK: c-index-api-loadTU-test.m:45:5: UnexposedStmt=main [Extent=45:5:54:1]
-// CHECK: c-index-api-loadTU-test.m:45:5: UnexposedStmt=main [Extent=45:5:54:1]
-// CHECK: c-index-api-loadTU-test.m:46:8: VarDecl=bee:46:8 (Definition) [Extent=46:8:46:10]
+// CHECK: c-index-api-loadTU-test.m:45:15: ParmDecl=argc:45:15 (Definition) [Extent=45:11:45:18]
+// CHECK: c-index-api-loadTU-test.m:45:34: ParmDecl=argv:45:34 (Definition) [Extent=45:27:45:37]
+// CHECK: c-index-api-loadTU-test.m:45:5: UnexposedStmt=main [Extent=45:42:54:1]
+// CHECK: c-index-api-loadTU-test.m:45:5: UnexposedStmt=main [Extent=46:2:46:11]
+// CHECK: c-index-api-loadTU-test.m:46:8: VarDecl=bee:46:8 (Definition) [Extent=46:2:46:10]
 // CHECK: c-index-api-loadTU-test.m:46:2: ObjCClassRef=Baz:32:12 [Extent=46:2:46:4]
-// CHECK: c-index-api-loadTU-test.m:46:8: UnexposedStmt=bee [Extent=46:8:46:10]
-// CHECK: c-index-api-loadTU-test.m:47:5: VarDecl=a:47:5 (Definition) [Extent=47:5:47:17]
+// CHECK: c-index-api-loadTU-test.m:46:8: UnexposedStmt=bee [Extent=47:2:47:18]
+// CHECK: c-index-api-loadTU-test.m:47:5: VarDecl=a:47:5 (Definition) [Extent=47:2:47:17]
 // CHECK: c-index-api-loadTU-test.m:47:2: TypeRef=id:0:0 [Extent=47:2:47:3]
 // CHECK: c-index-api-loadTU-test.m:47:9: ObjCMessageExpr=foo:8:1 [Extent=47:9:47:17]
 // CHECK: c-index-api-loadTU-test.m:47:10: DeclRefExpr=bee:46:8 [Extent=47:10:47:12]
-// CHECK: c-index-api-loadTU-test.m:47:5: UnexposedStmt=a [Extent=47:5:47:17]
-// CHECK: c-index-api-loadTU-test.m:48:12: VarDecl=c:48:12 (Definition) [Extent=48:12:48:25]
+// CHECK: c-index-api-loadTU-test.m:47:5: UnexposedStmt=a [Extent=48:2:48:26]
+// CHECK: c-index-api-loadTU-test.m:48:12: VarDecl=c:48:12 (Definition) [Extent=48:2:48:25]
 // CHECK: c-index-api-loadTU-test.m:48:2: TypeRef=id:0:0 [Extent=48:2:48:3]
 // CHECK: c-index-api-loadTU-test.m:48:6: ObjCProtocolRef=SubP:28:1 [Extent=48:6:48:9]
 // CHECK: c-index-api-loadTU-test.m:48:16: UnexposedExpr=fooC:9:1 [Extent=48:16:48:25]
 // CHECK: c-index-api-loadTU-test.m:48:16: ObjCMessageExpr=fooC:9:1 [Extent=48:16:48:25]
-// CHECK: c-index-api-loadTU-test.m:48:12: UnexposedStmt=c [Extent=48:12:48:25]
-// CHECK: c-index-api-loadTU-test.m:49:13: VarDecl=d:49:13 (Definition) [Extent=49:13:49:13]
+// CHECK: c-index-api-loadTU-test.m:48:12: UnexposedStmt=c [Extent=49:2:49:14]
+// CHECK: c-index-api-loadTU-test.m:49:13: VarDecl=d:49:13 (Definition) [Extent=49:2:49:13]
 // CHECK: c-index-api-loadTU-test.m:49:2: TypeRef=id:0:0 [Extent=49:2:49:3]
 // CHECK: c-index-api-loadTU-test.m:49:6: ObjCProtocolRef=Proto:24:1 [Extent=49:6:49:10]
 // CHECK: c-index-api-loadTU-test.m:50:2: UnexposedExpr= [Extent=50:2:50:6]

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=94200&r1=94199&r2=94200&view=diff

==============================================================================
--- cfe/trunk/test/Index/c-index-getCursor-test.m (original)
+++ cfe/trunk/test/Index/c-index-getCursor-test.m Fri Jan 22 13:49:59 2010
@@ -59,13 +59,15 @@
 // CHECK: {start_line=8 start_col=1 end_line=8 end_col=7} ObjCClassMethodDecl=fooC:8:1
 // CHECK: {start_line=8 start_col=8 end_line=10 end_col=4} ObjCInterfaceDecl=Foo:3:12
 // CHECK: {start_line=10 start_col=5 end_line=11 end_col=1} Invalid Cursor => NoDeclFound
-// CHECK: {start_line=12 start_col=1 end_line=16 end_col=4} ObjCInterfaceDecl=Bar:12:12
+// CHECK: {start_line=12 start_col=1 end_line=12 end_col=17} ObjCInterfaceDecl=Bar:12:12
+// CHECK: {start_line=12 start_col=18 end_line=12 end_col=20} ObjCSuperClassRef=Foo:3:12
+// CHECK: {start_line=12 start_col=21 end_line=16 end_col=4} ObjCInterfaceDecl=Bar:12:12
 // CHECK: {start_line=16 start_col=5 end_line=17 end_col=1} Invalid Cursor => NoDeclFound
-// CHECK: {start_line=18 start_col=1 end_line=18 end_col=24} ObjCCategoryDecl=FooCat:18:12
+// CHECK: {start_line=18 start_col=1 end_line=18 end_col=11} ObjCCategoryDecl=FooCat:18:12
+// CHECK: {start_line=18 start_col=12 end_line=18 end_col=14} ObjCClassRef=Foo:3:12
+// CHECK: {start_line=18 start_col=15 end_line=18 end_col=24} ObjCCategoryDecl=FooCat:18:12
 // CHECK: {start_line=19 start_col=1 end_line=19 end_col=28} ObjCInstanceMethodDecl=catMethodWithFloat::19:1
-// CHECK: {start_line=19 start_col=29 end_line=19 end_col=33} ParmDecl=fArg:19:36 (Definition)
-// CHECK: {start_line=19 start_col=34 end_line=19 end_col=35} ObjCInstanceMethodDecl=catMethodWithFloat::19:1
-// CHECK: {start_line=19 start_col=36 end_line=19 end_col=39} ParmDecl=fArg:19:36 (Definition)
+// CHECK: {start_line=19 start_col=29 end_line=19 end_col=39} ParmDecl=fArg:19:36 (Definition)
 // CHECK: {start_line=19 start_col=40 end_line=19 end_col=40} ObjCInstanceMethodDecl=catMethodWithFloat::19:1
 // CHECK: {start_line=19 start_col=41 end_line=19 end_col=41} ObjCCategoryDecl=FooCat:18:12
 // CHECK: {start_line=20 start_col=1 end_line=20 end_col=22} ObjCInstanceMethodDecl=floatMethod:20:1
@@ -75,13 +77,17 @@
 // CHECK: {start_line=24 start_col=1 end_line=24 end_col=10} ObjCInstanceMethodDecl=pMethod:24:1
 // CHECK: {start_line=24 start_col=11 end_line=25 end_col=4} ObjCProtocolDecl=Proto:23:1 (Definition)
 // CHECK: {start_line=25 start_col=5 end_line=26 end_col=1} Invalid Cursor => NoDeclFound
-// CHECK: {start_line=27 start_col=1 end_line=27 end_col=23} ObjCProtocolDecl=SubP:27:1 (Definition)
+// CHECK: {start_line=27 start_col=1 end_line=27 end_col=16} ObjCProtocolDecl=SubP:27:1 (Definition)
+// CHECK: {start_line=27 start_col=17 end_line=27 end_col=21} ObjCProtocolRef=Proto:23:1
+// CHECK: {start_line=27 start_col=22 end_line=27 end_col=23} ObjCProtocolDecl=SubP:27:1 (Definition)
 // CHECK: {start_line=28 start_col=1 end_line=28 end_col=11} ObjCInstanceMethodDecl=spMethod:28:1
 // CHECK: {start_line=28 start_col=12 end_line=29 end_col=4} ObjCProtocolDecl=SubP:27:1 (Definition)
 // CHECK: {start_line=29 start_col=5 end_line=30 end_col=1} Invalid Cursor => NoDeclFound
-// CHECK: {start_line=31 start_col=1 end_line=33 end_col=4} ObjCInterfaceDecl=Baz:31:12
-// CHECK: {start_line=33 start_col=5 end_line=33 end_col=7} ObjCIvarDecl=_anIVar:33:9 (Definition)
-// CHECK: {start_line=33 start_col=8 end_line=33 end_col=8} ObjCInterfaceDecl=Baz:31:12
+// CHECK: {start_line=31 start_col=1 end_line=31 end_col=17} ObjCInterfaceDecl=Baz:31:12
+// CHECK: {start_line=31 start_col=18 end_line=31 end_col=20} ObjCSuperClassRef=Bar:12:12
+// CHECK: {start_line=31 start_col=21 end_line=31 end_col=22} ObjCInterfaceDecl=Baz:31:12
+// CHECK: {start_line=31 start_col=23 end_line=31 end_col=26} ObjCProtocolRef=SubP:27:1
+// CHECK: {start_line=31 start_col=27 end_line=33 end_col=8} ObjCInterfaceDecl=Baz:31:12
 // CHECK: {start_line=33 start_col=9 end_line=33 end_col=15} ObjCIvarDecl=_anIVar:33:9 (Definition)
 // CHECK: {start_line=33 start_col=16 end_line=35 end_col=1} ObjCInterfaceDecl=Baz:31:12
 // CHECK: {start_line=36 start_col=1 end_line=36 end_col=20} ObjCInstanceMethodDecl=bazMethod:36:1
@@ -90,53 +96,35 @@
 // CHECK: {start_line=40 start_col=1 end_line=41 end_col=2} EnumDecl=:40:1 (Definition)
 // CHECK: {start_line=41 start_col=3 end_line=41 end_col=10} EnumConstantDecl=someEnum:41:3 (Definition)
 // CHECK: {start_line=41 start_col=11 end_line=42 end_col=1} EnumDecl=:40:1 (Definition)
-// CHECK: {start_line=42 start_col=2 end_line=43 end_col=1} Invalid Cursor => NoDeclFound
-// CHECK: {start_line=44 start_col=1 end_line=44 end_col=3} FunctionDecl=main:44:5 (Definition)
-// CHECK: {start_line=44 start_col=4 end_line=44 end_col=4} Invalid Cursor => NoDeclFound
+// CHECK: {start_line=42 start_col=2 end_line=44 end_col=4} Invalid Cursor => NoDeclFound
 // CHECK: {start_line=44 start_col=5 end_line=44 end_col=10} FunctionDecl=main:44:5 (Definition)
-// CHECK: {start_line=44 start_col=11 end_line=44 end_col=13} ParmDecl=argc:44:15 (Definition)
-// CHECK: {start_line=44 start_col=14 end_line=44 end_col=14} FunctionDecl=main:44:5 (Definition)
-// CHECK: {start_line=44 start_col=15 end_line=44 end_col=18} ParmDecl=argc:44:15 (Definition)
+// CHECK: {start_line=44 start_col=11 end_line=44 end_col=18} ParmDecl=argc:44:15 (Definition)
 // CHECK: {start_line=44 start_col=19 end_line=44 end_col=26} FunctionDecl=main:44:5 (Definition)
-// CHECK: {start_line=44 start_col=27 end_line=44 end_col=30} ParmDecl=argv:44:34 (Definition)
-// CHECK: {start_line=44 start_col=31 end_line=44 end_col=31} FunctionDecl=main:44:5 (Definition)
-// CHECK: {start_line=44 start_col=32 end_line=44 end_col=32} ParmDecl=argv:44:34 (Definition)
-// CHECK: {start_line=44 start_col=33 end_line=44 end_col=33} FunctionDecl=main:44:5 (Definition)
-// CHECK: {start_line=44 start_col=34 end_line=44 end_col=39} ParmDecl=argv:44:34 (Definition)
-// CHECK: {start_line=44 start_col=40 end_line=44 end_col=41} FunctionDecl=main:44:5 (Definition)
+// CHECK: {start_line=44 start_col=27 end_line=44 end_col=37} ParmDecl=argv:44:34 (Definition)
+// CHECK: {start_line=44 start_col=38 end_line=44 end_col=41} FunctionDecl=main:44:5 (Definition)
 // CHECK: {start_line=44 start_col=42 end_line=45 end_col=1} UnexposedStmt=main
 // CHECK: {start_line=45 start_col=2 end_line=45 end_col=4} ObjCClassRef=Baz:31:12
-// CHECK: {start_line=45 start_col=5 end_line=45 end_col=5} UnexposedStmt=main
-// CHECK: {start_line=45 start_col=6 end_line=45 end_col=6} VarDecl=bee:45:8 (Definition)
-// CHECK: {start_line=45 start_col=7 end_line=45 end_col=7} UnexposedStmt=main
-// CHECK: {start_line=45 start_col=8 end_line=45 end_col=10} VarDecl=bee:45:8 (Definition)
+// CHECK: {start_line=45 start_col=5 end_line=45 end_col=10} VarDecl=bee:45:8 (Definition)
 // CHECK: {start_line=45 start_col=11 end_line=45 end_col=11} UnexposedStmt=main
 // CHECK: {start_line=45 start_col=12 end_line=46 end_col=1} UnexposedStmt=main
-// CHECK: {start_line=46 start_col=2 end_line=46 end_col=3} TypedefDecl=id:0:0 (Definition)
-// CHECK: {start_line=46 start_col=4 end_line=46 end_col=4} UnexposedStmt=main
-// CHECK: {start_line=46 start_col=5 end_line=46 end_col=8} VarDecl=a:46:5 (Definition)
+// CHECK: {start_line=46 start_col=2 end_line=46 end_col=3} TypeRef=id:0:0
+// CHECK: {start_line=46 start_col=4 end_line=46 end_col=8} VarDecl=a:46:5 (Definition)
 // CHECK: {start_line=46 start_col=9 end_line=46 end_col=9} ObjCMessageExpr=foo:7:1
 // CHECK: {start_line=46 start_col=10 end_line=46 end_col=12} DeclRefExpr=bee:45:8
 // CHECK: {start_line=46 start_col=13 end_line=46 end_col=17} ObjCMessageExpr=foo:7:1
 // CHECK: {start_line=46 start_col=18 end_line=46 end_col=18} UnexposedStmt=main
 // CHECK: {start_line=46 start_col=19 end_line=47 end_col=1} UnexposedStmt=main
-// CHECK: {start_line=47 start_col=2 end_line=47 end_col=3} TypedefDecl=id:0:0 (Definition)
-// CHECK: {start_line=47 start_col=4 end_line=47 end_col=4} UnexposedStmt=main
-// CHECK: {start_line=47 start_col=5 end_line=47 end_col=5} VarDecl=c:47:12 (Definition)
+// CHECK: {start_line=47 start_col=2 end_line=47 end_col=3} TypeRef=id:0:0
+// CHECK: {start_line=47 start_col=4 end_line=47 end_col=5} VarDecl=c:47:12 (Definition)
 // CHECK: {start_line=47 start_col=6 end_line=47 end_col=9} ObjCProtocolRef=SubP:27:1
-// CHECK: {start_line=47 start_col=10 end_line=47 end_col=10} VarDecl=c:47:12 (Definition)
-// CHECK: {start_line=47 start_col=11 end_line=47 end_col=11} UnexposedStmt=main
-// CHECK: {start_line=47 start_col=12 end_line=47 end_col=15} VarDecl=c:47:12 (Definition)
+// CHECK: {start_line=47 start_col=10 end_line=47 end_col=15} VarDecl=c:47:12 (Definition)
 // CHECK: {start_line=47 start_col=16 end_line=47 end_col=25} ObjCMessageExpr=fooC:8:1
 // CHECK: {start_line=47 start_col=26 end_line=47 end_col=26} UnexposedStmt=main
 // CHECK: {start_line=47 start_col=27 end_line=48 end_col=1} UnexposedStmt=main
-// CHECK: {start_line=48 start_col=2 end_line=48 end_col=3} TypedefDecl=id:0:0 (Definition)
-// CHECK: {start_line=48 start_col=4 end_line=48 end_col=4} UnexposedStmt=main
-// CHECK: {start_line=48 start_col=5 end_line=48 end_col=5} VarDecl=d:48:13 (Definition)
+// CHECK: {start_line=48 start_col=2 end_line=48 end_col=3} TypeRef=id:0:0
+// CHECK: {start_line=48 start_col=4 end_line=48 end_col=5} VarDecl=d:48:13 (Definition)
 // CHECK: {start_line=48 start_col=6 end_line=48 end_col=10} ObjCProtocolRef=Proto:23:1
-// CHECK: {start_line=48 start_col=11 end_line=48 end_col=11} VarDecl=d:48:13 (Definition)
-// CHECK: {start_line=48 start_col=12 end_line=48 end_col=12} UnexposedStmt=main
-// CHECK: {start_line=48 start_col=13 end_line=48 end_col=13} VarDecl=d:48:13 (Definition)
+// CHECK: {start_line=48 start_col=11 end_line=48 end_col=13} VarDecl=d:48:13 (Definition)
 // CHECK: {start_line=48 start_col=14 end_line=48 end_col=14} UnexposedStmt=main
 // CHECK: {start_line=48 start_col=15 end_line=49 end_col=1} UnexposedStmt=main
 // CHECK: {start_line=49 start_col=2 end_line=49 end_col=2} DeclRefExpr=d:48:13
@@ -163,4 +151,3 @@
 // CHECK: {start_line=52 start_col=33 end_line=52 end_col=35} DeclRefExpr=bee:45:8
 // CHECK: {start_line=52 start_col=36 end_line=52 end_col=36} CallExpr=main:44:5
 // CHECK: {start_line=52 start_col=37 end_line=53 end_col=1} UnexposedStmt=main
-

Removed: cfe/trunk/test/Index/find-decls.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/find-decls.c?rev=94199&view=auto

==============================================================================
--- cfe/trunk/test/Index/find-decls.c (original)
+++ cfe/trunk/test/Index/find-decls.c (removed)
@@ -1,25 +0,0 @@
-// RUN: %clang_cc1 -fblocks -emit-pch %S/Inputs/t1.c -o %t1.ast
-// RUN: %clang_cc1 -fblocks -emit-pch %S/Inputs/t2.c -o %t2.ast
-
-// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/t1.c:8:7 -print-decls > %t
-// RUN: cat %t | count 3
-// RUN: grep 'foo.h:4:6,' %t | count 2
-// RUN: grep 't2.c:5:6,' %t
-
-// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/t1.c:5:47 -print-decls > %t
-// RUN: cat %t | count 1
-// RUN: grep 't1.c:5:12,' %t
-
-// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/t1.c:6:20 -print-decls > %t
-// RUN: cat %t | count 1
-// RUN: grep 't1.c:3:19,' %t
-
-// field test
-
-// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/t1.c:21:6 -print-decls > %t
-// RUN: cat %t | count 1
-// RUN: grep 't1.c:12:7,' %t
-
-// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/t1.c:22:21 -print-decls > %t
-// RUN: cat %t | count 1
-// RUN: grep 't1.c:16:7,' %t

Removed: cfe/trunk/test/Index/find-defs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/find-defs.c?rev=94199&view=auto

==============================================================================
--- cfe/trunk/test/Index/find-defs.c (original)
+++ cfe/trunk/test/Index/find-defs.c (removed)
@@ -1,18 +0,0 @@
-// RUN: %clang_cc1 -fblocks -emit-pch %S/Inputs/t1.c -o %t1.ast
-// RUN: %clang_cc1 -fblocks -emit-pch %S/Inputs/t2.c -o %t2.ast
-
-// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/foo.h:1:14 -print-defs > %t
-// RUN: cat %t | count 1
-// RUN: grep 't2.c:3:5,' %t
-
-// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/foo.h:3:9 -print-defs > %t
-// RUN: cat %t | count 1
-// RUN: grep 't1.c:3:6,' %t
-
-// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/foo.h:4:9 -print-defs > %t
-// RUN: cat %t | count 1
-// RUN: grep 't2.c:5:6,' %t
-
-// RUN: index-test %t1.ast %t2.ast -point-at %S/Inputs/t1.c:8:7 -print-defs > %t
-// RUN: cat %t | count 1
-// RUN: grep 't2.c:5:6,' %t

Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=94200&r1=94199&r2=94200&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Fri Jan 22 13:49:59 2010
@@ -19,6 +19,7 @@
 #include "clang/AST/StmtVisitor.h"
 #include "clang/AST/TypeLocVisitor.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/System/Program.h"
 
@@ -133,9 +134,40 @@
   return Result;
 }
 
+static SourceRange translateSourceRange(CXSourceRange R) {
+  return SourceRange(SourceLocation::getFromRawEncoding(R.begin_int_data),
+                     SourceLocation::getFromRawEncoding(R.end_int_data));
+}
+
+/// \brief The result of comparing two source ranges.
+enum RangeComparisonResult {
+  /// \brief Either the ranges overlap or one of the ranges is invalid.
+  RangeOverlap,
+  
+  /// \brief The first range ends before the second range starts.
+  RangeBefore,
+  
+  /// \brief The first range starts after the second range ends.
+  RangeAfter
+};
+
+/// \brief Compare two source ranges to determine their relative position in 
+/// the translation unit.
+static RangeComparisonResult RangeCompare(SourceManager &SM, 
+                                          SourceRange R1, 
+                                          SourceRange R2) {
+  assert(R1.isValid() && "First range is invalid?");
+  assert(R2.isValid() && "Second range is invalid?");
+  if (SM.isBeforeInTranslationUnit(R1.getEnd(), R2.getBegin()))
+    return RangeBefore;
+  if (SM.isBeforeInTranslationUnit(R2.getEnd(), R1.getBegin()))
+    return RangeAfter;
+  return RangeOverlap;
+}
+
 
 //===----------------------------------------------------------------------===//
-// Visitors.
+// Cursor visitor.
 //===----------------------------------------------------------------------===//
 
 namespace {
@@ -145,25 +177,53 @@
                       public TypeLocVisitor<CursorVisitor, bool>,
                       public StmtVisitor<CursorVisitor, bool>
 {
+  /// \brief The translation unit we are traversing.
   ASTUnit *TU;
+  
+  /// \brief The parent cursor whose children we are traversing.
   CXCursor Parent;
+  
+  /// \brief The declaration that serves at the parent of any statement or
+  /// expression nodes.
   Decl *StmtParent;
+  
+  /// \brief The visitor function.
   CXCursorVisitor Visitor;
+  
+  /// \brief The opaque client data, to be passed along to the visitor.
   CXClientData ClientData;
-
+  
   // MaxPCHLevel - the maximum PCH level of declarations that we will pass on
   // to the visitor. Declarations with a PCH level greater than this value will
   // be suppressed.
   unsigned MaxPCHLevel;
-  
+
+  /// \brief When valid, a source range to which the cursor should restrict
+  /// its search.
+  SourceRange RegionOfInterest;
+    
   using DeclVisitor<CursorVisitor, bool>::Visit;
   using TypeLocVisitor<CursorVisitor, bool>::Visit;
   using StmtVisitor<CursorVisitor, bool>::Visit;
+    
+  /// \brief Determine whether this particular source range comes before, comes 
+  /// after, or overlaps the region of interest. 
+  ///
+  /// \param R a source range retrieved from the abstract syntax tree.
+  RangeComparisonResult CompareRegionOfInterest(SourceRange R); 
+  
+  /// \brief Determine whether this particular source range comes before, comes 
+  /// after, or overlaps the region of interest. 
+  ///
+  /// \param CXR a source range retrieved from a cursor.
+  RangeComparisonResult CompareRegionOfInterest(CXSourceRange CXR); 
   
 public:
   CursorVisitor(ASTUnit *TU, CXCursorVisitor Visitor, CXClientData ClientData, 
-                unsigned MaxPCHLevel)
-    : TU(TU), Visitor(Visitor), ClientData(ClientData), MaxPCHLevel(MaxPCHLevel)
+                unsigned MaxPCHLevel, 
+                SourceRange RegionOfInterest = SourceRange())
+    : TU(TU), Visitor(Visitor), ClientData(ClientData), 
+      MaxPCHLevel(MaxPCHLevel), RegionOfInterest(RegionOfInterest)
   {
     Parent.kind = CXCursor_NoDeclFound;
     Parent.data[0] = 0;
@@ -172,7 +232,7 @@
     StmtParent = 0;
   }
   
-  bool Visit(CXCursor Cursor);
+  bool Visit(CXCursor Cursor, bool CheckedRegionOfInterest = false);
   bool VisitChildren(CXCursor Parent);
   
   // Declaration visitors
@@ -231,12 +291,32 @@
   
 } // end anonymous namespace
 
+RangeComparisonResult CursorVisitor::CompareRegionOfInterest(SourceRange R) {
+  assert(RegionOfInterest.isValid() && "RangeCompare called with invalid range");
+  if (R.isInvalid())
+    return RangeOverlap;
+
+  // Move the end of the input range to the end of the last token in that
+  // range.
+  R.setEnd(TU->getPreprocessor().getLocForEndOfToken(R.getEnd(), 1));
+  return RangeCompare(TU->getSourceManager(), R, RegionOfInterest);
+}
+
+RangeComparisonResult CursorVisitor::CompareRegionOfInterest(CXSourceRange CXR) {
+  return CompareRegionOfInterest(translateSourceRange(CXR));
+}
+
 /// \brief Visit the given cursor and, if requested by the visitor,
 /// its children.
 ///
+/// \param Cursor the cursor to visit.
+///
+/// \param CheckRegionOfInterest if true, then the caller already checked that
+/// this cursor is within the region of interest.
+///
 /// \returns true if the visitation should be aborted, false if it
 /// should continue.
-bool CursorVisitor::Visit(CXCursor Cursor) {
+bool CursorVisitor::Visit(CXCursor Cursor, bool CheckedRegionOfInterest) {
   if (clang_isInvalid(Cursor.kind))
     return false;
   
@@ -250,6 +330,15 @@
       return false;
   }
 
+  // If we have a range of interest, and this cursor doesn't intersect with it,
+  // we're done.
+  if (RegionOfInterest.isValid() && !CheckedRegionOfInterest) {
+    CXSourceRange Range = clang_getCursorExtent(Cursor);
+    if (translateSourceRange(Range).isInvalid() || 
+        CompareRegionOfInterest(Range))
+      return false;
+  }
+  
   switch (Visitor(Cursor, Parent, ClientData)) {
   case CXChildVisit_Break:
     return true;
@@ -310,11 +399,12 @@
   
   if (clang_isTranslationUnit(Cursor.kind)) {
     ASTUnit *CXXUnit = getCursorASTUnit(Cursor);
-    if (!CXXUnit->isMainFileAST() && CXXUnit->getOnlyLocalDecls()) {
+    if (!CXXUnit->isMainFileAST() && CXXUnit->getOnlyLocalDecls() &&
+        RegionOfInterest.isInvalid()) {
       const std::vector<Decl*> &TLDs = CXXUnit->getTopLevelDecls();
       for (std::vector<Decl*>::const_iterator it = TLDs.begin(),
            ie = TLDs.end(); it != ie; ++it) {
-        if (Visit(MakeCXCursor(*it, CXXUnit)))
+        if (Visit(MakeCXCursor(*it, CXXUnit), true))
           return true;
       }
     } else {
@@ -332,7 +422,27 @@
 bool CursorVisitor::VisitDeclContext(DeclContext *DC) {
   for (DeclContext::decl_iterator
        I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) {
-    if (Visit(MakeCXCursor(*I, TU)))
+    if (RegionOfInterest.isValid()) {
+      SourceRange R = (*I)->getSourceRange();
+      if (R.isInvalid())
+        continue;
+      
+      switch (CompareRegionOfInterest(R)) {
+      case RangeBefore:
+        // This declaration comes before the region of interest; skip it.
+        continue;
+      
+      case RangeAfter:
+        // This declaration comes after the region of interest; we're done.
+        return false;
+      
+      case RangeOverlap:
+        // This declaration overlaps the region of interest; visit it.
+        break;
+      }      
+    }
+    
+    if (Visit(MakeCXCursor(*I, TU), true))
       return true;
   }
   
@@ -1131,6 +1241,14 @@
   return NULL;
 }
 
+enum CXChildVisitResult GetCursorVisitor(CXCursor cursor, 
+                                         CXCursor parent, 
+                                         CXClientData client_data) {
+  CXCursor *BestCursor = static_cast<CXCursor *>(client_data);
+  *BestCursor = cursor;
+  return CXChildVisit_Recurse;
+}
+  
 CXCursor clang_getCursor(CXTranslationUnit CTUnit, const char *source_name,
                          unsigned line, unsigned column) {
   assert(CTUnit && "Passed null CXTranslationUnit");
@@ -1144,32 +1262,21 @@
 
   SourceLocation SLoc =
     CXXUnit->getSourceManager().getLocation(File, line, column);
-
-  ASTLocation LastLoc = CXXUnit->getLastASTLocation();
-  ASTLocation ALoc = ResolveLocationInAST(CXXUnit->getASTContext(), SLoc,
-                                          &LastLoc);
-  
-  // FIXME: This doesn't look thread-safe.
-  if (ALoc.isValid())
-    CXXUnit->setLastASTLocation(ALoc);
-
-  Decl *Dcl = ALoc.getParentDecl();
-  if (ALoc.isNamedRef())
-    Dcl = ALoc.AsNamedRef().ND;
-  Stmt *Stm = ALoc.dyn_AsStmt();
-  if (Dcl) {
-    if (Stm)
-      return MakeCXCursor(Stm, Dcl, CXXUnit);
-
-    if (ALoc.isNamedRef()) {
-      if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(Dcl))
-        return MakeCursorObjCClassRef(Class, ALoc.AsNamedRef().Loc, CXXUnit);
-      if (ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(Dcl))
-        return MakeCursorObjCProtocolRef(Proto, ALoc.AsNamedRef().Loc, CXXUnit);
-    }
-    return MakeCXCursor(Dcl, CXXUnit);
+  
+  CXCursor Result = MakeCXCursorInvalid(CXCursor_NoDeclFound);
+  if (SLoc.isValid()) {
+    SourceRange RegionOfInterest(SLoc, 
+                       CXXUnit->getPreprocessor().getLocForEndOfToken(SLoc, 1));
+    
+    // FIXME: Would be great to have a "hint" cursor, then walk from that
+    // hint cursor upward until we find a cursor whose source range encloses
+    // the region of interest, rather than starting from the translation unit.
+    CXCursor Parent = clang_getTranslationUnitCursor(CXXUnit);
+    CursorVisitor CursorVis(CXXUnit, GetCursorVisitor, &Result, 
+                            Decl::MaxPCHLevel, RegionOfInterest);
+    CursorVis.VisitChildren(Parent);
   }
-  return MakeCXCursorInvalid(CXCursor_NoDeclFound);
+  return Result;  
 }
 
 CXCursor clang_getNullCursor(void) {
@@ -1304,6 +1411,10 @@
   if (clang_isExpression(C.kind))
     return translateSourceRange(getCursorContext(C), 
                                 getCursorExpr(C)->getSourceRange());
+
+  if (clang_isStatement(C.kind))
+    return translateSourceRange(getCursorContext(C), 
+                                getCursorStmt(C)->getSourceRange());
   
   if (!getCursorDecl(C)) {
     CXSourceRange empty = { 0, 0, 0 };





More information about the cfe-commits mailing list