mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[AST] Retrieve @main type from module.
Added a convenience function to ModuleDecl to look up the entry point @main type if there is one.
This commit is contained in:
@@ -1876,6 +1876,22 @@ bool SourceFile::registerMainDecl(ValueDecl *mainDecl, SourceLoc diagLoc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NominalTypeDecl *ModuleDecl::getMainTypeDecl() const {
|
||||
if (!EntryPointInfo.hasEntryPoint())
|
||||
return nullptr;
|
||||
auto *file = EntryPointInfo.getEntryPointFile();
|
||||
if (!file)
|
||||
return nullptr;
|
||||
auto *mainDecl = file->getMainDecl();
|
||||
if (!mainDecl)
|
||||
return nullptr;
|
||||
auto *func = dyn_cast<FuncDecl>(file->getMainDecl());
|
||||
if (!func)
|
||||
return nullptr;
|
||||
auto *nominalType = dyn_cast<NominalTypeDecl>(func->getDeclContext());
|
||||
return nominalType;
|
||||
}
|
||||
|
||||
bool ModuleDecl::registerEntryPointFile(FileUnit *file, SourceLoc diagLoc,
|
||||
Optional<ArtificialMainKind> kind) {
|
||||
if (!EntryPointInfo.hasEntryPoint()) {
|
||||
|
||||
Reference in New Issue
Block a user