| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 1 | //===--- SymbolCollector.cpp -------------------------------------*- C++-*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "SymbolCollector.h" |
| Eric Liu | f768868 | 2018-09-07 09:40:36 +0000 | [diff] [blame] | 11 | #include "AST.h" |
| Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 12 | #include "CanonicalIncludes.h" |
| Eric Liu | f768868 | 2018-09-07 09:40:36 +0000 | [diff] [blame] | 13 | #include "CodeComplete.h" |
| 14 | #include "CodeCompletionStrings.h" |
| 15 | #include "Logger.h" |
| 16 | #include "SourceCode.h" |
| 17 | #include "URI.h" |
| Eric Liu | a57afd0 | 2018-09-17 07:43:49 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
| 19 | #include "clang/AST/DeclBase.h" |
| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclCXX.h" |
| Ilya Biryukov | cf124bd | 2018-04-13 11:03:07 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclTemplate.h" |
| Haojian Wu | 7dd4950 | 2018-10-17 08:38:36 +0000 | [diff] [blame] | 22 | #include "clang/Basic/SourceLocation.h" |
| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 23 | #include "clang/Basic/SourceManager.h" |
| Eric Liu | a57afd0 | 2018-09-17 07:43:49 +0000 | [diff] [blame] | 24 | #include "clang/Basic/Specifiers.h" |
| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 25 | #include "clang/Index/IndexSymbol.h" |
| 26 | #include "clang/Index/USRGeneration.h" |
| Eric Liu | a57afd0 | 2018-09-17 07:43:49 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Casting.h" |
| Eric Liu | 278e2d1 | 2018-01-29 15:13:29 +0000 | [diff] [blame] | 28 | #include "llvm/Support/FileSystem.h" |
| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 29 | #include "llvm/Support/MemoryBuffer.h" |
| 30 | #include "llvm/Support/Path.h" |
| 31 | |
| 32 | namespace clang { |
| 33 | namespace clangd { |
| 34 | |
| 35 | namespace { |
| Ilya Biryukov | f118d51 | 2018-04-14 16:27:35 +0000 | [diff] [blame] | 36 | /// If \p ND is a template specialization, returns the described template. |
| Ilya Biryukov | cf124bd | 2018-04-13 11:03:07 +0000 | [diff] [blame] | 37 | /// Otherwise, returns \p ND. |
| 38 | const NamedDecl &getTemplateOrThis(const NamedDecl &ND) { |
| Ilya Biryukov | f118d51 | 2018-04-14 16:27:35 +0000 | [diff] [blame] | 39 | if (auto T = ND.getDescribedTemplate()) |
| 40 | return *T; |
| Ilya Biryukov | cf124bd | 2018-04-13 11:03:07 +0000 | [diff] [blame] | 41 | return ND; |
| 42 | } |
| 43 | |
| Eric Liu | 7f24765 | 2018-02-06 16:10:35 +0000 | [diff] [blame] | 44 | // Returns a URI of \p Path. Firstly, this makes the \p Path absolute using the |
| 45 | // current working directory of the given SourceManager if the Path is not an |
| 46 | // absolute path. If failed, this resolves relative paths against \p FallbackDir |
| 47 | // to get an absolute path. Then, this tries creating an URI for the absolute |
| 48 | // path with schemes specified in \p Opts. This returns an URI with the first |
| 49 | // working scheme, if there is any; otherwise, this returns None. |
| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 50 | // |
| 51 | // The Path can be a path relative to the build directory, or retrieved from |
| 52 | // the SourceManager. |
| Eric Liu | 7f24765 | 2018-02-06 16:10:35 +0000 | [diff] [blame] | 53 | llvm::Optional<std::string> toURI(const SourceManager &SM, StringRef Path, |
| 54 | const SymbolCollector::Options &Opts) { |
| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 55 | llvm::SmallString<128> AbsolutePath(Path); |
| 56 | if (std::error_code EC = |
| 57 | SM.getFileManager().getVirtualFileSystem()->makeAbsolute( |
| 58 | AbsolutePath)) |
| Sam McCall | bed5885 | 2018-07-11 10:35:11 +0000 | [diff] [blame] | 59 | log("Warning: could not make absolute file: {0}", EC.message()); |
| Eric Liu | 278e2d1 | 2018-01-29 15:13:29 +0000 | [diff] [blame] | 60 | if (llvm::sys::path::is_absolute(AbsolutePath)) { |
| 61 | // Handle the symbolic link path case where the current working directory |
| 62 | // (getCurrentWorkingDirectory) is a symlink./ We always want to the real |
| 63 | // file path (instead of the symlink path) for the C++ symbols. |
| 64 | // |
| 65 | // Consider the following example: |
| 66 | // |
| 67 | // src dir: /project/src/foo.h |
| 68 | // current working directory (symlink): /tmp/build -> /project/src/ |
| 69 | // |
| 70 | // The file path of Symbol is "/project/src/foo.h" instead of |
| 71 | // "/tmp/build/foo.h" |
| 72 | if (const DirectoryEntry *Dir = SM.getFileManager().getDirectory( |
| 73 | llvm::sys::path::parent_path(AbsolutePath.str()))) { |
| 74 | StringRef DirName = SM.getFileManager().getCanonicalName(Dir); |
| 75 | SmallString<128> AbsoluteFilename; |
| 76 | llvm::sys::path::append(AbsoluteFilename, DirName, |
| 77 | llvm::sys::path::filename(AbsolutePath.str())); |
| 78 | AbsolutePath = AbsoluteFilename; |
| 79 | } |
| Eric Liu | 7f24765 | 2018-02-06 16:10:35 +0000 | [diff] [blame] | 80 | } else if (!Opts.FallbackDir.empty()) { |
| 81 | llvm::sys::fs::make_absolute(Opts.FallbackDir, AbsolutePath); |
| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 82 | } |
| Eric Liu | 7f24765 | 2018-02-06 16:10:35 +0000 | [diff] [blame] | 83 | |
| Eric Liu | a095770 | 2018-06-25 11:50:11 +0000 | [diff] [blame] | 84 | llvm::sys::path::remove_dots(AbsolutePath, /*remove_dot_dot=*/true); |
| 85 | |
| Eric Liu | 7f24765 | 2018-02-06 16:10:35 +0000 | [diff] [blame] | 86 | std::string ErrMsg; |
| 87 | for (const auto &Scheme : Opts.URISchemes) { |
| 88 | auto U = URI::create(AbsolutePath, Scheme); |
| 89 | if (U) |
| 90 | return U->toString(); |
| 91 | ErrMsg += llvm::toString(U.takeError()) + "\n"; |
| 92 | } |
| Sam McCall | bed5885 | 2018-07-11 10:35:11 +0000 | [diff] [blame] | 93 | log("Failed to create an URI for file {0}: {1}", AbsolutePath, ErrMsg); |
| Eric Liu | 7f24765 | 2018-02-06 16:10:35 +0000 | [diff] [blame] | 94 | return llvm::None; |
| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 95 | } |
| Eric Liu | 4feda80 | 2017-12-19 11:37:40 +0000 | [diff] [blame] | 96 | |
| Eric Liu | d67ec24 | 2018-05-16 12:12:30 +0000 | [diff] [blame] | 97 | // All proto generated headers should start with this line. |
| 98 | static const char *PROTO_HEADER_COMMENT = |
| 99 | "// Generated by the protocol buffer compiler. DO NOT EDIT!"; |
| 100 | |
| 101 | // Checks whether the decl is a private symbol in a header generated by |
| 102 | // protobuf compiler. |
| 103 | // To identify whether a proto header is actually generated by proto compiler, |
| 104 | // we check whether it starts with PROTO_HEADER_COMMENT. |
| 105 | // FIXME: make filtering extensible when there are more use cases for symbol |
| 106 | // filters. |
| 107 | bool isPrivateProtoDecl(const NamedDecl &ND) { |
| 108 | const auto &SM = ND.getASTContext().getSourceManager(); |
| 109 | auto Loc = findNameLoc(&ND); |
| 110 | auto FileName = SM.getFilename(Loc); |
| 111 | if (!FileName.endswith(".proto.h") && !FileName.endswith(".pb.h")) |
| 112 | return false; |
| 113 | auto FID = SM.getFileID(Loc); |
| 114 | // Double check that this is an actual protobuf header. |
| 115 | if (!SM.getBufferData(FID).startswith(PROTO_HEADER_COMMENT)) |
| 116 | return false; |
| 117 | |
| 118 | // ND without identifier can be operators. |
| 119 | if (ND.getIdentifier() == nullptr) |
| 120 | return false; |
| 121 | auto Name = ND.getIdentifier()->getName(); |
| 122 | if (!Name.contains('_')) |
| 123 | return false; |
| 124 | // Nested proto entities (e.g. Message::Nested) have top-level decls |
| 125 | // that shouldn't be used (Message_Nested). Ignore them completely. |
| 126 | // The nested entities are dangling type aliases, we may want to reconsider |
| 127 | // including them in the future. |
| 128 | // For enum constants, SOME_ENUM_CONSTANT is not private and should be |
| 129 | // indexed. Outer_INNER is private. This heuristic relies on naming style, it |
| 130 | // will include OUTER_INNER and exclude some_enum_constant. |
| 131 | // FIXME: the heuristic relies on naming style (i.e. no underscore in |
| 132 | // user-defined names) and can be improved. |
| Kirill Bobyrev | 4a5ff88 | 2018-10-07 14:49:41 +0000 | [diff] [blame] | 133 | return (ND.getKind() != Decl::EnumConstant) || llvm::any_of(Name, islower); |
| Eric Liu | d67ec24 | 2018-05-16 12:12:30 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 136 | // We only collect #include paths for symbols that are suitable for global code |
| 137 | // completion, except for namespaces since #include path for a namespace is hard |
| 138 | // to define. |
| 139 | bool shouldCollectIncludePath(index::SymbolKind Kind) { |
| 140 | using SK = index::SymbolKind; |
| 141 | switch (Kind) { |
| 142 | case SK::Macro: |
| 143 | case SK::Enum: |
| 144 | case SK::Struct: |
| 145 | case SK::Class: |
| 146 | case SK::Union: |
| 147 | case SK::TypeAlias: |
| 148 | case SK::Using: |
| 149 | case SK::Function: |
| 150 | case SK::Variable: |
| 151 | case SK::EnumConstant: |
| 152 | return true; |
| 153 | default: |
| 154 | return false; |
| 155 | } |
| 156 | } |
| 157 | |
| Eric Liu | 02ce01f | 2018-02-22 10:14:05 +0000 | [diff] [blame] | 158 | /// Gets a canonical include (URI of the header or <header> or "header") for |
| 159 | /// header of \p Loc. |
| 160 | /// Returns None if fails to get include header for \p Loc. |
| Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 161 | llvm::Optional<std::string> |
| Eric Liu | b96363d | 2018-03-01 18:06:40 +0000 | [diff] [blame] | 162 | getIncludeHeader(llvm::StringRef QName, const SourceManager &SM, |
| 163 | SourceLocation Loc, const SymbolCollector::Options &Opts) { |
| Eric Liu | 3cee95e | 2018-05-24 14:40:24 +0000 | [diff] [blame] | 164 | std::vector<std::string> Headers; |
| 165 | // Collect the #include stack. |
| 166 | while (true) { |
| 167 | if (!Loc.isValid()) |
| 168 | break; |
| 169 | auto FilePath = SM.getFilename(Loc); |
| 170 | if (FilePath.empty()) |
| 171 | break; |
| 172 | Headers.push_back(FilePath); |
| 173 | if (SM.isInMainFile(Loc)) |
| 174 | break; |
| 175 | Loc = SM.getIncludeLoc(SM.getFileID(Loc)); |
| Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 176 | } |
| Eric Liu | 3cee95e | 2018-05-24 14:40:24 +0000 | [diff] [blame] | 177 | if (Headers.empty()) |
| 178 | return llvm::None; |
| 179 | llvm::StringRef Header = Headers[0]; |
| 180 | if (Opts.Includes) { |
| 181 | Header = Opts.Includes->mapHeader(Headers, QName); |
| 182 | if (Header.startswith("<") || Header.startswith("\"")) |
| 183 | return Header.str(); |
| 184 | } |
| 185 | return toURI(SM, Header, Opts); |
| Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| Haojian Wu | d81e314 | 2018-08-31 12:54:13 +0000 | [diff] [blame] | 188 | // Return the symbol range of the token at \p TokLoc. |
| 189 | std::pair<SymbolLocation::Position, SymbolLocation::Position> |
| 190 | getTokenRange(SourceLocation TokLoc, const SourceManager &SM, |
| 191 | const LangOptions &LangOpts) { |
| 192 | auto CreatePosition = [&SM](SourceLocation Loc) { |
| 193 | auto LSPLoc = sourceLocToPosition(SM, Loc); |
| 194 | SymbolLocation::Position Pos; |
| Haojian Wu | b515fab | 2018-10-18 10:43:50 +0000 | [diff] [blame^] | 195 | Pos.setLine(LSPLoc.line); |
| 196 | Pos.setColumn(LSPLoc.character); |
| Haojian Wu | d81e314 | 2018-08-31 12:54:13 +0000 | [diff] [blame] | 197 | return Pos; |
| 198 | }; |
| 199 | |
| 200 | auto TokenLength = clang::Lexer::MeasureTokenLength(TokLoc, SM, LangOpts); |
| 201 | return {CreatePosition(TokLoc), |
| 202 | CreatePosition(TokLoc.getLocWithOffset(TokenLength))}; |
| 203 | } |
| 204 | |
| 205 | // Return the symbol location of the token at \p TokLoc. |
| Eric Liu | 48db19e | 2018-07-09 15:31:07 +0000 | [diff] [blame] | 206 | llvm::Optional<SymbolLocation> |
| 207 | getTokenLocation(SourceLocation TokLoc, const SourceManager &SM, |
| 208 | const SymbolCollector::Options &Opts, |
| 209 | const clang::LangOptions &LangOpts, |
| 210 | std::string &FileURIStorage) { |
| 211 | auto U = toURI(SM, SM.getFilename(TokLoc), Opts); |
| Eric Liu | 7f24765 | 2018-02-06 16:10:35 +0000 | [diff] [blame] | 212 | if (!U) |
| 213 | return llvm::None; |
| 214 | FileURIStorage = std::move(*U); |
| Sam McCall | 6003951 | 2018-02-09 14:42:01 +0000 | [diff] [blame] | 215 | SymbolLocation Result; |
| 216 | Result.FileURI = FileURIStorage; |
| Haojian Wu | d81e314 | 2018-08-31 12:54:13 +0000 | [diff] [blame] | 217 | auto Range = getTokenRange(TokLoc, SM, LangOpts); |
| 218 | Result.Start = Range.first; |
| 219 | Result.End = Range.second; |
| Haojian Wu | 545c02a | 2018-04-13 08:30:39 +0000 | [diff] [blame] | 220 | |
| Sam McCall | 6003951 | 2018-02-09 14:42:01 +0000 | [diff] [blame] | 221 | return std::move(Result); |
| Haojian Wu | b018906 | 2018-01-31 12:56:51 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| Eric Liu | cf8601b | 2018-02-28 09:33:15 +0000 | [diff] [blame] | 224 | // Checks whether \p ND is a definition of a TagDecl (class/struct/enum/union) |
| 225 | // in a header file, in which case clangd would prefer to use ND as a canonical |
| 226 | // declaration. |
| 227 | // FIXME: handle symbol types that are not TagDecl (e.g. functions), if using |
| Fangrui Song | 943e12e | 2018-03-29 20:03:16 +0000 | [diff] [blame] | 228 | // the first seen declaration as canonical declaration is not a good enough |
| Eric Liu | cf8601b | 2018-02-28 09:33:15 +0000 | [diff] [blame] | 229 | // heuristic. |
| 230 | bool isPreferredDeclaration(const NamedDecl &ND, index::SymbolRoleSet Roles) { |
| Sam McCall | 5fb9746 | 2018-10-05 14:03:04 +0000 | [diff] [blame] | 231 | const auto& SM = ND.getASTContext().getSourceManager(); |
| Eric Liu | cf8601b | 2018-02-28 09:33:15 +0000 | [diff] [blame] | 232 | return (Roles & static_cast<unsigned>(index::SymbolRole::Definition)) && |
| 233 | llvm::isa<TagDecl>(&ND) && |
| Sam McCall | 5fb9746 | 2018-10-05 14:03:04 +0000 | [diff] [blame] | 234 | !SM.isWrittenInMainFile(SM.getExpansionLoc(ND.getLocation())); |
| Eric Liu | cf8601b | 2018-02-28 09:33:15 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| Sam McCall | b013831 | 2018-09-04 14:39:56 +0000 | [diff] [blame] | 237 | RefKind toRefKind(index::SymbolRoleSet Roles) { |
| 238 | return static_cast<RefKind>(static_cast<unsigned>(RefKind::All) & Roles); |
| Haojian Wu | d81e314 | 2018-08-31 12:54:13 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| Eric Liu | a57afd0 | 2018-09-17 07:43:49 +0000 | [diff] [blame] | 241 | template <class T> bool explicitTemplateSpecialization(const NamedDecl &ND) { |
| 242 | if (const auto *TD = llvm::dyn_cast<T>(&ND)) |
| 243 | if (TD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) |
| 244 | return true; |
| 245 | return false; |
| 246 | } |
| 247 | |
| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 248 | } // namespace |
| 249 | |
| Eric Liu | 9af958f | 2018-01-10 14:57:58 +0000 | [diff] [blame] | 250 | SymbolCollector::SymbolCollector(Options Opts) : Opts(std::move(Opts)) {} |
| 251 | |
| Eric Liu | 76f6b44 | 2018-01-09 17:32:00 +0000 | [diff] [blame] | 252 | void SymbolCollector::initialize(ASTContext &Ctx) { |
| 253 | ASTCtx = &Ctx; |
| 254 | CompletionAllocator = std::make_shared<GlobalCodeCompletionAllocator>(); |
| 255 | CompletionTUInfo = |
| 256 | llvm::make_unique<CodeCompletionTUInfo>(CompletionAllocator); |
| 257 | } |
| 258 | |
| Eric Liu | 8763e48 | 2018-06-21 12:12:26 +0000 | [diff] [blame] | 259 | bool SymbolCollector::shouldCollectSymbol(const NamedDecl &ND, |
| 260 | ASTContext &ASTCtx, |
| 261 | const Options &Opts) { |
| Eric Liu | 8763e48 | 2018-06-21 12:12:26 +0000 | [diff] [blame] | 262 | if (ND.isImplicit()) |
| 263 | return false; |
| 264 | // Skip anonymous declarations, e.g (anonymous enum/class/struct). |
| 265 | if (ND.getDeclName().isEmpty()) |
| 266 | return false; |
| 267 | |
| 268 | // FIXME: figure out a way to handle internal linkage symbols (e.g. static |
| 269 | // variables, function) defined in the .cc files. Also we skip the symbols |
| 270 | // in anonymous namespace as the qualifier names of these symbols are like |
| 271 | // `foo::<anonymous>::bar`, which need a special handling. |
| 272 | // In real world projects, we have a relatively large set of header files |
| 273 | // that define static variables (like "static const int A = 1;"), we still |
| 274 | // want to collect these symbols, although they cause potential ODR |
| 275 | // violations. |
| 276 | if (ND.isInAnonymousNamespace()) |
| 277 | return false; |
| 278 | |
| 279 | // We want most things but not "local" symbols such as symbols inside |
| 280 | // FunctionDecl, BlockDecl, ObjCMethodDecl and OMPDeclareReductionDecl. |
| 281 | // FIXME: Need a matcher for ExportDecl in order to include symbols declared |
| 282 | // within an export. |
| Eric Liu | a57afd0 | 2018-09-17 07:43:49 +0000 | [diff] [blame] | 283 | const auto *DeclCtx = ND.getDeclContext(); |
| 284 | switch (DeclCtx->getDeclKind()) { |
| 285 | case Decl::TranslationUnit: |
| 286 | case Decl::Namespace: |
| 287 | case Decl::LinkageSpec: |
| 288 | case Decl::Enum: |
| 289 | case Decl::ObjCProtocol: |
| 290 | case Decl::ObjCInterface: |
| 291 | case Decl::ObjCCategory: |
| 292 | case Decl::ObjCCategoryImpl: |
| 293 | case Decl::ObjCImplementation: |
| 294 | break; |
| 295 | default: |
| 296 | // Record has a few derivations (e.g. CXXRecord, Class specialization), it's |
| 297 | // easier to cast. |
| 298 | if (!llvm::isa<RecordDecl>(DeclCtx)) |
| 299 | return false; |
| 300 | } |
| 301 | if (explicitTemplateSpecialization<FunctionDecl>(ND) || |
| 302 | explicitTemplateSpecialization<CXXRecordDecl>(ND) || |
| 303 | explicitTemplateSpecialization<VarDecl>(ND)) |
| Eric Liu | 8763e48 | 2018-06-21 12:12:26 +0000 | [diff] [blame] | 304 | return false; |
| 305 | |
| Eric Liu | a57afd0 | 2018-09-17 07:43:49 +0000 | [diff] [blame] | 306 | const auto &SM = ASTCtx.getSourceManager(); |
| 307 | // Skip decls in the main file. |
| 308 | if (SM.isInMainFile(SM.getExpansionLoc(ND.getBeginLoc()))) |
| 309 | return false; |
| Eric Liu | 8763e48 | 2018-06-21 12:12:26 +0000 | [diff] [blame] | 310 | // Avoid indexing internal symbols in protobuf generated headers. |
| 311 | if (isPrivateProtoDecl(ND)) |
| 312 | return false; |
| 313 | return true; |
| 314 | } |
| 315 | |
| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 316 | // Always return true to continue indexing. |
| 317 | bool SymbolCollector::handleDeclOccurence( |
| 318 | const Decl *D, index::SymbolRoleSet Roles, |
| Sam McCall | b9d5711 | 2018-04-09 14:28:52 +0000 | [diff] [blame] | 319 | ArrayRef<index::SymbolRelation> Relations, SourceLocation Loc, |
| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 320 | index::IndexDataConsumer::ASTNodeInfo ASTNode) { |
| Eric Liu | 9af958f | 2018-01-10 14:57:58 +0000 | [diff] [blame] | 321 | assert(ASTCtx && PP.get() && "ASTContext and Preprocessor must be set."); |
| Sam McCall | 93f99bf | 2018-03-12 14:49:09 +0000 | [diff] [blame] | 322 | assert(CompletionAllocator && CompletionTUInfo); |
| Eric Liu | 77d1811 | 2018-06-04 11:31:55 +0000 | [diff] [blame] | 323 | assert(ASTNode.OrigD); |
| 324 | // If OrigD is an declaration associated with a friend declaration and it's |
| 325 | // not a definition, skip it. Note that OrigD is the occurrence that the |
| 326 | // collector is currently visiting. |
| 327 | if ((ASTNode.OrigD->getFriendObjectKind() != |
| 328 | Decl::FriendObjectKind::FOK_None) && |
| 329 | !(Roles & static_cast<unsigned>(index::SymbolRole::Definition))) |
| 330 | return true; |
| 331 | // A declaration created for a friend declaration should not be used as the |
| 332 | // canonical declaration in the index. Use OrigD instead, unless we've already |
| 333 | // picked a replacement for D |
| 334 | if (D->getFriendObjectKind() != Decl::FriendObjectKind::FOK_None) |
| 335 | D = CanonicalDecls.try_emplace(D, ASTNode.OrigD).first->second; |
| Sam McCall | 93f99bf | 2018-03-12 14:49:09 +0000 | [diff] [blame] | 336 | const NamedDecl *ND = llvm::dyn_cast<NamedDecl>(D); |
| 337 | if (!ND) |
| 338 | return true; |
| Eric Liu | 9af958f | 2018-01-10 14:57:58 +0000 | [diff] [blame] | 339 | |
| Sam McCall | 93f99bf | 2018-03-12 14:49:09 +0000 | [diff] [blame] | 340 | // Mark D as referenced if this is a reference coming from the main file. |
| 341 | // D may not be an interesting symbol, but it's cheaper to check at the end. |
| Sam McCall | b9d5711 | 2018-04-09 14:28:52 +0000 | [diff] [blame] | 342 | auto &SM = ASTCtx->getSourceManager(); |
| Haojian Wu | d81e314 | 2018-08-31 12:54:13 +0000 | [diff] [blame] | 343 | auto SpellingLoc = SM.getSpellingLoc(Loc); |
| Sam McCall | 93f99bf | 2018-03-12 14:49:09 +0000 | [diff] [blame] | 344 | if (Opts.CountReferences && |
| 345 | (Roles & static_cast<unsigned>(index::SymbolRole::Reference)) && |
| Haojian Wu | d81e314 | 2018-08-31 12:54:13 +0000 | [diff] [blame] | 346 | SM.getFileID(SpellingLoc) == SM.getMainFileID()) |
| Sam McCall | 93f99bf | 2018-03-12 14:49:09 +0000 | [diff] [blame] | 347 | ReferencedDecls.insert(ND); |
| 348 | |
| Haojian Wu | e83cacc | 2018-10-15 11:46:26 +0000 | [diff] [blame] | 349 | bool CollectRef = static_cast<unsigned>(Opts.RefFilter) & Roles; |
| 350 | bool IsOnlyRef = |
| 351 | !(Roles & (static_cast<unsigned>(index::SymbolRole::Declaration) | |
| 352 | static_cast<unsigned>(index::SymbolRole::Definition))); |
| Haojian Wu | d81e314 | 2018-08-31 12:54:13 +0000 | [diff] [blame] | 353 | |
| Haojian Wu | e83cacc | 2018-10-15 11:46:26 +0000 | [diff] [blame] | 354 | if (IsOnlyRef && !CollectRef) |
| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 355 | return true; |
| Eric Liu | 8763e48 | 2018-06-21 12:12:26 +0000 | [diff] [blame] | 356 | if (!shouldCollectSymbol(*ND, *ASTCtx, Opts)) |
| Sam McCall | 93f99bf | 2018-03-12 14:49:09 +0000 | [diff] [blame] | 357 | return true; |
| Haojian Wu | 7dd4950 | 2018-10-17 08:38:36 +0000 | [diff] [blame] | 358 | if (CollectRef && |
| 359 | (Opts.RefsInHeaders || SM.getFileID(SpellingLoc) == SM.getMainFileID())) |
| Haojian Wu | e83cacc | 2018-10-15 11:46:26 +0000 | [diff] [blame] | 360 | DeclRefs[ND].emplace_back(SpellingLoc, Roles); |
| 361 | // Don't continue indexing if this is a mere reference. |
| 362 | if (IsOnlyRef) |
| 363 | return true; |
| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 364 | |
| Haojian Wu | c6ddb46 | 2018-08-07 08:57:52 +0000 | [diff] [blame] | 365 | auto ID = getSymbolID(ND); |
| 366 | if (!ID) |
| Sam McCall | 93f99bf | 2018-03-12 14:49:09 +0000 | [diff] [blame] | 367 | return true; |
| Eric Liu | 76f6b44 | 2018-01-09 17:32:00 +0000 | [diff] [blame] | 368 | |
| Sam McCall | 93f99bf | 2018-03-12 14:49:09 +0000 | [diff] [blame] | 369 | const NamedDecl &OriginalDecl = *cast<NamedDecl>(ASTNode.OrigD); |
| Haojian Wu | c6ddb46 | 2018-08-07 08:57:52 +0000 | [diff] [blame] | 370 | const Symbol *BasicSymbol = Symbols.find(*ID); |
| Sam McCall | 93f99bf | 2018-03-12 14:49:09 +0000 | [diff] [blame] | 371 | if (!BasicSymbol) // Regardless of role, ND is the canonical declaration. |
| Haojian Wu | c6ddb46 | 2018-08-07 08:57:52 +0000 | [diff] [blame] | 372 | BasicSymbol = addDeclaration(*ND, std::move(*ID)); |
| Sam McCall | 93f99bf | 2018-03-12 14:49:09 +0000 | [diff] [blame] | 373 | else if (isPreferredDeclaration(OriginalDecl, Roles)) |
| 374 | // If OriginalDecl is preferred, replace the existing canonical |
| 375 | // declaration (e.g. a class forward declaration). There should be at most |
| 376 | // one duplicate as we expect to see only one preferred declaration per |
| 377 | // TU, because in practice they are definitions. |
| Haojian Wu | c6ddb46 | 2018-08-07 08:57:52 +0000 | [diff] [blame] | 378 | BasicSymbol = addDeclaration(OriginalDecl, std::move(*ID)); |
| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 379 | |
| Sam McCall | 93f99bf | 2018-03-12 14:49:09 +0000 | [diff] [blame] | 380 | if (Roles & static_cast<unsigned>(index::SymbolRole::Definition)) |
| 381 | addDefinition(OriginalDecl, *BasicSymbol); |
| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 382 | return true; |
| 383 | } |
| 384 | |
| Eric Liu | 48db19e | 2018-07-09 15:31:07 +0000 | [diff] [blame] | 385 | bool SymbolCollector::handleMacroOccurence(const IdentifierInfo *Name, |
| 386 | const MacroInfo *MI, |
| 387 | index::SymbolRoleSet Roles, |
| 388 | SourceLocation Loc) { |
| 389 | if (!Opts.CollectMacro) |
| 390 | return true; |
| 391 | assert(PP.get()); |
| 392 | |
| 393 | const auto &SM = PP->getSourceManager(); |
| 394 | if (SM.isInMainFile(SM.getExpansionLoc(MI->getDefinitionLoc()))) |
| 395 | return true; |
| 396 | // Header guards are not interesting in index. Builtin macros don't have |
| 397 | // useful locations and are not needed for code completions. |
| 398 | if (MI->isUsedForHeaderGuard() || MI->isBuiltinMacro()) |
| 399 | return true; |
| 400 | |
| 401 | // Mark the macro as referenced if this is a reference coming from the main |
| 402 | // file. The macro may not be an interesting symbol, but it's cheaper to check |
| 403 | // at the end. |
| 404 | if (Opts.CountReferences && |
| 405 | (Roles & static_cast<unsigned>(index::SymbolRole::Reference)) && |
| 406 | SM.getFileID(SM.getSpellingLoc(Loc)) == SM.getMainFileID()) |
| 407 | ReferencedMacros.insert(Name); |
| 408 | // Don't continue indexing if this is a mere reference. |
| 409 | // FIXME: remove macro with ID if it is undefined. |
| 410 | if (!(Roles & static_cast<unsigned>(index::SymbolRole::Declaration) || |
| 411 | Roles & static_cast<unsigned>(index::SymbolRole::Definition))) |
| 412 | return true; |
| 413 | |
| Eric Liu | d25f121 | 2018-09-06 09:59:37 +0000 | [diff] [blame] | 414 | auto ID = getSymbolID(*Name, MI, SM); |
| 415 | if (!ID) |
| Eric Liu | 48db19e | 2018-07-09 15:31:07 +0000 | [diff] [blame] | 416 | return true; |
| Eric Liu | 48db19e | 2018-07-09 15:31:07 +0000 | [diff] [blame] | 417 | |
| 418 | // Only collect one instance in case there are multiple. |
| Eric Liu | d25f121 | 2018-09-06 09:59:37 +0000 | [diff] [blame] | 419 | if (Symbols.find(*ID) != nullptr) |
| Eric Liu | 48db19e | 2018-07-09 15:31:07 +0000 | [diff] [blame] | 420 | return true; |
| 421 | |
| 422 | Symbol S; |
| Eric Liu | d25f121 | 2018-09-06 09:59:37 +0000 | [diff] [blame] | 423 | S.ID = std::move(*ID); |
| Eric Liu | 48db19e | 2018-07-09 15:31:07 +0000 | [diff] [blame] | 424 | S.Name = Name->getName(); |
| Eric Liu | 6df6600 | 2018-09-06 18:52:26 +0000 | [diff] [blame] | 425 | S.Flags |= Symbol::IndexedForCodeCompletion; |
| Eric Liu | 48db19e | 2018-07-09 15:31:07 +0000 | [diff] [blame] | 426 | S.SymInfo = index::getSymbolInfoForMacro(*MI); |
| 427 | std::string FileURI; |
| 428 | if (auto DeclLoc = getTokenLocation(MI->getDefinitionLoc(), SM, Opts, |
| 429 | PP->getLangOpts(), FileURI)) |
| 430 | S.CanonicalDeclaration = *DeclLoc; |
| 431 | |
| 432 | CodeCompletionResult SymbolCompletion(Name); |
| 433 | const auto *CCS = SymbolCompletion.CreateCodeCompletionStringForMacro( |
| 434 | *PP, *CompletionAllocator, *CompletionTUInfo); |
| 435 | std::string Signature; |
| 436 | std::string SnippetSuffix; |
| 437 | getSignature(*CCS, &Signature, &SnippetSuffix); |
| 438 | |
| 439 | std::string Include; |
| 440 | if (Opts.CollectIncludePath && shouldCollectIncludePath(S.SymInfo.Kind)) { |
| 441 | if (auto Header = |
| 442 | getIncludeHeader(Name->getName(), SM, |
| 443 | SM.getExpansionLoc(MI->getDefinitionLoc()), Opts)) |
| 444 | Include = std::move(*Header); |
| 445 | } |
| 446 | S.Signature = Signature; |
| 447 | S.CompletionSnippetSuffix = SnippetSuffix; |
| Eric Liu | 83f63e4 | 2018-09-03 10:18:21 +0000 | [diff] [blame] | 448 | if (!Include.empty()) |
| 449 | S.IncludeHeaders.emplace_back(Include, 1); |
| 450 | |
| Eric Liu | 48db19e | 2018-07-09 15:31:07 +0000 | [diff] [blame] | 451 | Symbols.insert(S); |
| 452 | return true; |
| 453 | } |
| 454 | |
| Sam McCall | 93f99bf | 2018-03-12 14:49:09 +0000 | [diff] [blame] | 455 | void SymbolCollector::finish() { |
| Eric Liu | 48db19e | 2018-07-09 15:31:07 +0000 | [diff] [blame] | 456 | // At the end of the TU, add 1 to the refcount of all referenced symbols. |
| 457 | auto IncRef = [this](const SymbolID &ID) { |
| 458 | if (const auto *S = Symbols.find(ID)) { |
| 459 | Symbol Inc = *S; |
| 460 | ++Inc.References; |
| 461 | Symbols.insert(Inc); |
| 462 | } |
| 463 | }; |
| 464 | for (const NamedDecl *ND : ReferencedDecls) { |
| Haojian Wu | c6ddb46 | 2018-08-07 08:57:52 +0000 | [diff] [blame] | 465 | if (auto ID = getSymbolID(ND)) { |
| 466 | IncRef(*ID); |
| 467 | } |
| Eric Liu | 48db19e | 2018-07-09 15:31:07 +0000 | [diff] [blame] | 468 | } |
| 469 | if (Opts.CollectMacro) { |
| 470 | assert(PP); |
| 471 | for (const IdentifierInfo *II : ReferencedMacros) { |
| Eric Liu | a62c9d6 | 2018-07-09 18:54:51 +0000 | [diff] [blame] | 472 | if (const auto *MI = PP->getMacroDefinition(II).getMacroInfo()) |
| Eric Liu | d25f121 | 2018-09-06 09:59:37 +0000 | [diff] [blame] | 473 | if (auto ID = getSymbolID(*II, MI, PP->getSourceManager())) |
| 474 | IncRef(*ID); |
| Eric Liu | 48db19e | 2018-07-09 15:31:07 +0000 | [diff] [blame] | 475 | } |
| Sam McCall | 93f99bf | 2018-03-12 14:49:09 +0000 | [diff] [blame] | 476 | } |
| Haojian Wu | d81e314 | 2018-08-31 12:54:13 +0000 | [diff] [blame] | 477 | |
| 478 | const auto &SM = ASTCtx->getSourceManager(); |
| Haojian Wu | 7dd4950 | 2018-10-17 08:38:36 +0000 | [diff] [blame] | 479 | llvm::DenseMap<FileID, std::string> URICache; |
| 480 | auto GetURI = [&](FileID FID) -> llvm::Optional<std::string> { |
| 481 | auto Found = URICache.find(FID); |
| 482 | if (Found == URICache.end()) { |
| Haojian Wu | 7dd4950 | 2018-10-17 08:38:36 +0000 | [diff] [blame] | 483 | if (auto *FileEntry = SM.getFileEntryForID(FID)) { |
| 484 | auto FileURI = toURI(SM, FileEntry->getName(), Opts); |
| 485 | if (!FileURI) { |
| 486 | log("Failed to create URI for file: {0}\n", FileEntry); |
| 487 | FileURI = ""; // reset to empty as we also want to cache this case. |
| 488 | } |
| 489 | Found = URICache.insert({FID, *FileURI}).first; |
| Haojian Wu | c014d86 | 2018-10-17 08:54:48 +0000 | [diff] [blame] | 490 | } else { |
| 491 | // Ignore cases where we can not find a corresponding file entry |
| 492 | // for the loc, thoses are not interesting, e.g. symbols formed |
| 493 | // via macro concatenation. |
| 494 | return llvm::None; |
| Haojian Wu | 7dd4950 | 2018-10-17 08:38:36 +0000 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | return Found->second; |
| 498 | }; |
| Haojian Wu | d81e314 | 2018-08-31 12:54:13 +0000 | [diff] [blame] | 499 | |
| Haojian Wu | 7dd4950 | 2018-10-17 08:38:36 +0000 | [diff] [blame] | 500 | if (auto MainFileURI = GetURI(SM.getMainFileID())) { |
| Sam McCall | b013831 | 2018-09-04 14:39:56 +0000 | [diff] [blame] | 501 | for (const auto &It : DeclRefs) { |
| Haojian Wu | d81e314 | 2018-08-31 12:54:13 +0000 | [diff] [blame] | 502 | if (auto ID = getSymbolID(It.first)) { |
| Haojian Wu | e83cacc | 2018-10-15 11:46:26 +0000 | [diff] [blame] | 503 | for (const auto &LocAndRole : It.second) { |
| Haojian Wu | 7dd4950 | 2018-10-17 08:38:36 +0000 | [diff] [blame] | 504 | auto FileID = SM.getFileID(LocAndRole.first); |
| 505 | if (auto FileURI = GetURI(FileID)) { |
| 506 | auto Range = |
| 507 | getTokenRange(LocAndRole.first, SM, ASTCtx->getLangOpts()); |
| 508 | Ref R; |
| 509 | R.Location.Start = Range.first; |
| 510 | R.Location.End = Range.second; |
| 511 | R.Location.FileURI = *FileURI; |
| 512 | R.Kind = toRefKind(LocAndRole.second); |
| 513 | Refs.insert(*ID, R); |
| 514 | } |
| Haojian Wu | d81e314 | 2018-08-31 12:54:13 +0000 | [diff] [blame] | 515 | } |
| 516 | } |
| 517 | } |
| Haojian Wu | d81e314 | 2018-08-31 12:54:13 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| Sam McCall | 93f99bf | 2018-03-12 14:49:09 +0000 | [diff] [blame] | 520 | ReferencedDecls.clear(); |
| Eric Liu | 48db19e | 2018-07-09 15:31:07 +0000 | [diff] [blame] | 521 | ReferencedMacros.clear(); |
| Sam McCall | b013831 | 2018-09-04 14:39:56 +0000 | [diff] [blame] | 522 | DeclRefs.clear(); |
| Sam McCall | 93f99bf | 2018-03-12 14:49:09 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| Sam McCall | 6003951 | 2018-02-09 14:42:01 +0000 | [diff] [blame] | 525 | const Symbol *SymbolCollector::addDeclaration(const NamedDecl &ND, |
| 526 | SymbolID ID) { |
| Ilya Biryukov | 4371450 | 2018-05-16 12:32:44 +0000 | [diff] [blame] | 527 | auto &Ctx = ND.getASTContext(); |
| 528 | auto &SM = Ctx.getSourceManager(); |
| Sam McCall | 6003951 | 2018-02-09 14:42:01 +0000 | [diff] [blame] | 529 | |
| Sam McCall | 6003951 | 2018-02-09 14:42:01 +0000 | [diff] [blame] | 530 | Symbol S; |
| 531 | S.ID = std::move(ID); |
| Eric Liu | 7ad1696 | 2018-06-22 10:46:59 +0000 | [diff] [blame] | 532 | std::string QName = printQualifiedName(ND); |
| Sam McCall | 6003951 | 2018-02-09 14:42:01 +0000 | [diff] [blame] | 533 | std::tie(S.Scope, S.Name) = splitQualifiedName(QName); |
| Sam McCall | 032db94 | 2018-06-22 06:41:43 +0000 | [diff] [blame] | 534 | // FIXME: this returns foo:bar: for objective-C methods, we prefer only foo: |
| 535 | // for consistency with CodeCompletionString and a clean name/signature split. |
| Marc-Andre Laperle | 945b5a3 | 2018-06-05 14:01:40 +0000 | [diff] [blame] | 536 | |
| Eric Liu | 6df6600 | 2018-09-06 18:52:26 +0000 | [diff] [blame] | 537 | if (isIndexedForCodeCompletion(ND, Ctx)) |
| 538 | S.Flags |= Symbol::IndexedForCodeCompletion; |
| Sam McCall | 6003951 | 2018-02-09 14:42:01 +0000 | [diff] [blame] | 539 | S.SymInfo = index::getSymbolInfo(&ND); |
| 540 | std::string FileURI; |
| Eric Liu | 48db19e | 2018-07-09 15:31:07 +0000 | [diff] [blame] | 541 | if (auto DeclLoc = getTokenLocation(findNameLoc(&ND), SM, Opts, |
| 542 | ASTCtx->getLangOpts(), FileURI)) |
| Sam McCall | 6003951 | 2018-02-09 14:42:01 +0000 | [diff] [blame] | 543 | S.CanonicalDeclaration = *DeclLoc; |
| 544 | |
| 545 | // Add completion info. |
| 546 | // FIXME: we may want to choose a different redecl, or combine from several. |
| 547 | assert(ASTCtx && PP.get() && "ASTContext and Preprocessor must be set."); |
| Ilya Biryukov | cf124bd | 2018-04-13 11:03:07 +0000 | [diff] [blame] | 548 | // We use the primary template, as clang does during code completion. |
| 549 | CodeCompletionResult SymbolCompletion(&getTemplateOrThis(ND), 0); |
| Sam McCall | 6003951 | 2018-02-09 14:42:01 +0000 | [diff] [blame] | 550 | const auto *CCS = SymbolCompletion.CreateCodeCompletionString( |
| 551 | *ASTCtx, *PP, CodeCompletionContext::CCC_Name, *CompletionAllocator, |
| 552 | *CompletionTUInfo, |
| Ilya Biryukov | 4371450 | 2018-05-16 12:32:44 +0000 | [diff] [blame] | 553 | /*IncludeBriefComments*/ false); |
| Sam McCall | a68951e | 2018-06-22 16:11:35 +0000 | [diff] [blame] | 554 | std::string Signature; |
| 555 | std::string SnippetSuffix; |
| 556 | getSignature(*CCS, &Signature, &SnippetSuffix); |
| Ilya Biryukov | 4371450 | 2018-05-16 12:32:44 +0000 | [diff] [blame] | 557 | std::string Documentation = |
| Ilya Biryukov | be0eb8f | 2018-05-24 14:49:23 +0000 | [diff] [blame] | 558 | formatDocumentation(*CCS, getDocComment(Ctx, SymbolCompletion, |
| 559 | /*CommentsFromHeaders=*/true)); |
| Sam McCall | a68951e | 2018-06-22 16:11:35 +0000 | [diff] [blame] | 560 | std::string ReturnType = getReturnType(*CCS); |
| Sam McCall | 6003951 | 2018-02-09 14:42:01 +0000 | [diff] [blame] | 561 | |
| Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 562 | std::string Include; |
| 563 | if (Opts.CollectIncludePath && shouldCollectIncludePath(S.SymInfo.Kind)) { |
| 564 | // Use the expansion location to get the #include header since this is |
| 565 | // where the symbol is exposed. |
| Eric Liu | b96363d | 2018-03-01 18:06:40 +0000 | [diff] [blame] | 566 | if (auto Header = getIncludeHeader( |
| 567 | QName, SM, SM.getExpansionLoc(ND.getLocation()), Opts)) |
| Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 568 | Include = std::move(*Header); |
| 569 | } |
| Sam McCall | a68951e | 2018-06-22 16:11:35 +0000 | [diff] [blame] | 570 | S.Signature = Signature; |
| 571 | S.CompletionSnippetSuffix = SnippetSuffix; |
| Sam McCall | 2e5700f | 2018-08-31 13:55:01 +0000 | [diff] [blame] | 572 | S.Documentation = Documentation; |
| 573 | S.ReturnType = ReturnType; |
| Eric Liu | 83f63e4 | 2018-09-03 10:18:21 +0000 | [diff] [blame] | 574 | if (!Include.empty()) |
| 575 | S.IncludeHeaders.emplace_back(Include, 1); |
| Sam McCall | 6003951 | 2018-02-09 14:42:01 +0000 | [diff] [blame] | 576 | |
| Sam McCall | 2161ec7 | 2018-07-05 06:20:41 +0000 | [diff] [blame] | 577 | S.Origin = Opts.Origin; |
| Eric Liu | 6df6600 | 2018-09-06 18:52:26 +0000 | [diff] [blame] | 578 | if (ND.getAvailability() == AR_Deprecated) |
| 579 | S.Flags |= Symbol::Deprecated; |
| Sam McCall | 6003951 | 2018-02-09 14:42:01 +0000 | [diff] [blame] | 580 | Symbols.insert(S); |
| 581 | return Symbols.find(S.ID); |
| 582 | } |
| 583 | |
| 584 | void SymbolCollector::addDefinition(const NamedDecl &ND, |
| 585 | const Symbol &DeclSym) { |
| 586 | if (DeclSym.Definition) |
| 587 | return; |
| 588 | // If we saw some forward declaration, we end up copying the symbol. |
| 589 | // This is not ideal, but avoids duplicating the "is this a definition" check |
| 590 | // in clang::index. We should only see one definition. |
| 591 | Symbol S = DeclSym; |
| 592 | std::string FileURI; |
| Eric Liu | 48db19e | 2018-07-09 15:31:07 +0000 | [diff] [blame] | 593 | if (auto DefLoc = getTokenLocation(findNameLoc(&ND), |
| 594 | ND.getASTContext().getSourceManager(), |
| 595 | Opts, ASTCtx->getLangOpts(), FileURI)) |
| Sam McCall | 6003951 | 2018-02-09 14:42:01 +0000 | [diff] [blame] | 596 | S.Definition = *DefLoc; |
| 597 | Symbols.insert(S); |
| 598 | } |
| 599 | |
| Haojian Wu | 4c1394d | 2017-12-12 15:42:10 +0000 | [diff] [blame] | 600 | } // namespace clangd |
| 601 | } // namespace clang |