2015-08-23 14:12:39 -04:00
|
|
|
use attr;
|
2016-02-09 11:36:51 +01:00
|
|
|
use ast::{Item, ItemKind};
|
2015-08-23 14:12:39 -04:00
|
|
|
|
|
|
|
pub enum EntryPointType {
|
|
|
|
None,
|
|
|
|
MainNamed,
|
|
|
|
MainAttr,
|
|
|
|
Start,
|
|
|
|
OtherMain, // Not an entry point, but some other function named main
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
// Beware, this is duplicated in librustc/middle/entry.rs, make sure to keep
|
|
|
|
// them in sync.
|
2015-08-23 14:12:39 -04:00
|
|
|
pub fn entry_point_type(item: &Item, depth: usize) -> EntryPointType {
|
|
|
|
match item.node {
|
2016-02-09 11:36:51 +01:00
|
|
|
ItemKind::Fn(..) => {
|
2015-08-23 14:12:39 -04:00
|
|
|
if attr::contains_name(&item.attrs, "start") {
|
|
|
|
EntryPointType::Start
|
|
|
|
} else if attr::contains_name(&item.attrs, "main") {
|
|
|
|
EntryPointType::MainAttr
|
2016-11-17 14:04:20 +00:00
|
|
|
} else if item.ident.name == "main" {
|
2015-08-23 14:12:39 -04:00
|
|
|
if depth == 1 {
|
|
|
|
// This is a top-level function so can be 'main'
|
|
|
|
EntryPointType::MainNamed
|
|
|
|
} else {
|
|
|
|
EntryPointType::OtherMain
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
EntryPointType::None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => EntryPointType::None,
|
|
|
|
}
|
|
|
|
}
|