summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-01-23 00:40:08 +0000
committerDouglas Gregor <dgregor@apple.com>2010-01-23 00:40:08 +0000
commit625a515120c6237386371ffe3a2afa82c7a83c62 (patch)
tree8de6d6bc374cadcef9b600ed6bcdbb2acb420b8b
parent4c823ba3588b56180cb4879c941218711c1bff08 (diff)
downloadbcm5719-llvm-625a515120c6237386371ffe3a2afa82c7a83c62.tar.gz
bcm5719-llvm-625a515120c6237386371ffe3a2afa82c7a83c62.zip
Teach the cursor visitor to recurse into the type information of
explicit casts, sizeof, alignof, and compound literals. llvm-svn: 94265
-rw-r--r--clang/test/Index/load-exprs.c13
-rw-r--r--clang/tools/CIndex/CIndex.cpp32
2 files changed, 45 insertions, 0 deletions
diff --git a/clang/test/Index/load-exprs.c b/clang/test/Index/load-exprs.c
new file mode 100644
index 00000000000..a360efd755a
--- /dev/null
+++ b/clang/test/Index/load-exprs.c
@@ -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"
diff --git a/clang/tools/CIndex/CIndex.cpp b/clang/tools/CIndex/CIndex.cpp
index 6cd545f53f4..a9889621c7d 100644
--- a/clang/tools/CIndex/CIndex.cpp
+++ b/clang/tools/CIndex/CIndex.cpp
@@ -292,6 +292,11 @@ public:
// 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 @@ bool CursorVisitor::VisitSwitchStmt(SwitchStmt *S) {
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) {
OpenPOWER on IntegriCloud