2015-09-22 08:58:20 +03:00
|
|
|
# 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/.
|
|
|
|
|
2018-05-04 06:44:51 +03:00
|
|
|
import runpy
|
2015-09-22 08:58:20 +03:00
|
|
|
import sys
|
|
|
|
import string
|
2016-05-11 00:17:15 +03:00
|
|
|
import argparse
|
2018-04-17 07:40:12 +03:00
|
|
|
|
2018-05-04 06:44:51 +03:00
|
|
|
class PropertyWrapper(object):
|
|
|
|
__slots__ = ["index", "prop", "idlname"]
|
2015-09-22 08:58:20 +03:00
|
|
|
|
2018-05-04 06:44:51 +03:00
|
|
|
def __init__(self, index, prop):
|
|
|
|
self.index = index
|
|
|
|
self.prop = prop
|
2018-06-27 08:34:29 +03:00
|
|
|
if "Internal" in prop.flags:
|
2018-05-04 06:44:51 +03:00
|
|
|
self.idlname = None
|
2016-05-11 00:17:15 +03:00
|
|
|
else:
|
2018-05-04 06:44:51 +03:00
|
|
|
idl_name = prop.method
|
2016-05-11 00:17:15 +03:00
|
|
|
if not idl_name.startswith("Moz"):
|
|
|
|
idl_name = idl_name[0].lower() + idl_name[1:]
|
2018-05-04 06:44:51 +03:00
|
|
|
self.idlname = idl_name
|
|
|
|
|
|
|
|
def __getattr__(self, name):
|
|
|
|
return getattr(self.prop, name)
|
2016-05-11 00:17:15 +03:00
|
|
|
|
2018-05-04 06:44:51 +03:00
|
|
|
|
2018-05-04 07:37:41 +03:00
|
|
|
def generate(output, dataFile):
|
|
|
|
output.write("""/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT */
|
|
|
|
|
|
|
|
/* processed file that defines CSS property tables that can't be generated
|
|
|
|
with the pre-processor, designed to be #included in nsCSSProps.cpp */
|
|
|
|
|
|
|
|
""")
|
|
|
|
|
2018-05-31 06:49:25 +03:00
|
|
|
raw_properties = runpy.run_path(dataFile)["data"]
|
2018-05-04 07:37:41 +03:00
|
|
|
properties = [PropertyWrapper(i, p)
|
2018-05-31 06:49:25 +03:00
|
|
|
for i, p in enumerate(raw_properties)
|
2018-05-04 07:37:41 +03:00
|
|
|
if p.type() != "alias"]
|
2015-09-23 01:37:17 +03:00
|
|
|
|
2018-05-04 07:37:41 +03:00
|
|
|
# Generate kIDLNameTable
|
|
|
|
output.write("const char* const nsCSSProps::"
|
|
|
|
"kIDLNameTable[eCSSProperty_COUNT] = {\n")
|
2015-09-22 08:58:20 +03:00
|
|
|
for p in properties:
|
2018-05-04 06:44:51 +03:00
|
|
|
if p.idlname is None:
|
2018-05-04 07:37:41 +03:00
|
|
|
output.write(" nullptr, // {}\n".format(p.name))
|
2015-09-22 08:58:20 +03:00
|
|
|
else:
|
2018-05-04 07:37:41 +03:00
|
|
|
output.write(' "{}",\n'.format(p.idlname))
|
|
|
|
output.write("};\n\n")
|
2015-09-23 01:37:17 +03:00
|
|
|
|
2018-05-04 07:37:41 +03:00
|
|
|
# Generate kIDLNameSortPositionTable
|
|
|
|
ps = sorted(properties, key=lambda p: p.idlname)
|
2015-09-23 01:37:17 +03:00
|
|
|
ps = [(p, position) for position, p in enumerate(ps)]
|
2018-05-04 07:37:41 +03:00
|
|
|
ps.sort(key=lambda (p, position): p.index)
|
|
|
|
output.write("const int32_t nsCSSProps::"
|
|
|
|
"kIDLNameSortPositionTable[eCSSProperty_COUNT] = {\n")
|
|
|
|
for (p, position) in ps:
|
|
|
|
output.write(" {},\n".format(position))
|
|
|
|
output.write("};\n\n")
|
|
|
|
|
2018-05-31 06:49:25 +03:00
|
|
|
# Generate preferences table
|
|
|
|
output.write("const nsCSSProps::PropertyPref "
|
|
|
|
"nsCSSProps::kPropertyPrefTable[] = {\n")
|
|
|
|
for p in raw_properties:
|
|
|
|
if not p.pref:
|
|
|
|
continue
|
|
|
|
if p.type() != "alias":
|
|
|
|
prop_id = "eCSSProperty_" + p.id
|
|
|
|
else:
|
|
|
|
prop_id = "eCSSPropertyAlias_" + p.alias_id
|
|
|
|
output.write(" {{ {}, \"{}\" }},\n".format(prop_id, p.pref))
|
|
|
|
output.write(" { eCSSProperty_UNKNOWN, nullptr },\n")
|
|
|
|
output.write("};\n\n")
|
|
|
|
|
2018-05-04 08:17:05 +03:00
|
|
|
# Generate shorthand subprop tables
|
|
|
|
names = []
|
|
|
|
for p in properties:
|
|
|
|
if p.type() != "shorthand":
|
|
|
|
continue
|
|
|
|
name = "g{}SubpropTable".format(p.method)
|
|
|
|
names.append(name)
|
|
|
|
output.write("static const nsCSSPropertyID {}[] = {{\n".format(name))
|
|
|
|
for subprop in p.subprops:
|
|
|
|
output.write(" eCSSProperty_{},\n".format(subprop))
|
|
|
|
output.write(" eCSSProperty_UNKNOWN\n")
|
|
|
|
output.write("};\n\n")
|
|
|
|
output.write("const nsCSSPropertyID* const\n")
|
|
|
|
output.write("nsCSSProps::kSubpropertyTable["
|
|
|
|
"eCSSProperty_COUNT - eCSSProperty_COUNT_no_shorthands"
|
|
|
|
"] = {\n")
|
|
|
|
for name in names:
|
|
|
|
output.write(" {},\n".format(name))
|
|
|
|
output.write("};\n\n")
|
|
|
|
|
2018-05-04 07:37:41 +03:00
|
|
|
# Generate assertions
|
|
|
|
msg = ("GenerateCSSPropsGenerated.py did not list properties "
|
|
|
|
"in nsCSSPropertyID order")
|
|
|
|
for p in properties:
|
|
|
|
output.write('static_assert(eCSSProperty_{} == {}, "{}");\n'
|
|
|
|
.format(p.id, p.index, msg))
|