mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #32139 from hamishknight/prime-time
This commit is contained in:
@@ -511,6 +511,27 @@ void ModuleDecl::addFile(FileUnit &newFile) {
|
||||
clearLookupCache();
|
||||
}
|
||||
|
||||
ArrayRef<SourceFile *>
|
||||
PrimarySourceFilesRequest::evaluate(Evaluator &evaluator,
|
||||
ModuleDecl *mod) const {
|
||||
assert(mod->isMainModule() && "Only the main module can have primaries");
|
||||
|
||||
SmallVector<SourceFile *, 8> primaries;
|
||||
for (auto *file : mod->getFiles()) {
|
||||
if (auto *SF = dyn_cast<SourceFile>(file)) {
|
||||
if (SF->isPrimary())
|
||||
primaries.push_back(SF);
|
||||
}
|
||||
}
|
||||
return mod->getASTContext().AllocateCopy(primaries);
|
||||
}
|
||||
|
||||
ArrayRef<SourceFile *> ModuleDecl::getPrimarySourceFiles() const {
|
||||
auto &eval = getASTContext().evaluator;
|
||||
auto *mutableThis = const_cast<ModuleDecl *>(this);
|
||||
return evaluateOrDefault(eval, PrimarySourceFilesRequest{mutableThis}, {});
|
||||
}
|
||||
|
||||
#define FORWARD(name, args) \
|
||||
for (const FileUnit *file : getFiles()) \
|
||||
file->name args;
|
||||
@@ -2182,12 +2203,15 @@ ModuleDecl::computeMagicFileStringMap(bool shouldDiagnose) const {
|
||||
SourceFile::SourceFile(ModuleDecl &M, SourceFileKind K,
|
||||
Optional<unsigned> bufferID,
|
||||
bool KeepParsedTokens, bool BuildSyntaxTree,
|
||||
ParsingOptions parsingOpts)
|
||||
ParsingOptions parsingOpts, bool isPrimary)
|
||||
: FileUnit(FileUnitKind::Source, M), BufferID(bufferID ? *bufferID : -1),
|
||||
ParsingOpts(parsingOpts), Kind(K),
|
||||
ParsingOpts(parsingOpts), IsPrimary(isPrimary), Kind(K),
|
||||
SyntaxInfo(new SourceFileSyntaxInfo(BuildSyntaxTree)) {
|
||||
M.getASTContext().addDestructorCleanup(*this);
|
||||
|
||||
assert(!IsPrimary || M.isMainModule() &&
|
||||
"A primary cannot appear outside the main module");
|
||||
|
||||
if (isScriptMode()) {
|
||||
bool problem = M.registerEntryPointFile(this, SourceLoc(), None);
|
||||
assert(!problem && "multiple main files?");
|
||||
|
||||
Reference in New Issue
Block a user