From cf6a52466924c4dd12ebdcb2e8160275a914155b Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 8 Aug 2017 13:11:45 +0100 Subject: Add support for array upper bounds with enums Signed-off-by: Daniel P. Berrange --- tools/keymap-gen | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/keymap-gen b/tools/keymap-gen index 6c539bd..f3a8634 100755 --- a/tools/keymap-gen +++ b/tools/keymap-gen @@ -147,6 +147,10 @@ class Database: MAP_QCODE: 16, } + ENUM_BOUND = { + MAP_QCODE: "Q_KEY_CODE__MAX", + } + def __init__(self): self.mapto = {} @@ -359,7 +363,7 @@ class LanguageSrcGenerator(LanguageGenerator): keys = range(keys[-1] + 1) if fromtype == self.TYPE_ENUM: - keymax = None + keymax = database.ENUM_BOUND[frommapname] else: keymax = len(keys) @@ -553,8 +557,8 @@ class CLanguageGenerator(LanguageSrcGenerator): self._varname = varname; totypename = self.strtypename if totype == self.TYPE_STRING else self.inttypename if fromtype in (self.TYPE_INT, self.TYPE_ENUM): - if length is None: - print("const %s %s[] = {" % (totypename, varname)) + if type(length) == str: + print("const %s %s[%s] = {" % (totypename, varname, length)) else: print("const %s %s[%d] = {" % (totypename, varname, length)) else: -- cgit v1.1