Commit b8ea0656 authored by Botond Baranyi's avatar Botond Baranyi
Browse files

xsd2ttcn: fixed handling of user-defined types whose names conflict with XSD...


xsd2ttcn: fixed handling of user-defined types whose names conflict with XSD built-in types (bug 533543)

Change-Id: I9815fc7e5528e34e292de5ac7d47c1769eb072b1
Signed-off-by: Botond Baranyi's avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent ae40d0c5
......@@ -56,7 +56,7 @@ type record List
XSD.AnyURI uri,
XSD.UnsignedInt version,
record of XSD.String attr optional,
record of XSD.Name name_list,
record of Name name_list,
record of Resource resource_list
}
with {
......@@ -80,7 +80,7 @@ type record Resource
{
XSD.AnyURI uri,
record of XSD.String attr optional,
record of XSD.Name name_list,
record of Name name_list,
record of Instance instance_list
}
with {
......
......@@ -54,7 +54,7 @@ import from XSD all;
3 Built-in Datatypes */
type XSD.Name NameA
type Name NameA
with {
variant "element";
};
......
......@@ -94,7 +94,7 @@ type XSD.AnyURI ID;
type record TypeWithIDs
{
XSD.ID id1,
ID id1,
XSD.ID id2
};
......
......@@ -97,7 +97,7 @@ void AttributeType::nameConversion_names(QualifiedNames& used_ns) {
}else {
q = QualifiedName(empty_string, empty_string);
}
XSDName2TTCN3Name(name.convertedValue, used_names, field_name, res, var);
XSDName2TTCN3Name(name.convertedValue, empty_string, used_names, field_name, res, var);
name.convertedValue = res;
addVariant(V_onlyValue, var);
if (q.name != used_names.back().name) {
......@@ -106,7 +106,7 @@ void AttributeType::nameConversion_names(QualifiedNames& used_ns) {
}
for (List<RootType*>::iterator st = nameDepList.begin(); st; st = st->Next) {
st->Data->setTypeValue(res);
st->Data->setTypeValueWoPrefix(res);
}
}
......
......@@ -235,6 +235,9 @@ void ComplexType::loadWithValues() {
const XMLParser::TagAttributes & atts = parser->getActualTagAttributes();
Mstring xsdPrefix = module->getxmlSchemaPrefixes().size() != 0 ?
(module->getxmlSchemaPrefixes().front() + ':') : empty_string;
switch (parser->getActualTagName()) {
case n_sequence:
if (!top && xsdtype != n_sequence && xsdtype != n_complexType && xsdtype != n_extension && xsdtype != n_restriction && xsdtype != n_element) {
......@@ -468,7 +471,7 @@ void ComplexType::loadWithValues() {
{
ComplexType * any = new ComplexType(this);
any->name.upload(Mstring("elem"));
any->type.upload(Mstring("string"), false);
any->type.upload(xsdPrefix + Mstring("string"), false);
any->applyNamespaceAttribute(V_anyElement, atts.namespace_);
any->setMinMaxOccurs(atts.minOccurs, atts.maxOccurs);
any->setXsdtype(n_any);
......@@ -480,7 +483,7 @@ void ComplexType::loadWithValues() {
AttributeType * anyattr = new AttributeType(this);
anyattr->setXsdtype(n_anyAttribute);
anyattr->setNameOfField(Mstring("attr"));
anyattr->setTypeValue(Mstring("string"));
anyattr->setTypeValue(xsdPrefix + Mstring("string"));
anyattr->setToAnyAttribute();
anyattr->applyMinMaxOccursAttribute(0, ULLONG_MAX);
anyattr->addNameSpaceAttribute(atts.namespace_);
......@@ -597,7 +600,7 @@ void ComplexType::loadWithValues() {
if (atts.mixed) {
ComplexType * mixed = new ComplexType(this);
mixed->name.upload(Mstring("embed_values"));
mixed->type.upload(Mstring("string"), false);
mixed->type.upload(xsdPrefix + Mstring("string"), false);
mixed->setMinMaxOccurs(0, ULLONG_MAX, false);
mixed->embed = true;
complexfields.push_back(mixed);
......@@ -844,7 +847,7 @@ void ComplexType::nameConversion(NameConversionMode conversion_mode, const List<
void ComplexType::nameConversion_names(const List<NamespaceType> &) {
Mstring res, var(module->getTargetNamespace());
XSDName2TTCN3Name(name.convertedValue, TTCN3ModuleInventory::getInstance().getTypenames(), type_name, res, var);
XSDName2TTCN3Name(name.convertedValue, empty_string, TTCN3ModuleInventory::getInstance().getTypenames(), type_name, res, var);
name.convertedValue = res;
bool found = false;
for (List<Mstring>::iterator vari = variant.begin(); vari; vari = vari->Next) {
......@@ -858,7 +861,7 @@ void ComplexType::nameConversion_names(const List<NamespaceType> &) {
addVariant(V_onlyValue, var);
}
for (List<RootType*>::iterator dep = nameDepList.begin(); dep; dep = dep->Next) {
dep->Data->setTypeValue(res);
dep->Data->setTypeValueWoPrefix(res);
}
}
......@@ -909,7 +912,7 @@ void ComplexType::nameConversion_types(const List<NamespaceType> & ns) {
setTypeValue(origTN->Data.name);
} else {
Mstring res, var;
XSDName2TTCN3Name(typeValue, TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name, res, var, type.no_replace);
XSDName2TTCN3Name(typeValue, uri, TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name, res, var, type.no_replace);
setTypeValue(res);
}
}
......@@ -936,14 +939,21 @@ void ComplexType::nameConversion_fields(const List<NamespaceType> & ns) {
Mstring res, var;
var = getModule()->getTargetNamespace();
XSDName2TTCN3Name(typeValue, TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name, res, var);
List<NamespaceType>::iterator declNS;
for (declNS = module->getDeclaredNamespaces().begin(); declNS; declNS = declNS->Next) {
if (prefix == declNS->Data.prefix) {
break;
}
}
XSDName2TTCN3Name(typeValue, declNS ? declNS->Data.uri : empty_string,
TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name, res, var);
field->Data->addVariant(V_onlyValue, var);
var = getModule()->getTargetNamespace();
if (field->Data->getName().list_extension) {
field->Data->useNameListProperty();
XSDName2TTCN3Name(field->Data->getName().convertedValue,
XSDName2TTCN3Name(field->Data->getName().convertedValue, empty_string,
used_field_names, field_name, res, var);
field->Data->setNameValue(res);
bool found_in_variant = false;
......@@ -966,7 +976,7 @@ void ComplexType::nameConversion_fields(const List<NamespaceType> & ns) {
field->Data->addVariant(V_untagged, empty_string, true);
}
} else {
XSDName2TTCN3Name(field->Data->getName().convertedValue,
XSDName2TTCN3Name(field->Data->getName().convertedValue, empty_string,
used_field_names, field_name, res, var);
field->Data->setNameValue(res);
field->Data->addVariant(V_onlyValue, var);
......@@ -2392,7 +2402,7 @@ void ComplexType::addTypeSubstitution(SimpleType * st){
}
element->top = false;
complexfields.push_back(element);
element->setTypeValue(st->getName().convertedValue.getValueWithoutPrefix(':'));
element->setTypeValue(st->getName().convertedValue);
element->setNameValue(st->getName().convertedValue.getValueWithoutPrefix(':'));
}
......
......@@ -69,7 +69,7 @@ void Constant::nameConversion_types(const List<NamespaceType> & ns) {
// otherwise the new value is always the same as the old.
} else {
Mstring res, var;
XSDName2TTCN3Name(value_str, TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name, res, var);
XSDName2TTCN3Name(value_str, empty_string, TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name, res, var);
setTypeValue(res);
}
}
......
......@@ -49,7 +49,8 @@ extern bool t_flag_used;
// variant - generated variant string for TTCN-3
//
void XSDName2TTCN3Name(const Mstring& in_str, QualifiedNames & used_names, modeType type_of_the_name,
void XSDName2TTCN3Name(const Mstring& in_str, const Mstring& in_namespace,
QualifiedNames & used_names, modeType type_of_the_name,
Mstring & res, Mstring & variant, bool no_replace) {
static const char* TTCN3_reserved_words[] = {
"action", "activate", "address", "alive", "all", "alt", "altstep", "and", "and4b", "any", "any2unistr", "anytype", "apply",
......@@ -150,7 +151,7 @@ void XSDName2TTCN3Name(const Mstring& in_str, QualifiedNames & used_names, modeT
// if (type_of_the_name == type_reference_name || type_of_the_name == field_reference_name) {
if (type_of_the_name == type_reference_name) {
if (isBuiltInType(res)) {
if (isBuiltInType(res) && (in_namespace == empty_string || in_namespace == XMLSchema)) {
res[0] = (char)toupper(res[0]);
res = "XSD." + res;
return;
......
......@@ -25,7 +25,8 @@ enum modeType {
type_reference_name, type_name, field_name, enum_id_name
};
void XSDName2TTCN3Name(const Mstring& in, QualifiedNames & used_names, modeType type_of_the_name,
void XSDName2TTCN3Name(const Mstring& in, const Mstring& in_namespace,
QualifiedNames & used_names, modeType type_of_the_name,
Mstring & res, Mstring & variant, bool no_replace = false);
class ReferenceData;
......
......@@ -33,6 +33,8 @@ RootType::RootType(XMLParser * a_parser, TTCN3Module * a_module, const Construct
, maxOccurs(1)
, min_mod(false)
, max_mod(false){
Mstring xsdPrefix = module->getxmlSchemaPrefixes().size() != 0 ?
(module->getxmlSchemaPrefixes().front() + ':') : empty_string;
switch (a_construct) {
case c_schema:
case c_annotation:
......@@ -43,16 +45,16 @@ RootType::RootType(XMLParser * a_parser, TTCN3Module * a_module, const Construct
case c_unknown: // because when using fields in complextypes we set construct to c_unknown
case c_simpleType:
origin = from_simpleType;
type.upload(Mstring("anySimpleType"), false);
type.upload(xsdPrefix + Mstring("anySimpleType"), false);
break;
case c_element:
origin = from_element;
type.upload(Mstring("anyType"), false);
type.upload(xsdPrefix + Mstring("anyType"), false);
addVariant(V_element);
break;
case c_attribute:
origin = from_attribute;
type.upload(Mstring("anySimpleType"), false);
type.upload(xsdPrefix + Mstring("anySimpleType"), false);
addVariant(V_attribute);
break;
case c_complexType:
......
......@@ -193,6 +193,11 @@ public:
void setTypeValue(const Mstring& str) {
type.convertedValue = str;
}
void setTypeValueWoPrefix(const Mstring& str) {
Mstring prefix = type.convertedValue.getPrefix(':');
type.convertedValue = prefix + ':' + str;
}
void useNameListProperty() {
name.convertedValue += "_list";
......
......@@ -525,7 +525,8 @@ void SimpleType::setReference(const Mstring& ref, bool only_name_dependency) {
if (name.convertedValue.empty()) {
name.upload(ref);
}
if (type.convertedValue.empty() || type.convertedValue == "anySimpleType") {
if (type.convertedValue.empty() ||
type.convertedValue.getValueWithoutPrefix(':') == "anySimpleType") {
type.upload(ref);
}
bool found = false;
......@@ -769,11 +770,11 @@ void SimpleType::nameConversion(NameConversionMode conversion_mode, const List<N
void SimpleType::nameConversion_names() {
Mstring res, var(module->getTargetNamespace());
XSDName2TTCN3Name(name.convertedValue, TTCN3ModuleInventory::getInstance().getTypenames(), type_name, res, var);
XSDName2TTCN3Name(name.convertedValue, empty_string, TTCN3ModuleInventory::getInstance().getTypenames(), type_name, res, var);
name.convertedValue = res;
addVariant(V_onlyValue, var);
for (List<RootType*>::iterator st = nameDepList.begin(); st; st = st->Next) {
st->Data->setTypeValue(res);
st->Data->setTypeValueWoPrefix(res);
}
if (outside_reference.get_ref() != NULL && defaultForEmptyConstant!= NULL) {
// We don't know if the name conversion already happened on the get_ref()
......@@ -817,7 +818,7 @@ void SimpleType::nameConversion_types(const List<NamespaceType> & ns) {
// otherwise the new value is always the same as the old.
} else {
Mstring res, var;
XSDName2TTCN3Name(value_str, TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name, res, var);
XSDName2TTCN3Name(value_str, uri, TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name, res, var);
setTypeValue(res);
}
}
......@@ -1274,7 +1275,7 @@ void EnumerationType::applyFacets() // string types, integer types, float types,
const LengthType & length = parent->getLength();
if (length.lower <= facet->Data.size() && facet->Data.size() <= length.upper) {
Mstring res, var;
XSDName2TTCN3Name(facet->Data, items_string, enum_id_name, res, var);
XSDName2TTCN3Name(facet->Data, empty_string, items_string, enum_id_name, res, var);
text_variants.push_back(var);
converted_facets.push_back(res);
}
......@@ -1341,7 +1342,7 @@ void EnumerationType::applyFacets() // string types, integer types, float types,
List<Mstring> text_variants;
for (List<Mstring>::iterator facet = facets.begin(); facet; facet = facet->Next) {
Mstring res, var;
XSDName2TTCN3Name(facet->Data, items_time, enum_id_name, res, var);
XSDName2TTCN3Name(facet->Data, empty_string, items_time, enum_id_name, res, var);
text_variants.push_back(var);
converted_facets.push_back(res);
}
......
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