Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Bug in my code or in OCL
Bug in my code or in OCL [message #658220] Mon, 07 March 2011 13:14 Go to next message
Wilbert Alberts is currently offline Wilbert AlbertsFriend
Messages: 99
Registered: June 2010
Member
Hi,

I'm trying to generate some code for a c like language. It contains pieces like:

typedef struct
{
  BAR b;
} FOO;

typdef struct
{
  int i;
} BAR;


However, in this case the order of the typedefs matters. So the typedef of BAR should precede the one of FOO.

So I need to order a collection of types in my model. I decided to first generate a set of all types present in my model. Then, I'll put them in the right order based on a recursive function which looks like:

[query public sortTypes(done: Sequence(PG_Type), tobedone: Set(PG_Type)) : Sequence(PG_Type) =
if tobedone->isEmpty() then done
else
   let bottom  : Set(PG_Type) = tobedone->select(t| done->includesAll(subTypes(t))),
       newdone : Sequence(PG_Type) = done->union(bottom->asSequence()),
       newtobe : Set(PG_Type) = tobedone-bottom
   in
       sortTypes(newdone, newtobe)
endif
/]


When I run this code, I get an error in the log stating:
Evaluation failed with an exception: org.eclipse.ocl.util.BagImpl cannot be cast to java.util.Set

As far as I can see, the typecast is done in the calculation of newtobe. However, I'm not an expert in OCL and I'm curious about the return types of the various expressions.

Any clues?

Greetings,
Wilbert.

[Updated on: Mon, 07 March 2011 13:29]

Report message to a moderator

Re: Bug in my code or in OCL [message #658224 is a reply to message #658220] Mon, 07 March 2011 13:31 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4189
Registered: July 2009
Senior Member
Hi Wilbert

There seems to be only one conversion to Set in your code and that is in
the call that you haven't shown. I suspect that you input argument is a
Bag a Set. (I seem to recall an earlier thread where Acceleo's query
argument checking was not as tight as it might be.)

Incidentally, have you considered the sortedBy iteration.

Regards

Ed Willink


On 07/03/2011 13:14, Wilbert Alberts wrote:
> Hi,
>
> I'm trying to generate some code for a c like language. It contains
> pieces like:
>
> typedef struct
> {
> BAR b;
> } FOO;
>
> typdef struct
> {
> int i;
> } BAR;
>
> However, in this case the order of the typedefs matters. So the
> typedef of BAR should precede the one of FOO.
>
> So I need to order a collection of types in my model. I decided to
> first generate a set of all types present in my model. Then, I'll put
> them in the right order based on a recursive function which looks like:
> [query public sortTypes(done: Sequence(PG_Type), tobedone:
> Set(PG_Type)) : Sequence(PG_Type) =
> if tobedone->isEmpty() then done
> else
> let bottom : Set(PG_Type) = tobedone->select(t|
> done->includesAll(subTypes(t))),
> newdone : Sequence(PG_Type) = done->union(bottom->asSequence()),
> newtobe : Set(PG_Type) = tobedone-bottom
> in
> sortTypes(newdone, newtobe)
> endif
> /]
>
>
> When I run this code, I get an error in the log stating: Evaluation
> failed with an exception: org.eclipse.ocl.util.BagImpl cannot be cast
> to java.util.Set
>
> As far as I can see, the typecast is done in the calculation of
> newtobe. However, I'm not an expert in OCL and I'm curious about the
> return types of the various expressions.
> Any clues?
>
> Greetings,
> Wilbert.
>
>
Re: Bug in my code or in OCL [message #658228 is a reply to message #658224] Mon, 07 March 2011 13:58 Go to previous message
Wilbert Alberts is currently offline Wilbert AlbertsFriend
Messages: 99
Registered: June 2010
Member
Hi Edward,

Thanks for taking a look at it.

In the meanwhile, the problem is gone (or masked) after changing
		newtobe : Set(PG_Type) = tobedone - bottom
into
		newtobe : Set(PG_Type) = (tobedone->asSet()) - (bottom->asSet())


As to your remark, the invocation of sortTypes is:
sortTypes(Sequence{}, deepTypess(ts))

where deepTypess is defined to return a Set(PG_Type)

I could show the full code to you but I'm afraid it might take too much time to justify the effort.

Would you be interested? As for me, the immediate urge is gone but I must admit that I remain a little suspicious.

Greetings,
wilbert.
Previous Topic:Best practice to test M2T transformation
Next Topic:[Xtend2] Migration Scenarios?
Goto Forum:
  


Current Time: Mon Dec 22 19:36:28 GMT 2014

Powered by FUDForum. Page generated in 0.01921 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software