From b66fb1c1d2e9ffa198a6f6ff491f1b0e37309b83 Mon Sep 17 00:00:00 2001 From: Tobin Ehlis Date: Wed, 15 Apr 2015 17:04:03 -0600 Subject: [PATCH] layers: Improve validate helpers treatment of flag enums --- vk_helper.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/vk_helper.py b/vk_helper.py index 93a915d..80bfc6b 100755 --- a/vk_helper.py +++ b/vk_helper.py @@ -1286,11 +1286,19 @@ class EnumCodeGen: body = [] for bet in sorted(self.et_dict): fet = self.tf_dict[bet] - body.append("static inline uint32_t validate_%s(%s input_value)\n{\n switch ((%s)input_value)\n {" % (fet, fet, fet)) - for e in sorted(self.et_dict[bet]): - if (self.ev_dict[e]['unique']): - body.append(' case %s:' % (e)) - body.append(' return 1;\n default:\n return 0;\n }\n}\n\n') + body.append("static inline uint32_t validate_%s(%s input_value)\n{" % (fet, fet)) + # TODO : This is not ideal, but allows for flag combinations. Need more rigorous validation of realistic flag combinations + if 'flags' in bet.lower(): + body.append(' if (input_value > (%s))' % (' | '.join(self.et_dict[bet]))) + body.append(' return 0;') + body.append(' return 1;') + body.append('}\n\n') + else: + body.append(' switch ((%s)input_value)\n {' % (fet)) + for e in sorted(self.et_dict[bet]): + if (self.ev_dict[e]['unique']): + body.append(' case %s:' % (e)) + body.append(' return 1;\n default:\n return 0;\n }\n}\n\n') return "\n".join(body) def _generateSHBody(self): -- 2.7.4