hdl.ir: raise DomainError if a domain is used but not defined.
Before this commit, a KeyError would be raised elsewhere in guts of hdl.ir, which is not helpful.
This commit is contained in:
parent
fdb0c5a6bc
commit
fc846532c7
|
@ -351,19 +351,24 @@ class Fragment:
|
||||||
|
|
||||||
subfrag._propagate_domains_down()
|
subfrag._propagate_domains_down()
|
||||||
|
|
||||||
def _propagate_domains(self, missing_domain):
|
def _create_missing_domains(self, missing_domain):
|
||||||
from .xfrm import DomainCollector
|
from .xfrm import DomainCollector
|
||||||
|
|
||||||
self._propagate_domains_up()
|
|
||||||
new_domains = []
|
new_domains = []
|
||||||
for domain_name in DomainCollector()(self):
|
for domain_name in DomainCollector()(self):
|
||||||
if domain_name is None:
|
if domain_name is None:
|
||||||
continue
|
continue
|
||||||
if domain_name not in self.domains:
|
if domain_name not in self.domains:
|
||||||
domain = missing_domain(domain_name)
|
domain = missing_domain(domain_name)
|
||||||
if domain is not None:
|
if domain is None:
|
||||||
self.add_domains(domain)
|
raise DomainError("Domain '{}' is used but not defined".format(domain_name))
|
||||||
new_domains.append(domain)
|
self.add_domains(domain)
|
||||||
|
new_domains.append(domain)
|
||||||
|
return new_domains
|
||||||
|
|
||||||
|
def _propagate_domains(self, missing_domain):
|
||||||
|
self._propagate_domains_up()
|
||||||
|
new_domains = self._create_missing_domains(missing_domain)
|
||||||
self._propagate_domains_down()
|
self._propagate_domains_down()
|
||||||
return new_domains
|
return new_domains
|
||||||
|
|
||||||
|
|
|
@ -380,6 +380,15 @@ class FragmentDomainsTestCase(FHDLTestCase):
|
||||||
self.assertEqual(f1.domains, {"cd": cd})
|
self.assertEqual(f1.domains, {"cd": cd})
|
||||||
self.assertEqual(f2.domains, {"cd": cd})
|
self.assertEqual(f2.domains, {"cd": cd})
|
||||||
|
|
||||||
|
def test_propagate_missing(self):
|
||||||
|
s1 = Signal()
|
||||||
|
f1 = Fragment()
|
||||||
|
f1.add_driver(s1, "sync")
|
||||||
|
|
||||||
|
with self.assertRaises(DomainError,
|
||||||
|
msg="Domain 'sync' is used but not defined"):
|
||||||
|
f1._propagate_domains(missing_domain=lambda name: None)
|
||||||
|
|
||||||
def test_propagate_create_missing(self):
|
def test_propagate_create_missing(self):
|
||||||
s1 = Signal()
|
s1 = Signal()
|
||||||
f1 = Fragment()
|
f1 = Fragment()
|
||||||
|
|
Loading…
Reference in a new issue