syntax: Move the AST from @T to Gc<T>
This commit is contained in:
@@ -21,15 +21,16 @@ use std::fmt;
|
||||
use std::fmt::Show;
|
||||
use std::option::Option;
|
||||
use std::rc::Rc;
|
||||
use std::gc::Gc;
|
||||
use serialize::{Encodable, Decodable, Encoder, Decoder};
|
||||
|
||||
/// A pointer abstraction. FIXME(eddyb) #10676 use Rc<T> in the future.
|
||||
pub type P<T> = @T;
|
||||
pub type P<T> = Gc<T>;
|
||||
|
||||
#[allow(non_snake_case_functions)]
|
||||
/// Construct a P<T> from a T value.
|
||||
pub fn P<T: 'static>(value: T) -> P<T> {
|
||||
@value
|
||||
box(GC) value
|
||||
}
|
||||
|
||||
// FIXME #6993: in librustc, uses of "ident" should be replaced
|
||||
@@ -217,7 +218,7 @@ pub enum DefRegion {
|
||||
|
||||
// The set of MetaItems that define the compilation environment of the crate,
|
||||
// used to drive conditional compilation
|
||||
pub type CrateConfig = Vec<@MetaItem> ;
|
||||
pub type CrateConfig = Vec<Gc<MetaItem>>;
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub struct Crate {
|
||||
@@ -232,7 +233,7 @@ pub type MetaItem = Spanned<MetaItem_>;
|
||||
#[deriving(Clone, Encodable, Decodable, Eq, Hash)]
|
||||
pub enum MetaItem_ {
|
||||
MetaWord(InternedString),
|
||||
MetaList(InternedString, Vec<@MetaItem> ),
|
||||
MetaList(InternedString, Vec<Gc<MetaItem>>),
|
||||
MetaNameValue(InternedString, Lit),
|
||||
}
|
||||
|
||||
@@ -264,8 +265,8 @@ impl PartialEq for MetaItem_ {
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub struct Block {
|
||||
pub view_items: Vec<ViewItem>,
|
||||
pub stmts: Vec<@Stmt>,
|
||||
pub expr: Option<@Expr>,
|
||||
pub stmts: Vec<Gc<Stmt>>,
|
||||
pub expr: Option<Gc<Expr>>,
|
||||
pub id: NodeId,
|
||||
pub rules: BlockCheckMode,
|
||||
pub span: Span,
|
||||
@@ -281,7 +282,7 @@ pub struct Pat {
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub struct FieldPat {
|
||||
pub ident: Ident,
|
||||
pub pat: @Pat,
|
||||
pub pat: Gc<Pat>,
|
||||
}
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
@@ -301,18 +302,18 @@ pub enum Pat_ {
|
||||
// which it is. The resolver determines this, and
|
||||
// records this pattern's NodeId in an auxiliary
|
||||
// set (of "pat_idents that refer to nullary enums")
|
||||
PatIdent(BindingMode, Path, Option<@Pat>),
|
||||
PatEnum(Path, Option<Vec<@Pat> >), /* "none" means a * pattern where
|
||||
PatIdent(BindingMode, Path, Option<Gc<Pat>>),
|
||||
PatEnum(Path, Option<Vec<Gc<Pat>>>), /* "none" means a * pattern where
|
||||
* we don't bind the fields to names */
|
||||
PatStruct(Path, Vec<FieldPat> , bool),
|
||||
PatTup(Vec<@Pat> ),
|
||||
PatBox(@Pat),
|
||||
PatRegion(@Pat), // reference pattern
|
||||
PatLit(@Expr),
|
||||
PatRange(@Expr, @Expr),
|
||||
PatStruct(Path, Vec<FieldPat>, bool),
|
||||
PatTup(Vec<Gc<Pat>>),
|
||||
PatBox(Gc<Pat>),
|
||||
PatRegion(Gc<Pat>), // reference pattern
|
||||
PatLit(Gc<Expr>),
|
||||
PatRange(Gc<Expr>, Gc<Expr>),
|
||||
// [a, b, ..i, y, z] is represented as
|
||||
// PatVec(~[a, b], Some(i), ~[y, z])
|
||||
PatVec(Vec<@Pat> , Option<@Pat>, Vec<@Pat> ),
|
||||
PatVec(Vec<Gc<Pat>>, Option<Gc<Pat>>, Vec<Gc<Pat>>),
|
||||
PatMac(Mac),
|
||||
}
|
||||
|
||||
@@ -365,13 +366,13 @@ pub type Stmt = Spanned<Stmt_>;
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub enum Stmt_ {
|
||||
// could be an item or a local (let) binding:
|
||||
StmtDecl(@Decl, NodeId),
|
||||
StmtDecl(Gc<Decl>, NodeId),
|
||||
|
||||
// expr without trailing semi-colon (must have unit type):
|
||||
StmtExpr(@Expr, NodeId),
|
||||
StmtExpr(Gc<Expr>, NodeId),
|
||||
|
||||
// expr with trailing semi-colon (may have any type):
|
||||
StmtSemi(@Expr, NodeId),
|
||||
StmtSemi(Gc<Expr>, NodeId),
|
||||
|
||||
// bool: is there a trailing sem-colon?
|
||||
StmtMac(Mac, bool),
|
||||
@@ -391,8 +392,8 @@ pub enum LocalSource {
|
||||
#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub struct Local {
|
||||
pub ty: P<Ty>,
|
||||
pub pat: @Pat,
|
||||
pub init: Option<@Expr>,
|
||||
pub pat: Gc<Pat>,
|
||||
pub init: Option<Gc<Expr>>,
|
||||
pub id: NodeId,
|
||||
pub span: Span,
|
||||
pub source: LocalSource,
|
||||
@@ -403,23 +404,23 @@ pub type Decl = Spanned<Decl_>;
|
||||
#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub enum Decl_ {
|
||||
// a local (let) binding:
|
||||
DeclLocal(@Local),
|
||||
DeclLocal(Gc<Local>),
|
||||
// an item binding:
|
||||
DeclItem(@Item),
|
||||
DeclItem(Gc<Item>),
|
||||
}
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub struct Arm {
|
||||
pub attrs: Vec<Attribute>,
|
||||
pub pats: Vec<@Pat>,
|
||||
pub guard: Option<@Expr>,
|
||||
pub body: @Expr,
|
||||
pub pats: Vec<Gc<Pat>>,
|
||||
pub guard: Option<Gc<Expr>>,
|
||||
pub body: Gc<Expr>,
|
||||
}
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub struct Field {
|
||||
pub ident: SpannedIdent,
|
||||
pub expr: @Expr,
|
||||
pub expr: Gc<Expr>,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
@@ -446,56 +447,56 @@ pub struct Expr {
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub enum Expr_ {
|
||||
ExprVstore(@Expr, ExprVstore),
|
||||
ExprVstore(Gc<Expr>, ExprVstore),
|
||||
// First expr is the place; second expr is the value.
|
||||
ExprBox(@Expr, @Expr),
|
||||
ExprVec(Vec<@Expr>),
|
||||
ExprCall(@Expr, Vec<@Expr>),
|
||||
ExprMethodCall(SpannedIdent, Vec<P<Ty>>, Vec<@Expr>),
|
||||
ExprTup(Vec<@Expr>),
|
||||
ExprBinary(BinOp, @Expr, @Expr),
|
||||
ExprUnary(UnOp, @Expr),
|
||||
ExprLit(@Lit),
|
||||
ExprCast(@Expr, P<Ty>),
|
||||
ExprIf(@Expr, P<Block>, Option<@Expr>),
|
||||
ExprWhile(@Expr, P<Block>),
|
||||
ExprBox(Gc<Expr>, Gc<Expr>),
|
||||
ExprVec(Vec<Gc<Expr>>),
|
||||
ExprCall(Gc<Expr>, Vec<Gc<Expr>>),
|
||||
ExprMethodCall(SpannedIdent, Vec<P<Ty>>, Vec<Gc<Expr>>),
|
||||
ExprTup(Vec<Gc<Expr>>),
|
||||
ExprBinary(BinOp, Gc<Expr>, Gc<Expr>),
|
||||
ExprUnary(UnOp, Gc<Expr>),
|
||||
ExprLit(Gc<Lit>),
|
||||
ExprCast(Gc<Expr>, P<Ty>),
|
||||
ExprIf(Gc<Expr>, P<Block>, Option<Gc<Expr>>),
|
||||
ExprWhile(Gc<Expr>, P<Block>),
|
||||
// FIXME #6993: change to Option<Name>
|
||||
ExprForLoop(@Pat, @Expr, P<Block>, Option<Ident>),
|
||||
ExprForLoop(Gc<Pat>, Gc<Expr>, P<Block>, Option<Ident>),
|
||||
// Conditionless loop (can be exited with break, cont, or ret)
|
||||
// FIXME #6993: change to Option<Name>
|
||||
ExprLoop(P<Block>, Option<Ident>),
|
||||
ExprMatch(@Expr, Vec<Arm>),
|
||||
ExprMatch(Gc<Expr>, Vec<Arm>),
|
||||
ExprFnBlock(P<FnDecl>, P<Block>),
|
||||
ExprProc(P<FnDecl>, P<Block>),
|
||||
ExprBlock(P<Block>),
|
||||
|
||||
ExprAssign(@Expr, @Expr),
|
||||
ExprAssignOp(BinOp, @Expr, @Expr),
|
||||
ExprField(@Expr, Ident, Vec<P<Ty>>),
|
||||
ExprIndex(@Expr, @Expr),
|
||||
ExprAssign(Gc<Expr>, Gc<Expr>),
|
||||
ExprAssignOp(BinOp, Gc<Expr>, Gc<Expr>),
|
||||
ExprField(Gc<Expr>, Ident, Vec<P<Ty>>),
|
||||
ExprIndex(Gc<Expr>, Gc<Expr>),
|
||||
|
||||
/// Expression that looks like a "name". For example,
|
||||
/// `std::slice::from_elem::<uint>` is an ExprPath that's the "name" part
|
||||
/// of a function call.
|
||||
ExprPath(Path),
|
||||
|
||||
ExprAddrOf(Mutability, @Expr),
|
||||
ExprAddrOf(Mutability, Gc<Expr>),
|
||||
ExprBreak(Option<Ident>),
|
||||
ExprAgain(Option<Ident>),
|
||||
ExprRet(Option<@Expr>),
|
||||
ExprRet(Option<Gc<Expr>>),
|
||||
|
||||
ExprInlineAsm(InlineAsm),
|
||||
|
||||
ExprMac(Mac),
|
||||
|
||||
// A struct literal expression.
|
||||
ExprStruct(Path, Vec<Field> , Option<@Expr> /* base */),
|
||||
ExprStruct(Path, Vec<Field> , Option<Gc<Expr>> /* base */),
|
||||
|
||||
// A vector literal constructed from one repeated element.
|
||||
ExprRepeat(@Expr /* element */, @Expr /* count */),
|
||||
ExprRepeat(Gc<Expr> /* element */, Gc<Expr> /* count */),
|
||||
|
||||
// No-op: used solely so we can pretty-print faithfully
|
||||
ExprParen(@Expr)
|
||||
ExprParen(Gc<Expr>)
|
||||
}
|
||||
|
||||
// When the main rust parser encounters a syntax-extension invocation, it
|
||||
@@ -667,7 +668,7 @@ pub struct TypeMethod {
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub enum TraitMethod {
|
||||
Required(TypeMethod),
|
||||
Provided(@Method),
|
||||
Provided(Gc<Method>),
|
||||
}
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
@@ -782,16 +783,16 @@ pub enum Ty_ {
|
||||
TyBox(P<Ty>),
|
||||
TyUniq(P<Ty>),
|
||||
TyVec(P<Ty>),
|
||||
TyFixedLengthVec(P<Ty>, @Expr),
|
||||
TyFixedLengthVec(P<Ty>, Gc<Expr>),
|
||||
TyPtr(MutTy),
|
||||
TyRptr(Option<Lifetime>, MutTy),
|
||||
TyClosure(@ClosureTy, Option<Lifetime>),
|
||||
TyProc(@ClosureTy),
|
||||
TyBareFn(@BareFnTy),
|
||||
TyUnboxedFn(@UnboxedFnTy),
|
||||
TyClosure(Gc<ClosureTy>, Option<Lifetime>),
|
||||
TyProc(Gc<ClosureTy>),
|
||||
TyBareFn(Gc<BareFnTy>),
|
||||
TyUnboxedFn(Gc<UnboxedFnTy>),
|
||||
TyTup(Vec<P<Ty>> ),
|
||||
TyPath(Path, Option<OwnedSlice<TyParamBound>>, NodeId), // for #7264; see above
|
||||
TyTypeof(@Expr),
|
||||
TyTypeof(Gc<Expr>),
|
||||
// TyInfer means the type should be inferred instead of it having been
|
||||
// specified. This can appear anywhere in a type.
|
||||
TyInfer,
|
||||
@@ -808,8 +809,8 @@ pub struct InlineAsm {
|
||||
pub asm: InternedString,
|
||||
pub asm_str_style: StrStyle,
|
||||
pub clobbers: InternedString,
|
||||
pub inputs: Vec<(InternedString, @Expr)>,
|
||||
pub outputs: Vec<(InternedString, @Expr)>,
|
||||
pub inputs: Vec<(InternedString, Gc<Expr>)>,
|
||||
pub outputs: Vec<(InternedString, Gc<Expr>)>,
|
||||
pub volatile: bool,
|
||||
pub alignstack: bool,
|
||||
pub dialect: AsmDialect
|
||||
@@ -818,7 +819,7 @@ pub struct InlineAsm {
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub struct Arg {
|
||||
pub ty: P<Ty>,
|
||||
pub pat: @Pat,
|
||||
pub pat: Gc<Pat>,
|
||||
pub id: NodeId,
|
||||
}
|
||||
|
||||
@@ -832,7 +833,7 @@ impl Arg {
|
||||
node: TyInfer,
|
||||
span: DUMMY_SP,
|
||||
}),
|
||||
pat: @Pat {
|
||||
pat: box(GC) Pat {
|
||||
id: DUMMY_NODE_ID,
|
||||
node: PatIdent(BindByValue(mutability), path, None),
|
||||
span: span
|
||||
@@ -903,14 +904,14 @@ pub struct Mod {
|
||||
/// to the last token in the external file.
|
||||
pub inner: Span,
|
||||
pub view_items: Vec<ViewItem>,
|
||||
pub items: Vec<@Item>,
|
||||
pub items: Vec<Gc<Item>>,
|
||||
}
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub struct ForeignMod {
|
||||
pub abi: Abi,
|
||||
pub view_items: Vec<ViewItem>,
|
||||
pub items: Vec<@ForeignItem>,
|
||||
pub items: Vec<Gc<ForeignItem>>,
|
||||
}
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
@@ -922,7 +923,7 @@ pub struct VariantArg {
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub enum VariantKind {
|
||||
TupleVariantKind(Vec<VariantArg>),
|
||||
StructVariantKind(@StructDef),
|
||||
StructVariantKind(Gc<StructDef>),
|
||||
}
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
@@ -936,7 +937,7 @@ pub struct Variant_ {
|
||||
pub attrs: Vec<Attribute>,
|
||||
pub kind: VariantKind,
|
||||
pub id: NodeId,
|
||||
pub disr_expr: Option<@Expr>,
|
||||
pub disr_expr: Option<Gc<Expr>>,
|
||||
pub vis: Visibility,
|
||||
}
|
||||
|
||||
@@ -984,7 +985,7 @@ pub enum ViewItem_ {
|
||||
// (containing arbitrary characters) from which to fetch the crate sources
|
||||
// For example, extern crate whatever = "github.com/mozilla/rust"
|
||||
ViewItemExternCrate(Ident, Option<(InternedString,StrStyle)>, NodeId),
|
||||
ViewItemUse(@ViewPath),
|
||||
ViewItemUse(Gc<ViewPath>),
|
||||
}
|
||||
|
||||
// Meta-data associated with an item
|
||||
@@ -1007,7 +1008,7 @@ pub struct AttrId(pub uint);
|
||||
pub struct Attribute_ {
|
||||
pub id: AttrId,
|
||||
pub style: AttrStyle,
|
||||
pub value: @MetaItem,
|
||||
pub value: Gc<MetaItem>,
|
||||
pub is_sugared_doc: bool,
|
||||
}
|
||||
|
||||
@@ -1105,18 +1106,18 @@ pub struct Item {
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub enum Item_ {
|
||||
ItemStatic(P<Ty>, Mutability, @Expr),
|
||||
ItemStatic(P<Ty>, Mutability, Gc<Expr>),
|
||||
ItemFn(P<FnDecl>, FnStyle, Abi, Generics, P<Block>),
|
||||
ItemMod(Mod),
|
||||
ItemForeignMod(ForeignMod),
|
||||
ItemTy(P<Ty>, Generics),
|
||||
ItemEnum(EnumDef, Generics),
|
||||
ItemStruct(@StructDef, Generics),
|
||||
ItemStruct(Gc<StructDef>, Generics),
|
||||
ItemTrait(Generics, Sized, Vec<TraitRef> , Vec<TraitMethod> ),
|
||||
ItemImpl(Generics,
|
||||
Option<TraitRef>, // (optional) trait this impl implements
|
||||
P<Ty>, // self
|
||||
Vec<@Method> ),
|
||||
Vec<Gc<Method>>),
|
||||
// a macro invocation (which includes macro definition)
|
||||
ItemMac(Mac),
|
||||
}
|
||||
@@ -1142,9 +1143,9 @@ pub enum ForeignItem_ {
|
||||
// that we trans.
|
||||
#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub enum InlinedItem {
|
||||
IIItem(@Item),
|
||||
IIMethod(DefId /* impl id */, bool /* is provided */, @Method),
|
||||
IIForeign(@ForeignItem),
|
||||
IIItem(Gc<Item>),
|
||||
IIMethod(DefId /* impl id */, bool /* is provided */, Gc<Method>),
|
||||
IIForeign(Gc<ForeignItem>),
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user