[PATCH] D73780: [clangd] Separate protobuf-related functions to a dedicated file.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 5 02:12:08 PST 2020
hokein updated this revision to Diff 242536.
hokein added a comment.
update based on the offline discussion.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D73780/new/
https://reviews.llvm.org/D73780
Files:
clang-tools-extra/clangd/SourceCode.cpp
clang-tools-extra/clangd/SourceCode.h
clang-tools-extra/clangd/index/SymbolCollector.cpp
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===================================================================
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -70,25 +70,13 @@
return URI::create(AbsolutePath).toString();
}
-// All proto generated headers should start with this line.
-static const char *PROTO_HEADER_COMMENT =
- "// Generated by the protocol buffer compiler. DO NOT EDIT!";
-
// Checks whether the decl is a private symbol in a header generated by
// protobuf compiler.
-// To identify whether a proto header is actually generated by proto compiler,
-// we check whether it starts with PROTO_HEADER_COMMENT.
// FIXME: make filtering extensible when there are more use cases for symbol
// filters.
bool isPrivateProtoDecl(const NamedDecl &ND) {
const auto &SM = ND.getASTContext().getSourceManager();
- auto Loc = nameLocation(ND, SM);
- auto FileName = SM.getFilename(Loc);
- if (!FileName.endswith(".proto.h") && !FileName.endswith(".pb.h"))
- return false;
- auto FID = SM.getFileID(Loc);
- // Double check that this is an actual protobuf header.
- if (!SM.getBufferData(FID).startswith(PROTO_HEADER_COMMENT))
+ if (!isProtoFile(nameLocation(ND, SM), SM))
return false;
// ND without identifier can be operators.
Index: clang-tools-extra/clangd/SourceCode.h
===================================================================
--- clang-tools-extra/clangd/SourceCode.h
+++ clang-tools-extra/clangd/SourceCode.h
@@ -298,6 +298,9 @@
bool isHeaderFile(llvm::StringRef FileName,
llvm::Optional<LangOptions> LangOpts = llvm::None);
+/// Returns true if the given location is in a generated protobuf file.
+bool isProtoFile(SourceLocation Loc, const SourceManager &SourceMgr);
+
} // namespace clangd
} // namespace clang
#endif
Index: clang-tools-extra/clangd/SourceCode.cpp
===================================================================
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -1127,5 +1127,19 @@
return Lang != types::TY_INVALID && types::onlyPrecompileType(Lang);
}
+bool isProtoFile(SourceLocation Loc, const SourceManager &SM) {
+ auto FileName = SM.getFilename(Loc);
+ if (!FileName.endswith(".proto.h") && !FileName.endswith(".pb.h"))
+ return false;
+ auto FID = SM.getFileID(Loc);
+ // All proto generated headers should start with this line.
+ static const char *PROTO_HEADER_COMMENT =
+ "// Generated by the protocol buffer compiler. DO NOT EDIT!";
+ // Double check that this is an actual protobuf header.
+ if (!SM.getBufferData(FID).startswith(PROTO_HEADER_COMMENT))
+ return false;
+ return true;
+}
+
} // namespace clangd
} // namespace clang
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73780.242536.patch
Type: text/x-patch
Size: 2800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200205/c03d63dc/attachment.bin>
More information about the cfe-commits
mailing list