2011-05-12 17:24:54 +02:00
|
|
|
import std::option;
|
2011-05-17 20:41:41 +02:00
|
|
|
import std::str;
|
|
|
|
import std::vec;
|
2011-05-12 17:24:54 +02:00
|
|
|
import util::common::span;
|
|
|
|
import util::common::spanned;
|
|
|
|
import util::common::ty_mach;
|
|
|
|
import util::common::filename;
|
2010-08-18 09:00:10 -07:00
|
|
|
|
|
|
|
type ident = str;
|
|
|
|
|
2011-01-13 17:42:28 -08:00
|
|
|
type path_ = rec(vec[ident] idents, vec[@ty] types);
|
|
|
|
type path = spanned[path_];
|
2010-10-04 17:25:52 -07:00
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
type crate_num = int;
|
2011-05-11 12:59:34 +02:00
|
|
|
const crate_num local_crate = 0;
|
2010-10-18 16:15:25 -07:00
|
|
|
type def_num = int;
|
|
|
|
type def_id = tup(crate_num, def_num);
|
|
|
|
|
2011-04-12 15:09:50 -07:00
|
|
|
type ty_param = ident;
|
2010-11-24 18:01:20 -08:00
|
|
|
|
2011-05-26 17:26:59 -07:00
|
|
|
type ann = rec(uint id);
|
2011-05-12 10:51:13 +02:00
|
|
|
|
2010-10-18 16:15:25 -07:00
|
|
|
tag def {
|
|
|
|
def_fn(def_id);
|
2010-12-14 15:32:13 -08:00
|
|
|
def_obj(def_id);
|
2010-12-30 15:27:19 -08:00
|
|
|
def_obj_field(def_id);
|
2010-10-18 16:15:25 -07:00
|
|
|
def_mod(def_id);
|
2011-03-10 21:33:53 -05:00
|
|
|
def_native_mod(def_id);
|
2010-10-18 16:15:25 -07:00
|
|
|
def_const(def_id);
|
|
|
|
def_arg(def_id);
|
|
|
|
def_local(def_id);
|
2010-12-01 10:19:20 -08:00
|
|
|
def_variant(def_id /* tag */, def_id /* variant */);
|
2010-10-18 16:15:25 -07:00
|
|
|
def_ty(def_id);
|
2011-04-12 15:09:50 -07:00
|
|
|
def_ty_arg(uint);
|
2010-12-10 18:08:32 -08:00
|
|
|
def_binding(def_id);
|
2011-01-01 13:13:00 -05:00
|
|
|
def_use(def_id);
|
2011-02-07 15:07:27 -05:00
|
|
|
def_native_ty(def_id);
|
|
|
|
def_native_fn(def_id);
|
2010-10-05 18:21:44 -07:00
|
|
|
}
|
2010-10-04 17:25:52 -07:00
|
|
|
|
2011-05-12 13:25:18 +02:00
|
|
|
fn variant_def_ids(&def d) -> tup(def_id, def_id) {
|
|
|
|
alt (d) {
|
|
|
|
case (def_variant(?tag_id, ?var_id)) {
|
|
|
|
ret tup(tag_id, var_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-29 13:21:16 -07:00
|
|
|
fn def_id_of_def(def d) -> def_id {
|
|
|
|
alt (d) {
|
|
|
|
case (def_fn(?id)) { ret id; }
|
|
|
|
case (def_obj(?id)) { ret id; }
|
|
|
|
case (def_obj_field(?id)) { ret id; }
|
|
|
|
case (def_mod(?id)) { ret id; }
|
|
|
|
case (def_native_mod(?id)) { ret id; }
|
|
|
|
case (def_const(?id)) { ret id; }
|
|
|
|
case (def_arg(?id)) { ret id; }
|
|
|
|
case (def_local(?id)) { ret id; }
|
|
|
|
case (def_variant(_, ?id)) { ret id; }
|
|
|
|
case (def_ty(?id)) { ret id; }
|
2011-04-12 15:09:50 -07:00
|
|
|
case (def_ty_arg(_)) { fail; }
|
2011-03-29 13:21:16 -07:00
|
|
|
case (def_binding(?id)) { ret id; }
|
|
|
|
case (def_use(?id)) { ret id; }
|
|
|
|
case (def_native_ty(?id)) { ret id; }
|
|
|
|
case (def_native_fn(?id)) { ret id; }
|
|
|
|
}
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
type crate = spanned[crate_];
|
2011-03-11 15:49:48 -08:00
|
|
|
type crate_ = rec(vec[@crate_directive] directives,
|
|
|
|
_mod module);
|
2010-08-18 09:00:10 -07:00
|
|
|
|
2011-02-23 14:37:39 -08:00
|
|
|
tag crate_directive_ {
|
|
|
|
cdir_expr(@expr);
|
2011-02-24 15:54:55 -08:00
|
|
|
// FIXME: cdir_let should be eliminated
|
|
|
|
// and redirected to the use of const stmt_decls inside
|
|
|
|
// crate directive blocks.
|
|
|
|
cdir_let(ident, @expr, vec[@crate_directive]);
|
2011-05-12 17:24:54 +02:00
|
|
|
cdir_src_mod(ident, option::t[filename]);
|
|
|
|
cdir_dir_mod(ident, option::t[filename], vec[@crate_directive]);
|
2011-02-23 14:37:39 -08:00
|
|
|
cdir_view_item(@view_item);
|
2011-03-04 11:28:40 -08:00
|
|
|
cdir_meta(vec[@meta_item]);
|
2011-02-23 14:37:39 -08:00
|
|
|
cdir_syntax(path);
|
2011-04-19 13:35:49 -07:00
|
|
|
cdir_auth(path, _auth);
|
2011-02-23 14:37:39 -08:00
|
|
|
}
|
|
|
|
type crate_directive = spanned[crate_directive_];
|
|
|
|
|
|
|
|
|
2010-12-30 11:21:37 -05:00
|
|
|
type meta_item = spanned[meta_item_];
|
|
|
|
type meta_item_ = rec(ident name, str value);
|
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
type block = spanned[block_];
|
2010-10-18 18:19:16 -07:00
|
|
|
type block_ = rec(vec[@stmt] stmts,
|
2011-05-12 17:24:54 +02:00
|
|
|
option::t[@expr] expr,
|
2011-05-26 15:59:39 -07:00
|
|
|
ann a);
|
2010-08-18 09:00:10 -07:00
|
|
|
|
2010-11-24 14:42:01 -08:00
|
|
|
type pat = spanned[pat_];
|
|
|
|
tag pat_ {
|
2010-11-24 15:45:59 -08:00
|
|
|
pat_wild(ann);
|
2010-12-10 17:24:53 -08:00
|
|
|
pat_bind(ident, def_id, ann);
|
2011-02-10 18:59:23 -08:00
|
|
|
pat_lit(@lit, ann);
|
2011-05-12 13:25:18 +02:00
|
|
|
pat_tag(path, vec[@pat], ann);
|
2010-11-24 14:42:01 -08:00
|
|
|
}
|
|
|
|
|
2010-11-29 14:18:26 -08:00
|
|
|
tag mutability {
|
|
|
|
mut;
|
|
|
|
imm;
|
2011-03-18 11:49:06 -07:00
|
|
|
maybe_mut;
|
2010-11-29 14:18:26 -08:00
|
|
|
}
|
|
|
|
|
2010-12-03 18:03:28 -08:00
|
|
|
tag layer {
|
|
|
|
layer_value;
|
|
|
|
layer_state;
|
|
|
|
layer_gc;
|
|
|
|
}
|
|
|
|
|
2011-04-19 13:35:49 -07:00
|
|
|
tag _auth {
|
|
|
|
auth_unsafe;
|
2010-12-03 18:03:28 -08:00
|
|
|
}
|
|
|
|
|
2011-02-18 17:30:57 -08:00
|
|
|
tag proto {
|
|
|
|
proto_iter;
|
|
|
|
proto_fn;
|
|
|
|
}
|
|
|
|
|
2010-09-27 18:25:02 -07:00
|
|
|
tag binop {
|
2010-09-28 10:30:34 -07:00
|
|
|
add;
|
|
|
|
sub;
|
|
|
|
mul;
|
|
|
|
div;
|
|
|
|
rem;
|
|
|
|
and;
|
|
|
|
or;
|
|
|
|
bitxor;
|
2010-09-27 18:25:02 -07:00
|
|
|
bitand;
|
|
|
|
bitor;
|
|
|
|
lsl;
|
|
|
|
lsr;
|
|
|
|
asr;
|
|
|
|
eq;
|
|
|
|
lt;
|
|
|
|
le;
|
|
|
|
ne;
|
|
|
|
ge;
|
|
|
|
gt;
|
|
|
|
}
|
|
|
|
|
2011-03-04 07:22:43 +01:00
|
|
|
fn binop_to_str(binop op) -> str {
|
|
|
|
alt (op) {
|
|
|
|
case (add) {ret "+";}
|
|
|
|
case (sub) {ret "-";}
|
|
|
|
case (mul) {ret "*";}
|
|
|
|
case (div) {ret "/";}
|
|
|
|
case (rem) {ret "%";}
|
|
|
|
case (and) {ret "&&";}
|
|
|
|
case (or) {ret "||";}
|
|
|
|
case (bitxor) {ret "^";}
|
|
|
|
case (bitand) {ret "&";}
|
|
|
|
case (bitor) {ret "|";}
|
|
|
|
case (lsl) {ret "<<";}
|
|
|
|
case (lsr) {ret ">>";}
|
|
|
|
case (asr) {ret ">>>";}
|
|
|
|
case (eq) {ret "==";}
|
|
|
|
case (lt) {ret "<";}
|
|
|
|
case (le) {ret "<=";}
|
|
|
|
case (ne) {ret "!=";}
|
|
|
|
case (ge) {ret ">=";}
|
|
|
|
case (gt) {ret ">";}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-27 18:25:02 -07:00
|
|
|
tag unop {
|
2011-04-04 15:44:15 -07:00
|
|
|
box(mutability);
|
2010-09-28 10:30:34 -07:00
|
|
|
deref;
|
2010-09-27 18:25:02 -07:00
|
|
|
bitnot;
|
|
|
|
not;
|
|
|
|
neg;
|
|
|
|
}
|
|
|
|
|
2011-03-04 07:22:43 +01:00
|
|
|
fn unop_to_str(unop op) -> str {
|
|
|
|
alt (op) {
|
2011-04-04 15:44:15 -07:00
|
|
|
case (box(?mt)) {
|
|
|
|
if (mt == mut) { ret "@mutable"; }
|
|
|
|
ret "@";
|
|
|
|
}
|
2011-03-04 07:22:43 +01:00
|
|
|
case (deref) {ret "*";}
|
|
|
|
case (bitnot) {ret "~";}
|
|
|
|
case (not) {ret "!";}
|
|
|
|
case (neg) {ret "-";}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-03 18:03:28 -08:00
|
|
|
tag mode {
|
|
|
|
val;
|
|
|
|
alias;
|
|
|
|
}
|
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
type stmt = spanned[stmt_];
|
|
|
|
tag stmt_ {
|
2011-04-12 12:16:21 -07:00
|
|
|
stmt_decl(@decl, ann);
|
|
|
|
stmt_expr(@expr, ann);
|
2011-02-24 15:54:55 -08:00
|
|
|
// These only exist in crate-level blocks.
|
|
|
|
stmt_crate_directive(@crate_directive);
|
2010-09-09 15:59:29 -07:00
|
|
|
}
|
|
|
|
|
2011-03-24 21:04:29 -04:00
|
|
|
tag init_op {
|
|
|
|
init_assign;
|
|
|
|
init_recv;
|
|
|
|
}
|
|
|
|
|
|
|
|
type initializer = rec(init_op op,
|
|
|
|
@expr expr);
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
type local = rec(option::t[@ty] ty,
|
2010-10-18 18:19:16 -07:00
|
|
|
bool infer,
|
|
|
|
ident ident,
|
2011-05-12 17:24:54 +02:00
|
|
|
option::t[initializer] init,
|
2010-11-12 16:11:33 -08:00
|
|
|
def_id id,
|
|
|
|
ann ann);
|
2010-10-18 18:19:16 -07:00
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
type decl = spanned[decl_];
|
|
|
|
tag decl_ {
|
2010-10-19 14:54:10 -07:00
|
|
|
decl_local(@local);
|
2010-10-18 18:19:16 -07:00
|
|
|
decl_item(@item);
|
2010-09-09 15:59:29 -07:00
|
|
|
}
|
|
|
|
|
2011-05-11 15:26:36 +02:00
|
|
|
type arm = rec(@pat pat, block block);
|
2010-11-24 15:45:59 -08:00
|
|
|
|
2010-11-30 16:31:43 -08:00
|
|
|
type elt = rec(mutability mut, @expr expr);
|
|
|
|
type field = rec(mutability mut, ident ident, @expr expr);
|
|
|
|
|
2011-03-26 00:53:57 -04:00
|
|
|
tag spawn_dom {
|
|
|
|
dom_implicit;
|
|
|
|
dom_thread;
|
|
|
|
}
|
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
type expr = spanned[expr_];
|
|
|
|
tag expr_ {
|
2011-03-17 17:39:47 -07:00
|
|
|
expr_vec(vec[@expr], mutability, ann);
|
2010-11-30 16:31:43 -08:00
|
|
|
expr_tup(vec[elt], ann);
|
2011-05-12 17:24:54 +02:00
|
|
|
expr_rec(vec[field], option::t[@expr], ann);
|
2010-11-03 15:53:53 -07:00
|
|
|
expr_call(@expr, vec[@expr], ann);
|
2011-04-07 13:49:27 -07:00
|
|
|
expr_self_method(ident, ann);
|
2011-05-12 17:24:54 +02:00
|
|
|
expr_bind(@expr, vec[option::t[@expr]], ann);
|
|
|
|
expr_spawn(spawn_dom, option::t[str], @expr, vec[@expr], ann);
|
2010-11-03 15:53:53 -07:00
|
|
|
expr_binary(binop, @expr, @expr, ann);
|
|
|
|
expr_unary(unop, @expr, ann);
|
|
|
|
expr_lit(@lit, ann);
|
|
|
|
expr_cast(@expr, @ty, ann);
|
2011-05-12 17:24:54 +02:00
|
|
|
expr_if(@expr, block, option::t[@expr], ann);
|
2010-11-03 15:53:53 -07:00
|
|
|
expr_while(@expr, block, ann);
|
2011-01-20 15:02:12 -08:00
|
|
|
expr_for(@decl, @expr, block, ann);
|
2011-02-14 18:17:31 -08:00
|
|
|
expr_for_each(@decl, @expr, block, ann);
|
2010-11-03 15:53:53 -07:00
|
|
|
expr_do_while(block, @expr, ann);
|
2010-11-24 14:42:01 -08:00
|
|
|
expr_alt(@expr, vec[arm], ann);
|
2010-11-03 15:53:53 -07:00
|
|
|
expr_block(block, ann);
|
|
|
|
expr_assign(@expr /* TODO: @expr|is_lval */, @expr, ann);
|
2010-12-08 14:50:47 -08:00
|
|
|
expr_assign_op(binop, @expr /* TODO: @expr|is_lval */, @expr, ann);
|
2011-03-12 21:00:39 -05:00
|
|
|
expr_send(@expr /* TODO: @expr|is_lval */, @expr, ann);
|
|
|
|
expr_recv(@expr /* TODO: @expr|is_lval */, @expr, ann);
|
2010-11-03 15:53:53 -07:00
|
|
|
expr_field(@expr, ident, ann);
|
|
|
|
expr_index(@expr, @expr, ann);
|
2011-05-12 13:25:18 +02:00
|
|
|
expr_path(path, ann);
|
2011-05-12 17:24:54 +02:00
|
|
|
expr_ext(path, vec[@expr], option::t[str], @expr, ann);
|
2011-03-24 12:12:04 -07:00
|
|
|
expr_fail(ann);
|
|
|
|
expr_break(ann);
|
|
|
|
expr_cont(ann);
|
2011-05-12 17:24:54 +02:00
|
|
|
expr_ret(option::t[@expr], ann);
|
|
|
|
expr_put(option::t[@expr], ann);
|
2011-03-24 12:12:04 -07:00
|
|
|
expr_be(@expr, ann);
|
2011-04-19 11:21:23 +02:00
|
|
|
expr_log(int, @expr, ann);
|
2011-05-02 17:47:24 -07:00
|
|
|
/* just an assert, no significance to typestate */
|
|
|
|
expr_assert(@expr, ann);
|
|
|
|
/* preds that typestate is aware of */
|
|
|
|
expr_check(@expr, ann);
|
2011-03-02 22:29:53 -05:00
|
|
|
expr_port(ann);
|
|
|
|
expr_chan(@expr, ann);
|
2011-05-06 17:08:41 -07:00
|
|
|
expr_anon_obj(anon_obj, vec[ty_param], obj_def_ids, ann);
|
2010-09-09 15:59:29 -07:00
|
|
|
}
|
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
type lit = spanned[lit_];
|
|
|
|
tag lit_ {
|
2010-09-27 18:25:02 -07:00
|
|
|
lit_str(str);
|
2010-09-09 15:59:29 -07:00
|
|
|
lit_char(char);
|
|
|
|
lit_int(int);
|
2010-09-21 16:22:32 -07:00
|
|
|
lit_uint(uint);
|
2010-11-22 17:41:26 -08:00
|
|
|
lit_mach_int(ty_mach, int);
|
2011-03-21 17:12:05 -07:00
|
|
|
lit_float(str);
|
2011-03-22 17:25:40 -07:00
|
|
|
lit_mach_float(ty_mach, str);
|
2010-09-20 23:56:43 -07:00
|
|
|
lit_nil;
|
2010-09-09 15:59:29 -07:00
|
|
|
lit_bool(bool);
|
|
|
|
}
|
|
|
|
|
2010-11-03 16:43:12 -07:00
|
|
|
// NB: If you change this, you'll probably want to change the corresponding
|
2010-12-21 12:13:51 -08:00
|
|
|
// type structure in middle/ty.rs as well.
|
2010-12-03 18:03:28 -08:00
|
|
|
|
2011-03-17 17:39:47 -07:00
|
|
|
type mt = rec(@ty ty, mutability mut);
|
|
|
|
type ty_field = rec(ident ident, mt mt);
|
2010-12-03 18:03:28 -08:00
|
|
|
type ty_arg = rec(mode mode, @ty ty);
|
2011-04-19 13:35:49 -07:00
|
|
|
type ty_method = rec(proto proto, ident ident,
|
2011-05-20 14:15:39 -07:00
|
|
|
vec[ty_arg] inputs, @ty output,
|
|
|
|
controlflow cf);
|
2010-10-05 18:21:44 -07:00
|
|
|
type ty = spanned[ty_];
|
|
|
|
tag ty_ {
|
2010-09-20 23:56:43 -07:00
|
|
|
ty_nil;
|
2011-05-14 19:02:30 -07:00
|
|
|
ty_bot; /* return type of ! functions and type of
|
|
|
|
ret/fail/break/cont. there is no syntax
|
|
|
|
for this type. */
|
|
|
|
/* bot represents the value of functions that don't return a value
|
|
|
|
locally to their context. in contrast, things like log that do
|
|
|
|
return, but don't return a meaningful value, have result type nil. */
|
2010-09-20 23:56:43 -07:00
|
|
|
ty_bool;
|
|
|
|
ty_int;
|
2010-09-21 16:22:32 -07:00
|
|
|
ty_uint;
|
2011-03-21 17:12:05 -07:00
|
|
|
ty_float;
|
2011-05-12 17:24:54 +02:00
|
|
|
ty_machine(util::common::ty_mach);
|
2010-09-20 23:56:43 -07:00
|
|
|
ty_char;
|
2010-09-21 16:22:32 -07:00
|
|
|
ty_str;
|
2011-03-17 17:39:47 -07:00
|
|
|
ty_box(mt);
|
|
|
|
ty_vec(mt);
|
2011-03-10 22:58:55 -05:00
|
|
|
ty_port(@ty);
|
|
|
|
ty_chan(@ty);
|
2011-03-17 17:39:47 -07:00
|
|
|
ty_tup(vec[mt]);
|
2010-11-30 16:31:43 -08:00
|
|
|
ty_rec(vec[ty_field]);
|
2011-05-20 14:15:39 -07:00
|
|
|
ty_fn(proto, vec[ty_arg], @ty, controlflow);
|
2010-12-14 17:42:12 -08:00
|
|
|
ty_obj(vec[ty_method]);
|
2011-05-12 13:25:18 +02:00
|
|
|
ty_path(path, ann);
|
2011-02-01 14:56:21 -08:00
|
|
|
ty_type;
|
2011-03-04 14:15:19 -08:00
|
|
|
ty_constr(@ty, vec[@constr]);
|
2010-09-09 15:59:29 -07:00
|
|
|
}
|
|
|
|
|
2011-03-04 14:15:19 -08:00
|
|
|
tag constr_arg_ {
|
|
|
|
carg_base;
|
|
|
|
carg_ident(ident);
|
|
|
|
}
|
|
|
|
type constr_arg = spanned[constr_arg_];
|
|
|
|
type constr_ = rec(path path, vec[@constr_arg] args);
|
|
|
|
type constr = spanned[constr_];
|
|
|
|
|
2010-10-18 16:15:25 -07:00
|
|
|
type arg = rec(mode mode, @ty ty, ident ident, def_id id);
|
2011-04-19 13:35:49 -07:00
|
|
|
type fn_decl = rec(vec[arg] inputs,
|
2011-05-04 11:28:13 -07:00
|
|
|
@ty output,
|
2011-05-14 19:02:30 -07:00
|
|
|
purity purity,
|
|
|
|
controlflow cf);
|
2011-05-04 11:28:13 -07:00
|
|
|
tag purity {
|
|
|
|
pure_fn; // declared with "pred"
|
|
|
|
impure_fn; // declared with "fn"
|
|
|
|
}
|
|
|
|
|
2011-05-14 19:02:30 -07:00
|
|
|
tag controlflow {
|
|
|
|
noreturn; // functions with return type _|_ that always
|
|
|
|
// raise an error or exit (i.e. never return to the caller)
|
|
|
|
return; // everything else
|
|
|
|
}
|
|
|
|
|
2011-02-04 11:10:04 -05:00
|
|
|
type _fn = rec(fn_decl decl,
|
2011-02-25 12:08:21 -05:00
|
|
|
proto proto,
|
2010-08-18 09:00:10 -07:00
|
|
|
block body);
|
|
|
|
|
2010-12-16 18:34:04 -08:00
|
|
|
type method_ = rec(ident ident, _fn meth, def_id id, ann ann);
|
2010-12-14 15:32:13 -08:00
|
|
|
type method = spanned[method_];
|
|
|
|
|
2010-12-16 18:34:04 -08:00
|
|
|
type obj_field = rec(@ty ty, ident ident, def_id id, ann ann);
|
2010-12-14 15:32:13 -08:00
|
|
|
type _obj = rec(vec[obj_field] fields,
|
2011-03-01 17:32:16 -08:00
|
|
|
vec[@method] methods,
|
2011-05-12 17:24:54 +02:00
|
|
|
option::t[@method] dtor);
|
2010-12-14 15:32:13 -08:00
|
|
|
|
2011-05-10 11:55:32 -07:00
|
|
|
type anon_obj = rec(
|
|
|
|
// New fields and methods, if they exist.
|
2011-05-13 11:00:26 -07:00
|
|
|
option::t[vec[obj_field]] fields,
|
2011-05-10 11:55:32 -07:00
|
|
|
vec[@method] methods,
|
|
|
|
// with_obj: the original object being extended, if it exists.
|
2011-05-20 17:41:36 -07:00
|
|
|
option::t[@expr] with_obj);
|
2011-05-06 17:08:41 -07:00
|
|
|
|
2011-01-01 13:13:00 -05:00
|
|
|
type _mod = rec(vec[@view_item] view_items,
|
2011-05-11 16:30:48 +02:00
|
|
|
vec[@item] items);
|
2010-08-18 09:00:10 -07:00
|
|
|
|
2011-02-23 14:06:37 -05:00
|
|
|
tag native_abi {
|
|
|
|
native_abi_rust;
|
|
|
|
native_abi_cdecl;
|
2011-03-28 08:24:11 -07:00
|
|
|
native_abi_llvm;
|
2011-05-03 18:03:59 -07:00
|
|
|
native_abi_rust_intrinsic;
|
2011-02-23 14:06:37 -05:00
|
|
|
}
|
|
|
|
|
2011-02-02 10:43:57 -05:00
|
|
|
type native_mod = rec(str native_name,
|
2011-02-23 14:06:37 -05:00
|
|
|
native_abi abi,
|
2011-03-07 11:48:43 -08:00
|
|
|
vec[@view_item] view_items,
|
2011-05-11 16:30:48 +02:00
|
|
|
vec[@native_item] items);
|
2011-02-01 13:40:04 -05:00
|
|
|
|
2010-12-03 18:12:51 -08:00
|
|
|
type variant_arg = rec(@ty ty, def_id id);
|
2011-03-29 12:46:55 +02:00
|
|
|
type variant_ = rec(str name, vec[variant_arg] args, def_id id, ann ann);
|
|
|
|
type variant = spanned[variant_];
|
2010-11-24 11:36:35 -08:00
|
|
|
|
2011-01-01 12:55:18 -05:00
|
|
|
type view_item = spanned[view_item_];
|
|
|
|
tag view_item_ {
|
2011-05-26 17:16:54 -07:00
|
|
|
view_item_use(ident, vec[@meta_item], def_id, ann);
|
2011-05-09 12:40:09 +02:00
|
|
|
view_item_import(ident, vec[ident], def_id);
|
2011-05-19 17:18:53 -07:00
|
|
|
view_item_import_glob(vec[ident], def_id);
|
2011-03-02 13:50:42 -08:00
|
|
|
view_item_export(ident);
|
2011-01-01 12:55:18 -05:00
|
|
|
}
|
|
|
|
|
2011-03-30 17:23:25 -07:00
|
|
|
type obj_def_ids = rec(def_id ty, def_id ctor);
|
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
type item = spanned[item_];
|
|
|
|
tag item_ {
|
2010-12-09 14:37:50 -08:00
|
|
|
item_const(ident, @ty, @expr, def_id, ann);
|
2010-11-24 16:52:49 -08:00
|
|
|
item_fn(ident, _fn, vec[ty_param], def_id, ann);
|
2010-10-18 18:19:16 -07:00
|
|
|
item_mod(ident, _mod, def_id);
|
2011-02-01 13:40:04 -05:00
|
|
|
item_native_mod(ident, native_mod, def_id);
|
2010-11-24 17:36:22 -08:00
|
|
|
item_ty(ident, @ty, vec[ty_param], def_id, ann);
|
2011-03-31 19:12:40 -07:00
|
|
|
item_tag(ident, vec[variant], vec[ty_param], def_id, ann);
|
2011-03-30 17:23:25 -07:00
|
|
|
item_obj(ident, _obj, vec[ty_param], obj_def_ids, ann);
|
2010-09-09 15:59:29 -07:00
|
|
|
}
|
2010-08-18 09:00:10 -07:00
|
|
|
|
2011-05-11 15:10:24 +02:00
|
|
|
fn item_ident(@item it) -> ident {
|
|
|
|
ret alt (it.node) {
|
|
|
|
case (item_const(?ident, _, _, _, _)) { ident }
|
|
|
|
case (item_fn(?ident, _, _, _, _)) { ident }
|
|
|
|
case (item_mod(?ident, _, _)) { ident }
|
|
|
|
case (item_native_mod(?ident, _, _)) { ident }
|
|
|
|
case (item_ty(?ident, _, _, _, _)) { ident }
|
|
|
|
case (item_tag(?ident, _, _, _, _)) { ident }
|
|
|
|
case (item_obj(?ident, _, _, _, _)) { ident }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-02 10:43:57 -05:00
|
|
|
type native_item = spanned[native_item_];
|
|
|
|
tag native_item_ {
|
|
|
|
native_item_ty(ident, def_id);
|
2011-05-12 17:24:54 +02:00
|
|
|
native_item_fn(ident, option::t[str],
|
2011-03-20 20:18:19 -07:00
|
|
|
fn_decl, vec[ty_param], def_id, ann);
|
2011-02-02 10:43:57 -05:00
|
|
|
}
|
|
|
|
|
2011-05-02 20:29:39 -04:00
|
|
|
fn is_exported(ident i, _mod m) -> bool {
|
|
|
|
auto count = 0;
|
2011-05-12 17:24:54 +02:00
|
|
|
for (@ast::view_item vi in m.view_items) {
|
2011-05-02 20:29:39 -04:00
|
|
|
alt (vi.node) {
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::view_item_export(?id)) {
|
2011-05-17 20:41:41 +02:00
|
|
|
if (str::eq(i, id)) {
|
2011-05-02 20:29:39 -04:00
|
|
|
ret true;
|
|
|
|
}
|
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
case (_) { /* fall through */ }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If there are no declared exports then everything is exported
|
|
|
|
if (count == 0) {
|
|
|
|
ret true;
|
|
|
|
} else {
|
|
|
|
ret false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-09 22:36:37 -05:00
|
|
|
fn is_call_expr(@expr e) -> bool {
|
|
|
|
alt (e.node) {
|
|
|
|
case (expr_call(_, _, _)) {
|
|
|
|
ret true;
|
|
|
|
}
|
|
|
|
case (_) {
|
|
|
|
ret false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-02 14:28:35 -07:00
|
|
|
fn is_constraint_arg(@expr e) -> bool {
|
|
|
|
alt (e.node) {
|
|
|
|
case (expr_lit(_,_)) {
|
|
|
|
ret true;
|
|
|
|
}
|
2011-05-12 13:25:18 +02:00
|
|
|
case (expr_path(_, _)) {
|
2011-05-02 14:28:35 -07:00
|
|
|
ret true;
|
|
|
|
}
|
|
|
|
case (_) {
|
|
|
|
ret false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-12 10:27:50 -07: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'";
|
2010-08-12 10:27:50 -07:00
|
|
|
// End:
|
|
|
|
//
|