2011-07-05 16:23:07 -07:00
|
|
|
// The Rust abstract syntax tree.
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
import std::option;
|
2011-09-12 16:13:28 -07:00
|
|
|
import codemap::{span, filename};
|
2011-07-05 11:48:19 +02:00
|
|
|
|
2011-08-12 06:36:51 -07:00
|
|
|
type spanned<T> = {node: T, span: span};
|
2011-08-12 08:57:21 -07:00
|
|
|
|
2011-09-02 15:34:58 -07:00
|
|
|
type ident = str;
|
2011-08-25 15:12:54 -07:00
|
|
|
|
2011-06-24 15:11:22 -07:00
|
|
|
// Functions may or may not have names.
|
2011-08-12 07:15:18 -07:00
|
|
|
type fn_ident = option::t<ident>;
|
2010-08-18 09:00:10 -07:00
|
|
|
|
2011-06-24 22:17:17 -07:00
|
|
|
// FIXME: with typestate constraint, could say
|
|
|
|
// idents and types are the same length, and are
|
|
|
|
// non-empty
|
2011-08-04 16:20:09 -07:00
|
|
|
type path_ = {global: bool, idents: [ident], types: [@ty]};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
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-06-19 22:41:21 +02:00
|
|
|
type node_id = int;
|
2011-07-27 14:19:39 +02:00
|
|
|
type def_id = {crate: crate_num, node: node_id};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
const local_crate: crate_num = 0;
|
2010-10-18 16:15:25 -07:00
|
|
|
|
2011-07-28 17:22:59 +00:00
|
|
|
type ty_param = {ident: ident, kind: kind};
|
2010-11-24 18:01:20 -08:00
|
|
|
|
2010-10-18 16:15:25 -07:00
|
|
|
tag def {
|
2011-06-20 17:29:54 -07:00
|
|
|
def_fn(def_id, purity);
|
2011-09-01 10:03:17 +02:00
|
|
|
def_obj_field(def_id, mutability);
|
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);
|
2011-09-01 10:03:17 +02:00
|
|
|
def_arg(def_id, mode);
|
2011-09-15 14:08:54 +02:00
|
|
|
def_local(def_id, let_style);
|
2011-06-15 11:19:50 -07:00
|
|
|
def_variant(def_id, /* tag */def_id);
|
2011-08-19 15:16:48 -07:00
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
/* variant */
|
2010-10-18 16:15:25 -07:00
|
|
|
def_ty(def_id);
|
2011-07-28 13:29:29 -07:00
|
|
|
def_ty_arg(uint, kind);
|
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);
|
2011-09-02 15:34:58 -07:00
|
|
|
def_upvar(def_id, @def, /* writable */bool);
|
2010-10-05 18:21:44 -07:00
|
|
|
}
|
2010-10-04 17:25:52 -07:00
|
|
|
|
2011-06-29 18:07:15 -07:00
|
|
|
// The set of meta_items that define the compilation environment of the crate,
|
|
|
|
// used to drive conditional compilation
|
2011-08-04 16:20:09 -07:00
|
|
|
type crate_cfg = [@meta_item];
|
2011-06-29 18:07:15 -07:00
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type crate = spanned<crate_>;
|
2010-08-18 09:00:10 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
type crate_ =
|
2011-08-04 16:20:09 -07:00
|
|
|
{directives: [@crate_directive],
|
2011-07-27 14:19:39 +02:00
|
|
|
module: _mod,
|
2011-08-04 16:20:09 -07:00
|
|
|
attrs: [attribute],
|
2011-07-27 14:19:39 +02:00
|
|
|
config: crate_cfg};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-02-23 14:37:39 -08:00
|
|
|
tag crate_directive_ {
|
2011-08-12 07:15:18 -07:00
|
|
|
cdir_src_mod(ident, option::t<filename>, [attribute]);
|
2011-08-19 15:16:48 -07:00
|
|
|
cdir_dir_mod(ident, option::t<filename>, [@crate_directive], [attribute]);
|
2011-02-23 14:37:39 -08:00
|
|
|
cdir_view_item(@view_item);
|
|
|
|
cdir_syntax(path);
|
2011-04-19 13:35:49 -07:00
|
|
|
cdir_auth(path, _auth);
|
2011-02-23 14:37:39 -08:00
|
|
|
}
|
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type crate_directive = spanned<crate_directive_>;
|
2011-02-23 14:37:39 -08:00
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type meta_item = spanned<meta_item_>;
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-06-21 14:23:16 -07:00
|
|
|
tag meta_item_ {
|
|
|
|
meta_word(ident);
|
2011-08-04 16:20:09 -07:00
|
|
|
meta_list(ident, [@meta_item]);
|
2011-07-05 17:01:23 -07:00
|
|
|
meta_name_value(ident, lit);
|
2011-06-21 14:23:16 -07:00
|
|
|
}
|
2010-12-30 11:21:37 -05:00
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type blk = spanned<blk_>;
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-09-02 15:34:58 -07:00
|
|
|
type blk_ =
|
|
|
|
{stmts: [@stmt], expr: option::t<@expr>, id: node_id, rules: check_mode};
|
2010-08-18 09:00:10 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
type pat = {id: node_id, node: pat_, span: span};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
type field_pat = {ident: ident, pat: @pat};
|
2011-07-11 14:13:20 +02:00
|
|
|
|
2010-11-24 14:42:01 -08:00
|
|
|
tag pat_ {
|
2011-07-04 21:53:33 +02:00
|
|
|
pat_wild;
|
|
|
|
pat_bind(ident);
|
|
|
|
pat_lit(@lit);
|
2011-08-04 16:20:09 -07:00
|
|
|
pat_tag(path, [@pat]);
|
|
|
|
pat_rec([field_pat], bool);
|
2011-08-15 13:15:19 +02:00
|
|
|
pat_tup([@pat]);
|
2011-07-13 10:50:16 +02:00
|
|
|
pat_box(@pat);
|
2011-09-23 11:15:17 -07:00
|
|
|
pat_uniq(@pat);
|
2011-09-28 12:07:33 -07:00
|
|
|
pat_range(@lit, @lit);
|
2010-11-24 14:42:01 -08:00
|
|
|
}
|
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
tag mutability { mut; imm; maybe_mut; }
|
2010-11-29 14:18:26 -08:00
|
|
|
|
2011-07-27 17:49:00 -07:00
|
|
|
tag kind { kind_pinned; kind_shared; kind_unique; }
|
2010-12-03 18:03:28 -08:00
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
tag _auth { auth_unsafe; }
|
2010-12-03 18:03:28 -08:00
|
|
|
|
2011-10-10 13:15:47 -07:00
|
|
|
tag proto {
|
|
|
|
proto_iter;
|
|
|
|
proto_fn;
|
|
|
|
proto_block;
|
|
|
|
proto_closure;
|
|
|
|
// Functions without an environment. Eventually, this will
|
|
|
|
// merge with proto_fn.
|
|
|
|
proto_bare;
|
|
|
|
}
|
2011-02-18 17:30:57 -08:00
|
|
|
|
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-09-20 18:06:47 -07:00
|
|
|
tag unop {
|
|
|
|
box(mutability);
|
|
|
|
uniq(mutability);
|
|
|
|
deref; not; neg;
|
|
|
|
}
|
2010-09-27 18:25:02 -07:00
|
|
|
|
2011-10-06 12:26:12 +02:00
|
|
|
tag mode { by_ref; by_val; by_mut_ref; by_move; mode_infer; }
|
2010-12-03 18:03:28 -08:00
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type stmt = spanned<stmt_>;
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
tag stmt_ {
|
2011-06-19 22:41:21 +02:00
|
|
|
stmt_decl(@decl, node_id);
|
|
|
|
stmt_expr(@expr, node_id);
|
2011-08-19 15:16:48 -07:00
|
|
|
|
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-08-10 19:21:29 -07:00
|
|
|
tag init_op { init_assign; init_move; }
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
type initializer = {op: init_op, expr: @expr};
|
2011-03-24 21:04:29 -04:00
|
|
|
|
2011-08-19 15:16:48 -07:00
|
|
|
type local_ = // FIXME: should really be a refinement on pat
|
|
|
|
{ty: @ty, pat: @pat, init: option::t<initializer>, id: node_id};
|
2011-03-24 21:04:29 -04:00
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type local = spanned<local_>;
|
2010-10-18 18:19:16 -07:00
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type decl = spanned<decl_>;
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-09-15 11:42:56 +02:00
|
|
|
tag let_style { let_copy; let_ref; }
|
|
|
|
|
|
|
|
tag decl_ { decl_local([(let_style, @local)]); decl_item(@item); }
|
2010-09-09 15:59:29 -07:00
|
|
|
|
2011-08-22 14:38:48 +02:00
|
|
|
type arm = {pats: [@pat], guard: option::t<@expr>, body: blk};
|
2010-11-24 15:45:59 -08:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
type field_ = {mut: mutability, ident: ident, expr: @expr};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type field = spanned<field_>;
|
2010-11-30 16:31:43 -08:00
|
|
|
|
2011-06-28 16:29:37 -07:00
|
|
|
tag check_mode { checked; unchecked; }
|
2011-03-26 00:53:57 -04:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
type expr = {id: node_id, node: expr_, span: span};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
tag expr_ {
|
2011-08-18 11:37:19 -07:00
|
|
|
expr_vec([@expr], mutability);
|
2011-08-12 07:15:18 -07:00
|
|
|
expr_rec([field], option::t<@expr>);
|
2011-08-04 16:20:09 -07:00
|
|
|
expr_call(@expr, [@expr]);
|
2011-08-15 12:08:05 +02:00
|
|
|
expr_tup([@expr]);
|
2011-06-21 22:16:40 +02:00
|
|
|
expr_self_method(ident);
|
2011-08-12 07:15:18 -07:00
|
|
|
expr_bind(@expr, [option::t<@expr>]);
|
2011-06-21 22:16:40 +02:00
|
|
|
expr_binary(binop, @expr, @expr);
|
|
|
|
expr_unary(unop, @expr);
|
|
|
|
expr_lit(@lit);
|
|
|
|
expr_cast(@expr, @ty);
|
2011-08-12 07:15:18 -07:00
|
|
|
expr_if(@expr, blk, option::t<@expr>);
|
2011-06-23 15:15:50 -07:00
|
|
|
expr_ternary(@expr, @expr, @expr);
|
2011-07-25 14:16:12 -07:00
|
|
|
expr_while(@expr, blk);
|
|
|
|
expr_for(@local, @expr, blk);
|
|
|
|
expr_for_each(@local, @expr, blk);
|
|
|
|
expr_do_while(blk, @expr);
|
2011-08-04 16:20:09 -07:00
|
|
|
expr_alt(@expr, [arm]);
|
2011-06-21 22:16:40 +02:00
|
|
|
expr_fn(_fn);
|
2011-07-25 14:16:12 -07:00
|
|
|
expr_block(blk);
|
2011-08-19 15:16:48 -07:00
|
|
|
|
2011-06-16 16:55:46 -07:00
|
|
|
/*
|
|
|
|
* FIXME: many of these @exprs should be constrained with
|
|
|
|
* is_lval once we have constrained types working.
|
|
|
|
*/
|
2011-08-15 15:35:40 -07:00
|
|
|
expr_copy(@expr);
|
2011-06-21 22:16:40 +02:00
|
|
|
expr_move(@expr, @expr);
|
2011-07-27 14:19:39 +02:00
|
|
|
expr_assign(@expr, @expr);
|
2011-06-21 22:16:40 +02:00
|
|
|
expr_swap(@expr, @expr);
|
|
|
|
expr_assign_op(binop, @expr, @expr);
|
|
|
|
expr_field(@expr, ident);
|
|
|
|
expr_index(@expr, @expr);
|
|
|
|
expr_path(path);
|
2011-08-12 07:15:18 -07:00
|
|
|
expr_fail(option::t<@expr>);
|
2011-06-21 22:16:40 +02:00
|
|
|
expr_break;
|
|
|
|
expr_cont;
|
2011-08-12 07:15:18 -07:00
|
|
|
expr_ret(option::t<@expr>);
|
|
|
|
expr_put(option::t<@expr>);
|
2011-06-21 22:16:40 +02:00
|
|
|
expr_be(@expr);
|
|
|
|
expr_log(int, @expr);
|
2011-08-19 15:16:48 -07:00
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
/* just an assert, no significance to typestate */
|
2011-06-21 22:16:40 +02:00
|
|
|
expr_assert(@expr);
|
2011-08-19 15:16:48 -07:00
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
/* preds that typestate is aware of */
|
2011-06-28 16:29:37 -07:00
|
|
|
expr_check(check_mode, @expr);
|
2011-08-19 15:16:48 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
/* FIXME Would be nice if expr_check desugared
|
|
|
|
to expr_if_check. */
|
2011-08-12 07:15:18 -07:00
|
|
|
expr_if_check(@expr, blk, option::t<@expr>);
|
2011-07-21 15:08:15 -07:00
|
|
|
expr_anon_obj(anon_obj);
|
2011-07-08 16:35:09 -07:00
|
|
|
expr_mac(mac);
|
|
|
|
}
|
|
|
|
|
2011-08-25 17:42:38 -07:00
|
|
|
/*
|
|
|
|
// Says whether this is a block the user marked as
|
|
|
|
// "unchecked"
|
|
|
|
tag blk_sort {
|
|
|
|
blk_unchecked; // declared as "exception to effect-checking rules"
|
|
|
|
blk_checked; // all typing rules apply
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type mac = spanned<mac_>;
|
2011-07-08 16:35:09 -07:00
|
|
|
|
|
|
|
tag mac_ {
|
2011-09-02 15:34:58 -07:00
|
|
|
mac_invoc(path, @expr, option::t<str>);
|
2011-07-08 16:35:09 -07:00
|
|
|
mac_embed_type(@ty);
|
2011-07-25 14:16:12 -07:00
|
|
|
mac_embed_block(blk);
|
2011-07-11 16:13:17 -07:00
|
|
|
mac_ellipsis;
|
2010-09-09 15:59:29 -07:00
|
|
|
}
|
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type lit = spanned<lit_>;
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
tag lit_ {
|
2011-09-02 15:34:58 -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-09-02 15:34:58 -07:00
|
|
|
lit_float(str);
|
|
|
|
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.
|
2011-07-27 14:19:39 +02:00
|
|
|
type mt = {ty: @ty, mut: mutability};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
type ty_field_ = {ident: ident, mt: mt};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
type ty_arg_ = {mode: mode, ty: @ty};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
|
|
|
type ty_method_ =
|
2011-07-27 14:19:39 +02:00
|
|
|
{proto: proto,
|
|
|
|
ident: ident,
|
2011-08-04 16:20:09 -07:00
|
|
|
inputs: [ty_arg],
|
2011-07-27 14:19:39 +02:00
|
|
|
output: @ty,
|
2011-09-14 10:38:23 +02:00
|
|
|
cf: ret_style,
|
2011-08-04 16:20:09 -07:00
|
|
|
constrs: [@constr]};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type ty_field = spanned<ty_field_>;
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type ty_arg = spanned<ty_arg_>;
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type ty_method = spanned<ty_method_>;
|
2011-06-03 15:26:03 -07:00
|
|
|
|
2011-07-05 11:48:19 +02:00
|
|
|
tag ty_mach {
|
|
|
|
ty_i8;
|
|
|
|
ty_i16;
|
|
|
|
ty_i32;
|
|
|
|
ty_i64;
|
|
|
|
ty_u8;
|
|
|
|
ty_u16;
|
|
|
|
ty_u32;
|
|
|
|
ty_u64;
|
|
|
|
ty_f32;
|
|
|
|
ty_f64;
|
|
|
|
}
|
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type ty = spanned<ty_>;
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
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. */
|
2011-08-19 15:16:48 -07:00
|
|
|
|
2011-09-02 15:34:58 -07:00
|
|
|
|
2011-09-12 11:27:30 +02:00
|
|
|
|
2011-09-12 12:39:38 +02:00
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
/* 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. */
|
2011-09-12 11:27:30 +02:00
|
|
|
ty_bool;
|
2010-09-20 23:56:43 -07:00
|
|
|
ty_int;
|
2010-09-21 16:22:32 -07:00
|
|
|
ty_uint;
|
2011-03-21 17:12:05 -07:00
|
|
|
ty_float;
|
2011-07-05 11:48:19 +02:00
|
|
|
ty_machine(ty_mach);
|
2010-09-20 23:56:43 -07:00
|
|
|
ty_char;
|
2011-09-02 16:45:00 -07:00
|
|
|
ty_str;
|
2011-03-17 17:39:47 -07:00
|
|
|
ty_box(mt);
|
2011-09-20 16:07:09 -07:00
|
|
|
ty_uniq(mt);
|
2011-09-02 16:09:41 +02:00
|
|
|
ty_vec(mt);
|
2011-06-03 14:34:19 -04:00
|
|
|
ty_ptr(mt);
|
2011-05-31 16:27:39 -07:00
|
|
|
ty_task;
|
2011-03-10 22:58:55 -05:00
|
|
|
ty_port(@ty);
|
|
|
|
ty_chan(@ty);
|
2011-08-04 16:20:09 -07:00
|
|
|
ty_rec([ty_field]);
|
2011-09-14 10:38:23 +02:00
|
|
|
ty_fn(proto, [ty_arg], @ty, ret_style, [@constr]);
|
2011-08-04 16:20:09 -07:00
|
|
|
ty_obj([ty_method]);
|
2011-08-15 12:08:05 +02:00
|
|
|
ty_tup([@ty]);
|
2011-06-19 22:41:21 +02:00
|
|
|
ty_path(path, node_id);
|
2011-02-01 14:56:21 -08:00
|
|
|
ty_type;
|
2011-08-04 16:20:09 -07:00
|
|
|
ty_constr(@ty, [@ty_constr]);
|
2011-07-08 16:35:09 -07:00
|
|
|
ty_mac(mac);
|
2011-08-19 15:16:48 -07:00
|
|
|
|
2011-08-10 12:51:50 -07:00
|
|
|
// ty_infer means the type should be inferred instead of it having been
|
|
|
|
// specified. This should only appear at the "top level" of a type and not
|
|
|
|
// nested in one.
|
|
|
|
ty_infer;
|
2010-09-09 15:59:29 -07:00
|
|
|
}
|
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-06-10 19:12:42 -07:00
|
|
|
/*
|
|
|
|
A constraint arg that's a function argument is referred to by its position
|
|
|
|
rather than name. This is so we could have higher-order functions that have
|
|
|
|
constraints (potentially -- right now there's no way to write that), and also
|
|
|
|
so that the typestate pass doesn't have to map a function name onto its decl.
|
|
|
|
So, the constr_arg type is parameterized: it's instantiated with uint for
|
|
|
|
declarations, and ident for uses.
|
|
|
|
*/
|
2011-08-12 06:36:51 -07:00
|
|
|
tag constr_arg_general_<T> { carg_base; carg_ident(T); carg_lit(@lit); }
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type fn_constr_arg = constr_arg_general_<uint>;
|
2011-08-12 06:36:51 -07:00
|
|
|
type sp_constr_arg<T> = spanned<constr_arg_general_<T>>;
|
2011-08-12 07:15:18 -07:00
|
|
|
type ty_constr_arg = sp_constr_arg<path>;
|
|
|
|
type constr_arg = spanned<fn_constr_arg>;
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-07-19 17:52:34 -07:00
|
|
|
// Constrained types' args are parameterized by paths, since
|
|
|
|
// we refer to paths directly and not by indices.
|
|
|
|
// The implicit root of such path, in the constraint-list for a
|
|
|
|
// constrained type, is * (referring to the base record)
|
2011-06-10 19:12:42 -07:00
|
|
|
|
2011-08-12 06:36:51 -07:00
|
|
|
type constr_general_<ARG, ID> =
|
2011-08-12 07:15:18 -07:00
|
|
|
{path: path, args: [@spanned<constr_arg_general_<ARG>>], id: ID};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-07-19 17:52:34 -07:00
|
|
|
// In the front end, constraints have a node ID attached.
|
|
|
|
// Typeck turns this to a def_id, using the output of resolve.
|
2011-08-12 06:36:51 -07:00
|
|
|
type constr_general<ARG> = spanned<constr_general_<ARG, node_id>>;
|
2011-08-12 07:15:18 -07:00
|
|
|
type constr_ = constr_general_<uint, node_id>;
|
|
|
|
type constr = spanned<constr_general_<uint, node_id>>;
|
|
|
|
type ty_constr_ = ast::constr_general_<ast::path, ast::node_id>;
|
|
|
|
type ty_constr = spanned<ty_constr_>;
|
2011-06-16 16:55:46 -07:00
|
|
|
|
2011-06-15 15:14:30 -07:00
|
|
|
/* The parser generates ast::constrs; resolve generates
|
|
|
|
a mapping from each function to a list of ty::constr_defs,
|
|
|
|
corresponding to these. */
|
2011-07-27 14:19:39 +02:00
|
|
|
type arg = {mode: mode, ty: @ty, ident: ident, id: node_id};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-08-05 11:46:43 -07:00
|
|
|
tag inlineness { il_normal; il_inline; }
|
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
type fn_decl =
|
2011-08-04 16:20:09 -07:00
|
|
|
{inputs: [arg],
|
2011-07-27 14:19:39 +02:00
|
|
|
output: @ty,
|
|
|
|
purity: purity,
|
2011-08-05 11:46:43 -07:00
|
|
|
il: inlineness,
|
2011-09-14 10:38:23 +02:00
|
|
|
cf: ret_style,
|
2011-08-04 16:20:09 -07:00
|
|
|
constraints: [@constr]};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-05-04 11:28:13 -07:00
|
|
|
tag purity {
|
2011-08-24 13:39:15 -07:00
|
|
|
pure_fn; // declared with "pure fn"
|
2011-05-04 11:28:13 -07:00
|
|
|
impure_fn; // declared with "fn"
|
|
|
|
}
|
|
|
|
|
2011-09-14 10:38:23 +02:00
|
|
|
tag ret_style {
|
2011-05-14 19:02:30 -07:00
|
|
|
noreturn; // functions with return type _|_ that always
|
|
|
|
// raise an error or exit (i.e. never return to the caller)
|
2011-09-14 10:38:23 +02:00
|
|
|
return_val; // everything else
|
2011-09-15 16:15:17 +02:00
|
|
|
return_ref(bool, uint);
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
type _fn = {decl: fn_decl, proto: proto, body: blk};
|
2010-08-18 09:00:10 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
type method_ = {ident: ident, meth: _fn, id: node_id};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type method = spanned<method_>;
|
2010-12-14 15:32:13 -08:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
type obj_field = {mut: mutability, ty: @ty, ident: ident, id: node_id};
|
|
|
|
type anon_obj_field =
|
|
|
|
{mut: mutability, ty: @ty, expr: @expr, ident: ident, id: node_id};
|
2010-12-14 15:32:13 -08:00
|
|
|
|
2011-08-04 16:20:09 -07:00
|
|
|
type _obj = {fields: [obj_field], methods: [@method]};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
|
|
|
type anon_obj =
|
2011-07-27 14:19:39 +02:00
|
|
|
// New fields and methods, if they exist.
|
2011-08-19 15:16:48 -07:00
|
|
|
// inner_obj: the original object being extended, if it exists.
|
2011-08-12 07:15:18 -07:00
|
|
|
{fields: option::t<[anon_obj_field]>,
|
2011-08-04 16:20:09 -07:00
|
|
|
methods: [@method],
|
2011-08-12 07:15:18 -07:00
|
|
|
inner_obj: option::t<@expr>};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-08-04 16:20:09 -07:00
|
|
|
type _mod = {view_items: [@view_item], items: [@item]};
|
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-07-18 13:14:33 -07:00
|
|
|
native_abi_x86stdcall;
|
2011-09-28 12:58:03 -07:00
|
|
|
native_abi_c_stack_cdecl;
|
2011-10-03 13:59:38 -07:00
|
|
|
native_abi_c_stack_stdcall;
|
2011-02-23 14:06:37 -05:00
|
|
|
}
|
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
type native_mod =
|
2011-09-02 15:34:58 -07:00
|
|
|
{native_name: str,
|
2011-07-27 14:19:39 +02:00
|
|
|
abi: native_abi,
|
2011-08-04 16:20:09 -07:00
|
|
|
view_items: [@view_item],
|
|
|
|
items: [@native_item]};
|
2011-02-01 13:40:04 -05:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
type variant_arg = {ty: @ty, id: node_id};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-08-25 17:00:12 -07:00
|
|
|
type variant_ = {name: ident, args: [variant_arg], id: node_id};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type variant = spanned<variant_>;
|
2010-11-24 11:36:35 -08:00
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type view_item = spanned<view_item_>;
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-08-16 14:22:07 -07:00
|
|
|
// FIXME: May want to just use path here, which would allow things like
|
|
|
|
// 'import ::foo'
|
|
|
|
type simple_path = [ident];
|
|
|
|
|
2011-08-16 15:21:30 -07:00
|
|
|
type import_ident_ = {name: ident, id: node_id};
|
|
|
|
|
|
|
|
type import_ident = spanned<import_ident_>;
|
|
|
|
|
2011-01-01 12:55:18 -05:00
|
|
|
tag view_item_ {
|
2011-08-04 16:20:09 -07:00
|
|
|
view_item_use(ident, [@meta_item], node_id);
|
2011-08-16 14:22:07 -07:00
|
|
|
view_item_import(ident, simple_path, node_id);
|
|
|
|
view_item_import_glob(simple_path, node_id);
|
2011-08-16 15:21:30 -07:00
|
|
|
view_item_import_from(simple_path, [import_ident], node_id);
|
2011-08-16 12:09:47 -07:00
|
|
|
view_item_export([ident], node_id);
|
2011-01-01 12:55:18 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
type obj_def_ids = {ty: node_id, ctor: node_id};
|
2011-03-30 17:23:25 -07:00
|
|
|
|
2011-06-14 16:13:19 -07:00
|
|
|
|
|
|
|
// Meta-data associated with an item
|
2011-08-12 07:15:18 -07:00
|
|
|
type attribute = spanned<attribute_>;
|
2011-06-14 16:13:19 -07:00
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-06-14 16:13:19 -07:00
|
|
|
// Distinguishes between attributes that decorate items and attributes that
|
|
|
|
// are contained as statements within items. These two cases need to be
|
|
|
|
// distinguished for pretty-printing.
|
2011-06-15 11:19:50 -07:00
|
|
|
tag attr_style { attr_outer; attr_inner; }
|
2011-06-14 16:13:19 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
type attribute_ = {style: attr_style, value: meta_item};
|
2011-06-14 16:13:19 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
type item = // For objs and resources, this is the type def_id
|
2011-08-04 16:20:09 -07:00
|
|
|
{ident: ident, attrs: [attribute], id: node_id, node: item_, span: span};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
tag item_ {
|
2011-06-16 11:53:06 +02:00
|
|
|
item_const(@ty, @expr);
|
2011-08-04 16:20:09 -07:00
|
|
|
item_fn(_fn, [ty_param]);
|
2011-06-16 11:53:06 +02:00
|
|
|
item_mod(_mod);
|
|
|
|
item_native_mod(native_mod);
|
2011-08-04 16:20:09 -07:00
|
|
|
item_ty(@ty, [ty_param]);
|
|
|
|
item_tag([variant], [ty_param]);
|
|
|
|
item_obj(_obj, [ty_param], /* constructor id */node_id);
|
2011-08-19 15:16:48 -07:00
|
|
|
item_res(_fn,
|
2011-09-02 15:34:58 -07:00
|
|
|
|
|
|
|
/* dtor */
|
2011-08-19 15:16:48 -07:00
|
|
|
node_id,
|
2011-09-02 15:34:58 -07:00
|
|
|
|
|
|
|
/* dtor id */
|
2011-08-04 16:20:09 -07:00
|
|
|
[ty_param],
|
2011-08-19 15:16:48 -07:00
|
|
|
|
|
|
|
/* ctor id */
|
|
|
|
node_id);
|
2011-05-11 15:10:24 +02:00
|
|
|
}
|
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
type native_item =
|
|
|
|
{ident: ident,
|
2011-08-04 16:20:09 -07:00
|
|
|
attrs: [attribute],
|
2011-07-27 14:19:39 +02:00
|
|
|
node: native_item_,
|
|
|
|
id: node_id,
|
|
|
|
span: span};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-02-02 10:43:57 -05:00
|
|
|
tag native_item_ {
|
2011-06-21 23:01:08 +02:00
|
|
|
native_item_ty;
|
2011-09-02 15:34:58 -07:00
|
|
|
native_item_fn(option::t<str>, fn_decl, [ty_param]);
|
2011-02-02 10:43:57 -05:00
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
//
|