Bug 1867190 - Initialise the PHC allocate delay later r=glandium
[gecko.git] / layout / style / GenerateComputedDOMStyleGenerated.py
blob2dcfabd2417da27d7122836873578df7b8694256
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/.
5 import runpy
7 FILE = """/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT */
9 /* processed file that defines entries for nsComputedDOMStyle, designed
10 to be #included in nsComputedDOMStyle.cpp */
12 static constexpr size_t kEntryIndices[eCSSProperty_COUNT] = {{
13 {indices}
14 }};
16 {asserts}
18 static constexpr Entry kEntries[eCSSProperty_COUNT] = {{
19 {entries}
20 }};
21 """
24 def generate(output, dataFile):
25 def order_key(p):
26 # Put prefixed properties after normal properties.
27 # The spec is unclear about this, and Blink doesn't have any sensible
28 # order at all, so it probably doesn't matter a lot. But originally
29 # Gecko put then later so we do so as well. See w3c/csswg-drafts#2827.
30 order = p.name.startswith("-")
31 return (order, p.name)
33 def has_cpp_getter(p):
34 if not "ExposedOnGetCS" in p.flags:
35 return False
36 if "SerializedByServo" in p.flags:
37 return False
38 if p.type() == "longhand" and "IsLogical" in p.flags:
39 return False
40 return True
42 def getter_entry(p):
43 if has_cpp_getter(p):
44 return "DoGet" + p.method
45 # Put a dummy getter here instead of nullptr because MSVC seems
46 # to have bug which ruins the table when we put nullptr for
47 # pointer-to-member-function. See bug 1471426.
48 return "DummyGetter"
50 properties = runpy.run_path(dataFile)["data"]
52 entries = []
53 indices = []
54 asserts = []
55 index_map = {}
56 non_aliases = list(filter(lambda p: p.type() != "alias", properties.values()))
57 for i, p in enumerate(sorted(non_aliases, key=order_key)):
58 can_be_exposed = "true" if "ExposedOnGetCS" in p.flags else "false"
59 entries.append(
60 "{{ eCSSProperty_{}, {}, &nsComputedDOMStyle::{}}}".format(
61 p.id, can_be_exposed, getter_entry(p)
64 index_map[p.id] = i
65 i += 1
67 for i, p in enumerate(non_aliases):
68 indices.append(str(index_map[p.id]))
69 asserts.append(
70 'static_assert(size_t(eCSSProperty_{}) == {}, "");'.format(p.id, i)
73 assert len(indices) == len(entries)
75 output.write(
76 FILE.format(
77 indices=", ".join(indices),
78 entries=",\n ".join(entries),
79 asserts="\n".join(asserts),