Bug 1454831 - Generate nsCSSPropertyID.h from data file directly. r=emilio
MozReview-Commit-ID: CcX2uzgjWFo
This commit is contained in:
35
layout/style/GenerateCSSPropertyID.py
Normal file
35
layout/style/GenerateCSSPropertyID.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
import string
|
||||||
|
|
||||||
|
def generate(output, template, dataFile):
|
||||||
|
with open(template, "r") as f:
|
||||||
|
template = string.Template(f.read())
|
||||||
|
with open(dataFile, "r") as f:
|
||||||
|
data = eval(f.read())
|
||||||
|
|
||||||
|
longhand_count = 0
|
||||||
|
shorthand_count = 0
|
||||||
|
alias_count = 0
|
||||||
|
property_ids = []
|
||||||
|
for name, method, id, flags, pref, prototype in data:
|
||||||
|
if prototype != "alias":
|
||||||
|
if prototype == "longhand":
|
||||||
|
assert shorthand_count == 0
|
||||||
|
longhand_count += 1
|
||||||
|
else:
|
||||||
|
assert alias_count == 0
|
||||||
|
shorthand_count += 1
|
||||||
|
property_ids.append("eCSSProperty_{}".format(id))
|
||||||
|
else:
|
||||||
|
alias_count += 1
|
||||||
|
property_ids.append("eCSSPropertyAlias_{}".format(id[0]))
|
||||||
|
|
||||||
|
output.write("/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT */\n\n")
|
||||||
|
output.write(template.substitute({
|
||||||
|
"property_ids": "\n".join(" {},".format(p) for p in property_ids),
|
||||||
|
"longhand_count": property_ids[longhand_count],
|
||||||
|
"shorthand_count": property_ids[longhand_count + shorthand_count],
|
||||||
|
}))
|
||||||
@@ -190,9 +190,6 @@ rusty-enums = [
|
|||||||
"mozilla::StyleGeometryBox",
|
"mozilla::StyleGeometryBox",
|
||||||
"mozilla::SystemColor",
|
"mozilla::SystemColor",
|
||||||
]
|
]
|
||||||
constified-enum-variants = [
|
|
||||||
{ enum = "nsCSSPropertyID", variants = ["eCSSProperty_COUNT.*"] },
|
|
||||||
]
|
|
||||||
whitelist-vars = [
|
whitelist-vars = [
|
||||||
"NS_AUTHOR_SPECIFIED_.*",
|
"NS_AUTHOR_SPECIFIED_.*",
|
||||||
"NS_THEME_.*",
|
"NS_THEME_.*",
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ DIRS += ['xbl-marquee']
|
|||||||
TEST_DIRS += ['test']
|
TEST_DIRS += ['test']
|
||||||
|
|
||||||
EXPORTS += [
|
EXPORTS += [
|
||||||
|
'!nsCSSPropertyID.h',
|
||||||
'AnimationCommon.h',
|
'AnimationCommon.h',
|
||||||
'CounterStyleManager.h',
|
'CounterStyleManager.h',
|
||||||
'nsAnimationManager.h',
|
'nsAnimationManager.h',
|
||||||
@@ -35,7 +36,6 @@ EXPORTS += [
|
|||||||
'nsCSSKeywords.h',
|
'nsCSSKeywords.h',
|
||||||
'nsCSSParser.h',
|
'nsCSSParser.h',
|
||||||
'nsCSSPropAliasList.h',
|
'nsCSSPropAliasList.h',
|
||||||
'nsCSSPropertyID.h',
|
|
||||||
'nsCSSPropertyIDSet.h',
|
'nsCSSPropertyIDSet.h',
|
||||||
'nsCSSPropList.h',
|
'nsCSSPropList.h',
|
||||||
'nsCSSProps.h',
|
'nsCSSProps.h',
|
||||||
@@ -276,10 +276,18 @@ CONTENT_ACCESSIBLE_FILES += [
|
|||||||
]
|
]
|
||||||
|
|
||||||
GENERATED_FILES += [
|
GENERATED_FILES += [
|
||||||
|
'nsCSSPropertyID.h',
|
||||||
'ServoCSSPropList.h',
|
'ServoCSSPropList.h',
|
||||||
'ServoCSSPropList.py',
|
'ServoCSSPropList.py',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
prop_id = GENERATED_FILES['nsCSSPropertyID.h']
|
||||||
|
prop_id.script = 'GenerateCSSPropertyID.py:generate'
|
||||||
|
prop_id.inputs = [
|
||||||
|
'nsCSSPropertyID.h.in',
|
||||||
|
'!ServoCssPropList.py',
|
||||||
|
]
|
||||||
|
|
||||||
servo_props = GENERATED_FILES['ServoCSSPropList.h']
|
servo_props = GENERATED_FILES['ServoCSSPropList.h']
|
||||||
servo_props.script = 'GenerateServoCSSPropList.py:generate_header'
|
servo_props.script = 'GenerateServoCSSPropList.py:generate_header'
|
||||||
servo_props.inputs = [
|
servo_props.inputs = [
|
||||||
|
|||||||
@@ -21,30 +21,7 @@
|
|||||||
enum nsCSSPropertyID {
|
enum nsCSSPropertyID {
|
||||||
eCSSProperty_UNKNOWN = -1,
|
eCSSProperty_UNKNOWN = -1,
|
||||||
|
|
||||||
#define CSS_PROP_LONGHAND(name_, id_, ...) eCSSProperty_##id_,
|
$property_ids
|
||||||
#include "mozilla/ServoCSSPropList.h"
|
|
||||||
#undef CSS_PROP_LONGHAND
|
|
||||||
|
|
||||||
eCSSProperty_COUNT_no_shorthands,
|
|
||||||
// Make the count continue where it left off:
|
|
||||||
eCSSProperty_COUNT_DUMMY = eCSSProperty_COUNT_no_shorthands - 1,
|
|
||||||
|
|
||||||
#define CSS_PROP_SHORTHAND(name_, id_, ...) eCSSProperty_##id_,
|
|
||||||
#include "mozilla/ServoCSSPropList.h"
|
|
||||||
#undef CSS_PROP_SHORTHAND
|
|
||||||
|
|
||||||
eCSSProperty_COUNT,
|
|
||||||
// Make the count continue where it left off:
|
|
||||||
eCSSProperty_COUNT_DUMMY2 = eCSSProperty_COUNT - 1,
|
|
||||||
|
|
||||||
#define CSS_PROP_ALIAS(aliasname_, aliasid_, id_, method_, pref_) \
|
|
||||||
eCSSPropertyAlias_##aliasid_,
|
|
||||||
#include "mozilla/ServoCSSPropList.h"
|
|
||||||
#undef CSS_PROP_ALIAS
|
|
||||||
|
|
||||||
eCSSProperty_COUNT_with_aliases,
|
|
||||||
// Make the count continue where it left off:
|
|
||||||
eCSSProperty_COUNT_DUMMY3 = eCSSProperty_COUNT_with_aliases - 1,
|
|
||||||
|
|
||||||
// Some of the values below could probably overlap with each other
|
// Some of the values below could probably overlap with each other
|
||||||
// if we had a need for them to do so.
|
// if we had a need for them to do so.
|
||||||
@@ -54,17 +31,17 @@ enum nsCSSPropertyID {
|
|||||||
eCSSPropertyExtra_no_properties,
|
eCSSPropertyExtra_no_properties,
|
||||||
eCSSPropertyExtra_all_properties,
|
eCSSPropertyExtra_all_properties,
|
||||||
|
|
||||||
// Extra dummy values for nsCSSParser internal use.
|
|
||||||
eCSSPropertyExtra_x_none_value,
|
|
||||||
eCSSPropertyExtra_x_auto_value,
|
|
||||||
|
|
||||||
// Extra value to represent custom properties (--*).
|
// Extra value to represent custom properties (--*).
|
||||||
eCSSPropertyExtra_variable,
|
eCSSPropertyExtra_variable,
|
||||||
|
|
||||||
// Extra value for use in the DOM API's
|
|
||||||
eCSSProperty_DOM
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const nsCSSPropertyID
|
||||||
|
eCSSProperty_COUNT_no_shorthands = $longhand_count;
|
||||||
|
const nsCSSPropertyID
|
||||||
|
eCSSProperty_COUNT = $shorthand_count;
|
||||||
|
const nsCSSPropertyID
|
||||||
|
eCSSProperty_COUNT_with_aliases = eCSSPropertyExtra_no_properties;
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
@@ -33,8 +33,7 @@ mod common {
|
|||||||
#[cfg(feature = "bindgen")]
|
#[cfg(feature = "bindgen")]
|
||||||
mod bindings {
|
mod bindings {
|
||||||
use bindgen::{Builder, CodegenConfig};
|
use bindgen::{Builder, CodegenConfig};
|
||||||
use bindgen::callbacks::{EnumVariantCustomBehavior, EnumVariantValue, ParseCallbacks};
|
use regex::Regex;
|
||||||
use regex::{Regex, RegexSet};
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::env;
|
use std::env;
|
||||||
@@ -416,27 +415,6 @@ mod bindings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn generate_structs() {
|
fn generate_structs() {
|
||||||
#[derive(Debug)]
|
|
||||||
struct Callbacks(HashMap<String, RegexSet>);
|
|
||||||
impl ParseCallbacks for Callbacks {
|
|
||||||
fn enum_variant_behavior(
|
|
||||||
&self,
|
|
||||||
enum_name: Option<&str>,
|
|
||||||
variant_name: &str,
|
|
||||||
_variant_value: EnumVariantValue,
|
|
||||||
) -> Option<EnumVariantCustomBehavior> {
|
|
||||||
enum_name
|
|
||||||
.and_then(|enum_name| self.0.get(enum_name))
|
|
||||||
.and_then(|regex| {
|
|
||||||
if regex.is_match(variant_name) {
|
|
||||||
Some(EnumVariantCustomBehavior::Constify)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let builder = Builder::get_initial_builder()
|
let builder = Builder::get_initial_builder()
|
||||||
.enable_cxx_namespaces()
|
.enable_cxx_namespaces()
|
||||||
.with_codegen_config(CodegenConfig {
|
.with_codegen_config(CodegenConfig {
|
||||||
@@ -452,21 +430,6 @@ mod bindings {
|
|||||||
.handle_str_items("whitelist-vars", |b, item| b.whitelist_var(item))
|
.handle_str_items("whitelist-vars", |b, item| b.whitelist_var(item))
|
||||||
.handle_str_items("whitelist-types", |b, item| b.whitelist_type(item))
|
.handle_str_items("whitelist-types", |b, item| b.whitelist_type(item))
|
||||||
.handle_str_items("opaque-types", |b, item| b.opaque_type(item))
|
.handle_str_items("opaque-types", |b, item| b.opaque_type(item))
|
||||||
.handle_list("constified-enum-variants", |builder, iter| {
|
|
||||||
let mut map = HashMap::new();
|
|
||||||
for item in iter {
|
|
||||||
let item = item.as_table().unwrap();
|
|
||||||
let name = item["enum"].as_str().unwrap();
|
|
||||||
let variants = item["variants"]
|
|
||||||
.as_array()
|
|
||||||
.unwrap()
|
|
||||||
.as_slice()
|
|
||||||
.iter()
|
|
||||||
.map(|item| item.as_str().unwrap());
|
|
||||||
map.insert(name.into(), RegexSet::new(variants).unwrap());
|
|
||||||
}
|
|
||||||
builder.parse_callbacks(Box::new(Callbacks(map)))
|
|
||||||
})
|
|
||||||
.handle_table_items("mapped-generic-types", |builder, item| {
|
.handle_table_items("mapped-generic-types", |builder, item| {
|
||||||
let generic = item["generic"].as_bool().unwrap();
|
let generic = item["generic"].as_bool().unwrap();
|
||||||
let gecko = item["gecko"].as_str().unwrap();
|
let gecko = item["gecko"].as_str().unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user