From 45de9de1e99c3d6a38055835b0fe6c65e1ddac73 Mon Sep 17 00:00:00 2001 From: William Throwe Date: Sun, 23 Aug 2015 14:12:39 -0400 Subject: Move entry point identification logic to libsyntax Identifying entry points will be useful in --test mode, which is handled in libsyntax. --- src/libsyntax/entry.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ src/libsyntax/lib.rs | 1 + 2 files changed, 43 insertions(+) create mode 100644 src/libsyntax/entry.rs (limited to 'src/libsyntax') diff --git a/src/libsyntax/entry.rs b/src/libsyntax/entry.rs new file mode 100644 index 00000000000..b6c5d0066a2 --- /dev/null +++ b/src/libsyntax/entry.rs @@ -0,0 +1,42 @@ +// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use attr; +use ast::{Item, ItemFn}; + +pub enum EntryPointType { + None, + MainNamed, + MainAttr, + Start, + OtherMain, // Not an entry point, but some other function named main +} + +pub fn entry_point_type(item: &Item, depth: usize) -> EntryPointType { + match item.node { + ItemFn(..) => { + if attr::contains_name(&item.attrs, "start") { + EntryPointType::Start + } else if attr::contains_name(&item.attrs, "main") { + EntryPointType::MainAttr + } 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, + } +} diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 0d1fa6dd726..d1c862ad40b 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -90,6 +90,7 @@ pub mod attr; pub mod codemap; pub mod config; pub mod diagnostic; +pub mod entry; pub mod feature_gate; pub mod fold; pub mod owned_slice; -- cgit 1.4.1-3-g733a5