libsyntax: Mechanically change ~[T]
to Vec<T>
This commit is contained in:
parent
df40aeccdb
commit
58fd6ab90d
48 changed files with 934 additions and 979 deletions
|
@ -9,6 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::vec_ng::Vec;
|
||||||
use std::fmt::Show;
|
use std::fmt::Show;
|
||||||
|
|
||||||
#[deriving(Eq)]
|
#[deriving(Eq)]
|
||||||
|
@ -117,7 +118,7 @@ pub fn lookup(name: &str) -> Option<Abi> {
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn all_names() -> ~[&'static str] {
|
pub fn all_names() -> Vec<&'static str> {
|
||||||
AbiDatas.map(|d| d.name)
|
AbiDatas.map(|d| d.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +233,7 @@ impl AbiSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_valid(&self) -> Option<(Abi, Abi)> {
|
pub fn check_valid(&self) -> Option<(Abi, Abi)> {
|
||||||
let mut abis = ~[];
|
let mut abis = Vec::new();
|
||||||
self.each(|abi| { abis.push(abi); true });
|
self.each(|abi| { abis.push(abi); true });
|
||||||
|
|
||||||
for (i, abi) in abis.iter().enumerate() {
|
for (i, abi) in abis.iter().enumerate() {
|
||||||
|
|
|
@ -98,7 +98,7 @@ pub type SyntaxContext = u32;
|
||||||
// it should cut down on memory use *a lot*; applying a mark
|
// it should cut down on memory use *a lot*; applying a mark
|
||||||
// to a tree containing 50 identifiers would otherwise generate
|
// to a tree containing 50 identifiers would otherwise generate
|
||||||
pub struct SCTable {
|
pub struct SCTable {
|
||||||
table: RefCell<~[SyntaxContext_]>,
|
table: RefCell<Vec<SyntaxContext_> >,
|
||||||
mark_memo: RefCell<HashMap<(SyntaxContext,Mrk),SyntaxContext>>,
|
mark_memo: RefCell<HashMap<(SyntaxContext,Mrk),SyntaxContext>>,
|
||||||
rename_memo: RefCell<HashMap<(SyntaxContext,Ident,Name),SyntaxContext>>,
|
rename_memo: RefCell<HashMap<(SyntaxContext,Ident,Name),SyntaxContext>>,
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ pub struct Path {
|
||||||
/// module (like paths in an import).
|
/// module (like paths in an import).
|
||||||
global: bool,
|
global: bool,
|
||||||
/// The segments in the path: the things separated by `::`.
|
/// The segments in the path: the things separated by `::`.
|
||||||
segments: ~[PathSegment],
|
segments: Vec<PathSegment> ,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A segment of a path: an identifier, an optional lifetime, and a set of
|
/// A segment of a path: an identifier, an optional lifetime, and a set of
|
||||||
|
@ -288,12 +288,12 @@ pub enum DefRegion {
|
||||||
|
|
||||||
// The set of MetaItems that define the compilation environment of the crate,
|
// The set of MetaItems that define the compilation environment of the crate,
|
||||||
// used to drive conditional compilation
|
// used to drive conditional compilation
|
||||||
pub type CrateConfig = ~[@MetaItem];
|
pub type CrateConfig = Vec<@MetaItem> ;
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct Crate {
|
pub struct Crate {
|
||||||
module: Mod,
|
module: Mod,
|
||||||
attrs: ~[Attribute],
|
attrs: Vec<Attribute> ,
|
||||||
config: CrateConfig,
|
config: CrateConfig,
|
||||||
span: Span,
|
span: Span,
|
||||||
}
|
}
|
||||||
|
@ -303,7 +303,7 @@ pub type MetaItem = Spanned<MetaItem_>;
|
||||||
#[deriving(Clone, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Encodable, Decodable, Hash)]
|
||||||
pub enum MetaItem_ {
|
pub enum MetaItem_ {
|
||||||
MetaWord(InternedString),
|
MetaWord(InternedString),
|
||||||
MetaList(InternedString, ~[@MetaItem]),
|
MetaList(InternedString, Vec<@MetaItem> ),
|
||||||
MetaNameValue(InternedString, Lit),
|
MetaNameValue(InternedString, Lit),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,8 +334,8 @@ impl Eq for MetaItem_ {
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct Block {
|
pub struct Block {
|
||||||
view_items: ~[ViewItem],
|
view_items: Vec<ViewItem> ,
|
||||||
stmts: ~[@Stmt],
|
stmts: Vec<@Stmt> ,
|
||||||
expr: Option<@Expr>,
|
expr: Option<@Expr>,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
rules: BlockCheckMode,
|
rules: BlockCheckMode,
|
||||||
|
@ -373,17 +373,17 @@ pub enum Pat_ {
|
||||||
// records this pattern's NodeId in an auxiliary
|
// records this pattern's NodeId in an auxiliary
|
||||||
// set (of "pat_idents that refer to nullary enums")
|
// set (of "pat_idents that refer to nullary enums")
|
||||||
PatIdent(BindingMode, Path, Option<@Pat>),
|
PatIdent(BindingMode, Path, Option<@Pat>),
|
||||||
PatEnum(Path, Option<~[@Pat]>), /* "none" means a * pattern where
|
PatEnum(Path, Option<Vec<@Pat> >), /* "none" means a * pattern where
|
||||||
* we don't bind the fields to names */
|
* we don't bind the fields to names */
|
||||||
PatStruct(Path, ~[FieldPat], bool),
|
PatStruct(Path, Vec<FieldPat> , bool),
|
||||||
PatTup(~[@Pat]),
|
PatTup(Vec<@Pat> ),
|
||||||
PatUniq(@Pat),
|
PatUniq(@Pat),
|
||||||
PatRegion(@Pat), // reference pattern
|
PatRegion(@Pat), // reference pattern
|
||||||
PatLit(@Expr),
|
PatLit(@Expr),
|
||||||
PatRange(@Expr, @Expr),
|
PatRange(@Expr, @Expr),
|
||||||
// [a, b, ..i, y, z] is represented as
|
// [a, b, ..i, y, z] is represented as
|
||||||
// PatVec(~[a, b], Some(i), ~[y, z])
|
// PatVec(~[a, b], Some(i), ~[y, z])
|
||||||
PatVec(~[@Pat], Option<@Pat>, ~[@Pat])
|
PatVec(Vec<@Pat> , Option<@Pat>, Vec<@Pat> )
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
|
@ -488,7 +488,7 @@ pub enum Decl_ {
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct Arm {
|
pub struct Arm {
|
||||||
pats: ~[@Pat],
|
pats: Vec<@Pat> ,
|
||||||
guard: Option<@Expr>,
|
guard: Option<@Expr>,
|
||||||
body: P<Block>,
|
body: P<Block>,
|
||||||
}
|
}
|
||||||
|
@ -526,10 +526,10 @@ pub enum Expr_ {
|
||||||
ExprVstore(@Expr, ExprVstore),
|
ExprVstore(@Expr, ExprVstore),
|
||||||
// First expr is the place; second expr is the value.
|
// First expr is the place; second expr is the value.
|
||||||
ExprBox(@Expr, @Expr),
|
ExprBox(@Expr, @Expr),
|
||||||
ExprVec(~[@Expr], Mutability),
|
ExprVec(Vec<@Expr> , Mutability),
|
||||||
ExprCall(@Expr, ~[@Expr]),
|
ExprCall(@Expr, Vec<@Expr> ),
|
||||||
ExprMethodCall(Ident, ~[P<Ty>], ~[@Expr]),
|
ExprMethodCall(Ident, Vec<P<Ty>> , Vec<@Expr> ),
|
||||||
ExprTup(~[@Expr]),
|
ExprTup(Vec<@Expr> ),
|
||||||
ExprBinary(BinOp, @Expr, @Expr),
|
ExprBinary(BinOp, @Expr, @Expr),
|
||||||
ExprUnary(UnOp, @Expr),
|
ExprUnary(UnOp, @Expr),
|
||||||
ExprLit(@Lit),
|
ExprLit(@Lit),
|
||||||
|
@ -541,14 +541,14 @@ pub enum Expr_ {
|
||||||
// Conditionless loop (can be exited with break, cont, or ret)
|
// Conditionless loop (can be exited with break, cont, or ret)
|
||||||
// FIXME #6993: change to Option<Name>
|
// FIXME #6993: change to Option<Name>
|
||||||
ExprLoop(P<Block>, Option<Ident>),
|
ExprLoop(P<Block>, Option<Ident>),
|
||||||
ExprMatch(@Expr, ~[Arm]),
|
ExprMatch(@Expr, Vec<Arm> ),
|
||||||
ExprFnBlock(P<FnDecl>, P<Block>),
|
ExprFnBlock(P<FnDecl>, P<Block>),
|
||||||
ExprProc(P<FnDecl>, P<Block>),
|
ExprProc(P<FnDecl>, P<Block>),
|
||||||
ExprBlock(P<Block>),
|
ExprBlock(P<Block>),
|
||||||
|
|
||||||
ExprAssign(@Expr, @Expr),
|
ExprAssign(@Expr, @Expr),
|
||||||
ExprAssignOp(BinOp, @Expr, @Expr),
|
ExprAssignOp(BinOp, @Expr, @Expr),
|
||||||
ExprField(@Expr, Ident, ~[P<Ty>]),
|
ExprField(@Expr, Ident, Vec<P<Ty>> ),
|
||||||
ExprIndex(@Expr, @Expr),
|
ExprIndex(@Expr, @Expr),
|
||||||
|
|
||||||
/// Expression that looks like a "name". For example,
|
/// Expression that looks like a "name". For example,
|
||||||
|
@ -569,7 +569,7 @@ pub enum Expr_ {
|
||||||
ExprMac(Mac),
|
ExprMac(Mac),
|
||||||
|
|
||||||
// A struct literal expression.
|
// A struct literal expression.
|
||||||
ExprStruct(Path, ~[Field], Option<@Expr> /* base */),
|
ExprStruct(Path, Vec<Field> , Option<@Expr> /* base */),
|
||||||
|
|
||||||
// A vector literal constructed from one repeated element.
|
// A vector literal constructed from one repeated element.
|
||||||
ExprRepeat(@Expr /* element */, @Expr /* count */, Mutability),
|
ExprRepeat(@Expr /* element */, @Expr /* count */, Mutability),
|
||||||
|
@ -600,14 +600,14 @@ pub enum TokenTree {
|
||||||
TTTok(Span, ::parse::token::Token),
|
TTTok(Span, ::parse::token::Token),
|
||||||
// a delimited sequence (the delimiters appear as the first
|
// a delimited sequence (the delimiters appear as the first
|
||||||
// and last elements of the vector)
|
// and last elements of the vector)
|
||||||
TTDelim(@~[TokenTree]),
|
TTDelim(@Vec<TokenTree> ),
|
||||||
|
|
||||||
// These only make sense for right-hand-sides of MBE macros:
|
// These only make sense for right-hand-sides of MBE macros:
|
||||||
|
|
||||||
// a kleene-style repetition sequence with a span, a TTForest,
|
// a kleene-style repetition sequence with a span, a TTForest,
|
||||||
// an optional separator, and a boolean where true indicates
|
// an optional separator, and a boolean where true indicates
|
||||||
// zero or more (..), and false indicates one or more (+).
|
// zero or more (..), and false indicates one or more (+).
|
||||||
TTSeq(Span, @~[TokenTree], Option<::parse::token::Token>, bool),
|
TTSeq(Span, @Vec<TokenTree> , Option<::parse::token::Token>, bool),
|
||||||
|
|
||||||
// a syntactic variable that will be filled in by macro expansion.
|
// a syntactic variable that will be filled in by macro expansion.
|
||||||
TTNonterminal(Span, Ident)
|
TTNonterminal(Span, Ident)
|
||||||
|
@ -673,7 +673,7 @@ pub enum Matcher_ {
|
||||||
MatchTok(::parse::token::Token),
|
MatchTok(::parse::token::Token),
|
||||||
// match repetitions of a sequence: body, separator, zero ok?,
|
// match repetitions of a sequence: body, separator, zero ok?,
|
||||||
// lo, hi position-in-match-array used:
|
// lo, hi position-in-match-array used:
|
||||||
MatchSeq(~[Matcher], Option<::parse::token::Token>, bool, uint, uint),
|
MatchSeq(Vec<Matcher> , Option<::parse::token::Token>, bool, uint, uint),
|
||||||
// parse a Rust NT: name to bind, name of NT, position in match array:
|
// parse a Rust NT: name to bind, name of NT, position in match array:
|
||||||
MatchNonterminal(Ident, Ident, uint)
|
MatchNonterminal(Ident, Ident, uint)
|
||||||
}
|
}
|
||||||
|
@ -686,7 +686,7 @@ pub type Mac = Spanned<Mac_>;
|
||||||
// There's only one flavor, now, so this could presumably be simplified.
|
// There's only one flavor, now, so this could presumably be simplified.
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub enum Mac_ {
|
pub enum Mac_ {
|
||||||
MacInvocTT(Path, ~[TokenTree], SyntaxContext), // new macro-invocation
|
MacInvocTT(Path, Vec<TokenTree> , SyntaxContext), // new macro-invocation
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
|
@ -700,7 +700,7 @@ pub type Lit = Spanned<Lit_>;
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub enum Lit_ {
|
pub enum Lit_ {
|
||||||
LitStr(InternedString, StrStyle),
|
LitStr(InternedString, StrStyle),
|
||||||
LitBinary(Rc<~[u8]>),
|
LitBinary(Rc<Vec<u8> >),
|
||||||
LitChar(u32),
|
LitChar(u32),
|
||||||
LitInt(i64, IntTy),
|
LitInt(i64, IntTy),
|
||||||
LitUint(u64, UintTy),
|
LitUint(u64, UintTy),
|
||||||
|
@ -729,7 +729,7 @@ pub struct TypeField {
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct TypeMethod {
|
pub struct TypeMethod {
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
attrs: ~[Attribute],
|
attrs: Vec<Attribute> ,
|
||||||
purity: Purity,
|
purity: Purity,
|
||||||
decl: P<FnDecl>,
|
decl: P<FnDecl>,
|
||||||
generics: Generics,
|
generics: Generics,
|
||||||
|
@ -858,7 +858,7 @@ pub enum Ty_ {
|
||||||
TyRptr(Option<Lifetime>, MutTy),
|
TyRptr(Option<Lifetime>, MutTy),
|
||||||
TyClosure(@ClosureTy),
|
TyClosure(@ClosureTy),
|
||||||
TyBareFn(@BareFnTy),
|
TyBareFn(@BareFnTy),
|
||||||
TyTup(~[P<Ty>]),
|
TyTup(Vec<P<Ty>> ),
|
||||||
TyPath(Path, Option<OptVec<TyParamBound>>, NodeId), // for #7264; see above
|
TyPath(Path, Option<OptVec<TyParamBound>>, NodeId), // for #7264; see above
|
||||||
TyTypeof(@Expr),
|
TyTypeof(@Expr),
|
||||||
// TyInfer means the type should be inferred instead of it having been
|
// TyInfer means the type should be inferred instead of it having been
|
||||||
|
@ -878,8 +878,8 @@ pub struct InlineAsm {
|
||||||
asm: InternedString,
|
asm: InternedString,
|
||||||
asm_str_style: StrStyle,
|
asm_str_style: StrStyle,
|
||||||
clobbers: InternedString,
|
clobbers: InternedString,
|
||||||
inputs: ~[(InternedString, @Expr)],
|
inputs: Vec<(InternedString, @Expr)> ,
|
||||||
outputs: ~[(InternedString, @Expr)],
|
outputs: Vec<(InternedString, @Expr)> ,
|
||||||
volatile: bool,
|
volatile: bool,
|
||||||
alignstack: bool,
|
alignstack: bool,
|
||||||
dialect: AsmDialect
|
dialect: AsmDialect
|
||||||
|
@ -914,7 +914,7 @@ impl Arg {
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct FnDecl {
|
pub struct FnDecl {
|
||||||
inputs: ~[Arg],
|
inputs: Vec<Arg> ,
|
||||||
output: P<Ty>,
|
output: P<Ty>,
|
||||||
cf: RetStyle,
|
cf: RetStyle,
|
||||||
variadic: bool
|
variadic: bool
|
||||||
|
@ -957,7 +957,7 @@ pub type ExplicitSelf = Spanned<ExplicitSelf_>;
|
||||||
#[deriving(Eq, Encodable, Decodable, Hash)]
|
#[deriving(Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct Method {
|
pub struct Method {
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
attrs: ~[Attribute],
|
attrs: Vec<Attribute> ,
|
||||||
generics: Generics,
|
generics: Generics,
|
||||||
explicit_self: ExplicitSelf,
|
explicit_self: ExplicitSelf,
|
||||||
purity: Purity,
|
purity: Purity,
|
||||||
|
@ -970,15 +970,15 @@ pub struct Method {
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct Mod {
|
pub struct Mod {
|
||||||
view_items: ~[ViewItem],
|
view_items: Vec<ViewItem> ,
|
||||||
items: ~[@Item],
|
items: Vec<@Item> ,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct ForeignMod {
|
pub struct ForeignMod {
|
||||||
abis: AbiSet,
|
abis: AbiSet,
|
||||||
view_items: ~[ViewItem],
|
view_items: Vec<ViewItem> ,
|
||||||
items: ~[@ForeignItem],
|
items: Vec<@ForeignItem> ,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
|
@ -989,19 +989,19 @@ pub struct VariantArg {
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub enum VariantKind {
|
pub enum VariantKind {
|
||||||
TupleVariantKind(~[VariantArg]),
|
TupleVariantKind(Vec<VariantArg> ),
|
||||||
StructVariantKind(@StructDef),
|
StructVariantKind(@StructDef),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct EnumDef {
|
pub struct EnumDef {
|
||||||
variants: ~[P<Variant>],
|
variants: Vec<P<Variant>> ,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct Variant_ {
|
pub struct Variant_ {
|
||||||
name: Ident,
|
name: Ident,
|
||||||
attrs: ~[Attribute],
|
attrs: Vec<Attribute> ,
|
||||||
kind: VariantKind,
|
kind: VariantKind,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
disr_expr: Option<@Expr>,
|
disr_expr: Option<@Expr>,
|
||||||
|
@ -1034,13 +1034,13 @@ pub enum ViewPath_ {
|
||||||
ViewPathGlob(Path, NodeId),
|
ViewPathGlob(Path, NodeId),
|
||||||
|
|
||||||
// foo::bar::{a,b,c}
|
// foo::bar::{a,b,c}
|
||||||
ViewPathList(Path, ~[PathListIdent], NodeId)
|
ViewPathList(Path, Vec<PathListIdent> , NodeId)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct ViewItem {
|
pub struct ViewItem {
|
||||||
node: ViewItem_,
|
node: ViewItem_,
|
||||||
attrs: ~[Attribute],
|
attrs: Vec<Attribute> ,
|
||||||
vis: Visibility,
|
vis: Visibility,
|
||||||
span: Span,
|
span: Span,
|
||||||
}
|
}
|
||||||
|
@ -1052,7 +1052,7 @@ pub enum ViewItem_ {
|
||||||
// (containing arbitrary characters) from which to fetch the crate sources
|
// (containing arbitrary characters) from which to fetch the crate sources
|
||||||
// For example, extern crate whatever = "github.com/mozilla/rust"
|
// For example, extern crate whatever = "github.com/mozilla/rust"
|
||||||
ViewItemExternMod(Ident, Option<(InternedString,StrStyle)>, NodeId),
|
ViewItemExternMod(Ident, Option<(InternedString,StrStyle)>, NodeId),
|
||||||
ViewItemUse(~[@ViewPath]),
|
ViewItemUse(Vec<@ViewPath> ),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meta-data associated with an item
|
// Meta-data associated with an item
|
||||||
|
@ -1109,7 +1109,7 @@ pub struct StructField_ {
|
||||||
kind: StructFieldKind,
|
kind: StructFieldKind,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
ty: P<Ty>,
|
ty: P<Ty>,
|
||||||
attrs: ~[Attribute],
|
attrs: Vec<Attribute> ,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type StructField = Spanned<StructField_>;
|
pub type StructField = Spanned<StructField_>;
|
||||||
|
@ -1122,7 +1122,7 @@ pub enum StructFieldKind {
|
||||||
|
|
||||||
#[deriving(Eq, Encodable, Decodable, Hash)]
|
#[deriving(Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct StructDef {
|
pub struct StructDef {
|
||||||
fields: ~[StructField], /* fields, not including ctor */
|
fields: Vec<StructField> , /* fields, not including ctor */
|
||||||
/* ID of the constructor. This is only used for tuple- or enum-like
|
/* ID of the constructor. This is only used for tuple- or enum-like
|
||||||
* structs. */
|
* structs. */
|
||||||
ctor_id: Option<NodeId>
|
ctor_id: Option<NodeId>
|
||||||
|
@ -1135,7 +1135,7 @@ pub struct StructDef {
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct Item {
|
pub struct Item {
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
attrs: ~[Attribute],
|
attrs: Vec<Attribute> ,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
node: Item_,
|
node: Item_,
|
||||||
vis: Visibility,
|
vis: Visibility,
|
||||||
|
@ -1151,11 +1151,11 @@ pub enum Item_ {
|
||||||
ItemTy(P<Ty>, Generics),
|
ItemTy(P<Ty>, Generics),
|
||||||
ItemEnum(EnumDef, Generics),
|
ItemEnum(EnumDef, Generics),
|
||||||
ItemStruct(@StructDef, Generics),
|
ItemStruct(@StructDef, Generics),
|
||||||
ItemTrait(Generics, ~[TraitRef], ~[TraitMethod]),
|
ItemTrait(Generics, Vec<TraitRef> , Vec<TraitMethod> ),
|
||||||
ItemImpl(Generics,
|
ItemImpl(Generics,
|
||||||
Option<TraitRef>, // (optional) trait this impl implements
|
Option<TraitRef>, // (optional) trait this impl implements
|
||||||
P<Ty>, // self
|
P<Ty>, // self
|
||||||
~[@Method]),
|
Vec<@Method> ),
|
||||||
// a macro invocation (which includes macro definition)
|
// a macro invocation (which includes macro definition)
|
||||||
ItemMac(Mac),
|
ItemMac(Mac),
|
||||||
}
|
}
|
||||||
|
@ -1163,7 +1163,7 @@ pub enum Item_ {
|
||||||
#[deriving(Eq, Encodable, Decodable, Hash)]
|
#[deriving(Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct ForeignItem {
|
pub struct ForeignItem {
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
attrs: ~[Attribute],
|
attrs: Vec<Attribute> ,
|
||||||
node: ForeignItem_,
|
node: ForeignItem_,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -1205,9 +1205,9 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn check_asts_encodable() {
|
fn check_asts_encodable() {
|
||||||
let e = Crate {
|
let e = Crate {
|
||||||
module: Mod {view_items: ~[], items: ~[]},
|
module: Mod {view_items: Vec::new(), items: Vec::new()},
|
||||||
attrs: ~[],
|
attrs: Vec::new(),
|
||||||
config: ~[],
|
config: Vec::new(),
|
||||||
span: Span {
|
span: Span {
|
||||||
lo: BytePos(10),
|
lo: BytePos(10),
|
||||||
hi: BytePos(20),
|
hi: BytePos(20),
|
||||||
|
|
|
@ -134,7 +134,7 @@ enum MapEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InlinedParent {
|
struct InlinedParent {
|
||||||
path: ~[PathElem],
|
path: Vec<PathElem> ,
|
||||||
// Required by NodeTraitMethod and NodeMethod.
|
// Required by NodeTraitMethod and NodeMethod.
|
||||||
def_id: DefId
|
def_id: DefId
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,7 @@ pub struct Map {
|
||||||
///
|
///
|
||||||
/// Also, indexing is pretty quick when you've got a vector and
|
/// Also, indexing is pretty quick when you've got a vector and
|
||||||
/// plain old integers.
|
/// plain old integers.
|
||||||
priv map: RefCell<~[MapEntry]>
|
priv map: RefCell<Vec<MapEntry> >
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Map {
|
impl Map {
|
||||||
|
@ -522,7 +522,7 @@ impl<'a, F: FoldOps> Folder for Ctx<'a, F> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn map_crate<F: FoldOps>(krate: Crate, fold_ops: F) -> (Crate, Map) {
|
pub fn map_crate<F: FoldOps>(krate: Crate, fold_ops: F) -> (Crate, Map) {
|
||||||
let map = Map { map: RefCell::new(~[]) };
|
let map = Map { map: RefCell::new(Vec::new()) };
|
||||||
let krate = {
|
let krate = {
|
||||||
let mut cx = Ctx {
|
let mut cx = Ctx {
|
||||||
map: &map,
|
map: &map,
|
||||||
|
@ -557,7 +557,7 @@ pub fn map_crate<F: FoldOps>(krate: Crate, fold_ops: F) -> (Crate, Map) {
|
||||||
// crate. The `path` should be the path to the item but should not include
|
// crate. The `path` should be the path to the item but should not include
|
||||||
// the item itself.
|
// the item itself.
|
||||||
pub fn map_decoded_item<F: FoldOps>(map: &Map,
|
pub fn map_decoded_item<F: FoldOps>(map: &Map,
|
||||||
path: ~[PathElem],
|
path: Vec<PathElem> ,
|
||||||
fold_ops: F,
|
fold_ops: F,
|
||||||
fold: |&mut Ctx<F>| -> InlinedItem)
|
fold: |&mut Ctx<F>| -> InlinedItem)
|
||||||
-> InlinedItem {
|
-> InlinedItem {
|
||||||
|
|
|
@ -180,8 +180,8 @@ pub fn is_call_expr(e: @Expr) -> bool {
|
||||||
|
|
||||||
pub fn block_from_expr(e: @Expr) -> P<Block> {
|
pub fn block_from_expr(e: @Expr) -> P<Block> {
|
||||||
P(Block {
|
P(Block {
|
||||||
view_items: ~[],
|
view_items: Vec::new(),
|
||||||
stmts: ~[],
|
stmts: Vec::new(),
|
||||||
expr: Some(e),
|
expr: Some(e),
|
||||||
id: e.id,
|
id: e.id,
|
||||||
rules: DefaultBlock,
|
rules: DefaultBlock,
|
||||||
|
@ -193,13 +193,13 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path {
|
||||||
ast::Path {
|
ast::Path {
|
||||||
span: s,
|
span: s,
|
||||||
global: false,
|
global: false,
|
||||||
segments: ~[
|
segments: vec!(
|
||||||
ast::PathSegment {
|
ast::PathSegment {
|
||||||
identifier: identifier,
|
identifier: identifier,
|
||||||
lifetimes: opt_vec::Empty,
|
lifetimes: opt_vec::Empty,
|
||||||
types: opt_vec::Empty,
|
types: opt_vec::Empty,
|
||||||
}
|
}
|
||||||
],
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ pub fn is_unguarded(a: &Arm) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unguarded_pat(a: &Arm) -> Option<~[@Pat]> {
|
pub fn unguarded_pat(a: &Arm) -> Option<Vec<@Pat> > {
|
||||||
if is_unguarded(a) {
|
if is_unguarded(a) {
|
||||||
Some(/* FIXME (#2543) */ a.pats.clone())
|
Some(/* FIXME (#2543) */ a.pats.clone())
|
||||||
} else {
|
} else {
|
||||||
|
@ -241,7 +241,7 @@ pub fn impl_pretty_name(trait_ref: &Option<TraitRef>, ty: &Ty) -> Ident {
|
||||||
token::gensym_ident(pretty)
|
token::gensym_ident(pretty)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn public_methods(ms: ~[@Method]) -> ~[@Method] {
|
pub fn public_methods(ms: Vec<@Method> ) -> Vec<@Method> {
|
||||||
ms.move_iter().filter(|m| {
|
ms.move_iter().filter(|m| {
|
||||||
match m.vis {
|
match m.vis {
|
||||||
Public => true,
|
Public => true,
|
||||||
|
@ -271,9 +271,9 @@ pub fn trait_method_to_ty_method(method: &TraitMethod) -> TypeMethod {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn split_trait_methods(trait_methods: &[TraitMethod])
|
pub fn split_trait_methods(trait_methods: &[TraitMethod])
|
||||||
-> (~[TypeMethod], ~[@Method]) {
|
-> (Vec<TypeMethod> , Vec<@Method> ) {
|
||||||
let mut reqd = ~[];
|
let mut reqd = Vec::new();
|
||||||
let mut provd = ~[];
|
let mut provd = Vec::new();
|
||||||
for trt_method in trait_methods.iter() {
|
for trt_method in trait_methods.iter() {
|
||||||
match *trt_method {
|
match *trt_method {
|
||||||
Required(ref tm) => reqd.push((*tm).clone()),
|
Required(ref tm) => reqd.push((*tm).clone()),
|
||||||
|
@ -724,7 +724,7 @@ pub fn new_rename_internal(id: Ident,
|
||||||
// FIXME #8215 : currently pub to allow testing
|
// FIXME #8215 : currently pub to allow testing
|
||||||
pub fn new_sctable_internal() -> SCTable {
|
pub fn new_sctable_internal() -> SCTable {
|
||||||
SCTable {
|
SCTable {
|
||||||
table: RefCell::new(~[EmptyCtxt,IllegalCtxt]),
|
table: RefCell::new(vec!(EmptyCtxt,IllegalCtxt)),
|
||||||
mark_memo: RefCell::new(HashMap::new()),
|
mark_memo: RefCell::new(HashMap::new()),
|
||||||
rename_memo: RefCell::new(HashMap::new()),
|
rename_memo: RefCell::new(HashMap::new()),
|
||||||
}
|
}
|
||||||
|
@ -754,7 +754,7 @@ pub fn display_sctable(table : &SCTable) {
|
||||||
|
|
||||||
|
|
||||||
/// Add a value to the end of a vec, return its index
|
/// Add a value to the end of a vec, return its index
|
||||||
fn idx_push<T>(vec: &mut ~[T], val: T) -> u32 {
|
fn idx_push<T>(vec: &mut Vec<T> , val: T) -> u32 {
|
||||||
vec.push(val);
|
vec.push(val);
|
||||||
(vec.len() - 1) as u32
|
(vec.len() - 1) as u32
|
||||||
}
|
}
|
||||||
|
@ -831,15 +831,15 @@ pub fn resolve_internal(id : Ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compute the marks associated with a syntax context.
|
/// Compute the marks associated with a syntax context.
|
||||||
pub fn mtwt_marksof(ctxt: SyntaxContext, stopname: Name) -> ~[Mrk] {
|
pub fn mtwt_marksof(ctxt: SyntaxContext, stopname: Name) -> Vec<Mrk> {
|
||||||
marksof(ctxt, stopname, get_sctable())
|
marksof(ctxt, stopname, get_sctable())
|
||||||
}
|
}
|
||||||
|
|
||||||
// the internal function for computing marks
|
// the internal function for computing marks
|
||||||
// it's not clear to me whether it's better to use a [] mutable
|
// it's not clear to me whether it's better to use a [] mutable
|
||||||
// vector or a cons-list for this.
|
// vector or a cons-list for this.
|
||||||
pub fn marksof(ctxt: SyntaxContext, stopname: Name, table: &SCTable) -> ~[Mrk] {
|
pub fn marksof(ctxt: SyntaxContext, stopname: Name, table: &SCTable) -> Vec<Mrk> {
|
||||||
let mut result = ~[];
|
let mut result = Vec::new();
|
||||||
let mut loopvar = ctxt;
|
let mut loopvar = ctxt;
|
||||||
loop {
|
loop {
|
||||||
let table_entry = {
|
let table_entry = {
|
||||||
|
@ -881,7 +881,7 @@ pub fn mtwt_outer_mark(ctxt: SyntaxContext) -> Mrk {
|
||||||
|
|
||||||
/// Push a name... unless it matches the one on top, in which
|
/// Push a name... unless it matches the one on top, in which
|
||||||
/// case pop and discard (so two of the same marks cancel)
|
/// case pop and discard (so two of the same marks cancel)
|
||||||
pub fn xorPush(marks: &mut ~[Mrk], mark: Mrk) {
|
pub fn xorPush(marks: &mut Vec<Mrk> , mark: Mrk) {
|
||||||
if (marks.len() > 0) && (getLast(marks) == mark) {
|
if (marks.len() > 0) && (getLast(marks) == mark) {
|
||||||
marks.pop().unwrap();
|
marks.pop().unwrap();
|
||||||
} else {
|
} else {
|
||||||
|
@ -891,7 +891,7 @@ pub fn xorPush(marks: &mut ~[Mrk], mark: Mrk) {
|
||||||
|
|
||||||
// get the last element of a mutable array.
|
// get the last element of a mutable array.
|
||||||
// FIXME #4903: , must be a separate procedure for now.
|
// FIXME #4903: , must be a separate procedure for now.
|
||||||
pub fn getLast(arr: &~[Mrk]) -> Mrk {
|
pub fn getLast(arr: &Vec<Mrk> ) -> Mrk {
|
||||||
*arr.last().unwrap()
|
*arr.last().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -956,21 +956,21 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test] fn xorpush_test () {
|
#[test] fn xorpush_test () {
|
||||||
let mut s = ~[];
|
let mut s = Vec::new();
|
||||||
xorPush(&mut s, 14);
|
xorPush(&mut s, 14);
|
||||||
assert_eq!(s.clone(), ~[14]);
|
assert_eq!(s.clone(), vec!(14));
|
||||||
xorPush(&mut s, 14);
|
xorPush(&mut s, 14);
|
||||||
assert_eq!(s.clone(), ~[]);
|
assert_eq!(s.clone(), Vec::new());
|
||||||
xorPush(&mut s, 14);
|
xorPush(&mut s, 14);
|
||||||
assert_eq!(s.clone(), ~[14]);
|
assert_eq!(s.clone(), vec!(14));
|
||||||
xorPush(&mut s, 15);
|
xorPush(&mut s, 15);
|
||||||
assert_eq!(s.clone(), ~[14, 15]);
|
assert_eq!(s.clone(), vec!(14, 15));
|
||||||
xorPush(&mut s, 16);
|
xorPush(&mut s, 16);
|
||||||
assert_eq!(s.clone(), ~[14, 15, 16]);
|
assert_eq!(s.clone(), vec!(14, 15, 16));
|
||||||
xorPush(&mut s, 16);
|
xorPush(&mut s, 16);
|
||||||
assert_eq!(s.clone(), ~[14, 15]);
|
assert_eq!(s.clone(), vec!(14, 15));
|
||||||
xorPush(&mut s, 15);
|
xorPush(&mut s, 15);
|
||||||
assert_eq!(s.clone(), ~[14]);
|
assert_eq!(s.clone(), vec!(14));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id(n: Name, s: SyntaxContext) -> Ident {
|
fn id(n: Name, s: SyntaxContext) -> Ident {
|
||||||
|
@ -987,7 +987,7 @@ mod test {
|
||||||
|
|
||||||
// unfold a vector of TestSC values into a SCTable,
|
// unfold a vector of TestSC values into a SCTable,
|
||||||
// returning the resulting index
|
// returning the resulting index
|
||||||
fn unfold_test_sc(tscs : ~[TestSC], tail: SyntaxContext, table: &SCTable)
|
fn unfold_test_sc(tscs : Vec<TestSC> , tail: SyntaxContext, table: &SCTable)
|
||||||
-> SyntaxContext {
|
-> SyntaxContext {
|
||||||
tscs.rev_iter().fold(tail, |tail : SyntaxContext, tsc : &TestSC|
|
tscs.rev_iter().fold(tail, |tail : SyntaxContext, tsc : &TestSC|
|
||||||
{match *tsc {
|
{match *tsc {
|
||||||
|
@ -996,8 +996,8 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
// gather a SyntaxContext back into a vector of TestSCs
|
// gather a SyntaxContext back into a vector of TestSCs
|
||||||
fn refold_test_sc(mut sc: SyntaxContext, table : &SCTable) -> ~[TestSC] {
|
fn refold_test_sc(mut sc: SyntaxContext, table : &SCTable) -> Vec<TestSC> {
|
||||||
let mut result = ~[];
|
let mut result = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
let table = table.table.borrow();
|
let table = table.table.borrow();
|
||||||
match table.get()[sc] {
|
match table.get()[sc] {
|
||||||
|
@ -1020,7 +1020,7 @@ mod test {
|
||||||
#[test] fn test_unfold_refold(){
|
#[test] fn test_unfold_refold(){
|
||||||
let mut t = new_sctable_internal();
|
let mut t = new_sctable_internal();
|
||||||
|
|
||||||
let test_sc = ~[M(3),R(id(101,0),14),M(9)];
|
let test_sc = vec!(M(3),R(id(101,0),14),M(9));
|
||||||
assert_eq!(unfold_test_sc(test_sc.clone(),EMPTY_CTXT,&mut t),4);
|
assert_eq!(unfold_test_sc(test_sc.clone(),EMPTY_CTXT,&mut t),4);
|
||||||
{
|
{
|
||||||
let table = t.table.borrow();
|
let table = t.table.borrow();
|
||||||
|
@ -1033,7 +1033,7 @@ mod test {
|
||||||
|
|
||||||
// extend a syntax context with a sequence of marks given
|
// extend a syntax context with a sequence of marks given
|
||||||
// in a vector. v[0] will be the outermost mark.
|
// in a vector. v[0] will be the outermost mark.
|
||||||
fn unfold_marks(mrks: ~[Mrk], tail: SyntaxContext, table: &SCTable)
|
fn unfold_marks(mrks: Vec<Mrk> , tail: SyntaxContext, table: &SCTable)
|
||||||
-> SyntaxContext {
|
-> SyntaxContext {
|
||||||
mrks.rev_iter().fold(tail, |tail:SyntaxContext, mrk:&Mrk|
|
mrks.rev_iter().fold(tail, |tail:SyntaxContext, mrk:&Mrk|
|
||||||
{new_mark_internal(*mrk,tail,table)})
|
{new_mark_internal(*mrk,tail,table)})
|
||||||
|
@ -1042,7 +1042,7 @@ mod test {
|
||||||
#[test] fn unfold_marks_test() {
|
#[test] fn unfold_marks_test() {
|
||||||
let mut t = new_sctable_internal();
|
let mut t = new_sctable_internal();
|
||||||
|
|
||||||
assert_eq!(unfold_marks(~[3,7],EMPTY_CTXT,&mut t),3);
|
assert_eq!(unfold_marks(vec!(3,7),EMPTY_CTXT,&mut t),3);
|
||||||
{
|
{
|
||||||
let table = t.table.borrow();
|
let table = t.table.borrow();
|
||||||
assert!(table.get()[2] == Mark(7,0));
|
assert!(table.get()[2] == Mark(7,0));
|
||||||
|
@ -1054,32 +1054,32 @@ mod test {
|
||||||
let stopname = 242;
|
let stopname = 242;
|
||||||
let name1 = 243;
|
let name1 = 243;
|
||||||
let mut t = new_sctable_internal();
|
let mut t = new_sctable_internal();
|
||||||
assert_eq!(marksof (EMPTY_CTXT,stopname,&t),~[]);
|
assert_eq!(marksof (EMPTY_CTXT,stopname,&t),Vec::new());
|
||||||
// FIXME #5074: ANF'd to dodge nested calls
|
// FIXME #5074: ANF'd to dodge nested calls
|
||||||
{ let ans = unfold_marks(~[4,98],EMPTY_CTXT,&mut t);
|
{ let ans = unfold_marks(vec!(4,98),EMPTY_CTXT,&mut t);
|
||||||
assert_eq! (marksof (ans,stopname,&t),~[4,98]);}
|
assert_eq! (marksof (ans,stopname,&t),vec!(4,98));}
|
||||||
// does xoring work?
|
// does xoring work?
|
||||||
{ let ans = unfold_marks(~[5,5,16],EMPTY_CTXT,&mut t);
|
{ let ans = unfold_marks(vec!(5,5,16),EMPTY_CTXT,&mut t);
|
||||||
assert_eq! (marksof (ans,stopname,&t), ~[16]);}
|
assert_eq! (marksof (ans,stopname,&t), vec!(16));}
|
||||||
// does nested xoring work?
|
// does nested xoring work?
|
||||||
{ let ans = unfold_marks(~[5,10,10,5,16],EMPTY_CTXT,&mut t);
|
{ let ans = unfold_marks(vec!(5,10,10,5,16),EMPTY_CTXT,&mut t);
|
||||||
assert_eq! (marksof (ans, stopname,&t), ~[16]);}
|
assert_eq! (marksof (ans, stopname,&t), vec!(16));}
|
||||||
// rename where stop doesn't match:
|
// rename where stop doesn't match:
|
||||||
{ let chain = ~[M(9),
|
{ let chain = vec!(M(9),
|
||||||
R(id(name1,
|
R(id(name1,
|
||||||
new_mark_internal (4, EMPTY_CTXT,&mut t)),
|
new_mark_internal (4, EMPTY_CTXT,&mut t)),
|
||||||
100101102),
|
100101102),
|
||||||
M(14)];
|
M(14));
|
||||||
let ans = unfold_test_sc(chain,EMPTY_CTXT,&mut t);
|
let ans = unfold_test_sc(chain,EMPTY_CTXT,&mut t);
|
||||||
assert_eq! (marksof (ans, stopname, &t), ~[9,14]);}
|
assert_eq! (marksof (ans, stopname, &t), vec!(9,14));}
|
||||||
// rename where stop does match
|
// rename where stop does match
|
||||||
{ let name1sc = new_mark_internal(4, EMPTY_CTXT, &mut t);
|
{ let name1sc = new_mark_internal(4, EMPTY_CTXT, &mut t);
|
||||||
let chain = ~[M(9),
|
let chain = vec!(M(9),
|
||||||
R(id(name1, name1sc),
|
R(id(name1, name1sc),
|
||||||
stopname),
|
stopname),
|
||||||
M(14)];
|
M(14));
|
||||||
let ans = unfold_test_sc(chain,EMPTY_CTXT,&mut t);
|
let ans = unfold_test_sc(chain,EMPTY_CTXT,&mut t);
|
||||||
assert_eq! (marksof (ans, stopname, &t), ~[9]); }
|
assert_eq! (marksof (ans, stopname, &t), vec!(9)); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1090,32 +1090,32 @@ mod test {
|
||||||
// - ctxt is MT
|
// - ctxt is MT
|
||||||
assert_eq!(resolve_internal(id(a,EMPTY_CTXT),&mut t, &mut rt),a);
|
assert_eq!(resolve_internal(id(a,EMPTY_CTXT),&mut t, &mut rt),a);
|
||||||
// - simple ignored marks
|
// - simple ignored marks
|
||||||
{ let sc = unfold_marks(~[1,2,3],EMPTY_CTXT,&mut t);
|
{ let sc = unfold_marks(vec!(1,2,3),EMPTY_CTXT,&mut t);
|
||||||
assert_eq!(resolve_internal(id(a,sc),&mut t, &mut rt),a);}
|
assert_eq!(resolve_internal(id(a,sc),&mut t, &mut rt),a);}
|
||||||
// - orthogonal rename where names don't match
|
// - orthogonal rename where names don't match
|
||||||
{ let sc = unfold_test_sc(~[R(id(50,EMPTY_CTXT),51),M(12)],EMPTY_CTXT,&mut t);
|
{ let sc = unfold_test_sc(vec!(R(id(50,EMPTY_CTXT),51),M(12)),EMPTY_CTXT,&mut t);
|
||||||
assert_eq!(resolve_internal(id(a,sc),&mut t, &mut rt),a);}
|
assert_eq!(resolve_internal(id(a,sc),&mut t, &mut rt),a);}
|
||||||
// - rename where names do match, but marks don't
|
// - rename where names do match, but marks don't
|
||||||
{ let sc1 = new_mark_internal(1,EMPTY_CTXT,&mut t);
|
{ let sc1 = new_mark_internal(1,EMPTY_CTXT,&mut t);
|
||||||
let sc = unfold_test_sc(~[R(id(a,sc1),50),
|
let sc = unfold_test_sc(vec!(R(id(a,sc1),50),
|
||||||
M(1),
|
M(1),
|
||||||
M(2)],
|
M(2)),
|
||||||
EMPTY_CTXT,&mut t);
|
EMPTY_CTXT,&mut t);
|
||||||
assert_eq!(resolve_internal(id(a,sc),&mut t, &mut rt), a);}
|
assert_eq!(resolve_internal(id(a,sc),&mut t, &mut rt), a);}
|
||||||
// - rename where names and marks match
|
// - rename where names and marks match
|
||||||
{ let sc1 = unfold_test_sc(~[M(1),M(2)],EMPTY_CTXT,&mut t);
|
{ let sc1 = unfold_test_sc(vec!(M(1),M(2)),EMPTY_CTXT,&mut t);
|
||||||
let sc = unfold_test_sc(~[R(id(a,sc1),50),M(1),M(2)],EMPTY_CTXT,&mut t);
|
let sc = unfold_test_sc(vec!(R(id(a,sc1),50),M(1),M(2)),EMPTY_CTXT,&mut t);
|
||||||
assert_eq!(resolve_internal(id(a,sc),&mut t, &mut rt), 50); }
|
assert_eq!(resolve_internal(id(a,sc),&mut t, &mut rt), 50); }
|
||||||
// - rename where names and marks match by literal sharing
|
// - rename where names and marks match by literal sharing
|
||||||
{ let sc1 = unfold_test_sc(~[M(1),M(2)],EMPTY_CTXT,&mut t);
|
{ let sc1 = unfold_test_sc(vec!(M(1),M(2)),EMPTY_CTXT,&mut t);
|
||||||
let sc = unfold_test_sc(~[R(id(a,sc1),50)],sc1,&mut t);
|
let sc = unfold_test_sc(vec!(R(id(a,sc1),50)),sc1,&mut t);
|
||||||
assert_eq!(resolve_internal(id(a,sc),&mut t, &mut rt), 50); }
|
assert_eq!(resolve_internal(id(a,sc),&mut t, &mut rt), 50); }
|
||||||
// - two renames of the same var.. can only happen if you use
|
// - two renames of the same var.. can only happen if you use
|
||||||
// local-expand to prevent the inner binding from being renamed
|
// local-expand to prevent the inner binding from being renamed
|
||||||
// during the rename-pass caused by the first:
|
// during the rename-pass caused by the first:
|
||||||
println!("about to run bad test");
|
println!("about to run bad test");
|
||||||
{ let sc = unfold_test_sc(~[R(id(a,EMPTY_CTXT),50),
|
{ let sc = unfold_test_sc(vec!(R(id(a,EMPTY_CTXT),50),
|
||||||
R(id(a,EMPTY_CTXT),51)],
|
R(id(a,EMPTY_CTXT),51)),
|
||||||
EMPTY_CTXT,&mut t);
|
EMPTY_CTXT,&mut t);
|
||||||
assert_eq!(resolve_internal(id(a,sc),&mut t, &mut rt), 51); }
|
assert_eq!(resolve_internal(id(a,sc),&mut t, &mut rt), 51); }
|
||||||
// the simplest double-rename:
|
// the simplest double-rename:
|
||||||
|
@ -1126,8 +1126,8 @@ mod test {
|
||||||
let sc = new_mark_internal(9,a50_to_a51,&mut t);
|
let sc = new_mark_internal(9,a50_to_a51,&mut t);
|
||||||
assert_eq!(resolve_internal(id(a,sc),&mut t, &mut rt),51);
|
assert_eq!(resolve_internal(id(a,sc),&mut t, &mut rt),51);
|
||||||
// but mark on the inside does:
|
// but mark on the inside does:
|
||||||
let a50_to_a51_b = unfold_test_sc(~[R(id(a,a_to_a50),51),
|
let a50_to_a51_b = unfold_test_sc(vec!(R(id(a,a_to_a50),51),
|
||||||
M(9)],
|
M(9)),
|
||||||
a_to_a50,
|
a_to_a50,
|
||||||
&mut t);
|
&mut t);
|
||||||
assert_eq!(resolve_internal(id(a,a50_to_a51_b),&mut t, &mut rt),50);}
|
assert_eq!(resolve_internal(id(a,a50_to_a51_b),&mut t, &mut rt),50);}
|
||||||
|
|
|
@ -146,7 +146,7 @@ pub fn mk_name_value_item(name: InternedString, value: ast::Lit)
|
||||||
@dummy_spanned(MetaNameValue(name, value))
|
@dummy_spanned(MetaNameValue(name, value))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_list_item(name: InternedString, items: ~[@MetaItem]) -> @MetaItem {
|
pub fn mk_list_item(name: InternedString, items: Vec<@MetaItem> ) -> @MetaItem {
|
||||||
@dummy_spanned(MetaList(name, items))
|
@dummy_spanned(MetaList(name, items))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,12 +212,12 @@ pub fn last_meta_item_value_str_by_name(items: &[@MetaItem], name: &str)
|
||||||
|
|
||||||
/* Higher-level applications */
|
/* Higher-level applications */
|
||||||
|
|
||||||
pub fn sort_meta_items(items: &[@MetaItem]) -> ~[@MetaItem] {
|
pub fn sort_meta_items(items: &[@MetaItem]) -> Vec<@MetaItem> {
|
||||||
// This is sort of stupid here, but we need to sort by
|
// This is sort of stupid here, but we need to sort by
|
||||||
// human-readable strings.
|
// human-readable strings.
|
||||||
let mut v = items.iter()
|
let mut v = items.iter()
|
||||||
.map(|&mi| (mi.name(), mi))
|
.map(|&mi| (mi.name(), mi))
|
||||||
.collect::<~[(InternedString, @MetaItem)]>();
|
.collect::<Vec<(InternedString, @MetaItem)> >();
|
||||||
|
|
||||||
v.sort_by(|&(ref a, _), &(ref b, _)| a.cmp(b));
|
v.sort_by(|&(ref a, _), &(ref b, _)| a.cmp(b));
|
||||||
|
|
||||||
|
@ -239,8 +239,8 @@ pub fn sort_meta_items(items: &[@MetaItem]) -> ~[@MetaItem] {
|
||||||
* From a list of crate attributes get only the meta_items that affect crate
|
* From a list of crate attributes get only the meta_items that affect crate
|
||||||
* linkage
|
* linkage
|
||||||
*/
|
*/
|
||||||
pub fn find_linkage_metas(attrs: &[Attribute]) -> ~[@MetaItem] {
|
pub fn find_linkage_metas(attrs: &[Attribute]) -> Vec<@MetaItem> {
|
||||||
let mut result = ~[];
|
let mut result = Vec::new();
|
||||||
for attr in attrs.iter().filter(|at| at.name().equiv(&("link"))) {
|
for attr in attrs.iter().filter(|at| at.name().equiv(&("link"))) {
|
||||||
match attr.meta().node {
|
match attr.meta().node {
|
||||||
MetaList(_, ref items) => result.push_all(*items),
|
MetaList(_, ref items) => result.push_all(*items),
|
||||||
|
|
|
@ -188,8 +188,7 @@ pub type FileName = ~str;
|
||||||
pub struct FileLines
|
pub struct FileLines
|
||||||
{
|
{
|
||||||
file: @FileMap,
|
file: @FileMap,
|
||||||
lines: ~[uint]
|
lines: Vec<uint> }
|
||||||
}
|
|
||||||
|
|
||||||
/// Identifies an offset of a multi-byte character in a FileMap
|
/// Identifies an offset of a multi-byte character in a FileMap
|
||||||
pub struct MultiByteChar {
|
pub struct MultiByteChar {
|
||||||
|
@ -210,9 +209,9 @@ pub struct FileMap {
|
||||||
/// The start position of this source in the CodeMap
|
/// The start position of this source in the CodeMap
|
||||||
start_pos: BytePos,
|
start_pos: BytePos,
|
||||||
/// Locations of lines beginnings in the source code
|
/// Locations of lines beginnings in the source code
|
||||||
lines: RefCell<~[BytePos]>,
|
lines: RefCell<Vec<BytePos> >,
|
||||||
/// Locations of multi-byte characters in the source code
|
/// Locations of multi-byte characters in the source code
|
||||||
multibyte_chars: RefCell<~[MultiByteChar]>,
|
multibyte_chars: RefCell<Vec<MultiByteChar> >,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileMap {
|
impl FileMap {
|
||||||
|
@ -257,13 +256,13 @@ impl FileMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CodeMap {
|
pub struct CodeMap {
|
||||||
files: RefCell<~[@FileMap]>
|
files: RefCell<Vec<@FileMap> >
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CodeMap {
|
impl CodeMap {
|
||||||
pub fn new() -> CodeMap {
|
pub fn new() -> CodeMap {
|
||||||
CodeMap {
|
CodeMap {
|
||||||
files: RefCell::new(~[]),
|
files: RefCell::new(Vec::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,8 +277,8 @@ impl CodeMap {
|
||||||
name: filename,
|
name: filename,
|
||||||
src: src,
|
src: src,
|
||||||
start_pos: Pos::from_uint(start_pos),
|
start_pos: Pos::from_uint(start_pos),
|
||||||
lines: RefCell::new(~[]),
|
lines: RefCell::new(Vec::new()),
|
||||||
multibyte_chars: RefCell::new(~[]),
|
multibyte_chars: RefCell::new(Vec::new()),
|
||||||
};
|
};
|
||||||
|
|
||||||
files.get().push(filemap);
|
files.get().push(filemap);
|
||||||
|
@ -330,7 +329,7 @@ impl CodeMap {
|
||||||
pub fn span_to_lines(&self, sp: Span) -> @FileLines {
|
pub fn span_to_lines(&self, sp: Span) -> @FileLines {
|
||||||
let lo = self.lookup_char_pos(sp.lo);
|
let lo = self.lookup_char_pos(sp.lo);
|
||||||
let hi = self.lookup_char_pos(sp.hi);
|
let hi = self.lookup_char_pos(sp.hi);
|
||||||
let mut lines = ~[];
|
let mut lines = Vec::new();
|
||||||
for i in range(lo.line - 1u, hi.line as uint) {
|
for i in range(lo.line - 1u, hi.line as uint) {
|
||||||
lines.push(i);
|
lines.push(i);
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,7 +48,7 @@ impl fmt::Show for CrateId {
|
||||||
|
|
||||||
impl FromStr for CrateId {
|
impl FromStr for CrateId {
|
||||||
fn from_str(s: &str) -> Option<CrateId> {
|
fn from_str(s: &str) -> Option<CrateId> {
|
||||||
let pieces: ~[&str] = s.splitn('#', 1).collect();
|
let pieces: Vec<&str> = s.splitn('#', 1).collect();
|
||||||
let path = pieces[0].to_owned();
|
let path = pieces[0].to_owned();
|
||||||
|
|
||||||
if path.starts_with("/") || path.ends_with("/") ||
|
if path.starts_with("/") || path.ends_with("/") ||
|
||||||
|
@ -56,13 +56,13 @@ impl FromStr for CrateId {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let path_pieces: ~[&str] = path.rsplitn('/', 1).collect();
|
let path_pieces: Vec<&str> = path.rsplitn('/', 1).collect();
|
||||||
let inferred_name = path_pieces[0];
|
let inferred_name = path_pieces[0];
|
||||||
|
|
||||||
let (name, version) = if pieces.len() == 1 {
|
let (name, version) = if pieces.len() == 1 {
|
||||||
(inferred_name.to_owned(), None)
|
(inferred_name.to_owned(), None)
|
||||||
} else {
|
} else {
|
||||||
let hash_pieces: ~[&str] = pieces[1].splitn(':', 1).collect();
|
let hash_pieces: Vec<&str> = pieces[1].splitn(':', 1).collect();
|
||||||
let (hash_name, hash_version) = if hash_pieces.len() == 1 {
|
let (hash_name, hash_version) = if hash_pieces.len() == 1 {
|
||||||
("", hash_pieces[0])
|
("", hash_pieces[0])
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -46,8 +46,8 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
||||||
|
|
||||||
let mut asm = InternedString::new("");
|
let mut asm = InternedString::new("");
|
||||||
let mut asm_str_style = None;
|
let mut asm_str_style = None;
|
||||||
let mut outputs = ~[];
|
let mut outputs = Vec::new();
|
||||||
let mut inputs = ~[];
|
let mut inputs = Vec::new();
|
||||||
let mut cons = ~"";
|
let mut cons = ~"";
|
||||||
let mut volatile = false;
|
let mut volatile = false;
|
||||||
let mut alignstack = false;
|
let mut alignstack = false;
|
||||||
|
@ -119,7 +119,7 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Clobbers => {
|
Clobbers => {
|
||||||
let mut clobs = ~[];
|
let mut clobs = Vec::new();
|
||||||
while p.token != token::EOF &&
|
while p.token != token::EOF &&
|
||||||
p.token != token::COLON &&
|
p.token != token::COLON &&
|
||||||
p.token != token::MOD_SEP {
|
p.token != token::MOD_SEP {
|
||||||
|
|
|
@ -74,7 +74,7 @@ pub trait IdentMacroExpander {
|
||||||
cx: &mut ExtCtxt,
|
cx: &mut ExtCtxt,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
ident: ast::Ident,
|
ident: ast::Ident,
|
||||||
token_tree: ~[ast::TokenTree])
|
token_tree: Vec<ast::TokenTree> )
|
||||||
-> MacResult;
|
-> MacResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,14 +83,14 @@ impl IdentMacroExpander for BasicIdentMacroExpander {
|
||||||
cx: &mut ExtCtxt,
|
cx: &mut ExtCtxt,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
ident: ast::Ident,
|
ident: ast::Ident,
|
||||||
token_tree: ~[ast::TokenTree])
|
token_tree: Vec<ast::TokenTree> )
|
||||||
-> MacResult {
|
-> MacResult {
|
||||||
(self.expander)(cx, sp, ident, token_tree)
|
(self.expander)(cx, sp, ident, token_tree)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type IdentMacroExpanderFn =
|
pub type IdentMacroExpanderFn =
|
||||||
fn(&mut ExtCtxt, Span, ast::Ident, ~[ast::TokenTree]) -> MacResult;
|
fn(&mut ExtCtxt, Span, ast::Ident, Vec<ast::TokenTree> ) -> MacResult;
|
||||||
|
|
||||||
pub type MacroCrateRegistrationFun =
|
pub type MacroCrateRegistrationFun =
|
||||||
fn(|ast::Name, SyntaxExtension|);
|
fn(|ast::Name, SyntaxExtension|);
|
||||||
|
@ -154,13 +154,13 @@ impl BlockInfo {
|
||||||
pub fn new() -> BlockInfo {
|
pub fn new() -> BlockInfo {
|
||||||
BlockInfo {
|
BlockInfo {
|
||||||
macros_escape: false,
|
macros_escape: false,
|
||||||
pending_renames: ~[],
|
pending_renames: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// a list of ident->name renamings
|
// a list of ident->name renamings
|
||||||
pub type RenameList = ~[(ast::Ident,Name)];
|
pub type RenameList = Vec<(ast::Ident,Name)> ;
|
||||||
|
|
||||||
// The base map of methods for expanding syntax extension
|
// The base map of methods for expanding syntax extension
|
||||||
// AST nodes into full ASTs
|
// AST nodes into full ASTs
|
||||||
|
@ -271,7 +271,7 @@ pub struct MacroCrate {
|
||||||
|
|
||||||
pub trait CrateLoader {
|
pub trait CrateLoader {
|
||||||
fn load_crate(&mut self, krate: &ast::ViewItem) -> MacroCrate;
|
fn load_crate(&mut self, krate: &ast::ViewItem) -> MacroCrate;
|
||||||
fn get_exported_macros(&mut self, crate_num: ast::CrateNum) -> ~[~str];
|
fn get_exported_macros(&mut self, crate_num: ast::CrateNum) -> Vec<~str> ;
|
||||||
fn get_registrar_symbol(&mut self, crate_num: ast::CrateNum) -> Option<~str>;
|
fn get_registrar_symbol(&mut self, crate_num: ast::CrateNum) -> Option<~str>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ pub struct ExtCtxt<'a> {
|
||||||
backtrace: Option<@ExpnInfo>,
|
backtrace: Option<@ExpnInfo>,
|
||||||
loader: &'a mut CrateLoader,
|
loader: &'a mut CrateLoader,
|
||||||
|
|
||||||
mod_path: ~[ast::Ident],
|
mod_path: Vec<ast::Ident> ,
|
||||||
trace_mac: bool
|
trace_mac: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ impl<'a> ExtCtxt<'a> {
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
backtrace: None,
|
backtrace: None,
|
||||||
loader: loader,
|
loader: loader,
|
||||||
mod_path: ~[],
|
mod_path: Vec::new(),
|
||||||
trace_mac: false
|
trace_mac: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,7 +329,7 @@ impl<'a> ExtCtxt<'a> {
|
||||||
pub fn backtrace(&self) -> Option<@ExpnInfo> { self.backtrace }
|
pub fn backtrace(&self) -> Option<@ExpnInfo> { self.backtrace }
|
||||||
pub fn mod_push(&mut self, i: ast::Ident) { self.mod_path.push(i); }
|
pub fn mod_push(&mut self, i: ast::Ident) { self.mod_path.push(i); }
|
||||||
pub fn mod_pop(&mut self) { self.mod_path.pop().unwrap(); }
|
pub fn mod_pop(&mut self) { self.mod_path.pop().unwrap(); }
|
||||||
pub fn mod_path(&self) -> ~[ast::Ident] { self.mod_path.clone() }
|
pub fn mod_path(&self) -> Vec<ast::Ident> { self.mod_path.clone() }
|
||||||
pub fn bt_push(&mut self, ei: codemap::ExpnInfo) {
|
pub fn bt_push(&mut self, ei: codemap::ExpnInfo) {
|
||||||
match ei {
|
match ei {
|
||||||
ExpnInfo {call_site: cs, callee: ref callee} => {
|
ExpnInfo {call_site: cs, callee: ref callee} => {
|
||||||
|
@ -458,11 +458,11 @@ pub fn get_single_str_from_tts(cx: &ExtCtxt,
|
||||||
/// parsing error, emit a non-fatal error and return None.
|
/// parsing error, emit a non-fatal error and return None.
|
||||||
pub fn get_exprs_from_tts(cx: &ExtCtxt,
|
pub fn get_exprs_from_tts(cx: &ExtCtxt,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tts: &[ast::TokenTree]) -> Option<~[@ast::Expr]> {
|
tts: &[ast::TokenTree]) -> Option<Vec<@ast::Expr> > {
|
||||||
let mut p = parse::new_parser_from_tts(cx.parse_sess(),
|
let mut p = parse::new_parser_from_tts(cx.parse_sess(),
|
||||||
cx.cfg(),
|
cx.cfg(),
|
||||||
tts.to_owned());
|
tts.to_owned());
|
||||||
let mut es = ~[];
|
let mut es = Vec::new();
|
||||||
while p.token != token::EOF {
|
while p.token != token::EOF {
|
||||||
if es.len() != 0 && !p.eat(&token::COMMA) {
|
if es.len() != 0 && !p.eat(&token::COMMA) {
|
||||||
cx.span_err(sp, "expected token: `,`");
|
cx.span_err(sp, "expected token: `,`");
|
||||||
|
@ -507,12 +507,12 @@ impl Drop for MapChainFrame {
|
||||||
|
|
||||||
// Only generic to make it easy to test
|
// Only generic to make it easy to test
|
||||||
pub struct SyntaxEnv {
|
pub struct SyntaxEnv {
|
||||||
priv chain: ~[MapChainFrame],
|
priv chain: Vec<MapChainFrame> ,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SyntaxEnv {
|
impl SyntaxEnv {
|
||||||
pub fn new() -> SyntaxEnv {
|
pub fn new() -> SyntaxEnv {
|
||||||
let mut map = SyntaxEnv { chain: ~[] };
|
let mut map = SyntaxEnv { chain: Vec::new() };
|
||||||
map.push_frame();
|
map.push_frame();
|
||||||
map
|
map
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,14 +34,14 @@ mod syntax {
|
||||||
|
|
||||||
pub trait AstBuilder {
|
pub trait AstBuilder {
|
||||||
// paths
|
// paths
|
||||||
fn path(&self, span: Span, strs: ~[ast::Ident]) -> ast::Path;
|
fn path(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path;
|
||||||
fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path;
|
fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path;
|
||||||
fn path_global(&self, span: Span, strs: ~[ast::Ident]) -> ast::Path;
|
fn path_global(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path;
|
||||||
fn path_all(&self, sp: Span,
|
fn path_all(&self, sp: Span,
|
||||||
global: bool,
|
global: bool,
|
||||||
idents: ~[ast::Ident],
|
idents: Vec<ast::Ident> ,
|
||||||
lifetimes: OptVec<ast::Lifetime>,
|
lifetimes: OptVec<ast::Lifetime>,
|
||||||
types: ~[P<ast::Ty>])
|
types: Vec<P<ast::Ty>> )
|
||||||
-> ast::Path;
|
-> ast::Path;
|
||||||
|
|
||||||
// types
|
// types
|
||||||
|
@ -61,8 +61,8 @@ pub trait AstBuilder {
|
||||||
fn ty_infer(&self, sp: Span) -> P<ast::Ty>;
|
fn ty_infer(&self, sp: Span) -> P<ast::Ty>;
|
||||||
fn ty_nil(&self) -> P<ast::Ty>;
|
fn ty_nil(&self) -> P<ast::Ty>;
|
||||||
|
|
||||||
fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> ~[P<ast::Ty>];
|
fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> Vec<P<ast::Ty>> ;
|
||||||
fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> ~[P<ast::Ty>];
|
fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> Vec<P<ast::Ty>> ;
|
||||||
fn ty_field_imm(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::TypeField;
|
fn ty_field_imm(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::TypeField;
|
||||||
fn strip_bounds(&self, bounds: &Generics) -> Generics;
|
fn strip_bounds(&self, bounds: &Generics) -> Generics;
|
||||||
|
|
||||||
|
@ -87,11 +87,11 @@ pub trait AstBuilder {
|
||||||
-> @ast::Stmt;
|
-> @ast::Stmt;
|
||||||
|
|
||||||
// blocks
|
// blocks
|
||||||
fn block(&self, span: Span, stmts: ~[@ast::Stmt], expr: Option<@ast::Expr>) -> P<ast::Block>;
|
fn block(&self, span: Span, stmts: Vec<@ast::Stmt> , expr: Option<@ast::Expr>) -> P<ast::Block>;
|
||||||
fn block_expr(&self, expr: @ast::Expr) -> P<ast::Block>;
|
fn block_expr(&self, expr: @ast::Expr) -> P<ast::Block>;
|
||||||
fn block_all(&self, span: Span,
|
fn block_all(&self, span: Span,
|
||||||
view_items: ~[ast::ViewItem],
|
view_items: Vec<ast::ViewItem> ,
|
||||||
stmts: ~[@ast::Stmt],
|
stmts: Vec<@ast::Stmt> ,
|
||||||
expr: Option<@ast::Expr>) -> P<ast::Block>;
|
expr: Option<@ast::Expr>) -> P<ast::Block>;
|
||||||
|
|
||||||
// expressions
|
// expressions
|
||||||
|
@ -109,19 +109,19 @@ pub trait AstBuilder {
|
||||||
fn expr_addr_of(&self, sp: Span, e: @ast::Expr) -> @ast::Expr;
|
fn expr_addr_of(&self, sp: Span, e: @ast::Expr) -> @ast::Expr;
|
||||||
fn expr_mut_addr_of(&self, sp: Span, e: @ast::Expr) -> @ast::Expr;
|
fn expr_mut_addr_of(&self, sp: Span, e: @ast::Expr) -> @ast::Expr;
|
||||||
fn expr_field_access(&self, span: Span, expr: @ast::Expr, ident: ast::Ident) -> @ast::Expr;
|
fn expr_field_access(&self, span: Span, expr: @ast::Expr, ident: ast::Ident) -> @ast::Expr;
|
||||||
fn expr_call(&self, span: Span, expr: @ast::Expr, args: ~[@ast::Expr]) -> @ast::Expr;
|
fn expr_call(&self, span: Span, expr: @ast::Expr, args: Vec<@ast::Expr> ) -> @ast::Expr;
|
||||||
fn expr_call_ident(&self, span: Span, id: ast::Ident, args: ~[@ast::Expr]) -> @ast::Expr;
|
fn expr_call_ident(&self, span: Span, id: ast::Ident, args: Vec<@ast::Expr> ) -> @ast::Expr;
|
||||||
fn expr_call_global(&self, sp: Span, fn_path: ~[ast::Ident],
|
fn expr_call_global(&self, sp: Span, fn_path: Vec<ast::Ident> ,
|
||||||
args: ~[@ast::Expr]) -> @ast::Expr;
|
args: Vec<@ast::Expr> ) -> @ast::Expr;
|
||||||
fn expr_method_call(&self, span: Span,
|
fn expr_method_call(&self, span: Span,
|
||||||
expr: @ast::Expr, ident: ast::Ident,
|
expr: @ast::Expr, ident: ast::Ident,
|
||||||
args: ~[@ast::Expr]) -> @ast::Expr;
|
args: Vec<@ast::Expr> ) -> @ast::Expr;
|
||||||
fn expr_block(&self, b: P<ast::Block>) -> @ast::Expr;
|
fn expr_block(&self, b: P<ast::Block>) -> @ast::Expr;
|
||||||
fn expr_cast(&self, sp: Span, expr: @ast::Expr, ty: P<ast::Ty>) -> @ast::Expr;
|
fn expr_cast(&self, sp: Span, expr: @ast::Expr, ty: P<ast::Ty>) -> @ast::Expr;
|
||||||
|
|
||||||
fn field_imm(&self, span: Span, name: Ident, e: @ast::Expr) -> ast::Field;
|
fn field_imm(&self, span: Span, name: Ident, e: @ast::Expr) -> ast::Field;
|
||||||
fn expr_struct(&self, span: Span, path: ast::Path, fields: ~[ast::Field]) -> @ast::Expr;
|
fn expr_struct(&self, span: Span, path: ast::Path, fields: Vec<ast::Field> ) -> @ast::Expr;
|
||||||
fn expr_struct_ident(&self, span: Span, id: ast::Ident, fields: ~[ast::Field]) -> @ast::Expr;
|
fn expr_struct_ident(&self, span: Span, id: ast::Ident, fields: Vec<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;
|
||||||
|
|
||||||
|
@ -131,9 +131,9 @@ pub trait AstBuilder {
|
||||||
fn expr_bool(&self, sp: Span, value: bool) -> @ast::Expr;
|
fn expr_bool(&self, sp: Span, value: bool) -> @ast::Expr;
|
||||||
|
|
||||||
fn expr_vstore(&self, sp: Span, expr: @ast::Expr, vst: ast::ExprVstore) -> @ast::Expr;
|
fn expr_vstore(&self, sp: Span, expr: @ast::Expr, vst: ast::ExprVstore) -> @ast::Expr;
|
||||||
fn expr_vec(&self, sp: Span, exprs: ~[@ast::Expr]) -> @ast::Expr;
|
fn expr_vec(&self, sp: Span, exprs: Vec<@ast::Expr> ) -> @ast::Expr;
|
||||||
fn expr_vec_uniq(&self, sp: Span, exprs: ~[@ast::Expr]) -> @ast::Expr;
|
fn expr_vec_uniq(&self, sp: Span, exprs: Vec<@ast::Expr> ) -> @ast::Expr;
|
||||||
fn expr_vec_slice(&self, sp: Span, exprs: ~[@ast::Expr]) -> @ast::Expr;
|
fn expr_vec_slice(&self, sp: Span, exprs: Vec<@ast::Expr> ) -> @ast::Expr;
|
||||||
fn expr_str(&self, sp: Span, s: InternedString) -> @ast::Expr;
|
fn expr_str(&self, sp: Span, s: InternedString) -> @ast::Expr;
|
||||||
fn expr_str_uniq(&self, sp: Span, s: InternedString) -> @ast::Expr;
|
fn expr_str_uniq(&self, sp: Span, s: InternedString) -> @ast::Expr;
|
||||||
|
|
||||||
|
@ -152,55 +152,55 @@ pub trait AstBuilder {
|
||||||
span: Span,
|
span: Span,
|
||||||
ident: ast::Ident,
|
ident: ast::Ident,
|
||||||
bm: ast::BindingMode) -> @ast::Pat;
|
bm: ast::BindingMode) -> @ast::Pat;
|
||||||
fn pat_enum(&self, span: Span, path: ast::Path, subpats: ~[@ast::Pat]) -> @ast::Pat;
|
fn pat_enum(&self, span: Span, path: ast::Path, subpats: Vec<@ast::Pat> ) -> @ast::Pat;
|
||||||
fn pat_struct(&self, span: Span,
|
fn pat_struct(&self, span: Span,
|
||||||
path: ast::Path, field_pats: ~[ast::FieldPat]) -> @ast::Pat;
|
path: ast::Path, field_pats: Vec<ast::FieldPat> ) -> @ast::Pat;
|
||||||
|
|
||||||
fn arm(&self, span: Span, pats: ~[@ast::Pat], expr: @ast::Expr) -> ast::Arm;
|
fn arm(&self, span: Span, pats: Vec<@ast::Pat> , expr: @ast::Expr) -> ast::Arm;
|
||||||
fn arm_unreachable(&self, span: Span) -> ast::Arm;
|
fn arm_unreachable(&self, span: Span) -> ast::Arm;
|
||||||
|
|
||||||
fn expr_match(&self, span: Span, arg: @ast::Expr, arms: ~[ast::Arm]) -> @ast::Expr;
|
fn expr_match(&self, span: Span, arg: @ast::Expr, arms: Vec<ast::Arm> ) -> @ast::Expr;
|
||||||
fn expr_if(&self, span: Span,
|
fn expr_if(&self, span: Span,
|
||||||
cond: @ast::Expr, then: @ast::Expr, els: Option<@ast::Expr>) -> @ast::Expr;
|
cond: @ast::Expr, then: @ast::Expr, els: Option<@ast::Expr>) -> @ast::Expr;
|
||||||
|
|
||||||
fn lambda_fn_decl(&self, span: Span,
|
fn lambda_fn_decl(&self, span: Span,
|
||||||
fn_decl: P<ast::FnDecl>, 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 lambda(&self, span: Span, ids: Vec<ast::Ident> , blk: P<ast::Block>) -> @ast::Expr;
|
||||||
fn lambda0(&self, span: Span, blk: P<ast::Block>) -> @ast::Expr;
|
fn lambda0(&self, span: Span, blk: P<ast::Block>) -> @ast::Expr;
|
||||||
fn lambda1(&self, span: Span, blk: P<ast::Block>, ident: ast::Ident) -> @ast::Expr;
|
fn lambda1(&self, span: Span, blk: P<ast::Block>, ident: ast::Ident) -> @ast::Expr;
|
||||||
|
|
||||||
fn lambda_expr(&self, span: Span, ids: ~[ast::Ident], blk: @ast::Expr) -> @ast::Expr;
|
fn lambda_expr(&self, span: Span, ids: Vec<ast::Ident> , blk: @ast::Expr) -> @ast::Expr;
|
||||||
fn lambda_expr_0(&self, span: Span, expr: @ast::Expr) -> @ast::Expr;
|
fn lambda_expr_0(&self, span: Span, expr: @ast::Expr) -> @ast::Expr;
|
||||||
fn lambda_expr_1(&self, span: Span, expr: @ast::Expr, ident: ast::Ident) -> @ast::Expr;
|
fn lambda_expr_1(&self, span: Span, expr: @ast::Expr, ident: ast::Ident) -> @ast::Expr;
|
||||||
|
|
||||||
fn lambda_stmts(&self, span: Span, ids: ~[ast::Ident], blk: ~[@ast::Stmt]) -> @ast::Expr;
|
fn lambda_stmts(&self, span: Span, ids: Vec<ast::Ident> , blk: Vec<@ast::Stmt> ) -> @ast::Expr;
|
||||||
fn lambda_stmts_0(&self, span: Span, stmts: ~[@ast::Stmt]) -> @ast::Expr;
|
fn lambda_stmts_0(&self, span: Span, stmts: Vec<@ast::Stmt> ) -> @ast::Expr;
|
||||||
fn lambda_stmts_1(&self, span: Span, stmts: ~[@ast::Stmt], ident: ast::Ident) -> @ast::Expr;
|
fn lambda_stmts_1(&self, span: Span, stmts: Vec<@ast::Stmt> , ident: ast::Ident) -> @ast::Expr;
|
||||||
|
|
||||||
// items
|
// items
|
||||||
fn item(&self, span: Span,
|
fn item(&self, span: Span,
|
||||||
name: Ident, attrs: ~[ast::Attribute], node: ast::Item_) -> @ast::Item;
|
name: Ident, attrs: Vec<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;
|
||||||
// FIXME unused self
|
// FIXME unused self
|
||||||
fn fn_decl(&self, inputs: ~[ast::Arg], output: P<ast::Ty>) -> P<ast::FnDecl>;
|
fn fn_decl(&self, inputs: Vec<ast::Arg> , output: P<ast::Ty>) -> P<ast::FnDecl>;
|
||||||
|
|
||||||
fn item_fn_poly(&self,
|
fn item_fn_poly(&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
inputs: ~[ast::Arg],
|
inputs: Vec<ast::Arg> ,
|
||||||
output: P<ast::Ty>,
|
output: P<ast::Ty>,
|
||||||
generics: Generics,
|
generics: Generics,
|
||||||
body: P<ast::Block>) -> @ast::Item;
|
body: P<ast::Block>) -> @ast::Item;
|
||||||
fn item_fn(&self,
|
fn item_fn(&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
inputs: ~[ast::Arg],
|
inputs: Vec<ast::Arg> ,
|
||||||
output: P<ast::Ty>,
|
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: Vec<P<ast::Ty>> ) -> ast::Variant;
|
||||||
fn item_enum_poly(&self,
|
fn item_enum_poly(&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
|
@ -216,8 +216,8 @@ pub trait AstBuilder {
|
||||||
fn item_struct(&self, span: Span, name: Ident, struct_def: ast::StructDef) -> @ast::Item;
|
fn item_struct(&self, span: Span, name: Ident, struct_def: ast::StructDef) -> @ast::Item;
|
||||||
|
|
||||||
fn item_mod(&self, span: Span,
|
fn item_mod(&self, span: Span,
|
||||||
name: Ident, attrs: ~[ast::Attribute],
|
name: Ident, attrs: Vec<ast::Attribute> ,
|
||||||
vi: ~[ast::ViewItem], items: ~[@ast::Item]) -> @ast::Item;
|
vi: Vec<ast::ViewItem> , items: Vec<@ast::Item> ) -> @ast::Item;
|
||||||
|
|
||||||
fn item_ty_poly(&self,
|
fn item_ty_poly(&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -232,7 +232,7 @@ pub trait AstBuilder {
|
||||||
fn meta_list(&self,
|
fn meta_list(&self,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
name: InternedString,
|
name: InternedString,
|
||||||
mis: ~[@ast::MetaItem])
|
mis: Vec<@ast::MetaItem> )
|
||||||
-> @ast::MetaItem;
|
-> @ast::MetaItem;
|
||||||
fn meta_name_value(&self,
|
fn meta_name_value(&self,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
|
@ -241,35 +241,35 @@ pub trait AstBuilder {
|
||||||
-> @ast::MetaItem;
|
-> @ast::MetaItem;
|
||||||
|
|
||||||
fn view_use(&self, sp: Span,
|
fn view_use(&self, sp: Span,
|
||||||
vis: ast::Visibility, vp: ~[@ast::ViewPath]) -> ast::ViewItem;
|
vis: ast::Visibility, vp: Vec<@ast::ViewPath> ) -> ast::ViewItem;
|
||||||
fn view_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> ast::ViewItem;
|
fn view_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> ast::ViewItem;
|
||||||
fn view_use_simple_(&self, sp: Span, vis: ast::Visibility,
|
fn view_use_simple_(&self, sp: Span, vis: ast::Visibility,
|
||||||
ident: ast::Ident, path: ast::Path) -> ast::ViewItem;
|
ident: ast::Ident, path: ast::Path) -> ast::ViewItem;
|
||||||
fn view_use_list(&self, sp: Span, vis: ast::Visibility,
|
fn view_use_list(&self, sp: Span, vis: ast::Visibility,
|
||||||
path: ~[ast::Ident], imports: &[ast::Ident]) -> ast::ViewItem;
|
path: Vec<ast::Ident> , imports: &[ast::Ident]) -> ast::ViewItem;
|
||||||
fn view_use_glob(&self, sp: Span,
|
fn view_use_glob(&self, sp: Span,
|
||||||
vis: ast::Visibility, path: ~[ast::Ident]) -> ast::ViewItem;
|
vis: ast::Visibility, path: Vec<ast::Ident> ) -> ast::ViewItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AstBuilder for ExtCtxt<'a> {
|
impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
fn path(&self, span: Span, strs: ~[ast::Ident]) -> ast::Path {
|
fn path(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path {
|
||||||
self.path_all(span, false, strs, opt_vec::Empty, ~[])
|
self.path_all(span, false, strs, opt_vec::Empty, Vec::new())
|
||||||
}
|
}
|
||||||
fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path {
|
fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path {
|
||||||
self.path(span, ~[id])
|
self.path(span, vec!(id))
|
||||||
}
|
}
|
||||||
fn path_global(&self, span: Span, strs: ~[ast::Ident]) -> ast::Path {
|
fn path_global(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path {
|
||||||
self.path_all(span, true, strs, opt_vec::Empty, ~[])
|
self.path_all(span, true, strs, opt_vec::Empty, Vec::new())
|
||||||
}
|
}
|
||||||
fn path_all(&self,
|
fn path_all(&self,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
global: bool,
|
global: bool,
|
||||||
mut idents: ~[ast::Ident],
|
mut idents: Vec<ast::Ident> ,
|
||||||
lifetimes: OptVec<ast::Lifetime>,
|
lifetimes: OptVec<ast::Lifetime>,
|
||||||
types: ~[P<ast::Ty>])
|
types: Vec<P<ast::Ty>> )
|
||||||
-> ast::Path {
|
-> ast::Path {
|
||||||
let last_identifier = idents.pop().unwrap();
|
let last_identifier = idents.pop().unwrap();
|
||||||
let mut segments: ~[ast::PathSegment] = idents.move_iter()
|
let mut segments: Vec<ast::PathSegment> = idents.move_iter()
|
||||||
.map(|ident| {
|
.map(|ident| {
|
||||||
ast::PathSegment {
|
ast::PathSegment {
|
||||||
identifier: ident,
|
identifier: ident,
|
||||||
|
@ -335,13 +335,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
self.ty_path(
|
self.ty_path(
|
||||||
self.path_all(DUMMY_SP,
|
self.path_all(DUMMY_SP,
|
||||||
true,
|
true,
|
||||||
~[
|
vec!(
|
||||||
self.ident_of("std"),
|
self.ident_of("std"),
|
||||||
self.ident_of("option"),
|
self.ident_of("option"),
|
||||||
self.ident_of("Option")
|
self.ident_of("Option")
|
||||||
],
|
),
|
||||||
opt_vec::Empty,
|
opt_vec::Empty,
|
||||||
~[ ty ]), None)
|
vec!( ty )), None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ty_field_imm(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::TypeField {
|
fn ty_field_imm(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::TypeField {
|
||||||
|
@ -379,15 +379,15 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
// these are strange, and probably shouldn't be used outside of
|
// these are strange, and probably shouldn't be used outside of
|
||||||
// pipes. Specifically, the global version possible generates
|
// pipes. Specifically, the global version possible generates
|
||||||
// incorrect code.
|
// incorrect code.
|
||||||
fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> ~[P<ast::Ty>] {
|
fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> Vec<P<ast::Ty>> {
|
||||||
opt_vec::take_vec(
|
opt_vec::take_vec(
|
||||||
ty_params.map(|p| self.ty_ident(DUMMY_SP, p.ident)))
|
ty_params.map(|p| self.ty_ident(DUMMY_SP, p.ident)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> ~[P<ast::Ty>] {
|
fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> Vec<P<ast::Ty>> {
|
||||||
opt_vec::take_vec(
|
opt_vec::take_vec(
|
||||||
ty_params.map(|p| self.ty_path(
|
ty_params.map(|p| self.ty_path(
|
||||||
self.path_global(DUMMY_SP, ~[p.ident]), None)))
|
self.path_global(DUMMY_SP, vec!(p.ident)), None)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn strip_bounds(&self, generics: &Generics) -> Generics {
|
fn strip_bounds(&self, generics: &Generics) -> Generics {
|
||||||
|
@ -459,17 +459,17 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
@respan(sp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID))
|
@respan(sp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block(&self, span: Span, stmts: ~[@ast::Stmt], expr: Option<@Expr>) -> P<ast::Block> {
|
fn block(&self, span: Span, stmts: Vec<@ast::Stmt> , expr: Option<@Expr>) -> P<ast::Block> {
|
||||||
self.block_all(span, ~[], stmts, expr)
|
self.block_all(span, Vec::new(), stmts, expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_expr(&self, expr: @ast::Expr) -> P<ast::Block> {
|
fn block_expr(&self, expr: @ast::Expr) -> P<ast::Block> {
|
||||||
self.block_all(expr.span, ~[], ~[], Some(expr))
|
self.block_all(expr.span, Vec::new(), Vec::new(), Some(expr))
|
||||||
}
|
}
|
||||||
fn block_all(&self,
|
fn block_all(&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
view_items: ~[ast::ViewItem],
|
view_items: Vec<ast::ViewItem> ,
|
||||||
stmts: ~[@ast::Stmt],
|
stmts: Vec<@ast::Stmt> ,
|
||||||
expr: Option<@ast::Expr>) -> P<ast::Block> {
|
expr: Option<@ast::Expr>) -> P<ast::Block> {
|
||||||
P(ast::Block {
|
P(ast::Block {
|
||||||
view_items: view_items,
|
view_items: view_items,
|
||||||
|
@ -517,7 +517,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expr_field_access(&self, sp: Span, expr: @ast::Expr, ident: ast::Ident) -> @ast::Expr {
|
fn expr_field_access(&self, sp: Span, expr: @ast::Expr, ident: ast::Ident) -> @ast::Expr {
|
||||||
self.expr(sp, ast::ExprField(expr, ident, ~[]))
|
self.expr(sp, ast::ExprField(expr, ident, Vec::new()))
|
||||||
}
|
}
|
||||||
fn expr_addr_of(&self, sp: Span, e: @ast::Expr) -> @ast::Expr {
|
fn expr_addr_of(&self, sp: Span, e: @ast::Expr) -> @ast::Expr {
|
||||||
self.expr(sp, ast::ExprAddrOf(ast::MutImmutable, e))
|
self.expr(sp, ast::ExprAddrOf(ast::MutImmutable, e))
|
||||||
|
@ -526,23 +526,23 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
self.expr(sp, ast::ExprAddrOf(ast::MutMutable, e))
|
self.expr(sp, ast::ExprAddrOf(ast::MutMutable, e))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expr_call(&self, span: Span, expr: @ast::Expr, args: ~[@ast::Expr]) -> @ast::Expr {
|
fn expr_call(&self, span: Span, expr: @ast::Expr, args: Vec<@ast::Expr> ) -> @ast::Expr {
|
||||||
self.expr(span, ast::ExprCall(expr, args))
|
self.expr(span, ast::ExprCall(expr, args))
|
||||||
}
|
}
|
||||||
fn expr_call_ident(&self, span: Span, id: ast::Ident, args: ~[@ast::Expr]) -> @ast::Expr {
|
fn expr_call_ident(&self, span: Span, id: ast::Ident, args: Vec<@ast::Expr> ) -> @ast::Expr {
|
||||||
self.expr(span, ast::ExprCall(self.expr_ident(span, id), args))
|
self.expr(span, ast::ExprCall(self.expr_ident(span, id), args))
|
||||||
}
|
}
|
||||||
fn expr_call_global(&self, sp: Span, fn_path: ~[ast::Ident],
|
fn expr_call_global(&self, sp: Span, fn_path: Vec<ast::Ident> ,
|
||||||
args: ~[@ast::Expr]) -> @ast::Expr {
|
args: Vec<@ast::Expr> ) -> @ast::Expr {
|
||||||
let pathexpr = self.expr_path(self.path_global(sp, fn_path));
|
let pathexpr = self.expr_path(self.path_global(sp, fn_path));
|
||||||
self.expr_call(sp, pathexpr, args)
|
self.expr_call(sp, pathexpr, args)
|
||||||
}
|
}
|
||||||
fn expr_method_call(&self, span: Span,
|
fn expr_method_call(&self, span: Span,
|
||||||
expr: @ast::Expr,
|
expr: @ast::Expr,
|
||||||
ident: ast::Ident,
|
ident: ast::Ident,
|
||||||
mut args: ~[@ast::Expr]) -> @ast::Expr {
|
mut args: Vec<@ast::Expr> ) -> @ast::Expr {
|
||||||
args.unshift(expr);
|
args.unshift(expr);
|
||||||
self.expr(span, ast::ExprMethodCall(ident, ~[], args))
|
self.expr(span, ast::ExprMethodCall(ident, Vec::new(), args))
|
||||||
}
|
}
|
||||||
fn expr_block(&self, b: P<ast::Block>) -> @ast::Expr {
|
fn expr_block(&self, b: P<ast::Block>) -> @ast::Expr {
|
||||||
self.expr(b.span, ast::ExprBlock(b))
|
self.expr(b.span, ast::ExprBlock(b))
|
||||||
|
@ -550,11 +550,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
fn field_imm(&self, span: Span, name: Ident, e: @ast::Expr) -> ast::Field {
|
fn field_imm(&self, span: Span, name: Ident, e: @ast::Expr) -> ast::Field {
|
||||||
ast::Field { ident: respan(span, name), expr: e, span: span }
|
ast::Field { ident: respan(span, name), expr: e, span: span }
|
||||||
}
|
}
|
||||||
fn expr_struct(&self, span: Span, path: ast::Path, fields: ~[ast::Field]) -> @ast::Expr {
|
fn expr_struct(&self, span: Span, path: ast::Path, fields: Vec<ast::Field> ) -> @ast::Expr {
|
||||||
self.expr(span, ast::ExprStruct(path, fields, None))
|
self.expr(span, ast::ExprStruct(path, fields, None))
|
||||||
}
|
}
|
||||||
fn expr_struct_ident(&self, span: Span,
|
fn expr_struct_ident(&self, span: Span,
|
||||||
id: ast::Ident, fields: ~[ast::Field]) -> @ast::Expr {
|
id: ast::Ident, fields: Vec<ast::Field> ) -> @ast::Expr {
|
||||||
self.expr_struct(span, self.path_ident(span, id), fields)
|
self.expr_struct(span, self.path_ident(span, id), fields)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -577,13 +577,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
fn expr_vstore(&self, sp: Span, expr: @ast::Expr, vst: ast::ExprVstore) -> @ast::Expr {
|
fn expr_vstore(&self, sp: Span, expr: @ast::Expr, vst: ast::ExprVstore) -> @ast::Expr {
|
||||||
self.expr(sp, ast::ExprVstore(expr, vst))
|
self.expr(sp, ast::ExprVstore(expr, vst))
|
||||||
}
|
}
|
||||||
fn expr_vec(&self, sp: Span, exprs: ~[@ast::Expr]) -> @ast::Expr {
|
fn expr_vec(&self, sp: Span, exprs: Vec<@ast::Expr> ) -> @ast::Expr {
|
||||||
self.expr(sp, ast::ExprVec(exprs, ast::MutImmutable))
|
self.expr(sp, ast::ExprVec(exprs, ast::MutImmutable))
|
||||||
}
|
}
|
||||||
fn expr_vec_uniq(&self, sp: Span, exprs: ~[@ast::Expr]) -> @ast::Expr {
|
fn expr_vec_uniq(&self, sp: Span, exprs: Vec<@ast::Expr> ) -> @ast::Expr {
|
||||||
self.expr_vstore(sp, self.expr_vec(sp, exprs), ast::ExprVstoreUniq)
|
self.expr_vstore(sp, self.expr_vec(sp, exprs), ast::ExprVstoreUniq)
|
||||||
}
|
}
|
||||||
fn expr_vec_slice(&self, sp: Span, exprs: ~[@ast::Expr]) -> @ast::Expr {
|
fn expr_vec_slice(&self, sp: Span, exprs: Vec<@ast::Expr> ) -> @ast::Expr {
|
||||||
self.expr_vstore(sp, self.expr_vec(sp, exprs), ast::ExprVstoreSlice)
|
self.expr_vstore(sp, self.expr_vec(sp, exprs), ast::ExprVstoreSlice)
|
||||||
}
|
}
|
||||||
fn expr_str(&self, sp: Span, s: InternedString) -> @ast::Expr {
|
fn expr_str(&self, sp: Span, s: InternedString) -> @ast::Expr {
|
||||||
|
@ -600,20 +600,18 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
|
|
||||||
|
|
||||||
fn expr_some(&self, sp: Span, expr: @ast::Expr) -> @ast::Expr {
|
fn expr_some(&self, sp: Span, expr: @ast::Expr) -> @ast::Expr {
|
||||||
let some = ~[
|
let some = vec!(
|
||||||
self.ident_of("std"),
|
self.ident_of("std"),
|
||||||
self.ident_of("option"),
|
self.ident_of("option"),
|
||||||
self.ident_of("Some"),
|
self.ident_of("Some"));
|
||||||
];
|
self.expr_call_global(sp, some, vec!(expr))
|
||||||
self.expr_call_global(sp, some, ~[expr])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expr_none(&self, sp: Span) -> @ast::Expr {
|
fn expr_none(&self, sp: Span) -> @ast::Expr {
|
||||||
let none = self.path_global(sp, ~[
|
let none = self.path_global(sp, vec!(
|
||||||
self.ident_of("std"),
|
self.ident_of("std"),
|
||||||
self.ident_of("option"),
|
self.ident_of("option"),
|
||||||
self.ident_of("None"),
|
self.ident_of("None")));
|
||||||
]);
|
|
||||||
self.expr_path(none)
|
self.expr_path(none)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,17 +619,15 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
let loc = self.codemap().lookup_char_pos(span.lo);
|
let loc = self.codemap().lookup_char_pos(span.lo);
|
||||||
self.expr_call_global(
|
self.expr_call_global(
|
||||||
span,
|
span,
|
||||||
~[
|
vec!(
|
||||||
self.ident_of("std"),
|
self.ident_of("std"),
|
||||||
self.ident_of("rt"),
|
self.ident_of("rt"),
|
||||||
self.ident_of("begin_unwind"),
|
self.ident_of("begin_unwind")),
|
||||||
],
|
vec!(
|
||||||
~[
|
|
||||||
self.expr_str(span, msg),
|
self.expr_str(span, msg),
|
||||||
self.expr_str(span,
|
self.expr_str(span,
|
||||||
token::intern_and_get_ident(loc.file.name)),
|
token::intern_and_get_ident(loc.file.name)),
|
||||||
self.expr_uint(span, loc.line),
|
self.expr_uint(span, loc.line)))
|
||||||
])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expr_unreachable(&self, span: Span) -> @ast::Expr {
|
fn expr_unreachable(&self, span: Span) -> @ast::Expr {
|
||||||
|
@ -662,17 +658,17 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
let pat = ast::PatIdent(bm, path, None);
|
let pat = ast::PatIdent(bm, path, None);
|
||||||
self.pat(span, pat)
|
self.pat(span, pat)
|
||||||
}
|
}
|
||||||
fn pat_enum(&self, span: Span, path: ast::Path, subpats: ~[@ast::Pat]) -> @ast::Pat {
|
fn pat_enum(&self, span: Span, path: ast::Path, subpats: Vec<@ast::Pat> ) -> @ast::Pat {
|
||||||
let pat = ast::PatEnum(path, Some(subpats));
|
let pat = ast::PatEnum(path, Some(subpats));
|
||||||
self.pat(span, pat)
|
self.pat(span, pat)
|
||||||
}
|
}
|
||||||
fn pat_struct(&self, span: Span,
|
fn pat_struct(&self, span: Span,
|
||||||
path: ast::Path, field_pats: ~[ast::FieldPat]) -> @ast::Pat {
|
path: ast::Path, field_pats: Vec<ast::FieldPat> ) -> @ast::Pat {
|
||||||
let pat = ast::PatStruct(path, field_pats, false);
|
let pat = ast::PatStruct(path, field_pats, false);
|
||||||
self.pat(span, pat)
|
self.pat(span, pat)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arm(&self, _span: Span, pats: ~[@ast::Pat], expr: @ast::Expr) -> ast::Arm {
|
fn arm(&self, _span: Span, pats: Vec<@ast::Pat> , expr: @ast::Expr) -> ast::Arm {
|
||||||
ast::Arm {
|
ast::Arm {
|
||||||
pats: pats,
|
pats: pats,
|
||||||
guard: None,
|
guard: None,
|
||||||
|
@ -681,10 +677,10 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arm_unreachable(&self, span: Span) -> ast::Arm {
|
fn arm_unreachable(&self, span: Span) -> ast::Arm {
|
||||||
self.arm(span, ~[self.pat_wild(span)], self.expr_unreachable(span))
|
self.arm(span, vec!(self.pat_wild(span)), self.expr_unreachable(span))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expr_match(&self, span: Span, arg: @ast::Expr, arms: ~[ast::Arm]) -> @Expr {
|
fn expr_match(&self, span: Span, arg: @ast::Expr, arms: Vec<ast::Arm> ) -> @Expr {
|
||||||
self.expr(span, ast::ExprMatch(arg, arms))
|
self.expr(span, ast::ExprMatch(arg, arms))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,7 +694,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
fn_decl: P<ast::FnDecl>, 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))
|
self.expr(span, ast::ExprFnBlock(fn_decl, blk))
|
||||||
}
|
}
|
||||||
fn lambda(&self, span: Span, ids: ~[ast::Ident], blk: P<ast::Block>) -> @ast::Expr {
|
fn lambda(&self, span: Span, ids: Vec<ast::Ident> , blk: P<ast::Block>) -> @ast::Expr {
|
||||||
let fn_decl = self.fn_decl(
|
let fn_decl = self.fn_decl(
|
||||||
ids.map(|id| self.arg(span, *id, self.ty_infer(span))),
|
ids.map(|id| self.arg(span, *id, self.ty_infer(span))),
|
||||||
self.ty_infer(span));
|
self.ty_infer(span));
|
||||||
|
@ -715,7 +711,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
quote_expr!(self, |$ident| $blk_e )
|
quote_expr!(self, |$ident| $blk_e )
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lambda_expr(&self, span: Span, ids: ~[ast::Ident], expr: @ast::Expr) -> @ast::Expr {
|
fn lambda_expr(&self, span: Span, ids: Vec<ast::Ident> , expr: @ast::Expr) -> @ast::Expr {
|
||||||
self.lambda(span, ids, self.block_expr(expr))
|
self.lambda(span, ids, self.block_expr(expr))
|
||||||
}
|
}
|
||||||
fn lambda_expr_0(&self, span: Span, expr: @ast::Expr) -> @ast::Expr {
|
fn lambda_expr_0(&self, span: Span, expr: @ast::Expr) -> @ast::Expr {
|
||||||
|
@ -725,13 +721,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
self.lambda1(span, self.block_expr(expr), ident)
|
self.lambda1(span, self.block_expr(expr), ident)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lambda_stmts(&self, span: Span, ids: ~[ast::Ident], stmts: ~[@ast::Stmt]) -> @ast::Expr {
|
fn lambda_stmts(&self, span: Span, ids: Vec<ast::Ident> , stmts: Vec<@ast::Stmt> ) -> @ast::Expr {
|
||||||
self.lambda(span, ids, self.block(span, stmts, None))
|
self.lambda(span, ids, self.block(span, stmts, None))
|
||||||
}
|
}
|
||||||
fn lambda_stmts_0(&self, span: Span, stmts: ~[@ast::Stmt]) -> @ast::Expr {
|
fn lambda_stmts_0(&self, span: Span, stmts: Vec<@ast::Stmt> ) -> @ast::Expr {
|
||||||
self.lambda0(span, self.block(span, stmts, None))
|
self.lambda0(span, self.block(span, stmts, None))
|
||||||
}
|
}
|
||||||
fn lambda_stmts_1(&self, span: Span, stmts: ~[@ast::Stmt], ident: ast::Ident) -> @ast::Expr {
|
fn lambda_stmts_1(&self, span: Span, stmts: Vec<@ast::Stmt> , ident: ast::Ident) -> @ast::Expr {
|
||||||
self.lambda1(span, self.block(span, stmts, None), ident)
|
self.lambda1(span, self.block(span, stmts, None), ident)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -745,7 +741,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME unused self
|
// FIXME unused self
|
||||||
fn fn_decl(&self, inputs: ~[ast::Arg], output: P<ast::Ty>) -> P<ast::FnDecl> {
|
fn fn_decl(&self, inputs: Vec<ast::Arg> , output: P<ast::Ty>) -> P<ast::FnDecl> {
|
||||||
P(ast::FnDecl {
|
P(ast::FnDecl {
|
||||||
inputs: inputs,
|
inputs: inputs,
|
||||||
output: output,
|
output: output,
|
||||||
|
@ -755,7 +751,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn item(&self, span: Span,
|
fn item(&self, span: Span,
|
||||||
name: Ident, attrs: ~[ast::Attribute], node: ast::Item_) -> @ast::Item {
|
name: Ident, attrs: Vec<ast::Attribute> , node: ast::Item_) -> @ast::Item {
|
||||||
// FIXME: Would be nice if our generated code didn't violate
|
// FIXME: Would be nice if our generated code didn't violate
|
||||||
// Rust coding conventions
|
// Rust coding conventions
|
||||||
@ast::Item { ident: name,
|
@ast::Item { ident: name,
|
||||||
|
@ -769,13 +765,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
fn item_fn_poly(&self,
|
fn item_fn_poly(&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
inputs: ~[ast::Arg],
|
inputs: Vec<ast::Arg> ,
|
||||||
output: P<ast::Ty>,
|
output: P<ast::Ty>,
|
||||||
generics: Generics,
|
generics: Generics,
|
||||||
body: P<ast::Block>) -> @ast::Item {
|
body: P<ast::Block>) -> @ast::Item {
|
||||||
self.item(span,
|
self.item(span,
|
||||||
name,
|
name,
|
||||||
~[],
|
Vec::new(),
|
||||||
ast::ItemFn(self.fn_decl(inputs, output),
|
ast::ItemFn(self.fn_decl(inputs, output),
|
||||||
ast::ImpureFn,
|
ast::ImpureFn,
|
||||||
AbiSet::Rust(),
|
AbiSet::Rust(),
|
||||||
|
@ -786,7 +782,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
fn item_fn(&self,
|
fn item_fn(&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
inputs: ~[ast::Arg],
|
inputs: Vec<ast::Arg> ,
|
||||||
output: P<ast::Ty>,
|
output: P<ast::Ty>,
|
||||||
body: P<ast::Block>
|
body: P<ast::Block>
|
||||||
) -> @ast::Item {
|
) -> @ast::Item {
|
||||||
|
@ -799,7 +795,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
body)
|
body)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn variant(&self, span: Span, name: Ident, tys: ~[P<ast::Ty>]) -> ast::Variant {
|
fn variant(&self, span: Span, name: Ident, tys: Vec<P<ast::Ty>> ) -> ast::Variant {
|
||||||
let args = tys.move_iter().map(|ty| {
|
let args = tys.move_iter().map(|ty| {
|
||||||
ast::VariantArg { ty: ty, id: ast::DUMMY_NODE_ID }
|
ast::VariantArg { ty: ty, id: ast::DUMMY_NODE_ID }
|
||||||
}).collect();
|
}).collect();
|
||||||
|
@ -807,7 +803,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
respan(span,
|
respan(span,
|
||||||
ast::Variant_ {
|
ast::Variant_ {
|
||||||
name: name,
|
name: name,
|
||||||
attrs: ~[],
|
attrs: Vec::new(),
|
||||||
kind: ast::TupleVariantKind(args),
|
kind: ast::TupleVariantKind(args),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
disr_expr: None,
|
disr_expr: None,
|
||||||
|
@ -818,7 +814,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
fn item_enum_poly(&self, span: Span, name: Ident,
|
fn item_enum_poly(&self, span: Span, name: Ident,
|
||||||
enum_definition: ast::EnumDef,
|
enum_definition: ast::EnumDef,
|
||||||
generics: Generics) -> @ast::Item {
|
generics: Generics) -> @ast::Item {
|
||||||
self.item(span, name, ~[], ast::ItemEnum(enum_definition, generics))
|
self.item(span, name, Vec::new(), ast::ItemEnum(enum_definition, generics))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn item_enum(&self, span: Span, name: Ident,
|
fn item_enum(&self, span: Span, name: Ident,
|
||||||
|
@ -839,13 +835,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
|
|
||||||
fn item_struct_poly(&self, span: Span, name: Ident,
|
fn item_struct_poly(&self, span: Span, name: Ident,
|
||||||
struct_def: ast::StructDef, generics: Generics) -> @ast::Item {
|
struct_def: ast::StructDef, generics: Generics) -> @ast::Item {
|
||||||
self.item(span, name, ~[], ast::ItemStruct(@struct_def, generics))
|
self.item(span, name, Vec::new(), ast::ItemStruct(@struct_def, generics))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn item_mod(&self, span: Span, name: Ident,
|
fn item_mod(&self, span: Span, name: Ident,
|
||||||
attrs: ~[ast::Attribute],
|
attrs: Vec<ast::Attribute> ,
|
||||||
vi: ~[ast::ViewItem],
|
vi: Vec<ast::ViewItem> ,
|
||||||
items: ~[@ast::Item]) -> @ast::Item {
|
items: Vec<@ast::Item> ) -> @ast::Item {
|
||||||
self.item(
|
self.item(
|
||||||
span,
|
span,
|
||||||
name,
|
name,
|
||||||
|
@ -859,7 +855,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
|
|
||||||
fn item_ty_poly(&self, span: Span, name: Ident, ty: P<ast::Ty>,
|
fn item_ty_poly(&self, span: Span, name: Ident, ty: P<ast::Ty>,
|
||||||
generics: Generics) -> @ast::Item {
|
generics: Generics) -> @ast::Item {
|
||||||
self.item(span, name, ~[], ast::ItemTy(ty, generics))
|
self.item(span, name, Vec::new(), 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 {
|
||||||
|
@ -880,7 +876,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
fn meta_list(&self,
|
fn meta_list(&self,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
name: InternedString,
|
name: InternedString,
|
||||||
mis: ~[@ast::MetaItem])
|
mis: Vec<@ast::MetaItem> )
|
||||||
-> @ast::MetaItem {
|
-> @ast::MetaItem {
|
||||||
@respan(sp, ast::MetaList(name, mis))
|
@respan(sp, ast::MetaList(name, mis))
|
||||||
}
|
}
|
||||||
|
@ -893,10 +889,10 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view_use(&self, sp: Span,
|
fn view_use(&self, sp: Span,
|
||||||
vis: ast::Visibility, vp: ~[@ast::ViewPath]) -> ast::ViewItem {
|
vis: ast::Visibility, vp: Vec<@ast::ViewPath> ) -> ast::ViewItem {
|
||||||
ast::ViewItem {
|
ast::ViewItem {
|
||||||
node: ast::ViewItemUse(vp),
|
node: ast::ViewItemUse(vp),
|
||||||
attrs: ~[],
|
attrs: Vec::new(),
|
||||||
vis: vis,
|
vis: vis,
|
||||||
span: sp
|
span: sp
|
||||||
}
|
}
|
||||||
|
@ -910,30 +906,30 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
fn view_use_simple_(&self, sp: Span, vis: ast::Visibility,
|
fn view_use_simple_(&self, sp: Span, vis: ast::Visibility,
|
||||||
ident: ast::Ident, path: ast::Path) -> ast::ViewItem {
|
ident: ast::Ident, path: ast::Path) -> ast::ViewItem {
|
||||||
self.view_use(sp, vis,
|
self.view_use(sp, vis,
|
||||||
~[@respan(sp,
|
vec!(@respan(sp,
|
||||||
ast::ViewPathSimple(ident,
|
ast::ViewPathSimple(ident,
|
||||||
path,
|
path,
|
||||||
ast::DUMMY_NODE_ID))])
|
ast::DUMMY_NODE_ID))))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view_use_list(&self, sp: Span, vis: ast::Visibility,
|
fn view_use_list(&self, sp: Span, vis: ast::Visibility,
|
||||||
path: ~[ast::Ident], imports: &[ast::Ident]) -> ast::ViewItem {
|
path: Vec<ast::Ident> , imports: &[ast::Ident]) -> ast::ViewItem {
|
||||||
let imports = imports.map(|id| {
|
let imports = imports.map(|id| {
|
||||||
respan(sp, ast::PathListIdent_ { name: *id, id: ast::DUMMY_NODE_ID })
|
respan(sp, ast::PathListIdent_ { name: *id, id: ast::DUMMY_NODE_ID })
|
||||||
});
|
});
|
||||||
|
|
||||||
self.view_use(sp, vis,
|
self.view_use(sp, vis,
|
||||||
~[@respan(sp,
|
vec!(@respan(sp,
|
||||||
ast::ViewPathList(self.path(sp, path),
|
ast::ViewPathList(self.path(sp, path),
|
||||||
imports,
|
imports,
|
||||||
ast::DUMMY_NODE_ID))])
|
ast::DUMMY_NODE_ID))))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view_use_glob(&self, sp: Span,
|
fn view_use_glob(&self, sp: Span,
|
||||||
vis: ast::Visibility, path: ~[ast::Ident]) -> ast::ViewItem {
|
vis: ast::Visibility, path: Vec<ast::Ident> ) -> ast::ViewItem {
|
||||||
self.view_use(sp, vis,
|
self.view_use(sp, vis,
|
||||||
~[@respan(sp,
|
vec!(@respan(sp,
|
||||||
ast::ViewPathGlob(self.path(sp, path), ast::DUMMY_NODE_ID))])
|
ast::ViewPathGlob(self.path(sp, path), ast::DUMMY_NODE_ID))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) ->
|
||||||
None => return MacResult::dummy_expr(sp),
|
None => return MacResult::dummy_expr(sp),
|
||||||
Some(e) => e,
|
Some(e) => e,
|
||||||
};
|
};
|
||||||
let mut bytes = ~[];
|
let mut bytes = Vec::new();
|
||||||
|
|
||||||
for expr in exprs.iter() {
|
for expr in exprs.iter() {
|
||||||
match expr.node {
|
match expr.node {
|
||||||
|
|
|
@ -31,7 +31,7 @@ pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::M
|
||||||
cx.cfg(),
|
cx.cfg(),
|
||||||
tts.to_owned());
|
tts.to_owned());
|
||||||
|
|
||||||
let mut cfgs = ~[];
|
let mut cfgs = Vec::new();
|
||||||
// parse `cfg!(meta_item, meta_item(x,y), meta_item="foo", ...)`
|
// parse `cfg!(meta_item, meta_item(x,y), meta_item="foo", ...)`
|
||||||
while p.token != token::EOF {
|
while p.token != token::EOF {
|
||||||
cfgs.push(p.parse_meta_item());
|
cfgs.push(p.parse_meta_item());
|
||||||
|
|
|
@ -48,13 +48,13 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
||||||
ast::Path {
|
ast::Path {
|
||||||
span: sp,
|
span: sp,
|
||||||
global: false,
|
global: false,
|
||||||
segments: ~[
|
segments: vec!(
|
||||||
ast::PathSegment {
|
ast::PathSegment {
|
||||||
identifier: res,
|
identifier: res,
|
||||||
lifetimes: opt_vec::Empty,
|
lifetimes: opt_vec::Empty,
|
||||||
types: opt_vec::Empty,
|
types: opt_vec::Empty,
|
||||||
}
|
}
|
||||||
]
|
)
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
span: sp,
|
span: sp,
|
||||||
|
|
|
@ -21,22 +21,22 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
|
||||||
push: |@Item|) {
|
push: |@Item|) {
|
||||||
let trait_def = TraitDef {
|
let trait_def = TraitDef {
|
||||||
span: span,
|
span: span,
|
||||||
attributes: ~[],
|
attributes: Vec::new(),
|
||||||
path: Path::new(~["std", "clone", "Clone"]),
|
path: Path::new(vec!("std", "clone", "Clone")),
|
||||||
additional_bounds: ~[],
|
additional_bounds: Vec::new(),
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
methods: ~[
|
methods: vec!(
|
||||||
MethodDef {
|
MethodDef {
|
||||||
name: "clone",
|
name: "clone",
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
explicit_self: borrowed_explicit_self(),
|
explicit_self: borrowed_explicit_self(),
|
||||||
args: ~[],
|
args: Vec::new(),
|
||||||
ret_ty: Self,
|
ret_ty: Self,
|
||||||
inline: true,
|
inline: true,
|
||||||
const_nonmatching: false,
|
const_nonmatching: false,
|
||||||
combine_substructure: |c, s, sub| cs_clone("Clone", c, s, sub)
|
combine_substructure: |c, s, sub| cs_clone("Clone", c, s, sub)
|
||||||
}
|
}
|
||||||
]
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
trait_def.expand(cx, mitem, item, push)
|
trait_def.expand(cx, mitem, item, push)
|
||||||
|
@ -49,16 +49,16 @@ pub fn expand_deriving_deep_clone(cx: &mut ExtCtxt,
|
||||||
push: |@Item|) {
|
push: |@Item|) {
|
||||||
let trait_def = TraitDef {
|
let trait_def = TraitDef {
|
||||||
span: span,
|
span: span,
|
||||||
attributes: ~[],
|
attributes: Vec::new(),
|
||||||
path: Path::new(~["std", "clone", "DeepClone"]),
|
path: Path::new(vec!("std", "clone", "DeepClone")),
|
||||||
additional_bounds: ~[],
|
additional_bounds: Vec::new(),
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
methods: ~[
|
methods: vec!(
|
||||||
MethodDef {
|
MethodDef {
|
||||||
name: "deep_clone",
|
name: "deep_clone",
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
explicit_self: borrowed_explicit_self(),
|
explicit_self: borrowed_explicit_self(),
|
||||||
args: ~[],
|
args: Vec::new(),
|
||||||
ret_ty: Self,
|
ret_ty: Self,
|
||||||
inline: true,
|
inline: true,
|
||||||
const_nonmatching: false,
|
const_nonmatching: false,
|
||||||
|
@ -66,7 +66,7 @@ pub fn expand_deriving_deep_clone(cx: &mut ExtCtxt,
|
||||||
// call deep_clone (not clone) here.
|
// call deep_clone (not clone) here.
|
||||||
combine_substructure: |c, s, sub| cs_clone("DeepClone", c, s, sub)
|
combine_substructure: |c, s, sub| cs_clone("DeepClone", c, s, sub)
|
||||||
}
|
}
|
||||||
]
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
trait_def.expand(cx, mitem, item, push)
|
trait_def.expand(cx, mitem, item, push)
|
||||||
|
@ -80,7 +80,7 @@ fn cs_clone(
|
||||||
let ctor_ident;
|
let ctor_ident;
|
||||||
let all_fields;
|
let all_fields;
|
||||||
let subcall = |field: &FieldInfo|
|
let subcall = |field: &FieldInfo|
|
||||||
cx.expr_method_call(field.span, field.self_, clone_ident, ~[]);
|
cx.expr_method_call(field.span, field.self_, clone_ident, Vec::new());
|
||||||
|
|
||||||
match *substr.fields {
|
match *substr.fields {
|
||||||
Struct(ref af) => {
|
Struct(ref af) => {
|
||||||
|
|
|
@ -36,8 +36,8 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
|
||||||
name: $name,
|
name: $name,
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
explicit_self: borrowed_explicit_self(),
|
explicit_self: borrowed_explicit_self(),
|
||||||
args: ~[borrowed_self()],
|
args: vec!(borrowed_self()),
|
||||||
ret_ty: Literal(Path::new(~["bool"])),
|
ret_ty: Literal(Path::new(vec!("bool"))),
|
||||||
inline: true,
|
inline: true,
|
||||||
const_nonmatching: true,
|
const_nonmatching: true,
|
||||||
combine_substructure: $f
|
combine_substructure: $f
|
||||||
|
@ -47,14 +47,14 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
|
||||||
|
|
||||||
let trait_def = TraitDef {
|
let trait_def = TraitDef {
|
||||||
span: span,
|
span: span,
|
||||||
attributes: ~[],
|
attributes: Vec::new(),
|
||||||
path: Path::new(~["std", "cmp", "Eq"]),
|
path: Path::new(vec!("std", "cmp", "Eq")),
|
||||||
additional_bounds: ~[],
|
additional_bounds: Vec::new(),
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
methods: ~[
|
methods: vec!(
|
||||||
md!("eq", cs_eq),
|
md!("eq", cs_eq),
|
||||||
md!("ne", cs_ne)
|
md!("ne", cs_ne)
|
||||||
]
|
)
|
||||||
};
|
};
|
||||||
trait_def.expand(cx, mitem, item, push)
|
trait_def.expand(cx, mitem, item, push)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,8 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
|
||||||
name: $name,
|
name: $name,
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
explicit_self: borrowed_explicit_self(),
|
explicit_self: borrowed_explicit_self(),
|
||||||
args: ~[borrowed_self()],
|
args: vec!(borrowed_self()),
|
||||||
ret_ty: Literal(Path::new(~["bool"])),
|
ret_ty: Literal(Path::new(vec!("bool"))),
|
||||||
inline: true,
|
inline: true,
|
||||||
const_nonmatching: false,
|
const_nonmatching: false,
|
||||||
combine_substructure: |cx, span, substr| cs_op($op, $equal, cx, span, substr)
|
combine_substructure: |cx, span, substr| cs_op($op, $equal, cx, span, substr)
|
||||||
|
@ -37,16 +37,16 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
|
||||||
|
|
||||||
let trait_def = TraitDef {
|
let trait_def = TraitDef {
|
||||||
span: span,
|
span: span,
|
||||||
attributes: ~[],
|
attributes: Vec::new(),
|
||||||
path: Path::new(~["std", "cmp", "Ord"]),
|
path: Path::new(vec!("std", "cmp", "Ord")),
|
||||||
additional_bounds: ~[],
|
additional_bounds: Vec::new(),
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
methods: ~[
|
methods: vec!(
|
||||||
md!("lt", true, false),
|
md!("lt", true, false),
|
||||||
md!("le", true, true),
|
md!("le", true, true),
|
||||||
md!("gt", false, false),
|
md!("gt", false, false),
|
||||||
md!("ge", false, true)
|
md!("ge", false, true)
|
||||||
]
|
)
|
||||||
};
|
};
|
||||||
trait_def.expand(cx, mitem, item, push)
|
trait_def.expand(cx, mitem, item, push)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,22 +26,22 @@ pub fn expand_deriving_totaleq(cx: &mut ExtCtxt,
|
||||||
|
|
||||||
let trait_def = TraitDef {
|
let trait_def = TraitDef {
|
||||||
span: span,
|
span: span,
|
||||||
attributes: ~[],
|
attributes: Vec::new(),
|
||||||
path: Path::new(~["std", "cmp", "TotalEq"]),
|
path: Path::new(vec!("std", "cmp", "TotalEq")),
|
||||||
additional_bounds: ~[],
|
additional_bounds: Vec::new(),
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
methods: ~[
|
methods: vec!(
|
||||||
MethodDef {
|
MethodDef {
|
||||||
name: "equals",
|
name: "equals",
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
explicit_self: borrowed_explicit_self(),
|
explicit_self: borrowed_explicit_self(),
|
||||||
args: ~[borrowed_self()],
|
args: vec!(borrowed_self()),
|
||||||
ret_ty: Literal(Path::new(~["bool"])),
|
ret_ty: Literal(Path::new(vec!("bool"))),
|
||||||
inline: true,
|
inline: true,
|
||||||
const_nonmatching: true,
|
const_nonmatching: true,
|
||||||
combine_substructure: cs_equals
|
combine_substructure: cs_equals
|
||||||
}
|
}
|
||||||
]
|
)
|
||||||
};
|
};
|
||||||
trait_def.expand(cx, mitem, item, push)
|
trait_def.expand(cx, mitem, item, push)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,22 +23,22 @@ pub fn expand_deriving_totalord(cx: &mut ExtCtxt,
|
||||||
push: |@Item|) {
|
push: |@Item|) {
|
||||||
let trait_def = TraitDef {
|
let trait_def = TraitDef {
|
||||||
span: span,
|
span: span,
|
||||||
attributes: ~[],
|
attributes: Vec::new(),
|
||||||
path: Path::new(~["std", "cmp", "TotalOrd"]),
|
path: Path::new(vec!("std", "cmp", "TotalOrd")),
|
||||||
additional_bounds: ~[],
|
additional_bounds: Vec::new(),
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
methods: ~[
|
methods: vec!(
|
||||||
MethodDef {
|
MethodDef {
|
||||||
name: "cmp",
|
name: "cmp",
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
explicit_self: borrowed_explicit_self(),
|
explicit_self: borrowed_explicit_self(),
|
||||||
args: ~[borrowed_self()],
|
args: vec!(borrowed_self()),
|
||||||
ret_ty: Literal(Path::new(~["std", "cmp", "Ordering"])),
|
ret_ty: Literal(Path::new(vec!("std", "cmp", "Ordering"))),
|
||||||
inline: true,
|
inline: true,
|
||||||
const_nonmatching: false,
|
const_nonmatching: false,
|
||||||
combine_substructure: cs_cmp
|
combine_substructure: cs_cmp
|
||||||
}
|
}
|
||||||
]
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
trait_def.expand(cx, mitem, item, push)
|
trait_def.expand(cx, mitem, item, push)
|
||||||
|
@ -52,9 +52,9 @@ pub fn ordering_const(cx: &mut ExtCtxt, span: Span, cnst: Ordering) -> ast::Path
|
||||||
Greater => "Greater"
|
Greater => "Greater"
|
||||||
};
|
};
|
||||||
cx.path_global(span,
|
cx.path_global(span,
|
||||||
~[cx.ident_of("std"),
|
vec!(cx.ident_of("std"),
|
||||||
cx.ident_of("cmp"),
|
cx.ident_of("cmp"),
|
||||||
cx.ident_of(cnst)])
|
cx.ident_of(cnst)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
|
pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
|
||||||
|
@ -99,7 +99,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
|
||||||
let if_ = cx.expr_if(span,
|
let if_ = cx.expr_if(span,
|
||||||
cond,
|
cond,
|
||||||
old, Some(cx.expr_ident(span, test_id)));
|
old, Some(cx.expr_ident(span, test_id)));
|
||||||
cx.expr_block(cx.block(span, ~[assign], Some(if_)))
|
cx.expr_block(cx.block(span, vec!(assign), Some(if_)))
|
||||||
},
|
},
|
||||||
cx.expr_path(equals_path.clone()),
|
cx.expr_path(equals_path.clone()),
|
||||||
|cx, span, list, _| {
|
|cx, span, list, _| {
|
||||||
|
|
|
@ -28,27 +28,26 @@ pub fn expand_deriving_decodable(cx: &mut ExtCtxt,
|
||||||
push: |@Item|) {
|
push: |@Item|) {
|
||||||
let trait_def = TraitDef {
|
let trait_def = TraitDef {
|
||||||
span: span,
|
span: span,
|
||||||
attributes: ~[],
|
attributes: Vec::new(),
|
||||||
path: Path::new_(~["serialize", "Decodable"], None,
|
path: Path::new_(vec!("serialize", "Decodable"), None,
|
||||||
~[~Literal(Path::new_local("__D"))], true),
|
vec!(~Literal(Path::new_local("__D"))), true),
|
||||||
additional_bounds: ~[],
|
additional_bounds: Vec::new(),
|
||||||
generics: LifetimeBounds {
|
generics: LifetimeBounds {
|
||||||
lifetimes: ~[],
|
lifetimes: Vec::new(),
|
||||||
bounds: ~[("__D", ~[Path::new(~["serialize", "Decoder"])])],
|
bounds: vec!(("__D", vec!(Path::new(vec!("serialize", "Decoder"))))),
|
||||||
},
|
},
|
||||||
methods: ~[
|
methods: vec!(
|
||||||
MethodDef {
|
MethodDef {
|
||||||
name: "decode",
|
name: "decode",
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
explicit_self: None,
|
explicit_self: None,
|
||||||
args: ~[Ptr(~Literal(Path::new_local("__D")),
|
args: vec!(Ptr(~Literal(Path::new_local("__D")),
|
||||||
Borrowed(None, MutMutable))],
|
Borrowed(None, MutMutable))),
|
||||||
ret_ty: Self,
|
ret_ty: Self,
|
||||||
inline: false,
|
inline: false,
|
||||||
const_nonmatching: true,
|
const_nonmatching: true,
|
||||||
combine_substructure: decodable_substructure,
|
combine_substructure: decodable_substructure,
|
||||||
},
|
})
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
trait_def.expand(cx, mitem, item, push)
|
trait_def.expand(cx, mitem, item, push)
|
||||||
|
@ -57,13 +56,13 @@ pub fn expand_deriving_decodable(cx: &mut ExtCtxt,
|
||||||
fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
||||||
substr: &Substructure) -> @Expr {
|
substr: &Substructure) -> @Expr {
|
||||||
let decoder = substr.nonself_args[0];
|
let decoder = substr.nonself_args[0];
|
||||||
let recurse = ~[cx.ident_of("serialize"),
|
let recurse = vec!(cx.ident_of("serialize"),
|
||||||
cx.ident_of("Decodable"),
|
cx.ident_of("Decodable"),
|
||||||
cx.ident_of("decode")];
|
cx.ident_of("decode"));
|
||||||
// throw an underscore in front to suppress unused variable warnings
|
// throw an underscore in front to suppress unused variable warnings
|
||||||
let blkarg = cx.ident_of("_d");
|
let blkarg = cx.ident_of("_d");
|
||||||
let blkdecoder = cx.expr_ident(trait_span, blkarg);
|
let blkdecoder = cx.expr_ident(trait_span, blkarg);
|
||||||
let calldecode = cx.expr_call_global(trait_span, recurse, ~[blkdecoder]);
|
let calldecode = cx.expr_call_global(trait_span, recurse, vec!(blkdecoder));
|
||||||
let lambdadecode = cx.lambda_expr_1(trait_span, calldecode, blkarg);
|
let lambdadecode = cx.lambda_expr_1(trait_span, calldecode, blkarg);
|
||||||
|
|
||||||
return match *substr.fields {
|
return match *substr.fields {
|
||||||
|
@ -80,24 +79,24 @@ fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
||||||
summary,
|
summary,
|
||||||
|cx, span, name, field| {
|
|cx, span, name, field| {
|
||||||
cx.expr_method_call(span, blkdecoder, read_struct_field,
|
cx.expr_method_call(span, blkdecoder, read_struct_field,
|
||||||
~[cx.expr_str(span, name),
|
vec!(cx.expr_str(span, name),
|
||||||
cx.expr_uint(span, field),
|
cx.expr_uint(span, field),
|
||||||
lambdadecode])
|
lambdadecode))
|
||||||
});
|
});
|
||||||
cx.expr_method_call(trait_span,
|
cx.expr_method_call(trait_span,
|
||||||
decoder,
|
decoder,
|
||||||
cx.ident_of("read_struct"),
|
cx.ident_of("read_struct"),
|
||||||
~[
|
vec!(
|
||||||
cx.expr_str(trait_span, token::get_ident(substr.type_ident)),
|
cx.expr_str(trait_span, token::get_ident(substr.type_ident)),
|
||||||
cx.expr_uint(trait_span, nfields),
|
cx.expr_uint(trait_span, nfields),
|
||||||
cx.lambda_expr_1(trait_span, result, blkarg)
|
cx.lambda_expr_1(trait_span, result, blkarg)
|
||||||
])
|
))
|
||||||
}
|
}
|
||||||
StaticEnum(_, ref fields) => {
|
StaticEnum(_, ref fields) => {
|
||||||
let variant = cx.ident_of("i");
|
let variant = cx.ident_of("i");
|
||||||
|
|
||||||
let mut arms = ~[];
|
let mut arms = Vec::new();
|
||||||
let mut variants = ~[];
|
let mut variants = Vec::new();
|
||||||
let rvariant_arg = cx.ident_of("read_enum_variant_arg");
|
let rvariant_arg = cx.ident_of("read_enum_variant_arg");
|
||||||
|
|
||||||
for (i, &(name, v_span, ref parts)) in fields.iter().enumerate() {
|
for (i, &(name, v_span, ref parts)) in fields.iter().enumerate() {
|
||||||
|
@ -110,29 +109,29 @@ fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
||||||
|cx, span, _, field| {
|
|cx, span, _, field| {
|
||||||
let idx = cx.expr_uint(span, field);
|
let idx = cx.expr_uint(span, field);
|
||||||
cx.expr_method_call(span, blkdecoder, rvariant_arg,
|
cx.expr_method_call(span, blkdecoder, rvariant_arg,
|
||||||
~[idx, lambdadecode])
|
vec!(idx, lambdadecode))
|
||||||
});
|
});
|
||||||
|
|
||||||
arms.push(cx.arm(v_span,
|
arms.push(cx.arm(v_span,
|
||||||
~[cx.pat_lit(v_span, cx.expr_uint(v_span, i))],
|
vec!(cx.pat_lit(v_span, cx.expr_uint(v_span, i))),
|
||||||
decoded));
|
decoded));
|
||||||
}
|
}
|
||||||
|
|
||||||
arms.push(cx.arm_unreachable(trait_span));
|
arms.push(cx.arm_unreachable(trait_span));
|
||||||
|
|
||||||
let result = cx.expr_match(trait_span, cx.expr_ident(trait_span, variant), arms);
|
let result = cx.expr_match(trait_span, cx.expr_ident(trait_span, variant), arms);
|
||||||
let lambda = cx.lambda_expr(trait_span, ~[blkarg, variant], result);
|
let lambda = cx.lambda_expr(trait_span, vec!(blkarg, variant), result);
|
||||||
let variant_vec = cx.expr_vec(trait_span, variants);
|
let variant_vec = cx.expr_vec(trait_span, variants);
|
||||||
let result = cx.expr_method_call(trait_span, blkdecoder,
|
let result = cx.expr_method_call(trait_span, blkdecoder,
|
||||||
cx.ident_of("read_enum_variant"),
|
cx.ident_of("read_enum_variant"),
|
||||||
~[variant_vec, lambda]);
|
vec!(variant_vec, lambda));
|
||||||
cx.expr_method_call(trait_span,
|
cx.expr_method_call(trait_span,
|
||||||
decoder,
|
decoder,
|
||||||
cx.ident_of("read_enum"),
|
cx.ident_of("read_enum"),
|
||||||
~[
|
vec!(
|
||||||
cx.expr_str(trait_span, token::get_ident(substr.type_ident)),
|
cx.expr_str(trait_span, token::get_ident(substr.type_ident)),
|
||||||
cx.lambda_expr_1(trait_span, result, blkarg)
|
cx.lambda_expr_1(trait_span, result, blkarg)
|
||||||
])
|
))
|
||||||
}
|
}
|
||||||
_ => cx.bug("expected StaticEnum or StaticStruct in deriving(Decodable)")
|
_ => cx.bug("expected StaticEnum or StaticStruct in deriving(Decodable)")
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,34 +21,33 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt,
|
||||||
push: |@Item|) {
|
push: |@Item|) {
|
||||||
let trait_def = TraitDef {
|
let trait_def = TraitDef {
|
||||||
span: span,
|
span: span,
|
||||||
attributes: ~[],
|
attributes: Vec::new(),
|
||||||
path: Path::new(~["std", "default", "Default"]),
|
path: Path::new(vec!("std", "default", "Default")),
|
||||||
additional_bounds: ~[],
|
additional_bounds: Vec::new(),
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
methods: ~[
|
methods: vec!(
|
||||||
MethodDef {
|
MethodDef {
|
||||||
name: "default",
|
name: "default",
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
explicit_self: None,
|
explicit_self: None,
|
||||||
args: ~[],
|
args: Vec::new(),
|
||||||
ret_ty: Self,
|
ret_ty: Self,
|
||||||
inline: true,
|
inline: true,
|
||||||
const_nonmatching: false,
|
const_nonmatching: false,
|
||||||
combine_substructure: default_substructure
|
combine_substructure: default_substructure
|
||||||
},
|
})
|
||||||
]
|
|
||||||
};
|
};
|
||||||
trait_def.expand(cx, mitem, item, push)
|
trait_def.expand(cx, mitem, item, push)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> @Expr {
|
fn default_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> @Expr {
|
||||||
let default_ident = ~[
|
let default_ident = vec!(
|
||||||
cx.ident_of("std"),
|
cx.ident_of("std"),
|
||||||
cx.ident_of("default"),
|
cx.ident_of("default"),
|
||||||
cx.ident_of("Default"),
|
cx.ident_of("Default"),
|
||||||
cx.ident_of("default")
|
cx.ident_of("default")
|
||||||
];
|
);
|
||||||
let default_call = |span| cx.expr_call_global(span, default_ident.clone(), ~[]);
|
let default_call = |span| cx.expr_call_global(span, default_ident.clone(), Vec::new());
|
||||||
|
|
||||||
return match *substr.fields {
|
return match *substr.fields {
|
||||||
StaticStruct(_, ref summary) => {
|
StaticStruct(_, ref summary) => {
|
||||||
|
|
|
@ -96,27 +96,26 @@ pub fn expand_deriving_encodable(cx: &mut ExtCtxt,
|
||||||
push: |@Item|) {
|
push: |@Item|) {
|
||||||
let trait_def = TraitDef {
|
let trait_def = TraitDef {
|
||||||
span: span,
|
span: span,
|
||||||
attributes: ~[],
|
attributes: Vec::new(),
|
||||||
path: Path::new_(~["serialize", "Encodable"], None,
|
path: Path::new_(vec!("serialize", "Encodable"), None,
|
||||||
~[~Literal(Path::new_local("__E"))], true),
|
vec!(~Literal(Path::new_local("__E"))), true),
|
||||||
additional_bounds: ~[],
|
additional_bounds: Vec::new(),
|
||||||
generics: LifetimeBounds {
|
generics: LifetimeBounds {
|
||||||
lifetimes: ~[],
|
lifetimes: Vec::new(),
|
||||||
bounds: ~[("__E", ~[Path::new(~["serialize", "Encoder"])])],
|
bounds: vec!(("__E", vec!(Path::new(vec!("serialize", "Encoder"))))),
|
||||||
},
|
},
|
||||||
methods: ~[
|
methods: vec!(
|
||||||
MethodDef {
|
MethodDef {
|
||||||
name: "encode",
|
name: "encode",
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
explicit_self: borrowed_explicit_self(),
|
explicit_self: borrowed_explicit_self(),
|
||||||
args: ~[Ptr(~Literal(Path::new_local("__E")),
|
args: vec!(Ptr(~Literal(Path::new_local("__E")),
|
||||||
Borrowed(None, MutMutable))],
|
Borrowed(None, MutMutable))),
|
||||||
ret_ty: nil_ty(),
|
ret_ty: nil_ty(),
|
||||||
inline: false,
|
inline: false,
|
||||||
const_nonmatching: true,
|
const_nonmatching: true,
|
||||||
combine_substructure: encodable_substructure,
|
combine_substructure: encodable_substructure,
|
||||||
},
|
})
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
trait_def.expand(cx, mitem, item, push)
|
trait_def.expand(cx, mitem, item, push)
|
||||||
|
@ -133,7 +132,7 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
||||||
return match *substr.fields {
|
return match *substr.fields {
|
||||||
Struct(ref fields) => {
|
Struct(ref fields) => {
|
||||||
let emit_struct_field = cx.ident_of("emit_struct_field");
|
let emit_struct_field = cx.ident_of("emit_struct_field");
|
||||||
let mut stmts = ~[];
|
let mut stmts = Vec::new();
|
||||||
for (i, &FieldInfo {
|
for (i, &FieldInfo {
|
||||||
name,
|
name,
|
||||||
self_,
|
self_,
|
||||||
|
@ -146,13 +145,13 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
||||||
token::intern_and_get_ident(format!("_field{}", i))
|
token::intern_and_get_ident(format!("_field{}", i))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let enc = cx.expr_method_call(span, self_, encode, ~[blkencoder]);
|
let enc = cx.expr_method_call(span, self_, encode, vec!(blkencoder));
|
||||||
let lambda = cx.lambda_expr_1(span, enc, blkarg);
|
let lambda = cx.lambda_expr_1(span, enc, blkarg);
|
||||||
let call = cx.expr_method_call(span, blkencoder,
|
let call = cx.expr_method_call(span, blkencoder,
|
||||||
emit_struct_field,
|
emit_struct_field,
|
||||||
~[cx.expr_str(span, name),
|
vec!(cx.expr_str(span, name),
|
||||||
cx.expr_uint(span, i),
|
cx.expr_uint(span, i),
|
||||||
lambda]);
|
lambda));
|
||||||
stmts.push(cx.stmt_expr(call));
|
stmts.push(cx.stmt_expr(call));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,11 +159,11 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
||||||
cx.expr_method_call(trait_span,
|
cx.expr_method_call(trait_span,
|
||||||
encoder,
|
encoder,
|
||||||
cx.ident_of("emit_struct"),
|
cx.ident_of("emit_struct"),
|
||||||
~[
|
vec!(
|
||||||
cx.expr_str(trait_span, token::get_ident(substr.type_ident)),
|
cx.expr_str(trait_span, token::get_ident(substr.type_ident)),
|
||||||
cx.expr_uint(trait_span, fields.len()),
|
cx.expr_uint(trait_span, fields.len()),
|
||||||
blk
|
blk
|
||||||
])
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
EnumMatching(idx, variant, ref fields) => {
|
EnumMatching(idx, variant, ref fields) => {
|
||||||
|
@ -175,14 +174,14 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
||||||
let me = cx.stmt_let(trait_span, false, blkarg, encoder);
|
let me = cx.stmt_let(trait_span, false, blkarg, encoder);
|
||||||
let encoder = cx.expr_ident(trait_span, blkarg);
|
let encoder = cx.expr_ident(trait_span, blkarg);
|
||||||
let emit_variant_arg = cx.ident_of("emit_enum_variant_arg");
|
let emit_variant_arg = cx.ident_of("emit_enum_variant_arg");
|
||||||
let mut stmts = ~[];
|
let mut stmts = Vec::new();
|
||||||
for (i, &FieldInfo { self_, span, .. }) in fields.iter().enumerate() {
|
for (i, &FieldInfo { self_, span, .. }) in fields.iter().enumerate() {
|
||||||
let enc = cx.expr_method_call(span, self_, encode, ~[blkencoder]);
|
let enc = cx.expr_method_call(span, self_, encode, vec!(blkencoder));
|
||||||
let lambda = cx.lambda_expr_1(span, enc, blkarg);
|
let lambda = cx.lambda_expr_1(span, enc, blkarg);
|
||||||
let call = cx.expr_method_call(span, blkencoder,
|
let call = cx.expr_method_call(span, blkencoder,
|
||||||
emit_variant_arg,
|
emit_variant_arg,
|
||||||
~[cx.expr_uint(span, i),
|
vec!(cx.expr_uint(span, i),
|
||||||
lambda]);
|
lambda));
|
||||||
stmts.push(cx.stmt_expr(call));
|
stmts.push(cx.stmt_expr(call));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,19 +189,19 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
||||||
let name = cx.expr_str(trait_span, token::get_ident(variant.node.name));
|
let name = cx.expr_str(trait_span, token::get_ident(variant.node.name));
|
||||||
let call = cx.expr_method_call(trait_span, blkencoder,
|
let call = cx.expr_method_call(trait_span, blkencoder,
|
||||||
cx.ident_of("emit_enum_variant"),
|
cx.ident_of("emit_enum_variant"),
|
||||||
~[name,
|
vec!(name,
|
||||||
cx.expr_uint(trait_span, idx),
|
cx.expr_uint(trait_span, idx),
|
||||||
cx.expr_uint(trait_span, fields.len()),
|
cx.expr_uint(trait_span, fields.len()),
|
||||||
blk]);
|
blk));
|
||||||
let blk = cx.lambda_expr_1(trait_span, call, blkarg);
|
let blk = cx.lambda_expr_1(trait_span, call, blkarg);
|
||||||
let ret = cx.expr_method_call(trait_span,
|
let ret = cx.expr_method_call(trait_span,
|
||||||
encoder,
|
encoder,
|
||||||
cx.ident_of("emit_enum"),
|
cx.ident_of("emit_enum"),
|
||||||
~[
|
vec!(
|
||||||
cx.expr_str(trait_span, token::get_ident(substr.type_ident)),
|
cx.expr_str(trait_span, token::get_ident(substr.type_ident)),
|
||||||
blk
|
blk
|
||||||
]);
|
));
|
||||||
cx.expr_block(cx.block(trait_span, ~[me], Some(ret)))
|
cx.expr_block(cx.block(trait_span, vec!(me), Some(ret)))
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => cx.bug("expected Struct or EnumMatching in deriving(Encodable)")
|
_ => cx.bug("expected Struct or EnumMatching in deriving(Encodable)")
|
||||||
|
|
|
@ -197,20 +197,19 @@ pub struct TraitDef<'a> {
|
||||||
/// The span for the current #[deriving(Foo)] header.
|
/// The span for the current #[deriving(Foo)] header.
|
||||||
span: Span,
|
span: Span,
|
||||||
|
|
||||||
attributes: ~[ast::Attribute],
|
attributes: Vec<ast::Attribute> ,
|
||||||
|
|
||||||
/// Path of the trait, including any type parameters
|
/// Path of the trait, including any type parameters
|
||||||
path: Path<'a>,
|
path: Path<'a>,
|
||||||
|
|
||||||
/// Additional bounds required of any type parameters of the type,
|
/// Additional bounds required of any type parameters of the type,
|
||||||
/// other than the current trait
|
/// other than the current trait
|
||||||
additional_bounds: ~[Ty<'a>],
|
additional_bounds: Vec<Ty<'a>> ,
|
||||||
|
|
||||||
/// Any extra lifetimes and/or bounds, e.g. `D: serialize::Decoder`
|
/// Any extra lifetimes and/or bounds, e.g. `D: serialize::Decoder`
|
||||||
generics: LifetimeBounds<'a>,
|
generics: LifetimeBounds<'a>,
|
||||||
|
|
||||||
methods: ~[MethodDef<'a>]
|
methods: Vec<MethodDef<'a>> }
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
pub struct MethodDef<'a> {
|
pub struct MethodDef<'a> {
|
||||||
|
@ -225,7 +224,7 @@ pub struct MethodDef<'a> {
|
||||||
explicit_self: Option<Option<PtrTy<'a>>>,
|
explicit_self: Option<Option<PtrTy<'a>>>,
|
||||||
|
|
||||||
/// Arguments other than the self argument
|
/// Arguments other than the self argument
|
||||||
args: ~[Ty<'a>],
|
args: Vec<Ty<'a>> ,
|
||||||
|
|
||||||
/// Return type
|
/// Return type
|
||||||
ret_ty: Ty<'a>,
|
ret_ty: Ty<'a>,
|
||||||
|
@ -264,39 +263,38 @@ pub struct FieldInfo {
|
||||||
self_: @Expr,
|
self_: @Expr,
|
||||||
/// The expressions corresponding to references to this field in
|
/// The expressions corresponding to references to this field in
|
||||||
/// the other Self arguments.
|
/// the other Self arguments.
|
||||||
other: ~[@Expr]
|
other: Vec<@Expr> }
|
||||||
}
|
|
||||||
|
|
||||||
/// Fields for a static method
|
/// Fields for a static method
|
||||||
pub enum StaticFields {
|
pub enum StaticFields {
|
||||||
/// Tuple structs/enum variants like this
|
/// Tuple structs/enum variants like this
|
||||||
Unnamed(~[Span]),
|
Unnamed(Vec<Span> ),
|
||||||
/// Normal structs/struct variants.
|
/// Normal structs/struct variants.
|
||||||
Named(~[(Ident, Span)])
|
Named(Vec<(Ident, Span)> )
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A summary of the possible sets of fields. See above for details
|
/// A summary of the possible sets of fields. See above for details
|
||||||
/// and examples
|
/// and examples
|
||||||
pub enum SubstructureFields<'a> {
|
pub enum SubstructureFields<'a> {
|
||||||
Struct(~[FieldInfo]),
|
Struct(Vec<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
|
fields: the field name is only non-`None` in the case of a struct
|
||||||
variant.
|
variant.
|
||||||
*/
|
*/
|
||||||
EnumMatching(uint, &'a ast::Variant, ~[FieldInfo]),
|
EnumMatching(uint, &'a ast::Variant, Vec<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
|
[field span, field ident, fields])] (i.e. all fields for self are in the
|
||||||
first tuple, for other1 are in the second tuple, etc.)
|
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>, Vec<(Span, Option<Ident>, @Expr)> )]),
|
||||||
|
|
||||||
/// A static method where Self is a struct.
|
/// A static method where Self is a struct.
|
||||||
StaticStruct(&'a ast::StructDef, StaticFields),
|
StaticStruct(&'a ast::StructDef, StaticFields),
|
||||||
/// A static method where Self is an enum.
|
/// A static method where Self is an enum.
|
||||||
StaticEnum(&'a ast::EnumDef, ~[(Ident, Span, StaticFields)])
|
StaticEnum(&'a ast::EnumDef, Vec<(Ident, Span, StaticFields)> )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -316,7 +314,7 @@ representing each variant: (variant index, ast::Variant instance,
|
||||||
pub type EnumNonMatchFunc<'a> =
|
pub type EnumNonMatchFunc<'a> =
|
||||||
'a |&mut ExtCtxt,
|
'a |&mut ExtCtxt,
|
||||||
Span,
|
Span,
|
||||||
&[(uint, P<ast::Variant>, ~[(Span, Option<Ident>, @Expr)])],
|
&[(uint, P<ast::Variant>, Vec<(Span, Option<Ident>, @Expr)> )],
|
||||||
&[@Expr]|
|
&[@Expr]|
|
||||||
-> @Expr;
|
-> @Expr;
|
||||||
|
|
||||||
|
@ -360,7 +358,7 @@ impl<'a> TraitDef<'a> {
|
||||||
cx: &mut ExtCtxt,
|
cx: &mut ExtCtxt,
|
||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
generics: &Generics,
|
generics: &Generics,
|
||||||
methods: ~[@ast::Method]) -> @ast::Item {
|
methods: Vec<@ast::Method> ) -> @ast::Item {
|
||||||
let trait_path = self.path.to_path(cx, self.span, type_ident, generics);
|
let trait_path = self.path.to_path(cx, self.span, type_ident, generics);
|
||||||
|
|
||||||
let mut trait_generics = self.generics.to_generics(cx, self.span,
|
let mut trait_generics = self.generics.to_generics(cx, self.span,
|
||||||
|
@ -397,7 +395,7 @@ impl<'a> TraitDef<'a> {
|
||||||
|
|
||||||
// Create the type of `self`.
|
// Create the type of `self`.
|
||||||
let self_type = cx.ty_path(
|
let self_type = cx.ty_path(
|
||||||
cx.path_all(self.span, false, ~[ type_ident ], self_lifetimes,
|
cx.path_all(self.span, false, vec!( type_ident ), self_lifetimes,
|
||||||
opt_vec::take_vec(self_ty_params)), None);
|
opt_vec::take_vec(self_ty_params)), None);
|
||||||
|
|
||||||
let doc_attr = cx.attribute(
|
let doc_attr = cx.attribute(
|
||||||
|
@ -412,7 +410,7 @@ impl<'a> TraitDef<'a> {
|
||||||
cx.item(
|
cx.item(
|
||||||
self.span,
|
self.span,
|
||||||
ident,
|
ident,
|
||||||
vec::append(~[doc_attr], self.attributes),
|
vec_ng::append(vec!(doc_attr), self.attributes),
|
||||||
ast::ItemImpl(trait_generics, opt_trait_ref,
|
ast::ItemImpl(trait_generics, opt_trait_ref,
|
||||||
self_type, methods.map(|x| *x)))
|
self_type, methods.map(|x| *x)))
|
||||||
}
|
}
|
||||||
|
@ -524,11 +522,11 @@ impl<'a> MethodDef<'a> {
|
||||||
trait_: &TraitDef,
|
trait_: &TraitDef,
|
||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
generics: &Generics)
|
generics: &Generics)
|
||||||
-> (ast::ExplicitSelf, ~[@Expr], ~[@Expr], ~[(Ident, P<ast::Ty>)]) {
|
-> (ast::ExplicitSelf, Vec<@Expr> , Vec<@Expr> , Vec<(Ident, P<ast::Ty>)> ) {
|
||||||
|
|
||||||
let mut self_args = ~[];
|
let mut self_args = Vec::new();
|
||||||
let mut nonself_args = ~[];
|
let mut nonself_args = Vec::new();
|
||||||
let mut arg_tys = ~[];
|
let mut arg_tys = Vec::new();
|
||||||
let mut nonstatic = false;
|
let mut nonstatic = false;
|
||||||
|
|
||||||
let ast_explicit_self = match self.explicit_self {
|
let ast_explicit_self = match self.explicit_self {
|
||||||
|
@ -575,7 +573,7 @@ impl<'a> MethodDef<'a> {
|
||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
generics: &Generics,
|
generics: &Generics,
|
||||||
explicit_self: ast::ExplicitSelf,
|
explicit_self: ast::ExplicitSelf,
|
||||||
arg_types: ~[(Ident, P<ast::Ty>)],
|
arg_types: Vec<(Ident, P<ast::Ty>)> ,
|
||||||
body: @Expr) -> @ast::Method {
|
body: @Expr) -> @ast::Method {
|
||||||
// create the generics that aren't for Self
|
// create the generics that aren't for Self
|
||||||
let fn_generics = self.generics.to_generics(cx, trait_.span, type_ident, generics);
|
let fn_generics = self.generics.to_generics(cx, trait_.span, type_ident, generics);
|
||||||
|
@ -598,16 +596,16 @@ impl<'a> MethodDef<'a> {
|
||||||
let body_block = cx.block_expr(body);
|
let body_block = cx.block_expr(body);
|
||||||
|
|
||||||
let attrs = if self.inline {
|
let attrs = if self.inline {
|
||||||
~[
|
vec!(
|
||||||
cx
|
cx
|
||||||
.attribute(trait_.span,
|
.attribute(trait_.span,
|
||||||
cx
|
cx
|
||||||
.meta_word(trait_.span,
|
.meta_word(trait_.span,
|
||||||
InternedString::new(
|
InternedString::new(
|
||||||
"inline")))
|
"inline")))
|
||||||
]
|
)
|
||||||
} else {
|
} else {
|
||||||
~[]
|
Vec::new()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create the method.
|
// Create the method.
|
||||||
|
@ -655,9 +653,9 @@ impl<'a> MethodDef<'a> {
|
||||||
nonself_args: &[@Expr])
|
nonself_args: &[@Expr])
|
||||||
-> @Expr {
|
-> @Expr {
|
||||||
|
|
||||||
let mut raw_fields = ~[]; // ~[[fields of self],
|
let mut raw_fields = Vec::new(); // ~[[fields of self],
|
||||||
// [fields of next Self arg], [etc]]
|
// [fields of next Self arg], [etc]]
|
||||||
let mut patterns = ~[];
|
let mut patterns = Vec::new();
|
||||||
for i in range(0u, self_args.len()) {
|
for i in range(0u, self_args.len()) {
|
||||||
let (pat, ident_expr) = trait_.create_struct_pattern(cx, type_ident, struct_def,
|
let (pat, ident_expr) = trait_.create_struct_pattern(cx, type_ident, struct_def,
|
||||||
format!("__self_{}", i),
|
format!("__self_{}", i),
|
||||||
|
@ -703,7 +701,7 @@ impl<'a> MethodDef<'a> {
|
||||||
// matter.
|
// matter.
|
||||||
for (&arg_expr, &pat) in self_args.iter().zip(patterns.iter()) {
|
for (&arg_expr, &pat) in self_args.iter().zip(patterns.iter()) {
|
||||||
body = cx.expr_match(trait_.span, arg_expr,
|
body = cx.expr_match(trait_.span, arg_expr,
|
||||||
~[ cx.arm(trait_.span, ~[pat], body) ])
|
vec!( cx.arm(trait_.span, vec!(pat), body) ))
|
||||||
}
|
}
|
||||||
body
|
body
|
||||||
}
|
}
|
||||||
|
@ -759,7 +757,7 @@ impl<'a> MethodDef<'a> {
|
||||||
self_args: &[@Expr],
|
self_args: &[@Expr],
|
||||||
nonself_args: &[@Expr])
|
nonself_args: &[@Expr])
|
||||||
-> @Expr {
|
-> @Expr {
|
||||||
let mut matches = ~[];
|
let mut matches = Vec::new();
|
||||||
self.build_enum_match(cx, trait_, enum_def, type_ident,
|
self.build_enum_match(cx, trait_, enum_def, type_ident,
|
||||||
self_args, nonself_args,
|
self_args, nonself_args,
|
||||||
None, &mut matches, 0)
|
None, &mut matches, 0)
|
||||||
|
@ -795,8 +793,8 @@ impl<'a> MethodDef<'a> {
|
||||||
self_args: &[@Expr],
|
self_args: &[@Expr],
|
||||||
nonself_args: &[@Expr],
|
nonself_args: &[@Expr],
|
||||||
matching: Option<uint>,
|
matching: Option<uint>,
|
||||||
matches_so_far: &mut ~[(uint, P<ast::Variant>,
|
matches_so_far: &mut Vec<(uint, P<ast::Variant>,
|
||||||
~[(Span, Option<Ident>, @Expr)])],
|
Vec<(Span, Option<Ident>, @Expr)> )> ,
|
||||||
match_count: uint) -> @Expr {
|
match_count: uint) -> @Expr {
|
||||||
if match_count == self_args.len() {
|
if match_count == self_args.len() {
|
||||||
// we've matched against all arguments, so make the final
|
// we've matched against all arguments, so make the final
|
||||||
|
@ -826,7 +824,7 @@ impl<'a> MethodDef<'a> {
|
||||||
(_, v, ref s) => (v, s)
|
(_, v, ref s) => (v, s)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut enum_matching_fields = vec::from_elem(self_vec.len(), ~[]);
|
let mut enum_matching_fields = vec::from_elem(self_vec.len(), Vec::new());
|
||||||
|
|
||||||
for triple in matches_so_far.tail().iter() {
|
for triple in matches_so_far.tail().iter() {
|
||||||
match triple {
|
match triple {
|
||||||
|
@ -865,7 +863,7 @@ impl<'a> MethodDef<'a> {
|
||||||
format!("__arg_{}", match_count)
|
format!("__arg_{}", match_count)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut arms = ~[];
|
let mut arms = Vec::new();
|
||||||
|
|
||||||
// the code for nonmatching variants only matters when
|
// the code for nonmatching variants only matters when
|
||||||
// we've seen at least one other variant already
|
// we've seen at least one other variant already
|
||||||
|
@ -895,7 +893,7 @@ impl<'a> MethodDef<'a> {
|
||||||
matches_so_far,
|
matches_so_far,
|
||||||
match_count + 1);
|
match_count + 1);
|
||||||
matches_so_far.pop().unwrap();
|
matches_so_far.pop().unwrap();
|
||||||
arms.push(cx.arm(trait_.span, ~[ pattern ], arm_expr));
|
arms.push(cx.arm(trait_.span, vec!( pattern ), arm_expr));
|
||||||
|
|
||||||
if enum_def.variants.len() > 1 {
|
if enum_def.variants.len() > 1 {
|
||||||
let e = &EnumNonMatching(&[]);
|
let e = &EnumNonMatching(&[]);
|
||||||
|
@ -904,7 +902,7 @@ impl<'a> MethodDef<'a> {
|
||||||
e);
|
e);
|
||||||
let wild_arm = cx.arm(
|
let wild_arm = cx.arm(
|
||||||
trait_.span,
|
trait_.span,
|
||||||
~[ cx.pat_wild(trait_.span) ],
|
vec!( cx.pat_wild(trait_.span) ),
|
||||||
wild_expr);
|
wild_expr);
|
||||||
arms.push(wild_arm);
|
arms.push(wild_arm);
|
||||||
}
|
}
|
||||||
|
@ -933,7 +931,7 @@ impl<'a> MethodDef<'a> {
|
||||||
match_count + 1);
|
match_count + 1);
|
||||||
matches_so_far.pop().unwrap();
|
matches_so_far.pop().unwrap();
|
||||||
|
|
||||||
let arm = cx.arm(trait_.span, ~[ pattern ], arm_expr);
|
let arm = cx.arm(trait_.span, vec!( pattern ), arm_expr);
|
||||||
arms.push(arm);
|
arms.push(arm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -997,8 +995,8 @@ impl<'a> TraitDef<'a> {
|
||||||
fn summarise_struct(&self,
|
fn summarise_struct(&self,
|
||||||
cx: &mut ExtCtxt,
|
cx: &mut ExtCtxt,
|
||||||
struct_def: &StructDef) -> StaticFields {
|
struct_def: &StructDef) -> StaticFields {
|
||||||
let mut named_idents = ~[];
|
let mut named_idents = Vec::new();
|
||||||
let mut just_spans = ~[];
|
let mut just_spans = Vec::new();
|
||||||
for field in struct_def.fields.iter(){
|
for field in struct_def.fields.iter(){
|
||||||
let sp = self.set_expn_info(cx, field.span);
|
let sp = self.set_expn_info(cx, field.span);
|
||||||
match field.node.kind {
|
match field.node.kind {
|
||||||
|
@ -1020,9 +1018,9 @@ impl<'a> TraitDef<'a> {
|
||||||
|
|
||||||
fn create_subpatterns(&self,
|
fn create_subpatterns(&self,
|
||||||
cx: &mut ExtCtxt,
|
cx: &mut ExtCtxt,
|
||||||
field_paths: ~[ast::Path],
|
field_paths: Vec<ast::Path> ,
|
||||||
mutbl: ast::Mutability)
|
mutbl: ast::Mutability)
|
||||||
-> ~[@ast::Pat] {
|
-> Vec<@ast::Pat> {
|
||||||
field_paths.map(|path| {
|
field_paths.map(|path| {
|
||||||
cx.pat(path.span,
|
cx.pat(path.span,
|
||||||
ast::PatIdent(ast::BindByRef(mutbl), (*path).clone(), None))
|
ast::PatIdent(ast::BindByRef(mutbl), (*path).clone(), None))
|
||||||
|
@ -1035,18 +1033,18 @@ impl<'a> TraitDef<'a> {
|
||||||
struct_def: &StructDef,
|
struct_def: &StructDef,
|
||||||
prefix: &str,
|
prefix: &str,
|
||||||
mutbl: ast::Mutability)
|
mutbl: ast::Mutability)
|
||||||
-> (@ast::Pat, ~[(Span, Option<Ident>, @Expr)]) {
|
-> (@ast::Pat, Vec<(Span, Option<Ident>, @Expr)> ) {
|
||||||
if struct_def.fields.is_empty() {
|
if struct_def.fields.is_empty() {
|
||||||
return (
|
return (
|
||||||
cx.pat_ident_binding_mode(
|
cx.pat_ident_binding_mode(
|
||||||
self.span, struct_ident, ast::BindByValue(ast::MutImmutable)),
|
self.span, struct_ident, ast::BindByValue(ast::MutImmutable)),
|
||||||
~[]);
|
Vec::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
let matching_path = cx.path(self.span, ~[ struct_ident ]);
|
let matching_path = cx.path(self.span, vec!( struct_ident ));
|
||||||
|
|
||||||
let mut paths = ~[];
|
let mut paths = Vec::new();
|
||||||
let mut ident_expr = ~[];
|
let mut ident_expr = Vec::new();
|
||||||
let mut struct_type = Unknown;
|
let mut struct_type = Unknown;
|
||||||
|
|
||||||
for (i, struct_field) in struct_def.fields.iter().enumerate() {
|
for (i, struct_field) in struct_def.fields.iter().enumerate() {
|
||||||
|
@ -1096,20 +1094,20 @@ impl<'a> TraitDef<'a> {
|
||||||
variant: &ast::Variant,
|
variant: &ast::Variant,
|
||||||
prefix: &str,
|
prefix: &str,
|
||||||
mutbl: ast::Mutability)
|
mutbl: ast::Mutability)
|
||||||
-> (@ast::Pat, ~[(Span, Option<Ident>, @Expr)]) {
|
-> (@ast::Pat, Vec<(Span, Option<Ident>, @Expr)> ) {
|
||||||
let variant_ident = variant.node.name;
|
let variant_ident = variant.node.name;
|
||||||
match variant.node.kind {
|
match variant.node.kind {
|
||||||
ast::TupleVariantKind(ref variant_args) => {
|
ast::TupleVariantKind(ref variant_args) => {
|
||||||
if variant_args.is_empty() {
|
if variant_args.is_empty() {
|
||||||
return (cx.pat_ident_binding_mode(variant.span, variant_ident,
|
return (cx.pat_ident_binding_mode(variant.span, variant_ident,
|
||||||
ast::BindByValue(ast::MutImmutable)),
|
ast::BindByValue(ast::MutImmutable)),
|
||||||
~[]);
|
Vec::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
let matching_path = cx.path_ident(variant.span, variant_ident);
|
let matching_path = cx.path_ident(variant.span, variant_ident);
|
||||||
|
|
||||||
let mut paths = ~[];
|
let mut paths = Vec::new();
|
||||||
let mut ident_expr = ~[];
|
let mut ident_expr = Vec::new();
|
||||||
for (i, va) in variant_args.iter().enumerate() {
|
for (i, va) in variant_args.iter().enumerate() {
|
||||||
let sp = self.set_expn_info(cx, va.ty.span);
|
let sp = self.set_expn_info(cx, va.ty.span);
|
||||||
let path = cx.path_ident(sp, cx.ident_of(format!("{}_{}", prefix, i)));
|
let path = cx.path_ident(sp, cx.ident_of(format!("{}_{}", prefix, i)));
|
||||||
|
@ -1179,7 +1177,7 @@ f(cx, span, ~[self_1.method(__arg_1_1, __arg_2_1),
|
||||||
~~~
|
~~~
|
||||||
*/
|
*/
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cs_same_method(f: |&mut ExtCtxt, Span, ~[@Expr]| -> @Expr,
|
pub fn cs_same_method(f: |&mut ExtCtxt, Span, Vec<@Expr> | -> @Expr,
|
||||||
enum_nonmatch_f: EnumNonMatchFunc,
|
enum_nonmatch_f: EnumNonMatchFunc,
|
||||||
cx: &mut ExtCtxt,
|
cx: &mut ExtCtxt,
|
||||||
trait_span: Span,
|
trait_span: Span,
|
||||||
|
|
|
@ -22,23 +22,23 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
|
||||||
|
|
||||||
let hash_trait_def = TraitDef {
|
let hash_trait_def = TraitDef {
|
||||||
span: span,
|
span: span,
|
||||||
attributes: ~[],
|
attributes: Vec::new(),
|
||||||
path: Path::new(~["std", "hash", "Hash"]),
|
path: Path::new(vec!("std", "hash", "Hash")),
|
||||||
additional_bounds: ~[],
|
additional_bounds: Vec::new(),
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
methods: ~[
|
methods: vec!(
|
||||||
MethodDef {
|
MethodDef {
|
||||||
name: "hash",
|
name: "hash",
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
explicit_self: borrowed_explicit_self(),
|
explicit_self: borrowed_explicit_self(),
|
||||||
args: ~[Ptr(~Literal(Path::new(~["std", "hash", "sip", "SipState"])),
|
args: vec!(Ptr(~Literal(Path::new(vec!("std", "hash", "sip", "SipState"))),
|
||||||
Borrowed(None, MutMutable))],
|
Borrowed(None, MutMutable))),
|
||||||
ret_ty: nil_ty(),
|
ret_ty: nil_ty(),
|
||||||
inline: true,
|
inline: true,
|
||||||
const_nonmatching: false,
|
const_nonmatching: false,
|
||||||
combine_substructure: hash_substructure
|
combine_substructure: hash_substructure
|
||||||
}
|
}
|
||||||
]
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
hash_trait_def.expand(cx, mitem, item, push);
|
hash_trait_def.expand(cx, mitem, item, push);
|
||||||
|
@ -51,10 +51,10 @@ fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
|
||||||
};
|
};
|
||||||
let hash_ident = substr.method_ident;
|
let hash_ident = substr.method_ident;
|
||||||
let call_hash = |span, thing_expr| {
|
let call_hash = |span, thing_expr| {
|
||||||
let expr = cx.expr_method_call(span, thing_expr, hash_ident, ~[state_expr]);
|
let expr = cx.expr_method_call(span, thing_expr, hash_ident, vec!(state_expr));
|
||||||
cx.stmt_expr(expr)
|
cx.stmt_expr(expr)
|
||||||
};
|
};
|
||||||
let mut stmts = ~[];
|
let mut stmts = Vec::new();
|
||||||
|
|
||||||
let fields = match *substr.fields {
|
let fields = match *substr.fields {
|
||||||
Struct(ref fs) => fs,
|
Struct(ref fs) => fs,
|
||||||
|
|
|
@ -23,21 +23,20 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
|
||||||
push: |@Item|) {
|
push: |@Item|) {
|
||||||
let trait_def = TraitDef {
|
let trait_def = TraitDef {
|
||||||
span: span,
|
span: span,
|
||||||
attributes: ~[],
|
attributes: Vec::new(),
|
||||||
path: Path::new(~["std", "num", "FromPrimitive"]),
|
path: Path::new(vec!("std", "num", "FromPrimitive")),
|
||||||
additional_bounds: ~[],
|
additional_bounds: Vec::new(),
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
methods: ~[
|
methods: vec!(
|
||||||
MethodDef {
|
MethodDef {
|
||||||
name: "from_i64",
|
name: "from_i64",
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
explicit_self: None,
|
explicit_self: None,
|
||||||
args: ~[
|
args: vec!(
|
||||||
Literal(Path::new(~["i64"])),
|
Literal(Path::new(vec!("i64")))),
|
||||||
],
|
ret_ty: Literal(Path::new_(vec!("std", "option", "Option"),
|
||||||
ret_ty: Literal(Path::new_(~["std", "option", "Option"],
|
|
||||||
None,
|
None,
|
||||||
~[~Self],
|
vec!(~Self),
|
||||||
true)),
|
true)),
|
||||||
// liable to cause code-bloat
|
// liable to cause code-bloat
|
||||||
inline: true,
|
inline: true,
|
||||||
|
@ -48,19 +47,17 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
|
||||||
name: "from_u64",
|
name: "from_u64",
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
explicit_self: None,
|
explicit_self: None,
|
||||||
args: ~[
|
args: vec!(
|
||||||
Literal(Path::new(~["u64"])),
|
Literal(Path::new(vec!("u64")))),
|
||||||
],
|
ret_ty: Literal(Path::new_(vec!("std", "option", "Option"),
|
||||||
ret_ty: Literal(Path::new_(~["std", "option", "Option"],
|
|
||||||
None,
|
None,
|
||||||
~[~Self],
|
vec!(~Self),
|
||||||
true)),
|
true)),
|
||||||
// liable to cause code-bloat
|
// liable to cause code-bloat
|
||||||
inline: true,
|
inline: true,
|
||||||
const_nonmatching: false,
|
const_nonmatching: false,
|
||||||
combine_substructure: |c, s, sub| cs_from("u64", c, s, sub),
|
combine_substructure: |c, s, sub| cs_from("u64", c, s, sub),
|
||||||
},
|
})
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
trait_def.expand(cx, mitem, item, push)
|
trait_def.expand(cx, mitem, item, push)
|
||||||
|
@ -84,7 +81,7 @@ fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure
|
||||||
return cx.expr_fail(trait_span, InternedString::new(""));
|
return cx.expr_fail(trait_span, InternedString::new(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut arms = ~[];
|
let mut arms = Vec::new();
|
||||||
|
|
||||||
for variant in enum_def.variants.iter() {
|
for variant in enum_def.variants.iter() {
|
||||||
match variant.node.kind {
|
match variant.node.kind {
|
||||||
|
@ -109,7 +106,7 @@ fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure
|
||||||
|
|
||||||
// arm for `_ if $guard => $body`
|
// arm for `_ if $guard => $body`
|
||||||
let arm = ast::Arm {
|
let arm = ast::Arm {
|
||||||
pats: ~[cx.pat_wild(span)],
|
pats: vec!(cx.pat_wild(span)),
|
||||||
guard: Some(guard),
|
guard: Some(guard),
|
||||||
body: cx.block_expr(body),
|
body: cx.block_expr(body),
|
||||||
};
|
};
|
||||||
|
@ -128,7 +125,7 @@ fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure
|
||||||
|
|
||||||
// arm for `_ => None`
|
// arm for `_ => None`
|
||||||
let arm = ast::Arm {
|
let arm = ast::Arm {
|
||||||
pats: ~[cx.pat_wild(trait_span)],
|
pats: vec!(cx.pat_wild(trait_span)),
|
||||||
guard: None,
|
guard: None,
|
||||||
body: cx.block_expr(cx.expr_none(trait_span)),
|
body: cx.block_expr(cx.expr_none(trait_span)),
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,48 +23,48 @@ pub fn expand_deriving_rand(cx: &mut ExtCtxt,
|
||||||
push: |@Item|) {
|
push: |@Item|) {
|
||||||
let trait_def = TraitDef {
|
let trait_def = TraitDef {
|
||||||
span: span,
|
span: span,
|
||||||
attributes: ~[],
|
attributes: Vec::new(),
|
||||||
path: Path::new(~["std", "rand", "Rand"]),
|
path: Path::new(vec!("std", "rand", "Rand")),
|
||||||
additional_bounds: ~[],
|
additional_bounds: Vec::new(),
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
methods: ~[
|
methods: vec!(
|
||||||
MethodDef {
|
MethodDef {
|
||||||
name: "rand",
|
name: "rand",
|
||||||
generics: LifetimeBounds {
|
generics: LifetimeBounds {
|
||||||
lifetimes: ~[],
|
lifetimes: Vec::new(),
|
||||||
bounds: ~[("R",
|
bounds: vec!(("R",
|
||||||
~[ Path::new(~["std", "rand", "Rng"]) ])]
|
vec!( Path::new(vec!("std", "rand", "Rng")) )))
|
||||||
},
|
},
|
||||||
explicit_self: None,
|
explicit_self: None,
|
||||||
args: ~[
|
args: vec!(
|
||||||
Ptr(~Literal(Path::new_local("R")),
|
Ptr(~Literal(Path::new_local("R")),
|
||||||
Borrowed(None, ast::MutMutable))
|
Borrowed(None, ast::MutMutable))
|
||||||
],
|
),
|
||||||
ret_ty: Self,
|
ret_ty: Self,
|
||||||
inline: false,
|
inline: false,
|
||||||
const_nonmatching: false,
|
const_nonmatching: false,
|
||||||
combine_substructure: rand_substructure
|
combine_substructure: rand_substructure
|
||||||
}
|
}
|
||||||
]
|
)
|
||||||
};
|
};
|
||||||
trait_def.expand(cx, mitem, item, push)
|
trait_def.expand(cx, mitem, item, push)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> @Expr {
|
fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> @Expr {
|
||||||
let rng = match substr.nonself_args {
|
let rng = match substr.nonself_args {
|
||||||
[rng] => ~[ rng ],
|
[rng] => vec!( rng ),
|
||||||
_ => cx.bug("Incorrect number of arguments to `rand` in `deriving(Rand)`")
|
_ => cx.bug("Incorrect number of arguments to `rand` in `deriving(Rand)`")
|
||||||
};
|
};
|
||||||
let rand_ident = ~[
|
let rand_ident = vec!(
|
||||||
cx.ident_of("std"),
|
cx.ident_of("std"),
|
||||||
cx.ident_of("rand"),
|
cx.ident_of("rand"),
|
||||||
cx.ident_of("Rand"),
|
cx.ident_of("Rand"),
|
||||||
cx.ident_of("rand")
|
cx.ident_of("rand")
|
||||||
];
|
);
|
||||||
let rand_call = |cx: &mut ExtCtxt, span| {
|
let rand_call = |cx: &mut ExtCtxt, span| {
|
||||||
cx.expr_call_global(span,
|
cx.expr_call_global(span,
|
||||||
rand_ident.clone(),
|
rand_ident.clone(),
|
||||||
~[ rng[0] ])
|
vec!( rng[0] ))
|
||||||
};
|
};
|
||||||
|
|
||||||
return match *substr.fields {
|
return match *substr.fields {
|
||||||
|
@ -84,13 +84,13 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
|
||||||
true,
|
true,
|
||||||
rand_ident.clone(),
|
rand_ident.clone(),
|
||||||
opt_vec::Empty,
|
opt_vec::Empty,
|
||||||
~[]);
|
Vec::new());
|
||||||
let rand_name = cx.expr_path(rand_name);
|
let rand_name = cx.expr_path(rand_name);
|
||||||
|
|
||||||
// ::std::rand::Rand::rand(rng)
|
// ::std::rand::Rand::rand(rng)
|
||||||
let rv_call = cx.expr_call(trait_span,
|
let rv_call = cx.expr_call(trait_span,
|
||||||
rand_name,
|
rand_name,
|
||||||
~[ rng[0] ]);
|
vec!( rng[0] ));
|
||||||
|
|
||||||
// need to specify the uint-ness of the random number
|
// need to specify the uint-ness of the random number
|
||||||
let uint_ty = cx.ty_ident(trait_span, cx.ident_of("uint"));
|
let uint_ty = cx.ty_ident(trait_span, cx.ident_of("uint"));
|
||||||
|
@ -113,15 +113,15 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
|
||||||
let pat = cx.pat_lit(v_span, i_expr);
|
let pat = cx.pat_lit(v_span, i_expr);
|
||||||
|
|
||||||
let thing = rand_thing(cx, v_span, ident, summary, |cx, sp| rand_call(cx, sp));
|
let thing = rand_thing(cx, v_span, ident, summary, |cx, sp| rand_call(cx, sp));
|
||||||
cx.arm(v_span, ~[ pat ], thing)
|
cx.arm(v_span, vec!( pat ), thing)
|
||||||
}).collect::<~[ast::Arm]>();
|
}).collect::<Vec<ast::Arm> >();
|
||||||
|
|
||||||
// _ => {} at the end. Should never occur
|
// _ => {} at the end. Should never occur
|
||||||
arms.push(cx.arm_unreachable(trait_span));
|
arms.push(cx.arm_unreachable(trait_span));
|
||||||
|
|
||||||
let match_expr = cx.expr_match(trait_span, rand_variant, arms);
|
let match_expr = cx.expr_match(trait_span, rand_variant, arms);
|
||||||
|
|
||||||
let block = cx.block(trait_span, ~[ let_statement ], Some(match_expr));
|
let block = cx.block(trait_span, vec!( let_statement ), Some(match_expr));
|
||||||
cx.expr_block(block)
|
cx.expr_block(block)
|
||||||
}
|
}
|
||||||
_ => cx.bug("Non-static method in `deriving(Rand)`")
|
_ => cx.bug("Non-static method in `deriving(Rand)`")
|
||||||
|
|
|
@ -26,27 +26,27 @@ pub fn expand_deriving_show(cx: &mut ExtCtxt,
|
||||||
item: @Item,
|
item: @Item,
|
||||||
push: |@Item|) {
|
push: |@Item|) {
|
||||||
// &mut ::std::fmt::Formatter
|
// &mut ::std::fmt::Formatter
|
||||||
let fmtr = Ptr(~Literal(Path::new(~["std", "fmt", "Formatter"])),
|
let fmtr = Ptr(~Literal(Path::new(vec!("std", "fmt", "Formatter"))),
|
||||||
Borrowed(None, ast::MutMutable));
|
Borrowed(None, ast::MutMutable));
|
||||||
|
|
||||||
let trait_def = TraitDef {
|
let trait_def = TraitDef {
|
||||||
span: span,
|
span: span,
|
||||||
attributes: ~[],
|
attributes: Vec::new(),
|
||||||
path: Path::new(~["std", "fmt", "Show"]),
|
path: Path::new(vec!("std", "fmt", "Show")),
|
||||||
additional_bounds: ~[],
|
additional_bounds: Vec::new(),
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
methods: ~[
|
methods: vec!(
|
||||||
MethodDef {
|
MethodDef {
|
||||||
name: "fmt",
|
name: "fmt",
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
explicit_self: borrowed_explicit_self(),
|
explicit_self: borrowed_explicit_self(),
|
||||||
args: ~[fmtr],
|
args: vec!(fmtr),
|
||||||
ret_ty: Literal(Path::new(~["std", "fmt", "Result"])),
|
ret_ty: Literal(Path::new(vec!("std", "fmt", "Result"))),
|
||||||
inline: false,
|
inline: false,
|
||||||
const_nonmatching: false,
|
const_nonmatching: false,
|
||||||
combine_substructure: show_substructure
|
combine_substructure: show_substructure
|
||||||
}
|
}
|
||||||
]
|
)
|
||||||
};
|
};
|
||||||
trait_def.expand(cx, mitem, item, push)
|
trait_def.expand(cx, mitem, item, push)
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
|
||||||
|
|
||||||
let mut format_string = token::get_ident(name).get().to_owned();
|
let mut format_string = token::get_ident(name).get().to_owned();
|
||||||
// the internal fields we're actually formatting
|
// the internal fields we're actually formatting
|
||||||
let mut exprs = ~[];
|
let mut exprs = Vec::new();
|
||||||
|
|
||||||
// Getting harder... making the format string:
|
// Getting harder... making the format string:
|
||||||
match *substr.fields {
|
match *substr.fields {
|
||||||
|
@ -124,10 +124,10 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
|
||||||
let formatter = substr.nonself_args[0];
|
let formatter = substr.nonself_args[0];
|
||||||
let buf = cx.expr_field_access(span, formatter, cx.ident_of("buf"));
|
let buf = cx.expr_field_access(span, formatter, cx.ident_of("buf"));
|
||||||
|
|
||||||
let std_write = ~[cx.ident_of("std"), cx.ident_of("fmt"), cx.ident_of("write")];
|
let std_write = vec!(cx.ident_of("std"), cx.ident_of("fmt"), cx.ident_of("write"));
|
||||||
let args = cx.ident_of("__args");
|
let args = cx.ident_of("__args");
|
||||||
let write_call = cx.expr_call_global(span, std_write, ~[buf, cx.expr_ident(span, args)]);
|
let write_call = cx.expr_call_global(span, std_write, vec!(buf, cx.expr_ident(span, args)));
|
||||||
let format_closure = cx.lambda_expr(span, ~[args], write_call);
|
let format_closure = cx.lambda_expr(span, vec!(args), write_call);
|
||||||
|
|
||||||
let s = token::intern_and_get_ident(format_string);
|
let s = token::intern_and_get_ident(format_string);
|
||||||
let format_string = cx.expr_str(span, s);
|
let format_string = cx.expr_str(span, s);
|
||||||
|
|
|
@ -30,22 +30,22 @@ pub enum PtrTy<'a> {
|
||||||
/// A path, e.g. `::std::option::Option::<int>` (global). Has support
|
/// A path, e.g. `::std::option::Option::<int>` (global). Has support
|
||||||
/// for type parameters and a lifetime.
|
/// for type parameters and a lifetime.
|
||||||
pub struct Path<'a> {
|
pub struct Path<'a> {
|
||||||
path: ~[&'a str],
|
path: Vec<&'a str> ,
|
||||||
lifetime: Option<&'a str>,
|
lifetime: Option<&'a str>,
|
||||||
params: ~[~Ty<'a>],
|
params: Vec<~Ty<'a>> ,
|
||||||
global: bool
|
global: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Path<'a> {
|
impl<'a> Path<'a> {
|
||||||
pub fn new<'r>(path: ~[&'r str]) -> Path<'r> {
|
pub fn new<'r>(path: Vec<&'r str> ) -> Path<'r> {
|
||||||
Path::new_(path, None, ~[], true)
|
Path::new_(path, None, Vec::new(), true)
|
||||||
}
|
}
|
||||||
pub fn new_local<'r>(path: &'r str) -> Path<'r> {
|
pub fn new_local<'r>(path: &'r str) -> Path<'r> {
|
||||||
Path::new_(~[ path ], None, ~[], false)
|
Path::new_(vec!( path ), None, Vec::new(), false)
|
||||||
}
|
}
|
||||||
pub fn new_<'r>(path: ~[&'r str],
|
pub fn new_<'r>(path: Vec<&'r str> ,
|
||||||
lifetime: Option<&'r str>,
|
lifetime: Option<&'r str>,
|
||||||
params: ~[~Ty<'r>],
|
params: Vec<~Ty<'r>> ,
|
||||||
global: bool)
|
global: bool)
|
||||||
-> Path<'r> {
|
-> Path<'r> {
|
||||||
Path {
|
Path {
|
||||||
|
@ -87,7 +87,7 @@ pub enum Ty<'a> {
|
||||||
// parameter, and things like `int`
|
// parameter, and things like `int`
|
||||||
Literal(Path<'a>),
|
Literal(Path<'a>),
|
||||||
// includes nil
|
// includes nil
|
||||||
Tuple(~[Ty<'a>])
|
Tuple(Vec<Ty<'a>> )
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn borrowed_ptrty<'r>() -> PtrTy<'r> {
|
pub fn borrowed_ptrty<'r>() -> PtrTy<'r> {
|
||||||
|
@ -106,7 +106,7 @@ pub fn borrowed_self<'r>() -> Ty<'r> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nil_ty() -> Ty<'static> {
|
pub fn nil_ty() -> Ty<'static> {
|
||||||
Tuple(~[])
|
Tuple(Vec::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mk_lifetime(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Option<ast::Lifetime> {
|
fn mk_lifetime(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Option<ast::Lifetime> {
|
||||||
|
@ -172,7 +172,7 @@ impl<'a> Ty<'a> {
|
||||||
});
|
});
|
||||||
let lifetimes = self_generics.lifetimes.clone();
|
let lifetimes = self_generics.lifetimes.clone();
|
||||||
|
|
||||||
cx.path_all(span, false, ~[self_ty], lifetimes,
|
cx.path_all(span, false, vec!(self_ty), lifetimes,
|
||||||
opt_vec::take_vec(self_params))
|
opt_vec::take_vec(self_params))
|
||||||
}
|
}
|
||||||
Literal(ref p) => {
|
Literal(ref p) => {
|
||||||
|
@ -195,7 +195,7 @@ fn mk_ty_param(cx: &ExtCtxt, span: Span, name: &str, bounds: &[Path],
|
||||||
cx.typaram(cx.ident_of(name), bounds, None)
|
cx.typaram(cx.ident_of(name), bounds, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mk_generics(lifetimes: ~[ast::Lifetime], ty_params: ~[ast::TyParam]) -> Generics {
|
fn mk_generics(lifetimes: Vec<ast::Lifetime> , ty_params: Vec<ast::TyParam> ) -> Generics {
|
||||||
Generics {
|
Generics {
|
||||||
lifetimes: opt_vec::from(lifetimes),
|
lifetimes: opt_vec::from(lifetimes),
|
||||||
ty_params: opt_vec::from(ty_params)
|
ty_params: opt_vec::from(ty_params)
|
||||||
|
@ -204,14 +204,14 @@ fn mk_generics(lifetimes: ~[ast::Lifetime], ty_params: ~[ast::TyParam]) -> Gene
|
||||||
|
|
||||||
/// Lifetimes and bounds on type parameters
|
/// Lifetimes and bounds on type parameters
|
||||||
pub struct LifetimeBounds<'a> {
|
pub struct LifetimeBounds<'a> {
|
||||||
lifetimes: ~[&'a str],
|
lifetimes: Vec<&'a str> ,
|
||||||
bounds: ~[(&'a str, ~[Path<'a>])]
|
bounds: vec!((&'a str, Vec<Path<'a>> ))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> LifetimeBounds<'a> {
|
impl<'a> LifetimeBounds<'a> {
|
||||||
pub fn empty() -> LifetimeBounds<'static> {
|
pub fn empty() -> LifetimeBounds<'static> {
|
||||||
LifetimeBounds {
|
LifetimeBounds {
|
||||||
lifetimes: ~[], bounds: ~[]
|
lifetimes: Vec::new(), bounds: Vec::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn to_generics(&self,
|
pub fn to_generics(&self,
|
||||||
|
|
|
@ -21,16 +21,16 @@ pub fn expand_deriving_zero(cx: &mut ExtCtxt,
|
||||||
push: |@Item|) {
|
push: |@Item|) {
|
||||||
let trait_def = TraitDef {
|
let trait_def = TraitDef {
|
||||||
span: span,
|
span: span,
|
||||||
attributes: ~[],
|
attributes: Vec::new(),
|
||||||
path: Path::new(~["std", "num", "Zero"]),
|
path: Path::new(vec!("std", "num", "Zero")),
|
||||||
additional_bounds: ~[],
|
additional_bounds: Vec::new(),
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
methods: ~[
|
methods: vec!(
|
||||||
MethodDef {
|
MethodDef {
|
||||||
name: "zero",
|
name: "zero",
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
explicit_self: None,
|
explicit_self: None,
|
||||||
args: ~[],
|
args: Vec::new(),
|
||||||
ret_ty: Self,
|
ret_ty: Self,
|
||||||
inline: true,
|
inline: true,
|
||||||
const_nonmatching: false,
|
const_nonmatching: false,
|
||||||
|
@ -40,8 +40,8 @@ pub fn expand_deriving_zero(cx: &mut ExtCtxt,
|
||||||
name: "is_zero",
|
name: "is_zero",
|
||||||
generics: LifetimeBounds::empty(),
|
generics: LifetimeBounds::empty(),
|
||||||
explicit_self: borrowed_explicit_self(),
|
explicit_self: borrowed_explicit_self(),
|
||||||
args: ~[],
|
args: Vec::new(),
|
||||||
ret_ty: Literal(Path::new(~["bool"])),
|
ret_ty: Literal(Path::new(vec!("bool"))),
|
||||||
inline: true,
|
inline: true,
|
||||||
const_nonmatching: false,
|
const_nonmatching: false,
|
||||||
combine_substructure: |cx, span, substr| {
|
combine_substructure: |cx, span, substr| {
|
||||||
|
@ -52,19 +52,19 @@ pub fn expand_deriving_zero(cx: &mut ExtCtxt,
|
||||||
cx, span, substr)
|
cx, span, substr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
)
|
||||||
};
|
};
|
||||||
trait_def.expand(cx, mitem, item, push)
|
trait_def.expand(cx, mitem, item, push)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn zero_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> @Expr {
|
fn zero_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> @Expr {
|
||||||
let zero_ident = ~[
|
let zero_ident = vec!(
|
||||||
cx.ident_of("std"),
|
cx.ident_of("std"),
|
||||||
cx.ident_of("num"),
|
cx.ident_of("num"),
|
||||||
cx.ident_of("Zero"),
|
cx.ident_of("Zero"),
|
||||||
cx.ident_of("zero")
|
cx.ident_of("zero")
|
||||||
];
|
);
|
||||||
let zero_call = |span| cx.expr_call_global(span, zero_ident.clone(), ~[]);
|
let zero_call = |span| cx.expr_call_global(span, zero_ident.clone(), Vec::new());
|
||||||
|
|
||||||
return match *substr.fields {
|
return match *substr.fields {
|
||||||
StaticStruct(_, ref summary) => {
|
StaticStruct(_, ref summary) => {
|
||||||
|
|
|
@ -169,21 +169,21 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
|
||||||
let none_arm = {
|
let none_arm = {
|
||||||
let break_expr = fld.cx.expr(span, ast::ExprBreak(opt_ident));
|
let break_expr = fld.cx.expr(span, ast::ExprBreak(opt_ident));
|
||||||
let none_pat = fld.cx.pat_ident(span, none_ident);
|
let none_pat = fld.cx.pat_ident(span, none_ident);
|
||||||
fld.cx.arm(span, ~[none_pat], break_expr)
|
fld.cx.arm(span, vec!(none_pat), break_expr)
|
||||||
};
|
};
|
||||||
|
|
||||||
// `Some(<src_pat>) => <src_loop_block>`
|
// `Some(<src_pat>) => <src_loop_block>`
|
||||||
let some_arm =
|
let some_arm =
|
||||||
fld.cx.arm(span,
|
fld.cx.arm(span,
|
||||||
~[fld.cx.pat_enum(span, some_path, ~[src_pat])],
|
vec!(fld.cx.pat_enum(span, some_path, vec!(src_pat))),
|
||||||
fld.cx.expr_block(src_loop_block));
|
fld.cx.expr_block(src_loop_block));
|
||||||
|
|
||||||
// `match i.next() { ... }`
|
// `match i.next() { ... }`
|
||||||
let match_expr = {
|
let match_expr = {
|
||||||
let next_call_expr =
|
let next_call_expr =
|
||||||
fld.cx.expr_method_call(span, fld.cx.expr_path(local_path), next_ident, ~[]);
|
fld.cx.expr_method_call(span, fld.cx.expr_path(local_path), next_ident, Vec::new());
|
||||||
|
|
||||||
fld.cx.expr_match(span, next_call_expr, ~[none_arm, some_arm])
|
fld.cx.expr_match(span, next_call_expr, vec!(none_arm, some_arm))
|
||||||
};
|
};
|
||||||
|
|
||||||
// ['ident:] loop { ... }
|
// ['ident:] loop { ... }
|
||||||
|
@ -196,8 +196,8 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
|
||||||
// `match &mut <src_expr> { i => loop { ... } }`
|
// `match &mut <src_expr> { i => loop { ... } }`
|
||||||
let discrim = fld.cx.expr_mut_addr_of(span, src_expr);
|
let discrim = fld.cx.expr_mut_addr_of(span, src_expr);
|
||||||
let i_pattern = fld.cx.pat_ident(span, local_ident);
|
let i_pattern = fld.cx.pat_ident(span, local_ident);
|
||||||
let arm = fld.cx.arm(span, ~[i_pattern], loop_expr);
|
let arm = fld.cx.arm(span, vec!(i_pattern), loop_expr);
|
||||||
fld.cx.expr_match(span, discrim, ~[arm])
|
fld.cx.expr_match(span, discrim, vec!(arm))
|
||||||
}
|
}
|
||||||
|
|
||||||
ast::ExprLoop(loop_block, opt_ident) => {
|
ast::ExprLoop(loop_block, opt_ident) => {
|
||||||
|
@ -221,7 +221,7 @@ fn rename_loop_label(opt_ident: Option<Ident>,
|
||||||
let new_label = fresh_name(&label);
|
let new_label = fresh_name(&label);
|
||||||
let rename = (label, new_label);
|
let rename = (label, new_label);
|
||||||
fld.extsbox.info().pending_renames.push(rename);
|
fld.extsbox.info().pending_renames.push(rename);
|
||||||
let mut pending_renames = ~[rename];
|
let mut pending_renames = vec!(rename);
|
||||||
let mut rename_fld = renames_to_fold(&mut pending_renames);
|
let mut rename_fld = renames_to_fold(&mut pending_renames);
|
||||||
(Some(rename_fld.fold_ident(label)),
|
(Some(rename_fld.fold_ident(label)),
|
||||||
rename_fld.fold_block(loop_block))
|
rename_fld.fold_block(loop_block))
|
||||||
|
@ -607,10 +607,10 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander)
|
||||||
// oh dear heaven... this is going to include the enum
|
// oh dear heaven... this is going to include the enum
|
||||||
// names, as well... but that should be okay, as long as
|
// names, as well... but that should be okay, as long as
|
||||||
// the new names are gensyms for the old ones.
|
// the new names are gensyms for the old ones.
|
||||||
let mut name_finder = new_name_finder(~[]);
|
let mut name_finder = new_name_finder(Vec::new());
|
||||||
name_finder.visit_pat(expanded_pat,());
|
name_finder.visit_pat(expanded_pat,());
|
||||||
// generate fresh names, push them to a new pending list
|
// generate fresh names, push them to a new pending list
|
||||||
let mut new_pending_renames = ~[];
|
let mut new_pending_renames = Vec::new();
|
||||||
for ident in name_finder.ident_accumulator.iter() {
|
for ident in name_finder.ident_accumulator.iter() {
|
||||||
let new_name = fresh_name(ident);
|
let new_name = fresh_name(ident);
|
||||||
new_pending_renames.push((*ident,new_name));
|
new_pending_renames.push((*ident,new_name));
|
||||||
|
@ -657,7 +657,7 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander)
|
||||||
// array (passed in to the traversal)
|
// array (passed in to the traversal)
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
struct NewNameFinderContext {
|
struct NewNameFinderContext {
|
||||||
ident_accumulator: ~[ast::Ident],
|
ident_accumulator: Vec<ast::Ident> ,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Visitor<()> for NewNameFinderContext {
|
impl Visitor<()> for NewNameFinderContext {
|
||||||
|
@ -700,7 +700,7 @@ impl Visitor<()> for NewNameFinderContext {
|
||||||
// return a visitor that extracts the pat_ident paths
|
// return a visitor that extracts the pat_ident paths
|
||||||
// from a given thingy and puts them in a mutable
|
// from a given thingy and puts them in a mutable
|
||||||
// array (passed in to the traversal)
|
// array (passed in to the traversal)
|
||||||
pub fn new_name_finder(idents: ~[ast::Ident]) -> NewNameFinderContext {
|
pub fn new_name_finder(idents: Vec<ast::Ident> ) -> NewNameFinderContext {
|
||||||
NewNameFinderContext {
|
NewNameFinderContext {
|
||||||
ident_accumulator: idents,
|
ident_accumulator: idents,
|
||||||
}
|
}
|
||||||
|
@ -860,7 +860,7 @@ fn new_mark_folder(m: Mrk) -> Marker {
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply a given mark to the given token trees. Used prior to expansion of a macro.
|
// apply a given mark to the given token trees. Used prior to expansion of a macro.
|
||||||
fn mark_tts(tts: &[TokenTree], m: Mrk) -> ~[TokenTree] {
|
fn mark_tts(tts: &[TokenTree], m: Mrk) -> Vec<TokenTree> {
|
||||||
fold_tts(tts, &mut new_mark_folder(m))
|
fold_tts(tts, &mut new_mark_folder(m))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -917,7 +917,7 @@ mod test {
|
||||||
// array (passed in to the traversal)
|
// array (passed in to the traversal)
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
struct NewPathExprFinderContext {
|
struct NewPathExprFinderContext {
|
||||||
path_accumulator: ~[ast::Path],
|
path_accumulator: Vec<ast::Path> ,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Visitor<()> for NewPathExprFinderContext {
|
impl Visitor<()> for NewPathExprFinderContext {
|
||||||
|
@ -941,7 +941,7 @@ mod test {
|
||||||
// return a visitor that extracts the paths
|
// return a visitor that extracts the paths
|
||||||
// from a given pattern and puts them in a mutable
|
// from a given pattern and puts them in a mutable
|
||||||
// array (passed in to the traversal)
|
// array (passed in to the traversal)
|
||||||
pub fn new_path_finder(paths: ~[ast::Path]) -> NewPathExprFinderContext {
|
pub fn new_path_finder(paths: Vec<ast::Path> ) -> NewPathExprFinderContext {
|
||||||
NewPathExprFinderContext {
|
NewPathExprFinderContext {
|
||||||
path_accumulator: paths
|
path_accumulator: paths
|
||||||
}
|
}
|
||||||
|
@ -954,7 +954,7 @@ mod test {
|
||||||
fail!("lolwut")
|
fail!("lolwut")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_exported_macros(&mut self, _: ast::CrateNum) -> ~[~str] {
|
fn get_exported_macros(&mut self, _: ast::CrateNum) -> Vec<~str> {
|
||||||
fail!("lolwut")
|
fail!("lolwut")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -975,7 +975,7 @@ mod test {
|
||||||
let crate_ast = parse::parse_crate_from_source_str(
|
let crate_ast = parse::parse_crate_from_source_str(
|
||||||
~"<test>",
|
~"<test>",
|
||||||
src,
|
src,
|
||||||
~[],sess);
|
Vec::new(),sess);
|
||||||
// should fail:
|
// should fail:
|
||||||
let mut loader = ErrLoader;
|
let mut loader = ErrLoader;
|
||||||
expand_crate(sess,&mut loader,crate_ast);
|
expand_crate(sess,&mut loader,crate_ast);
|
||||||
|
@ -990,7 +990,7 @@ mod test {
|
||||||
let crate_ast = parse::parse_crate_from_source_str(
|
let crate_ast = parse::parse_crate_from_source_str(
|
||||||
~"<test>",
|
~"<test>",
|
||||||
src,
|
src,
|
||||||
~[],sess);
|
Vec::new(),sess);
|
||||||
// should fail:
|
// should fail:
|
||||||
let mut loader = ErrLoader;
|
let mut loader = ErrLoader;
|
||||||
expand_crate(sess,&mut loader,crate_ast);
|
expand_crate(sess,&mut loader,crate_ast);
|
||||||
|
@ -1004,7 +1004,7 @@ mod test {
|
||||||
let crate_ast = parse::parse_crate_from_source_str(
|
let crate_ast = parse::parse_crate_from_source_str(
|
||||||
~"<test>",
|
~"<test>",
|
||||||
src,
|
src,
|
||||||
~[], sess);
|
Vec::new(), sess);
|
||||||
// should fail:
|
// should fail:
|
||||||
let mut loader = ErrLoader;
|
let mut loader = ErrLoader;
|
||||||
expand_crate(sess, &mut loader, crate_ast);
|
expand_crate(sess, &mut loader, crate_ast);
|
||||||
|
@ -1014,9 +1014,9 @@ mod test {
|
||||||
let attr1 = make_dummy_attr ("foo");
|
let attr1 = make_dummy_attr ("foo");
|
||||||
let attr2 = make_dummy_attr ("bar");
|
let attr2 = make_dummy_attr ("bar");
|
||||||
let escape_attr = make_dummy_attr ("macro_escape");
|
let escape_attr = make_dummy_attr ("macro_escape");
|
||||||
let attrs1 = ~[attr1, escape_attr, attr2];
|
let attrs1 = vec!(attr1, escape_attr, attr2);
|
||||||
assert_eq!(contains_macro_escape (attrs1),true);
|
assert_eq!(contains_macro_escape (attrs1),true);
|
||||||
let attrs2 = ~[attr1,attr2];
|
let attrs2 = vec!(attr1,attr2);
|
||||||
assert_eq!(contains_macro_escape (attrs2),false);
|
assert_eq!(contains_macro_escape (attrs2),false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1082,48 +1082,30 @@ mod test {
|
||||||
// in principle, you might want to control this boolean on a per-varref basis,
|
// 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
|
// but that would make things even harder to understand, and might not be
|
||||||
// necessary for thorough testing.
|
// necessary for thorough testing.
|
||||||
type RenamingTest = (&'static str, ~[~[uint]], bool);
|
type RenamingTest = (&'static str, vec!(Vec<uint> ), bool);
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn automatic_renaming () {
|
fn automatic_renaming () {
|
||||||
let tests: ~[RenamingTest] =
|
let tests: Vec<RenamingTest> =
|
||||||
~[// b & c should get new names throughout, in the expr too:
|
vec!(// b & c should get new names throughout, in the expr too:
|
||||||
("fn a() -> int { let b = 13; let c = b; b+c }",
|
("fn a() -> int { let b = 13; let c = b; b+c }",
|
||||||
~[~[0,1],~[2]], false),
|
vec!(vec!(0,1),vec!(2)), false),
|
||||||
// both x's should be renamed (how is this causing a bug?)
|
// both x's should be renamed (how is this causing a bug?)
|
||||||
("fn main () {let x: int = 13;x;}",
|
("fn main () {let x: int = 13;x;}",
|
||||||
~[~[0]], false),
|
vec!(vec!(0)), false),
|
||||||
// the use of b after the + should be renamed, the other one not:
|
// the use of b after the + should be renamed, the other one not:
|
||||||
("macro_rules! f (($x:ident) => (b + $x)) fn a() -> int { let b = 13; f!(b)}",
|
("macro_rules! f (($x:ident) => (b + $x)) fn a() -> int { let b = 13; f!(b)}",
|
||||||
~[~[1]], false),
|
vec!(vec!(1)), false),
|
||||||
// the b before the plus should not be renamed (requires marks)
|
// the b before the plus should not be renamed (requires marks)
|
||||||
("macro_rules! f (($x:ident) => ({let b=9; ($x + b)})) fn a() -> int { f!(b)}",
|
("macro_rules! f (($x:ident) => ({let b=9; ($x + b)})) fn a() -> int { f!(b)}",
|
||||||
~[~[1]], false),
|
vec!(vec!(1)), false),
|
||||||
// the marks going in and out of letty should cancel, allowing that $x to
|
// the marks going in and out of letty should cancel, allowing that $x to
|
||||||
// capture the one following the semicolon.
|
// capture the one following the semicolon.
|
||||||
// this was an awesome test case, and caught a *lot* of bugs.
|
// this was an awesome test case, and caught a *lot* of bugs.
|
||||||
("macro_rules! letty(($x:ident) => (let $x = 15;))
|
("macro_rules! letty(($x:ident) => (let $x = 15;))
|
||||||
macro_rules! user(($x:ident) => ({letty!($x); $x}))
|
macro_rules! user(($x:ident) => ({letty!($x); $x}))
|
||||||
fn main() -> int {user!(z)}",
|
fn main() -> int {user!(z)}",
|
||||||
~[~[0]], false),
|
vec!(vec!(0)), false));
|
||||||
// no longer a fixme #8062: this test exposes a *potential* bug; our system does
|
|
||||||
// not behave exactly like MTWT, but a conversation with Matthew Flatt
|
|
||||||
// suggests that this can only occur in the presence of local-expand, which
|
|
||||||
// we have no plans to support.
|
|
||||||
// ("fn main() {let hrcoo = 19; macro_rules! getx(()=>(hrcoo)); getx!();}",
|
|
||||||
// ~[~[0]], true)
|
|
||||||
// FIXME #6994: the next string exposes the bug referred to in issue 6994, so I'm
|
|
||||||
// commenting it out.
|
|
||||||
// the z flows into and out of two macros (g & f) along one path, and one
|
|
||||||
// (just g) along the other, so the result of the whole thing should
|
|
||||||
// be "let z_123 = 3; z_123"
|
|
||||||
//"macro_rules! g (($x:ident) =>
|
|
||||||
// ({macro_rules! f(($y:ident)=>({let $y=3;$x}));f!($x)}))
|
|
||||||
// fn a(){g!(z)}"
|
|
||||||
// create a really evil test case where a $x appears inside a binding of $x
|
|
||||||
// but *shouldnt* bind because it was inserted by a different macro....
|
|
||||||
// can't write this test case until we have macro-generating macros.
|
|
||||||
];
|
|
||||||
for (idx,s) in tests.iter().enumerate() {
|
for (idx,s) in tests.iter().enumerate() {
|
||||||
run_renaming_test(s,idx);
|
run_renaming_test(s,idx);
|
||||||
}
|
}
|
||||||
|
@ -1137,12 +1119,12 @@ mod test {
|
||||||
};
|
};
|
||||||
let cr = expand_crate_str(teststr.to_owned());
|
let cr = expand_crate_str(teststr.to_owned());
|
||||||
// find the bindings:
|
// find the bindings:
|
||||||
let mut name_finder = new_name_finder(~[]);
|
let mut name_finder = new_name_finder(Vec::new());
|
||||||
visit::walk_crate(&mut name_finder,&cr,());
|
visit::walk_crate(&mut name_finder,&cr,());
|
||||||
let bindings = name_finder.ident_accumulator;
|
let bindings = name_finder.ident_accumulator;
|
||||||
|
|
||||||
// find the varrefs:
|
// find the varrefs:
|
||||||
let mut path_finder = new_path_finder(~[]);
|
let mut path_finder = new_path_finder(Vec::new());
|
||||||
visit::walk_crate(&mut path_finder,&cr,());
|
visit::walk_crate(&mut path_finder,&cr,());
|
||||||
let varrefs = path_finder.path_accumulator;
|
let varrefs = path_finder.path_accumulator;
|
||||||
|
|
||||||
|
@ -1205,11 +1187,11 @@ foo_module!()
|
||||||
";
|
";
|
||||||
let cr = expand_crate_str(crate_str);
|
let cr = expand_crate_str(crate_str);
|
||||||
// find the xx binding
|
// find the xx binding
|
||||||
let mut name_finder = new_name_finder(~[]);
|
let mut name_finder = new_name_finder(Vec::new());
|
||||||
visit::walk_crate(&mut name_finder, &cr, ());
|
visit::walk_crate(&mut name_finder, &cr, ());
|
||||||
let bindings = name_finder.ident_accumulator;
|
let bindings = name_finder.ident_accumulator;
|
||||||
|
|
||||||
let cxbinds: ~[&ast::Ident] =
|
let cxbinds: Vec<&ast::Ident> =
|
||||||
bindings.iter().filter(|b| {
|
bindings.iter().filter(|b| {
|
||||||
let ident = token::get_ident(**b);
|
let ident = token::get_ident(**b);
|
||||||
let string = ident.get();
|
let string = ident.get();
|
||||||
|
@ -1222,7 +1204,7 @@ foo_module!()
|
||||||
};
|
};
|
||||||
let resolved_binding = mtwt_resolve(*cxbind);
|
let resolved_binding = mtwt_resolve(*cxbind);
|
||||||
// find all the xx varrefs:
|
// find all the xx varrefs:
|
||||||
let mut path_finder = new_path_finder(~[]);
|
let mut path_finder = new_path_finder(Vec::new());
|
||||||
visit::walk_crate(&mut path_finder, &cr, ());
|
visit::walk_crate(&mut path_finder, &cr, ());
|
||||||
let varrefs = path_finder.path_accumulator;
|
let varrefs = path_finder.path_accumulator;
|
||||||
|
|
||||||
|
@ -1256,10 +1238,10 @@ foo_module!()
|
||||||
#[test]
|
#[test]
|
||||||
fn pat_idents(){
|
fn pat_idents(){
|
||||||
let pat = string_to_pat(~"(a,Foo{x:c @ (b,9),y:Bar(4,d)})");
|
let pat = string_to_pat(~"(a,Foo{x:c @ (b,9),y:Bar(4,d)})");
|
||||||
let mut pat_idents = new_name_finder(~[]);
|
let mut pat_idents = new_name_finder(Vec::new());
|
||||||
pat_idents.visit_pat(pat, ());
|
pat_idents.visit_pat(pat, ());
|
||||||
assert_eq!(pat_idents.ident_accumulator,
|
assert_eq!(pat_idents.ident_accumulator,
|
||||||
strs_to_idents(~["a","c","b","d"]));
|
strs_to_idents(vec!("a","c","b","d")));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,8 @@ struct Context<'a> {
|
||||||
|
|
||||||
// Parsed argument expressions and the types that we've found so far for
|
// Parsed argument expressions and the types that we've found so far for
|
||||||
// them.
|
// them.
|
||||||
args: ~[@ast::Expr],
|
args: Vec<@ast::Expr>,
|
||||||
arg_types: ~[Option<ArgumentType>],
|
arg_types: Vec<Option<ArgumentType>>,
|
||||||
// Parsed named expressions and the types that we've found for them so far.
|
// Parsed named expressions and the types that we've found for them so far.
|
||||||
// Note that we keep a side-array of the ordering of the named arguments
|
// Note that we keep a side-array of the ordering of the named arguments
|
||||||
// found to be sure that we can translate them in the same order that they
|
// found to be sure that we can translate them in the same order that they
|
||||||
|
@ -52,9 +52,9 @@ struct Context<'a> {
|
||||||
name_ordering: ~[~str],
|
name_ordering: ~[~str],
|
||||||
|
|
||||||
// Collection of the compiled `rt::Piece` structures
|
// Collection of the compiled `rt::Piece` structures
|
||||||
pieces: ~[@ast::Expr],
|
pieces: Vec<@ast::Expr> ,
|
||||||
name_positions: HashMap<~str, uint>,
|
name_positions: HashMap<~str, uint>,
|
||||||
method_statics: ~[@ast::Item],
|
method_statics: Vec<@ast::Item> ,
|
||||||
|
|
||||||
// Updated as arguments are consumed or methods are entered
|
// Updated as arguments are consumed or methods are entered
|
||||||
nest_level: uint,
|
nest_level: uint,
|
||||||
|
@ -70,10 +70,9 @@ struct Context<'a> {
|
||||||
/// Some((fmtstr, unnamed arguments, ordering of named arguments,
|
/// Some((fmtstr, unnamed arguments, ordering of named arguments,
|
||||||
/// named arguments))
|
/// named arguments))
|
||||||
fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
||||||
-> (@ast::Expr, Option<(@ast::Expr, ~[@ast::Expr], ~[~str],
|
-> (@ast::Expr, Option<(@ast::Expr, Vec<@ast::Expr>, ~[~str],
|
||||||
HashMap<~str, @ast::Expr>)>)
|
HashMap<~str, @ast::Expr>)>) {
|
||||||
{
|
let mut args = Vec::new();
|
||||||
let mut args = ~[];
|
|
||||||
let mut names = HashMap::<~str, @ast::Expr>::new();
|
let mut names = HashMap::<~str, @ast::Expr>::new();
|
||||||
let mut order = ~[];
|
let mut order = ~[];
|
||||||
|
|
||||||
|
@ -357,7 +356,7 @@ impl<'a> Context<'a> {
|
||||||
|
|
||||||
/// These attributes are applied to all statics that this syntax extension
|
/// These attributes are applied to all statics that this syntax extension
|
||||||
/// will generate.
|
/// will generate.
|
||||||
fn static_attrs(&self) -> ~[ast::Attribute] {
|
fn static_attrs(&self) -> Vec<ast::Attribute> {
|
||||||
// Flag statics as `address_insignificant` so LLVM can merge duplicate
|
// Flag statics as `address_insignificant` so LLVM can merge duplicate
|
||||||
// globals as much as possible (which we're generating a whole lot of).
|
// globals as much as possible (which we're generating a whole lot of).
|
||||||
let unnamed = self.ecx
|
let unnamed = self.ecx
|
||||||
|
@ -371,41 +370,41 @@ impl<'a> Context<'a> {
|
||||||
InternedString::new("dead_code"));
|
InternedString::new("dead_code"));
|
||||||
let allow_dead_code = self.ecx.meta_list(self.fmtsp,
|
let allow_dead_code = self.ecx.meta_list(self.fmtsp,
|
||||||
InternedString::new("allow"),
|
InternedString::new("allow"),
|
||||||
~[dead_code]);
|
vec!(dead_code));
|
||||||
let allow_dead_code = self.ecx.attribute(self.fmtsp, allow_dead_code);
|
let allow_dead_code = self.ecx.attribute(self.fmtsp, allow_dead_code);
|
||||||
return ~[unnamed, allow_dead_code];
|
return vec!(unnamed, allow_dead_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parsepath(&self, s: &str) -> ~[ast::Ident] {
|
fn parsepath(&self, s: &str) -> Vec<ast::Ident> {
|
||||||
~[self.ecx.ident_of("std"), self.ecx.ident_of("fmt"),
|
vec!(self.ecx.ident_of("std"), self.ecx.ident_of("fmt"),
|
||||||
self.ecx.ident_of("parse"), self.ecx.ident_of(s)]
|
self.ecx.ident_of("parse"), self.ecx.ident_of(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rtpath(&self, s: &str) -> ~[ast::Ident] {
|
fn rtpath(&self, s: &str) -> Vec<ast::Ident> {
|
||||||
~[self.ecx.ident_of("std"), self.ecx.ident_of("fmt"),
|
vec!(self.ecx.ident_of("std"), self.ecx.ident_of("fmt"),
|
||||||
self.ecx.ident_of("rt"), self.ecx.ident_of(s)]
|
self.ecx.ident_of("rt"), self.ecx.ident_of(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ctpath(&self, s: &str) -> ~[ast::Ident] {
|
fn ctpath(&self, s: &str) -> Vec<ast::Ident> {
|
||||||
~[self.ecx.ident_of("std"), self.ecx.ident_of("fmt"),
|
vec!(self.ecx.ident_of("std"), self.ecx.ident_of("fmt"),
|
||||||
self.ecx.ident_of("parse"), self.ecx.ident_of(s)]
|
self.ecx.ident_of("parse"), self.ecx.ident_of(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn none(&self) -> @ast::Expr {
|
fn none(&self) -> @ast::Expr {
|
||||||
let none = self.ecx.path_global(self.fmtsp, ~[
|
let none = self.ecx.path_global(self.fmtsp, vec!(
|
||||||
self.ecx.ident_of("std"),
|
self.ecx.ident_of("std"),
|
||||||
self.ecx.ident_of("option"),
|
self.ecx.ident_of("option"),
|
||||||
self.ecx.ident_of("None")]);
|
self.ecx.ident_of("None")));
|
||||||
self.ecx.expr_path(none)
|
self.ecx.expr_path(none)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn some(&self, e: @ast::Expr) -> @ast::Expr {
|
fn some(&self, e: @ast::Expr) -> @ast::Expr {
|
||||||
let p = self.ecx.path_global(self.fmtsp, ~[
|
let p = self.ecx.path_global(self.fmtsp, vec!(
|
||||||
self.ecx.ident_of("std"),
|
self.ecx.ident_of("std"),
|
||||||
self.ecx.ident_of("option"),
|
self.ecx.ident_of("option"),
|
||||||
self.ecx.ident_of("Some")]);
|
self.ecx.ident_of("Some")));
|
||||||
let p = self.ecx.expr_path(p);
|
let p = self.ecx.expr_path(p);
|
||||||
self.ecx.expr_call(self.fmtsp, p, ~[e])
|
self.ecx.expr_call(self.fmtsp, p, vec!(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trans_count(&self, c: parse::Count) -> @ast::Expr {
|
fn trans_count(&self, c: parse::Count) -> @ast::Expr {
|
||||||
|
@ -413,11 +412,11 @@ impl<'a> Context<'a> {
|
||||||
match c {
|
match c {
|
||||||
parse::CountIs(i) => {
|
parse::CountIs(i) => {
|
||||||
self.ecx.expr_call_global(sp, self.rtpath("CountIs"),
|
self.ecx.expr_call_global(sp, self.rtpath("CountIs"),
|
||||||
~[self.ecx.expr_uint(sp, i)])
|
vec!(self.ecx.expr_uint(sp, i)))
|
||||||
}
|
}
|
||||||
parse::CountIsParam(i) => {
|
parse::CountIsParam(i) => {
|
||||||
self.ecx.expr_call_global(sp, self.rtpath("CountIsParam"),
|
self.ecx.expr_call_global(sp, self.rtpath("CountIsParam"),
|
||||||
~[self.ecx.expr_uint(sp, i)])
|
vec!(self.ecx.expr_uint(sp, i)))
|
||||||
}
|
}
|
||||||
parse::CountImplied => {
|
parse::CountImplied => {
|
||||||
let path = self.ecx.path_global(sp, self.rtpath("CountImplied"));
|
let path = self.ecx.path_global(sp, self.rtpath("CountImplied"));
|
||||||
|
@ -434,7 +433,7 @@ impl<'a> Context<'a> {
|
||||||
};
|
};
|
||||||
let i = i + self.args.len();
|
let i = i + self.args.len();
|
||||||
self.ecx.expr_call_global(sp, self.rtpath("CountIsParam"),
|
self.ecx.expr_call_global(sp, self.rtpath("CountIsParam"),
|
||||||
~[self.ecx.expr_uint(sp, i)])
|
vec!(self.ecx.expr_uint(sp, i)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -450,21 +449,19 @@ impl<'a> Context<'a> {
|
||||||
}).collect();
|
}).collect();
|
||||||
let s = token::intern_and_get_ident(arm.selector);
|
let s = token::intern_and_get_ident(arm.selector);
|
||||||
let selector = self.ecx.expr_str(sp, s);
|
let selector = self.ecx.expr_str(sp, s);
|
||||||
self.ecx.expr_struct(sp, p, ~[
|
self.ecx.expr_struct(sp, p, vec!(
|
||||||
self.ecx.field_imm(sp,
|
self.ecx.field_imm(sp,
|
||||||
self.ecx.ident_of("selector"),
|
self.ecx.ident_of("selector"),
|
||||||
selector),
|
selector),
|
||||||
self.ecx.field_imm(sp, self.ecx.ident_of("result"),
|
self.ecx.field_imm(sp, self.ecx.ident_of("result"),
|
||||||
self.ecx.expr_vec_slice(sp, result)),
|
self.ecx.expr_vec_slice(sp, result))))
|
||||||
])
|
|
||||||
}).collect();
|
}).collect();
|
||||||
let default = default.iter().map(|p| {
|
let default = default.iter().map(|p| {
|
||||||
self.trans_piece(p)
|
self.trans_piece(p)
|
||||||
}).collect();
|
}).collect();
|
||||||
self.ecx.expr_call_global(sp, self.rtpath("Select"), ~[
|
self.ecx.expr_call_global(sp, self.rtpath("Select"), vec!(
|
||||||
self.ecx.expr_vec_slice(sp, arms),
|
self.ecx.expr_vec_slice(sp, arms),
|
||||||
self.ecx.expr_vec_slice(sp, default),
|
self.ecx.expr_vec_slice(sp, default)))
|
||||||
])
|
|
||||||
}
|
}
|
||||||
parse::Plural(offset, ref arms, ref default) => {
|
parse::Plural(offset, ref arms, ref default) => {
|
||||||
let offset = match offset {
|
let offset = match offset {
|
||||||
|
@ -487,23 +484,21 @@ impl<'a> Context<'a> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let selector = self.ecx.expr_call_global(sp,
|
let selector = self.ecx.expr_call_global(sp,
|
||||||
lr, ~[selarg]);
|
lr, vec!(selarg));
|
||||||
self.ecx.expr_struct(sp, p, ~[
|
self.ecx.expr_struct(sp, p, vec!(
|
||||||
self.ecx.field_imm(sp,
|
self.ecx.field_imm(sp,
|
||||||
self.ecx.ident_of("selector"),
|
self.ecx.ident_of("selector"),
|
||||||
selector),
|
selector),
|
||||||
self.ecx.field_imm(sp, self.ecx.ident_of("result"),
|
self.ecx.field_imm(sp, self.ecx.ident_of("result"),
|
||||||
self.ecx.expr_vec_slice(sp, result)),
|
self.ecx.expr_vec_slice(sp, result))))
|
||||||
])
|
|
||||||
}).collect();
|
}).collect();
|
||||||
let default = default.iter().map(|p| {
|
let default = default.iter().map(|p| {
|
||||||
self.trans_piece(p)
|
self.trans_piece(p)
|
||||||
}).collect();
|
}).collect();
|
||||||
self.ecx.expr_call_global(sp, self.rtpath("Plural"), ~[
|
self.ecx.expr_call_global(sp, self.rtpath("Plural"), vec!(
|
||||||
offset,
|
offset,
|
||||||
self.ecx.expr_vec_slice(sp, arms),
|
self.ecx.expr_vec_slice(sp, arms),
|
||||||
self.ecx.expr_vec_slice(sp, default),
|
self.ecx.expr_vec_slice(sp, default)))
|
||||||
])
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let life = self.ecx.lifetime(sp, self.ecx.ident_of("static").name);
|
let life = self.ecx.lifetime(sp, self.ecx.ident_of("static").name);
|
||||||
|
@ -512,7 +507,7 @@ impl<'a> Context<'a> {
|
||||||
true,
|
true,
|
||||||
self.rtpath("Method"),
|
self.rtpath("Method"),
|
||||||
opt_vec::with(life),
|
opt_vec::with(life),
|
||||||
~[]
|
Vec::new()
|
||||||
), None);
|
), None);
|
||||||
let st = ast::ItemStatic(ty, ast::MutImmutable, method);
|
let st = ast::ItemStatic(ty, ast::MutImmutable, method);
|
||||||
let static_name = self.ecx.ident_of(format!("__STATIC_METHOD_{}",
|
let static_name = self.ecx.ident_of(format!("__STATIC_METHOD_{}",
|
||||||
|
@ -530,13 +525,13 @@ impl<'a> Context<'a> {
|
||||||
let s = token::intern_and_get_ident(s);
|
let s = token::intern_and_get_ident(s);
|
||||||
self.ecx.expr_call_global(sp,
|
self.ecx.expr_call_global(sp,
|
||||||
self.rtpath("String"),
|
self.rtpath("String"),
|
||||||
~[
|
vec!(
|
||||||
self.ecx.expr_str(sp, s)
|
self.ecx.expr_str(sp, s)
|
||||||
])
|
))
|
||||||
}
|
}
|
||||||
parse::CurrentArgument => {
|
parse::CurrentArgument => {
|
||||||
let nil = self.ecx.expr_lit(sp, ast::LitNil);
|
let nil = self.ecx.expr_lit(sp, ast::LitNil);
|
||||||
self.ecx.expr_call_global(sp, self.rtpath("CurrentArgument"), ~[nil])
|
self.ecx.expr_call_global(sp, self.rtpath("CurrentArgument"), vec!(nil))
|
||||||
}
|
}
|
||||||
parse::Argument(ref arg) => {
|
parse::Argument(ref arg) => {
|
||||||
// Translate the position
|
// Translate the position
|
||||||
|
@ -549,7 +544,7 @@ impl<'a> Context<'a> {
|
||||||
}
|
}
|
||||||
parse::ArgumentIs(i) => {
|
parse::ArgumentIs(i) => {
|
||||||
self.ecx.expr_call_global(sp, self.rtpath("ArgumentIs"),
|
self.ecx.expr_call_global(sp, self.rtpath("ArgumentIs"),
|
||||||
~[self.ecx.expr_uint(sp, i)])
|
vec!(self.ecx.expr_uint(sp, i)))
|
||||||
}
|
}
|
||||||
// Named arguments are converted to positional arguments at
|
// Named arguments are converted to positional arguments at
|
||||||
// the end of the list of arguments
|
// the end of the list of arguments
|
||||||
|
@ -560,7 +555,7 @@ impl<'a> Context<'a> {
|
||||||
};
|
};
|
||||||
let i = i + self.args.len();
|
let i = i + self.args.len();
|
||||||
self.ecx.expr_call_global(sp, self.rtpath("ArgumentIs"),
|
self.ecx.expr_call_global(sp, self.rtpath("ArgumentIs"),
|
||||||
~[self.ecx.expr_uint(sp, i)])
|
vec!(self.ecx.expr_uint(sp, i)))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -583,13 +578,12 @@ impl<'a> Context<'a> {
|
||||||
let prec = self.trans_count(arg.format.precision);
|
let prec = self.trans_count(arg.format.precision);
|
||||||
let width = self.trans_count(arg.format.width);
|
let width = self.trans_count(arg.format.width);
|
||||||
let path = self.ecx.path_global(sp, self.rtpath("FormatSpec"));
|
let path = self.ecx.path_global(sp, self.rtpath("FormatSpec"));
|
||||||
let fmt = self.ecx.expr_struct(sp, path, ~[
|
let fmt = self.ecx.expr_struct(sp, path, vec!(
|
||||||
self.ecx.field_imm(sp, self.ecx.ident_of("fill"), fill),
|
self.ecx.field_imm(sp, self.ecx.ident_of("fill"), fill),
|
||||||
self.ecx.field_imm(sp, self.ecx.ident_of("align"), align),
|
self.ecx.field_imm(sp, self.ecx.ident_of("align"), align),
|
||||||
self.ecx.field_imm(sp, self.ecx.ident_of("flags"), flags),
|
self.ecx.field_imm(sp, self.ecx.ident_of("flags"), flags),
|
||||||
self.ecx.field_imm(sp, self.ecx.ident_of("precision"), prec),
|
self.ecx.field_imm(sp, self.ecx.ident_of("precision"), prec),
|
||||||
self.ecx.field_imm(sp, self.ecx.ident_of("width"), width),
|
self.ecx.field_imm(sp, self.ecx.ident_of("width"), width)));
|
||||||
]);
|
|
||||||
|
|
||||||
// Translate the method (if any)
|
// Translate the method (if any)
|
||||||
let method = match arg.method {
|
let method = match arg.method {
|
||||||
|
@ -600,12 +594,11 @@ impl<'a> Context<'a> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let path = self.ecx.path_global(sp, self.rtpath("Argument"));
|
let path = self.ecx.path_global(sp, self.rtpath("Argument"));
|
||||||
let s = self.ecx.expr_struct(sp, path, ~[
|
let s = self.ecx.expr_struct(sp, path, vec!(
|
||||||
self.ecx.field_imm(sp, self.ecx.ident_of("position"), pos),
|
self.ecx.field_imm(sp, self.ecx.ident_of("position"), pos),
|
||||||
self.ecx.field_imm(sp, self.ecx.ident_of("format"), fmt),
|
self.ecx.field_imm(sp, self.ecx.ident_of("format"), fmt),
|
||||||
self.ecx.field_imm(sp, self.ecx.ident_of("method"), method),
|
self.ecx.field_imm(sp, self.ecx.ident_of("method"), method)));
|
||||||
]);
|
self.ecx.expr_call_global(sp, self.rtpath("Argument"), vec!(s))
|
||||||
self.ecx.expr_call_global(sp, self.rtpath("Argument"), ~[s])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -613,11 +606,11 @@ impl<'a> Context<'a> {
|
||||||
/// Actually builds the expression which the iformat! block will be expanded
|
/// Actually builds the expression which the iformat! block will be expanded
|
||||||
/// to
|
/// to
|
||||||
fn to_expr(&self, extra: @ast::Expr) -> @ast::Expr {
|
fn to_expr(&self, extra: @ast::Expr) -> @ast::Expr {
|
||||||
let mut lets = ~[];
|
let mut lets = Vec::new();
|
||||||
let mut locals = ~[];
|
let mut locals = Vec::new();
|
||||||
let mut names = vec::from_fn(self.name_positions.len(), |_| None);
|
let mut names = vec::from_fn(self.name_positions.len(), |_| None);
|
||||||
let mut pats = ~[];
|
let mut pats = Vec::new();
|
||||||
let mut heads = ~[];
|
let mut heads = Vec::new();
|
||||||
|
|
||||||
// First, declare all of our methods that are statics
|
// First, declare all of our methods that are statics
|
||||||
for &method in self.method_statics.iter() {
|
for &method in self.method_statics.iter() {
|
||||||
|
@ -631,15 +624,14 @@ impl<'a> Context<'a> {
|
||||||
let fmt = self.ecx.expr_vec(self.fmtsp, self.pieces.clone());
|
let fmt = self.ecx.expr_vec(self.fmtsp, self.pieces.clone());
|
||||||
let piece_ty = self.ecx.ty_path(self.ecx.path_all(
|
let piece_ty = self.ecx.ty_path(self.ecx.path_all(
|
||||||
self.fmtsp,
|
self.fmtsp,
|
||||||
true, ~[
|
true, vec!(
|
||||||
self.ecx.ident_of("std"),
|
self.ecx.ident_of("std"),
|
||||||
self.ecx.ident_of("fmt"),
|
self.ecx.ident_of("fmt"),
|
||||||
self.ecx.ident_of("rt"),
|
self.ecx.ident_of("rt"),
|
||||||
self.ecx.ident_of("Piece"),
|
self.ecx.ident_of("Piece")),
|
||||||
],
|
|
||||||
opt_vec::with(
|
opt_vec::with(
|
||||||
self.ecx.lifetime(self.fmtsp, self.ecx.ident_of("static").name)),
|
self.ecx.lifetime(self.fmtsp, self.ecx.ident_of("static").name)),
|
||||||
~[]
|
Vec::new()
|
||||||
), None);
|
), None);
|
||||||
let ty = ast::TyFixedLengthVec(
|
let ty = ast::TyFixedLengthVec(
|
||||||
piece_ty,
|
piece_ty,
|
||||||
|
@ -696,18 +688,17 @@ impl<'a> Context<'a> {
|
||||||
// Now create the fmt::Arguments struct with all our locals we created.
|
// Now create the fmt::Arguments struct with all our locals we created.
|
||||||
let fmt = self.ecx.expr_ident(self.fmtsp, static_name);
|
let fmt = self.ecx.expr_ident(self.fmtsp, static_name);
|
||||||
let args_slice = self.ecx.expr_ident(self.fmtsp, slicename);
|
let args_slice = self.ecx.expr_ident(self.fmtsp, slicename);
|
||||||
let result = self.ecx.expr_call_global(self.fmtsp, ~[
|
let result = self.ecx.expr_call_global(self.fmtsp, vec!(
|
||||||
self.ecx.ident_of("std"),
|
self.ecx.ident_of("std"),
|
||||||
self.ecx.ident_of("fmt"),
|
self.ecx.ident_of("fmt"),
|
||||||
self.ecx.ident_of("Arguments"),
|
self.ecx.ident_of("Arguments"),
|
||||||
self.ecx.ident_of("new"),
|
self.ecx.ident_of("new")), vec!(fmt, args_slice));
|
||||||
], ~[fmt, args_slice]);
|
|
||||||
|
|
||||||
// We did all the work of making sure that the arguments
|
// We did all the work of making sure that the arguments
|
||||||
// structure is safe, so we can safely have an unsafe block.
|
// structure is safe, so we can safely have an unsafe block.
|
||||||
let result = self.ecx.expr_block(P(ast::Block {
|
let result = self.ecx.expr_block(P(ast::Block {
|
||||||
view_items: ~[],
|
view_items: Vec::new(),
|
||||||
stmts: ~[],
|
stmts: Vec::new(),
|
||||||
expr: Some(result),
|
expr: Some(result),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
rules: ast::UnsafeBlock(ast::CompilerGenerated),
|
rules: ast::UnsafeBlock(ast::CompilerGenerated),
|
||||||
|
@ -716,8 +707,8 @@ impl<'a> Context<'a> {
|
||||||
let resname = self.ecx.ident_of("__args");
|
let resname = self.ecx.ident_of("__args");
|
||||||
lets.push(self.ecx.stmt_let(self.fmtsp, false, resname, result));
|
lets.push(self.ecx.stmt_let(self.fmtsp, false, resname, result));
|
||||||
let res = self.ecx.expr_ident(self.fmtsp, resname);
|
let res = self.ecx.expr_ident(self.fmtsp, resname);
|
||||||
let result = self.ecx.expr_call(extra.span, extra, ~[
|
let result = self.ecx.expr_call(extra.span, extra, vec!(
|
||||||
self.ecx.expr_addr_of(extra.span, res)]);
|
self.ecx.expr_addr_of(extra.span, res)));
|
||||||
let body = self.ecx.expr_block(self.ecx.block(self.fmtsp, lets,
|
let body = self.ecx.expr_block(self.ecx.block(self.fmtsp, lets,
|
||||||
Some(result)));
|
Some(result)));
|
||||||
|
|
||||||
|
@ -749,9 +740,9 @@ impl<'a> Context<'a> {
|
||||||
// But the nested match expression is proved to perform not as well
|
// But the nested match expression is proved to perform not as well
|
||||||
// as series of let's; the first approach does.
|
// as series of let's; the first approach does.
|
||||||
let pat = self.ecx.pat(self.fmtsp, ast::PatTup(pats));
|
let pat = self.ecx.pat(self.fmtsp, ast::PatTup(pats));
|
||||||
let arm = self.ecx.arm(self.fmtsp, ~[pat], body);
|
let arm = self.ecx.arm(self.fmtsp, vec!(pat), body);
|
||||||
let head = self.ecx.expr(self.fmtsp, ast::ExprTup(heads));
|
let head = self.ecx.expr(self.fmtsp, ast::ExprTup(heads));
|
||||||
self.ecx.expr_match(self.fmtsp, head, ~[arm])
|
self.ecx.expr_match(self.fmtsp, head, vec!(arm))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_arg(&self, sp: Span, argno: Position, arg: @ast::Expr)
|
fn format_arg(&self, sp: Span, argno: Position, arg: @ast::Expr)
|
||||||
|
@ -787,31 +778,27 @@ impl<'a> Context<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String => {
|
String => {
|
||||||
return self.ecx.expr_call_global(sp, ~[
|
return self.ecx.expr_call_global(sp, vec!(
|
||||||
self.ecx.ident_of("std"),
|
self.ecx.ident_of("std"),
|
||||||
self.ecx.ident_of("fmt"),
|
self.ecx.ident_of("fmt"),
|
||||||
self.ecx.ident_of("argumentstr"),
|
self.ecx.ident_of("argumentstr")), vec!(arg))
|
||||||
], ~[arg])
|
|
||||||
}
|
}
|
||||||
Unsigned => {
|
Unsigned => {
|
||||||
return self.ecx.expr_call_global(sp, ~[
|
return self.ecx.expr_call_global(sp, vec!(
|
||||||
self.ecx.ident_of("std"),
|
self.ecx.ident_of("std"),
|
||||||
self.ecx.ident_of("fmt"),
|
self.ecx.ident_of("fmt"),
|
||||||
self.ecx.ident_of("argumentuint"),
|
self.ecx.ident_of("argumentuint")), vec!(arg))
|
||||||
], ~[arg])
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let format_fn = self.ecx.path_global(sp, ~[
|
let format_fn = self.ecx.path_global(sp, vec!(
|
||||||
self.ecx.ident_of("std"),
|
self.ecx.ident_of("std"),
|
||||||
self.ecx.ident_of("fmt"),
|
self.ecx.ident_of("fmt"),
|
||||||
self.ecx.ident_of(fmt_fn),
|
self.ecx.ident_of(fmt_fn)));
|
||||||
]);
|
self.ecx.expr_call_global(sp, vec!(
|
||||||
self.ecx.expr_call_global(sp, ~[
|
|
||||||
self.ecx.ident_of("std"),
|
self.ecx.ident_of("std"),
|
||||||
self.ecx.ident_of("fmt"),
|
self.ecx.ident_of("fmt"),
|
||||||
self.ecx.ident_of("argument"),
|
self.ecx.ident_of("argument")), vec!(self.ecx.expr_path(format_fn), arg))
|
||||||
], ~[self.ecx.expr_path(format_fn), arg])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -832,8 +819,8 @@ pub fn expand_args(ecx: &mut ExtCtxt, sp: Span,
|
||||||
/// expression.
|
/// expression.
|
||||||
pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span,
|
pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span,
|
||||||
extra: @ast::Expr,
|
extra: @ast::Expr,
|
||||||
efmt: @ast::Expr, args: ~[@ast::Expr],
|
efmt: @ast::Expr, args: Vec<@ast::Expr>,
|
||||||
name_ordering: ~[~str],
|
name_ordering: Vec<~str>,
|
||||||
names: HashMap<~str, @ast::Expr>) -> @ast::Expr {
|
names: HashMap<~str, @ast::Expr>) -> @ast::Expr {
|
||||||
let arg_types = vec::from_fn(args.len(), |_| None);
|
let arg_types = vec::from_fn(args.len(), |_| None);
|
||||||
let mut cx = Context {
|
let mut cx = Context {
|
||||||
|
@ -846,8 +833,8 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span,
|
||||||
name_ordering: name_ordering,
|
name_ordering: name_ordering,
|
||||||
nest_level: 0,
|
nest_level: 0,
|
||||||
next_arg: 0,
|
next_arg: 0,
|
||||||
pieces: ~[],
|
pieces: Vec::new(),
|
||||||
method_statics: ~[],
|
method_statics: Vec::new(),
|
||||||
fmtsp: sp,
|
fmtsp: sp,
|
||||||
};
|
};
|
||||||
cx.fmtsp = efmt.span;
|
cx.fmtsp = efmt.span;
|
||||||
|
|
|
@ -41,11 +41,11 @@ pub mod rt {
|
||||||
pub use codemap::{BytePos, Span, dummy_spanned};
|
pub use codemap::{BytePos, Span, dummy_spanned};
|
||||||
|
|
||||||
pub trait ToTokens {
|
pub trait ToTokens {
|
||||||
fn to_tokens(&self, _cx: &ExtCtxt) -> ~[TokenTree];
|
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> ;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToTokens for ~[TokenTree] {
|
impl ToTokens for Vec<TokenTree> {
|
||||||
fn to_tokens(&self, _cx: &ExtCtxt) -> ~[TokenTree] {
|
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
|
||||||
(*self).clone()
|
(*self).clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,7 @@ pub mod rt {
|
||||||
macro_rules! impl_to_tokens(
|
macro_rules! impl_to_tokens(
|
||||||
($t:ty) => (
|
($t:ty) => (
|
||||||
impl ToTokens for $t {
|
impl ToTokens for $t {
|
||||||
fn to_tokens(&self, cx: &ExtCtxt) -> ~[TokenTree] {
|
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
|
||||||
cx.parse_tts(self.to_source())
|
cx.parse_tts(self.to_source())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ pub mod rt {
|
||||||
macro_rules! impl_to_tokens_self(
|
macro_rules! impl_to_tokens_self(
|
||||||
($t:ty) => (
|
($t:ty) => (
|
||||||
impl<'a> ToTokens for $t {
|
impl<'a> ToTokens for $t {
|
||||||
fn to_tokens(&self, cx: &ExtCtxt) -> ~[TokenTree] {
|
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
|
||||||
cx.parse_tts(self.to_source())
|
cx.parse_tts(self.to_source())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ pub mod rt {
|
||||||
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_expr(&self, s: ~str) -> @ast::Expr;
|
||||||
fn parse_stmt(&self, s: ~str) -> @ast::Stmt;
|
fn parse_stmt(&self, s: ~str) -> @ast::Stmt;
|
||||||
fn parse_tts(&self, s: ~str) -> ~[ast::TokenTree];
|
fn parse_tts(&self, s: ~str) -> Vec<ast::TokenTree> ;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ExtParseUtils for ExtCtxt<'a> {
|
impl<'a> ExtParseUtils for ExtCtxt<'a> {
|
||||||
|
@ -266,7 +266,7 @@ pub mod rt {
|
||||||
parse::parse_stmt_from_source_str("<quote expansion>".to_str(),
|
parse::parse_stmt_from_source_str("<quote expansion>".to_str(),
|
||||||
s,
|
s,
|
||||||
self.cfg(),
|
self.cfg(),
|
||||||
~[],
|
Vec::new(),
|
||||||
self.parse_sess())
|
self.parse_sess())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ pub mod rt {
|
||||||
self.parse_sess())
|
self.parse_sess())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_tts(&self, s: ~str) -> ~[ast::TokenTree] {
|
fn parse_tts(&self, s: ~str) -> Vec<ast::TokenTree> {
|
||||||
parse::parse_tts_from_source_str("<quote expansion>".to_str(),
|
parse::parse_tts_from_source_str("<quote expansion>".to_str(),
|
||||||
s,
|
s,
|
||||||
self.cfg(),
|
self.cfg(),
|
||||||
|
@ -298,16 +298,16 @@ pub fn expand_quote_tokens(cx: &mut ExtCtxt,
|
||||||
pub fn expand_quote_expr(cx: &mut ExtCtxt,
|
pub fn expand_quote_expr(cx: &mut ExtCtxt,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tts: &[ast::TokenTree]) -> base::MacResult {
|
tts: &[ast::TokenTree]) -> base::MacResult {
|
||||||
let expanded = expand_parse_call(cx, sp, "parse_expr", ~[], tts);
|
let expanded = expand_parse_call(cx, sp, "parse_expr", Vec::new(), tts);
|
||||||
base::MRExpr(expanded)
|
base::MRExpr(expanded)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expand_quote_item(cx: &mut ExtCtxt,
|
pub fn expand_quote_item(cx: &mut ExtCtxt,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tts: &[ast::TokenTree]) -> base::MacResult {
|
tts: &[ast::TokenTree]) -> base::MacResult {
|
||||||
let e_attrs = cx.expr_vec_uniq(sp, ~[]);
|
let e_attrs = cx.expr_vec_uniq(sp, Vec::new());
|
||||||
let expanded = expand_parse_call(cx, sp, "parse_item",
|
let expanded = expand_parse_call(cx, sp, "parse_item",
|
||||||
~[e_attrs], tts);
|
vec!(e_attrs), tts);
|
||||||
base::MRExpr(expanded)
|
base::MRExpr(expanded)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ pub fn expand_quote_pat(cx: &mut ExtCtxt,
|
||||||
tts: &[ast::TokenTree]) -> base::MacResult {
|
tts: &[ast::TokenTree]) -> base::MacResult {
|
||||||
let e_refutable = cx.expr_lit(sp, ast::LitBool(true));
|
let e_refutable = cx.expr_lit(sp, ast::LitBool(true));
|
||||||
let expanded = expand_parse_call(cx, sp, "parse_pat",
|
let expanded = expand_parse_call(cx, sp, "parse_pat",
|
||||||
~[e_refutable], tts);
|
vec!(e_refutable), tts);
|
||||||
base::MRExpr(expanded)
|
base::MRExpr(expanded)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,20 +325,20 @@ pub fn expand_quote_ty(cx: &mut ExtCtxt,
|
||||||
tts: &[ast::TokenTree]) -> base::MacResult {
|
tts: &[ast::TokenTree]) -> base::MacResult {
|
||||||
let e_param_colons = cx.expr_lit(sp, ast::LitBool(false));
|
let e_param_colons = cx.expr_lit(sp, ast::LitBool(false));
|
||||||
let expanded = expand_parse_call(cx, sp, "parse_ty",
|
let expanded = expand_parse_call(cx, sp, "parse_ty",
|
||||||
~[e_param_colons], tts);
|
vec!(e_param_colons), tts);
|
||||||
base::MRExpr(expanded)
|
base::MRExpr(expanded)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expand_quote_stmt(cx: &mut ExtCtxt,
|
pub fn expand_quote_stmt(cx: &mut ExtCtxt,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tts: &[ast::TokenTree]) -> base::MacResult {
|
tts: &[ast::TokenTree]) -> base::MacResult {
|
||||||
let e_attrs = cx.expr_vec_uniq(sp, ~[]);
|
let e_attrs = cx.expr_vec_uniq(sp, Vec::new());
|
||||||
let expanded = expand_parse_call(cx, sp, "parse_stmt",
|
let expanded = expand_parse_call(cx, sp, "parse_stmt",
|
||||||
~[e_attrs], tts);
|
vec!(e_attrs), tts);
|
||||||
base::MRExpr(expanded)
|
base::MRExpr(expanded)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ids_ext(strs: ~[~str]) -> ~[ast::Ident] {
|
fn ids_ext(strs: Vec<~str> ) -> Vec<ast::Ident> {
|
||||||
strs.map(|str| str_to_ident(*str))
|
strs.map(|str| str_to_ident(*str))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,7 +352,7 @@ fn mk_ident(cx: &ExtCtxt, sp: Span, ident: ast::Ident) -> @ast::Expr {
|
||||||
cx.expr_method_call(sp,
|
cx.expr_method_call(sp,
|
||||||
cx.expr_ident(sp, id_ext("ext_cx")),
|
cx.expr_ident(sp, id_ext("ext_cx")),
|
||||||
id_ext("ident_of"),
|
id_ext("ident_of"),
|
||||||
~[e_str])
|
vec!(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 {
|
||||||
|
@ -377,18 +377,18 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
|
||||||
BINOP(binop) => {
|
BINOP(binop) => {
|
||||||
return cx.expr_call_ident(sp,
|
return cx.expr_call_ident(sp,
|
||||||
id_ext("BINOP"),
|
id_ext("BINOP"),
|
||||||
~[mk_binop(cx, sp, binop)]);
|
vec!(mk_binop(cx, sp, binop)));
|
||||||
}
|
}
|
||||||
BINOPEQ(binop) => {
|
BINOPEQ(binop) => {
|
||||||
return cx.expr_call_ident(sp,
|
return cx.expr_call_ident(sp,
|
||||||
id_ext("BINOPEQ"),
|
id_ext("BINOPEQ"),
|
||||||
~[mk_binop(cx, sp, binop)]);
|
vec!(mk_binop(cx, sp, binop)));
|
||||||
}
|
}
|
||||||
|
|
||||||
LIT_CHAR(i) => {
|
LIT_CHAR(i) => {
|
||||||
let e_char = cx.expr_lit(sp, ast::LitChar(i));
|
let e_char = cx.expr_lit(sp, ast::LitChar(i));
|
||||||
|
|
||||||
return cx.expr_call_ident(sp, id_ext("LIT_CHAR"), ~[e_char]);
|
return cx.expr_call_ident(sp, id_ext("LIT_CHAR"), vec!(e_char));
|
||||||
}
|
}
|
||||||
|
|
||||||
LIT_INT(i, ity) => {
|
LIT_INT(i, ity) => {
|
||||||
|
@ -405,7 +405,7 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
|
||||||
|
|
||||||
return cx.expr_call_ident(sp,
|
return cx.expr_call_ident(sp,
|
||||||
id_ext("LIT_INT"),
|
id_ext("LIT_INT"),
|
||||||
~[e_i64, e_ity]);
|
vec!(e_i64, e_ity));
|
||||||
}
|
}
|
||||||
|
|
||||||
LIT_UINT(u, uty) => {
|
LIT_UINT(u, uty) => {
|
||||||
|
@ -422,7 +422,7 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
|
||||||
|
|
||||||
return cx.expr_call_ident(sp,
|
return cx.expr_call_ident(sp,
|
||||||
id_ext("LIT_UINT"),
|
id_ext("LIT_UINT"),
|
||||||
~[e_u64, e_uty]);
|
vec!(e_u64, e_uty));
|
||||||
}
|
}
|
||||||
|
|
||||||
LIT_INT_UNSUFFIXED(i) => {
|
LIT_INT_UNSUFFIXED(i) => {
|
||||||
|
@ -430,7 +430,7 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
|
||||||
|
|
||||||
return cx.expr_call_ident(sp,
|
return cx.expr_call_ident(sp,
|
||||||
id_ext("LIT_INT_UNSUFFIXED"),
|
id_ext("LIT_INT_UNSUFFIXED"),
|
||||||
~[e_i64]);
|
vec!(e_i64));
|
||||||
}
|
}
|
||||||
|
|
||||||
LIT_FLOAT(fident, fty) => {
|
LIT_FLOAT(fident, fty) => {
|
||||||
|
@ -444,39 +444,39 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
|
||||||
|
|
||||||
return cx.expr_call_ident(sp,
|
return cx.expr_call_ident(sp,
|
||||||
id_ext("LIT_FLOAT"),
|
id_ext("LIT_FLOAT"),
|
||||||
~[e_fident, e_fty]);
|
vec!(e_fident, e_fty));
|
||||||
}
|
}
|
||||||
|
|
||||||
LIT_STR(ident) => {
|
LIT_STR(ident) => {
|
||||||
return cx.expr_call_ident(sp,
|
return cx.expr_call_ident(sp,
|
||||||
id_ext("LIT_STR"),
|
id_ext("LIT_STR"),
|
||||||
~[mk_ident(cx, sp, ident)]);
|
vec!(mk_ident(cx, sp, ident)));
|
||||||
}
|
}
|
||||||
|
|
||||||
LIT_STR_RAW(ident, n) => {
|
LIT_STR_RAW(ident, n) => {
|
||||||
return cx.expr_call_ident(sp,
|
return cx.expr_call_ident(sp,
|
||||||
id_ext("LIT_STR_RAW"),
|
id_ext("LIT_STR_RAW"),
|
||||||
~[mk_ident(cx, sp, ident),
|
vec!(mk_ident(cx, sp, ident),
|
||||||
cx.expr_uint(sp, n)]);
|
cx.expr_uint(sp, n)));
|
||||||
}
|
}
|
||||||
|
|
||||||
IDENT(ident, b) => {
|
IDENT(ident, b) => {
|
||||||
return cx.expr_call_ident(sp,
|
return cx.expr_call_ident(sp,
|
||||||
id_ext("IDENT"),
|
id_ext("IDENT"),
|
||||||
~[mk_ident(cx, sp, ident),
|
vec!(mk_ident(cx, sp, ident),
|
||||||
cx.expr_bool(sp, b)]);
|
cx.expr_bool(sp, b)));
|
||||||
}
|
}
|
||||||
|
|
||||||
LIFETIME(ident) => {
|
LIFETIME(ident) => {
|
||||||
return cx.expr_call_ident(sp,
|
return cx.expr_call_ident(sp,
|
||||||
id_ext("LIFETIME"),
|
id_ext("LIFETIME"),
|
||||||
~[mk_ident(cx, sp, ident)]);
|
vec!(mk_ident(cx, sp, ident)));
|
||||||
}
|
}
|
||||||
|
|
||||||
DOC_COMMENT(ident) => {
|
DOC_COMMENT(ident) => {
|
||||||
return cx.expr_call_ident(sp,
|
return cx.expr_call_ident(sp,
|
||||||
id_ext("DOC_COMMENT"),
|
id_ext("DOC_COMMENT"),
|
||||||
~[mk_ident(cx, sp, ident)]);
|
vec!(mk_ident(cx, sp, ident)));
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERPOLATED(_) => fail!("quote! with interpolated token"),
|
INTERPOLATED(_) => fail!("quote! with interpolated token"),
|
||||||
|
@ -523,7 +523,7 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn mk_tt(cx: &ExtCtxt, sp: Span, tt: &ast::TokenTree) -> ~[@ast::Stmt] {
|
fn mk_tt(cx: &ExtCtxt, sp: Span, tt: &ast::TokenTree) -> Vec<@ast::Stmt> {
|
||||||
|
|
||||||
match *tt {
|
match *tt {
|
||||||
|
|
||||||
|
@ -531,13 +531,13 @@ fn mk_tt(cx: &ExtCtxt, sp: Span, tt: &ast::TokenTree) -> ~[@ast::Stmt] {
|
||||||
let e_sp = cx.expr_ident(sp, id_ext("_sp"));
|
let e_sp = cx.expr_ident(sp, id_ext("_sp"));
|
||||||
let e_tok = cx.expr_call_ident(sp,
|
let e_tok = cx.expr_call_ident(sp,
|
||||||
id_ext("TTTok"),
|
id_ext("TTTok"),
|
||||||
~[e_sp, mk_token(cx, sp, tok)]);
|
vec!(e_sp, mk_token(cx, sp, tok)));
|
||||||
let e_push =
|
let e_push =
|
||||||
cx.expr_method_call(sp,
|
cx.expr_method_call(sp,
|
||||||
cx.expr_ident(sp, id_ext("tt")),
|
cx.expr_ident(sp, id_ext("tt")),
|
||||||
id_ext("push"),
|
id_ext("push"),
|
||||||
~[e_tok]);
|
vec!(e_tok));
|
||||||
~[cx.stmt_expr(e_push)]
|
vec!(cx.stmt_expr(e_push))
|
||||||
}
|
}
|
||||||
|
|
||||||
ast::TTDelim(ref tts) => mk_tts(cx, sp, **tts),
|
ast::TTDelim(ref tts) => mk_tts(cx, sp, **tts),
|
||||||
|
@ -551,22 +551,22 @@ fn mk_tt(cx: &ExtCtxt, sp: Span, tt: &ast::TokenTree) -> ~[@ast::Stmt] {
|
||||||
cx.expr_method_call(sp,
|
cx.expr_method_call(sp,
|
||||||
cx.expr_ident(sp, ident),
|
cx.expr_ident(sp, ident),
|
||||||
id_ext("to_tokens"),
|
id_ext("to_tokens"),
|
||||||
~[cx.expr_ident(sp, id_ext("ext_cx"))]);
|
vec!(cx.expr_ident(sp, id_ext("ext_cx"))));
|
||||||
|
|
||||||
let e_push =
|
let e_push =
|
||||||
cx.expr_method_call(sp,
|
cx.expr_method_call(sp,
|
||||||
cx.expr_ident(sp, id_ext("tt")),
|
cx.expr_ident(sp, id_ext("tt")),
|
||||||
id_ext("push_all_move"),
|
id_ext("push_all_move"),
|
||||||
~[e_to_toks]);
|
vec!(e_to_toks));
|
||||||
|
|
||||||
~[cx.stmt_expr(e_push)]
|
vec!(cx.stmt_expr(e_push))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mk_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
fn mk_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
||||||
-> ~[@ast::Stmt] {
|
-> Vec<@ast::Stmt> {
|
||||||
let mut ss = ~[];
|
let mut ss = Vec::new();
|
||||||
for tt in tts.iter() {
|
for tt in tts.iter() {
|
||||||
ss.push_all_move(mk_tt(cx, sp, tt));
|
ss.push_all_move(mk_tt(cx, sp, tt));
|
||||||
}
|
}
|
||||||
|
@ -623,7 +623,7 @@ fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
||||||
let e_sp = cx.expr_method_call(sp,
|
let e_sp = cx.expr_method_call(sp,
|
||||||
cx.expr_ident(sp, id_ext("ext_cx")),
|
cx.expr_ident(sp, id_ext("ext_cx")),
|
||||||
id_ext("call_site"),
|
id_ext("call_site"),
|
||||||
~[]);
|
Vec::new());
|
||||||
|
|
||||||
let stmt_let_sp = cx.stmt_let(sp, false,
|
let stmt_let_sp = cx.stmt_let(sp, false,
|
||||||
id_ext("_sp"),
|
id_ext("_sp"),
|
||||||
|
@ -631,12 +631,12 @@ fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
||||||
|
|
||||||
let stmt_let_tt = cx.stmt_let(sp, true,
|
let stmt_let_tt = cx.stmt_let(sp, true,
|
||||||
id_ext("tt"),
|
id_ext("tt"),
|
||||||
cx.expr_vec_uniq(sp, ~[]));
|
cx.expr_vec_uniq(sp, Vec::new()));
|
||||||
|
|
||||||
let block = cx.expr_block(
|
let block = cx.expr_block(
|
||||||
cx.block_all(sp,
|
cx.block_all(sp,
|
||||||
~[],
|
Vec::new(),
|
||||||
~[stmt_let_sp, stmt_let_tt] + mk_tts(cx, sp, tts),
|
vec!(stmt_let_sp, stmt_let_tt) + mk_tts(cx, sp, tts),
|
||||||
Some(cx.expr_ident(sp, id_ext("tt")))));
|
Some(cx.expr_ident(sp, id_ext("tt")))));
|
||||||
|
|
||||||
(cx_expr, block)
|
(cx_expr, block)
|
||||||
|
@ -646,36 +646,36 @@ fn expand_wrapper(cx: &ExtCtxt,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
cx_expr: @ast::Expr,
|
cx_expr: @ast::Expr,
|
||||||
expr: @ast::Expr) -> @ast::Expr {
|
expr: @ast::Expr) -> @ast::Expr {
|
||||||
let uses = ~[ cx.view_use_glob(sp, ast::Inherited,
|
let uses = vec!( cx.view_use_glob(sp, ast::Inherited,
|
||||||
ids_ext(~[~"syntax",
|
ids_ext(vec!(~"syntax",
|
||||||
~"ext",
|
~"ext",
|
||||||
~"quote",
|
~"quote",
|
||||||
~"rt"])) ];
|
~"rt"))) );
|
||||||
|
|
||||||
let stmt_let_ext_cx = cx.stmt_let(sp, false, id_ext("ext_cx"), cx_expr);
|
let stmt_let_ext_cx = cx.stmt_let(sp, false, id_ext("ext_cx"), cx_expr);
|
||||||
|
|
||||||
cx.expr_block(cx.block_all(sp, uses, ~[stmt_let_ext_cx], Some(expr)))
|
cx.expr_block(cx.block_all(sp, uses, vec!(stmt_let_ext_cx), Some(expr)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expand_parse_call(cx: &ExtCtxt,
|
fn expand_parse_call(cx: &ExtCtxt,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
parse_method: &str,
|
parse_method: &str,
|
||||||
arg_exprs: ~[@ast::Expr],
|
arg_exprs: Vec<@ast::Expr> ,
|
||||||
tts: &[ast::TokenTree]) -> @ast::Expr {
|
tts: &[ast::TokenTree]) -> @ast::Expr {
|
||||||
let (cx_expr, tts_expr) = expand_tts(cx, sp, tts);
|
let (cx_expr, tts_expr) = expand_tts(cx, sp, tts);
|
||||||
|
|
||||||
let cfg_call = || cx.expr_method_call(
|
let cfg_call = || cx.expr_method_call(
|
||||||
sp, cx.expr_ident(sp, id_ext("ext_cx")),
|
sp, cx.expr_ident(sp, id_ext("ext_cx")),
|
||||||
id_ext("cfg"), ~[]);
|
id_ext("cfg"), Vec::new());
|
||||||
|
|
||||||
let parse_sess_call = || cx.expr_method_call(
|
let parse_sess_call = || cx.expr_method_call(
|
||||||
sp, cx.expr_ident(sp, id_ext("ext_cx")),
|
sp, cx.expr_ident(sp, id_ext("ext_cx")),
|
||||||
id_ext("parse_sess"), ~[]);
|
id_ext("parse_sess"), Vec::new());
|
||||||
|
|
||||||
let new_parser_call =
|
let new_parser_call =
|
||||||
cx.expr_call(sp,
|
cx.expr_call(sp,
|
||||||
cx.expr_ident(sp, id_ext("new_parser_from_tts")),
|
cx.expr_ident(sp, id_ext("new_parser_from_tts")),
|
||||||
~[parse_sess_call(), cfg_call(), tts_expr]);
|
vec!(parse_sess_call(), cfg_call(), tts_expr));
|
||||||
|
|
||||||
let expr = cx.expr_method_call(sp, new_parser_call, id_ext(parse_method),
|
let expr = cx.expr_method_call(sp, new_parser_call, id_ext(parse_method),
|
||||||
arg_exprs);
|
arg_exprs);
|
||||||
|
|
|
@ -16,7 +16,7 @@ use visit;
|
||||||
use visit::Visitor;
|
use visit::Visitor;
|
||||||
|
|
||||||
struct MacroRegistrarContext {
|
struct MacroRegistrarContext {
|
||||||
registrars: ~[(ast::NodeId, Span)],
|
registrars: Vec<(ast::NodeId, Span)> ,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Visitor<()> for MacroRegistrarContext {
|
impl Visitor<()> for MacroRegistrarContext {
|
||||||
|
@ -36,7 +36,7 @@ impl Visitor<()> for MacroRegistrarContext {
|
||||||
|
|
||||||
pub fn find_macro_registrar(diagnostic: @diagnostic::SpanHandler,
|
pub fn find_macro_registrar(diagnostic: @diagnostic::SpanHandler,
|
||||||
krate: &ast::Crate) -> Option<ast::DefId> {
|
krate: &ast::Crate) -> Option<ast::DefId> {
|
||||||
let mut ctx = MacroRegistrarContext { registrars: ~[] };
|
let mut ctx = MacroRegistrarContext { registrars: Vec::new() };
|
||||||
visit::walk_crate(&mut ctx, krate, ());
|
visit::walk_crate(&mut ctx, krate, ());
|
||||||
|
|
||||||
match ctx.registrars.len() {
|
match ctx.registrars.len() {
|
||||||
|
|
|
@ -99,11 +99,11 @@ nonempty body. */
|
||||||
|
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
pub struct MatcherPos {
|
pub struct MatcherPos {
|
||||||
elts: ~[ast::Matcher], // maybe should be <'>? Need to understand regions.
|
elts: Vec<ast::Matcher> , // maybe should be <'>? Need to understand regions.
|
||||||
sep: Option<Token>,
|
sep: Option<Token>,
|
||||||
idx: uint,
|
idx: uint,
|
||||||
up: Option<~MatcherPos>,
|
up: Option<~MatcherPos>,
|
||||||
matches: ~[~[@NamedMatch]],
|
matches: vec!(Vec<@NamedMatch> ),
|
||||||
match_lo: uint, match_hi: uint,
|
match_lo: uint, match_hi: uint,
|
||||||
sp_lo: BytePos,
|
sp_lo: BytePos,
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ pub fn count_names(ms: &[Matcher]) -> uint {
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initial_matcher_pos(ms: ~[Matcher], sep: Option<Token>, lo: BytePos)
|
pub fn initial_matcher_pos(ms: Vec<Matcher> , sep: Option<Token>, lo: BytePos)
|
||||||
-> ~MatcherPos {
|
-> ~MatcherPos {
|
||||||
let mut match_idx_hi = 0u;
|
let mut match_idx_hi = 0u;
|
||||||
for elt in ms.iter() {
|
for elt in ms.iter() {
|
||||||
|
@ -131,7 +131,7 @@ pub fn initial_matcher_pos(ms: ~[Matcher], sep: Option<Token>, lo: BytePos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let matches = vec::from_fn(count_names(ms), |_i| ~[]);
|
let matches = vec::from_fn(count_names(ms), |_i| Vec::new());
|
||||||
~MatcherPos {
|
~MatcherPos {
|
||||||
elts: ms,
|
elts: ms,
|
||||||
sep: sep,
|
sep: sep,
|
||||||
|
@ -164,7 +164,7 @@ pub fn initial_matcher_pos(ms: ~[Matcher], sep: Option<Token>, lo: BytePos)
|
||||||
// ast::Matcher it was derived from.
|
// ast::Matcher it was derived from.
|
||||||
|
|
||||||
pub enum NamedMatch {
|
pub enum NamedMatch {
|
||||||
MatchedSeq(~[@NamedMatch], codemap::Span),
|
MatchedSeq(Vec<@NamedMatch> , codemap::Span),
|
||||||
MatchedNonterminal(Nonterminal)
|
MatchedNonterminal(Nonterminal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ pub enum ParseResult {
|
||||||
pub fn parse_or_else<R: Reader>(sess: @ParseSess,
|
pub fn parse_or_else<R: Reader>(sess: @ParseSess,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
rdr: R,
|
rdr: R,
|
||||||
ms: ~[Matcher])
|
ms: Vec<Matcher> )
|
||||||
-> HashMap<Ident, @NamedMatch> {
|
-> HashMap<Ident, @NamedMatch> {
|
||||||
match parse(sess, cfg, rdr, ms) {
|
match parse(sess, cfg, rdr, ms) {
|
||||||
Success(m) => m,
|
Success(m) => m,
|
||||||
|
@ -230,13 +230,13 @@ pub fn parse<R: Reader>(sess: @ParseSess,
|
||||||
rdr: R,
|
rdr: R,
|
||||||
ms: &[Matcher])
|
ms: &[Matcher])
|
||||||
-> ParseResult {
|
-> ParseResult {
|
||||||
let mut cur_eis = ~[];
|
let mut cur_eis = Vec::new();
|
||||||
cur_eis.push(initial_matcher_pos(ms.to_owned(), None, rdr.peek().sp.lo));
|
cur_eis.push(initial_matcher_pos(ms.to_owned(), None, rdr.peek().sp.lo));
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let mut bb_eis = ~[]; // black-box parsed by parser.rs
|
let mut bb_eis = Vec::new(); // black-box parsed by parser.rs
|
||||||
let mut next_eis = ~[]; // or proceed normally
|
let mut next_eis = Vec::new(); // or proceed normally
|
||||||
let mut eof_eis = ~[];
|
let mut eof_eis = Vec::new();
|
||||||
|
|
||||||
let TokenAndSpan {tok: tok, sp: sp} = rdr.peek();
|
let TokenAndSpan {tok: tok, sp: sp} = rdr.peek();
|
||||||
|
|
||||||
|
@ -317,13 +317,13 @@ pub fn parse<R: Reader>(sess: @ParseSess,
|
||||||
new_ei.idx += 1u;
|
new_ei.idx += 1u;
|
||||||
//we specifically matched zero repeats.
|
//we specifically matched zero repeats.
|
||||||
for idx in range(match_idx_lo, match_idx_hi) {
|
for idx in range(match_idx_lo, match_idx_hi) {
|
||||||
new_ei.matches[idx].push(@MatchedSeq(~[], sp));
|
new_ei.matches[idx].push(@MatchedSeq(Vec::new(), sp));
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_eis.push(new_ei);
|
cur_eis.push(new_ei);
|
||||||
}
|
}
|
||||||
|
|
||||||
let matches = vec::from_elem(ei.matches.len(), ~[]);
|
let matches = vec::from_elem(ei.matches.len(), Vec::new());
|
||||||
let ei_t = ei;
|
let ei_t = ei;
|
||||||
cur_eis.push(~MatcherPos {
|
cur_eis.push(~MatcherPos {
|
||||||
elts: (*matchers).clone(),
|
elts: (*matchers).clone(),
|
||||||
|
@ -351,7 +351,7 @@ pub fn parse<R: Reader>(sess: @ParseSess,
|
||||||
/* error messages here could be improved with links to orig. rules */
|
/* error messages here could be improved with links to orig. rules */
|
||||||
if token_name_eq(&tok, &EOF) {
|
if token_name_eq(&tok, &EOF) {
|
||||||
if eof_eis.len() == 1u {
|
if eof_eis.len() == 1u {
|
||||||
let mut v = ~[];
|
let mut v = Vec::new();
|
||||||
for dv in eof_eis[0u].matches.mut_iter() {
|
for dv in eof_eis[0u].matches.mut_iter() {
|
||||||
v.push(dv.pop().unwrap());
|
v.push(dv.pop().unwrap());
|
||||||
}
|
}
|
||||||
|
@ -413,12 +413,12 @@ pub fn parse<R: Reader>(sess: @ParseSess,
|
||||||
|
|
||||||
pub fn parse_nt(p: &mut Parser, name: &str) -> Nonterminal {
|
pub fn parse_nt(p: &mut Parser, name: &str) -> Nonterminal {
|
||||||
match name {
|
match name {
|
||||||
"item" => match p.parse_item(~[]) {
|
"item" => match p.parse_item(Vec::new()) {
|
||||||
Some(i) => token::NtItem(i),
|
Some(i) => token::NtItem(i),
|
||||||
None => p.fatal("expected an item keyword")
|
None => p.fatal("expected an item keyword")
|
||||||
},
|
},
|
||||||
"block" => token::NtBlock(p.parse_block()),
|
"block" => token::NtBlock(p.parse_block()),
|
||||||
"stmt" => token::NtStmt(p.parse_stmt(~[])),
|
"stmt" => token::NtStmt(p.parse_stmt(Vec::new())),
|
||||||
"pat" => token::NtPat(p.parse_pat()),
|
"pat" => token::NtPat(p.parse_pat()),
|
||||||
"expr" => token::NtExpr(p.parse_expr()),
|
"expr" => token::NtExpr(p.parse_expr()),
|
||||||
"ty" => token::NtTy(p.parse_ty(false /* no need to disambiguate*/)),
|
"ty" => token::NtTy(p.parse_ty(false /* no need to disambiguate*/)),
|
||||||
|
|
|
@ -90,8 +90,8 @@ impl AnyMacro for ParserAnyMacro {
|
||||||
|
|
||||||
struct MacroRulesMacroExpander {
|
struct MacroRulesMacroExpander {
|
||||||
name: Ident,
|
name: Ident,
|
||||||
lhses: @~[@NamedMatch],
|
lhses: @Vec<@NamedMatch> ,
|
||||||
rhses: @~[@NamedMatch],
|
rhses: @Vec<@NamedMatch> ,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MacroExpander for MacroRulesMacroExpander {
|
impl MacroExpander for MacroRulesMacroExpander {
|
||||||
|
@ -174,7 +174,7 @@ fn generic_extension(cx: &ExtCtxt,
|
||||||
pub fn add_new_extension(cx: &mut ExtCtxt,
|
pub fn add_new_extension(cx: &mut ExtCtxt,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
arg: ~[ast::TokenTree])
|
arg: Vec<ast::TokenTree> )
|
||||||
-> base::MacResult {
|
-> base::MacResult {
|
||||||
// these spans won't matter, anyways
|
// these spans won't matter, anyways
|
||||||
fn ms(m: Matcher_) -> Matcher {
|
fn ms(m: Matcher_) -> Matcher {
|
||||||
|
@ -191,15 +191,14 @@ pub fn add_new_extension(cx: &mut ExtCtxt,
|
||||||
// The grammar for macro_rules! is:
|
// The grammar for macro_rules! is:
|
||||||
// $( $lhs:mtcs => $rhs:tt );+
|
// $( $lhs:mtcs => $rhs:tt );+
|
||||||
// ...quasiquoting this would be nice.
|
// ...quasiquoting this would be nice.
|
||||||
let argument_gram = ~[
|
let argument_gram = vec!(
|
||||||
ms(MatchSeq(~[
|
ms(MatchSeq(vec!(
|
||||||
ms(MatchNonterminal(lhs_nm, special_idents::matchers, 0u)),
|
ms(MatchNonterminal(lhs_nm, special_idents::matchers, 0u)),
|
||||||
ms(MatchTok(FAT_ARROW)),
|
ms(MatchTok(FAT_ARROW)),
|
||||||
ms(MatchNonterminal(rhs_nm, special_idents::tt, 1u)),
|
ms(MatchNonterminal(rhs_nm, special_idents::tt, 1u))), Some(SEMI), false, 0u, 2u)),
|
||||||
], Some(SEMI), false, 0u, 2u)),
|
|
||||||
//to phase into semicolon-termination instead of
|
//to phase into semicolon-termination instead of
|
||||||
//semicolon-separation
|
//semicolon-separation
|
||||||
ms(MatchSeq(~[ms(MatchTok(SEMI))], None, true, 2u, 2u))];
|
ms(MatchSeq(vec!(ms(MatchTok(SEMI))), None, true, 2u, 2u)));
|
||||||
|
|
||||||
|
|
||||||
// Parse the macro_rules! invocation (`none` is for no interpolations):
|
// Parse the macro_rules! invocation (`none` is for no interpolations):
|
||||||
|
|
|
@ -22,7 +22,7 @@ use collections::HashMap;
|
||||||
|
|
||||||
///an unzipping of `TokenTree`s
|
///an unzipping of `TokenTree`s
|
||||||
struct TtFrame {
|
struct TtFrame {
|
||||||
forest: @~[ast::TokenTree],
|
forest: @Vec<ast::TokenTree> ,
|
||||||
idx: Cell<uint>,
|
idx: Cell<uint>,
|
||||||
dotdotdoted: bool,
|
dotdotdoted: bool,
|
||||||
sep: Option<Token>,
|
sep: Option<Token>,
|
||||||
|
@ -35,8 +35,8 @@ pub struct TtReader {
|
||||||
priv stack: RefCell<@TtFrame>,
|
priv stack: RefCell<@TtFrame>,
|
||||||
/* for MBE-style macro transcription */
|
/* for MBE-style macro transcription */
|
||||||
priv interpolations: RefCell<HashMap<Ident, @NamedMatch>>,
|
priv interpolations: RefCell<HashMap<Ident, @NamedMatch>>,
|
||||||
priv repeat_idx: RefCell<~[uint]>,
|
priv repeat_idx: RefCell<Vec<uint> >,
|
||||||
priv repeat_len: RefCell<~[uint]>,
|
priv repeat_len: RefCell<Vec<uint> >,
|
||||||
/* cached: */
|
/* cached: */
|
||||||
cur_tok: RefCell<Token>,
|
cur_tok: RefCell<Token>,
|
||||||
cur_span: RefCell<Span>,
|
cur_span: RefCell<Span>,
|
||||||
|
@ -47,7 +47,7 @@ pub struct TtReader {
|
||||||
* should) be none. */
|
* should) be none. */
|
||||||
pub fn new_tt_reader(sp_diag: @SpanHandler,
|
pub fn new_tt_reader(sp_diag: @SpanHandler,
|
||||||
interp: Option<HashMap<Ident, @NamedMatch>>,
|
interp: Option<HashMap<Ident, @NamedMatch>>,
|
||||||
src: ~[ast::TokenTree])
|
src: Vec<ast::TokenTree> )
|
||||||
-> TtReader {
|
-> TtReader {
|
||||||
let r = TtReader {
|
let r = TtReader {
|
||||||
sp_diag: sp_diag,
|
sp_diag: sp_diag,
|
||||||
|
@ -62,8 +62,8 @@ pub fn new_tt_reader(sp_diag: @SpanHandler,
|
||||||
None => RefCell::new(HashMap::new()),
|
None => RefCell::new(HashMap::new()),
|
||||||
Some(x) => RefCell::new(x),
|
Some(x) => RefCell::new(x),
|
||||||
},
|
},
|
||||||
repeat_idx: RefCell::new(~[]),
|
repeat_idx: RefCell::new(Vec::new()),
|
||||||
repeat_len: RefCell::new(~[]),
|
repeat_len: RefCell::new(Vec::new()),
|
||||||
/* dummy values, never read: */
|
/* dummy values, never read: */
|
||||||
cur_tok: RefCell::new(EOF),
|
cur_tok: RefCell::new(EOF),
|
||||||
cur_span: RefCell::new(DUMMY_SP),
|
cur_span: RefCell::new(DUMMY_SP),
|
||||||
|
|
|
@ -22,11 +22,11 @@ pub trait Folder {
|
||||||
noop_fold_crate(c, self)
|
noop_fold_crate(c, self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_meta_items(&mut self, meta_items: &[@MetaItem]) -> ~[@MetaItem] {
|
fn fold_meta_items(&mut self, meta_items: &[@MetaItem]) -> Vec<@MetaItem> {
|
||||||
meta_items.map(|x| fold_meta_item_(*x, self))
|
meta_items.map(|x| fold_meta_item_(*x, self))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_view_paths(&mut self, view_paths: &[@ViewPath]) -> ~[@ViewPath] {
|
fn fold_view_paths(&mut self, view_paths: &[@ViewPath]) -> Vec<@ViewPath> {
|
||||||
view_paths.map(|view_path| {
|
view_paths.map(|view_path| {
|
||||||
let inner_view_path = match view_path.node {
|
let inner_view_path = match view_path.node {
|
||||||
ViewPathSimple(ref ident, ref path, node_id) => {
|
ViewPathSimple(ref ident, ref path, node_id) => {
|
||||||
|
@ -283,7 +283,7 @@ pub trait Folder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_exprs(&self, f: |@Expr| -> @Expr, es: &[@Expr]) -> ~[@Expr] {
|
fn map_exprs(&self, f: |@Expr| -> @Expr, es: &[@Expr]) -> Vec<@Expr> {
|
||||||
es.map(|x| f(*x))
|
es.map(|x| f(*x))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,7 +370,7 @@ fn fold_arg_<T: Folder>(a: &Arg, fld: &mut T) -> Arg {
|
||||||
// since many token::IDENT are not necessary part of let bindings and most
|
// since many token::IDENT are not necessary part of let bindings and most
|
||||||
// token::LIFETIME are certainly not loop labels. But we can't tell in their
|
// token::LIFETIME are certainly not loop labels. But we can't tell in their
|
||||||
// token form. So this is less ideal and hacky but it works.
|
// token form. So this is less ideal and hacky but it works.
|
||||||
pub fn fold_tts<T: Folder>(tts: &[TokenTree], fld: &mut T) -> ~[TokenTree] {
|
pub fn fold_tts<T: Folder>(tts: &[TokenTree], fld: &mut T) -> Vec<TokenTree> {
|
||||||
tts.map(|tt| {
|
tts.map(|tt| {
|
||||||
match *tt {
|
match *tt {
|
||||||
TTTok(span, ref tok) =>
|
TTTok(span, ref tok) =>
|
||||||
|
|
|
@ -21,14 +21,14 @@ use std::default::Default;
|
||||||
#[deriving(Clone, Encodable, Decodable, Hash)]
|
#[deriving(Clone, Encodable, Decodable, Hash)]
|
||||||
pub enum OptVec<T> {
|
pub enum OptVec<T> {
|
||||||
Empty,
|
Empty,
|
||||||
Vec(~[T])
|
Vec(Vec<T> )
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with<T>(t: T) -> OptVec<T> {
|
pub fn with<T>(t: T) -> OptVec<T> {
|
||||||
Vec(~[t])
|
Vec(vec!(t))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from<T>(t: ~[T]) -> OptVec<T> {
|
pub fn from<T>(t: Vec<T> ) -> OptVec<T> {
|
||||||
if t.len() == 0 {
|
if t.len() == 0 {
|
||||||
Empty
|
Empty
|
||||||
} else {
|
} else {
|
||||||
|
@ -44,7 +44,7 @@ impl<T> OptVec<T> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Empty => {
|
Empty => {
|
||||||
*self = Vec(~[t]);
|
*self = Vec(vec!(t));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,11 +121,11 @@ impl<T> OptVec<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn map_to_vec<B>(&self, op: |&T| -> B) -> ~[B] {
|
pub fn map_to_vec<B>(&self, op: |&T| -> B) -> Vec<B> {
|
||||||
self.iter().map(op).collect()
|
self.iter().map(op).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mapi_to_vec<B>(&self, op: |uint, &T| -> B) -> ~[B] {
|
pub fn mapi_to_vec<B>(&self, op: |uint, &T| -> B) -> Vec<B> {
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
self.map_to_vec(|a| {
|
self.map_to_vec(|a| {
|
||||||
let i = index;
|
let i = index;
|
||||||
|
@ -135,16 +135,16 @@ impl<T> OptVec<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take_vec<T>(v: OptVec<T>) -> ~[T] {
|
pub fn take_vec<T>(v: OptVec<T>) -> Vec<T> {
|
||||||
match v {
|
match v {
|
||||||
Empty => ~[],
|
Empty => Vec::new(),
|
||||||
Vec(v) => v
|
Vec(v) => v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Clone> OptVec<T> {
|
impl<T:Clone> OptVec<T> {
|
||||||
pub fn prepend(&self, t: T) -> OptVec<T> {
|
pub fn prepend(&self, t: T) -> OptVec<T> {
|
||||||
let mut v0 = ~[t];
|
let mut v0 = vec!(t);
|
||||||
match *self {
|
match *self {
|
||||||
Empty => {}
|
Empty => {}
|
||||||
Vec(ref v1) => { v0.push_all(*v1); }
|
Vec(ref v1) => { v0.push_all(*v1); }
|
||||||
|
|
|
@ -17,19 +17,19 @@ use parse::token::INTERPOLATED;
|
||||||
|
|
||||||
// a parser that can parse attributes.
|
// a parser that can parse attributes.
|
||||||
pub trait ParserAttr {
|
pub trait ParserAttr {
|
||||||
fn parse_outer_attributes(&mut self) -> ~[ast::Attribute];
|
fn parse_outer_attributes(&mut self) -> Vec<ast::Attribute> ;
|
||||||
fn parse_attribute(&mut self, permit_inner: bool) -> ast::Attribute;
|
fn parse_attribute(&mut self, permit_inner: bool) -> ast::Attribute;
|
||||||
fn parse_inner_attrs_and_next(&mut self)
|
fn parse_inner_attrs_and_next(&mut self)
|
||||||
-> (~[ast::Attribute], ~[ast::Attribute]);
|
-> (Vec<ast::Attribute> , Vec<ast::Attribute> );
|
||||||
fn parse_meta_item(&mut self) -> @ast::MetaItem;
|
fn parse_meta_item(&mut self) -> @ast::MetaItem;
|
||||||
fn parse_meta_seq(&mut self) -> ~[@ast::MetaItem];
|
fn parse_meta_seq(&mut self) -> Vec<@ast::MetaItem> ;
|
||||||
fn parse_optional_meta(&mut self) -> ~[@ast::MetaItem];
|
fn parse_optional_meta(&mut self) -> Vec<@ast::MetaItem> ;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParserAttr for Parser {
|
impl ParserAttr for Parser {
|
||||||
// Parse attributes that appear before an item
|
// Parse attributes that appear before an item
|
||||||
fn parse_outer_attributes(&mut self) -> ~[ast::Attribute] {
|
fn parse_outer_attributes(&mut self) -> Vec<ast::Attribute> {
|
||||||
let mut attrs: ~[ast::Attribute] = ~[];
|
let mut attrs: Vec<ast::Attribute> = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
debug!("parse_outer_attributes: self.token={:?}",
|
debug!("parse_outer_attributes: self.token={:?}",
|
||||||
self.token);
|
self.token);
|
||||||
|
@ -116,9 +116,9 @@ impl ParserAttr for Parser {
|
||||||
// you can make the 'next' field an Option, but the result is going to be
|
// you can make the 'next' field an Option, but the result is going to be
|
||||||
// more useful as a vector.
|
// more useful as a vector.
|
||||||
fn parse_inner_attrs_and_next(&mut self)
|
fn parse_inner_attrs_and_next(&mut self)
|
||||||
-> (~[ast::Attribute], ~[ast::Attribute]) {
|
-> (Vec<ast::Attribute> , Vec<ast::Attribute> ) {
|
||||||
let mut inner_attrs: ~[ast::Attribute] = ~[];
|
let mut inner_attrs: Vec<ast::Attribute> = Vec::new();
|
||||||
let mut next_outer_attrs: ~[ast::Attribute] = ~[];
|
let mut next_outer_attrs: Vec<ast::Attribute> = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
let attr = match self.token {
|
let attr = match self.token {
|
||||||
token::INTERPOLATED(token::NtAttr(..)) => {
|
token::INTERPOLATED(token::NtAttr(..)) => {
|
||||||
|
@ -188,17 +188,17 @@ impl ParserAttr for Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
// matches meta_seq = ( COMMASEP(meta_item) )
|
// matches meta_seq = ( COMMASEP(meta_item) )
|
||||||
fn parse_meta_seq(&mut self) -> ~[@ast::MetaItem] {
|
fn parse_meta_seq(&mut self) -> Vec<@ast::MetaItem> {
|
||||||
self.parse_seq(&token::LPAREN,
|
self.parse_seq(&token::LPAREN,
|
||||||
&token::RPAREN,
|
&token::RPAREN,
|
||||||
seq_sep_trailing_disallowed(token::COMMA),
|
seq_sep_trailing_disallowed(token::COMMA),
|
||||||
|p| p.parse_meta_item()).node
|
|p| p.parse_meta_item()).node
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_optional_meta(&mut self) -> ~[@ast::MetaItem] {
|
fn parse_optional_meta(&mut self) -> Vec<@ast::MetaItem> {
|
||||||
match self.token {
|
match self.token {
|
||||||
token::LPAREN => self.parse_meta_seq(),
|
token::LPAREN => self.parse_meta_seq(),
|
||||||
_ => ~[]
|
_ => Vec::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub enum CommentStyle {
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
pub struct Comment {
|
pub struct Comment {
|
||||||
style: CommentStyle,
|
style: CommentStyle,
|
||||||
lines: ~[~str],
|
lines: Vec<~str> ,
|
||||||
pos: BytePos
|
pos: BytePos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ pub fn doc_comment_style(comment: &str) -> ast::AttrStyle {
|
||||||
|
|
||||||
pub fn strip_doc_comment_decoration(comment: &str) -> ~str {
|
pub fn strip_doc_comment_decoration(comment: &str) -> ~str {
|
||||||
/// remove whitespace-only lines from the start/end of lines
|
/// remove whitespace-only lines from the start/end of lines
|
||||||
fn vertical_trim(lines: ~[~str]) -> ~[~str] {
|
fn vertical_trim(lines: Vec<~str> ) -> Vec<~str> {
|
||||||
let mut i = 0u;
|
let mut i = 0u;
|
||||||
let mut j = lines.len();
|
let mut j = lines.len();
|
||||||
// first line of all-stars should be omitted
|
// first line of all-stars should be omitted
|
||||||
|
@ -75,7 +75,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// remove a "[ \t]*\*" block from each line, if possible
|
/// remove a "[ \t]*\*" block from each line, if possible
|
||||||
fn horizontal_trim(lines: ~[~str]) -> ~[~str] {
|
fn horizontal_trim(lines: Vec<~str> ) -> Vec<~str> {
|
||||||
let mut i = uint::MAX;
|
let mut i = uint::MAX;
|
||||||
let mut can_trim = true;
|
let mut can_trim = true;
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
|
@ -122,7 +122,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str {
|
||||||
let lines = comment.slice(3u, comment.len() - 2u)
|
let lines = comment.slice(3u, comment.len() - 2u)
|
||||||
.lines_any()
|
.lines_any()
|
||||||
.map(|s| s.to_owned())
|
.map(|s| s.to_owned())
|
||||||
.collect::<~[~str]>();
|
.collect::<Vec<~str> >();
|
||||||
|
|
||||||
let lines = vertical_trim(lines);
|
let lines = vertical_trim(lines);
|
||||||
let lines = horizontal_trim(lines);
|
let lines = horizontal_trim(lines);
|
||||||
|
@ -157,9 +157,9 @@ fn consume_non_eol_whitespace(rdr: &StringReader) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_blank_line_comment(rdr: &StringReader, comments: &mut ~[Comment]) {
|
fn push_blank_line_comment(rdr: &StringReader, comments: &mut Vec<Comment> ) {
|
||||||
debug!(">>> blank-line comment");
|
debug!(">>> blank-line comment");
|
||||||
let v: ~[~str] = ~[];
|
let v: Vec<~str> = Vec::new();
|
||||||
comments.push(Comment {
|
comments.push(Comment {
|
||||||
style: BlankLine,
|
style: BlankLine,
|
||||||
lines: v,
|
lines: v,
|
||||||
|
@ -168,7 +168,7 @@ fn push_blank_line_comment(rdr: &StringReader, comments: &mut ~[Comment]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn consume_whitespace_counting_blank_lines(rdr: &StringReader,
|
fn consume_whitespace_counting_blank_lines(rdr: &StringReader,
|
||||||
comments: &mut ~[Comment]) {
|
comments: &mut Vec<Comment> ) {
|
||||||
while is_whitespace(rdr.curr.get()) && !is_eof(rdr) {
|
while is_whitespace(rdr.curr.get()) && !is_eof(rdr) {
|
||||||
if rdr.col.get() == CharPos(0u) && rdr.curr_is('\n') {
|
if rdr.col.get() == CharPos(0u) && rdr.curr_is('\n') {
|
||||||
push_blank_line_comment(rdr, &mut *comments);
|
push_blank_line_comment(rdr, &mut *comments);
|
||||||
|
@ -179,22 +179,22 @@ fn consume_whitespace_counting_blank_lines(rdr: &StringReader,
|
||||||
|
|
||||||
|
|
||||||
fn read_shebang_comment(rdr: &StringReader, code_to_the_left: bool,
|
fn read_shebang_comment(rdr: &StringReader, code_to_the_left: bool,
|
||||||
comments: &mut ~[Comment]) {
|
comments: &mut Vec<Comment> ) {
|
||||||
debug!(">>> shebang comment");
|
debug!(">>> shebang comment");
|
||||||
let p = rdr.last_pos.get();
|
let p = rdr.last_pos.get();
|
||||||
debug!("<<< shebang comment");
|
debug!("<<< shebang comment");
|
||||||
comments.push(Comment {
|
comments.push(Comment {
|
||||||
style: if code_to_the_left { Trailing } else { Isolated },
|
style: if code_to_the_left { Trailing } else { Isolated },
|
||||||
lines: ~[read_one_line_comment(rdr)],
|
lines: vec!(read_one_line_comment(rdr)),
|
||||||
pos: p
|
pos: p
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_line_comments(rdr: &StringReader, code_to_the_left: bool,
|
fn read_line_comments(rdr: &StringReader, code_to_the_left: bool,
|
||||||
comments: &mut ~[Comment]) {
|
comments: &mut Vec<Comment> ) {
|
||||||
debug!(">>> line comments");
|
debug!(">>> line comments");
|
||||||
let p = rdr.last_pos.get();
|
let p = rdr.last_pos.get();
|
||||||
let mut lines: ~[~str] = ~[];
|
let mut lines: Vec<~str> = Vec::new();
|
||||||
while rdr.curr_is('/') && nextch_is(rdr, '/') {
|
while rdr.curr_is('/') && nextch_is(rdr, '/') {
|
||||||
let line = read_one_line_comment(rdr);
|
let line = read_one_line_comment(rdr);
|
||||||
debug!("{}", line);
|
debug!("{}", line);
|
||||||
|
@ -232,7 +232,7 @@ fn all_whitespace(s: &str, col: CharPos) -> Option<uint> {
|
||||||
return Some(cursor);
|
return Some(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trim_whitespace_prefix_and_push_line(lines: &mut ~[~str],
|
fn trim_whitespace_prefix_and_push_line(lines: &mut Vec<~str> ,
|
||||||
s: ~str, col: CharPos) {
|
s: ~str, col: CharPos) {
|
||||||
let len = s.len();
|
let len = s.len();
|
||||||
let s1 = match all_whitespace(s, col) {
|
let s1 = match all_whitespace(s, col) {
|
||||||
|
@ -249,10 +249,10 @@ fn trim_whitespace_prefix_and_push_line(lines: &mut ~[~str],
|
||||||
|
|
||||||
fn read_block_comment(rdr: &StringReader,
|
fn read_block_comment(rdr: &StringReader,
|
||||||
code_to_the_left: bool,
|
code_to_the_left: bool,
|
||||||
comments: &mut ~[Comment]) {
|
comments: &mut Vec<Comment> ) {
|
||||||
debug!(">>> block comment");
|
debug!(">>> block comment");
|
||||||
let p = rdr.last_pos.get();
|
let p = rdr.last_pos.get();
|
||||||
let mut lines: ~[~str] = ~[];
|
let mut lines: Vec<~str> = Vec::new();
|
||||||
let col: CharPos = rdr.col.get();
|
let col: CharPos = rdr.col.get();
|
||||||
bump(rdr);
|
bump(rdr);
|
||||||
bump(rdr);
|
bump(rdr);
|
||||||
|
@ -324,7 +324,7 @@ fn peeking_at_comment(rdr: &StringReader) -> bool {
|
||||||
|
|
||||||
fn consume_comment(rdr: &StringReader,
|
fn consume_comment(rdr: &StringReader,
|
||||||
code_to_the_left: bool,
|
code_to_the_left: bool,
|
||||||
comments: &mut ~[Comment]) {
|
comments: &mut Vec<Comment> ) {
|
||||||
debug!(">>> consume comment");
|
debug!(">>> consume comment");
|
||||||
if rdr.curr_is('/') && nextch_is(rdr, '/') {
|
if rdr.curr_is('/') && nextch_is(rdr, '/') {
|
||||||
read_line_comments(rdr, code_to_the_left, comments);
|
read_line_comments(rdr, code_to_the_left, comments);
|
||||||
|
@ -348,15 +348,15 @@ pub fn gather_comments_and_literals(span_diagnostic:
|
||||||
@diagnostic::SpanHandler,
|
@diagnostic::SpanHandler,
|
||||||
path: ~str,
|
path: ~str,
|
||||||
srdr: &mut io::Reader)
|
srdr: &mut io::Reader)
|
||||||
-> (~[Comment], ~[Literal]) {
|
-> (Vec<Comment> , Vec<Literal> ) {
|
||||||
let src = srdr.read_to_end().unwrap();
|
let src = srdr.read_to_end().unwrap();
|
||||||
let src = str::from_utf8_owned(src).unwrap();
|
let src = str::from_utf8_owned(src).unwrap();
|
||||||
let cm = CodeMap::new();
|
let cm = CodeMap::new();
|
||||||
let filemap = cm.new_filemap(path, src);
|
let filemap = cm.new_filemap(path, src);
|
||||||
let rdr = lexer::new_low_level_string_reader(span_diagnostic, filemap);
|
let rdr = lexer::new_low_level_string_reader(span_diagnostic, filemap);
|
||||||
|
|
||||||
let mut comments: ~[Comment] = ~[];
|
let mut comments: Vec<Comment> = Vec::new();
|
||||||
let mut literals: ~[Literal] = ~[];
|
let mut literals: Vec<Literal> = Vec::new();
|
||||||
let mut first_read: bool = true;
|
let mut first_read: bool = true;
|
||||||
while !is_eof(&rdr) {
|
while !is_eof(&rdr) {
|
||||||
loop {
|
loop {
|
||||||
|
|
|
@ -1048,7 +1048,7 @@ mod test {
|
||||||
|
|
||||||
// check that the given reader produces the desired stream
|
// check that the given reader produces the desired stream
|
||||||
// of tokens (stop checking after exhausting the expected vec)
|
// of tokens (stop checking after exhausting the expected vec)
|
||||||
fn check_tokenization (env: Env, expected: ~[token::Token]) {
|
fn check_tokenization (env: Env, expected: Vec<token::Token> ) {
|
||||||
for expected_tok in expected.iter() {
|
for expected_tok in expected.iter() {
|
||||||
let TokenAndSpan {tok:actual_tok, sp: _} =
|
let TokenAndSpan {tok:actual_tok, sp: _} =
|
||||||
env.string_reader.next_token();
|
env.string_reader.next_token();
|
||||||
|
@ -1064,32 +1064,32 @@ mod test {
|
||||||
#[test] fn doublecolonparsing () {
|
#[test] fn doublecolonparsing () {
|
||||||
let env = setup (~"a b");
|
let env = setup (~"a b");
|
||||||
check_tokenization (env,
|
check_tokenization (env,
|
||||||
~[mk_ident("a",false),
|
vec!(mk_ident("a",false),
|
||||||
mk_ident("b",false)]);
|
mk_ident("b",false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test] fn dcparsing_2 () {
|
#[test] fn dcparsing_2 () {
|
||||||
let env = setup (~"a::b");
|
let env = setup (~"a::b");
|
||||||
check_tokenization (env,
|
check_tokenization (env,
|
||||||
~[mk_ident("a",true),
|
vec!(mk_ident("a",true),
|
||||||
token::MOD_SEP,
|
token::MOD_SEP,
|
||||||
mk_ident("b",false)]);
|
mk_ident("b",false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test] fn dcparsing_3 () {
|
#[test] fn dcparsing_3 () {
|
||||||
let env = setup (~"a ::b");
|
let env = setup (~"a ::b");
|
||||||
check_tokenization (env,
|
check_tokenization (env,
|
||||||
~[mk_ident("a",false),
|
vec!(mk_ident("a",false),
|
||||||
token::MOD_SEP,
|
token::MOD_SEP,
|
||||||
mk_ident("b",false)]);
|
mk_ident("b",false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test] fn dcparsing_4 () {
|
#[test] fn dcparsing_4 () {
|
||||||
let env = setup (~"a:: b");
|
let env = setup (~"a:: b");
|
||||||
check_tokenization (env,
|
check_tokenization (env,
|
||||||
~[mk_ident("a",true),
|
vec!(mk_ident("a",true),
|
||||||
token::MOD_SEP,
|
token::MOD_SEP,
|
||||||
mk_ident("b",false)]);
|
mk_ident("b",false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test] fn character_a() {
|
#[test] fn character_a() {
|
||||||
|
|
|
@ -42,7 +42,7 @@ pub struct ParseSess {
|
||||||
cm: @codemap::CodeMap, // better be the same as the one in the reader!
|
cm: @codemap::CodeMap, // better be the same as the one in the reader!
|
||||||
span_diagnostic: @SpanHandler, // better be the same as the one in the reader!
|
span_diagnostic: @SpanHandler, // better be the same as the one in the reader!
|
||||||
/// Used to determine and report recursive mod inclusions
|
/// Used to determine and report recursive mod inclusions
|
||||||
included_mod_stack: RefCell<~[Path]>,
|
included_mod_stack: RefCell<Vec<Path> >,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_parse_sess() -> @ParseSess {
|
pub fn new_parse_sess() -> @ParseSess {
|
||||||
|
@ -50,7 +50,7 @@ pub fn new_parse_sess() -> @ParseSess {
|
||||||
@ParseSess {
|
@ParseSess {
|
||||||
cm: cm,
|
cm: cm,
|
||||||
span_diagnostic: mk_span_handler(default_handler(), cm),
|
span_diagnostic: mk_span_handler(default_handler(), cm),
|
||||||
included_mod_stack: RefCell::new(~[]),
|
included_mod_stack: RefCell::new(Vec::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ pub fn new_parse_sess_special_handler(sh: @SpanHandler,
|
||||||
@ParseSess {
|
@ParseSess {
|
||||||
cm: cm,
|
cm: cm,
|
||||||
span_diagnostic: sh,
|
span_diagnostic: sh,
|
||||||
included_mod_stack: RefCell::new(~[]),
|
included_mod_stack: RefCell::new(Vec::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ pub fn parse_crate_attrs_from_file(
|
||||||
input: &Path,
|
input: &Path,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
sess: @ParseSess
|
sess: @ParseSess
|
||||||
) -> ~[ast::Attribute] {
|
) -> Vec<ast::Attribute> {
|
||||||
let mut parser = new_parser_from_file(sess, cfg, input);
|
let mut parser = new_parser_from_file(sess, cfg, input);
|
||||||
let (inner, _) = parser.parse_inner_attrs_and_next();
|
let (inner, _) = parser.parse_inner_attrs_and_next();
|
||||||
return inner;
|
return inner;
|
||||||
|
@ -104,7 +104,7 @@ pub fn parse_crate_attrs_from_source_str(name: ~str,
|
||||||
source: ~str,
|
source: ~str,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
sess: @ParseSess)
|
sess: @ParseSess)
|
||||||
-> ~[ast::Attribute] {
|
-> Vec<ast::Attribute> {
|
||||||
let mut p = new_parser_from_source_str(sess,
|
let mut p = new_parser_from_source_str(sess,
|
||||||
cfg,
|
cfg,
|
||||||
name,
|
name,
|
||||||
|
@ -144,7 +144,7 @@ pub fn parse_meta_from_source_str(name: ~str,
|
||||||
pub fn parse_stmt_from_source_str(name: ~str,
|
pub fn parse_stmt_from_source_str(name: ~str,
|
||||||
source: ~str,
|
source: ~str,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
attrs: ~[ast::Attribute],
|
attrs: Vec<ast::Attribute> ,
|
||||||
sess: @ParseSess)
|
sess: @ParseSess)
|
||||||
-> @ast::Stmt {
|
-> @ast::Stmt {
|
||||||
let mut p = new_parser_from_source_str(
|
let mut p = new_parser_from_source_str(
|
||||||
|
@ -160,7 +160,7 @@ pub fn parse_tts_from_source_str(name: ~str,
|
||||||
source: ~str,
|
source: ~str,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
sess: @ParseSess)
|
sess: @ParseSess)
|
||||||
-> ~[ast::TokenTree] {
|
-> Vec<ast::TokenTree> {
|
||||||
let mut p = new_parser_from_source_str(
|
let mut p = new_parser_from_source_str(
|
||||||
sess,
|
sess,
|
||||||
cfg,
|
cfg,
|
||||||
|
@ -214,7 +214,7 @@ pub fn filemap_to_parser(sess: @ParseSess,
|
||||||
// compiler expands into it
|
// compiler expands into it
|
||||||
pub fn new_parser_from_tts(sess: @ParseSess,
|
pub fn new_parser_from_tts(sess: @ParseSess,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
tts: ~[ast::TokenTree]) -> Parser {
|
tts: Vec<ast::TokenTree> ) -> Parser {
|
||||||
tts_to_parser(sess,tts,cfg)
|
tts_to_parser(sess,tts,cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,10 +256,10 @@ pub fn string_to_filemap(sess: @ParseSess, source: ~str, path: ~str)
|
||||||
|
|
||||||
// given a filemap, produce a sequence of token-trees
|
// given a filemap, produce a sequence of token-trees
|
||||||
pub fn filemap_to_tts(sess: @ParseSess, filemap: @FileMap)
|
pub fn filemap_to_tts(sess: @ParseSess, filemap: @FileMap)
|
||||||
-> ~[ast::TokenTree] {
|
-> Vec<ast::TokenTree> {
|
||||||
// it appears to me that the cfg doesn't matter here... indeed,
|
// it appears to me that the cfg doesn't matter here... indeed,
|
||||||
// parsing tt's probably shouldn't require a parser at all.
|
// parsing tt's probably shouldn't require a parser at all.
|
||||||
let cfg = ~[];
|
let cfg = Vec::new();
|
||||||
let srdr = lexer::new_string_reader(sess.span_diagnostic, filemap);
|
let srdr = lexer::new_string_reader(sess.span_diagnostic, filemap);
|
||||||
let mut p1 = Parser(sess, cfg, ~srdr);
|
let mut p1 = Parser(sess, cfg, ~srdr);
|
||||||
p1.parse_all_token_trees()
|
p1.parse_all_token_trees()
|
||||||
|
@ -267,7 +267,7 @@ pub fn filemap_to_tts(sess: @ParseSess, filemap: @FileMap)
|
||||||
|
|
||||||
// given tts and cfg, produce a parser
|
// given tts and cfg, produce a parser
|
||||||
pub fn tts_to_parser(sess: @ParseSess,
|
pub fn tts_to_parser(sess: @ParseSess,
|
||||||
tts: ~[ast::TokenTree],
|
tts: Vec<ast::TokenTree> ,
|
||||||
cfg: ast::CrateConfig) -> Parser {
|
cfg: ast::CrateConfig) -> Parser {
|
||||||
let trdr = lexer::new_tt_reader(sess.span_diagnostic, None, tts);
|
let trdr = lexer::new_tt_reader(sess.span_diagnostic, None, tts);
|
||||||
Parser(sess, cfg, ~trdr)
|
Parser(sess, cfg, ~trdr)
|
||||||
|
@ -318,13 +318,13 @@ mod test {
|
||||||
node: ast::ExprPath(ast::Path {
|
node: ast::ExprPath(ast::Path {
|
||||||
span: sp(0, 1),
|
span: sp(0, 1),
|
||||||
global: false,
|
global: false,
|
||||||
segments: ~[
|
segments: vec!(
|
||||||
ast::PathSegment {
|
ast::PathSegment {
|
||||||
identifier: str_to_ident("a"),
|
identifier: str_to_ident("a"),
|
||||||
lifetimes: opt_vec::Empty,
|
lifetimes: opt_vec::Empty,
|
||||||
types: opt_vec::Empty,
|
types: opt_vec::Empty,
|
||||||
}
|
}
|
||||||
],
|
),
|
||||||
}),
|
}),
|
||||||
span: sp(0, 1)
|
span: sp(0, 1)
|
||||||
})
|
})
|
||||||
|
@ -337,7 +337,7 @@ mod test {
|
||||||
node: ast::ExprPath(ast::Path {
|
node: ast::ExprPath(ast::Path {
|
||||||
span: sp(0, 6),
|
span: sp(0, 6),
|
||||||
global: true,
|
global: true,
|
||||||
segments: ~[
|
segments: vec!(
|
||||||
ast::PathSegment {
|
ast::PathSegment {
|
||||||
identifier: str_to_ident("a"),
|
identifier: str_to_ident("a"),
|
||||||
lifetimes: opt_vec::Empty,
|
lifetimes: opt_vec::Empty,
|
||||||
|
@ -348,7 +348,7 @@ mod test {
|
||||||
lifetimes: opt_vec::Empty,
|
lifetimes: opt_vec::Empty,
|
||||||
types: opt_vec::Empty,
|
types: opt_vec::Empty,
|
||||||
}
|
}
|
||||||
]
|
)
|
||||||
}),
|
}),
|
||||||
span: sp(0, 6)
|
span: sp(0, 6)
|
||||||
})
|
})
|
||||||
|
@ -550,13 +550,13 @@ mod test {
|
||||||
node:ast::ExprPath(ast::Path{
|
node:ast::ExprPath(ast::Path{
|
||||||
span: sp(7, 8),
|
span: sp(7, 8),
|
||||||
global: false,
|
global: false,
|
||||||
segments: ~[
|
segments: vec!(
|
||||||
ast::PathSegment {
|
ast::PathSegment {
|
||||||
identifier: str_to_ident("d"),
|
identifier: str_to_ident("d"),
|
||||||
lifetimes: opt_vec::Empty,
|
lifetimes: opt_vec::Empty,
|
||||||
types: opt_vec::Empty,
|
types: opt_vec::Empty,
|
||||||
}
|
}
|
||||||
],
|
),
|
||||||
}),
|
}),
|
||||||
span:sp(7,8)
|
span:sp(7,8)
|
||||||
})),
|
})),
|
||||||
|
@ -572,13 +572,13 @@ mod test {
|
||||||
node: ast::ExprPath(ast::Path {
|
node: ast::ExprPath(ast::Path {
|
||||||
span:sp(0,1),
|
span:sp(0,1),
|
||||||
global:false,
|
global:false,
|
||||||
segments: ~[
|
segments: vec!(
|
||||||
ast::PathSegment {
|
ast::PathSegment {
|
||||||
identifier: str_to_ident("b"),
|
identifier: str_to_ident("b"),
|
||||||
lifetimes: opt_vec::Empty,
|
lifetimes: opt_vec::Empty,
|
||||||
types: opt_vec::Empty,
|
types: opt_vec::Empty,
|
||||||
}
|
}
|
||||||
],
|
),
|
||||||
}),
|
}),
|
||||||
span: sp(0,1)},
|
span: sp(0,1)},
|
||||||
ast::DUMMY_NODE_ID),
|
ast::DUMMY_NODE_ID),
|
||||||
|
@ -599,13 +599,13 @@ mod test {
|
||||||
ast::Path {
|
ast::Path {
|
||||||
span:sp(0,1),
|
span:sp(0,1),
|
||||||
global:false,
|
global:false,
|
||||||
segments: ~[
|
segments: vec!(
|
||||||
ast::PathSegment {
|
ast::PathSegment {
|
||||||
identifier: str_to_ident("b"),
|
identifier: str_to_ident("b"),
|
||||||
lifetimes: opt_vec::Empty,
|
lifetimes: opt_vec::Empty,
|
||||||
types: opt_vec::Empty,
|
types: opt_vec::Empty,
|
||||||
}
|
}
|
||||||
],
|
),
|
||||||
},
|
},
|
||||||
None /* no idea */),
|
None /* no idea */),
|
||||||
span: sp(0,1)});
|
span: sp(0,1)});
|
||||||
|
@ -618,22 +618,22 @@ mod test {
|
||||||
assert!(string_to_item(~"fn a (b : int) { b; }") ==
|
assert!(string_to_item(~"fn a (b : int) { b; }") ==
|
||||||
Some(
|
Some(
|
||||||
@ast::Item{ident:str_to_ident("a"),
|
@ast::Item{ident:str_to_ident("a"),
|
||||||
attrs:~[],
|
attrs:Vec::new(),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
node: ast::ItemFn(ast::P(ast::FnDecl {
|
node: ast::ItemFn(ast::P(ast::FnDecl {
|
||||||
inputs: ~[ast::Arg{
|
inputs: vec!(ast::Arg{
|
||||||
ty: ast::P(ast::Ty{id: ast::DUMMY_NODE_ID,
|
ty: ast::P(ast::Ty{id: ast::DUMMY_NODE_ID,
|
||||||
node: ast::TyPath(ast::Path{
|
node: ast::TyPath(ast::Path{
|
||||||
span:sp(10,13),
|
span:sp(10,13),
|
||||||
global:false,
|
global:false,
|
||||||
segments: ~[
|
segments: vec!(
|
||||||
ast::PathSegment {
|
ast::PathSegment {
|
||||||
identifier:
|
identifier:
|
||||||
str_to_ident("int"),
|
str_to_ident("int"),
|
||||||
lifetimes: opt_vec::Empty,
|
lifetimes: opt_vec::Empty,
|
||||||
types: opt_vec::Empty,
|
types: opt_vec::Empty,
|
||||||
}
|
}
|
||||||
],
|
),
|
||||||
}, None, ast::DUMMY_NODE_ID),
|
}, None, ast::DUMMY_NODE_ID),
|
||||||
span:sp(10,13)
|
span:sp(10,13)
|
||||||
}),
|
}),
|
||||||
|
@ -644,21 +644,21 @@ mod test {
|
||||||
ast::Path {
|
ast::Path {
|
||||||
span:sp(6,7),
|
span:sp(6,7),
|
||||||
global:false,
|
global:false,
|
||||||
segments: ~[
|
segments: vec!(
|
||||||
ast::PathSegment {
|
ast::PathSegment {
|
||||||
identifier:
|
identifier:
|
||||||
str_to_ident("b"),
|
str_to_ident("b"),
|
||||||
lifetimes: opt_vec::Empty,
|
lifetimes: opt_vec::Empty,
|
||||||
types: opt_vec::Empty,
|
types: opt_vec::Empty,
|
||||||
}
|
}
|
||||||
],
|
),
|
||||||
},
|
},
|
||||||
None // no idea
|
None // no idea
|
||||||
),
|
),
|
||||||
span: sp(6,7)
|
span: sp(6,7)
|
||||||
},
|
},
|
||||||
id: ast::DUMMY_NODE_ID
|
id: ast::DUMMY_NODE_ID
|
||||||
}],
|
}),
|
||||||
output: ast::P(ast::Ty{id: ast::DUMMY_NODE_ID,
|
output: ast::P(ast::Ty{id: ast::DUMMY_NODE_ID,
|
||||||
node: ast::TyNil,
|
node: ast::TyNil,
|
||||||
span:sp(15,15)}), // not sure
|
span:sp(15,15)}), // not sure
|
||||||
|
@ -672,15 +672,15 @@ mod test {
|
||||||
ty_params: opt_vec::Empty,
|
ty_params: opt_vec::Empty,
|
||||||
},
|
},
|
||||||
ast::P(ast::Block {
|
ast::P(ast::Block {
|
||||||
view_items: ~[],
|
view_items: Vec::new(),
|
||||||
stmts: ~[@Spanned{
|
stmts: vec!(@Spanned{
|
||||||
node: ast::StmtSemi(@ast::Expr{
|
node: ast::StmtSemi(@ast::Expr{
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
node: ast::ExprPath(
|
node: ast::ExprPath(
|
||||||
ast::Path{
|
ast::Path{
|
||||||
span:sp(17,18),
|
span:sp(17,18),
|
||||||
global:false,
|
global:false,
|
||||||
segments: ~[
|
segments: vec!(
|
||||||
ast::PathSegment {
|
ast::PathSegment {
|
||||||
identifier:
|
identifier:
|
||||||
str_to_ident(
|
str_to_ident(
|
||||||
|
@ -690,11 +690,11 @@ mod test {
|
||||||
types:
|
types:
|
||||||
opt_vec::Empty
|
opt_vec::Empty
|
||||||
}
|
}
|
||||||
],
|
),
|
||||||
}),
|
}),
|
||||||
span: sp(17,18)},
|
span: sp(17,18)},
|
||||||
ast::DUMMY_NODE_ID),
|
ast::DUMMY_NODE_ID),
|
||||||
span: sp(17,18)}],
|
span: sp(17,18)}),
|
||||||
expr: None,
|
expr: None,
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
rules: ast::DefaultBlock, // no idea
|
rules: ast::DefaultBlock, // no idea
|
||||||
|
|
|
@ -93,7 +93,7 @@ enum restriction {
|
||||||
RESTRICT_NO_BAR_OR_DOUBLEBAR_OP,
|
RESTRICT_NO_BAR_OR_DOUBLEBAR_OP,
|
||||||
}
|
}
|
||||||
|
|
||||||
type ItemInfo = (Ident, Item_, Option<~[Attribute]>);
|
type ItemInfo = (Ident, Item_, Option<Vec<Attribute> >);
|
||||||
|
|
||||||
/// How to parse a path. There are four different kinds of paths, all of which
|
/// How to parse a path. There are four different kinds of paths, all of which
|
||||||
/// are parsed somewhat differently.
|
/// are parsed somewhat differently.
|
||||||
|
@ -129,7 +129,7 @@ pub struct PathAndBounds {
|
||||||
enum ItemOrViewItem {
|
enum ItemOrViewItem {
|
||||||
// Indicates a failure to parse any kind of item. The attributes are
|
// Indicates a failure to parse any kind of item. The attributes are
|
||||||
// returned.
|
// returned.
|
||||||
IoviNone(~[Attribute]),
|
IoviNone(Vec<Attribute> ),
|
||||||
IoviItem(@Item),
|
IoviItem(@Item),
|
||||||
IoviForeignItem(@ForeignItem),
|
IoviForeignItem(@ForeignItem),
|
||||||
IoviViewItem(ViewItem)
|
IoviViewItem(ViewItem)
|
||||||
|
@ -257,7 +257,7 @@ macro_rules! maybe_whole (
|
||||||
};
|
};
|
||||||
match __found__ {
|
match __found__ {
|
||||||
Some(INTERPOLATED(token::$constructor(x))) => {
|
Some(INTERPOLATED(token::$constructor(x))) => {
|
||||||
return (~[], x)
|
return (Vec::new(), x)
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -266,21 +266,20 @@ macro_rules! maybe_whole (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
fn maybe_append(lhs: ~[Attribute], rhs: Option<~[Attribute]>)
|
fn maybe_append(lhs: Vec<Attribute> , rhs: Option<Vec<Attribute> >)
|
||||||
-> ~[Attribute] {
|
-> Vec<Attribute> {
|
||||||
match rhs {
|
match rhs {
|
||||||
None => lhs,
|
None => lhs,
|
||||||
Some(ref attrs) => vec::append(lhs, (*attrs))
|
Some(ref attrs) => vec_ng::append(lhs, (*attrs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct ParsedItemsAndViewItems {
|
struct ParsedItemsAndViewItems {
|
||||||
attrs_remaining: ~[Attribute],
|
attrs_remaining: Vec<Attribute> ,
|
||||||
view_items: ~[ViewItem],
|
view_items: Vec<ViewItem> ,
|
||||||
items: ~[@Item],
|
items: Vec<@Item> ,
|
||||||
foreign_items: ~[@ForeignItem]
|
foreign_items: Vec<@ForeignItem> }
|
||||||
}
|
|
||||||
|
|
||||||
/* ident is handled by common.rs */
|
/* ident is handled by common.rs */
|
||||||
|
|
||||||
|
@ -314,8 +313,8 @@ pub fn Parser(sess: @ParseSess, cfg: ast::CrateConfig, rdr: ~Reader:)
|
||||||
restriction: UNRESTRICTED,
|
restriction: UNRESTRICTED,
|
||||||
quote_depth: 0,
|
quote_depth: 0,
|
||||||
obsolete_set: HashSet::new(),
|
obsolete_set: HashSet::new(),
|
||||||
mod_path_stack: ~[],
|
mod_path_stack: Vec::new(),
|
||||||
open_braces: ~[],
|
open_braces: Vec::new(),
|
||||||
nopod: marker::NoPod
|
nopod: marker::NoPod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -343,9 +342,9 @@ pub struct Parser {
|
||||||
/// extra detail when the same error is seen twice
|
/// extra detail when the same error is seen twice
|
||||||
obsolete_set: HashSet<ObsoleteSyntax>,
|
obsolete_set: HashSet<ObsoleteSyntax>,
|
||||||
/// Used to determine the path to externally loaded source files
|
/// Used to determine the path to externally loaded source files
|
||||||
mod_path_stack: ~[InternedString],
|
mod_path_stack: Vec<InternedString> ,
|
||||||
/// Stack of spans of open delimiters. Used for error message.
|
/// Stack of spans of open delimiters. Used for error message.
|
||||||
open_braces: ~[Span],
|
open_braces: Vec<Span> ,
|
||||||
/* do not copy the parser; its state is tied to outside state */
|
/* do not copy the parser; its state is tied to outside state */
|
||||||
priv nopod: marker::NoPod
|
priv nopod: marker::NoPod
|
||||||
}
|
}
|
||||||
|
@ -407,7 +406,7 @@ impl Parser {
|
||||||
} else if inedible.contains(&self.token) {
|
} else if inedible.contains(&self.token) {
|
||||||
// leave it in the input
|
// leave it in the input
|
||||||
} else {
|
} else {
|
||||||
let expected = vec::append(edible.to_owned(), inedible);
|
let expected = vec_ng::append(edible.to_owned(), inedible);
|
||||||
let expect = tokens_to_str(expected);
|
let expect = tokens_to_str(expected);
|
||||||
let actual = self.this_token_to_str();
|
let actual = self.this_token_to_str();
|
||||||
self.fatal(
|
self.fatal(
|
||||||
|
@ -446,7 +445,7 @@ impl Parser {
|
||||||
match e.node {
|
match e.node {
|
||||||
ExprPath(..) => {
|
ExprPath(..) => {
|
||||||
// might be unit-struct construction; check for recoverableinput error.
|
// might be unit-struct construction; check for recoverableinput error.
|
||||||
let expected = vec::append(edible.to_owned(), inedible);
|
let expected = vec_ng::append(edible.to_owned(), inedible);
|
||||||
self.check_for_erroneous_unit_struct_expecting(expected);
|
self.check_for_erroneous_unit_struct_expecting(expected);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -465,7 +464,7 @@ impl Parser {
|
||||||
debug!("commit_stmt {:?}", s);
|
debug!("commit_stmt {:?}", s);
|
||||||
let _s = s; // unused, but future checks might want to inspect `s`.
|
let _s = s; // unused, but future checks might want to inspect `s`.
|
||||||
if self.last_token.as_ref().map_or(false, |t| is_ident_or_path(*t)) {
|
if self.last_token.as_ref().map_or(false, |t| is_ident_or_path(*t)) {
|
||||||
let expected = vec::append(edible.to_owned(), inedible);
|
let expected = vec_ng::append(edible.to_owned(), inedible);
|
||||||
self.check_for_erroneous_unit_struct_expecting(expected);
|
self.check_for_erroneous_unit_struct_expecting(expected);
|
||||||
}
|
}
|
||||||
self.expect_one_of(edible, inedible)
|
self.expect_one_of(edible, inedible)
|
||||||
|
@ -578,9 +577,9 @@ impl Parser {
|
||||||
&mut self,
|
&mut self,
|
||||||
sep: &token::Token,
|
sep: &token::Token,
|
||||||
f: |&mut Parser| -> T)
|
f: |&mut Parser| -> T)
|
||||||
-> ~[T] {
|
-> Vec<T> {
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
let mut vector = ~[];
|
let mut vector = Vec::new();
|
||||||
while self.token != token::BINOP(token::OR) &&
|
while self.token != token::BINOP(token::OR) &&
|
||||||
self.token != token::OROR {
|
self.token != token::OROR {
|
||||||
if first {
|
if first {
|
||||||
|
@ -655,7 +654,7 @@ impl Parser {
|
||||||
ket: &token::Token,
|
ket: &token::Token,
|
||||||
sep: SeqSep,
|
sep: SeqSep,
|
||||||
f: |&mut Parser| -> T)
|
f: |&mut Parser| -> T)
|
||||||
-> ~[T] {
|
-> Vec<T> {
|
||||||
let val = self.parse_seq_to_before_end(ket, sep, f);
|
let val = self.parse_seq_to_before_end(ket, sep, f);
|
||||||
self.bump();
|
self.bump();
|
||||||
val
|
val
|
||||||
|
@ -669,9 +668,9 @@ impl Parser {
|
||||||
ket: &token::Token,
|
ket: &token::Token,
|
||||||
sep: SeqSep,
|
sep: SeqSep,
|
||||||
f: |&mut Parser| -> T)
|
f: |&mut Parser| -> T)
|
||||||
-> ~[T] {
|
-> Vec<T> {
|
||||||
let mut first: bool = true;
|
let mut first: bool = true;
|
||||||
let mut v: ~[T] = ~[];
|
let mut v: Vec<T> = Vec::new();
|
||||||
while self.token != *ket {
|
while self.token != *ket {
|
||||||
match sep.sep {
|
match sep.sep {
|
||||||
Some(ref t) => {
|
Some(ref t) => {
|
||||||
|
@ -695,7 +694,7 @@ impl Parser {
|
||||||
ket: &token::Token,
|
ket: &token::Token,
|
||||||
sep: SeqSep,
|
sep: SeqSep,
|
||||||
f: |&mut Parser| -> T)
|
f: |&mut Parser| -> T)
|
||||||
-> ~[T] {
|
-> Vec<T> {
|
||||||
self.expect(bra);
|
self.expect(bra);
|
||||||
let result = self.parse_seq_to_before_end(ket, sep, f);
|
let result = self.parse_seq_to_before_end(ket, sep, f);
|
||||||
self.bump();
|
self.bump();
|
||||||
|
@ -710,7 +709,7 @@ impl Parser {
|
||||||
ket: &token::Token,
|
ket: &token::Token,
|
||||||
sep: SeqSep,
|
sep: SeqSep,
|
||||||
f: |&mut Parser| -> T)
|
f: |&mut Parser| -> T)
|
||||||
-> Spanned<~[T]> {
|
-> Spanned<Vec<T> > {
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
self.expect(bra);
|
self.expect(bra);
|
||||||
let result = self.parse_seq_to_before_end(ket, sep, f);
|
let result = self.parse_seq_to_before_end(ket, sep, f);
|
||||||
|
@ -950,7 +949,7 @@ impl Parser {
|
||||||
};
|
};
|
||||||
|
|
||||||
let inputs = if self.eat(&token::OROR) {
|
let inputs = if self.eat(&token::OROR) {
|
||||||
~[]
|
Vec::new()
|
||||||
} else {
|
} else {
|
||||||
self.expect_or();
|
self.expect_or();
|
||||||
let inputs = self.parse_seq_to_before_or(
|
let inputs = self.parse_seq_to_before_or(
|
||||||
|
@ -1034,7 +1033,7 @@ impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the methods in a trait declaration
|
// parse the methods in a trait declaration
|
||||||
pub fn parse_trait_methods(&mut self) -> ~[TraitMethod] {
|
pub fn parse_trait_methods(&mut self) -> Vec<TraitMethod> {
|
||||||
self.parse_unspanned_seq(
|
self.parse_unspanned_seq(
|
||||||
&token::LBRACE,
|
&token::LBRACE,
|
||||||
&token::RBRACE,
|
&token::RBRACE,
|
||||||
|
@ -1083,7 +1082,7 @@ impl Parser {
|
||||||
debug!("parse_trait_methods(): parsing provided method");
|
debug!("parse_trait_methods(): parsing provided method");
|
||||||
let (inner_attrs, body) =
|
let (inner_attrs, body) =
|
||||||
p.parse_inner_attrs_and_block();
|
p.parse_inner_attrs_and_block();
|
||||||
let attrs = vec::append(attrs, inner_attrs);
|
let attrs = vec_ng::append(attrs, inner_attrs);
|
||||||
Provided(@ast::Method {
|
Provided(@ast::Method {
|
||||||
ident: ident,
|
ident: ident,
|
||||||
attrs: attrs,
|
attrs: attrs,
|
||||||
|
@ -1176,7 +1175,7 @@ impl Parser {
|
||||||
// (t) is a parenthesized ty
|
// (t) is a parenthesized ty
|
||||||
// (t,) is the type of a tuple with only one field,
|
// (t,) is the type of a tuple with only one field,
|
||||||
// of type t
|
// of type t
|
||||||
let mut ts = ~[self.parse_ty(false)];
|
let mut ts = vec!(self.parse_ty(false));
|
||||||
let mut one_tuple = false;
|
let mut one_tuple = false;
|
||||||
while self.token == token::COMMA {
|
while self.token == token::COMMA {
|
||||||
self.bump();
|
self.bump();
|
||||||
|
@ -1479,7 +1478,7 @@ impl Parser {
|
||||||
// Parse any number of segments and bound sets. A segment is an
|
// Parse any number of segments and bound sets. A segment is an
|
||||||
// identifier followed by an optional lifetime and a set of types.
|
// identifier followed by an optional lifetime and a set of types.
|
||||||
// A bound set is a set of type parameter bounds.
|
// A bound set is a set of type parameter bounds.
|
||||||
let mut segments = ~[];
|
let mut segments = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
// First, parse an identifier.
|
// First, parse an identifier.
|
||||||
let identifier = self.parse_ident();
|
let identifier = self.parse_ident();
|
||||||
|
@ -1541,7 +1540,7 @@ impl Parser {
|
||||||
let span = mk_sp(lo, self.last_span.hi);
|
let span = mk_sp(lo, self.last_span.hi);
|
||||||
|
|
||||||
// Assemble the path segments.
|
// Assemble the path segments.
|
||||||
let mut path_segments = ~[];
|
let mut path_segments = Vec::new();
|
||||||
let mut bounds = None;
|
let mut bounds = None;
|
||||||
let last_segment_index = segments.len() - 1;
|
let last_segment_index = segments.len() - 1;
|
||||||
for (i, segment_and_bounds) in segments.move_iter().enumerate() {
|
for (i, segment_and_bounds) in segments.move_iter().enumerate() {
|
||||||
|
@ -1690,11 +1689,11 @@ impl Parser {
|
||||||
ExprBinary(binop, lhs, rhs)
|
ExprBinary(binop, lhs, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_call(&mut self, f: @Expr, args: ~[@Expr]) -> ast::Expr_ {
|
pub fn mk_call(&mut self, f: @Expr, args: Vec<@Expr> ) -> ast::Expr_ {
|
||||||
ExprCall(f, args)
|
ExprCall(f, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mk_method_call(&mut self, ident: Ident, tps: ~[P<Ty>], args: ~[@Expr]) -> ast::Expr_ {
|
fn mk_method_call(&mut self, ident: Ident, tps: Vec<P<Ty>> , args: Vec<@Expr> ) -> ast::Expr_ {
|
||||||
ExprMethodCall(ident, tps, args)
|
ExprMethodCall(ident, tps, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1702,7 +1701,7 @@ impl Parser {
|
||||||
ExprIndex(expr, idx)
|
ExprIndex(expr, idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_field(&mut self, expr: @Expr, ident: Ident, tys: ~[P<Ty>]) -> ast::Expr_ {
|
pub fn mk_field(&mut self, expr: @Expr, ident: Ident, tys: Vec<P<Ty>> ) -> ast::Expr_ {
|
||||||
ExprField(expr, ident, tys)
|
ExprField(expr, ident, tys)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1754,7 +1753,7 @@ impl Parser {
|
||||||
let lit = @spanned(lo, hi, LitNil);
|
let lit = @spanned(lo, hi, LitNil);
|
||||||
return self.mk_expr(lo, hi, ExprLit(lit));
|
return self.mk_expr(lo, hi, ExprLit(lit));
|
||||||
}
|
}
|
||||||
let mut es = ~[self.parse_expr()];
|
let mut es = vec!(self.parse_expr());
|
||||||
self.commit_expr(*es.last().unwrap(), &[], &[token::COMMA, token::RPAREN]);
|
self.commit_expr(*es.last().unwrap(), &[], &[token::COMMA, token::RPAREN]);
|
||||||
while self.token == token::COMMA {
|
while self.token == token::COMMA {
|
||||||
self.bump();
|
self.bump();
|
||||||
|
@ -1786,8 +1785,8 @@ impl Parser {
|
||||||
let decl = self.parse_proc_decl();
|
let decl = self.parse_proc_decl();
|
||||||
let body = self.parse_expr();
|
let body = self.parse_expr();
|
||||||
let fakeblock = P(ast::Block {
|
let fakeblock = P(ast::Block {
|
||||||
view_items: ~[],
|
view_items: Vec::new(),
|
||||||
stmts: ~[],
|
stmts: Vec::new(),
|
||||||
expr: Some(body),
|
expr: Some(body),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
rules: DefaultBlock,
|
rules: DefaultBlock,
|
||||||
|
@ -1840,7 +1839,7 @@ impl Parser {
|
||||||
if self.token == token::RBRACKET {
|
if self.token == token::RBRACKET {
|
||||||
// Empty vector.
|
// Empty vector.
|
||||||
self.bump();
|
self.bump();
|
||||||
ex = ExprVec(~[], mutbl);
|
ex = ExprVec(Vec::new(), mutbl);
|
||||||
} else {
|
} else {
|
||||||
// Nonempty vector.
|
// Nonempty vector.
|
||||||
let first_expr = self.parse_expr();
|
let first_expr = self.parse_expr();
|
||||||
|
@ -1860,11 +1859,11 @@ impl Parser {
|
||||||
seq_sep_trailing_allowed(token::COMMA),
|
seq_sep_trailing_allowed(token::COMMA),
|
||||||
|p| p.parse_expr()
|
|p| p.parse_expr()
|
||||||
);
|
);
|
||||||
ex = ExprVec(~[first_expr] + remaining_exprs, mutbl);
|
ex = ExprVec(vec!(first_expr) + remaining_exprs, mutbl);
|
||||||
} else {
|
} else {
|
||||||
// Vector with one element.
|
// Vector with one element.
|
||||||
self.expect(&token::RBRACKET);
|
self.expect(&token::RBRACKET);
|
||||||
ex = ExprVec(~[first_expr], mutbl);
|
ex = ExprVec(vec!(first_expr), mutbl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hi = self.last_span.hi;
|
hi = self.last_span.hi;
|
||||||
|
@ -1919,7 +1918,7 @@ impl Parser {
|
||||||
if self.looking_at_struct_literal() {
|
if self.looking_at_struct_literal() {
|
||||||
// It's a struct literal.
|
// It's a struct literal.
|
||||||
self.bump();
|
self.bump();
|
||||||
let mut fields = ~[];
|
let mut fields = Vec::new();
|
||||||
let mut base = None;
|
let mut base = None;
|
||||||
|
|
||||||
while self.token != token::RBRACE {
|
while self.token != token::RBRACE {
|
||||||
|
@ -1981,7 +1980,7 @@ impl Parser {
|
||||||
self.expect(&token::LT);
|
self.expect(&token::LT);
|
||||||
self.parse_generic_values_after_lt()
|
self.parse_generic_values_after_lt()
|
||||||
} else {
|
} else {
|
||||||
(opt_vec::Empty, ~[])
|
(opt_vec::Empty, Vec::new())
|
||||||
};
|
};
|
||||||
|
|
||||||
// expr.f() method call
|
// expr.f() method call
|
||||||
|
@ -2143,7 +2142,7 @@ impl Parser {
|
||||||
|
|
||||||
// Parse the open delimiter.
|
// Parse the open delimiter.
|
||||||
self.open_braces.push(self.span);
|
self.open_braces.push(self.span);
|
||||||
let mut result = ~[parse_any_tt_tok(self)];
|
let mut result = vec!(parse_any_tt_tok(self));
|
||||||
|
|
||||||
let trees =
|
let trees =
|
||||||
self.parse_seq_to_before_end(&close_delim,
|
self.parse_seq_to_before_end(&close_delim,
|
||||||
|
@ -2163,15 +2162,15 @@ impl Parser {
|
||||||
|
|
||||||
// parse a stream of tokens into a list of TokenTree's,
|
// parse a stream of tokens into a list of TokenTree's,
|
||||||
// up to EOF.
|
// up to EOF.
|
||||||
pub fn parse_all_token_trees(&mut self) -> ~[TokenTree] {
|
pub fn parse_all_token_trees(&mut self) -> Vec<TokenTree> {
|
||||||
let mut tts = ~[];
|
let mut tts = Vec::new();
|
||||||
while self.token != token::EOF {
|
while self.token != token::EOF {
|
||||||
tts.push(self.parse_token_tree());
|
tts.push(self.parse_token_tree());
|
||||||
}
|
}
|
||||||
tts
|
tts
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_matchers(&mut self) -> ~[Matcher] {
|
pub fn parse_matchers(&mut self) -> Vec<Matcher> {
|
||||||
// unification of Matcher's and TokenTree's would vastly improve
|
// unification of Matcher's and TokenTree's would vastly improve
|
||||||
// the interpolation of Matcher's
|
// the interpolation of Matcher's
|
||||||
maybe_whole!(self, NtMatchers);
|
maybe_whole!(self, NtMatchers);
|
||||||
|
@ -2192,8 +2191,8 @@ impl Parser {
|
||||||
pub fn parse_matcher_subseq_upto(&mut self,
|
pub fn parse_matcher_subseq_upto(&mut self,
|
||||||
name_idx: @Cell<uint>,
|
name_idx: @Cell<uint>,
|
||||||
ket: &token::Token)
|
ket: &token::Token)
|
||||||
-> ~[Matcher] {
|
-> Vec<Matcher> {
|
||||||
let mut ret_val = ~[];
|
let mut ret_val = Vec::new();
|
||||||
let mut lparens = 0u;
|
let mut lparens = 0u;
|
||||||
|
|
||||||
while self.token != *ket || lparens > 0u {
|
while self.token != *ket || lparens > 0u {
|
||||||
|
@ -2478,7 +2477,7 @@ impl Parser {
|
||||||
_ => {
|
_ => {
|
||||||
// No argument list - `do foo {`
|
// No argument list - `do foo {`
|
||||||
P(FnDecl {
|
P(FnDecl {
|
||||||
inputs: ~[],
|
inputs: Vec::new(),
|
||||||
output: P(Ty {
|
output: P(Ty {
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
node: TyInfer,
|
node: TyInfer,
|
||||||
|
@ -2513,8 +2512,8 @@ impl Parser {
|
||||||
let decl = parse_decl(self);
|
let decl = parse_decl(self);
|
||||||
let body = parse_body(self);
|
let body = parse_body(self);
|
||||||
let fakeblock = P(ast::Block {
|
let fakeblock = P(ast::Block {
|
||||||
view_items: ~[],
|
view_items: Vec::new(),
|
||||||
stmts: ~[],
|
stmts: Vec::new(),
|
||||||
expr: Some(body),
|
expr: Some(body),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
rules: DefaultBlock,
|
rules: DefaultBlock,
|
||||||
|
@ -2601,7 +2600,7 @@ impl Parser {
|
||||||
let lo = self.last_span.lo;
|
let lo = self.last_span.lo;
|
||||||
let discriminant = self.parse_expr();
|
let discriminant = self.parse_expr();
|
||||||
self.commit_expr_expecting(discriminant, token::LBRACE);
|
self.commit_expr_expecting(discriminant, token::LBRACE);
|
||||||
let mut arms: ~[Arm] = ~[];
|
let mut arms: Vec<Arm> = Vec::new();
|
||||||
while self.token != token::RBRACE {
|
while self.token != token::RBRACE {
|
||||||
let pats = self.parse_pats();
|
let pats = self.parse_pats();
|
||||||
let mut guard = None;
|
let mut guard = None;
|
||||||
|
@ -2622,8 +2621,8 @@ impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
let blk = P(ast::Block {
|
let blk = P(ast::Block {
|
||||||
view_items: ~[],
|
view_items: Vec::new(),
|
||||||
stmts: ~[],
|
stmts: Vec::new(),
|
||||||
expr: Some(expr),
|
expr: Some(expr),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
rules: DefaultBlock,
|
rules: DefaultBlock,
|
||||||
|
@ -2662,8 +2661,8 @@ impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse patterns, separated by '|' s
|
// parse patterns, separated by '|' s
|
||||||
fn parse_pats(&mut self) -> ~[@Pat] {
|
fn parse_pats(&mut self) -> Vec<@Pat> {
|
||||||
let mut pats = ~[];
|
let mut pats = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
pats.push(self.parse_pat());
|
pats.push(self.parse_pat());
|
||||||
if self.token == token::BINOP(token::OR) { self.bump(); }
|
if self.token == token::BINOP(token::OR) { self.bump(); }
|
||||||
|
@ -2673,10 +2672,10 @@ impl Parser {
|
||||||
|
|
||||||
fn parse_pat_vec_elements(
|
fn parse_pat_vec_elements(
|
||||||
&mut self,
|
&mut self,
|
||||||
) -> (~[@Pat], Option<@Pat>, ~[@Pat]) {
|
) -> (Vec<@Pat> , Option<@Pat>, Vec<@Pat> ) {
|
||||||
let mut before = ~[];
|
let mut before = Vec::new();
|
||||||
let mut slice = None;
|
let mut slice = None;
|
||||||
let mut after = ~[];
|
let mut after = Vec::new();
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
let mut before_slice = true;
|
let mut before_slice = true;
|
||||||
|
|
||||||
|
@ -2733,8 +2732,8 @@ impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the fields of a struct-like pattern
|
// parse the fields of a struct-like pattern
|
||||||
fn parse_pat_fields(&mut self) -> (~[ast::FieldPat], bool) {
|
fn parse_pat_fields(&mut self) -> (Vec<ast::FieldPat> , bool) {
|
||||||
let mut fields = ~[];
|
let mut fields = Vec::new();
|
||||||
let mut etc = false;
|
let mut etc = false;
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
while self.token != token::RBRACE {
|
while self.token != token::RBRACE {
|
||||||
|
@ -2900,7 +2899,7 @@ impl Parser {
|
||||||
let expr = self.mk_expr(lo, hi, ExprLit(lit));
|
let expr = self.mk_expr(lo, hi, ExprLit(lit));
|
||||||
pat = PatLit(expr);
|
pat = PatLit(expr);
|
||||||
} else {
|
} else {
|
||||||
let mut fields = ~[self.parse_pat()];
|
let mut fields = vec!(self.parse_pat());
|
||||||
if self.look_ahead(1, |t| *t != token::RPAREN) {
|
if self.look_ahead(1, |t| *t != token::RPAREN) {
|
||||||
while self.token == token::COMMA {
|
while self.token == token::COMMA {
|
||||||
self.bump();
|
self.bump();
|
||||||
|
@ -3002,7 +3001,7 @@ impl Parser {
|
||||||
pat = PatStruct(enum_path, fields, etc);
|
pat = PatStruct(enum_path, fields, etc);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let mut args: ~[@Pat] = ~[];
|
let mut args: Vec<@Pat> = Vec::new();
|
||||||
match self.token {
|
match self.token {
|
||||||
token::LPAREN => {
|
token::LPAREN => {
|
||||||
let is_star = self.look_ahead(1, |t| {
|
let is_star = self.look_ahead(1, |t| {
|
||||||
|
@ -3128,7 +3127,7 @@ impl Parser {
|
||||||
|
|
||||||
// parse a structure field
|
// parse a structure field
|
||||||
fn parse_name_and_ty(&mut self, pr: Visibility,
|
fn parse_name_and_ty(&mut self, pr: Visibility,
|
||||||
attrs: ~[Attribute]) -> StructField {
|
attrs: Vec<Attribute> ) -> StructField {
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
if !is_plain_ident(&self.token) {
|
if !is_plain_ident(&self.token) {
|
||||||
self.fatal("expected ident");
|
self.fatal("expected ident");
|
||||||
|
@ -3146,7 +3145,7 @@ impl Parser {
|
||||||
|
|
||||||
// parse a statement. may include decl.
|
// parse a statement. may include decl.
|
||||||
// precondition: any attributes are parsed already
|
// precondition: any attributes are parsed already
|
||||||
pub fn parse_stmt(&mut self, item_attrs: ~[Attribute]) -> @Stmt {
|
pub fn parse_stmt(&mut self, item_attrs: Vec<Attribute> ) -> @Stmt {
|
||||||
maybe_whole!(self, NtStmt);
|
maybe_whole!(self, NtStmt);
|
||||||
|
|
||||||
fn check_expected_item(p: &mut Parser, found_attrs: bool) {
|
fn check_expected_item(p: &mut Parser, found_attrs: bool) {
|
||||||
|
@ -3229,7 +3228,7 @@ impl Parser {
|
||||||
self.mk_item(
|
self.mk_item(
|
||||||
lo, hi, id /*id is good here*/,
|
lo, hi, id /*id is good here*/,
|
||||||
ItemMac(spanned(lo, hi, MacInvocTT(pth, tts, EMPTY_CTXT))),
|
ItemMac(spanned(lo, hi, MacInvocTT(pth, tts, EMPTY_CTXT))),
|
||||||
Inherited, ~[/*no attrs*/]))),
|
Inherited, Vec::new(/*no attrs*/)))),
|
||||||
ast::DUMMY_NODE_ID));
|
ast::DUMMY_NODE_ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3275,12 +3274,12 @@ impl Parser {
|
||||||
}
|
}
|
||||||
self.expect(&token::LBRACE);
|
self.expect(&token::LBRACE);
|
||||||
|
|
||||||
return self.parse_block_tail_(lo, DefaultBlock, ~[]);
|
return self.parse_block_tail_(lo, DefaultBlock, Vec::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse a block. Inner attrs are allowed.
|
// parse a block. Inner attrs are allowed.
|
||||||
fn parse_inner_attrs_and_block(&mut self)
|
fn parse_inner_attrs_and_block(&mut self)
|
||||||
-> (~[Attribute], P<Block>) {
|
-> (Vec<Attribute> , P<Block>) {
|
||||||
|
|
||||||
maybe_whole!(pair_empty self, NtBlock);
|
maybe_whole!(pair_empty self, NtBlock);
|
||||||
|
|
||||||
|
@ -3299,13 +3298,13 @@ impl Parser {
|
||||||
// necessary, and this should take a qualifier.
|
// necessary, and this should take a qualifier.
|
||||||
// some blocks start with "#{"...
|
// some blocks start with "#{"...
|
||||||
fn parse_block_tail(&mut self, lo: BytePos, s: BlockCheckMode) -> P<Block> {
|
fn parse_block_tail(&mut self, lo: BytePos, s: BlockCheckMode) -> P<Block> {
|
||||||
self.parse_block_tail_(lo, s, ~[])
|
self.parse_block_tail_(lo, s, Vec::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the rest of a block expression or function body
|
// parse the rest of a block expression or function body
|
||||||
fn parse_block_tail_(&mut self, lo: BytePos, s: BlockCheckMode,
|
fn parse_block_tail_(&mut self, lo: BytePos, s: BlockCheckMode,
|
||||||
first_item_attrs: ~[Attribute]) -> P<Block> {
|
first_item_attrs: Vec<Attribute> ) -> P<Block> {
|
||||||
let mut stmts = ~[];
|
let mut stmts = Vec::new();
|
||||||
let mut expr = None;
|
let mut expr = None;
|
||||||
|
|
||||||
// wouldn't it be more uniform to parse view items only, here?
|
// wouldn't it be more uniform to parse view items only, here?
|
||||||
|
@ -3333,7 +3332,7 @@ impl Parser {
|
||||||
token::SEMI => {
|
token::SEMI => {
|
||||||
if !attributes_box.is_empty() {
|
if !attributes_box.is_empty() {
|
||||||
self.span_err(self.last_span, "expected item after attributes");
|
self.span_err(self.last_span, "expected item after attributes");
|
||||||
attributes_box = ~[];
|
attributes_box = Vec::new();
|
||||||
}
|
}
|
||||||
self.bump(); // empty
|
self.bump(); // empty
|
||||||
}
|
}
|
||||||
|
@ -3342,7 +3341,7 @@ impl Parser {
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let stmt = self.parse_stmt(attributes_box);
|
let stmt = self.parse_stmt(attributes_box);
|
||||||
attributes_box = ~[];
|
attributes_box = Vec::new();
|
||||||
match stmt.node {
|
match stmt.node {
|
||||||
StmtExpr(e, stmt_id) => {
|
StmtExpr(e, stmt_id) => {
|
||||||
// expression without semicolon
|
// expression without semicolon
|
||||||
|
@ -3510,7 +3509,7 @@ impl Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_generic_values_after_lt(&mut self) -> (OptVec<ast::Lifetime>, ~[P<Ty>]) {
|
fn parse_generic_values_after_lt(&mut self) -> (OptVec<ast::Lifetime>, Vec<P<Ty>> ) {
|
||||||
let lifetimes = self.parse_lifetimes();
|
let lifetimes = self.parse_lifetimes();
|
||||||
let result = self.parse_seq_to_gt(
|
let result = self.parse_seq_to_gt(
|
||||||
Some(token::COMMA),
|
Some(token::COMMA),
|
||||||
|
@ -3519,9 +3518,9 @@ impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_fn_args(&mut self, named_args: bool, allow_variadic: bool)
|
fn parse_fn_args(&mut self, named_args: bool, allow_variadic: bool)
|
||||||
-> (~[Arg], bool) {
|
-> (Vec<Arg> , bool) {
|
||||||
let sp = self.span;
|
let sp = self.span;
|
||||||
let mut args: ~[Option<Arg>] =
|
let mut args: Vec<Option<Arg>> =
|
||||||
self.parse_unspanned_seq(
|
self.parse_unspanned_seq(
|
||||||
&token::LPAREN,
|
&token::LPAREN,
|
||||||
&token::RPAREN,
|
&token::RPAREN,
|
||||||
|
@ -3716,7 +3715,7 @@ impl Parser {
|
||||||
fn_inputs
|
fn_inputs
|
||||||
}
|
}
|
||||||
token::RPAREN => {
|
token::RPAREN => {
|
||||||
~[Arg::new_self(explicit_self_sp, mutbl_self)]
|
vec!(Arg::new_self(explicit_self_sp, mutbl_self))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let token_str = self.this_token_to_str();
|
let token_str = self.this_token_to_str();
|
||||||
|
@ -3749,7 +3748,7 @@ impl Parser {
|
||||||
fn parse_fn_block_decl(&mut self) -> P<FnDecl> {
|
fn parse_fn_block_decl(&mut self) -> P<FnDecl> {
|
||||||
let inputs_captures = {
|
let inputs_captures = {
|
||||||
if self.eat(&token::OROR) {
|
if self.eat(&token::OROR) {
|
||||||
~[]
|
Vec::new()
|
||||||
} else {
|
} else {
|
||||||
self.parse_unspanned_seq(
|
self.parse_unspanned_seq(
|
||||||
&token::BINOP(token::OR),
|
&token::BINOP(token::OR),
|
||||||
|
@ -3812,7 +3811,7 @@ impl Parser {
|
||||||
|
|
||||||
fn mk_item(&mut self, lo: BytePos, hi: BytePos, ident: Ident,
|
fn mk_item(&mut self, lo: BytePos, hi: BytePos, ident: Ident,
|
||||||
node: Item_, vis: Visibility,
|
node: Item_, vis: Visibility,
|
||||||
attrs: ~[Attribute]) -> @Item {
|
attrs: Vec<Attribute> ) -> @Item {
|
||||||
@Item {
|
@Item {
|
||||||
ident: ident,
|
ident: ident,
|
||||||
attrs: attrs,
|
attrs: attrs,
|
||||||
|
@ -3832,7 +3831,7 @@ impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse a method in a trait impl, starting with `attrs` attributes.
|
// 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<Vec<Attribute> >) -> @Method {
|
||||||
let next_attrs = self.parse_outer_attributes();
|
let next_attrs = self.parse_outer_attributes();
|
||||||
let attrs = match already_parsed_attrs {
|
let attrs = match already_parsed_attrs {
|
||||||
Some(mut a) => { a.push_all_move(next_attrs); a }
|
Some(mut a) => { a.push_all_move(next_attrs); a }
|
||||||
|
@ -3851,7 +3850,7 @@ impl Parser {
|
||||||
|
|
||||||
let (inner_attrs, body) = self.parse_inner_attrs_and_block();
|
let (inner_attrs, body) = self.parse_inner_attrs_and_block();
|
||||||
let hi = body.span.hi;
|
let hi = body.span.hi;
|
||||||
let attrs = vec::append(attrs, inner_attrs);
|
let attrs = vec_ng::append(attrs, inner_attrs);
|
||||||
@ast::Method {
|
@ast::Method {
|
||||||
ident: ident,
|
ident: ident,
|
||||||
attrs: attrs,
|
attrs: attrs,
|
||||||
|
@ -3877,7 +3876,7 @@ impl Parser {
|
||||||
self.bump();
|
self.bump();
|
||||||
traits = self.parse_trait_ref_list(&token::LBRACE);
|
traits = self.parse_trait_ref_list(&token::LBRACE);
|
||||||
} else {
|
} else {
|
||||||
traits = ~[];
|
traits = Vec::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
let meths = self.parse_trait_methods();
|
let meths = self.parse_trait_methods();
|
||||||
|
@ -3925,7 +3924,7 @@ impl Parser {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut meths = ~[];
|
let mut meths = Vec::new();
|
||||||
self.expect(&token::LBRACE);
|
self.expect(&token::LBRACE);
|
||||||
let (inner_attrs, next) = self.parse_inner_attrs_and_next();
|
let (inner_attrs, next) = self.parse_inner_attrs_and_next();
|
||||||
let mut method_attrs = Some(next);
|
let mut method_attrs = Some(next);
|
||||||
|
@ -3948,7 +3947,7 @@ impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse B + C<~str,int> + D
|
// parse B + C<~str,int> + D
|
||||||
fn parse_trait_ref_list(&mut self, ket: &token::Token) -> ~[TraitRef] {
|
fn parse_trait_ref_list(&mut self, ket: &token::Token) -> Vec<TraitRef> {
|
||||||
self.parse_seq_to_before_end(
|
self.parse_seq_to_before_end(
|
||||||
ket,
|
ket,
|
||||||
seq_sep_trailing_disallowed(token::BINOP(token::PLUS)),
|
seq_sep_trailing_disallowed(token::BINOP(token::PLUS)),
|
||||||
|
@ -3961,13 +3960,13 @@ impl Parser {
|
||||||
let class_name = self.parse_ident();
|
let class_name = self.parse_ident();
|
||||||
let generics = self.parse_generics();
|
let generics = self.parse_generics();
|
||||||
|
|
||||||
let mut fields: ~[StructField];
|
let mut fields: Vec<StructField> ;
|
||||||
let is_tuple_like;
|
let is_tuple_like;
|
||||||
|
|
||||||
if self.eat(&token::LBRACE) {
|
if self.eat(&token::LBRACE) {
|
||||||
// It's a record-like struct.
|
// It's a record-like struct.
|
||||||
is_tuple_like = false;
|
is_tuple_like = false;
|
||||||
fields = ~[];
|
fields = Vec::new();
|
||||||
while self.token != token::RBRACE {
|
while self.token != token::RBRACE {
|
||||||
fields.push(self.parse_struct_decl_field());
|
fields.push(self.parse_struct_decl_field());
|
||||||
}
|
}
|
||||||
|
@ -3998,7 +3997,7 @@ impl Parser {
|
||||||
} else if self.eat(&token::SEMI) {
|
} else if self.eat(&token::SEMI) {
|
||||||
// It's a unit-like struct.
|
// It's a unit-like struct.
|
||||||
is_tuple_like = true;
|
is_tuple_like = true;
|
||||||
fields = ~[];
|
fields = Vec::new();
|
||||||
} else {
|
} else {
|
||||||
let token_str = self.this_token_to_str();
|
let token_str = self.this_token_to_str();
|
||||||
self.fatal(format!("expected `\\{`, `(`, or `;` after struct \
|
self.fatal(format!("expected `\\{`, `(`, or `;` after struct \
|
||||||
|
@ -4019,7 +4018,7 @@ impl Parser {
|
||||||
// parse a structure field declaration
|
// parse a structure field declaration
|
||||||
pub fn parse_single_struct_field(&mut self,
|
pub fn parse_single_struct_field(&mut self,
|
||||||
vis: Visibility,
|
vis: Visibility,
|
||||||
attrs: ~[Attribute])
|
attrs: Vec<Attribute> )
|
||||||
-> StructField {
|
-> StructField {
|
||||||
let a_var = self.parse_name_and_ty(vis, attrs);
|
let a_var = self.parse_name_and_ty(vis, attrs);
|
||||||
match self.token {
|
match self.token {
|
||||||
|
@ -4064,7 +4063,7 @@ impl Parser {
|
||||||
// attributes (of length 0 or 1), parse all of the items in a module
|
// attributes (of length 0 or 1), parse all of the items in a module
|
||||||
fn parse_mod_items(&mut self,
|
fn parse_mod_items(&mut self,
|
||||||
term: token::Token,
|
term: token::Token,
|
||||||
first_item_attrs: ~[Attribute])
|
first_item_attrs: Vec<Attribute> )
|
||||||
-> Mod {
|
-> Mod {
|
||||||
// parse all of the items up to closing or an attribute.
|
// parse all of the items up to closing or an attribute.
|
||||||
// view items are legal here.
|
// view items are legal here.
|
||||||
|
@ -4074,7 +4073,7 @@ impl Parser {
|
||||||
items: starting_items,
|
items: starting_items,
|
||||||
..
|
..
|
||||||
} = self.parse_items_and_view_items(first_item_attrs, true, true);
|
} = self.parse_items_and_view_items(first_item_attrs, true, true);
|
||||||
let mut items: ~[@Item] = starting_items;
|
let mut items: Vec<@Item> = starting_items;
|
||||||
let attrs_remaining_len = attrs_remaining.len();
|
let attrs_remaining_len = attrs_remaining.len();
|
||||||
|
|
||||||
// don't think this other loop is even necessary....
|
// don't think this other loop is even necessary....
|
||||||
|
@ -4162,7 +4161,7 @@ impl Parser {
|
||||||
id: ast::Ident,
|
id: ast::Ident,
|
||||||
outer_attrs: &[ast::Attribute],
|
outer_attrs: &[ast::Attribute],
|
||||||
id_sp: Span)
|
id_sp: Span)
|
||||||
-> (ast::Item_, ~[ast::Attribute]) {
|
-> (ast::Item_, Vec<ast::Attribute> ) {
|
||||||
let mut prefix = Path::new(self.sess.cm.span_to_filename(self.span));
|
let mut prefix = Path::new(self.sess.cm.span_to_filename(self.span));
|
||||||
prefix.pop();
|
prefix.pop();
|
||||||
let mod_path = Path::new(".").join_many(self.mod_path_stack);
|
let mod_path = Path::new(".").join_many(self.mod_path_stack);
|
||||||
|
@ -4201,8 +4200,8 @@ impl Parser {
|
||||||
|
|
||||||
fn eval_src_mod_from_path(&mut self,
|
fn eval_src_mod_from_path(&mut self,
|
||||||
path: Path,
|
path: Path,
|
||||||
outer_attrs: ~[ast::Attribute],
|
outer_attrs: Vec<ast::Attribute> ,
|
||||||
id_sp: Span) -> (ast::Item_, ~[ast::Attribute]) {
|
id_sp: Span) -> (ast::Item_, Vec<ast::Attribute> ) {
|
||||||
{
|
{
|
||||||
let mut included_mod_stack = self.sess
|
let mut included_mod_stack = self.sess
|
||||||
.included_mod_stack
|
.included_mod_stack
|
||||||
|
@ -4232,7 +4231,7 @@ impl Parser {
|
||||||
&path,
|
&path,
|
||||||
id_sp);
|
id_sp);
|
||||||
let (inner, next) = p0.parse_inner_attrs_and_next();
|
let (inner, next) = p0.parse_inner_attrs_and_next();
|
||||||
let mod_attrs = vec::append(outer_attrs, inner);
|
let mod_attrs = vec_ng::append(outer_attrs, inner);
|
||||||
let first_item_outer_attrs = next;
|
let first_item_outer_attrs = next;
|
||||||
let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs);
|
let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs);
|
||||||
{
|
{
|
||||||
|
@ -4246,7 +4245,7 @@ impl Parser {
|
||||||
|
|
||||||
// parse a function declaration from a foreign module
|
// parse a function declaration from a foreign module
|
||||||
fn parse_item_foreign_fn(&mut self, vis: ast::Visibility,
|
fn parse_item_foreign_fn(&mut self, vis: ast::Visibility,
|
||||||
attrs: ~[Attribute]) -> @ForeignItem {
|
attrs: Vec<Attribute> ) -> @ForeignItem {
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
|
|
||||||
// Parse obsolete purity.
|
// Parse obsolete purity.
|
||||||
|
@ -4269,7 +4268,7 @@ impl Parser {
|
||||||
|
|
||||||
// parse a static item from a foreign module
|
// parse a static item from a foreign module
|
||||||
fn parse_item_foreign_static(&mut self, vis: ast::Visibility,
|
fn parse_item_foreign_static(&mut self, vis: ast::Visibility,
|
||||||
attrs: ~[Attribute]) -> @ForeignItem {
|
attrs: Vec<Attribute> ) -> @ForeignItem {
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
|
|
||||||
self.expect_keyword(keywords::Static);
|
self.expect_keyword(keywords::Static);
|
||||||
|
@ -4303,7 +4302,7 @@ impl Parser {
|
||||||
// parse_foreign_items.
|
// parse_foreign_items.
|
||||||
fn parse_foreign_mod_items(&mut self,
|
fn parse_foreign_mod_items(&mut self,
|
||||||
abis: AbiSet,
|
abis: AbiSet,
|
||||||
first_item_attrs: ~[Attribute])
|
first_item_attrs: Vec<Attribute> )
|
||||||
-> ForeignMod {
|
-> ForeignMod {
|
||||||
let ParsedItemsAndViewItems {
|
let ParsedItemsAndViewItems {
|
||||||
attrs_remaining: attrs_remaining,
|
attrs_remaining: attrs_remaining,
|
||||||
|
@ -4332,7 +4331,7 @@ impl Parser {
|
||||||
fn parse_item_extern_crate(&mut self,
|
fn parse_item_extern_crate(&mut self,
|
||||||
lo: BytePos,
|
lo: BytePos,
|
||||||
visibility: Visibility,
|
visibility: Visibility,
|
||||||
attrs: ~[Attribute])
|
attrs: Vec<Attribute> )
|
||||||
-> ItemOrViewItem {
|
-> ItemOrViewItem {
|
||||||
|
|
||||||
let (maybe_path, ident) = match self.token {
|
let (maybe_path, ident) = match self.token {
|
||||||
|
@ -4377,7 +4376,7 @@ impl Parser {
|
||||||
lo: BytePos,
|
lo: BytePos,
|
||||||
opt_abis: Option<AbiSet>,
|
opt_abis: Option<AbiSet>,
|
||||||
visibility: Visibility,
|
visibility: Visibility,
|
||||||
attrs: ~[Attribute])
|
attrs: Vec<Attribute> )
|
||||||
-> ItemOrViewItem {
|
-> ItemOrViewItem {
|
||||||
|
|
||||||
self.expect(&token::LBRACE);
|
self.expect(&token::LBRACE);
|
||||||
|
@ -4410,7 +4409,7 @@ impl Parser {
|
||||||
// parse a structure-like enum variant definition
|
// parse a structure-like enum variant definition
|
||||||
// this should probably be renamed or refactored...
|
// this should probably be renamed or refactored...
|
||||||
fn parse_struct_def(&mut self) -> @StructDef {
|
fn parse_struct_def(&mut self) -> @StructDef {
|
||||||
let mut fields: ~[StructField] = ~[];
|
let mut fields: Vec<StructField> = Vec::new();
|
||||||
while self.token != token::RBRACE {
|
while self.token != token::RBRACE {
|
||||||
fields.push(self.parse_struct_decl_field());
|
fields.push(self.parse_struct_decl_field());
|
||||||
}
|
}
|
||||||
|
@ -4424,7 +4423,7 @@ impl Parser {
|
||||||
|
|
||||||
// parse the part of an "enum" decl following the '{'
|
// parse the part of an "enum" decl following the '{'
|
||||||
fn parse_enum_def(&mut self, _generics: &ast::Generics) -> EnumDef {
|
fn parse_enum_def(&mut self, _generics: &ast::Generics) -> EnumDef {
|
||||||
let mut variants = ~[];
|
let mut variants = Vec::new();
|
||||||
let mut all_nullary = true;
|
let mut all_nullary = true;
|
||||||
let mut have_disr = false;
|
let mut have_disr = false;
|
||||||
while self.token != token::RBRACE {
|
while self.token != token::RBRACE {
|
||||||
|
@ -4435,7 +4434,7 @@ impl Parser {
|
||||||
|
|
||||||
let ident;
|
let ident;
|
||||||
let kind;
|
let kind;
|
||||||
let mut args = ~[];
|
let mut args = Vec::new();
|
||||||
let mut disr_expr = None;
|
let mut disr_expr = None;
|
||||||
ident = self.parse_ident();
|
ident = self.parse_ident();
|
||||||
if self.eat(&token::LBRACE) {
|
if self.eat(&token::LBRACE) {
|
||||||
|
@ -4462,7 +4461,7 @@ impl Parser {
|
||||||
disr_expr = Some(self.parse_expr());
|
disr_expr = Some(self.parse_expr());
|
||||||
kind = TupleVariantKind(args);
|
kind = TupleVariantKind(args);
|
||||||
} else {
|
} else {
|
||||||
kind = TupleVariantKind(~[]);
|
kind = TupleVariantKind(Vec::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
let vr = ast::Variant_ {
|
let vr = ast::Variant_ {
|
||||||
|
@ -4551,13 +4550,13 @@ impl Parser {
|
||||||
// NB: this function no longer parses the items inside an
|
// NB: this function no longer parses the items inside an
|
||||||
// extern crate.
|
// extern crate.
|
||||||
fn parse_item_or_view_item(&mut self,
|
fn parse_item_or_view_item(&mut self,
|
||||||
attrs: ~[Attribute],
|
attrs: Vec<Attribute> ,
|
||||||
macros_allowed: bool)
|
macros_allowed: bool)
|
||||||
-> ItemOrViewItem {
|
-> ItemOrViewItem {
|
||||||
match self.token {
|
match self.token {
|
||||||
INTERPOLATED(token::NtItem(item)) => {
|
INTERPOLATED(token::NtItem(item)) => {
|
||||||
self.bump();
|
self.bump();
|
||||||
let new_attrs = vec::append(attrs, item.attrs);
|
let new_attrs = vec_ng::append(attrs, item.attrs);
|
||||||
return IoviItem(@Item {
|
return IoviItem(@Item {
|
||||||
attrs: new_attrs,
|
attrs: new_attrs,
|
||||||
..(*item).clone()
|
..(*item).clone()
|
||||||
|
@ -4732,7 +4731,7 @@ impl Parser {
|
||||||
|
|
||||||
// parse a foreign item; on failure, return IoviNone.
|
// parse a foreign item; on failure, return IoviNone.
|
||||||
fn parse_foreign_item(&mut self,
|
fn parse_foreign_item(&mut self,
|
||||||
attrs: ~[Attribute],
|
attrs: Vec<Attribute> ,
|
||||||
macros_allowed: bool)
|
macros_allowed: bool)
|
||||||
-> ItemOrViewItem {
|
-> ItemOrViewItem {
|
||||||
maybe_whole!(iovi self, NtItem);
|
maybe_whole!(iovi self, NtItem);
|
||||||
|
@ -4756,7 +4755,7 @@ impl Parser {
|
||||||
// this is the fall-through for parsing items.
|
// this is the fall-through for parsing items.
|
||||||
fn parse_macro_use_or_failure(
|
fn parse_macro_use_or_failure(
|
||||||
&mut self,
|
&mut self,
|
||||||
attrs: ~[Attribute],
|
attrs: Vec<Attribute> ,
|
||||||
macros_allowed: bool,
|
macros_allowed: bool,
|
||||||
lo: BytePos,
|
lo: BytePos,
|
||||||
visibility: Visibility
|
visibility: Visibility
|
||||||
|
@ -4820,7 +4819,7 @@ impl Parser {
|
||||||
return IoviNone(attrs);
|
return IoviNone(attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_item(&mut self, attrs: ~[Attribute]) -> Option<@Item> {
|
pub fn parse_item(&mut self, attrs: Vec<Attribute> ) -> Option<@Item> {
|
||||||
match self.parse_item_or_view_item(attrs, true) {
|
match self.parse_item_or_view_item(attrs, true) {
|
||||||
IoviNone(_) => None,
|
IoviNone(_) => None,
|
||||||
IoviViewItem(_) =>
|
IoviViewItem(_) =>
|
||||||
|
@ -4854,20 +4853,20 @@ impl Parser {
|
||||||
let path = ast::Path {
|
let path = ast::Path {
|
||||||
span: mk_sp(lo, self.span.hi),
|
span: mk_sp(lo, self.span.hi),
|
||||||
global: false,
|
global: false,
|
||||||
segments: ~[]
|
segments: Vec::new()
|
||||||
};
|
};
|
||||||
return @spanned(lo, self.span.hi,
|
return @spanned(lo, self.span.hi,
|
||||||
ViewPathList(path, idents, ast::DUMMY_NODE_ID));
|
ViewPathList(path, idents, ast::DUMMY_NODE_ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
let first_ident = self.parse_ident();
|
let first_ident = self.parse_ident();
|
||||||
let mut path = ~[first_ident];
|
let mut path = vec!(first_ident);
|
||||||
match self.token {
|
match self.token {
|
||||||
token::EQ => {
|
token::EQ => {
|
||||||
// x = foo::bar
|
// x = foo::bar
|
||||||
self.bump();
|
self.bump();
|
||||||
let path_lo = self.span.lo;
|
let path_lo = self.span.lo;
|
||||||
path = ~[self.parse_ident()];
|
path = vec!(self.parse_ident());
|
||||||
while self.token == token::MOD_SEP {
|
while self.token == token::MOD_SEP {
|
||||||
self.bump();
|
self.bump();
|
||||||
let id = self.parse_ident();
|
let id = self.parse_ident();
|
||||||
|
@ -4965,8 +4964,8 @@ impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
// matches view_paths = view_path | view_path , view_paths
|
// matches view_paths = view_path | view_path , view_paths
|
||||||
fn parse_view_paths(&mut self) -> ~[@ViewPath] {
|
fn parse_view_paths(&mut self) -> Vec<@ViewPath> {
|
||||||
let mut vp = ~[self.parse_view_path()];
|
let mut vp = vec!(self.parse_view_path());
|
||||||
while self.token == token::COMMA {
|
while self.token == token::COMMA {
|
||||||
self.bump();
|
self.bump();
|
||||||
self.obsolete(self.last_span, ObsoleteMultipleImport);
|
self.obsolete(self.last_span, ObsoleteMultipleImport);
|
||||||
|
@ -4980,15 +4979,15 @@ impl Parser {
|
||||||
// - mod_items uses extern_mod_allowed = true
|
// - mod_items uses extern_mod_allowed = true
|
||||||
// - block_tail_ uses extern_mod_allowed = false
|
// - block_tail_ uses extern_mod_allowed = false
|
||||||
fn parse_items_and_view_items(&mut self,
|
fn parse_items_and_view_items(&mut self,
|
||||||
first_item_attrs: ~[Attribute],
|
first_item_attrs: Vec<Attribute> ,
|
||||||
mut extern_mod_allowed: bool,
|
mut extern_mod_allowed: bool,
|
||||||
macros_allowed: bool)
|
macros_allowed: bool)
|
||||||
-> ParsedItemsAndViewItems {
|
-> ParsedItemsAndViewItems {
|
||||||
let mut attrs = vec::append(first_item_attrs,
|
let mut attrs = vec_ng::append(first_item_attrs,
|
||||||
self.parse_outer_attributes());
|
self.parse_outer_attributes());
|
||||||
// First, parse view items.
|
// First, parse view items.
|
||||||
let mut view_items : ~[ast::ViewItem] = ~[];
|
let mut view_items : Vec<ast::ViewItem> = Vec::new();
|
||||||
let mut items = ~[];
|
let mut items = Vec::new();
|
||||||
|
|
||||||
// I think this code would probably read better as a single
|
// I think this code would probably read better as a single
|
||||||
// loop with a mutable three-state-variable (for extern crates,
|
// loop with a mutable three-state-variable (for extern crates,
|
||||||
|
@ -5001,7 +5000,7 @@ impl Parser {
|
||||||
attrs_remaining: attrs,
|
attrs_remaining: attrs,
|
||||||
view_items: view_items,
|
view_items: view_items,
|
||||||
items: items,
|
items: items,
|
||||||
foreign_items: ~[]
|
foreign_items: Vec::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IoviViewItem(view_item) => {
|
IoviViewItem(view_item) => {
|
||||||
|
@ -5056,18 +5055,18 @@ impl Parser {
|
||||||
attrs_remaining: attrs,
|
attrs_remaining: attrs,
|
||||||
view_items: view_items,
|
view_items: view_items,
|
||||||
items: items,
|
items: items,
|
||||||
foreign_items: ~[]
|
foreign_items: Vec::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parses a sequence of foreign items. Stops when it finds program
|
// Parses a sequence of foreign items. Stops when it finds program
|
||||||
// text that can't be parsed as an item
|
// text that can't be parsed as an item
|
||||||
fn parse_foreign_items(&mut self, first_item_attrs: ~[Attribute],
|
fn parse_foreign_items(&mut self, first_item_attrs: Vec<Attribute> ,
|
||||||
macros_allowed: bool)
|
macros_allowed: bool)
|
||||||
-> ParsedItemsAndViewItems {
|
-> ParsedItemsAndViewItems {
|
||||||
let mut attrs = vec::append(first_item_attrs,
|
let mut attrs = vec_ng::append(first_item_attrs,
|
||||||
self.parse_outer_attributes());
|
self.parse_outer_attributes());
|
||||||
let mut foreign_items = ~[];
|
let mut foreign_items = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
match self.parse_foreign_item(attrs, macros_allowed) {
|
match self.parse_foreign_item(attrs, macros_allowed) {
|
||||||
IoviNone(returned_attrs) => {
|
IoviNone(returned_attrs) => {
|
||||||
|
@ -5095,8 +5094,8 @@ impl Parser {
|
||||||
|
|
||||||
ParsedItemsAndViewItems {
|
ParsedItemsAndViewItems {
|
||||||
attrs_remaining: attrs,
|
attrs_remaining: attrs,
|
||||||
view_items: ~[],
|
view_items: Vec::new(),
|
||||||
items: ~[],
|
items: Vec::new(),
|
||||||
foreign_items: foreign_items
|
foreign_items: foreign_items
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ pub enum Nonterminal {
|
||||||
NtAttr(@ast::Attribute), // #[foo]
|
NtAttr(@ast::Attribute), // #[foo]
|
||||||
NtPath(~ast::Path),
|
NtPath(~ast::Path),
|
||||||
NtTT( @ast::TokenTree), // needs @ed to break a circularity
|
NtTT( @ast::TokenTree), // needs @ed to break a circularity
|
||||||
NtMatchers(~[ast::Matcher])
|
NtMatchers(Vec<ast::Matcher> )
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for Nonterminal {
|
impl fmt::Show for Nonterminal {
|
||||||
|
@ -412,11 +412,11 @@ macro_rules! declare_special_idents_and_keywords {(
|
||||||
// The indices here must correspond to the numbers in
|
// The indices here must correspond to the numbers in
|
||||||
// special_idents, in Keyword to_ident(), and in static
|
// special_idents, in Keyword to_ident(), and in static
|
||||||
// constants below.
|
// constants below.
|
||||||
let init_vec = ~[
|
let init_vec = vec!(
|
||||||
$( $si_str, )*
|
$( $si_str, )*
|
||||||
$( $sk_str, )*
|
$( $sk_str, )*
|
||||||
$( $rk_str, )*
|
$( $rk_str, )*
|
||||||
];
|
);
|
||||||
|
|
||||||
interner::StrInterner::prefill(init_vec)
|
interner::StrInterner::prefill(init_vec)
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ pub fn tok_str(t: Token) -> ~str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn buf_str(toks: ~[Token], szs: ~[int], left: uint, right: uint,
|
pub fn buf_str(toks: Vec<Token> , szs: Vec<int> , left: uint, right: uint,
|
||||||
lim: uint) -> ~str {
|
lim: uint) -> ~str {
|
||||||
let n = toks.len();
|
let n = toks.len();
|
||||||
assert_eq!(n, szs.len());
|
assert_eq!(n, szs.len());
|
||||||
|
@ -156,9 +156,9 @@ pub fn mk_printer(out: ~io::Writer, linewidth: uint) -> Printer {
|
||||||
// fall behind.
|
// fall behind.
|
||||||
let n: uint = 3 * linewidth;
|
let n: uint = 3 * linewidth;
|
||||||
debug!("mk_printer {}", linewidth);
|
debug!("mk_printer {}", linewidth);
|
||||||
let token: ~[Token] = vec::from_elem(n, Eof);
|
let token: Vec<Token> = vec::from_elem(n, Eof);
|
||||||
let size: ~[int] = vec::from_elem(n, 0);
|
let size: Vec<int> = vec::from_elem(n, 0);
|
||||||
let scan_stack: ~[uint] = vec::from_elem(n, 0u);
|
let scan_stack: Vec<uint> = vec::from_elem(n, 0u);
|
||||||
Printer {
|
Printer {
|
||||||
out: out,
|
out: out,
|
||||||
buf_len: n,
|
buf_len: n,
|
||||||
|
@ -174,7 +174,7 @@ pub fn mk_printer(out: ~io::Writer, linewidth: uint) -> Printer {
|
||||||
scan_stack_empty: true,
|
scan_stack_empty: true,
|
||||||
top: 0,
|
top: 0,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
print_stack: ~[],
|
print_stack: Vec::new(),
|
||||||
pending_indentation: 0
|
pending_indentation: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,8 +264,8 @@ pub struct Printer {
|
||||||
space: int, // number of spaces left on line
|
space: int, // number of spaces left on line
|
||||||
left: uint, // index of left side of input stream
|
left: uint, // index of left side of input stream
|
||||||
right: uint, // index of right side of input stream
|
right: uint, // index of right side of input stream
|
||||||
token: ~[Token], // ring-buffr stream goes through
|
token: Vec<Token> , // ring-buffr stream goes through
|
||||||
size: ~[int], // ring-buffer of calculated sizes
|
size: Vec<int> , // ring-buffer of calculated sizes
|
||||||
left_total: int, // running size of stream "...left"
|
left_total: int, // running size of stream "...left"
|
||||||
right_total: int, // running size of stream "...right"
|
right_total: int, // running size of stream "...right"
|
||||||
// pseudo-stack, really a ring too. Holds the
|
// pseudo-stack, really a ring too. Holds the
|
||||||
|
@ -274,12 +274,12 @@ pub struct Printer {
|
||||||
// Begin (if there is any) on top of it. Stuff is flushed off the
|
// 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
|
// bottom as it becomes irrelevant due to the primary ring-buffer
|
||||||
// advancing.
|
// advancing.
|
||||||
scan_stack: ~[uint],
|
scan_stack: Vec<uint> ,
|
||||||
scan_stack_empty: bool, // top==bottom disambiguator
|
scan_stack_empty: bool, // top==bottom disambiguator
|
||||||
top: uint, // index of top of scan_stack
|
top: uint, // index of top of scan_stack
|
||||||
bottom: uint, // index of bottom of scan_stack
|
bottom: uint, // index of bottom of scan_stack
|
||||||
// stack of blocks-in-progress being flushed by print
|
// stack of blocks-in-progress being flushed by print
|
||||||
print_stack: ~[PrintStackElem],
|
print_stack: Vec<PrintStackElem> ,
|
||||||
// buffered indentation to avoid writing trailing whitespace
|
// buffered indentation to avoid writing trailing whitespace
|
||||||
pending_indentation: int,
|
pending_indentation: int,
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,10 +60,10 @@ pub struct State<'a> {
|
||||||
s: pp::Printer,
|
s: pp::Printer,
|
||||||
cm: Option<@CodeMap>,
|
cm: Option<@CodeMap>,
|
||||||
intr: @token::IdentInterner,
|
intr: @token::IdentInterner,
|
||||||
comments: Option<~[comments::Comment]>,
|
comments: Option<Vec<comments::Comment> >,
|
||||||
literals: Option<~[comments::Literal]>,
|
literals: Option<Vec<comments::Literal> >,
|
||||||
cur_cmnt_and_lit: CurrentCommentAndLiteral,
|
cur_cmnt_and_lit: CurrentCommentAndLiteral,
|
||||||
boxes: RefCell<~[pp::Breaks]>,
|
boxes: RefCell<Vec<pp::Breaks> >,
|
||||||
ann: &'a PpAnn
|
ann: &'a PpAnn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ pub fn rust_printer_annotated<'a>(writer: ~io::Writer, ann: &'a PpAnn) -> State<
|
||||||
cur_cmnt: 0,
|
cur_cmnt: 0,
|
||||||
cur_lit: 0
|
cur_lit: 0
|
||||||
},
|
},
|
||||||
boxes: RefCell::new(~[]),
|
boxes: RefCell::new(Vec::new()),
|
||||||
ann: ann
|
ann: ann
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ pub fn print_crate(cm: @CodeMap,
|
||||||
cur_cmnt: 0,
|
cur_cmnt: 0,
|
||||||
cur_lit: 0
|
cur_lit: 0
|
||||||
},
|
},
|
||||||
boxes: RefCell::new(~[]),
|
boxes: RefCell::new(Vec::new()),
|
||||||
ann: ann
|
ann: ann
|
||||||
};
|
};
|
||||||
print_crate_(&mut s, krate)
|
print_crate_(&mut s, krate)
|
||||||
|
@ -1981,7 +1981,7 @@ pub fn print_generics(s: &mut State,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ints = ~[];
|
let mut ints = Vec::new();
|
||||||
for i in range(0u, total) {
|
for i in range(0u, total) {
|
||||||
ints.push(i);
|
ints.push(i);
|
||||||
}
|
}
|
||||||
|
@ -2540,7 +2540,7 @@ mod test {
|
||||||
let abba_ident = token::str_to_ident("abba");
|
let abba_ident = token::str_to_ident("abba");
|
||||||
|
|
||||||
let decl = ast::FnDecl {
|
let decl = ast::FnDecl {
|
||||||
inputs: ~[],
|
inputs: Vec::new(),
|
||||||
output: ast::P(ast::Ty {id: 0,
|
output: ast::P(ast::Ty {id: 0,
|
||||||
node: ast::TyNil,
|
node: ast::TyNil,
|
||||||
span: codemap::DUMMY_SP}),
|
span: codemap::DUMMY_SP}),
|
||||||
|
@ -2559,9 +2559,9 @@ mod test {
|
||||||
|
|
||||||
let var = codemap::respan(codemap::DUMMY_SP, ast::Variant_ {
|
let var = codemap::respan(codemap::DUMMY_SP, ast::Variant_ {
|
||||||
name: ident,
|
name: ident,
|
||||||
attrs: ~[],
|
attrs: Vec::new(),
|
||||||
// making this up as I go.... ?
|
// making this up as I go.... ?
|
||||||
kind: ast::TupleVariantKind(~[]),
|
kind: ast::TupleVariantKind(Vec::new()),
|
||||||
id: 0,
|
id: 0,
|
||||||
disr_expr: None,
|
disr_expr: None,
|
||||||
vis: ast::Public,
|
vis: ast::Public,
|
||||||
|
|
|
@ -24,7 +24,7 @@ use std::rc::Rc;
|
||||||
|
|
||||||
pub struct Interner<T> {
|
pub struct Interner<T> {
|
||||||
priv map: RefCell<HashMap<T, Name>>,
|
priv map: RefCell<HashMap<T, Name>>,
|
||||||
priv vect: RefCell<~[T]>,
|
priv vect: RefCell<Vec<T> >,
|
||||||
}
|
}
|
||||||
|
|
||||||
// when traits can extend traits, we should extend index<Name,T> to get []
|
// when traits can extend traits, we should extend index<Name,T> to get []
|
||||||
|
@ -32,7 +32,7 @@ impl<T:Eq + Hash + Freeze + Clone + 'static> Interner<T> {
|
||||||
pub fn new() -> Interner<T> {
|
pub fn new() -> Interner<T> {
|
||||||
Interner {
|
Interner {
|
||||||
map: RefCell::new(HashMap::new()),
|
map: RefCell::new(HashMap::new()),
|
||||||
vect: RefCell::new(~[]),
|
vect: RefCell::new(Vec::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ impl RcStr {
|
||||||
// &str rather than RcStr, resulting in less allocation.
|
// &str rather than RcStr, resulting in less allocation.
|
||||||
pub struct StrInterner {
|
pub struct StrInterner {
|
||||||
priv map: RefCell<HashMap<RcStr, Name>>,
|
priv map: RefCell<HashMap<RcStr, Name>>,
|
||||||
priv vect: RefCell<~[RcStr]>,
|
priv vect: RefCell<Vec<RcStr> >,
|
||||||
}
|
}
|
||||||
|
|
||||||
// when traits can extend traits, we should extend index<Name,T> to get []
|
// when traits can extend traits, we should extend index<Name,T> to get []
|
||||||
|
@ -142,7 +142,7 @@ impl StrInterner {
|
||||||
pub fn new() -> StrInterner {
|
pub fn new() -> StrInterner {
|
||||||
StrInterner {
|
StrInterner {
|
||||||
map: RefCell::new(HashMap::new()),
|
map: RefCell::new(HashMap::new()),
|
||||||
vect: RefCell::new(~[]),
|
vect: RefCell::new(Vec::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,20 +17,20 @@ use parse::token;
|
||||||
|
|
||||||
// map a string to tts, using a made-up filename: return both the TokenTree's
|
// map a string to tts, using a made-up filename: return both the TokenTree's
|
||||||
// and the ParseSess
|
// and the ParseSess
|
||||||
pub fn string_to_tts_and_sess (source_str : ~str) -> (~[ast::TokenTree], @ParseSess) {
|
pub fn string_to_tts_and_sess (source_str : ~str) -> (Vec<ast::TokenTree> , @ParseSess) {
|
||||||
let ps = new_parse_sess();
|
let ps = new_parse_sess();
|
||||||
(filemap_to_tts(ps,string_to_filemap(ps,source_str,~"bogofile")),ps)
|
(filemap_to_tts(ps,string_to_filemap(ps,source_str,~"bogofile")),ps)
|
||||||
}
|
}
|
||||||
|
|
||||||
// map a string to tts, using a made-up filename:
|
// map a string to tts, using a made-up filename:
|
||||||
pub fn string_to_tts(source_str : ~str) -> ~[ast::TokenTree] {
|
pub fn string_to_tts(source_str : ~str) -> Vec<ast::TokenTree> {
|
||||||
let (tts,_) = string_to_tts_and_sess(source_str);
|
let (tts,_) = string_to_tts_and_sess(source_str);
|
||||||
tts
|
tts
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn string_to_parser_and_sess(source_str: ~str) -> (Parser,@ParseSess) {
|
pub fn string_to_parser_and_sess(source_str: ~str) -> (Parser,@ParseSess) {
|
||||||
let ps = new_parse_sess();
|
let ps = new_parse_sess();
|
||||||
(new_parser_from_source_str(ps,~[],~"bogofile",source_str),ps)
|
(new_parser_from_source_str(ps,Vec::new(),~"bogofile",source_str),ps)
|
||||||
}
|
}
|
||||||
|
|
||||||
// map string to parser (via tts)
|
// map string to parser (via tts)
|
||||||
|
@ -69,14 +69,14 @@ pub fn string_to_expr (source_str : ~str) -> @ast::Expr {
|
||||||
// parse a string, return an item
|
// 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| {
|
with_error_checking_parse(source_str, |p| {
|
||||||
p.parse_item(~[])
|
p.parse_item(Vec::new())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse a string, return a stmt
|
// parse a string, return a stmt
|
||||||
pub fn string_to_stmt(source_str : ~str) -> @ast::Stmt {
|
pub fn string_to_stmt(source_str : ~str) -> @ast::Stmt {
|
||||||
with_error_checking_parse(source_str, |p| {
|
with_error_checking_parse(source_str, |p| {
|
||||||
p.parse_stmt(~[])
|
p.parse_stmt(Vec::new())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ pub fn string_to_pat(source_str : ~str) -> @ast::Pat {
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert a vector of strings to a vector of ast::Ident's
|
// convert a vector of strings to a vector of ast::Ident's
|
||||||
pub fn strs_to_idents(ids: ~[&str]) -> ~[ast::Ident] {
|
pub fn strs_to_idents(ids: Vec<&str> ) -> Vec<ast::Ident> {
|
||||||
ids.map(|u| token::str_to_ident(*u))
|
ids.map(|u| token::str_to_ident(*u))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ use std::vec;
|
||||||
pub enum SmallVector<T> {
|
pub enum SmallVector<T> {
|
||||||
priv Zero,
|
priv Zero,
|
||||||
priv One(T),
|
priv One(T),
|
||||||
priv Many(~[T]),
|
priv Many(Vec<T> ),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Container for SmallVector<T> {
|
impl<T> Container for SmallVector<T> {
|
||||||
|
@ -46,7 +46,7 @@ impl<T> SmallVector<T> {
|
||||||
One(v)
|
One(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn many(vs: ~[T]) -> SmallVector<T> {
|
pub fn many(vs: Vec<T> ) -> SmallVector<T> {
|
||||||
Many(vs)
|
Many(vs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ impl<T> SmallVector<T> {
|
||||||
One(..) => {
|
One(..) => {
|
||||||
let one = mem::replace(self, Zero);
|
let one = mem::replace(self, Zero);
|
||||||
match one {
|
match one {
|
||||||
One(v1) => mem::replace(self, Many(~[v1, v])),
|
One(v1) => mem::replace(self, Many(vec!(v1, v))),
|
||||||
_ => unreachable!()
|
_ => unreachable!()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ mod test {
|
||||||
assert_eq!(0, v.len());
|
assert_eq!(0, v.len());
|
||||||
|
|
||||||
assert_eq!(1, SmallVector::one(1).len());
|
assert_eq!(1, SmallVector::one(1).len());
|
||||||
assert_eq!(5, SmallVector::many(~[1, 2, 3, 4, 5]).len());
|
assert_eq!(5, SmallVector::many(vec!(1, 2, 3, 4, 5)).len());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -161,7 +161,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_iterator() {
|
fn test_from_iterator() {
|
||||||
let v: SmallVector<int> = (~[1, 2, 3]).move_iter().collect();
|
let v: SmallVector<int> = (vec!(1, 2, 3)).move_iter().collect();
|
||||||
assert_eq!(3, v.len());
|
assert_eq!(3, v.len());
|
||||||
assert_eq!(&1, v.get(0));
|
assert_eq!(&1, v.get(0));
|
||||||
assert_eq!(&2, v.get(1));
|
assert_eq!(&2, v.get(1));
|
||||||
|
@ -171,14 +171,14 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_move_iter() {
|
fn test_move_iter() {
|
||||||
let v = SmallVector::zero();
|
let v = SmallVector::zero();
|
||||||
let v: ~[int] = v.move_iter().collect();
|
let v: Vec<int> = v.move_iter().collect();
|
||||||
assert_eq!(~[], v);
|
assert_eq!(Vec::new(), v);
|
||||||
|
|
||||||
let v = SmallVector::one(1);
|
let v = SmallVector::one(1);
|
||||||
assert_eq!(~[1], v.move_iter().collect());
|
assert_eq!(vec!(1), v.move_iter().collect());
|
||||||
|
|
||||||
let v = SmallVector::many(~[1, 2, 3]);
|
let v = SmallVector::many(vec!(1, 2, 3));
|
||||||
assert_eq!(~[1, 2, 3], v.move_iter().collect());
|
assert_eq!(vec!(1, 2, 3), v.move_iter().collect());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -190,12 +190,12 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn test_expect_one_many() {
|
fn test_expect_one_many() {
|
||||||
SmallVector::many(~[1, 2]).expect_one("");
|
SmallVector::many(vec!(1, 2)).expect_one("");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_expect_one_one() {
|
fn test_expect_one_one() {
|
||||||
assert_eq!(1, SmallVector::one(1).expect_one(""));
|
assert_eq!(1, SmallVector::one(1).expect_one(""));
|
||||||
assert_eq!(1, SmallVector::many(~[1]).expect_one(""));
|
assert_eq!(1, SmallVector::many(vec!(1)).expect_one(""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue