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 from __future__
import print_function
13 sys
.path
.append(os
.path
.dirname(__file__
))
17 AUTOGENERATED_WARNING_COMMENT
= (
18 "/* THIS FILE IS AUTOGENERATED BY gen-usecounters.py - DO NOT EDIT */"
22 def generate_list(f
, counters
):
23 def print_optional_macro_declare(name
):
27 #define %(name)s(interface_, name_) // nothing
28 #define DEFINED_%(name)s
35 def print_optional_macro_undeclare(name
):
38 #ifdef DEFINED_%(name)s
39 #undef DEFINED_%(name)s
47 print(AUTOGENERATED_WARNING_COMMENT
, file=f
)
49 print_optional_macro_declare("USE_COUNTER_DOM_METHOD")
50 print_optional_macro_declare("USE_COUNTER_DOM_ATTRIBUTE")
51 print_optional_macro_declare("USE_COUNTER_CUSTOM")
53 for counter
in counters
:
54 if counter
["type"] == "method":
56 "USE_COUNTER_DOM_METHOD(%s, %s)"
57 % (counter
["interface_name"], counter
["method_name"]),
60 elif counter
["type"] == "attribute":
62 "USE_COUNTER_DOM_ATTRIBUTE(%s, %s)"
63 % (counter
["interface_name"], counter
["attribute_name"]),
66 elif counter
["type"] == "custom":
67 desc
= counter
["desc"].replace("\\", r
"\\").replace('"', r
"\"")
68 print('USE_COUNTER_CUSTOM(%s, "%s")' % (counter["name
"], desc), file=f)
70 print_optional_macro_undeclare("USE_COUNTER_DOM_METHOD
")
71 print_optional_macro_undeclare("USE_COUNTER_DOM_ATTRIBUTE
")
72 print_optional_macro_undeclare("USE_COUNTER_CUSTOM
")
75 def use_counter_list(output_header, conf_filename):
76 counters = usecounters.read_conf(conf_filename)
77 generate_list(output_header, counters)