[great-users] Code Generator and GRE fails when a model element is associated to more than one elements as destinations with the same association
Gürkan Özhan
gurkanozhan at gmail.com
Sun Feb 22 18:02:46 CST 2009
Dear GReAT developers and users,
This will be a rather long mail, so I apologize for that, but this
is necessary to explain the rather difficult to encounter issue that I
face with. I am using GReat 1.6.1, and I don't know whether this
problem (if you will also call a problem) still exists in 1.6.2, but I
will try that soon. My original transformation was rather big and
complex, so I recreated the problem in a modified version of the
simple House2Order example. Here is the story:
If a model element E1 is associated as source with more than one
elements, say, E2 and E3 as destinations using the same connection
element , then the generated code is errorenous, suffering from
duplicate type definition errors . The specific place of the error is
inside the class definition of E1 where duplicate association role
types are defined for E2 and E3 with the same name as the connection
element. As a result, the GR-engine or GR-debugger give error.
PART OF THE GENERATED SOURCE FROM THE MODIFIED HOUSEMODEL and HOUSE2ORDER :
class E1 : public ::GS_HouseModel::MgaObject {
public:
...
static ::Uml::AssociationRole meta_dstAdjacentTo;
static ::Uml::AssociationRole meta_dstAdjacentTo_rev;
Udm::AClassAssocAttr< ::GS_HouseModel::AdjacentTo,
::GS_HouseModel::E3> dstAdjacentTo() const { return
Udm::AClassAssocAttr< ::GS_HouseModel::AdjacentTo,
::GS_HouseModel::E3>(impl, meta_dstAdjacentTo,
meta_dstAdjacentTo_rev); }
template<class Pred> Udm::AClassAssocAttr<
::GS_HouseModel::AdjacentTo, ::GS_HouseModel::E3, Pred>
dstAdjacentTo_sorted(const Pred &) const { return
Udm::AClassAssocAttr< ::GS_HouseModel::AdjacentTo,
::GS_HouseModel::E3, Pred>(impl,
meta_dstAdjacentTo, meta_dstAdjacentTo_rev); }
static ::Uml::AssociationRole meta_dstAdjacentTo;
static ::Uml::AssociationRole meta_dstAdjacentTo_rev;
Udm::AClassAssocAttr< ::GS_HouseModel::AdjacentTo,
::GS_HouseModel::E2> dstAdjacentTo() const { return
Udm::AClassAssocAttr< ::GS_HouseModel::AdjacentTo,
::GS_HouseModel::E2>(impl, meta_dstAdjacentTo,
meta_dstAdjacentTo_rev); }
template<class Pred> Udm::AClassAssocAttr<
::GS_HouseModel::AdjacentTo, ::GS_HouseModel::E2, Pred>
dstAdjacentTo_sorted(const Pred &) const { return
Udm::AClassAssocAttr< ::GS_HouseModel::AdjacentTo,
::GS_HouseModel::E2, Pred>(impl,
meta_dstAdjacentTo, meta_dstAdjacentTo_rev); }
...........................
COMPILE ERROR FOR THE ABOVE:
1>D:\PhD\ModelTrans\House2OrderTest\Udm\GS_HouseModel.h(101) : error
C2086: 'Uml::AssociationRole GS_HouseModel::E1::meta_dstAdjacentTo' :
redefinition
1> D:\PhD\ModelTrans\House2OrderTest\Udm\GS_HouseModel.h(96) :
see declaration of 'GS_HouseModel::E1::meta_dstAdjacentTo'
1>D:\PhD\ModelTrans\House2OrderTest\Udm\GS_HouseModel.h(102) : error
C2086: 'Uml::AssociationRole
GS_HouseModel::E1::meta_dstAdjacentTo_rev' : redefinition
1> D:\PhD\ModelTrans\House2OrderTest\Udm\GS_HouseModel.h(97) :
see declaration of 'GS_HouseModel::E1::meta_dstAdjacentTo_rev'
1>D:\PhD\ModelTrans\House2OrderTest\Udm\GS_HouseModel.h(103) : error
C2556: 'Udm::AClassAssocAttr<CLASS,TARGETCLASS>
GS_HouseModel::E1::dstAdjacentTo(void) const' : overloaded function
differs only by return type from
'Udm::AClassAssocAttr<CLASS,TARGETCLASS>
GS_HouseModel::E1::dstAdjacentTo(void) const'
1> with
1> [
1> CLASS=GS_HouseModel::AdjacentTo,
1> TARGETCLASS=GS_HouseModel::E2
1> ]
1> and
1> [
1> CLASS=GS_HouseModel::AdjacentTo,
1> TARGETCLASS=GS_HouseModel::E3
1> ]
1> D:\PhD\ModelTrans\House2OrderTest\Udm\GS_HouseModel.h(98) :
see declaration of 'GS_HouseModel::E1::dstAdjacentTo'
1>D:\PhD\ModelTrans\House2OrderTest\Udm\GS_HouseModel.h(103) : error
C2371: 'GS_HouseModel::E1::dstAdjacentTo' : redefinition; different
basic types
1> D:\PhD\ModelTrans\House2OrderTest\Udm\GS_HouseModel.h(98) :
see declaration of 'GS_HouseModel::E1::dstAdjacentTo'
If we change the destination role names in the metamodel (e.g.,
dstConnNameE2, and dstConnNameE3 instead of dstConnName) and then rum
the UMT interpreter, the interpretation ignores the newly given role
names and again produces the same role names as before inside the
target UMT file. Luckily we are able to further rename the rolenames
within the UMT file. If we do so and generate code, then the above
problem in the source entity's generated code is corrected as seen
below:
static ::Uml::AssociationRole meta_dstAdjacentToE3;
static ::Uml::AssociationRole meta_dstAdjacentToE3_rev;
Udm::AClassAssocAttr< ::GS_HouseModel::AdjacentTo,
::GS_HouseModel::E3> dstAdjacentToE3() const { return
Udm::AClassAssocAttr< ::GS_HouseModel::AdjacentTo,
::GS_HouseModel::E3>(impl, meta_dstAdjacentToE3,
meta_dstAdjacentToE3_rev); }
template<class Pred> Udm::AClassAssocAttr<
::GS_HouseModel::AdjacentTo, ::GS_HouseModel::E3, Pred>
dstAdjacentToE3_sorted(const Pred &) const { return
Udm::AClassAssocAttr< ::GS_HouseModel::AdjacentTo,
::GS_HouseModel::E3, Pred>(impl, meta_dstAdjacentToE3,
meta_dstAdjacentToE3_rev); }
static ::Uml::AssociationRole meta_dstAdjacentToE2;
static ::Uml::AssociationRole meta_dstAdjacentToE2_rev;
Udm::AClassAssocAttr< ::GS_HouseModel::AdjacentTo,
::GS_HouseModel::E2> dstAdjacentToE2() const { return
Udm::AClassAssocAttr< ::GS_HouseModel::AdjacentTo,
::GS_HouseModel::E2>(impl, meta_dstAdjacentToE2,
meta_dstAdjacentToE2_rev); }
template<class Pred> Udm::AClassAssocAttr<
::GS_HouseModel::AdjacentTo, ::GS_HouseModel::E2, Pred>
dstAdjacentToE2_sorted(const Pred &) const { return
Udm::AClassAssocAttr< ::GS_HouseModel::AdjacentTo,
::GS_HouseModel::E2, Pred>(impl, meta_dstAdjacentToE2,
meta_dstAdjacentToE2_rev); }
In the code, we can see the unambiguous declations of
meta_dstAdjacentToE3 and meta_dstAdjacentToE2. Unfortunately this time
we get an error in the generated code of the source metamodel as;
1>..\Udm\GS_HouseModel.cpp(174) : error C2039:
'meta_dstAdjacentToE3_end_' : is not a member of
'GS_HouseModel::AdjacentTo'
1> d:\phd\modeltrans\house2ordertest\udm\GS_HouseModel.h(245) :
see declaration of 'GS_HouseModel::AdjacentTo'
complaining about this line:
::GS_HouseModel::AdjacentTo::meta_dstAdjacentToE3_end_
::GS_HouseModel::E3::meta_srcAdjacentTo_rev =
::GS_HouseModel::E1::meta_dstAdjacentToE3;
When we check the generated definition of the association class we see:
static ::Uml::AssociationRole meta_dstAdjacentTo_end_;
Udm::AssocEndAttr< ::GS_HouseModel::Room> dstAdjacentTo_end() const
{ return Udm::AssocEndAttr< ::GS_HouseModel::Room>(impl,
meta_dstAdjacentTo_end_); }
static ::Uml::AssociationRole meta_srcAdjacentTo_end_;
Udm::AssocEndAttr< ::GS_HouseModel::Room> srcAdjacentTo_end() const
{ return Udm::AssocEndAttr< ::GS_HouseModel::Room>(impl,
meta_srcAdjacentTo_end_); }
Hence, there is no E2 and E3 specific definitions here.
In this issue report I propose two suggestions:
1. In the metamodel, the specific role names that we provide in
associations should be preserved by the UMT interpreter.
2. The code generator should generate as many meta_XXX_end_ types as
we provide in 1 in the generated source code of the association class.
Kind regards,
Gurkan Ozhan
More information about the great-users
mailing list