[clangd] Get rid of regexes in CanonicalIncludes

Summary: Replace them with suffix mappings.

Reviewers: ioeric, kbobyrev

Reviewed By: ioeric

Subscribers: MaskRay, jkorous, arphaman, jfb, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D51088

llvm-svn: 340410
This commit is contained in:
Ilya Biryukov 2018-08-22 13:51:19 +00:00
parent 7413e985ea
commit 22abe49fff
2 changed files with 687 additions and 679 deletions

File diff suppressed because it is too large Load Diff

View File

@ -40,8 +40,10 @@ public:
/// Adds a string-to-string mapping from \p Path to \p CanonicalPath.
void addMapping(llvm::StringRef Path, llvm::StringRef CanonicalPath);
/// Maps all files matching \p RE to \p CanonicalPath
void addRegexMapping(llvm::StringRef RE, llvm::StringRef CanonicalPath);
/// Maps files with last path components matching \p Suffix to \p
/// CanonicalPath.
void addPathSuffixMapping(llvm::StringRef Suffix,
llvm::StringRef CanonicalPath);
/// Sets the canonical include for any symbol with \p QualifiedName.
/// Symbol mappings take precedence over header mappings.
@ -55,17 +57,15 @@ public:
llvm::StringRef QualifiedName) const;
private:
// A map from header patterns to header names. This needs to be mutable so
// that we can match again a Regex in a const function member.
// FIXME(ioeric): All the regexes we have so far are suffix matches. The
// performance could be improved by allowing only suffix matches instead of
// arbitrary regexes.
mutable std::vector<std::pair<llvm::Regex, std::string>>
RegexHeaderMappingTable;
// A map from fully qualified symbol names to header names.
/// A map from full include path to a canonical path.
llvm::StringMap<std::string> FullPathMapping;
/// A map from a suffix (one or components of a path) to a canonical path.
llvm::StringMap<std::string> SuffixHeaderMapping;
/// Maximum number of path components stored in a key of SuffixHeaderMapping.
/// Used to reduce the number of lookups into SuffixHeaderMapping.
int MaxSuffixComponents = 0;
/// A map from fully qualified symbol names to header names.
llvm::StringMap<std::string> SymbolMapping;
// Guards Regex matching as it's not thread-safe.
mutable std::mutex RegexMutex;
};
/// Returns a CommentHandler that parses pragma comment on include files to