From 35cba6d49ce9bbdd39be6d09525b8a855df2c24e Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 23 Sep 2018 13:31:06 -0700 Subject: [PATCH] Remove clang_utils.* --- CMakeLists.txt | 1 - src/clang_complete.cc | 5 +- src/clang_complete.hh | 2 +- src/clang_tu.cc | 170 ++++++++++++++++++++++++++++++- src/{clang_tu.h => clang_tu.hh} | 6 +- src/clang_utils.cc | 175 -------------------------------- src/clang_utils.h | 13 --- src/indexer.cc | 12 +-- src/indexer.h | 2 +- src/messages/ccls_member.cc | 1 + src/project.cc | 1 - 11 files changed, 182 insertions(+), 206 deletions(-) rename src/{clang_tu.h => clang_tu.hh} (88%) delete mode 100644 src/clang_utils.cc delete mode 100644 src/clang_utils.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3985e129..6b447d76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,7 +181,6 @@ target_sources(ccls PRIVATE third_party/siphash.cc) target_sources(ccls PRIVATE src/clang_complete.cc src/clang_tu.cc - src/clang_utils.cc src/config.cc src/filesystem.cc src/fuzzy_match.cc diff --git a/src/clang_complete.cc b/src/clang_complete.cc index 41b855bc..dd825fd2 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -3,13 +3,12 @@ #include "clang_complete.hh" -#include "clang_utils.h" +#include "clang_tu.hh" #include "filesystem.hh" #include "log.hh" #include "match.h" #include "platform.h" -#include #include #include #include @@ -96,7 +95,7 @@ public: auto it = FID2concerned.try_emplace(FID.getHashValue()); if (it.second) { const FileEntry *FE = SM.getFileEntryForID(FID); - it.first->second = FE && FileName(*FE) == path; + it.first->second = FE && PathFromFileEntry(*FE) == path; } return it.first->second; } diff --git a/src/clang_complete.hh b/src/clang_complete.hh index 677bc204..eb749169 100644 --- a/src/clang_complete.hh +++ b/src/clang_complete.hh @@ -3,7 +3,7 @@ #pragma once -#include "clang_tu.h" +#include "clang_tu.hh" #include "lru_cache.h" #include "lsp_completion.h" #include "lsp_diagnostic.h" diff --git a/src/clang_tu.cc b/src/clang_tu.cc index 2986544e..ef717981 100644 --- a/src/clang_tu.cc +++ b/src/clang_tu.cc @@ -1,16 +1,32 @@ // Copyright 2017-2018 ccls Authors // SPDX-License-Identifier: Apache-2.0 -#include "clang_tu.h" +#include "clang_tu.hh" -#include "clang_utils.h" #include "config.h" +#include "platform.h" +#include #include +#include + +#include + using namespace clang; -#include -#include +std::string PathFromFileEntry(const FileEntry &file) { + StringRef Name = file.tryGetRealPathName(); + if (Name.empty()) + Name = file.getName(); + std::string ret = NormalizePath(Name); + // Resolve /usr/include/c++/7.3.0 symlink. + if (!StartsWith(ret, g_config->projectRoot)) { + SmallString<256> dest; + llvm::sys::fs::real_path(ret, dest); + ret = llvm::sys::path::convert_to_slash(dest.str()); + } + return ret; +} Range FromCharSourceRange(const SourceManager &SM, const LangOptions &LangOpts, CharSourceRange R, @@ -69,3 +85,149 @@ BuildCompilerInvocation(std::vector args, } return CI; } + +// clang::BuiltinType::getName without PrintingPolicy +const char *ClangBuiltinTypeName(int kind) { + switch (BuiltinType::Kind(kind)) { + case BuiltinType::Void: + return "void"; + case BuiltinType::Bool: + return "bool"; + case BuiltinType::Char_S: + case BuiltinType::Char_U: + return "char"; + case BuiltinType::SChar: + return "signed char"; + case BuiltinType::Short: + return "short"; + case BuiltinType::Int: + return "int"; + case BuiltinType::Long: + return "long"; + case BuiltinType::LongLong: + return "long long"; + case BuiltinType::Int128: + return "__int128"; + case BuiltinType::UChar: + return "unsigned char"; + case BuiltinType::UShort: + return "unsigned short"; + case BuiltinType::UInt: + return "unsigned int"; + case BuiltinType::ULong: + return "unsigned long"; + case BuiltinType::ULongLong: + return "unsigned long long"; + case BuiltinType::UInt128: + return "unsigned __int128"; + case BuiltinType::Half: + return "__fp16"; + case BuiltinType::Float: + return "float"; + case BuiltinType::Double: + return "double"; + case BuiltinType::LongDouble: + return "long double"; +#if LLVM_VERSION_MAJOR >= 7 + case BuiltinType::ShortAccum: + return "short _Accum"; + case BuiltinType::Accum: + return "_Accum"; + case BuiltinType::LongAccum: + return "long _Accum"; + case BuiltinType::UShortAccum: + return "unsigned short _Accum"; + case BuiltinType::UAccum: + return "unsigned _Accum"; + case BuiltinType::ULongAccum: + return "unsigned long _Accum"; + case BuiltinType::BuiltinType::ShortFract: + return "short _Fract"; + case BuiltinType::BuiltinType::Fract: + return "_Fract"; + case BuiltinType::BuiltinType::LongFract: + return "long _Fract"; + case BuiltinType::BuiltinType::UShortFract: + return "unsigned short _Fract"; + case BuiltinType::BuiltinType::UFract: + return "unsigned _Fract"; + case BuiltinType::BuiltinType::ULongFract: + return "unsigned long _Fract"; + case BuiltinType::BuiltinType::SatShortAccum: + return "_Sat short _Accum"; + case BuiltinType::BuiltinType::SatAccum: + return "_Sat _Accum"; + case BuiltinType::BuiltinType::SatLongAccum: + return "_Sat long _Accum"; + case BuiltinType::BuiltinType::SatUShortAccum: + return "_Sat unsigned short _Accum"; + case BuiltinType::BuiltinType::SatUAccum: + return "_Sat unsigned _Accum"; + case BuiltinType::BuiltinType::SatULongAccum: + return "_Sat unsigned long _Accum"; + case BuiltinType::BuiltinType::SatShortFract: + return "_Sat short _Fract"; + case BuiltinType::BuiltinType::SatFract: + return "_Sat _Fract"; + case BuiltinType::BuiltinType::SatLongFract: + return "_Sat long _Fract"; + case BuiltinType::BuiltinType::SatUShortFract: + return "_Sat unsigned short _Fract"; + case BuiltinType::BuiltinType::SatUFract: + return "_Sat unsigned _Fract"; + case BuiltinType::BuiltinType::SatULongFract: + return "_Sat unsigned long _Fract"; +#endif + case BuiltinType::Float16: + return "_Float16"; + case BuiltinType::Float128: + return "__float128"; + case BuiltinType::WChar_S: + case BuiltinType::WChar_U: + return "wchar_t"; +#if LLVM_VERSION_MAJOR >= 7 + case BuiltinType::Char8: + return "char8_t"; +#endif + case BuiltinType::Char16: + return "char16_t"; + case BuiltinType::Char32: + return "char32_t"; + case BuiltinType::NullPtr: + return "nullptr_t"; + case BuiltinType::Overload: + return ""; + case BuiltinType::BoundMember: + return ""; + case BuiltinType::PseudoObject: + return ""; + case BuiltinType::Dependent: + return ""; + case BuiltinType::UnknownAny: + return ""; + case BuiltinType::ARCUnbridgedCast: + return ""; + case BuiltinType::BuiltinFn: + return ""; + case BuiltinType::ObjCId: + return "id"; + case BuiltinType::ObjCClass: + return "Class"; + case BuiltinType::ObjCSel: + return "SEL"; + case BuiltinType::OCLSampler: + return "sampler_t"; + case BuiltinType::OCLEvent: + return "event_t"; + case BuiltinType::OCLClkEvent: + return "clk_event_t"; + case BuiltinType::OCLQueue: + return "queue_t"; + case BuiltinType::OCLReserveID: + return "reserve_id_t"; + case BuiltinType::OMPArraySection: + return ""; + default: + return ""; + } +} diff --git a/src/clang_tu.h b/src/clang_tu.hh similarity index 88% rename from src/clang_tu.h rename to src/clang_tu.hh index 8e104e18..c790aa69 100644 --- a/src/clang_tu.h +++ b/src/clang_tu.hh @@ -2,13 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once + #include "position.h" #include +#include #include #include -#include +std::string PathFromFileEntry(const clang::FileEntry &file); Range FromCharSourceRange(const clang::SourceManager &SM, const clang::LangOptions &LangOpts, @@ -26,3 +28,5 @@ Range FromTokenRange(const clang::SourceManager &SM, std::unique_ptr BuildCompilerInvocation(std::vector args, llvm::IntrusiveRefCntPtr VFS); + +const char *ClangBuiltinTypeName(int); diff --git a/src/clang_utils.cc b/src/clang_utils.cc deleted file mode 100644 index 1026a6f3..00000000 --- a/src/clang_utils.cc +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright 2017-2018 ccls Authors -// SPDX-License-Identifier: Apache-2.0 - -#include "clang_utils.h" - -#include "config.h" -#include "filesystem.hh" -#include "platform.h" -#include "utils.h" - -#include -#include -using namespace clang; -using namespace llvm; - -std::string FileName(const FileEntry &file) { - StringRef Name = file.tryGetRealPathName(); - if (Name.empty()) - Name = file.getName(); - std::string ret = NormalizePath(Name); - // Resolve /usr/include/c++/7.3.0 symlink. - if (!StartsWith(ret, g_config->projectRoot)) { - SmallString<256> dest; - sys::fs::real_path(ret, dest); - ret = sys::path::convert_to_slash(dest.str()); - } - return ret; -} - -// clang::BuiltinType::getName without PrintingPolicy -const char *ClangBuiltinTypeName(int kind) { - switch (BuiltinType::Kind(kind)) { - case BuiltinType::Void: - return "void"; - case BuiltinType::Bool: - return "bool"; - case BuiltinType::Char_S: - return "char"; - case BuiltinType::Char_U: - return "char"; - case BuiltinType::SChar: - return "signed char"; - case BuiltinType::Short: - return "short"; - case BuiltinType::Int: - return "int"; - case BuiltinType::Long: - return "long"; - case BuiltinType::LongLong: - return "long long"; - case BuiltinType::Int128: - return "__int128"; - case BuiltinType::UChar: - return "unsigned char"; - case BuiltinType::UShort: - return "unsigned short"; - case BuiltinType::UInt: - return "unsigned int"; - case BuiltinType::ULong: - return "unsigned long"; - case BuiltinType::ULongLong: - return "unsigned long long"; - case BuiltinType::UInt128: - return "unsigned __int128"; - case BuiltinType::Half: - return "__fp16"; - case BuiltinType::Float: - return "float"; - case BuiltinType::Double: - return "double"; - case BuiltinType::LongDouble: - return "long double"; -#if LLVM_VERSION_MAJOR >= 7 - case BuiltinType::ShortAccum: - return "short _Accum"; - case BuiltinType::Accum: - return "_Accum"; - case BuiltinType::LongAccum: - return "long _Accum"; - case BuiltinType::UShortAccum: - return "unsigned short _Accum"; - case BuiltinType::UAccum: - return "unsigned _Accum"; - case BuiltinType::ULongAccum: - return "unsigned long _Accum"; - case BuiltinType::BuiltinType::ShortFract: - return "short _Fract"; - case BuiltinType::BuiltinType::Fract: - return "_Fract"; - case BuiltinType::BuiltinType::LongFract: - return "long _Fract"; - case BuiltinType::BuiltinType::UShortFract: - return "unsigned short _Fract"; - case BuiltinType::BuiltinType::UFract: - return "unsigned _Fract"; - case BuiltinType::BuiltinType::ULongFract: - return "unsigned long _Fract"; - case BuiltinType::BuiltinType::SatShortAccum: - return "_Sat short _Accum"; - case BuiltinType::BuiltinType::SatAccum: - return "_Sat _Accum"; - case BuiltinType::BuiltinType::SatLongAccum: - return "_Sat long _Accum"; - case BuiltinType::BuiltinType::SatUShortAccum: - return "_Sat unsigned short _Accum"; - case BuiltinType::BuiltinType::SatUAccum: - return "_Sat unsigned _Accum"; - case BuiltinType::BuiltinType::SatULongAccum: - return "_Sat unsigned long _Accum"; - case BuiltinType::BuiltinType::SatShortFract: - return "_Sat short _Fract"; - case BuiltinType::BuiltinType::SatFract: - return "_Sat _Fract"; - case BuiltinType::BuiltinType::SatLongFract: - return "_Sat long _Fract"; - case BuiltinType::BuiltinType::SatUShortFract: - return "_Sat unsigned short _Fract"; - case BuiltinType::BuiltinType::SatUFract: - return "_Sat unsigned _Fract"; - case BuiltinType::BuiltinType::SatULongFract: - return "_Sat unsigned long _Fract"; -#endif - case BuiltinType::Float16: - return "_Float16"; - case BuiltinType::Float128: - return "__float128"; - case BuiltinType::WChar_S: - case BuiltinType::WChar_U: - return "wchar_t"; -#if LLVM_VERSION_MAJOR >= 7 - case BuiltinType::Char8: - return "char8_t"; -#endif - case BuiltinType::Char16: - return "char16_t"; - case BuiltinType::Char32: - return "char32_t"; - case BuiltinType::NullPtr: - return "nullptr_t"; - case BuiltinType::Overload: - return ""; - case BuiltinType::BoundMember: - return ""; - case BuiltinType::PseudoObject: - return ""; - case BuiltinType::Dependent: - return ""; - case BuiltinType::UnknownAny: - return ""; - case BuiltinType::ARCUnbridgedCast: - return ""; - case BuiltinType::BuiltinFn: - return ""; - case BuiltinType::ObjCId: - return "id"; - case BuiltinType::ObjCClass: - return "Class"; - case BuiltinType::ObjCSel: - return "SEL"; - case BuiltinType::OCLSampler: - return "sampler_t"; - case BuiltinType::OCLEvent: - return "event_t"; - case BuiltinType::OCLClkEvent: - return "clk_event_t"; - case BuiltinType::OCLQueue: - return "queue_t"; - case BuiltinType::OCLReserveID: - return "reserve_id_t"; - case BuiltinType::OMPArraySection: - return ""; - default: - return ""; - } -} diff --git a/src/clang_utils.h b/src/clang_utils.h deleted file mode 100644 index 9c43bd51..00000000 --- a/src/clang_utils.h +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017-2018 ccls Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include - -#include - -// Returns the absolute path to |file|. -std::string FileName(const clang::FileEntry &file); - -const char *ClangBuiltinTypeName(int); diff --git a/src/indexer.cc b/src/indexer.cc index 84303b9b..bd37a012 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -4,7 +4,7 @@ #include "indexer.h" #include "clang_complete.hh" -#include "clang_tu.h" +#include "clang_tu.hh" #include "log.hh" #include "match.h" #include "pipeline.hh" @@ -61,7 +61,7 @@ struct IndexParam { // generating an index for it): auto [it, inserted] = UID2File.try_emplace(File.getUniqueID()); if (inserted) { - std::string path = FileName(File); + std::string path = PathFromFileEntry(File); it->second.path = path; it->second.mtime = File.getModificationTime(); if (!it->second.mtime) @@ -85,7 +85,7 @@ struct IndexParam { bool UseMultiVersion(const FileEntry &FE) { auto it = UID2multi.try_emplace(FE.getUniqueID()); if (it.second) - it.first->second = multiVersionMatcher->IsMatch(FileName(FE)); + it.first->second = multiVersionMatcher->IsMatch(PathFromFileEntry(FE)); return it.first->second; } }; @@ -1084,9 +1084,9 @@ public: if (!FE) return; if (IndexFile *db = param.ConsumeFile(*FE)) { - std::string file_name = FileName(*File); - if (file_name.size()) - db->includes.push_back({spell.start.line, Intern(file_name)}); + std::string path = PathFromFileEntry(*File); + if (path.size()) + db->includes.push_back({spell.start.line, Intern(path)}); } } void MacroDefined(const Token &Tok, const MacroDirective *MD) override { diff --git a/src/indexer.h b/src/indexer.h index 6d274166..dc9ccb76 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -3,7 +3,6 @@ #pragma once -#include "clang_utils.h" #include "language.h" #include "lsp.h" #include "lsp_diagnostic.h" @@ -13,6 +12,7 @@ #include "symbol.h" #include "utils.h" +#include #include #include #include diff --git a/src/messages/ccls_member.cc b/src/messages/ccls_member.cc index 2c13b19d..3ea02645 100644 --- a/src/messages/ccls_member.cc +++ b/src/messages/ccls_member.cc @@ -1,6 +1,7 @@ // Copyright 2017-2018 ccls Authors // SPDX-License-Identifier: Apache-2.0 +#include "clang_tu.hh" #include "hierarchy.hh" #include "message_handler.h" #include "pipeline.hh" diff --git a/src/project.cc b/src/project.cc index 2c0fcf6e..47709b39 100644 --- a/src/project.cc +++ b/src/project.cc @@ -3,7 +3,6 @@ #include "project.h" -#include "clang_utils.h" #include "filesystem.hh" #include "language.h" #include "log.hh"