[cfe-commits] r94265 - in /cfe/trunk: test/Index/load-exprs.c tools/CIndex/CIndex.cpp

Douglas Gregor dgregor at apple.com
Fri Jan 22 16:40:08 PST 2010


Author: dgregor
Date: Fri Jan 22 18:40:08 2010
New Revision: 94265

URL: http://llvm.org/viewvc/llvm-project?rev=94265&view=rev
Log:
Teach the cursor visitor to recurse into the type information of
explicit casts, sizeof, alignof, and compound literals.

Added:
    cfe/trunk/test/Index/load-exprs.c
Modified:
    cfe/trunk/tools/CIndex/CIndex.cpp

Added: cfe/trunk/test/Index/load-exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/load-exprs.c?rev=94265&view=auto

==============================================================================
--- cfe/trunk/test/Index/load-exprs.c (added)
+++ cfe/trunk/test/Index/load-exprs.c Fri Jan 22 18:40:08 2010
@@ -0,0 +1,13 @@
+typedef int T;
+struct X { int a, b; };
+void f(void *ptr) {
+  T* t_ptr = (T *)ptr;
+  (void)sizeof(T);
+  struct X x = (struct X){1, 2};
+}
+
+// RUN: c-index-test -test-load-source all %s | FileCheck %s
+
+// CHECK: load-exprs.c:4:15: TypeRef=T:1:13 [Extent=4:15:4:15]
+// CHECK: load-exprs.c:5:16: TypeRef=T:1:13 [Extent=5:16:5:16]
+// FIXME: the source location for "struct X" points at "struct", not "X"

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

==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Fri Jan 22 18:40:08 2010
@@ -292,6 +292,11 @@
   // FIXME: LabelStmt label?
   bool VisitIfStmt(IfStmt *S);
   bool VisitSwitchStmt(SwitchStmt *S);
+  
+  // Expression visitors
+  bool VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
+  bool VisitExplicitCastExpr(ExplicitCastExpr *E);
+  bool VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
 };
   
 } // end anonymous namespace
@@ -824,6 +829,33 @@
   return false;
 }
 
+bool CursorVisitor::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
+  if (E->isArgumentType()) {
+    if (TypeSourceInfo *TSInfo = E->getArgumentTypeInfo())
+      return Visit(TSInfo->getTypeLoc());
+    
+    return false;
+  }
+  
+  return VisitExpr(E);
+}
+
+bool CursorVisitor::VisitExplicitCastExpr(ExplicitCastExpr *E) {
+  if (TypeSourceInfo *TSInfo = E->getTypeInfoAsWritten())
+    if (Visit(TSInfo->getTypeLoc()))
+      return true;
+  
+  return VisitCastExpr(E);
+}
+
+bool CursorVisitor::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
+  if (TypeSourceInfo *TSInfo = E->getTypeSourceInfo())
+    if (Visit(TSInfo->getTypeLoc()))
+      return true;
+  
+  return VisitExpr(E);
+}
+
 CXString CIndexer::createCXString(const char *String, bool DupString){
   CXString Str;
   if (DupString) {





More information about the cfe-commits mailing list