diff options
-rw-r--r-- | clang/test/Index/load-exprs.c | 13 | ||||
-rw-r--r-- | clang/tools/CIndex/CIndex.cpp | 32 |
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) { |