]> granicus.if.org Git - clang/commitdiff
[libclang] Add CXIndexOpt_IndexFunctionLocalSymbols indexing option to indicate
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 14 Jan 2012 00:11:49 +0000 (00:11 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 14 Jan 2012 00:11:49 +0000 (00:11 +0000)
that one wants indexing callbacks for function-local symbols as well.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148160 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang-c/Index.h
tools/c-index-test/c-index-test.c
tools/libclang/IndexBody.cpp
tools/libclang/IndexingContext.cpp
tools/libclang/IndexingContext.h

index 92315a387f50c3726b8150663deabbb4efb5ad15..588d93a932895e51ab24563ad525ba2966342747 100644 (file)
@@ -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;
 
 /**
index d46f2dc4998abb189d5be2c1b1e1844f58810c32..03eeb511cd66cd24e667d0245a184f35addea5ee 100644 (file)
@@ -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),
index 177cad7ccaaf0cf096bbb447c85af0d165d12141..6dd45af814a9f898a9ed39421e255be98cb3afb3 100644 (file)
@@ -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
index 14dbc97002548cde858999f79ee73520babcc3da..f731580e6658b91d3d56f3fa1d673dc2d7d5759b 100644 (file)
@@ -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;
index b58e3b690e850640914edb1d5654d0b977702ed2..4a321204a8c6125c1beccc70a1d948632bb34444 100644 (file)
@@ -324,6 +324,10 @@ public:
     return IndexOptions & CXIndexOpt_SuppressRedundantRefs;
   }
 
+  bool indexFunctionLocalSymbols() const {
+    return IndexOptions & CXIndexOpt_IndexFunctionLocalSymbols;
+  }
+
   bool shouldAbort();
 
   bool hasDiagnosticCallback() const { return CB.diagnostic; }