2011-05-12 17:24:54 +02:00
|
|
|
import std::_vec;
|
|
|
|
import std::_str;
|
|
|
|
import std::option;
|
|
|
|
import std::option::some;
|
|
|
|
import std::option::none;
|
|
|
|
import std::map::hashmap;
|
|
|
|
|
|
|
|
import driver::session;
|
|
|
|
import ast::ident;
|
|
|
|
import front::parser::parser;
|
|
|
|
import front::parser::spanned;
|
|
|
|
import front::parser::new_parser;
|
|
|
|
import front::parser::parse_mod_items;
|
|
|
|
import util::common;
|
|
|
|
import util::common::filename;
|
|
|
|
import util::common::span;
|
|
|
|
import util::common::new_str_hash;
|
2011-02-24 15:54:55 -08:00
|
|
|
|
|
|
|
|
|
|
|
// Simple dynamic-typed value type for eval_expr.
|
|
|
|
tag val {
|
|
|
|
val_bool(bool);
|
|
|
|
val_int(int);
|
|
|
|
val_str(str);
|
|
|
|
}
|
|
|
|
|
2011-05-03 15:50:56 -07:00
|
|
|
tag eval_mode {
|
|
|
|
mode_depend;
|
|
|
|
mode_parse;
|
|
|
|
}
|
|
|
|
|
2011-02-24 15:54:55 -08:00
|
|
|
type env = vec[tup(ident, val)];
|
2011-04-08 18:44:20 +02:00
|
|
|
type ctx = @rec(parser p,
|
2011-05-03 15:50:56 -07:00
|
|
|
eval_mode mode,
|
|
|
|
mutable vec[str] deps,
|
2011-05-12 17:24:54 +02:00
|
|
|
session::session sess,
|
2011-05-12 13:25:18 +02:00
|
|
|
mutable uint chpos,
|
|
|
|
mutable uint next_ann);
|
2011-02-24 15:54:55 -08:00
|
|
|
|
|
|
|
fn mk_env() -> env {
|
|
|
|
let env e = vec();
|
|
|
|
ret e;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn val_is_bool(val v) -> bool {
|
|
|
|
alt (v) {
|
|
|
|
case (val_bool(_)) { ret true; }
|
|
|
|
case (_) { }
|
|
|
|
}
|
|
|
|
ret false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn val_is_int(val v) -> bool {
|
|
|
|
alt (v) {
|
2011-03-10 10:17:10 -08:00
|
|
|
case (val_int(_)) { ret true; }
|
2011-02-24 15:54:55 -08:00
|
|
|
case (_) { }
|
|
|
|
}
|
|
|
|
ret false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn val_is_str(val v) -> bool {
|
|
|
|
alt (v) {
|
|
|
|
case (val_str(_)) { ret true; }
|
|
|
|
case (_) { }
|
|
|
|
}
|
|
|
|
ret false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn val_as_bool(val v) -> bool {
|
|
|
|
alt (v) {
|
|
|
|
case (val_bool(?b)) { ret b; }
|
|
|
|
case (_) { }
|
|
|
|
}
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn val_as_int(val v) -> int {
|
|
|
|
alt (v) {
|
|
|
|
case (val_int(?i)) { ret i; }
|
|
|
|
case (_) { }
|
|
|
|
}
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn val_as_str(val v) -> str {
|
|
|
|
alt (v) {
|
|
|
|
case (val_str(?s)) { ret s; }
|
|
|
|
case (_) { }
|
|
|
|
}
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
fn lookup(session::session sess, env e, span sp, ident i) -> val {
|
2011-02-24 15:54:55 -08:00
|
|
|
for (tup(ident, val) pair in e) {
|
2011-05-12 17:24:54 +02:00
|
|
|
if (_str::eq(i, pair._0)) {
|
2011-02-24 15:54:55 -08:00
|
|
|
ret pair._1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sess.span_err(sp, "unknown variable: " + i);
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
fn eval_lit(ctx cx, span sp, @ast::lit lit) -> val {
|
2011-02-24 15:54:55 -08:00
|
|
|
alt (lit.node) {
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::lit_bool(?b)) { ret val_bool(b); }
|
|
|
|
case (ast::lit_int(?i)) { ret val_int(i); }
|
|
|
|
case (ast::lit_str(?s)) { ret val_str(s); }
|
2011-02-24 15:54:55 -08:00
|
|
|
case (_) {
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(sp, "evaluating unsupported literal");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
fn eval_expr(ctx cx, env e, @ast::expr x) -> val {
|
2011-02-24 15:54:55 -08:00
|
|
|
alt (x.node) {
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::expr_path(?pth, _)) {
|
|
|
|
if (_vec::len[ident](pth.node.idents) == 1u &&
|
|
|
|
_vec::len[@ast::ty](pth.node.types) == 0u) {
|
2011-04-08 18:44:20 +02:00
|
|
|
ret lookup(cx.sess, e, x.span, pth.node.idents.(0));
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(x.span, "evaluating structured path-name");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::expr_lit(?lit, _)) {
|
2011-04-08 18:44:20 +02:00
|
|
|
ret eval_lit(cx, x.span, lit);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::expr_unary(?op, ?a, _)) {
|
2011-04-08 18:44:20 +02:00
|
|
|
auto av = eval_expr(cx, e, a);
|
2011-02-24 15:54:55 -08:00
|
|
|
alt (op) {
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::not) {
|
2011-02-24 15:54:55 -08:00
|
|
|
if (val_is_bool(av)) {
|
|
|
|
ret val_bool(!val_as_bool(av));
|
|
|
|
}
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(x.span, "bad types in '!' expression");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
case (_) {
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(x.span, "evaluating unsupported unop");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::expr_binary(?op, ?a, ?b, _)) {
|
2011-04-08 18:44:20 +02:00
|
|
|
auto av = eval_expr(cx, e, a);
|
|
|
|
auto bv = eval_expr(cx, e, b);
|
2011-02-24 15:54:55 -08:00
|
|
|
alt (op) {
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::add) {
|
2011-02-24 15:54:55 -08:00
|
|
|
if (val_is_int(av) && val_is_int(bv)) {
|
|
|
|
ret val_int(val_as_int(av) + val_as_int(bv));
|
|
|
|
}
|
|
|
|
if (val_is_str(av) && val_is_str(bv)) {
|
|
|
|
ret val_str(val_as_str(av) + val_as_str(bv));
|
|
|
|
}
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(x.span, "bad types in '+' expression");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::sub) {
|
2011-02-24 15:54:55 -08:00
|
|
|
if (val_is_int(av) && val_is_int(bv)) {
|
|
|
|
ret val_int(val_as_int(av) - val_as_int(bv));
|
|
|
|
}
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(x.span, "bad types in '-' expression");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::mul) {
|
2011-02-24 15:54:55 -08:00
|
|
|
if (val_is_int(av) && val_is_int(bv)) {
|
|
|
|
ret val_int(val_as_int(av) * val_as_int(bv));
|
|
|
|
}
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(x.span, "bad types in '*' expression");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::div) {
|
2011-02-24 15:54:55 -08:00
|
|
|
if (val_is_int(av) && val_is_int(bv)) {
|
|
|
|
ret val_int(val_as_int(av) / val_as_int(bv));
|
|
|
|
}
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(x.span, "bad types in '/' expression");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::rem) {
|
2011-02-24 15:54:55 -08:00
|
|
|
if (val_is_int(av) && val_is_int(bv)) {
|
|
|
|
ret val_int(val_as_int(av) % val_as_int(bv));
|
|
|
|
}
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(x.span, "bad types in '%' expression");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::and) {
|
2011-02-24 15:54:55 -08:00
|
|
|
if (val_is_bool(av) && val_is_bool(bv)) {
|
|
|
|
ret val_bool(val_as_bool(av) && val_as_bool(bv));
|
|
|
|
}
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(x.span, "bad types in '&&' expression");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::or) {
|
2011-02-24 15:54:55 -08:00
|
|
|
if (val_is_bool(av) && val_is_bool(bv)) {
|
|
|
|
ret val_bool(val_as_bool(av) || val_as_bool(bv));
|
|
|
|
}
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(x.span, "bad types in '||' expression");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::eq) {
|
2011-04-08 18:44:20 +02:00
|
|
|
ret val_bool(val_eq(cx.sess, x.span, av, bv));
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::ne) {
|
2011-04-08 18:44:20 +02:00
|
|
|
ret val_bool(! val_eq(cx.sess, x.span, av, bv));
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
case (_) {
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(x.span, "evaluating unsupported binop");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case (_) {
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(x.span, "evaluating unsupported expression");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
fn val_eq(session::session sess, span sp, val av, val bv) -> bool {
|
2011-02-24 15:54:55 -08:00
|
|
|
if (val_is_bool(av) && val_is_bool(bv)) {
|
|
|
|
ret val_as_bool(av) == val_as_bool(bv);
|
|
|
|
}
|
|
|
|
if (val_is_int(av) && val_is_int(bv)) {
|
|
|
|
ret val_as_int(av) == val_as_int(bv);
|
|
|
|
}
|
|
|
|
if (val_is_str(av) && val_is_str(bv)) {
|
2011-05-12 17:24:54 +02:00
|
|
|
ret _str::eq(val_as_str(av),
|
2011-02-24 15:54:55 -08:00
|
|
|
val_as_str(bv));
|
|
|
|
}
|
|
|
|
sess.span_err(sp, "bad types in comparison");
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
2011-04-19 13:35:49 -07:00
|
|
|
fn eval_crate_directives(ctx cx,
|
2011-02-24 15:54:55 -08:00
|
|
|
env e,
|
2011-05-12 17:24:54 +02:00
|
|
|
vec[@ast::crate_directive] cdirs,
|
2011-02-24 15:54:55 -08:00
|
|
|
str prefix,
|
2011-05-12 17:24:54 +02:00
|
|
|
&mutable vec[@ast::view_item] view_items,
|
|
|
|
&mutable vec[@ast::item] items) {
|
2011-02-24 15:54:55 -08:00
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
for (@ast::crate_directive sub_cdir in cdirs) {
|
2011-04-08 18:44:20 +02:00
|
|
|
eval_crate_directive(cx, e, sub_cdir, prefix,
|
2011-05-11 16:30:48 +02:00
|
|
|
view_items, items);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-19 13:35:49 -07:00
|
|
|
fn eval_crate_directives_to_mod(ctx cx, env e,
|
2011-05-12 17:24:54 +02:00
|
|
|
vec[@ast::crate_directive] cdirs,
|
|
|
|
str prefix) -> ast::_mod {
|
|
|
|
let vec[@ast::view_item] view_items = vec();
|
|
|
|
let vec[@ast::item] items = vec();
|
2011-02-24 15:54:55 -08:00
|
|
|
|
2011-04-08 18:44:20 +02:00
|
|
|
eval_crate_directives(cx, e, cdirs, prefix,
|
2011-05-11 16:30:48 +02:00
|
|
|
view_items, items);
|
2011-02-24 15:54:55 -08:00
|
|
|
|
2011-05-11 16:30:48 +02:00
|
|
|
ret rec(view_items=view_items, items=items);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-19 13:35:49 -07:00
|
|
|
fn eval_crate_directive_block(ctx cx,
|
2011-02-24 15:54:55 -08:00
|
|
|
env e,
|
2011-05-12 17:24:54 +02:00
|
|
|
&ast::block blk,
|
2011-02-24 15:54:55 -08:00
|
|
|
str prefix,
|
2011-05-12 17:24:54 +02:00
|
|
|
&mutable vec[@ast::view_item] view_items,
|
|
|
|
&mutable vec[@ast::item] items) {
|
2011-02-24 15:54:55 -08:00
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
for (@ast::stmt s in blk.node.stmts) {
|
2011-02-24 15:54:55 -08:00
|
|
|
alt (s.node) {
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::stmt_crate_directive(?cdir)) {
|
2011-04-08 18:44:20 +02:00
|
|
|
eval_crate_directive(cx, e, cdir, prefix,
|
2011-05-11 16:30:48 +02:00
|
|
|
view_items, items);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
case (_) {
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(s.span,
|
|
|
|
"unsupported stmt in crate-directive block");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-19 13:35:49 -07:00
|
|
|
fn eval_crate_directive_expr(ctx cx,
|
2011-02-24 15:54:55 -08:00
|
|
|
env e,
|
2011-05-12 17:24:54 +02:00
|
|
|
@ast::expr x,
|
2011-02-24 15:54:55 -08:00
|
|
|
str prefix,
|
2011-05-12 17:24:54 +02:00
|
|
|
&mutable vec[@ast::view_item] view_items,
|
|
|
|
&mutable vec[@ast::item] items) {
|
2011-02-24 15:54:55 -08:00
|
|
|
alt (x.node) {
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::expr_if(?cond, ?thn, ?elopt, _)) {
|
2011-04-08 18:44:20 +02:00
|
|
|
auto cv = eval_expr(cx, e, cond);
|
2011-02-24 15:54:55 -08:00
|
|
|
if (!val_is_bool(cv)) {
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(x.span, "bad cond type in 'if'");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (val_as_bool(cv)) {
|
2011-04-08 18:44:20 +02:00
|
|
|
ret eval_crate_directive_block(cx, e, thn, prefix,
|
2011-05-11 16:30:48 +02:00
|
|
|
view_items, items);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
alt (elopt) {
|
2011-05-12 17:24:54 +02:00
|
|
|
case (some[@ast::expr](?els)) {
|
2011-04-08 18:44:20 +02:00
|
|
|
ret eval_crate_directive_expr(cx, e, els, prefix,
|
2011-05-11 16:30:48 +02:00
|
|
|
view_items, items);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
case (_) {
|
|
|
|
// Absent-else is ok.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::expr_alt(?v, ?arms, _)) {
|
2011-04-08 18:44:20 +02:00
|
|
|
auto vv = eval_expr(cx, e, v);
|
2011-05-12 17:24:54 +02:00
|
|
|
for (ast::arm arm in arms) {
|
2011-02-24 15:54:55 -08:00
|
|
|
alt (arm.pat.node) {
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::pat_lit(?lit, _)) {
|
2011-04-08 18:44:20 +02:00
|
|
|
auto pv = eval_lit(cx, arm.pat.span, lit);
|
|
|
|
if (val_eq(cx.sess, arm.pat.span, vv, pv)) {
|
2011-02-24 15:54:55 -08:00
|
|
|
ret eval_crate_directive_block
|
2011-05-11 16:30:48 +02:00
|
|
|
(cx, e, arm.block, prefix, view_items, items);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
}
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::pat_wild(_)) {
|
2011-02-24 15:54:55 -08:00
|
|
|
ret eval_crate_directive_block
|
2011-04-08 18:44:20 +02:00
|
|
|
(cx, e, arm.block, prefix,
|
2011-05-11 16:30:48 +02:00
|
|
|
view_items, items);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
case (_) {
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(arm.pat.span,
|
|
|
|
"bad pattern type in 'alt'");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(x.span, "no cases matched in 'alt'");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::expr_block(?block, _)) {
|
2011-04-08 18:44:20 +02:00
|
|
|
ret eval_crate_directive_block(cx, e, block, prefix,
|
2011-05-11 16:30:48 +02:00
|
|
|
view_items, items);
|
2011-03-07 21:21:01 -05:00
|
|
|
}
|
|
|
|
|
2011-02-24 15:54:55 -08:00
|
|
|
case (_) {
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.sess.span_err(x.span, "unsupported expr type");
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-19 13:35:49 -07:00
|
|
|
fn eval_crate_directive(ctx cx,
|
2011-02-24 15:54:55 -08:00
|
|
|
env e,
|
2011-05-12 17:24:54 +02:00
|
|
|
@ast::crate_directive cdir,
|
2011-02-24 15:54:55 -08:00
|
|
|
str prefix,
|
2011-05-12 17:24:54 +02:00
|
|
|
&mutable vec[@ast::view_item] view_items,
|
|
|
|
&mutable vec[@ast::item] items) {
|
2011-02-24 15:54:55 -08:00
|
|
|
alt (cdir.node) {
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::cdir_let(?id, ?x, ?cdirs)) {
|
2011-04-08 18:44:20 +02:00
|
|
|
auto v = eval_expr(cx, e, x);
|
2011-02-24 15:54:55 -08:00
|
|
|
auto e0 = vec(tup(id, v)) + e;
|
2011-04-08 18:44:20 +02:00
|
|
|
eval_crate_directives(cx, e0, cdirs, prefix,
|
2011-05-11 16:30:48 +02:00
|
|
|
view_items, items);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::cdir_expr(?x)) {
|
2011-04-08 18:44:20 +02:00
|
|
|
eval_crate_directive_expr(cx, e, x, prefix,
|
2011-05-11 16:30:48 +02:00
|
|
|
view_items, items);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::cdir_src_mod(?id, ?file_opt)) {
|
2011-02-24 15:54:55 -08:00
|
|
|
|
|
|
|
auto file_path = id + ".rs";
|
|
|
|
alt (file_opt) {
|
|
|
|
case (some[filename](?f)) {
|
|
|
|
file_path = f;
|
|
|
|
}
|
|
|
|
case (none[filename]) {}
|
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
auto full_path = prefix + std::fs::path_sep() + file_path;
|
2011-02-24 15:54:55 -08:00
|
|
|
|
2011-05-03 15:50:56 -07:00
|
|
|
if (cx.mode == mode_depend) {
|
|
|
|
cx.deps += vec(full_path);
|
|
|
|
ret;
|
|
|
|
}
|
|
|
|
|
2011-04-08 18:44:20 +02:00
|
|
|
auto start_id = cx.p.next_def_id();
|
2011-05-12 13:25:18 +02:00
|
|
|
auto p0 = new_parser(cx.sess, e, start_id, full_path, cx.chpos,
|
|
|
|
cx.next_ann);
|
2011-05-12 17:24:54 +02:00
|
|
|
auto m0 = parse_mod_items(p0, token::EOF);
|
2011-03-10 17:34:58 -05:00
|
|
|
auto next_id = p0.next_def_id();
|
2011-04-08 18:44:20 +02:00
|
|
|
// Thread defids and chpos through the parsers
|
|
|
|
cx.p.set_def(next_id._1);
|
|
|
|
cx.chpos = p0.get_chpos();
|
2011-05-12 13:25:18 +02:00
|
|
|
cx.next_ann = p0.next_ann_num();
|
2011-05-12 17:24:54 +02:00
|
|
|
auto im = ast::item_mod(id, m0, next_id);
|
2011-04-08 18:44:20 +02:00
|
|
|
auto i = @spanned(cdir.span.lo, cdir.span.hi, im);
|
2011-05-12 17:24:54 +02:00
|
|
|
_vec::push[@ast::item](items, i);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::cdir_dir_mod(?id, ?dir_opt, ?cdirs)) {
|
2011-02-24 15:54:55 -08:00
|
|
|
|
|
|
|
auto path = id;
|
|
|
|
alt (dir_opt) {
|
|
|
|
case (some[filename](?d)) {
|
|
|
|
path = d;
|
|
|
|
}
|
|
|
|
case (none[filename]) {}
|
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
auto full_path = prefix + std::fs::path_sep() + path;
|
2011-04-08 18:44:20 +02:00
|
|
|
auto m0 = eval_crate_directives_to_mod(cx, e, cdirs, full_path);
|
2011-05-12 17:24:54 +02:00
|
|
|
auto im = ast::item_mod(id, m0, cx.p.next_def_id());
|
2011-04-08 18:44:20 +02:00
|
|
|
auto i = @spanned(cdir.span.lo, cdir.span.hi, im);
|
2011-05-12 17:24:54 +02:00
|
|
|
_vec::push[@ast::item](items, i);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::cdir_view_item(?vi)) {
|
|
|
|
_vec::push[@ast::view_item](view_items, vi);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::cdir_meta(?mi)) {
|
2011-04-18 09:22:23 +02:00
|
|
|
cx.sess.add_metadata(mi);
|
|
|
|
}
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::cdir_syntax(?pth)) {}
|
|
|
|
case (ast::cdir_auth(?pth, ?eff)) {}
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
2011-03-25 15:07:27 -07:00
|
|
|
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
2011-02-24 15:54:55 -08:00
|
|
|
// End:
|
|
|
|
//
|