Skip to content

Commit ed6e566

Browse files
committed
Refactor CheckUses
1 parent 99d2f72 commit ed6e566

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

compiler/lib/src/main/scala/analysis/Analyzers/BasicUseAnalyzer.scala

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,31 @@ trait BasicUseAnalyzer extends TypeExpressionAnalyzer {
3434
def stateMachineUse(a: Analysis, node: AstNode[Ast.QualIdent], use: Name.Qualified): Result = default(a)
3535

3636
/** An implied constant use */
37-
def impliedConstantUse(a: Analysis, iu: ImpliedUse) =
38-
for {
39-
a <- iu.annotateResult(exprNode(a, iu.asExprNode))
37+
def impliedConstantUse(a: Analysis, iu: ImpliedUse) = {
38+
val result = for {
39+
a <- exprNode(a, iu.asExprNode)
4040
_ <- impliedUse(a, iu, ImpliedUse.Kind.Constant)
4141
} yield a
42+
iu.annotateResult(result)
43+
}
4244

4345
/** An implied port use */
44-
def impliedPortUse(a: Analysis, iu: ImpliedUse) =
45-
for {
46-
a <- iu.annotateResult(portUse(a, iu.asQualIdentNode, iu.name))
46+
def impliedPortUse(a: Analysis, iu: ImpliedUse) = {
47+
val result = for {
48+
a <- portUse(a, iu.asQualIdentNode, iu.name)
4749
_ <- impliedUse(a, iu, ImpliedUse.Kind.Port)
4850
} yield a
51+
iu.annotateResult(result)
52+
}
4953

5054
/** An implied type use */
51-
def impliedTypeUse(a: Analysis, iu: ImpliedUse) =
52-
for {
53-
a <- iu.annotateResult(typeUse(a, iu.asTypeNameNode, iu.name))
55+
def impliedTypeUse(a: Analysis, iu: ImpliedUse) = {
56+
val result = for {
57+
a <- typeUse(a, iu.asTypeNameNode, iu.name)
5458
_ <- impliedUse(a, iu, ImpliedUse.Kind.Type)
5559
} yield a
60+
iu.annotateResult(result)
61+
}
5662

5763
/** An implied use */
5864
def impliedUse(a: Analysis, iu: ImpliedUse, kind: ImpliedUse.Kind): Result =

compiler/lib/src/main/scala/analysis/CheckSemantics/CheckUses.scala

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,24 @@ object CheckUses extends BasicUseAnalyzer {
8888
val symQualifiedName = a.getQualifiedName(sym).toString
8989
val iuName = iu.name.toString
9090
// 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-
)
91+
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
107106
)
108-
}
109-
iu.annotateResult(result)
107+
)
108+
}
110109
}
111110

112111
override def defComponentAnnotatedNode(a: Analysis, aNode: Ast.Annotated[AstNode[Ast.DefComponent]]) = {

0 commit comments

Comments
 (0)