diff options
| author | John Clements <clements@racket-lang.org> | 2014-07-04 12:05:43 -0700 |
|---|---|---|
| committer | John Clements <clements@racket-lang.org> | 2014-07-04 12:05:43 -0700 |
| commit | f126eacd115415b0814ceb4a1c71380a0b2eb752 (patch) | |
| tree | fa104dfe2ced2a824de8a370e543dd94a1570418 /src/libsyntax | |
| parent | 4358bf8bfa1bfc853b51c29d48a2d57eb8dfee0a (diff) | |
| download | rust-f126eacd115415b0814ceb4a1c71380a0b2eb752.tar.gz rust-f126eacd115415b0814ceb4a1c71380a0b2eb752.zip | |
comments, whitespace, rename NameFinderContext to PatIdentFinder
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 18 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 34 |
2 files changed, 27 insertions, 25 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 237d0660a41..e2a74ba4dfc 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -453,10 +453,10 @@ pub enum Expr_ { ExprCast(Gc<Expr>, P<Ty>), ExprIf(Gc<Expr>, P<Block>, Option<Gc<Expr>>), ExprWhile(Gc<Expr>, P<Block>), - // FIXME #6993: change to Option<Name> + // FIXME #6993: change to Option<Name> ... or not, if these are hygienic. 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> + // FIXME #6993: change to Option<Name> ... or not, if these are hygienic. ExprLoop(P<Block>, Option<Ident>), ExprMatch(Gc<Expr>, Vec<Arm>), ExprFnBlock(P<FnDecl>, P<Block>), @@ -468,9 +468,8 @@ pub enum Expr_ { ExprField(Gc<Expr>, SpannedIdent, 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. + /// Variable reference, possibly containing `::` and/or + /// type parameters, e.g. foo::bar::<baz> ExprPath(Path), ExprAddrOf(Mutability, Gc<Expr>), @@ -643,6 +642,8 @@ pub struct TypeField { pub span: Span, } +/// Represents a required method in a trait declaration, +/// one without a default implementation #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)] pub struct TypeMethod { pub ident: Ident, @@ -656,6 +657,8 @@ pub struct TypeMethod { pub vis: Visibility, } +/// Represents a method declaration in a trait declaration, possibly +/// including a default implementation // A trait method is either required (meaning it doesn't have an // implementation, just a signature) or provided (meaning it has a default // implementation). @@ -741,6 +744,7 @@ impl fmt::Show for Onceness { } } +/// Represents the type of a closure #[deriving(PartialEq, Eq, Encodable, Decodable, Hash)] pub struct ClosureTy { pub lifetimes: Vec<Lifetime>, @@ -809,6 +813,7 @@ pub struct InlineAsm { pub dialect: AsmDialect } +/// represents an argument in a function header #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)] pub struct Arg { pub ty: P<Ty>, @@ -836,7 +841,7 @@ impl Arg { } } -// represents the header (not the body) of a function declaration +/// represents the header (not the body) of a function declaration #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)] pub struct FnDecl { pub inputs: Vec<Arg>, @@ -1107,6 +1112,7 @@ pub enum Item_ { ItemTy(P<Ty>, Generics), ItemEnum(EnumDef, Generics), ItemStruct(Gc<StructDef>, Generics), + /// Represents a Trait Declaration ItemTrait(Generics, Sized, Vec<TraitRef> , Vec<TraitMethod> ), ItemImpl(Generics, Option<TraitRef>, // (optional) trait this impl implements diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 253102ba5de..a4d32a1c020 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -267,7 +267,8 @@ fn expand_loop_block(loop_block: P<Block>, } } -// eval $e with a new exts frame: +// eval $e with a new exts frame. +// must be a macro so that $e isn't evaluated too early. macro_rules! with_exts_frame ( ($extsboxexpr:expr,$macros_escape:expr,$e:expr) => ({$extsboxexpr.push_frame(); @@ -609,7 +610,7 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander) } = **local; // expand the pat (it might contain macro uses): let expanded_pat = fld.fold_pat(pat); - // find the pat_idents in the pattern: + // find the PatIdents in the pattern: // oh dear heaven... this is going to include the enum // names, as well... but that should be okay, as long as // the new names are gensyms for the old ones. @@ -691,39 +692,34 @@ fn expand_arm(arm: &ast::Arm, fld: &mut MacroExpander) -> ast::Arm { -// a visitor that extracts the pat_ident (binding) paths -// from a given thingy and puts them in a mutable -// array +/// A visitor that extracts the PatIdent (binding) paths +/// from a given thingy and puts them in a mutable +/// array #[deriving(Clone)] -struct NameFinderContext { +struct PatIdentFinder { ident_accumulator: Vec<ast::Ident> , } -impl Visitor<()> for NameFinderContext { +impl Visitor<()> for PatIdentFinder { fn visit_pat(&mut self, pattern: &ast::Pat, _: ()) { match *pattern { - // we found a pat_ident! - ast::Pat { - id: _, - node: ast::PatIdent(_, ref path1, ref inner), - span: _ - } => { + ast::Pat { id: _, node: ast::PatIdent(_, ref path1, ref inner), span: _ } => { self.ident_accumulator.push(path1.node); - // visit optional subpattern of pat_ident: + // visit optional subpattern of PatIdent: for subpat in inner.iter() { self.visit_pat(&**subpat, ()) } } - // use the default traversal for non-pat_idents + // use the default traversal for non-PatIdents _ => visit::walk_pat(self, pattern, ()) } } } -// find the pat_ident paths in a pattern +/// find the PatIdent paths in a pattern fn pattern_bindings(pat : &ast::Pat) -> Vec<ast::Ident> { - let mut name_finder = NameFinderContext{ident_accumulator:Vec::new()}; + let mut name_finder = PatIdentFinder{ident_accumulator:Vec::new()}; name_finder.visit_pat(pat,()); name_finder.ident_accumulator } @@ -1028,7 +1024,7 @@ fn original_span(cx: &ExtCtxt) -> Gc<codemap::ExpnInfo> { #[cfg(test)] mod test { use super::{pattern_bindings, expand_crate, contains_macro_escape}; - use super::{NameFinderContext}; + use super::{PatIdentFinder}; use ast; use ast::{Attribute_, AttrOuter, MetaWord}; use attr; @@ -1167,7 +1163,7 @@ mod test { // find the pat_ident paths in a crate fn crate_bindings(the_crate : &ast::Crate) -> Vec<ast::Ident> { - let mut name_finder = NameFinderContext{ident_accumulator:Vec::new()}; + let mut name_finder = PatIdentFinder{ident_accumulator:Vec::new()}; visit::walk_crate(&mut name_finder, the_crate, ()); name_finder.ident_accumulator } |
