Skip to content

Commit

Permalink
[kxml_compiler]The kxml_compiler segfaulted when generated code from an
Browse files Browse the repository at this point in the history
XSD where the root element was a complexType which was a sequence of
elements. This was becasuse the subelements was not added by the schema/
parser class during the parse.
  • Loading branch information
martonmiklos committed May 1, 2020
1 parent 101e0e7 commit bb0b86e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion kxml_compiler/creator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ ClassDescription Creator::createClassDescription(const Schema::Element &element)

QString targetClassName = Namer::getClassName(targetElement.name());

if (targetElement.text() && !targetElement.hasAttributeRelations() && !r.isList()) {
if ((targetElement.text() || targetElement.type() < Schema::Element::ComplexType)
&& !targetElement.hasAttributeRelations() && !r.isList()) {
if (mVerbose) {
qDebug() << " FLATTEN";
}
Expand Down
4 changes: 3 additions & 1 deletion kxml_compiler/kxml_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ int main(int argc, char **argv)
qDebug() << "Create classes";
}
foreach (Schema::Element e, schemaDocument.usedElements()) {
if (!e.text()) {
// only generate classes for the simple types (nodes with no childs/attributes)
if (!e.text()
&& !(e.attributeRelations().count() == 0 && e.elementRelations().count() == 0)) {
c.createClass(e);
}
}
Expand Down
3 changes: 2 additions & 1 deletion kxml_compiler/parsercreatordom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ void ParserCreatorDom::createElementParser(KODE::Class &c, const Schema::Element

Schema::Element targetElement = creator()->document().element((*it).target());

if (targetElement.text() && !targetElement.hasAttributeRelations() && !(*it).isList()) {
if ((targetElement.text() || targetElement.type() < Schema::Node::ComplexType)
&& !targetElement.hasAttributeRelations() && !(*it).isList()) {
QString data = stringToDataConverter("e.text()", targetElement.type());
code += "result.set" + className + "( " + data + " );";
} else {
Expand Down
8 changes: 8 additions & 0 deletions kxml_compiler/parserxsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ Schema::Document ParserXsd::parse(const XSD::Parser &parser)
e.setBaseType(Schema::Node::String);
} else if (complexType.baseTypeName().qname() == "xs:boolean") {
e.setBaseType(Schema::Node::Boolean);
} else if (complexType.baseTypeName().qname() == "xs:decimal") {
e.setBaseType(Schema::Node::Decimal);
} else if (complexType.baseTypeName().qname() == "xs:date") {
e.setBaseType(Schema::Node::Date);
} else if (complexType.baseTypeName().qname() == "xs:normalizedString") {
e.setBaseType(Schema::Node::NormalizedString);
} else if (complexType.baseTypeName().qname() == "xs:token") {
Expand All @@ -120,6 +124,10 @@ Schema::Document ParserXsd::parse(const XSD::Parser &parser)
e.setType(Schema::Node::String);
} else if (element.type().qname() == "xs:boolean") {
e.setType(Schema::Node::Boolean);
} else if (element.type().qname() == "xs:decimal") {
e.setType(Schema::Node::Decimal);
} else if (element.type().qname() == "xs:date") {
e.setType(Schema::Node::Date);
} else if (element.type().qname() == "xs:normalizedString") {
e.setType(Schema::Node::NormalizedString);
} else if (element.type().qname() == "xs:token") {
Expand Down
5 changes: 3 additions & 2 deletions kxml_compiler/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ class KSCHEMA_EXPORT Node : public Annotatable
Int, // xs:int -> signed 32-bit integer
Date,
Enumeration,
ComplexType,
DateTime,
Decimal,
Boolean
Boolean,
ComplexType // always keep this as a last
};

Node();
virtual ~Node();

Expand Down
3 changes: 2 additions & 1 deletion schema/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ void Parser::parseCompositor(ParserContext *context, const QDomElement &element,
foreach (Element e, newElements) {
e.setCompositor(compositor);
ct.addElement(e);
d->mElements.append(e);
}
}
}
Expand Down Expand Up @@ -734,7 +735,7 @@ void Parser::addGlobalElement(const Element &newElement)
}

if (!found) {
d->mElements.append(newElement);
d->mElements.prepend(newElement);
}
}

Expand Down

0 comments on commit bb0b86e

Please sign in to comment.