compat.fhdl.structure: always order default case as the very last.
This commit is contained in:
parent
f1174655b1
commit
f689b777b4
|
@ -79,6 +79,7 @@ class Case(ast.Switch):
|
||||||
"`with m.Case(): stmts`")
|
"`with m.Case(): stmts`")
|
||||||
def __init__(self, test, cases):
|
def __init__(self, test, cases):
|
||||||
new_cases = []
|
new_cases = []
|
||||||
|
default = None
|
||||||
for k, v in cases.items():
|
for k, v in cases.items():
|
||||||
if isinstance(k, (bool, int)):
|
if isinstance(k, (bool, int)):
|
||||||
k = Const(k)
|
k = Const(k)
|
||||||
|
@ -86,10 +87,13 @@ class Case(ast.Switch):
|
||||||
and not (isinstance(k, str) and k == "default")):
|
and not (isinstance(k, str) and k == "default")):
|
||||||
raise TypeError("Case object is not a Migen constant")
|
raise TypeError("Case object is not a Migen constant")
|
||||||
if isinstance(k, str) and k == "default":
|
if isinstance(k, str) and k == "default":
|
||||||
k = "-" * len(ast.Value.wrap(test))
|
default = v
|
||||||
else:
|
else:
|
||||||
k = k.value
|
k = k.value
|
||||||
new_cases.append((k, v))
|
new_cases.append((k, v))
|
||||||
|
if default is not None:
|
||||||
|
k = "-" * len(ast.Value.wrap(test))
|
||||||
|
new_cases.append((k, default))
|
||||||
super().__init__(test, OrderedDict(new_cases))
|
super().__init__(test, OrderedDict(new_cases))
|
||||||
|
|
||||||
@deprecated("instead of `Case(...).makedefault()`, use an explicit default case: "
|
@deprecated("instead of `Case(...).makedefault()`, use an explicit default case: "
|
||||||
|
|
Loading…
Reference in a new issue