bsloane1650 commented on a change in pull request #259: Incremental progress on 
schema compilation space/speed issue.
URL: https://github.com/apache/incubator-daffodil/pull/259#discussion_r303222691
 
 

 ##########
 File path: 
daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions3.tdml
 ##########
 @@ -0,0 +1,400 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<tdml:testSuite
+ suiteName="expressions3"
+ xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData";
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+ xmlns:xs="http://www.w3.org/2001/XMLSchema";
+ xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/";
+ xmlns:dfdlx="http://www.ogf.org/dfdl/dfdl-1.0/extensions";
+ xmlns:ex="http://example.com";
+ xmlns:fn="http://www.w3.org/2005/xpath-functions";
+ defaultRoundTrip="true">
+
+  <tdml:defineSchema name="s1" elementFormDefault="unqualified">
+    <xs:include 
schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+    <dfdl:format ref="ex:GeneralFormat" lengthKind="delimited"/>
+
+    <xs:group name="g">
+      <!-- 
+        The path expression below is going to have different type
+        elements for the different instances of this group in the 
+        final schema. 
+        
+        Ultimately they all are converted to string.
+       -->
+      <xs:sequence>
+      <xs:choice dfdl:choiceDispatchKey="{ ../foo/bar }">
+        <xs:element name="c1" type="xs:string" dfdl:choiceBranchKey="1" />
+        <xs:element name="c2" type="xs:string" dfdl:choiceBranchKey="2" />
+      </xs:choice>
+      </xs:sequence>
+    </xs:group>
+
+    <xs:element name="r">
+      <xs:complexType>
+        <xs:sequence dfdl:separator="|">
+          <xs:element name="e1">
+            <xs:complexType>
+              <xs:sequence>
+                <xs:element name="foo">
+                  <xs:complexType>
+                    <xs:sequence dfdl:separator="|">
+                      <xs:element name="bar" type="xs:string" />
+                      <xs:group ref="ex:g" />
+                    </xs:sequence>
+                  </xs:complexType>
+                </xs:element>
+              </xs:sequence>
+            </xs:complexType>
+          </xs:element>
+          <xs:element name="e2">
+            <xs:complexType>
+              <xs:sequence>
+                <xs:element name="foo">
+                  <xs:complexType>
+                    <xs:sequence dfdl:separator="|">
+                      <xs:element name="bar" type="xs:int" />
+                      <xs:group ref="ex:g" />
+                    </xs:sequence>
+                  </xs:complexType>
+                </xs:element>
+              </xs:sequence>
+            </xs:complexType>
+          </xs:element>
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+ </tdml:defineSchema>
+
+  <tdml:parserTestCase name="test_polymorphic_expr_1" model="s1" root="r"
+    description="Polymorphic path expression">
+    <tdml:document>1|a|2|b</tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <ex:r>
+          <e1>
+            <foo>
+              <bar>1</bar>
+              <c1>a</c1>
+            </foo>
+          </e1>
+          <e2>
+            <foo>
+              <bar>2</bar>
+              <c2>b</c2>
+            </foo>
+          </e2>
+        </ex:r>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+    <tdml:warnings>
+      <tdml:warning>should be manually cast</tdml:warning>  
+    </tdml:warnings>
+  </tdml:parserTestCase>
+
+  <tdml:defineSchema name="s2a" elementFormDefault="unqualified">
+    <xs:include 
schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+    <dfdl:format ref="ex:GeneralFormat" lengthKind="delimited"/>
+
+    <xs:group name="g">
+      <!-- 
+        The path expression below is depending on the ability to 
+        compile polymorphically. The expression ../foo/hdr is always an int.
+        The expression ../foo/bar is a string, or an integer depending on 
+        the context. 
+       -->
+      <xs:sequence>
+      <xs:choice dfdl:choiceDispatchKey="{ 
+         xs:string(if (../foo/hdr eq 1) 
+           then xs:int( fn:round( xs:double( ../foo/bar) ) )
+           else xs:int( fn:round( xs:double( ../foo/bar) ) + 1 ) )}">
+        <xs:element name="c1" type="xs:string" dfdl:choiceBranchKey="1" />
+        <xs:element name="c2" type="xs:string" dfdl:choiceBranchKey="2" />
+      </xs:choice>
+      </xs:sequence>
+    </xs:group>
+
+    <xs:element name="r">
+      <xs:complexType>
+        <xs:sequence dfdl:separator="|">
+          <xs:element name="e1">
+            <xs:complexType>
+              <xs:sequence>
+                <xs:element name="foo">
+                  <xs:complexType>
+                    <xs:sequence dfdl:separator="|">
+                      <xs:element name="hdr" type="xs:int"/>
+                      <xs:element name="bar" type="xs:float" />
+                      <xs:group ref="ex:g" />
+                    </xs:sequence>
+                  </xs:complexType>
+                </xs:element>
+              </xs:sequence>
+            </xs:complexType>
+          </xs:element>
+          <xs:element name="e2">
+            <xs:complexType>
+              <xs:sequence>
+                <xs:element name="foo">
+                  <xs:complexType>
+                    <xs:sequence dfdl:separator="|">
+                      <xs:element name="hdr" type="xs:int"/>
+                      <xs:element name="bar" type="xs:int" />
+                      <xs:group ref="ex:g" />
+                    </xs:sequence>
+                  </xs:complexType>
+                </xs:element>
+              </xs:sequence>
+            </xs:complexType>
+          </xs:element>
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+ </tdml:defineSchema>
+
+  <tdml:parserTestCase name="test_polymorphic_expr_2a" model="s2a" root="r"
+    description="Polymorphic path expression">
+    <tdml:document>1|1|a|2|1|b</tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <ex:r>
+          <e1>
+            <foo>
+              <hdr>1</hdr>
+              <bar>1.0</bar>
+              <c1>a</c1>
+            </foo>
+          </e1>
+          <e2>
+            <foo>
+              <hdr>2</hdr>
+              <bar>1</bar>
+              <c2>b</c2>
+            </foo>
+          </e2>
+        </ex:r>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+  
+  <tdml:defineSchema name="s2b" elementFormDefault="unqualified">
+    <xs:include 
schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+    <dfdl:format ref="ex:GeneralFormat" lengthKind="delimited"/>
+
+    <xs:group name="g">
+      <!-- 
+        The path expression below is depending on the ability to 
+        compile polymorphically. The expression ../foo/hdr is always an int.
+        The expression ../foo/bar is a string, or an integer depending on 
+        the context. 
+       -->
+      <xs:sequence>
+      <xs:choice dfdl:choiceDispatchKey="{ 
+         xs:string(if (../foo/hdr eq 1) 
+           then xs:int( ../foo/bar )
+           else xs:int( ../foo/bar + 1 ) )}">
+        <xs:element name="c1" type="xs:string" dfdl:choiceBranchKey="1" />
+        <xs:element name="c2" type="xs:string" dfdl:choiceBranchKey="2" />
+      </xs:choice>
+      </xs:sequence>
+    </xs:group>
+
+    <xs:element name="r">
+      <xs:complexType>
+        <xs:sequence dfdl:separator="|">
+          <xs:element name="e1">
+            <xs:complexType>
+              <xs:sequence>
+                <xs:element name="foo">
+                  <xs:complexType>
+                    <xs:sequence dfdl:separator="|">
+                      <xs:element name="hdr" type="xs:int"/>
+                      <xs:element name="bar" type="xs:float" />
+                      <xs:group ref="ex:g" />
+                    </xs:sequence>
+                  </xs:complexType>
+                </xs:element>
+              </xs:sequence>
+            </xs:complexType>
+          </xs:element>
+          <xs:element name="e2">
+            <xs:complexType>
+              <xs:sequence>
+                <xs:element name="foo">
+                  <xs:complexType>
+                    <xs:sequence dfdl:separator="|">
+                      <xs:element name="hdr" type="xs:int"/>
+                      <xs:element name="bar" type="xs:int" />
+                      <xs:group ref="ex:g" />
+                    </xs:sequence>
+                  </xs:complexType>
+                </xs:element>
+              </xs:sequence>
+            </xs:complexType>
+          </xs:element>
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+ </tdml:defineSchema>
+
+  <tdml:parserTestCase name="test_polymorphic_expr_2b" model="s2b" root="r"
+    description="Polymorphic path expression">
+    <tdml:document>1|1|a|2|1|b</tdml:document>
+    <tdml:errors>
+      <tdml:error>Schema Definition Error</tdml:error>
+      <tdml:error>expression ../foo/bar</tdml:error>
+      <tdml:error>SignedNumeric</tdml:error>
+      <tdml:error>cannot be converted to xs:int</tdml:error>
+      <tdml:error>element bar with xs:int type at Location</tdml:error>
+    </tdml:errors>
+  </tdml:parserTestCase>
+    
+  
+  <tdml:defineSchema name="s3" elementFormDefault="unqualified">
+    <xs:include 
schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+    <dfdl:format ref="ex:GeneralFormat" lengthKind="delimited"/>
+
+    <xs:group name="g">
+      <!-- 
+        The path expression below is depending on the ability to 
+        compile polymorphically. The expression ../foo/hdr is always an int.
+        The expression ../foo/bar is a string, or a complex type depending on 
+        the context. So this shouldn't compile since you can't do math on 
+        a complex type. 
+       -->
+      <xs:sequence>
+      <xs:choice dfdl:choiceDispatchKey="{ 
+         xs:string(if (../foo/hdr eq 1) 
+           then xs:int( ../foo/bar )
+           else xs:int( ../foo/bar + 1 ) )}">
+        <xs:element name="c1" type="xs:string" dfdl:choiceBranchKey="1" />
+        <xs:element name="c2" type="xs:string" dfdl:choiceBranchKey="2" />
+      </xs:choice>
+      </xs:sequence>
+    </xs:group>
+
+    <xs:element name="r">
+      <xs:complexType>
+        <xs:sequence dfdl:separator="|">
+          <xs:element name="e1">
+            <xs:complexType>
+              <xs:sequence>
+                <xs:element name="foo">
+                  <xs:complexType>
+                    <xs:sequence dfdl:separator="|">
+                      <xs:element name="hdr" type="xs:int"/>
+                      <xs:element name="bar" type="xs:float" />
+                      <xs:group ref="ex:g" />
+                    </xs:sequence>
+                  </xs:complexType>
+                </xs:element>
+              </xs:sequence>
+            </xs:complexType>
+          </xs:element>
+          <xs:element name="e2">
+            <xs:complexType>
+              <xs:sequence>
+                <xs:element name="foo">
+                  <xs:complexType>
+                    <xs:sequence dfdl:separator="|">
+                      <xs:element name="hdr" type="xs:int"/>
+                      <xs:element name="bar">
+                        <xs:complexType>
+                          <xs:sequence>
+                            <xs:element name="quux" type="xs:int" />
+                          </xs:sequence>
+                        </xs:complexType>
+                      </xs:element>
+                      <xs:group ref="ex:g" />
+                    </xs:sequence>
+                  </xs:complexType>
+                </xs:element>
+              </xs:sequence>
+            </xs:complexType>
+          </xs:element>
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+ </tdml:defineSchema>
+
+  <tdml:parserTestCase name="test_polymorphic_expr_3" model="s3" root="r"
+    description="Polymorphic path expression">
+    <tdml:document>1|1|a|2|1|b</tdml:document>
+    <tdml:errors>
+      <tdml:error>Schema Definition Error</tdml:error>
+      <tdml:error>cannot be converted to xs:int</tdml:error>
+      <tdml:error>Left operand for operator '+' must have numeric 
type</tdml:error>
 
 Review comment:
   We should add this to the test; as this seems like a place where it would be 
easy to accidentally break our diagnostics without noticing.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to