More aster driven cleanup
This commit is contained in:
parent
989c8ff809
commit
35eb234c41
@ -9,7 +9,7 @@ use syntax::ast::{
|
|||||||
EnumDef,
|
EnumDef,
|
||||||
};
|
};
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::codemap::{Span, respan};
|
use syntax::codemap::Span;
|
||||||
use syntax::ext::base::{ExtCtxt, ItemDecorator};
|
use syntax::ext::base::{ExtCtxt, ItemDecorator};
|
||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
use syntax::ext::deriving::generic::{
|
use syntax::ext::deriving::generic::{
|
||||||
@ -137,7 +137,6 @@ fn deserialize_substructure(
|
|||||||
StaticStruct(ref struct_def, ref fields) => {
|
StaticStruct(ref struct_def, ref fields) => {
|
||||||
deserialize_struct(
|
deserialize_struct(
|
||||||
cx,
|
cx,
|
||||||
span,
|
|
||||||
&builder,
|
&builder,
|
||||||
substr.type_ident,
|
substr.type_ident,
|
||||||
substr.type_ident,
|
substr.type_ident,
|
||||||
@ -206,7 +205,6 @@ fn deserialize_visitor(
|
|||||||
|
|
||||||
fn deserialize_struct(
|
fn deserialize_struct(
|
||||||
cx: &ExtCtxt,
|
cx: &ExtCtxt,
|
||||||
span: Span,
|
|
||||||
builder: &aster::AstBuilder,
|
builder: &aster::AstBuilder,
|
||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
struct_ident: Ident,
|
struct_ident: Ident,
|
||||||
@ -249,7 +247,6 @@ fn deserialize_struct(
|
|||||||
Named(ref fields) => {
|
Named(ref fields) => {
|
||||||
deserialize_struct_named_fields(
|
deserialize_struct_named_fields(
|
||||||
cx,
|
cx,
|
||||||
span,
|
|
||||||
builder,
|
builder,
|
||||||
struct_ident,
|
struct_ident,
|
||||||
struct_path,
|
struct_path,
|
||||||
@ -407,7 +404,6 @@ fn deserialize_seq(
|
|||||||
|
|
||||||
fn deserialize_struct_named_fields(
|
fn deserialize_struct_named_fields(
|
||||||
cx: &ExtCtxt,
|
cx: &ExtCtxt,
|
||||||
span: Span,
|
|
||||||
builder: &aster::AstBuilder,
|
builder: &aster::AstBuilder,
|
||||||
struct_ident: Ident,
|
struct_ident: Ident,
|
||||||
struct_path: ast::Path,
|
struct_path: ast::Path,
|
||||||
@ -429,7 +425,6 @@ fn deserialize_struct_named_fields(
|
|||||||
|
|
||||||
let field_visitor = deserialize_field_visitor(
|
let field_visitor = deserialize_field_visitor(
|
||||||
cx,
|
cx,
|
||||||
span,
|
|
||||||
builder,
|
builder,
|
||||||
&field_names,
|
&field_names,
|
||||||
fields,
|
fields,
|
||||||
@ -482,32 +477,18 @@ fn deserialize_struct_named_fields(
|
|||||||
|
|
||||||
fn deserialize_field_visitor(
|
fn deserialize_field_visitor(
|
||||||
cx: &ExtCtxt,
|
cx: &ExtCtxt,
|
||||||
span: Span,
|
builder: &aster::AstBuilder,
|
||||||
_builder: &aster::AstBuilder,
|
|
||||||
field_names: &[ast::Ident],
|
field_names: &[ast::Ident],
|
||||||
fields: &[(Ident, Span)],
|
fields: &[(Ident, Span)],
|
||||||
struct_def: &StructDef,
|
struct_def: &StructDef,
|
||||||
) -> Vec<P<ast::Item>> {
|
) -> Vec<P<ast::Item>> {
|
||||||
// Create the field names for the fields.
|
let field_enum = builder.item().enum_("__Field")
|
||||||
let field_variants: Vec<P<ast::Variant>> = field_names.iter()
|
.with_variants(
|
||||||
.map(|field| {
|
field_names.iter().map(|field| {
|
||||||
P(respan(
|
builder.variant(field).tuple().build()
|
||||||
span,
|
|
||||||
ast::Variant_ {
|
|
||||||
name: *field,
|
|
||||||
attrs: Vec::new(),
|
|
||||||
kind: ast::TupleVariantKind(Vec::new()),
|
|
||||||
id: ast::DUMMY_NODE_ID,
|
|
||||||
disr_expr: None,
|
|
||||||
vis: ast::Inherited,
|
|
||||||
}))
|
|
||||||
})
|
})
|
||||||
.collect();
|
)
|
||||||
|
.build();
|
||||||
let field_enum = cx.item_enum(
|
|
||||||
span,
|
|
||||||
token::str_to_ident("__Field"),
|
|
||||||
ast::EnumDef { variants: field_variants });
|
|
||||||
|
|
||||||
// Get aliases
|
// Get aliases
|
||||||
let aliases: Vec<Option<&ast::Lit>> = struct_def.fields.iter()
|
let aliases: Vec<Option<&ast::Lit>> = struct_def.fields.iter()
|
||||||
@ -679,15 +660,14 @@ fn deserialize_enum(
|
|||||||
// Match arms to extract a variant from a string
|
// Match arms to extract a variant from a string
|
||||||
let variant_arms: Vec<_> = fields.iter()
|
let variant_arms: Vec<_> = fields.iter()
|
||||||
.zip(enum_def.variants.iter())
|
.zip(enum_def.variants.iter())
|
||||||
.map(|(&(name, span, ref fields), variant)| {
|
.map(|(&(name, _, ref fields), variant)| {
|
||||||
let value = deserialize_enum_variant(
|
let value = deserialize_enum_variant(
|
||||||
cx,
|
cx,
|
||||||
span,
|
|
||||||
builder,
|
builder,
|
||||||
type_ident,
|
type_ident,
|
||||||
name,
|
name,
|
||||||
fields,
|
fields,
|
||||||
cx.expr_ident(span, cx.ident_of("visitor")),
|
builder.expr().id("visitor"),
|
||||||
variant,
|
variant,
|
||||||
visitor_item.clone(),
|
visitor_item.clone(),
|
||||||
visitor_ty.clone(),
|
visitor_ty.clone(),
|
||||||
@ -740,7 +720,6 @@ fn deserialize_enum(
|
|||||||
|
|
||||||
fn deserialize_enum_variant(
|
fn deserialize_enum_variant(
|
||||||
cx: &ExtCtxt,
|
cx: &ExtCtxt,
|
||||||
span: Span,
|
|
||||||
builder: &aster::AstBuilder,
|
builder: &aster::AstBuilder,
|
||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
variant_ident: Ident,
|
variant_ident: Ident,
|
||||||
@ -780,7 +759,6 @@ fn deserialize_enum_variant(
|
|||||||
Named(ref fields) => {
|
Named(ref fields) => {
|
||||||
deserialize_enum_variant_map(
|
deserialize_enum_variant_map(
|
||||||
cx,
|
cx,
|
||||||
span,
|
|
||||||
builder,
|
builder,
|
||||||
&*fields,
|
&*fields,
|
||||||
variant_path,
|
variant_path,
|
||||||
@ -846,7 +824,6 @@ fn deserialize_enum_variant_seq(
|
|||||||
|
|
||||||
fn deserialize_enum_variant_map(
|
fn deserialize_enum_variant_map(
|
||||||
cx: &ExtCtxt,
|
cx: &ExtCtxt,
|
||||||
span: Span,
|
|
||||||
builder: &aster::AstBuilder,
|
builder: &aster::AstBuilder,
|
||||||
fields: &[(Ident, Span)],
|
fields: &[(Ident, Span)],
|
||||||
variant_path: ast::Path,
|
variant_path: ast::Path,
|
||||||
@ -867,7 +844,6 @@ fn deserialize_enum_variant_map(
|
|||||||
|
|
||||||
let field_visitor = deserialize_field_visitor(
|
let field_visitor = deserialize_field_visitor(
|
||||||
cx,
|
cx,
|
||||||
span,
|
|
||||||
builder,
|
builder,
|
||||||
&field_names,
|
&field_names,
|
||||||
fields,
|
fields,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user