diff options
| author | bors <bors@rust-lang.org> | 2014-01-09 12:31:35 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-01-09 12:31:35 -0800 |
| commit | 9d63403c1c500cc47f876bfc527cc8327464de3d (patch) | |
| tree | df2ace956c0631a5c6f3edb2e9f020330f863a89 /src/libsyntax | |
| parent | 63ba93f91d6988506fd25a91c7d80820818159ab (diff) | |
| parent | 72ee4a57b7ab3651db1ec99ff3167b86f2583c43 (diff) | |
| download | rust-9d63403c1c500cc47f876bfc527cc8327464de3d.tar.gz rust-9d63403c1c500cc47f876bfc527cc8327464de3d.zip | |
auto merge of #11417 : eddyb/rust/desnaking, r=bstrie
Diffstat (limited to 'src/libsyntax')
53 files changed, 2369 insertions, 2430 deletions
diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 9f69379f3c5..9194acfcdec 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -32,6 +32,7 @@ pub enum Abi { RustIntrinsic, } +#[allow(non_camel_case_types)] #[deriving(Eq)] pub enum Architecture { // NB. You cannot change the ordering of these diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 8864c678b95..2458577aa86 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -197,7 +197,7 @@ pub static DUMMY_NODE_ID: NodeId = -1; // detects Copy, Send, Send, and Freeze. #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum TyParamBound { - TraitTyParamBound(trait_ref), + TraitTyParamBound(TraitRef), RegionTyParamBound } @@ -234,8 +234,8 @@ pub enum MethodProvenance { #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum Def { - DefFn(DefId, purity), - DefStaticMethod(/* method */ DefId, MethodProvenance, purity), + DefFn(DefId, Purity), + DefStaticMethod(/* method */ DefId, MethodProvenance, Purity), DefSelf(NodeId, bool /* is_mutbl */), DefSelfTy(/* trait id */ NodeId), DefMod(DefId), @@ -246,7 +246,7 @@ pub enum Def { DefVariant(DefId /* enum */, DefId /* variant */, bool /* is_structure */), DefTy(DefId), DefTrait(DefId), - DefPrimTy(prim_ty), + DefPrimTy(PrimTy), DefTyParam(DefId, uint), DefBinding(NodeId, BindingMode), DefUse(DefId), @@ -256,13 +256,13 @@ pub enum Def { NodeId), // id for the block/body of the closure expr /// Note that if it's a tuple struct's definition, the node id of the DefId - /// may either refer to the item definition's id or the struct_def.ctor_id. + /// may either refer to the item definition's id or the StructDef.ctor_id. /// /// The cases that I have encountered so far are (this is not exhaustive): /// - If it's a ty_path referring to some tuple struct, then DefMap maps /// it to a def whose id is the item definition's id. /// - If it's an ExprPath referring to some tuple struct, then DefMap maps - /// it to a def whose id is the struct_def.ctor_id. + /// it to a def whose id is the StructDef.ctor_id. DefStruct(DefId), DefTyParamBinder(NodeId), /* struct, impl or trait with ty params */ DefRegion(NodeId), @@ -284,7 +284,7 @@ pub type CrateConfig = ~[@MetaItem]; #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct Crate { - module: _mod, + module: Mod, attrs: ~[Attribute], config: CrateConfig, span: Span, @@ -296,7 +296,7 @@ pub type MetaItem = Spanned<MetaItem_>; pub enum MetaItem_ { MetaWord(@str), MetaList(@str, ~[@MetaItem]), - MetaNameValue(@str, lit), + MetaNameValue(@str, Lit), } // can't be derived because the MetaList requires an unordered comparison @@ -326,7 +326,7 @@ impl Eq for MetaItem_ { #[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] pub struct Block { - view_items: ~[view_item], + view_items: ~[ViewItem], stmts: ~[@Stmt], expr: Option<@Expr>, id: NodeId, @@ -464,7 +464,7 @@ pub enum Stmt_ { StmtSemi(@Expr, NodeId), // bool: is there a trailing sem-colon? - StmtMac(mac, bool), + StmtMac(Mac, bool), } // FIXME (pending discussion of #1697, #2178...): local should really be @@ -486,7 +486,7 @@ pub enum Decl_ { // a local (let) binding: DeclLocal(@Local), // an item binding: - DeclItem(@item), + DeclItem(@Item), } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] @@ -553,7 +553,7 @@ pub enum Expr_ { ExprTup(~[@Expr]), ExprBinary(NodeId, BinOp, @Expr, @Expr), ExprUnary(NodeId, UnOp, @Expr), - ExprLit(@lit), + ExprLit(@Lit), ExprCast(@Expr, P<Ty>), ExprIf(@Expr, P<Block>, Option<@Expr>), ExprWhile(@Expr, P<Block>), @@ -563,8 +563,8 @@ pub enum Expr_ { // FIXME #6993: change to Option<Name> ExprLoop(P<Block>, Option<Ident>), ExprMatch(@Expr, ~[Arm]), - ExprFnBlock(P<fn_decl>, P<Block>), - ExprProc(P<fn_decl>, P<Block>), + ExprFnBlock(P<FnDecl>, P<Block>), + ExprProc(P<FnDecl>, P<Block>), ExprDoBody(@Expr), ExprBlock(P<Block>), @@ -588,9 +588,9 @@ pub enum Expr_ { /// Gets the log level for the enclosing module ExprLogLevel, - ExprInlineAsm(inline_asm), + ExprInlineAsm(InlineAsm), - ExprMac(mac), + ExprMac(Mac), // A struct literal expression. ExprStruct(Path, ~[Field], Option<@Expr> /* base */), @@ -610,31 +610,38 @@ pub enum Expr_ { // 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 -// macro_parser::matched_nonterminals into the tt_nonterminals it finds. +// macro_parser::matched_nonterminals into the TTNonterminals it finds. // -// The RHS of an MBE macro is the only place a tt_nonterminal or tt_seq +// The RHS of an MBE macro is the only place a TTNonterminal or TTSeq // 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. // #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[doc="For macro invocations; parsing is delegated to the macro"] -pub enum token_tree { +pub enum TokenTree { // a single token - tt_tok(Span, ::parse::token::Token), + TTTok(Span, ::parse::token::Token), // a delimited sequence (the delimiters appear as the first // and last elements of the vector) - tt_delim(@~[token_tree]), + TTDelim(@~[TokenTree]), // These only make sense for right-hand-sides of MBE macros: - // a kleene-style repetition sequence with a span, a tt_forest, + // a kleene-style repetition sequence with a span, a TTForest, // an optional separator, and a boolean where true indicates // zero or more (..), and false indicates one or more (+). - tt_seq(Span, @~[token_tree], Option<::parse::token::Token>, bool), + TTSeq(Span, @~[TokenTree], Option<::parse::token::Token>, bool), // a syntactic variable that will be filled in by macro expansion. - tt_nonterminal(Span, Ident) + TTNonterminal(Span, Ident) +} + +// NOTE remove after next snapshot +// Required for ext::quote macros. +#[cfg(stage0)] +pub fn tt_tok(span: Span, tok: ::parse::token::Token) -> TokenTree { + TTTok(span, tok) } // @@ -646,15 +653,15 @@ pub enum token_tree { // token-trees, and are thus primarily used by the macro-defining extension // itself. // -// match_tok -// --------- +// MatchTok +// -------- // // A matcher that matches a single token, denoted by the token itself. So // long as there's no $ involved. // // -// match_seq -// --------- +// MatchSeq +// -------- // // A matcher that matches a sequence of sub-matchers, denoted various // possible ways: @@ -665,7 +672,7 @@ pub enum token_tree { // $(A B C);* zero or more semi-separated 'A B C' seqs // // -// match_nonterminal +// MatchNonterminal // ----------------- // // A matcher that matches one of a few interesting named rust @@ -682,35 +689,35 @@ pub enum token_tree { // // 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 -// by an match_seq, specifically this one: +// by an MatchSeq, specifically this one: // // $( $lhs:matchers => $rhs:tt );+ // // If you understand that, you have closed to loop and understand the whole // macro system. Congratulations. // -pub type matcher = Spanned<matcher_>; +pub type Matcher = Spanned<Matcher_>; #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum matcher_ { +pub enum Matcher_ { // match one token - match_tok(::parse::token::Token), + MatchTok(::parse::token::Token), // match repetitions of a sequence: body, separator, zero ok?, // lo, hi position-in-match-array used: - match_seq(~[matcher], Option<::parse::token::Token>, bool, uint, uint), + MatchSeq(~[Matcher], Option<::parse::token::Token>, bool, uint, uint), // parse a Rust NT: name to bind, name of NT, position in match array: - match_nonterminal(Ident, Ident, uint) + MatchNonterminal(Ident, Ident, uint) } -pub type mac = Spanned<mac_>; +pub type Mac = Spanned<Mac_>; // 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. #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum mac_ { - mac_invoc_tt(Path,~[token_tree],SyntaxContext), // new macro-invocation +pub enum Mac_ { + MacInvocTT(Path, ~[TokenTree], SyntaxContext), // new macro-invocation } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] @@ -719,26 +726,26 @@ pub enum StrStyle { RawStr(uint) } -pub type lit = Spanned<lit_>; +pub type Lit = Spanned<Lit_>; #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum lit_ { - lit_str(@str, StrStyle), - lit_binary(@[u8]), - lit_char(u32), - lit_int(i64, int_ty), - lit_uint(u64, uint_ty), - lit_int_unsuffixed(i64), - lit_float(@str, float_ty), - lit_float_unsuffixed(@str), - lit_nil, - lit_bool(bool), +pub enum Lit_ { + LitStr(@str, StrStyle), + LitBinary(@[u8]), + LitChar(u32), + LitInt(i64, IntTy), + LitUint(u64, UintTy), + LitIntUnsuffixed(i64), + LitFloat(@str, FloatTy), + LitFloatUnsuffixed(@str), + LitNil, + LitBool(bool), } // NB: If you change this, you'll probably want to change the corresponding // type structure in middle/ty.rs as well. #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub struct mt { +pub struct MutTy { ty: P<Ty>, mutbl: Mutability, } @@ -746,7 +753,7 @@ pub struct mt { #[deriving(Eq, Encodable, Decodable,IterBytes)] pub struct TypeField { ident: Ident, - mt: mt, + mt: MutTy, span: Span, } @@ -754,10 +761,10 @@ pub struct TypeField { pub struct TypeMethod { ident: Ident, attrs: ~[Attribute], - purity: purity, - decl: P<fn_decl>, + purity: Purity, + decl: P<FnDecl>, generics: Generics, - explicit_self: explicit_self, + explicit_self: ExplicitSelf, id: NodeId, span: Span, } @@ -766,48 +773,48 @@ pub struct TypeMethod { // implementation, just a signature) or provided (meaning it has a default // implementation). #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum trait_method { - required(TypeMethod), - provided(@method), +pub enum TraitMethod { + Required(TypeMethod), + Provided(@Method), } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum int_ty { - ty_i, - ty_i8, - ty_i16, - ty_i32, - ty_i64, +pub enum IntTy { + TyI, + TyI8, + TyI16, + TyI32, + TyI64, } -impl ToStr for int_ty { +impl ToStr for IntTy { fn to_str(&self) -> ~str { ::ast_util::int_ty_to_str(*self) } } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum uint_ty { - ty_u, - ty_u8, - ty_u16, - ty_u32, - ty_u64, +pub enum UintTy { + TyU, + TyU8, + TyU16, + TyU32, + TyU64, } -impl ToStr for uint_ty { +impl ToStr for UintTy { fn to_str(&self) -> ~str { ::ast_util::uint_ty_to_str(*self) } } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum float_ty { - ty_f32, - ty_f64, +pub enum FloatTy { + TyF32, + TyF64, } -impl ToStr for float_ty { +impl ToStr for FloatTy { fn to_str(&self) -> ~str { ::ast_util::float_ty_to_str(*self) } @@ -817,19 +824,19 @@ impl ToStr for float_ty { #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct Ty { id: NodeId, - node: ty_, + node: Ty_, span: Span, } // Not represented directly in the AST, referred to by name through a ty_path. #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum prim_ty { - ty_int(int_ty), - ty_uint(uint_ty), - ty_float(float_ty), - ty_str, - ty_bool, - ty_char +pub enum PrimTy { + TyInt(IntTy), + TyUint(UintTy), + TyFloat(FloatTy), + TyStr, + TyBool, + TyChar } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] @@ -848,13 +855,13 @@ impl ToStr for Onceness { } #[deriving(Eq, Encodable, Decodable,IterBytes)] -pub struct TyClosure { +pub struct ClosureTy { sigil: Sigil, region: Option<Lifetime>, lifetimes: OptVec<Lifetime>, - purity: purity, + purity: Purity, onceness: Onceness, - decl: P<fn_decl>, + decl: P<FnDecl>, // 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:()", @@ -863,42 +870,42 @@ pub struct TyClosure { } #[deriving(Eq, Encodable, Decodable,IterBytes)] -pub struct TyBareFn { - purity: purity, +pub struct BareFnTy { + purity: Purity, abis: AbiSet, lifetimes: OptVec<Lifetime>, - decl: P<fn_decl> + decl: P<FnDecl> } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum ty_ { - ty_nil, - ty_bot, /* bottom type */ - ty_box(P<Ty>), - ty_uniq(P<Ty>), - ty_vec(P<Ty>), - ty_fixed_length_vec(P<Ty>, @Expr), - ty_ptr(mt), - ty_rptr(Option<Lifetime>, mt), - ty_closure(@TyClosure), - ty_bare_fn(@TyBareFn), - ty_tup(~[P<Ty>]), - ty_path(Path, Option<OptVec<TyParamBound>>, NodeId), // for #7264; see above - ty_typeof(@Expr), +pub enum Ty_ { + TyNil, + TyBot, /* bottom type */ + TyBox(P<Ty>), + TyUniq(P<Ty>), + TyVec(P<Ty>), + TyFixedLengthVec(P<Ty>, @Expr), + TyPtr(MutTy), + TyRptr(Option<Lifetime>, MutTy), + TyClosure(@ClosureTy), + TyBareFn(@BareFnTy), + TyTup(~[P<Ty>]), + TyPath(Path, Option<OptVec<TyParamBound>>, NodeId), // for #7264; see above + TyTypeof(@Expr), // 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, + TyInfer, } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum asm_dialect { - asm_att, - asm_intel +pub enum AsmDialect { + AsmAtt, + AsmIntel } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub struct inline_asm { +pub struct InlineAsm { asm: @str, asm_str_style: StrStyle, clobbers: @str, @@ -906,159 +913,159 @@ pub struct inline_asm { outputs: ~[(@str, @Expr)], volatile: bool, alignstack: bool, - dialect: asm_dialect + dialect: AsmDialect } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub struct arg { +pub struct Arg { ty: P<Ty>, pat: @Pat, id: NodeId, } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub struct fn_decl { - inputs: ~[arg], +pub struct FnDecl { + inputs: ~[Arg], output: P<Ty>, - cf: ret_style, + cf: RetStyle, variadic: bool } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum purity { - unsafe_fn, // declared with "unsafe fn" - impure_fn, // declared with "fn" - extern_fn, // declared with "extern fn" +pub enum Purity { + UnsafeFn, // declared with "unsafe fn" + ImpureFn, // declared with "fn" + ExternFn, // declared with "extern fn" } -impl ToStr for purity { +impl ToStr for Purity { fn to_str(&self) -> ~str { match *self { - impure_fn => ~"impure", - unsafe_fn => ~"unsafe", - extern_fn => ~"extern" + ImpureFn => ~"impure", + UnsafeFn => ~"unsafe", + ExternFn => ~"extern" } } } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum ret_style { - noreturn, // functions with return type _|_ that always +pub enum RetStyle { + NoReturn, // functions with return type _|_ that always // raise an error or exit (i.e. never return to the caller) - return_val, // everything else + Return, // everything else } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum explicit_self_ { - sty_static, // no self - sty_value(Mutability), // `self` - sty_region(Option<Lifetime>, Mutability), // `&'lt self` - sty_box(Mutability), // `@self` - sty_uniq(Mutability) // `~self` +pub enum ExplicitSelf_ { + SelfStatic, // no self + SelfValue(Mutability), // `self` + SelfRegion(Option<Lifetime>, Mutability), // `&'lt self` + SelfBox(Mutability), // `@self` + SelfUniq(Mutability) // `~self` } -pub type explicit_self = Spanned<explicit_self_>; +pub type ExplicitSelf = Spanned<ExplicitSelf_>; #[deriving(Eq, Encodable, Decodable,IterBytes)] -pub struct method { +pub struct Method { ident: Ident, attrs: ~[Attribute], generics: Generics, - explicit_self: explicit_self, - purity: purity, - decl: P<fn_decl>, + explicit_self: ExplicitSelf, + purity: Purity, + decl: P<FnDecl>, body: P<Block>, id: NodeId, span: Span, self_id: NodeId, - vis: visibility, + vis: Visibility, } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub struct _mod { - view_items: ~[view_item], - items: ~[@item], +pub struct Mod { + view_items: ~[ViewItem], + items: ~[@Item], } #[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] -pub struct foreign_mod { +pub struct ForeignMod { abis: AbiSet, - view_items: ~[view_item], - items: ~[@foreign_item], + view_items: ~[ViewItem], + items: ~[@ForeignItem], } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub struct variant_arg { +pub struct VariantArg { ty: P<Ty>, id: NodeId, } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum variant_kind { - tuple_variant_kind(~[variant_arg]), - struct_variant_kind(@struct_def), +pub enum VariantKind { + TupleVariantKind(~[VariantArg]), + StructVariantKind(@StructDef), } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub struct enum_def { - variants: ~[P<variant>], +pub struct EnumDef { + variants: ~[P<Variant>], } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub struct variant_ { +pub struct Variant_ { name: Ident, attrs: ~[Attribute], - kind: variant_kind, + kind: VariantKind, id: NodeId, disr_expr: Option<@Expr>, - vis: visibility, + vis: Visibility, } -pub type variant = Spanned<variant_>; +pub type Variant = Spanned<Variant_>; #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub struct path_list_ident_ { +pub struct PathListIdent_ { name: Ident, id: NodeId, } -pub type path_list_ident = Spanned<path_list_ident_>; +pub type PathListIdent = Spanned<PathListIdent_>; -pub type view_path = Spanned<view_path_>; +pub type ViewPath = Spanned<ViewPath_>; #[deriving(Eq, Encodable, Decodable, IterBytes)] -pub enum view_path_ { +pub enum ViewPath_ { // quux = foo::bar::baz // // or just // // foo::bar::baz (with 'baz =' implicitly on the left) - view_path_simple(Ident, Path, NodeId), + ViewPathSimple(Ident, Path, NodeId), // foo::bar::* - view_path_glob(Path, NodeId), + ViewPathGlob(Path, NodeId), // foo::bar::{a,b,c} - view_path_list(Path, ~[path_list_ident], NodeId) + ViewPathList(Path, ~[PathListIdent], NodeId) } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub struct view_item { - node: view_item_, +pub struct ViewItem { + node: ViewItem_, attrs: ~[Attribute], - vis: visibility, + vis: Visibility, span: Span, } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum view_item_ { +pub enum ViewItem_ { // ident: name used to refer to this crate in the code // optional @str: if present, this is a location (containing // arbitrary characters) from which to fetch the crate sources // For example, extern mod whatever = "github.com/mozilla/rust" - view_item_extern_mod(Ident, Option<(@str, StrStyle)>, NodeId), - view_item_use(~[@view_path]), + ViewItemExternMod(Ident, Option<(@str, StrStyle)>, NodeId), + ViewItemUse(~[@ViewPath]), } // Meta-data associated with an item @@ -1082,53 +1089,53 @@ pub struct Attribute_ { } /* - trait_refs appear in impls. - resolve maps each trait_ref's ref_id to its defining trait; that's all + TraitRef's appear in impls. + resolve maps each TraitRef's ref_id to its defining trait; that's all that the ref_id is for. The impl_id maps to the "self type" of this impl. - If this impl is an item_impl, the impl_id is redundant (it could be the + If this impl is an ItemImpl, the impl_id is redundant (it could be the same as the impl's node id). */ #[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] -pub struct trait_ref { +pub struct TraitRef { path: Path, ref_id: NodeId, } #[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] -pub enum visibility { - public, - private, - inherited, +pub enum Visibility { + Public, + Private, + Inherited, } -impl visibility { - pub fn inherit_from(&self, parent_visibility: visibility) -> visibility { +impl Visibility { + pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility { match self { - &inherited => parent_visibility, - &public | &private => *self + &Inherited => parent_visibility, + &Public | &Private => *self } } } #[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] -pub struct struct_field_ { - kind: struct_field_kind, +pub struct StructField_ { + kind: StructFieldKind, id: NodeId, ty: P<Ty>, attrs: ~[Attribute], } -pub type struct_field = Spanned<struct_field_>; +pub type StructField = Spanned<StructField_>; #[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] -pub enum struct_field_kind { - named_field(Ident, visibility), - unnamed_field // element of a tuple-like struct +pub enum StructFieldKind { + NamedField(Ident, Visibility), + UnnamedField // element of a tuple-like struct } #[deriving(Eq, Encodable, Decodable,IterBytes)] -pub struct struct_def { - fields: ~[struct_field], /* fields, not including ctor */ +pub struct StructDef { + fields: ~[StructField], /* fields, not including ctor */ /* ID of the constructor. This is only used for tuple- or enum-like * structs. */ ctor_id: Option<NodeId> @@ -1139,57 +1146,57 @@ pub struct struct_def { we just use dummy names for anon items. */ #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub struct item { +pub struct Item { ident: Ident, attrs: ~[Attribute], id: NodeId, - node: item_, - vis: visibility, + node: Item_, + vis: Visibility, span: Span, } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum item_ { - item_static(P<Ty>, Mutability, @Expr), - item_fn(P<fn_decl>, purity, AbiSet, Generics, P<Block>), - item_mod(_mod), - item_foreign_mod(foreign_mod), - item_ty(P<Ty>, Generics), - item_enum(enum_def, Generics), - item_struct(@struct_def, Generics), - item_trait(Generics, ~[trait_ref], ~[trait_method]), - item_impl(Generics, - Option<trait_ref>, // (optional) trait this impl implements - P<Ty>, // self - ~[@method]), +pub enum Item_ { + ItemStatic(P<Ty>, Mutability, @Expr), + ItemFn(P<FnDecl>, Purity, AbiSet, Generics, P<Block>), + ItemMod(Mod), + ItemForeignMod(ForeignMod), + ItemTy(P<Ty>, Generics), + ItemEnum(EnumDef, Generics), + ItemStruct(@StructDef, Generics), + ItemTrait(Generics, ~[TraitRef], ~[TraitMethod]), + ItemImpl(Generics, + Option<TraitRef>, // (optional) trait this impl implements + P<Ty>, // self + ~[@Method]), // a macro invocation (which includes macro definition) - item_mac(mac), + ItemMac(Mac), } #[deriving(Eq, Encodable, Decodable,IterBytes)] -pub struct foreign_item { +pub struct ForeignItem { ident: Ident, attrs: ~[Attribute], - node: foreign_item_, + node: ForeignItem_, id: NodeId, span: Span, - vis: visibility, + vis: Visibility, } #[deriving(Eq, Encodable, Decodable,IterBytes)] -pub enum foreign_item_ { - foreign_item_fn(P<fn_decl>, Generics), - foreign_item_static(P<Ty>, /* is_mutbl */ bool), +pub enum ForeignItem_ { + ForeignItemFn(P<FnDecl>, Generics), + ForeignItemStatic(P<Ty>, /* is_mutbl */ bool), } // 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. #[deriving(Eq, Encodable, Decodable,IterBytes)] -pub enum inlined_item { - ii_item(@item), - ii_method(DefId /* impl id */, bool /* is provided */, @method), - ii_foreign(@foreign_item), +pub enum InlinedItem { + IIItem(@Item), + IIMethod(DefId /* impl id */, bool /* is provided */, @Method), + IIForeign(@ForeignItem), } #[cfg(test)] @@ -1200,7 +1207,7 @@ mod test { // Assert that the AST remains Freeze (#10693). #[test] fn ast_is_freeze() { - is_freeze::<item>(); + is_freeze::<Item>(); } } @@ -1292,7 +1299,7 @@ mod test { let e : crate = spanned{ node: crate_{ - module: _mod {view_items: ~[], items: ~[]}, + module: Mod {view_items: ~[], items: ~[]}, attrs: ~[], config: ~[] }, diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index a19b930be3e..0f5737d775e 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -14,10 +14,9 @@ use ast; use ast_util; use codemap::Span; use diagnostic::SpanHandler; -use fold::ast_fold; +use fold::Folder; use fold; -use parse::token::get_ident_interner; -use parse::token::ident_interner; +use parse::token::{get_ident_interner, IdentInterner}; use parse::token::special_idents; use print::pprust; use util::small_vector::SmallVector; @@ -26,34 +25,34 @@ use std::cell::RefCell; use std::hashmap::HashMap; #[deriving(Clone, Eq)] -pub enum path_elt { - path_mod(Ident), - path_name(Ident), +pub enum PathElem { + PathMod(Ident), + PathName(Ident), // A pretty name can come from an `impl` block. We attempt to select a // reasonable name for debuggers to see, but to guarantee uniqueness with // other paths the hash should also be taken into account during symbol // generation. - path_pretty_name(Ident, u64), + PathPrettyName(Ident, u64), } -impl path_elt { +impl PathElem { pub fn ident(&self) -> Ident { match *self { - path_mod(ident) | - path_name(ident) | - path_pretty_name(ident, _) => ident + PathMod(ident) | + PathName(ident) | + PathPrettyName(ident, _) => ident } } } -pub type path = ~[path_elt]; +pub type Path = ~[PathElem]; -pub fn path_to_str_with_sep(p: &[path_elt], sep: &str, itr: @ident_interner) - -> ~str { +pub fn path_to_str_with_sep(p: &[PathElem], sep: &str, itr: @IdentInterner) + -> ~str { let strs = p.map(|e| { match *e { - path_mod(s) | path_name(s) | path_pretty_name(s, _) => { + PathMod(s) | PathName(s) | PathPrettyName(s, _) => { itr.get(s.name) } } @@ -61,7 +60,7 @@ pub fn path_to_str_with_sep(p: &[path_elt], sep: &str, itr: @ident_interner) strs.connect(sep) } -pub fn path_ident_to_str(p: &path, i: Ident, itr: @ident_interner) -> ~str { +pub fn path_ident_to_str(p: &Path, i: Ident, itr: @IdentInterner) -> ~str { if p.is_empty() { itr.get(i.name).to_owned() } else { @@ -69,13 +68,13 @@ pub fn path_ident_to_str(p: &path, i: Ident, itr: @ident_interner) -> ~str { } } -pub fn path_to_str(p: &[path_elt], itr: @ident_interner) -> ~str { +pub fn path_to_str(p: &[PathElem], itr: @IdentInterner) -> ~str { path_to_str_with_sep(p, "::", itr) } -pub fn path_elt_to_str(pe: path_elt, itr: @ident_interner) -> ~str { +pub fn path_elem_to_str(pe: PathElem, itr: @IdentInterner) -> ~str { match pe { - path_mod(s) | path_name(s) | path_pretty_name(s, _) => { + PathMod(s) | PathName(s) | PathPrettyName(s, _) => { itr.get(s.name).to_owned() } } @@ -90,26 +89,26 @@ pub fn path_elt_to_str(pe: path_elt, itr: @ident_interner) -> ~str { // relic of $ being one of the very few valid symbol names on // unix. These kinds of details shouldn't be exposed way up here // in the ast. -fn pretty_ty(ty: &Ty, itr: @ident_interner, out: &mut ~str) { +fn pretty_ty(ty: &Ty, itr: @IdentInterner, out: &mut ~str) { let (prefix, subty) = match ty.node { - ty_uniq(ty) => ("$UP$", &*ty), - ty_box(ty) => ("$SP$", &*ty), - ty_ptr(mt { ty, mutbl }) => (if mutbl == MutMutable {"$RPmut$"} else {"$RP$"}, - &*ty), - ty_rptr(_, mt { ty, mutbl }) => (if mutbl == MutMutable {"$BPmut$"} else {"$BP$"}, - &*ty), + TyUniq(ty) => ("$UP$", &*ty), + TyBox(ty) => ("$SP$", &*ty), + TyPtr(MutTy { ty, mutbl }) => (if mutbl == MutMutable {"$RPmut$"} else {"$RP$"}, + &*ty), + TyRptr(_, MutTy { ty, mutbl }) => (if mutbl == MutMutable {"$BPmut$"} else {"$BP$"}, + &*ty), - ty_vec(ty) => ("$VEC$", &*ty), - ty_fixed_length_vec(ty, _) => ("$FIXEDVEC$", &*ty), + TyVec(ty) => ("$VEC$", &*ty), + TyFixedLengthVec(ty, _) => ("$FIXEDVEC$", &*ty), // these can't be represented as <prefix><contained ty>, so // need custom handling. - ty_nil => { out.push_str("$NIL$"); return } - ty_path(ref path, _, _) => { - out.push_str(itr.get(path.segments.last().identifier.name)); - return - } - ty_tup(ref tys) => { + TyNil => { out.push_str("$NIL$"); return } + TyPath(ref path, _, _) => { + out.push_str(itr.get(path.segments.last().identifier.name)); + return + } + TyTup(ref tys) => { out.push_str(format!("$TUP_{}$", tys.len())); for subty in tys.iter() { pretty_ty(*subty, itr, out); @@ -119,11 +118,11 @@ fn pretty_ty(ty: &Ty, itr: @ident_interner, out: &mut ~str) { } // meh, better than nothing. - ty_bot => { out.push_str("$BOT$"); return } - ty_closure(..) => { out.push_str("$CLOSURE$"); return } - ty_bare_fn(..) => { out.push_str("$FN$"); return } - ty_typeof(..) => { out.push_str("$TYPEOF$"); return } - ty_infer(..) => { out.push_str("$INFER$"); return } + TyBot => { out.push_str("$BOT$"); return } + TyClosure(..) => { out.push_str("$CLOSURE$"); return } + TyBareFn(..) => { out.push_str("$FN$"); return } + TyTypeof(..) => { out.push_str("$TYPEOF$"); return } + TyInfer(..) => { out.push_str("$INFER$"); return } }; @@ -131,7 +130,7 @@ fn pretty_ty(ty: &Ty, itr: @ident_interner, out: &mut ~str) { pretty_ty(subty, itr, out); } -pub fn impl_pretty_name(trait_ref: &Option<trait_ref>, ty: &Ty) -> path_elt { +pub fn impl_pretty_name(trait_ref: &Option<TraitRef>, ty: &Ty) -> PathElem { let itr = get_ident_interner(); let hash = (trait_ref, ty).hash(); @@ -145,56 +144,56 @@ pub fn impl_pretty_name(trait_ref: &Option<trait_ref>, ty: &Ty) -> path_elt { }; pretty_ty(ty, itr, &mut pretty); - path_pretty_name(Ident::new(itr.gensym(pretty)), hash) + PathPrettyName(Ident::new(itr.gensym(pretty)), hash) } #[deriving(Clone)] -pub enum ast_node { - node_item(@item, @path), - node_foreign_item(@foreign_item, AbiSet, visibility, @path), - node_trait_method(@trait_method, DefId /* trait did */, - @path /* path to the trait */), - node_method(@method, DefId /* impl did */, @path /* path to the impl */), - - /// node_variant represents a variant of an enum, e.g., for - /// `enum A { B, C, D }`, there would be a node_item for `A`, and a - /// node_variant item for each of `B`, `C`, and `D`. - node_variant(P<variant>, @item, @path), - node_expr(@Expr), - node_stmt(@Stmt), - node_arg(@Pat), +pub enum Node { + NodeItem(@Item, @Path), + NodeForeignItem(@ForeignItem, AbiSet, Visibility, @Path), + NodeTraitMethod(@TraitMethod, DefId /* trait did */, + @Path /* path to the trait */), + NodeMethod(@Method, DefId /* impl did */, @Path /* path to the impl */), + + /// NodeVariant represents a variant of an enum, e.g., for + /// `enum A { B, C, D }`, there would be a NodeItem for `A`, and a + /// NodeVariant item for each of `B`, `C`, and `D`. + NodeVariant(P<Variant>, @Item, @Path), + NodeExpr(@Expr), + NodeStmt(@Stmt), + NodeArg(@Pat), // HACK(eddyb) should always be a pattern, but `self` is not, and thus it // is identified only by an ident and no span is available. In all other // cases, node_span will return the proper span (required by borrowck). - node_local(Ident, Option<@Pat>), - node_block(P<Block>), + NodeLocal(Ident, Option<@Pat>), + NodeBlock(P<Block>), - /// node_struct_ctor represents a tuple struct. - node_struct_ctor(@struct_def, @item, @path), - node_callee_scope(@Expr) + /// NodeStructCtor represents a tuple struct. + NodeStructCtor(@StructDef, @Item, @Path), + NodeCalleeScope(@Expr) } -impl ast_node { +impl Node { pub fn with_attrs<T>(&self, f: |Option<&[Attribute]>| -> T) -> T { let attrs = match *self { - node_item(i, _) => Some(i.attrs.as_slice()), - node_foreign_item(fi, _, _, _) => Some(fi.attrs.as_slice()), - node_trait_method(tm, _, _) => match *tm { - required(ref type_m) => Some(type_m.attrs.as_slice()), - provided(m) => Some(m.attrs.as_slice()) + NodeItem(i, _) => Some(i.attrs.as_slice()), + NodeForeignItem(fi, _, _, _) => Some(fi.attrs.as_slice()), + NodeTraitMethod(tm, _, _) => match *tm { + Required(ref type_m) => Some(type_m.attrs.as_slice()), + Provided(m) => Some(m.attrs.as_slice()) }, - node_method(m, _, _) => Some(m.attrs.as_slice()), - node_variant(ref v, _, _) => Some(v.node.attrs.as_slice()), + NodeMethod(m, _, _) => Some(m.attrs.as_slice()), + NodeVariant(ref v, _, _) => Some(v.node.attrs.as_slice()), // unit/tuple structs take the attributes straight from // the struct definition. - node_struct_ctor(_, strct, _) => Some(strct.attrs.as_slice()), + NodeStructCtor(_, strct, _) => Some(strct.attrs.as_slice()), _ => None }; f(attrs) } } -pub type map = @RefCell<HashMap<NodeId, ast_node>>; +pub type Map = @RefCell<HashMap<NodeId, Node>>; pub trait FoldOps { fn new_id(&self, id: ast::NodeId) -> ast::NodeId { @@ -206,24 +205,24 @@ pub trait FoldOps { } pub struct Ctx<F> { - map: map, - path: path, + map: Map, + path: Path, diag: @SpanHandler, fold_ops: F } impl<F> Ctx<F> { - fn insert(&self, id: ast::NodeId, node: ast_node) { + fn insert(&self, id: ast::NodeId, node: Node) { let mut map = self.map.borrow_mut(); map.get().insert(id, node); } - fn map_self(&self, m: @method) { - self.insert(m.self_id, node_local(special_idents::self_, None)); + fn map_self(&self, m: @Method) { + self.insert(m.self_id, NodeLocal(special_idents::self_, None)); } } -impl<F: FoldOps> ast_fold for Ctx<F> { +impl<F: FoldOps> Folder for Ctx<F> { fn new_id(&mut self, id: ast::NodeId) -> ast::NodeId { self.fold_ops.new_id(id) } @@ -232,69 +231,65 @@ impl<F: FoldOps> ast_fold for Ctx<F> { self.fold_ops.new_span(span) } - fn fold_item(&mut self, i: @item) -> SmallVector<@item> { + fn fold_item(&mut self, i: @Item) -> SmallVector<@Item> { // clone is FIXME #2543 let item_path = @self.path.clone(); self.path.push(match i.node { - item_impl(_, ref maybe_trait, ty, _) => { + ItemImpl(_, ref maybe_trait, ty, _) => { // Right now the ident on impls is __extensions__ which isn't // very pretty when debugging, so attempt to select a better // name to use. impl_pretty_name(maybe_trait, ty) } - item_mod(_) | item_foreign_mod(_) => path_mod(i.ident), - _ => path_name(i.ident) + ItemMod(_) | ItemForeignMod(_) => PathMod(i.ident), + _ => PathName(i.ident) }); let i = fold::noop_fold_item(i, self).expect_one("expected one item"); - self.insert(i.id, node_item(i, item_path)); + self.insert(i.id, NodeItem(i, item_path)); match i.node { - item_impl(_, _, _, ref ms) => { + ItemImpl(_, _, _, ref ms) => { // clone is FIXME #2543 let p = @self.path.clone(); let impl_did = ast_util::local_def(i.id); for &m in ms.iter() { - self.insert(m.id, node_method(m, impl_did, p)); + self.insert(m.id, NodeMethod(m, impl_did, p)); self.map_self(m); } } - item_enum(ref enum_definition, _) => { + ItemEnum(ref enum_definition, _) => { // clone is FIXME #2543 let p = @self.path.clone(); for &v in enum_definition.variants.iter() { - self.insert(v.node.id, node_variant(v, i, p)); + self.insert(v.node.id, NodeVariant(v, i, p)); } } - item_foreign_mod(ref nm) => { + ItemForeignMod(ref nm) => { for nitem in nm.items.iter() { // Compute the visibility for this native item. - let visibility = match nitem.vis { - public => public, - private => private, - inherited => i.vis - }; + let visibility = nitem.vis.inherit_from(i.vis); self.insert(nitem.id, // Anonymous extern mods go in the parent scope. - node_foreign_item(*nitem, nm.abis, visibility, item_path)); + NodeForeignItem(*nitem, nm.abis, visibility, item_path)); } } - item_struct(struct_def, _) => { + ItemStruct(struct_def, _) => { // If this is a tuple-like struct, register the constructor. match struct_def.ctor_id { None => {} Some(ctor_id) => { // clone is FIXME #2543 let p = @self.path.clone(); - self.insert(ctor_id, node_struct_ctor(struct_def, i, p)); + self.insert(ctor_id, NodeStructCtor(struct_def, i, p)); } } } - item_trait(_, ref traits, ref methods) => { + ItemTrait(_, ref traits, ref methods) => { for t in traits.iter() { - self.insert(t.ref_id, node_item(i, item_path)); + self.insert(t.ref_id, NodeItem(i, item_path)); } // clone is FIXME #2543 @@ -302,11 +297,11 @@ impl<F: FoldOps> ast_fold for Ctx<F> { for tm in methods.iter() { let d_id = ast_util::local_def(i.id); match *tm { - required(ref m) => { - self.insert(m.id, node_trait_method(@(*tm).clone(), d_id, p)); + Required(ref m) => { + self.insert(m.id, NodeTraitMethod(@(*tm).clone(), d_id, p)); } - provided(m) => { - self.insert(m.id, node_trait_method(@provided(m), d_id, p)); + Provided(m) => { + self.insert(m.id, NodeTraitMethod(@Provided(m), d_id, p)); self.map_self(m); } } @@ -325,7 +320,7 @@ impl<F: FoldOps> ast_fold for Ctx<F> { match pat.node { PatIdent(_, ref path, _) => { // Note: this is at least *potentially* a pattern... - self.insert(pat.id, node_local(ast_util::path_to_ident(path), Some(pat))); + self.insert(pat.id, NodeLocal(ast_util::path_to_ident(path), Some(pat))); } _ => {} } @@ -336,13 +331,13 @@ impl<F: FoldOps> ast_fold for Ctx<F> { fn fold_expr(&mut self, expr: @Expr) -> @Expr { let expr = fold::noop_fold_expr(expr, self); - self.insert(expr.id, node_expr(expr)); + self.insert(expr.id, NodeExpr(expr)); // Expressions which are or might be calls: { let r = expr.get_callee_id(); for callee_id in r.iter() { - self.insert(*callee_id, node_callee_scope(expr)); + self.insert(*callee_id, NodeCalleeScope(expr)); } } @@ -351,34 +346,34 @@ impl<F: FoldOps> ast_fold for Ctx<F> { fn fold_stmt(&mut self, stmt: &Stmt) -> SmallVector<@Stmt> { let stmt = fold::noop_fold_stmt(stmt, self).expect_one("expected one statement"); - self.insert(ast_util::stmt_id(stmt), node_stmt(stmt)); + self.insert(ast_util::stmt_id(stmt), NodeStmt(stmt)); SmallVector::one(stmt) } - fn fold_method(&mut self, m: @method) -> @method { - self.path.push(path_name(m.ident)); + fn fold_method(&mut self, m: @Method) -> @Method { + self.path.push(PathName(m.ident)); let m = fold::noop_fold_method(m, self); self.path.pop(); m } - fn fold_fn_decl(&mut self, decl: &fn_decl) -> P<fn_decl> { + fn fold_fn_decl(&mut self, decl: &FnDecl) -> P<FnDecl> { let decl = fold::noop_fold_fn_decl(decl, self); for a in decl.inputs.iter() { - self.insert(a.id, node_arg(a.pat)); + self.insert(a.id, NodeArg(a.pat)); } decl } fn fold_block(&mut self, block: P<Block>) -> P<Block> { let block = fold::noop_fold_block(block, self); - self.insert(block.id, node_block(block)); + self.insert(block.id, NodeBlock(block)); block } } pub fn map_crate<F: 'static + FoldOps>(diag: @SpanHandler, c: Crate, - fold_ops: F) -> (Crate, map) { + fold_ops: F) -> (Crate, Map) { let mut cx = Ctx { map: @RefCell::new(HashMap::new()), path: ~[], @@ -392,11 +387,11 @@ pub fn map_crate<F: 'static + FoldOps>(diag: @SpanHandler, c: Crate, // crate. The `path` should be the path to the item but should not include // the item itself. pub fn map_decoded_item<F: 'static + FoldOps>(diag: @SpanHandler, - map: map, - path: path, + map: Map, + path: Path, fold_ops: F, - fold_ii: |&mut Ctx<F>| -> inlined_item) - -> inlined_item { + fold_ii: |&mut Ctx<F>| -> InlinedItem) + -> InlinedItem { // I believe it is ok for the local IDs of inlined items from other crates // to overlap with the local ids from this crate, so just generate the ids // starting from 0. @@ -413,18 +408,18 @@ pub fn map_decoded_item<F: 'static + FoldOps>(diag: @SpanHandler, // don't decode and instantiate the impl, but just the method, we have to // add it to the table now. Likewise with foreign items. match ii { - ii_item(..) => {} // fallthrough - ii_foreign(i) => { - cx.insert(i.id, node_foreign_item(i, - AbiSet::Intrinsic(), - i.vis, // Wrong but OK - @path)); + IIItem(..) => {} // fallthrough + IIForeign(i) => { + cx.insert(i.id, NodeForeignItem(i, + AbiSet::Intrinsic(), + i.vis, // Wrong but OK + @path)); } - ii_method(impl_did, is_provided, m) => { + IIMethod(impl_did, is_provided, m) => { let entry = if is_provided { - node_trait_method(@provided(m), impl_did, @path) + NodeTraitMethod(@Provided(m), impl_did, @path) } else { - node_method(m, impl_did, @path) + NodeMethod(m, impl_did, @path) }; cx.insert(m.id, entry); cx.map_self(m); @@ -434,100 +429,98 @@ pub fn map_decoded_item<F: 'static + FoldOps>(diag: @SpanHandler, ii } -pub fn node_id_to_str(map: map, id: NodeId, itr: @ident_interner) -> ~str { +pub fn node_id_to_str(map: Map, id: NodeId, itr: @IdentInterner) -> ~str { let map = map.borrow(); match map.get().find(&id) { None => { format!("unknown node (id={})", id) } - Some(&node_item(item, path)) => { + Some(&NodeItem(item, path)) => { let path_str = path_ident_to_str(path, item.ident, itr); let item_str = match item.node { - item_static(..) => ~"static", - item_fn(..) => ~"fn", - item_mod(..) => ~"mod", - item_foreign_mod(..) => ~"foreign mod", - item_ty(..) => ~"ty", - item_enum(..) => ~"enum", - item_struct(..) => ~"struct", - item_trait(..) => ~"trait", - item_impl(..) => ~"impl", - item_mac(..) => ~"macro" + ItemStatic(..) => ~"static", + ItemFn(..) => ~"fn", + ItemMod(..) => ~"mod", + ItemForeignMod(..) => ~"foreign mod", + ItemTy(..) => ~"ty", + ItemEnum(..) => ~"enum", + ItemStruct(..) => ~"struct", + ItemTrait(..) => ~"trait", + ItemImpl(..) => ~"impl", + ItemMac(..) => ~"macro" }; format!("{} {} (id={})", item_str, path_str, id) } - Some(&node_foreign_item(item, abi, _, path)) => { + Some(&NodeForeignItem(item, abi, _, path)) => { format!("foreign item {} with abi {:?} (id={})", path_ident_to_str(path, item.ident, itr), abi, id) } - Some(&node_method(m, _, path)) => { + Some(&NodeMethod(m, _, path)) => { format!("method {} in {} (id={})", itr.get(m.ident.name), path_to_str(*path, itr), id) } - Some(&node_trait_method(ref tm, _, path)) => { + Some(&NodeTraitMethod(ref tm, _, path)) => { let m = ast_util::trait_method_to_ty_method(&**tm); format!("method {} in {} (id={})", itr.get(m.ident.name), path_to_str(*path, itr), id) } - Some(&node_variant(ref variant, _, path)) => { + Some(&NodeVariant(ref variant, _, path)) => { format!("variant {} in {} (id={})", itr.get(variant.node.name.name), path_to_str(*path, itr), id) } - Some(&node_expr(expr)) => { + Some(&NodeExpr(expr)) => { format!("expr {} (id={})", pprust::expr_to_str(expr, itr), id) } - Some(&node_callee_scope(expr)) => { + Some(&NodeCalleeScope(expr)) => { format!("callee_scope {} (id={})", pprust::expr_to_str(expr, itr), id) } - Some(&node_stmt(stmt)) => { + Some(&NodeStmt(stmt)) => { format!("stmt {} (id={})", pprust::stmt_to_str(stmt, itr), id) } - Some(&node_arg(pat)) => { + Some(&NodeArg(pat)) => { format!("arg {} (id={})", pprust::pat_to_str(pat, itr), id) } - Some(&node_local(ident, _)) => { + Some(&NodeLocal(ident, _)) => { format!("local (id={}, name={})", id, itr.get(ident.name)) } - Some(&node_block(block)) => { + Some(&NodeBlock(block)) => { format!("block {} (id={})", pprust::block_to_str(block, itr), id) } - Some(&node_struct_ctor(_, _, path)) => { + Some(&NodeStructCtor(_, _, path)) => { format!("struct_ctor {} (id={})", path_to_str(*path, itr), id) } } } -pub fn node_item_query<Result>(items: map, id: NodeId, query: |@item| -> Result, error_msg: ~str) +pub fn node_item_query<Result>(items: Map, id: NodeId, query: |@Item| -> Result, error_msg: ~str) -> Result { let items = items.borrow(); match items.get().find(&id) { - Some(&node_item(it, _)) => query(it), + Some(&NodeItem(it, _)) => query(it), _ => fail!("{}", error_msg) } } -pub fn node_span(items: map, - id: ast::NodeId) - -> Span { +pub fn node_span(items: Map, id: ast::NodeId) -> Span { let items = items.borrow(); match items.get().find(&id) { - Some(&node_item(item, _)) => item.span, - Some(&node_foreign_item(foreign_item, _, _, _)) => foreign_item.span, - Some(&node_trait_method(@required(ref type_method), _, _)) => type_method.span, - Some(&node_trait_method(@provided(ref method), _, _)) => method.span, - Some(&node_method(method, _, _)) => method.span, - Some(&node_variant(variant, _, _)) => variant.span, - Some(&node_expr(expr)) => expr.span, - Some(&node_stmt(stmt)) => stmt.span, - Some(&node_arg(pat)) => pat.span, - Some(&node_local(_, pat)) => match pat { + Some(&NodeItem(item, _)) => item.span, + Some(&NodeForeignItem(foreign_item, _, _, _)) => foreign_item.span, + Some(&NodeTraitMethod(@Required(ref type_method), _, _)) => type_method.span, + Some(&NodeTraitMethod(@Provided(ref method), _, _)) => method.span, + Some(&NodeMethod(method, _, _)) => method.span, + Some(&NodeVariant(variant, _, _)) => variant.span, + Some(&NodeExpr(expr)) => expr.span, + Some(&NodeStmt(stmt)) => stmt.span, + Some(&NodeArg(pat)) => pat.span, + Some(&NodeLocal(_, pat)) => match pat { Some(pat) => pat.span, - None => fail!("node_span: cannot get span from node_local (likely `self`)") + None => fail!("node_span: cannot get span from NodeLocal (likely `self`)") }, - Some(&node_block(block)) => block.span, - Some(&node_struct_ctor(_, item, _)) => item.span, - Some(&node_callee_scope(expr)) => expr.span, + Some(&NodeBlock(block)) => block.span, + Some(&NodeStructCtor(_, item, _)) => item.span, + Some(&NodeCalleeScope(expr)) => expr.span, None => fail!("node_span: could not find id {}", id), } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 973d7f5aa9e..bcac69c188a 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -151,46 +151,46 @@ pub fn is_path(e: @Expr) -> bool { return match e.node { ExprPath(_) => true, _ => false }; } -pub fn int_ty_to_str(t: int_ty) -> ~str { +pub fn int_ty_to_str(t: IntTy) -> ~str { match t { - ty_i => ~"", - ty_i8 => ~"i8", - ty_i16 => ~"i16", - ty_i32 => ~"i32", - ty_i64 => ~"i64" + TyI => ~"", + TyI8 => ~"i8", + TyI16 => ~"i16", + TyI32 => ~"i32", + TyI64 => ~"i64" } } -pub fn int_ty_max(t: int_ty) -> u64 { +pub fn int_ty_max(t: IntTy) -> u64 { match t { - ty_i8 => 0x80u64, - ty_i16 => 0x8000u64, - ty_i | ty_i32 => 0x80000000u64, // actually ni about ty_i - ty_i64 => 0x8000000000000000u64 + TyI8 => 0x80u64, + TyI16 => 0x8000u64, + TyI | TyI32 => 0x80000000u64, // actually ni about TyI + TyI64 => 0x8000000000000000u64 } } -pub fn uint_ty_to_str(t: uint_ty) -> ~str { +pub fn uint_ty_to_str(t: UintTy) -> ~str { match t { - ty_u => ~"u", - ty_u8 => ~"u8", - ty_u16 => ~"u16", - ty_u32 => ~"u32", - ty_u64 => ~"u64" + TyU => ~"u", + TyU8 => ~"u8", + TyU16 => ~"u16", + TyU32 => ~"u32", + TyU64 => ~"u64" } } -pub fn uint_ty_max(t: uint_ty) -> u64 { +pub fn uint_ty_max(t: UintTy) -> u64 { match t { - ty_u8 => 0xffu64, - ty_u16 => 0xffffu64, - ty_u | ty_u32 => 0xffffffffu64, // actually ni about ty_u - ty_u64 => 0xffffffffffffffffu64 + TyU8 => 0xffu64, + TyU16 => 0xffffu64, + TyU | TyU32 => 0xffffffffu64, // actually ni about TyU + TyU64 => 0xffffffffffffffffu64 } } -pub fn float_ty_to_str(t: float_ty) -> ~str { - match t { ty_f32 => ~"f32", ty_f64 => ~"f64" } +pub fn float_ty_to_str(t: FloatTy) -> ~str { + match t { TyF32 => ~"f32", TyF64 => ~"f64" } } pub fn is_call_expr(e: @Expr) -> bool { @@ -243,21 +243,21 @@ pub fn unguarded_pat(a: &Arm) -> Option<~[@Pat]> { } } -pub fn public_methods(ms: ~[@method]) -> ~[@method] { +pub fn public_methods(ms: ~[@Method]) -> ~[@Method] { ms.move_iter().filter(|m| { match m.vis { - public => true, + Public => true, _ => false } }).collect() } -// extract a TypeMethod from a trait_method. if the trait_method is +// extract a TypeMethod from a TraitMethod. if the TraitMethod is // a default, pull out the useful fields to make a TypeMethod -pub fn trait_method_to_ty_method(method: &trait_method) -> TypeMethod { +pub fn trait_method_to_ty_method(method: &TraitMethod) -> TypeMethod { match *method { - required(ref m) => (*m).clone(), - provided(ref m) => { + Required(ref m) => (*m).clone(), + Provided(ref m) => { TypeMethod { ident: m.ident, attrs: m.attrs.clone(), @@ -272,23 +272,23 @@ pub fn trait_method_to_ty_method(method: &trait_method) -> TypeMethod { } } -pub fn split_trait_methods(trait_methods: &[trait_method]) - -> (~[TypeMethod], ~[@method]) { +pub fn split_trait_methods(trait_methods: &[TraitMethod]) + -> (~[TypeMethod], ~[@Method]) { let mut reqd = ~[]; let mut provd = ~[]; for trt_method in trait_methods.iter() { match *trt_method { - required(ref tm) => reqd.push((*tm).clone()), - provided(m) => provd.push(m) + Required(ref tm) => reqd.push((*tm).clone()), + Provided(m) => provd.push(m) } }; (reqd, provd) } -pub fn struct_field_visibility(field: ast::struct_field) -> visibility { +pub fn struct_field_visibility(field: ast::StructField) -> Visibility { match field.node.kind { - ast::named_field(_, visibility) => visibility, - ast::unnamed_field => ast::public + ast::NamedField(_, visibility) => visibility, + ast::UnnamedField => ast::Public } } @@ -332,14 +332,14 @@ pub fn empty_generics() -> Generics { // Enumerating the IDs which appear in an AST #[deriving(Encodable, Decodable)] -pub struct id_range { +pub struct IdRange { min: NodeId, max: NodeId, } -impl id_range { - pub fn max() -> id_range { - id_range { +impl IdRange { + pub fn max() -> IdRange { + IdRange { min: u32::max_value, max: u32::min_value, } @@ -378,7 +378,7 @@ impl<'a, O: IdVisitingOperation> IdVisitor<'a, O> { impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { fn visit_mod(&mut self, - module: &_mod, + module: &Mod, _: Span, node_id: NodeId, env: ()) { @@ -386,19 +386,19 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { visit::walk_mod(self, module, env) } - fn visit_view_item(&mut self, view_item: &view_item, env: ()) { + fn visit_view_item(&mut self, view_item: &ViewItem, env: ()) { match view_item.node { - view_item_extern_mod(_, _, node_id) => { + ViewItemExternMod(_, _, node_id) => { self.operation.visit_id(node_id) } - view_item_use(ref view_paths) => { + ViewItemUse(ref view_paths) => { for view_path in view_paths.iter() { match view_path.node { - view_path_simple(_, _, node_id) | - view_path_glob(_, node_id) => { + ViewPathSimple(_, _, node_id) | + ViewPathGlob(_, node_id) => { self.operation.visit_id(node_id) } - view_path_list(_, ref paths, node_id) => { + ViewPathList(_, ref paths, node_id) => { self.operation.visit_id(node_id); for path in paths.iter() { self.operation.visit_id(path.node.id) @@ -411,12 +411,12 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { visit::walk_view_item(self, view_item, env) } - fn visit_foreign_item(&mut self, foreign_item: &foreign_item, env: ()) { + fn visit_foreign_item(&mut self, foreign_item: &ForeignItem, env: ()) { self.operation.visit_id(foreign_item.id); visit::walk_foreign_item(self, foreign_item, env) } - fn visit_item(&mut self, item: &item, env: ()) { + fn visit_item(&mut self, item: &Item, env: ()) { if !self.pass_through_items { if self.visited_outermost { return @@ -427,7 +427,7 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { self.operation.visit_id(item.id); match item.node { - item_enum(ref enum_definition, _) => { + ItemEnum(ref enum_definition, _) => { for variant in enum_definition.variants.iter() { self.operation.visit_id(variant.node.id) } @@ -475,7 +475,7 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { fn visit_ty(&mut self, typ: &Ty, env: ()) { self.operation.visit_id(typ.id); match typ.node { - ty_path(_, _, id) => self.operation.visit_id(id), + TyPath(_, _, id) => self.operation.visit_id(id), _ => {} } visit::walk_ty(self, typ, env) @@ -487,16 +487,16 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { } fn visit_fn(&mut self, - function_kind: &visit::fn_kind, - function_declaration: &fn_decl, + function_kind: &visit::FnKind, + function_declaration: &FnDecl, block: &Block, span: Span, node_id: NodeId, env: ()) { if !self.pass_through_items { match *function_kind { - visit::fk_method(..) if self.visited_outermost => return, - visit::fk_method(..) => self.visited_outermost = true, + visit::FkMethod(..) if self.visited_outermost => return, + visit::FkMethod(..) => self.visited_outermost = true, _ => {} } } @@ -504,14 +504,14 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { self.operation.visit_id(node_id); match *function_kind { - visit::fk_item_fn(_, generics, _, _) => { + visit::FkItemFn(_, generics, _, _) => { self.visit_generics_helper(generics) } - visit::fk_method(_, generics, method) => { + visit::FkMethod(_, generics, method) => { self.operation.visit_id(method.self_id); self.visit_generics_helper(generics) } - visit::fk_fn_block => {} + visit::FkFnBlock => {} } for argument in function_declaration.inputs.iter() { @@ -528,19 +528,19 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { if !self.pass_through_items { match *function_kind { - visit::fk_method(..) => self.visited_outermost = false, + visit::FkMethod(..) => self.visited_outermost = false, _ => {} } } } - fn visit_struct_field(&mut self, struct_field: &struct_field, env: ()) { + fn visit_struct_field(&mut self, struct_field: &StructField, env: ()) { self.operation.visit_id(struct_field.node.id); visit::walk_struct_field(self, struct_field, env) } fn visit_struct_def(&mut self, - struct_def: &struct_def, + struct_def: &StructDef, ident: ast::Ident, generics: &ast::Generics, id: NodeId, @@ -550,16 +550,16 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { visit::walk_struct_def(self, struct_def, ident, generics, id, ()); } - fn visit_trait_method(&mut self, tm: &ast::trait_method, _: ()) { + fn visit_trait_method(&mut self, tm: &ast::TraitMethod, _: ()) { match *tm { - ast::required(ref m) => self.operation.visit_id(m.id), - ast::provided(ref m) => self.operation.visit_id(m.id), + ast::Required(ref m) => self.operation.visit_id(m.id), + ast::Provided(ref m) => self.operation.visit_id(m.id), } visit::walk_trait_method(self, tm, ()); } } -pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &inlined_item, +pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &InlinedItem, operation: &O) { let mut id_visitor = IdVisitor { operation: operation, @@ -568,14 +568,14 @@ pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &inlined_item, }; match *item { - ii_item(i) => id_visitor.visit_item(i, ()), - ii_foreign(i) => id_visitor.visit_foreign_item(i, ()), - ii_method(_, _, m) => visit::walk_method_helper(&mut id_visitor, m, ()), + IIItem(i) => id_visitor.visit_item(i, ()), + IIForeign(i) => id_visitor.visit_foreign_item(i, ()), + IIMethod(_, _, m) => visit::walk_method_helper(&mut id_visitor, m, ()), } } struct IdRangeComputingVisitor { - result: Cell<id_range>, + result: Cell<IdRange>, } impl IdVisitingOperation for IdRangeComputingVisitor { @@ -586,18 +586,18 @@ impl IdVisitingOperation for IdRangeComputingVisitor { } } -pub fn compute_id_range_for_inlined_item(item: &inlined_item) -> id_range { +pub fn compute_id_range_for_inlined_item(item: &InlinedItem) -> IdRange { let visitor = IdRangeComputingVisitor { - result: Cell::new(id_range::max()) + result: Cell::new(IdRange::max()) }; visit_ids_for_inlined_item(item, &visitor); visitor.result.get() } -pub fn is_item_impl(item: @ast::item) -> bool { +pub fn is_item_impl(item: @ast::Item) -> bool { match item.node { - item_impl(..) => true, - _ => false + ItemImpl(..) => true, + _ => false } } @@ -630,21 +630,21 @@ pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool { } pub trait EachViewItem { - fn each_view_item(&self, f: |&ast::view_item| -> bool) -> bool; + fn each_view_item(&self, f: |&ast::ViewItem| -> bool) -> bool; } struct EachViewItemData<'a> { - callback: 'a |&ast::view_item| -> bool, + callback: 'a |&ast::ViewItem| -> bool, } impl<'a> Visitor<()> for EachViewItemData<'a> { - fn visit_view_item(&mut self, view_item: &ast::view_item, _: ()) { + fn visit_view_item(&mut self, view_item: &ast::ViewItem, _: ()) { let _ = (self.callback)(view_item); } } impl EachViewItem for ast::Crate { - fn each_view_item(&self, f: |&ast::view_item| -> bool) -> bool { + fn each_view_item(&self, f: |&ast::ViewItem| -> bool) -> bool { let mut visit = EachViewItemData { callback: f, }; @@ -653,17 +653,16 @@ impl EachViewItem for ast::Crate { } } -pub fn view_path_id(p: &view_path) -> NodeId { +pub fn view_path_id(p: &ViewPath) -> NodeId { match p.node { - view_path_simple(_, _, id) | - view_path_glob(_, id) | - view_path_list(_, _, id) => id + ViewPathSimple(_, _, id) | ViewPathGlob(_, id) + | ViewPathList(_, _, id) => id } } /// Returns true if the given struct def is tuple-like; i.e. that its fields /// are unnamed. -pub fn struct_def_is_tuple_like(struct_def: &ast::struct_def) -> bool { +pub fn struct_def_is_tuple_like(struct_def: &ast::StructDef) -> bool { struct_def.ctor_id.is_some() } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index df8b45dbcf5..c44861bd7d7 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -66,7 +66,7 @@ impl AttrMetaMethods for MetaItem { match self.node { MetaNameValue(_, ref v) => { match v.node { - ast::lit_str(s, _) => Some(s), + ast::LitStr(s, _) => Some(s), _ => None, } }, @@ -126,11 +126,11 @@ impl AttributeMethods for Attribute { /* Constructors */ pub fn mk_name_value_item_str(name: @str, value: @str) -> @MetaItem { - let value_lit = dummy_spanned(ast::lit_str(value, ast::CookedStr)); + let value_lit = dummy_spanned(ast::LitStr(value, ast::CookedStr)); mk_name_value_item(name, value_lit) } -pub fn mk_name_value_item(name: @str, value: ast::lit) -> @MetaItem { +pub fn mk_name_value_item(name: @str, value: ast::Lit) -> @MetaItem { @dummy_spanned(MetaNameValue(name, value)) } @@ -152,7 +152,7 @@ pub fn mk_attr(item: @MetaItem) -> Attribute { pub fn mk_sugared_doc_attr(text: @str, lo: BytePos, hi: BytePos) -> Attribute { let style = doc_comment_style(text); - let lit = spanned(lo, hi, ast::lit_str(text, ast::CookedStr)); + let lit = spanned(lo, hi, ast::LitStr(text, ast::CookedStr)); let attr = Attribute_ { style: style, value: @spanned(lo, hi, MetaNameValue(@"doc", lit)), @@ -423,16 +423,16 @@ pub fn find_repr_attr(diagnostic: @SpanHandler, attr: @ast::MetaItem, acc: ReprA fn int_type_of_word(s: &str) -> Option<IntType> { match s { - "i8" => Some(SignedInt(ast::ty_i8)), - "u8" => Some(UnsignedInt(ast::ty_u8)), - "i16" => Some(SignedInt(ast::ty_i16)), - "u16" => Some(UnsignedInt(ast::ty_u16)), - "i32" => Some(SignedInt(ast::ty_i32)), - "u32" => Some(UnsignedInt(ast::ty_u32)), - "i64" => Some(SignedInt(ast::ty_i64)), - "u64" => Some(UnsignedInt(ast::ty_u64)), - "int" => Some(SignedInt(ast::ty_i)), - "uint" => Some(UnsignedInt(ast::ty_u)), + "i8" => Some(SignedInt(ast::TyI8)), + "u8" => Some(UnsignedInt(ast::TyU8)), + "i16" => Some(SignedInt(ast::TyI16)), + "u16" => Some(UnsignedInt(ast::TyU16)), + "i32" => Some(SignedInt(ast::TyI32)), + "u32" => Some(UnsignedInt(ast::TyU32)), + "i64" => Some(SignedInt(ast::TyI64)), + "u64" => Some(UnsignedInt(ast::TyU64)), + "int" => Some(SignedInt(ast::TyI)), + "uint" => Some(UnsignedInt(ast::TyU)), _ => None } } @@ -456,8 +456,8 @@ impl ReprAttr { #[deriving(Eq)] pub enum IntType { - SignedInt(ast::int_ty), - UnsignedInt(ast::uint_ty) + SignedInt(ast::IntTy), + UnsignedInt(ast::UintTy) } impl IntType { @@ -470,10 +470,10 @@ impl IntType { } fn is_ffi_safe(self) -> bool { match self { - SignedInt(ast::ty_i8) | UnsignedInt(ast::ty_u8) | - SignedInt(ast::ty_i16) | UnsignedInt(ast::ty_u16) | - SignedInt(ast::ty_i32) | UnsignedInt(ast::ty_u32) | - SignedInt(ast::ty_i64) | UnsignedInt(ast::ty_u64) => true, + SignedInt(ast::TyI8) | UnsignedInt(ast::TyU8) | + SignedInt(ast::TyI16) | UnsignedInt(ast::TyU16) | + SignedInt(ast::TyI32) | UnsignedInt(ast::TyU32) | + SignedInt(ast::TyI64) | UnsignedInt(ast::TyU64) => true, _ => false } } diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index af3f0488d96..18479d4ef41 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -24,7 +24,7 @@ pub trait Emitter { fn emit(&self, cmsp: Option<(&codemap::CodeMap, Span)>, msg: &str, - lvl: level); + lvl: Level); } // a span-handler is like a handler but also @@ -37,18 +37,18 @@ pub struct SpanHandler { impl SpanHandler { pub fn span_fatal(@self, sp: Span, msg: &str) -> ! { - self.handler.emit(Some((&*self.cm, sp)), msg, fatal); + self.handler.emit(Some((&*self.cm, sp)), msg, Fatal); fail!(); } pub fn span_err(@self, sp: Span, msg: &str) { - self.handler.emit(Some((&*self.cm, sp)), msg, error); + self.handler.emit(Some((&*self.cm, sp)), msg, Error); self.handler.bump_err_count(); } pub fn span_warn(@self, sp: Span, msg: &str) { - self.handler.emit(Some((&*self.cm, sp)), msg, warning); + self.handler.emit(Some((&*self.cm, sp)), msg, Warning); } pub fn span_note(@self, sp: Span, msg: &str) { - self.handler.emit(Some((&*self.cm, sp)), msg, note); + self.handler.emit(Some((&*self.cm, sp)), msg, Note); } pub fn span_bug(@self, sp: Span, msg: &str) -> ! { self.span_fatal(sp, ice_msg(msg)); @@ -71,11 +71,11 @@ pub struct Handler { impl Handler { pub fn fatal(@self, msg: &str) -> ! { - self.emit.emit(None, msg, fatal); + self.emit.emit(None, msg, Fatal); fail!(); } pub fn err(@self, msg: &str) { - self.emit.emit(None, msg, error); + self.emit.emit(None, msg, Error); self.bump_err_count(); } pub fn bump_err_count(@self) { @@ -100,10 +100,10 @@ impl Handler { self.fatal(s); } pub fn warn(@self, msg: &str) { - self.emit.emit(None, msg, warning); + self.emit.emit(None, msg, Warning); } pub fn note(@self, msg: &str) { - self.emit.emit(None, msg, note); + self.emit.emit(None, msg, Note); } pub fn bug(@self, msg: &str) -> ! { self.fatal(ice_msg(msg)); @@ -114,7 +114,7 @@ impl Handler { pub fn emit(@self, cmsp: Option<(&codemap::CodeMap, Span)>, msg: &str, - lvl: level) { + lvl: Level) { self.emit.emit(cmsp, msg, lvl); } } @@ -145,28 +145,30 @@ pub fn mk_handler(emitter: Option<@Emitter>) -> @Handler { } #[deriving(Eq)] -pub enum level { - fatal, - error, - warning, - note, +pub enum Level { + Fatal, + Error, + Warning, + Note, } -fn diagnosticstr(lvl: level) -> ~str { - match lvl { - fatal => ~"error", - error => ~"error", - warning => ~"warning", - note => ~"note" +impl ToStr for Level { + fn to_str(&self) -> ~str { + match *self { + Fatal | Error => ~"error", + Warning => ~"warning", + Note => ~"note" + } } } -fn diagnosticcolor(lvl: level) -> term::color::Color { - match lvl { - fatal => term::color::BRIGHT_RED, - error => term::color::BRIGHT_RED, - warning => term::color::BRIGHT_YELLOW, - note => term::color::BRIGHT_GREEN +impl Level { + fn color(self) -> term::color::Color { + match self { + Fatal | Error => term::color::BRIGHT_RED, + Warning => term::color::BRIGHT_YELLOW, + Note => term::color::BRIGHT_GREEN + } } } @@ -212,15 +214,15 @@ fn print_maybe_styled(msg: &str, color: term::attr::Attr) { } } -fn print_diagnostic(topic: &str, lvl: level, msg: &str) { +fn print_diagnostic(topic: &str, lvl: Level, msg: &str) { let mut stderr = io::stderr(); if !topic.is_empty() { write!(&mut stderr as &mut io::Writer, "{} ", topic); } - print_maybe_styled(format!("{}: ", diagnosticstr(lvl)), - term::attr::ForegroundColor(diagnosticcolor(lvl))); + print_maybe_styled(format!("{}: ", lvl.to_str()), + term::attr::ForegroundColor(lvl.color())); print_maybe_styled(format!("{}\n", msg), term::attr::Bold); } @@ -230,7 +232,7 @@ impl Emitter for DefaultEmitter { fn emit(&self, cmsp: Option<(&codemap::CodeMap, Span)>, msg: &str, - lvl: level) { + lvl: Level) { match cmsp { Some((cm, sp)) => { let sp = cm.adjust_span(sp); @@ -247,7 +249,7 @@ impl Emitter for DefaultEmitter { fn highlight_lines(cm: &codemap::CodeMap, sp: Span, - lvl: level, + lvl: Level, lines: &codemap::FileLines) { let fm = lines.file; let mut err = io::stderr(); @@ -308,7 +310,7 @@ fn highlight_lines(cm: &codemap::CodeMap, let num_squigglies = hi.col.to_uint()-lo.col.to_uint()-1u; num_squigglies.times(|| s.push_char('~')); } - print_maybe_styled(s + "\n", term::attr::ForegroundColor(diagnosticcolor(lvl))); + print_maybe_styled(s + "\n", term::attr::ForegroundColor(lvl.color())); } } @@ -319,10 +321,10 @@ fn print_macro_backtrace(cm: &codemap::CodeMap, sp: Span) { codemap::MacroAttribute => ("#[", "]"), codemap::MacroBang => ("", "!") }; - print_diagnostic(ss, note, + print_diagnostic(ss, Note, format!("in expansion of {}{}{}", pre, ei.callee.name, post)); let ss = cm.span_to_str(ei.call_site); - print_diagnostic(ss, note, "expansion site"); + print_diagnostic(ss, Note, "expansion site"); print_macro_backtrace(cm, ei.call_site); } } diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index 0d78acadcae..e5145d37278 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -37,7 +37,7 @@ fn next_state(s: State) -> Option<State> { } } -pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { let mut p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), @@ -50,7 +50,7 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) let mut cons = ~""; let mut volatile = false; let mut alignstack = false; - let mut dialect = ast::asm_att; + let mut dialect = ast::AsmAtt; let mut state = Asm; @@ -139,7 +139,7 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) } else if "alignstack" == option { alignstack = true; } else if "intel" == option { - dialect = ast::asm_intel; + dialect = ast::AsmIntel; } if p.token == token::COMMA { @@ -187,7 +187,7 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) MRExpr(@ast::Expr { id: ast::DUMMY_NODE_ID, - node: ast::ExprInlineAsm(ast::inline_asm { + node: ast::ExprInlineAsm(ast::InlineAsm { asm: asm, asm_str_style: asm_str_style.unwrap(), clobbers: cons.to_managed(), diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index cbd7e7ca0ee..76135f31e31 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -25,9 +25,9 @@ use std::hashmap::HashMap; // // MacResult, NormalTT, IdentTT // -// also note that ast::mac used to have a bunch of extraneous cases and +// also note that ast::Mac used to have a bunch of extraneous cases and // is now probably a redundant AST node, can be merged with -// ast::mac_invoc_tt. +// ast::MacInvocTT. pub struct MacroDef { name: @str, @@ -35,7 +35,7 @@ pub struct MacroDef { } pub type ItemDecorator = - fn(&ExtCtxt, Span, @ast::MetaItem, ~[@ast::item]) -> ~[@ast::item]; + fn(&ExtCtxt, Span, @ast::MetaItem, ~[@ast::Item]) -> ~[@ast::Item]; pub struct SyntaxExpanderTT { expander: SyntaxExpanderTTExpander, @@ -46,13 +46,13 @@ pub trait SyntaxExpanderTTTrait { fn expand(&self, ecx: &mut ExtCtxt, span: Span, - token_tree: &[ast::token_tree], + token_tree: &[ast::TokenTree], context: ast::SyntaxContext) -> MacResult; } pub type SyntaxExpanderTTFunNoCtxt = - fn(ecx: &mut ExtCtxt, span: codemap::Span, token_tree: &[ast::token_tree]) + fn(ecx: &mut ExtCtxt, span: codemap::Span, token_tree: &[ast::TokenTree]) -> MacResult; enum SyntaxExpanderTTExpander { @@ -63,7 +63,7 @@ impl SyntaxExpanderTTTrait for SyntaxExpanderTT { fn expand(&self, ecx: &mut ExtCtxt, span: Span, - token_tree: &[ast::token_tree], + token_tree: &[ast::TokenTree], _: ast::SyntaxContext) -> MacResult { match self.expander { @@ -89,7 +89,7 @@ pub trait SyntaxExpanderTTItemTrait { cx: &mut ExtCtxt, sp: Span, ident: ast::Ident, - token_tree: ~[ast::token_tree], + token_tree: ~[ast::TokenTree], context: ast::SyntaxContext) -> MacResult; } @@ -99,7 +99,7 @@ impl SyntaxExpanderTTItemTrait for SyntaxExpanderTTItem { cx: &mut ExtCtxt, sp: Span, ident: ast::Ident, - token_tree: ~[ast::token_tree], + token_tree: ~[ast::TokenTree], context: ast::SyntaxContext) -> MacResult { match self.expander { @@ -114,21 +114,21 @@ impl SyntaxExpanderTTItemTrait for SyntaxExpanderTTItem { } pub type SyntaxExpanderTTItemFun = - fn(&mut ExtCtxt, Span, ast::Ident, ~[ast::token_tree], ast::SyntaxContext) + fn(&mut ExtCtxt, Span, ast::Ident, ~[ast::TokenTree], ast::SyntaxContext) -> MacResult; pub type SyntaxExpanderTTItemFunNoCtxt = - fn(&mut ExtCtxt, Span, ast::Ident, ~[ast::token_tree]) -> MacResult; + fn(&mut ExtCtxt, Span, ast::Ident, ~[ast::TokenTree]) -> MacResult; pub trait AnyMacro { fn make_expr(&self) -> @ast::Expr; - fn make_items(&self) -> SmallVector<@ast::item>; + fn make_items(&self) -> SmallVector<@ast::Item>; fn make_stmt(&self) -> @ast::Stmt; } pub enum MacResult { MRExpr(@ast::Expr), - MRItem(@ast::item), + MRItem(@ast::Item), MRAny(@AnyMacro), MRDef(MacroDef), } @@ -393,15 +393,15 @@ impl ExtCtxt { pub fn expr_to_str(cx: &ExtCtxt, expr: @ast::Expr, err_msg: &str) -> (@str, ast::StrStyle) { match expr.node { - ast::ExprLit(l) => match l.node { - ast::lit_str(s, style) => (s, style), - _ => cx.span_fatal(l.span, err_msg) - }, - _ => cx.span_fatal(expr.span, err_msg) + ast::ExprLit(l) => match l.node { + ast::LitStr(s, style) => (s, style), + _ => cx.span_fatal(l.span, err_msg) + }, + _ => cx.span_fatal(expr.span, err_msg) } } -pub fn check_zero_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree], +pub fn check_zero_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree], name: &str) { if tts.len() != 0 { cx.span_fatal(sp, format!("{} takes no arguments", name)); @@ -410,7 +410,7 @@ pub fn check_zero_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree], pub fn get_single_str_from_tts(cx: &ExtCtxt, sp: Span, - tts: &[ast::token_tree], + tts: &[ast::TokenTree], name: &str) -> @str { if tts.len() != 1 { @@ -418,15 +418,15 @@ pub fn get_single_str_from_tts(cx: &ExtCtxt, } match tts[0] { - ast::tt_tok(_, token::LIT_STR(ident)) - | ast::tt_tok(_, token::LIT_STR_RAW(ident, _)) => cx.str_of(ident), + ast::TTTok(_, token::LIT_STR(ident)) + | ast::TTTok(_, token::LIT_STR_RAW(ident, _)) => cx.str_of(ident), _ => cx.span_fatal(sp, format!("{} requires a string.", name)), } } pub fn get_exprs_from_tts(cx: &ExtCtxt, sp: Span, - tts: &[ast::token_tree]) -> ~[@ast::Expr] { + tts: &[ast::TokenTree]) -> ~[@ast::Expr] { let mut p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.to_owned()); diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 481472e8f0b..85cda0bd1ae 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -15,7 +15,7 @@ use ast_util; use codemap::{Span, respan, DUMMY_SP}; use ext::base::ExtCtxt; use ext::quote::rt::*; -use fold::ast_fold; +use fold::Folder; use opt_vec; use opt_vec::OptVec; @@ -43,9 +43,9 @@ pub trait AstBuilder { -> ast::Path; // types - fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::mt; + fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy; - fn ty(&self, span: Span, ty: ast::ty_) -> P<ast::Ty>; + fn ty(&self, span: Span, ty: ast::Ty_) -> P<ast::Ty>; fn ty_path(&self, ast::Path, Option<OptVec<ast::TyParamBound>>) -> P<ast::Ty>; fn ty_ident(&self, span: Span, idents: ast::Ident) -> P<ast::Ty>; @@ -67,7 +67,7 @@ pub trait AstBuilder { fn typaram(&self, id: ast::Ident, bounds: OptVec<ast::TyParamBound>) -> ast::TyParam; - fn trait_ref(&self, path: ast::Path) -> ast::trait_ref; + fn trait_ref(&self, path: ast::Path) -> ast::TraitRef; fn typarambound(&self, path: ast::Path) -> ast::TyParamBound; fn lifetime(&self, span: Span, ident: ast::Ident) -> ast::Lifetime; @@ -86,7 +86,7 @@ pub trait AstBuilder { fn block(&self, span: Span, stmts: ~[@ast::Stmt], expr: Option<@ast::Expr>) -> P<ast::Block>; fn block_expr(&self, expr: @ast::Expr) -> P<ast::Block>; fn block_all(&self, span: Span, - view_items: ~[ast::view_item], + view_items: ~[ast::ViewItem], stmts: ~[@ast::Stmt], expr: Option<@ast::Expr>) -> P<ast::Block>; @@ -119,7 +119,7 @@ pub trait AstBuilder { fn expr_struct(&self, span: Span, path: ast::Path, fields: ~[ast::Field]) -> @ast::Expr; fn expr_struct_ident(&self, span: Span, id: ast::Ident, fields: ~[ast::Field]) -> @ast::Expr; - fn expr_lit(&self, sp: Span, lit: ast::lit_) -> @ast::Expr; + fn expr_lit(&self, sp: Span, lit: ast::Lit_) -> @ast::Expr; fn expr_uint(&self, span: Span, i: uint) -> @ast::Expr; fn expr_int(&self, sp: Span, i: int) -> @ast::Expr; @@ -160,7 +160,7 @@ pub trait AstBuilder { cond: @ast::Expr, then: @ast::Expr, els: Option<@ast::Expr>) -> @ast::Expr; fn lambda_fn_decl(&self, span: Span, - fn_decl: P<ast::fn_decl>, blk: P<ast::Block>) -> @ast::Expr; + fn_decl: P<ast::FnDecl>, blk: P<ast::Block>) -> @ast::Expr; fn lambda(&self, span: Span, ids: ~[ast::Ident], blk: P<ast::Block>) -> @ast::Expr; fn lambda0(&self, span: Span, blk: P<ast::Block>) -> @ast::Expr; @@ -176,64 +176,64 @@ pub trait AstBuilder { // items fn item(&self, span: Span, - name: Ident, attrs: ~[ast::Attribute], node: ast::item_) -> @ast::item; + name: Ident, attrs: ~[ast::Attribute], node: ast::Item_) -> @ast::Item; - fn arg(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::arg; + fn arg(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::Arg; // XXX unused self - fn fn_decl(&self, inputs: ~[ast::arg], output: P<ast::Ty>) -> P<ast::fn_decl>; + fn fn_decl(&self, inputs: ~[ast::Arg], output: P<ast::Ty>) -> P<ast::FnDecl>; fn item_fn_poly(&self, span: Span, name: Ident, - inputs: ~[ast::arg], + inputs: ~[ast::Arg], output: P<ast::Ty>, generics: Generics, - body: P<ast::Block>) -> @ast::item; + body: P<ast::Block>) -> @ast::Item; fn item_fn(&self, span: Span, name: Ident, - inputs: ~[ast::arg], + inputs: ~[ast::Arg], output: P<ast::Ty>, - body: P<ast::Block>) -> @ast::item; + body: P<ast::Block>) -> @ast::Item; - fn variant(&self, span: Span, name: Ident, tys: ~[P<ast::Ty>]) -> ast::variant; + fn variant(&self, span: Span, name: Ident, tys: ~[P<ast::Ty>]) -> ast::Variant; fn item_enum_poly(&self, span: Span, name: Ident, - enum_definition: ast::enum_def, - generics: Generics) -> @ast::item; - fn item_enum(&self, span: Span, name: Ident, enum_def: ast::enum_def) -> @ast::item; + enum_definition: ast::EnumDef, + generics: Generics) -> @ast::Item; + fn item_enum(&self, span: Span, name: Ident, enum_def: ast::EnumDef) -> @ast::Item; fn item_struct_poly(&self, span: Span, name: Ident, - struct_def: ast::struct_def, - generics: Generics) -> @ast::item; - fn item_struct(&self, span: Span, name: Ident, struct_def: ast::struct_def) -> @ast::item; + struct_def: ast::StructDef, + generics: Generics) -> @ast::Item; + fn item_struct(&self, span: Span, name: Ident, struct_def: ast::StructDef) -> @ast::Item; fn item_mod(&self, span: Span, name: Ident, attrs: ~[ast::Attribute], - vi: ~[ast::view_item], items: ~[@ast::item]) -> @ast::item; + vi: ~[ast::ViewItem], items: ~[@ast::Item]) -> @ast::Item; fn item_ty_poly(&self, span: Span, name: Ident, ty: P<ast::Ty>, - generics: Generics) -> @ast::item; - fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> @ast::item; + generics: Generics) -> @ast::Item; + fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> @ast::Item; fn attribute(&self, sp: Span, mi: @ast::MetaItem) -> ast::Attribute; fn meta_word(&self, sp: Span, w: @str) -> @ast::MetaItem; fn meta_list(&self, sp: Span, name: @str, mis: ~[@ast::MetaItem]) -> @ast::MetaItem; - fn meta_name_value(&self, sp: Span, name: @str, value: ast::lit_) -> @ast::MetaItem; + fn meta_name_value(&self, sp: Span, name: @str, value: ast::Lit_) -> @ast::MetaItem; fn view_use(&self, sp: Span, - vis: ast::visibility, vp: ~[@ast::view_path]) -> ast::view_item; - fn view_use_list(&self, sp: Span, vis: ast::visibility, - path: ~[ast::Ident], imports: &[ast::Ident]) -> ast::view_item; + vis: ast::Visibility, vp: ~[@ast::ViewPath]) -> ast::ViewItem; + fn view_use_list(&self, sp: Span, vis: ast::Visibility, + path: ~[ast::Ident], imports: &[ast::Ident]) -> ast::ViewItem; fn view_use_glob(&self, sp: Span, - vis: ast::visibility, path: ~[ast::Ident]) -> ast::view_item; + vis: ast::Visibility, path: ~[ast::Ident]) -> ast::ViewItem; } impl AstBuilder for ExtCtxt { @@ -274,14 +274,14 @@ impl AstBuilder for ExtCtxt { } } - fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::mt { - ast::mt { + fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy { + ast::MutTy { ty: ty, mutbl: mutbl } } - fn ty(&self, span: Span, ty: ast::ty_) -> P<ast::Ty> { + fn ty(&self, span: Span, ty: ast::Ty_) -> P<ast::Ty> { P(ast::Ty { id: ast::DUMMY_NODE_ID, span: span, @@ -292,7 +292,7 @@ impl AstBuilder for ExtCtxt { fn ty_path(&self, path: ast::Path, bounds: Option<OptVec<ast::TyParamBound>>) -> P<ast::Ty> { self.ty(path.span, - ast::ty_path(path, bounds, ast::DUMMY_NODE_ID)) + ast::TyPath(path, bounds, ast::DUMMY_NODE_ID)) } // Might need to take bounds as an argument in the future, if you ever want @@ -309,15 +309,15 @@ impl AstBuilder for ExtCtxt { mutbl: ast::Mutability) -> P<ast::Ty> { self.ty(span, - ast::ty_rptr(lifetime, self.ty_mt(ty, mutbl))) + ast::TyRptr(lifetime, self.ty_mt(ty, mutbl))) } fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty> { - self.ty(span, ast::ty_uniq(ty)) + self.ty(span, ast::TyUniq(ty)) } fn ty_box(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty> { - self.ty(span, ast::ty_box(ty)) + self.ty(span, ast::TyBox(ty)) } fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty> { @@ -336,19 +336,19 @@ impl AstBuilder for ExtCtxt { fn ty_field_imm(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::TypeField { ast::TypeField { ident: name, - mt: ast::mt { ty: ty, mutbl: ast::MutImmutable }, + mt: ast::MutTy { ty: ty, mutbl: ast::MutImmutable }, span: span, } } fn ty_infer(&self, span: Span) -> P<ast::Ty> { - self.ty(span, ast::ty_infer) + self.ty(span, ast::TyInfer) } fn ty_nil(&self) -> P<ast::Ty> { P(ast::Ty { id: ast::DUMMY_NODE_ID, - node: ast::ty_nil, + node: ast::TyNil, span: DUMMY_SP, }) } @@ -381,8 +381,8 @@ impl AstBuilder for ExtCtxt { } } - fn trait_ref(&self, path: ast::Path) -> ast::trait_ref { - ast::trait_ref { + fn trait_ref(&self, path: ast::Path) -> ast::TraitRef { + ast::TraitRef { path: path, ref_id: ast::DUMMY_NODE_ID } @@ -449,7 +449,7 @@ impl AstBuilder for ExtCtxt { } fn block_all(&self, span: Span, - view_items: ~[ast::view_item], + view_items: ~[ast::ViewItem], stmts: ~[@ast::Stmt], expr: Option<@ast::Expr>) -> P<ast::Block> { P(ast::Block { @@ -541,20 +541,20 @@ impl AstBuilder for ExtCtxt { self.expr_struct(span, self.path_ident(span, id), fields) } - fn expr_lit(&self, sp: Span, lit: ast::lit_) -> @ast::Expr { + fn expr_lit(&self, sp: Span, lit: ast::Lit_) -> @ast::Expr { self.expr(sp, ast::ExprLit(@respan(sp, lit))) } fn expr_uint(&self, span: Span, i: uint) -> @ast::Expr { - self.expr_lit(span, ast::lit_uint(i as u64, ast::ty_u)) + self.expr_lit(span, ast::LitUint(i as u64, ast::TyU)) } fn expr_int(&self, sp: Span, i: int) -> @ast::Expr { - self.expr_lit(sp, ast::lit_int(i as i64, ast::ty_i)) + self.expr_lit(sp, ast::LitInt(i as i64, ast::TyI)) } fn expr_u8(&self, sp: Span, u: u8) -> @ast::Expr { - self.expr_lit(sp, ast::lit_uint(u as u64, ast::ty_u8)) + self.expr_lit(sp, ast::LitUint(u as u64, ast::TyU8)) } fn expr_bool(&self, sp: Span, value: bool) -> @ast::Expr { - self.expr_lit(sp, ast::lit_bool(value)) + self.expr_lit(sp, ast::LitBool(value)) } fn expr_vstore(&self, sp: Span, expr: @ast::Expr, vst: ast::ExprVstore) -> @ast::Expr { @@ -570,7 +570,7 @@ impl AstBuilder for ExtCtxt { self.expr_vstore(sp, self.expr_vec(sp, exprs), ast::ExprVstoreSlice) } fn expr_str(&self, sp: Span, s: @str) -> @ast::Expr { - self.expr_lit(sp, ast::lit_str(s, ast::CookedStr)) + self.expr_lit(sp, ast::LitStr(s, ast::CookedStr)) } fn expr_str_uniq(&self, sp: Span, s: @str) -> @ast::Expr { self.expr_vstore(sp, self.expr_str(sp, s), ast::ExprVstoreUniq) @@ -675,7 +675,7 @@ impl AstBuilder for ExtCtxt { } fn lambda_fn_decl(&self, span: Span, - fn_decl: P<ast::fn_decl>, blk: P<ast::Block>) -> @ast::Expr { + fn_decl: P<ast::FnDecl>, blk: P<ast::Block>) -> @ast::Expr { self.expr(span, ast::ExprFnBlock(fn_decl, blk)) } fn lambda(&self, span: Span, ids: ~[ast::Ident], blk: P<ast::Block>) -> @ast::Expr { @@ -715,9 +715,9 @@ impl AstBuilder for ExtCtxt { self.lambda1(span, self.block(span, stmts, None), ident) } - fn arg(&self, span: Span, ident: ast::Ident, ty: P<ast::Ty>) -> ast::arg { + fn arg(&self, span: Span, ident: ast::Ident, ty: P<ast::Ty>) -> ast::Arg { let arg_pat = self.pat_ident(span, ident); - ast::arg { + ast::Arg { ty: ty, pat: arg_pat, id: ast::DUMMY_NODE_ID @@ -725,51 +725,51 @@ impl AstBuilder for ExtCtxt { } // XXX unused self - fn fn_decl(&self, inputs: ~[ast::arg], output: P<ast::Ty>) -> P<ast::fn_decl> { - P(ast::fn_decl { + fn fn_decl(&self, inputs: ~[ast::Arg], output: P<ast::Ty>) -> P<ast::FnDecl> { + P(ast::FnDecl { inputs: inputs, output: output, - cf: ast::return_val, + cf: ast::Return, variadic: false }) } fn item(&self, span: Span, - name: Ident, attrs: ~[ast::Attribute], node: ast::item_) -> @ast::item { + name: Ident, attrs: ~[ast::Attribute], node: ast::Item_) -> @ast::Item { // XXX: Would be nice if our generated code didn't violate // Rust coding conventions - @ast::item { ident: name, + @ast::Item { ident: name, attrs: attrs, id: ast::DUMMY_NODE_ID, node: node, - vis: ast::inherited, + vis: ast::Inherited, span: span } } fn item_fn_poly(&self, span: Span, name: Ident, - inputs: ~[ast::arg], + inputs: ~[ast::Arg], output: P<ast::Ty>, generics: Generics, - body: P<ast::Block>) -> @ast::item { + body: P<ast::Block>) -> @ast::Item { self.item(span, name, ~[], - ast::item_fn(self.fn_decl(inputs, output), - ast::impure_fn, - AbiSet::Rust(), - generics, - body)) + ast::ItemFn(self.fn_decl(inputs, output), + ast::ImpureFn, + AbiSet::Rust(), + generics, + body)) } fn item_fn(&self, span: Span, name: Ident, - inputs: ~[ast::arg], + inputs: ~[ast::Arg], output: P<ast::Ty>, body: P<ast::Block> - ) -> @ast::item { + ) -> @ast::Item { self.item_fn_poly( span, name, @@ -779,40 +779,36 @@ impl AstBuilder for ExtCtxt { body) } - fn variant(&self, span: Span, name: Ident, tys: ~[P<ast::Ty>]) -> ast::variant { + fn variant(&self, span: Span, name: Ident, tys: ~[P<ast::Ty>]) -> ast::Variant { let args = tys.move_iter().map(|ty| { - ast::variant_arg { ty: ty, id: ast::DUMMY_NODE_ID } + ast::VariantArg { ty: ty, id: ast::DUMMY_NODE_ID } }).collect(); respan(span, - ast::variant_ { + ast::Variant_ { name: name, attrs: ~[], - kind: ast::tuple_variant_kind(args), + kind: ast::TupleVariantKind(args), id: ast::DUMMY_NODE_ID, disr_expr: None, - vis: ast::public + vis: ast::Public }) } fn item_enum_poly(&self, span: Span, name: Ident, - enum_definition: ast::enum_def, - generics: Generics) -> @ast::item { - self.item(span, name, ~[], ast::item_enum(enum_definition, generics)) + enum_definition: ast::EnumDef, + generics: Generics) -> @ast::Item { + self.item(span, name, ~[], ast::ItemEnum(enum_definition, generics)) } fn item_enum(&self, span: Span, name: Ident, - enum_definition: ast::enum_def) -> @ast::item { + enum_definition: ast::EnumDef) -> @ast::Item { self.item_enum_poly(span, name, enum_definition, ast_util::empty_generics()) } - fn item_struct( - &self, - span: Span, - name: Ident, - struct_def: ast::struct_def - ) -> @ast::item { + fn item_struct(&self, span: Span, name: Ident, + struct_def: ast::StructDef) -> @ast::Item { self.item_struct_poly( span, name, @@ -821,25 +817,20 @@ impl AstBuilder for ExtCtxt { ) } - fn item_struct_poly( - &self, - span: Span, - name: Ident, - struct_def: ast::struct_def, - generics: Generics - ) -> @ast::item { - self.item(span, name, ~[], ast::item_struct(@struct_def, generics)) + fn item_struct_poly(&self, span: Span, name: Ident, + struct_def: ast::StructDef, generics: Generics) -> @ast::Item { + self.item(span, name, ~[], ast::ItemStruct(@struct_def, generics)) } fn item_mod(&self, span: Span, name: Ident, attrs: ~[ast::Attribute], - vi: ~[ast::view_item], - items: ~[@ast::item]) -> @ast::item { + vi: ~[ast::ViewItem], + items: ~[@ast::Item]) -> @ast::Item { self.item( span, name, attrs, - ast::item_mod(ast::_mod { + ast::ItemMod(ast::Mod { view_items: vi, items: items, }) @@ -847,11 +838,11 @@ impl AstBuilder for ExtCtxt { } fn item_ty_poly(&self, span: Span, name: Ident, ty: P<ast::Ty>, - generics: Generics) -> @ast::item { - self.item(span, name, ~[], ast::item_ty(ty, generics)) + generics: Generics) -> @ast::Item { + self.item(span, name, ~[], ast::ItemTy(ty, generics)) } - fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> @ast::item { + fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> @ast::Item { self.item_ty_poly(span, name, ty, ast_util::empty_generics()) } @@ -869,38 +860,38 @@ impl AstBuilder for ExtCtxt { fn meta_list(&self, sp: Span, name: @str, mis: ~[@ast::MetaItem]) -> @ast::MetaItem { @respan(sp, ast::MetaList(name, mis)) } - fn meta_name_value(&self, sp: Span, name: @str, value: ast::lit_) -> @ast::MetaItem { + fn meta_name_value(&self, sp: Span, name: @str, value: ast::Lit_) -> @ast::MetaItem { @respan(sp, ast::MetaNameValue(name, respan(sp, value))) } fn view_use(&self, sp: Span, - vis: ast::visibility, vp: ~[@ast::view_path]) -> ast::view_item { - ast::view_item { - node: ast::view_item_use(vp), + vis: ast::Visibility, vp: ~[@ast::ViewPath]) -> ast::ViewItem { + ast::ViewItem { + node: ast::ViewItemUse(vp), attrs: ~[], vis: vis, span: sp } } - fn view_use_list(&self, sp: Span, vis: ast::visibility, - path: ~[ast::Ident], imports: &[ast::Ident]) -> ast::view_item { + fn view_use_list(&self, sp: Span, vis: ast::Visibility, + path: ~[ast::Ident], imports: &[ast::Ident]) -> ast::ViewItem { let imports = imports.map(|id| { - respan(sp, ast::path_list_ident_ { name: *id, id: ast::DUMMY_NODE_ID }) + respan(sp, ast::PathListIdent_ { name: *id, id: ast::DUMMY_NODE_ID }) }); self.view_use(sp, vis, ~[@respan(sp, - ast::view_path_list(self.path(sp, path), - imports, - ast::DUMMY_NODE_ID))]) + ast::ViewPathList(self.path(sp, path), + imports, + ast::DUMMY_NODE_ID))]) } fn view_use_glob(&self, sp: Span, - vis: ast::visibility, path: ~[ast::Ident]) -> ast::view_item { + vis: ast::Visibility, path: ~[ast::Ident]) -> ast::ViewItem { self.view_use(sp, vis, ~[@respan(sp, - ast::view_path_glob(self.path(sp, path), ast::DUMMY_NODE_ID))]) + ast::ViewPathGlob(self.path(sp, path), ast::DUMMY_NODE_ID))]) } } @@ -908,7 +899,7 @@ struct Duplicator<'a> { cx: &'a ExtCtxt, } -impl<'a> ast_fold for Duplicator<'a> { +impl<'a> Folder for Duplicator<'a> { fn new_id(&mut self, _: NodeId) -> NodeId { ast::DUMMY_NODE_ID } diff --git a/src/libsyntax/ext/bytes.rs b/src/libsyntax/ext/bytes.rs index 1878f6f3c3c..945e7c0d666 100644 --- a/src/libsyntax/ext/bytes.rs +++ b/src/libsyntax/ext/bytes.rs @@ -18,7 +18,7 @@ use ext::build::AstBuilder; use std::char; -pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { +pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { // Gather all argument expressions let exprs = get_exprs_from_tts(cx, sp, tts); let mut bytes = ~[]; @@ -28,14 +28,14 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> // expression is a literal ast::ExprLit(lit) => match lit.node { // string literal, push each byte to vector expression - ast::lit_str(s, _) => { + ast::LitStr(s, _) => { for byte in s.bytes() { bytes.push(cx.expr_u8(expr.span, byte)); } } // u8 literal, push to vector expression - ast::lit_uint(v, ast::ty_u8) => { + ast::LitUint(v, ast::TyU8) => { if v > 0xFF { cx.span_err(expr.span, "Too large u8 literal in bytes!") } else { @@ -44,7 +44,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> } // integer literal, push to vector expression - ast::lit_int_unsuffixed(v) => { + ast::LitIntUnsuffixed(v) => { if v > 0xFF { cx.span_err(expr.span, "Too large integer literal in bytes!") } else if v < 0 { @@ -55,7 +55,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> } // char literal, push to vector expression - ast::lit_char(v) => { + ast::LitChar(v) => { if char::from_u32(v).unwrap().is_ascii() { bytes.push(cx.expr_u8(expr.span, v as u8)); } else { diff --git a/src/libsyntax/ext/cfg.rs b/src/libsyntax/ext/cfg.rs index f3f44f4fa3f..9af295c0b11 100644 --- a/src/libsyntax/ext/cfg.rs +++ b/src/libsyntax/ext/cfg.rs @@ -23,9 +23,9 @@ use attr; use attr::*; use parse; use parse::token; -use parse::attr::parser_attr; +use parse::attr::ParserAttr; -pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { +pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { let mut p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.to_owned()); diff --git a/src/libsyntax/ext/concat.rs b/src/libsyntax/ext/concat.rs index d8be7dedef2..251492141c8 100644 --- a/src/libsyntax/ext/concat.rs +++ b/src/libsyntax/ext/concat.rs @@ -17,7 +17,7 @@ use ext::build::AstBuilder; pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, sp: codemap::Span, - tts: &[ast::token_tree]) -> base::MacResult { + tts: &[ast::TokenTree]) -> base::MacResult { let es = base::get_exprs_from_tts(cx, sp, tts); let mut accumulator = ~""; for e in es.move_iter() { @@ -25,26 +25,24 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, match e.node { ast::ExprLit(lit) => { match lit.node { - ast::lit_str(s, _) | - ast::lit_float(s, _) | - ast::lit_float_unsuffixed(s) => { + ast::LitStr(s, _) | ast::LitFloat(s, _) + | ast::LitFloatUnsuffixed(s) => { accumulator.push_str(s); } - ast::lit_char(c) => { + ast::LitChar(c) => { accumulator.push_char(char::from_u32(c).unwrap()); } - ast::lit_int(i, _) | - ast::lit_int_unsuffixed(i) => { + ast::LitInt(i, _) | ast::LitIntUnsuffixed(i) => { accumulator.push_str(format!("{}", i)); } - ast::lit_uint(u, _) => { + ast::LitUint(u, _) => { accumulator.push_str(format!("{}", u)); } - ast::lit_nil => {} - ast::lit_bool(b) => { + ast::LitNil => {} + ast::LitBool(b) => { accumulator.push_str(format!("{}", b)); } - ast::lit_binary(..) => { + ast::LitBinary(..) => { cx.span_err(e.span, "cannot concatenate a binary literal"); } } diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index 0cb3e781c26..0d053bb1d12 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -16,18 +16,18 @@ use opt_vec; use parse::token; use parse::token::{str_to_ident}; -pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { let mut res_str = ~""; for (i, e) in tts.iter().enumerate() { if i & 1 == 1 { match *e { - ast::tt_tok(_, token::COMMA) => (), + ast::TTTok(_, token::COMMA) => (), _ => cx.span_fatal(sp, "concat_idents! expecting comma.") } } else { match *e { - ast::tt_tok(_, token::IDENT(ident,_)) => res_str.push_str(cx.str_of(ident)), + ast::TTTok(_, token::IDENT(ident,_)) => res_str.push_str(cx.str_of(ident)), _ => cx.span_fatal(sp, "concat_idents! requires ident args.") } } diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index c3c57082684..aa8dcc3981b 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, item, Expr}; +use ast::{MetaItem, Item, Expr}; use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; @@ -17,8 +17,8 @@ use ext::deriving::generic::*; pub fn expand_deriving_clone(cx: &ExtCtxt, span: Span, mitem: @MetaItem, - in_items: ~[@item]) - -> ~[@item] { + in_items: ~[@Item]) + -> ~[@Item] { let trait_def = TraitDef { cx: cx, span: span, @@ -45,8 +45,8 @@ pub fn expand_deriving_clone(cx: &ExtCtxt, pub fn expand_deriving_deep_clone(cx: &ExtCtxt, span: Span, mitem: @MetaItem, - in_items: ~[@item]) - -> ~[@item] { + in_items: ~[@Item]) + -> ~[@Item] { let trait_def = TraitDef { cx: cx, span: span, diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax/ext/deriving/cmp/eq.rs index f7b249fc8d8..99b5163214a 100644 --- a/src/libsyntax/ext/deriving/cmp/eq.rs +++ b/src/libsyntax/ext/deriving/cmp/eq.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, item, Expr}; +use ast::{MetaItem, Item, Expr}; use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; @@ -17,7 +17,7 @@ use ext::deriving::generic::*; pub fn expand_deriving_eq(cx: &ExtCtxt, span: Span, mitem: @MetaItem, - in_items: ~[@item]) -> ~[@item] { + in_items: ~[@Item]) -> ~[@Item] { // structures are equal if all fields are equal, and non equal, if // any fields are not equal or if the enum variants are different fn cs_eq(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr { diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index c1e4e1e2b64..8a2b11b798c 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -9,7 +9,7 @@ // except according to those terms. use ast; -use ast::{MetaItem, item, Expr}; +use ast::{MetaItem, Item, Expr}; use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; @@ -18,7 +18,7 @@ use ext::deriving::generic::*; pub fn expand_deriving_ord(cx: &ExtCtxt, span: Span, mitem: @MetaItem, - in_items: ~[@item]) -> ~[@item] { + in_items: ~[@Item]) -> ~[@Item] { macro_rules! md ( ($name:expr, $op:expr, $equal:expr) => { MethodDef { diff --git a/src/libsyntax/ext/deriving/cmp/totaleq.rs b/src/libsyntax/ext/deriving/cmp/totaleq.rs index 0b4d2659fd1..6a1aaeb2f9e 100644 --- a/src/libsyntax/ext/deriving/cmp/totaleq.rs +++ b/src/libsyntax/ext/deriving/cmp/totaleq.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, item, Expr}; +use ast::{MetaItem, Item, Expr}; use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; @@ -17,7 +17,7 @@ use ext::deriving::generic::*; pub fn expand_deriving_totaleq(cx: &ExtCtxt, span: Span, mitem: @MetaItem, - in_items: ~[@item]) -> ~[@item] { + in_items: ~[@Item]) -> ~[@Item] { fn cs_equals(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr { cs_and(|cx, span, _, _| cx.expr_bool(span, false), cx, span, substr) diff --git a/src/libsyntax/ext/deriving/cmp/totalord.rs b/src/libsyntax/ext/deriving/cmp/totalord.rs index 3c58bfa01a9..f1e360f20ba 100644 --- a/src/libsyntax/ext/deriving/cmp/totalord.rs +++ b/src/libsyntax/ext/deriving/cmp/totalord.rs @@ -9,7 +9,7 @@ // except according to those terms. use ast; -use ast::{MetaItem, item, Expr}; +use ast::{MetaItem, Item, Expr}; use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; @@ -19,7 +19,7 @@ use std::cmp::{Ordering, Equal, Less, Greater}; pub fn expand_deriving_totalord(cx: &ExtCtxt, span: Span, mitem: @MetaItem, - in_items: ~[@item]) -> ~[@item] { + in_items: ~[@Item]) -> ~[@Item] { let trait_def = TraitDef { cx: cx, span: span, diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index de995af9ae3..9272152e8d5 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -13,7 +13,7 @@ The compiler code necessary for #[deriving(Decodable)]. See encodable.rs for more. */ -use ast::{MetaItem, item, Expr, MutMutable, Ident}; +use ast::{MetaItem, Item, Expr, MutMutable, Ident}; use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; @@ -22,7 +22,7 @@ use ext::deriving::generic::*; pub fn expand_deriving_decodable(cx: &ExtCtxt, span: Span, mitem: @MetaItem, - in_items: ~[@item]) -> ~[@item] { + in_items: ~[@Item]) -> ~[@Item] { let trait_def = TraitDef { cx: cx, span: span, diff --git a/src/libsyntax/ext/deriving/default.rs b/src/libsyntax/ext/deriving/default.rs index ba2df120796..0ae3c6f4593 100644 --- a/src/libsyntax/ext/deriving/default.rs +++ b/src/libsyntax/ext/deriving/default.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, item, Expr}; +use ast::{MetaItem, Item, Expr}; use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; @@ -17,8 +17,8 @@ use ext::deriving::generic::*; pub fn expand_deriving_default(cx: &ExtCtxt, span: Span, mitem: @MetaItem, - in_items: ~[@item]) - -> ~[@item] { + in_items: ~[@Item]) + -> ~[@Item] { let trait_def = TraitDef { cx: cx, span: span, diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index a6cba59aea5..285bf86916e 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -75,7 +75,7 @@ would yield functions like: } */ -use ast::{MetaItem, item, Expr, MutImmutable, MutMutable}; +use ast::{MetaItem, Item, Expr, MutImmutable, MutMutable}; use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; @@ -84,7 +84,7 @@ use ext::deriving::generic::*; pub fn expand_deriving_encodable(cx: &ExtCtxt, span: Span, mitem: @MetaItem, - in_items: ~[@item]) -> ~[@item] { + in_items: ~[@Item]) -> ~[@Item] { let trait_def = TraitDef { cx: cx, span: span, diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index 234551ccb01..826d5381d47 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -126,7 +126,7 @@ When generating the `expr` for a call with `self == C0(a)` and `other == C0(b)`, the SubstructureFields is ~~~ -EnumMatching(0, <ast::variant for C0>, +EnumMatching(0, <ast::Variant for C0>, ~[FieldInfo { span: <span of int> name: None, @@ -138,7 +138,7 @@ EnumMatching(0, <ast::variant for C0>, For `C1 {x}` and `C1 {x}`, ~~~ -EnumMatching(1, <ast::variant for C1>, +EnumMatching(1, <ast::Variant for C1>, ~[FieldInfo { span: <span of x> name: Some(<ident of x>), @@ -150,9 +150,9 @@ EnumMatching(1, <ast::variant for C1>, For `C0(a)` and `C1 {x}` , ~~~ -EnumNonMatching(~[(0, <ast::variant for B0>, +EnumNonMatching(~[(0, <ast::Variant for B0>, ~[(<span of int>, None, <expr for &a>)]), - (1, <ast::variant for B1>, + (1, <ast::Variant for B1>, ~[(<span of x>, Some(<ident of x>), <expr for &other.x>)])]) ~~~ @@ -164,18 +164,18 @@ EnumNonMatching(~[(0, <ast::variant for B0>, A static method on the above would result in, ~~~~ -StaticStruct(<ast::struct_def of A>, Named(~[(<ident of x>, <span of x>)])) +StaticStruct(<ast::StructDef of A>, Named(~[(<ident of x>, <span of x>)])) -StaticStruct(<ast::struct_def of B>, Unnamed(~[<span of x>])) +StaticStruct(<ast::StructDef of B>, Unnamed(~[<span of x>])) -StaticEnum(<ast::enum_def of C>, ~[(<ident of C0>, Unnamed(~[<span of int>])), - (<ident of C1>, Named(~[(<ident of x>, <span of x>)]))]) +StaticEnum(<ast::EnumDef of C>, ~[(<ident of C0>, Unnamed(~[<span of int>])), + (<ident of C1>, Named(~[(<ident of x>, <span of x>)]))]) ~~~ */ use ast; -use ast::{P, enum_def, Expr, Ident, Generics, struct_def}; +use ast::{P, EnumDef, Expr, Ident, Generics, StructDef}; use ext::base::ExtCtxt; use ext::build::AstBuilder; @@ -274,23 +274,23 @@ pub enum StaticFields { pub enum SubstructureFields<'a> { Struct(~[FieldInfo]), /** - Matching variants of the enum: variant index, ast::variant, + Matching variants of the enum: variant index, ast::Variant, fields: the field name is only non-`None` in the case of a struct variant. */ - EnumMatching(uint, &'a ast::variant, ~[FieldInfo]), + EnumMatching(uint, &'a ast::Variant, ~[FieldInfo]), /** - non-matching variants of the enum, [(variant index, ast::variant, + non-matching variants of the enum, [(variant index, ast::Variant, [field span, field ident, fields])] (i.e. all fields for self are in the first tuple, for other1 are in the second tuple, etc.) */ - EnumNonMatching(&'a [(uint, P<ast::variant>, ~[(Span, Option<Ident>, @Expr)])]), + EnumNonMatching(&'a [(uint, P<ast::Variant>, ~[(Span, Option<Ident>, @Expr)])]), /// A static method where Self is a struct. - StaticStruct(&'a ast::struct_def, StaticFields), + StaticStruct(&'a ast::StructDef, StaticFields), /// A static method where Self is an enum. - StaticEnum(&'a ast::enum_def, ~[(Ident, StaticFields)]) + StaticEnum(&'a ast::EnumDef, ~[(Ident, StaticFields)]) } @@ -304,13 +304,13 @@ pub type CombineSubstructureFunc<'a> = /** Deal with non-matching enum variants, the arguments are a list -representing each variant: (variant index, ast::variant instance, +representing each variant: (variant index, ast::Variant instance, [variant fields]), and a list of the nonself args of the type */ pub type EnumNonMatchFunc<'a> = 'a |&ExtCtxt, Span, - &[(uint, P<ast::variant>, ~[(Span, Option<Ident>, @Expr)])], + &[(uint, P<ast::Variant>, ~[(Span, Option<Ident>, @Expr)])], &[@Expr]| -> @Expr; @@ -318,17 +318,17 @@ pub type EnumNonMatchFunc<'a> = impl<'a> TraitDef<'a> { pub fn expand(&self, _mitem: @ast::MetaItem, - in_items: ~[@ast::item]) -> ~[@ast::item] { + in_items: ~[@ast::Item]) -> ~[@ast::Item] { let mut result = ~[]; for item in in_items.iter() { result.push(*item); match item.node { - ast::item_struct(struct_def, ref generics) => { + ast::ItemStruct(struct_def, ref generics) => { result.push(self.expand_struct_def(struct_def, item.ident, generics)); } - ast::item_enum(ref enum_def, ref generics) => { + ast::ItemEnum(ref enum_def, ref generics) => { result.push(self.expand_enum_def(enum_def, item.ident, generics)); @@ -351,7 +351,7 @@ impl<'a> TraitDef<'a> { */ fn create_derived_impl(&self, type_ident: Ident, generics: &Generics, - methods: ~[@ast::method]) -> @ast::item { + methods: ~[@ast::Method]) -> @ast::Item { let cx = self.cx; let trait_path = self.path.to_path(cx, self.span, type_ident, generics); @@ -395,21 +395,19 @@ impl<'a> TraitDef<'a> { self.span, cx.meta_name_value(self.span, @"doc", - ast::lit_str(@"Automatically derived.", ast::CookedStr))); + ast::LitStr(@"Automatically derived.", ast::CookedStr))); cx.item( self.span, ::parse::token::special_idents::clownshoes_extensions, ~[doc_attr], - ast::item_impl(trait_generics, - Some(trait_ref), - self_type, - methods.map(|x| *x))) + ast::ItemImpl(trait_generics, Some(trait_ref), + self_type, methods.map(|x| *x))) } fn expand_struct_def(&self, - struct_def: &struct_def, + struct_def: &StructDef, type_ident: Ident, - generics: &Generics) -> @ast::item { + generics: &Generics) -> @ast::Item { let methods = self.methods.map(|method_def| { let (explicit_self, self_args, nonself_args, tys) = method_def.split_self_nonself_args(self, type_ident, generics); @@ -437,9 +435,9 @@ impl<'a> TraitDef<'a> { } fn expand_enum_def(&self, - enum_def: &enum_def, + enum_def: &EnumDef, type_ident: Ident, - generics: &Generics) -> @ast::item { + generics: &Generics) -> @ast::Item { let methods = self.methods.map(|method_def| { let (explicit_self, self_args, nonself_args, tys) = method_def.split_self_nonself_args(self, type_ident, generics); @@ -497,7 +495,7 @@ impl<'a> MethodDef<'a> { fn split_self_nonself_args(&self, trait_: &TraitDef, type_ident: Ident, generics: &Generics) - -> (ast::explicit_self, ~[@Expr], ~[@Expr], ~[(Ident, P<ast::Ty>)]) { + -> (ast::ExplicitSelf, ~[@Expr], ~[@Expr], ~[(Ident, P<ast::Ty>)]) { let mut self_args = ~[]; let mut nonself_args = ~[]; @@ -514,7 +512,7 @@ impl<'a> MethodDef<'a> { explicit_self } - None => codemap::respan(trait_.span, ast::sty_static), + None => codemap::respan(trait_.span, ast::SelfStatic), }; for (i, ty) in self.args.iter().enumerate() { @@ -545,9 +543,9 @@ impl<'a> MethodDef<'a> { fn create_method(&self, trait_: &TraitDef, type_ident: Ident, generics: &Generics, - explicit_self: ast::explicit_self, + explicit_self: ast::ExplicitSelf, arg_types: ~[(Ident, P<ast::Ty>)], - body: @Expr) -> @ast::method { + body: @Expr) -> @ast::Method { // create the generics that aren't for Self let fn_generics = self.generics.to_generics(trait_.cx, trait_.span, type_ident, generics); @@ -568,18 +566,18 @@ impl<'a> MethodDef<'a> { }; // Create the method. - @ast::method { + @ast::Method { ident: method_ident, attrs: attrs, generics: fn_generics, explicit_self: explicit_self, - purity: ast::impure_fn, + purity: ast::ImpureFn, decl: fn_decl, body: body_block, id: ast::DUMMY_NODE_ID, span: trait_.span, self_id: ast::DUMMY_NODE_ID, - vis: ast::inherited, + vis: ast::Inherited, } } @@ -606,7 +604,7 @@ impl<'a> MethodDef<'a> { */ fn expand_struct_method_body(&self, trait_: &TraitDef, - struct_def: &struct_def, + struct_def: &StructDef, type_ident: Ident, self_args: &[@Expr], nonself_args: &[@Expr]) @@ -665,7 +663,7 @@ impl<'a> MethodDef<'a> { fn expand_static_struct_method_body(&self, trait_: &TraitDef, - struct_def: &struct_def, + struct_def: &StructDef, type_ident: Ident, self_args: &[@Expr], nonself_args: &[@Expr]) @@ -706,7 +704,7 @@ impl<'a> MethodDef<'a> { */ fn expand_enum_method_body(&self, trait_: &TraitDef, - enum_def: &enum_def, + enum_def: &EnumDef, type_ident: Ident, self_args: &[@Expr], nonself_args: &[@Expr]) @@ -741,12 +739,12 @@ impl<'a> MethodDef<'a> { */ fn build_enum_match(&self, trait_: &TraitDef, - enum_def: &enum_def, + enum_def: &EnumDef, type_ident: Ident, self_args: &[@Expr], nonself_args: &[@Expr], matching: Option<uint>, - matches_so_far: &mut ~[(uint, P<ast::variant>, + matches_so_far: &mut ~[(uint, P<ast::Variant>, ~[(Span, Option<Ident>, @Expr)])], match_count: uint) -> @Expr { let cx = trait_.cx; @@ -891,7 +889,7 @@ impl<'a> MethodDef<'a> { fn expand_static_enum_method_body(&self, trait_: &TraitDef, - enum_def: &enum_def, + enum_def: &EnumDef, type_ident: Ident, self_args: &[@Expr], nonself_args: &[@Expr]) @@ -899,10 +897,10 @@ impl<'a> MethodDef<'a> { let summary = enum_def.variants.map(|v| { let ident = v.node.name; let summary = match v.node.kind { - ast::tuple_variant_kind(ref args) => { + ast::TupleVariantKind(ref args) => { Unnamed(args.map(|va| trait_.set_expn_info(va.ty.span))) } - ast::struct_variant_kind(struct_def) => { + ast::StructVariantKind(struct_def) => { trait_.summarise_struct(struct_def) } }; @@ -937,14 +935,14 @@ impl<'a> TraitDef<'a> { to_set } - fn summarise_struct(&self, struct_def: &struct_def) -> StaticFields { + fn summarise_struct(&self, struct_def: &StructDef) -> StaticFields { let mut named_idents = ~[]; let mut just_spans = ~[]; for field in struct_def.fields.iter(){ let sp = self.set_expn_info(field.span); match field.node.kind { - ast::named_field(ident, _) => named_idents.push((ident, sp)), - ast::unnamed_field => just_spans.push(sp), + ast::NamedField(ident, _) => named_idents.push((ident, sp)), + ast::UnnamedField => just_spans.push(sp), } } @@ -971,7 +969,7 @@ impl<'a> TraitDef<'a> { fn create_struct_pattern(&self, struct_ident: Ident, - struct_def: &struct_def, + struct_def: &StructDef, prefix: &str, mutbl: ast::Mutability) -> (@ast::Pat, ~[(Span, Option<Ident>, @Expr)]) { @@ -993,13 +991,13 @@ impl<'a> TraitDef<'a> { for (i, struct_field) in struct_def.fields.iter().enumerate() { let sp = self.set_expn_info(struct_field.span); let opt_id = match struct_field.node.kind { - ast::named_field(ident, _) if (struct_type == Unknown || - struct_type == Record) => { + ast::NamedField(ident, _) if (struct_type == Unknown || + struct_type == Record) => { struct_type = Record; Some(ident) } - ast::unnamed_field if (struct_type == Unknown || - struct_type == Tuple) => { + ast::UnnamedField if (struct_type == Unknown || + struct_type == Tuple) => { struct_type = Tuple; None } @@ -1030,14 +1028,14 @@ impl<'a> TraitDef<'a> { } fn create_enum_variant_pattern(&self, - variant: &ast::variant, + variant: &ast::Variant, prefix: &str, mutbl: ast::Mutability) -> (@ast::Pat, ~[(Span, Option<Ident>, @Expr)]) { let cx = self.cx; let variant_ident = variant.node.name; match variant.node.kind { - ast::tuple_variant_kind(ref variant_args) => { + ast::TupleVariantKind(ref variant_args) => { if variant_args.is_empty() { return (cx.pat_ident_binding_mode(variant.span, variant_ident, ast::BindByValue(ast::MutImmutable)), @@ -1061,7 +1059,7 @@ impl<'a> TraitDef<'a> { (cx.pat_enum(variant.span, matching_path, subpats), ident_expr) } - ast::struct_variant_kind(struct_def) => { + ast::StructVariantKind(struct_def) => { self.create_struct_pattern(variant_ident, struct_def, prefix, mutbl) } diff --git a/src/libsyntax/ext/deriving/iter_bytes.rs b/src/libsyntax/ext/deriving/iter_bytes.rs index 8b2ad95e45c..2bf69e34674 100644 --- a/src/libsyntax/ext/deriving/iter_bytes.rs +++ b/src/libsyntax/ext/deriving/iter_bytes.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, item, Expr, BiAnd}; +use ast::{MetaItem, Item, Expr, BiAnd}; use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; @@ -18,7 +18,7 @@ use ext::deriving::generic::*; pub fn expand_deriving_iter_bytes(cx: &ExtCtxt, span: Span, mitem: @MetaItem, - in_items: ~[@item]) -> ~[@item] { + in_items: ~[@Item]) -> ~[@Item] { let trait_def = TraitDef { cx: cx, span: span, diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 1529fbae7e1..652f5ebe6c7 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -18,7 +18,7 @@ library. */ -use ast::{enum_def, Ident, item, Generics, struct_def}; +use ast::{EnumDef, Ident, Item, Generics, StructDef}; use ast::{MetaItem, MetaList, MetaNameValue, MetaWord}; use ext::base::ExtCtxt; use codemap::Span; @@ -47,22 +47,22 @@ pub mod generic; pub type ExpandDerivingStructDefFn<'a> = 'a |&ExtCtxt, Span, - x: &struct_def, + x: &StructDef, Ident, y: &Generics| - -> @item; + -> @Item; pub type ExpandDerivingEnumDefFn<'a> = 'a |&ExtCtxt, Span, - x: &enum_def, + x: &EnumDef, Ident, y: &Generics| - -> @item; + -> @Item; pub fn expand_meta_deriving(cx: &ExtCtxt, _span: Span, mitem: @MetaItem, - in_items: ~[@item]) - -> ~[@item] { + in_items: ~[@Item]) + -> ~[@Item] { match mitem.node { MetaNameValue(_, ref l) => { cx.span_err(l.span, "unexpected value in `deriving`"); diff --git a/src/libsyntax/ext/deriving/primitive.rs b/src/libsyntax/ext/deriving/primitive.rs index ba2d85f357a..f621ad854aa 100644 --- a/src/libsyntax/ext/deriving/primitive.rs +++ b/src/libsyntax/ext/deriving/primitive.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, item, Expr}; +use ast::{MetaItem, Item, Expr}; use ast; use codemap::Span; use ext::base::ExtCtxt; @@ -18,7 +18,7 @@ use ext::deriving::generic::*; pub fn expand_deriving_from_primitive(cx: &ExtCtxt, span: Span, mitem: @MetaItem, - in_items: ~[@item]) -> ~[@item] { + in_items: ~[@Item]) -> ~[@Item] { let trait_def = TraitDef { cx: cx, span: span, @@ -85,7 +85,7 @@ fn cs_from(name: &str, cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr for variant in enum_def.variants.iter() { match variant.node.kind { - ast::tuple_variant_kind(ref args) => { + ast::TupleVariantKind(ref args) => { if !args.is_empty() { cx.span_err(span, "`FromPrimitive` cannot be derived for \ enum variants with arguments"); @@ -110,7 +110,7 @@ fn cs_from(name: &str, cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr arms.push(arm); } - ast::struct_variant_kind(_) => { + ast::StructVariantKind(_) => { cx.span_err(span, "`FromPrimitive` cannot be derived for enums \ with struct variants"); return cx.expr_fail(span, @""); diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 1491797c808..f065340bdc2 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -9,7 +9,7 @@ // except according to those terms. use ast; -use ast::{MetaItem, item, Expr, Ident}; +use ast::{MetaItem, Item, Expr, Ident}; use codemap::Span; use ext::base::ExtCtxt; use ext::build::{AstBuilder}; @@ -19,8 +19,8 @@ use opt_vec; pub fn expand_deriving_rand(cx: &ExtCtxt, span: Span, mitem: @MetaItem, - in_items: ~[@item]) - -> ~[@item] { + in_items: ~[@Item]) + -> ~[@Item] { let trait_def = TraitDef { cx: cx, span: span, diff --git a/src/libsyntax/ext/deriving/to_str.rs b/src/libsyntax/ext/deriving/to_str.rs index 25700f93a33..81453a5a10b 100644 --- a/src/libsyntax/ext/deriving/to_str.rs +++ b/src/libsyntax/ext/deriving/to_str.rs @@ -9,7 +9,7 @@ // except according to those terms. use ast; -use ast::{MetaItem, item, Expr}; +use ast::{MetaItem, Item, Expr}; use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; @@ -18,8 +18,8 @@ use ext::deriving::generic::*; pub fn expand_deriving_to_str(cx: &ExtCtxt, span: Span, mitem: @MetaItem, - in_items: ~[@item]) - -> ~[@item] { + in_items: ~[@Item]) + -> ~[@Item] { let trait_def = TraitDef { cx: cx, span: span, @@ -98,9 +98,9 @@ fn to_str_substructure(cx: &ExtCtxt, span: Span, EnumMatching(_, variant, ref fields) => { match variant.node.kind { - ast::tuple_variant_kind(..) => + ast::TupleVariantKind(..) => doit("(", @")", variant.node.name, *fields), - ast::struct_variant_kind(..) => + ast::StructVariantKind(..) => doit("{", @"}", variant.node.name, *fields), } } diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index 89bed626c1e..a2e69cd377a 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -153,9 +153,9 @@ impl<'a> Ty<'a> { } Tuple(ref fields) => { let ty = if fields.is_empty() { - ast::ty_nil + ast::TyNil } else { - ast::ty_tup(fields.map(|f| f.to_ty(cx, span, self_ty, self_generics))) + ast::TyTup(fields.map(|f| f.to_ty(cx, span, self_ty, self_generics))) }; cx.ty(span, ty) @@ -240,21 +240,21 @@ impl<'a> LifetimeBounds<'a> { pub fn get_explicit_self(cx: &ExtCtxt, span: Span, self_ptr: &Option<PtrTy>) - -> (@Expr, ast::explicit_self) { + -> (@Expr, ast::ExplicitSelf) { let self_path = cx.expr_self(span); match *self_ptr { None => { - (self_path, respan(span, ast::sty_value(ast::MutImmutable))) + (self_path, respan(span, ast::SelfValue(ast::MutImmutable))) } Some(ref ptr) => { let self_ty = respan( span, match *ptr { - Send => ast::sty_uniq(ast::MutImmutable), - Managed => ast::sty_box(ast::MutImmutable), + Send => ast::SelfUniq(ast::MutImmutable), + Managed => ast::SelfBox(ast::MutImmutable), Borrowed(ref lt, mutbl) => { let lt = lt.map(|s| cx.lifetime(span, cx.ident_of(s))); - ast::sty_region(lt, mutbl) + ast::SelfRegion(lt, mutbl) } }); let self_expr = cx.expr_deref(span, self_path); diff --git a/src/libsyntax/ext/deriving/zero.rs b/src/libsyntax/ext/deriving/zero.rs index c406dbf0d01..034a7970515 100644 --- a/src/libsyntax/ext/deriving/zero.rs +++ b/src/libsyntax/ext/deriving/zero.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{MetaItem, item, Expr}; +use ast::{MetaItem, Item, Expr}; use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; @@ -17,8 +17,8 @@ use ext::deriving::generic::*; pub fn expand_deriving_zero(cx: &ExtCtxt, span: Span, mitem: @MetaItem, - in_items: ~[@item]) - -> ~[@item] { + in_items: ~[@Item]) + -> ~[@Item] { let trait_def = TraitDef { cx: cx, span: span, diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index cebd7aac4e3..be5560adca8 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -22,7 +22,7 @@ use ext::build::AstBuilder; use std::os; -pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { let var = get_single_str_from_tts(cx, sp, tts, "option_env!"); @@ -33,7 +33,7 @@ pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) MRExpr(e) } -pub fn expand_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { let exprs = get_exprs_from_tts(cx, sp, tts); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 5d497dd541f..75c0371f625 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -9,9 +9,9 @@ // except according to those terms. use ast::{P, Block, Crate, DeclLocal, ExprMac, SyntaxContext}; -use ast::{Local, Ident, mac_invoc_tt}; -use ast::{item_mac, Mrk, Stmt, StmtDecl, StmtMac, StmtExpr, StmtSemi}; -use ast::{token_tree}; +use ast::{Local, Ident, MacInvocTT}; +use ast::{ItemMac, Mrk, Stmt, StmtDecl, StmtMac, StmtExpr, StmtSemi}; +use ast::{TokenTree}; use ast; use ast_util::{mtwt_outer_mark, new_rename, new_mark}; use ext::build::AstBuilder; @@ -43,7 +43,7 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr { // for the other three macro invocation chunks of code // in this file. // Token-tree macros: - mac_invoc_tt(ref pth, ref tts, ctxt) => { + MacInvocTT(ref pth, ref tts, ctxt) => { if (pth.segments.len() > 1u) { fld.cx.span_fatal( pth.span, @@ -210,7 +210,7 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr { // // NB: there is some redundancy between this and expand_item, below, and // they might benefit from some amount of semantic and language-UI merger. -pub fn expand_mod_items(module_: &ast::_mod, fld: &mut MacroExpander) -> ast::_mod { +pub fn expand_mod_items(module_: &ast::Mod, fld: &mut MacroExpander) -> ast::Mod { // Fold the contents first: let module_ = noop_fold_mod(module_, fld); @@ -240,7 +240,7 @@ pub fn expand_mod_items(module_: &ast::_mod, fld: &mut MacroExpander) -> ast::_m }) }); - ast::_mod { + ast::Mod { items: new_items, ..module_ } @@ -258,11 +258,11 @@ macro_rules! with_exts_frame ( ) // When we enter a module, record it, for the sake of `module!` -pub fn expand_item(it: @ast::item, fld: &mut MacroExpander) - -> SmallVector<@ast::item> { +pub fn expand_item(it: @ast::Item, fld: &mut MacroExpander) + -> SmallVector<@ast::Item> { match it.node { - ast::item_mac(..) => expand_item_mac(it, fld), - ast::item_mod(_) | ast::item_foreign_mod(_) => { + ast::ItemMac(..) => expand_item_mac(it, fld), + ast::ItemMod(_) | ast::ItemForeignMod(_) => { fld.cx.mod_push(it.ident); let macro_escape = contains_macro_escape(it.attrs); let result = with_exts_frame!(fld.extsbox, @@ -282,11 +282,11 @@ pub fn contains_macro_escape(attrs: &[ast::Attribute]) -> bool { // Support for item-position macro invocations, exactly the same // logic as for expression-position macro invocations. -pub fn expand_item_mac(it: @ast::item, fld: &mut MacroExpander) - -> SmallVector<@ast::item> { +pub fn expand_item_mac(it: @ast::Item, fld: &mut MacroExpander) + -> SmallVector<@ast::Item> { let (pth, tts, ctxt) = match it.node { - item_mac(codemap::Spanned { - node: mac_invoc_tt(ref pth, ref tts, ctxt), + ItemMac(codemap::Spanned { + node: MacInvocTT(ref pth, ref tts, ctxt), .. }) => { (pth, (*tts).clone(), ctxt) @@ -379,7 +379,7 @@ pub fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<@Stmt> { let (pth, tts, semi, ctxt) = match s.node { StmtMac(ref mac, semi) => { match mac.node { - mac_invoc_tt(ref pth, ref tts, ctxt) => { + MacInvocTT(ref pth, ref tts, ctxt) => { (pth, (*tts).clone(), semi, ctxt) } } @@ -631,7 +631,7 @@ struct IdentRenamer<'a> { renames: &'a mut RenameList, } -impl<'a> ast_fold for IdentRenamer<'a> { +impl<'a> Folder for IdentRenamer<'a> { fn fold_ident(&mut self, id: ast::Ident) -> ast::Ident { let new_ctxt = self.renames.iter().fold(id.ctxt, |ctxt, &(from, to)| { new_rename(from, to, ctxt) @@ -837,15 +837,15 @@ pub fn std_macros() -> @str { } struct Injector { - sm: @ast::item, + sm: @ast::Item, } -impl ast_fold for Injector { - fn fold_mod(&mut self, module: &ast::_mod) -> ast::_mod { +impl Folder for Injector { + fn fold_mod(&mut self, module: &ast::Mod) -> ast::Mod { // Just inject the standard macros at the start of the first module // in the crate: that is, at the start of the crate file itself. let items = vec::append(~[ self.sm ], module.items); - ast::_mod { + ast::Mod { items: items, ..(*module).clone() // FIXME #2543: Bad copy. } @@ -878,16 +878,16 @@ pub struct MacroExpander<'a> { cx: &'a mut ExtCtxt, } -impl<'a> ast_fold for MacroExpander<'a> { +impl<'a> Folder for MacroExpander<'a> { fn fold_expr(&mut self, expr: @ast::Expr) -> @ast::Expr { expand_expr(expr, self) } - fn fold_mod(&mut self, module: &ast::_mod) -> ast::_mod { + fn fold_mod(&mut self, module: &ast::Mod) -> ast::Mod { expand_mod_items(module, self) } - fn fold_item(&mut self, item: @ast::item) -> SmallVector<@ast::item> { + fn fold_item(&mut self, item: @ast::Item) -> SmallVector<@ast::Item> { expand_item(item, self) } @@ -968,7 +968,7 @@ pub struct ContextWrapper { context_function: @CtxtFn, } -impl ast_fold for ContextWrapper { +impl Folder for ContextWrapper { fn fold_ident(&mut self, id: ast::Ident) -> ast::Ident { let ast::Ident { name, @@ -979,12 +979,12 @@ impl ast_fold for ContextWrapper { ctxt: self.context_function.f(ctxt), } } - fn fold_mac(&mut self, m: &ast::mac) -> ast::mac { + fn fold_mac(&mut self, m: &ast::Mac) -> ast::Mac { let macro = match m.node { - mac_invoc_tt(ref path, ref tts, ctxt) => { - mac_invoc_tt(self.fold_path(path), - fold_tts(*tts, self), - self.context_function.f(ctxt)) + MacInvocTT(ref path, ref tts, ctxt) => { + MacInvocTT(self.fold_path(path), + fold_tts(*tts, self), + self.context_function.f(ctxt)) } }; Spanned { @@ -995,7 +995,7 @@ impl ast_fold for ContextWrapper { } // given a function from ctxts to ctxts, produce -// an ast_fold that applies that function to all ctxts: +// a Folder that applies that function to all ctxts: pub fn fun_to_ctxt_folder<T : 'static + CtxtFn>(cf: @T) -> ContextWrapper { ContextWrapper { context_function: cf as @CtxtFn, @@ -1012,7 +1012,7 @@ pub fn new_rename_folder(from: ast::Ident, to: ast::Name) -> ContextWrapper { } // apply a given mark to the given token trees. Used prior to expansion of a macro. -fn mark_tts(tts : &[token_tree], m : Mrk) -> ~[token_tree] { +fn mark_tts(tts : &[TokenTree], m : Mrk) -> ~[TokenTree] { fold_tts(tts, &mut new_mark_folder(m)) } @@ -1028,7 +1028,7 @@ fn mark_stmt(expr : &ast::Stmt, m : Mrk) -> @ast::Stmt { } // apply a given mark to the given item. Used following the expansion of a macro. -fn mark_item(expr : @ast::item, m : Mrk) -> SmallVector<@ast::item> { +fn mark_item(expr : @ast::Item, m : Mrk) -> SmallVector<@ast::Item> { new_mark_folder(m).fold_item(expr) } @@ -1041,8 +1041,8 @@ pub fn replace_ctxts(expr : @ast::Expr, ctxt : SyntaxContext) -> @ast::Expr { // take the mark from the given ctxt (that has a mark at the outside), // and apply it to everything in the token trees, thereby cancelling // that mark. -pub fn mtwt_cancel_outer_mark(tts: &[ast::token_tree], ctxt: ast::SyntaxContext) - -> ~[ast::token_tree] { +pub fn mtwt_cancel_outer_mark(tts: &[ast::TokenTree], ctxt: ast::SyntaxContext) + -> ~[ast::TokenTree] { let outer_mark = mtwt_outer_mark(ctxt); mark_tts(tts,outer_mark) } @@ -1221,14 +1221,14 @@ mod test { assert_eq!(marked_once.len(),1); let marked_once_ctxt = match marked_once[0] { - ast::tt_tok(_,token::IDENT(id,_)) => id.ctxt, + ast::TTTok(_,token::IDENT(id,_)) => id.ctxt, _ => fail!(format!("unexpected shape for marked tts: {:?}",marked_once[0])) }; assert_eq!(mtwt_marksof(marked_once_ctxt,invalid_name),~[fm]); let remarked = mtwt_cancel_outer_mark(marked_once,marked_once_ctxt); assert_eq!(remarked.len(),1); match remarked[0] { - ast::tt_tok(_,token::IDENT(id,_)) => + ast::TTTok(_,token::IDENT(id,_)) => assert_eq!(mtwt_marksof(id.ctxt,invalid_name),~[]), _ => fail!(format!("unexpected shape for marked tts: {:?}",remarked[0])) } @@ -1315,11 +1315,11 @@ mod test { // in principle, you might want to control this boolean on a per-varref basis, // but that would make things even harder to understand, and might not be // necessary for thorough testing. - type renaming_test = (&'static str, ~[~[uint]], bool); + type RenamingTest = (&'static str, ~[~[uint]], bool); #[test] fn automatic_renaming () { - let tests : ~[renaming_test] = + let tests : ~[RenamingTest] = ~[// b & c should get new names throughout, in the expr too: ("fn a() -> int { let b = 13; let c = b; b+c }", ~[~[0,1],~[2]], false), @@ -1363,7 +1363,7 @@ mod test { } // run one of the renaming tests - fn run_renaming_test(t : &renaming_test, test_idx: uint) { + fn run_renaming_test(t: &RenamingTest, test_idx: uint) { let invalid_name = token::special_idents::invalid.name; let (teststr, bound_connections, bound_ident_check) = match *t { (ref str,ref conns, bic) => (str.to_managed(), conns.clone(), bic) diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index 34a8236905b..411bf921dd2 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -16,7 +16,7 @@ use ext::base; use ext::build::AstBuilder; pub fn expand_syntax_ext(ecx: &mut base::ExtCtxt, sp: Span, - _tts: &[ast::token_tree]) -> base::MacResult { + _tts: &[ast::TokenTree]) -> base::MacResult { ecx.span_err(sp, "`fmt!` is deprecated, use `format!` instead"); ecx.parse_sess.span_diagnostic.span_note(sp, "see http://static.rust-lang.org/doc/master/std/fmt/index.html \ diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index d04e2e91d64..a4b8dd78403 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -48,7 +48,7 @@ struct Context<'a> { // Collection of the compiled `rt::Piece` structures pieces: ~[@ast::Expr], name_positions: HashMap<@str, uint>, - method_statics: ~[@ast::item], + method_statics: ~[@ast::Item], // Updated as arguments are consumed or methods are entered nest_level: uint, @@ -58,7 +58,7 @@ struct Context<'a> { impl<'a> Context<'a> { /// Parses the arguments from the given list of tokens, returning None if /// there's a parse error so we can continue parsing other format! expressions. - fn parse_args(&mut self, sp: Span, tts: &[ast::token_tree]) + fn parse_args(&mut self, sp: Span, tts: &[ast::TokenTree]) -> (@ast::Expr, Option<@ast::Expr>) { let mut p = rsparse::new_parser_from_tts(self.ecx.parse_sess(), self.ecx.cfg(), @@ -476,7 +476,7 @@ impl<'a> Context<'a> { opt_vec::with(life), ~[] ), None); - let st = ast::item_static(ty, ast::MutImmutable, method); + let st = ast::ItemStatic(ty, ast::MutImmutable, method); let static_name = self.ecx.ident_of(format!("__STATIC_METHOD_{}", self.method_statics.len())); let item = self.ecx.item(sp, static_name, self.static_attrs(), st); @@ -490,7 +490,7 @@ impl<'a> Context<'a> { ~[self.ecx.expr_str(sp, s.to_managed())]) } parse::CurrentArgument => { - let nil = self.ecx.expr_lit(sp, ast::lit_nil); + let nil = self.ecx.expr_lit(sp, ast::LitNil); self.ecx.expr_call_global(sp, rtpath("CurrentArgument"), ~[nil]) } parse::Argument(ref arg) => { @@ -522,7 +522,7 @@ impl<'a> Context<'a> { // Translate the format let fill = match arg.format.fill { Some(c) => c, None => ' ' }; - let fill = self.ecx.expr_lit(sp, ast::lit_char(fill as u32)); + let fill = self.ecx.expr_lit(sp, ast::LitChar(fill as u32)); let align = match arg.format.align { parse::AlignLeft => { self.ecx.path_global(sp, parsepath("AlignLeft")) @@ -595,12 +595,12 @@ impl<'a> Context<'a> { self.ecx.lifetime(self.fmtsp, self.ecx.ident_of("static"))), ~[] ), None); - let ty = ast::ty_fixed_length_vec( + let ty = ast::TyFixedLengthVec( piece_ty, self.ecx.expr_uint(self.fmtsp, self.pieces.len()) ); let ty = self.ecx.ty(self.fmtsp, ty); - let st = ast::item_static(ty, ast::MutImmutable, fmt); + let st = ast::ItemStatic(ty, ast::MutImmutable, fmt); let static_name = self.ecx.ident_of("__STATIC_FMTSTR"); let item = self.ecx.item(self.fmtsp, static_name, self.static_attrs(), st); @@ -726,7 +726,7 @@ impl<'a> Context<'a> { } pub fn expand_args(ecx: &mut ExtCtxt, sp: Span, - tts: &[ast::token_tree]) -> base::MacResult { + tts: &[ast::TokenTree]) -> base::MacResult { let mut cx = Context { ecx: ecx, args: ~[], diff --git a/src/libsyntax/ext/log_syntax.rs b/src/libsyntax/ext/log_syntax.rs index 22b04501cfb..74032095840 100644 --- a/src/libsyntax/ext/log_syntax.rs +++ b/src/libsyntax/ext/log_syntax.rs @@ -17,20 +17,20 @@ use parse::token::{get_ident_interner}; pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: codemap::Span, - tt: &[ast::token_tree]) + tt: &[ast::TokenTree]) -> base::MacResult { cx.print_backtrace(); println( print::pprust::tt_to_str( - &ast::tt_delim(@tt.to_owned()), + &ast::TTDelim(@tt.to_owned()), get_ident_interner())); //trivial expression MRExpr(@ast::Expr { id: ast::DUMMY_NODE_ID, node: ast::ExprLit(@codemap::Spanned { - node: ast::lit_nil, + node: ast::LitNil, span: sp }), span: sp, diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 0f0793e03b7..e66e394d639 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -23,7 +23,7 @@ use parse; * * This is registered as a set of expression syntax extension called quote! * that lifts its argument token-tree to an AST representing the -* construction of the same token tree, with ast::tt_nonterminal nodes +* construction of the same token tree, with ast::TTNonterminal nodes * interpreted as antiquotes (splices). * */ @@ -40,11 +40,11 @@ pub mod rt { pub use codemap::{BytePos, Span, dummy_spanned}; pub trait ToTokens { - fn to_tokens(&self, _cx: &ExtCtxt) -> ~[token_tree]; + fn to_tokens(&self, _cx: &ExtCtxt) -> ~[TokenTree]; } - impl ToTokens for ~[token_tree] { - fn to_tokens(&self, _cx: &ExtCtxt) -> ~[token_tree] { + impl ToTokens for ~[TokenTree] { + fn to_tokens(&self, _cx: &ExtCtxt) -> ~[TokenTree] { (*self).clone() } } @@ -56,7 +56,7 @@ pub mod rt { pub fn to_source() -> ~str; // If you can make source, you can definitely make tokens. - pub fn to_tokens(cx: &ExtCtxt) -> ~[token_tree] { + pub fn to_tokens(cx: &ExtCtxt) -> ~[TokenTree] { cx.parse_tts(self.to_source()) } } @@ -74,13 +74,13 @@ pub mod rt { } } - impl ToSource for @ast::item { + impl ToSource for @ast::Item { fn to_source(&self) -> @str { pprust::item_to_str(*self, get_ident_interner()).to_managed() } } - impl<'a> ToSource for &'a [@ast::item] { + impl<'a> ToSource for &'a [@ast::Item] { fn to_source(&self) -> @str { self.map(|i| i.to_source()).connect("\n\n").to_managed() } @@ -118,28 +118,28 @@ pub mod rt { impl<'a> ToSource for &'a str { fn to_source(&self) -> @str { - let lit = dummy_spanned(ast::lit_str(self.to_managed(), ast::CookedStr)); + let lit = dummy_spanned(ast::LitStr(self.to_managed(), ast::CookedStr)); pprust::lit_to_str(&lit).to_managed() } } impl ToSource for int { fn to_source(&self) -> @str { - let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i)); + let lit = dummy_spanned(ast::LitInt(*self as i64, ast::TyI)); pprust::lit_to_str(&lit).to_managed() } } impl ToSource for i8 { fn to_source(&self) -> @str { - let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i8)); + let lit = dummy_spanned(ast::LitInt(*self as i64, ast::TyI8)); pprust::lit_to_str(&lit).to_managed() } } impl ToSource for i16 { fn to_source(&self) -> @str { - let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i16)); + let lit = dummy_spanned(ast::LitInt(*self as i64, ast::TyI16)); pprust::lit_to_str(&lit).to_managed() } } @@ -147,49 +147,49 @@ pub mod rt { impl ToSource for i32 { fn to_source(&self) -> @str { - let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i32)); + let lit = dummy_spanned(ast::LitInt(*self as i64, ast::TyI32)); pprust::lit_to_str(&lit).to_managed() } } impl ToSource for i64 { fn to_source(&self) -> @str { - let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i64)); + let lit = dummy_spanned(ast::LitInt(*self as i64, ast::TyI64)); pprust::lit_to_str(&lit).to_managed() } } impl ToSource for uint { fn to_source(&self) -> @str { - let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u)); + let lit = dummy_spanned(ast::LitUint(*self as u64, ast::TyU)); pprust::lit_to_str(&lit).to_managed() } } impl ToSource for u8 { fn to_source(&self) -> @str { - let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u8)); + let lit = dummy_spanned(ast::LitUint(*self as u64, ast::TyU8)); pprust::lit_to_str(&lit).to_managed() } } impl ToSource for u16 { fn to_source(&self) -> @str { - let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u16)); + let lit = dummy_spanned(ast::LitUint(*self as u64, ast::TyU16)); pprust::lit_to_str(&lit).to_managed() } } impl ToSource for u32 { fn to_source(&self) -> @str { - let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u32)); + let lit = dummy_spanned(ast::LitUint(*self as u64, ast::TyU32)); pprust::lit_to_str(&lit).to_managed() } } impl ToSource for u64 { fn to_source(&self) -> @str { - let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u64)); + let lit = dummy_spanned(ast::LitUint(*self as u64, ast::TyU64)); pprust::lit_to_str(&lit).to_managed() } } @@ -199,7 +199,7 @@ pub mod rt { macro_rules! impl_to_tokens( ($t:ty) => ( impl ToTokens for $t { - fn to_tokens(&self, cx: &ExtCtxt) -> ~[token_tree] { + fn to_tokens(&self, cx: &ExtCtxt) -> ~[TokenTree] { cx.parse_tts(self.to_source()) } } @@ -209,7 +209,7 @@ pub mod rt { macro_rules! impl_to_tokens_self( ($t:ty) => ( impl<'a> ToTokens for $t { - fn to_tokens(&self, cx: &ExtCtxt) -> ~[token_tree] { + fn to_tokens(&self, cx: &ExtCtxt) -> ~[TokenTree] { cx.parse_tts(self.to_source()) } } @@ -217,8 +217,8 @@ pub mod rt { ) impl_to_tokens!(ast::Ident) - impl_to_tokens!(@ast::item) - impl_to_tokens_self!(&'a [@ast::item]) + impl_to_tokens!(@ast::Item) + impl_to_tokens_self!(&'a [@ast::Item]) impl_to_tokens!(ast::Ty) impl_to_tokens_self!(&'a [ast::Ty]) impl_to_tokens!(Generics) @@ -237,15 +237,15 @@ pub mod rt { impl_to_tokens!(u64) pub trait ExtParseUtils { - fn parse_item(&self, s: @str) -> @ast::item; + fn parse_item(&self, s: @str) -> @ast::Item; fn parse_expr(&self, s: @str) -> @ast::Expr; fn parse_stmt(&self, s: @str) -> @ast::Stmt; - fn parse_tts(&self, s: @str) -> ~[ast::token_tree]; + fn parse_tts(&self, s: @str) -> ~[ast::TokenTree]; } impl ExtParseUtils for ExtCtxt { - fn parse_item(&self, s: @str) -> @ast::item { + fn parse_item(&self, s: @str) -> @ast::Item { let res = parse::parse_item_from_source_str( @"<quote expansion>", s, @@ -278,7 +278,7 @@ pub mod rt { self.parse_sess()) } - fn parse_tts(&self, s: @str) -> ~[ast::token_tree] { + fn parse_tts(&self, s: @str) -> ~[ast::TokenTree] { parse::parse_tts_from_source_str( @"<quote expansion>", s, @@ -291,7 +291,7 @@ pub mod rt { pub fn expand_quote_tokens(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::token_tree]) -> base::MacResult { + tts: &[ast::TokenTree]) -> base::MacResult { let (cx_expr, expr) = expand_tts(cx, sp, tts); let expanded = expand_wrapper(cx, sp, cx_expr, expr); base::MRExpr(expanded) @@ -299,14 +299,14 @@ pub fn expand_quote_tokens(cx: &mut ExtCtxt, pub fn expand_quote_expr(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::token_tree]) -> base::MacResult { + tts: &[ast::TokenTree]) -> base::MacResult { let expanded = expand_parse_call(cx, sp, "parse_expr", ~[], tts); base::MRExpr(expanded) } pub fn expand_quote_item(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::token_tree]) -> base::MacResult { + tts: &[ast::TokenTree]) -> base::MacResult { let e_attrs = cx.expr_vec_uniq(sp, ~[]); let expanded = expand_parse_call(cx, sp, "parse_item", ~[e_attrs], tts); @@ -315,8 +315,8 @@ pub fn expand_quote_item(cx: &mut ExtCtxt, pub fn expand_quote_pat(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::token_tree]) -> base::MacResult { - let e_refutable = cx.expr_lit(sp, ast::lit_bool(true)); + tts: &[ast::TokenTree]) -> base::MacResult { + let e_refutable = cx.expr_lit(sp, ast::LitBool(true)); let expanded = expand_parse_call(cx, sp, "parse_pat", ~[e_refutable], tts); base::MRExpr(expanded) @@ -324,8 +324,8 @@ pub fn expand_quote_pat(cx: &mut ExtCtxt, pub fn expand_quote_ty(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::token_tree]) -> base::MacResult { - let e_param_colons = cx.expr_lit(sp, ast::lit_bool(false)); + tts: &[ast::TokenTree]) -> base::MacResult { + let e_param_colons = cx.expr_lit(sp, ast::LitBool(false)); let expanded = expand_parse_call(cx, sp, "parse_ty", ~[e_param_colons], tts); base::MRExpr(expanded) @@ -333,7 +333,7 @@ pub fn expand_quote_ty(cx: &mut ExtCtxt, pub fn expand_quote_stmt(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::token_tree]) -> base::MacResult { + tts: &[ast::TokenTree]) -> base::MacResult { let e_attrs = cx.expr_vec_uniq(sp, ~[]); let expanded = expand_parse_call(cx, sp, "parse_stmt", ~[e_attrs], tts); @@ -357,7 +357,7 @@ fn mk_ident(cx: &ExtCtxt, sp: Span, ident: ast::Ident) -> @ast::Expr { ~[e_str]) } -fn mk_binop(cx: &ExtCtxt, sp: Span, bop: token::binop) -> @ast::Expr { +fn mk_binop(cx: &ExtCtxt, sp: Span, bop: token::BinOp) -> @ast::Expr { let name = match bop { PLUS => "PLUS", MINUS => "MINUS", @@ -388,25 +388,22 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr { } LIT_CHAR(i) => { - let s_ity = ~"ty_char"; - let e_ity = cx.expr_ident(sp, id_ext(s_ity)); - - let e_char = cx.expr_lit(sp, ast::lit_char(i)); + let e_char = cx.expr_lit(sp, ast::LitChar(i)); - return cx.expr_call_ident(sp, id_ext("LIT_CHAR"), ~[e_char, e_ity]); + return cx.expr_call_ident(sp, id_ext("LIT_CHAR"), ~[e_char]); } LIT_INT(i, ity) => { let s_ity = match ity { - ast::ty_i => ~"ty_i", - ast::ty_i8 => ~"ty_i8", - ast::ty_i16 => ~"ty_i16", - ast::ty_i32 => ~"ty_i32", - ast::ty_i64 => ~"ty_i64" + ast::TyI => ~"TyI", + ast::TyI8 => ~"TyI8", + ast::TyI16 => ~"TyI16", + ast::TyI32 => ~"TyI32", + ast::TyI64 => ~"TyI64" }; let e_ity = cx.expr_ident(sp, id_ext(s_ity)); - let e_i64 = cx.expr_lit(sp, ast::lit_int(i, ast::ty_i64)); + let e_i64 = cx.expr_lit(sp, ast::LitInt(i, ast::TyI64)); return cx.expr_call_ident(sp, id_ext("LIT_INT"), @@ -415,15 +412,15 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr { LIT_UINT(u, uty) => { let s_uty = match uty { - ast::ty_u => ~"ty_u", - ast::ty_u8 => ~"ty_u8", - ast::ty_u16 => ~"ty_u16", - ast::ty_u32 => ~"ty_u32", - ast::ty_u64 => ~"ty_u64" + ast::TyU => ~"TyU", + ast::TyU8 => ~"TyU8", + ast::TyU16 => ~"TyU16", + ast::TyU32 => ~"TyU32", + ast::TyU64 => ~"TyU64" }; let e_uty = cx.expr_ident(sp, id_ext(s_uty)); - let e_u64 = cx.expr_lit(sp, ast::lit_uint(u, ast::ty_u64)); + let e_u64 = cx.expr_lit(sp, ast::LitUint(u, ast::TyU64)); return cx.expr_call_ident(sp, id_ext("LIT_UINT"), @@ -431,7 +428,7 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr { } LIT_INT_UNSUFFIXED(i) => { - let e_i64 = cx.expr_lit(sp, ast::lit_int(i, ast::ty_i64)); + let e_i64 = cx.expr_lit(sp, ast::LitInt(i, ast::TyI64)); return cx.expr_call_ident(sp, id_ext("LIT_INT_UNSUFFIXED"), @@ -440,8 +437,8 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr { LIT_FLOAT(fident, fty) => { let s_fty = match fty { - ast::ty_f32 => ~"ty_f32", - ast::ty_f64 => ~"ty_f64" + ast::TyF32 => ~"TyF32", + ast::TyF64 => ~"TyF64" }; let e_fty = cx.expr_ident(sp, id_ext(s_fty)); @@ -528,15 +525,14 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr { } -fn mk_tt(cx: &ExtCtxt, sp: Span, tt: &ast::token_tree) - -> ~[@ast::Stmt] { +fn mk_tt(cx: &ExtCtxt, sp: Span, tt: &ast::TokenTree) -> ~[@ast::Stmt] { match *tt { - ast::tt_tok(sp, ref tok) => { + ast::TTTok(sp, ref tok) => { let e_sp = cx.expr_ident(sp, id_ext("sp")); let e_tok = cx.expr_call_ident(sp, - id_ext("tt_tok"), + id_ext("TTTok"), ~[e_sp, mk_token(cx, sp, tok)]); let e_push = cx.expr_method_call(sp, @@ -546,10 +542,10 @@ fn mk_tt(cx: &ExtCtxt, sp: Span, tt: &ast::token_tree) ~[cx.stmt_expr(e_push)] } - ast::tt_delim(ref tts) => mk_tts(cx, sp, **tts), - ast::tt_seq(..) => fail!("tt_seq in quote!"), + ast::TTDelim(ref tts) => mk_tts(cx, sp, **tts), + ast::TTSeq(..) => fail!("TTSeq in quote!"), - ast::tt_nonterminal(sp, ident) => { + ast::TTNonterminal(sp, ident) => { // tt.push_all_move($ident.to_tokens(ext_cx)) @@ -570,7 +566,7 @@ fn mk_tt(cx: &ExtCtxt, sp: Span, tt: &ast::token_tree) } } -fn mk_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) +fn mk_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> ~[@ast::Stmt] { let mut ss = ~[]; for tt in tts.iter() { @@ -579,10 +575,10 @@ fn mk_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) ss } -fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) +fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> (@ast::Expr, @ast::Expr) { // NB: It appears that the main parser loses its mind if we consider - // $foo as a tt_nonterminal during the main parse, so we have to re-parse + // $foo as a TTNonterminal during the main parse, so we have to re-parse // under quote_depth > 0. This is silly and should go away; the _guess_ is // it has to do with transition away from supporting old-style macros, so // try removing it when enough of them are gone. @@ -652,7 +648,7 @@ fn expand_wrapper(cx: &ExtCtxt, sp: Span, cx_expr: @ast::Expr, expr: @ast::Expr) -> @ast::Expr { - let uses = ~[ cx.view_use_glob(sp, ast::public, + let uses = ~[ cx.view_use_glob(sp, ast::Public, ids_ext(~[~"syntax", ~"ext", ~"quote", @@ -667,7 +663,7 @@ fn expand_parse_call(cx: &ExtCtxt, sp: Span, parse_method: &str, arg_exprs: ~[@ast::Expr], - tts: &[ast::token_tree]) -> @ast::Expr { + tts: &[ast::TokenTree]) -> @ast::Expr { let (cx_expr, tts_expr) = expand_tts(cx, sp, tts); let cfg_call = || cx.expr_method_call( diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index fae3f013f91..3e781451b08 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -28,7 +28,7 @@ use std::str; // a given file into the current one. /* line!(): expands to the current line number */ -pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "line!"); @@ -39,7 +39,7 @@ pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) } /* col!(): expands to the current column number */ -pub fn expand_col(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_col(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "col!"); @@ -51,7 +51,7 @@ pub fn expand_col(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) /* file!(): expands to the current filename */ /* The filemap (`loc.file`) contains a bunch more information we could spit * out if we wanted. */ -pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "file!"); @@ -61,13 +61,13 @@ pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) base::MRExpr(cx.expr_str(topmost.call_site, filename)) } -pub fn expand_stringify(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_stringify(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { let s = pprust::tts_to_str(tts, get_ident_interner()); base::MRExpr(cx.expr_str(sp, s.to_managed())) } -pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "module_path!"); base::MRExpr(cx.expr_str(sp, @@ -77,7 +77,7 @@ pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) // include! : parse the given file as an expr // This is generally a bad idea because it's going to behave // unhygienically. -pub fn expand_include(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_include(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include!"); // The file will be added to the code map by the parser @@ -92,7 +92,7 @@ pub fn expand_include(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) } // include_str! : read the given file, insert it as a literal string expr -pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include_str!"); let file = res_rel_file(cx, sp, &Path::new(file)); @@ -119,7 +119,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) } } -pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { use std::at_vec; @@ -133,7 +133,7 @@ pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) } Ok(bytes) => { let bytes = at_vec::to_managed_move(bytes); - base::MRExpr(cx.expr_lit(sp, ast::lit_binary(bytes))) + base::MRExpr(cx.expr_lit(sp, ast::LitBinary(bytes))) } } } diff --git a/src/libsyntax/ext/trace_macros.rs b/src/libsyntax/ext/trace_macros.rs index a7d1d8fb366..679e9a5098e 100644 --- a/src/libsyntax/ext/trace_macros.rs +++ b/src/libsyntax/ext/trace_macros.rs @@ -12,20 +12,20 @@ use ast; use codemap::Span; use ext::base::ExtCtxt; use ext::base; -use parse::lexer::{new_tt_reader, reader}; +use parse::lexer::{new_tt_reader, Reader}; use parse::parser::Parser; use parse::token::keywords; pub fn expand_trace_macros(cx: &mut ExtCtxt, sp: Span, - tt: &[ast::token_tree]) + tt: &[ast::TokenTree]) -> base::MacResult { let sess = cx.parse_sess(); let cfg = cx.cfg(); let tt_rdr = new_tt_reader(cx.parse_sess().span_diagnostic, None, tt.to_owned()); - let rdr = tt_rdr as @reader; + let rdr = tt_rdr as @Reader; let mut rust_parser = Parser(sess, cfg.clone(), rdr.dup()); if rust_parser.is_keyword(keywords::True) { diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 8b22e32262b..22074a73a8b 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -11,14 +11,14 @@ // Earley-like parser for macros. use ast; -use ast::{matcher, match_tok, match_seq, match_nonterminal, Ident}; +use ast::{Matcher, MatchTok, MatchSeq, MatchNonterminal, Ident}; use codemap::{BytePos, mk_sp}; use codemap; use parse::lexer::*; //resolve bug? use parse::ParseSess; -use parse::attr::parser_attr; +use parse::attr::ParserAttr; use parse::parser::{LifetimeAndTypesWithoutColons, Parser}; -use parse::token::{Token, EOF, to_str, nonterminal, get_ident_interner, ident_to_str}; +use parse::token::{Token, EOF, to_str, Nonterminal, get_ident_interner, ident_to_str}; use parse::token; use std::hashmap::HashMap; @@ -33,7 +33,7 @@ ones. Instead of NTs, we have a special case for Kleene star. The big-O, in pathological cases, is worse than traditional Earley parsing, but it's an easier fit for Macro-by-Example-style rules, and I think the overhead is lower. (In order to prevent the pathological case, we'd need to lazily -construct the resulting `named_match`es at the very end. It'd be a pain, +construct the resulting `NamedMatch`es at the very end. It'd be a pain, and require more memory to keep around old items, but it would also save overhead)*/ @@ -93,60 +93,42 @@ eof: [a $( a )* a b ·] */ -/* to avoid costly uniqueness checks, we require that `match_seq` always has a +/* to avoid costly uniqueness checks, we require that `MatchSeq` always has a nonempty body. */ -#[deriving(Clone)] -pub enum matcher_pos_up { /* to break a circularity */ - matcher_pos_up(Option<~MatcherPos>) -} - -pub fn is_some(mpu: &matcher_pos_up) -> bool { - match *mpu { - matcher_pos_up(None) => false, - _ => true - } -} #[deriving(Clone)] pub struct MatcherPos { - elts: ~[ast::matcher], // maybe should be <'>? Need to understand regions. + elts: ~[ast::Matcher], // maybe should be <'>? Need to understand regions. sep: Option<Token>, idx: uint, - up: matcher_pos_up, // mutable for swapping only - matches: ~[~[@named_match]], + up: Option<~MatcherPos>, + matches: ~[~[@NamedMatch]], match_lo: uint, match_hi: uint, sp_lo: BytePos, } -pub fn copy_up(mpu: &matcher_pos_up) -> ~MatcherPos { - match *mpu { - matcher_pos_up(Some(ref mp)) => (*mp).clone(), - _ => fail!() - } -} - -pub fn count_names(ms: &[matcher]) -> uint { +pub fn count_names(ms: &[Matcher]) -> uint { ms.iter().fold(0, |ct, m| { ct + match m.node { - match_tok(_) => 0u, - match_seq(ref more_ms, _, _, _, _) => count_names((*more_ms)), - match_nonterminal(_,_,_) => 1u + MatchTok(_) => 0u, + MatchSeq(ref more_ms, _, _, _, _) => count_names((*more_ms)), + MatchNonterminal(_, _, _) => 1u }}) } -pub fn initial_matcher_pos(ms: ~[matcher], sep: Option<Token>, lo: BytePos) +pub fn initial_matcher_pos(ms: ~[Matcher], sep: Option<Token>, lo: BytePos) -> ~MatcherPos { let mut match_idx_hi = 0u; for elt in ms.iter() { match elt.node { - match_tok(_) => (), - match_seq(_,_,_,_,hi) => { - match_idx_hi = hi; // it is monotonic... - } - match_nonterminal(_,_,pos) => { - match_idx_hi = pos+1u; // ...so latest is highest - } + MatchTok(_) => (), + MatchSeq(_,_,_,_,hi) => { + match_idx_hi = hi; // it is monotonic... + } + MatchNonterminal(_,_,pos) => { + match_idx_hi = pos+1u; // ...so latest is highest + } } } let matches = vec::from_fn(count_names(ms), |_i| ~[]); @@ -154,7 +136,7 @@ pub fn initial_matcher_pos(ms: ~[matcher], sep: Option<Token>, lo: BytePos) elts: ms, sep: sep, idx: 0u, - up: matcher_pos_up(None), + up: None, matches: matches, match_lo: 0u, match_hi: match_idx_hi, @@ -162,45 +144,43 @@ pub fn initial_matcher_pos(ms: ~[matcher], sep: Option<Token>, lo: BytePos) } } -// named_match is a pattern-match result for a single ast::match_nonterminal: +// NamedMatch is a pattern-match result for a single ast::MatchNonterminal: // so it is associated with a single ident in a parse, and all -// matched_nonterminals in the named_match have the same nonterminal type -// (expr, item, etc). All the leaves in a single named_match correspond to a -// single matcher_nonterminal in the ast::matcher that produced it. +// MatchedNonterminal's in the NamedMatch have the same nonterminal type +// (expr, item, etc). All the leaves in a single NamedMatch correspond to a +// single matcher_nonterminal in the ast::Matcher that produced it. // // It should probably be renamed, it has more or less exact correspondence to -// ast::match nodes, and the in-memory structure of a particular named_match +// ast::match nodes, and the in-memory structure of a particular NamedMatch // represents the match that occurred when a particular subset of an -// ast::match -- those ast::matcher nodes leading to a single -// match_nonterminal -- was applied to a particular token tree. +// ast::match -- those ast::Matcher nodes leading to a single +// MatchNonterminal -- was applied to a particular token tree. // -// The width of each matched_seq in the named_match, and the identity of the -// matched_nonterminals, will depend on the token tree it was applied to: each -// matched_seq corresponds to a single match_seq in the originating -// ast::matcher. The depth of the named_match structure will therefore depend -// only on the nesting depth of ast::match_seqs in the originating -// ast::matcher it was derived from. - -pub enum named_match { - matched_seq(~[@named_match], codemap::Span), - matched_nonterminal(nonterminal) +// The width of each MatchedSeq in the NamedMatch, and the identity of the +// MatchedNonterminal's, will depend on the token tree it was applied to: each +// MatchedSeq corresponds to a single MatchSeq in the originating +// ast::Matcher. The depth of the NamedMatch structure will therefore depend +// only on the nesting depth of ast::MatchSeq's in the originating +// ast::Matcher it was derived from. + +pub enum NamedMatch { + MatchedSeq(~[@NamedMatch], codemap::Span), + MatchedNonterminal(Nonterminal) } -pub type earley_item = ~MatcherPos; - -pub fn nameize(p_s: @ParseSess, ms: &[matcher], res: &[@named_match]) - -> HashMap<Ident,@named_match> { - fn n_rec(p_s: @ParseSess, m: &matcher, res: &[@named_match], - ret_val: &mut HashMap<Ident, @named_match>) { +pub fn nameize(p_s: @ParseSess, ms: &[Matcher], res: &[@NamedMatch]) + -> HashMap<Ident, @NamedMatch> { + fn n_rec(p_s: @ParseSess, m: &Matcher, res: &[@NamedMatch], + ret_val: &mut HashMap<Ident, @NamedMatch>) { match *m { - codemap::Spanned {node: match_tok(_), .. } => (), - codemap::Spanned {node: match_seq(ref more_ms, _, _, _, _), .. } => { + codemap::Spanned {node: MatchTok(_), .. } => (), + codemap::Spanned {node: MatchSeq(ref more_ms, _, _, _, _), .. } => { for next_m in more_ms.iter() { n_rec(p_s, next_m, res, ret_val) }; } codemap::Spanned { - node: match_nonterminal(ref bind_name, _, idx), span: sp + node: MatchNonterminal(ref bind_name, _, idx), span: sp } => { if ret_val.contains_key(bind_name) { p_s.span_diagnostic.span_fatal(sp, ~"Duplicated bind name: "+ @@ -215,21 +195,21 @@ pub fn nameize(p_s: @ParseSess, ms: &[matcher], res: &[@named_match]) ret_val } -pub enum parse_result { - success(HashMap<Ident, @named_match>), - failure(codemap::Span, ~str), - error(codemap::Span, ~str) +pub enum ParseResult { + Success(HashMap<Ident, @NamedMatch>), + Failure(codemap::Span, ~str), + Error(codemap::Span, ~str) } pub fn parse_or_else(sess: @ParseSess, cfg: ast::CrateConfig, - rdr: @reader, - ms: ~[matcher]) - -> HashMap<Ident, @named_match> { + rdr: @Reader, + ms: ~[Matcher]) + -> HashMap<Ident, @NamedMatch> { match parse(sess, cfg, rdr, ms) { - success(m) => m, - failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str), - error(sp, str) => sess.span_diagnostic.span_fatal(sp, str) + Success(m) => m, + Failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str), + Error(sp, str) => sess.span_diagnostic.span_fatal(sp, str) } } @@ -244,9 +224,9 @@ pub fn token_name_eq(t1 : &Token, t2 : &Token) -> bool { pub fn parse(sess: @ParseSess, cfg: ast::CrateConfig, - rdr: @reader, - ms: &[matcher]) - -> parse_result { + rdr: @Reader, + ms: &[Matcher]) + -> ParseResult { let mut cur_eis = ~[]; cur_eis.push(initial_matcher_pos(ms.to_owned(), None, rdr.peek().sp.lo)); @@ -267,7 +247,7 @@ pub fn parse(sess: @ParseSess, /* at end of sequence */ if idx >= len { // can't move out of `match`es, so: - if is_some(&ei.up) { + if ei.up.is_some() { // hack: a matcher sequence is repeating iff it has a // parent (the top level is just a container) @@ -277,7 +257,7 @@ pub fn parse(sess: @ParseSess, if idx == len { // pop from the matcher position - let mut new_pos = copy_up(&ei.up); + let mut new_pos = ei.up.clone().unwrap(); // update matches (the MBE "parse tree") by appending // each tree as a subtree. @@ -290,9 +270,8 @@ pub fn parse(sess: @ParseSess, for idx in range(ei.match_lo, ei.match_hi) { let sub = ei.matches[idx].clone(); new_pos.matches[idx] - .push(@matched_seq(sub, - mk_sp(ei.sp_lo, - sp.hi))); + .push(@MatchedSeq(sub, mk_sp(ei.sp_lo, + sp.hi))); } new_pos.idx += 1; @@ -325,14 +304,14 @@ pub fn parse(sess: @ParseSess, } else { match ei.elts[idx].node.clone() { /* need to descend into sequence */ - match_seq(ref matchers, ref sep, zero_ok, - match_idx_lo, match_idx_hi) => { + MatchSeq(ref matchers, ref sep, zero_ok, + match_idx_lo, match_idx_hi) => { if zero_ok { let mut new_ei = ei.clone(); new_ei.idx += 1u; //we specifically matched zero repeats. for idx in range(match_idx_lo, match_idx_hi) { - new_ei.matches[idx].push(@matched_seq(~[], sp)); + new_ei.matches[idx].push(@MatchedSeq(~[], sp)); } cur_eis.push(new_ei); @@ -344,14 +323,14 @@ pub fn parse(sess: @ParseSess, elts: (*matchers).clone(), sep: (*sep).clone(), idx: 0u, - up: matcher_pos_up(Some(ei_t)), + up: Some(ei_t), matches: matches, match_lo: match_idx_lo, match_hi: match_idx_hi, sp_lo: sp.lo }); } - match_nonterminal(_,_,_) => { bb_eis.push(ei) } - match_tok(ref t) => { + MatchNonterminal(_,_,_) => { bb_eis.push(ei) } + MatchTok(ref t) => { let mut ei_t = ei.clone(); //if (token_name_eq(t,&tok)) { if (token::mtwt_token_eq(t,&tok)) { @@ -370,29 +349,29 @@ pub fn parse(sess: @ParseSess, for dv in eof_eis[0u].matches.mut_iter() { v.push(dv.pop()); } - return success(nameize(sess, ms, v)); + return Success(nameize(sess, ms, v)); } else if eof_eis.len() > 1u { - return error(sp, ~"Ambiguity: multiple successful parses"); + return Error(sp, ~"Ambiguity: multiple successful parses"); } else { - return failure(sp, ~"Unexpected end of macro invocation"); + return Failure(sp, ~"Unexpected end of macro invocation"); } } else { if (bb_eis.len() > 0u && next_eis.len() > 0u) || bb_eis.len() > 1u { let nts = bb_eis.map(|ei| { match ei.elts[ei.idx].node { - match_nonterminal(ref bind,ref name,_) => { + MatchNonterminal(ref bind,ref name,_) => { format!("{} ('{}')", ident_to_str(name), ident_to_str(bind)) } _ => fail!() } }).connect(" or "); - return error(sp, format!( + return Error(sp, format!( "Local ambiguity: multiple parsing options: \ built-in NTs {} or {} other options.", nts, next_eis.len())); } else if (bb_eis.len() == 0u && next_eis.len() == 0u) { - return failure(sp, ~"No rules expected the token: " + return Failure(sp, ~"No rules expected the token: " + to_str(get_ident_interner(), &tok)); } else if (next_eis.len() > 0u) { /* Now process the next token */ @@ -405,8 +384,8 @@ pub fn parse(sess: @ParseSess, let mut ei = bb_eis.pop(); match ei.elts[ei.idx].node { - match_nonterminal(_, ref name, idx) => { - ei.matches[idx].push(@matched_nonterminal( + MatchNonterminal(_, ref name, idx) => { + ei.matches[idx].push(@MatchedNonterminal( parse_nt(&mut rust_parser, ident_to_str(name)))); ei.idx += 1u; } @@ -424,36 +403,36 @@ pub fn parse(sess: @ParseSess, } } -pub fn parse_nt(p: &mut Parser, name: &str) -> nonterminal { +pub fn parse_nt(p: &mut Parser, name: &str) -> Nonterminal { match name { "item" => match p.parse_item(~[]) { - Some(i) => token::nt_item(i), + Some(i) => token::NtItem(i), None => p.fatal("expected an item keyword") }, - "block" => token::nt_block(p.parse_block()), - "stmt" => token::nt_stmt(p.parse_stmt(~[])), - "pat" => token::nt_pat(p.parse_pat()), - "expr" => token::nt_expr(p.parse_expr()), - "ty" => token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)), + "block" => token::NtBlock(p.parse_block()), + "stmt" => token::NtStmt(p.parse_stmt(~[])), + "pat" => token::NtPat(p.parse_pat()), + "expr" => token::NtExpr(p.parse_expr()), + "ty" => token::NtTy(p.parse_ty(false /* no need to disambiguate*/)), // this could be handled like a token, since it is one "ident" => match p.token { - token::IDENT(sn,b) => { p.bump(); token::nt_ident(~sn,b) } + token::IDENT(sn,b) => { p.bump(); token::NtIdent(~sn,b) } _ => { let token_str = token::to_str(get_ident_interner(), &p.token); p.fatal(~"expected ident, found " + token_str) } }, "path" => { - token::nt_path(~p.parse_path(LifetimeAndTypesWithoutColons).path) + token::NtPath(~p.parse_path(LifetimeAndTypesWithoutColons).path) } - "attr" => token::nt_attr(@p.parse_attribute(false)), + "attr" => token::NtAttr(@p.parse_attribute(false)), "tt" => { p.quote_depth += 1u; //but in theory, non-quoted tts might be useful - let res = token::nt_tt(@p.parse_token_tree()); + let res = token::NtTT(@p.parse_token_tree()); p.quote_depth -= 1u; res } - "matchers" => token::nt_matchers(p.parse_matchers()), + "matchers" => token::NtMatchers(p.parse_matchers()), _ => p.fatal(~"Unsupported builtin nonterminal parser: " + name) } } diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index a2f218325b4..dc5eb0e9537 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -8,21 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{Ident, matcher_, matcher, match_tok, match_nonterminal, match_seq}; -use ast::{tt_delim}; +use ast::{Ident, Matcher_, Matcher, MatchTok, MatchNonterminal, MatchSeq}; +use ast::{TTDelim}; use ast; use codemap::{Span, Spanned, DUMMY_SP}; use ext::base::{AnyMacro, ExtCtxt, MacResult, MRAny, MRDef, MacroDef}; use ext::base::{NormalTT, SyntaxExpanderTTTrait}; use ext::base; -use ext::tt::macro_parser::{error}; -use ext::tt::macro_parser::{named_match, matched_seq, matched_nonterminal}; -use ext::tt::macro_parser::{parse, parse_or_else, success, failure}; -use parse::lexer::{new_tt_reader, reader}; +use ext::tt::macro_parser::{Success, Error, Failure}; +use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal}; +use ext::tt::macro_parser::{parse, parse_or_else}; +use parse::lexer::{new_tt_reader, Reader}; use parse::parser::Parser; -use parse::attr::parser_attr; +use parse::attr::ParserAttr; use parse::token::{get_ident_interner, special_idents, gensym_ident, ident_to_str}; -use parse::token::{FAT_ARROW, SEMI, nt_matchers, nt_tt, EOF}; +use parse::token::{FAT_ARROW, SEMI, NtMatchers, NtTT, EOF}; use print; use std::cell::RefCell; use util::small_vector::SmallVector; @@ -63,7 +63,7 @@ impl AnyMacro for ParserAnyMacro { self.ensure_complete_parse(true); ret } - fn make_items(&self) -> SmallVector<@ast::item> { + fn make_items(&self) -> SmallVector<@ast::Item> { let mut ret = SmallVector::zero(); loop { let mut parser = self.parser.borrow_mut(); @@ -89,15 +89,15 @@ impl AnyMacro for ParserAnyMacro { struct MacroRulesSyntaxExpanderTTFun { name: Ident, - lhses: @~[@named_match], - rhses: @~[@named_match], + lhses: @~[@NamedMatch], + rhses: @~[@NamedMatch], } impl SyntaxExpanderTTTrait for MacroRulesSyntaxExpanderTTFun { fn expand(&self, cx: &mut ExtCtxt, sp: Span, - arg: &[ast::token_tree], + arg: &[ast::TokenTree], _: ast::SyntaxContext) -> MacResult { generic_extension(cx, sp, self.name, arg, *self.lhses, *self.rhses) @@ -108,16 +108,15 @@ impl SyntaxExpanderTTTrait for MacroRulesSyntaxExpanderTTFun { fn generic_extension(cx: &ExtCtxt, sp: Span, name: Ident, - arg: &[ast::token_tree], - lhses: &[@named_match], - rhses: &[@named_match]) + arg: &[ast::TokenTree], + lhses: &[@NamedMatch], + rhses: &[@NamedMatch]) -> MacResult { if cx.trace_macros() { println!("{}! \\{ {} \\}", cx.str_of(name), - print::pprust::tt_to_str( - &ast::tt_delim(@arg.to_owned()), - get_ident_interner())); + print::pprust::tt_to_str(&TTDelim(@arg.to_owned()), + get_ident_interner())); } // Which arm's failure should we report? (the one furthest along) @@ -128,17 +127,17 @@ fn generic_extension(cx: &ExtCtxt, for (i, lhs) in lhses.iter().enumerate() { // try each arm's matchers match *lhs { - @matched_nonterminal(nt_matchers(ref mtcs)) => { + @MatchedNonterminal(NtMatchers(ref mtcs)) => { // `none` is because we're not interpolating - let arg_rdr = new_tt_reader(s_d, None, arg.to_owned()) as @reader; + let arg_rdr = new_tt_reader(s_d, None, arg.to_owned()) as @Reader; match parse(cx.parse_sess(), cx.cfg(), arg_rdr, *mtcs) { - success(named_matches) => { + Success(named_matches) => { let rhs = match rhses[i] { // okay, what's your transcriber? - @matched_nonterminal(nt_tt(@ref tt)) => { + @MatchedNonterminal(NtTT(@ref tt)) => { match (*tt) { // cut off delimiters; don't parse 'em - tt_delim(ref tts) => { + TTDelim(ref tts) => { (*tts).slice(1u,(*tts).len()-1u).to_owned() } _ => cx.span_fatal( @@ -150,18 +149,18 @@ fn generic_extension(cx: &ExtCtxt, // rhs has holes ( `$id` and `$(...)` that need filled) let trncbr = new_tt_reader(s_d, Some(named_matches), rhs); - let p = Parser(cx.parse_sess(), cx.cfg(), trncbr as @reader); + let p = Parser(cx.parse_sess(), cx.cfg(), trncbr as @Reader); // Let the context choose how to interpret the result. // Weird, but useful for X-macros. return MRAny(@ParserAnyMacro { parser: RefCell::new(p), } as @AnyMacro) } - failure(sp, ref msg) => if sp.lo >= best_fail_spot.lo { + Failure(sp, ref msg) => if sp.lo >= best_fail_spot.lo { best_fail_spot = sp; best_fail_msg = (*msg).clone(); }, - error(sp, ref msg) => cx.span_fatal(sp, (*msg)) + Error(sp, ref msg) => cx.span_fatal(sp, (*msg)) } } _ => cx.bug("non-matcher found in parsed lhses") @@ -176,11 +175,11 @@ fn generic_extension(cx: &ExtCtxt, pub fn add_new_extension(cx: &mut ExtCtxt, sp: Span, name: Ident, - arg: ~[ast::token_tree], + arg: ~[ast::TokenTree], _: ast::SyntaxContext) -> base::MacResult { // these spans won't matter, anyways - fn ms(m: matcher_) -> matcher { + fn ms(m: Matcher_) -> Matcher { Spanned { node: m.clone(), span: DUMMY_SP @@ -195,14 +194,14 @@ pub fn add_new_extension(cx: &mut ExtCtxt, // $( $lhs:mtcs => $rhs:tt );+ // ...quasiquoting this would be nice. let argument_gram = ~[ - ms(match_seq(~[ - ms(match_nonterminal(lhs_nm, special_idents::matchers, 0u)), - ms(match_tok(FAT_ARROW)), - ms(match_nonterminal(rhs_nm, special_idents::tt, 1u)), + ms(MatchSeq(~[ + ms(MatchNonterminal(lhs_nm, special_idents::matchers, 0u)), + ms(MatchTok(FAT_ARROW)), + ms(MatchNonterminal(rhs_nm, special_idents::tt, 1u)), ], Some(SEMI), false, 0u, 2u)), //to phase into semicolon-termination instead of //semicolon-separation - ms(match_seq(~[ms(match_tok(SEMI))], None, true, 2u, 2u))]; + ms(MatchSeq(~[ms(MatchTok(SEMI))], None, true, 2u, 2u))]; // Parse the macro_rules! invocation (`none` is for no interpolations): @@ -211,18 +210,18 @@ pub fn add_new_extension(cx: &mut ExtCtxt, arg.clone()); let argument_map = parse_or_else(cx.parse_sess(), cx.cfg(), - arg_reader as @reader, + arg_reader as @Reader, argument_gram); // Extract the arguments: let lhses = match *argument_map.get(&lhs_nm) { - @matched_seq(ref s, _) => /* FIXME (#2543) */ @(*s).clone(), + @MatchedSeq(ref s, _) => /* FIXME (#2543) */ @(*s).clone(), _ => cx.span_bug(sp, "wrong-structured lhs") }; let rhses = match *argument_map.get(&rhs_nm) { - @matched_seq(ref s, _) => /* FIXME (#2543) */ @(*s).clone(), - _ => cx.span_bug(sp, "wrong-structured rhs") + @MatchedSeq(ref s, _) => /* FIXME (#2543) */ @(*s).clone(), + _ => cx.span_bug(sp, "wrong-structured rhs") }; let exp = ~MacroRulesSyntaxExpanderTTFun { diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 060f6b8a8b9..2b90f4221a8 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -9,11 +9,11 @@ // except according to those terms. use ast; -use ast::{token_tree, tt_delim, tt_tok, tt_seq, tt_nonterminal,Ident}; +use ast::{TokenTree, TTDelim, TTTok, TTSeq, TTNonterminal, Ident}; use codemap::{Span, DUMMY_SP}; use diagnostic::SpanHandler; -use ext::tt::macro_parser::{named_match, matched_seq, matched_nonterminal}; -use parse::token::{EOF, INTERPOLATED, IDENT, Token, nt_ident}; +use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal}; +use parse::token::{EOF, INTERPOLATED, IDENT, Token, NtIdent}; use parse::token::{ident_to_str}; use parse::lexer::TokenAndSpan; @@ -21,9 +21,9 @@ use std::cell::{Cell, RefCell}; use std::hashmap::HashMap; use std::option; -///an unzipping of `token_tree`s +///an unzipping of `TokenTree`s struct TtFrame { - forest: @~[ast::token_tree], + forest: @~[ast::TokenTree], idx: Cell<uint>, dotdotdoted: bool, sep: Option<Token>, @@ -35,7 +35,7 @@ pub struct TtReader { // the unzipped tree: priv stack: RefCell<@TtFrame>, /* for MBE-style macro transcription */ - priv interpolations: RefCell<HashMap<Ident, @named_match>>, + priv interpolations: RefCell<HashMap<Ident, @NamedMatch>>, priv repeat_idx: RefCell<~[uint]>, priv repeat_len: RefCell<~[uint]>, /* cached: */ @@ -44,11 +44,11 @@ pub struct TtReader { } /** This can do Macro-By-Example transcription. On the other hand, if - * `src` contains no `tt_seq`s and `tt_nonterminal`s, `interp` can (and + * `src` contains no `TTSeq`s and `TTNonterminal`s, `interp` can (and * should) be none. */ pub fn new_tt_reader(sp_diag: @SpanHandler, - interp: Option<HashMap<Ident,@named_match>>, - src: ~[ast::token_tree]) + interp: Option<HashMap<Ident, @NamedMatch>>, + src: ~[ast::TokenTree]) -> @TtReader { let r = @TtReader { sp_diag: sp_diag, @@ -99,22 +99,22 @@ pub fn dup_tt_reader(r: @TtReader) -> @TtReader { } -fn lookup_cur_matched_by_matched(r: &TtReader, start: @named_match) - -> @named_match { - fn red(ad: @named_match, idx: &uint) -> @named_match { +fn lookup_cur_matched_by_matched(r: &TtReader, start: @NamedMatch) + -> @NamedMatch { + fn red(ad: @NamedMatch, idx: &uint) -> @NamedMatch { match *ad { - matched_nonterminal(_) => { - // end of the line; duplicate henceforth - ad - } - matched_seq(ref ads, _) => ads[*idx] + MatchedNonterminal(_) => { + // end of the line; duplicate henceforth + ad + } + MatchedSeq(ref ads, _) => ads[*idx] } } let repeat_idx = r.repeat_idx.borrow(); repeat_idx.get().iter().fold(start, red) } -fn lookup_cur_matched(r: &TtReader, name: Ident) -> @named_match { +fn lookup_cur_matched(r: &TtReader, name: Ident) -> @NamedMatch { let matched_opt = { let interpolations = r.interpolations.borrow(); interpolations.get().find_copy(&name) @@ -130,43 +130,43 @@ fn lookup_cur_matched(r: &TtReader, name: Ident) -> @named_match { } #[deriving(Clone)] -enum lis { - lis_unconstrained, - lis_constraint(uint, Ident), - lis_contradiction(~str), +enum LockstepIterSize { + LisUnconstrained, + LisConstraint(uint, Ident), + LisContradiction(~str), } -fn lockstep_iter_size(t: &token_tree, r: &TtReader) -> lis { - fn lis_merge(lhs: lis, rhs: lis) -> lis { - match lhs { - lis_unconstrained => rhs.clone(), - lis_contradiction(_) => lhs.clone(), - lis_constraint(l_len, ref l_id) => match rhs { - lis_unconstrained => lhs.clone(), - lis_contradiction(_) => rhs.clone(), - lis_constraint(r_len, _) if l_len == r_len => lhs.clone(), - lis_constraint(r_len, ref r_id) => { +fn lis_merge(lhs: LockstepIterSize, rhs: LockstepIterSize) -> LockstepIterSize { + match lhs { + LisUnconstrained => rhs.clone(), + LisContradiction(_) => lhs.clone(), + LisConstraint(l_len, ref l_id) => match rhs { + LisUnconstrained => lhs.clone(), + LisContradiction(_) => rhs.clone(), + LisConstraint(r_len, _) if l_len == r_len => lhs.clone(), + LisConstraint(r_len, ref r_id) => { let l_n = ident_to_str(l_id); let r_n = ident_to_str(r_id); - lis_contradiction(format!("Inconsistent lockstep iteration: \ - '{}' has {} items, but '{}' has {}", - l_n, l_len, r_n, r_len)) + LisContradiction(format!("Inconsistent lockstep iteration: \ + '{}' has {} items, but '{}' has {}", + l_n, l_len, r_n, r_len)) } - } } } +} + +fn lockstep_iter_size(t: &TokenTree, r: &TtReader) -> LockstepIterSize { match *t { - tt_delim(ref tts) | tt_seq(_, ref tts, _, _) => { - tts.iter().fold(lis_unconstrained, |lis, tt| { - let lis2 = lockstep_iter_size(tt, r); - lis_merge(lis, lis2) - }) - } - tt_tok(..) => lis_unconstrained, - tt_nonterminal(_, name) => match *lookup_cur_matched(r, name) { - matched_nonterminal(_) => lis_unconstrained, - matched_seq(ref ads, _) => lis_constraint(ads.len(), name) - } + TTDelim(ref tts) | TTSeq(_, ref tts, _, _) => { + tts.iter().fold(LisUnconstrained, |lis, tt| { + lis_merge(lis, lockstep_iter_size(tt, r)) + }) + } + TTTok(..) => LisUnconstrained, + TTNonterminal(_, name) => match *lookup_cur_matched(r, name) { + MatchedNonterminal(_) => LisUnconstrained, + MatchedSeq(ref ads, _) => LisConstraint(ads.len(), name) + } } } @@ -228,11 +228,11 @@ pub fn tt_next_token(r: &TtReader) -> TokenAndSpan { } } } - loop { /* because it's easiest, this handles `tt_delim` not starting - with a `tt_tok`, even though it won't happen */ + loop { /* because it's easiest, this handles `TTDelim` not starting + with a `TTTok`, even though it won't happen */ // XXX(pcwalton): Bad copy. match r.stack.get().forest[r.stack.get().idx.get()].clone() { - tt_delim(tts) => { + TTDelim(tts) => { r.stack.set(@TtFrame { forest: tts, idx: Cell::new(0u), @@ -242,28 +242,28 @@ pub fn tt_next_token(r: &TtReader) -> TokenAndSpan { }); // if this could be 0-length, we'd need to potentially recur here } - tt_tok(sp, tok) => { + TTTok(sp, tok) => { r.cur_span.set(sp); r.cur_tok.set(tok); r.stack.get().idx.set(r.stack.get().idx.get() + 1u); return ret_val; } - tt_seq(sp, tts, sep, zerok) => { + TTSeq(sp, tts, sep, zerok) => { // XXX(pcwalton): Bad copy. - let t = tt_seq(sp, tts, sep.clone(), zerok); + let t = TTSeq(sp, tts, sep.clone(), zerok); match lockstep_iter_size(&t, r) { - lis_unconstrained => { + LisUnconstrained => { r.sp_diag.span_fatal( sp, /* blame macro writer */ "attempted to repeat an expression \ containing no syntax \ variables matched as repeating at this depth"); } - lis_contradiction(ref msg) => { + LisContradiction(ref msg) => { /* FIXME #2887 blame macro invoker instead*/ r.sp_diag.span_fatal(sp, (*msg)); } - lis_constraint(len, _) => { + LisConstraint(len, _) => { if len == 0 { if !zerok { r.sp_diag.span_fatal(sp, /* FIXME #2887 blame invoker @@ -293,25 +293,25 @@ pub fn tt_next_token(r: &TtReader) -> TokenAndSpan { } } // FIXME #2887: think about span stuff here - tt_nonterminal(sp, ident) => { + TTNonterminal(sp, ident) => { match *lookup_cur_matched(r, ident) { /* sidestep the interpolation tricks for ident because (a) idents can be in lots of places, so it'd be a pain (b) we actually can, since it's a token. */ - matched_nonterminal(nt_ident(~sn,b)) => { + MatchedNonterminal(NtIdent(~sn,b)) => { r.cur_span.set(sp); r.cur_tok.set(IDENT(sn,b)); r.stack.get().idx.set(r.stack.get().idx.get() + 1u); return ret_val; } - matched_nonterminal(ref other_whole_nt) => { + MatchedNonterminal(ref other_whole_nt) => { // XXX(pcwalton): Bad copy. r.cur_span.set(sp); r.cur_tok.set(INTERPOLATED((*other_whole_nt).clone())); r.stack.get().idx.set(r.stack.get().idx.get() + 1u); return ret_val; } - matched_seq(..) => { + MatchedSeq(..) => { r.sp_diag.span_fatal( r.cur_span.get(), /* blame the macro writer */ format!("variable '{}' is still repeating at this depth", diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 8fab2df7a5d..c73edb0bfcf 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -16,7 +16,7 @@ use opt_vec::OptVec; use util::small_vector::SmallVector; // We may eventually want to be able to fold over type parameters, too. -pub trait ast_fold { +pub trait Folder { fn fold_crate(&mut self, c: Crate) -> Crate { noop_fold_crate(c, self) } @@ -25,24 +25,24 @@ pub trait ast_fold { meta_items.map(|x| fold_meta_item_(*x, self)) } - fn fold_view_paths(&mut self, view_paths: &[@view_path]) -> ~[@view_path] { + fn fold_view_paths(&mut self, view_paths: &[@ViewPath]) -> ~[@ViewPath] { view_paths.map(|view_path| { let inner_view_path = match view_path.node { - view_path_simple(ref ident, ref path, node_id) => { - view_path_simple(ident.clone(), - self.fold_path(path), - self.new_id(node_id)) + ViewPathSimple(ref ident, ref path, node_id) => { + ViewPathSimple(ident.clone(), + self.fold_path(path), + self.new_id(node_id)) } - view_path_glob(ref path, node_id) => { - view_path_glob(self.fold_path(path), self.new_id(node_id)) + ViewPathGlob(ref path, node_id) => { + ViewPathGlob(self.fold_path(path), self.new_id(node_id)) } - view_path_list(ref path, ref path_list_idents, node_id) => { - view_path_list(self.fold_path(path), - path_list_idents.map(|path_list_ident| { + ViewPathList(ref path, ref path_list_idents, node_id) => { + ViewPathList(self.fold_path(path), + path_list_idents.map(|path_list_ident| { let id = self.new_id(path_list_ident.node .id); Spanned { - node: path_list_ident_ { + node: PathListIdent_ { name: path_list_ident.node .name .clone(), @@ -50,9 +50,9 @@ pub trait ast_fold { }, span: self.new_span( path_list_ident.span) - } - }), - self.new_id(node_id)) + } + }), + self.new_id(node_id)) } }; @Spanned { @@ -62,20 +62,16 @@ pub trait ast_fold { }) } - fn fold_view_item(&mut self, vi: &view_item) -> view_item { + fn fold_view_item(&mut self, vi: &ViewItem) -> ViewItem { let inner_view_item = match vi.node { - view_item_extern_mod(ref ident, - string, - node_id) => { - view_item_extern_mod(ident.clone(), - string, - self.new_id(node_id)) + ViewItemExternMod(ref ident, string, node_id) => { + ViewItemExternMod(ident.clone(), string, self.new_id(node_id)) } - view_item_use(ref view_paths) => { - view_item_use(self.fold_view_paths(*view_paths)) + ViewItemUse(ref view_paths) => { + ViewItemUse(self.fold_view_paths(*view_paths)) } }; - view_item { + ViewItem { node: inner_view_item, attrs: vi.attrs.map(|a| fold_attribute_(*a, self)), vis: vi.vis, @@ -83,19 +79,19 @@ pub trait ast_fold { } } - fn fold_foreign_item(&mut self, ni: @foreign_item) -> @foreign_item { + fn fold_foreign_item(&mut self, ni: @ForeignItem) -> @ForeignItem { noop_fold_foreign_item(ni, self) } - fn fold_item(&mut self, i: @item) -> SmallVector<@item> { + fn fold_item(&mut self, i: @Item) -> SmallVector<@Item> { noop_fold_item(i, self) } - fn fold_struct_field(&mut self, sf: &struct_field) -> struct_field { + fn fold_struct_field(&mut self, sf: &StructField) -> StructField { let fold_attribute = |x| fold_attribute_(x, self); Spanned { - node: ast::struct_field_ { + node: ast::StructField_ { kind: sf.node.kind, id: self.new_id(sf.node.id), ty: self.fold_ty(sf.node.ty), @@ -105,11 +101,11 @@ pub trait ast_fold { } } - fn fold_item_underscore(&mut self, i: &item_) -> item_ { + fn fold_item_underscore(&mut self, i: &Item_) -> Item_ { noop_fold_item_underscore(i, self) } - fn fold_fn_decl(&mut self, d: &fn_decl) -> P<fn_decl> { + fn fold_fn_decl(&mut self, d: &FnDecl) -> P<FnDecl> { noop_fold_fn_decl(d, self) } @@ -117,7 +113,7 @@ pub trait ast_fold { noop_fold_type_method(m, self) } - fn fold_method(&mut self, m: @method) -> @method { + fn fold_method(&mut self, m: @Method) -> @Method { noop_fold_method(m, self) } @@ -163,16 +159,16 @@ pub trait ast_fold { fn fold_ty(&mut self, t: P<Ty>) -> P<Ty> { let node = match t.node { - ty_nil | ty_bot | ty_infer => t.node.clone(), - ty_box(ty) => ty_box(self.fold_ty(ty)), - ty_uniq(ty) => ty_uniq(self.fold_ty(ty)), - ty_vec(ty) => ty_vec(self.fold_ty(ty)), - ty_ptr(ref mt) => ty_ptr(fold_mt(mt, self)), - ty_rptr(ref region, ref mt) => { - ty_rptr(fold_opt_lifetime(region, self), fold_mt(mt, self)) + TyNil | TyBot | TyInfer => t.node.clone(), + TyBox(ty) => TyBox(self.fold_ty(ty)), + TyUniq(ty) => TyUniq(self.fold_ty(ty)), + TyVec(ty) => TyVec(self.fold_ty(ty)), + TyPtr(ref mt) => TyPtr(fold_mt(mt, self)), + TyRptr(ref region, ref mt) => { + TyRptr(fold_opt_lifetime(region, self), fold_mt(mt, self)) } - ty_closure(ref f) => { - ty_closure(@TyClosure { + TyClosure(ref f) => { + TyClosure(@ClosureTy { sigil: f.sigil, purity: f.purity, region: fold_opt_lifetime(&f.region, self), @@ -182,24 +178,24 @@ pub trait ast_fold { lifetimes: f.lifetimes.map(|l| fold_lifetime(l, self)), }) } - ty_bare_fn(ref f) => { - ty_bare_fn(@TyBareFn { + TyBareFn(ref f) => { + TyBareFn(@BareFnTy { lifetimes: f.lifetimes.map(|l| fold_lifetime(l, self)), purity: f.purity, abis: f.abis, decl: self.fold_fn_decl(f.decl) }) } - ty_tup(ref tys) => ty_tup(tys.map(|&ty| self.fold_ty(ty))), - ty_path(ref path, ref bounds, id) => { - ty_path(self.fold_path(path), - fold_opt_bounds(bounds, self), - self.new_id(id)) + TyTup(ref tys) => TyTup(tys.map(|&ty| self.fold_ty(ty))), + TyPath(ref path, ref bounds, id) => { + TyPath(self.fold_path(path), + fold_opt_bounds(bounds, self), + self.new_id(id)) } - ty_fixed_length_vec(ty, e) => { - ty_fixed_length_vec(self.fold_ty(ty), self.fold_expr(e)) + TyFixedLengthVec(ty, e) => { + TyFixedLengthVec(self.fold_ty(ty), self.fold_expr(e)) } - ty_typeof(expr) => ty_typeof(self.fold_expr(expr)), + TyTypeof(expr) => TyTypeof(self.fold_expr(expr)), }; P(Ty { id: self.new_id(t.id), @@ -208,12 +204,12 @@ pub trait ast_fold { }) } - fn fold_mod(&mut self, m: &_mod) -> _mod { + fn fold_mod(&mut self, m: &Mod) -> Mod { noop_fold_mod(m, self) } - fn fold_foreign_mod(&mut self, nm: &foreign_mod) -> foreign_mod { - ast::foreign_mod { + fn fold_foreign_mod(&mut self, nm: &ForeignMod) -> ForeignMod { + ast::ForeignMod { abis: nm.abis, view_items: nm.view_items .iter() @@ -226,15 +222,15 @@ pub trait ast_fold { } } - fn fold_variant(&mut self, v: &variant) -> P<variant> { + fn fold_variant(&mut self, v: &Variant) -> P<Variant> { let kind; match v.node.kind { - tuple_variant_kind(ref variant_args) => { - kind = tuple_variant_kind(variant_args.map(|x| + TupleVariantKind(ref variant_args) => { + kind = TupleVariantKind(variant_args.map(|x| fold_variant_arg_(x, self))) } - struct_variant_kind(ref struct_def) => { - kind = struct_variant_kind(@ast::struct_def { + StructVariantKind(ref struct_def) => { + kind = StructVariantKind(@ast::StructDef { fields: struct_def.fields.iter() .map(|f| self.fold_struct_field(f)).collect(), ctor_id: struct_def.ctor_id.map(|c| self.new_id(c)) @@ -249,7 +245,7 @@ pub trait ast_fold { Some(e) => Some(self.fold_expr(e)), None => None }; - let node = ast::variant_ { + let node = ast::Variant_ { name: v.node.name, attrs: attrs, kind: kind, @@ -289,13 +285,13 @@ pub trait ast_fold { } } - fn fold_mac(&mut self, macro: &mac) -> mac { + fn fold_mac(&mut self, macro: &Mac) -> Mac { Spanned { node: match macro.node { - mac_invoc_tt(ref p, ref tts, ctxt) => { - mac_invoc_tt(self.fold_path(p), - fold_tts(*tts, self), - ctxt) + MacInvocTT(ref p, ref tts, ctxt) => { + MacInvocTT(self.fold_path(p), + fold_tts(*tts, self), + ctxt) } }, span: self.new_span(macro.span) @@ -314,29 +310,29 @@ pub trait ast_fold { sp } - fn fold_explicit_self(&mut self, es: &explicit_self) -> explicit_self { + fn fold_explicit_self(&mut self, es: &ExplicitSelf) -> ExplicitSelf { Spanned { span: self.new_span(es.span), node: self.fold_explicit_self_(&es.node) } } - fn fold_explicit_self_(&mut self, es: &explicit_self_) -> explicit_self_ { + fn fold_explicit_self_(&mut self, es: &ExplicitSelf_) -> ExplicitSelf_ { match *es { - sty_static | sty_value(_) | sty_uniq(_) | sty_box(_) => { + SelfStatic | SelfValue(_) | SelfUniq(_) | SelfBox(_) => { *es } - sty_region(ref lifetime, m) => { - sty_region(fold_opt_lifetime(lifetime, self), m) + SelfRegion(ref lifetime, m) => { + SelfRegion(fold_opt_lifetime(lifetime, self), m) } } } } -/* some little folds that probably aren't useful to have in ast_fold itself*/ +/* some little folds that probably aren't useful to have in Folder itself*/ //used in noop_fold_item and noop_fold_crate and noop_fold_crate_directive -fn fold_meta_item_<T: ast_fold>(mi: @MetaItem, fld: &mut T) -> @MetaItem { +fn fold_meta_item_<T: Folder>(mi: @MetaItem, fld: &mut T) -> @MetaItem { @Spanned { node: match mi.node { @@ -354,7 +350,7 @@ fn fold_meta_item_<T: ast_fold>(mi: @MetaItem, fld: &mut T) -> @MetaItem { } //used in noop_fold_item and noop_fold_crate -fn fold_attribute_<T: ast_fold>(at: Attribute, fld: &mut T) -> Attribute { +fn fold_attribute_<T: Folder>(at: Attribute, fld: &mut T) -> Attribute { Spanned { span: fld.new_span(at.span), node: ast::Attribute_ { @@ -366,35 +362,35 @@ fn fold_attribute_<T: ast_fold>(at: Attribute, fld: &mut T) -> Attribute { } //used in noop_fold_foreign_item and noop_fold_fn_decl -fn fold_arg_<T: ast_fold>(a: &arg, fld: &mut T) -> arg { - ast::arg { +fn fold_arg_<T: Folder>(a: &Arg, fld: &mut T) -> Arg { + Arg { ty: fld.fold_ty(a.ty), pat: fld.fold_pat(a.pat), id: fld.new_id(a.id), } } -// build a new vector of tts by appling the ast_fold's fold_ident to +// build a new vector of tts by appling the Folder's fold_ident to // all of the identifiers in the token trees. -pub fn fold_tts<T: ast_fold>(tts: &[token_tree], fld: &mut T) -> ~[token_tree] { +pub fn fold_tts<T: Folder>(tts: &[TokenTree], fld: &mut T) -> ~[TokenTree] { tts.map(|tt| { match *tt { - tt_tok(span, ref tok) => - tt_tok(span,maybe_fold_ident(tok,fld)), - tt_delim(tts) => tt_delim(@fold_tts(*tts, fld)), - tt_seq(span, pattern, ref sep, is_optional) => - tt_seq(span, - @fold_tts(*pattern, fld), - sep.as_ref().map(|tok|maybe_fold_ident(tok,fld)), - is_optional), - tt_nonterminal(sp,ref ident) => - tt_nonterminal(sp,fld.fold_ident(*ident)) + TTTok(span, ref tok) => + TTTok(span,maybe_fold_ident(tok,fld)), + TTDelim(tts) => TTDelim(@fold_tts(*tts, fld)), + TTSeq(span, pattern, ref sep, is_optional) => + TTSeq(span, + @fold_tts(*pattern, fld), + sep.as_ref().map(|tok|maybe_fold_ident(tok,fld)), + is_optional), + TTNonterminal(sp,ref ident) => + TTNonterminal(sp,fld.fold_ident(*ident)) } }) } // apply ident folder if it's an ident, otherwise leave it alone -fn maybe_fold_ident<T: ast_fold>(t: &token::Token, fld: &mut T) -> token::Token { +fn maybe_fold_ident<T: Folder>(t: &token::Token, fld: &mut T) -> token::Token { match *t { token::IDENT(id, followed_by_colons) => { token::IDENT(fld.fold_ident(id), followed_by_colons) @@ -403,9 +399,8 @@ fn maybe_fold_ident<T: ast_fold>(t: &token::Token, fld: &mut T) -> token::Token } } -pub fn noop_fold_fn_decl<T: ast_fold>(decl: &fn_decl, fld: &mut T) - -> P<fn_decl> { - P(fn_decl { +pub fn noop_fold_fn_decl<T: Folder>(decl: &FnDecl, fld: &mut T) -> P<FnDecl> { + P(FnDecl { inputs: decl.inputs.map(|x| fold_arg_(x, fld)), // bad copy output: fld.fold_ty(decl.output), cf: decl.cf, @@ -413,7 +408,7 @@ pub fn noop_fold_fn_decl<T: ast_fold>(decl: &fn_decl, fld: &mut T) }) } -fn fold_ty_param_bound<T: ast_fold>(tpb: &TyParamBound, fld: &mut T) +fn fold_ty_param_bound<T: Folder>(tpb: &TyParamBound, fld: &mut T) -> TyParamBound { match *tpb { TraitTyParamBound(ref ty) => TraitTyParamBound(fold_trait_ref(ty, fld)), @@ -421,7 +416,7 @@ fn fold_ty_param_bound<T: ast_fold>(tpb: &TyParamBound, fld: &mut T) } } -pub fn fold_ty_param<T: ast_fold>(tp: &TyParam, fld: &mut T) -> TyParam { +pub fn fold_ty_param<T: Folder>(tp: &TyParam, fld: &mut T) -> TyParam { TyParam { ident: tp.ident, id: fld.new_id(tp.id), @@ -429,12 +424,12 @@ pub fn fold_ty_param<T: ast_fold>(tp: &TyParam, fld: &mut T) -> TyParam { } } -pub fn fold_ty_params<T: ast_fold>(tps: &OptVec<TyParam>, fld: &mut T) +pub fn fold_ty_params<T: Folder>(tps: &OptVec<TyParam>, fld: &mut T) -> OptVec<TyParam> { tps.map(|tp| fold_ty_param(tp, fld)) } -pub fn fold_lifetime<T: ast_fold>(l: &Lifetime, fld: &mut T) -> Lifetime { +pub fn fold_lifetime<T: Folder>(l: &Lifetime, fld: &mut T) -> Lifetime { Lifetime { id: fld.new_id(l.id), span: fld.new_span(l.span), @@ -442,38 +437,38 @@ pub fn fold_lifetime<T: ast_fold>(l: &Lifetime, fld: &mut T) -> Lifetime { } } -pub fn fold_lifetimes<T: ast_fold>(lts: &OptVec<Lifetime>, fld: &mut T) +pub fn fold_lifetimes<T: Folder>(lts: &OptVec<Lifetime>, fld: &mut T) -> OptVec<Lifetime> { lts.map(|l| fold_lifetime(l, fld)) } -pub fn fold_opt_lifetime<T: ast_fold>(o_lt: &Option<Lifetime>, fld: &mut T) +pub fn fold_opt_lifetime<T: Folder>(o_lt: &Option<Lifetime>, fld: &mut T) -> Option<Lifetime> { o_lt.as_ref().map(|lt| fold_lifetime(lt, fld)) } -pub fn fold_generics<T: ast_fold>(generics: &Generics, fld: &mut T) -> Generics { +pub fn fold_generics<T: Folder>(generics: &Generics, fld: &mut T) -> Generics { Generics {ty_params: fold_ty_params(&generics.ty_params, fld), lifetimes: fold_lifetimes(&generics.lifetimes, fld)} } -fn fold_struct_def<T: ast_fold>(struct_def: @struct_def, fld: &mut T) -> @struct_def { - @ast::struct_def { +fn fold_struct_def<T: Folder>(struct_def: @StructDef, fld: &mut T) -> @StructDef { + @ast::StructDef { fields: struct_def.fields.map(|f| fold_struct_field(f, fld)), ctor_id: struct_def.ctor_id.map(|cid| fld.new_id(cid)), } } -fn fold_trait_ref<T: ast_fold>(p: &trait_ref, fld: &mut T) -> trait_ref { - ast::trait_ref { +fn fold_trait_ref<T: Folder>(p: &TraitRef, fld: &mut T) -> TraitRef { + ast::TraitRef { path: fld.fold_path(&p.path), ref_id: fld.new_id(p.ref_id), } } -fn fold_struct_field<T: ast_fold>(f: &struct_field, fld: &mut T) -> struct_field { +fn fold_struct_field<T: Folder>(f: &StructField, fld: &mut T) -> StructField { Spanned { - node: ast::struct_field_ { + node: ast::StructField_ { kind: f.node.kind, id: fld.new_id(f.node.id), ty: fld.fold_ty(f.node.ty), @@ -483,7 +478,7 @@ fn fold_struct_field<T: ast_fold>(f: &struct_field, fld: &mut T) -> struct_field } } -fn fold_field_<T: ast_fold>(field: Field, folder: &mut T) -> Field { +fn fold_field_<T: Folder>(field: Field, folder: &mut T) -> Field { ast::Field { ident: respan(field.ident.span, folder.fold_ident(field.ident.node)), expr: folder.fold_expr(field.expr), @@ -491,15 +486,15 @@ fn fold_field_<T: ast_fold>(field: Field, folder: &mut T) -> Field { } } -fn fold_mt<T: ast_fold>(mt: &mt, folder: &mut T) -> mt { - mt { +fn fold_mt<T: Folder>(mt: &MutTy, folder: &mut T) -> MutTy { + MutTy { ty: folder.fold_ty(mt.ty), mutbl: mt.mutbl, } } -fn fold_opt_bounds<T: ast_fold>(b: &Option<OptVec<TyParamBound>>, folder: &mut T) - -> Option<OptVec<TyParamBound>> { +fn fold_opt_bounds<T: Folder>(b: &Option<OptVec<TyParamBound>>, folder: &mut T) + -> Option<OptVec<TyParamBound>> { b.as_ref().map(|bounds| { bounds.map(|bound| { fold_ty_param_bound(bound, folder) @@ -507,14 +502,14 @@ fn fold_opt_bounds<T: ast_fold>(b: &Option<OptVec<TyParamBound>>, folder: &mut T }) } -fn fold_variant_arg_<T: ast_fold>(va: &variant_arg, folder: &mut T) -> variant_arg { - ast::variant_arg { +fn fold_variant_arg_<T: Folder>(va: &VariantArg, folder: &mut T) -> VariantArg { + ast::VariantArg { ty: folder.fold_ty(va.ty), id: folder.new_id(va.id) } } -pub fn noop_fold_block<T: ast_fold>(b: P<Block>, folder: &mut T) -> P<Block> { +pub fn noop_fold_block<T: Folder>(b: P<Block>, folder: &mut T) -> P<Block> { let view_items = b.view_items.map(|x| folder.fold_view_item(x)); let stmts = b.stmts.iter().flat_map(|s| folder.fold_stmt(*s).move_iter()).collect(); P(Block { @@ -527,13 +522,13 @@ pub fn noop_fold_block<T: ast_fold>(b: P<Block>, folder: &mut T) -> P<Block> { }) } -pub fn noop_fold_item_underscore<T: ast_fold>(i: &item_, folder: &mut T) -> item_ { +pub fn noop_fold_item_underscore<T: Folder>(i: &Item_, folder: &mut T) -> Item_ { match *i { - item_static(t, m, e) => { - item_static(folder.fold_ty(t), m, folder.fold_expr(e)) + ItemStatic(t, m, e) => { + ItemStatic(folder.fold_ty(t), m, folder.fold_expr(e)) } - item_fn(decl, purity, abi, ref generics, body) => { - item_fn( + ItemFn(decl, purity, abi, ref generics, body) => { + ItemFn( folder.fold_fn_decl(decl), purity, abi, @@ -541,50 +536,47 @@ pub fn noop_fold_item_underscore<T: ast_fold>(i: &item_, folder: &mut T) -> item folder.fold_block(body) ) } - item_mod(ref m) => item_mod(folder.fold_mod(m)), - item_foreign_mod(ref nm) => { - item_foreign_mod(folder.fold_foreign_mod(nm)) + ItemMod(ref m) => ItemMod(folder.fold_mod(m)), + ItemForeignMod(ref nm) => ItemForeignMod(folder.fold_foreign_mod(nm)), + ItemTy(t, ref generics) => { + ItemTy(folder.fold_ty(t), fold_generics(generics, folder)) } - item_ty(t, ref generics) => { - item_ty(folder.fold_ty(t), - fold_generics(generics, folder)) - } - item_enum(ref enum_definition, ref generics) => { - item_enum( - ast::enum_def { + ItemEnum(ref enum_definition, ref generics) => { + ItemEnum( + ast::EnumDef { variants: enum_definition.variants.map(|&x| { folder.fold_variant(x) }), }, fold_generics(generics, folder)) } - item_struct(ref struct_def, ref generics) => { + ItemStruct(ref struct_def, ref generics) => { let struct_def = fold_struct_def(*struct_def, folder); - item_struct(struct_def, fold_generics(generics, folder)) + ItemStruct(struct_def, fold_generics(generics, folder)) } - item_impl(ref generics, ref ifce, ty, ref methods) => { - item_impl(fold_generics(generics, folder), - ifce.as_ref().map(|p| fold_trait_ref(p, folder)), - folder.fold_ty(ty), - methods.map(|x| folder.fold_method(*x)) + ItemImpl(ref generics, ref ifce, ty, ref methods) => { + ItemImpl(fold_generics(generics, folder), + ifce.as_ref().map(|p| fold_trait_ref(p, folder)), + folder.fold_ty(ty), + methods.map(|x| folder.fold_method(*x)) ) } - item_trait(ref generics, ref traits, ref methods) => { + ItemTrait(ref generics, ref traits, ref methods) => { let methods = methods.map(|method| { match *method { - required(ref m) => required(folder.fold_type_method(m)), - provided(method) => provided(folder.fold_method(method)) + Required(ref m) => Required(folder.fold_type_method(m)), + Provided(method) => Provided(folder.fold_method(method)) } }); - item_trait(fold_generics(generics, folder), - traits.map(|p| fold_trait_ref(p, folder)), - methods) + ItemTrait(fold_generics(generics, folder), + traits.map(|p| fold_trait_ref(p, folder)), + methods) } - item_mac(ref m) => item_mac(folder.fold_mac(m)), + ItemMac(ref m) => ItemMac(folder.fold_mac(m)), } } -pub fn noop_fold_type_method<T: ast_fold>(m: &TypeMethod, fld: &mut T) -> TypeMethod { +pub fn noop_fold_type_method<T: Folder>(m: &TypeMethod, fld: &mut T) -> TypeMethod { TypeMethod { ident: fld.fold_ident(m.ident), attrs: m.attrs.map(|a| fold_attribute_(*a, fld)), @@ -597,8 +589,8 @@ pub fn noop_fold_type_method<T: ast_fold>(m: &TypeMethod, fld: &mut T) -> TypeMe } } -pub fn noop_fold_mod<T: ast_fold>(m: &_mod, folder: &mut T) -> _mod { - ast::_mod { +pub fn noop_fold_mod<T: Folder>(m: &Mod, folder: &mut T) -> Mod { + ast::Mod { view_items: m.view_items .iter() .map(|x| folder.fold_view_item(x)).collect(), @@ -606,7 +598,7 @@ pub fn noop_fold_mod<T: ast_fold>(m: &_mod, folder: &mut T) -> _mod { } } -pub fn noop_fold_crate<T: ast_fold>(c: Crate, folder: &mut T) -> Crate { +pub fn noop_fold_crate<T: Folder>(c: Crate, folder: &mut T) -> Crate { let fold_meta_item = |x| fold_meta_item_(x, folder); let fold_attribute = |x| fold_attribute_(x, folder); @@ -618,11 +610,10 @@ pub fn noop_fold_crate<T: ast_fold>(c: Crate, folder: &mut T) -> Crate { } } -pub fn noop_fold_item<T: ast_fold>(i: &item, folder: &mut T) - -> SmallVector<@item> { +pub fn noop_fold_item<T: Folder>(i: &Item, folder: &mut T) -> SmallVector<@Item> { let fold_attribute = |x| fold_attribute_(x, folder); - SmallVector::one(@item { + SmallVector::one(@Item { ident: folder.fold_ident(i.ident), attrs: i.attrs.map(|e| fold_attribute(*e)), id: folder.new_id(i.id), @@ -632,22 +623,21 @@ pub fn noop_fold_item<T: ast_fold>(i: &item, folder: &mut T) }) } -pub fn noop_fold_foreign_item<T: ast_fold>(ni: &foreign_item, folder: &mut T) - -> @foreign_item { - @foreign_item { +pub fn noop_fold_foreign_item<T: Folder>(ni: &ForeignItem, folder: &mut T) -> @ForeignItem { + @ForeignItem { ident: folder.fold_ident(ni.ident), attrs: ni.attrs.map(|x| fold_attribute_(*x, folder)), node: match ni.node { - foreign_item_fn(ref fdec, ref generics) => { - foreign_item_fn(P(fn_decl { + ForeignItemFn(ref fdec, ref generics) => { + ForeignItemFn(P(FnDecl { inputs: fdec.inputs.map(|a| fold_arg_(a, folder)), output: folder.fold_ty(fdec.output), cf: fdec.cf, variadic: fdec.variadic }), fold_generics(generics, folder)) } - foreign_item_static(t, m) => { - foreign_item_static(folder.fold_ty(t), m) + ForeignItemStatic(t, m) => { + ForeignItemStatic(folder.fold_ty(t), m) } }, id: folder.new_id(ni.id), @@ -656,8 +646,8 @@ pub fn noop_fold_foreign_item<T: ast_fold>(ni: &foreign_item, folder: &mut T) } } -pub fn noop_fold_method<T: ast_fold>(m: &method, folder: &mut T) -> @method { - @method { +pub fn noop_fold_method<T: Folder>(m: &Method, folder: &mut T) -> @Method { + @Method { ident: folder.fold_ident(m.ident), attrs: m.attrs.map(|a| fold_attribute_(*a, folder)), generics: fold_generics(&m.generics, folder), @@ -672,7 +662,7 @@ pub fn noop_fold_method<T: ast_fold>(m: &method, folder: &mut T) -> @method { } } -pub fn noop_fold_pat<T: ast_fold>(p: @Pat, folder: &mut T) -> @Pat { +pub fn noop_fold_pat<T: Folder>(p: @Pat, folder: &mut T) -> @Pat { let node = match p.node { PatWild => PatWild, PatWildMulti => PatWildMulti, @@ -717,7 +707,7 @@ pub fn noop_fold_pat<T: ast_fold>(p: @Pat, folder: &mut T) -> @Pat { } } -pub fn noop_fold_expr<T: ast_fold>(e: @Expr, folder: &mut T) -> @Expr { +pub fn noop_fold_expr<T: Folder>(e: @Expr, folder: &mut T) -> @Expr { let fold_field = |x| fold_field_(x, folder); let node = match e.node { @@ -818,7 +808,7 @@ pub fn noop_fold_expr<T: ast_fold>(e: @Expr, folder: &mut T) -> @Expr { ExprRet(e.map(|x| folder.fold_expr(x))) } ExprInlineAsm(ref a) => { - ExprInlineAsm(inline_asm { + ExprInlineAsm(InlineAsm { inputs: a.inputs.map(|&(c, input)| (c, folder.fold_expr(input))), outputs: a.outputs.map(|&(c, out)| (c, folder.fold_expr(out))), .. (*a).clone() @@ -840,7 +830,7 @@ pub fn noop_fold_expr<T: ast_fold>(e: @Expr, folder: &mut T) -> @Expr { } } -pub fn noop_fold_stmt<T: ast_fold>(s: &Stmt, folder: &mut T) -> SmallVector<@Stmt> { +pub fn noop_fold_stmt<T: Folder>(s: &Stmt, folder: &mut T) -> SmallVector<@Stmt> { let nodes = match s.node { StmtDecl(d, nid) => { folder.fold_decl(d).move_iter() @@ -871,14 +861,14 @@ mod test { use super::*; // this version doesn't care about getting comments or docstrings in. - fn fake_print_crate(s: &mut pprust::ps, crate: &ast::Crate) { + fn fake_print_crate(s: &mut pprust::State, crate: &ast::Crate) { pprust::print_mod(s, &crate.module, crate.attrs); } // change every identifier to "zz" struct ToZzIdentFolder; - impl ast_fold for ToZzIdentFolder { + impl Folder for ToZzIdentFolder { fn fold_ident(&mut self, _: ast::Ident) -> ast::Ident { token::str_to_ident("zz") } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 5128cdd54cc..0fd4c5c193c 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -28,6 +28,8 @@ This API is completely unstable and subject to change. #[feature(macro_rules, globs, managed_boxes)]; +#[deny(non_camel_case_types)]; + extern mod extra; pub mod util { diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index c8ebc803604..e7630a66855 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -16,7 +16,7 @@ use parse::parser::Parser; use parse::token::INTERPOLATED; // a parser that can parse attributes. -pub trait parser_attr { +pub trait ParserAttr { fn parse_outer_attributes(&mut self) -> ~[ast::Attribute]; fn parse_attribute(&mut self, permit_inner: bool) -> ast::Attribute; fn parse_inner_attrs_and_next(&mut self) @@ -26,7 +26,7 @@ pub trait parser_attr { fn parse_optional_meta(&mut self) -> ~[@ast::MetaItem]; } -impl parser_attr for Parser { +impl ParserAttr for Parser { // Parse attributes that appear before an item fn parse_outer_attributes(&mut self) -> ~[ast::Attribute] { let mut attrs: ~[ast::Attribute] = ~[]; @@ -34,7 +34,7 @@ impl parser_attr for Parser { debug!("parse_outer_attributes: self.token={:?}", self.token); match self.token { - token::INTERPOLATED(token::nt_attr(..)) => { + token::INTERPOLATED(token::NtAttr(..)) => { attrs.push(self.parse_attribute(false)); } token::POUND => { @@ -69,7 +69,7 @@ impl parser_attr for Parser { debug!("parse_attributes: permit_inner={:?} self.token={:?}", permit_inner, self.token); let (span, value) = match self.token { - INTERPOLATED(token::nt_attr(attr)) => { + INTERPOLATED(token::NtAttr(attr)) => { assert!(attr.node.style == ast::AttrOuter); self.bump(); (attr.span, attr.node.value) @@ -121,7 +121,7 @@ impl parser_attr for Parser { let mut next_outer_attrs: ~[ast::Attribute] = ~[]; loop { let attr = match self.token { - token::INTERPOLATED(token::nt_attr(..)) => { + token::INTERPOLATED(token::NtAttr(..)) => { self.parse_attribute(true) } token::POUND => { @@ -165,7 +165,7 @@ impl parser_attr for Parser { // FIXME #623 Non-string meta items are not serialized correctly; // just forbid them for now match lit.node { - ast::lit_str(..) => (), + ast::LitStr(..) => {} _ => { self.span_err( lit.span, diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index e0ab7f1535d..86ab2e099d0 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -11,7 +11,7 @@ use ast; use codemap::{BytePos, CharPos, CodeMap, Pos}; use diagnostic; -use parse::lexer::{is_whitespace, with_str_from, reader}; +use parse::lexer::{is_whitespace, with_str_from, Reader}; use parse::lexer::{StringReader, bump, is_eof, nextch, TokenAndSpan}; use parse::lexer::{is_line_non_doc_comment, is_block_non_doc_comment}; use parse::lexer; @@ -23,16 +23,16 @@ use std::str; use std::uint; #[deriving(Clone, Eq)] -pub enum cmnt_style { - isolated, // No code on either side of each line of the comment - trailing, // Code exists to the left of the comment - mixed, // Code before /* foo */ and after the comment - blank_line, // Just a manual blank line "\n\n", for layout +pub enum CommentStyle { + Isolated, // No code on either side of each line of the comment + Trailing, // Code exists to the left of the comment + Mixed, // Code before /* foo */ and after the comment + BlankLine, // Just a manual blank line "\n\n", for layout } #[deriving(Clone)] -pub struct cmnt { - style: cmnt_style, +pub struct Comment { + style: CommentStyle, lines: ~[~str], pos: BytePos } @@ -159,18 +159,18 @@ fn consume_non_eol_whitespace(rdr: @StringReader) { } } -fn push_blank_line_comment(rdr: @StringReader, comments: &mut ~[cmnt]) { +fn push_blank_line_comment(rdr: @StringReader, comments: &mut ~[Comment]) { debug!(">>> blank-line comment"); let v: ~[~str] = ~[]; - comments.push(cmnt { - style: blank_line, + comments.push(Comment { + style: BlankLine, lines: v, pos: rdr.last_pos.get(), }); } fn consume_whitespace_counting_blank_lines(rdr: @StringReader, - comments: &mut ~[cmnt]) { + comments: &mut ~[Comment]) { while is_whitespace(rdr.curr.get()) && !is_eof(rdr) { if rdr.col.get() == CharPos(0u) && rdr.curr.get() == '\n' { push_blank_line_comment(rdr, &mut *comments); @@ -181,19 +181,19 @@ fn consume_whitespace_counting_blank_lines(rdr: @StringReader, fn read_shebang_comment(rdr: @StringReader, code_to_the_left: bool, - comments: &mut ~[cmnt]) { + comments: &mut ~[Comment]) { debug!(">>> shebang comment"); let p = rdr.last_pos.get(); debug!("<<< shebang comment"); - comments.push(cmnt { - style: if code_to_the_left { trailing } else { isolated }, + comments.push(Comment { + style: if code_to_the_left { Trailing } else { Isolated }, lines: ~[read_one_line_comment(rdr)], pos: p }); } fn read_line_comments(rdr: @StringReader, code_to_the_left: bool, - comments: &mut ~[cmnt]) { + comments: &mut ~[Comment]) { debug!(">>> line comments"); let p = rdr.last_pos.get(); let mut lines: ~[~str] = ~[]; @@ -208,8 +208,8 @@ fn read_line_comments(rdr: @StringReader, code_to_the_left: bool, } debug!("<<< line comments"); if !lines.is_empty() { - comments.push(cmnt { - style: if code_to_the_left { trailing } else { isolated }, + comments.push(Comment { + style: if code_to_the_left { Trailing } else { Isolated }, lines: lines, pos: p }); @@ -251,7 +251,7 @@ fn trim_whitespace_prefix_and_push_line(lines: &mut ~[~str], fn read_block_comment(rdr: @StringReader, code_to_the_left: bool, - comments: &mut ~[cmnt]) { + comments: &mut ~[Comment]) { debug!(">>> block comment"); let p = rdr.last_pos.get(); let mut lines: ~[~str] = ~[]; @@ -280,7 +280,7 @@ fn read_block_comment(rdr: @StringReader, while level > 0 { debug!("=== block comment level {}", level); if is_eof(rdr) { - (rdr as @reader).fatal(~"unterminated block comment"); + (rdr as @Reader).fatal(~"unterminated block comment"); } if rdr.curr.get() == '\n' { trim_whitespace_prefix_and_push_line(&mut lines, curr_line, @@ -309,13 +309,13 @@ fn read_block_comment(rdr: @StringReader, } } - let mut style = if code_to_the_left { trailing } else { isolated }; + let mut style = if code_to_the_left { Trailing } else { Isolated }; consume_non_eol_whitespace(rdr); if !is_eof(rdr) && rdr.curr.get() != '\n' && lines.len() == 1u { - style = mixed; + style = Mixed; } debug!("<<< block comment"); - comments.push(cmnt {style: style, lines: lines, pos: p}); + comments.push(Comment {style: style, lines: lines, pos: p}); } fn peeking_at_comment(rdr: @StringReader) -> bool { @@ -326,7 +326,7 @@ fn peeking_at_comment(rdr: @StringReader) -> bool { fn consume_comment(rdr: @StringReader, code_to_the_left: bool, - comments: &mut ~[cmnt]) { + comments: &mut ~[Comment]) { debug!(">>> consume comment"); if rdr.curr.get() == '/' && nextch(rdr) == '/' { read_line_comments(rdr, code_to_the_left, comments); @@ -339,7 +339,7 @@ fn consume_comment(rdr: @StringReader, } #[deriving(Clone)] -pub struct lit { +pub struct Literal { lit: ~str, pos: BytePos } @@ -350,14 +350,14 @@ pub fn gather_comments_and_literals(span_diagnostic: @diagnostic::SpanHandler, path: @str, srdr: &mut io::Reader) - -> (~[cmnt], ~[lit]) { + -> (~[Comment], ~[Literal]) { let src = str::from_utf8_owned(srdr.read_to_end()).to_managed(); let cm = CodeMap::new(); let filemap = cm.new_filemap(path, src); let rdr = lexer::new_low_level_string_reader(span_diagnostic, filemap); - let mut comments: ~[cmnt] = ~[]; - let mut literals: ~[lit] = ~[]; + let mut comments: ~[Comment] = ~[]; + let mut literals: ~[Literal] = ~[]; let mut first_read: bool = true; while !is_eof(rdr) { loop { @@ -382,7 +382,7 @@ pub fn gather_comments_and_literals(span_diagnostic: if token::is_lit(&tok) { with_str_from(rdr, bstart, |s| { debug!("tok lit: {}", s); - literals.push(lit {lit: s.to_owned(), pos: sp.lo}); + literals.push(Literal {lit: s.to_owned(), pos: sp.lo}); }) } else { debug!("tok: {}", token::to_str(get_ident_interner(), &tok)); diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 3b81b09112b..9304b842294 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -25,13 +25,13 @@ use std::util; pub use ext::tt::transcribe::{TtReader, new_tt_reader}; -pub trait reader { +pub trait Reader { fn is_eof(@self) -> bool; fn next_token(@self) -> TokenAndSpan; fn fatal(@self, ~str) -> !; fn span_diag(@self) -> @SpanHandler; fn peek(@self) -> TokenAndSpan; - fn dup(@self) -> @reader; + fn dup(@self) -> @Reader; } #[deriving(Clone, Eq)] @@ -104,7 +104,7 @@ fn dup_string_reader(r: @StringReader) -> @StringReader { } } -impl reader for StringReader { +impl Reader for StringReader { fn is_eof(@self) -> bool { is_eof(self) } // return the next token. EFFECT: advances the string_reader. fn next_token(@self) -> TokenAndSpan { @@ -129,10 +129,10 @@ impl reader for StringReader { sp: self.peek_span.get(), } } - fn dup(@self) -> @reader { dup_string_reader(self) as @reader } + fn dup(@self) -> @Reader { dup_string_reader(self) as @Reader } } -impl reader for TtReader { +impl Reader for TtReader { fn is_eof(@self) -> bool { let cur_tok = self.cur_tok.borrow(); *cur_tok.get() == token::EOF @@ -152,7 +152,7 @@ impl reader for TtReader { sp: self.cur_span.get(), } } - fn dup(@self) -> @reader { dup_tt_reader(self) as @reader } + fn dup(@self) -> @Reader { dup_tt_reader(self) as @Reader } } // report a lexical error spanning [`from_pos`, `to_pos`) @@ -486,35 +486,35 @@ fn scan_number(c: char, rdr: @StringReader) -> token::Token { c = rdr.curr.get(); nextch(rdr); if c == 'u' || c == 'i' { - enum Result { Signed(ast::int_ty), Unsigned(ast::uint_ty) } + enum Result { Signed(ast::IntTy), Unsigned(ast::UintTy) } let signed = c == 'i'; let mut tp = { - if signed { Signed(ast::ty_i) } - else { Unsigned(ast::ty_u) } + if signed { Signed(ast::TyI) } + else { Unsigned(ast::TyU) } }; bump(rdr); c = rdr.curr.get(); if c == '8' { bump(rdr); - tp = if signed { Signed(ast::ty_i8) } - else { Unsigned(ast::ty_u8) }; + tp = if signed { Signed(ast::TyI8) } + else { Unsigned(ast::TyU8) }; } n = nextch(rdr); if c == '1' && n == '6' { bump(rdr); bump(rdr); - tp = if signed { Signed(ast::ty_i16) } - else { Unsigned(ast::ty_u16) }; + tp = if signed { Signed(ast::TyI16) } + else { Unsigned(ast::TyU16) }; } else if c == '3' && n == '2' { bump(rdr); bump(rdr); - tp = if signed { Signed(ast::ty_i32) } - else { Unsigned(ast::ty_u32) }; + tp = if signed { Signed(ast::TyI32) } + else { Unsigned(ast::TyU32) }; } else if c == '6' && n == '4' { bump(rdr); bump(rdr); - tp = if signed { Signed(ast::ty_i64) } - else { Unsigned(ast::ty_u64) }; + tp = if signed { Signed(ast::TyI64) } + else { Unsigned(ast::TyU64) }; } if num_str.len() == 0u { fatal_span(rdr, start_bpos, rdr.last_pos.get(), @@ -566,13 +566,11 @@ fn scan_number(c: char, rdr: @StringReader) -> token::Token { if c == '3' && n == '2' { bump(rdr); bump(rdr); - return token::LIT_FLOAT(str_to_ident(num_str), - ast::ty_f32); + return token::LIT_FLOAT(str_to_ident(num_str), ast::TyF32); } else if c == '6' && n == '4' { bump(rdr); bump(rdr); - return token::LIT_FLOAT(str_to_ident(num_str), - ast::ty_f64); + return token::LIT_FLOAT(str_to_ident(num_str), ast::TyF64); /* FIXME (#2252): if this is out of range for either a 32-bit or 64-bit float, it won't be noticed till the back-end. */ @@ -665,7 +663,7 @@ fn next_token_inner(rdr: @StringReader) -> token::Token { if is_dec_digit(c) { return scan_number(c, rdr); } - fn binop(rdr: @StringReader, op: token::binop) -> token::Token { + fn binop(rdr: @StringReader, op: token::BinOp) -> token::Token { bump(rdr); if rdr.curr.get() == '=' { bump(rdr); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index b64f16aff59..ea069c2ffe3 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -15,8 +15,7 @@ use ast; use codemap::{Span, CodeMap, FileMap, FileSubstr}; use codemap; use diagnostic::{SpanHandler, mk_span_handler, mk_handler, Emitter}; -use parse::attr::parser_attr; -use parse::lexer::reader; +use parse::attr::ParserAttr; use parse::parser::Parser; use std::cell::RefCell; @@ -133,7 +132,7 @@ pub fn parse_item_from_source_str( cfg: ast::CrateConfig, attrs: ~[ast::Attribute], sess: @ParseSess -) -> Option<@ast::item> { +) -> Option<@ast::Item> { let mut p = new_parser_from_source_str(sess, cfg, name, source); maybe_aborted(p.parse_item(attrs),p) } @@ -169,7 +168,7 @@ pub fn parse_tts_from_source_str( source: @str, cfg: ast::CrateConfig, sess: @ParseSess -) -> ~[ast::token_tree] { +) -> ~[ast::TokenTree] { let mut p = new_parser_from_source_str( sess, cfg, @@ -255,7 +254,7 @@ pub fn filemap_to_parser(sess: @ParseSess, // compiler expands into it pub fn new_parser_from_tts(sess: @ParseSess, cfg: ast::CrateConfig, - tts: ~[ast::token_tree]) -> Parser { + tts: ~[ast::TokenTree]) -> Parser { tts_to_parser(sess,tts,cfg) } @@ -307,21 +306,21 @@ pub fn substring_to_filemap(sess: @ParseSess, source: @str, path: @str, // given a filemap, produce a sequence of token-trees pub fn filemap_to_tts(sess: @ParseSess, filemap: @FileMap) - -> ~[ast::token_tree] { + -> ~[ast::TokenTree] { // it appears to me that the cfg doesn't matter here... indeed, // parsing tt's probably shouldn't require a parser at all. let cfg = ~[]; let srdr = lexer::new_string_reader(sess.span_diagnostic, filemap); - let mut p1 = Parser(sess, cfg, srdr as @reader); + let mut p1 = Parser(sess, cfg, srdr as @lexer::Reader); p1.parse_all_token_trees() } // given tts and cfg, produce a parser pub fn tts_to_parser(sess: @ParseSess, - tts: ~[ast::token_tree], + tts: ~[ast::TokenTree], cfg: ast::CrateConfig) -> Parser { let trdr = lexer::new_tt_reader(sess.span_diagnostic, None, tts); - Parser(sess, cfg, trdr as @reader) + Parser(sess, cfg, trdr as @lexer::Reader) } // abort if necessary @@ -415,26 +414,26 @@ mod test { #[test] fn string_to_tts_macro () { let tts = string_to_tts(@"macro_rules! zip (($a)=>($a))"); match tts { - [ast::tt_tok(_,_), - ast::tt_tok(_,token::NOT), - ast::tt_tok(_,_), - ast::tt_delim(delim_elts)] => + [ast::TTTok(_,_), + ast::TTTok(_,token::NOT), + ast::TTTok(_,_), + ast::TTDelim(delim_elts)] => match *delim_elts { - [ast::tt_tok(_,token::LPAREN), - ast::tt_delim(first_set), - ast::tt_tok(_,token::FAT_ARROW), - ast::tt_delim(second_set), - ast::tt_tok(_,token::RPAREN)] => + [ast::TTTok(_,token::LPAREN), + ast::TTDelim(first_set), + ast::TTTok(_,token::FAT_ARROW), + ast::TTDelim(second_set), + ast::TTTok(_,token::RPAREN)] => match *first_set { - [ast::tt_tok(_,token::LPAREN), - ast::tt_tok(_,token::DOLLAR), - ast::tt_tok(_,_), - ast::tt_tok(_,token::RPAREN)] => + [ast::TTTok(_,token::LPAREN), + ast::TTTok(_,token::DOLLAR), + ast::TTTok(_,_), + ast::TTTok(_,token::RPAREN)] => match *second_set { - [ast::tt_tok(_,token::LPAREN), - ast::tt_tok(_,token::DOLLAR), - ast::tt_tok(_,_), - ast::tt_tok(_,token::RPAREN)] => + [ast::TTTok(_,token::LPAREN), + ast::TTTok(_,token::DOLLAR), + ast::TTTok(_,_), + ast::TTTok(_,token::RPAREN)] => assert_eq!("correct","correct"), _ => assert_eq!("wrong 4","correct") }, @@ -461,7 +460,7 @@ mod test { assert_eq!(to_json_str(@tts), ~"[\ {\ - \"variant\":\"tt_tok\",\ + \"variant\":\"TTTok\",\ \"fields\":[\ null,\ {\ @@ -474,7 +473,7 @@ mod test { ]\ },\ {\ - \"variant\":\"tt_tok\",\ + \"variant\":\"TTTok\",\ \"fields\":[\ null,\ {\ @@ -487,18 +486,18 @@ mod test { ]\ },\ {\ - \"variant\":\"tt_delim\",\ + \"variant\":\"TTDelim\",\ \"fields\":[\ [\ {\ - \"variant\":\"tt_tok\",\ + \"variant\":\"TTTok\",\ \"fields\":[\ null,\ \"LPAREN\"\ ]\ },\ {\ - \"variant\":\"tt_tok\",\ + \"variant\":\"TTTok\",\ \"fields\":[\ null,\ {\ @@ -511,14 +510,14 @@ mod test { ]\ },\ {\ - \"variant\":\"tt_tok\",\ + \"variant\":\"TTTok\",\ \"fields\":[\ null,\ \"COLON\"\ ]\ },\ {\ - \"variant\":\"tt_tok\",\ + \"variant\":\"TTTok\",\ \"fields\":[\ null,\ {\ @@ -531,7 +530,7 @@ mod test { ]\ },\ {\ - \"variant\":\"tt_tok\",\ + \"variant\":\"TTTok\",\ \"fields\":[\ null,\ \"RPAREN\"\ @@ -541,18 +540,18 @@ mod test { ]\ },\ {\ - \"variant\":\"tt_delim\",\ + \"variant\":\"TTDelim\",\ \"fields\":[\ [\ {\ - \"variant\":\"tt_tok\",\ + \"variant\":\"TTTok\",\ \"fields\":[\ null,\ \"LBRACE\"\ ]\ },\ {\ - \"variant\":\"tt_tok\",\ + \"variant\":\"TTTok\",\ \"fields\":[\ null,\ {\ @@ -565,14 +564,14 @@ mod test { ]\ },\ {\ - \"variant\":\"tt_tok\",\ + \"variant\":\"TTTok\",\ \"fields\":[\ null,\ \"SEMI\"\ ]\ },\ {\ - \"variant\":\"tt_tok\",\ + \"variant\":\"TTTok\",\ \"fields\":[\ null,\ \"RBRACE\"\ @@ -661,13 +660,13 @@ mod test { // this test depends on the intern order of "fn" and "int" assert_eq!(string_to_item(@"fn a (b : int) { b; }"), Some( - @ast::item{ident:str_to_ident("a"), + @ast::Item{ident:str_to_ident("a"), attrs:~[], id: ast::DUMMY_NODE_ID, - node: ast::item_fn(ast::P(ast::fn_decl{ - inputs: ~[ast::arg{ + node: ast::ItemFn(ast::P(ast::FnDecl { + inputs: ~[ast::Arg{ ty: ast::P(ast::Ty{id: ast::DUMMY_NODE_ID, - node: ast::ty_path(ast::Path{ + node: ast::TyPath(ast::Path{ span:sp(10,13), global:false, segments: ~[ @@ -704,12 +703,12 @@ mod test { id: ast::DUMMY_NODE_ID }], output: ast::P(ast::Ty{id: ast::DUMMY_NODE_ID, - node: ast::ty_nil, + node: ast::TyNil, span:sp(15,15)}), // not sure - cf: ast::return_val, + cf: ast::Return, variadic: false }), - ast::impure_fn, + ast::ImpureFn, abi::AbiSet::Rust(), ast::Generics{ // no idea on either of these: lifetimes: opt_vec::Empty, @@ -744,7 +743,7 @@ mod test { rules: ast::DefaultBlock, // no idea span: sp(15,21), })), - vis: ast::inherited, + vis: ast::Inherited, span: sp(0,21)})); } diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 824420e9966..dba4f62aa9c 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -17,7 +17,7 @@ Obsolete syntax that becomes too hard to parse can be removed. */ -use ast::{Expr, ExprLit, lit_nil}; +use ast::{Expr, ExprLit, LitNil}; use codemap::{Span, respan}; use parse::parser::Parser; use parse::token; @@ -158,7 +158,7 @@ impl ParserObsoleteMethods for Parser { // a placeholder expression fn obsolete_expr(&mut self, sp: Span, kind: ObsoleteSyntax) -> @Expr { self.obsolete(sp, kind); - self.mk_expr(sp.lo, sp.hi, ExprLit(@respan(sp, lit_nil))) + self.mk_expr(sp.lo, sp.hi, ExprLit(@respan(sp, LitNil))) } fn report(&mut self, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 26653fe4a1e..149b7c1cf18 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -14,14 +14,14 @@ use abi; use abi::AbiSet; use ast::{Sigil, BorrowedSigil, ManagedSigil, OwnedSigil}; use ast::{CallSugar, NoSugar, DoSugar}; -use ast::{TyBareFn, TyClosure}; +use ast::{BareFnTy, ClosureTy}; use ast::{RegionTyParamBound, TraitTyParamBound}; -use ast::{provided, public, purity}; -use ast::{_mod, BiAdd, arg, Arm, Attribute, BindByRef, BindByValue}; +use ast::{Provided, Public, Purity}; +use ast::{Mod, BiAdd, Arg, Arm, Attribute, BindByRef, BindByValue}; use ast::{BiBitAnd, BiBitOr, BiBitXor, Block}; use ast::{BlockCheckMode, UnBox}; use ast::{Crate, CrateConfig, Decl, DeclItem}; -use ast::{DeclLocal, DefaultBlock, UnDeref, BiDiv, EMPTY_CTXT, enum_def, explicit_self}; +use ast::{DeclLocal, DefaultBlock, UnDeref, BiDiv, EMPTY_CTXT, EnumDef, ExplicitSelf}; use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain}; use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock}; use ast::{ExprBreak, ExprCall, ExprCast, ExprDoBody}; @@ -30,45 +30,45 @@ use ast::{ExprLit, ExprLogLevel, ExprLoop, ExprMac}; use ast::{ExprMethodCall, ExprParen, ExprPath, ExprProc, ExprRepeat}; use ast::{ExprRet, ExprSelf, ExprStruct, ExprTup, ExprUnary}; use ast::{ExprVec, ExprVstore, ExprVstoreSlice, ExprVstoreBox}; -use ast::{ExprVstoreMutSlice, ExprWhile, ExprForLoop, extern_fn, Field, fn_decl}; +use ast::{ExprVstoreMutSlice, ExprWhile, ExprForLoop, ExternFn, Field, FnDecl}; use ast::{ExprVstoreUniq, Onceness, Once, Many}; -use ast::{foreign_item, foreign_item_static, foreign_item_fn, foreign_mod}; -use ast::{Ident, impure_fn, inherited, item, item_, item_static}; -use ast::{item_enum, item_fn, item_foreign_mod, item_impl}; -use ast::{item_mac, item_mod, item_struct, item_trait, item_ty, lit, lit_}; -use ast::{lit_bool, lit_float, lit_float_unsuffixed, lit_int, lit_char}; -use ast::{lit_int_unsuffixed, lit_nil, lit_str, lit_uint, Local}; -use ast::{MutImmutable, MutMutable, mac_, mac_invoc_tt, matcher, match_nonterminal}; -use ast::{match_seq, match_tok, method, mt, BiMul, Mutability}; -use ast::{named_field, UnNeg, noreturn, UnNot, P, Pat, PatBox, PatEnum}; +use ast::{ForeignItem, ForeignItemStatic, ForeignItemFn, ForeignMod}; +use ast::{Ident, ImpureFn, Inherited, Item, Item_, ItemStatic}; +use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl}; +use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy, Lit, Lit_}; +use ast::{LitBool, LitFloat, LitFloatUnsuffixed, LitInt, LitChar}; +use ast::{LitIntUnsuffixed, LitNil, LitStr, LitUint, Local}; +use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, Matcher, MatchNonterminal}; +use ast::{MatchSeq, MatchTok, Method, MutTy, BiMul, Mutability}; +use ast::{NamedField, UnNeg, NoReturn, UnNot, P, Pat, PatBox, PatEnum}; use ast::{PatIdent, PatLit, PatRange, PatRegion, PatStruct}; -use ast::{PatTup, PatUniq, PatWild, PatWildMulti, private}; -use ast::{BiRem, required}; -use ast::{ret_style, return_val, BiShl, BiShr, Stmt, StmtDecl}; -use ast::{StmtExpr, StmtSemi, StmtMac, struct_def, struct_field}; -use ast::{struct_variant_kind, BiSub}; +use ast::{PatTup, PatUniq, PatWild, PatWildMulti, Private}; +use ast::{BiRem, Required}; +use ast::{RetStyle, Return, BiShl, BiShr, Stmt, StmtDecl}; +use ast::{StmtExpr, StmtSemi, StmtMac, StructDef, StructField}; +use ast::{StructVariantKind, BiSub}; use ast::StrStyle; -use ast::{sty_box, sty_region, sty_static, sty_uniq, sty_value}; -use ast::{token_tree, trait_method, trait_ref, tt_delim, tt_seq, tt_tok}; -use ast::{tt_nonterminal, tuple_variant_kind, Ty, ty_, ty_bot, ty_box}; -use ast::{TypeField, ty_fixed_length_vec, ty_closure, ty_bare_fn, ty_typeof}; -use ast::{ty_infer, TypeMethod}; -use ast::{ty_nil, TyParam, TyParamBound, ty_path, ty_ptr, ty_rptr}; -use ast::{ty_tup, ty_u32, ty_uniq, ty_vec, UnUniq}; -use ast::{unnamed_field, UnsafeBlock, unsafe_fn, view_item}; -use ast::{view_item_, view_item_extern_mod, view_item_use}; -use ast::{view_path, view_path_glob, view_path_list, view_path_simple}; -use ast::visibility; +use ast::{SelfBox, SelfRegion, SelfStatic, SelfUniq, SelfValue}; +use ast::{TokenTree, TraitMethod, TraitRef, TTDelim, TTSeq, TTTok}; +use ast::{TTNonterminal, TupleVariantKind, Ty, Ty_, TyBot, TyBox}; +use ast::{TypeField, TyFixedLengthVec, TyClosure, TyBareFn, TyTypeof}; +use ast::{TyInfer, TypeMethod}; +use ast::{TyNil, TyParam, TyParamBound, TyPath, TyPtr, TyRptr}; +use ast::{TyTup, TyU32, TyUniq, TyVec, UnUniq}; +use ast::{UnnamedField, UnsafeBlock, UnsafeFn, ViewItem}; +use ast::{ViewItem_, ViewItemExternMod, ViewItemUse}; +use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple}; +use ast::Visibility; use ast; use ast_util::{as_prec, operator_prec}; use ast_util; use codemap::{Span, BytePos, Spanned, spanned, mk_sp}; use codemap; -use parse::attr::parser_attr; +use parse::attr::ParserAttr; use parse::classify; use parse::common::{SeqSep, seq_sep_none}; use parse::common::{seq_sep_trailing_disallowed, seq_sep_trailing_allowed}; -use parse::lexer::reader; +use parse::lexer::Reader; use parse::lexer::TokenAndSpan; use parse::obsolete::*; use parse::token::{can_begin_expr, get_ident_interner, ident_to_str, is_ident}; @@ -85,6 +85,7 @@ use std::hashmap::HashSet; use std::util; use std::vec; +#[allow(non_camel_case_types)] #[deriving(Eq)] enum restriction { UNRESTRICTED, @@ -93,7 +94,7 @@ enum restriction { RESTRICT_NO_BAR_OR_DOUBLEBAR_OP, } -type item_info = (Ident, item_, Option<~[Attribute]>); +type ItemInfo = (Ident, Item_, Option<~[Attribute]>); /// How to parse a path. There are four different kinds of paths, all of which /// are parsed somewhat differently. @@ -126,13 +127,13 @@ struct PathAndBounds { bounds: Option<OptVec<TyParamBound>>, } -pub enum item_or_view_item { +enum ItemOrViewItem { // Indicates a failure to parse any kind of item. The attributes are // returned. - iovi_none(~[Attribute]), - iovi_item(@item), - iovi_foreign_item(@foreign_item), - iovi_view_item(view_item) + IoviNone(~[Attribute]), + IoviItem(@Item), + IoviForeignItem(@ForeignItem), + IoviViewItem(ViewItem) } /* The expr situation is not as complex as I thought it would be. @@ -144,14 +145,14 @@ macro_rules! maybe_whole_expr ( // This horrible convolution is brought to you by // @mut, have a terrible day let mut maybe_path = match ($p).token { - INTERPOLATED(token::nt_path(ref pt)) => Some((**pt).clone()), + INTERPOLATED(token::NtPath(ref pt)) => Some((**pt).clone()), _ => None, }; let ret = match ($p).token { - INTERPOLATED(token::nt_expr(e)) => { + INTERPOLATED(token::NtExpr(e)) => { Some(e) } - INTERPOLATED(token::nt_path(_)) => { + INTERPOLATED(token::NtPath(_)) => { let pt = maybe_path.take_unwrap(); Some($p.mk_expr(($p).span.lo, ($p).span.hi, ExprPath(pt))) } @@ -243,7 +244,7 @@ macro_rules! maybe_whole ( }; match __found__ { Some(INTERPOLATED(token::$constructor(x))) => { - return iovi_item(x.clone()) + return IoviItem(x.clone()) } _ => {} } @@ -279,14 +280,14 @@ fn maybe_append(lhs: ~[Attribute], rhs: Option<~[Attribute]>) struct ParsedItemsAndViewItems { attrs_remaining: ~[Attribute], - view_items: ~[view_item], - items: ~[@item], - foreign_items: ~[@foreign_item] + view_items: ~[ViewItem], + items: ~[@Item], + foreign_items: ~[@ForeignItem] } /* ident is handled by common.rs */ -pub fn Parser(sess: @ParseSess, cfg: ast::CrateConfig, rdr: @reader) +pub fn Parser(sess: @ParseSess, cfg: ast::CrateConfig, rdr: @Reader) -> Parser { let tok0 = rdr.next_token(); let interner = get_ident_interner(); @@ -340,8 +341,8 @@ pub struct Parser { tokens_consumed: uint, restriction: restriction, quote_depth: uint, // not (yet) related to the quasiquoter - reader: @reader, - interner: @token::ident_interner, + reader: @Reader, + interner: @token::IdentInterner, /// The set of seen errors about obsolete syntax. Used to suppress /// extra detail when the same error is seen twice obsolete_set: HashSet<ObsoleteSyntax>, @@ -486,7 +487,7 @@ impl Parser { self.bump(); i } - token::INTERPOLATED(token::nt_ident(..)) => { + token::INTERPOLATED(token::NtIdent(..)) => { self.bug("ident interpolation not converted to real token"); } _ => { @@ -496,12 +497,12 @@ impl Parser { } } - pub fn parse_path_list_ident(&mut self) -> ast::path_list_ident { + pub fn parse_path_list_ident(&mut self) -> ast::PathListIdent { let lo = self.span.lo; let ident = self.parse_ident(); let hi = self.last_span.hi; - spanned(lo, hi, ast::path_list_ident_ { name: ident, - id: ast::DUMMY_NODE_ID }) + spanned(lo, hi, ast::PathListIdent_ { name: ident, + id: ast::DUMMY_NODE_ID }) } // consume token 'tok' if it exists. Returns true if the given @@ -850,8 +851,8 @@ impl Parser { } } - // parse a ty_bare_fun type: - pub fn parse_ty_bare_fn(&mut self) -> ty_ { + // parse a TyBareFn type: + pub fn parse_ty_bare_fn(&mut self) -> Ty_ { /* [extern "ABI"] [unsafe] fn <'lt> (S) -> T @@ -871,7 +872,7 @@ impl Parser { let purity = self.parse_unsafety(); self.expect_keyword(keywords::Fn); let (decl, lifetimes) = self.parse_ty_fn_decl(true); - return ty_bare_fn(@TyBareFn { + return TyBareFn(@BareFnTy { abis: abis, purity: purity, lifetimes: lifetimes, @@ -881,12 +882,12 @@ impl Parser { // Parses a procedure type (`proc`). The initial `proc` keyword must // already have been parsed. - pub fn parse_proc_type(&mut self) -> ty_ { + pub fn parse_proc_type(&mut self) -> Ty_ { let (decl, lifetimes) = self.parse_ty_fn_decl(false); - ty_closure(@TyClosure { + TyClosure(@ClosureTy { sigil: OwnedSigil, region: None, - purity: impure_fn, + purity: ImpureFn, onceness: Once, bounds: None, decl: decl, @@ -894,11 +895,11 @@ impl Parser { }) } - // parse a ty_closure type + // parse a TyClosure type pub fn parse_ty_closure(&mut self, opt_sigil: Option<ast::Sigil>, mut region: Option<ast::Lifetime>) - -> ty_ { + -> Ty_ { /* (&|~|@) ['r] [unsafe] [once] fn [:Bounds] <'lt> (S) -> T @@ -963,7 +964,7 @@ impl Parser { let bounds = self.parse_optional_ty_param_bounds(); let (return_style, output) = self.parse_ret_ty(); - let decl = P(ast::fn_decl { + let decl = P(FnDecl { inputs: inputs, output: output, cf: return_style, @@ -974,7 +975,7 @@ impl Parser { } }; - return ty_closure(@TyClosure { + return TyClosure(@ClosureTy { sigil: sigil, region: region, purity: purity, @@ -993,17 +994,17 @@ impl Parser { } } - pub fn parse_unsafety(&mut self) -> purity { + pub fn parse_unsafety(&mut self) -> Purity { if self.eat_keyword(keywords::Unsafe) { - return unsafe_fn; + return UnsafeFn; } else { - return impure_fn; + return ImpureFn; } } // parse a function type (following the 'fn') pub fn parse_ty_fn_decl(&mut self, allow_variadic: bool) - -> (P<fn_decl>, OptVec<ast::Lifetime>) { + -> (P<FnDecl>, OptVec<ast::Lifetime>) { /* (fn) <'lt> (S) -> T @@ -1024,7 +1025,7 @@ impl Parser { let (inputs, variadic) = self.parse_fn_args(false, allow_variadic); let (ret_style, ret_ty) = self.parse_ret_ty(); - let decl = P(ast::fn_decl { + let decl = P(FnDecl { inputs: inputs, output: ret_ty, cf: ret_style, @@ -1034,7 +1035,7 @@ impl Parser { } // parse the methods in a trait declaration - pub fn parse_trait_methods(&mut self) -> ~[trait_method] { + pub fn parse_trait_methods(&mut self) -> ~[TraitMethod] { self.parse_unspanned_seq( &token::LBRACE, &token::RBRACE, @@ -1065,10 +1066,10 @@ impl Parser { debug!("parse_trait_methods(): parsing required method"); // NB: at the moment, visibility annotations on required // methods are ignored; this could change. - if vis != ast::inherited { + if vis != ast::Inherited { p.obsolete(vis_span, ObsoleteTraitFuncVisibility); } - required(TypeMethod { + Required(TypeMethod { ident: ident, attrs: attrs, purity: pur, @@ -1084,7 +1085,7 @@ impl Parser { let (inner_attrs, body) = p.parse_inner_attrs_and_block(); let attrs = vec::append(attrs, inner_attrs); - provided(@ast::method { + Provided(@ast::Method { ident: ident, attrs: attrs, generics: generics, @@ -1109,10 +1110,10 @@ impl Parser { } // parse a possibly mutable type - pub fn parse_mt(&mut self) -> mt { + pub fn parse_mt(&mut self) -> MutTy { let mutbl = self.parse_mutability(); let t = self.parse_ty(false); - mt { ty: t, mutbl: mutbl } + MutTy { ty: t, mutbl: mutbl } } // parse [mut/const/imm] ID : TY @@ -1126,34 +1127,34 @@ impl Parser { let hi = ty.span.hi; ast::TypeField { ident: id, - mt: ast::mt { ty: ty, mutbl: mutbl }, + mt: MutTy { ty: ty, mutbl: mutbl }, span: mk_sp(lo, hi), } } // parse optional return type [ -> TY ] in function decl - pub fn parse_ret_ty(&mut self) -> (ret_style, P<Ty>) { + pub fn parse_ret_ty(&mut self) -> (RetStyle, P<Ty>) { return if self.eat(&token::RARROW) { let lo = self.span.lo; if self.eat(&token::NOT) { ( - noreturn, + NoReturn, P(Ty { id: ast::DUMMY_NODE_ID, - node: ty_bot, + node: TyBot, span: mk_sp(lo, self.last_span.hi) }) ) } else { - (return_val, self.parse_ty(false)) + (Return, self.parse_ty(false)) } } else { let pos = self.span.lo; ( - return_val, + Return, P(Ty { id: ast::DUMMY_NODE_ID, - node: ty_nil, + node: TyNil, span: mk_sp(pos, pos), }) ) @@ -1164,7 +1165,7 @@ impl Parser { // Useless second parameter for compatibility with quasiquote macros. // Bleh! pub fn parse_ty(&mut self, _: bool) -> P<Ty> { - maybe_whole!(no_clone self, nt_ty); + maybe_whole!(no_clone self, NtTy); let lo = self.span.lo; @@ -1172,7 +1173,7 @@ impl Parser { self.bump(); if self.token == token::RPAREN { self.bump(); - ty_nil + TyNil } else { // (t) is a parenthesized ty // (t,) is the type of a tuple with only one field, @@ -1194,7 +1195,7 @@ impl Parser { return ts[0] } - let t = ty_tup(ts); + let t = TyTup(ts); self.expect(&token::RPAREN); t } @@ -1209,7 +1210,7 @@ impl Parser { } else if self.token == token::BINOP(token::STAR) { // STAR POINTER (bare pointer?) self.bump(); - ty_ptr(self.parse_mt()) + TyPtr(self.parse_mt()) } else if self.token == token::LBRACKET { // VECTOR self.expect(&token::LBRACKET); @@ -1218,8 +1219,8 @@ impl Parser { // Parse the `, ..e` in `[ int, ..e ]` // where `e` is a const expression let t = match self.maybe_parse_fixed_vstore() { - None => ty_vec(t), - Some(suffix) => ty_fixed_length_vec(t, suffix) + None => TyVec(t), + Some(suffix) => TyFixedLengthVec(t, suffix) }; self.expect(&token::RBRACKET); t @@ -1251,7 +1252,7 @@ impl Parser { self.expect(&token::LPAREN); let e = self.parse_expr(); self.expect(&token::RPAREN); - ty_typeof(e) + TyTypeof(e) } else if self.eat_keyword(keywords::Proc) { self.parse_proc_type() } else if self.token == token::MOD_SEP @@ -1261,7 +1262,7 @@ impl Parser { path, bounds } = self.parse_path(LifetimeAndTypesAndBounds); - ty_path(path, bounds, ast::DUMMY_NODE_ID) + TyPath(path, bounds, ast::DUMMY_NODE_ID) } else { let msg = format!("expected type, found token {:?}", self.token); self.fatal(msg); @@ -1274,7 +1275,7 @@ impl Parser { // parse the type following a @ or a ~ pub fn parse_box_or_uniq_pointee(&mut self, sigil: ast::Sigil) - -> ty_ { + -> Ty_ { // ~'foo fn() or ~fn() are parsed directly as obsolete fn types: match self.token { token::LIFETIME(..) => { @@ -1297,13 +1298,13 @@ impl Parser { // rather than boxed ptrs. But the special casing of str/vec is not // reflected in the AST type. if sigil == OwnedSigil { - ty_uniq(self.parse_ty(false)) + TyUniq(self.parse_ty(false)) } else { - ty_box(self.parse_ty(false)) + TyBox(self.parse_ty(false)) } } - pub fn parse_borrowed_pointee(&mut self) -> ty_ { + pub fn parse_borrowed_pointee(&mut self) -> Ty_ { // look for `&'lt` or `&'foo ` and interpret `foo` as the region name: let opt_lifetime = self.parse_opt_lifetime(); @@ -1313,7 +1314,7 @@ impl Parser { } let mt = self.parse_mt(); - return ty_rptr(opt_lifetime, mt); + return TyRptr(opt_lifetime, mt); } pub fn is_named_argument(&mut self) -> bool { @@ -1337,7 +1338,7 @@ impl Parser { // This version of parse arg doesn't necessarily require // identifier names. - pub fn parse_arg_general(&mut self, require_name: bool) -> arg { + pub fn parse_arg_general(&mut self, require_name: bool) -> Arg { let pat = if require_name || self.is_named_argument() { debug!("parse_arg_general parse_pat (require_name:{:?})", require_name); @@ -1354,7 +1355,7 @@ impl Parser { let t = self.parse_ty(false); - ast::arg { + Arg { ty: t, pat: pat, id: ast::DUMMY_NODE_ID, @@ -1362,23 +1363,23 @@ impl Parser { } // parse a single function argument - pub fn parse_arg(&mut self) -> arg { + pub fn parse_arg(&mut self) -> Arg { self.parse_arg_general(true) } // parse an argument in a lambda header e.g. |arg, arg| - pub fn parse_fn_block_arg(&mut self) -> arg { + pub fn parse_fn_block_arg(&mut self) -> Arg { let pat = self.parse_pat(); let t = if self.eat(&token::COLON) { self.parse_ty(false) } else { P(Ty { id: ast::DUMMY_NODE_ID, - node: ty_infer, + node: TyInfer, span: mk_sp(self.span.lo, self.span.hi), }) }; - ast::arg { + Arg { ty: t, pat: pat, id: ast::DUMMY_NODE_ID @@ -1397,29 +1398,29 @@ impl Parser { } // matches token_lit = LIT_INT | ... - pub fn lit_from_token(&mut self, tok: &token::Token) -> lit_ { + pub fn lit_from_token(&mut self, tok: &token::Token) -> Lit_ { match *tok { - token::LIT_CHAR(i) => lit_char(i), - token::LIT_INT(i, it) => lit_int(i, it), - token::LIT_UINT(u, ut) => lit_uint(u, ut), - token::LIT_INT_UNSUFFIXED(i) => lit_int_unsuffixed(i), - token::LIT_FLOAT(s, ft) => lit_float(self.id_to_str(s), ft), + token::LIT_CHAR(i) => LitChar(i), + token::LIT_INT(i, it) => LitInt(i, it), + token::LIT_UINT(u, ut) => LitUint(u, ut), + token::LIT_INT_UNSUFFIXED(i) => LitIntUnsuffixed(i), + token::LIT_FLOAT(s, ft) => LitFloat(self.id_to_str(s), ft), token::LIT_FLOAT_UNSUFFIXED(s) => - lit_float_unsuffixed(self.id_to_str(s)), - token::LIT_STR(s) => lit_str(self.id_to_str(s), ast::CookedStr), - token::LIT_STR_RAW(s, n) => lit_str(self.id_to_str(s), ast::RawStr(n)), - token::LPAREN => { self.expect(&token::RPAREN); lit_nil }, + LitFloatUnsuffixed(self.id_to_str(s)), + token::LIT_STR(s) => LitStr(self.id_to_str(s), ast::CookedStr), + token::LIT_STR_RAW(s, n) => LitStr(self.id_to_str(s), ast::RawStr(n)), + token::LPAREN => { self.expect(&token::RPAREN); LitNil }, _ => { self.unexpected_last(tok); } } } // matches lit = true | false | token_lit - pub fn parse_lit(&mut self) -> lit { + pub fn parse_lit(&mut self) -> Lit { let lo = self.span.lo; let lit = if self.eat_keyword(keywords::True) { - lit_bool(true) + LitBool(true) } else if self.eat_keyword(keywords::False) { - lit_bool(false) + LitBool(false) } else { let token = self.bump_and_get(); let lit = self.lit_from_token(&token); @@ -1454,11 +1455,11 @@ impl Parser { pub fn parse_path(&mut self, mode: PathParsingMode) -> PathAndBounds { // Check for a whole path... let found = match self.token { - INTERPOLATED(token::nt_path(_)) => Some(self.bump_and_get()), + INTERPOLATED(token::NtPath(_)) => Some(self.bump_and_get()), _ => None, }; match found { - Some(INTERPOLATED(token::nt_path(~path))) => { + Some(INTERPOLATED(token::NtPath(~path))) => { return PathAndBounds { path: path, bounds: None, @@ -1709,7 +1710,7 @@ impl Parser { ExprAssignOp(ast::DUMMY_NODE_ID, binop, lhs, rhs) } - pub fn mk_mac_expr(&mut self, lo: BytePos, hi: BytePos, m: mac_) -> @Expr { + pub fn mk_mac_expr(&mut self, lo: BytePos, hi: BytePos, m: Mac_) -> @Expr { @Expr { id: ast::DUMMY_NODE_ID, node: ExprMac(codemap::Spanned {node: m, span: mk_sp(lo, hi)}), @@ -1720,7 +1721,7 @@ impl Parser { pub fn mk_lit_u32(&mut self, i: u32) -> @Expr { let span = &self.span; let lv_lit = @codemap::Spanned { - node: lit_uint(i as u64, ty_u32), + node: LitUint(i as u64, TyU32), span: *span }; @@ -1750,7 +1751,7 @@ impl Parser { if self.token == token::RPAREN { hi = self.span.hi; self.bump(); - let lit = @spanned(lo, hi, lit_nil); + let lit = @spanned(lo, hi, LitNil); return self.mk_expr(lo, hi, ExprLit(lit)); } let mut es = ~[self.parse_expr()]; @@ -1914,7 +1915,7 @@ impl Parser { |p| p.parse_token_tree()); let hi = self.span.hi; - return self.mk_mac_expr(lo, hi, mac_invoc_tt(pth, tts, EMPTY_CTXT)); + return self.mk_mac_expr(lo, hi, MacInvocTT(pth, tts, EMPTY_CTXT)); } else if self.token == token::LBRACE { // This might be a struct literal. if self.looking_at_struct_literal() { @@ -2073,21 +2074,21 @@ impl Parser { } // parse a single token tree from the input. - pub fn parse_token_tree(&mut self) -> token_tree { + pub fn parse_token_tree(&mut self) -> TokenTree { // FIXME #6994: currently, this is too eager. It - // parses token trees but also identifies tt_seq's - // and tt_nonterminals; it's too early to know yet + // parses token trees but also identifies TTSeq's + // and TTNonterminal's; it's too early to know yet // whether something will be a nonterminal or a seq // yet. - maybe_whole!(deref self, nt_tt); + maybe_whole!(deref self, NtTT); // this is the fall-through for the 'match' below. // invariants: the current token is not a left-delimiter, // not an EOF, and not the desired right-delimiter (if // it were, parse_seq_to_before_end would have prevented // reaching this point. - fn parse_non_delim_tt_tok(p: &mut Parser) -> token_tree { - maybe_whole!(deref p, nt_tt); + fn parse_non_delim_tt_tok(p: &mut Parser) -> TokenTree { + maybe_whole!(deref p, NtTT); match p.token { token::RPAREN | token::RBRACE | token::RBRACKET => { // This is a conservative error: only report the last unclosed delimiter. The @@ -2117,14 +2118,9 @@ impl Parser { let seq = match seq { Spanned { node, .. } => node, }; - tt_seq( - mk_sp(sp.lo, p.span.hi), - @seq, - s, - z - ) + TTSeq(mk_sp(sp.lo, p.span.hi), @seq, s, z) } else { - tt_nonterminal(sp, p.parse_ident()) + TTNonterminal(sp, p.parse_ident()) } } _ => { @@ -2133,9 +2129,9 @@ impl Parser { } } - // turn the next token into a tt_tok: - fn parse_any_tt_tok(p: &mut Parser) -> token_tree{ - tt_tok(p.span, p.bump_and_get()) + // turn the next token into a TTTok: + fn parse_any_tt_tok(p: &mut Parser) -> TokenTree { + TTTok(p.span, p.bump_and_get()) } match self.token { @@ -2165,15 +2161,15 @@ impl Parser { result.push(parse_any_tt_tok(self)); self.open_braces.pop(); - tt_delim(@result) + TTDelim(@result) } _ => parse_non_delim_tt_tok(self) } } - // parse a stream of tokens into a list of token_trees, + // parse a stream of tokens into a list of TokenTree's, // up to EOF. - pub fn parse_all_token_trees(&mut self) -> ~[token_tree] { + pub fn parse_all_token_trees(&mut self) -> ~[TokenTree] { let mut tts = ~[]; while self.token != token::EOF { tts.push(self.parse_token_tree()); @@ -2181,10 +2177,10 @@ impl Parser { tts } - pub fn parse_matchers(&mut self) -> ~[matcher] { - // unification of matchers and token_trees would vastly improve - // the interpolation of matchers - maybe_whole!(self, nt_matchers); + pub fn parse_matchers(&mut self) -> ~[Matcher] { + // unification of Matcher's and TokenTree's would vastly improve + // the interpolation of Matcher's + maybe_whole!(self, NtMatchers); let name_idx = @Cell::new(0u); match self.token { token::LBRACE | token::LPAREN | token::LBRACKET => { @@ -2196,13 +2192,13 @@ impl Parser { } } - // This goofy function is necessary to correctly match parens in matchers. - // Otherwise, `$( ( )` would be a valid matcher, and `$( () )` would be + // This goofy function is necessary to correctly match parens in Matcher's. + // Otherwise, `$( ( )` would be a valid Matcher, and `$( () )` would be // invalid. It's similar to common::parse_seq. pub fn parse_matcher_subseq_upto(&mut self, name_idx: @Cell<uint>, ket: &token::Token) - -> ~[matcher] { + -> ~[Matcher] { let mut ret_val = ~[]; let mut lparens = 0u; @@ -2217,7 +2213,7 @@ impl Parser { return ret_val; } - pub fn parse_matcher(&mut self, name_idx: @Cell<uint>) -> matcher { + pub fn parse_matcher(&mut self, name_idx: @Cell<uint>) -> Matcher { let lo = self.span.lo; let m = if self.token == token::DOLLAR { @@ -2231,17 +2227,17 @@ impl Parser { self.fatal("repetition body must be nonempty"); } let (sep, zerok) = self.parse_sep_and_zerok(); - match_seq(ms, sep, zerok, name_idx_lo, name_idx.get()) + MatchSeq(ms, sep, zerok, name_idx_lo, name_idx.get()) } else { let bound_to = self.parse_ident(); self.expect(&token::COLON); let nt_name = self.parse_ident(); - let m = match_nonterminal(bound_to, nt_name, name_idx.get()); + let m = MatchNonterminal(bound_to, nt_name, name_idx.get()); name_idx.set(name_idx.get() + 1u); m } } else { - match_tok(self.bump_and_get()) + MatchTok(self.bump_and_get()) }; return spanned(lo, self.span.hi, m); @@ -2283,7 +2279,7 @@ impl Parser { // HACK: turn &[...] into a &-evec ex = match e.node { ExprVec(..) | ExprLit(@codemap::Spanned { - node: lit_str(..), span: _ + node: LitStr(..), span: _ }) if m == MutImmutable => { ExprVstore(e, ExprVstoreSlice) @@ -2304,7 +2300,7 @@ impl Parser { // HACK: turn @[...] into a @-evec ex = match e.node { ExprVec(..) | - ExprLit(@codemap::Spanned { node: lit_str(..), span: _}) | + ExprLit(@codemap::Spanned { node: LitStr(..), span: _}) | ExprRepeat(..) => ExprVstore(e, ExprVstoreBox), _ => self.mk_unary(UnBox, e) }; @@ -2317,7 +2313,7 @@ impl Parser { // HACK: turn ~[...] into a ~-evec ex = match e.node { ExprVec(..) | - ExprLit(@codemap::Spanned { node: lit_str(..), span: _}) | + ExprLit(@codemap::Spanned { node: LitStr(..), span: _}) | ExprRepeat(..) => ExprVstore(e, ExprVstoreUniq), _ => self.mk_unary(UnUniq, e) }; @@ -2331,7 +2327,7 @@ impl Parser { ex = match subexpression.node { ExprVec(..) | ExprLit(@codemap::Spanned { - node: lit_str(..), + node: LitStr(..), span: _ }) | ExprRepeat(..) => ExprVstore(subexpression, ExprVstoreUniq), @@ -2459,22 +2455,22 @@ impl Parser { self.parse_lambda_expr_( |p| { match p.token { - token::BINOP(token::OR) | token::OROR => { - p.parse_fn_block_decl() - } - _ => { - // No argument list - `do foo {` - P(ast::fn_decl { - inputs: ~[], - output: P(Ty { - id: ast::DUMMY_NODE_ID, - node: ty_infer, - span: p.span - }), - cf: return_val, - variadic: false - }) - } + token::BINOP(token::OR) | token::OROR => { + p.parse_fn_block_decl() + } + _ => { + // No argument list - `do foo {` + P(FnDecl { + inputs: ~[], + output: P(Ty { + id: ast::DUMMY_NODE_ID, + node: TyInfer, + span: p.span + }), + cf: Return, + variadic: false + }) + } } }, |p| { @@ -2493,7 +2489,7 @@ impl Parser { // this is used both in parsing a lambda expr // and in parsing a block expr as e.g. in for... pub fn parse_lambda_expr_(&mut self, - parse_decl: |&mut Parser| -> P<fn_decl>, + parse_decl: |&mut Parser| -> P<FnDecl>, parse_body: |&mut Parser| -> @Expr) -> @Expr { let lo = self.last_span.lo; @@ -2857,7 +2853,7 @@ impl Parser { // parse a pattern. pub fn parse_pat(&mut self) -> @Pat { - maybe_whole!(self, nt_pat); + maybe_whole!(self, NtPat); let lo = self.span.lo; let mut hi; @@ -2883,7 +2879,7 @@ impl Parser { pat = match sub.node { PatLit(e@@Expr { node: ExprLit(@codemap::Spanned { - node: lit_str(..), + node: LitStr(..), span: _}), .. }) => { let vst = @Expr { @@ -2911,7 +2907,7 @@ impl Parser { pat = match sub.node { PatLit(e@@Expr { node: ExprLit(@codemap::Spanned { - node: lit_str(..), + node: LitStr(..), span: _}), .. }) => { let vst = @Expr { @@ -2939,7 +2935,7 @@ impl Parser { // HACK: parse &"..." as a literal of a borrowed str pat = match sub.node { PatLit(e@@Expr { - node: ExprLit(@codemap::Spanned{ node: lit_str(..), .. }), + node: ExprLit(@codemap::Spanned{ node: LitStr(..), .. }), .. }) => { let vst = @Expr { @@ -2965,7 +2961,7 @@ impl Parser { hi = self.span.hi; self.bump(); let lit = @codemap::Spanned { - node: lit_nil, + node: LitNil, span: mk_sp(lo, hi)}; let expr = self.mk_expr(lo, hi, ExprLit(lit)); pat = PatLit(expr); @@ -3170,7 +3166,7 @@ impl Parser { let mut ty = P(Ty { id: ast::DUMMY_NODE_ID, - node: ty_infer, + node: TyInfer, span: mk_sp(lo, lo), }); if self.eat(&token::COLON) { ty = self.parse_ty(false); } @@ -3196,9 +3192,8 @@ impl Parser { } // parse a structure field - fn parse_name_and_ty(&mut self, - pr: visibility, - attrs: ~[Attribute]) -> struct_field { + fn parse_name_and_ty(&mut self, pr: Visibility, + attrs: ~[Attribute]) -> StructField { let lo = self.span.lo; if !is_plain_ident(&self.token) { self.fatal("expected ident"); @@ -3206,8 +3201,8 @@ impl Parser { let name = self.parse_ident(); self.expect(&token::COLON); let ty = self.parse_ty(false); - spanned(lo, self.last_span.hi, ast::struct_field_ { - kind: named_field(name, pr), + spanned(lo, self.last_span.hi, ast::StructField_ { + kind: NamedField(name, pr), id: ast::DUMMY_NODE_ID, ty: ty, attrs: attrs, @@ -3217,7 +3212,7 @@ impl Parser { // parse a statement. may include decl. // precondition: any attributes are parsed already pub fn parse_stmt(&mut self, item_attrs: ~[Attribute]) -> @Stmt { - maybe_whole!(self, nt_stmt); + maybe_whole!(self, NtStmt); fn check_expected_item(p: &mut Parser, found_attrs: bool) { // If we have attributes then we should have an item @@ -3271,34 +3266,34 @@ impl Parser { if id == token::special_idents::invalid { return @spanned(lo, hi, StmtMac( - spanned(lo, hi, mac_invoc_tt(pth, tts, EMPTY_CTXT)), false)); + spanned(lo, hi, MacInvocTT(pth, tts, EMPTY_CTXT)), false)); } else { // if it has a special ident, it's definitely an item return @spanned(lo, hi, StmtDecl( @spanned(lo, hi, DeclItem( self.mk_item( lo, hi, id /*id is good here*/, - item_mac(spanned(lo, hi, mac_invoc_tt(pth, tts, EMPTY_CTXT))), - inherited, ~[/*no attrs*/]))), + ItemMac(spanned(lo, hi, MacInvocTT(pth, tts, EMPTY_CTXT))), + Inherited, ~[/*no attrs*/]))), ast::DUMMY_NODE_ID)); } } else { let found_attrs = !item_attrs.is_empty(); match self.parse_item_or_view_item(item_attrs, false) { - iovi_item(i) => { + IoviItem(i) => { let hi = i.span.hi; let decl = @spanned(lo, hi, DeclItem(i)); return @spanned(lo, hi, StmtDecl(decl, ast::DUMMY_NODE_ID)); } - iovi_view_item(vi) => { + IoviViewItem(vi) => { self.span_fatal(vi.span, "view items must be declared at the top of the block"); } - iovi_foreign_item(_) => { + IoviForeignItem(_) => { self.fatal("foreign items are not allowed here"); } - iovi_none(_) => { /* fallthrough */ } + IoviNone(_) => { /* fallthrough */ } } check_expected_item(self, found_attrs); @@ -3317,7 +3312,7 @@ impl Parser { // parse a block. No inner attrs are allowed. pub fn parse_block(&mut self) -> P<Block> { - maybe_whole!(no_clone self, nt_block); + maybe_whole!(no_clone self, NtBlock); let lo = self.span.lo; if self.eat_keyword(keywords::Unsafe) { @@ -3332,7 +3327,7 @@ impl Parser { fn parse_inner_attrs_and_block(&mut self) -> (~[Attribute], P<Block>) { - maybe_whole!(pair_empty self, nt_block); + maybe_whole!(pair_empty self, NtBlock); let lo = self.span.lo; if self.eat_keyword(keywords::Unsafe) { @@ -3548,9 +3543,9 @@ impl Parser { } fn parse_fn_args(&mut self, named_args: bool, allow_variadic: bool) - -> (~[arg], bool) { + -> (~[Arg], bool) { let sp = self.span; - let mut args: ~[Option<arg>] = + let mut args: ~[Option<Arg>] = self.parse_unspanned_seq( &token::LPAREN, &token::RPAREN, @@ -3595,12 +3590,12 @@ impl Parser { } // parse the argument list and result type of a function declaration - pub fn parse_fn_decl(&mut self, allow_variadic: bool) -> P<fn_decl> { + pub fn parse_fn_decl(&mut self, allow_variadic: bool) -> P<FnDecl> { let (args, variadic) = self.parse_fn_args(true, allow_variadic); let (ret_style, ret_ty) = self.parse_ret_ty(); - P(ast::fn_decl { + P(FnDecl { inputs: args, output: ret_ty, cf: ret_style, @@ -3625,12 +3620,12 @@ impl Parser { // parse the argument list and result type of a function // that may have a self type. - fn parse_fn_decl_with_self(&mut self, parse_arg_fn: |&mut Parser| -> arg) - -> (explicit_self, P<fn_decl>) { + fn parse_fn_decl_with_self(&mut self, parse_arg_fn: |&mut Parser| -> Arg) + -> (ExplicitSelf, P<FnDecl>) { fn maybe_parse_explicit_self(cnstr: |v: Mutability| -> - ast::explicit_self_, + ast::ExplicitSelf_, p: &mut Parser) - -> ast::explicit_self_ { + -> ast::ExplicitSelf_ { // We need to make sure it isn't a type if p.look_ahead(1, |t| token::is_keyword(keywords::Self, t)) || ((p.look_ahead(1, |t| token::is_keyword(keywords::Const, t)) || @@ -3642,12 +3637,12 @@ impl Parser { p.expect_self_ident(); cnstr(mutability) } else { - sty_static + SelfStatic } } fn maybe_parse_borrowed_explicit_self(this: &mut Parser) - -> ast::explicit_self_ { + -> ast::ExplicitSelf_ { // The following things are possible to see here: // // fn(&mut self) @@ -3660,7 +3655,7 @@ impl Parser { if this.look_ahead(1, |t| token::is_keyword(keywords::Self, t)) { this.bump(); this.expect_self_ident(); - sty_region(None, MutImmutable) + SelfRegion(None, MutImmutable) } else if this.look_ahead(1, |t| Parser::token_is_mutability(t)) && this.look_ahead(2, |t| token::is_keyword(keywords::Self, @@ -3668,7 +3663,7 @@ impl Parser { this.bump(); let mutability = this.parse_mutability(); this.expect_self_ident(); - sty_region(None, mutability) + SelfRegion(None, mutability) } else if this.look_ahead(1, |t| Parser::token_is_lifetime(t)) && this.look_ahead(2, |t| token::is_keyword(keywords::Self, @@ -3676,7 +3671,7 @@ impl Parser { this.bump(); let lifetime = this.parse_lifetime(); this.expect_self_ident(); - sty_region(Some(lifetime), MutImmutable) + SelfRegion(Some(lifetime), MutImmutable) } else if this.look_ahead(1, |t| Parser::token_is_lifetime(t)) && this.look_ahead(2, |t| { Parser::token_is_mutability(t) @@ -3687,9 +3682,9 @@ impl Parser { let lifetime = this.parse_lifetime(); let mutability = this.parse_mutability(); this.expect_self_ident(); - sty_region(Some(lifetime), mutability) + SelfRegion(Some(lifetime), mutability) } else { - sty_static + SelfStatic } } @@ -3703,7 +3698,7 @@ impl Parser { maybe_parse_borrowed_explicit_self(self) } token::AT => { - maybe_parse_explicit_self(sty_box, self) + maybe_parse_explicit_self(SelfBox, self) } token::TILDE => { maybe_parse_explicit_self(|mutability| { @@ -3711,12 +3706,12 @@ impl Parser { self.span_err(self.last_span, "mutability declaration not allowed here"); } - sty_uniq(MutImmutable) + SelfUniq(MutImmutable) }, self) } token::IDENT(..) if self.is_self_ident() => { self.bump(); - sty_value(MutImmutable) + SelfValue(MutImmutable) } token::BINOP(token::STAR) => { // Possibly "*self" or "*mut self" -- not supported. Try to avoid @@ -3729,13 +3724,13 @@ impl Parser { self.span_err(self.span, "cannot pass self by unsafe pointer"); self.bump(); } - sty_value(mutability) + SelfValue(mutability) } _ if Parser::token_is_mutability(&self.token) && self.look_ahead(1, |t| token::is_keyword(keywords::Self, t)) => { let mutability = self.parse_mutability(); self.expect_self_ident(); - sty_value(mutability) + SelfValue(mutability) } _ if Parser::token_is_mutability(&self.token) && self.look_ahead(1, |t| *t == token::TILDE) && @@ -3743,16 +3738,16 @@ impl Parser { let mutability = self.parse_mutability(); self.bump(); self.expect_self_ident(); - sty_uniq(mutability) + SelfUniq(mutability) } _ => { - sty_static + SelfStatic } }; // If we parsed a self type, expect a comma before the argument list. let fn_inputs; - if explicit_self != sty_static { + if explicit_self != SelfStatic { match self.token { token::COMMA => { self.bump(); @@ -3785,7 +3780,7 @@ impl Parser { let (ret_style, ret_ty) = self.parse_ret_ty(); - let fn_decl = P(ast::fn_decl { + let fn_decl = P(FnDecl { inputs: fn_inputs, output: ret_ty, cf: ret_style, @@ -3796,7 +3791,7 @@ impl Parser { } // parse the |arg, arg| header on a lambda - fn parse_fn_block_decl(&mut self) -> P<fn_decl> { + fn parse_fn_block_decl(&mut self) -> P<FnDecl> { let inputs_captures = { if self.eat(&token::OROR) { ~[] @@ -3814,21 +3809,21 @@ impl Parser { } else { P(Ty { id: ast::DUMMY_NODE_ID, - node: ty_infer, + node: TyInfer, span: self.span, }) }; - P(ast::fn_decl { + P(FnDecl { inputs: inputs_captures, output: output, - cf: return_val, + cf: Return, variadic: false }) } // Parses the `(arg, arg) -> return_type` header on a procedure. - fn parse_proc_decl(&mut self) -> P<fn_decl> { + fn parse_proc_decl(&mut self) -> P<FnDecl> { let inputs = self.parse_unspanned_seq(&token::LPAREN, &token::RPAREN, @@ -3840,15 +3835,15 @@ impl Parser { } else { P(Ty { id: ast::DUMMY_NODE_ID, - node: ty_infer, + node: TyInfer, span: self.span, }) }; - P(ast::fn_decl { + P(FnDecl { inputs: inputs, output: output, - cf: return_val, + cf: Return, variadic: false }) } @@ -3861,28 +3856,28 @@ impl Parser { } fn mk_item(&mut self, lo: BytePos, hi: BytePos, ident: Ident, - node: item_, vis: visibility, - attrs: ~[Attribute]) -> @item { - @ast::item { ident: ident, - attrs: attrs, - id: ast::DUMMY_NODE_ID, - node: node, - vis: vis, - span: mk_sp(lo, hi) } + node: Item_, vis: Visibility, + attrs: ~[Attribute]) -> @Item { + @Item { + ident: ident, + attrs: attrs, + id: ast::DUMMY_NODE_ID, + node: node, + vis: vis, + span: mk_sp(lo, hi) + } } // parse an item-position function declaration. - fn parse_item_fn(&mut self, purity: purity, abis: AbiSet) -> item_info { + fn parse_item_fn(&mut self, purity: Purity, abis: AbiSet) -> ItemInfo { let (ident, generics) = self.parse_fn_header(); let decl = self.parse_fn_decl(false); let (inner_attrs, body) = self.parse_inner_attrs_and_block(); - (ident, - item_fn(decl, purity, abis, generics, body), - Some(inner_attrs)) + (ident, ItemFn(decl, purity, abis, generics, body), Some(inner_attrs)) } // parse a method in a trait impl, starting with `attrs` attributes. - fn parse_method(&mut self, already_parsed_attrs: Option<~[Attribute]>) -> @method { + fn parse_method(&mut self, already_parsed_attrs: Option<~[Attribute]>) -> @Method { let next_attrs = self.parse_outer_attributes(); let attrs = match already_parsed_attrs { Some(mut a) => { a.push_all_move(next_attrs); a } @@ -3902,7 +3897,7 @@ impl Parser { let (inner_attrs, body) = self.parse_inner_attrs_and_block(); let hi = body.span.hi; let attrs = vec::append(attrs, inner_attrs); - @ast::method { + @ast::Method { ident: ident, attrs: attrs, generics: generics, @@ -3918,7 +3913,7 @@ impl Parser { } // parse trait Foo { ... } - fn parse_item_trait(&mut self) -> item_info { + fn parse_item_trait(&mut self) -> ItemInfo { let ident = self.parse_ident(); let tps = self.parse_generics(); @@ -3932,13 +3927,13 @@ impl Parser { } let meths = self.parse_trait_methods(); - (ident, item_trait(tps, traits, meths), None) + (ident, ItemTrait(tps, traits, meths), None) } // Parses two variants (with the region/type params always optional): // impl<T> Foo { ... } // impl<T> ToStr for ~[T] { ... } - fn parse_item_impl(&mut self) -> item_info { + fn parse_item_impl(&mut self) -> ItemInfo { // First, parse type parameters if necessary. let generics = self.parse_generics(); @@ -3957,13 +3952,13 @@ impl Parser { let opt_trait = if could_be_trait && self.eat_keyword(keywords::For) { // New-style trait. Reinterpret the type as a trait. let opt_trait_ref = match ty.node { - ty_path(ref path, None, node_id) => { - Some(trait_ref { + TyPath(ref path, None, node_id) => { + Some(TraitRef { path: /* bad */ (*path).clone(), ref_id: node_id }) } - ty_path(..) => { + TyPath(..) => { self.span_err(ty.span, "bounded traits are only valid in type position"); None @@ -3995,19 +3990,19 @@ impl Parser { Some(inner_attrs) }; - (ident, item_impl(generics, opt_trait, ty, meths), inner_attrs) + (ident, ItemImpl(generics, opt_trait, ty, meths), inner_attrs) } // parse a::B<~str,int> - fn parse_trait_ref(&mut self) -> trait_ref { - ast::trait_ref { + fn parse_trait_ref(&mut self) -> TraitRef { + ast::TraitRef { path: self.parse_path(LifetimeAndTypesWithoutColons).path, ref_id: ast::DUMMY_NODE_ID, } } // parse B + C<~str,int> + D - fn parse_trait_ref_list(&mut self, ket: &token::Token) -> ~[trait_ref] { + fn parse_trait_ref_list(&mut self, ket: &token::Token) -> ~[TraitRef] { self.parse_seq_to_before_end( ket, seq_sep_trailing_disallowed(token::BINOP(token::PLUS)), @@ -4016,11 +4011,11 @@ impl Parser { } // parse struct Foo { ... } - fn parse_item_struct(&mut self) -> item_info { + fn parse_item_struct(&mut self) -> ItemInfo { let class_name = self.parse_ident(); let generics = self.parse_generics(); - let mut fields: ~[struct_field]; + let mut fields: ~[StructField]; let is_tuple_like; if self.eat(&token::LBRACE) { @@ -4045,8 +4040,8 @@ impl Parser { |p| { let attrs = p.parse_outer_attributes(); let lo = p.span.lo; - let struct_field_ = ast::struct_field_ { - kind: unnamed_field, + let struct_field_ = ast::StructField_ { + kind: UnnamedField, id: ast::DUMMY_NODE_ID, ty: p.parse_ty(false), attrs: attrs, @@ -4068,7 +4063,7 @@ impl Parser { let _ = ast::DUMMY_NODE_ID; // XXX: Workaround for crazy bug. let new_id = ast::DUMMY_NODE_ID; (class_name, - item_struct(@ast::struct_def { + ItemStruct(@ast::StructDef { fields: fields, ctor_id: if is_tuple_like { Some(new_id) } else { None } }, generics), @@ -4077,9 +4072,9 @@ impl Parser { // parse a structure field declaration pub fn parse_single_struct_field(&mut self, - vis: visibility, + vis: Visibility, attrs: ~[Attribute]) - -> struct_field { + -> StructField { let a_var = self.parse_name_and_ty(vis, attrs); match self.token { token::COMMA => { @@ -4097,26 +4092,26 @@ impl Parser { } // parse an element of a struct definition - fn parse_struct_decl_field(&mut self) -> struct_field { + fn parse_struct_decl_field(&mut self) -> StructField { let attrs = self.parse_outer_attributes(); if self.eat_keyword(keywords::Priv) { - return self.parse_single_struct_field(private, attrs); + return self.parse_single_struct_field(Private, attrs); } if self.eat_keyword(keywords::Pub) { - return self.parse_single_struct_field(public, attrs); + return self.parse_single_struct_field(Public, attrs); } - return self.parse_single_struct_field(inherited, attrs); + return self.parse_single_struct_field(Inherited, attrs); } // parse visiility: PUB, PRIV, or nothing - fn parse_visibility(&mut self) -> visibility { - if self.eat_keyword(keywords::Pub) { public } - else if self.eat_keyword(keywords::Priv) { private } - else { inherited } + fn parse_visibility(&mut self) -> Visibility { + if self.eat_keyword(keywords::Pub) { Public } + else if self.eat_keyword(keywords::Priv) { Private } + else { Inherited } } // given a termination token and a vector of already-parsed @@ -4124,7 +4119,7 @@ impl Parser { fn parse_mod_items(&mut self, term: token::Token, first_item_attrs: ~[Attribute]) - -> _mod { + -> Mod { // parse all of the items up to closing or an attribute. // view items are legal here. let ParsedItemsAndViewItems { @@ -4133,7 +4128,7 @@ impl Parser { items: starting_items, .. } = self.parse_items_and_view_items(first_item_attrs, true, true); - let mut items: ~[@item] = starting_items; + let mut items: ~[@Item] = starting_items; let attrs_remaining_len = attrs_remaining.len(); // don't think this other loop is even necessary.... @@ -4149,8 +4144,8 @@ impl Parser { attrs); match self.parse_item_or_view_item(attrs, true /* macros allowed */) { - iovi_item(item) => items.push(item), - iovi_view_item(view_item) => { + IoviItem(item) => items.push(item), + IoviViewItem(view_item) => { self.span_fatal(view_item.span, "view items must be declared at the top of \ the module"); @@ -4168,10 +4163,10 @@ impl Parser { self.span_err(self.last_span, "expected item after attributes"); } - ast::_mod { view_items: view_items, items: items } + ast::Mod { view_items: view_items, items: items } } - fn parse_item_const(&mut self) -> item_info { + fn parse_item_const(&mut self) -> ItemInfo { let m = if self.eat_keyword(keywords::Mut) {MutMutable} else {MutImmutable}; let id = self.parse_ident(); self.expect(&token::COLON); @@ -4179,11 +4174,11 @@ impl Parser { self.expect(&token::EQ); let e = self.parse_expr(); self.commit_expr_expecting(e, token::SEMI); - (id, item_static(ty, m, e), None) + (id, ItemStatic(ty, m, e), None) } // parse a `mod <foo> { ... }` or `mod <foo>;` item - fn parse_item_mod(&mut self, outer_attrs: &[Attribute]) -> item_info { + fn parse_item_mod(&mut self, outer_attrs: &[Attribute]) -> ItemInfo { let id_span = self.span; let id = self.parse_ident(); if self.token == token::SEMI { @@ -4198,7 +4193,7 @@ impl Parser { let m = self.parse_mod_items(token::RBRACE, next); self.expect(&token::RBRACE); self.pop_mod_path(); - (id, item_mod(m), Some(inner)) + (id, ItemMod(m), Some(inner)) } } @@ -4221,7 +4216,7 @@ impl Parser { id: ast::Ident, outer_attrs: &[ast::Attribute], id_sp: Span) - -> (ast::item_, ~[ast::Attribute]) { + -> (ast::Item_, ~[ast::Attribute]) { let mut prefix = Path::new(self.sess.cm.span_to_filename(self.span)); prefix.pop(); let mod_path = Path::new(".").join_many(self.mod_path_stack); @@ -4260,7 +4255,7 @@ impl Parser { fn eval_src_mod_from_path(&mut self, path: Path, outer_attrs: ~[ast::Attribute], - id_sp: Span) -> (ast::item_, ~[ast::Attribute]) { + id_sp: Span) -> (ast::Item_, ~[ast::Attribute]) { { let mut included_mod_stack = self.sess .included_mod_stack @@ -4299,17 +4294,17 @@ impl Parser { .borrow_mut(); included_mod_stack.get().pop(); } - return (ast::item_mod(m0), mod_attrs); + return (ast::ItemMod(m0), mod_attrs); } // parse a function declaration from a foreign module - fn parse_item_foreign_fn(&mut self, vis: ast::visibility, - attrs: ~[Attribute]) -> @foreign_item { + fn parse_item_foreign_fn(&mut self, vis: ast::Visibility, + attrs: ~[Attribute]) -> @ForeignItem { let lo = self.span.lo; // Parse obsolete purity. let purity = self.parse_fn_purity(); - if purity != impure_fn { + if purity != ImpureFn { self.obsolete(self.last_span, ObsoleteUnsafeExternFn); } @@ -4317,17 +4312,17 @@ impl Parser { let decl = self.parse_fn_decl(true); let hi = self.span.hi; self.expect(&token::SEMI); - @ast::foreign_item { ident: ident, - attrs: attrs, - node: foreign_item_fn(decl, generics), - id: ast::DUMMY_NODE_ID, - span: mk_sp(lo, hi), - vis: vis } + @ast::ForeignItem { ident: ident, + attrs: attrs, + node: ForeignItemFn(decl, generics), + id: ast::DUMMY_NODE_ID, + span: mk_sp(lo, hi), + vis: vis } } // parse a static item from a foreign module - fn parse_item_foreign_static(&mut self, vis: ast::visibility, - attrs: ~[Attribute]) -> @foreign_item { + fn parse_item_foreign_static(&mut self, vis: ast::Visibility, + attrs: ~[Attribute]) -> @ForeignItem { let lo = self.span.lo; self.expect_keyword(keywords::Static); @@ -4338,20 +4333,20 @@ impl Parser { let ty = self.parse_ty(false); let hi = self.span.hi; self.expect(&token::SEMI); - @ast::foreign_item { ident: ident, - attrs: attrs, - node: foreign_item_static(ty, mutbl), - id: ast::DUMMY_NODE_ID, - span: mk_sp(lo, hi), - vis: vis } + @ast::ForeignItem { ident: ident, + attrs: attrs, + node: ForeignItemStatic(ty, mutbl), + id: ast::DUMMY_NODE_ID, + span: mk_sp(lo, hi), + vis: vis } } // parse safe/unsafe and fn - fn parse_fn_purity(&mut self) -> purity { - if self.eat_keyword(keywords::Fn) { impure_fn } + fn parse_fn_purity(&mut self) -> Purity { + if self.eat_keyword(keywords::Fn) { ImpureFn } else if self.eat_keyword(keywords::Unsafe) { self.expect_keyword(keywords::Fn); - unsafe_fn + UnsafeFn } else { self.unexpected(); } } @@ -4362,7 +4357,7 @@ impl Parser { fn parse_foreign_mod_items(&mut self, abis: AbiSet, first_item_attrs: ~[Attribute]) - -> foreign_mod { + -> ForeignMod { let ParsedItemsAndViewItems { attrs_remaining: attrs_remaining, view_items: view_items, @@ -4374,7 +4369,7 @@ impl Parser { "expected item after attributes"); } assert!(self.token == token::RBRACE); - ast::foreign_mod { + ast::ForeignMod { abis: abis, view_items: view_items, items: foreign_items @@ -4385,10 +4380,10 @@ impl Parser { fn parse_item_foreign_mod(&mut self, lo: BytePos, opt_abis: Option<AbiSet>, - visibility: visibility, + visibility: Visibility, attrs: ~[Attribute], items_allowed: bool) - -> item_or_view_item { + -> ItemOrViewItem { let mut must_be_named_mod = false; if self.is_keyword(keywords::Mod) { must_be_named_mod = true; @@ -4440,10 +4435,10 @@ impl Parser { let item = self.mk_item(lo, self.last_span.hi, ident, - item_foreign_mod(m), + ItemForeignMod(m), visibility, maybe_append(attrs, Some(inner))); - return iovi_item(item); + return IoviItem(item); } if opt_abis.is_some() { @@ -4460,8 +4455,8 @@ impl Parser { } // extern mod foo; self.expect(&token::SEMI); - iovi_view_item(ast::view_item { - node: view_item_extern_mod(ident, maybe_path, ast::DUMMY_NODE_ID), + IoviViewItem(ast::ViewItem { + node: ViewItemExternMod(ident, maybe_path, ast::DUMMY_NODE_ID), attrs: attrs, vis: visibility, span: mk_sp(lo, self.last_span.hi) @@ -4469,32 +4464,32 @@ impl Parser { } // parse type Foo = Bar; - fn parse_item_type(&mut self) -> item_info { + fn parse_item_type(&mut self) -> ItemInfo { let ident = self.parse_ident(); let tps = self.parse_generics(); self.expect(&token::EQ); let ty = self.parse_ty(false); self.expect(&token::SEMI); - (ident, item_ty(ty, tps), None) + (ident, ItemTy(ty, tps), None) } // parse a structure-like enum variant definition // this should probably be renamed or refactored... - fn parse_struct_def(&mut self) -> @struct_def { - let mut fields: ~[struct_field] = ~[]; + fn parse_struct_def(&mut self) -> @StructDef { + let mut fields: ~[StructField] = ~[]; while self.token != token::RBRACE { fields.push(self.parse_struct_decl_field()); } self.bump(); - return @ast::struct_def { + return @ast::StructDef { fields: fields, ctor_id: None }; } // parse the part of an "enum" decl following the '{' - fn parse_enum_def(&mut self, _generics: &ast::Generics) -> enum_def { + fn parse_enum_def(&mut self, _generics: &ast::Generics) -> EnumDef { let mut variants = ~[]; let mut all_nullary = true; let mut have_disr = false; @@ -4512,7 +4507,7 @@ impl Parser { if self.eat(&token::LBRACE) { // Parse a struct variant. all_nullary = false; - kind = struct_variant_kind(self.parse_struct_def()); + kind = StructVariantKind(self.parse_struct_def()); } else if self.token == token::LPAREN { all_nullary = false; let arg_tys = self.parse_unspanned_seq( @@ -4522,21 +4517,21 @@ impl Parser { |p| p.parse_ty(false) ); for ty in arg_tys.move_iter() { - args.push(ast::variant_arg { + args.push(ast::VariantArg { ty: ty, id: ast::DUMMY_NODE_ID, }); } - kind = tuple_variant_kind(args); + kind = TupleVariantKind(args); } else if self.eat(&token::EQ) { have_disr = true; disr_expr = Some(self.parse_expr()); - kind = tuple_variant_kind(args); + kind = TupleVariantKind(args); } else { - kind = tuple_variant_kind(~[]); + kind = TupleVariantKind(~[]); } - let vr = ast::variant_ { + let vr = ast::Variant_ { name: ident, attrs: variant_attrs, kind: kind, @@ -4554,17 +4549,17 @@ impl Parser { enum"); } - ast::enum_def { variants: variants } + ast::EnumDef { variants: variants } } // parse an "enum" declaration - fn parse_item_enum(&mut self) -> item_info { + fn parse_item_enum(&mut self) -> ItemInfo { let id = self.parse_ident(); let generics = self.parse_generics(); self.expect(&token::LBRACE); let enum_definition = self.parse_enum_def(&generics); - (id, item_enum(enum_definition, generics), None) + (id, ItemEnum(enum_definition, generics), None) } fn fn_expr_lookahead(tok: &token::Token) -> bool { @@ -4621,20 +4616,21 @@ impl Parser { } // parse one of the items or view items allowed by the - // flags; on failure, return iovi_none. + // flags; on failure, return IoviNone. // NB: this function no longer parses the items inside an // extern mod. fn parse_item_or_view_item(&mut self, attrs: ~[Attribute], macros_allowed: bool) - -> item_or_view_item { + -> ItemOrViewItem { match self.token { - INTERPOLATED(token::nt_item(item)) => { + INTERPOLATED(token::NtItem(item)) => { self.bump(); let new_attrs = vec::append(attrs, item.attrs); - return iovi_item(@ast::item { - attrs: new_attrs, - ..(*item).clone()}); + return IoviItem(@Item { + attrs: new_attrs, + ..(*item).clone() + }); } _ => {} } @@ -4645,10 +4641,10 @@ impl Parser { // must be a view item: if self.eat_keyword(keywords::Use) { - // USE ITEM (iovi_view_item) + // USE ITEM (IoviViewItem) let view_item = self.parse_use(); self.expect(&token::SEMI); - return iovi_view_item(ast::view_item { + return IoviViewItem(ast::ViewItem { node: view_item, attrs: attrs, vis: visibility, @@ -4663,16 +4659,16 @@ impl Parser { // EXTERN FUNCTION ITEM let abis = opt_abis.unwrap_or(AbiSet::C()); let (ident, item_, extra_attrs) = - self.parse_item_fn(extern_fn, abis); + self.parse_item_fn(ExternFn, abis); let item = self.mk_item(lo, self.last_span.hi, ident, item_, visibility, maybe_append(attrs, extra_attrs)); - return iovi_item(item); + return IoviItem(item); } else { - // EXTERN MODULE ITEM (iovi_view_item) + // EXTERN MODULE ITEM (IoviViewItem) return self.parse_item_foreign_mod(lo, opt_abis, visibility, attrs, true); } @@ -4688,21 +4684,21 @@ impl Parser { item_, visibility, maybe_append(attrs, extra_attrs)); - return iovi_item(item); + return IoviItem(item); } if self.is_keyword(keywords::Fn) && self.look_ahead(1, |f| !Parser::fn_expr_lookahead(f)) { // FUNCTION ITEM self.bump(); let (ident, item_, extra_attrs) = - self.parse_item_fn(impure_fn, AbiSet::Rust()); + self.parse_item_fn(ImpureFn, AbiSet::Rust()); let item = self.mk_item(lo, self.last_span.hi, ident, item_, visibility, maybe_append(attrs, extra_attrs)); - return iovi_item(item); + return IoviItem(item); } if self.is_keyword(keywords::Unsafe) && self.look_ahead(1u, |t| *t != token::LBRACE) { @@ -4710,14 +4706,14 @@ impl Parser { self.bump(); self.expect_keyword(keywords::Fn); let (ident, item_, extra_attrs) = - self.parse_item_fn(unsafe_fn, AbiSet::Rust()); + self.parse_item_fn(UnsafeFn, AbiSet::Rust()); let item = self.mk_item(lo, self.last_span.hi, ident, item_, visibility, maybe_append(attrs, extra_attrs)); - return iovi_item(item); + return IoviItem(item); } if self.eat_keyword(keywords::Mod) { // MODULE ITEM @@ -4728,7 +4724,7 @@ impl Parser { item_, visibility, maybe_append(attrs, extra_attrs)); - return iovi_item(item); + return IoviItem(item); } if self.eat_keyword(keywords::Type) { // TYPE ITEM @@ -4739,7 +4735,7 @@ impl Parser { item_, visibility, maybe_append(attrs, extra_attrs)); - return iovi_item(item); + return IoviItem(item); } if self.eat_keyword(keywords::Enum) { // ENUM ITEM @@ -4750,7 +4746,7 @@ impl Parser { item_, visibility, maybe_append(attrs, extra_attrs)); - return iovi_item(item); + return IoviItem(item); } if self.eat_keyword(keywords::Trait) { // TRAIT ITEM @@ -4761,7 +4757,7 @@ impl Parser { item_, visibility, maybe_append(attrs, extra_attrs)); - return iovi_item(item); + return IoviItem(item); } if self.eat_keyword(keywords::Impl) { // IMPL ITEM @@ -4772,7 +4768,7 @@ impl Parser { item_, visibility, maybe_append(attrs, extra_attrs)); - return iovi_item(item); + return IoviItem(item); } if self.eat_keyword(keywords::Struct) { // STRUCT ITEM @@ -4783,17 +4779,17 @@ impl Parser { item_, visibility, maybe_append(attrs, extra_attrs)); - return iovi_item(item); + return IoviItem(item); } self.parse_macro_use_or_failure(attrs,macros_allowed,lo,visibility) } - // parse a foreign item; on failure, return iovi_none. + // parse a foreign item; on failure, return IoviNone. fn parse_foreign_item(&mut self, attrs: ~[Attribute], macros_allowed: bool) - -> item_or_view_item { - maybe_whole!(iovi self, nt_item); + -> ItemOrViewItem { + maybe_whole!(iovi self, NtItem); let lo = self.span.lo; let visibility = self.parse_visibility(); @@ -4801,12 +4797,12 @@ impl Parser { if self.is_keyword(keywords::Static) { // FOREIGN STATIC ITEM let item = self.parse_item_foreign_static(visibility, attrs); - return iovi_foreign_item(item); + return IoviForeignItem(item); } if self.is_keyword(keywords::Fn) || self.is_keyword(keywords::Unsafe) { // FOREIGN FUNCTION ITEM let item = self.parse_item_foreign_fn(visibility, attrs); - return iovi_foreign_item(item); + return IoviForeignItem(item); } self.parse_macro_use_or_failure(attrs,macros_allowed,lo,visibility) } @@ -4816,9 +4812,9 @@ impl Parser { &mut self, attrs: ~[Attribute], macros_allowed: bool, - lo : BytePos, - visibility : visibility - ) -> item_or_view_item { + lo: BytePos, + visibility: Visibility + ) -> ItemOrViewItem { if macros_allowed && !token::is_any_keyword(&self.token) && self.look_ahead(1, |t| *t == token::NOT) && (self.look_ahead(2, |t| is_plain_ident(t)) @@ -4850,24 +4846,24 @@ impl Parser { _ => self.fatal("expected open delimiter") }; // single-variant-enum... : - let m = ast::mac_invoc_tt(pth, tts, EMPTY_CTXT); - let m: ast::mac = codemap::Spanned { node: m, + let m = ast::MacInvocTT(pth, tts, EMPTY_CTXT); + let m: ast::Mac = codemap::Spanned { node: m, span: mk_sp(self.span.lo, self.span.hi) }; - let item_ = item_mac(m); + let item_ = ItemMac(m); let item = self.mk_item(lo, self.last_span.hi, id, item_, visibility, attrs); - return iovi_item(item); + return IoviItem(item); } // FAILURE TO PARSE ITEM - if visibility != inherited { + if visibility != Inherited { let mut s = ~"unmatched visibility `"; - if visibility == public { + if visibility == Public { s.push_str("pub") } else { s.push_str("priv") @@ -4875,23 +4871,23 @@ impl Parser { s.push_char('`'); self.span_fatal(self.last_span, s); } - return iovi_none(attrs); + return IoviNone(attrs); } - pub fn parse_item(&mut self, attrs: ~[Attribute]) -> Option<@ast::item> { + pub fn parse_item(&mut self, attrs: ~[Attribute]) -> Option<@Item> { match self.parse_item_or_view_item(attrs, true) { - iovi_none(_) => None, - iovi_view_item(_) => + IoviNone(_) => None, + IoviViewItem(_) => self.fatal("view items are not allowed here"), - iovi_foreign_item(_) => + IoviForeignItem(_) => self.fatal("foreign items are not allowed here"), - iovi_item(item) => Some(item) + IoviItem(item) => Some(item) } } // parse, e.g., "use a::b::{z,y}" - fn parse_use(&mut self) -> view_item_ { - return view_item_use(self.parse_view_paths()); + fn parse_use(&mut self) -> ViewItem_ { + return ViewItemUse(self.parse_view_paths()); } @@ -4900,7 +4896,7 @@ impl Parser { // | MOD? non_global_path MOD_SEP LBRACE ident_seq RBRACE // | MOD? non_global_path MOD_SEP STAR // | MOD? non_global_path - fn parse_view_path(&mut self) -> @view_path { + fn parse_view_path(&mut self) -> @ViewPath { let lo = self.span.lo; if self.token == token::LBRACE { @@ -4915,12 +4911,12 @@ impl Parser { segments: ~[] }; return @spanned(lo, self.span.hi, - view_path_list(path, idents, ast::DUMMY_NODE_ID)); + ViewPathList(path, idents, ast::DUMMY_NODE_ID)); } let first_ident = self.parse_ident(); let mut path = ~[first_ident]; - debug!("parsed view_path: {}", self.id_to_str(first_ident)); + debug!("parsed view path: {}", self.id_to_str(first_ident)); match self.token { token::EQ => { // x = foo::bar @@ -4944,9 +4940,8 @@ impl Parser { }).collect() }; return @spanned(lo, self.span.hi, - view_path_simple(first_ident, - path, - ast::DUMMY_NODE_ID)); + ViewPathSimple(first_ident, path, + ast::DUMMY_NODE_ID)); } token::MOD_SEP => { @@ -4980,7 +4975,7 @@ impl Parser { }).collect() }; return @spanned(lo, self.span.hi, - view_path_list(path, idents, ast::DUMMY_NODE_ID)); + ViewPathList(path, idents, ast::DUMMY_NODE_ID)); } // foo::bar::* @@ -4998,7 +4993,7 @@ impl Parser { }).collect() }; return @spanned(lo, self.span.hi, - view_path_glob(path, ast::DUMMY_NODE_ID)); + ViewPathGlob(path, ast::DUMMY_NODE_ID)); } _ => break @@ -5021,11 +5016,11 @@ impl Parser { }; return @spanned(lo, self.last_span.hi, - view_path_simple(last, path, ast::DUMMY_NODE_ID)); + ViewPathSimple(last, path, ast::DUMMY_NODE_ID)); } // matches view_paths = view_path | view_path , view_paths - fn parse_view_paths(&mut self) -> ~[@view_path] { + fn parse_view_paths(&mut self) -> ~[@ViewPath] { let mut vp = ~[self.parse_view_path()]; while self.token == token::COMMA { self.bump(); @@ -5047,7 +5042,7 @@ impl Parser { let mut attrs = vec::append(first_item_attrs, self.parse_outer_attributes()); // First, parse view items. - let mut view_items : ~[ast::view_item] = ~[]; + let mut view_items : ~[ast::ViewItem] = ~[]; let mut items = ~[]; // I think this code would probably read better as a single @@ -5056,7 +5051,7 @@ impl Parser { // of macros, I'd like to delay that entire check until later. loop { match self.parse_item_or_view_item(attrs, macros_allowed) { - iovi_none(attrs) => { + IoviNone(attrs) => { return ParsedItemsAndViewItems { attrs_remaining: attrs, view_items: view_items, @@ -5064,27 +5059,26 @@ impl Parser { foreign_items: ~[] } } - iovi_view_item(view_item) => { + IoviViewItem(view_item) => { match view_item.node { - view_item_use(..) => { + ViewItemUse(..) => { // `extern mod` must precede `use`. extern_mod_allowed = false; } - view_item_extern_mod(..) - if !extern_mod_allowed => { + ViewItemExternMod(..) if !extern_mod_allowed => { self.span_err(view_item.span, "\"extern mod\" declarations are not allowed here"); } - view_item_extern_mod(..) => {} + ViewItemExternMod(..) => {} } view_items.push(view_item); } - iovi_item(item) => { + IoviItem(item) => { items.push(item); attrs = self.parse_outer_attributes(); break; } - iovi_foreign_item(_) => { + IoviForeignItem(_) => { fail!(); } } @@ -5094,20 +5088,20 @@ impl Parser { // Next, parse items. loop { match self.parse_item_or_view_item(attrs, macros_allowed) { - iovi_none(returned_attrs) => { + IoviNone(returned_attrs) => { attrs = returned_attrs; break } - iovi_view_item(view_item) => { + IoviViewItem(view_item) => { attrs = self.parse_outer_attributes(); self.span_err(view_item.span, "`use` and `extern mod` declarations must precede items"); } - iovi_item(item) => { + IoviItem(item) => { attrs = self.parse_outer_attributes(); items.push(item) } - iovi_foreign_item(_) => { + IoviForeignItem(_) => { fail!(); } } @@ -5131,23 +5125,23 @@ impl Parser { let mut foreign_items = ~[]; loop { match self.parse_foreign_item(attrs, macros_allowed) { - iovi_none(returned_attrs) => { + IoviNone(returned_attrs) => { if self.token == token::RBRACE { attrs = returned_attrs; break } self.unexpected(); }, - iovi_view_item(view_item) => { + IoviViewItem(view_item) => { // I think this can't occur: self.span_err(view_item.span, "`use` and `extern mod` declarations must precede items"); } - iovi_item(item) => { + IoviItem(item) => { // FIXME #5668: this will occur for a macro invocation: self.span_fatal(item.span, "macros cannot expand to foreign items"); } - iovi_foreign_item(foreign_item) => { + IoviForeignItem(foreign_item) => { foreign_items.push(foreign_item); } } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 9e1eec19b2c..42313e64283 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -19,8 +19,9 @@ use std::cast; use std::char; use std::local_data; +#[allow(non_camel_case_types)] #[deriving(Clone, Encodable, Decodable, Eq, IterBytes)] -pub enum binop { +pub enum BinOp { PLUS, MINUS, STAR, @@ -33,6 +34,7 @@ pub enum binop { SHR, } +#[allow(non_camel_case_types)] #[deriving(Clone, Encodable, Decodable, Eq, IterBytes)] pub enum Token { /* Expression-operator symbols. */ @@ -47,8 +49,8 @@ pub enum Token { OROR, NOT, TILDE, - BINOP(binop), - BINOPEQ(binop), + BINOP(BinOp), + BINOPEQ(BinOp), /* Structural symbols */ AT, @@ -74,10 +76,10 @@ pub enum Token { /* Literals */ LIT_CHAR(u32), - LIT_INT(i64, ast::int_ty), - LIT_UINT(u64, ast::uint_ty), + LIT_INT(i64, ast::IntTy), + LIT_UINT(u64, ast::UintTy), LIT_INT_UNSUFFIXED(i64), - LIT_FLOAT(ast::Ident, ast::float_ty), + LIT_FLOAT(ast::Ident, ast::FloatTy), LIT_FLOAT_UNSUFFIXED(ast::Ident), LIT_STR(ast::Ident), LIT_STR_RAW(ast::Ident, uint), /* raw str delimited by n hash symbols */ @@ -91,7 +93,7 @@ pub enum Token { LIFETIME(ast::Ident), /* For interpolation */ - INTERPOLATED(nonterminal), + INTERPOLATED(Nonterminal), DOC_COMMENT(ast::Ident), EOF, @@ -99,21 +101,21 @@ pub enum Token { #[deriving(Clone, Encodable, Decodable, Eq, IterBytes)] /// For interpolation during macro expansion. -pub enum nonterminal { - nt_item(@ast::item), - nt_block(P<ast::Block>), - nt_stmt(@ast::Stmt), - nt_pat( @ast::Pat), - nt_expr(@ast::Expr), - nt_ty( P<ast::Ty>), - nt_ident(~ast::Ident, bool), - nt_attr(@ast::Attribute), // #[foo] - nt_path(~ast::Path), - nt_tt( @ast::token_tree), //needs @ed to break a circularity - nt_matchers(~[ast::matcher]) -} - -pub fn binop_to_str(o: binop) -> ~str { +pub enum Nonterminal { + NtItem(@ast::Item), + NtBlock(P<ast::Block>), + NtStmt(@ast::Stmt), + NtPat( @ast::Pat), + NtExpr(@ast::Expr), + NtTy( P<ast::Ty>), + NtIdent(~ast::Ident, bool), + NtAttr(@ast::Attribute), // #[foo] + NtPath(~ast::Path), + NtTT( @ast::TokenTree), // needs @ed to break a circularity + NtMatchers(~[ast::Matcher]) +} + +pub fn binop_to_str(o: BinOp) -> ~str { match o { PLUS => ~"+", MINUS => ~"-", @@ -128,7 +130,7 @@ pub fn binop_to_str(o: binop) -> ~str { } } -pub fn to_str(input: @ident_interner, t: &Token) -> ~str { +pub fn to_str(input: @IdentInterner, t: &Token) -> ~str { match *t { EQ => ~"=", LT => ~"<", @@ -212,22 +214,22 @@ pub fn to_str(input: @ident_interner, t: &Token) -> ~str { EOF => ~"<eof>", INTERPOLATED(ref nt) => { match nt { - &nt_expr(e) => ::print::pprust::expr_to_str(e, input), - &nt_attr(e) => ::print::pprust::attribute_to_str(e, input), + &NtExpr(e) => ::print::pprust::expr_to_str(e, input), + &NtAttr(e) => ::print::pprust::attribute_to_str(e, input), _ => { ~"an interpolated " + match (*nt) { - nt_item(..) => ~"item", - nt_block(..) => ~"block", - nt_stmt(..) => ~"statement", - nt_pat(..) => ~"pattern", - nt_attr(..) => fail!("should have been handled"), - nt_expr(..) => fail!("should have been handled above"), - nt_ty(..) => ~"type", - nt_ident(..) => ~"identifier", - nt_path(..) => ~"path", - nt_tt(..) => ~"tt", - nt_matchers(..) => ~"matcher sequence" + NtItem(..) => ~"item", + NtBlock(..) => ~"block", + NtStmt(..) => ~"statement", + NtPat(..) => ~"pattern", + NtAttr(..) => fail!("should have been handled"), + NtExpr(..) => fail!("should have been handled above"), + NtTy(..) => ~"type", + NtIdent(..) => ~"identifier", + NtPath(..) => ~"path", + NtTT(..) => ~"tt", + NtMatchers(..) => ~"matcher sequence" } } } @@ -260,10 +262,10 @@ pub fn can_begin_expr(t: &Token) -> bool { BINOP(OR) => true, // in lambda syntax OROR => true, // in lambda syntax MOD_SEP => true, - INTERPOLATED(nt_expr(..)) - | INTERPOLATED(nt_ident(..)) - | INTERPOLATED(nt_block(..)) - | INTERPOLATED(nt_path(..)) => true, + INTERPOLATED(NtExpr(..)) + | INTERPOLATED(NtIdent(..)) + | INTERPOLATED(NtBlock(..)) + | INTERPOLATED(NtPath(..)) => true, _ => false } } @@ -303,7 +305,7 @@ pub fn is_ident(t: &Token) -> bool { pub fn is_ident_or_path(t: &Token) -> bool { match *t { - IDENT(_, _) | INTERPOLATED(nt_path(..)) => true, + IDENT(_, _) | INTERPOLATED(NtPath(..)) => true, _ => false } } @@ -381,7 +383,7 @@ macro_rules! declare_special_idents_and_keywords {( } } - fn mk_fresh_ident_interner() -> @ident_interner { + fn mk_fresh_ident_interner() -> @IdentInterner { // The indices here must correspond to the numbers in // special_idents, in Keyword to_ident(), and in static // constants below. @@ -508,12 +510,12 @@ pub fn token_to_binop(tok: &Token) -> Option<ast::BinOp> { } // looks like we can get rid of this completely... -pub type ident_interner = StrInterner; +pub type IdentInterner = StrInterner; // if an interner exists in TLS, return it. Otherwise, prepare a // fresh one. -pub fn get_ident_interner() -> @ident_interner { - local_data_key!(key: @@::parse::token::ident_interner) +pub fn get_ident_interner() -> @IdentInterner { + local_data_key!(key: @@::parse::token::IdentInterner) match local_data::get(key, |k| k.map(|k| *k)) { Some(interner) => *interner, None => { @@ -526,7 +528,7 @@ pub fn get_ident_interner() -> @ident_interner { /* for when we don't care about the contents; doesn't interact with TLD or serialization */ -pub fn mk_fake_ident_interner() -> @ident_interner { +pub fn mk_fake_ident_interner() -> @IdentInterner { @interner::StrInterner::new() } diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index a6239ab3806..c421c2f4d7a 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -41,12 +41,12 @@ * the Mesa implementation (somewhat randomly) stores the offset on the print * stack in terms of margin-col rather than col itself. I store col. * - * I also implemented a small change in the STRING token, in that I store an + * I also implemented a small change in the String token, in that I store an * explicit length for the string. For most tokens this is just the length of * the accompanying string. But it's necessary to permit it to differ, for * encoding things that are supposed to "go on their own line" -- certain * classes of comment and blank-line -- where relying on adjacent - * hardbreak-like BREAK tokens with long blankness indication doesn't actually + * hardbreak-like Break tokens with long blankness indication doesn't actually * work. To see why, consider when there is a "thing that should be on its own * line" between two long blocks, say functions. If you put a hardbreak after * each function (or before each) and the breaking algorithm decides to break @@ -65,43 +65,43 @@ use std::io; use std::vec; #[deriving(Clone, Eq)] -pub enum breaks { - consistent, - inconsistent, +pub enum Breaks { + Consistent, + Inconsistent, } #[deriving(Clone)] -pub struct break_t { +pub struct BreakToken { offset: int, blank_space: int } #[deriving(Clone)] -pub struct begin_t { +pub struct BeginToken { offset: int, - breaks: breaks + breaks: Breaks } #[deriving(Clone)] -pub enum token { - STRING(@str, int), - BREAK(break_t), - BEGIN(begin_t), - END, - EOF, +pub enum Token { + String(@str, int), + Break(BreakToken), + Begin(BeginToken), + End, + Eof, } -impl token { +impl Token { pub fn is_eof(&self) -> bool { - match *self { EOF => true, _ => false } + match *self { Eof => true, _ => false } } pub fn is_hardbreak_tok(&self) -> bool { match *self { - BREAK(break_t { + Break(BreakToken { offset: 0, blank_space: bs - }) if bs == size_infinity => + }) if bs == SIZE_INFINITY => true, _ => false @@ -109,17 +109,17 @@ impl token { } } -pub fn tok_str(t: token) -> ~str { +pub fn tok_str(t: Token) -> ~str { match t { - STRING(s, len) => return format!("STR({},{})", s, len), - BREAK(_) => return ~"BREAK", - BEGIN(_) => return ~"BEGIN", - END => return ~"END", - EOF => return ~"EOF" + String(s, len) => return format!("STR({},{})", s, len), + Break(_) => return ~"BREAK", + Begin(_) => return ~"BEGIN", + End => return ~"END", + Eof => return ~"EOF" } } -pub fn buf_str(toks: ~[token], szs: ~[int], left: uint, right: uint, +pub fn buf_str(toks: ~[Token], szs: ~[int], left: uint, right: uint, lim: uint) -> ~str { let n = toks.len(); assert_eq!(n, szs.len()); @@ -139,21 +139,24 @@ pub fn buf_str(toks: ~[token], szs: ~[int], left: uint, right: uint, return s; } -pub enum print_stack_break { fits, broken(breaks), } +enum PrintStackBreak { + Fits, + Broken(Breaks), +} -pub struct print_stack_elt { +struct PrintStackElem { offset: int, - pbreak: print_stack_break + pbreak: PrintStackBreak } -pub static size_infinity: int = 0xffff; +static SIZE_INFINITY: int = 0xffff; pub fn mk_printer(out: ~io::Writer, linewidth: uint) -> Printer { // Yes 3, it makes the ring buffers big enough to never // fall behind. let n: uint = 3 * linewidth; debug!("mk_printer {}", linewidth); - let token: ~[token] = vec::from_elem(n, EOF); + let token: ~[Token] = vec::from_elem(n, Eof); let size: ~[int] = vec::from_elem(n, 0); let scan_stack: ~[uint] = vec::from_elem(n, 0u); Printer { @@ -187,9 +190,9 @@ pub fn mk_printer(out: ~io::Writer, linewidth: uint) -> Printer { * Yes, linewidth is chars and tokens are multi-char, but in the worst * case every token worth buffering is 1 char long, so it's ok. * - * Tokens are STRING, BREAK, and BEGIN/END to delimit blocks. + * Tokens are String, Break, and Begin/End to delimit blocks. * - * BEGIN tokens can carry an offset, saying "how far to indent when you break + * Begin tokens can carry an offset, saying "how far to indent when you break * inside here", as well as a flag indicating "consistent" or "inconsistent" * breaking. Consistent breaking means that after the first break, no attempt * will be made to flow subsequent breaks together onto lines. Inconsistent @@ -223,10 +226,10 @@ pub fn mk_printer(out: ~io::Writer, linewidth: uint) -> Printer { * and point-in-infinite-stream senses freely. * * There is a parallel ring buffer, 'size', that holds the calculated size of - * each token. Why calculated? Because for BEGIN/END pairs, the "size" - * includes everything betwen the pair. That is, the "size" of BEGIN is - * actually the sum of the sizes of everything between BEGIN and the paired - * END that follows. Since that is arbitrarily far in the future, 'size' is + * each token. Why calculated? Because for Begin/End pairs, the "size" + * includes everything betwen the pair. That is, the "size" of Begin is + * actually the sum of the sizes of everything between Begin and the paired + * End that follows. Since that is arbitrarily far in the future, 'size' is * being rewritten regularly while the printer runs; in fact most of the * machinery is here to work out 'size' entries on the fly (and give up when * they're so obviously over-long that "infinity" is a good enough @@ -261,14 +264,14 @@ pub struct Printer { space: int, // number of spaces left on line left: uint, // index of left side of input stream right: uint, // index of right side of input stream - token: ~[token], // ring-buffr stream goes through + token: ~[Token], // ring-buffr stream goes through size: ~[int], // ring-buffer of calculated sizes left_total: int, // running size of stream "...left" right_total: int, // running size of stream "...right" // pseudo-stack, really a ring too. Holds the - // primary-ring-buffers index of the BEGIN that started the - // current block, possibly with the most recent BREAK after that - // BEGIN (if there is any) on top of it. Stuff is flushed off the + // primary-ring-buffers index of the Begin that started the + // current block, possibly with the most recent Break after that + // Begin (if there is any) on top of it. Stuff is flushed off the // bottom as it becomes irrelevant due to the primary ring-buffer // advancing. scan_stack: ~[uint], @@ -276,21 +279,21 @@ pub struct Printer { top: uint, // index of top of scan_stack bottom: uint, // index of bottom of scan_stack // stack of blocks-in-progress being flushed by print - print_stack: ~[print_stack_elt], + print_stack: ~[PrintStackElem], // buffered indentation to avoid writing trailing whitespace pending_indentation: int, } impl Printer { - pub fn last_token(&mut self) -> token { self.token[self.right] } + pub fn last_token(&mut self) -> Token { self.token[self.right] } // be very careful with this! - pub fn replace_last_token(&mut self, t: token) { + pub fn replace_last_token(&mut self, t: Token) { self.token[self.right] = t; } - pub fn pretty_print(&mut self, t: token) { + pub fn pretty_print(&mut self, t: Token) { debug!("pp ~[{},{}]", self.left, self.right); match t { - EOF => { + Eof => { if !self.scan_stack_empty { self.check_stack(0); self.advance_left(self.token[self.left], @@ -298,39 +301,39 @@ impl Printer { } self.indent(0); } - BEGIN(b) => { + Begin(b) => { if self.scan_stack_empty { self.left_total = 1; self.right_total = 1; self.left = 0u; self.right = 0u; } else { self.advance_right(); } - debug!("pp BEGIN({})/buffer ~[{},{}]", + debug!("pp Begin({})/buffer ~[{},{}]", b.offset, self.left, self.right); self.token[self.right] = t; self.size[self.right] = -self.right_total; self.scan_push(self.right); } - END => { + End => { if self.scan_stack_empty { - debug!("pp END/print ~[{},{}]", self.left, self.right); + debug!("pp End/print ~[{},{}]", self.left, self.right); self.print(t, 0); } else { - debug!("pp END/buffer ~[{},{}]", self.left, self.right); + debug!("pp End/buffer ~[{},{}]", self.left, self.right); self.advance_right(); self.token[self.right] = t; self.size[self.right] = -1; self.scan_push(self.right); } } - BREAK(b) => { + Break(b) => { if self.scan_stack_empty { self.left_total = 1; self.right_total = 1; self.left = 0u; self.right = 0u; } else { self.advance_right(); } - debug!("pp BREAK({})/buffer ~[{},{}]", + debug!("pp Break({})/buffer ~[{},{}]", b.offset, self.left, self.right); self.check_stack(0); self.scan_push(self.right); @@ -338,13 +341,13 @@ impl Printer { self.size[self.right] = -self.right_total; self.right_total += b.blank_space; } - STRING(s, len) => { + String(s, len) => { if self.scan_stack_empty { - debug!("pp STRING('{}')/print ~[{},{}]", + debug!("pp String('{}')/print ~[{},{}]", s, self.left, self.right); self.print(t, len); } else { - debug!("pp STRING('{}')/buffer ~[{},{}]", + debug!("pp String('{}')/buffer ~[{},{}]", s, self.left, self.right); self.advance_right(); self.token[self.right] = t; @@ -364,7 +367,7 @@ impl Printer { if !self.scan_stack_empty { if self.left == self.scan_stack[self.bottom] { debug!("setting {} to infinity and popping", self.left); - self.size[self.scan_pop_bottom()] = size_infinity; + self.size[self.scan_pop_bottom()] = SIZE_INFINITY; } } self.advance_left(self.token[self.left], self.size[self.left]); @@ -407,14 +410,14 @@ impl Printer { self.right %= self.buf_len; assert!((self.right != self.left)); } - pub fn advance_left(&mut self, x: token, L: int) { + pub fn advance_left(&mut self, x: Token, L: int) { debug!("advnce_left ~[{},{}], sizeof({})={}", self.left, self.right, self.left, L); if L >= 0 { self.print(x, L); match x { - BREAK(b) => self.left_total += b.blank_space, - STRING(_, len) => { + Break(b) => self.left_total += b.blank_space, + String(_, len) => { assert_eq!(len, L); self.left_total += len; } _ => () @@ -431,14 +434,14 @@ impl Printer { if !self.scan_stack_empty { let x = self.scan_top(); match self.token[x] { - BEGIN(_) => { + Begin(_) => { if k > 0 { self.size[self.scan_pop()] = self.size[x] + self.right_total; self.check_stack(k - 1); } } - END => { + End => { // paper says + not =, but that makes no sense. self.size[self.scan_pop()] = 1; self.check_stack(k + 1); @@ -460,15 +463,15 @@ impl Printer { debug!("INDENT {}", amount); self.pending_indentation += amount; } - pub fn get_top(&mut self) -> print_stack_elt { + pub fn get_top(&mut self) -> PrintStackElem { let print_stack = &mut self.print_stack; let n = print_stack.len(); if n != 0u { print_stack[n - 1u] } else { - print_stack_elt { + PrintStackElem { offset: 0, - pbreak: broken(inconsistent) + pbreak: Broken(Inconsistent) } } } @@ -479,7 +482,7 @@ impl Printer { } write!(self.out, "{}", s); } - pub fn print(&mut self, x: token, L: int) { + pub fn print(&mut self, x: Token, L: int) { debug!("print {} {} (remaining line space={})", tok_str(x), L, self.space); debug!("{}", buf_str(self.token.clone(), @@ -488,50 +491,50 @@ impl Printer { self.right, 6)); match x { - BEGIN(b) => { + Begin(b) => { if L > self.space { let col = self.margin - self.space + b.offset; - debug!("print BEGIN -> push broken block at col {}", col); - self.print_stack.push(print_stack_elt { + debug!("print Begin -> push broken block at col {}", col); + self.print_stack.push(PrintStackElem { offset: col, - pbreak: broken(b.breaks) + pbreak: Broken(b.breaks) }); } else { - debug!("print BEGIN -> push fitting block"); - self.print_stack.push(print_stack_elt { + debug!("print Begin -> push fitting block"); + self.print_stack.push(PrintStackElem { offset: 0, - pbreak: fits + pbreak: Fits }); } } - END => { - debug!("print END -> pop END"); + End => { + debug!("print End -> pop End"); let print_stack = &mut self.print_stack; assert!((print_stack.len() != 0u)); print_stack.pop(); } - BREAK(b) => { + Break(b) => { let top = self.get_top(); match top.pbreak { - fits => { - debug!("print BREAK({}) in fitting block", b.blank_space); + Fits => { + debug!("print Break({}) in fitting block", b.blank_space); self.space -= b.blank_space; self.indent(b.blank_space); } - broken(consistent) => { - debug!("print BREAK({}+{}) in consistent block", + Broken(Consistent) => { + debug!("print Break({}+{}) in consistent block", top.offset, b.offset); self.print_newline(top.offset + b.offset); self.space = self.margin - (top.offset + b.offset); } - broken(inconsistent) => { + Broken(Inconsistent) => { if L > self.space { - debug!("print BREAK({}+{}) w/ newline in inconsistent", + debug!("print Break({}+{}) w/ newline in inconsistent", top.offset, b.offset); self.print_newline(top.offset + b.offset); self.space = self.margin - (top.offset + b.offset); } else { - debug!("print BREAK({}) w/o newline in inconsistent", + debug!("print Break({}) w/o newline in inconsistent", b.blank_space); self.indent(b.blank_space); self.space -= b.blank_space; @@ -539,15 +542,15 @@ impl Printer { } } } - STRING(s, len) => { - debug!("print STRING({})", s); + String(s, len) => { + debug!("print String({})", s); assert_eq!(L, len); // assert!(L <= space); self.space -= len; self.print_str(s); } - EOF => { - // EOF should never get here. + Eof => { + // Eof should never get here. fail!(); } } @@ -557,38 +560,38 @@ impl Printer { // Convenience functions to talk to the printer. // // "raw box" -pub fn rbox(p: &mut Printer, indent: uint, b: breaks) { - p.pretty_print(BEGIN(begin_t { +pub fn rbox(p: &mut Printer, indent: uint, b: Breaks) { + p.pretty_print(Begin(BeginToken { offset: indent as int, breaks: b })); } -pub fn ibox(p: &mut Printer, indent: uint) { rbox(p, indent, inconsistent); } +pub fn ibox(p: &mut Printer, indent: uint) { rbox(p, indent, Inconsistent); } -pub fn cbox(p: &mut Printer, indent: uint) { rbox(p, indent, consistent); } +pub fn cbox(p: &mut Printer, indent: uint) { rbox(p, indent, Consistent); } pub fn break_offset(p: &mut Printer, n: uint, off: int) { - p.pretty_print(BREAK(break_t { + p.pretty_print(Break(BreakToken { offset: off, blank_space: n as int })); } -pub fn end(p: &mut Printer) { p.pretty_print(END); } +pub fn end(p: &mut Printer) { p.pretty_print(End); } -pub fn eof(p: &mut Printer) { p.pretty_print(EOF); } +pub fn eof(p: &mut Printer) { p.pretty_print(Eof); } pub fn word(p: &mut Printer, wrd: &str) { - p.pretty_print(STRING(/* bad */ wrd.to_managed(), wrd.len() as int)); + p.pretty_print(String(/* bad */ wrd.to_managed(), wrd.len() as int)); } pub fn huge_word(p: &mut Printer, wrd: &str) { - p.pretty_print(STRING(/* bad */ wrd.to_managed(), size_infinity)); + p.pretty_print(String(/* bad */ wrd.to_managed(), SIZE_INFINITY)); } pub fn zero_word(p: &mut Printer, wrd: &str) { - p.pretty_print(STRING(/* bad */ wrd.to_managed(), 0)); + p.pretty_print(String(/* bad */ wrd.to_managed(), 0)); } pub fn spaces(p: &mut Printer, n: uint) { break_offset(p, n, 0); } @@ -597,10 +600,10 @@ pub fn zerobreak(p: &mut Printer) { spaces(p, 0u); } pub fn space(p: &mut Printer) { spaces(p, 1u); } -pub fn hardbreak(p: &mut Printer) { spaces(p, size_infinity as uint); } +pub fn hardbreak(p: &mut Printer) { spaces(p, SIZE_INFINITY as uint); } -pub fn hardbreak_tok_offset(off: int) -> token { - BREAK(break_t {offset: off, blank_space: size_infinity}) +pub fn hardbreak_tok_offset(off: int) -> Token { + Break(BreakToken {offset: off, blank_space: SIZE_INFINITY}) } -pub fn hardbreak_tok() -> token { return hardbreak_tok_offset(0); } +pub fn hardbreak_tok() -> Token { return hardbreak_tok_offset(0); } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 82a7d550f64..1e2e5dbc010 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -9,7 +9,7 @@ // except according to those terms. use abi::AbiSet; -use ast::{P, RegionTyParamBound, TraitTyParamBound, required, provided}; +use ast::{P, RegionTyParamBound, TraitTyParamBound, Required, Provided}; use ast; use ast_util; use opt_vec::OptVec; @@ -19,11 +19,11 @@ use codemap::{CodeMap, BytePos}; use codemap; use diagnostic; use parse::classify::expr_is_simple_block; -use parse::token::{ident_interner, ident_to_str, interner_get}; +use parse::token::{IdentInterner, ident_to_str, interner_get}; use parse::{comments, token}; use parse; use print::pp::{break_offset, word, space, zerobreak, hardbreak}; -use print::pp::{breaks, consistent, inconsistent, eof}; +use print::pp::{Breaks, Consistent, Inconsistent, eof}; use print::pp; use print::pprust; @@ -34,58 +34,48 @@ use std::str; use std::io; use std::io::mem::MemWriter; -// The &mut ps is stored here to prevent recursive type. -pub enum ann_node<'a,'b> { - node_block(&'b mut ps, &'a ast::Block), - node_item(&'b mut ps, &'a ast::item), - node_expr(&'b mut ps, &'a ast::Expr), - node_pat(&'b mut ps, &'a ast::Pat), +// The &mut State is stored here to prevent recursive type. +pub enum AnnNode<'a,'b> { + NodeBlock(&'b mut State, &'a ast::Block), + NodeItem(&'b mut State, &'a ast::Item), + NodeExpr(&'b mut State, &'a ast::Expr), + NodePat(&'b mut State, &'a ast::Pat), } -pub trait pp_ann { - fn pre(&self, _node: ann_node) {} - fn post(&self, _node: ann_node) {} +pub trait PpAnn { + fn pre(&self, _node: AnnNode) {} + fn post(&self, _node: AnnNode) {} } -pub struct no_ann { - contents: (), -} - -impl no_ann { - pub fn new() -> no_ann { - no_ann { - contents: (), - } - } -} +pub struct NoAnn; -impl pp_ann for no_ann {} +impl PpAnn for NoAnn {} pub struct CurrentCommentAndLiteral { cur_cmnt: uint, cur_lit: uint, } -pub struct ps { +pub struct State { s: pp::Printer, cm: Option<@CodeMap>, - intr: @token::ident_interner, - comments: Option<~[comments::cmnt]>, - literals: Option<~[comments::lit]>, + intr: @token::IdentInterner, + comments: Option<~[comments::Comment]>, + literals: Option<~[comments::Literal]>, cur_cmnt_and_lit: CurrentCommentAndLiteral, - boxes: RefCell<~[pp::breaks]>, - ann: @pp_ann + boxes: RefCell<~[pp::Breaks]>, + ann: @PpAnn } -pub fn ibox(s: &mut ps, u: uint) { +pub fn ibox(s: &mut State, u: uint) { { let mut boxes = s.boxes.borrow_mut(); - boxes.get().push(pp::inconsistent); + boxes.get().push(pp::Inconsistent); } pp::ibox(&mut s.s, u); } -pub fn end(s: &mut ps) { +pub fn end(s: &mut State) { { let mut boxes = s.boxes.borrow_mut(); boxes.get().pop(); @@ -93,20 +83,20 @@ pub fn end(s: &mut ps) { pp::end(&mut s.s); } -pub fn rust_printer(writer: ~io::Writer, intr: @ident_interner) -> ps { - return rust_printer_annotated(writer, intr, @no_ann::new() as @pp_ann); +pub fn rust_printer(writer: ~io::Writer, intr: @IdentInterner) -> State { + return rust_printer_annotated(writer, intr, @NoAnn as @PpAnn); } pub fn rust_printer_annotated(writer: ~io::Writer, - intr: @ident_interner, - ann: @pp_ann) - -> ps { - return ps { + intr: @IdentInterner, + ann: @PpAnn) + -> State { + return State { s: pp::mk_printer(writer, default_columns), - cm: None::<@CodeMap>, + cm: None, intr: intr, - comments: None::<~[comments::cmnt]>, - literals: None::<~[comments::lit]>, + comments: None, + literals: None, cur_cmnt_and_lit: CurrentCommentAndLiteral { cur_cmnt: 0, cur_lit: 0 @@ -124,20 +114,20 @@ pub static default_columns: uint = 78u; // it can scan the input text for comments and literals to // copy forward. pub fn print_crate(cm: @CodeMap, - intr: @ident_interner, + intr: @IdentInterner, span_diagnostic: @diagnostic::SpanHandler, crate: &ast::Crate, filename: @str, input: &mut io::Reader, out: ~io::Writer, - ann: @pp_ann, + ann: @PpAnn, is_expanded: bool) { let (cmnts, lits) = comments::gather_comments_and_literals( span_diagnostic, filename, input ); - let mut s = ps { + let mut s = State { s: pp::mk_printer(out, default_columns), cm: Some(cm), intr: intr, @@ -160,60 +150,60 @@ pub fn print_crate(cm: @CodeMap, print_crate_(&mut s, crate); } -pub fn print_crate_(s: &mut ps, crate: &ast::Crate) { +pub fn print_crate_(s: &mut State, crate: &ast::Crate) { print_mod(s, &crate.module, crate.attrs); print_remaining_comments(s); eof(&mut s.s); } -pub fn ty_to_str(ty: &ast::Ty, intr: @ident_interner) -> ~str { +pub fn ty_to_str(ty: &ast::Ty, intr: @IdentInterner) -> ~str { to_str(ty, print_type, intr) } -pub fn pat_to_str(pat: &ast::Pat, intr: @ident_interner) -> ~str { +pub fn pat_to_str(pat: &ast::Pat, intr: @IdentInterner) -> ~str { to_str(pat, print_pat, intr) } -pub fn expr_to_str(e: &ast::Expr, intr: @ident_interner) -> ~str { +pub fn expr_to_str(e: &ast::Expr, intr: @IdentInterner) -> ~str { to_str(e, print_expr, intr) } -pub fn lifetime_to_str(e: &ast::Lifetime, intr: @ident_interner) -> ~str { +pub fn lifetime_to_str(e: &ast::Lifetime, intr: @IdentInterner) -> ~str { to_str(e, print_lifetime, intr) } -pub fn tt_to_str(tt: &ast::token_tree, intr: @ident_interner) -> ~str { +pub fn tt_to_str(tt: &ast::TokenTree, intr: @IdentInterner) -> ~str { to_str(tt, print_tt, intr) } -pub fn tts_to_str(tts: &[ast::token_tree], intr: @ident_interner) -> ~str { +pub fn tts_to_str(tts: &[ast::TokenTree], intr: @IdentInterner) -> ~str { to_str(&tts, print_tts, intr) } -pub fn stmt_to_str(s: &ast::Stmt, intr: @ident_interner) -> ~str { +pub fn stmt_to_str(s: &ast::Stmt, intr: @IdentInterner) -> ~str { to_str(s, print_stmt, intr) } -pub fn item_to_str(i: &ast::item, intr: @ident_interner) -> ~str { +pub fn item_to_str(i: &ast::Item, intr: @IdentInterner) -> ~str { to_str(i, print_item, intr) } pub fn generics_to_str(generics: &ast::Generics, - intr: @ident_interner) -> ~str { + intr: @IdentInterner) -> ~str { to_str(generics, print_generics, intr) } -pub fn path_to_str(p: &ast::Path, intr: @ident_interner) -> ~str { +pub fn path_to_str(p: &ast::Path, intr: @IdentInterner) -> ~str { to_str(p, |a,b| print_path(a, b, false), intr) } -pub fn fun_to_str(decl: &ast::fn_decl, purity: ast::purity, name: ast::Ident, - opt_explicit_self: Option<ast::explicit_self_>, - generics: &ast::Generics, intr: @ident_interner) -> ~str { +pub fn fun_to_str(decl: &ast::FnDecl, purity: ast::Purity, name: ast::Ident, + opt_explicit_self: Option<ast::ExplicitSelf_>, + generics: &ast::Generics, intr: @IdentInterner) -> ~str { let wr = ~MemWriter::new(); let mut s = rust_printer(wr as ~io::Writer, intr); print_fn(&mut s, decl, Some(purity), AbiSet::Rust(), - name, generics, opt_explicit_self, ast::inherited); + name, generics, opt_explicit_self, ast::Inherited); end(&mut s); // Close the head box end(&mut s); // Close the outer box eof(&mut s.s); @@ -222,7 +212,7 @@ pub fn fun_to_str(decl: &ast::fn_decl, purity: ast::purity, name: ast::Ident, } } -pub fn block_to_str(blk: &ast::Block, intr: @ident_interner) -> ~str { +pub fn block_to_str(blk: &ast::Block, intr: @IdentInterner) -> ~str { let wr = ~MemWriter::new(); let mut s = rust_printer(wr as ~io::Writer, intr); // containing cbox, will be closed by print-block at } @@ -236,28 +226,28 @@ pub fn block_to_str(blk: &ast::Block, intr: @ident_interner) -> ~str { } } -pub fn meta_item_to_str(mi: &ast::MetaItem, intr: @ident_interner) -> ~str { +pub fn meta_item_to_str(mi: &ast::MetaItem, intr: @IdentInterner) -> ~str { to_str(mi, print_meta_item, intr) } -pub fn attribute_to_str(attr: &ast::Attribute, intr: @ident_interner) -> ~str { +pub fn attribute_to_str(attr: &ast::Attribute, intr: @IdentInterner) -> ~str { to_str(attr, print_attribute, intr) } -pub fn variant_to_str(var: &ast::variant, intr: @ident_interner) -> ~str { +pub fn variant_to_str(var: &ast::Variant, intr: @IdentInterner) -> ~str { to_str(var, print_variant, intr) } -pub fn cbox(s: &mut ps, u: uint) { +pub fn cbox(s: &mut State, u: uint) { { let mut boxes = s.boxes.borrow_mut(); - boxes.get().push(pp::consistent); + boxes.get().push(pp::Consistent); } pp::cbox(&mut s.s, u); } // "raw box" -pub fn rbox(s: &mut ps, u: uint, b: pp::breaks) { +pub fn rbox(s: &mut State, u: uint, b: pp::Breaks) { { let mut boxes = s.boxes.borrow_mut(); boxes.get().push(b); @@ -265,17 +255,17 @@ pub fn rbox(s: &mut ps, u: uint, b: pp::breaks) { pp::rbox(&mut s.s, u, b); } -pub fn nbsp(s: &mut ps) { word(&mut s.s, " "); } +pub fn nbsp(s: &mut State) { word(&mut s.s, " "); } -pub fn word_nbsp(s: &mut ps, w: &str) { word(&mut s.s, w); nbsp(s); } +pub fn word_nbsp(s: &mut State, w: &str) { word(&mut s.s, w); nbsp(s); } -pub fn word_space(s: &mut ps, w: &str) { word(&mut s.s, w); space(&mut s.s); } +pub fn word_space(s: &mut State, w: &str) { word(&mut s.s, w); space(&mut s.s); } -pub fn popen(s: &mut ps) { word(&mut s.s, "("); } +pub fn popen(s: &mut State) { word(&mut s.s, "("); } -pub fn pclose(s: &mut ps) { word(&mut s.s, ")"); } +pub fn pclose(s: &mut State) { word(&mut s.s, ")"); } -pub fn head(s: &mut ps, w: &str) { +pub fn head(s: &mut State, w: &str) { // outer-box is consistent cbox(s, indent_unit); // head-box is inconsistent @@ -286,16 +276,16 @@ pub fn head(s: &mut ps, w: &str) { } } -pub fn bopen(s: &mut ps) { +pub fn bopen(s: &mut State) { word(&mut s.s, "{"); end(s); // close the head-box } -pub fn bclose_(s: &mut ps, span: codemap::Span, indented: uint) { +pub fn bclose_(s: &mut State, span: codemap::Span, indented: uint) { bclose_maybe_open(s, span, indented, true); } -pub fn bclose_maybe_open (s: &mut ps, span: codemap::Span, indented: uint, - close_box: bool) { +pub fn bclose_maybe_open (s: &mut State, span: codemap::Span, + indented: uint, close_box: bool) { maybe_print_comment(s, span.hi); break_offset_if_not_bol(s, 1u, -(indented as int)); word(&mut s.s, "}"); @@ -303,34 +293,36 @@ pub fn bclose_maybe_open (s: &mut ps, span: codemap::Span, indented: uint, end(s); // close the outer-box } } -pub fn bclose(s: &mut ps, span: codemap::Span) { bclose_(s, span, indent_unit); } +pub fn bclose(s: &mut State, span: codemap::Span) { + bclose_(s, span, indent_unit); +} -pub fn is_begin(s: &mut ps) -> bool { - match s.s.last_token() { pp::BEGIN(_) => true, _ => false } +pub fn is_begin(s: &mut State) -> bool { + match s.s.last_token() { pp::Begin(_) => true, _ => false } } -pub fn is_end(s: &mut ps) -> bool { - match s.s.last_token() { pp::END => true, _ => false } +pub fn is_end(s: &mut State) -> bool { + match s.s.last_token() { pp::End => true, _ => false } } -pub fn is_bol(s: &mut ps) -> bool { +pub fn is_bol(s: &mut State) -> bool { return s.s.last_token().is_eof() || s.s.last_token().is_hardbreak_tok(); } -pub fn in_cbox(s: &mut ps) -> bool { +pub fn in_cbox(s: &mut State) -> bool { let boxes = s.boxes.borrow(); let len = boxes.get().len(); if len == 0u { return false; } - return boxes.get()[len - 1u] == pp::consistent; + return boxes.get()[len - 1u] == pp::Consistent; } -pub fn hardbreak_if_not_bol(s: &mut ps) { +pub fn hardbreak_if_not_bol(s: &mut State) { if !is_bol(s) { hardbreak(&mut s.s) } } -pub fn space_if_not_bol(s: &mut ps) { if !is_bol(s) { space(&mut s.s); } } -pub fn break_offset_if_not_bol(s: &mut ps, n: uint, off: int) { +pub fn space_if_not_bol(s: &mut State) { if !is_bol(s) { space(&mut s.s); } } +pub fn break_offset_if_not_bol(s: &mut State, n: uint, off: int) { if !is_bol(s) { break_offset(&mut s.s, n, off); } else { @@ -345,7 +337,7 @@ pub fn break_offset_if_not_bol(s: &mut ps, n: uint, off: int) { // Synthesizes a comment that was not textually present in the original source // file. -pub fn synth_comment(s: &mut ps, text: ~str) { +pub fn synth_comment(s: &mut State, text: ~str) { word(&mut s.s, "/*"); space(&mut s.s); word(&mut s.s, text); @@ -353,7 +345,7 @@ pub fn synth_comment(s: &mut ps, text: ~str) { word(&mut s.s, "*/"); } -pub fn commasep<T>(s: &mut ps, b: breaks, elts: &[T], op: |&mut ps, &T|) { +pub fn commasep<T>(s: &mut State, b: Breaks, elts: &[T], op: |&mut State, &T|) { rbox(s, 0u, b); let mut first = true; for elt in elts.iter() { @@ -365,10 +357,10 @@ pub fn commasep<T>(s: &mut ps, b: breaks, elts: &[T], op: |&mut ps, &T|) { pub fn commasep_cmnt<T>( - s: &mut ps, - b: breaks, + s: &mut State, + b: Breaks, elts: &[T], - op: |&mut ps, &T|, + op: |&mut State, &T|, get_span: |&T| -> codemap::Span) { rbox(s, 0u, b); let len = elts.len(); @@ -387,11 +379,11 @@ pub fn commasep_cmnt<T>( end(s); } -pub fn commasep_exprs(s: &mut ps, b: breaks, exprs: &[@ast::Expr]) { +pub fn commasep_exprs(s: &mut State, b: Breaks, exprs: &[@ast::Expr]) { commasep_cmnt(s, b, exprs, |p, &e| print_expr(p, e), |e| e.span); } -pub fn print_mod(s: &mut ps, _mod: &ast::_mod, attrs: &[ast::Attribute]) { +pub fn print_mod(s: &mut State, _mod: &ast::Mod, attrs: &[ast::Attribute]) { print_inner_attributes(s, attrs); for vitem in _mod.view_items.iter() { print_view_item(s, vitem); @@ -399,7 +391,7 @@ pub fn print_mod(s: &mut ps, _mod: &ast::_mod, attrs: &[ast::Attribute]) { for item in _mod.items.iter() { print_item(s, *item); } } -pub fn print_foreign_mod(s: &mut ps, nmod: &ast::foreign_mod, +pub fn print_foreign_mod(s: &mut State, nmod: &ast::ForeignMod, attrs: &[ast::Attribute]) { print_inner_attributes(s, attrs); for vitem in nmod.view_items.iter() { @@ -408,96 +400,95 @@ pub fn print_foreign_mod(s: &mut ps, nmod: &ast::foreign_mod, for item in nmod.items.iter() { print_foreign_item(s, *item); } } -pub fn print_opt_lifetime(s: &mut ps, lifetime: &Option<ast::Lifetime>) { +pub fn print_opt_lifetime(s: &mut State, lifetime: &Option<ast::Lifetime>) { for l in lifetime.iter() { print_lifetime(s, l); nbsp(s); } } -pub fn print_type(s: &mut ps, ty: &ast::Ty) { +pub fn print_type(s: &mut State, ty: &ast::Ty) { maybe_print_comment(s, ty.span.lo); ibox(s, 0u); match ty.node { - ast::ty_nil => word(&mut s.s, "()"), - ast::ty_bot => word(&mut s.s, "!"), - ast::ty_box(ty) => { word(&mut s.s, "@"); print_type(s, ty); } - ast::ty_uniq(ty) => { word(&mut s.s, "~"); print_type(s, ty); } - ast::ty_vec(ty) => { - word(&mut s.s, "["); - print_type(s, ty); - word(&mut s.s, "]"); - } - ast::ty_ptr(ref mt) => { word(&mut s.s, "*"); print_mt(s, mt); } - ast::ty_rptr(ref lifetime, ref mt) => { - word(&mut s.s, "&"); - print_opt_lifetime(s, lifetime); - print_mt(s, mt); - } - ast::ty_tup(ref elts) => { - popen(s); - commasep(s, inconsistent, *elts, print_type_ref); - if elts.len() == 1 { - word(&mut s.s, ","); + ast::TyNil => word(&mut s.s, "()"), + ast::TyBot => word(&mut s.s, "!"), + ast::TyBox(ty) => { word(&mut s.s, "@"); print_type(s, ty); } + ast::TyUniq(ty) => { word(&mut s.s, "~"); print_type(s, ty); } + ast::TyVec(ty) => { + word(&mut s.s, "["); + print_type(s, ty); + word(&mut s.s, "]"); + } + ast::TyPtr(ref mt) => { word(&mut s.s, "*"); print_mt(s, mt); } + ast::TyRptr(ref lifetime, ref mt) => { + word(&mut s.s, "&"); + print_opt_lifetime(s, lifetime); + print_mt(s, mt); + } + ast::TyTup(ref elts) => { + popen(s); + commasep(s, Inconsistent, *elts, print_type_ref); + if elts.len() == 1 { + word(&mut s.s, ","); + } + pclose(s); + } + ast::TyBareFn(f) => { + let generics = ast::Generics { + lifetimes: f.lifetimes.clone(), + ty_params: opt_vec::Empty + }; + print_ty_fn(s, Some(f.abis), None, &None, + f.purity, ast::Many, f.decl, None, &None, + Some(&generics), None); + } + ast::TyClosure(f) => { + let generics = ast::Generics { + lifetimes: f.lifetimes.clone(), + ty_params: opt_vec::Empty + }; + print_ty_fn(s, None, Some(f.sigil), &f.region, + f.purity, f.onceness, f.decl, None, &f.bounds, + Some(&generics), None); + } + ast::TyPath(ref path, ref bounds, _) => print_bounded_path(s, path, bounds), + ast::TyFixedLengthVec(ty, v) => { + word(&mut s.s, "["); + print_type(s, ty); + word(&mut s.s, ", .."); + print_expr(s, v); + word(&mut s.s, "]"); + } + ast::TyTypeof(e) => { + word(&mut s.s, "typeof("); + print_expr(s, e); + word(&mut s.s, ")"); + } + ast::TyInfer => { + fail!("print_type shouldn't see a ty_infer"); } - pclose(s); - } - ast::ty_bare_fn(f) => { - let generics = ast::Generics { - lifetimes: f.lifetimes.clone(), - ty_params: opt_vec::Empty - }; - print_ty_fn(s, Some(f.abis), None, &None, - f.purity, ast::Many, f.decl, None, &None, - Some(&generics), None); - } - ast::ty_closure(f) => { - let generics = ast::Generics { - lifetimes: f.lifetimes.clone(), - ty_params: opt_vec::Empty - }; - print_ty_fn(s, None, Some(f.sigil), &f.region, - f.purity, f.onceness, f.decl, None, &f.bounds, - Some(&generics), None); - } - ast::ty_path(ref path, ref bounds, _) => print_bounded_path(s, path, bounds), - ast::ty_fixed_length_vec(ty, v) => { - word(&mut s.s, "["); - print_type(s, ty); - word(&mut s.s, ", .."); - print_expr(s, v); - word(&mut s.s, "]"); - } - ast::ty_typeof(e) => { - word(&mut s.s, "typeof("); - print_expr(s, e); - word(&mut s.s, ")"); - } - ast::ty_infer => { - fail!("print_type shouldn't see a ty_infer"); - } - } end(s); } -pub fn print_type_ref(s: &mut ps, ty: &P<ast::Ty>) { +pub fn print_type_ref(s: &mut State, ty: &P<ast::Ty>) { print_type(s, *ty); } -pub fn print_foreign_item(s: &mut ps, item: &ast::foreign_item) { +pub fn print_foreign_item(s: &mut State, item: &ast::ForeignItem) { hardbreak_if_not_bol(s); maybe_print_comment(s, item.span.lo); print_outer_attributes(s, item.attrs); match item.node { - ast::foreign_item_fn(decl, ref generics) => { + ast::ForeignItemFn(decl, ref generics) => { print_fn(s, decl, None, AbiSet::Rust(), item.ident, generics, None, item.vis); end(s); // end head-ibox word(&mut s.s, ";"); end(s); // end the outer fn box } - ast::foreign_item_static(t, m) => { + ast::ForeignItemStatic(t, m) => { head(s, visibility_qualified(item.vis, "static")); if m { word_space(s, "mut"); @@ -512,16 +503,16 @@ pub fn print_foreign_item(s: &mut ps, item: &ast::foreign_item) { } } -pub fn print_item(s: &mut ps, item: &ast::item) { +pub fn print_item(s: &mut State, item: &ast::Item) { hardbreak_if_not_bol(s); maybe_print_comment(s, item.span.lo); print_outer_attributes(s, item.attrs); { - let ann_node = node_item(s, item); + let ann_node = NodeItem(s, item); s.ann.pre(ann_node); } match item.node { - ast::item_static(ty, m, expr) => { + ast::ItemStatic(ty, m, expr) => { head(s, visibility_qualified(item.vis, "static")); if m == ast::MutMutable { word_space(s, "mut"); @@ -538,7 +529,7 @@ pub fn print_item(s: &mut ps, item: &ast::item) { end(s); // end the outer cbox } - ast::item_fn(decl, purity, abi, ref typarams, body) => { + ast::ItemFn(decl, purity, abi, ref typarams, body) => { print_fn( s, decl, @@ -552,7 +543,7 @@ pub fn print_item(s: &mut ps, item: &ast::item) { word(&mut s.s, " "); print_block_with_attrs(s, body, item.attrs); } - ast::item_mod(ref _mod) => { + ast::ItemMod(ref _mod) => { head(s, visibility_qualified(item.vis, "mod")); print_ident(s, item.ident); nbsp(s); @@ -560,14 +551,14 @@ pub fn print_item(s: &mut ps, item: &ast::item) { print_mod(s, _mod, item.attrs); bclose(s, item.span); } - ast::item_foreign_mod(ref nmod) => { + ast::ItemForeignMod(ref nmod) => { head(s, "extern"); word_nbsp(s, nmod.abis.to_str()); bopen(s); print_foreign_mod(s, nmod, item.attrs); bclose(s, item.span); } - ast::item_ty(ty, ref params) => { + ast::ItemTy(ty, ref params) => { ibox(s, indent_unit); ibox(s, 0u); word_nbsp(s, visibility_qualified(item.vis, "type")); @@ -581,7 +572,7 @@ pub fn print_item(s: &mut ps, item: &ast::item) { word(&mut s.s, ";"); end(s); // end the outer ibox } - ast::item_enum(ref enum_definition, ref params) => { + ast::ItemEnum(ref enum_definition, ref params) => { print_enum_def( s, enum_definition, @@ -591,12 +582,12 @@ pub fn print_item(s: &mut ps, item: &ast::item) { item.vis ); } - ast::item_struct(struct_def, ref generics) => { + ast::ItemStruct(struct_def, ref generics) => { head(s, visibility_qualified(item.vis, "struct")); print_struct(s, struct_def, generics, item.ident, item.span); } - ast::item_impl(ref generics, ref opt_trait, ty, ref methods) => { + ast::ItemImpl(ref generics, ref opt_trait, ty, ref methods) => { head(s, visibility_qualified(item.vis, "impl")); if generics.is_parameterized() { print_generics(s, generics); @@ -622,7 +613,7 @@ pub fn print_item(s: &mut ps, item: &ast::item) { } bclose(s, item.span); } - ast::item_trait(ref generics, ref traits, ref methods) => { + ast::ItemTrait(ref generics, ref traits, ref methods) => { head(s, visibility_qualified(item.vis, "trait")); print_ident(s, item.ident); print_generics(s, generics); @@ -644,7 +635,7 @@ pub fn print_item(s: &mut ps, item: &ast::item) { bclose(s, item.span); } // I think it's reasonable to hide the context here: - ast::item_mac(codemap::Spanned { node: ast::mac_invoc_tt(ref pth, ref tts, _), + ast::ItemMac(codemap::Spanned { node: ast::MacInvocTT(ref pth, ref tts, _), ..}) => { print_visibility(s, item.vis); print_path(s, pth, false); @@ -658,18 +649,18 @@ pub fn print_item(s: &mut ps, item: &ast::item) { } } { - let ann_node = node_item(s, item); + let ann_node = NodeItem(s, item); s.ann.post(ann_node); } } -fn print_trait_ref(s: &mut ps, t: &ast::trait_ref) { +fn print_trait_ref(s: &mut State, t: &ast::TraitRef) { print_path(s, &t.path, false); } -pub fn print_enum_def(s: &mut ps, enum_definition: &ast::enum_def, +pub fn print_enum_def(s: &mut State, enum_definition: &ast::EnumDef, generics: &ast::Generics, ident: ast::Ident, - span: codemap::Span, visibility: ast::visibility) { + span: codemap::Span, visibility: ast::Visibility) { head(s, visibility_qualified(visibility, "enum")); print_ident(s, ident); print_generics(s, generics); @@ -677,8 +668,8 @@ pub fn print_enum_def(s: &mut ps, enum_definition: &ast::enum_def, print_variants(s, enum_definition.variants, span); } -pub fn print_variants(s: &mut ps, - variants: &[P<ast::variant>], +pub fn print_variants(s: &mut State, + variants: &[P<ast::Variant>], span: codemap::Span) { bopen(s); for &v in variants.iter() { @@ -694,31 +685,31 @@ pub fn print_variants(s: &mut ps, bclose(s, span); } -pub fn visibility_to_str(vis: ast::visibility) -> ~str { +pub fn visibility_to_str(vis: ast::Visibility) -> ~str { match vis { - ast::private => ~"priv", - ast::public => ~"pub", - ast::inherited => ~"" + ast::Private => ~"priv", + ast::Public => ~"pub", + ast::Inherited => ~"" } } -pub fn visibility_qualified(vis: ast::visibility, s: &str) -> ~str { +pub fn visibility_qualified(vis: ast::Visibility, s: &str) -> ~str { match vis { - ast::private | ast::public => visibility_to_str(vis) + " " + s, - ast::inherited => s.to_owned() + ast::Private | ast::Public => visibility_to_str(vis) + " " + s, + ast::Inherited => s.to_owned() } } -pub fn print_visibility(s: &mut ps, vis: ast::visibility) { +pub fn print_visibility(s: &mut State, vis: ast::Visibility) { match vis { - ast::private | ast::public => + ast::Private | ast::Public => word_nbsp(s, visibility_to_str(vis)), - ast::inherited => () + ast::Inherited => () } } -pub fn print_struct(s: &mut ps, - struct_def: &ast::struct_def, +pub fn print_struct(s: &mut State, + struct_def: &ast::StructDef, generics: &ast::Generics, ident: ast::Ident, span: codemap::Span) { @@ -727,10 +718,10 @@ pub fn print_struct(s: &mut ps, if ast_util::struct_def_is_tuple_like(struct_def) { if !struct_def.fields.is_empty() { popen(s); - commasep(s, inconsistent, struct_def.fields, |s, field| { + commasep(s, Inconsistent, struct_def.fields, |s, field| { match field.node.kind { - ast::named_field(..) => fail!("unexpected named field"), - ast::unnamed_field => { + ast::NamedField(..) => fail!("unexpected named field"), + ast::UnnamedField => { maybe_print_comment(s, field.span.lo); print_type(s, field.node.ty); } @@ -748,8 +739,8 @@ pub fn print_struct(s: &mut ps, for field in struct_def.fields.iter() { match field.node.kind { - ast::unnamed_field => fail!("unexpected unnamed field"), - ast::named_field(ident, visibility) => { + ast::UnnamedField => fail!("unexpected unnamed field"), + ast::NamedField(ident, visibility) => { hardbreak_if_not_bol(s); maybe_print_comment(s, field.span.lo); print_outer_attributes(s, field.node.attrs); @@ -773,13 +764,13 @@ pub fn print_struct(s: &mut ps, /// appropriate macro, transcribe back into the grammar we just parsed from, /// and then pretty-print the resulting AST nodes (so, e.g., we print /// expression arguments as expressions). It can be done! I think. -pub fn print_tt(s: &mut ps, tt: &ast::token_tree) { +pub fn print_tt(s: &mut State, tt: &ast::TokenTree) { match *tt { - ast::tt_delim(ref tts) => print_tts(s, &(tts.as_slice())), - ast::tt_tok(_, ref tk) => { + ast::TTDelim(ref tts) => print_tts(s, &(tts.as_slice())), + ast::TTTok(_, ref tk) => { word(&mut s.s, parse::token::to_str(s.intr, tk)); } - ast::tt_seq(_, ref tts, ref sep, zerok) => { + ast::TTSeq(_, ref tts, ref sep, zerok) => { word(&mut s.s, "$("); for tt_elt in (*tts).iter() { print_tt(s, tt_elt); } word(&mut s.s, ")"); @@ -789,14 +780,14 @@ pub fn print_tt(s: &mut ps, tt: &ast::token_tree) { } word(&mut s.s, if zerok { "*" } else { "+" }); } - ast::tt_nonterminal(_, name) => { + ast::TTNonterminal(_, name) => { word(&mut s.s, "$"); print_ident(s, name); } } } -pub fn print_tts(s: &mut ps, tts: & &[ast::token_tree]) { +pub fn print_tts(s: &mut State, tts: & &[ast::TokenTree]) { ibox(s, 0); for (i, tt) in tts.iter().enumerate() { if i != 0 { @@ -807,21 +798,21 @@ pub fn print_tts(s: &mut ps, tts: & &[ast::token_tree]) { end(s); } -pub fn print_variant(s: &mut ps, v: &ast::variant) { +pub fn print_variant(s: &mut State, v: &ast::Variant) { print_visibility(s, v.node.vis); match v.node.kind { - ast::tuple_variant_kind(ref args) => { + ast::TupleVariantKind(ref args) => { print_ident(s, v.node.name); if !args.is_empty() { popen(s); - fn print_variant_arg(s: &mut ps, arg: &ast::variant_arg) { + fn print_variant_arg(s: &mut State, arg: &ast::VariantArg) { print_type(s, arg.ty); } - commasep(s, consistent, *args, print_variant_arg); + commasep(s, Consistent, *args, print_variant_arg); pclose(s); } } - ast::struct_variant_kind(struct_def) => { + ast::StructVariantKind(struct_def) => { head(s, ""); let generics = ast_util::empty_generics(); print_struct(s, struct_def, &generics, v.node.name, v.span); @@ -837,7 +828,7 @@ pub fn print_variant(s: &mut ps, v: &ast::variant) { } } -pub fn print_ty_method(s: &mut ps, m: &ast::TypeMethod) { +pub fn print_ty_method(s: &mut State, m: &ast::TypeMethod) { hardbreak_if_not_bol(s); maybe_print_comment(s, m.span.lo); print_outer_attributes(s, m.attrs); @@ -855,14 +846,14 @@ pub fn print_ty_method(s: &mut ps, m: &ast::TypeMethod) { word(&mut s.s, ";"); } -pub fn print_trait_method(s: &mut ps, m: &ast::trait_method) { +pub fn print_trait_method(s: &mut State, m: &ast::TraitMethod) { match *m { - required(ref ty_m) => print_ty_method(s, ty_m), - provided(m) => print_method(s, m) + Required(ref ty_m) => print_ty_method(s, ty_m), + Provided(m) => print_method(s, m) } } -pub fn print_method(s: &mut ps, meth: &ast::method) { +pub fn print_method(s: &mut State, meth: &ast::Method) { hardbreak_if_not_bol(s); maybe_print_comment(s, meth.span.lo); print_outer_attributes(s, meth.attrs); @@ -873,7 +864,7 @@ pub fn print_method(s: &mut ps, meth: &ast::method) { print_block_with_attrs(s, meth.body, meth.attrs); } -pub fn print_outer_attributes(s: &mut ps, attrs: &[ast::Attribute]) { +pub fn print_outer_attributes(s: &mut State, attrs: &[ast::Attribute]) { let mut count = 0; for attr in attrs.iter() { match attr.node.style { @@ -884,7 +875,7 @@ pub fn print_outer_attributes(s: &mut ps, attrs: &[ast::Attribute]) { if count > 0 { hardbreak_if_not_bol(s); } } -pub fn print_inner_attributes(s: &mut ps, attrs: &[ast::Attribute]) { +pub fn print_inner_attributes(s: &mut State, attrs: &[ast::Attribute]) { let mut count = 0; for attr in attrs.iter() { match attr.node.style { @@ -901,7 +892,7 @@ pub fn print_inner_attributes(s: &mut ps, attrs: &[ast::Attribute]) { if count > 0 { hardbreak_if_not_bol(s); } } -pub fn print_attribute(s: &mut ps, attr: &ast::Attribute) { +pub fn print_attribute(s: &mut State, attr: &ast::Attribute) { hardbreak_if_not_bol(s); maybe_print_comment(s, attr.span.lo); if attr.node.is_sugared_doc { @@ -915,7 +906,7 @@ pub fn print_attribute(s: &mut ps, attr: &ast::Attribute) { } -pub fn print_stmt(s: &mut ps, st: &ast::Stmt) { +pub fn print_stmt(s: &mut State, st: &ast::Stmt) { maybe_print_comment(s, st.span.lo); match st.node { ast::StmtDecl(decl, _) => { @@ -940,40 +931,42 @@ pub fn print_stmt(s: &mut ps, st: &ast::Stmt) { maybe_print_trailing_comment(s, st.span, None); } -pub fn print_block(s: &mut ps, blk: &ast::Block) { - print_possibly_embedded_block(s, blk, block_normal, indent_unit); +pub fn print_block(s: &mut State, blk: &ast::Block) { + print_possibly_embedded_block(s, blk, BlockNormal, indent_unit); } -pub fn print_block_unclosed(s: &mut ps, blk: &ast::Block) { - print_possibly_embedded_block_(s, blk, block_normal, indent_unit, &[], +pub fn print_block_unclosed(s: &mut State, blk: &ast::Block) { + print_possibly_embedded_block_(s, blk, BlockNormal, indent_unit, &[], false); } -pub fn print_block_unclosed_indent(s: &mut ps, blk: &ast::Block, indented: uint) { - print_possibly_embedded_block_(s, blk, block_normal, indented, &[], - false); +pub fn print_block_unclosed_indent(s: &mut State, blk: &ast::Block, indented: uint) { + print_possibly_embedded_block_(s, blk, BlockNormal, indented, &[], false); } -pub fn print_block_with_attrs(s: &mut ps, +pub fn print_block_with_attrs(s: &mut State, blk: &ast::Block, attrs: &[ast::Attribute]) { - print_possibly_embedded_block_(s, blk, block_normal, indent_unit, attrs, + print_possibly_embedded_block_(s, blk, BlockNormal, indent_unit, attrs, true); } -pub enum embed_type { block_block_fn, block_normal, } +enum EmbedType { + BlockBlockFn, + BlockNormal, +} -pub fn print_possibly_embedded_block(s: &mut ps, +pub fn print_possibly_embedded_block(s: &mut State, blk: &ast::Block, - embedded: embed_type, + embedded: EmbedType, indented: uint) { print_possibly_embedded_block_( s, blk, embedded, indented, &[], true); } -pub fn print_possibly_embedded_block_(s: &mut ps, +pub fn print_possibly_embedded_block_(s: &mut State, blk: &ast::Block, - embedded: embed_type, + embedded: EmbedType, indented: uint, attrs: &[ast::Attribute], close_box: bool) { @@ -983,12 +976,12 @@ pub fn print_possibly_embedded_block_(s: &mut ps, } maybe_print_comment(s, blk.span.lo); { - let ann_node = node_block(s, blk); + let ann_node = NodeBlock(s, blk); s.ann.pre(ann_node); } match embedded { - block_block_fn => end(s), - block_normal => bopen(s) + BlockBlockFn => end(s), + BlockNormal => bopen(s) } print_inner_attributes(s, attrs); @@ -1007,19 +1000,19 @@ pub fn print_possibly_embedded_block_(s: &mut ps, } bclose_maybe_open(s, blk.span, indented, close_box); { - let ann_node = node_block(s, blk); + let ann_node = NodeBlock(s, blk); s.ann.post(ann_node); } } -pub fn print_if(s: &mut ps, test: &ast::Expr, blk: &ast::Block, +pub fn print_if(s: &mut State, test: &ast::Expr, blk: &ast::Block, elseopt: Option<@ast::Expr>, chk: bool) { head(s, "if"); if chk { word_nbsp(s, "check"); } print_expr(s, test); space(&mut s.s); print_block(s, blk); - fn do_else(s: &mut ps, els: Option<@ast::Expr>) { + fn do_else(s: &mut State, els: Option<@ast::Expr>) { match els { Some(_else) => { match _else.node { @@ -1052,10 +1045,10 @@ pub fn print_if(s: &mut ps, test: &ast::Expr, blk: &ast::Block, do_else(s, elseopt); } -pub fn print_mac(s: &mut ps, m: &ast::mac) { +pub fn print_mac(s: &mut State, m: &ast::Mac) { match m.node { // I think it's reasonable to hide the ctxt here: - ast::mac_invoc_tt(ref pth, ref tts, _) => { + ast::MacInvocTT(ref pth, ref tts, _) => { print_path(s, pth, false); word(&mut s.s, "!"); popen(s); @@ -1065,7 +1058,7 @@ pub fn print_mac(s: &mut ps, m: &ast::mac) { } } -pub fn print_vstore(s: &mut ps, t: ast::Vstore) { +pub fn print_vstore(s: &mut State, t: ast::Vstore) { match t { ast::VstoreFixed(Some(i)) => word(&mut s.s, format!("{}", i)), ast::VstoreFixed(None) => word(&mut s.s, "_"), @@ -1078,7 +1071,7 @@ pub fn print_vstore(s: &mut ps, t: ast::Vstore) { } } -pub fn print_expr_vstore(s: &mut ps, t: ast::ExprVstore) { +pub fn print_expr_vstore(s: &mut State, t: ast::ExprVstore) { match t { ast::ExprVstoreUniq => word(&mut s.s, "~"), ast::ExprVstoreBox => word(&mut s.s, "@"), @@ -1090,7 +1083,7 @@ pub fn print_expr_vstore(s: &mut ps, t: ast::ExprVstore) { } } -pub fn print_call_pre(s: &mut ps, +pub fn print_call_pre(s: &mut State, sugar: ast::CallSugar, base_args: &mut ~[@ast::Expr]) -> Option<@ast::Expr> { @@ -1107,13 +1100,13 @@ pub fn print_call_pre(s: &mut ps, } } -pub fn print_call_post(s: &mut ps, +pub fn print_call_post(s: &mut State, sugar: ast::CallSugar, blk: &Option<@ast::Expr>, base_args: &mut ~[@ast::Expr]) { if sugar == ast::NoSugar || !base_args.is_empty() { popen(s); - commasep_exprs(s, inconsistent, *base_args); + commasep_exprs(s, Inconsistent, *base_args); pclose(s); } if sugar != ast::NoSugar { @@ -1134,8 +1127,8 @@ pub fn print_call_post(s: &mut ps, } } -pub fn print_expr(s: &mut ps, expr: &ast::Expr) { - fn print_field(s: &mut ps, field: &ast::Field) { +pub fn print_expr(s: &mut State, expr: &ast::Expr) { + fn print_field(s: &mut State, field: &ast::Field) { ibox(s, indent_unit); print_ident(s, field.ident.node); word_space(s, ":"); @@ -1147,7 +1140,7 @@ pub fn print_expr(s: &mut ps, expr: &ast::Expr) { maybe_print_comment(s, expr.span.lo); ibox(s, indent_unit); { - let ann_node = node_expr(s, expr); + let ann_node = NodeExpr(s, expr); s.ann.pre(ann_node); } match expr.node { @@ -1162,7 +1155,7 @@ pub fn print_expr(s: &mut ps, expr: &ast::Expr) { word(&mut s.s, "mut"); if exprs.len() > 0u { nbsp(s); } } - commasep_exprs(s, inconsistent, *exprs); + commasep_exprs(s, Inconsistent, *exprs); word(&mut s.s, "]"); end(s); } @@ -1185,7 +1178,7 @@ pub fn print_expr(s: &mut ps, expr: &ast::Expr) { ast::ExprStruct(ref path, ref fields, wth) => { print_path(s, path, true); word(&mut s.s, "{"); - commasep_cmnt(s, consistent, (*fields), print_field, get_span); + commasep_cmnt(s, Consistent, (*fields), print_field, get_span); match wth { Some(expr) => { ibox(s, indent_unit); @@ -1201,7 +1194,7 @@ pub fn print_expr(s: &mut ps, expr: &ast::Expr) { } ast::ExprTup(ref exprs) => { popen(s); - commasep_exprs(s, inconsistent, *exprs); + commasep_exprs(s, Inconsistent, *exprs); if exprs.len() == 1 { word(&mut s.s, ","); } @@ -1221,7 +1214,7 @@ pub fn print_expr(s: &mut ps, expr: &ast::Expr) { print_ident(s, ident); if tys.len() > 0u { word(&mut s.s, "::<"); - commasep(s, inconsistent, *tys, print_type_ref); + commasep(s, Inconsistent, *tys, print_type_ref); word(&mut s.s, ">"); } print_call_post(s, sugar, &blk, &mut base_args); @@ -1434,7 +1427,7 @@ pub fn print_expr(s: &mut ps, expr: &ast::Expr) { print_ident(s, id); if tys.len() > 0u { word(&mut s.s, "::<"); - commasep(s, inconsistent, *tys, print_type_ref); + commasep(s, Inconsistent, *tys, print_type_ref); word(&mut s.s, ">"); } } @@ -1512,21 +1505,21 @@ pub fn print_expr(s: &mut ps, expr: &ast::Expr) { } } { - let ann_node = node_expr(s, expr); + let ann_node = NodeExpr(s, expr); s.ann.post(ann_node); } end(s); } -pub fn print_local_decl(s: &mut ps, loc: &ast::Local) { +pub fn print_local_decl(s: &mut State, loc: &ast::Local) { print_pat(s, loc.pat); match loc.ty.node { - ast::ty_infer => (), - _ => { word_space(s, ":"); print_type(s, loc.ty); } + ast::TyInfer => {} + _ => { word_space(s, ":"); print_type(s, loc.ty); } } } -pub fn print_decl(s: &mut ps, decl: &ast::Decl) { +pub fn print_decl(s: &mut State, decl: &ast::Decl) { maybe_print_comment(s, decl.span.lo); match decl.node { ast::DeclLocal(ref loc) => { @@ -1534,7 +1527,7 @@ pub fn print_decl(s: &mut ps, decl: &ast::Decl) { ibox(s, indent_unit); word_nbsp(s, "let"); - fn print_local(s: &mut ps, loc: &ast::Local) { + fn print_local(s: &mut State, loc: &ast::Local) { ibox(s, indent_unit); print_local_decl(s, loc); end(s); @@ -1555,22 +1548,22 @@ pub fn print_decl(s: &mut ps, decl: &ast::Decl) { } } -pub fn print_ident(s: &mut ps, ident: ast::Ident) { +pub fn print_ident(s: &mut State, ident: ast::Ident) { word(&mut s.s, ident_to_str(&ident)); } -pub fn print_name(s: &mut ps, name: ast::Name) { +pub fn print_name(s: &mut State, name: ast::Name) { word(&mut s.s, interner_get(name)); } -pub fn print_for_decl(s: &mut ps, loc: &ast::Local, coll: &ast::Expr) { +pub fn print_for_decl(s: &mut State, loc: &ast::Local, coll: &ast::Expr) { print_local_decl(s, loc); space(&mut s.s); word_space(s, "in"); print_expr(s, coll); } -fn print_path_(s: &mut ps, +fn print_path_(s: &mut State, path: &ast::Path, colons_before_params: bool, opt_bounds: &Option<OptVec<ast::TyParamBound>>) { @@ -1617,7 +1610,7 @@ fn print_path_(s: &mut ps, word_space(s, ",") } commasep(s, - inconsistent, + Inconsistent, segment.types.map_to_vec(|&t| t), print_type_ref); } @@ -1627,19 +1620,19 @@ fn print_path_(s: &mut ps, } } -pub fn print_path(s: &mut ps, path: &ast::Path, colons_before_params: bool) { +pub fn print_path(s: &mut State, path: &ast::Path, colons_before_params: bool) { print_path_(s, path, colons_before_params, &None) } -pub fn print_bounded_path(s: &mut ps, path: &ast::Path, +pub fn print_bounded_path(s: &mut State, path: &ast::Path, bounds: &Option<OptVec<ast::TyParamBound>>) { print_path_(s, path, false, bounds) } -pub fn print_pat(s: &mut ps, pat: &ast::Pat) { +pub fn print_pat(s: &mut State, pat: &ast::Pat) { maybe_print_comment(s, pat.span.lo); { - let ann_node = node_pat(s, pat); + let ann_node = NodePat(s, pat); s.ann.pre(ann_node); } /* Pat isn't normalized, but the beauty of it @@ -1674,7 +1667,7 @@ pub fn print_pat(s: &mut ps, pat: &ast::Pat) { Some(ref args) => { if !args.is_empty() { popen(s); - commasep(s, inconsistent, *args, + commasep(s, Inconsistent, *args, |s, &p| print_pat(s, p)); pclose(s); } else { } @@ -1684,7 +1677,7 @@ pub fn print_pat(s: &mut ps, pat: &ast::Pat) { ast::PatStruct(ref path, ref fields, etc) => { print_path(s, path, true); word(&mut s.s, "{"); - fn print_field(s: &mut ps, f: &ast::FieldPat) { + fn print_field(s: &mut State, f: &ast::FieldPat) { cbox(s, indent_unit); print_ident(s, f.ident); word_space(s, ":"); @@ -1692,7 +1685,7 @@ pub fn print_pat(s: &mut ps, pat: &ast::Pat) { end(s); } fn get_span(f: &ast::FieldPat) -> codemap::Span { return f.pat.span; } - commasep_cmnt(s, consistent, *fields, + commasep_cmnt(s, Consistent, *fields, |s, f| print_field(s,f), get_span); if etc { @@ -1703,7 +1696,7 @@ pub fn print_pat(s: &mut ps, pat: &ast::Pat) { } ast::PatTup(ref elts) => { popen(s); - commasep(s, inconsistent, *elts, |s, &p| print_pat(s, p)); + commasep(s, Inconsistent, *elts, |s, &p| print_pat(s, p)); if elts.len() == 1 { word(&mut s.s, ","); } @@ -1730,7 +1723,7 @@ pub fn print_pat(s: &mut ps, pat: &ast::Pat) { } ast::PatVec(ref before, slice, ref after) => { word(&mut s.s, "["); - commasep(s, inconsistent, *before, |s, &p| print_pat(s, p)); + commasep(s, Inconsistent, *before, |s, &p| print_pat(s, p)); for &p in slice.iter() { if !before.is_empty() { word_space(s, ","); } match p { @@ -1742,53 +1735,53 @@ pub fn print_pat(s: &mut ps, pat: &ast::Pat) { print_pat(s, p); if !after.is_empty() { word_space(s, ","); } } - commasep(s, inconsistent, *after, |s, &p| print_pat(s, p)); + commasep(s, Inconsistent, *after, |s, &p| print_pat(s, p)); word(&mut s.s, "]"); } } { - let ann_node = node_pat(s, pat); + let ann_node = NodePat(s, pat); s.ann.post(ann_node); } } -pub fn explicit_self_to_str(explicit_self: &ast::explicit_self_, intr: @ident_interner) -> ~str { +pub fn explicit_self_to_str(explicit_self: &ast::ExplicitSelf_, intr: @IdentInterner) -> ~str { to_str(explicit_self, |a, &b| { print_explicit_self(a, b); () }, intr) } // Returns whether it printed anything -pub fn print_explicit_self(s: &mut ps, explicit_self: ast::explicit_self_) -> bool { +pub fn print_explicit_self(s: &mut State, explicit_self: ast::ExplicitSelf_) -> bool { match explicit_self { - ast::sty_static => { return false; } - ast::sty_value(m) => { + ast::SelfStatic => { return false; } + ast::SelfValue(m) => { print_mutability(s, m); word(&mut s.s, "self"); } - ast::sty_uniq(m) => { + ast::SelfUniq(m) => { print_mutability(s, m); word(&mut s.s, "~self"); } - ast::sty_region(ref lt, m) => { + ast::SelfRegion(ref lt, m) => { word(&mut s.s, "&"); print_opt_lifetime(s, lt); print_mutability(s, m); word(&mut s.s, "self"); } - ast::sty_box(m) => { + ast::SelfBox(m) => { word(&mut s.s, "@"); print_mutability(s, m); word(&mut s.s, "self"); } } return true; } -pub fn print_fn(s: &mut ps, - decl: &ast::fn_decl, - purity: Option<ast::purity>, +pub fn print_fn(s: &mut State, + decl: &ast::FnDecl, + purity: Option<ast::Purity>, abis: AbiSet, name: ast::Ident, generics: &ast::Generics, - opt_explicit_self: Option<ast::explicit_self_>, - vis: ast::visibility) { + opt_explicit_self: Option<ast::ExplicitSelf_>, + vis: ast::Visibility) { head(s, ""); print_fn_header_info(s, opt_explicit_self, purity, abis, ast::Many, None, vis); nbsp(s); @@ -1797,11 +1790,11 @@ pub fn print_fn(s: &mut ps, print_fn_args_and_ret(s, decl, opt_explicit_self); } -pub fn print_fn_args(s: &mut ps, decl: &ast::fn_decl, - opt_explicit_self: Option<ast::explicit_self_>) { +pub fn print_fn_args(s: &mut State, decl: &ast::FnDecl, + opt_explicit_self: Option<ast::ExplicitSelf_>) { // It is unfortunate to duplicate the commasep logic, but we want the // self type and the args all in the same box. - rbox(s, 0u, inconsistent); + rbox(s, 0u, Inconsistent); let mut first = true; for explicit_self in opt_explicit_self.iter() { first = !print_explicit_self(s, *explicit_self); @@ -1815,8 +1808,8 @@ pub fn print_fn_args(s: &mut ps, decl: &ast::fn_decl, end(s); } -pub fn print_fn_args_and_ret(s: &mut ps, decl: &ast::fn_decl, - opt_explicit_self: Option<ast::explicit_self_>) { +pub fn print_fn_args_and_ret(s: &mut State, decl: &ast::FnDecl, + opt_explicit_self: Option<ast::ExplicitSelf_>) { popen(s); print_fn_args(s, decl, opt_explicit_self); if decl.variadic { @@ -1826,7 +1819,7 @@ pub fn print_fn_args_and_ret(s: &mut ps, decl: &ast::fn_decl, maybe_print_comment(s, decl.output.span.lo); match decl.output.node { - ast::ty_nil => {} + ast::TyNil => {} _ => { space_if_not_bol(s); word_space(s, "->"); @@ -1835,13 +1828,13 @@ pub fn print_fn_args_and_ret(s: &mut ps, decl: &ast::fn_decl, } } -pub fn print_fn_block_args(s: &mut ps, decl: &ast::fn_decl) { +pub fn print_fn_block_args(s: &mut State, decl: &ast::FnDecl) { word(&mut s.s, "|"); print_fn_args(s, decl, None); word(&mut s.s, "|"); match decl.output.node { - ast::ty_infer => {} + ast::TyInfer => {} _ => { space_if_not_bol(s); word_space(s, "->"); @@ -1852,14 +1845,14 @@ pub fn print_fn_block_args(s: &mut ps, decl: &ast::fn_decl) { maybe_print_comment(s, decl.output.span.lo); } -pub fn print_proc_args(s: &mut ps, decl: &ast::fn_decl) { +pub fn print_proc_args(s: &mut State, decl: &ast::FnDecl) { word(&mut s.s, "proc"); word(&mut s.s, "("); print_fn_args(s, decl, None); word(&mut s.s, ")"); match decl.output.node { - ast::ty_infer => {} + ast::TyInfer => {} _ => { space_if_not_bol(s); word_space(s, "->"); @@ -1870,7 +1863,7 @@ pub fn print_proc_args(s: &mut ps, decl: &ast::fn_decl) { maybe_print_comment(s, decl.output.span.lo); } -pub fn print_bounds(s: &mut ps, bounds: &OptVec<ast::TyParamBound>, +pub fn print_bounds(s: &mut State, bounds: &OptVec<ast::TyParamBound>, print_colon_anyway: bool) { if !bounds.is_empty() { word(&mut s.s, ":"); @@ -1893,16 +1886,16 @@ pub fn print_bounds(s: &mut ps, bounds: &OptVec<ast::TyParamBound>, } } -pub fn print_lifetime(s: &mut ps, lifetime: &ast::Lifetime) { +pub fn print_lifetime(s: &mut State, lifetime: &ast::Lifetime) { word(&mut s.s, "'"); print_ident(s, lifetime.ident); } -pub fn print_generics(s: &mut ps, generics: &ast::Generics) { +pub fn print_generics(s: &mut State, generics: &ast::Generics) { let total = generics.lifetimes.len() + generics.ty_params.len(); if total > 0 { word(&mut s.s, "<"); - fn print_item(s: &mut ps, generics: &ast::Generics, idx: uint) { + fn print_item(s: &mut State, generics: &ast::Generics, idx: uint) { if idx < generics.lifetimes.len() { let lifetime = generics.lifetimes.get(idx); print_lifetime(s, lifetime); @@ -1919,13 +1912,13 @@ pub fn print_generics(s: &mut ps, generics: &ast::Generics) { ints.push(i); } - commasep(s, inconsistent, ints, + commasep(s, Inconsistent, ints, |s, &i| print_item(s, generics, i)); word(&mut s.s, ">"); } } -pub fn print_meta_item(s: &mut ps, item: &ast::MetaItem) { +pub fn print_meta_item(s: &mut State, item: &ast::MetaItem) { ibox(s, indent_unit); match item.node { ast::MetaWord(name) => word(&mut s.s, name), @@ -1938,7 +1931,7 @@ pub fn print_meta_item(s: &mut ps, item: &ast::MetaItem) { word(&mut s.s, name); popen(s); commasep(s, - consistent, + Consistent, items.as_slice(), |p, &i| print_meta_item(p, i)); pclose(s); @@ -1947,9 +1940,9 @@ pub fn print_meta_item(s: &mut ps, item: &ast::MetaItem) { end(s); } -pub fn print_view_path(s: &mut ps, vp: &ast::view_path) { +pub fn print_view_path(s: &mut State, vp: &ast::ViewPath) { match vp.node { - ast::view_path_simple(ident, ref path, _) => { + ast::ViewPathSimple(ident, ref path, _) => { // FIXME(#6993) can't compare identifiers directly here if path.segments.last().identifier.name != ident.name { print_ident(s, ident); @@ -1959,19 +1952,19 @@ pub fn print_view_path(s: &mut ps, vp: &ast::view_path) { print_path(s, path, false); } - ast::view_path_glob(ref path, _) => { + ast::ViewPathGlob(ref path, _) => { print_path(s, path, false); word(&mut s.s, "::*"); } - ast::view_path_list(ref path, ref idents, _) => { + ast::ViewPathList(ref path, ref idents, _) => { if path.segments.is_empty() { word(&mut s.s, "{"); } else { print_path(s, path, false); word(&mut s.s, "::{"); } - commasep(s, inconsistent, (*idents), |s, w| { + commasep(s, Inconsistent, (*idents), |s, w| { print_ident(s, w.node.name); }); word(&mut s.s, "}"); @@ -1979,17 +1972,17 @@ pub fn print_view_path(s: &mut ps, vp: &ast::view_path) { } } -pub fn print_view_paths(s: &mut ps, vps: &[@ast::view_path]) { - commasep(s, inconsistent, vps, |p, &vp| print_view_path(p, vp)); +pub fn print_view_paths(s: &mut State, vps: &[@ast::ViewPath]) { + commasep(s, Inconsistent, vps, |p, &vp| print_view_path(p, vp)); } -pub fn print_view_item(s: &mut ps, item: &ast::view_item) { +pub fn print_view_item(s: &mut State, item: &ast::ViewItem) { hardbreak_if_not_bol(s); maybe_print_comment(s, item.span.lo); print_outer_attributes(s, item.attrs); print_visibility(s, item.vis); match item.node { - ast::view_item_extern_mod(id, ref optional_path, _) => { + ast::ViewItemExternMod(id, ref optional_path, _) => { head(s, "extern mod"); print_ident(s, id); for &(ref p, style) in optional_path.iter() { @@ -2000,7 +1993,7 @@ pub fn print_view_item(s: &mut ps, item: &ast::view_item) { } } - ast::view_item_use(ref vps) => { + ast::ViewItemUse(ref vps) => { head(s, "use"); print_view_paths(s, *vps); } @@ -2010,53 +2003,53 @@ pub fn print_view_item(s: &mut ps, item: &ast::view_item) { end(s); // end outer head-block } -pub fn print_mutability(s: &mut ps, mutbl: ast::Mutability) { +pub fn print_mutability(s: &mut State, mutbl: ast::Mutability) { match mutbl { ast::MutMutable => word_nbsp(s, "mut"), ast::MutImmutable => {/* nothing */ } } } -pub fn print_mt(s: &mut ps, mt: &ast::mt) { +pub fn print_mt(s: &mut State, mt: &ast::MutTy) { print_mutability(s, mt.mutbl); print_type(s, mt.ty); } -pub fn print_arg(s: &mut ps, input: &ast::arg) { +pub fn print_arg(s: &mut State, input: &ast::Arg) { ibox(s, indent_unit); match input.ty.node { - ast::ty_infer => print_pat(s, input.pat), - _ => { - match input.pat.node { - ast::PatIdent(_, ref path, _) if - path.segments.len() == 1 && - path.segments[0].identifier.name == - parse::token::special_idents::invalid.name => { - // Do nothing. - } - _ => { - print_pat(s, input.pat); - word(&mut s.s, ":"); - space(&mut s.s); + ast::TyInfer => print_pat(s, input.pat), + _ => { + match input.pat.node { + ast::PatIdent(_, ref path, _) if + path.segments.len() == 1 && + path.segments[0].identifier.name == + parse::token::special_idents::invalid.name => { + // Do nothing. + } + _ => { + print_pat(s, input.pat); + word(&mut s.s, ":"); + space(&mut s.s); + } } + print_type(s, input.ty); } - print_type(s, input.ty); - } } end(s); } -pub fn print_ty_fn(s: &mut ps, +pub fn print_ty_fn(s: &mut State, opt_abis: Option<AbiSet>, opt_sigil: Option<ast::Sigil>, opt_region: &Option<ast::Lifetime>, - purity: ast::purity, + purity: ast::Purity, onceness: ast::Onceness, - decl: &ast::fn_decl, + decl: &ast::FnDecl, id: Option<ast::Ident>, opt_bounds: &Option<OptVec<ast::TyParamBound>>, generics: Option<&ast::Generics>, - opt_explicit_self: Option<ast::explicit_self_>) { + opt_explicit_self: Option<ast::ExplicitSelf_>) { ibox(s, indent_unit); // Duplicates the logic in `print_fn_header_info()`. This is because that @@ -2096,7 +2089,7 @@ pub fn print_ty_fn(s: &mut ps, // It is unfortunate to duplicate the commasep logic, but we want the // self type and the args all in the same box. - rbox(s, 0u, inconsistent); + rbox(s, 0u, Inconsistent); let mut first = true; for explicit_self in opt_explicit_self.iter() { first = !print_explicit_self(s, *explicit_self); @@ -2121,12 +2114,12 @@ pub fn print_ty_fn(s: &mut ps, maybe_print_comment(s, decl.output.span.lo); match decl.output.node { - ast::ty_nil => {} + ast::TyNil => {} _ => { space_if_not_bol(s); ibox(s, indent_unit); word_space(s, "->"); - if decl.cf == ast::noreturn { word_nbsp(s, "!"); } + if decl.cf == ast::NoReturn { word_nbsp(s, "!"); } else { print_type(s, decl.output); } end(s); } @@ -2135,13 +2128,13 @@ pub fn print_ty_fn(s: &mut ps, end(s); } -pub fn maybe_print_trailing_comment(s: &mut ps, span: codemap::Span, +pub fn maybe_print_trailing_comment(s: &mut State, span: codemap::Span, next_pos: Option<BytePos>) { let cm; match s.cm { Some(ccm) => cm = ccm, _ => return } match next_comment(s) { Some(ref cmnt) => { - if (*cmnt).style != comments::trailing { return; } + if (*cmnt).style != comments::Trailing { return; } let span_line = cm.lookup_char_pos(span.hi); let comment_line = cm.lookup_char_pos((*cmnt).pos); let mut next = (*cmnt).pos + BytePos(1); @@ -2156,7 +2149,7 @@ pub fn maybe_print_trailing_comment(s: &mut ps, span: codemap::Span, } } -pub fn print_remaining_comments(s: &mut ps) { +pub fn print_remaining_comments(s: &mut State) { // If there aren't any remaining comments, then we need to manually // make sure there is a line break at the end. if next_comment(s).is_none() { hardbreak(&mut s.s); } @@ -2171,7 +2164,7 @@ pub fn print_remaining_comments(s: &mut ps) { } } -pub fn print_literal(s: &mut ps, lit: &ast::lit) { +pub fn print_literal(s: &mut State, lit: &ast::Lit) { maybe_print_comment(s, lit.span.lo); match next_lit(s, lit.span.lo) { Some(ref ltrl) => { @@ -2181,14 +2174,14 @@ pub fn print_literal(s: &mut ps, lit: &ast::lit) { _ => () } match lit.node { - ast::lit_str(st, style) => print_string(s, st, style), - ast::lit_char(ch) => { + ast::LitStr(st, style) => print_string(s, st, style), + ast::LitChar(ch) => { let mut res = ~"'"; char::from_u32(ch).unwrap().escape_default(|c| res.push_char(c)); res.push_char('\''); word(&mut s.s, res); } - ast::lit_int(i, t) => { + ast::LitInt(i, t) => { if i < 0_i64 { word(&mut s.s, ~"-" + (-i as u64).to_str_radix(10u) @@ -2199,30 +2192,30 @@ pub fn print_literal(s: &mut ps, lit: &ast::lit) { + ast_util::int_ty_to_str(t)); } } - ast::lit_uint(u, t) => { + ast::LitUint(u, t) => { word(&mut s.s, u.to_str_radix(10u) + ast_util::uint_ty_to_str(t)); } - ast::lit_int_unsuffixed(i) => { + ast::LitIntUnsuffixed(i) => { if i < 0_i64 { word(&mut s.s, ~"-" + (-i as u64).to_str_radix(10u)); } else { word(&mut s.s, (i as u64).to_str_radix(10u)); } } - ast::lit_float(f, t) => { + ast::LitFloat(f, t) => { word(&mut s.s, f.to_owned() + ast_util::float_ty_to_str(t)); } - ast::lit_float_unsuffixed(f) => word(&mut s.s, f), - ast::lit_nil => word(&mut s.s, "()"), - ast::lit_bool(val) => { + ast::LitFloatUnsuffixed(f) => word(&mut s.s, f), + ast::LitNil => word(&mut s.s, "()"), + ast::LitBool(val) => { if val { word(&mut s.s, "true"); } else { word(&mut s.s, "false"); } } - ast::lit_binary(arr) => { + ast::LitBinary(arr) => { ibox(s, indent_unit); word(&mut s.s, "["); - commasep_cmnt(s, inconsistent, arr, |s, u| word(&mut s.s, format!("{}", *u)), + commasep_cmnt(s, Inconsistent, arr, |s, u| word(&mut s.s, format!("{}", *u)), |_| lit.span); word(&mut s.s, "]"); end(s); @@ -2230,11 +2223,11 @@ pub fn print_literal(s: &mut ps, lit: &ast::lit) { } } -pub fn lit_to_str(l: &ast::lit) -> ~str { +pub fn lit_to_str(l: &ast::Lit) -> ~str { return to_str(l, print_literal, parse::token::mk_fake_ident_interner()); } -pub fn next_lit(s: &mut ps, pos: BytePos) -> Option<comments::lit> { +pub fn next_lit(s: &mut State, pos: BytePos) -> Option<comments::Literal> { match s.literals { Some(ref lits) => { while s.cur_cmnt_and_lit.cur_lit < lits.len() { @@ -2249,7 +2242,7 @@ pub fn next_lit(s: &mut ps, pos: BytePos) -> Option<comments::lit> { } } -pub fn maybe_print_comment(s: &mut ps, pos: BytePos) { +pub fn maybe_print_comment(s: &mut State, pos: BytePos) { loop { match next_comment(s) { Some(ref cmnt) => { @@ -2263,51 +2256,50 @@ pub fn maybe_print_comment(s: &mut ps, pos: BytePos) { } } -pub fn print_comment(s: &mut ps, cmnt: &comments::cmnt) { +pub fn print_comment(s: &mut State, cmnt: &comments::Comment) { match cmnt.style { - comments::mixed => { - assert_eq!(cmnt.lines.len(), 1u); - zerobreak(&mut s.s); - word(&mut s.s, cmnt.lines[0]); - zerobreak(&mut s.s); - } - comments::isolated => { - pprust::hardbreak_if_not_bol(s); - for line in cmnt.lines.iter() { - // Don't print empty lines because they will end up as trailing - // whitespace - if !line.is_empty() { word(&mut s.s, *line); } - hardbreak(&mut s.s); - } - } - comments::trailing => { - word(&mut s.s, " "); - if cmnt.lines.len() == 1u { + comments::Mixed => { + assert_eq!(cmnt.lines.len(), 1u); + zerobreak(&mut s.s); word(&mut s.s, cmnt.lines[0]); - hardbreak(&mut s.s); - } else { - ibox(s, 0u); + zerobreak(&mut s.s); + } + comments::Isolated => { + pprust::hardbreak_if_not_bol(s); for line in cmnt.lines.iter() { + // Don't print empty lines because they will end up as trailing + // whitespace if !line.is_empty() { word(&mut s.s, *line); } hardbreak(&mut s.s); } - end(s); } - } - comments::blank_line => { - // We need to do at least one, possibly two hardbreaks. - let is_semi = - match s.s.last_token() { - pp::STRING(s, _) => ";" == s, - _ => false + comments::Trailing => { + word(&mut s.s, " "); + if cmnt.lines.len() == 1u { + word(&mut s.s, cmnt.lines[0]); + hardbreak(&mut s.s); + } else { + ibox(s, 0u); + for line in cmnt.lines.iter() { + if !line.is_empty() { word(&mut s.s, *line); } + hardbreak(&mut s.s); + } + end(s); + } + } + comments::BlankLine => { + // We need to do at least one, possibly two hardbreaks. + let is_semi = match s.s.last_token() { + pp::String(s, _) => ";" == s, + _ => false }; - if is_semi || is_begin(s) || is_end(s) { hardbreak(&mut s.s); } - hardbreak(&mut s.s); - } + if is_semi || is_begin(s) || is_end(s) { hardbreak(&mut s.s); } + hardbreak(&mut s.s); + } } } -pub fn print_string(s: &mut ps, st: &str, style: ast::StrStyle) { +pub fn print_string(s: &mut State, st: &str, style: ast::StrStyle) { let st = match style { ast::CookedStr => format!("\"{}\"", st.escape_default()), ast::RawStr(n) => format!("r{delim}\"{string}\"{delim}", @@ -2326,7 +2318,7 @@ unsafe fn get_mem_writer(writer: &mut ~io::Writer) -> ~str { result } -pub fn to_str<T>(t: &T, f: |&mut ps, &T|, intr: @ident_interner) -> ~str { +pub fn to_str<T>(t: &T, f: |&mut State, &T|, intr: @IdentInterner) -> ~str { let wr = ~MemWriter::new(); let mut s = rust_printer(wr as ~io::Writer, intr); f(&mut s, t); @@ -2336,22 +2328,22 @@ pub fn to_str<T>(t: &T, f: |&mut ps, &T|, intr: @ident_interner) -> ~str { } } -pub fn next_comment(s: &mut ps) -> Option<comments::cmnt> { +pub fn next_comment(s: &mut State) -> Option<comments::Comment> { match s.comments { - Some(ref cmnts) => { - if s.cur_cmnt_and_lit.cur_cmnt < cmnts.len() { - return Some(cmnts[s.cur_cmnt_and_lit.cur_cmnt].clone()); - } else { - return None::<comments::cmnt>; + Some(ref cmnts) => { + if s.cur_cmnt_and_lit.cur_cmnt < cmnts.len() { + Some(cmnts[s.cur_cmnt_and_lit.cur_cmnt].clone()) + } else { + None + } } - } - _ => return None::<comments::cmnt> + _ => None } } -pub fn print_opt_purity(s: &mut ps, opt_purity: Option<ast::purity>) { +pub fn print_opt_purity(s: &mut State, opt_purity: Option<ast::Purity>) { match opt_purity { - Some(ast::impure_fn) => { } + Some(ast::ImpureFn) => { } Some(purity) => { word_nbsp(s, purity_to_str(purity)); } @@ -2359,7 +2351,7 @@ pub fn print_opt_purity(s: &mut ps, opt_purity: Option<ast::purity>) { } } -pub fn print_opt_abis_and_extern_if_nondefault(s: &mut ps, +pub fn print_opt_abis_and_extern_if_nondefault(s: &mut State, opt_abis: Option<AbiSet>) { match opt_abis { Some(abis) if !abis.is_rust() => { @@ -2370,7 +2362,7 @@ pub fn print_opt_abis_and_extern_if_nondefault(s: &mut ps, }; } -pub fn print_extern_opt_abis(s: &mut ps, opt_abis: Option<AbiSet>) { +pub fn print_extern_opt_abis(s: &mut State, opt_abis: Option<AbiSet>) { match opt_abis { Some(abis) => { word_nbsp(s, "extern"); @@ -2380,7 +2372,7 @@ pub fn print_extern_opt_abis(s: &mut ps, opt_abis: Option<AbiSet>) { }; } -pub fn print_opt_sigil(s: &mut ps, opt_sigil: Option<ast::Sigil>) { +pub fn print_opt_sigil(s: &mut State, opt_sigil: Option<ast::Sigil>) { match opt_sigil { Some(ast::BorrowedSigil) => { word(&mut s.s, "&"); } Some(ast::OwnedSigil) => { word(&mut s.s, "~"); } @@ -2389,20 +2381,20 @@ pub fn print_opt_sigil(s: &mut ps, opt_sigil: Option<ast::Sigil>) { }; } -pub fn print_fn_header_info(s: &mut ps, - _opt_explicit_self: Option<ast::explicit_self_>, - opt_purity: Option<ast::purity>, +pub fn print_fn_header_info(s: &mut State, + _opt_explicit_self: Option<ast::ExplicitSelf_>, + opt_purity: Option<ast::Purity>, abis: AbiSet, onceness: ast::Onceness, opt_sigil: Option<ast::Sigil>, - vis: ast::visibility) { + vis: ast::Visibility) { word(&mut s.s, visibility_qualified(vis, "")); if abis != AbiSet::Rust() { word_nbsp(s, "extern"); word_nbsp(s, abis.to_str()); - if opt_purity != Some(ast::extern_fn) { + if opt_purity != Some(ast::ExternFn) { print_opt_purity(s, opt_purity); } } else { @@ -2414,11 +2406,11 @@ pub fn print_fn_header_info(s: &mut ps, print_opt_sigil(s, opt_sigil); } -pub fn purity_to_str(p: ast::purity) -> &'static str { +pub fn purity_to_str(p: ast::Purity) -> &'static str { match p { - ast::impure_fn => "impure", - ast::unsafe_fn => "unsafe", - ast::extern_fn => "extern" + ast::ImpureFn => "impure", + ast::UnsafeFn => "unsafe", + ast::ExternFn => "extern" } } @@ -2429,14 +2421,14 @@ pub fn onceness_to_str(o: ast::Onceness) -> &'static str { } } -pub fn print_purity(s: &mut ps, p: ast::purity) { +pub fn print_purity(s: &mut State, p: ast::Purity) { match p { - ast::impure_fn => (), + ast::ImpureFn => (), _ => word_nbsp(s, purity_to_str(p)) } } -pub fn print_onceness(s: &mut ps, o: ast::Onceness) { +pub fn print_onceness(s: &mut State, o: ast::Onceness) { match o { ast::Once => { word_nbsp(s, "once"); } ast::Many => {} @@ -2456,16 +2448,16 @@ mod test { fn test_fun_to_str() { let abba_ident = token::str_to_ident("abba"); - let decl = ast::fn_decl { + let decl = ast::FnDecl { inputs: ~[], output: ast::P(ast::Ty {id: 0, - node: ast::ty_nil, + node: ast::TyNil, span: codemap::DUMMY_SP}), - cf: ast::return_val, + cf: ast::Return, variadic: false }; let generics = ast_util::empty_generics(); - assert_eq!(&fun_to_str(&decl, ast::impure_fn, abba_ident, + assert_eq!(&fun_to_str(&decl, ast::ImpureFn, abba_ident, None, &generics, token::get_ident_interner()), &~"fn abba()"); } @@ -2474,14 +2466,14 @@ mod test { fn test_variant_to_str() { let ident = token::str_to_ident("principal_skinner"); - let var = codemap::respan(codemap::DUMMY_SP, ast::variant_ { + let var = codemap::respan(codemap::DUMMY_SP, ast::Variant_ { name: ident, attrs: ~[], // making this up as I go.... ? - kind: ast::tuple_variant_kind(~[]), + kind: ast::TupleVariantKind(~[]), id: 0, disr_expr: None, - vis: ast::public, + vis: ast::Public, }); let varstr = variant_to_str(&var,token::get_ident_interner()); diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs index dc546c7610f..5153ddf1c7d 100644 --- a/src/libsyntax/util/parser_testing.rs +++ b/src/libsyntax/util/parser_testing.rs @@ -15,15 +15,15 @@ use parse::{new_parser_from_source_str}; use parse::parser::Parser; use parse::token; -// map a string to tts, using a made-up filename: return both the token_trees +// map a string to tts, using a made-up filename: return both the TokenTree's // and the ParseSess -pub fn string_to_tts_and_sess (source_str : @str) -> (~[ast::token_tree],@ParseSess) { +pub fn string_to_tts_and_sess (source_str : @str) -> (~[ast::TokenTree], @ParseSess) { let ps = new_parse_sess(None); (filemap_to_tts(ps,string_to_filemap(ps,source_str,@"bogofile")),ps) } // map a string to tts, using a made-up filename: -pub fn string_to_tts(source_str : @str) -> ~[ast::token_tree] { +pub fn string_to_tts(source_str : @str) -> ~[ast::TokenTree] { let (tts,_) = string_to_tts_and_sess(source_str); tts } @@ -67,7 +67,7 @@ pub fn string_to_expr (source_str : @str) -> @ast::Expr { } // parse a string, return an item -pub fn string_to_item (source_str : @str) -> Option<@ast::item> { +pub fn string_to_item (source_str : @str) -> Option<@ast::Item> { with_error_checking_parse(source_str, |p| { p.parse_item(~[]) }) @@ -86,7 +86,7 @@ pub fn string_to_pat(source_str : @str) -> @ast::Pat { string_to_parser(source_str).parse_pat() } -// convert a vector of strings to a vector of ast::idents +// convert a vector of strings to a vector of ast::Ident's pub fn strs_to_idents(ids: ~[&str]) -> ~[ast::Ident] { ids.map(|u| token::str_to_ident(*u)) } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 6484855d9d9..8e678a9bb73 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -28,34 +28,32 @@ use opt_vec::OptVec; // execute before AST node B, then A is visited first. The borrow checker in // particular relies on this property. -pub enum fn_kind<'a> { +pub enum FnKind<'a> { // fn foo() or extern "Abi" fn foo() - fk_item_fn(Ident, &'a Generics, purity, AbiSet), + FkItemFn(Ident, &'a Generics, Purity, AbiSet), // fn foo(&self) - fk_method(Ident, &'a Generics, &'a method), + FkMethod(Ident, &'a Generics, &'a Method), // |x, y| ... // proc(x, y) ... - fk_fn_block, + FkFnBlock, } -pub fn name_of_fn(fk: &fn_kind) -> Ident { +pub fn name_of_fn(fk: &FnKind) -> Ident { match *fk { - fk_item_fn(name, _, _, _) | fk_method(name, _, _) => { - name - } - fk_fn_block(..) => parse::token::special_idents::anon, + FkItemFn(name, _, _, _) | FkMethod(name, _, _) => name, + FkFnBlock(..) => parse::token::special_idents::anon } } -pub fn generics_of_fn(fk: &fn_kind) -> Generics { +pub fn generics_of_fn(fk: &FnKind) -> Generics { match *fk { - fk_item_fn(_, generics, _, _) | - fk_method(_, generics, _) => { + FkItemFn(_, generics, _, _) | + FkMethod(_, generics, _) => { (*generics).clone() } - fk_fn_block(..) => { + FkFnBlock(..) => { Generics { lifetimes: opt_vec::Empty, ty_params: opt_vec::Empty, @@ -68,10 +66,10 @@ pub trait Visitor<E: Clone> { fn visit_ident(&mut self, _sp: Span, _ident: Ident, _e: E) { /*! Visit the idents */ } - fn visit_mod(&mut self, m: &_mod, _s: Span, _n: NodeId, e: E) { walk_mod(self, m, e) } - fn visit_view_item(&mut self, i: &view_item, e: E) { walk_view_item(self, i, e) } - fn visit_foreign_item(&mut self, i: &foreign_item, e: E) { walk_foreign_item(self, i, e) } - fn visit_item(&mut self, i: &item, e: E) { walk_item(self, i, e) } + fn visit_mod(&mut self, m: &Mod, _s: Span, _n: NodeId, e: E) { walk_mod(self, m, e) } + fn visit_view_item(&mut self, i: &ViewItem, e: E) { walk_view_item(self, i, e) } + fn visit_foreign_item(&mut self, i: &ForeignItem, e: E) { walk_foreign_item(self, i, e) } + fn visit_item(&mut self, i: &Item, e: E) { walk_item(self, i, e) } fn visit_local(&mut self, l: &Local, e: E) { walk_local(self, l, e) } fn visit_block(&mut self, b: &Block, e: E) { walk_block(self, b, e) } fn visit_stmt(&mut self, s: &Stmt, e: E) { walk_stmt(self, s, e) } @@ -82,16 +80,16 @@ pub trait Visitor<E: Clone> { fn visit_expr_post(&mut self, _ex: &Expr, _e: E) { } fn visit_ty(&mut self, t: &Ty, e: E) { walk_ty(self, t, e) } fn visit_generics(&mut self, g: &Generics, e: E) { walk_generics(self, g, e) } - fn visit_fn(&mut self, fk: &fn_kind, fd: &fn_decl, b: &Block, s: Span, n: NodeId, e: E) { + fn visit_fn(&mut self, fk: &FnKind, fd: &FnDecl, b: &Block, s: Span, n: NodeId, e: E) { walk_fn(self, fk, fd, b, s, n , e) } fn visit_ty_method(&mut self, t: &TypeMethod, e: E) { walk_ty_method(self, t, e) } - fn visit_trait_method(&mut self, t: &trait_method, e: E) { walk_trait_method(self, t, e) } - fn visit_struct_def(&mut self, s: &struct_def, i: Ident, g: &Generics, n: NodeId, e: E) { + fn visit_trait_method(&mut self, t: &TraitMethod, e: E) { walk_trait_method(self, t, e) } + fn visit_struct_def(&mut self, s: &StructDef, i: Ident, g: &Generics, n: NodeId, e: E) { walk_struct_def(self, s, i, g, n, e) } - fn visit_struct_field(&mut self, s: &struct_field, e: E) { walk_struct_field(self, s, e) } - fn visit_variant(&mut self, v: &variant, g: &Generics, e: E) { walk_variant(self, v, g, e) } + fn visit_struct_field(&mut self, s: &StructField, e: E) { walk_struct_field(self, s, e) } + fn visit_variant(&mut self, v: &Variant, g: &Generics, e: E) { walk_variant(self, v, g, e) } fn visit_opt_lifetime_ref(&mut self, _span: Span, opt_lifetime: &Option<Lifetime>, @@ -112,10 +110,10 @@ pub trait Visitor<E: Clone> { fn visit_lifetime_decl(&mut self, _lifetime: &Lifetime, _e: E) { /*! Visits a declaration of a lifetime */ } - fn visit_explicit_self(&mut self, es: &explicit_self, e: E) { + fn visit_explicit_self(&mut self, es: &ExplicitSelf, e: E) { walk_explicit_self(self, es, e) } - fn visit_mac(&mut self, macro: &mac, e: E) { + fn visit_mac(&mut self, macro: &Mac, e: E) { walk_mac(self, macro, e) } fn visit_path(&mut self, path: &Path, _id: ast::NodeId, e: E) { @@ -127,7 +125,7 @@ pub fn walk_crate<E: Clone, V: Visitor<E>>(visitor: &mut V, crate: &Crate, env: visitor.visit_mod(&crate.module, crate.span, CRATE_NODE_ID, env) } -pub fn walk_mod<E: Clone, V: Visitor<E>>(visitor: &mut V, module: &_mod, env: E) { +pub fn walk_mod<E: Clone, V: Visitor<E>>(visitor: &mut V, module: &Mod, env: E) { for view_item in module.view_items.iter() { visitor.visit_view_item(view_item, env.clone()) } @@ -137,22 +135,22 @@ pub fn walk_mod<E: Clone, V: Visitor<E>>(visitor: &mut V, module: &_mod, env: E) } } -pub fn walk_view_item<E: Clone, V: Visitor<E>>(visitor: &mut V, vi: &view_item, env: E) { +pub fn walk_view_item<E: Clone, V: Visitor<E>>(visitor: &mut V, vi: &ViewItem, env: E) { match vi.node { - view_item_extern_mod(name, _, _) => { + ViewItemExternMod(name, _, _) => { visitor.visit_ident(vi.span, name, env) } - view_item_use(ref paths) => { + ViewItemUse(ref paths) => { for vp in paths.iter() { match vp.node { - view_path_simple(ident, ref path, id) => { + ViewPathSimple(ident, ref path, id) => { visitor.visit_ident(vp.span, ident, env.clone()); visitor.visit_path(path, id, env.clone()); } - view_path_glob(ref path, id) => { + ViewPathGlob(ref path, id) => { visitor.visit_path(path, id, env.clone()); } - view_path_list(ref path, ref list, _) => { + ViewPathList(ref path, ref list, _) => { for id in list.iter() { visitor.visit_ident(id.span, id.node.name, env.clone()) } @@ -174,42 +172,41 @@ pub fn walk_local<E: Clone, V: Visitor<E>>(visitor: &mut V, local: &Local, env: } fn walk_explicit_self<E: Clone, V: Visitor<E>>(visitor: &mut V, - explicit_self: &explicit_self, + explicit_self: &ExplicitSelf, env: E) { match explicit_self.node { - sty_static | sty_value(_) | sty_box(_) | sty_uniq(_) => { - } - sty_region(ref lifetime, _) => { + SelfStatic | SelfValue(_) | SelfBox(_) | SelfUniq(_) => {} + SelfRegion(ref lifetime, _) => { visitor.visit_opt_lifetime_ref(explicit_self.span, lifetime, env) } } } fn walk_trait_ref<E: Clone, V: Visitor<E>>(visitor: &mut V, - trait_ref: &trait_ref, + trait_ref: &TraitRef, env: E) { visitor.visit_path(&trait_ref.path, trait_ref.ref_id, env) } -pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &item, env: E) { +pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &Item, env: E) { visitor.visit_ident(item.span, item.ident, env.clone()); match item.node { - item_static(typ, _, expr) => { + ItemStatic(typ, _, expr) => { visitor.visit_ty(typ, env.clone()); visitor.visit_expr(expr, env); } - item_fn(declaration, purity, abi, ref generics, body) => { - visitor.visit_fn(&fk_item_fn(item.ident, generics, purity, abi), + ItemFn(declaration, purity, abi, ref generics, body) => { + visitor.visit_fn(&FkItemFn(item.ident, generics, purity, abi), declaration, body, item.span, item.id, env) } - item_mod(ref module) => { + ItemMod(ref module) => { visitor.visit_mod(module, item.span, item.id, env) } - item_foreign_mod(ref foreign_module) => { + ItemForeignMod(ref foreign_module) => { for view_item in foreign_module.view_items.iter() { visitor.visit_view_item(view_item, env.clone()) } @@ -217,15 +214,15 @@ pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &item, env: E) visitor.visit_foreign_item(*foreign_item, env.clone()) } } - item_ty(typ, ref type_parameters) => { + ItemTy(typ, ref type_parameters) => { visitor.visit_ty(typ, env.clone()); visitor.visit_generics(type_parameters, env) } - item_enum(ref enum_definition, ref type_parameters) => { + ItemEnum(ref enum_definition, ref type_parameters) => { visitor.visit_generics(type_parameters, env.clone()); walk_enum_def(visitor, enum_definition, type_parameters, env) } - item_impl(ref type_parameters, + ItemImpl(ref type_parameters, ref trait_references, typ, ref methods) => { @@ -238,7 +235,7 @@ pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &item, env: E) walk_method_helper(visitor, *method, env.clone()) } } - item_struct(struct_definition, ref generics) => { + ItemStruct(struct_definition, ref generics) => { visitor.visit_generics(generics, env.clone()); visitor.visit_struct_def(struct_definition, item.ident, @@ -246,7 +243,7 @@ pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &item, env: E) item.id, env) } - item_trait(ref generics, ref trait_paths, ref methods) => { + ItemTrait(ref generics, ref trait_paths, ref methods) => { visitor.visit_generics(generics, env.clone()); for trait_path in trait_paths.iter() { visitor.visit_path(&trait_path.path, @@ -257,12 +254,12 @@ pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &item, env: E) visitor.visit_trait_method(method, env.clone()) } } - item_mac(ref macro) => visitor.visit_mac(macro, env), + ItemMac(ref macro) => visitor.visit_mac(macro, env), } } pub fn walk_enum_def<E: Clone, V:Visitor<E>>(visitor: &mut V, - enum_definition: &enum_def, + enum_definition: &EnumDef, generics: &Generics, env: E) { for &variant in enum_definition.variants.iter() { @@ -271,18 +268,18 @@ pub fn walk_enum_def<E: Clone, V:Visitor<E>>(visitor: &mut V, } pub fn walk_variant<E: Clone, V: Visitor<E>>(visitor: &mut V, - variant: &variant, + variant: &Variant, generics: &Generics, env: E) { visitor.visit_ident(variant.span, variant.node.name, env.clone()); match variant.node.kind { - tuple_variant_kind(ref variant_arguments) => { + TupleVariantKind(ref variant_arguments) => { for variant_argument in variant_arguments.iter() { visitor.visit_ty(variant_argument.ty, env.clone()) } } - struct_variant_kind(struct_definition) => { + StructVariantKind(struct_definition) => { visitor.visit_struct_def(struct_definition, variant.node.name, generics, @@ -302,22 +299,22 @@ pub fn skip_ty<E, V: Visitor<E>>(_: &mut V, _: &Ty, _: E) { pub fn walk_ty<E: Clone, V: Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) { match typ.node { - ty_uniq(ty) | ty_vec(ty) | ty_box(ty) => { + TyUniq(ty) | TyVec(ty) | TyBox(ty) => { visitor.visit_ty(ty, env) } - ty_ptr(ref mutable_type) => { + TyPtr(ref mutable_type) => { visitor.visit_ty(mutable_type.ty, env) } - ty_rptr(ref lifetime, ref mutable_type) => { + TyRptr(ref lifetime, ref mutable_type) => { visitor.visit_opt_lifetime_ref(typ.span, lifetime, env.clone()); visitor.visit_ty(mutable_type.ty, env) } - ty_tup(ref tuple_element_types) => { + TyTup(ref tuple_element_types) => { for &tuple_element_type in tuple_element_types.iter() { visitor.visit_ty(tuple_element_type, env.clone()) } } - ty_closure(ref function_declaration) => { + TyClosure(ref function_declaration) => { for argument in function_declaration.decl.inputs.iter() { visitor.visit_ty(argument.ty, env.clone()) } @@ -332,7 +329,7 @@ pub fn walk_ty<E: Clone, V: Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) { walk_lifetime_decls(visitor, &function_declaration.lifetimes, env.clone()); } - ty_bare_fn(ref function_declaration) => { + TyBareFn(ref function_declaration) => { for argument in function_declaration.decl.inputs.iter() { visitor.visit_ty(argument.ty, env.clone()) } @@ -340,20 +337,20 @@ pub fn walk_ty<E: Clone, V: Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) { walk_lifetime_decls(visitor, &function_declaration.lifetimes, env.clone()); } - ty_path(ref path, ref bounds, id) => { + TyPath(ref path, ref bounds, id) => { visitor.visit_path(path, id, env.clone()); for bounds in bounds.iter() { walk_ty_param_bounds(visitor, bounds, env.clone()) } } - ty_fixed_length_vec(ty, expression) => { + TyFixedLengthVec(ty, expression) => { visitor.visit_ty(ty, env.clone()); visitor.visit_expr(expression, env) } - ty_typeof(expression) => { + TyTypeof(expression) => { visitor.visit_expr(expression, env) } - ty_nil | ty_bot | ty_infer => () + TyNil | TyBot | TyInfer => {} } } @@ -432,16 +429,16 @@ pub fn walk_pat<E: Clone, V: Visitor<E>>(visitor: &mut V, pattern: &Pat, env: E) } pub fn walk_foreign_item<E: Clone, V: Visitor<E>>(visitor: &mut V, - foreign_item: &foreign_item, + foreign_item: &ForeignItem, env: E) { visitor.visit_ident(foreign_item.span, foreign_item.ident, env.clone()); match foreign_item.node { - foreign_item_fn(function_declaration, ref generics) => { + ForeignItemFn(function_declaration, ref generics) => { walk_fn_decl(visitor, function_declaration, env.clone()); visitor.visit_generics(generics, env) } - foreign_item_static(typ, _) => visitor.visit_ty(typ, env), + ForeignItemStatic(typ, _) => visitor.visit_ty(typ, env), } } @@ -468,7 +465,7 @@ pub fn walk_generics<E: Clone, V: Visitor<E>>(visitor: &mut V, } pub fn walk_fn_decl<E: Clone, V: Visitor<E>>(visitor: &mut V, - function_declaration: &fn_decl, + function_declaration: &FnDecl, env: E) { for argument in function_declaration.inputs.iter() { visitor.visit_pat(argument.pat, env.clone()); @@ -478,14 +475,14 @@ pub fn walk_fn_decl<E: Clone, V: Visitor<E>>(visitor: &mut V, } // Note: there is no visit_method() method in the visitor, instead override -// visit_fn() and check for fk_method(). I named this visit_method_helper() +// visit_fn() and check for FkMethod(). I named this visit_method_helper() // because it is not a default impl of any method, though I doubt that really // clarifies anything. - Niko pub fn walk_method_helper<E: Clone, V: Visitor<E>>(visitor: &mut V, - method: &method, + method: &Method, env: E) { visitor.visit_ident(method.span, method.ident, env.clone()); - visitor.visit_fn(&fk_method(method.ident, &method.generics, method), + visitor.visit_fn(&FkMethod(method.ident, &method.generics, method), method.decl, method.body, method.span, @@ -494,8 +491,8 @@ pub fn walk_method_helper<E: Clone, V: Visitor<E>>(visitor: &mut V, } pub fn walk_fn<E: Clone, V: Visitor<E>>(visitor: &mut V, - function_kind: &fn_kind, - function_declaration: &fn_decl, + function_kind: &FnKind, + function_declaration: &FnDecl, function_body: &Block, _span: Span, _: NodeId, @@ -503,16 +500,15 @@ pub fn walk_fn<E: Clone, V: Visitor<E>>(visitor: &mut V, walk_fn_decl(visitor, function_declaration, env.clone()); match *function_kind { - fk_item_fn(_, generics, _, _) => { + FkItemFn(_, generics, _, _) => { visitor.visit_generics(generics, env.clone()); } - fk_method(_, generics, method) => { + FkMethod(_, generics, method) => { visitor.visit_generics(generics, env.clone()); visitor.visit_explicit_self(&method.explicit_self, env.clone()); } - fk_fn_block(..) => { - } + FkFnBlock(..) => {} } visitor.visit_block(function_body, env) @@ -531,18 +527,18 @@ pub fn walk_ty_method<E: Clone, V: Visitor<E>>(visitor: &mut V, } pub fn walk_trait_method<E: Clone, V: Visitor<E>>(visitor: &mut V, - trait_method: &trait_method, + trait_method: &TraitMethod, env: E) { match *trait_method { - required(ref method_type) => { + Required(ref method_type) => { visitor.visit_ty_method(method_type, env) } - provided(method) => walk_method_helper(visitor, method, env), + Provided(method) => walk_method_helper(visitor, method, env), } } pub fn walk_struct_def<E: Clone, V: Visitor<E>>(visitor: &mut V, - struct_definition: &struct_def, + struct_definition: &StructDef, _: Ident, _: &Generics, _: NodeId, @@ -553,10 +549,10 @@ pub fn walk_struct_def<E: Clone, V: Visitor<E>>(visitor: &mut V, } pub fn walk_struct_field<E: Clone, V: Visitor<E>>(visitor: &mut V, - struct_field: &struct_field, + struct_field: &StructField, env: E) { match struct_field.node.kind { - named_field(name, _) => { + NamedField(name, _) => { visitor.visit_ident(struct_field.span, name, env.clone()) } _ => {} @@ -609,7 +605,7 @@ pub fn walk_exprs<E: Clone, V: Visitor<E>>(visitor: &mut V, } } -pub fn walk_mac<E, V: Visitor<E>>(_: &mut V, _: &mac, _: E) { +pub fn walk_mac<E, V: Visitor<E>>(_: &mut V, _: &Mac, _: E) { // Empty! } @@ -686,7 +682,7 @@ pub fn walk_expr<E: Clone, V: Visitor<E>>(visitor: &mut V, expression: &Expr, en } } ExprFnBlock(function_declaration, body) => { - visitor.visit_fn(&fk_fn_block, + visitor.visit_fn(&FkFnBlock, function_declaration, body, expression.span, @@ -694,7 +690,7 @@ pub fn walk_expr<E: Clone, V: Visitor<E>>(visitor: &mut V, expression: &Expr, en env.clone()) } ExprProc(function_declaration, body) => { - visitor.visit_fn(&fk_fn_block, + visitor.visit_fn(&FkFnBlock, function_declaration, body, expression.span, |
