Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions compiler/lib/src/main/scala/analysis/Analysis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -352,24 +352,12 @@ case class Analysis(
def getNonnegativeIntValueOpt[T](nodeOpt: Option[AstNode[T]]): Result.Result[Option[Int]] =
Result.mapOpt(nodeOpt, (node: AstNode[T]) => getNonnegativeIntValue(node.id))

/** Gets a bounded array size from an AST node */
def getBoundedArraySize(id: AstNode.Id): Result.Result[Int] =
for {
v <- getIntValue(id)
size <- if (v >= 1 && v <= Error.maxArraySize)
Right(v.intValue) else {
val loc = Locations.get(id)
Left(SemanticError.InvalidArraySize(loc, v))
}
}
yield size

/** Gets an optional unbounded array size */
def getUnboundedArraySizeOpt[T](nodeOpt: Option[AstNode[T]]): Result.Result[Option[Int]] =
Result.mapOpt(nodeOpt, (node: AstNode[T]) => getUnboundedArraySize(node.id))
/** Gets an optional array size */
def getArraySizeOpt[T](nodeOpt: Option[AstNode[T]]): Result.Result[Option[Int]] =
Result.mapOpt(nodeOpt, (node: AstNode[T]) => getArraySize(node.id))

/** Gets an unbounded array size from an AST node */
def getUnboundedArraySize(id: AstNode.Id): Result.Result[Int] =
/** Gets an array size from an AST node */
def getArraySize(id: AstNode.Id): Result.Result[Int] =
for {
v <- getIntValue(id)
size <- if (v >= 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object FinalizeTypeDefs
// Visit the element type of A, to update its members
eltType <- TypeVisitor.ty(a, arrayType.anonArray.eltType)
// Update the size and element type in A
size <- a.getBoundedArraySize(data.size.id)
size <- a.getArraySize(data.size.id)
arrayType <- {
val anonArray = Type.AnonArray(Some(size.toInt), eltType)
Right(arrayType.copy(anonArray = anonArray))
Expand Down Expand Up @@ -137,7 +137,7 @@ object FinalizeTypeDefs
// Compute the sizes
sizes <- {
def mapping(member: Ast.StructTypeMember) = for {
intOpt <- a.getUnboundedArraySizeOpt(member.size)
intOpt <- a.getArraySizeOpt(member.size)
} yield (intOpt.map(n => (member.name, n)))
for (pairs <- Result.map(members, mapping)) yield {
pairs.filter(_.isDefined).map(_.get).toMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ object PortInstance {
private def getArraySize(a: Analysis, sizeOpt: Option[AstNode[Ast.Expr]]):
Result.Result[Int] =
sizeOpt match {
case Some(size) => a.getUnboundedArraySize(size.id)
case Some(size) => a.getArraySize(size.id)
case None => Right(1)
}

Expand Down
Loading