This commit is contained in:
Jacob Dufault 2018-01-10 18:43:01 -08:00
parent 5605dfbb00
commit 54394ed868
26 changed files with 166 additions and 152 deletions

View File

@ -125,13 +125,13 @@ lsCompletionItemKind GetCompletionKind(CXCursorKind cursor_kind) {
case CXCursor_ObjCClassRef:
return lsCompletionItemKind::Reference;
// return lsCompletionItemKind::Property;
// return lsCompletionItemKind::Unit;
// return lsCompletionItemKind::Value;
// return lsCompletionItemKind::Keyword;
// return lsCompletionItemKind::Snippet;
// return lsCompletionItemKind::Color;
// return lsCompletionItemKind::File;
// return lsCompletionItemKind::Property;
// return lsCompletionItemKind::Unit;
// return lsCompletionItemKind::Value;
// return lsCompletionItemKind::Keyword;
// return lsCompletionItemKind::Snippet;
// return lsCompletionItemKind::Color;
// return lsCompletionItemKind::File;
case CXCursor_NotImplemented:
return lsCompletionItemKind::Text;
@ -389,7 +389,8 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) {
if (!session->tu)
continue;
WorkingFilesSnapshot snapshot = completion_manager->working_files_->AsSnapshot();
WorkingFilesSnapshot snapshot =
completion_manager->working_files_->AsSnapshot();
std::vector<CXUnsavedFile> unsaved = snapshot.AsUnsavedFiles();
// Emit code completion data.
@ -450,9 +451,9 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) {
ls_completion_item.documentation = ToString(
clang_getCompletionBriefComment(result.CompletionString));
ls_completion_item.priority_ =
GetCompletionPriority(result.CompletionString, result.CursorKind,
ls_completion_item.label);
ls_completion_item.priority_ = GetCompletionPriority(
result.CompletionString, result.CursorKind,
ls_completion_item.label);
ls_result.push_back(ls_completion_item);
}

View File

@ -19,8 +19,8 @@ void EmitDiagnostics(std::string path,
CXTranslationUnit tu) {
std::string output = "Fatal errors while trying to parse " + path + "\n";
output +=
"Args: " + StringJoinMap(
args, [](const char* arg) { return std::string(arg); }) +
"Args: " +
StringJoinMap(args, [](const char* arg) { return std::string(arg); }) +
"\n";
size_t num_diagnostics = clang_getNumDiagnostics(tu);

View File

@ -25,6 +25,6 @@ std::string ToString(CXCursorKind cursor_kind);
// Converts Clang formatting replacement operations into LSP text edits.
#if USE_CLANG_CXX
std::vector<lsTextEdit> ConvertClangReplacementsIntoTextEdits(
llvm::StringRef document,
const std::vector<clang::tooling::Replacement>& clang_replacements);
llvm::StringRef document,
const std::vector<clang::tooling::Replacement>& clang_replacements);
#endif

View File

@ -30,8 +30,8 @@
#include "working_files.h"
#include <doctest/doctest.h>
#include <loguru.hpp>
#include <rapidjson/error/en.h>
#include <loguru.hpp>
#include <climits>
#include <functional>

View File

@ -138,8 +138,7 @@ MAKE_REFLECT_STRUCT(Config,
enableComments,
dumpAST
);
dumpAST);
// Expected client version. We show an error if this doesn't match.
constexpr const int kExpectedClientVersion = 3;

View File

