diff options
author | Sandro S. Andrade <sandroandrade@kde.org> | 2013-10-13 01:52:01 -0300 |
---|---|---|
committer | Sandro S. Andrade <sandroandrade@kde.org> | 2013-10-13 06:48:52 +0200 |
commit | bd593f7348c8012698fff260d7967528bcf67afe (patch) | |
tree | ca75826e9812d10e337ca14bd3bd4264d7466a2a /scripts/templates | |
parent | b505b189ff61ba1d325d95d6ef928aa146bb4c05 (diff) |
Fix template bugs when generating MOF metamodel implementation
Change-Id: I2d75b3b668248988f15f0f496cb2d4ef386b48cc
Reviewed-by: Sandro S. Andrade <sandroandrade@kde.org>
Diffstat (limited to 'scripts/templates')
-rw-r--r-- | scripts/templates/common.tmpl | 40 | ||||
-rw-r--r-- | scripts/templates/qclass.cpp | 22 | ||||
-rw-r--r-- | scripts/templates/qclass.h | 27 | ||||
-rw-r--r-- | scripts/templates/qobjectclass.cpp | 3 |
4 files changed, 54 insertions, 38 deletions
diff --git a/scripts/templates/common.tmpl b/scripts/templates/common.tmpl index 7d9d052f..fa8afb5a 100644 --- a/scripts/templates/common.tmpl +++ b/scripts/templates/common.tmpl @@ -13,15 +13,19 @@ [%- SET isUnique = attribute.findvalue("@isUnique") -%] [%- SET isOrdered = attribute.findvalue("@isOrdered") -%] [%- IF multiplicity == "*" %][% IF (isUnique == "true" || isUnique == "") && (isOrdered == "false" || isOrdered == "") %]QSet[% ELSE %]QList[% END %]<[% END -%] - [%- attributeType = attribute.findvalue("@type") -%] - [%- IF attributeType != "" -%] - [%- IF xmi.findnodes("//packagedElement[@xmi:type='uml:Enumeration' and @name='$attributeType']").findvalue("@name") != "" -%] + [%- SET attributeType = attribute.findvalue("@type").split('#').last -%] + [%- IF attributeType == "" -%][%- SET attributeType = attribute.findnodes("type").findvalue("@xmi:idref") -%][%- END -%] + [%- IF attributeType == "" -%][%- SET attributeType = attribute.findnodes("type").findvalue("@href") -%][%- END -%] + [%- IF !attributeType.match('PrimitiveTypes\.xmi') -%] + [%- IF xmi.findnodes("//packagedElement[@xmi:type='uml:Enumeration' and @name='$attributeType']").findvalue("@name") != "" -%] Qt${namespace}::${attributeType} - [%- ELSE -%] + [%- ELSE -%] +[%- IF attributeType != "" -%] [% IF external == "false" %]QObject *[% ELSE %]Q${namespace}${attributeType} *[% END %] - [%- END -%] +[%- ELSE %] [% END -%] + [%- END -%] [%- ELSE -%] -${uml2qt_type.item(attribute.findnodes("type").findvalue("@href").split("#").last)}[%- IF multiplicity != "*" %] [% END -%] +${uml2qt_type.item(attributeType.split('#').last)}[%- IF multiplicity != "*" %] [% END -%] [%- END -%] [%- IF multiplicity == "*" %]> [% END -%] [%- END -%] @@ -162,8 +166,9 @@ ${attributeName} [%- END %] [%- SET operationName = operation.findvalue("@name") -%] [%- NEXT IF redefinedOperations.grep("^${className}-${operationName}$").size > 0 -%] +[%- SET qtType = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']"), "false") -%] - Q_INVOKABLE [% QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']"), "false") -%] + Q_INVOKABLE [%- IF qtType != " " -%]${qtType}[%- ELSE -%]void [%- END -%] ${operationName}( [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] [%- QT_TYPE(namespace, parameter, "false") -%] @@ -272,13 +277,13 @@ ${parameter.findvalue("@name")} [%- IF found == "false" -%] // OPERATIONS [${className}] -[%- SET found = "true" -%] +[% SET found = "true" -%] [% END -%] [% SET operationName = operation.findvalue("@name") -%] [%- NEXT IF redefinedOperations.grep("^${className}-${operationName}$").size > 0 -%] [%- SET return = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']"), "false") %] [%- SET originalReturn = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']"), "true") %] -[% return -%] +[%- IF return != " " %]${return}[%- ELSE %]void [%- END -%] Q${namespace}${originalClassName}Object::${operationName}( [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] [%- QT_TYPE(namespace, parameter, "false") -%] @@ -347,10 +352,8 @@ ${parameter.findvalue("@name")} [%- END %] } -[%- IF loop.last %] [% END -%] [%- END -%] -[%- END -%] [%- MACRO GENERATE_CPP_SLOTS(originalClassName, class, visitedClasses, redefinedProperties) BLOCK -%] [%- FOREACH parent IN class.findnodes("generalization") -%] [%- SET parentName = parent.findvalue("@general") -%] @@ -424,20 +427,25 @@ void Q${namespace}${originalClassName}Object::unset${qtAttribute.remove("^is").u [% END -%] [%- END %] [%- END -%] -[%- MACRO GENERATE_FWD_DECLARATIONS(class, visitedClasses, forwards, useNamespace) BLOCK -%] +[%- MACRO GENERATE_FWD_DECLARATIONS(class, visitedClasses, forwards, useNamespace, superclasses, recursive) BLOCK -%] +[%- IF recursive != "false" -%] [%- FOREACH parent IN class.findnodes("generalization") -%] [%- SET parentName = parent.findvalue("@general") -%] [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%] - [%- visitedClasses.push("${parentName}") -%] - [%- GENERATE_FWD_DECLARATIONS(xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${parentName}\"]"), visitedClasses, forwards, useNamespace) -%] + [%- visitedClasses.push("${parentName}") -%] + [%- GENERATE_FWD_DECLARATIONS(xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${parentName}\"]"), visitedClasses, forwards, useNamespace, superclasses) -%] [%- END -%] [%- END -%] -[%- FOREACH forward = class.findnodes("ownedAttribute[@type] | ownedOperation/ownedParameter[@type]") -%] +[%- END -%] +[%- FOREACH forward = class.findnodes("ownedAttribute[@type] | ownedOperation/ownedParameter[@type] | ownedAttribute/type | ownedOperation/ownedParameter/type") -%] [%- SET forwardName = forward.findvalue('@type') -%] +[%- IF forwardName == "" -%][%- SET forwardName = forward.findvalue('@xmi:idref') -%][%- END -%] +[%- IF forwardName == "" -%][%- SET forwardName = forward.findvalue('@href') -%][%- END -%] +[%- NEXT IF forwardName.match('PrimitiveTypes') -%] [%- IF xmi.findnodes("//packagedElement[@xmi:type='uml:Enumeration' and @name='$forwardName']").findvalue("@name") != "" -%] [%- useNamespace.push("true") -%] [%- ELSE -%] -[%- IF forwardName != className -%][%- forwards.push("Q${namespace}${forwardName}") -%][%- END -%] +[%- IF forwardName != className && superclasses.grep("^${namespace}${forwardName}\$").size == 0 -%][%- forwards.push("Q${namespace}${forwardName}") -%][%- END -%] [%- END -%] [%- END -%] [%- END -%] diff --git a/scripts/templates/qclass.cpp b/scripts/templates/qclass.cpp index 706f7aca..bf204676 100644 --- a/scripts/templates/qclass.cpp +++ b/scripts/templates/qclass.cpp @@ -53,7 +53,7 @@ [% SET useNamespace = 'false' -%] [%- forwards = [] -%] [%- visitedClasses = [] -%] -[%- GENERATE_FWD_DECLARATIONS(class, visitedClasses, forwards, useNamespace) -%] +[%- GENERATE_FWD_DECLARATIONS(class, visitedClasses, forwards, useNamespace, superclasses) -%] [%- FOREACH forward = forwards.unique.sort %] #include <Qt${namespace}/${forward}> [%- IF loop.last %] @@ -137,6 +137,7 @@ QModelingElement *Q${namespace}${className}::clone() const [%- IF loop.first %] // OWNED ATTRIBUTES + [%- END %] [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] @@ -146,7 +147,7 @@ QModelingElement *Q${namespace}${className}::clone() const [%- SET derivedUnion = attribute.findvalue("@isDerivedUnion") -%] [%- SET association = attribute.findvalue("@association") -%] [%- SET documentation = attribute.findvalue("ownedComment/body/text()") -%] -[%- IF documentation != "" %] +[%- IF documentation != "" -%] /*! ${documentation} */ @@ -167,9 +168,9 @@ QModelingElement *Q${namespace}${className}::clone() const return _${PLURALFORM(qtAttribute, attribute)}; [%- END %] } + [%- SET attributeName = attribute.findvalue("@name").ucfirst %] [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" %] - void Q${namespace}${className}::add${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*')}${qtAttribute}) { // This is a [% IF readOnly == "" || readOnly == "false" %]read-write[% ELSE %]read-only[% END %][% IF derived == "true" %] derived[% END %][% IF derivedUnion == "true" %] union[% END %] [% IF association != "" %]association end[% ELSE %]property[% END %] @@ -288,8 +289,8 @@ void Q${namespace}${className}::remove${attributeName}(${qtType.remove("QSet<"). [%- END %] } } - [%- ELSE %] + [%- ELSE %] void Q${namespace}${className}::set${attributeName.remove("^Is")}([% IF !qtType.match('\*$') %]${qtType.trim} [% ELSE %]${qtType}[% END %]${qtAttribute}) { // This is a [% IF readOnly == "" || readOnly == "false" %]read-write[% ELSE %]read-only[% END %][% IF derived == "true" %] derived[% END %][% IF derivedUnion == "true" %] union[% END %] [% IF association != "" %]association end[% ELSE %]property[% END %] @@ -352,24 +353,25 @@ void Q${namespace}${className}::set${attributeName.remove("^Is")}([% IF !qtType. [%- END %] } } + [%- END %] [%- END %] [%- FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%] [%- IF loop.first %] - // OPERATIONS + [%- END %] [%- SET operationName = operation.findvalue("@name") -%] [%- SET returnType = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']")) %] [%- SET documentation = operation.findvalue("ownedComment/body/text()") -%] -[%- IF documentation != "" %] +[%- IF documentation != "" -%] /*! ${documentation} */ -[%- END %] -${returnType}Q${namespace}${className}::${operationName}( +[% END %] +[%- IF returnType != " " -%]${returnType}[%- ELSE -%]void [%- END -%]Q${namespace}${className}::${operationName}( [%- SET parameters = operation.findnodes("ownedParameter[@direction!='return']") -%] [%- FOREACH parameter = parameters -%] [%- QT_TYPE(namespace, parameter) -%] @@ -383,11 +385,13 @@ ${parameter.findvalue("@name")} [%- FOREACH parameter = parameters %] Q_UNUSED(${parameter.findvalue("@name")}); [%- END %] + [%- IF returnType != " " -%] [%- IF returnType.match('\*$') %] return 0; [%- ELSE %] return ${returnType}(); + [%- END -%] [%- END %] } -[%- END %] +[%- END %] diff --git a/scripts/templates/qclass.h b/scripts/templates/qclass.h index b75f0e8e..d13fe6c4 100644 --- a/scripts/templates/qclass.h +++ b/scripts/templates/qclass.h @@ -57,16 +57,10 @@ #include <QtModeling/QModelingElement> [% END -%] -[%- SET useNamespace = 'false' -%] +[% SET useNamespace = 'false' -%] [%- forwards = [] -%] -[%- FOREACH forward = class.findnodes("ownedAttribute[@type] | ownedOperation/ownedParameter[@type]") -%] -[%- SET forwardName = forward.findvalue('@type') -%] -[%- IF xmi.findnodes("//packagedElement[@xmi:type='uml:Enumeration' and @name='$forwardName']").findvalue("@name") != "" -%] - [%- SET useNamespace = 'true' -%] -[%- ELSE -%] -[%- IF forwardName != className && superclasses.grep("^${namespace}${forwardName}\$").size == 0 -%][%- forwards.push("${namespace}${forwardName}") -%][%- END -%] -[%- END -%] -[%- END -%] +[%- visitedClasses = [] -%] +[%- GENERATE_FWD_DECLARATIONS(class, visitedClasses, forwards, useNamespace, superclasses, "false") -%] [%- IF useNamespace == 'true' %] #include <Qt${namespace}/Qt${namespace}Namespace> [% END -%] @@ -77,7 +71,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Qt${namespace}) [%- FOREACH forward = forwards.unique.sort %] -class Q${forward}; +class ${forward}; [%- IF loop.last %] [% END %] [%- END -%] @@ -121,10 +115,19 @@ public: // Operations [%- END %] [% SET operationName = operation.findvalue("@name") -%] - [% QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']")) -%] +[%- SET qtType = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']")) -%] +[%- IF qtType != " " -%] + ${qtType} +[%- ELSE -%] + void +[%- END -%] ${operationName}( [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] - [%- QT_TYPE(namespace, parameter) -%] + [%- SET qtType = QT_TYPE(namespace, parameter) -%] + [%- IF qtType != " " -%] + [%- qtType -%] + [%- ELSE -%] + [%- END -%] ${parameter.findvalue("@name")} [%- IF !loop.last %], [% END -%] [%- END -%] diff --git a/scripts/templates/qobjectclass.cpp b/scripts/templates/qobjectclass.cpp index 96d4aa60..8568b560 100644 --- a/scripts/templates/qobjectclass.cpp +++ b/scripts/templates/qobjectclass.cpp @@ -43,10 +43,11 @@ #include "private/qmodelingobject_p.h" #include <Qt${namespace}/Q${namespace}${className}> +[%- superclasses = [] %] [% SET useNamespace = 'false' -%] [%- forwards = [] -%] [%- visitedClasses = [] -%] -[%- GENERATE_FWD_DECLARATIONS(class, visitedClasses, forwards, useNamespace) -%] +[%- GENERATE_FWD_DECLARATIONS(class, visitedClasses, forwards, useNamespace, superclasses) -%] [%- FOREACH forward = forwards.unique.sort -%] #include <Qt${namespace}/${forward}> [% IF loop.last %] |