diff options
-rw-r--r-- | clang/include/clang-c/Index.h | 8 | ||||
-rw-r--r-- | clang/tools/c-index-test/c-index-test.c | 21 | ||||
-rw-r--r-- | clang/tools/libclang/IndexBody.cpp | 6 | ||||
-rw-r--r-- | clang/tools/libclang/IndexingContext.cpp | 2 | ||||
-rw-r--r-- | clang/tools/libclang/IndexingContext.h | 4 |
5 files changed, 31 insertions, 10 deletions
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 92315a387f5..588d93a9328 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -4455,7 +4455,13 @@ typedef enum { * for only one reference of an entity per source file that does not also * include a declaration/definition of the entity. */ - CXIndexOpt_SuppressRedundantRefs = 0x1 + CXIndexOpt_SuppressRedundantRefs = 0x1, + + /** + * \brief Function-local symbols should be indexed. If this is not set + * function-local symbols will be ignored. + */ + CXIndexOpt_IndexFunctionLocalSymbols = 0x2 } CXIndexOptFlags; /** diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index d46f2dc4998..03eeb511cd6 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -1911,6 +1911,17 @@ static IndexerCallbacks IndexCB = { index_indexEntityReference }; +static unsigned getIndexOptions(void) { + unsigned index_opts; + index_opts = 0; + if (getenv("CINDEXTEST_SUPPRESSREFS")) + index_opts |= CXIndexOpt_SuppressRedundantRefs; + if (getenv("CINDEXTEST_INDEXLOCALSYMBOLS")) + index_opts |= CXIndexOpt_IndexFunctionLocalSymbols; + + return index_opts; +} + static int index_file(int argc, const char **argv) { const char *check_prefix; CXIndex Idx; @@ -1946,10 +1957,7 @@ static int index_file(int argc, const char **argv) { index_data.fail_for_error = 0; index_data.abort = 0; - index_opts = 0; - if (getenv("CINDEXTEST_SUPPRESSREFS")) - index_opts |= CXIndexOpt_SuppressRedundantRefs; - + index_opts = getIndexOptions(); idxAction = clang_IndexAction_create(Idx); result = clang_indexSourceFile(idxAction, &index_data, &IndexCB,sizeof(IndexCB), index_opts, @@ -2001,10 +2009,7 @@ static int index_tu(int argc, const char **argv) { index_data.fail_for_error = 0; index_data.abort = 0; - index_opts = 0; - if (getenv("CINDEXTEST_SUPPRESSREFS")) - index_opts |= CXIndexOpt_SuppressRedundantRefs; - + index_opts = getIndexOptions(); idxAction = clang_IndexAction_create(Idx); result = clang_indexTranslationUnit(idxAction, &index_data, &IndexCB,sizeof(IndexCB), diff --git a/clang/tools/libclang/IndexBody.cpp b/clang/tools/libclang/IndexBody.cpp index 177cad7ccaa..6dd45af814a 100644 --- a/clang/tools/libclang/IndexBody.cpp +++ b/clang/tools/libclang/IndexBody.cpp @@ -84,6 +84,12 @@ public: Parent, ParentDC, E); return true; } + + bool VisitDeclStmt(DeclStmt *S) { + if (IndexCtx.indexFunctionLocalSymbols()) + IndexCtx.indexDeclGroupRef(S->getDeclGroup()); + return true; + } }; } // anonymous namespace diff --git a/clang/tools/libclang/IndexingContext.cpp b/clang/tools/libclang/IndexingContext.cpp index 14dbc970025..f731580e665 100644 --- a/clang/tools/libclang/IndexingContext.cpp +++ b/clang/tools/libclang/IndexingContext.cpp @@ -551,7 +551,7 @@ bool IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc, return false; if (Loc.isInvalid()) return false; - if (D->getParentFunctionOrMethod()) + if (!indexFunctionLocalSymbols() && D->getParentFunctionOrMethod()) return false; if (isNotFromSourceFile(D->getLocation())) return false; diff --git a/clang/tools/libclang/IndexingContext.h b/clang/tools/libclang/IndexingContext.h index b58e3b690e8..4a321204a8c 100644 --- a/clang/tools/libclang/IndexingContext.h +++ b/clang/tools/libclang/IndexingContext.h @@ -324,6 +324,10 @@ public: return IndexOptions & CXIndexOpt_SuppressRedundantRefs; } + bool indexFunctionLocalSymbols() const { + return IndexOptions & CXIndexOpt_IndexFunctionLocalSymbols; + } + bool shouldAbort(); bool hasDiagnosticCallback() const { return CB.diagnostic; } |