Skip to content

Commit

Permalink
Fix non-exhaustive warnings in the EveryReadIsExpression and GoReads
Browse files Browse the repository at this point in the history
I'm not sure that Borrowed types is possible there but types allow them.
As side effect, remove dead code
  • Loading branch information
Mingun committed Dec 1, 2020
1 parent 53c44ed commit 692dd6b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,34 @@ trait CommonReads extends LanguageCompiler {
*/
def attrValidateAll(attr: AttrLikeSpec) =
attr.valid.foreach(valid => attrValidate(attr.id, attr, valid))

/**
* Allocates new IO for type with known size
*
* @param id name of attribute for read
* @param bytes specifies properties of the returned sub-stream
* @param io name of the parent stream from which
* @param rep specifies the repeat pattern for the attribute
*
* @return string with allocated sub-stream name
*/
def allocateSubstream(
id: Identifier,
bytes: BytesType,
io: String,
rep: RepeatSpec,
): String = {
// we have a fixed buffer, thus we shall create separate IO for it
val rawId = RawIdentifier(id)

// Default endianness isn't required for the BytesType
attrParse2(rawId, bytes, io, rep, true, None)

this match {
case thisStore: AllocateAndStoreIO =>
thisStore.allocateIO(rawId, rep)
case thisLocal: AllocateIOLocalVar =>
thisLocal.allocateIO(rawId, rep)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,10 @@ trait EveryReadIsExpression
def attrUserTypeParse(id: Identifier, dataType: UserType, io: String, rep: RepeatSpec, defEndian: Option[FixedEndian], assignType: DataType): Unit = {
val newIO = dataType match {
case knownSizeType: UserTypeFromBytes =>
// we have a fixed buffer, thus we shall create separate IO for it
val rawId = RawIdentifier(id)
val byteType = knownSizeType.bytes

attrParse2(rawId, byteType, io, rep, true, defEndian)

val extraType = rep match {
case NoRepeat => byteType
case _ => ArrayTypeInStream(byteType)
}

this match {
case thisStore: AllocateAndStoreIO =>
thisStore.allocateIO(rawId, rep)
case thisLocal: AllocateIOLocalVar =>
thisLocal.allocateIO(rawId, rep)
}
case _: UserTypeInstream =>
allocateSubstream(id, knownSizeType.bytes, io, rep)
case knownSizeType: CalcUserTypeFromBytes =>
allocateSubstream(id, knownSizeType.bytes, io, rep)
case _: UserTypeInstream | _: CalcUserType =>
// no fixed buffer, just use regular IO
io
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,10 @@ trait GoReads extends CommonReads with ObjectOrientedLanguage with GoSwitchOps {
def attrUserTypeParse(id: Identifier, dataType: UserType, io: String, rep: RepeatSpec, defEndian: Option[FixedEndian]): Unit = {
val newIO = dataType match {
case knownSizeType: UserTypeFromBytes =>
// we have a fixed buffer, thus we shall create separate IO for it
val rawId = RawIdentifier(id)
val byteType = knownSizeType.bytes

attrParse2(rawId, byteType, io, rep, true, defEndian)

val extraType = rep match {
case NoRepeat => byteType
case _ => ArrayTypeInStream(byteType)
}

this match {
case thisStore: AllocateAndStoreIO =>
thisStore.allocateIO(rawId, rep)
case thisLocal: AllocateIOLocalVar =>
thisLocal.allocateIO(rawId, rep)
}
case _: UserTypeInstream =>
allocateSubstream(id, knownSizeType.bytes, io, rep)
case knownSizeType: CalcUserTypeFromBytes =>
allocateSubstream(id, knownSizeType.bytes, io, rep)
case _: UserTypeInstream | _: CalcUserType =>
// no fixed buffer, just use regular IO
io
}
Expand Down

0 comments on commit 692dd6b

Please sign in to comment.