Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -328,11 +328,11 @@ def : Joined<["-"], "objcmt-white-list-dir-path=">, Flags<[CC1Option]>, Alias; -def index_store_path : Separate<["-"], "index-store-path">, Flags<[CC1Option]>, +def index_store_path : Separate<["-"], "index-store-path">, Flags<[CoreOption,CC1Option]>, HelpText<"Enable indexing with the specified data store path">; -def index_ignore_system_symbols : Flag<["-"], "index-ignore-system-symbols">, Flags<[CC1Option]>, +def index_ignore_system_symbols : Flag<["-"], "index-ignore-system-symbols">, Flags<[CoreOption,CC1Option]>, HelpText<"Ignore symbols from system headers">; -def index_record_codegen_name : Flag<["-"], "index-record-codegen-name">, Flags<[CC1Option]>, +def index_record_codegen_name : Flag<["-"], "index-record-codegen-name">, Flags<[CoreOption,CC1Option]>, HelpText<"Record the codegen name for symbols">; // Make sure all other -ccc- options are rejected. Index: include/clang/Index/IndexDataStore.h =================================================================== --- include/clang/Index/IndexDataStore.h +++ include/clang/Index/IndexDataStore.h @@ -14,6 +14,8 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" + +#include #include #include #include Index: include/indexstore/IndexStoreCXX.h =================================================================== --- include/indexstore/IndexStoreCXX.h +++ include/indexstore/IndexStoreCXX.h @@ -86,14 +86,15 @@ uint64_t getRoles() { return indexstore_occurrence_get_roles(obj); } bool foreachRelation(llvm::function_ref receiver) { -#if INDEXSTORE_HAS_BLOCKS return indexstore_occurrence_relations_apply( - obj, ^bool(indexstore_symbol_relation_t sym_rel) { - return receiver(sym_rel); - }); + obj, +#if INDEXSTORE_HAS_BLOCKS + ^bool(indexstore_symbol_relation_t sym_rel) { #else - return false; + [receiver](indexstore_symbol_relation_t sym_rel) { #endif + return receiver(sym_rel); + }); } std::pair getLineCol() { @@ -141,14 +142,15 @@ bool foreachUnit(bool sorted, llvm::function_ref receiver) { -#if INDEXSTORE_HAS_BLOCKS return indexstore_store_units_apply( - obj, sorted, ^bool(indexstore_string_ref_t unit_name) { - return receiver(stringFromIndexStoreStringRef(unit_name)); - }); + obj, sorted, +#if INDEXSTORE_HAS_BLOCKS + ^bool(indexstore_string_ref_t unit_name) { #else - return false; + [receiver](indexstore_string_ref_t unit_name) { #endif + return receiver(stringFromIndexStoreStringRef(unit_name)); + }); } class UnitEvent { @@ -215,17 +217,20 @@ typedef std::function UnitEventHandler; void setUnitEventHandler(UnitEventHandler handler) { -#if INDEXSTORE_HAS_BLOCKS if (!handler) { indexstore_store_set_unit_event_handler(obj, nullptr); return; } indexstore_store_set_unit_event_handler( - obj, ^(indexstore_unit_event_notification_t evt_note) { + obj, +#if INDEXSTORE_HAS_BLOCKS + ^(indexstore_unit_event_notification_t evt_note) { +#else + [handler](indexstore_unit_event_notification_t evt_note) { +#endif handler(UnitEventNotification(evt_note)); }); -#endif } bool startEventListening(bool waitInitialSync, std::string &error) { @@ -332,20 +337,26 @@ receiver(symbol); }); #else - return false; + return indexstore_record_reader_search_symbols( + obj, + [filter](indexstore_symbol_t symbol, bool *stop) { + return filter(symbol, *stop); + }, + [receiver](indexstore_symbol_t symbol) { receiver(symbol); }); #endif } bool foreachSymbol(bool noCache, llvm::function_ref receiver) { -#if INDEXSTORE_HAS_BLOCKS return indexstore_record_reader_symbols_apply( - obj, noCache, ^bool(indexstore_symbol_t sym) { - return receiver(sym); - }); + obj, noCache, +#if INDEXSTORE_HAS_BLOCKS + ^bool(indexstore_symbol_t sym) { #else - return false; + [receiver](indexstore_symbol_t sym) { #endif + return receiver(sym); + }); } /// \param DeclsFilter if non-empty indicates the list of decls that we want @@ -356,7 +367,6 @@ foreachOccurrence(ArrayRef symbolsFilter, ArrayRef relatedSymbolsFilter, llvm::function_ref receiver) { -#if INDEXSTORE_HAS_BLOCKS llvm::SmallVector c_symbolsFilter; c_symbolsFilter.reserve(symbolsFilter.size()); for (IndexRecordSymbol sym : symbolsFilter) { @@ -367,27 +377,30 @@ for (IndexRecordSymbol sym : relatedSymbolsFilter) { c_relatedSymbolsFilter.push_back(sym.obj); } + return indexstore_record_reader_occurrences_of_symbols_apply( obj, c_symbolsFilter.data(), c_symbolsFilter.size(), c_relatedSymbolsFilter.data(), c_relatedSymbolsFilter.size(), +#if INDEXSTORE_HAS_BLOCKS ^bool(indexstore_occurrence_t occur) { - return receiver(occur); - }); #else - return false; + [receiver](indexstore_occurrence_t occur) { #endif + return receiver(occur); + }); } bool foreachOccurrence(llvm::function_ref receiver) { -#if INDEXSTORE_HAS_BLOCKS return indexstore_record_reader_occurrences_apply( - obj, ^bool(indexstore_occurrence_t occur) { - return receiver(occur); - }); + obj, +#if INDEXSTORE_HAS_BLOCKS + ^bool(indexstore_occurrence_t occur) { #else - return false; + [receiver](indexstore_occurrence_t occur) { #endif + return receiver(occur); + }); } bool foreachOccurrenceInLineRange( @@ -399,7 +412,9 @@ return receiver(occur); }); #else - return false; + return indexstore_record_reader_occurrences_in_line_range_apply( + obj, lineStart, lineEnd, + [receiver](indexstore_occurrence_t occur) { return receiver(occur); }); #endif } }; @@ -541,25 +556,27 @@ bool foreachDependency(llvm::function_ref receiver) { -#if INDEXSTORE_HAS_BLOCKS return indexstore_unit_reader_dependencies_apply( - obj, ^bool(indexstore_unit_dependency_t dep) { - return receiver(dep); - }); + obj, +#if INDEXSTORE_HAS_BLOCKS + ^bool(indexstore_unit_dependency_t dep) { #else - return false; + [receiver](indexstore_unit_dependency_t dep) { #endif + return receiver(dep); + }); } bool foreachInclude(llvm::function_ref receiver) { -#if INDEXSTORE_HAS_BLOCKS return indexstore_unit_reader_includes_apply( - obj, ^bool(indexstore_unit_include_t inc) { - return receiver(inc); - }); + obj, +#if INDEXSTORE_HAS_BLOCKS + ^bool(indexstore_unit_include_t inc) { #else - return false; + [receiver](indexstore_unit_include_t inc) { #endif + return receiver(inc); + }); } }; Index: include/indexstore/indexstore.h =================================================================== --- include/indexstore/indexstore.h +++ include/indexstore/indexstore.h @@ -14,6 +14,8 @@ #ifndef LLVM_CLANG_C_INDEXSTORE_INDEXSTORE_H #define LLVM_CLANG_C_INDEXSTORE_INDEXSTORE_H +#include "llvm/ADT/STLExtras.h" + #include #include #include @@ -49,7 +51,11 @@ #ifndef INDEXSTORE_PUBLIC #if defined(_MSC_VER) -#define INDEXSTORE_PUBLIC __declspec(dllimport) +#ifdef _INDEXSTORE_LIB_ + #define INDEXSTORE_PUBLIC __declspec(dllexport) +#else + #define INDEXSTORE_PUBLIC __declspec(dllimport) +#endif #else #define INDEXSTORE_PUBLIC #endif @@ -88,10 +94,12 @@ INDEXSTORE_PUBLIC void indexstore_store_dispose(indexstore_t store); -#if INDEXSTORE_HAS_BLOCKS INDEXSTORE_PUBLIC bool indexstore_store_units_apply( indexstore_t, unsigned sorted, +#if INDEXSTORE_HAS_BLOCKS bool (^applier)(indexstore_string_ref_t unit_name)); +#else + llvm::function_ref applier); #endif typedef void *indexstore_unit_event_notification_t; @@ -129,6 +137,13 @@ INDEXSTORE_PUBLIC void indexstore_store_set_unit_event_handler( indexstore_t store, indexstore_unit_event_handler_t handler); +#else +typedef std::function +indexstore_unit_event_handler_t; + +INDEXSTORE_PUBLIC void indexstore_store_set_unit_event_handler( + indexstore_t store, + llvm::function_ref handler); #endif typedef struct { @@ -294,10 +309,12 @@ INDEXSTORE_PUBLIC indexstore_symbol_t indexstore_occurrence_get_symbol(indexstore_occurrence_t occur); -#if INDEXSTORE_HAS_BLOCKS INDEXSTORE_PUBLIC bool indexstore_occurrence_relations_apply( indexstore_occurrence_t occur, +#if INDEXSTORE_HAS_BLOCKS bool (^applier)(indexstore_symbol_relation_t relation)); +#else + llvm::function_ref applier); #endif INDEXSTORE_PUBLIC uint64_t @@ -315,7 +332,6 @@ INDEXSTORE_PUBLIC void indexstore_record_reader_dispose(indexstore_record_reader_t reader); -#if INDEXSTORE_HAS_BLOCKS /// Goes through the symbol data and passes symbols to \c receiver, for the /// symbol data that \c filter returns true on. /// @@ -323,23 +339,40 @@ /// interested in. INDEXSTORE_PUBLIC bool indexstore_record_reader_search_symbols( indexstore_record_reader_t reader, +#if INDEXSTORE_HAS_BLOCKS bool (^filter)(indexstore_symbol_t symbol, bool *stop), void (^receiver)(indexstore_symbol_t symbol)); +#else + llvm::function_ref filter, + llvm::function_ref receiver); +#endif /// \param nocache if true, avoids allocating memory for the symbols. /// Useful when the caller does not intend to keep \c indexstore_record_reader_t /// for more queries. INDEXSTORE_PUBLIC bool indexstore_record_reader_symbols_apply( indexstore_record_reader_t reader, bool nocache, +#if INDEXSTORE_HAS_BLOCKS bool (^applier)(indexstore_symbol_t symbol)); +#else + llvm::function_ref applier); +#endif INDEXSTORE_PUBLIC bool indexstore_record_reader_occurrences_apply( indexstore_record_reader_t reader, +#if INDEXSTORE_HAS_BLOCKS bool (^applier)(indexstore_occurrence_t occur)); +#else + llvm::function_ref applier); +#endif INDEXSTORE_PUBLIC bool indexstore_record_reader_occurrences_in_line_range_apply( indexstore_record_reader_t reader, unsigned line_start, unsigned line_count, +#if INDEXSTORE_HAS_BLOCKS bool (^applier)(indexstore_occurrence_t occur)); +#else + llvm::function_ref applier); +#endif /// \param symbols if non-zero \c symbols_count, indicates the list of symbols /// that we want to get occurrences for. An empty array indicates that we want @@ -349,7 +382,10 @@ indexstore_record_reader_t reader, indexstore_symbol_t *symbols, size_t symbols_count, indexstore_symbol_t *related_symbols, size_t related_symbols_count, +#if INDEXSTORE_HAS_BLOCKS bool (^applier)(indexstore_occurrence_t occur)); +#else + llvm::function_ref applier); #endif typedef void *indexstore_unit_reader_t; @@ -438,15 +474,20 @@ INDEXSTORE_PUBLIC unsigned indexstore_unit_include_get_source_line(indexstore_unit_include_t dep); -#if INDEXSTORE_HAS_BLOCKS INDEXSTORE_PUBLIC bool indexstore_unit_reader_dependencies_apply( indexstore_unit_reader_t reader, +#if INDEXSTORE_HAS_BLOCKS bool (^applier)(indexstore_unit_dependency_t dep)); +#else + llvm::function_ref applier); +#endif INDEXSTORE_PUBLIC bool indexstore_unit_reader_includes_apply( indexstore_unit_reader_t reader, +#if INDEXSTORE_HAS_BLOCKS bool (^applier)(indexstore_unit_include_t include)); - +#else + llvm::function_ref applier); #endif INDEXSTORE_END_DECLS Index: lib/Index/IndexUnitReader.cpp =================================================================== --- lib/Index/IndexUnitReader.cpp +++ lib/Index/IndexUnitReader.cpp @@ -21,7 +21,11 @@ #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +#if !defined(_MSC_VER) && !defined(__MINGW32__) #include +#else +#include +#endif using namespace clang; using namespace clang::index; Index: tools/IndexStore/CMakeLists.txt =================================================================== --- tools/IndexStore/CMakeLists.txt +++ tools/IndexStore/CMakeLists.txt @@ -23,9 +23,6 @@ set(output_name "IndexStore") endif() -# FIXME: needs to be ported to non-Apple platforms. -if(APPLE) - add_clang_library(IndexStore ${ENABLE_SHARED} ${ENABLE_STATIC} OUTPUT_NAME ${output_name} ${SOURCES} @@ -46,7 +43,7 @@ set_target_properties(IndexStore PROPERTIES VERSION ${INDEXSTORE_LIBRARY_VERSION} - DEFINE_SYMBOL _CINDEX_LIB_) + DEFINE_SYMBOL _INDEXSTORE_LIB_) elseif(APPLE) set(INDEXSTORE_LINK_FLAGS " -Wl,-compatibility_version -Wl,1") set(INDEXSTORE_LINK_FLAGS "${INDEXSTORE_LINK_FLAGS} -Wl,-current_version -Wl,${INDEXSTORE_LIBRARY_VERSION}") @@ -62,7 +59,7 @@ set_target_properties(IndexStore PROPERTIES VERSION ${INDEXSTORE_LIBRARY_VERSION} - DEFINE_SYMBOL _CINDEX_LIB_) + DEFINE_SYMBOL _INDEXSTORE_LIB_) endif() endif() @@ -91,4 +88,3 @@ PATTERN "*.h" PATTERN ".svn" EXCLUDE ) -endif() Index: tools/IndexStore/IndexStore.cpp =================================================================== --- tools/IndexStore/IndexStore.cpp +++ tools/IndexStore/IndexStore.cpp @@ -22,7 +22,10 @@ #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/Chrono.h" + +#if INDEXSTORE_HAS_BLOCKS #include +#endif using namespace clang; using namespace clang::index; @@ -81,10 +84,13 @@ delete static_cast(store); } -#if INDEXSTORE_HAS_BLOCKS bool indexstore_store_units_apply( indexstore_t c_store, unsigned sorted, +#if INDEXSTORE_HAS_BLOCKS bool (^applier)(indexstore_string_ref_t unit_name)) { +#else + llvm::function_ref applier) { +#endif IndexDataStore *store = static_cast(c_store); return store->foreachUnitName(sorted, [&](StringRef unitName) -> bool { return applier(toIndexStoreString(unitName)); @@ -158,12 +164,11 @@ public: BlockWrapper(indexstore_unit_event_handler_t handler) { - blk_handler = Block_copy(handler); + blk_handler = handler; } BlockWrapper(const BlockWrapper &other) { - blk_handler = Block_copy(other.blk_handler); + blk_handler = other.blk_handler; } - ~BlockWrapper() { Block_release(blk_handler); } void operator()(indexstore_unit_event_notification_t evt_note) const { blk_handler(evt_note); @@ -177,7 +182,6 @@ handler(&evtNote); }); } -#endif bool indexstore_store_start_unit_event_listening( indexstore_t c_store, indexstore_unit_event_listen_options_t *client_opts, @@ -286,10 +290,13 @@ return (indexstore_symbol_t) static_cast(occur)->Dcl; } -#if INDEXSTORE_HAS_BLOCKS bool indexstore_occurrence_relations_apply( indexstore_occurrence_t occur, +#if INDEXSTORE_HAS_BLOCKS bool (^applier)(indexstore_symbol_relation_t symbol_rel)) { +#else + llvm::function_ref applier) { +#endif auto *recOccur = static_cast(occur); for (auto &rel : recOccur->Relations) { if (!applier(&rel)) @@ -297,7 +304,6 @@ } return true; } -#endif uint64_t indexstore_occurrence_get_roles(indexstore_occurrence_t occur) { return static_cast(occur)->Roles; @@ -335,7 +341,6 @@ delete reader; } -#if INDEXSTORE_HAS_BLOCKS /// Goes through the symbol data and passes symbols to \c receiver, for the /// symbol data that \c filter returns true on. /// @@ -343,8 +348,13 @@ /// interested in. bool indexstore_record_reader_search_symbols( indexstore_record_reader_t rdr, +#if INDEXSTORE_HAS_BLOCKS bool (^filter)(indexstore_symbol_t symbol, bool *stop), void (^receiver)(indexstore_symbol_t symbol)) { +#else + llvm::function_ref filter, + llvm::function_ref receiver) { +#endif auto *reader = static_cast(rdr); auto filterFn = @@ -362,7 +372,11 @@ bool indexstore_record_reader_symbols_apply( indexstore_record_reader_t rdr, bool nocache, +#if INDEXSTORE_HAS_BLOCKS bool (^applier)(indexstore_symbol_t symbol)) { +#else + llvm::function_ref applier) { +#endif auto *reader = static_cast(rdr); auto receiverFn = [&](const IndexRecordDecl *D) -> bool { return applier((indexstore_symbol_t)D); @@ -372,7 +386,11 @@ bool indexstore_record_reader_occurrences_apply( indexstore_record_reader_t rdr, +#if INDEXSTORE_HAS_BLOCKS bool (^applier)(indexstore_occurrence_t occur)) { +#else + llvm::function_ref applier) { +#endif auto *reader = static_cast(rdr); auto receiverFn = [&](const IndexRecordOccurrence &RO) -> bool { return applier((indexstore_occurrence_t)&RO); @@ -382,7 +400,11 @@ bool indexstore_record_reader_occurrences_in_line_range_apply( indexstore_record_reader_t rdr, unsigned line_start, unsigned line_count, +#if INDEXSTORE_HAS_BLOCKS bool (^applier)(indexstore_occurrence_t occur)) { +#else + llvm::function_ref applier) { +#endif auto *reader = static_cast(rdr); auto receiverFn = [&](const IndexRecordOccurrence &RO) -> bool { return applier((indexstore_occurrence_t)&RO); @@ -399,7 +421,11 @@ indexstore_record_reader_t rdr, indexstore_symbol_t *symbols, size_t symbols_count, indexstore_symbol_t *related_symbols, size_t related_symbols_count, +#if INDEXSTORE_HAS_BLOCKS bool (^applier)(indexstore_occurrence_t occur)) { +#else + llvm::function_ref applier) { +#endif auto *reader = static_cast(rdr); auto receiverFn = [&](const IndexRecordOccurrence &RO) -> bool { return applier((indexstore_occurrence_t)&RO); @@ -408,7 +434,6 @@ {(IndexRecordDecl **)symbols, symbols_count}, {(IndexRecordDecl **)related_symbols, related_symbols_count}, receiverFn); } -#endif size_t indexstore_store_get_unit_name_from_output_path(indexstore_t store, const char *output_path, @@ -417,7 +442,7 @@ SmallString<256> unitName; IndexUnitWriter::getUnitNameForAbsoluteOutputFile(output_path, unitName); size_t nameLen = unitName.size(); - strlcpy(name_buf, unitName.c_str(), buf_size); + strncpy(name_buf, unitName.c_str(), buf_size); return nameLen; } @@ -614,10 +639,13 @@ return inc->SourceLine; } -#if INDEXSTORE_HAS_BLOCKS bool indexstore_unit_reader_dependencies_apply( indexstore_unit_reader_t rdr, +#if INDEXSTORE_HAS_BLOCKS bool (^applier)(indexstore_unit_dependency_t)) { +#else + llvm::function_ref applier) { +#endif auto reader = static_cast(rdr); return reader->foreachDependency( [&](const IndexUnitReader::DependencyInfo &depInfo) -> bool { @@ -626,11 +654,15 @@ } bool indexstore_unit_reader_includes_apply( - indexstore_unit_reader_t rdr, bool (^applier)(indexstore_unit_include_t)) { + indexstore_unit_reader_t rdr, +#if INDEXSTORE_HAS_BLOCKS + bool (^applier)(indexstore_unit_include_t)) { +#else + llvm::function_ref applier) { +#endif auto reader = static_cast(rdr); return reader->foreachInclude( [&](const IndexUnitReader::IncludeInfo &incInfo) -> bool { return applier((void *)&incInfo); }); } -#endif Index: tools/c-index-test/CMakeLists.txt =================================================================== --- tools/c-index-test/CMakeLists.txt +++ tools/c-index-test/CMakeLists.txt @@ -12,9 +12,7 @@ set(INDEXSTORE_LIB) set(CINDEXTEST_LIBS) -if(APPLE) - set(INDEXSTORE_LIB IndexStore) -endif() +set(INDEXSTORE_LIB IndexStore) if(NOT MSVC) set_property( Index: tools/c-index-test/JSONAggregation.cpp =================================================================== --- tools/c-index-test/JSONAggregation.cpp +++ tools/c-index-test/JSONAggregation.cpp @@ -20,8 +20,6 @@ using namespace indexstore; using namespace llvm; -#if INDEXSTORE_HAS_BLOCKS - namespace { typedef size_t FilePathIndex; @@ -412,10 +410,3 @@ aggregator->dumpJSON(OS); return false; } - -#else - -bool index::aggregateDataAsJSON(StringRef StorePath, raw_ostream &OS) { - return true; -} -#endif Index: tools/c-index-test/core_main.cpp =================================================================== --- tools/c-index-test/core_main.cpp +++ tools/c-index-test/core_main.cpp @@ -446,8 +446,6 @@ return !Unit; } -#if INDEXSTORE_HAS_BLOCKS - //===----------------------------------------------------------------------===// // Print Record //===----------------------------------------------------------------------===// @@ -750,20 +748,6 @@ return !Success; } -#else - -static int printUnit(StringRef Filename, raw_ostream &OS) { return 1; } - -static int printStoreUnits(StringRef StorePath, raw_ostream &OS) { return 1; } - -static int printStoreFileRecord(StringRef storePath, StringRef filePath, - Optional lineStart, - unsigned lineCount, raw_ostream &OS) { - return 1; -} - -#endif - //===----------------------------------------------------------------------===// // Helper Utils //===----------------------------------------------------------------------===// @@ -795,8 +779,6 @@ } } -#if INDEXSTORE_HAS_BLOCKS - static void printSymbol(const IndexRecordDecl &Rec, raw_ostream &OS) { printSymbolInfo(Rec.SymInfo, OS); OS << " | "; @@ -925,13 +907,6 @@ }); } -#else - -static int printRecord(StringRef Filename, raw_ostream &OS) { return 1; } -static int printStoreRecords(StringRef StorePath, raw_ostream &OS) { return 1; } - -#endif - static int watchDirectory(StringRef dirPath) { raw_ostream &OS = outs(); auto receiver = [&](ArrayRef Events, @@ -1084,11 +1059,9 @@ return printUnit(options::InputFiles[0], outs()); } -#if INDEXSTORE_HAS_BLOCKS if (options::Action == ActionType::PrintStoreFormatVersion) { outs() << indexstore::IndexStore::formatVersion() << '\n'; } -#endif if (options::Action == ActionType::AggregateAsJSON) { if (options::InputFiles.empty()) {