stevedlawrence commented on code in PR #1098:
URL: https://github.com/apache/daffodil/pull/1098#discussion_r1367415838
##########
daffodil-codegen-c/src/main/scala/org/apache/daffodil/codegen/c/generators/BinaryValueCodeGenerator.scala:
##########
@@ -50,6 +51,53 @@ trait BinaryValueCodeGenerator {
if (e.hasFixedValue && e.fixedValueAsString.nonEmpty) {
validateFixed(deref)
}
+
+ // Check if the element's value is restricted to a set of enumerations
+ if (e.typeDef.optRestriction.exists(_.hasEnumeration)) {
+ // Split the enumeration values into an array of strings ready to be
inserted into the C code
+ val enumerationValues =
e.typeDef.optRestriction.flatMap(_.enumerationValues).get
+ val enums = enumerationValues.split('|').map(_.replaceAll("\\\\(\\W)",
"$1"))
+ // Call another function which can be redefined differently if necessary
+ valueValidateEnumeration(e, deref, enums, cgState)
+ }
+
+ // Check if the element's value is restricted to a range (we will need to
handle any
+ // combination of inclusive and exclusive endpoints when generating our C
expression)
+ val hasMinExclusive = e.typeDef.optRestriction.exists(_.hasMinExclusive)
+ val hasMinInclusive = e.typeDef.optRestriction.exists(_.hasMinInclusive)
+ val hasMaxExclusive = e.typeDef.optRestriction.exists(_.hasMaxExclusive)
+ val hasMaxInclusive = e.typeDef.optRestriction.exists(_.hasMaxInclusive)
+ if (hasMinExclusive || hasMinInclusive || hasMaxExclusive ||
hasMaxInclusive) {
+ // Generate the minimum endpoint comparison
+ val minEndpoint = if (hasMinExclusive) {
+ val endpoint = e.typeDef.optRestriction.map(_.minExclusiveValue).get
+ s"""> $endpoint"""
+ } else if (hasMinInclusive) {
+ val endpoint = e.typeDef.optRestriction.map(_.minInclusiveValue).get
+ // Avoid unsigned >= 0 comparisons (causes gcc warnings)
+ e.optPrimType.get match {
+ case PrimType.UnsignedByte | PrimType.UnsignedShort |
PrimType.UnsignedInt |
+ PrimType.UnsignedLong | PrimType.NonNegativeInteger if
endpoint.toString == "0" =>
+ ""
Review Comment:
Could also consider making it a `Option[String]`, that might be a bit more
self descriptive, and could maybe make later logic more functional, e.g.
`(minEndpoint.toSeq ++ maxEndpoint.toSeq).mkString(" && ")`. That might be too
one-liner-y but using Options in general might make things a bit clear and self
descriptive.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]