xsd2ttcn: list length restriction corrected (Bug 495990)
authorebensza <bence.janos.szabo@ericsson.com>
Mon, 20 Jun 2016 10:19:30 +0000 (12:19 +0200)
committerebensza <bence.janos.szabo@ericsson.com>
Tue, 21 Jun 2016 10:34:28 +0000 (12:34 +0200)
Signed-off-by: ebensza <bence.janos.szabo@ericsson.com>
regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_list_complextype_e.ttcn
regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_list_simpletype_e.ttcn
regression_test/XML/XmlWorkflow/xsd/list_complextype.xsd
regression_test/XML/XmlWorkflow/xsd/list_simpletype.xsd
xsdconvert/ComplexType.cc
xsdconvert/ComplexType.hh
xsdconvert/SimpleType.cc
xsdconvert/SimpleType.hh
xsdconvert/XMLParser.cc

index 1bf29018a6b24eb6f120ff4e33cc3f8899389bbb..7f075be61e0fb257ae6ee90eb9273b67f93708c2 100644 (file)
@@ -60,6 +60,13 @@ with {
 };
 
 
+type record length(3) of XSD.String ElementWithList2 length(4)
+with {
+  variant "list";
+  variant "element";
+};
+
+
 type record ChoiceWithList
 {
        union {
@@ -76,6 +83,25 @@ with {
 };
 
 
+type record ChoiceWithList2
+{
+       union {
+               record length(3) of XSD.Float element1,
+               record of XSD.String element2,
+               record length(3) of XSD.String element3 length(4)
+       } choice
+}
+with {
+  variant (choice) "untagged";
+  variant (choice.element1) "name as capitalized";
+  variant (choice.element1) "list";
+  variant (choice.element2) "name as capitalized";
+  variant (choice.element2) "list";
+  variant (choice.element3) "name as capitalized";
+  variant (choice.element3) "list";
+};
+
+
 type XSD.Token Ipv4 (pattern "IPV4")
 with {
   variant "name as uncapitalized";
index 768f00dd264cb3f95fcb354d488102cfe74826f2..e9ab5da14b41eb51b0c4082f52162cbfadea62f5 100644 (file)
@@ -44,6 +44,13 @@ module www_example_org_list_simpletype {
 import from XSD all;
 
 
+type record length(3) of XSD.String ListLength length(4)
+with {
+  variant "name as uncapitalized";
+  variant "list";
+};
+
+
 type record of enumerated
 {
        orange,
@@ -114,6 +121,13 @@ with {
 };
 
 
+type record length(3) of XSD.Float ElementWithList
+with {
+  variant "list";
+  variant "element";
+};
+
+
 }
 with {
   encode "XML";
index 1889d039dc57a0e0c977842df4f356d6add1937f..f69db00d8b818067fa61b7d3a34031c787f4da15 100644 (file)
        </xs:simpleType>
 </xs:element>
 
+<xs:element name="ElementWithList2">
+       <xs:simpleType>
+               <xs:restriction>
+                       <xs:simpleType>
+                               <xs:list>
+                                       <xs:simpleType>
+                                               <xs:restriction base="xs:string">
+                                                       <xs:length value="4" />
+                                               </xs:restriction>
+                                       </xs:simpleType>
+                               </xs:list>    
+                       </xs:simpleType>
+                       <xs:minLength value="3" />
+                       <xs:maxLength value="3" />
+               </xs:restriction>
+       </xs:simpleType>
+</xs:element>
+
 <xs:complexType name="ChoiceWithList">
        <xs:choice>
                <xs:element name="Element1">
        </xs:choice>
 </xs:complexType>
 
+<xs:complexType name="ChoiceWithList2">
+       <xs:choice>
+               <xs:element name="Element1">
+                       <xs:simpleType>
+                               <xs:restriction>
+                                       <xs:simpleType>
+                                               <xs:list itemType="xs:float" />
+                                       </xs:simpleType>
+                                       <xs:minLength value="3" />
+                                       <xs:maxLength value="3" />
+                               </xs:restriction>
+                       </xs:simpleType>
+               </xs:element>
+               <xs:element name="Element2">
+                       <xs:simpleType>
+                               <xs:list itemType="xs:string" />
+                       </xs:simpleType>
+               </xs:element>
+               <xs:element name="Element3">
+                       <xs:simpleType>
+                               <xs:restriction>
+                                       <xs:simpleType>
+                                               <xs:list>
+                                                       <xs:simpleType>
+                                                               <xs:restriction base="string">
+                                                                       <xs:length value="4" />
+                                                               </xs:restriction>
+                                                       </xs:simpleType>
+                                               </xs:list> 
+                                       </xs:simpleType>
+                                       <xs:minLength value="3" />
+                                       <xs:maxLength value="3" />
+                               </xs:restriction>
+                       </xs:simpleType>
+               </xs:element>
+       </xs:choice>
+</xs:complexType>
+
 <xs:simpleType name="ipv4">
        <xs:restriction base="xs:token">
                <xs:pattern value="IPV4"/>
index 6cd1129b599e9647fc3043df4e3693cbc3adda20..b67ea6c123e91b4233a2fbffcdd2bca5665cb34a 100644 (file)
@@ -4,6 +4,21 @@
  xmlns:this="www.example.org/list/simpletype"
  targetNamespace="www.example.org/list/simpletype">
 
+<xsd:simpleType name="listLength">
+       <xsd:restriction>
+               <xsd:simpleType>
+                       <xsd:list>
+                               <xsd:simpleType>
+                                       <xsd:restriction base="xsd:string">
+                                               <xsd:length value="4" />
+                                       </xsd:restriction>
+                               </xsd:simpleType>
+                       </xsd:list>    
+               </xsd:simpleType>
+               <xsd:length value="3"/>
+       </xsd:restriction>
+</xsd:simpleType>
+
 <xsd:element name="SimpleListEnumeration">
        <xsd:simpleType>
                <xsd:list>
        </xsd:complexType>
 </xsd:element>
 
+<xsd:element name="ElementWithList">
+       <xsd:simpleType>
+               <xsd:restriction>
+                       <xsd:simpleType>
+                               <xsd:list itemType="xsd:float" />
+                       </xsd:simpleType>
+                       <xsd:minLength value="3" />
+                       <xsd:maxLength value="3" />
+               </xsd:restriction>
+       </xsd:simpleType>
+</xsd:element>
 
 
 
index 7c56c8955f0a97a3f37a040fbb9d15b9403dce25..130189a24991342fa8f41cf844505eac48c68bfb 100644 (file)
@@ -35,7 +35,6 @@ ComplexType::ComplexType(XMLParser * a_parser, TTCN3Module * a_module, Construct
 , fromAll(false)
 , max_alt(0)
 , skipback(0)
-, list(false)
 , lastType()
 , actualPath(empty_string)
 , actfield(this)
@@ -63,7 +62,6 @@ ComplexType::ComplexType(ComplexType & other)
 , fromAll(other.fromAll)
 , max_alt(other.max_alt)
 , skipback(other.skipback)
-, list(other.list)
 , lastType(other.lastType)
 , actualPath(other.actualPath)
 , actfield(this)
@@ -111,7 +109,6 @@ ComplexType::ComplexType(ComplexType * other)
 , fromAll(false)
 , max_alt(0)
 , skipback(0)
-, list(false)
 , lastType()
 , actualPath(empty_string)
 , actfield(this)
@@ -141,7 +138,6 @@ ComplexType::ComplexType(const SimpleType & other, CT_fromST c)
 , fromAll(false)
 , max_alt(0)
 , skipback(0)
-, list(false)
 , lastType()
 , actualPath(empty_string)
 , actfield(this)
@@ -301,6 +297,12 @@ void ComplexType::loadWithValues() {
         complexfields.push_back(f);
         basefield = f;
         actfield = f;
+        
+        // If it is a restriction of a list, then no new basefield will be 
+        // present, to we apply the references to the parent.
+        if(parent != NULL && parent->inList) {
+          parent->applyReference(*f, true);
+        }
       } else if (cmode == CT_complextype_mode) {
         setReference(atts.base);
         xsdtype = n_restriction;
@@ -585,12 +587,14 @@ void ComplexType::loadWithValues() {
       break;
     case n_list:
       if (parent != NULL && parent->basefield == this) {
-        parent->list = true;
+        parent->inList = true;
         parent->SimpleType::loadWithValues();
         parent->basefield = NULL;
         setInvisible();
-        break;
+      } else if(parent != NULL) {
+        SimpleType::loadWithValues();
       }
+      break;
     case n_length:
     case n_minLength:
     case n_maxLength:
@@ -626,12 +630,6 @@ void ComplexType::modifyValues() {
     skipback = skipback - 1;
   }
   
-  //embedded simpletype with list in element
-  if(xsdtype == n_simpleType && list) {
-    list = false;
-    return;
-  }
-  
 
   if ( parent != NULL && 
       (xsdtype == n_element || 
@@ -645,7 +643,7 @@ void ComplexType::modifyValues() {
        xsdtype == n_attributeGroup || 
        xsdtype == n_extension || 
        xsdtype == n_restriction || 
-       (xsdtype == n_simpleType && !list) || 
+       (xsdtype == n_simpleType && !inList) || 
        xsdtype == n_simpleContent ||
        (xsdtype == n_sequence && skipback < 0)
       )) {
@@ -659,6 +657,9 @@ void ComplexType::modifyValues() {
       parent->lastType = xsdtype;
     }
   }
+  if (xsdtype == n_simpleType) {
+    inList = false;
+  }
 }
 
 void ComplexType::referenceResolving() {
@@ -1869,7 +1870,13 @@ void ComplexType::resolveSimpleTypeRestriction() {
       addNameSpaceAsVariant(this, ct);
     }
     if(!basefield->parent->top){
-      applyReference(*basefield, true);
+      // This is the case of restriction -> list -> simpletype -> restriction
+      // we have to apply the reference to the parent's parent.
+      if(basefield->parent->parent != NULL && !basefield->parent->isVisible()) {
+        basefield->parent->parent->applyReference(*basefield, true);
+      } else {
+        applyReference(*basefield, true);
+      }
       basefield->setInvisible();
     }
   }
index 08ad6568be7a591c09af10702e2f9ae19066e687..7ce650dd176763528ec53cd9bca3ceae089df3dd 100644 (file)
@@ -71,9 +71,6 @@ private:
   bool fromAll;
   unsigned max_alt;
   int skipback;
-  //Special use: true if an element of a complextype is restricted to a list
-  // in a simpletype
-  bool list;
   TagName lastType;
   Mstring actualPath;
   RootType * actfield;
index 73a45fd5cd2e03cf6c95d6e98a6e552337ca434f..5021f7e2ea420e1c4187ff1492d1215498d97845 100644 (file)
@@ -46,6 +46,7 @@ SimpleType::SimpleType(XMLParser * a_parser, TTCN3Module * a_module, ConstructTy
 , typeSubsGroup(NULL)
 , addedToTypeSubstitution(false)
 , block(not_set)
+, inList(false)
 , parent(NULL) {
 }
 
@@ -70,6 +71,7 @@ SimpleType::SimpleType(const SimpleType& other)
 , typeSubsGroup(other.typeSubsGroup)
 , addedToTypeSubstitution(other.addedToTypeSubstitution)
 , block(other.block)
+, inList(other.inList)
 , parent(NULL) {
   length.parent = this;
   pattern.parent = this;
@@ -93,6 +95,7 @@ void SimpleType::loadWithValues() {
       setMaxOccurs(ULLONG_MAX);
       addVariant(V_list);
       mode = listMode;
+      inList = true;
       break;
     case n_union:
     { // generating complextype from simpletype
@@ -132,7 +135,7 @@ void SimpleType::loadWithValues() {
       break;
     }
     case n_length:
-      if (mode == listMode) {
+       if (inList && (xsdtype != n_NOTSET || mode == restrictionAfterListMode)) {
         setMinOccurs(strtoull(atts.value.c_str(), NULL, 0));
         setMaxOccurs(strtoull(atts.value.c_str(), NULL, 0));
         break;
@@ -142,7 +145,7 @@ void SimpleType::loadWithValues() {
       length.modified = true;
       break;
     case n_minLength:
-      if (mode == listMode) {
+      if (inList && (xsdtype != n_NOTSET || mode == restrictionAfterListMode)) {
         setMinOccurs(strtoull(atts.value.c_str(), NULL, 0));
         break;
       }
@@ -150,7 +153,7 @@ void SimpleType::loadWithValues() {
       length.modified = true;
       break;
     case n_maxLength:
-      if (mode == listMode) {
+      if (inList && (xsdtype != n_NOTSET || mode == restrictionAfterListMode)) {
         setMaxOccurs(strtoull(atts.value.c_str(), NULL, 0));
         break;
       }
@@ -591,7 +594,7 @@ void SimpleType::referenceForST(SimpleType * found_ST) {
   if (construct == c_element)
     return;
 
-  if (mode == listMode)
+  if (mode == listMode || mode == restrictionAfterListMode)
     return;
 
   if (!found_ST->builtInBase.empty()) {
@@ -605,7 +608,7 @@ void SimpleType::referenceForST(SimpleType * found_ST) {
   value.applyReference(found_ST->value);
 
   mode = found_ST->mode;
-  if (found_ST->mode != listMode) {
+  if (found_ST->mode != listMode && found_ST->mode != restrictionAfterListMode) {
     type.upload(found_ST->getType().convertedValue);
   }
 }
@@ -877,7 +880,7 @@ LengthType::LengthType(SimpleType * a_simpleType)
 , upper(ULLONG_MAX) {
 }
 
-void LengthType::applyReference(const LengthType & other) {
+void LengthType::applyReference(const LengthType & other) { 
   if (!modified) modified = other.modified;
   if (other.facet_minLength > facet_minLength) facet_minLength = other.facet_minLength;
   if (other.facet_maxLength < facet_maxLength) facet_maxLength = other.facet_maxLength;
@@ -903,6 +906,7 @@ void LengthType::applyFacets() // only for string types and list types without Q
     }
     case SimpleType::extensionMode:
     case SimpleType::listMode:
+    case SimpleType::restrictionAfterListMode:
       lower = facet_minLength;
       upper = facet_maxLength;
       break;
@@ -1603,3 +1607,4 @@ void ValueType::printToFile(FILE * file) const {
 
   fputc(')', file);
 }
+
index 5c89eb3769e738ab1b53c2162ef4161ff294b708..9a141048f83b09bf3f420ebfcd22f4ae2f6ae423 100644 (file)
@@ -200,7 +200,8 @@ public:
     noMode,
     restrictionMode,
     extensionMode,
-    listMode
+    listMode,
+    restrictionAfterListMode
   };
 
 protected:
@@ -236,6 +237,12 @@ protected:
   bool addedToTypeSubstitution;
   BlockValue block;
   
+  //Special use: true if an element of a complexType is restricted to a list
+  // in a simpleType, or a simpleType is a restriction of a list, which is a 
+  // restriction of a simpleType
+  bool inList;
+  // We are inside a list if inList is true and mode == listMode
+  
   //Element substitution
   void addToSubstitutions();
 
@@ -370,6 +377,10 @@ public:
       return block;
   }
   
+  void setList(const bool value) {
+      inList = value;
+  }
+  
   void addToNameDepList(SimpleType * t) {
       //If the type has a substitution, we add the namedep to the substitution
       if(subsGroup != NULL && this != (SimpleType*)subsGroup){
@@ -386,3 +397,4 @@ public:
 };
 
 #endif /* SIMPLETYPE_H_ */
+
index 3a99d8576e04fe516c97e5019b13942077961681..d9857d9e99d9491edeb6dd9921f2c0507a78bf18 100644 (file)
@@ -353,7 +353,15 @@ void XMLParser::endelementHandler(const xmlChar * localname) {
      tag == n_documentation){
     inside_annotation.pop_back();
   }
-
+  
+  if(tag == n_list) {
+      if(module->hasDefinedMainType()) {
+          SimpleType& st = (SimpleType&)(module->getLastMainType());
+          if(st.getXsdtype() == n_NOTSET){
+            st.setMode(SimpleType::restrictionAfterListMode);
+          }
+      }
+  }
 
   --actualDepth;
   if (actualDepth == 0 || actualDepth == 1) {
@@ -836,3 +844,4 @@ void XMLParser::TagAttributes::fillUp(TagAttributeName * att_name_e, Mstring * a
     }
   }
 }
+
This page took 0.031868 seconds and 5 git commands to generate.