@@ -81,23 +81,33 @@ object CheckUses extends BasicUseAnalyzer {
8181 visitExprNode(a, node)
8282 }
8383
84- override def impliedConstantUse (a : Analysis , iu : ImpliedUse ) =
85- for {
86- a <- super .impliedConstantUse(a, iu)
87- _ <- checkImpliedUse(a, iu, " constant" )
88- } yield a
89-
90- override def impliedPortUse (a : Analysis , iu : ImpliedUse ) =
91- for {
92- a <- super .impliedPortUse(a, iu)
93- _ <- checkImpliedUse(a, iu, " port" )
94- } yield a
95-
96- override def impliedTypeUse (a : Analysis , iu : ImpliedUse ) =
97- for {
98- a <- super .impliedTypeUse(a, iu)
99- _ <- checkImpliedUse(a, iu, " type" )
100- } yield a
84+ // Check that an implied use (a) is not a member
85+ // of a def and (b) does not shadow the required def
86+ override def impliedUse (a : Analysis , iu : ImpliedUse , kind : ImpliedUse .Kind ) = {
87+ val sym = a.useDefMap(iu.id)
88+ val symQualifiedName = a.getQualifiedName(sym).toString
89+ val iuName = iu.name.toString
90+ // Check that the name of the def matches the name of the use
91+ val result = if symQualifiedName == iuName
92+ // OK, they match
93+ then Right (a)
94+ else {
95+ val msg = if symQualifiedName.length < iuName.length
96+ // Definition has a shorter name: the use is a member of the definition
97+ then s " it has $iuName as a member "
98+ // Definition has a longer name: it shadows the required definition
99+ else s " it shadows $iuName here "
100+ Left (
101+ SemanticError .InvalidSymbol (
102+ symQualifiedName,
103+ Locations .get(iu.id),
104+ msg,
105+ sym.getLoc
106+ )
107+ )
108+ }
109+ iu.annotateResult(result)
110+ }
101111
102112 override def defComponentAnnotatedNode (a : Analysis , aNode : Ast .Annotated [AstNode [Ast .DefComponent ]]) = {
103113 val (_, node, _) = aNode
@@ -186,36 +196,4 @@ object CheckUses extends BasicUseAnalyzer {
186196 }
187197 }
188198
189- // Check that an implied use (a) is not a member
190- // of a def and (b) does not shadow the required def
191- private def checkImpliedUse (
192- a : Analysis ,
193- iu : ImpliedUse ,
194- kind : String
195- ) = {
196- val sym = a.useDefMap(iu.id)
197- val symQualifiedName = a.getQualifiedName(sym).toString
198- val iuName = iu.name.toString
199- // Check that the name of the def matches the name of the use
200- val result = if symQualifiedName == iuName
201- // OK, they match
202- then Right (())
203- else {
204- val msg = if symQualifiedName.length < iuName.length
205- // Definition has a shorter name: the use is a member of the definition
206- then s " it has $iuName as a member "
207- // Definition has a longer name: it shadows the required definition
208- else s " it shadows $iuName here "
209- Left (
210- SemanticError .InvalidSymbol (
211- symQualifiedName,
212- Locations .get(iu.id),
213- msg,
214- sym.getLoc
215- )
216- )
217- }
218- iu.annotateResult(result)
219- }
220-
221199}
0 commit comments