|
14 | 14 | using namespace clang;
|
15 | 15 |
|
16 | 16 | namespace ccls {
|
17 |
| -std::string PathFromFileEntry(const FileEntry &file) { |
18 |
| - StringRef Name = file.tryGetRealPathName(); |
19 |
| - if (Name.empty()) |
20 |
| - Name = file.getName(); |
21 |
| - std::string ret = NormalizePath(Name); |
| 17 | +std::string pathFromFileEntry(const FileEntry &file) { |
| 18 | + StringRef name = file.tryGetRealPathName(); |
| 19 | + if (name.empty()) |
| 20 | + name = file.getName(); |
| 21 | + std::string ret = normalizePath(name); |
22 | 22 | // Resolve symlinks outside of workspace folders, e.g. /usr/include/c++/7.3.0
|
23 |
| - return NormalizeFolder(ret) ? ret : RealPath(ret); |
| 23 | + return normalizeFolder(ret) ? ret : realPath(ret); |
24 | 24 | }
|
25 | 25 |
|
26 |
| -static Pos Decomposed2LineAndCol(const SourceManager &SM, |
27 |
| - std::pair<FileID, unsigned> I) { |
28 |
| - int l = (int)SM.getLineNumber(I.first, I.second) - 1, |
29 |
| - c = (int)SM.getColumnNumber(I.first, I.second) - 1; |
30 |
| - bool Invalid = false; |
31 |
| - StringRef Buf = SM.getBufferData(I.first, &Invalid); |
32 |
| - if (!Invalid) { |
33 |
| - StringRef P = Buf.substr(I.second - c, c); |
| 26 | +static Pos decomposed2LineAndCol(const SourceManager &sm, |
| 27 | + std::pair<FileID, unsigned> i) { |
| 28 | + int l = (int)sm.getLineNumber(i.first, i.second) - 1, |
| 29 | + c = (int)sm.getColumnNumber(i.first, i.second) - 1; |
| 30 | + bool invalid = false; |
| 31 | + StringRef buf = sm.getBufferData(i.first, &invalid); |
| 32 | + if (!invalid) { |
| 33 | + StringRef p = buf.substr(i.second - c, c); |
34 | 34 | c = 0;
|
35 |
| - for (size_t i = 0; i < P.size(); ) |
36 |
| - if (c++, (uint8_t)P[i++] >= 128) |
37 |
| - while (i < P.size() && (uint8_t)P[i] >= 128 && (uint8_t)P[i] < 192) |
| 35 | + for (size_t i = 0; i < p.size();) |
| 36 | + if (c++, (uint8_t)p[i++] >= 128) |
| 37 | + while (i < p.size() && (uint8_t)p[i] >= 128 && (uint8_t)p[i] < 192) |
38 | 38 | i++;
|
39 | 39 | }
|
40 | 40 | return {(uint16_t)std::min<int>(l, UINT16_MAX),
|
41 | 41 | (int16_t)std::min<int>(c, INT16_MAX)};
|
42 | 42 | }
|
43 | 43 |
|
44 |
| -Range FromCharSourceRange(const SourceManager &SM, const LangOptions &LangOpts, |
45 |
| - CharSourceRange R, |
46 |
| - llvm::sys::fs::UniqueID *UniqueID) { |
47 |
| - SourceLocation BLoc = R.getBegin(), ELoc = R.getEnd(); |
48 |
| - std::pair<FileID, unsigned> BInfo = SM.getDecomposedLoc(BLoc), |
49 |
| - EInfo = SM.getDecomposedLoc(ELoc); |
50 |
| - if (R.isTokenRange()) |
51 |
| - EInfo.second += Lexer::MeasureTokenLength(ELoc, SM, LangOpts); |
52 |
| - if (UniqueID) { |
53 |
| - if (const FileEntry *F = SM.getFileEntryForID(BInfo.first)) |
54 |
| - *UniqueID = F->getUniqueID(); |
| 44 | +Range fromCharSourceRange(const SourceManager &sm, const LangOptions &lang, |
| 45 | + CharSourceRange csr, |
| 46 | + llvm::sys::fs::UniqueID *uniqueID) { |
| 47 | + SourceLocation bloc = csr.getBegin(), eloc = csr.getEnd(); |
| 48 | + std::pair<FileID, unsigned> binfo = sm.getDecomposedLoc(bloc), |
| 49 | + einfo = sm.getDecomposedLoc(eloc); |
| 50 | + if (csr.isTokenRange()) |
| 51 | + einfo.second += Lexer::MeasureTokenLength(eloc, sm, lang); |
| 52 | + if (uniqueID) { |
| 53 | + if (const FileEntry *F = sm.getFileEntryForID(binfo.first)) |
| 54 | + *uniqueID = F->getUniqueID(); |
55 | 55 | else
|
56 |
| - *UniqueID = llvm::sys::fs::UniqueID(0, 0); |
| 56 | + *uniqueID = llvm::sys::fs::UniqueID(0, 0); |
57 | 57 | }
|
58 |
| - return {Decomposed2LineAndCol(SM, BInfo), Decomposed2LineAndCol(SM, EInfo)}; |
| 58 | + return {decomposed2LineAndCol(sm, binfo), decomposed2LineAndCol(sm, einfo)}; |
59 | 59 | }
|
60 | 60 |
|
61 |
| -Range FromCharRange(const SourceManager &SM, const LangOptions &Lang, |
62 |
| - SourceRange R, llvm::sys::fs::UniqueID *UniqueID) { |
63 |
| - return FromCharSourceRange(SM, Lang, CharSourceRange::getCharRange(R), |
64 |
| - UniqueID); |
| 61 | +Range fromCharRange(const SourceManager &sm, const LangOptions &lang, |
| 62 | + SourceRange sr, llvm::sys::fs::UniqueID *uniqueID) { |
| 63 | + return fromCharSourceRange(sm, lang, CharSourceRange::getCharRange(sr), |
| 64 | + uniqueID); |
65 | 65 | }
|
66 | 66 |
|
67 |
| -Range FromTokenRange(const SourceManager &SM, const LangOptions &Lang, |
68 |
| - SourceRange R, llvm::sys::fs::UniqueID *UniqueID) { |
69 |
| - return FromCharSourceRange(SM, Lang, CharSourceRange::getTokenRange(R), |
70 |
| - UniqueID); |
| 67 | +Range fromTokenRange(const SourceManager &sm, const LangOptions &lang, |
| 68 | + SourceRange sr, llvm::sys::fs::UniqueID *uniqueID) { |
| 69 | + return fromCharSourceRange(sm, lang, CharSourceRange::getTokenRange(sr), |
| 70 | + uniqueID); |
71 | 71 | }
|
72 | 72 |
|
73 |
| -Range FromTokenRangeDefaulted(const SourceManager &SM, const LangOptions &Lang, |
74 |
| - SourceRange R, const FileEntry *FE, Range range) { |
75 |
| - auto I = SM.getDecomposedLoc(SM.getExpansionLoc(R.getBegin())); |
76 |
| - if (SM.getFileEntryForID(I.first) == FE) |
77 |
| - range.start = Decomposed2LineAndCol(SM, I); |
78 |
| - SourceLocation L = SM.getExpansionLoc(R.getEnd()); |
79 |
| - I = SM.getDecomposedLoc(L); |
80 |
| - if (SM.getFileEntryForID(I.first) == FE) { |
81 |
| - I.second += Lexer::MeasureTokenLength(L, SM, Lang); |
82 |
| - range.end = Decomposed2LineAndCol(SM, I); |
| 73 | +Range fromTokenRangeDefaulted(const SourceManager &sm, const LangOptions &lang, |
| 74 | + SourceRange sr, const FileEntry *fe, Range range) { |
| 75 | + auto decomposed = sm.getDecomposedLoc(sm.getExpansionLoc(sr.getBegin())); |
| 76 | + if (sm.getFileEntryForID(decomposed.first) == fe) |
| 77 | + range.start = decomposed2LineAndCol(sm, decomposed); |
| 78 | + SourceLocation sl = sm.getExpansionLoc(sr.getEnd()); |
| 79 | + decomposed = sm.getDecomposedLoc(sl); |
| 80 | + if (sm.getFileEntryForID(decomposed.first) == fe) { |
| 81 | + decomposed.second += Lexer::MeasureTokenLength(sl, sm, lang); |
| 82 | + range.end = decomposed2LineAndCol(sm, decomposed); |
83 | 83 | }
|
84 | 84 | return range;
|
85 | 85 | }
|
86 | 86 |
|
87 | 87 | std::unique_ptr<CompilerInvocation>
|
88 |
| -BuildCompilerInvocation(const std::string &main, std::vector<const char *> args, |
89 |
| - IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) { |
| 88 | +buildCompilerInvocation(const std::string &main, std::vector<const char *> args, |
| 89 | + IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs) { |
90 | 90 | std::string save = "-resource-dir=" + g_config->clang.resourceDir;
|
91 | 91 | args.push_back(save.c_str());
|
92 |
| - IntrusiveRefCntPtr<DiagnosticsEngine> Diags( |
| 92 | + IntrusiveRefCntPtr<DiagnosticsEngine> diags( |
93 | 93 | CompilerInstance::createDiagnostics(new DiagnosticOptions,
|
94 | 94 | new IgnoringDiagConsumer, true));
|
95 |
| - std::unique_ptr<CompilerInvocation> CI = |
96 |
| - createInvocationFromCommandLine(args, Diags, VFS); |
97 |
| - if (CI) { |
98 |
| - CI->getDiagnosticOpts().IgnoreWarnings = true; |
99 |
| - CI->getFrontendOpts().DisableFree = false; |
100 |
| - CI->getLangOpts()->SpellChecking = false; |
101 |
| - auto &IS = CI->getFrontendOpts().Inputs; |
102 |
| - if (IS.size()) |
103 |
| - IS[0] = FrontendInputFile(main, IS[0].getKind(), IS[0].isSystem()); |
| 95 | + std::unique_ptr<CompilerInvocation> ci = |
| 96 | + createInvocationFromCommandLine(args, diags, vfs); |
| 97 | + if (ci) { |
| 98 | + ci->getDiagnosticOpts().IgnoreWarnings = true; |
| 99 | + ci->getFrontendOpts().DisableFree = false; |
| 100 | + ci->getLangOpts()->SpellChecking = false; |
| 101 | + auto &isec = ci->getFrontendOpts().Inputs; |
| 102 | + if (isec.size()) |
| 103 | + isec[0] = FrontendInputFile(main, isec[0].getKind(), isec[0].isSystem()); |
104 | 104 | }
|
105 |
| - return CI; |
| 105 | + return ci; |
106 | 106 | }
|
107 | 107 |
|
108 | 108 | // clang::BuiltinType::getName without PrintingPolicy
|
109 |
| -const char *ClangBuiltinTypeName(int kind) { |
| 109 | +const char *clangBuiltinTypeName(int kind) { |
110 | 110 | switch (BuiltinType::Kind(kind)) {
|
111 | 111 | case BuiltinType::Void:
|
112 | 112 | return "void";
|
|
0 commit comments