2014-01-30 12:29:35 -06:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 18:48:01 -06:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2011-07-05 18:23:07 -05:00
|
|
|
// The Rust abstract syntax tree.
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2014-01-27 06:18:36 -06:00
|
|
|
use codemap::{Span, Spanned, DUMMY_SP};
|
2014-04-02 03:19:41 -05:00
|
|
|
use abi::Abi;
|
2014-01-27 06:18:36 -06:00
|
|
|
use ast_util;
|
2014-03-19 09:52:37 -05:00
|
|
|
use owned_slice::OwnedSlice;
|
2014-01-31 18:10:06 -06:00
|
|
|
use parse::token::{InternedString, special_idents, str_to_ident};
|
|
|
|
use parse::token;
|
2012-05-21 12:45:56 -05:00
|
|
|
|
2014-02-19 20:56:33 -06:00
|
|
|
use std::fmt;
|
|
|
|
use std::fmt::Show;
|
2013-06-24 19:40:33 -05:00
|
|
|
use std::option::Option;
|
2014-01-31 22:54:41 -06:00
|
|
|
use std::rc::Rc;
|
2014-06-11 21:33:52 -05:00
|
|
|
use std::gc::{Gc, GC};
|
2014-02-05 10:52:54 -06:00
|
|
|
use serialize::{Encodable, Decodable, Encoder, Decoder};
|
2012-12-23 16:41:37 -06:00
|
|
|
|
2013-11-30 16:00:39 -06:00
|
|
|
/// A pointer abstraction. FIXME(eddyb) #10676 use Rc<T> in the future.
|
2014-05-16 02:16:13 -05:00
|
|
|
pub type P<T> = Gc<T>;
|
2013-11-30 16:00:39 -06:00
|
|
|
|
2014-05-25 18:27:36 -05:00
|
|
|
#[allow(non_snake_case_functions)]
|
2013-11-30 16:00:39 -06:00
|
|
|
/// Construct a P<T> from a T value.
|
|
|
|
pub fn P<T: 'static>(value: T) -> P<T> {
|
2014-05-16 02:16:13 -05:00
|
|
|
box(GC) value
|
2013-11-30 16:00:39 -06:00
|
|
|
}
|
2013-06-07 12:39:59 -05:00
|
|
|
|
|
|
|
// FIXME #6993: in librustc, uses of "ident" should be replaced
|
|
|
|
// by just "Name".
|
|
|
|
|
2013-05-17 12:18:09 -05:00
|
|
|
// an identifier contains a Name (index into the interner
|
|
|
|
// table) and a SyntaxContext to track renaming and
|
2013-02-26 12:15:29 -06:00
|
|
|
// macro expansion per Flatt et al., "Macros
|
|
|
|
// That Work Together"
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, Hash, PartialOrd, Eq, Ord, Show)]
|
2014-02-24 14:47:19 -06:00
|
|
|
pub struct Ident {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub name: Name,
|
|
|
|
pub ctxt: SyntaxContext
|
2014-02-24 14:47:19 -06:00
|
|
|
}
|
2012-09-19 20:50:24 -05:00
|
|
|
|
2013-09-01 19:50:59 -05:00
|
|
|
impl Ident {
|
|
|
|
/// Construct an identifier with the given name and an empty context:
|
2013-09-01 20:45:37 -05:00
|
|
|
pub fn new(name: Name) -> Ident { Ident {name: name, ctxt: EMPTY_CTXT}}
|
2013-09-01 19:50:59 -05:00
|
|
|
}
|
2013-06-04 14:34:25 -05:00
|
|
|
|
2014-05-29 19:45:07 -05:00
|
|
|
impl PartialEq for Ident {
|
2013-07-10 00:52:34 -05:00
|
|
|
fn eq(&self, other: &Ident) -> bool {
|
2014-01-19 02:21:14 -06:00
|
|
|
if self.ctxt == other.ctxt {
|
2013-07-10 00:52:34 -05:00
|
|
|
self.name == other.name
|
|
|
|
} else {
|
2013-07-12 00:58:14 -05:00
|
|
|
// IF YOU SEE ONE OF THESE FAILS: it means that you're comparing
|
|
|
|
// idents that have different contexts. You can't fix this without
|
|
|
|
// knowing whether the comparison should be hygienic or non-hygienic.
|
|
|
|
// if it should be non-hygienic (most things are), just compare the
|
|
|
|
// 'name' fields of the idents. Or, even better, replace the idents
|
|
|
|
// with Name's.
|
2014-02-15 02:54:32 -06:00
|
|
|
//
|
|
|
|
// On the other hand, if the comparison does need to be hygienic,
|
|
|
|
// one example and its non-hygienic counterpart would be:
|
|
|
|
// syntax::parse::token::mtwt_token_eq
|
|
|
|
// syntax::ext::tt::macro_parser::token_name_eq
|
|
|
|
fail!("not allowed to compare these idents: {:?}, {:?}. \
|
|
|
|
Probably related to issue \\#6993", self, other);
|
2013-07-10 00:52:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &Ident) -> bool {
|
|
|
|
! self.eq(other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-18 06:12:07 -05:00
|
|
|
/// A SyntaxContext represents a chain of macro-expandings
|
|
|
|
/// and renamings. Each macro expansion corresponds to
|
|
|
|
/// a fresh uint
|
2013-04-03 12:28:14 -05:00
|
|
|
|
|
|
|
// I'm representing this syntax context as an index into
|
|
|
|
// a table, in order to work around a compiler bug
|
|
|
|
// that's causing unreleased memory to cause core dumps
|
|
|
|
// and also perhaps to save some work in destructor checks.
|
|
|
|
// the special uint '0' will be used to indicate an empty
|
2013-05-16 19:42:08 -05:00
|
|
|
// syntax context.
|
2013-04-03 12:28:14 -05:00
|
|
|
|
|
|
|
// this uint is a reference to a table stored in thread-local
|
|
|
|
// storage.
|
2013-11-26 23:02:25 -06:00
|
|
|
pub type SyntaxContext = u32;
|
|
|
|
pub static EMPTY_CTXT : SyntaxContext = 0;
|
|
|
|
pub static ILLEGAL_CTXT : SyntaxContext = 1;
|
2013-04-03 12:28:14 -05:00
|
|
|
|
2013-07-18 06:12:07 -05:00
|
|
|
/// A name is a part of an identifier, representing a string or gensym. It's
|
|
|
|
/// the result of interning.
|
2013-11-26 23:02:25 -06:00
|
|
|
pub type Name = u32;
|
2013-10-29 05:03:32 -05:00
|
|
|
|
2013-07-18 06:12:07 -05:00
|
|
|
/// A mark represents a unique id associated with a macro expansion
|
2013-11-26 23:02:25 -06:00
|
|
|
pub type Mrk = u32;
|
2012-09-19 20:50:24 -05:00
|
|
|
|
2014-03-18 12:58:26 -05:00
|
|
|
impl<S: Encoder<E>, E> Encodable<S, E> for Ident {
|
|
|
|
fn encode(&self, s: &mut S) -> Result<(), E> {
|
|
|
|
s.emit_str(token::get_ident(*self).get())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<D:Decoder<E>, E> Decodable<D, E> for Ident {
|
|
|
|
fn decode(d: &mut D) -> Result<Ident, E> {
|
2014-05-14 23:16:44 -05:00
|
|
|
Ok(str_to_ident(try!(d.read_str()).as_slice()))
|
2014-03-18 12:58:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-18 06:12:07 -05:00
|
|
|
/// Function name (not all functions have names)
|
2013-09-01 20:45:37 -05:00
|
|
|
pub type FnIdent = Option<Ident>;
|
2010-08-18 11:00:10 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-02-11 18:33:31 -06:00
|
|
|
pub struct Lifetime {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub id: NodeId,
|
|
|
|
pub span: Span,
|
|
|
|
pub name: Name
|
2013-02-11 18:33:31 -06:00
|
|
|
}
|
|
|
|
|
2013-03-05 19:02:23 -06:00
|
|
|
// a "Path" is essentially Rust's notion of a name;
|
2014-05-29 19:45:07 -05:00
|
|
|
// for instance: std::cmp::PartialEq . It's represented
|
2013-03-05 19:02:23 -06:00
|
|
|
// as a sequence of identifiers, along with a bunch
|
|
|
|
// of supporting information.
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-03-26 19:00:35 -05:00
|
|
|
pub struct Path {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub span: Span,
|
2013-07-18 06:12:07 -05:00
|
|
|
/// A `::foo` path, is relative to the crate root rather than current
|
|
|
|
/// module (like paths in an import).
|
2014-03-27 17:39:48 -05:00
|
|
|
pub global: bool,
|
2013-08-07 11:47:28 -05:00
|
|
|
/// The segments in the path: the things separated by `::`.
|
2014-03-27 17:39:48 -05:00
|
|
|
pub segments: Vec<PathSegment> ,
|
2013-08-07 11:47:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A segment of a path: an identifier, an optional lifetime, and a set of
|
|
|
|
/// types.
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-08-07 11:47:28 -05:00
|
|
|
pub struct PathSegment {
|
|
|
|
/// The identifier portion of this path segment.
|
2014-03-27 17:39:48 -05:00
|
|
|
pub identifier: Ident,
|
2013-10-29 05:03:32 -05:00
|
|
|
/// The lifetime parameters for this path segment.
|
2014-03-27 17:39:48 -05:00
|
|
|
pub lifetimes: Vec<Lifetime>,
|
2013-08-07 11:47:28 -05:00
|
|
|
/// The type parameters for this path segment, if present.
|
2014-03-27 17:39:48 -05:00
|
|
|
pub types: OwnedSlice<P<Ty>>,
|
2013-01-13 12:48:09 -06:00
|
|
|
}
|
2010-10-04 19:25:52 -05:00
|
|
|
|
2013-11-26 23:02:25 -06:00
|
|
|
pub type CrateNum = u32;
|
2012-03-14 16:18:53 -05:00
|
|
|
|
2013-11-26 23:02:25 -06:00
|
|
|
pub type NodeId = u32;
|
2012-03-14 16:18:53 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, Eq, Ord, PartialOrd, PartialEq, Encodable, Decodable, Hash, Show)]
|
2013-09-01 20:45:37 -05:00
|
|
|
pub struct DefId {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub krate: CrateNum,
|
|
|
|
pub node: NodeId,
|
2013-01-13 13:05:40 -06:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2013-11-24 17:38:41 -06:00
|
|
|
/// Item definitions in the currently-compiled crate would have the CrateNum
|
|
|
|
/// LOCAL_CRATE in their DefId.
|
2013-07-27 03:25:59 -05:00
|
|
|
pub static LOCAL_CRATE: CrateNum = 0;
|
|
|
|
pub static CRATE_NODE_ID: NodeId = 0;
|
2010-10-18 18:15:25 -05:00
|
|
|
|
2013-09-06 21:11:55 -05:00
|
|
|
// When parsing and doing expansions, we initially give all AST nodes this AST
|
|
|
|
// node value. Then later, in the renumber pass, we renumber them to have
|
|
|
|
// small, positive ids.
|
|
|
|
pub static DUMMY_NODE_ID: NodeId = -1;
|
|
|
|
|
2012-10-17 00:14:59 -05:00
|
|
|
// The AST represents all type param bounds as types.
|
|
|
|
// typeck::collect::compute_bounds matches these against
|
|
|
|
// the "special" built-in traits (see middle::lang_items) and
|
2014-03-22 08:42:32 -05:00
|
|
|
// detects Copy, Send and Share.
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-02-14 23:50:03 -06:00
|
|
|
pub enum TyParamBound {
|
2014-01-09 07:05:33 -06:00
|
|
|
TraitTyParamBound(TraitRef),
|
2014-05-02 13:04:26 -05:00
|
|
|
StaticRegionTyParamBound,
|
2014-06-01 20:41:46 -05:00
|
|
|
UnboxedFnTyParamBound(UnboxedFnTy),
|
2014-05-02 13:04:26 -05:00
|
|
|
OtherRegionTyParamBound(Span) // FIXME -- just here until work for #5723 lands
|
2013-01-10 13:16:54 -06:00
|
|
|
}
|
2011-12-28 10:50:12 -06:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-02-14 23:50:03 -06:00
|
|
|
pub struct TyParam {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub ident: Ident,
|
|
|
|
pub id: NodeId,
|
2014-04-02 19:38:45 -05:00
|
|
|
pub sized: Sized,
|
2014-03-27 17:39:48 -05:00
|
|
|
pub bounds: OwnedSlice<TyParamBound>,
|
2014-04-02 19:53:57 -05:00
|
|
|
pub default: Option<P<Ty>>,
|
|
|
|
pub span: Span
|
2013-02-14 23:50:03 -06:00
|
|
|
}
|
|
|
|
|
2014-07-03 01:17:10 -05:00
|
|
|
/// Represents lifetimes and type parameters attached to a declaration
|
|
|
|
/// of a function, enum, trait, etc.
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-02-14 23:50:03 -06:00
|
|
|
pub struct Generics {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub lifetimes: Vec<Lifetime>,
|
|
|
|
pub ty_params: OwnedSlice<TyParam>,
|
2013-02-14 23:50:03 -06:00
|
|
|
}
|
|
|
|
|
2013-05-31 17:17:22 -05:00
|
|
|
impl Generics {
|
|
|
|
pub fn is_parameterized(&self) -> bool {
|
2013-03-06 11:27:23 -06:00
|
|
|
self.lifetimes.len() + self.ty_params.len() > 0
|
|
|
|
}
|
2013-05-31 17:17:22 -05:00
|
|
|
pub fn is_lt_parameterized(&self) -> bool {
|
2013-03-06 11:27:23 -06:00
|
|
|
self.lifetimes.len() > 0
|
|
|
|
}
|
2013-05-31 17:17:22 -05:00
|
|
|
pub fn is_type_parameterized(&self) -> bool {
|
2013-03-06 11:27:23 -06:00
|
|
|
self.ty_params.len() > 0
|
2013-02-14 23:50:03 -06:00
|
|
|
}
|
2013-01-13 13:15:14 -06:00
|
|
|
}
|
2010-11-24 20:01:20 -06:00
|
|
|
|
2013-07-19 06:51:37 -05:00
|
|
|
// The set of MetaItems that define the compilation environment of the crate,
|
2011-06-29 20:07:15 -05:00
|
|
|
// used to drive conditional compilation
|
2014-05-16 02:16:13 -05:00
|
|
|
pub type CrateConfig = Vec<Gc<MetaItem>>;
|
2010-08-18 11:00:10 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-07-19 00:38:55 -05:00
|
|
|
pub struct Crate {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub module: Mod,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub config: CrateConfig,
|
|
|
|
pub span: Span,
|
2013-01-14 21:06:59 -06:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
pub type MetaItem = Spanned<MetaItem_>;
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, Encodable, Decodable, Eq, Hash)]
|
2013-07-19 06:51:37 -05:00
|
|
|
pub enum MetaItem_ {
|
2014-01-08 12:35:15 -06:00
|
|
|
MetaWord(InternedString),
|
2014-05-16 02:16:13 -05:00
|
|
|
MetaList(InternedString, Vec<Gc<MetaItem>>),
|
2014-01-08 12:35:15 -06:00
|
|
|
MetaNameValue(InternedString, Lit),
|
2013-07-19 06:51:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// can't be derived because the MetaList requires an unordered comparison
|
2014-05-29 19:45:07 -05:00
|
|
|
impl PartialEq for MetaItem_ {
|
2013-07-19 06:51:37 -05:00
|
|
|
fn eq(&self, other: &MetaItem_) -> bool {
|
|
|
|
match *self {
|
|
|
|
MetaWord(ref ns) => match *other {
|
|
|
|
MetaWord(ref no) => (*ns) == (*no),
|
|
|
|
_ => false
|
|
|
|
},
|
|
|
|
MetaNameValue(ref ns, ref vs) => match *other {
|
|
|
|
MetaNameValue(ref no, ref vo) => {
|
|
|
|
(*ns) == (*no) && vs.node == vo.node
|
|
|
|
}
|
|
|
|
_ => false
|
|
|
|
},
|
|
|
|
MetaList(ref ns, ref miss) => match *other {
|
|
|
|
MetaList(ref no, ref miso) => {
|
|
|
|
ns == no &&
|
|
|
|
miss.iter().all(|mi| miso.iter().any(|x| x.node == mi.node))
|
|
|
|
}
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-21 16:23:16 -05:00
|
|
|
}
|
2010-12-30 10:21:37 -06:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-07-19 00:38:55 -05:00
|
|
|
pub struct Block {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub view_items: Vec<ViewItem>,
|
2014-05-16 02:16:13 -05:00
|
|
|
pub stmts: Vec<Gc<Stmt>>,
|
|
|
|
pub expr: Option<Gc<Expr>>,
|
2014-03-27 17:39:48 -05:00
|
|
|
pub id: NodeId,
|
|
|
|
pub rules: BlockCheckMode,
|
|
|
|
pub span: Span,
|
2013-01-14 21:35:08 -06:00
|
|
|
}
|
2010-08-18 11:00:10 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-09-01 20:45:37 -05:00
|
|
|
pub struct Pat {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub id: NodeId,
|
|
|
|
pub node: Pat_,
|
|
|
|
pub span: Span,
|
2013-01-14 22:52:28 -06:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-09-01 20:45:37 -05:00
|
|
|
pub struct FieldPat {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub ident: Ident,
|
2014-05-16 02:16:13 -05:00
|
|
|
pub pat: Gc<Pat>,
|
2013-01-14 22:52:28 -06:00
|
|
|
}
|
2011-07-11 07:13:20 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-09-01 20:45:37 -05:00
|
|
|
pub enum BindingMode {
|
|
|
|
BindByRef(Mutability),
|
2013-10-20 07:31:23 -05:00
|
|
|
BindByValue(Mutability),
|
2012-07-31 21:25:24 -05:00
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-09-01 20:45:37 -05:00
|
|
|
pub enum Pat_ {
|
|
|
|
PatWild,
|
2013-11-07 21:25:39 -06:00
|
|
|
PatWildMulti,
|
2014-01-27 06:18:36 -06:00
|
|
|
// A PatIdent may either be a new bound variable,
|
2014-07-03 01:17:10 -05:00
|
|
|
// or a nullary enum (in which case the third field
|
2012-08-20 14:23:37 -05:00
|
|
|
// is None).
|
2012-01-19 16:24:03 -06:00
|
|
|
// In the nullary enum case, the parser can't determine
|
2012-01-14 18:05:07 -06:00
|
|
|
// which it is. The resolver determines this, and
|
2013-07-27 03:25:59 -05:00
|
|
|
// records this pattern's NodeId in an auxiliary
|
2014-06-30 20:02:14 -05:00
|
|
|
// set (of "PatIdents that refer to nullary enums")
|
|
|
|
PatIdent(BindingMode, SpannedIdent, Option<Gc<Pat>>),
|
2014-05-16 02:16:13 -05:00
|
|
|
PatEnum(Path, Option<Vec<Gc<Pat>>>), /* "none" means a * pattern where
|
2014-01-27 06:18:36 -06:00
|
|
|
* we don't bind the fields to names */
|
2014-05-16 02:16:13 -05:00
|
|
|
PatStruct(Path, Vec<FieldPat>, bool),
|
|
|
|
PatTup(Vec<Gc<Pat>>),
|
|
|
|
PatBox(Gc<Pat>),
|
|
|
|
PatRegion(Gc<Pat>), // reference pattern
|
|
|
|
PatLit(Gc<Expr>),
|
|
|
|
PatRange(Gc<Expr>, Gc<Expr>),
|
2013-02-26 12:58:46 -06:00
|
|
|
// [a, b, ..i, y, z] is represented as
|
2014-01-27 06:18:36 -06:00
|
|
|
// PatVec(~[a, b], Some(i), ~[y, z])
|
2014-05-16 02:16:13 -05:00
|
|
|
PatVec(Vec<Gc<Pat>>, Option<Gc<Pat>>, Vec<Gc<Pat>>),
|
2014-05-19 15:29:41 -05:00
|
|
|
PatMac(Mac),
|
2010-11-24 16:42:01 -06:00
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
2013-09-01 20:45:37 -05:00
|
|
|
pub enum Mutability {
|
|
|
|
MutMutable,
|
|
|
|
MutImmutable,
|
2013-08-02 23:41:06 -05:00
|
|
|
}
|
2010-11-29 16:18:26 -06:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-09-01 20:45:37 -05:00
|
|
|
pub enum ExprVstore {
|
|
|
|
ExprVstoreUniq, // ~[1,2,3,4]
|
|
|
|
ExprVstoreSlice, // &[1,2,3,4]
|
|
|
|
ExprVstoreMutSlice, // &mut [1,2,3,4]
|
2012-09-11 23:25:01 -05:00
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-09-01 20:45:37 -05:00
|
|
|
pub enum BinOp {
|
|
|
|
BiAdd,
|
|
|
|
BiSub,
|
|
|
|
BiMul,
|
|
|
|
BiDiv,
|
|
|
|
BiRem,
|
|
|
|
BiAnd,
|
|
|
|
BiOr,
|
|
|
|
BiBitXor,
|
|
|
|
BiBitAnd,
|
|
|
|
BiBitOr,
|
|
|
|
BiShl,
|
|
|
|
BiShr,
|
|
|
|
BiEq,
|
|
|
|
BiLt,
|
|
|
|
BiLe,
|
|
|
|
BiNe,
|
|
|
|
BiGe,
|
|
|
|
BiGt,
|
2010-09-27 20:25:02 -05:00
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-09-01 20:45:37 -05:00
|
|
|
pub enum UnOp {
|
2013-12-31 14:55:39 -06:00
|
|
|
UnBox,
|
2013-09-01 20:45:37 -05:00
|
|
|
UnUniq,
|
|
|
|
UnDeref,
|
|
|
|
UnNot,
|
|
|
|
UnNeg
|
2012-09-07 20:53:14 -05:00
|
|
|
}
|
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
pub type Stmt = Spanned<Stmt_>;
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-09-01 20:45:37 -05:00
|
|
|
pub enum Stmt_ {
|
2013-05-07 11:38:48 -05:00
|
|
|
// could be an item or a local (let) binding:
|
2014-05-16 02:16:13 -05:00
|
|
|
StmtDecl(Gc<Decl>, NodeId),
|
2012-07-03 19:30:25 -05:00
|
|
|
|
|
|
|
// expr without trailing semi-colon (must have unit type):
|
2014-05-16 02:16:13 -05:00
|
|
|
StmtExpr(Gc<Expr>, NodeId),
|
2012-07-03 19:30:25 -05:00
|
|
|
|
|
|
|
// expr with trailing semi-colon (may have any type):
|
2014-05-16 02:16:13 -05:00
|
|
|
StmtSemi(Gc<Expr>, NodeId),
|
2012-11-12 22:06:55 -06:00
|
|
|
|
2012-11-21 12:37:43 -06:00
|
|
|
// bool: is there a trailing sem-colon?
|
2014-01-09 07:05:33 -06:00
|
|
|
StmtMac(Mac, bool),
|
2010-09-09 17:59:29 -05:00
|
|
|
}
|
|
|
|
|
2014-05-26 07:00:08 -05:00
|
|
|
/// Where a local declaration came from: either a true `let ... =
|
|
|
|
/// ...;`, or one desugared from the pattern of a for loop.
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-05-26 07:00:08 -05:00
|
|
|
pub enum LocalSource {
|
|
|
|
LocalLet,
|
|
|
|
LocalFor,
|
|
|
|
}
|
|
|
|
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (pending discussion of #1697, #2178...): local should really be
|
|
|
|
// a refinement on pat.
|
2013-11-24 17:38:41 -06:00
|
|
|
/// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-07-19 00:38:55 -05:00
|
|
|
pub struct Local {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub ty: P<Ty>,
|
2014-05-16 02:16:13 -05:00
|
|
|
pub pat: Gc<Pat>,
|
|
|
|
pub init: Option<Gc<Expr>>,
|
2014-03-27 17:39:48 -05:00
|
|
|
pub id: NodeId,
|
|
|
|
pub span: Span,
|
2014-05-26 07:00:08 -05:00
|
|
|
pub source: LocalSource,
|
2013-01-14 22:52:28 -06:00
|
|
|
}
|
2011-03-24 20:04:29 -05:00
|
|
|
|
2013-09-01 20:45:37 -05:00
|
|
|
pub type Decl = Spanned<Decl_>;
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-09-01 20:45:37 -05:00
|
|
|
pub enum Decl_ {
|
2013-05-07 11:38:48 -05:00
|
|
|
// a local (let) binding:
|
2014-05-16 02:16:13 -05:00
|
|
|
DeclLocal(Gc<Local>),
|
2013-05-07 11:38:48 -05:00
|
|
|
// an item binding:
|
2014-05-16 02:16:13 -05:00
|
|
|
DeclItem(Gc<Item>),
|
2013-06-04 23:43:41 -05:00
|
|
|
}
|
2010-09-09 17:59:29 -05:00
|
|
|
|
2014-06-25 17:20:01 -05:00
|
|
|
/// represents one arm of a 'match'
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-09-01 20:45:37 -05:00
|
|
|
pub struct Arm {
|
2014-04-22 23:54:48 -05:00
|
|
|
pub attrs: Vec<Attribute>,
|
2014-05-16 02:16:13 -05:00
|
|
|
pub pats: Vec<Gc<Pat>>,
|
|
|
|
pub guard: Option<Gc<Expr>>,
|
|
|
|
pub body: Gc<Expr>,
|
2013-01-14 22:52:28 -06:00
|
|
|
}
|
2010-11-24 17:45:59 -06:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-07-19 09:24:22 -05:00
|
|
|
pub struct Field {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub ident: SpannedIdent,
|
2014-05-16 02:16:13 -05:00
|
|
|
pub expr: Gc<Expr>,
|
2014-03-27 17:39:48 -05:00
|
|
|
pub span: Span,
|
2013-01-14 23:36:27 -06:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2013-10-28 21:22:42 -05:00
|
|
|
pub type SpannedIdent = Spanned<Ident>;
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-07-27 03:25:59 -05:00
|
|
|
pub enum BlockCheckMode {
|
|
|
|
DefaultBlock,
|
2013-09-05 22:50:10 -05:00
|
|
|
UnsafeBlock(UnsafeSource),
|
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-09-05 22:50:10 -05:00
|
|
|
pub enum UnsafeSource {
|
|
|
|
CompilerGenerated,
|
|
|
|
UserProvided,
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2011-10-06 18:42:27 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-09-01 20:45:37 -05:00
|
|
|
pub struct Expr {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub id: NodeId,
|
|
|
|
pub node: Expr_,
|
|
|
|
pub span: Span,
|
2013-01-15 15:51:43 -06:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-09-01 20:45:37 -05:00
|
|
|
pub enum Expr_ {
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprVstore(Gc<Expr>, ExprVstore),
|
2013-12-17 18:46:18 -06:00
|
|
|
// First expr is the place; second expr is the value.
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprBox(Gc<Expr>, Gc<Expr>),
|
|
|
|
ExprVec(Vec<Gc<Expr>>),
|
|
|
|
ExprCall(Gc<Expr>, Vec<Gc<Expr>>),
|
|
|
|
ExprMethodCall(SpannedIdent, Vec<P<Ty>>, Vec<Gc<Expr>>),
|
|
|
|
ExprTup(Vec<Gc<Expr>>),
|
|
|
|
ExprBinary(BinOp, Gc<Expr>, Gc<Expr>),
|
|
|
|
ExprUnary(UnOp, Gc<Expr>),
|
|
|
|
ExprLit(Gc<Lit>),
|
|
|
|
ExprCast(Gc<Expr>, P<Ty>),
|
|
|
|
ExprIf(Gc<Expr>, P<Block>, Option<Gc<Expr>>),
|
|
|
|
ExprWhile(Gc<Expr>, P<Block>),
|
2014-07-04 14:05:43 -05:00
|
|
|
// FIXME #6993: change to Option<Name> ... or not, if these are hygienic.
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprForLoop(Gc<Pat>, Gc<Expr>, P<Block>, Option<Ident>),
|
2013-10-03 04:53:46 -05:00
|
|
|
// Conditionless loop (can be exited with break, cont, or ret)
|
2014-07-04 14:05:43 -05:00
|
|
|
// FIXME #6993: change to Option<Name> ... or not, if these are hygienic.
|
2013-11-30 16:00:39 -06:00
|
|
|
ExprLoop(P<Block>, Option<Ident>),
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprMatch(Gc<Expr>, Vec<Arm>),
|
2014-01-09 07:05:33 -06:00
|
|
|
ExprFnBlock(P<FnDecl>, P<Block>),
|
|
|
|
ExprProc(P<FnDecl>, P<Block>),
|
2013-11-30 16:00:39 -06:00
|
|
|
ExprBlock(P<Block>),
|
2013-09-01 20:45:37 -05:00
|
|
|
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprAssign(Gc<Expr>, Gc<Expr>),
|
|
|
|
ExprAssignOp(BinOp, Gc<Expr>, Gc<Expr>),
|
2014-06-13 16:56:42 -05:00
|
|
|
ExprField(Gc<Expr>, SpannedIdent, Vec<P<Ty>>),
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprIndex(Gc<Expr>, Gc<Expr>),
|
2013-11-24 17:38:41 -06:00
|
|
|
|
2014-07-04 14:05:43 -05:00
|
|
|
/// Variable reference, possibly containing `::` and/or
|
|
|
|
/// type parameters, e.g. foo::bar::<baz>
|
2013-09-01 20:45:37 -05:00
|
|
|
ExprPath(Path),
|
2013-05-10 17:15:06 -05:00
|
|
|
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprAddrOf(Mutability, Gc<Expr>),
|
2014-02-15 02:54:32 -06:00
|
|
|
ExprBreak(Option<Ident>),
|
|
|
|
ExprAgain(Option<Ident>),
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprRet(Option<Gc<Expr>>),
|
2013-08-28 01:12:05 -05:00
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
ExprInlineAsm(InlineAsm),
|
2011-08-19 17:16:48 -05:00
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
ExprMac(Mac),
|
2012-07-23 18:39:18 -05:00
|
|
|
|
|
|
|
// A struct literal expression.
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprStruct(Path, Vec<Field> , Option<Gc<Expr>> /* base */),
|
2012-08-03 20:01:30 -05:00
|
|
|
|
|
|
|
// A vector literal constructed from one repeated element.
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprRepeat(Gc<Expr> /* element */, Gc<Expr> /* count */),
|
2012-10-27 19:14:09 -05:00
|
|
|
|
|
|
|
// No-op: used solely so we can pretty-print faithfully
|
2014-05-16 02:16:13 -05:00
|
|
|
ExprParen(Gc<Expr>)
|
2011-07-08 18:35:09 -05:00
|
|
|
}
|
|
|
|
|
2012-07-27 21:14:46 -05:00
|
|
|
// When the main rust parser encounters a syntax-extension invocation, it
|
|
|
|
// parses the arguments to the invocation as a token-tree. This is a very
|
|
|
|
// loose structure, such that all sorts of different AST-fragments can
|
|
|
|
// be passed to syntax extensions using a uniform type.
|
|
|
|
//
|
|
|
|
// If the syntax extension is an MBE macro, it will attempt to match its
|
|
|
|
// LHS "matchers" against the provided token tree, and if it finds a
|
|
|
|
// match, will transcribe the RHS token tree, splicing in any captured
|
2014-01-09 07:05:33 -06:00
|
|
|
// macro_parser::matched_nonterminals into the TTNonterminals it finds.
|
2012-07-27 21:14:46 -05:00
|
|
|
//
|
2014-01-09 07:05:33 -06:00
|
|
|
// The RHS of an MBE macro is the only place a TTNonterminal or TTSeq
|
2012-07-27 21:14:46 -05:00
|
|
|
// makes any real sense. You could write them elsewhere but nothing
|
|
|
|
// else knows what to do with them, so you'll probably get a syntax
|
|
|
|
// error.
|
|
|
|
//
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2012-06-27 17:29:35 -05:00
|
|
|
#[doc="For macro invocations; parsing is delegated to the macro"]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum TokenTree {
|
2013-02-04 15:15:17 -06:00
|
|
|
// a single token
|
2014-01-09 07:05:33 -06:00
|
|
|
TTTok(Span, ::parse::token::Token),
|
2013-02-04 15:15:17 -06:00
|
|
|
// a delimited sequence (the delimiters appear as the first
|
|
|
|
// and last elements of the vector)
|
2014-03-27 09:40:35 -05:00
|
|
|
// FIXME(eddyb) #6308 Use Rc<[TokenTree]> after DST.
|
|
|
|
TTDelim(Rc<Vec<TokenTree>>),
|
2013-06-06 13:14:29 -05:00
|
|
|
|
2013-02-04 15:15:17 -06:00
|
|
|
// These only make sense for right-hand-sides of MBE macros:
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
// a kleene-style repetition sequence with a span, a TTForest,
|
2013-06-25 13:40:51 -05:00
|
|
|
// an optional separator, and a boolean where true indicates
|
2013-11-28 14:22:53 -06:00
|
|
|
// zero or more (..), and false indicates one or more (+).
|
2014-03-27 09:40:35 -05:00
|
|
|
// FIXME(eddyb) #6308 Use Rc<[TokenTree]> after DST.
|
|
|
|
TTSeq(Span, Rc<Vec<TokenTree>>, Option<::parse::token::Token>, bool),
|
2013-02-04 15:15:17 -06:00
|
|
|
|
|
|
|
// a syntactic variable that will be filled in by macro expansion.
|
2014-01-09 07:05:33 -06:00
|
|
|
TTNonterminal(Span, Ident)
|
|
|
|
}
|
|
|
|
|
2012-07-27 19:42:32 -05:00
|
|
|
//
|
|
|
|
// Matchers are nodes defined-by and recognized-by the main rust parser and
|
2012-07-27 21:14:46 -05:00
|
|
|
// language, but they're only ever found inside syntax-extension invocations;
|
|
|
|
// indeed, the only thing that ever _activates_ the rules in the rust parser
|
2012-07-27 21:19:40 -05:00
|
|
|
// for parsing a matcher is a matcher looking for the 'matchers' nonterminal
|
2012-07-27 21:14:46 -05:00
|
|
|
// itself. Matchers represent a small sub-language for pattern-matching
|
|
|
|
// token-trees, and are thus primarily used by the macro-defining extension
|
|
|
|
// itself.
|
2012-07-27 19:42:32 -05:00
|
|
|
//
|
2014-01-09 07:05:33 -06:00
|
|
|
// MatchTok
|
|
|
|
// --------
|
2012-07-27 19:42:32 -05:00
|
|
|
//
|
2012-07-27 21:14:46 -05:00
|
|
|
// A matcher that matches a single token, denoted by the token itself. So
|
|
|
|
// long as there's no $ involved.
|
2012-07-27 19:42:32 -05:00
|
|
|
//
|
2012-07-27 21:14:46 -05:00
|
|
|
//
|
2014-01-09 07:05:33 -06:00
|
|
|
// MatchSeq
|
|
|
|
// --------
|
2012-07-27 21:14:46 -05:00
|
|
|
//
|
|
|
|
// A matcher that matches a sequence of sub-matchers, denoted various
|
|
|
|
// possible ways:
|
2012-07-27 19:42:32 -05:00
|
|
|
//
|
|
|
|
// $(M)* zero or more Ms
|
|
|
|
// $(M)+ one or more Ms
|
|
|
|
// $(M),+ one or more comma-separated Ms
|
|
|
|
// $(A B C);* zero or more semi-separated 'A B C' seqs
|
|
|
|
//
|
|
|
|
//
|
2014-01-09 07:05:33 -06:00
|
|
|
// MatchNonterminal
|
2012-07-27 21:14:46 -05:00
|
|
|
// -----------------
|
|
|
|
//
|
|
|
|
// A matcher that matches one of a few interesting named rust
|
|
|
|
// nonterminals, such as types, expressions, items, or raw token-trees. A
|
|
|
|
// black-box matcher on expr, for example, binds an expr to a given ident,
|
|
|
|
// and that ident can re-occur as an interpolation in the RHS of a
|
|
|
|
// macro-by-example rule. For example:
|
2012-07-27 19:42:32 -05:00
|
|
|
//
|
|
|
|
// $foo:expr => 1 + $foo // interpolate an expr
|
|
|
|
// $foo:tt => $foo // interpolate a token-tree
|
|
|
|
// $foo:tt => bar! $foo // only other valid interpolation
|
2012-07-27 20:06:24 -05:00
|
|
|
// // is in arg position for another
|
|
|
|
// // macro
|
2012-07-27 19:42:32 -05:00
|
|
|
//
|
|
|
|
// As a final, horrifying aside, note that macro-by-example's input is
|
|
|
|
// also matched by one of these matchers. Holy self-referential! It is matched
|
2014-01-30 12:29:35 -06:00
|
|
|
// by a MatchSeq, specifically this one:
|
2012-07-27 19:42:32 -05:00
|
|
|
//
|
2012-07-27 21:19:40 -05:00
|
|
|
// $( $lhs:matchers => $rhs:tt );+
|
2012-07-27 19:42:32 -05:00
|
|
|
//
|
|
|
|
// If you understand that, you have closed to loop and understand the whole
|
|
|
|
// macro system. Congratulations.
|
|
|
|
//
|
2014-01-09 07:05:33 -06:00
|
|
|
pub type Matcher = Spanned<Matcher_>;
|
2012-07-27 21:14:46 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum Matcher_ {
|
2012-07-27 21:14:46 -05:00
|
|
|
// match one token
|
2014-01-09 07:05:33 -06:00
|
|
|
MatchTok(::parse::token::Token),
|
2012-07-27 21:14:46 -05:00
|
|
|
// match repetitions of a sequence: body, separator, zero ok?,
|
|
|
|
// lo, hi position-in-match-array used:
|
2014-02-28 15:09:09 -06:00
|
|
|
MatchSeq(Vec<Matcher> , Option<::parse::token::Token>, bool, uint, uint),
|
2012-07-27 21:14:46 -05:00
|
|
|
// parse a Rust NT: name to bind, name of NT, position in match array:
|
2014-01-09 07:05:33 -06:00
|
|
|
MatchNonterminal(Ident, Ident, uint)
|
2012-06-12 12:59:50 -05:00
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
pub type Mac = Spanned<Mac_>;
|
2011-07-08 18:35:09 -05:00
|
|
|
|
2013-06-06 13:14:29 -05:00
|
|
|
// represents a macro invocation. The Path indicates which macro
|
|
|
|
// is being invoked, and the vector of token-trees contains the source
|
|
|
|
// of the macro invocation.
|
|
|
|
// There's only one flavor, now, so this could presumably be simplified.
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum Mac_ {
|
2014-02-28 15:09:09 -06:00
|
|
|
MacInvocTT(Path, Vec<TokenTree> , SyntaxContext), // new macro-invocation
|
2010-09-09 17:59:29 -05:00
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-10-07 19:49:10 -05:00
|
|
|
pub enum StrStyle {
|
|
|
|
CookedStr,
|
|
|
|
RawStr(uint)
|
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
pub type Lit = Spanned<Lit_>;
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum Lit_ {
|
2014-01-10 16:02:36 -06:00
|
|
|
LitStr(InternedString, StrStyle),
|
2014-02-28 15:09:09 -06:00
|
|
|
LitBinary(Rc<Vec<u8> >),
|
2014-06-06 10:04:04 -05:00
|
|
|
LitByte(u8),
|
2014-05-01 08:35:06 -05:00
|
|
|
LitChar(char),
|
2014-01-09 07:05:33 -06:00
|
|
|
LitInt(i64, IntTy),
|
|
|
|
LitUint(u64, UintTy),
|
|
|
|
LitIntUnsuffixed(i64),
|
2014-01-15 19:15:39 -06:00
|
|
|
LitFloat(InternedString, FloatTy),
|
|
|
|
LitFloatUnsuffixed(InternedString),
|
2014-01-09 07:05:33 -06:00
|
|
|
LitNil,
|
|
|
|
LitBool(bool),
|
2010-09-09 17:59:29 -05:00
|
|
|
}
|
|
|
|
|
2010-11-03 18:43:12 -05:00
|
|
|
// NB: If you change this, you'll probably want to change the corresponding
|
2010-12-21 14:13:51 -06:00
|
|
|
// type structure in middle/ty.rs as well.
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct MutTy {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub ty: P<Ty>,
|
|
|
|
pub mutbl: Mutability,
|
2013-01-14 23:36:27 -06:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-07-27 03:25:59 -05:00
|
|
|
pub struct TypeField {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub ident: Ident,
|
|
|
|
pub mt: MutTy,
|
|
|
|
pub span: Span,
|
2013-01-15 17:03:49 -06:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2014-07-04 14:05:43 -05:00
|
|
|
/// Represents a required method in a trait declaration,
|
|
|
|
/// one without a default implementation
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-07-27 03:25:59 -05:00
|
|
|
pub struct TypeMethod {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub ident: Ident,
|
|
|
|
pub attrs: Vec<Attribute>,
|
2014-04-06 20:04:40 -05:00
|
|
|
pub fn_style: FnStyle,
|
2014-03-27 17:39:48 -05:00
|
|
|
pub decl: P<FnDecl>,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub explicit_self: ExplicitSelf,
|
|
|
|
pub id: NodeId,
|
|
|
|
pub span: Span,
|
2014-05-22 12:49:26 -05:00
|
|
|
pub vis: Visibility,
|
2013-01-15 17:03:49 -06:00
|
|
|
}
|
2011-06-03 17:26:03 -05:00
|
|
|
|
2014-07-04 14:05:43 -05:00
|
|
|
/// Represents a method declaration in a trait declaration, possibly
|
|
|
|
/// including a default implementation
|
2012-07-10 15:44:20 -05:00
|
|
|
// A trait method is either required (meaning it doesn't have an
|
|
|
|
// implementation, just a signature) or provided (meaning it has a default
|
|
|
|
// implementation).
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum TraitMethod {
|
|
|
|
Required(TypeMethod),
|
2014-05-16 02:16:13 -05:00
|
|
|
Provided(Gc<Method>),
|
2012-07-10 15:44:20 -05:00
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum IntTy {
|
|
|
|
TyI,
|
|
|
|
TyI8,
|
|
|
|
TyI16,
|
|
|
|
TyI32,
|
|
|
|
TyI64,
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2011-12-07 14:06:12 -06:00
|
|
|
|
2014-02-19 20:56:33 -06:00
|
|
|
impl fmt::Show for IntTy {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2014-04-21 16:58:52 -05:00
|
|
|
write!(f, "{}", ast_util::int_ty_to_str(*self, None))
|
2013-01-22 09:01:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum UintTy {
|
|
|
|
TyU,
|
|
|
|
TyU8,
|
|
|
|
TyU16,
|
|
|
|
TyU32,
|
|
|
|
TyU64,
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2011-12-07 14:06:12 -06:00
|
|
|
|
2014-02-19 20:56:33 -06:00
|
|
|
impl fmt::Show for UintTy {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2014-04-21 16:58:52 -05:00
|
|
|
write!(f, "{}", ast_util::uint_ty_to_str(*self, None))
|
2013-01-22 09:01:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum FloatTy {
|
|
|
|
TyF32,
|
|
|
|
TyF64,
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2011-07-05 04:48:19 -05:00
|
|
|
|
2014-02-19 20:56:33 -06:00
|
|
|
impl fmt::Show for FloatTy {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2014-05-10 16:05:06 -05:00
|
|
|
write!(f, "{}", ast_util::float_ty_to_str(*self))
|
2013-01-22 09:01:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-29 19:45:07 -05:00
|
|
|
// NB PartialEq method appears below.
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-01-29 15:54:06 -06:00
|
|
|
pub struct Ty {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub id: NodeId,
|
|
|
|
pub node: Ty_,
|
|
|
|
pub span: Span,
|
2013-01-15 16:59:39 -06:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2012-02-06 08:29:56 -06:00
|
|
|
// Not represented directly in the AST, referred to by name through a ty_path.
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum PrimTy {
|
|
|
|
TyInt(IntTy),
|
|
|
|
TyUint(UintTy),
|
|
|
|
TyFloat(FloatTy),
|
|
|
|
TyStr,
|
|
|
|
TyBool,
|
|
|
|
TyChar
|
2012-02-06 08:29:56 -06:00
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-01-29 15:54:06 -06:00
|
|
|
pub enum Onceness {
|
2012-11-02 15:33:51 -05:00
|
|
|
Once,
|
|
|
|
Many
|
|
|
|
}
|
|
|
|
|
2014-02-19 20:56:33 -06:00
|
|
|
impl fmt::Show for Onceness {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2013-02-03 22:47:26 -06:00
|
|
|
match *self {
|
2014-02-19 20:56:33 -06:00
|
|
|
Once => "once".fmt(f),
|
|
|
|
Many => "many".fmt(f),
|
2012-11-14 20:59:30 -06:00
|
|
|
}
|
|
|
|
}
|
2013-01-08 16:00:45 -06:00
|
|
|
}
|
|
|
|
|
2014-07-04 14:05:43 -05:00
|
|
|
/// Represents the type of a closure
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct ClosureTy {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub lifetimes: Vec<Lifetime>,
|
2014-04-06 20:04:40 -05:00
|
|
|
pub fn_style: FnStyle,
|
2014-03-27 17:39:48 -05:00
|
|
|
pub onceness: Onceness,
|
|
|
|
pub decl: P<FnDecl>,
|
2013-06-20 17:23:25 -05:00
|
|
|
// Optional optvec distinguishes between "fn()" and "fn:()" so we can
|
|
|
|
// implement issue #7264. None means "fn()", which means infer a default
|
|
|
|
// bound based on pointer sigil during typeck. Some(Empty) means "fn:()",
|
|
|
|
// which means use no bounds (e.g., not even Owned on a ~fn()).
|
2014-03-27 17:39:48 -05:00
|
|
|
pub bounds: Option<OwnedSlice<TyParamBound>>,
|
2013-01-31 19:12:29 -06:00
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct BareFnTy {
|
2014-04-06 20:04:40 -05:00
|
|
|
pub fn_style: FnStyle,
|
2014-04-02 03:19:41 -05:00
|
|
|
pub abi: Abi,
|
2014-03-27 17:39:48 -05:00
|
|
|
pub lifetimes: Vec<Lifetime>,
|
|
|
|
pub decl: P<FnDecl>
|
2012-11-04 22:41:00 -06:00
|
|
|
}
|
|
|
|
|
2014-06-01 20:41:46 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
|
|
|
pub struct UnboxedFnTy {
|
|
|
|
pub decl: P<FnDecl>,
|
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum Ty_ {
|
|
|
|
TyNil,
|
|
|
|
TyBot, /* bottom type */
|
|
|
|
TyBox(P<Ty>),
|
|
|
|
TyUniq(P<Ty>),
|
|
|
|
TyVec(P<Ty>),
|
2014-05-16 02:16:13 -05:00
|
|
|
TyFixedLengthVec(P<Ty>, Gc<Expr>),
|
2014-01-09 07:05:33 -06:00
|
|
|
TyPtr(MutTy),
|
|
|
|
TyRptr(Option<Lifetime>, MutTy),
|
2014-05-16 02:16:13 -05:00
|
|
|
TyClosure(Gc<ClosureTy>, Option<Lifetime>),
|
|
|
|
TyProc(Gc<ClosureTy>),
|
|
|
|
TyBareFn(Gc<BareFnTy>),
|
|
|
|
TyUnboxedFn(Gc<UnboxedFnTy>),
|
2014-02-28 15:09:09 -06:00
|
|
|
TyTup(Vec<P<Ty>> ),
|
2014-03-19 09:52:37 -05:00
|
|
|
TyPath(Path, Option<OwnedSlice<TyParamBound>>, NodeId), // for #7264; see above
|
2014-06-11 14:14:38 -05:00
|
|
|
// No-op; kept solely so that we can pretty-print faithfully
|
|
|
|
TyParen(P<Ty>),
|
2014-05-16 02:16:13 -05:00
|
|
|
TyTypeof(Gc<Expr>),
|
2014-01-27 06:18:36 -06:00
|
|
|
// TyInfer means the type should be inferred instead of it having been
|
2014-03-10 18:17:46 -05:00
|
|
|
// specified. This can appear anywhere in a type.
|
2014-01-09 07:05:33 -06:00
|
|
|
TyInfer,
|
2010-09-09 17:59:29 -05:00
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum AsmDialect {
|
|
|
|
AsmAtt,
|
|
|
|
AsmIntel
|
2013-03-27 16:42:19 -05:00
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct InlineAsm {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub asm: InternedString,
|
|
|
|
pub asm_str_style: StrStyle,
|
|
|
|
pub clobbers: InternedString,
|
2014-05-16 02:16:13 -05:00
|
|
|
pub inputs: Vec<(InternedString, Gc<Expr>)>,
|
|
|
|
pub outputs: Vec<(InternedString, Gc<Expr>)>,
|
2014-03-27 17:39:48 -05:00
|
|
|
pub volatile: bool,
|
|
|
|
pub alignstack: bool,
|
|
|
|
pub dialect: AsmDialect
|
2013-03-27 15:42:21 -05:00
|
|
|
}
|
|
|
|
|
2014-07-04 14:05:43 -05:00
|
|
|
/// represents an argument in a function header
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct Arg {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub ty: P<Ty>,
|
2014-05-16 02:16:13 -05:00
|
|
|
pub pat: Gc<Pat>,
|
2014-03-27 17:39:48 -05:00
|
|
|
pub id: NodeId,
|
2013-01-15 18:05:20 -06:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2014-01-27 06:18:36 -06:00
|
|
|
impl Arg {
|
|
|
|
pub fn new_self(span: Span, mutability: Mutability) -> Arg {
|
2014-06-30 20:02:14 -05:00
|
|
|
let path = Spanned{span:span,node:special_idents::self_};
|
2014-01-27 06:18:36 -06:00
|
|
|
Arg {
|
|
|
|
// HACK(eddyb) fake type for the self argument.
|
|
|
|
ty: P(Ty {
|
|
|
|
id: DUMMY_NODE_ID,
|
|
|
|
node: TyInfer,
|
|
|
|
span: DUMMY_SP,
|
|
|
|
}),
|
2014-05-16 02:16:13 -05:00
|
|
|
pat: box(GC) Pat {
|
2014-01-27 06:18:36 -06:00
|
|
|
id: DUMMY_NODE_ID,
|
|
|
|
node: PatIdent(BindByValue(mutability), path, None),
|
|
|
|
span: span
|
|
|
|
},
|
|
|
|
id: DUMMY_NODE_ID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-04 14:05:43 -05:00
|
|
|
/// represents the header (not the body) of a function declaration
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct FnDecl {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub inputs: Vec<Arg>,
|
|
|
|
pub output: P<Ty>,
|
|
|
|
pub cf: RetStyle,
|
|
|
|
pub variadic: bool
|
2013-01-15 18:05:20 -06:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-04-06 20:04:40 -05:00
|
|
|
pub enum FnStyle {
|
2014-01-09 07:05:33 -06:00
|
|
|
UnsafeFn, // declared with "unsafe fn"
|
2014-04-06 20:04:40 -05:00
|
|
|
NormalFn, // declared with "fn"
|
2011-05-04 13:28:13 -05:00
|
|
|
}
|
|
|
|
|
2014-04-06 20:04:40 -05:00
|
|
|
impl fmt::Show for FnStyle {
|
2014-02-19 20:56:33 -06:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2013-02-03 22:47:26 -06:00
|
|
|
match *self {
|
2014-04-06 20:04:40 -05:00
|
|
|
NormalFn => "normal".fmt(f),
|
2014-02-19 20:56:33 -06:00
|
|
|
UnsafeFn => "unsafe".fmt(f),
|
2013-01-08 16:00:45 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum RetStyle {
|
|
|
|
NoReturn, // functions with return type _|_ that always
|
2011-05-14 21:02:30 -05:00
|
|
|
// raise an error or exit (i.e. never return to the caller)
|
2014-01-09 07:05:33 -06:00
|
|
|
Return, // everything else
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum ExplicitSelf_ {
|
|
|
|
SelfStatic, // no self
|
2014-01-27 06:18:36 -06:00
|
|
|
SelfValue, // `self`
|
2014-01-11 18:25:51 -06:00
|
|
|
SelfRegion(Option<Lifetime>, Mutability), // `&'lt self`, `&'lt mut self`
|
2014-01-27 06:18:36 -06:00
|
|
|
SelfUniq // `~self`
|
2012-07-30 18:33:02 -05:00
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
pub type ExplicitSelf = Spanned<ExplicitSelf_>;
|
2012-07-30 18:33:02 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct Method {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub ident: Ident,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub explicit_self: ExplicitSelf,
|
2014-04-06 20:04:40 -05:00
|
|
|
pub fn_style: FnStyle,
|
2014-03-27 17:39:48 -05:00
|
|
|
pub decl: P<FnDecl>,
|
|
|
|
pub body: P<Block>,
|
|
|
|
pub id: NodeId,
|
|
|
|
pub span: Span,
|
|
|
|
pub vis: Visibility,
|
2013-01-15 18:05:20 -06:00
|
|
|
}
|
2010-12-14 17:32:13 -06:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct Mod {
|
2014-04-26 15:05:45 -05:00
|
|
|
/// A span from the first token past `{` to the last token until `}`.
|
|
|
|
/// For `mod foo;`, the inner span ranges from the first token
|
|
|
|
/// to the last token in the external file.
|
|
|
|
pub inner: Span,
|
|
|
|
pub view_items: Vec<ViewItem>,
|
2014-05-16 02:16:13 -05:00
|
|
|
pub items: Vec<Gc<Item>>,
|
2013-01-15 18:05:20 -06:00
|
|
|
}
|
2010-08-18 11:00:10 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct ForeignMod {
|
2014-04-02 03:19:41 -05:00
|
|
|
pub abi: Abi,
|
2014-03-27 17:39:48 -05:00
|
|
|
pub view_items: Vec<ViewItem>,
|
2014-05-16 02:16:13 -05:00
|
|
|
pub items: Vec<Gc<ForeignItem>>,
|
2013-01-15 18:05:20 -06:00
|
|
|
}
|
2011-02-01 12:40:04 -06:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct VariantArg {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub ty: P<Ty>,
|
|
|
|
pub id: NodeId,
|
2013-01-15 18:05:20 -06:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum VariantKind {
|
2014-03-27 17:39:48 -05:00
|
|
|
TupleVariantKind(Vec<VariantArg>),
|
2014-05-16 02:16:13 -05:00
|
|
|
StructVariantKind(Gc<StructDef>),
|
2012-08-07 16:24:04 -05:00
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct EnumDef {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub variants: Vec<P<Variant>>,
|
2013-01-15 18:05:20 -06:00
|
|
|
}
|
2012-10-07 12:31:34 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct Variant_ {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub name: Ident,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub kind: VariantKind,
|
|
|
|
pub id: NodeId,
|
2014-05-16 02:16:13 -05:00
|
|
|
pub disr_expr: Option<Gc<Expr>>,
|
2014-03-27 17:39:48 -05:00
|
|
|
pub vis: Visibility,
|
2013-01-15 18:05:20 -06:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
pub type Variant = Spanned<Variant_>;
|
2010-11-24 13:36:35 -06:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct PathListIdent_ {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub name: Ident,
|
|
|
|
pub id: NodeId,
|
2013-01-13 19:27:57 -06:00
|
|
|
}
|
2012-03-14 16:18:53 -05:00
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
pub type PathListIdent = Spanned<PathListIdent_>;
|
2012-02-18 01:05:20 -06:00
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
pub type ViewPath = Spanned<ViewPath_>;
|
2012-03-14 16:18:53 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum ViewPath_ {
|
2012-02-18 01:05:20 -06:00
|
|
|
|
|
|
|
// quux = foo::bar::baz
|
|
|
|
//
|
|
|
|
// or just
|
|
|
|
//
|
|
|
|
// foo::bar::baz (with 'baz =' implicitly on the left)
|
2014-01-09 07:05:33 -06:00
|
|
|
ViewPathSimple(Ident, Path, NodeId),
|
2011-08-16 17:21:30 -05:00
|
|
|
|
2012-02-18 01:05:20 -06:00
|
|
|
// foo::bar::*
|
2014-01-09 07:05:33 -06:00
|
|
|
ViewPathGlob(Path, NodeId),
|
2011-08-16 17:21:30 -05:00
|
|
|
|
2012-02-18 01:05:20 -06:00
|
|
|
// foo::bar::{a,b,c}
|
2014-02-28 15:09:09 -06:00
|
|
|
ViewPathList(Path, Vec<PathListIdent> , NodeId)
|
2012-02-18 01:05:20 -06:00
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct ViewItem {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub node: ViewItem_,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub vis: Visibility,
|
|
|
|
pub span: Span,
|
2013-01-13 18:51:48 -06:00
|
|
|
}
|
2012-03-14 16:18:53 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum ViewItem_ {
|
2013-07-31 15:47:32 -05:00
|
|
|
// ident: name used to refer to this crate in the code
|
2014-02-05 18:02:10 -06:00
|
|
|
// optional (InternedString,StrStyle): if present, this is a location
|
|
|
|
// (containing arbitrary characters) from which to fetch the crate sources
|
2014-06-16 18:07:34 -05:00
|
|
|
// For example, extern crate whatever = "github.com/rust-lang/rust"
|
2014-03-07 01:57:45 -06:00
|
|
|
ViewItemExternCrate(Ident, Option<(InternedString,StrStyle)>, NodeId),
|
2014-05-16 02:16:13 -05:00
|
|
|
ViewItemUse(Gc<ViewPath>),
|
2011-01-01 11:55:18 -06:00
|
|
|
}
|
|
|
|
|
2011-06-14 18:13:19 -05:00
|
|
|
// Meta-data associated with an item
|
2013-08-31 11:13:04 -05:00
|
|
|
pub type Attribute = Spanned<Attribute_>;
|
2011-06-14 18:13:19 -05:00
|
|
|
|
2013-07-19 06:51:37 -05:00
|
|
|
// Distinguishes between Attributes that decorate items and Attributes that
|
2011-06-14 18:13:19 -05:00
|
|
|
// are contained as statements within items. These two cases need to be
|
|
|
|
// distinguished for pretty-printing.
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-07-19 06:51:37 -05:00
|
|
|
pub enum AttrStyle {
|
|
|
|
AttrOuter,
|
|
|
|
AttrInner,
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2011-06-14 18:13:19 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-05-20 02:07:24 -05:00
|
|
|
pub struct AttrId(pub uint);
|
|
|
|
|
2012-06-30 05:54:54 -05:00
|
|
|
// doc-comments are promoted to attributes that have is_sugared_doc = true
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2013-07-19 06:51:37 -05:00
|
|
|
pub struct Attribute_ {
|
2014-05-20 02:07:24 -05:00
|
|
|
pub id: AttrId,
|
2014-03-27 17:39:48 -05:00
|
|
|
pub style: AttrStyle,
|
2014-05-16 02:16:13 -05:00
|
|
|
pub value: Gc<MetaItem>,
|
2014-03-27 17:39:48 -05:00
|
|
|
pub is_sugared_doc: bool,
|
2013-01-13 18:51:48 -06:00
|
|
|
}
|
2011-06-14 18:13:19 -05:00
|
|
|
|
2012-04-13 14:22:35 -05:00
|
|
|
/*
|
2014-01-09 07:05:33 -06:00
|
|
|
TraitRef's appear in impls.
|
|
|
|
resolve maps each TraitRef's ref_id to its defining trait; that's all
|
2012-06-26 18:25:52 -05:00
|
|
|
that the ref_id is for. The impl_id maps to the "self type" of this impl.
|
2014-01-09 07:05:33 -06:00
|
|
|
If this impl is an ItemImpl, the impl_id is redundant (it could be the
|
2012-12-10 15:47:54 -06:00
|
|
|
same as the impl's node id).
|
2012-04-13 14:22:35 -05:00
|
|
|
*/
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct TraitRef {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub path: Path,
|
|
|
|
pub ref_id: NodeId,
|
2013-01-15 18:05:20 -06:00
|
|
|
}
|
2012-04-11 18:18:00 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum Visibility {
|
|
|
|
Public,
|
|
|
|
Inherited,
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
2012-05-08 09:06:24 -05:00
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
impl Visibility {
|
|
|
|
pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility {
|
2013-03-28 13:27:54 -05:00
|
|
|
match self {
|
2014-01-09 07:05:33 -06:00
|
|
|
&Inherited => parent_visibility,
|
2014-04-15 20:02:58 -05:00
|
|
|
&Public => *self
|
2013-03-28 13:27:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-04-02 19:38:45 -05:00
|
|
|
pub enum Sized {
|
|
|
|
DynSize,
|
|
|
|
StaticSize,
|
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct StructField_ {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub kind: StructFieldKind,
|
|
|
|
pub id: NodeId,
|
|
|
|
pub ty: P<Ty>,
|
|
|
|
pub attrs: Vec<Attribute>,
|
2013-01-13 17:28:49 -06:00
|
|
|
}
|
2012-08-15 17:53:58 -05:00
|
|
|
|
2014-06-05 17:00:29 -05:00
|
|
|
impl StructField_ {
|
|
|
|
pub fn ident(&self) -> Option<Ident> {
|
|
|
|
match self.kind {
|
|
|
|
NamedField(ref ident, _) => Some(ident.clone()),
|
|
|
|
UnnamedField(_) => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
pub type StructField = Spanned<StructField_>;
|
2012-08-15 17:53:58 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum StructFieldKind {
|
|
|
|
NamedField(Ident, Visibility),
|
2014-03-25 18:53:52 -05:00
|
|
|
UnnamedField(Visibility), // element of a tuple-like struct
|
|
|
|
}
|
|
|
|
|
|
|
|
impl StructFieldKind {
|
|
|
|
pub fn is_unnamed(&self) -> bool {
|
|
|
|
match *self {
|
|
|
|
UnnamedField(..) => true,
|
|
|
|
NamedField(..) => false,
|
|
|
|
}
|
|
|
|
}
|
2012-08-15 17:53:58 -05:00
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct StructDef {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub fields: Vec<StructField>, /* fields, not including ctor */
|
2012-10-23 21:18:18 -05:00
|
|
|
/* ID of the constructor. This is only used for tuple- or enum-like
|
|
|
|
* structs. */
|
2014-02-24 01:17:02 -06:00
|
|
|
pub ctor_id: Option<NodeId>,
|
|
|
|
pub super_struct: Option<P<Ty>>, // Super struct, if specified.
|
|
|
|
pub is_virtual: bool, // True iff the struct may be inherited from.
|
2013-01-13 15:45:57 -06:00
|
|
|
}
|
2012-08-07 17:34:07 -05:00
|
|
|
|
2012-08-29 14:22:05 -05:00
|
|
|
/*
|
|
|
|
FIXME (#3300): Should allow items to be anonymous. Right now
|
|
|
|
we just use dummy names for anon items.
|
|
|
|
*/
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct Item {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub ident: Ident,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub id: NodeId,
|
|
|
|
pub node: Item_,
|
|
|
|
pub vis: Visibility,
|
|
|
|
pub span: Span,
|
2013-01-13 15:13:41 -06:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum Item_ {
|
2014-05-16 02:16:13 -05:00
|
|
|
ItemStatic(P<Ty>, Mutability, Gc<Expr>),
|
2014-04-06 20:04:40 -05:00
|
|
|
ItemFn(P<FnDecl>, FnStyle, Abi, Generics, P<Block>),
|
2014-01-09 07:05:33 -06:00
|
|
|
ItemMod(Mod),
|
|
|
|
ItemForeignMod(ForeignMod),
|
|
|
|
ItemTy(P<Ty>, Generics),
|
|
|
|
ItemEnum(EnumDef, Generics),
|
2014-05-16 02:16:13 -05:00
|
|
|
ItemStruct(Gc<StructDef>, Generics),
|
2014-07-04 14:05:43 -05:00
|
|
|
/// Represents a Trait Declaration
|
2014-04-02 19:38:45 -05:00
|
|
|
ItemTrait(Generics, Sized, Vec<TraitRef> , Vec<TraitMethod> ),
|
2014-01-09 07:05:33 -06:00
|
|
|
ItemImpl(Generics,
|
|
|
|
Option<TraitRef>, // (optional) trait this impl implements
|
|
|
|
P<Ty>, // self
|
2014-05-16 02:16:13 -05:00
|
|
|
Vec<Gc<Method>>),
|
2013-02-26 12:15:29 -06:00
|
|
|
// a macro invocation (which includes macro definition)
|
2014-01-09 07:05:33 -06:00
|
|
|
ItemMac(Mac),
|
2011-05-11 08:10:24 -05:00
|
|
|
}
|
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub struct ForeignItem {
|
2014-03-27 17:39:48 -05:00
|
|
|
pub ident: Ident,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub node: ForeignItem_,
|
|
|
|
pub id: NodeId,
|
|
|
|
pub span: Span,
|
|
|
|
pub vis: Visibility,
|
2013-01-13 14:02:16 -06:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum ForeignItem_ {
|
|
|
|
ForeignItemFn(P<FnDecl>, Generics),
|
|
|
|
ForeignItemStatic(P<Ty>, /* is_mutbl */ bool),
|
2011-02-02 09:43:57 -06:00
|
|
|
}
|
|
|
|
|
2012-03-01 21:37:52 -06:00
|
|
|
// The data we save and restore about an inlined item or method. This is not
|
|
|
|
// part of the AST that we parse from a file, but it becomes part of the tree
|
|
|
|
// that we trans.
|
2014-05-31 12:43:52 -05:00
|
|
|
#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum InlinedItem {
|
2014-05-16 02:16:13 -05:00
|
|
|
IIItem(Gc<Item>),
|
|
|
|
IIMethod(DefId /* impl id */, bool /* is provided */, Gc<Method>),
|
|
|
|
IIForeign(Gc<ForeignItem>),
|
2012-03-01 21:37:52 -06:00
|
|
|
}
|
|
|
|
|
2013-11-27 09:48:58 -06:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
2014-02-21 16:18:39 -06:00
|
|
|
use serialize::json;
|
2014-02-05 10:52:54 -06:00
|
|
|
use serialize;
|
2014-01-14 03:47:29 -06:00
|
|
|
use codemap::*;
|
2013-11-27 09:48:58 -06:00
|
|
|
use super::*;
|
|
|
|
|
2013-04-03 12:28:14 -05:00
|
|
|
// are ASTs encodable?
|
2014-03-18 12:58:26 -05:00
|
|
|
#[test]
|
|
|
|
fn check_asts_encodable() {
|
|
|
|
use std::io;
|
|
|
|
let e = Crate {
|
2014-04-26 15:05:45 -05:00
|
|
|
module: Mod {
|
|
|
|
inner: Span {
|
|
|
|
lo: BytePos(11),
|
|
|
|
hi: BytePos(19),
|
|
|
|
expn_info: None,
|
|
|
|
},
|
|
|
|
view_items: Vec::new(),
|
|
|
|
items: Vec::new(),
|
|
|
|
},
|
2014-03-18 12:58:26 -05:00
|
|
|
attrs: Vec::new(),
|
|
|
|
config: Vec::new(),
|
|
|
|
span: Span {
|
|
|
|
lo: BytePos(10),
|
|
|
|
hi: BytePos(20),
|
|
|
|
expn_info: None,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
// doesn't matter which encoder we use....
|
|
|
|
let _f = &e as &serialize::Encodable<json::Encoder, io::IoError>;
|
|
|
|
}
|
2013-02-13 14:49:45 -06:00
|
|
|
}
|