mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-23 05:40:09 +00:00
042dd99484
These are still disabled by default, but will work in ObjC code if you enable the `-import-insertions` flag. Completion requires ASTSignals to be available; before ASTSignals are available, we will always use #include. Once they are available, the behavior varies as follows: - For source files, use #import if the ObjC language flag is enabled - For header files: - If the ObjC language flag is disabled, use #include - If the header file contains any #imports, use #import - If the header file references any ObjC decls, use #import - Otherwise, use #include IncludeFixer support is similar, but it does not rely upon ASTSignals, instead it does the above checks excluding the scan for ObjC symbols. Differential Revision: https://reviews.llvm.org/D139458
53 lines
1.8 KiB
C++
53 lines
1.8 KiB
C++
//===--- ASTSignals.cpp ------------------------------------------*- C++-*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "ASTSignals.h"
|
|
#include "AST.h"
|
|
#include "FindTarget.h"
|
|
#include "Headers.h"
|
|
#include "support/Trace.h"
|
|
#include "clang/AST/DeclObjC.h"
|
|
|
|
namespace clang {
|
|
namespace clangd {
|
|
ASTSignals ASTSignals::derive(const ParsedAST &AST) {
|
|
trace::Span Span("ASTSignals::derive");
|
|
ASTSignals Signals;
|
|
Signals.InsertionDirective = preferredIncludeDirective(
|
|
AST.tuPath(), AST.getLangOpts(),
|
|
AST.getIncludeStructure().MainFileIncludes, AST.getLocalTopLevelDecls());
|
|
const SourceManager &SM = AST.getSourceManager();
|
|
findExplicitReferences(
|
|
AST.getASTContext(),
|
|
[&](ReferenceLoc Ref) {
|
|
for (const NamedDecl *ND : Ref.Targets) {
|
|
if (!isInsideMainFile(Ref.NameLoc, SM))
|
|
continue;
|
|
SymbolID ID = getSymbolID(ND);
|
|
if (!ID)
|
|
continue;
|
|
unsigned &SymbolCount = Signals.ReferencedSymbols[ID];
|
|
SymbolCount++;
|
|
// Process namespace only when we see the symbol for the first time.
|
|
if (SymbolCount != 1)
|
|
continue;
|
|
if (const auto *NSD = dyn_cast<NamespaceDecl>(ND->getDeclContext())) {
|
|
if (NSD->isAnonymousNamespace())
|
|
continue;
|
|
std::string NS = printNamespaceScope(*NSD);
|
|
if (!NS.empty())
|
|
Signals.RelatedNamespaces[NS]++;
|
|
}
|
|
}
|
|
},
|
|
AST.getHeuristicResolver());
|
|
return Signals;
|
|
}
|
|
} // namespace clangd
|
|
} // namespace clang
|