Bug 1850713: remove duplicated setting of early hint preloader id in `ScriptLoader...
[gecko.git] / dom / base / gen-usecounters.py
blobbd0dba7b0bbcae90f912c62daf4dddc62fd233b0
1 #!/usr/bin/env python
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 import os
8 import sys
10 sys.path.append(os.path.dirname(__file__))
12 import usecounters
14 AUTOGENERATED_WARNING_COMMENT = (
15 "/* THIS FILE IS AUTOGENERATED BY gen-usecounters.py - DO NOT EDIT */"
19 def generate_list(f, counters):
20 def print_optional_macro_declare(name):
21 print(
22 """
23 #ifndef %(name)s
24 #define %(name)s(interface_, name_) // nothing
25 #define DEFINED_%(name)s
26 #endif
27 """
28 % {"name": name},
29 file=f,
32 def print_optional_macro_undeclare(name):
33 print(
34 """
35 #ifdef DEFINED_%(name)s
36 #undef DEFINED_%(name)s
37 #undef %(name)s
38 #endif
39 """
40 % {"name": name},
41 file=f,
44 print(AUTOGENERATED_WARNING_COMMENT, file=f)
46 print_optional_macro_declare("USE_COUNTER_DOM_METHOD")
47 print_optional_macro_declare("USE_COUNTER_DOM_ATTRIBUTE")
48 print_optional_macro_declare("USE_COUNTER_CUSTOM")
50 for counter in counters:
51 if counter["type"] == "method":
52 print(
53 "USE_COUNTER_DOM_METHOD(%s, %s)"
54 % (counter["interface_name"], counter["method_name"]),
55 file=f,
57 elif counter["type"] == "attribute":
58 print(
59 "USE_COUNTER_DOM_ATTRIBUTE(%s, %s)"
60 % (counter["interface_name"], counter["attribute_name"]),
61 file=f,
63 elif counter["type"] == "custom":
64 desc = counter["desc"].replace("\\", r"\\").replace('"', r"\"")
65 print('USE_COUNTER_CUSTOM(%s, "%s")' % (counter["name"], desc), file=f)
67 print_optional_macro_undeclare("USE_COUNTER_DOM_METHOD")
68 print_optional_macro_undeclare("USE_COUNTER_DOM_ATTRIBUTE")
69 print_optional_macro_undeclare("USE_COUNTER_CUSTOM")
72 def use_counter_list(output_header, conf_filename):
73 counters = usecounters.read_conf(conf_filename)
74 generate_list(output_header, counters)