about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-12-19 12:23:39 -0800
committerAlex Crichton <alex@alexcrichton.com>2013-12-20 09:10:11 -0800
commit87add533278d723057192292306505e269e737bc (patch)
treee57c474628555700051889ddc4a52c7e5d17487e /src/libsyntax/parse
parentd760f994de00f4e700a03a650e5065c8391b7f73 (diff)
downloadrust-87add533278d723057192292306505e269e737bc.tar.gz
rust-87add533278d723057192292306505e269e737bc.zip
rustc: Improve crate id extraction
Right now the --crate-id and related flags are all process *after* the entire
crate is parsed. This is less than desirable when used with makefiles because it
means that just to learn the output name of the crate you have to parse the
entire crate (unnecessary).

This commit changes the behavior to lift the handling of these flags much sooner
in the compilation process. This allows us to not have to parse the entire crate
and only have to worry about parsing the crate attributes themselves. The
related methods have all been updated to take an array of attributes rather than
a crate.

Additionally, this ceases duplication of the "what output are we producing"
logic in order to correctly handle things in the case of --test.

Finally, this adds tests for all of this functionality to ensure that it does
not regress.
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/mod.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs
index 612151f83e4..73240a9effd 100644
--- a/src/libsyntax/parse/mod.rs
+++ b/src/libsyntax/parse/mod.rs
@@ -79,6 +79,16 @@ pub fn parse_crate_from_file(
     // why is there no p.abort_if_errors here?
 }
 
+pub fn parse_crate_attrs_from_file(
+    input: &Path,
+    cfg: ast::CrateConfig,
+    sess: @mut ParseSess
+) -> ~[ast::Attribute] {
+    let parser = new_parser_from_file(sess, cfg, input);
+    let (inner, _) = parser.parse_inner_attrs_and_next();
+    return inner;
+}
+
 pub fn parse_crate_from_source_str(
     name: @str,
     source: @str,
@@ -92,6 +102,20 @@ pub fn parse_crate_from_source_str(
     maybe_aborted(p.parse_crate_mod(),p)
 }
 
+pub fn parse_crate_attrs_from_source_str(
+    name: @str,
+    source: @str,
+    cfg: ast::CrateConfig,
+    sess: @mut ParseSess
+) -> ~[ast::Attribute] {
+    let p = new_parser_from_source_str(sess,
+                                       /*bad*/ cfg.clone(),
+                                       name,
+                                       source);
+    let (inner, _) = maybe_aborted(p.parse_inner_attrs_and_next(),p);
+    return inner;
+}
+
 pub fn parse_expr_from_source_str(
     name: @str,
     source: @str,