Skip to content

Commit 7c3d858

Browse files
davidschrammelsameo
authored andcommitted
[PATCH] [util,topgen] Check for duplicate constant declarations
Co-authored-by: Samuel Ortiz <[email protected]> Signed-off-by: David Schrammel <[email protected]>
1 parent 4b15a86 commit 7c3d858

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

util/topgen/lib.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ def add_constant(self, constant_name: Name, docstring=""):
4444

4545
value = len(self.constants)
4646

47+
# Check that we're not adding duplicates
48+
for const in self.constants:
49+
if full_name == const[0]:
50+
raise ValueError('{} is already declared with value {}'.format(const[0], const[1]))
51+
4752
self.constants.append((full_name, value, docstring))
4853

4954
return full_name
@@ -148,6 +153,11 @@ def add_constant(self, constant_name: str, docstring="") -> str:
148153
full_name = constant_name
149154
value = self.enum_counter
150155
self.enum_counter += 1
156+
157+
# Check that we're not adding duplicates
158+
for const in self.constants:
159+
if full_name == const[0]:
160+
raise ValueError('{} is already declared with value {}'.format(const[0], const[1]))
151161
self.constants.append((full_name, value, docstring))
152162
return full_name
153163

0 commit comments

Comments
 (0)