3
3
from .parameter import Parameter
4
4
5
5
from .. import component as comp
6
+ from ..messages import RDLCompileError
6
7
7
8
if TYPE_CHECKING :
8
9
from ..compiler import RDLEnvironment
12
13
13
14
TypeNSRef = Union [comp .Component , Type ['rdltypes.UserEnum' ], Type ['rdltypes.UserStruct' ]]
14
15
TypeNSEntry = TypeNSRef
15
- TypeNSScope = Dict [str , TypeNSEntry ]
16
+ TypeNSScope = Dict [str , Tuple [ TypeNSEntry , Optional [ 'SourceRefBase' ]] ]
16
17
17
18
ElementNSRef = Union [comp .Component , Parameter ]
18
19
ElementNSEntry = Tuple [ElementNSRef , Optional [comp .Component ]]
19
- ElementNSScope = Dict [str , ElementNSEntry ]
20
+ ElementNSScope = Dict [str , Tuple [ ElementNSEntry , Optional [ 'SourceRefBase' ]] ]
20
21
21
22
DefaultNSRef = Union ['ASTNode' , bool , 'rdltypes.InterruptType' ]
22
23
DefaultNSEntry = Tuple ['SourceRefBase' , DefaultNSRef ]
@@ -37,34 +38,53 @@ def __init__(self, env: 'RDLEnvironment'):
37
38
38
39
def register_type (self , name : str , ref : TypeNSRef , src_ref : Optional ['SourceRefBase' ]) -> None :
39
40
if name in self .type_ns_stack [- 1 ]:
40
- self .msg .fatal (
41
- "Multiple declarations of type '%s'" % name ,
41
+ other_src_ref = self .type_ns_stack [- 1 ][name ][1 ]
42
+ self .msg .error (
43
+ f"Multiple declarations of type '{ name } '" ,
42
44
src_ref
43
45
)
44
- self .type_ns_stack [- 1 ][name ] = ref
46
+ self .msg .warning (
47
+ f"Previous declaration of '{ name } ' is here." ,
48
+ other_src_ref
49
+ )
50
+ raise RDLCompileError ("Namespace error" )
51
+
52
+ self .type_ns_stack [- 1 ][name ] = (ref , src_ref )
45
53
46
54
def register_element (self , name : str , ref : ElementNSRef , parent_comp_def : Optional [comp .Component ], src_ref : Optional ['SourceRefBase' ]) -> None :
47
55
if name in self .element_ns_stack [- 1 ]:
48
- self .msg .fatal (
56
+ other_src_ref = self .element_ns_stack [- 1 ][name ][1 ]
57
+ self .msg .error (
49
58
"Multiple declarations of instance '%s'" % name ,
50
59
src_ref
51
60
)
52
- self .element_ns_stack [- 1 ][name ] = (ref , parent_comp_def )
61
+ self .msg .warning (
62
+ f"Previous declaration of '{ name } ' is here." ,
63
+ other_src_ref
64
+ )
65
+ raise RDLCompileError ("Namespace error" )
66
+ self .element_ns_stack [- 1 ][name ] = ((ref , parent_comp_def ), src_ref )
53
67
54
68
def register_default_property (self , name : str , ref : DefaultNSRef , src_ref : 'SourceRefBase' , overwrite_ok : bool = False ) -> None :
55
69
if not overwrite_ok :
56
70
if name in self .default_property_ns_stack [- 1 ]:
57
- self .msg .fatal (
71
+ other_src_ref = self .default_property_ns_stack [- 1 ][name ][0 ]
72
+ self .msg .error (
58
73
"Default property '%s' was already assigned in this scope" % name ,
59
74
src_ref
60
75
)
76
+ self .msg .warning (
77
+ f"Previous declaration of '{ name } ' is here." ,
78
+ other_src_ref
79
+ )
80
+ raise RDLCompileError ("Namespace error" )
61
81
62
82
self .default_property_ns_stack [- 1 ][name ] = (src_ref , ref )
63
83
64
84
def lookup_type (self , name : str ) -> Optional [TypeNSEntry ]:
65
85
for scope in reversed (self .type_ns_stack ):
66
86
if name in scope :
67
- return scope [name ]
87
+ return scope [name ][ 0 ]
68
88
return None
69
89
70
90
def lookup_element (self , name : str ) -> Union [ElementNSEntry , Tuple [None , None ]]:
@@ -80,7 +100,7 @@ def lookup_element(self, name: str) -> Union[ElementNSEntry, Tuple[None, None]]:
80
100
"""
81
101
for i , scope in enumerate (reversed (self .element_ns_stack )):
82
102
if name in scope :
83
- el , parent_def = scope [name ]
103
+ el , parent_def = scope [name ][ 0 ]
84
104
if i == 0 :
85
105
# Return anything from local namespace
86
106
return (el , parent_def )
0 commit comments