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 {
};
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";
......
......@@ -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";
......
......@@ -43,6 +43,24 @@
</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">
......@@ -64,6 +82,44 @@
</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"/>
......
......@@ -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>
......@@ -84,6 +99,17 @@
</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>
......
......@@ -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();
}
}
......
......@@ -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;
......
......@@ -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);
}
......@@ -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_ */
......@@ -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
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment