Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kxml_compiler]Fix segfault when parsing an XSD containing a sequence type rootitem #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why < and not just !=?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why < and not just !=?

Makes sense I will fix it!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably means there's no need for it to be last anymore, i.e. you could revert the change to the enum, unless I'm missing something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. When I started to work on this I was not 100% confident that no other kind of types needs to be treated similar to complexTypes. But at the end it turned out that no need for that.

Also it might be useful to remove/refactor the Schema::Element::text in this PR because I think the name 'text' is a bit misleading and from the type (complexType or not) and from the number of attributes and relations it is possible to determine that a simple C++ type (QString/int/something similar) member or a class representing the questioned element shall be generated.

&& !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