From 85950a801f7a30e962feb85bb3cc358aa2b82562 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 6 Mar 2018 10:03:15 +0100 Subject: [PATCH] Move #[css(iterable)] on fields rather than variants --- components/style/counter_style/mod.rs | 3 +- components/style/media_queries.rs | 3 +- components/style/properties/helpers.mako.rs | 18 ++++---- components/style/stylesheets/document_rule.rs | 4 +- .../stylesheets/font_feature_values_rule.rs | 3 +- .../style/stylesheets/keyframes_rule.rs | 4 +- components/style/values/specified/box.rs | 4 +- components/style/values/specified/counters.rs | 3 +- components/style/values/specified/font.rs | 12 +++--- components/style_derive/to_css.rs | 41 ++++++++----------- 10 files changed, 44 insertions(+), 51 deletions(-) diff --git a/components/style/counter_style/mod.rs b/components/style/counter_style/mod.rs index 397598d45a7..e727e004ebd 100644 --- a/components/style/counter_style/mod.rs +++ b/components/style/counter_style/mod.rs @@ -547,9 +547,8 @@ impl Parse for Fallback { /// #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] -#[css(iterable)] #[derive(Clone, Debug, Eq, PartialEq, ToComputedValue, ToCss)] -pub struct Symbols(pub Vec); +pub struct Symbols(#[css(iterable)] pub Vec); impl Parse for Symbols { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { diff --git a/components/style/media_queries.rs b/components/style/media_queries.rs index e6fb4614762..0232916fc28 100644 --- a/components/style/media_queries.rs +++ b/components/style/media_queries.rs @@ -25,10 +25,11 @@ pub use gecko::media_queries::{Device, Expression}; /// A type that encapsulates a media query list. #[cfg_attr(feature = "servo", derive(MallocSizeOf))] -#[css(comma, iterable)] +#[css(comma)] #[derive(Clone, Debug, ToCss)] pub struct MediaList { /// The list of media queries. + #[css(iterable)] pub media_queries: Vec, } diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 6e6c15d981f..1be21cd377c 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -126,9 +126,7 @@ % endif % if not allow_empty: % if separator == "Comma": - #[css(comma, iterable)] - % else: - #[css(iterable)] + #[css(comma)] % endif #[derive(ToCss)] % endif @@ -136,6 +134,9 @@ % if allow_empty and allow_empty != "NotInitial": pub Vec, % else: + % if not allow_empty: + #[css(iterable)] + % endif pub SmallVec<[single_value::T; 1]>, % endif ); @@ -189,13 +190,16 @@ #[derive(Clone, Debug, MallocSizeOf, PartialEq)] % if not allow_empty: % if separator == "Comma": - #[css(comma, iterable)] - % else: - #[css(iterable)] + #[css(comma)] % endif #[derive(ToCss)] % endif - pub struct SpecifiedValue(pub Vec); + pub struct SpecifiedValue( + % if not allow_empty: + #[css(iterable)] + % endif + pub Vec, + ); % if allow_empty: impl ToCss for SpecifiedValue { diff --git a/components/style/stylesheets/document_rule.rs b/components/style/stylesheets/document_rule.rs index 104f13ec710..8c9a3e21ee6 100644 --- a/components/style/stylesheets/document_rule.rs +++ b/components/style/stylesheets/document_rule.rs @@ -176,9 +176,9 @@ impl UrlMatchingFunction { /// The `@document` rule's condition is written as a comma-separated list of /// URL matching functions, and the condition evaluates to true whenever any /// one of those functions evaluates to true. -#[css(comma, iterable)] +#[css(comma)] #[derive(Clone, Debug, ToCss)] -pub struct DocumentCondition(Vec); +pub struct DocumentCondition(#[css(iterable)] Vec); impl DocumentCondition { /// Parse a document condition. diff --git a/components/style/stylesheets/font_feature_values_rule.rs b/components/style/stylesheets/font_feature_values_rule.rs index f27ac9b6d3d..eb799793f79 100644 --- a/components/style/stylesheets/font_feature_values_rule.rs +++ b/components/style/stylesheets/font_feature_values_rule.rs @@ -118,9 +118,8 @@ impl ToGeckoFontFeatureValues for PairValues { } /// A @font-feature-values block declaration value that keeps a list of values. -#[css(iterable)] #[derive(Clone, Debug, PartialEq, ToCss)] -pub struct VectorValues(pub Vec); +pub struct VectorValues(#[css(iterable)] pub Vec); impl Parse for VectorValues { fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) diff --git a/components/style/stylesheets/keyframes_rule.rs b/components/style/stylesheets/keyframes_rule.rs index aeb9265c549..266d953cd99 100644 --- a/components/style/stylesheets/keyframes_rule.rs +++ b/components/style/stylesheets/keyframes_rule.rs @@ -145,9 +145,9 @@ impl KeyframePercentage { /// A keyframes selector is a list of percentages or from/to symbols, which are /// converted at parse time to percentages. -#[css(comma, iterable)] +#[css(comma)] #[derive(Clone, Debug, Eq, PartialEq, ToCss)] -pub struct KeyframeSelector(Vec); +pub struct KeyframeSelector(#[css(iterable)] Vec); impl KeyframeSelector { /// Return the list of percentages this selector contains. diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index 731b0ee18d6..973708561bc 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -369,9 +369,9 @@ pub enum OverflowClipBox { pub enum WillChange { /// Expresses no particular intent Auto, - #[css(comma, iterable)] /// - AnimateableFeatures(Box<[CustomIdent]>), + #[css(comma)] + AnimateableFeatures(#[css(iterable)] Box<[CustomIdent]>), } impl WillChange { diff --git a/components/style/values/specified/counters.rs b/components/style/values/specified/counters.rs index 9460f3965cf..3252001f142 100644 --- a/components/style/values/specified/counters.rs +++ b/components/style/values/specified/counters.rs @@ -92,8 +92,7 @@ pub enum Content { #[cfg(feature = "gecko")] MozAltContent, /// Content items. - #[css(iterable)] - Items(Box<[ContentItem]>), + Items(#[css(iterable)] Box<[ContentItem]>), } /// Items for the `content` property. diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index 8b2cf9737b9..7d442b49126 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -152,8 +152,8 @@ impl From for FontSize { #[derive(Clone, Debug, Eq, Hash, PartialEq, ToCss)] pub enum FontFamily { /// List of `font-family` - #[css(iterable, comma)] - Values(FontFamilyList), + #[css(comma)] + Values(#[css(iterable)] FontFamilyList), /// System font System(SystemFont), } @@ -718,11 +718,11 @@ pub enum VariantAlternates { #[css(function)] Stylistic(CustomIdent), /// Enables display with stylistic sets - #[css(comma, function, iterable)] - Styleset(Box<[CustomIdent]>), + #[css(comma, function)] + Styleset(#[css(iterable)] Box<[CustomIdent]>), /// Enables display of specific character variants - #[css(comma, function, iterable)] - CharacterVariant(Box<[CustomIdent]>), + #[css(comma, function)] + CharacterVariant(#[css(iterable)] Box<[CustomIdent]>), /// Enables display of swash glyphs #[css(function)] Swash(CustomIdent), diff --git a/components/style_derive/to_css.rs b/components/style_derive/to_css.rs index a3018943aac..8f0e182ef67 100644 --- a/components/style_derive/to_css.rs +++ b/components/style_derive/to_css.rs @@ -4,7 +4,7 @@ use cg::{self, WhereClause}; use darling::util::Override; -use quote::Tokens; +use quote::{ToTokens, Tokens}; use syn::{self, Data}; use synstructure::{Structure, VariantInfo}; @@ -18,7 +18,6 @@ pub fn derive(input: syn::DeriveInput) -> Tokens { if let Data::Enum(_) = input.data { assert!(input_attrs.function.is_none(), "#[css(function)] is not allowed on enums"); assert!(!input_attrs.comma, "#[css(comma)] is not allowed on enums"); - assert!(!input_attrs.iterable, "#[css(iterable)] is not allowed on enums"); } let s = Structure::new(&input); @@ -86,30 +85,24 @@ fn derive_variant_arm( } } else if !bindings.is_empty() { let mut expr = quote! {}; - if variant_attrs.iterable { - assert_eq!(bindings.len(), 1); - let binding = &bindings[0]; - expr = quote! { - #expr - - for item in #binding.iter() { - writer.item(&item)?; - } - }; - } else { - for binding in bindings { - let attrs = cg::parse_field_attrs::(&binding.ast()); - if attrs.skip { - continue; + for binding in bindings { + let attrs = cg::parse_field_attrs::(&binding.ast()); + if attrs.skip { + continue; + } + let variant_expr = if attrs.iterable { + quote! { + for item in #binding.iter() { + writer.item(&item)?; + } } + } else { if !attrs.ignore_bound { where_clause.add_trait_bound(&binding.ast().ty); } - expr = quote! { - #expr - writer.item(#binding)?; - }; - } + quote!{ writer.item(#binding)?; } + }; + variant_expr.to_tokens(&mut expr) } quote! {{ @@ -148,15 +141,12 @@ struct CssInputAttrs { function: Option>, // Here because structs variants are also their whole type definition. comma: bool, - // Here because structs variants are also their whole type definition. - iterable: bool, } #[darling(attributes(css), default)] #[derive(Default, FromVariant)] pub struct CssVariantAttrs { pub function: Option>, - pub iterable: bool, pub comma: bool, pub dimension: bool, pub keyword: Option, @@ -167,5 +157,6 @@ pub struct CssVariantAttrs { #[derive(Default, FromField)] struct CssFieldAttrs { ignore_bound: bool, + iterable: bool, skip: bool, }