From d53bfad8e7b6f199436d8838f75eb90713dffd1d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 29 Jun 2011 18:07:15 -0700 Subject: [PATCH] Introduce a config property to the crate AST node This represents the compilation environment, defined as AST meta_items, Used for driving conditional compilation and will eventually replace the environment used by the parser for the current conditional compilation scheme. Issue #489 --- src/comp/front/ast.rs | 7 ++++++- src/comp/front/fold.rs | 3 ++- src/comp/front/parser.rs | 6 ++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 1f4981c809a8..c120535d1d01 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -76,11 +76,16 @@ fn def_id_of_def(def d) -> def_id { fail; } +// The set of meta_items that define the compilation environment of the crate, +// used to drive conditional compilation +type crate_cfg = vec[@meta_item]; + type crate = spanned[crate_]; type crate_ = rec(vec[@crate_directive] directives, _mod module, - vec[attribute] attrs); + vec[attribute] attrs, + crate_cfg config); tag crate_directive_ { cdir_expr(@expr); diff --git a/src/comp/front/fold.rs b/src/comp/front/fold.rs index 5a8781793999..ec3a626a01e4 100644 --- a/src/comp/front/fold.rs +++ b/src/comp/front/fold.rs @@ -131,7 +131,8 @@ fn noop_fold_crate(&crate_ c, ast_fold fld) -> crate_ { auto fold_attribute = bind fold_attribute_(_,fold_meta_item); ret rec(directives=map(fld.fold_crate_directive, c.directives), - module=c.module, attrs=map(fold_attribute, c.attrs)); + module=c.module, attrs=map(fold_attribute, c.attrs), + config=map(fold_meta_item, c.config)); } fn noop_fold_crate_directive(&crate_directive_ cd, ast_fold fld) diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 5c50a55e8e37..a383e79619a6 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -2318,7 +2318,8 @@ fn parse_crate_from_source_file(&parser p) -> @ast::crate { let vec[@ast::crate_directive] cdirs = []; ret @spanned(lo, p.get_lo_pos(), rec(directives=cdirs, module=m, - attrs=crate_attrs._0)); + attrs=crate_attrs._0, + config=[])); } fn parse_str(&parser p) -> ast::ident { @@ -2450,7 +2451,8 @@ fn parse_crate_from_crate_file(&parser p) -> @ast::crate { expect(p, token::EOF); ret @spanned(lo, hi, rec(directives=cdirs, module=m, - attrs=crate_attrs)); + attrs=crate_attrs, + config=[])); } // // Local Variables: