From d62e3ed3f4b9e1c7492194d0c9997147bdfe6aa6 Mon Sep 17 00:00:00 2001 From: Kadir Cetinkaya Date: Wed, 25 Sep 2019 11:35:38 +0200 Subject: [clangd] Implement GetEligiblePoints Summary: This is an helper for incoming move definition out-of-line action to figure out possible insertion locations for definition of a qualified name. Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68024 --- clang-tools-extra/clangd/SourceCode.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'clang-tools-extra/clangd/SourceCode.h') diff --git a/clang-tools-extra/clangd/SourceCode.h b/clang-tools-extra/clangd/SourceCode.h index 3017746c17e..a05d8adf923 100644 --- a/clang-tools-extra/clangd/SourceCode.h +++ b/clang-tools-extra/clangd/SourceCode.h @@ -262,6 +262,27 @@ llvm::StringSet<> collectWords(llvm::StringRef Content); std::vector visibleNamespaces(llvm::StringRef Code, const format::FormatStyle &Style); +/// Represents locations that can accept a definition. +struct EligibleRegion { + /// Namespace that owns all of the EligiblePoints, e.g. + /// namespace a{ namespace b {^ void foo();^} } + /// It will be “a::b” for both carrot locations. + std::string EnclosingNamespace; + /// Offsets into the code marking eligible points to insert a function + /// definition. + std::vector EligiblePoints; +}; + +/// Returns most eligible region to insert a definition for \p +/// FullyQualifiedName in the \p Code. +/// Pseudo parses \pCode under the hood to determine namespace decls and +/// possible insertion points. Choses the region that matches the longest prefix +/// of \p FullyQualifiedName. Returns EOF if there are no shared namespaces. +/// \p FullyQualifiedName should not contain anonymous namespaces. +EligibleRegion getEligiblePoints(llvm::StringRef Code, + llvm::StringRef FullyQualifiedName, + const format::FormatStyle &Style); + struct DefinedMacro { llvm::StringRef Name; const MacroInfo *Info; -- cgit v1.2.3