rust/src/libsyntax/entry.rs

35 lines
1021 B
Rust
Raw Normal View History

use attr;
use ast::{Item, ItemKind};
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.
pub fn entry_point_type(item: &Item, depth: usize) -> EntryPointType {
match item.node {
ItemKind::Fn(..) => {
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" {
if depth == 1 {
// This is a top-level function so can be 'main'
EntryPointType::MainNamed
} else {
EntryPointType::OtherMain
}
} else {
EntryPointType::None
}
}
_ => EntryPointType::None,
}
}