From: Rob Hoes Subject: [PATCH RFC 2/9] libxl idl: allow implicit enum values Date: Wed, 24 Jun 2015 14:47:29 +0100 Message-ID: <1435153656-19485-3-git-send-email-rob.hoes@citrix.com> References: <1435153656-19485-1-git-send-email-rob.hoes@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Z7l1s-0005F1-Uf for xen-devel@lists.xenproject.org; Wed, 24 Jun 2015 13:47:53 +0000 In-Reply-To: <1435153656-19485-1-git-send-email-rob.hoes@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: euan.harris@citrix.com, Ian.Jackson@eu.citrix.com, Rob Hoes List-Id: xen-devel@lists.xenproject.org Introducing two special enum values: * ENUM_NEXT: equal to the previous value in the enum plus 1 * ENUM_PREV: equal to the previous value in the enum minus 1 This makes it a little easier to maintain enums for which we do not care too much about the exact enum values. Signed-off-by: Rob Hoes --- tools/libxl/idl.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/libxl/idl.py b/tools/libxl/idl.py index 437049e..9fccefa 100644 --- a/tools/libxl/idl.py +++ b/tools/libxl/idl.py @@ -8,6 +8,9 @@ DIR_IN = 1 DIR_OUT = 2 DIR_BOTH = 3 +ENUM_NEXT = sys.maxint +ENUM_PREV = sys.maxint - 1 + _default_namespace = "" def namespace(s): if type(s) != str: @@ -174,9 +177,18 @@ class Enumeration(Type): self.namespace) self.values = [] + last = None for v in values: # (value, name) (num,name) = v + if num == ENUM_NEXT or num == ENUM_PREV: + if last == None: + raise ValueError + elif num == ENUM_NEXT: + num = last + 1 + else: + num = last - 1 + last = num self.values.append(EnumerationValue(self, num, name, typename=self.rawname)) def lookup(self, name): @@ -354,6 +366,7 @@ def parse(f): globs[n] = t elif n in ['PASS_BY_REFERENCE', 'PASS_BY_VALUE', 'DIR_NONE', 'DIR_IN', 'DIR_OUT', 'DIR_BOTH', + 'ENUM_NEXT', 'ENUM_PREV', 'namespace', 'hidden']: globs[n] = t -- 2.4.1