Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Jul 15, 2018
1 parent 5dcccea commit df72a9e
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 53 deletions.
2 changes: 0 additions & 2 deletions src/clang_complete.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include "threaded_queue.h"
#include "working_files.h"

#include <clang-c/Index.h>

#include <functional>
#include <memory>
#include <mutex>
Expand Down
33 changes: 2 additions & 31 deletions src/clang_utils.cc
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
#include "clang_utils.h"

#include "config.h"
#include "filesystem.hh"
#include "platform.h"
#include "utils.h"

#include <clang/AST/Type.h>
using namespace clang;
using namespace llvm;

std::string FileName(CXFile file) {
std::string ret;
// clang > 6
#if CINDEX_VERSION >= 48
ret = ToString(clang_File_tryGetRealPathName(file));
#endif
if (ret.empty())
// clang_getFileName return values may contain ..
ret = NormalizePath(ToString(clang_getFileName(file)));
// Resolve /usr/include/c++/7.3.0 symlink.
if (!StartsWith(ret, g_config->projectRoot)) {
SmallString<256> dest;
sys::fs::real_path(ret, dest);
ret = dest.str();
}
return ret;
}

std::string FileName(const FileEntry& file) {
StringRef Name = file.tryGetRealPathName();
if (Name.empty())
Expand All @@ -39,19 +23,6 @@ std::string FileName(const FileEntry& file) {
return ret;
}

std::string ToString(CXString cx_string) {
std::string string;
if (cx_string.data != nullptr) {
string = clang_getCString(cx_string);
clang_disposeString(cx_string);
}
return string;
}

std::string ToString(CXCursorKind kind) {
return ToString(clang_getCursorKindSpelling(kind));
}

// clang::BuiltinType::getName without PrintingPolicy
const char* ClangBuiltinTypeName(int kind) {
switch (BuiltinType::Kind(kind)) {
Expand Down
11 changes: 1 addition & 10 deletions src/clang_utils.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
#pragma once

#include "lsp_diagnostic.h"

#include <clang-c/Index.h>
#include <clang/Basic/FileManager.h>

#include <optional>
#include <vector>
#include <string>

// Returns the absolute path to |file|.
std::string FileName(CXFile file);
std::string FileName(const clang::FileEntry& file);

std::string ToString(CXString cx_string);

std::string ToString(CXCursorKind cursor_kind);

const char* ClangBuiltinTypeName(int);
1 change: 0 additions & 1 deletion src/file_consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "serializer.h"
#include "utils.h"

#include <clang-c/Index.h>
#include <clang/Basic/FileManager.h>

#include <mutex>
Expand Down
3 changes: 2 additions & 1 deletion src/indexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "serializer.h"
using ccls::Intern;

#include <clang-c/Index.h>
#include <clang/AST/AST.h>
#include <clang/Frontend/ASTUnit.h>
#include <clang/Frontend/CompilerInstance.h>
Expand Down Expand Up @@ -777,7 +778,7 @@ class IndexDataConsumer : public index::IndexDataConsumer {
}
[[fallthrough]];
case Decl::Record: {
auto *RD = cast<RecordDecl>(OrigD);
auto *RD = cast<RecordDecl>(D);
// spec has no Union, use Class
type->def.kind = RD->getTagKind() == TTK_Struct ? lsSymbolKind::Struct
: lsSymbolKind::Class;
Expand Down
1 change: 1 addition & 0 deletions src/indexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "file_consumer.h"
#include "language.h"
#include "lsp.h"
#include "lsp_diagnostic.h"
#include "maybe.h"
#include "position.h"
#include "serializer.h"
Expand Down
2 changes: 1 addition & 1 deletion src/messages/ccls_memberHierarchy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ bool Expand(MessageHandler* m,
bool qualified,
int levels) {
if (0 < entry->usr && entry->usr <= BuiltinType::LastKind) {
entry->name = ClangBuiltinTypeName(CXTypeKind(entry->usr));
entry->name = ClangBuiltinTypeName(int(entry->usr));
return true;
}
const QueryType& type = m->db->Type(entry->usr);
Expand Down
9 changes: 5 additions & 4 deletions src/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "serializer.h"
#include "utils.h"

#include <llvm/Config/llvm-config.h>

#include <rapidjson/document.h>
#include <rapidjson/prettywriter.h>
#include <rapidjson/stringbuffer.h>
Expand Down Expand Up @@ -227,13 +229,12 @@ IndexFile* FindDbForPathEnding(

bool RunIndexTests(const std::string& filter_path, bool enable_update) {
gTestOutputMode = true;
std::string version = ToString(clang_getClangVersion());
std::string version = LLVM_VERSION_STRING;

// Index tests change based on the version of clang used.
static const char kRequiredClangVersion[] =
"clang version 6.0.0 (tags/RELEASE_600/final)";
static const char kRequiredClangVersion[] = "6.0.0";
if (version != kRequiredClangVersion &&
version.find("trunk") == std::string::npos) {
version.find("svn") == std::string::npos) {
fprintf(stderr,
"Index tests must be run using clang version %s, ccls is running "
"with %s\n",
Expand Down
4 changes: 1 addition & 3 deletions src/working_files.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
#include "lsp_diagnostic.h"
#include "utils.h"

#include <clang-c/Index.h>
#include <optional>

#include <mutex>
#include <optional>
#include <string>

struct WorkingFile {
Expand Down

0 comments on commit df72a9e

Please sign in to comment.