1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 # You can obtain one at http://mozilla.org/MPL/2.0/.
11 class PropertyWrapper(object):
12 __slots__
= ["index", "prop", "idlname"]
14 def __init__(self
, index
, prop
):
17 if "Internal" in prop
.flags
:
20 idl_name
= prop
.method
21 if not idl_name
.startswith("Moz"):
22 idl_name
= idl_name
[0].lower() + idl_name
[1:]
23 self
.idlname
= idl_name
25 def __getattr__(self
, name
):
26 return getattr(self
.prop
, name
)
29 def generate(output
, dataFile
):
31 """/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT */
33 /* processed file that defines CSS property tables that can't be generated
34 with the pre-processor, designed to be #included in nsCSSProps.cpp */
39 raw_properties
= runpy
.run_path(dataFile
)["data"]
42 for i
, p
in enumerate(raw_properties
.values())
43 if p
.type() != "alias"
46 # Generate kIDLNameTable
48 "const char* const nsCSSProps::" "kIDLNameTable[eCSSProperty_COUNT] = {\n"
52 output
.write(" nullptr, // {}\n".format(p
.name
))
54 output
.write(' "{}",\n'.format(p
.idlname
))
55 output
.write("};\n\n")
57 # Generate kIDLNameSortPositionTable
58 ps
= sorted(properties
, key
=lambda p
: p
.idlname
if p
.idlname
else "")
59 ps
= [(p
, position
) for position
, p
in enumerate(ps
)]
60 ps
.sort(key
=lambda item
: item
[0].index
)
62 "const int32_t nsCSSProps::"
63 "kIDLNameSortPositionTable[eCSSProperty_COUNT] = {\n"
65 for p
, position
in ps
:
66 output
.write(" {},\n".format(position
))
67 output
.write("};\n\n")
69 # Generate preferences table
71 "const nsCSSProps::PropertyPref " "nsCSSProps::kPropertyPrefTable[] = {\n"
73 for p
in raw_properties
.values():
76 if p
.type() != "alias":
77 prop_id
= "eCSSProperty_" + p
.id
79 prop_id
= "eCSSPropertyAlias_" + p
.alias_id
80 output
.write(' {{ {}, "{}" }},\n'.format(prop_id
, p
.pref
))
81 output
.write(" { eCSSProperty_UNKNOWN, nullptr },\n")
82 output
.write("};\n\n")
84 # Generate shorthand subprop tables
87 if p
.type() != "shorthand":
89 name
= "g{}SubpropTable".format(p
.method
)
91 output
.write("static const nsCSSPropertyID {}[] = {{\n".format(name
))
92 for subprop
in p
.subprops
:
93 output
.write(" eCSSProperty_{},\n".format(subprop
))
94 output
.write(" eCSSProperty_UNKNOWN\n")
95 output
.write("};\n\n")
96 output
.write("const nsCSSPropertyID* const\n")
98 "nsCSSProps::kSubpropertyTable["
99 "eCSSProperty_COUNT - eCSSProperty_COUNT_no_shorthands"
103 output
.write(" {},\n".format(name
))
104 output
.write("};\n\n")
106 # Generate assertions
108 "GenerateCSSPropsGenerated.py did not list properties "
109 "in nsCSSPropertyID order"
113 'static_assert(eCSSProperty_{} == {}, "{}");\n'.format(p
.id, p
.index
, msg
)