2011-07-05 16:23:07 -07:00
|
|
|
// The Rust abstract syntax tree.
|
2011-06-15 11:19:50 -07:00
|
|
|
|
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.
|
2012-01-31 17:05:20 -08:00
|
|
|
type fn_ident = option<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;
|
2011-12-16 16:55:22 +01:00
|
|
|
const crate_node_id: node_id = 0;
|
2010-10-18 16:15:25 -07:00
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum ty_param_bound {
|
2012-01-19 17:56:05 -08:00
|
|
|
bound_copy,
|
|
|
|
bound_send,
|
|
|
|
bound_iface(@ty),
|
2011-12-28 17:50:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type ty_param = {ident: ident, id: node_id, bounds: @[ty_param_bound]};
|
2010-11-24 18:01:20 -08:00
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum def {
|
2012-01-19 17:56:05 -08:00
|
|
|
def_fn(def_id, purity),
|
|
|
|
def_self(def_id),
|
|
|
|
def_mod(def_id),
|
|
|
|
def_native_mod(def_id),
|
|
|
|
def_const(def_id),
|
|
|
|
def_arg(def_id, mode),
|
|
|
|
def_local(def_id, let_style),
|
|
|
|
def_variant(def_id /* enum */, def_id /* variant */),
|
|
|
|
def_ty(def_id),
|
2012-02-06 15:29:56 +01:00
|
|
|
def_prim_ty(prim_ty),
|
2012-01-19 17:56:05 -08:00
|
|
|
def_ty_param(def_id, uint),
|
|
|
|
def_binding(def_id),
|
|
|
|
def_use(def_id),
|
|
|
|
def_upvar(def_id, @def, node_id), // node_id == expr_fn or expr_fn_block
|
2012-02-07 11:31:15 -08:00
|
|
|
def_class(def_id),
|
|
|
|
// first def_id is for parent class
|
|
|
|
def_class_field(def_id, def_id),
|
|
|
|
// No purity allowed for now, I guess
|
|
|
|
// (simpler this way, b/c presumably methods read mutable state)
|
|
|
|
def_class_method(def_id, def_id)
|
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
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum crate_directive_ {
|
2012-01-19 17:56:05 -08:00
|
|
|
cdir_src_mod(ident, [attribute]),
|
|
|
|
cdir_dir_mod(ident, [@crate_directive], [attribute]),
|
2011-12-07 13:29:04 -08:00
|
|
|
|
2012-01-19 17:56:05 -08:00
|
|
|
// NB: cdir_view_item is *not* processed by the rest of the compiler, the
|
2011-12-07 13:29:04 -08:00
|
|
|
// attached view_items are sunk into the crate's module during parsing,
|
2012-01-19 14:34:23 -08:00
|
|
|
// and processed (resolved, imported, etc.) there. This enum-variant
|
|
|
|
// exists only to preserve the view items in order in case we decide to
|
2011-12-07 13:29:04 -08:00
|
|
|
// pretty-print crates in the future.
|
2012-01-19 17:56:05 -08:00
|
|
|
cdir_view_item(@view_item),
|
2011-12-07 13:29:04 -08:00
|
|
|
|
2012-01-19 17:56:05 -08:00
|
|
|
cdir_syntax(@path),
|
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
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum meta_item_ {
|
2012-01-19 17:56:05 -08:00
|
|
|
meta_word(ident),
|
|
|
|
meta_list(ident, [@meta_item]),
|
|
|
|
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
|
|
|
|
2012-01-31 17:05:20 -08:00
|
|
|
type blk_ = {view_items: [@view_item], stmts: [@stmt], expr: option<@expr>,
|
2011-11-23 20:57:34 +01:00
|
|
|
id: node_id, rules: blk_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
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum pat_ {
|
2012-01-19 17:56:05 -08:00
|
|
|
pat_wild,
|
2012-01-14 16:05:07 -08:00
|
|
|
// A pat_ident may either be a new bound variable,
|
2012-01-19 14:24:03 -08:00
|
|
|
// or a nullary enum (in which case the second field
|
2012-01-14 16:05:07 -08:00
|
|
|
// is none).
|
2012-01-19 14:24:03 -08:00
|
|
|
// In the nullary enum case, the parser can't determine
|
2012-01-14 16:05:07 -08:00
|
|
|
// which it is. The resolver determines this, and
|
|
|
|
// records this pattern's node_id in an auxiliary
|
2012-01-25 14:34:31 +01:00
|
|
|
// set (of "pat_idents that refer to nullary enums")
|
2012-01-14 16:05:07 -08:00
|
|
|
// After the resolution phase, code should never pattern-
|
|
|
|
// match on a pat directly! Always call pat_util::normalize_pat --
|
2012-01-25 14:34:31 +01:00
|
|
|
// it turns any pat_idents that refer to nullary enums into pat_enums.
|
2012-01-31 17:05:20 -08:00
|
|
|
pat_ident(@path, option<@pat>),
|
2012-01-25 14:34:31 +01:00
|
|
|
pat_enum(@path, [@pat]),
|
2012-01-19 17:56:05 -08:00
|
|
|
pat_rec([field_pat], bool),
|
|
|
|
pat_tup([@pat]),
|
|
|
|
pat_box(@pat),
|
|
|
|
pat_uniq(@pat),
|
|
|
|
pat_lit(@expr),
|
|
|
|
pat_range(@expr, @expr),
|
2010-11-24 14:42:01 -08:00
|
|
|
}
|
|
|
|
|
2012-01-19 17:56:05 -08:00
|
|
|
enum mutability { mut, imm, maybe_mut, }
|
2010-11-29 14:18:26 -08:00
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum proto {
|
2012-01-19 17:56:05 -08:00
|
|
|
proto_bare, // native fn
|
|
|
|
proto_any, // fn
|
|
|
|
proto_uniq, // fn~
|
|
|
|
proto_box, // fn@
|
|
|
|
proto_block, // fn&
|
2011-10-10 13:15:47 -07:00
|
|
|
}
|
2011-02-18 17:30:57 -08:00
|
|
|
|
2012-01-12 15:38:44 -08:00
|
|
|
pure fn is_blockish(p: ast::proto) -> bool {
|
|
|
|
alt p {
|
2012-01-18 22:37:22 -08:00
|
|
|
proto_any | proto_block { true }
|
|
|
|
proto_bare | proto_uniq | proto_box { false }
|
2012-01-12 15:38:44 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum binop {
|
2012-01-19 17:56:05 -08:00
|
|
|
add,
|
|
|
|
subtract,
|
|
|
|
mul,
|
|
|
|
div,
|
|
|
|
rem,
|
|
|
|
and,
|
|
|
|
or,
|
|
|
|
bitxor,
|
|
|
|
bitand,
|
|
|
|
bitor,
|
|
|
|
lsl,
|
|
|
|
lsr,
|
|
|
|
asr,
|
|
|
|
eq,
|
|
|
|
lt,
|
|
|
|
le,
|
|
|
|
ne,
|
|
|
|
ge,
|
|
|
|
gt,
|
2010-09-27 18:25:02 -07:00
|
|
|
}
|
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum unop {
|
2012-01-19 17:56:05 -08:00
|
|
|
box(mutability),
|
|
|
|
uniq(mutability),
|
|
|
|
deref, not, neg,
|
2011-09-20 18:06:47 -07:00
|
|
|
}
|
2010-09-27 18:25:02 -07:00
|
|
|
|
2012-02-02 16:50:17 -08:00
|
|
|
// Generally, after typeck you can get the inferred value
|
|
|
|
// using ty::resolved_T(...).
|
|
|
|
enum inferable<T> {
|
|
|
|
expl(T), infer(node_id)
|
|
|
|
}
|
|
|
|
|
|
|
|
// "resolved" mode: the real modes.
|
|
|
|
enum rmode { by_ref, by_val, by_mut_ref, by_move, by_copy }
|
|
|
|
|
|
|
|
// inferable mode.
|
|
|
|
type mode = inferable<rmode>;
|
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
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum stmt_ {
|
2012-01-19 17:56:05 -08:00
|
|
|
stmt_decl(@decl, node_id),
|
2012-01-04 14:16:41 -08:00
|
|
|
|
|
|
|
// expr without trailing semi-colon (must have unit type):
|
2012-01-19 17:56:05 -08:00
|
|
|
stmt_expr(@expr, node_id),
|
2012-01-04 14:16:41 -08:00
|
|
|
|
|
|
|
// expr with trailing semi-colon (may have any type):
|
2012-01-19 17:56:05 -08:00
|
|
|
stmt_semi(@expr, node_id),
|
2010-09-09 15:59:29 -07:00
|
|
|
}
|
|
|
|
|
2012-01-19 17:56:05 -08:00
|
|
|
enum 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
|
2012-01-31 17:05:20 -08:00
|
|
|
{ty: @ty, pat: @pat, init: option<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
|
|
|
|
2012-01-19 17:56:05 -08:00
|
|
|
enum let_style { let_copy, let_ref, }
|
2011-09-15 11:42:56 +02:00
|
|
|
|
2012-01-19 17:56:05 -08:00
|
|
|
enum decl_ { decl_local([(let_style, @local)]), decl_item(@item), }
|
2010-09-09 15:59:29 -07:00
|
|
|
|
2012-01-31 17:05:20 -08:00
|
|
|
type arm = {pats: [@pat], guard: option<@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
|
|
|
|
2012-01-19 17:56:05 -08:00
|
|
|
enum blk_check_mode { default_blk, unchecked_blk, unsafe_blk, }
|
2011-10-06 16:42:27 -07:00
|
|
|
|
2012-01-19 17:56:05 -08:00
|
|
|
enum expr_check_mode { claimed_expr, checked_expr, }
|
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
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum expr_ {
|
2012-01-19 17:56:05 -08:00
|
|
|
expr_vec([@expr], mutability),
|
2012-01-31 17:05:20 -08:00
|
|
|
expr_rec([field], option<@expr>),
|
2012-01-19 17:56:05 -08:00
|
|
|
expr_call(@expr, [@expr], bool),
|
|
|
|
expr_tup([@expr]),
|
2012-01-31 17:05:20 -08:00
|
|
|
expr_bind(@expr, [option<@expr>]),
|
2012-01-19 17:56:05 -08:00
|
|
|
expr_binary(binop, @expr, @expr),
|
|
|
|
expr_unary(unop, @expr),
|
|
|
|
expr_lit(@lit),
|
|
|
|
expr_cast(@expr, @ty),
|
2012-01-31 17:05:20 -08:00
|
|
|
expr_if(@expr, blk, option<@expr>),
|
2012-01-19 17:56:05 -08:00
|
|
|
expr_while(@expr, blk),
|
|
|
|
expr_for(@local, @expr, blk),
|
|
|
|
expr_do_while(blk, @expr),
|
|
|
|
expr_alt(@expr, [arm]),
|
|
|
|
expr_fn(proto, fn_decl, blk, @capture_clause),
|
|
|
|
expr_fn_block(fn_decl, blk),
|
|
|
|
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.
|
|
|
|
*/
|
2012-01-19 17:56:05 -08:00
|
|
|
expr_copy(@expr),
|
|
|
|
expr_move(@expr, @expr),
|
|
|
|
expr_assign(@expr, @expr),
|
|
|
|
expr_swap(@expr, @expr),
|
|
|
|
expr_assign_op(binop, @expr, @expr),
|
|
|
|
expr_field(@expr, ident, [@ty]),
|
|
|
|
expr_index(@expr, @expr),
|
|
|
|
expr_path(@path),
|
2012-01-31 17:05:20 -08:00
|
|
|
expr_fail(option<@expr>),
|
2012-01-19 17:56:05 -08:00
|
|
|
expr_break,
|
|
|
|
expr_cont,
|
2012-01-31 17:05:20 -08:00
|
|
|
expr_ret(option<@expr>),
|
2012-01-19 17:56:05 -08:00
|
|
|
expr_be(@expr),
|
|
|
|
expr_log(int, @expr, @expr),
|
2011-08-19 15:16:48 -07:00
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
/* just an assert, no significance to typestate */
|
2012-01-19 17:56:05 -08: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 */
|
2012-01-19 17:56:05 -08:00
|
|
|
expr_check(expr_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. */
|
2012-01-31 17:05:20 -08:00
|
|
|
expr_if_check(@expr, blk, option<@expr>),
|
2012-01-19 17:56:05 -08:00
|
|
|
expr_mac(mac),
|
2011-07-08 16:35:09 -07:00
|
|
|
}
|
|
|
|
|
2011-12-17 21:12:30 -08:00
|
|
|
type capture_item = {
|
|
|
|
id: int,
|
|
|
|
name: ident, // Currently, can only capture a local var.
|
|
|
|
span: span
|
|
|
|
};
|
|
|
|
type capture_clause = {
|
|
|
|
copies: [@capture_item],
|
|
|
|
moves: [@capture_item]
|
2011-12-08 11:47:01 -08:00
|
|
|
};
|
|
|
|
|
2011-08-25 17:42:38 -07:00
|
|
|
/*
|
|
|
|
// Says whether this is a block the user marked as
|
|
|
|
// "unchecked"
|
2012-01-19 14:24:03 -08:00
|
|
|
enum blk_sort {
|
2012-01-19 17:56:05 -08:00
|
|
|
blk_unchecked, // declared as "exception to effect-checking rules"
|
|
|
|
blk_checked, // all typing rules apply
|
2011-08-25 17:42:38 -07:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type mac = spanned<mac_>;
|
2011-07-08 16:35:09 -07:00
|
|
|
|
2012-02-01 00:20:31 -07:00
|
|
|
type mac_arg = option::t<@expr>;
|
2012-01-31 23:50:12 -07:00
|
|
|
|
|
|
|
type mac_body_ = {span: span};
|
2012-01-31 20:30:26 -07:00
|
|
|
type mac_body = option::t<mac_body_>;
|
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum mac_ {
|
2012-01-31 23:50:12 -07:00
|
|
|
mac_invoc(@path, mac_arg, mac_body),
|
2012-01-19 17:56:05 -08:00
|
|
|
mac_embed_type(@ty),
|
|
|
|
mac_embed_block(blk),
|
|
|
|
mac_ellipsis,
|
2012-01-25 16:38:09 -07:00
|
|
|
// the span is used by the quoter/anti-quoter ...
|
|
|
|
mac_aq(span /* span of quote */, @expr), // anti-quote
|
2012-02-01 16:19:45 -07:00
|
|
|
mac_var(uint)
|
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
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum lit_ {
|
2012-01-19 17:56:05 -08:00
|
|
|
lit_str(str),
|
|
|
|
lit_int(i64, int_ty),
|
|
|
|
lit_uint(u64, uint_ty),
|
|
|
|
lit_float(str, float_ty),
|
|
|
|
lit_nil,
|
|
|
|
lit_bool(bool),
|
2010-09-09 15:59:29 -07:00
|
|
|
}
|
|
|
|
|
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-08-12 07:15:18 -07:00
|
|
|
type ty_field = spanned<ty_field_>;
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2012-01-30 11:43:45 -08:00
|
|
|
type ty_method = {ident: ident, attrs: [attribute],
|
|
|
|
decl: fn_decl, tps: [ty_param], span: span};
|
2011-06-03 15:26:03 -07:00
|
|
|
|
2012-01-19 17:56:05 -08:00
|
|
|
enum int_ty { ty_i, ty_char, ty_i8, ty_i16, ty_i32, ty_i64, }
|
2011-12-07 21:06:12 +01:00
|
|
|
|
2012-01-19 17:56:05 -08:00
|
|
|
enum uint_ty { ty_u, ty_u8, ty_u16, ty_u32, ty_u64, }
|
2011-12-07 21:06:12 +01:00
|
|
|
|
2012-01-19 17:56:05 -08:00
|
|
|
enum float_ty { ty_f, ty_f32, ty_f64, }
|
2011-07-05 11:48:19 +02:00
|
|
|
|
2011-08-12 07:15:18 -07:00
|
|
|
type ty = spanned<ty_>;
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2012-02-06 15:29:56 +01:00
|
|
|
// Not represented directly in the AST, referred to by name through a ty_path.
|
|
|
|
enum prim_ty {
|
2012-01-19 17:56:05 -08:00
|
|
|
ty_int(int_ty),
|
|
|
|
ty_uint(uint_ty),
|
|
|
|
ty_float(float_ty),
|
|
|
|
ty_str,
|
2012-02-06 15:29:56 +01:00
|
|
|
ty_bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ty_ {
|
|
|
|
ty_nil,
|
|
|
|
ty_bot, /* bottom type */
|
2012-01-19 17:56:05 -08:00
|
|
|
ty_box(mt),
|
|
|
|
ty_uniq(mt),
|
|
|
|
ty_vec(mt),
|
|
|
|
ty_ptr(mt),
|
|
|
|
ty_rec([ty_field]),
|
|
|
|
ty_fn(proto, fn_decl),
|
|
|
|
ty_tup([@ty]),
|
|
|
|
ty_path(@path, node_id),
|
|
|
|
ty_constr(@ty, [@ty_constr]),
|
|
|
|
ty_mac(mac),
|
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.
|
2012-01-19 17:56:05 -08:00
|
|
|
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.
|
|
|
|
*/
|
2012-01-19 17:56:05 -08:00
|
|
|
enum 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-11-30 13:38:38 +01:00
|
|
|
type ty_constr_arg = sp_constr_arg<@path>;
|
2011-08-12 07:15:18 -07:00
|
|
|
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-11-30 13:38:38 +01: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>>;
|
2011-11-30 13:38:38 +01:00
|
|
|
type ty_constr_ = constr_general_<@path, node_id>;
|
2011-08-12 07:15:18 -07:00
|
|
|
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
|
|
|
|
|
|
|
type fn_decl =
|
2011-12-29 20:07:55 -08:00
|
|
|
{inputs: [arg],
|
2011-07-27 14:19:39 +02:00
|
|
|
output: @ty,
|
|
|
|
purity: purity,
|
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
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum purity {
|
2012-01-19 17:56:05 -08:00
|
|
|
pure_fn, // declared with "pure fn"
|
|
|
|
unsafe_fn, // declared with "unsafe fn"
|
|
|
|
impure_fn, // declared with "fn"
|
2011-05-04 11:28:13 -07:00
|
|
|
}
|
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum ret_style {
|
2012-01-19 17:56:05 -08:00
|
|
|
noreturn, // functions with return type _|_ that always
|
2011-05-14 19:02:30 -07:00
|
|
|
// raise an error or exit (i.e. never return to the caller)
|
2012-01-19 17:56:05 -08:00
|
|
|
return_val, // everything else
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
|
|
|
|
2012-01-30 11:43:45 -08:00
|
|
|
type method = {ident: ident, attrs: [attribute],
|
|
|
|
tps: [ty_param], decl: fn_decl, body: blk,
|
2011-12-22 17:49:54 +01:00
|
|
|
id: node_id, span: span};
|
2010-12-14 15:32:13 -08: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
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum native_abi {
|
2012-01-19 17:56:05 -08:00
|
|
|
native_abi_rust_intrinsic,
|
|
|
|
native_abi_cdecl,
|
|
|
|
native_abi_stdcall,
|
2011-02-23 14:06:37 -05:00
|
|
|
}
|
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
type native_mod =
|
2011-11-21 02:15:40 +08:00
|
|
|
{view_items: [@view_item],
|
2011-08-04 16:20:09 -07:00
|
|
|
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
|
|
|
|
2012-01-25 16:23:43 -08:00
|
|
|
type variant_ = {name: ident, attrs: [attribute], args: [variant_arg],
|
2012-01-31 17:05:20 -08:00
|
|
|
id: node_id, disr_expr: option<@expr>};
|
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_>;
|
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum view_item_ {
|
2012-01-19 17:56:05 -08:00
|
|
|
view_item_use(ident, [@meta_item], node_id),
|
|
|
|
view_item_import(ident, @simple_path, node_id),
|
|
|
|
view_item_import_glob(@simple_path, node_id),
|
|
|
|
view_item_import_from(@simple_path, [import_ident], node_id),
|
|
|
|
view_item_export([ident], node_id),
|
2012-01-20 19:44:38 -08:00
|
|
|
// export foo::{}
|
2012-01-25 14:34:31 +01:00
|
|
|
view_item_export_enum_none(ident, node_id),
|
2012-01-20 19:44:38 -08:00
|
|
|
// export foo::{bar, baz, blat}
|
2012-01-25 14:34:31 +01:00
|
|
|
view_item_export_enum_some(ident, [import_ident], node_id)
|
2011-01-01 12:55:18 -05: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.
|
2012-01-19 17:56:05 -08:00
|
|
|
enum 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
|
|
|
|
2012-01-13 10:58:31 +01:00
|
|
|
type item = {ident: ident, attrs: [attribute],
|
|
|
|
id: node_id, node: item_, span: span};
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum item_ {
|
2012-01-19 17:56:05 -08:00
|
|
|
item_const(@ty, @expr),
|
|
|
|
item_fn(fn_decl, [ty_param], blk),
|
|
|
|
item_mod(_mod),
|
|
|
|
item_native_mod(native_mod),
|
|
|
|
item_ty(@ty, [ty_param]),
|
2012-01-25 14:34:31 +01:00
|
|
|
item_enum([variant], [ty_param]),
|
2011-12-22 17:49:54 +01:00
|
|
|
item_res(fn_decl /* dtor */, [ty_param], blk,
|
2012-01-19 17:56:05 -08:00
|
|
|
node_id /* dtor id */, node_id /* ctor id */),
|
2012-01-31 19:30:40 -08:00
|
|
|
item_class([ty_param], /* ty params for class */
|
|
|
|
[@class_item], /* methods, etc. */
|
|
|
|
/* (not including ctor) */
|
2012-02-07 11:31:15 -08:00
|
|
|
node_id, /* ctor id */
|
2012-01-31 19:30:40 -08:00
|
|
|
fn_decl, /* ctor decl */
|
|
|
|
blk /* ctor body */
|
|
|
|
),
|
2012-01-19 17:56:05 -08:00
|
|
|
item_iface([ty_param], [ty_method]),
|
2012-01-31 17:05:20 -08:00
|
|
|
item_impl([ty_param], option<@ty> /* iface */,
|
2012-01-19 17:56:05 -08:00
|
|
|
@ty /* self */, [@method]),
|
2011-05-11 15:10:24 +02:00
|
|
|
}
|
|
|
|
|
2012-02-07 11:31:15 -08:00
|
|
|
type class_item_ = {privacy: privacy, decl: class_member};
|
2012-01-31 19:30:40 -08:00
|
|
|
type class_item = spanned<class_item_>;
|
|
|
|
|
|
|
|
enum class_member {
|
|
|
|
instance_var(ident, @ty, class_mutability, node_id),
|
2012-02-07 11:31:15 -08:00
|
|
|
class_method(@item) // FIXME: methods aren't allowed to be
|
|
|
|
// type-parametric.
|
|
|
|
// without constrained types, have to duplicate some stuff. or factor out
|
|
|
|
// item to separate out things with type params?
|
2012-01-31 19:30:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
enum class_mutability { class_mutable, class_immutable }
|
|
|
|
|
|
|
|
enum privacy { priv, pub }
|
|
|
|
|
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
|
|
|
|
2012-01-19 14:24:03 -08:00
|
|
|
enum native_item_ {
|
2012-01-19 17:56:05 -08:00
|
|
|
native_item_fn(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
|
|
|
|
// End:
|
|
|
|
//
|