about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorWilliam Throwe <wtt6@cornell.edu>2015-08-23 14:12:39 -0400
committerWilliam Throwe <wtt6@cornell.edu>2015-08-24 20:27:42 -0400
commit45de9de1e99c3d6a38055835b0fe6c65e1ddac73 (patch)
treed1005c7bcc751e92520619ec881e34ff15711fba /src/libsyntax
parent4c996499a1bcf747b12f8290eeff3024e59da529 (diff)
downloadrust-45de9de1e99c3d6a38055835b0fe6c65e1ddac73.tar.gz
rust-45de9de1e99c3d6a38055835b0fe6c65e1ddac73.zip
Move entry point identification logic to libsyntax
Identifying entry points will be useful in --test mode, which is
handled in libsyntax.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/entry.rs42
-rw-r--r--src/libsyntax/lib.rs1
2 files changed, 43 insertions, 0 deletions
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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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;