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/.
10 sys
.path
.append(os
.path
.dirname(__file__
))
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
):
24 #define %(name)s(interface_, name_) // nothing
25 #define DEFINED_%(name)s
32 def print_optional_macro_undeclare(name
):
35 #ifdef DEFINED_%(name)s
36 #undef DEFINED_%(name)s
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":
53 "USE_COUNTER_DOM_METHOD(%s, %s)"
54 % (counter
["interface_name"], counter
["method_name"]),
57 elif counter
["type"] == "attribute":
59 "USE_COUNTER_DOM_ATTRIBUTE(%s, %s)"
60 % (counter
["interface_name"], counter
["attribute_name"]),
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)