Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/swift-4.0-branch' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-ci committed Jun 29, 2017
2 parents e6e0195 + 678b2be commit 04f4347
Show file tree
Hide file tree
Showing 86 changed files with 9,123 additions and 31 deletions.
4 changes: 4 additions & 0 deletions include/clang/Basic/DiagnosticFrontendKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ def err_modules_embed_file_not_found :
Error<"file '%0' specified by '-fmodules-embed-file=' not found">,
DefaultFatal;

def remark_index_producing_module_file_data : Remark<"producing index data for "
"module file '%0'">,
InGroup<IndexStore>;

def err_test_module_file_extension_version : Error<
"test module file extension '%0' has different version (%1.%2) than expected "
"(%3.%4)">;
Expand Down
1 change: 1 addition & 0 deletions include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ def MissingFieldInitializers : DiagGroup<"missing-field-initializers">;
def ModuleBuild : DiagGroup<"module-build">;
def ModuleConflict : DiagGroup<"module-conflict">;
def ModuleFileExtension : DiagGroup<"module-file-extension">;
def IndexStore : DiagGroup<"index-store">;
def NewlineEOF : DiagGroup<"newline-eof">;
def Nullability : DiagGroup<"nullability">;
def NullabilityDeclSpec : DiagGroup<"nullability-declspec">;
Expand Down
47 changes: 47 additions & 0 deletions include/clang/DirectoryWatcher/DirectoryWatcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//===- DirectoryWatcher.h - Listens for directory file changes --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
/// \file
/// \brief Utility class for listening for file system changes in a directory.
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_DIRECTORYWATCHER_DIRECTORYWATCHER_H
#define LLVM_CLANG_DIRECTORYWATCHER_DIRECTORYWATCHER_H

#include "clang/Basic/LLVM.h"
#include "clang/Index/IndexDataStore.h"
#include <functional>
#include <memory>
#include <string>

namespace clang {

/// Provides notifications for file system changes in a directory.
///
/// Guarantees that the first time the directory is processed, the receiver will
/// be invoked even if the directory is empty.
class DirectoryWatcher : public index::AbstractDirectoryWatcher {
struct Implementation;
Implementation &Impl;

DirectoryWatcher();

DirectoryWatcher(const DirectoryWatcher&) = delete;
DirectoryWatcher &operator =(const DirectoryWatcher&) = delete;

public:
~DirectoryWatcher();

static std::unique_ptr<DirectoryWatcher>
create(StringRef Path, EventReceiver Receiver, bool waitInitialSync,
std::string &Error);
};

} // namespace clang

#endif
6 changes: 4 additions & 2 deletions include/clang/Driver/Job.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ using llvm::opt::ArgStringList;
struct CrashReportInfo {
StringRef Filename;
StringRef VFSPath;
StringRef IndexStorePath;

CrashReportInfo(StringRef Filename, StringRef VFSPath)
: Filename(Filename), VFSPath(VFSPath) {}
CrashReportInfo(StringRef Filename, StringRef VFSPath,
StringRef IndexStorePath)
: Filename(Filename), VFSPath(VFSPath), IndexStorePath(IndexStorePath) {}
};

/// Command - An executable path/name and argument vector to
Expand Down
7 changes: 7 additions & 0 deletions include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ def objcmt_whitelist_dir_path: Joined<["-"], "objcmt-whitelist-dir-path=">, Flag
def : Joined<["-"], "objcmt-white-list-dir-path=">, Flags<[CC1Option]>,
Alias<objcmt_whitelist_dir_path>;

def index_store_path : Separate<["-"], "index-store-path">, Flags<[CC1Option]>,
HelpText<"Enable indexing with the specified data store path">;
def index_ignore_system_symbols : Flag<["-"], "index-ignore-system-symbols">, Flags<[CC1Option]>,
HelpText<"Ignore symbols from system headers">;
def index_record_codegen_name : Flag<["-"], "index-record-codegen-name">, Flags<[CC1Option]>,
HelpText<"Record the codegen name for symbols">;

// Make sure all other -ccc- options are rejected.
def ccc_ : Joined<["-"], "ccc-">, Group<internal_Group>, Flags<[Unsupported]>;

