summaryrefslogtreecommitdiffstats
path: root/dom/base/gen-usecounters.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /dom/base/gen-usecounters.py
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/gen-usecounters.py')
-rwxr-xr-xdom/base/gen-usecounters.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/dom/base/gen-usecounters.py b/dom/base/gen-usecounters.py
new file mode 100755
index 0000000000..bd0dba7b0b
--- /dev/null
+++ b/dom/base/gen-usecounters.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import sys
+
+sys.path.append(os.path.dirname(__file__))
+
+import usecounters
+
+AUTOGENERATED_WARNING_COMMENT = (
+ "/* THIS FILE IS AUTOGENERATED BY gen-usecounters.py - DO NOT EDIT */"
+)
+
+
+def generate_list(f, counters):
+ def print_optional_macro_declare(name):
+ print(
+ """
+#ifndef %(name)s
+#define %(name)s(interface_, name_) // nothing
+#define DEFINED_%(name)s
+#endif
+"""
+ % {"name": name},
+ file=f,
+ )
+
+ def print_optional_macro_undeclare(name):
+ print(
+ """
+#ifdef DEFINED_%(name)s
+#undef DEFINED_%(name)s
+#undef %(name)s
+#endif
+"""
+ % {"name": name},
+ file=f,
+ )
+
+ print(AUTOGENERATED_WARNING_COMMENT, file=f)
+
+ print_optional_macro_declare("USE_COUNTER_DOM_METHOD")
+ print_optional_macro_declare("USE_COUNTER_DOM_ATTRIBUTE")
+ print_optional_macro_declare("USE_COUNTER_CUSTOM")
+
+ for counter in counters:
+ if counter["type"] == "method":
+ print(
+ "USE_COUNTER_DOM_METHOD(%s, %s)"
+ % (counter["interface_name"], counter["method_name"]),
+ file=f,
+ )
+ elif counter["type"] == "attribute":
+ print(
+ "USE_COUNTER_DOM_ATTRIBUTE(%s, %s)"
+ % (counter["interface_name"], counter["attribute_name"]),
+ file=f,
+ )
+ elif counter["type"] == "custom":
+ desc = counter["desc"].replace("\\", r"\\").replace('"', r"\"")
+ print('USE_COUNTER_CUSTOM(%s, "%s")' % (counter["name"], desc), file=f)
+
+ print_optional_macro_undeclare("USE_COUNTER_DOM_METHOD")
+ print_optional_macro_undeclare("USE_COUNTER_DOM_ATTRIBUTE")
+ print_optional_macro_undeclare("USE_COUNTER_CUSTOM")
+
+
+def use_counter_list(output_header, conf_filename):
+ counters = usecounters.read_conf(conf_filename)
+ generate_list(output_header, counters)