-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathSwiftBodyEmissionStrategy.cpp
More file actions
32 lines (30 loc) · 1.4 KB
/
SwiftBodyEmissionStrategy.cpp
File metadata and controls
32 lines (30 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "swift/extractor/infra/SwiftBodyEmissionStrategy.h"
using namespace codeql;
// In order to not emit duplicated entries for declarations, we restrict emission to only
// Decls declared within the current "scope".
// Depending on the whether we are extracting a primary source file or not the scope is defined as
// follows:
// - not extracting a primary source file (`currentPrimarySourceFile == nullptr`): the current
// scope means the current module. This is used in the case of system or builtin modules.
// - extracting a primary source file: in this mode, we extract several files belonging to the
// same module one by one. In this mode, we restrict emission only to the same file ignoring
// all the other files.
bool SwiftBodyEmissionStrategy::shouldEmitDeclBody(const swift::Decl& decl) {
auto module = decl.getModuleContext();
if (module != ¤tModule) {
return false;
}
if (currentLazyDeclaration && currentLazyDeclaration != &decl) {
return false;
}
// ModuleDecl is a special case: if it passed the previous test, it is the current module
// but it never has a source file, so we short circuit to emit it in any case
if (!currentPrimarySourceFile || decl.getKind() == swift::DeclKind::Module) {
return true;
}
if (auto context = decl.getDeclContext()) {
return currentPrimarySourceFile == context->getParentSourceFile();
//Nothing
}
return false;
}