Expand Down
9 changes: 7 additions & 2 deletions include/clang/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ class FrontendOptions {
std::string MTMigrateDir;
std::string ARCMTMigrateReportOut;

std::string IndexStorePath;
unsigned IndexIgnoreSystemSymbols : 1;
unsigned IndexRecordCodegenName : 1;

/// The input files and their types.
std::vector<FrontendInputFile> Inputs;

Expand Down Expand Up @@ -285,8 +289,9 @@ class FrontendOptions {
SkipFunctionBodies(false), UseGlobalModuleIndex(true),
GenerateGlobalModuleIndex(true), ASTDumpDecls(false), ASTDumpLookups(false),
BuildingImplicitModule(false), ModulesEmbedAllFiles(false),
IncludeTimestamps(true), ARCMTAction(ARCMT_None),
ObjCMTAction(ObjCMT_None), ProgramAction(frontend::ParseSyntaxOnly)
IncludeTimestamps(true), ARCMTAction(ARCMT_None), ObjCMTAction(ObjCMT_None),
IndexIgnoreSystemSymbols(false), IndexRecordCodegenName(false),
ProgramAction(frontend::ParseSyntaxOnly)
{}

/// getInputKindForExtension - Return the appropriate input kind for a file
Expand Down
102 changes: 102 additions & 0 deletions include/clang/Index/IndexDataStore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//===--- IndexDataStore.h - Index data store info -------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_INDEX_INDEXDATASTORE_H
#define LLVM_CLANG_INDEX_INDEXDATASTORE_H

#include "clang/Basic/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/STLExtras.h"
#include <functional>
#include <memory>
#include <string>
#include <vector>

namespace clang {
namespace index {

class AbstractDirectoryWatcher {
public:
enum class EventKind {
/// A file was added.
Added,
/// A file was removed.
Removed,
/// A file was modified.
Modified,
/// The watched directory got deleted. No more events will follow.
DirectoryDeleted,
};

struct Event {
EventKind Kind;
std::string Filename;
timespec ModTime;
};

typedef std::function<void(ArrayRef<Event> Events, bool isInitial)> EventReceiver;
typedef std::unique_ptr<AbstractDirectoryWatcher>(CreateFnTy)
(StringRef Path, EventReceiver Receiver, bool waitInitialSync, std::string &Error);

virtual ~AbstractDirectoryWatcher() {}
};

class IndexDataStore {
public:
~IndexDataStore();

static std::unique_ptr<IndexDataStore>
create(StringRef IndexStorePath, std::string &Error);

StringRef getFilePath() const;
bool foreachUnitName(bool sorted,
llvm::function_ref<bool(StringRef unitName)> receiver);

static unsigned getFormatVersion();

enum class UnitEventKind {
Added,
Removed,
Modified,
/// The directory got deleted. No more events will follow.
DirectoryDeleted,
};
struct UnitEvent {
UnitEventKind Kind;
StringRef UnitName;
timespec ModTime;
};
struct UnitEventNotification {
bool IsInitial;
ArrayRef<UnitEvent> Events;
};
typedef std::function<void(UnitEventNotification)> UnitEventHandler;

void setUnitEventHandler(UnitEventHandler Handler);
/// \returns true if an error occurred.
bool startEventListening(llvm::function_ref<AbstractDirectoryWatcher::CreateFnTy> createFn,
bool waitInitialSync, std::string &Error);
void stopEventListening();

void discardUnit(StringRef UnitName);
void discardRecord(StringRef RecordName);

void purgeStaleData();

private:
IndexDataStore(void *Impl) : Impl(Impl) {}

void *Impl; // An IndexDataStoreImpl.
};

} // namespace index
} // namespace clang

#endif
53 changes: 53 additions & 0 deletions include/clang/Index/IndexDataStoreSymbolUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//===--- IndexDataStoreSymbolUtils.h - Utilities for indexstore symbols ---===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_INDEX_INDEXDATASTORESYMBOLUTILS_H
#define LLVM_CLANG_INDEX_INDEXDATASTORESYMBOLUTILS_H

#include "indexstore/indexstore.h"
#include "clang/Index/IndexSymbol.h"

namespace clang {
namespace index {

/// Map an indexstore_symbol_kind_t to a SymbolKind, handling unknown values.
SymbolKind getSymbolKind(indexstore_symbol_kind_t K);

SymbolSubKind getSymbolSubKind(indexstore_symbol_subkind_t K);

/// Map an indexstore_symbol_language_t to a SymbolLanguage, handling unknown
/// values.
SymbolLanguage getSymbolLanguage(indexstore_symbol_language_t L);

/// Map an indexstore representation to a SymbolPropertySet, handling
/// unknown values.
SymbolPropertySet getSymbolProperties(uint64_t Props);

/// Map an indexstore representation to a SymbolRoleSet, handling unknown
/// values.
SymbolRoleSet getSymbolRoles(uint64_t Roles);

/// Map a SymbolLanguage to a indexstore_symbol_language_t.
indexstore_symbol_kind_t getIndexStoreKind(SymbolKind K);

indexstore_symbol_subkind_t getIndexStoreSubKind(SymbolSubKind K);

/// Map a SymbolLanguage to a indexstore_symbol_language_t.
indexstore_symbol_language_t getIndexStoreLang(SymbolLanguage L);

/// Map a SymbolPropertySet to its indexstore representation.
uint64_t getIndexStoreProperties(SymbolPropertySet Props);

/// Map a SymbolRoleSet to its indexstore representation.
uint64_t getIndexStoreRoles(SymbolRoleSet Roles);

} // end namespace index
} // end namespace clang

#endif // LLVM_CLANG_INDEX_INDEXDATASTORESYMBOLUTILS_H
109 changes: 109 additions & 0 deletions include/clang/Index/IndexRecordReader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//===--- IndexRecordReader.h - Index record deserialization ---------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_INDEX_INDEXRECORDREADER_H
#define LLVM_CLANG_INDEX_INDEXRECORDREADER_H

#include "clang/Index/IndexSymbol.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include <memory>

namespace llvm {
class MemoryBuffer;
}

namespace clang {
namespace index {

struct IndexRecordDecl {
unsigned DeclID;
SymbolInfo SymInfo;
SymbolRoleSet Roles;
SymbolRoleSet RelatedRoles;
StringRef Name;
StringRef USR;
StringRef CodeGenName;
};

struct IndexRecordRelation {
SymbolRoleSet Roles;
const IndexRecordDecl *Dcl = nullptr;

IndexRecordRelation() = default;
IndexRecordRelation(SymbolRoleSet Roles, const IndexRecordDecl *Dcl)
: Roles(Roles), Dcl(Dcl) {}
};

struct IndexRecordOccurrence {
const IndexRecordDecl *Dcl;
SmallVector<IndexRecordRelation, 4> Relations;
SymbolRoleSet Roles;
unsigned Line;
unsigned Column;
};

class IndexRecordReader {
IndexRecordReader();

public:
static std::unique_ptr<IndexRecordReader>
createWithRecordFilename(StringRef RecordFilename, StringRef StorePath,
std::string &Error);
static std::unique_ptr<IndexRecordReader>
createWithFilePath(StringRef FilePath, std::string &Error);
static std::unique_ptr<IndexRecordReader>
createWithBuffer(std::unique_ptr<llvm::MemoryBuffer> Buffer,
std::string &Error);

~IndexRecordReader();

struct DeclSearchReturn {
bool AcceptDecl;
bool ContinueSearch;
};
typedef DeclSearchReturn(DeclSearchCheck)(const IndexRecordDecl &);

/// Goes through and passes record decls, after filtering using a \c Checker
/// function.
///
/// Resulting decls can be used as filter for \c foreachOccurrence. This
/// allows allocating memory only for the record decls that the caller is
/// interested in.
bool searchDecls(llvm::function_ref<DeclSearchCheck> Checker,
llvm::function_ref<void(const IndexRecordDecl *)> Receiver);

/// \param NoCache if true, avoids allocating memory for the decls.
/// Useful when the caller does not intend to keep \c IndexRecordReader
/// for more queries.
bool foreachDecl(bool NoCache,
llvm::function_ref<bool(const IndexRecordDecl *)> Receiver);

/// \param DeclsFilter if non-empty indicates the list of decls that we want
/// to get occurrences for. An empty array indicates that we want occurrences
/// for all decls.
/// \param RelatedDeclsFilter Same as \c DeclsFilter but for related decls.
bool foreachOccurrence(ArrayRef<const IndexRecordDecl *> DeclsFilter,
ArrayRef<const IndexRecordDecl *> RelatedDeclsFilter,
llvm::function_ref<bool(const IndexRecordOccurrence &)> Receiver);
bool foreachOccurrence(
llvm::function_ref<bool(const IndexRecordOccurrence &)> Receiver);

bool foreachOccurrenceInLineRange(unsigned lineStart, unsigned lineCount,
llvm::function_ref<bool(const IndexRecordOccurrence &)> Receiver);

struct Implementation;
private:
Implementation &Impl;
};

} // namespace index
} // namespace clang

#endif
Loading

0 comments on commit 04f4347

Please sign in to comment.