Use Names in hir::{Field, ExprMethodCall, ExprField}
This commit is contained in:
parent
a4af958786
commit
64fb709f99
19 changed files with 79 additions and 91 deletions
|
|
@ -721,9 +721,9 @@ pub fn noop_fold_struct_field<T: Folder>(f: StructField, fld: &mut T) -> StructF
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_field<T: Folder>(Field {ident, expr, span}: Field, folder: &mut T) -> Field {
|
||||
pub fn noop_fold_field<T: Folder>(Field {name, expr, span}: Field, folder: &mut T) -> Field {
|
||||
Field {
|
||||
ident: respan(ident.span, fold_ident(folder, ident.node)),
|
||||
name: respan(folder.new_span(name.span), folder.fold_name(name.node)),
|
||||
expr: folder.fold_expr(expr),
|
||||
span: folder.new_span(span)
|
||||
}
|
||||
|
|
@ -1050,9 +1050,9 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
|
|||
ExprCall(folder.fold_expr(f),
|
||||
args.move_map(|x| folder.fold_expr(x)))
|
||||
}
|
||||
ExprMethodCall(i, tps, args) => {
|
||||
ExprMethodCall(name, tps, args) => {
|
||||
ExprMethodCall(
|
||||
respan(folder.new_span(i.span), fold_ident(folder, i.node)),
|
||||
respan(folder.new_span(name.span), folder.fold_name(name.node)),
|
||||
tps.move_map(|x| folder.fold_ty(x)),
|
||||
args.move_map(|x| folder.fold_expr(x)))
|
||||
}
|
||||
|
|
@ -1102,10 +1102,10 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
|
|||
folder.fold_expr(el),
|
||||
folder.fold_expr(er))
|
||||
}
|
||||
ExprField(el, ident) => {
|
||||
ExprField(el, name) => {
|
||||
ExprField(folder.fold_expr(el),
|
||||
respan(folder.new_span(ident.span),
|
||||
fold_ident(folder, ident.node)))
|
||||
respan(folder.new_span(name.span),
|
||||
folder.fold_name(name.node)))
|
||||
}
|
||||
ExprTupField(el, ident) => {
|
||||
ExprTupField(folder.fold_expr(el),
|
||||
|
|
|
|||
|
|
@ -52,10 +52,6 @@ use util;
|
|||
use std::fmt;
|
||||
use serialize::{Encodable, Encoder, Decoder};
|
||||
|
||||
|
||||
/// Function name (not all functions have names)
|
||||
pub type FnIdent = Option<Ident>;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
|
||||
pub struct Lifetime {
|
||||
pub id: NodeId,
|
||||
|
|
@ -416,7 +412,7 @@ pub enum Pat_ {
|
|||
/// which it is. The resolver determines this, and
|
||||
/// records this pattern's NodeId in an auxiliary
|
||||
/// set (of "PatIdents that refer to nullary enums")
|
||||
PatIdent(BindingMode, SpannedIdent, Option<P<Pat>>),
|
||||
PatIdent(BindingMode, Spanned<Ident>, Option<P<Pat>>),
|
||||
|
||||
/// "None" means a * pattern where we don't bind the fields to names.
|
||||
PatEnum(Path, Option<Vec<P<Pat>>>),
|
||||
|
|
@ -564,13 +560,11 @@ pub struct Arm {
|
|||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct Field {
|
||||
pub ident: SpannedIdent,
|
||||
pub name: Spanned<Name>,
|
||||
pub expr: P<Expr>,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
pub type SpannedIdent = Spanned<Ident>;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||
pub enum BlockCheckMode {
|
||||
DefaultBlock,
|
||||
|
|
@ -612,7 +606,7 @@ pub enum Expr_ {
|
|||
ExprCall(P<Expr>, Vec<P<Expr>>),
|
||||
/// A method call (`x.foo::<Bar, Baz>(a, b, c, d)`)
|
||||
///
|
||||
/// The `SpannedIdent` is the identifier for the method name.
|
||||
/// The `Spanned<Name>` is the identifier for the method name.
|
||||
/// The vector of `Ty`s are the ascripted type parameters for the method
|
||||
/// (within the angle brackets).
|
||||
///
|
||||
|
|
@ -622,7 +616,7 @@ pub enum Expr_ {
|
|||
///
|
||||
/// Thus, `x.foo::<Bar, Baz>(a, b, c, d)` is represented as
|
||||
/// `ExprMethodCall(foo, [Bar, Baz], [x, a, b, c, d])`.
|
||||
ExprMethodCall(SpannedIdent, Vec<P<Ty>>, Vec<P<Expr>>),
|
||||
ExprMethodCall(Spanned<Name>, Vec<P<Ty>>, Vec<P<Expr>>),
|
||||
/// A tuple (`(a, b, c ,d)`)
|
||||
ExprTup(Vec<P<Expr>>),
|
||||
/// A binary operation (For example: `a + b`, `a * b`)
|
||||
|
|
@ -662,7 +656,7 @@ pub enum Expr_ {
|
|||
/// For example, `a += 1`.
|
||||
ExprAssignOp(BinOp, P<Expr>, P<Expr>),
|
||||
/// Access of a named struct field (`obj.foo`)
|
||||
ExprField(P<Expr>, SpannedIdent),
|
||||
ExprField(P<Expr>, Spanned<Name>),
|
||||
/// Access of an unnamed field of a struct or tuple-struct
|
||||
///
|
||||
/// For example, `foo.0`.
|
||||
|
|
@ -682,9 +676,9 @@ pub enum Expr_ {
|
|||
/// A referencing operation (`&a` or `&mut a`)
|
||||
ExprAddrOf(Mutability, P<Expr>),
|
||||
/// A `break`, with an optional label to break
|
||||
ExprBreak(Option<SpannedIdent>),
|
||||
ExprBreak(Option<Spanned<Ident>>),
|
||||
/// A `continue`, with an optional label
|
||||
ExprAgain(Option<SpannedIdent>),
|
||||
ExprAgain(Option<Spanned<Ident>>),
|
||||
/// A `return`, with an optional value to be returned
|
||||
ExprRet(Option<P<Expr>>),
|
||||
|
||||
|
|
@ -744,13 +738,6 @@ pub struct MutTy {
|
|||
pub mutbl: Mutability,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct TypeField {
|
||||
pub ident: Ident,
|
||||
pub mt: MutTy,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// Represents a method's signature in a trait declaration,
|
||||
/// or in an implementation.
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use hir;
|
|||
|
||||
use syntax::ast::*;
|
||||
use syntax::ptr::P;
|
||||
use syntax::codemap::Spanned;
|
||||
use syntax::codemap::{respan, Spanned};
|
||||
use syntax::owned_slice::OwnedSlice;
|
||||
|
||||
|
||||
|
|
@ -370,7 +370,10 @@ pub fn lower_struct_field(f: &StructField) -> hir::StructField {
|
|||
}
|
||||
|
||||
pub fn lower_field(f: &Field) -> hir::Field {
|
||||
hir::Field { ident: f.ident, expr: lower_expr(&f.expr), span: f.span }
|
||||
hir::Field {
|
||||
name: respan(f.ident.span, f.ident.node.name),
|
||||
expr: lower_expr(&f.expr), span: f.span
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lower_mt(mt: &MutTy) -> hir::MutTy {
|
||||
|
|
@ -704,7 +707,7 @@ pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
|
|||
}
|
||||
ExprMethodCall(i, ref tps, ref args) => {
|
||||
hir::ExprMethodCall(
|
||||
i,
|
||||
respan(i.span, i.node.name),
|
||||
tps.iter().map(|x| lower_ty(x)).collect(),
|
||||
args.iter().map(|x| lower_expr(x)).collect())
|
||||
}
|
||||
|
|
@ -755,7 +758,7 @@ pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
|
|||
lower_expr(er))
|
||||
}
|
||||
ExprField(ref el, ident) => {
|
||||
hir::ExprField(lower_expr(el), ident)
|
||||
hir::ExprField(lower_expr(el), respan(ident.span, ident.node.name))
|
||||
}
|
||||
ExprTupField(ref el, ident) => {
|
||||
hir::ExprTupField(lower_expr(el), ident)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub use self::AnnNode::*;
|
|||
use syntax::abi;
|
||||
use syntax::ast;
|
||||
use syntax::owned_slice::OwnedSlice;
|
||||
use syntax::codemap::{self, CodeMap, BytePos};
|
||||
use syntax::codemap::{self, CodeMap, BytePos, Spanned};
|
||||
use syntax::diagnostic;
|
||||
use syntax::parse::token::{self, BinOpToken};
|
||||
use syntax::parse::lexer::comments;
|
||||
|
|
@ -1223,7 +1223,7 @@ impl<'a> State<'a> {
|
|||
&fields[..],
|
||||
|s, field| {
|
||||
try!(s.ibox(indent_unit));
|
||||
try!(s.print_ident(field.ident.node));
|
||||
try!(s.print_name(field.name.node));
|
||||
try!(s.word_space(":"));
|
||||
try!(s.print_expr(&*field.expr));
|
||||
s.end()
|
||||
|
|
@ -1265,13 +1265,13 @@ impl<'a> State<'a> {
|
|||
}
|
||||
|
||||
fn print_expr_method_call(&mut self,
|
||||
ident: hir::SpannedIdent,
|
||||
name: Spanned<ast::Name>,
|
||||
tys: &[P<hir::Ty>],
|
||||
args: &[P<hir::Expr>]) -> io::Result<()> {
|
||||
let base_args = &args[1..];
|
||||
try!(self.print_expr(&*args[0]));
|
||||
try!(word(&mut self.s, "."));
|
||||
try!(self.print_ident(ident.node));
|
||||
try!(self.print_name(name.node));
|
||||
if !tys.is_empty() {
|
||||
try!(word(&mut self.s, "::<"));
|
||||
try!(self.commasep(Inconsistent, tys,
|
||||
|
|
@ -1329,8 +1329,8 @@ impl<'a> State<'a> {
|
|||
hir::ExprCall(ref func, ref args) => {
|
||||
try!(self.print_expr_call(&**func, &args[..]));
|
||||
}
|
||||
hir::ExprMethodCall(ident, ref tys, ref args) => {
|
||||
try!(self.print_expr_method_call(ident, &tys[..], &args[..]));
|
||||
hir::ExprMethodCall(name, ref tys, ref args) => {
|
||||
try!(self.print_expr_method_call(name, &tys[..], &args[..]));
|
||||
}
|
||||
hir::ExprBinary(op, ref lhs, ref rhs) => {
|
||||
try!(self.print_expr_binary(op, &**lhs, &**rhs));
|
||||
|
|
@ -1435,10 +1435,10 @@ impl<'a> State<'a> {
|
|||
try!(self.word_space("="));
|
||||
try!(self.print_expr(&**rhs));
|
||||
}
|
||||
hir::ExprField(ref expr, id) => {
|
||||
hir::ExprField(ref expr, name) => {
|
||||
try!(self.print_expr(&**expr));
|
||||
try!(word(&mut self.s, "."));
|
||||
try!(self.print_ident(id.node));
|
||||
try!(self.print_name(name.node));
|
||||
}
|
||||
hir::ExprTupField(ref expr, id) => {
|
||||
try!(self.print_expr(&**expr));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue