Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
clang-tools-extra/clangd/SourceCode.cpp
Show First 20 Lines • Show All 790 Lines • ▼ Show 20 Lines | llvm::SmallVector<llvm::StringRef> ancestorNamespaces(llvm::StringRef NS) { | ||||
llvm::SmallVector<llvm::StringRef> Results; | llvm::SmallVector<llvm::StringRef> Results; | ||||
Results.push_back(NS.take_front(0)); | Results.push_back(NS.take_front(0)); | ||||
NS.split(Results, "::", /*MaxSplit=*/-1, /*KeepEmpty=*/false); | NS.split(Results, "::", /*MaxSplit=*/-1, /*KeepEmpty=*/false); | ||||
for (llvm::StringRef &R : Results) | for (llvm::StringRef &R : Results) | ||||
R = NS.take_front(R.end() - NS.begin()); | R = NS.take_front(R.end() - NS.begin()); | ||||
return Results; | return Results; | ||||
} | } | ||||
// Checks whether \p FileName is a valid spelling of main file. | |||||
bool isMainFile(llvm::StringRef FileName, const SourceManager &SM) { | |||||
auto FE = SM.getFileManager().getFile(FileName); | |||||
return FE && *FE == SM.getFileEntryForID(SM.getMainFileID()); | |||||
} | |||||
} // namespace | } // namespace | ||||
std::vector<std::string> visibleNamespaces(llvm::StringRef Code, | std::vector<std::string> visibleNamespaces(llvm::StringRef Code, | ||||
const LangOptions &LangOpts) { | const LangOptions &LangOpts) { | ||||
std::string Current; | std::string Current; | ||||
// Map from namespace to (resolved) namespaces introduced via using directive. | // Map from namespace to (resolved) namespaces introduced via using directive. | ||||
llvm::StringMap<llvm::StringSet<>> UsingDirectives; | llvm::StringMap<llvm::StringSet<>> UsingDirectives; | ||||
▲ Show 20 Lines • Show All 407 Lines • ▼ Show 20 Lines | bool isProtoFile(SourceLocation Loc, const SourceManager &SM) { | ||||
auto FID = SM.getFileID(Loc); | auto FID = SM.getFileID(Loc); | ||||
// All proto generated headers should start with this line. | // All proto generated headers should start with this line. | ||||
static const char *ProtoHeaderComment = | static const char *ProtoHeaderComment = | ||||
"// Generated by the protocol buffer compiler. DO NOT EDIT!"; | "// Generated by the protocol buffer compiler. DO NOT EDIT!"; | ||||
// Double check that this is an actual protobuf header. | // Double check that this is an actual protobuf header. | ||||
return SM.getBufferData(FID).startswith(ProtoHeaderComment); | return SM.getBufferData(FID).startswith(ProtoHeaderComment); | ||||
} | } | ||||
SourceLocation translatePreamblePatchLocation(SourceLocation Loc, | |||||
const SourceManager &SM) { | |||||
auto DefFile = SM.getFileID(Loc); | |||||
if (auto FE = SM.getFileEntryRefForID(DefFile)) { | |||||
sammccall: just make it a function? it captures nothing | |||||
auto IncludeLoc = SM.getIncludeLoc(DefFile); | |||||
// Preamble patch is included inside the builtin file. | |||||
if (IncludeLoc.isValid() && SM.isWrittenInBuiltinFile(IncludeLoc) && | |||||
FE->getName().endswith(PreamblePatch::HeaderName)) { | |||||
auto Presumed = SM.getPresumedLoc(Loc); | |||||
// Check that line directive is pointing at main file. | |||||
if (Presumed.isValid() && Presumed.getFileID().isInvalid() && | |||||
isMainFile(Presumed.getFilename(), SM)) { | |||||
Loc = SM.translateLineCol(SM.getMainFileID(), Presumed.getLine(), | |||||
Presumed.getColumn()); | |||||
} | |||||
} | |||||
} | |||||
return Loc; | |||||
} | |||||
} // namespace clangd | } // namespace clangd | ||||
} // namespace clang | } // namespace clang |
just make it a function? it captures nothing