Alter the semantics of derived_from so that it is [] rather than None when the property is not derived.

This simplifies some logic in this patch and going forward. Note that the old code stored the
derived_from array as rust idents, but then used the parameter (not rust-ident-ified) to access
DERIVED_LONGHANDS. No other consumers actually seem to use the values in derived_from, so we
change the representation to the more natural thing.
This commit is contained in:
Bobby Holley 2016-04-14 20:16:56 -07:00
parent f39ec2b15e
commit 0fe55f01b5

View file

@ -84,10 +84,7 @@ class Longhand(object):
self.custom_cascade = custom_cascade self.custom_cascade = custom_cascade
self.internal = internal self.internal = internal
self.gecko_ffi_name = gecko_ffi_name or "m" + self.camel_case self.gecko_ffi_name = gecko_ffi_name or "m" + self.camel_case
if derived_from is None: self.derived_from = (derived_from or "").split()
self.derived_from = None
else:
self.derived_from = [ to_rust_ident(name) for name in derived_from ]
class Shorthand(object): class Shorthand(object):
def __init__(self, name, sub_properties, experimental=False, internal=False): def __init__(self, name, sub_properties, experimental=False, internal=False):
@ -185,9 +182,6 @@ pub mod longhands {
<% <%
if not CONFIG['product'] in products: if not CONFIG['product'] in products:
return "" return ""
if derived_from is not None:
derived_from = derived_from.split()
property = Longhand(name, property = Longhand(name,
derived_from=derived_from, derived_from=derived_from,
keyword=keyword, keyword=keyword,
@ -200,13 +194,12 @@ pub mod longhands {
LONGHANDS.append(property) LONGHANDS.append(property)
LONGHANDS_BY_NAME[name] = property LONGHANDS_BY_NAME[name] = property
if derived_from is not None: for derived in property.derived_from:
for name in derived_from: DERIVED_LONGHANDS.setdefault(derived, []).append(property)
DERIVED_LONGHANDS.setdefault(name, []).append(property)
%> %>
pub mod ${property.ident} { pub mod ${property.ident} {
#![allow(unused_imports)] #![allow(unused_imports)]
% if derived_from is None: % if not property.derived_from:
use cssparser::Parser; use cssparser::Parser;
use parser::ParserContext; use parser::ParserContext;
use properties::{CSSWideKeyword, DeclaredValue, Shorthand}; use properties::{CSSWideKeyword, DeclaredValue, Shorthand};
@ -238,7 +231,7 @@ pub mod longhands {
} }
_ => panic!("entered the wrong cascade_property() implementation"), _ => panic!("entered the wrong cascade_property() implementation"),
}; };
% if property.derived_from is None: % if not property.derived_from:
if seen.get_${property.ident}() { if seen.get_${property.ident}() {
return return
} }
@ -287,7 +280,7 @@ pub mod longhands {
// Do not allow stylesheets to set derived properties. // Do not allow stylesheets to set derived properties.
% endif % endif
} }
% if derived_from is None: % if not property.derived_from:
pub fn parse_declared(context: &ParserContext, input: &mut Parser) pub fn parse_declared(context: &ParserContext, input: &mut Parser)
-> Result<DeclaredValue<SpecifiedValue>, ()> { -> Result<DeclaredValue<SpecifiedValue>, ()> {
match input.try(CSSWideKeyword::parse) { match input.try(CSSWideKeyword::parse) {
@ -330,7 +323,7 @@ pub mod longhands {
experimental="${experimental}" internal="${internal}" experimental="${experimental}" internal="${internal}"
gecko_ffi_name="${gecko_ffi_name}"> gecko_ffi_name="${gecko_ffi_name}">
${caller.body()} ${caller.body()}
% if derived_from is None: % if not derived_from:
pub fn parse_specified(context: &ParserContext, input: &mut Parser) pub fn parse_specified(context: &ParserContext, input: &mut Parser)
-> Result<DeclaredValue<SpecifiedValue>, ()> { -> Result<DeclaredValue<SpecifiedValue>, ()> {
parse(context, input).map(DeclaredValue::Value) parse(context, input).map(DeclaredValue::Value)
@ -5803,7 +5796,7 @@ mod property_bit_field {
self.storage[bit / 32] |= 1 << (bit % 32) self.storage[bit / 32] |= 1 << (bit % 32)
} }
% for i, property in enumerate(LONGHANDS): % for i, property in enumerate(LONGHANDS):
% if property.derived_from is None: % if not property.derived_from:
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[inline] #[inline]
pub fn get_${property.ident}(&self) -> bool { pub fn get_${property.ident}(&self) -> bool {
@ -5820,7 +5813,7 @@ mod property_bit_field {
} }
% for property in LONGHANDS: % for property in LONGHANDS:
% if property.derived_from is None: % if not property.derived_from:
#[allow(non_snake_case)] #[allow(non_snake_case)]
fn substitute_variables_${property.ident}<F>( fn substitute_variables_${property.ident}<F>(
value: &DeclaredValue<longhands::${property.ident}::SpecifiedValue>, value: &DeclaredValue<longhands::${property.ident}::SpecifiedValue>,
@ -5991,7 +5984,7 @@ fn deduplicate_property_declarations(declarations: Vec<PropertyDeclaration>)
match declaration { match declaration {
% for property in LONGHANDS: % for property in LONGHANDS:
PropertyDeclaration::${property.camel_case}(..) => { PropertyDeclaration::${property.camel_case}(..) => {
% if property.derived_from is None: % if not property.derived_from:
if seen.get_${property.ident}() { if seen.get_${property.ident}() {
continue continue
} }
@ -6150,7 +6143,7 @@ impl PropertyDeclaration {
match *self { match *self {
% for property in LONGHANDS: % for property in LONGHANDS:
PropertyDeclaration::${property.camel_case}(..) => PropertyDeclaration::${property.camel_case}(..) =>
% if property.derived_from is None: % if not property.derived_from:
PropertyDeclarationName::Longhand("${property.name}"), PropertyDeclarationName::Longhand("${property.name}"),
% else: % else:
PropertyDeclarationName::Internal, PropertyDeclarationName::Internal,
@ -6166,7 +6159,7 @@ impl PropertyDeclaration {
match *self { match *self {
% for property in LONGHANDS: % for property in LONGHANDS:
PropertyDeclaration::${property.camel_case} PropertyDeclaration::${property.camel_case}
% if property.derived_from is None: % if not property.derived_from:
(ref value) => value.to_css_string(), (ref value) => value.to_css_string(),
% else: % else:
(_) => panic!("unsupported property declaration: ${property.name}"), (_) => panic!("unsupported property declaration: ${property.name}"),
@ -6215,7 +6208,7 @@ impl PropertyDeclaration {
match *self { match *self {
% for property in LONGHANDS: % for property in LONGHANDS:
PropertyDeclaration::${property.camel_case}(..) => PropertyDeclaration::${property.camel_case}(..) =>
% if property.derived_from is None: % if not property.derived_from:
name.eq_ignore_ascii_case("${property.name}"), name.eq_ignore_ascii_case("${property.name}"),
% else: % else:
false, false,
@ -6244,7 +6237,7 @@ impl PropertyDeclaration {
} }
match_ignore_ascii_case! { name, match_ignore_ascii_case! { name,
% for property in LONGHANDS: % for property in LONGHANDS:
% if property.derived_from is None: % if not property.derived_from:
"${property.name}" => { "${property.name}" => {
% if property.internal: % if property.internal:
if context.stylesheet_origin != Origin::UserAgent { if context.stylesheet_origin != Origin::UserAgent {
@ -6857,7 +6850,7 @@ fn cascade_with_cached_declarations<C: ComputedValues>(
match *declaration { match *declaration {
% for style_struct in active_style_structs(): % for style_struct in active_style_structs():
% for property in style_struct.longhands: % for property in style_struct.longhands:
% if property.derived_from is None: % if not property.derived_from:
PropertyDeclaration::${property.camel_case}(ref PropertyDeclaration::${property.camel_case}(ref
${'_' if not style_struct.inherited else ''}declared_value) ${'_' if not style_struct.inherited else ''}declared_value)
=> { => {
@ -7363,7 +7356,7 @@ macro_rules! css_properties_accessors {
($macro_name: ident) => { ($macro_name: ident) => {
$macro_name! { $macro_name! {
% for property in SHORTHANDS + LONGHANDS: % for property in SHORTHANDS + LONGHANDS:
% if property.derived_from is None and not property.internal: % if not property.derived_from and not property.internal:
% if '-' in property.name: % if '-' in property.name:
[${property.ident.capitalize()}, Set${property.ident.capitalize()}, "${property.name}"], [${property.ident.capitalize()}, Set${property.ident.capitalize()}, "${property.name}"],
% endif % endif