Commit 2b00ec8e authored by ebensza's avatar ebensza
Browse files

xsd2ttcn: list length restriction corrected (Bug 495990)


Signed-off-by: default avatarebensza <bence.janos.szabo@ericsson.com>
parent f1d42b47
...@@ -60,6 +60,13 @@ with { ...@@ -60,6 +60,13 @@ with {
}; };
type record length(3) of XSD.String ElementWithList2 length(4)
with {
variant "list";
variant "element";
};
type record ChoiceWithList type record ChoiceWithList
{ {
union { union {
...@@ -76,6 +83,25 @@ with { ...@@ -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") type XSD.Token Ipv4 (pattern "IPV4")
with { with {
variant "name as uncapitalized"; variant "name as uncapitalized";
......
...@@ -44,6 +44,13 @@ module www_example_org_list_simpletype { ...@@ -44,6 +44,13 @@ module www_example_org_list_simpletype {
import from XSD all; 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 type record of enumerated
{ {
orange, orange,
...@@ -114,6 +121,13 @@ with { ...@@ -114,6 +121,13 @@ with {
}; };
type record length(3) of XSD.Float ElementWithList
with {
variant "list";
variant "element";
};
} }
with { with {
encode "XML"; encode "XML";
......
...@@ -43,6 +43,24 @@ ...@@ -43,6 +43,24 @@
</xs:simpleType> </xs:simpleType>
</xs:element> </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:complexType name="ChoiceWithList">
<xs:choice> <xs:choice>
<xs:element name="Element1"> <xs:element name="Element1">
...@@ -64,6 +82,44 @@ ...@@ -64,6 +82,44 @@
</xs:choice> </xs:choice>
</xs:complexType> </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:simpleType name="ipv4">
<xs:restriction base="xs:token"> <xs:restriction base="xs:token">
<xs:pattern value="IPV4"/> <xs:pattern value="IPV4"/>
......
...@@ -4,6 +4,21 @@ ...@@ -4,6 +4,21 @@
xmlns:this="www.example.org/list/simpletype" xmlns:this="www.example.org/list/simpletype"
targetNamespace="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:element name="SimpleListEnumeration">
<xsd:simpleType> <xsd:simpleType>
<xsd:list> <xsd:list>
...@@ -84,6 +99,17 @@ ...@@ -84,6 +99,17 @@
</xsd:complexType> </xsd:complexType>
</xsd:element> </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>
......
...@@ -35,7 +35,6 @@ ComplexType::ComplexType(XMLParser * a_parser, TTCN3Module * a_module, Construct ...@@ -35,7 +35,6 @@ ComplexType::ComplexType(XMLParser * a_parser, TTCN3Module * a_module, Construct
, fromAll(false) , fromAll(false)
, max_alt(0) , max_alt(0)
, skipback(0) , skipback(0)
, list(false)
, lastType() , lastType()
, actualPath(empty_string) , actualPath(empty_string)
, actfield(this) , actfield(this)
...@@ -63,7 +62,6 @@ ComplexType::ComplexType(ComplexType & other) ...@@ -63,7 +62,6 @@ ComplexType::ComplexType(ComplexType & other)
, fromAll(other.fromAll) , fromAll(other.fromAll)
, max_alt(other.max_alt) , max_alt(other.max_alt)
, skipback(other.skipback) , skipback(other.skipback)
, list(other.list)
, lastType(other.lastType) , lastType(other.lastType)
, actualPath(other.actualPath) , actualPath(other.actualPath)
, actfield(this) , actfield(this)
...@@ -111,7 +109,6 @@ ComplexType::ComplexType(ComplexType * other) ...@@ -111,7 +109,6 @@ ComplexType::ComplexType(ComplexType * other)
, fromAll(false) , fromAll(false)
, max_alt(0) , max_alt(0)
, skipback(0) , skipback(0)
, list(false)
, lastType() , lastType()
, actualPath(empty_string) , actualPath(empty_string)
, actfield(this) , actfield(this)
...@@ -141,7 +138,6 @@ ComplexType::ComplexType(const SimpleType & other, CT_fromST c) ...@@ -141,7 +138,6 @@ ComplexType::ComplexType(const SimpleType & other, CT_fromST c)
, fromAll(false) , fromAll(false)
, max_alt(0) , max_alt(0)
, skipback(0) , skipback(0)
, list(false)
, lastType() , lastType()
, actualPath(empty_string) , actualPath(empty_string)
, actfield(this) , actfield(this)
...@@ -301,6 +297,12 @@ void ComplexType::loadWithValues() { ...@@ -301,6 +297,12 @@ void ComplexType::loadWithValues() {
complexfields.push_back(f); complexfields.push_back(f);
basefield = f; basefield = f;
actfield = 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) { } else if (cmode == CT_complextype_mode) {
setReference(atts.base); setReference(atts.base);
xsdtype = n_restriction; xsdtype = n_restriction;
...@@ -585,12 +587,14 @@ void ComplexType::loadWithValues() { ...@@ -585,12 +587,14 @@ void ComplexType::loadWithValues() {
break; break;
case n_list: case n_list:
if (parent != NULL && parent->basefield == this) { if (parent != NULL && parent->basefield == this) {
parent->list = true; parent->inList = true;
parent->SimpleType::loadWithValues(); parent->SimpleType::loadWithValues();
parent->basefield = NULL; parent->basefield = NULL;
setInvisible(); setInvisible();
break; } else if(parent != NULL) {
SimpleType::loadWithValues();
} }
break;
case n_length: case n_length:
case n_minLength: case n_minLength:
case n_maxLength: case n_maxLength:
...@@ -626,12 +630,6 @@ void ComplexType::modifyValues() { ...@@ -626,12 +630,6 @@ void ComplexType::modifyValues() {
skipback = skipback - 1; skipback = skipback - 1;
} }
//embedded simpletype with list in element
if(xsdtype == n_simpleType && list) {
list = false;
return;
}
if ( parent != NULL && if ( parent != NULL &&
(xsdtype == n_element || (xsdtype == n_element ||
...@@ -645,7 +643,7 @@ void ComplexType::modifyValues() { ...@@ -645,7 +643,7 @@ void ComplexType::modifyValues() {
xsdtype == n_attributeGroup || xsdtype == n_attributeGroup ||
xsdtype == n_extension || xsdtype == n_extension ||
xsdtype == n_restriction || xsdtype == n_restriction ||
(xsdtype == n_simpleType && !list) || (xsdtype == n_simpleType && !inList) ||
xsdtype == n_simpleContent || xsdtype == n_simpleContent ||
(xsdtype == n_sequence && skipback < 0) (xsdtype == n_sequence && skipback < 0)
)) { )) {
...@@ -659,6 +657,9 @@ void ComplexType::modifyValues() { ...@@ -659,6 +657,9 @@ void ComplexType::modifyValues() {
parent->lastType = xsdtype; parent->lastType = xsdtype;
} }
} }
if (xsdtype == n_simpleType) {
inList = false;
}
} }
void ComplexType::referenceResolving() { void ComplexType::referenceResolving() {
...@@ -1869,7 +1870,13 @@ void ComplexType::resolveSimpleTypeRestriction() { ...@@ -1869,7 +1870,13 @@ void ComplexType::resolveSimpleTypeRestriction() {
addNameSpaceAsVariant(this, ct); addNameSpaceAsVariant(this, ct);
} }
if(!basefield->parent->top){ 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(); basefield->setInvisible();
} }
} }
......
...@@ -71,9 +71,6 @@ private: ...@@ -71,9 +71,6 @@ private:
bool fromAll; bool fromAll;
unsigned max_alt; unsigned max_alt;
int skipback; int skipback;
//Special use: true if an element of a complextype is restricted to a list
// in a simpletype
bool list;
TagName lastType; TagName lastType;
Mstring actualPath; Mstring actualPath;
RootType * actfield; RootType * actfield;
......
...@@ -46,6 +46,7 @@ SimpleType::SimpleType(XMLParser * a_parser, TTCN3Module * a_module, ConstructTy ...@@ -46,6 +46,7 @@ SimpleType::SimpleType(XMLParser * a_parser, TTCN3Module * a_module, ConstructTy
, typeSubsGroup(NULL) , typeSubsGroup(NULL)
, addedToTypeSubstitution(false) , addedToTypeSubstitution(false)
, block(not_set) , block(not_set)
, inList(false)
, parent(NULL) { , parent(NULL) {
} }
...@@ -70,6 +71,7 @@ SimpleType::SimpleType(const SimpleType& other) ...@@ -70,6 +71,7 @@ SimpleType::SimpleType(const SimpleType& other)
, typeSubsGroup(other.typeSubsGroup) , typeSubsGroup(other.typeSubsGroup)
, addedToTypeSubstitution(other.addedToTypeSubstitution) , addedToTypeSubstitution(other.addedToTypeSubstitution)
, block(other.block) , block(other.block)
, inList(other.inList)
, parent(NULL) { , parent(NULL) {
length.parent = this; length.parent = this;
pattern.parent = this; pattern.parent = this;
...@@ -93,6 +95,7 @@ void SimpleType::loadWithValues() { ...@@ -93,6 +95,7 @@ void SimpleType::loadWithValues() {
setMaxOccurs(ULLONG_MAX); setMaxOccurs(ULLONG_MAX);
addVariant(V_list); addVariant(V_list);
mode = listMode; mode = listMode;
inList = true;
break; break;
case n_union: case n_union:
{ // generating complextype from simpletype { // generating complextype from simpletype
...@@ -132,7 +135,7 @@ void SimpleType::loadWithValues() { ...@@ -132,7 +135,7 @@ void SimpleType::loadWithValues() {
break; break;
} }
case n_length: case n_length:
if (mode == listMode) { if (inList && (xsdtype != n_NOTSET || mode == restrictionAfterListMode)) {
setMinOccurs(strtoull(atts.value.c_str(), NULL, 0)); setMinOccurs(strtoull(atts.value.c_str(), NULL, 0));
setMaxOccurs(strtoull(atts.value.c_str(), NULL, 0)); setMaxOccurs(strtoull(atts.value.c_str(), NULL, 0));
break; break;
...@@ -142,7 +145,7 @@ void SimpleType::loadWithValues() { ...@@ -142,7 +145,7 @@ void SimpleType::loadWithValues() {
length.modified = true; length.modified = true;
break; break;
case n_minLength: case n_minLength:
if (mode == listMode) { if (inList && (xsdtype != n_NOTSET || mode == restrictionAfterListMode)) {
setMinOccurs(strtoull(atts.value.c_str(), NULL, 0)); setMinOccurs(strtoull(atts.value.c_str(), NULL, 0));
break; break;
} }
...@@ -150,7 +153,7 @@ void SimpleType::loadWithValues() { ...@@ -150,7 +153,7 @@ void SimpleType::loadWithValues() {
length.modified = true; length.modified = true;
break; break;
case n_maxLength: case n_maxLength:
if (mode == listMode) { if (inList && (xsdtype != n_NOTSET || mode == restrictionAfterListMode)) {
setMaxOccurs(strtoull(atts.value.c_str(), NULL, 0)); setMaxOccurs(strtoull(atts.value.c_str(), NULL, 0));
break; break;
} }
...@@ -591,7 +594,7 @@ void SimpleType::referenceForST(SimpleType * found_ST) { ...@@ -591,7 +594,7 @@ void SimpleType::referenceForST(SimpleType * found_ST) {
if (construct == c_element) if (construct == c_element)
return; return;
if (mode == listMode) if (mode == listMode || mode == restrictionAfterListMode)
return; return;
if (!found_ST->builtInBase.empty()) { if (!found_ST->builtInBase.empty()) {
...@@ -605,7 +608,7 @@ void SimpleType::referenceForST(SimpleType * found_ST) { ...@@ -605,7 +608,7 @@ void SimpleType::referenceForST(SimpleType * found_ST) {
value.applyReference(found_ST->value); value.applyReference(found_ST->value);
mode = found_ST->mode; mode = found_ST->mode;
if (found_ST->mode != listMode) { if (found_ST->mode != listMode && found_ST->mode != restrictionAfterListMode) {
type.upload(found_ST->getType().convertedValue); type.upload(found_ST->getType().convertedValue);
} }
} }
...@@ -877,7 +880,7 @@ LengthType::LengthType(SimpleType * a_simpleType) ...@@ -877,7 +880,7 @@ LengthType::LengthType(SimpleType * a_simpleType)
, upper(ULLONG_MAX) { , upper(ULLONG_MAX) {
} }
void LengthType::applyReference(const LengthType & other) { void LengthType::applyReference(const LengthType & other) {
if (!modified) modified = other.modified; if (!modified) modified = other.modified;
if (other.facet_minLength > facet_minLength) facet_minLength = other.facet_minLength; if (other.facet_minLength > facet_minLength) facet_minLength = other.facet_minLength;
if (other.facet_maxLength < facet_maxLength) facet_maxLength = other.facet_maxLength; 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 ...@@ -903,6 +906,7 @@ void LengthType::applyFacets() // only for string types and list types without Q
} }
case SimpleType::extensionMode: case SimpleType::extensionMode:
case SimpleType::listMode: case SimpleType::listMode:
case SimpleType::restrictionAfterListMode:
lower = facet_minLength; lower = facet_minLength;
upper = facet_maxLength; upper = facet_maxLength;
break; break;
...@@ -1603,3 +1607,4 @@ void ValueType::printToFile(FILE * file) const { ...@@ -1603,3 +1607,4 @@ void ValueType::printToFile(FILE * file) const {
fputc(')', file); fputc(')', file);
} }
...@@ -200,7 +200,8 @@ public: ...@@ -200,7 +200,8 @@ public:
noMode, noMode,
restrictionMode, restrictionMode,
extensionMode, extensionMode,
listMode listMode,
restrictionAfterListMode
}; };
protected: protected:
...@@ -236,6 +237,12 @@ protected: ...@@ -236,6 +237,12 @@ protected:
bool addedToTypeSubstitution; bool addedToTypeSubstitution;
BlockValue block; 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 //Element substitution
void addToSubstitutions(); void addToSubstitutions();
...@@ -370,6 +377,10 @@ public: ...@@ -370,6 +377,10 @@ public:
return block; return block;
} }
void setList(const bool value) {
inList = value;
}
void addToNameDepList(SimpleType * t) { void addToNameDepList(SimpleType * t) {
//If the type has a substitution, we add the namedep to the substitution //If the type has a substitution, we add the namedep to the substitution
if(subsGroup != NULL && this != (SimpleType*)subsGroup){ if(subsGroup != NULL && this != (SimpleType*)subsGroup){
...@@ -386,3 +397,4 @@ public: ...@@ -386,3 +397,4 @@ public:
}; };
#endif /* SIMPLETYPE_H_ */ #endif /* SIMPLETYPE_H_ */
...@@ -353,7 +353,15 @@ void XMLParser::endelementHandler(const xmlChar * localname) { ...@@ -353,7 +353,15 @@ void XMLParser::endelementHandler(const xmlChar * localname) {
tag == n_documentation){ tag == n_documentation){
inside_annotation.pop_back(); 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; --actualDepth;
if (actualDepth == 0 || actualDepth == 1) { if (actualDepth == 0 || actualDepth == 1) {
...@@ -836,3 +844,4 @@ void XMLParser::TagAttributes::fillUp(TagAttributeName * att_name_e, Mstring * a ...@@ -836,3 +844,4 @@ void XMLParser::TagAttributes::fillUp(TagAttributeName * att_name_e, Mstring * a
} }
} }
} }
Markdown is supported
0% or