[PATCH] keymap-gen: add support for generating output for C++
- From: Peter Korsgaard <peter korsgaard com>
- To: berrange redhat com, gtk-vnc-list gnome org
- Subject: [PATCH] keymap-gen: add support for generating output for C++
- Date: Wed, 12 Jul 2017 20:30:37 +0200
Designated initializers ([index] = value,) are not available in C++:
https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html
So add a custom stdc++ output format which outputs all array entries instead
of the "sparse" C variant.
Signed-off-by: Peter Korsgaard <peter korsgaard com>
---
A gitlab pull request was sent ~1 month ago, without any feedback:
https://gitlab.com/keycodemap/keycodemapdb/merge_requests/2
So trying here instead.
tools/keymap-gen | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/tools/keymap-gen b/tools/keymap-gen
index a10c538..914b40c 100755
--- a/tools/keymap-gen
+++ b/tools/keymap-gen
@@ -493,11 +493,31 @@ class CLanguageGenerator(LanguageSrcGenerator):
if value is not None:
print(" [0x%x] = \"%s\", /* %s */" % (index, value, comment))
+class CppLanguageGenerator(CLanguageGenerator):
+
+ # designated initializers not available in C++
+ def _array_entry_code(self, index, value, comment):
+ if value is not None:
+ print(" 0x%x, /* %s */" % (value, comment))
+ else:
+ print(" 0, /* %s */" % comment)
+
+ def _array_entry_name(self, index, value, comment):
+ if value is not None:
+ print(" \"%s\", /* %s */" % (value, comment))
+ else:
+ print(" 0, /* %s */" % comment)
+
class StdCLanguageGenerator(CLanguageGenerator):
def __init__(self):
super(StdCLanguageGenerator, self).__init__("unsigned short", "char *")
+class StdCppLanguageGenerator(CppLanguageGenerator):
+
+ def __init__(self):
+ super(StdCppLanguageGenerator, self).__init__("unsigned short", "char *")
+
class GLib2LanguageGenerator(CLanguageGenerator):
def __init__(self):
@@ -603,6 +623,7 @@ class PodLanguageGenerator(LanguageDocGenerator):
SRC_GENERATORS = {
"stdc": StdCLanguageGenerator(),
+ "stdc++": StdCppLanguageGenerator(),
"glib2": GLib2LanguageGenerator(),
"python2": PythonLanguageGenerator(),
"python3": PythonLanguageGenerator(),
--
2.11.0
[
Date Prev][
Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]