@ -106,7 +106,6 @@ ClangSymbolKind GetSymbolKind(CXIdxEntityKind kind) {
}
}
// Caches all instances of constructors, regardless if they are indexed or not.
// The constructor may have a make_unique call associated with it that we need
// to export. If we do not capture the parameter type description for the
@ -339,7 +338,8 @@ std::string GetDocumentContentInRange(CXTranslationUnit cx_tu,
for (unsigned i = 0; i < num_tokens; ++i) {
// Add whitespace between the previous token and this one.
Range token_range = ResolveCXSourceRange(clang_getTokenExtent(cx_tu, tokens[i]));
Range token_range =
ResolveCXSourceRange(clang_getTokenExtent(cx_tu, tokens[i]));
if (previous_token_range) {
// Insert newlines.
int16_t line_delta =
@ -419,9 +419,9 @@ void SetVarDetail(IndexVar* var,
def.comments = cursor.get_comments();
std::string qualified_name =
semanticContainer
? param->ns.QualifiedName(semanticContainer, def.short_name)
: def.short_name;
semanticContainer
? param->ns.QualifiedName(semanticContainer, def.short_name)
: def.short_name;
if (semanticContainer && semanticContainer->cursor.kind == CXCursor_EnumDecl)
def.detailed_name = std::move(qualified_name);
else {
@ -463,8 +463,7 @@ void OnIndexReference_Function(IndexFile* db,
AddFuncRef(&caller->def.callees,
IndexFuncRef(called->id, loc, is_implicit));
AddFuncRef(&called->callers,
IndexFuncRef(caller->id, loc, is_implicit));
AddFuncRef(&called->callers, IndexFuncRef(caller->id, loc, is_implicit));
} else {
AddFuncRef(&called->callers, IndexFuncRef(loc, is_implicit));
}
@ -594,8 +593,8 @@ void OnIndexDiagnostic(CXClientData client_data,
unsigned int line, column;
clang_getSpellingLocation(diag_loc, &file, &line, &column, nullptr);
// Skip empty diagnostic.
if(!line && !column)
continue;
if (!line && !column)
continue;
IndexFile* db = ConsumeFile(param, file);
if (!db)
continue;
@ -1036,7 +1035,8 @@ ClangCursor::VisitResult VisitMacroDefinitionAndExpansions(ClangCursor cursor,
var_def->def.kind = ClangSymbolKind::Macro;
var_def->def.comments = cursor.get_comments();
var_def->def.definition_spelling = decl_loc_spelling;
var_def->def.definition_extent = ResolveCXSourceRange(cx_extent, nullptr);
var_def->def.definition_extent =
ResolveCXSourceRange(cx_extent, nullptr);
}
break;
@ -1312,9 +1312,9 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
// We don't need to assign declaring type multiple times if this variable
// has already been seen.
if (!decl->isRedeclaration) {
//optional<IndexTypeId> var_type =
// optional<IndexTypeId> var_type =
// ResolveToDeclarationType(db, decl_cursor);
//if (var_type.has_value()) {
// if (var_type.has_value()) {
// // Don't treat enum definition variables as instantiations.
// bool is_enum_member =
// decl->semanticContainer &&
@ -1597,7 +1597,8 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
decl->lexicalContainer);
optional<IndexTypeId> parent_type_id =
ResolveToDeclarationType(db, base_class->cursor);
// type_def ptr could be invalidated by ResolveToDeclarationType and TemplateVisitor.
// type_def ptr could be invalidated by ResolveToDeclarationType and
// TemplateVisitor.
type = db->Resolve(type_id);
if (parent_type_id) {
IndexType* parent_type_def = db->Resolve(parent_type_id.value());
@ -1675,7 +1676,8 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
// definition, We use cursor extent (larger than spelling range) `e.x`. It
// would be better if we could restrict the ranges to `.x` or just `x`.
// Nevertheless, larger ranges are less specific, and should do no harm
// because they will be overriden by more specific variable references `e`.
// because they will be overriden by more specific variable references
// `e`.
Range loc = ref->cursor.kind == CXCursor_MemberRefExpr &&
ref_cursor.get_spelling().empty()
? ref_cursor.get_extent()
@ -1750,17 +1752,17 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
!CursorSpellingContainsString(ref->cursor, param->tu->cx_tu,
called->def.short_name)));
// Extents have larger ranges and thus less specific, and will be overriden
// by other functions if exist.
// Extents have larger ranges and thus less specific, and will be
// overriden by other functions if exist.
//
// Members of non-concrete template types do not have useful spelling ranges.
// See the comment above for the CXIdxEntity_Field case.
// Members of non-concrete template types do not have useful spelling
// ranges. See the comment above for the CXIdxEntity_Field case.
if (is_implicit || (ref->cursor.kind == CXCursor_MemberRefExpr &&
ref_cursor.get_spelling().empty()))
loc = ref_cursor.get_extent();
OnIndexReference_Function(db, loc, ref->container->cursor,
called_id, called, is_implicit);
OnIndexReference_Function(db, loc, ref->container->cursor, called_id,
called, is_implicit);
// Checks if |str| starts with |start|. Ignores case.
auto str_begin = [](const char* start, const char* str) {
@ -1800,8 +1802,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
param->ctors.TryFindConstructorUsr(ctor_type_usr, call_type_desc);
if (ctor_usr) {
IndexFunc* ctor = db->Resolve(db->ToFuncId(*ctor_usr));
AddFuncRef(&ctor->callers,
IndexFuncRef(loc, true /*is_implicit*/));
AddFuncRef(&ctor->callers, IndexFuncRef(loc, true /*is_implicit*/));
}
}
}
@ -1837,21 +1838,26 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
// Foo f;
// }
//
UniqueAdd(referenced->uses, ClangCursor(ref->cursor).get_spelling_range());
UniqueAdd(referenced->uses,
ClangCursor(ref->cursor).get_spelling_range());
break;
}
default:
std::cerr << "!! Unhandled indexEntityReference: " << cursor.ToString()
<< " at " << ClangCursor(ref->cursor).get_spelling_range().start.ToString()
<< std::endl;
std::cerr
<< "!! Unhandled indexEntityReference: " << cursor.ToString()
<< " at "
<< ClangCursor(ref->cursor).get_spelling_range().start.ToString()
<< std::endl;
std::cerr << " ref->referencedEntity->kind = "
<< ref->referencedEntity->kind << std::endl;
if (ref->parentEntity)
std::cerr << " ref->parentEntity->kind = "
<< ref->parentEntity->kind << std::endl;
std::cerr << " ref->loc = "
<< ClangCursor(ref->cursor).get_spelling_range().start.ToString() << std::endl;
std::cerr
<< " ref->loc = "
<< ClangCursor(ref->cursor).get_spelling_range().start.ToString()
<< std::endl;
std::cerr << " ref->kind = " << ref->kind << std::endl;
if (ref->parentEntity)
std::cerr << " parentEntity = "
@ -2003,7 +2009,7 @@ std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
std::unordered_map<std::string, int> inc_to_line;
// TODO
if (param.primary_file)
for (auto &inc : param.primary_file->includes)
for (auto& inc : param.primary_file->includes)
inc_to_line[inc.resolved_path] = inc.line;
auto result = param.file_consumer->TakeLocalState();
@ -2080,12 +2086,14 @@ void ClangSanityCheck() {
void* reserved) -> CXIdxClientFile {
return nullptr;
};
callback.ppIncludedFile = [](
CXClientData client_data,
const CXIdxIncludedFileInfo* file) -> CXIdxClientFile { return nullptr; };
callback.importedASTFile = [](
CXClientData client_data,
const CXIdxImportedASTFileInfo*) -> CXIdxClientASTFile {
callback.ppIncludedFile =
[](CXClientData client_data,
const CXIdxIncludedFileInfo* file) -> CXIdxClientFile {
return nullptr;
};
callback.importedASTFile =
[](CXClientData client_data,
const CXIdxImportedASTFileInfo*) -> CXIdxClientASTFile {
return nullptr;
};
callback.startedTranslationUnit = [](CXClientData client_data,

View File

@ -112,7 +112,8 @@ enum class ClangSymbolKind : uint8_t {
Parameter = 25,
Using,
};
MAKE_REFLECT_TYPE_PROXY(ClangSymbolKind, std::underlying_type<ClangSymbolKind>::type);
MAKE_REFLECT_TYPE_PROXY(ClangSymbolKind,
std::underlying_type<ClangSymbolKind>::type);
struct IndexFuncRef {
// NOTE: id can be -1 if the function call is not coming from a function.

View File

@ -458,7 +458,6 @@ enum class lsDocumentHighlightKind {
};
MAKE_REFLECT_TYPE_PROXY(lsDocumentHighlightKind, int);
struct lsFormattingOptions {
// Size of a tab in spaces.
int tabSize;

View File

@ -1,7 +1,7 @@
#include "match.h"
#include "queue_manager.h"
#include "language_server_api.h"
#include "queue_manager.h"
#include <doctest/doctest.h>
#include <iostream>
@ -22,11 +22,10 @@ optional<Matcher> Matcher::Create(const std::string& search) {
Matcher m;
m.regex_string = search;
m.regex = std::regex(
search,
std::regex_constants::ECMAScript | std::regex_constants::icase |
std::regex_constants::optimize
search, std::regex_constants::ECMAScript | std::regex_constants::icase |
std::regex_constants::optimize
// std::regex_constants::nosubs
);
);
return m;
} catch (std::exception e) {
Out_ShowLogMessage out;

View File

@ -21,7 +21,7 @@ struct ScanLineEvent {
return !(pos == other.pos) ? pos < other.pos : other.end_pos < end_pos;
}
};
}
} // namespace
MessageHandler::MessageHandler() {
// Dynamically allocate |message_handlers|, otherwise there will be static
@ -35,7 +35,7 @@ MessageHandler::MessageHandler() {
std::vector<MessageHandler*>* MessageHandler::message_handlers = nullptr;
bool FindFileOrFail(QueryDatabase* db,
const Project *project,
const Project* project,
optional<lsRequestId> id,
const std::string& absolute_path,
QueryFile** out_query_file,
@ -143,14 +143,14 @@ void EmitSemanticHighlighting(QueryDatabase* db,
auto concise_name = detailed_name.substr(0, detailed_name.find('<'));
if (sym.loc.range.start.line <= working_file->index_lines.size()) {
std::string& line =
working_file->index_lines[sym.loc.range.start.line - 1];
working_file->index_lines[sym.loc.range.start.line - 1];
auto pos = line.find(concise_name);
sym.loc.range.end.line = sym.loc.range.start.line;
if (pos == std::string::npos)
sym.loc.range.end.column = sym.loc.range.start.column;
else
sym.loc.range.end.column =
sym.loc.range.start.column + concise_name.size();
sym.loc.range.start.column + concise_name.size();
}
break;
}
@ -209,8 +209,8 @@ void EmitSemanticHighlighting(QueryDatabase* db,
for (auto& entry : grouped_symbols) {
Out_CqueryPublishSemanticHighlighting::Symbol& symbol = entry.second;
for (auto& loc : symbol.ranges) {
// For ranges sharing the same start point, the one with leftmost end point
// comes first.
// For ranges sharing the same start point, the one with leftmost end
// point comes first.
events.push_back({loc.start, loc.end, id, &symbol});
// For ranges sharing the same end point, their relative order does not
// matter, therefore we arbitrarily assign loc.end to them. We use
@ -231,9 +231,11 @@ void EmitSemanticHighlighting(QueryDatabase* db,
// the ealier. The order of [a0, b) [a1, b) does not matter.
// The order of [a, b) [b, c) does not as long as we do not emit empty
// ranges.
// Attribute range [events[i-1].pos, events[i].pos) to events[top-1].symbol .
// Attribute range [events[i-1].pos, events[i].pos) to events[top-1].symbol
// .
if (top && !(events[i - 1].pos == events[i].pos))
events[top - 1].symbol->ranges.emplace_back(events[i - 1].pos, events[i].pos);
events[top - 1].symbol->ranges.emplace_back(events[i - 1].pos,
events[i].pos);
if (events[i].id >= 0)
events[top++] = events[i];
else

View File

@ -178,8 +178,7 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
Timer time;
// Open up / load the project.
project->Load(config,
config->extraClangArguments,
project->Load(config, config->extraClangArguments,
config->compilationDatabaseDirectory, project_path,
config->resourceDirectory);
time.ResetAndPrint("[perf] Loaded compilation entries (" +

View File

@ -8,9 +8,8 @@ struct Ipc_Shutdown : public IpcMessage<Ipc_Shutdown> {
MAKE_REFLECT_EMPTY_STRUCT(Ipc_Shutdown);
REGISTER_IPC_MESSAGE(Ipc_Shutdown);
struct Out_Shutdown
: public lsOutMessage<Out_Shutdown> {
lsRequestId id; // defaults to std::monostate (null)
struct Out_Shutdown : public lsOutMessage<Out_Shutdown> {
lsRequestId id; // defaults to std::monostate (null)
std::monostate result; // null
};
MAKE_REFLECT_STRUCT(Out_Shutdown, jsonrpc, id, result);

View File

@ -249,7 +249,8 @@ struct WorkspaceSymbolHandler : BaseMessageHandler<Ipc_WorkspaceSymbol> {
longest = std::max(longest, int(db->short_names[i].size()));
std::vector<int> score(longest); // score for each position
std::vector<int> dp(longest); // dp[i]: maximum value by aligning pattern to str[0..i]
std::vector<int> dp(
longest); // dp[i]: maximum value by aligning pattern to str[0..i]
std::vector<std::pair<int, int>> permutation(result_indices.size());
for (int i = 0; i < int(result_indices.size()); i++) {
permutation[i] = {
@ -260,15 +261,14 @@ struct WorkspaceSymbolHandler : BaseMessageHandler<Ipc_WorkspaceSymbol> {
std::greater<std::pair<int, int>>());
out.result.reserve(result_indices.size());
for (int i = 0; i < int(result_indices.size()); i++)
out.result.push_back(std::move(unsorted_results[permutation[i].second]));
}
else {
out.result.push_back(
std::move(unsorted_results[permutation[i].second]));
} else {
out.result.reserve(unsorted_results.size());
for (const auto& entry : unsorted_results)
out.result.push_back(std::move(entry));
}
LOG_S(INFO) << "[querydb] Found " << out.result.size()
<< " results for query " << query;
QueueManager::WriteStdout(IpcId::WorkspaceSymbol, out);

View File

@ -7,10 +7,10 @@
#include <pthread.h>
#if defined(__FreeBSD__)
# include <pthread_np.h>
# include <sys/thr.h>
#include <pthread_np.h>
#include <sys/thr.h>
#elif defined(__OpenBSD__)
# include <pthread_np.h>
#include <pthread_np.h>
#endif
#include <assert.h>
@ -130,7 +130,10 @@ std::string GetExecutablePath() {
return result;
#elif defined(__FreeBSD__)
static const int name[] = {
CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1,
CTL_KERN,
KERN_PROC,
KERN_PROC_PATHNAME,
-1,
};
char path[MAXPATHLEN];
size_t len = sizeof(path);
@ -139,7 +142,7 @@ std::string GetExecutablePath() {
return std::string(path);
#else
char buffer[PATH_MAX] = {0};
if(-1 == readlink("/proc/self/exe", buffer, PATH_MAX))
if (-1 == readlink("/proc/self/exe", buffer, PATH_MAX))
return "";
return buffer;
#endif

View File

@ -147,7 +147,6 @@ bool RunObjectiveCIndexTests() {
}
// TODO Wait for debugger to attach
void TraceMe() {
}
void TraceMe() {}
#endif

View File

@ -95,7 +95,6 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
Config* init_opts,
ProjectConfig* config,
const CompileCommandsEntry& entry) {
auto cleanup_maybe_relative_path = [&](const std::string& path) {
// TODO/FIXME: Normalization will fail for paths that do not exist. Should
// it return an optional<std::string>?
@ -246,14 +245,16 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
// Using -fparse-all-comments enables documententation in the indexer and in
// code completion.
if (init_opts->enableComments > 1 && !AnyStartsWith(result.args, "-fparse-all-comments")) {
if (init_opts->enableComments > 1 &&
!AnyStartsWith(result.args, "-fparse-all-comments")) {
result.args.push_back("-fparse-all-comments");
}
return result;
}
std::vector<Project::Entry> LoadFromDirectoryListing(Config* init_opts, ProjectConfig* config) {
std::vector<Project::Entry> LoadFromDirectoryListing(Config* init_opts,
ProjectConfig* config) {
std::vector<Project::Entry> result;
std::vector<std::string> args;
@ -281,7 +282,8 @@ std::vector<Project::Entry> LoadFromDirectoryListing(Config* init_opts, ProjectC
e.file = file;
e.args = args;
e.args.push_back(e.file);
result.push_back(GetCompilationEntryFromCompileCommandEntry(init_opts, config, e));
result.push_back(
GetCompilationEntryFromCompileCommandEntry(init_opts, config, e));
}
}
@ -351,7 +353,8 @@ std::vector<Project::Entry> LoadCompilationEntriesFromDirectory(
absolute_filename = directory + "/" + relative_filename;
entry.file = NormalizePathWithTestOptOut(absolute_filename);
result.push_back(GetCompilationEntryFromCompileCommandEntry(init_opts, config, entry));
result.push_back(
GetCompilationEntryFromCompileCommandEntry(init_opts, config, entry));
our_time.Pause();
}
@ -416,8 +419,8 @@ void Project::Load(Config* init_opts,
config.extra_flags = extra_flags;
config.project_dir = root_directory;
config.resource_dir = resource_directory;
entries =
LoadCompilationEntriesFromDirectory(init_opts, &config, opt_compilation_db_dir);
entries = LoadCompilationEntriesFromDirectory(init_opts, &config,
opt_compilation_db_dir);
// Cleanup / postprocess include directories.
quote_include_directories.assign(config.quote_dirs.begin(),
@ -545,12 +548,13 @@ TEST_SUITE("Project") {
// FIXME: Fix this test.
TEST_CASE("Path in args") {
CheckFlags("/home/user", "/home/user/foo/bar.c",
/* raw */ {"cc", "-O0", "foo/bar.c"},
/* expected */
{"cc", "-working-directory", "/home/user", "-xc", "-std=gnu11",
"-O0", "&/home/user/foo/bar.c", "-resource-dir=/w/resource_dir/",
"-Wno-unknown-warning-option"});
CheckFlags(
"/home/user", "/home/user/foo/bar.c",
/* raw */ {"cc", "-O0", "foo/bar.c"},
/* expected */
{"cc", "-working-directory", "/home/user", "-xc", "-std=gnu11", "-O0",
"&/home/user/foo/bar.c", "-resource-dir=/w/resource_dir/",
"-Wno-unknown-warning-option"});
}
TEST_CASE("Implied binary") {
@ -907,7 +911,8 @@ TEST_SUITE("Project") {
"debian_jessie_amd64-sysroot",
"-fno-exceptions",
"-fvisibility-inlines-hidden",
"&/w/c/s/out/Release/../../ash/login/ui/lock_screen_sanity_unittest.cc",
"&/w/c/s/out/Release/../../ash/login/ui/"
"lock_screen_sanity_unittest.cc",
"-resource-dir=/w/resource_dir/",
"-Wno-unknown-warning-option"});
}

View File

@ -233,8 +233,8 @@ QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexFile& indexed) {
for (const IndexFuncRef& caller : func.callers) {
// Make ranges of implicit function calls larger (spanning one more column
// to the left/right). This is hacky but useful. e.g.
// textDocument/definition on the space/semicolon in `A a;` or `return 42;`
// will take you to the constructor.
// textDocument/definition on the space/semicolon in `A a;` or `return
// 42;` will take you to the constructor.
Range range = caller.loc;
if (caller.is_implicit) {
if (range.start.column > 1)

View File

@ -503,16 +503,17 @@ std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile* working_file,
//
// Then order functions before other types, which makes goto definition work
// better on constructors.
std::sort(symbols.begin(), symbols.end(), [](const SymbolRef& a,
const SymbolRef& b) {
int a_size = ComputeRangeSize(a.loc.range);
int b_size = ComputeRangeSize(b.loc.range);
std::sort(symbols.begin(), symbols.end(),
[](const SymbolRef& a, const SymbolRef& b) {
int a_size = ComputeRangeSize(a.loc.range);
int b_size = ComputeRangeSize(b.loc.range);
if (a_size != b_size)
return a_size < b_size;
// operator> orders Var/Func in front of orders.
return static_cast<int>(a.idx.kind) > static_cast<int>(b.idx.kind);
});
if (a_size != b_size)
return a_size < b_size;
// operator> orders Var/Func in front of orders.
return static_cast<int>(a.idx.kind) >
static_cast<int>(b.idx.kind);
});
return symbols;
}

View File

@ -226,7 +226,6 @@ void Reflect(Writer& visitor, SerializeFormat& value) {
}
std::string Serialize(SerializeFormat format, IndexFile& file) {
switch (format) {
case SerializeFormat::Json: {
rapidjson::StringBuffer output;
@ -261,8 +260,8 @@ std::unique_ptr<IndexFile> Deserialize(SerializeFormat format,
if (reader.HasParseError())
return nullptr;
// Do not deserialize a document with a bad version. Doing so could cause a
// crash because the file format may have changed.
// Do not deserialize a document with a bad version. Doing so could cause
// a crash because the file format may have changed.
if (expected_version) {
auto actual_version = reader.FindMember("version");
if (actual_version == reader.MemberEnd() ||
@ -291,7 +290,8 @@ std::unique_ptr<IndexFile> Deserialize(SerializeFormat format,
if (file->version != expected_version)
return nullptr;
} catch (msgpack::unpack_error& ex) {
LOG_S(ERROR) << "msgpack::unpack_err for '" << path << "' " << ex.what();
LOG_S(ERROR) << "msgpack::unpack_err for '" << path << "' "
<< ex.what();
return nullptr;
}
break;

View File

@ -15,12 +15,12 @@ class Reader {
virtual ~Reader() {}
virtual SerializeFormat Format() const = 0;
//virtual bool IsBool() = 0;
// virtual bool IsBool() = 0;
virtual bool IsNull() = 0;
virtual bool IsArray() = 0;
virtual bool IsInt() = 0;
//virtual bool IsInt64() = 0;
//virtual bool IsUint64() = 0;
// virtual bool IsInt64() = 0;
// virtual bool IsUint64() = 0;
virtual bool IsString() = 0;
virtual void GetNull() = 0;
@ -60,12 +60,12 @@ class Writer {
struct IndexFile;
#define REFLECT_MEMBER_START() \
if (!ReflectMemberStart(visitor, value)) \
return
#define REFLECT_MEMBER_START1(value) \
if (!ReflectMemberStart(visitor, value)) \
return
#define REFLECT_MEMBER_START() \
if (!ReflectMemberStart(visitor, value)) \
return
#define REFLECT_MEMBER_START1(value) \
if (!ReflectMemberStart(visitor, value)) \
return
#define REFLECT_MEMBER_END() ReflectMemberEnd(visitor, value);
#define REFLECT_MEMBER_END1(value) ReflectMemberEnd(visitor, value);
#define REFLECT_MEMBER(name) ReflectMember(visitor, #name, value.name)
@ -106,11 +106,11 @@ struct IndexFile;
// Reflects the struct so it is serialized as an array instead of an object.
// This currently only supports writers.
#define MAKE_REFLECT_STRUCT_WRITER_AS_ARRAY(type, ...) \
inline void Reflect(Writer& visitor, type& value) { \
visitor.StartArray(NUM_VA_ARGS(__VA_ARGS__)); \
MACRO_MAP(_MAPPABLE_REFLECT_ARRAY, __VA_ARGS__) \
visitor.EndArray(); \
#define MAKE_REFLECT_STRUCT_WRITER_AS_ARRAY(type, ...) \
inline void Reflect(Writer& visitor, type& value) { \
visitor.StartArray(NUM_VA_ARGS(__VA_ARGS__)); \
MACRO_MAP(_MAPPABLE_REFLECT_ARRAY, __VA_ARGS__) \
visitor.EndArray(); \
}
// API:
@ -265,7 +265,6 @@ void ReflectMember(Writer& visitor, const char* name, std::string& value);
// Reader:
inline void DefaultReflectMemberStart(Reader& visitor) {}
template <typename T>
bool ReflectMemberStart(Reader& visitor, T& value) {

View File

@ -12,12 +12,12 @@ class JsonReader : public Reader {
JsonReader(rapidjson::GenericValue<rapidjson::UTF8<>>* m) : m_(m) {}
SerializeFormat Format() const override { return SerializeFormat::Json; }
//bool IsBool() override { return m_->IsBool(); }
// bool IsBool() override { return m_->IsBool(); }
bool IsNull() override { return m_->IsNull(); }
bool IsArray() override { return m_->IsArray(); }
bool IsInt() override { return m_->IsInt(); }
//bool IsInt64() override { return m_->IsInt64(); }
//bool IsUint64() override { return m_->IsUint64(); }
// bool IsInt64() override { return m_->IsInt64(); }
// bool IsUint64() override { return m_->IsUint64(); }
bool IsString() override { return m_->IsString(); }
void GetNull() override {}
@ -43,7 +43,8 @@ class JsonReader : public Reader {
void DoMember(const char* name, std::function<void(Reader&)> fn) override {
if (m_->GetType() != rapidjson::Type::kObjectType)
return; // FIXME: signal an error that object was not deserialized correctly?
return; // FIXME: signal an error that object was not deserialized
// correctly?
auto it = m_->FindMember(name);
if (it != m_->MemberEnd()) {

View File

@ -17,7 +17,9 @@ class MessagePackReader : public Reader {
public:
MessagePackReader(msgpack::unpacker* pk) : pk_(pk) { pk->next(oh_); }
SerializeFormat Format() const override { return SerializeFormat::MessagePack; }
SerializeFormat Format() const override {
return SerializeFormat::MessagePack;
}
bool IsNull() override { return oh_.get().is_nil(); }
bool IsArray() override { return oh_.get().type == msgpack::type::ARRAY; }
@ -36,9 +38,7 @@ class MessagePackReader : public Reader {
std::string GetString() override { return Get<std::string>(); }
bool HasMember(const char* x) override { return true; }
std::unique_ptr<Reader> operator[](const char* x) override {
return {};
}
std::unique_ptr<Reader> operator[](const char* x) override { return {}; }
void IterArray(std::function<void(Reader&)> fn) override {
size_t n = Get<size_t>();
@ -56,7 +56,9 @@ class MessagePackWriter : public Writer {
public:
MessagePackWriter(msgpack::packer<msgpack::sbuffer>* m) : m_(m) {}
SerializeFormat Format() const override { return SerializeFormat::MessagePack; }
SerializeFormat Format() const override {
return SerializeFormat::MessagePack;
}
void Null() override { m_->pack_nil(); }
void Bool(bool x) override { m_->pack(x); }
@ -66,7 +68,9 @@ class MessagePackWriter : public Writer {
void Double(double x) override { m_->pack(x); }
void String(const char* x) override { m_->pack(x); }
// TODO Remove std::string
void String(const char* x, size_t len) override { m_->pack(std::string(x, len)); }
void String(const char* x, size_t len) override {
m_->pack(std::string(x, len));
}
void StartArray(size_t n) override { m_->pack(n); }
void EndArray() override {}
void StartObject() override {}

View File

@ -240,7 +240,7 @@ bool RunIndexTests(const std::string& filter_path, bool enable_update) {
std::cout << std::endl;
if (enable_update) {
std::cout
<< "[Enter to continue - type u to update test, a to update all]";
<< "[Enter to continue - type u to update test, a to update all]";
char c = 'u';
if (!update_all) {
c = (char)std::cin.get();

View File

@ -27,7 +27,7 @@ struct index_sequence {};
template <size_t I, size_t... Is>
struct make_index_sequence {
using type = typename make_index_sequence<I-1, I-1, Is...>::type;
using type = typename make_index_sequence<I - 1, I - 1, Is...>::type;
};
template <size_t... Is>
@ -35,7 +35,7 @@ struct make_index_sequence<0, Is...> {
using type = index_sequence<Is...>;
};
}
} // namespace
// std::lock accepts two or more arguments. We define an overload for one
// argument.
@ -44,16 +44,12 @@ template <typename Lockable>
void lock(Lockable& l) {
l.lock();
}
}
} // namespace std
template <typename... Queue>
struct MultiQueueLock {
MultiQueueLock(Queue... lockable) : tuple_{lockable...} {
lock();
}
~MultiQueueLock() {
unlock();
}
MultiQueueLock(Queue... lockable) : tuple_{lockable...} { lock(); }
~MultiQueueLock() { unlock(); }
void lock() {
lock_impl(typename make_index_sequence<sizeof...(Queue)>::type{});
}

View File

@ -75,8 +75,7 @@ std::string GetFunctionSignature(IndexFile* db,
// Second pass: insert argument names before each comma and closing paren.
int i = function_name_offset;
std::string type_desc_with_names(type_desc.begin(),
type_desc.begin() + i);
std::string type_desc_with_names(type_desc.begin(), type_desc.begin() + i);
type_desc_with_names.append(function_name);
for (auto& arg : args) {
if (arg.first < 0) {

View File

@ -149,7 +149,7 @@ static void GetFilesInFolderHelper(
const std::function<void(const std::string&)>& handler) {
std::queue<std::pair<std::string, std::string>> q;
q.push(make_pair(folder, output_prefix));
while(!q.empty()) {
while (!q.empty()) {
tinydir_dir dir;
if (tinydir_open(&dir, q.front().first.c_str()) == -1) {
LOG_S(WARNING) << "Unable to open directory " << folder;