dawn_json_generator: Assert that enum values are unique.

This will be useful when we add all texture formats because there are
more than 50 of them and we want to make sure no two enum values
collide.

BUG=dawn:128

Change-Id: I928d3311ee3f6422ea503a3fa90c5e377fe5e03d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/8360
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py
index 9eb4c2e..02dccfb 100644
--- a/generator/dawn_json_generator.py
+++ b/generator/dawn_json_generator.py
@@ -67,6 +67,13 @@
         Type.__init__(self, name, json_data)
         self.values = [EnumValue(Name(m['name']), m['value']) for m in self.json_data['values']]
 
+        # Assert that all values are unique in enums
+        all_values = set()
+        for value in self.values:
+            if value.value in all_values:
+                raise Exception("Duplicate value {} in enum {}".format(value.value, name))
+            all_values.add(value.value)
+
 BitmaskValue = namedtuple('BitmaskValue', ['name', 'value'])
 class BitmaskType(Type):
     def __init__(self, name, json_data):