mbeckerle commented on code in PR #1366:
URL: https://github.com/apache/daffodil/pull/1366#discussion_r1842661089
##########
daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaSet.scala:
##########
@@ -540,8 +540,51 @@ final class SchemaSet private (
.flatMap(_.defineVariables)
.union(predefinedVars)
+ // propagated to referenced element propCache
+ private lazy val propagateReferenceeAndTypeUsedProperties = {
+ root.allComponents.collect {
+ case ref: AbstractElementRef =>
+ val referent = ref.optReferredToComponent.get
+ ref.propCache.foreach(kv =>
+ // if the referent or its simpleType carries the property then add it
+ if (
+ referent.formatAnnotation.justThisOneProperties.contains(kv._1)
+ || referent.optSimpleType.exists {
+ case std: SimpleTypeDefBase =>
+ std.formatAnnotation.justThisOneProperties.contains(kv._1)
+ case _ => false
+ }
+ ) {
+ // only add the used properties that the referent carries, not any
local properties that aren't shared
+ referent.propCache.put(kv._1, kv._2)
+ }
+ )
+ case ele: ElementDeclMixin =>
+ val ost = ele.optSimpleType
+ if (ost.isDefined && ost.get.isInstanceOf[SimpleTypeDefBase]) {
+ val std = ost.get.asInstanceOf[SimpleTypeDefBase]
+ if (std.propCache.nonEmpty) {
+ // if it has used properties transfer it to the element that's
using it
+ // we don't need the check for what is carries since all
properties on the type are shared
+ // by the element using it
+ std.propCache.foreach(kv => ele.propCache.put(kv._1, kv._2))
+ }
+ // copy the used properties from the element to the type
+ ele.propCache.foreach(kv =>
+ if (std.formatAnnotation.justThisOneProperties.contains(kv._1)) {
+ // only add the used properties that the simple type carries,
not any local element properties that aren't shared
+ std.propCache.put(kv._1, kv._2)
+ }
+ )
+ }
+ case _ => // do nothing
+ }
+ }
+
private lazy val checkUnusedProperties = LV('hasUnusedProperties) {
Review Comment:
Needs same scaladoc warning as is on the AnnotatedSchemaComponent val of the
same name. This pass must happen after all other compilation has been done.
##########
daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaSet.scala:
##########
@@ -540,8 +540,51 @@ final class SchemaSet private (
.flatMap(_.defineVariables)
.union(predefinedVars)
+ // propagated to referenced element propCache
Review Comment:
Please give real scaladoc to this method and explain the problem (which I
think is that a simpleType could have properties that we only know are used due
to an element decl that references that type.
Explain the algorithm being used to determine properties that are unused.
The way you are using and populating the propCache to get this answer and how
information moves from one object's propCache to another is needs explanation.
The code here is simpler than I expected. Nothing is chasing the simpleType
base chains for example, and there is some reason why we don't have to do that.
You have a case for element refs and one for element decls, but nothing for
simple types?
##########
daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaSet.scala:
##########
@@ -540,8 +540,51 @@ final class SchemaSet private (
.flatMap(_.defineVariables)
.union(predefinedVars)
+ // propagated to referenced element propCache
+ private lazy val propagateReferenceeAndTypeUsedProperties = {
+ root.allComponents.collect {
+ case ref: AbstractElementRef =>
+ val referent = ref.optReferredToComponent.get
+ ref.propCache.foreach(kv =>
+ // if the referent or its simpleType carries the property then add it
+ if (
+ referent.formatAnnotation.justThisOneProperties.contains(kv._1)
+ || referent.optSimpleType.exists {
+ case std: SimpleTypeDefBase =>
+ std.formatAnnotation.justThisOneProperties.contains(kv._1)
+ case _ => false
+ }
+ ) {
+ // only add the used properties that the referent carries, not any
local properties that aren't shared
+ referent.propCache.put(kv._1, kv._2)
+ }
+ )
+ case ele: ElementDeclMixin =>
+ val ost = ele.optSimpleType
+ if (ost.isDefined && ost.get.isInstanceOf[SimpleTypeDefBase]) {
+ val std = ost.get.asInstanceOf[SimpleTypeDefBase]
+ if (std.propCache.nonEmpty) {
+ // if it has used properties transfer it to the element that's
using it
+ // we don't need the check for what is carries since all
properties on the type are shared
Review Comment:
typo in comment "is carries" -> "it carries"
##########
daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaSet.scala:
##########
@@ -540,8 +540,51 @@ final class SchemaSet private (
.flatMap(_.defineVariables)
.union(predefinedVars)
+ // propagated to referenced element propCache
+ private lazy val propagateReferenceeAndTypeUsedProperties = {
+ root.allComponents.collect {
+ case ref: AbstractElementRef =>
+ val referent = ref.optReferredToComponent.get
Review Comment:
Is a referent the one doing the referring, or the one referred to? Ambiguous
to me. Explain val referent with a comment.
--
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]