Bug in my code or in OCL [message #658220] |
Mon, 07 March 2011 13:14  |
Wilbert Alberts Messages: 209 Registered: June 2010 |
Senior 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   |
Ed Willink Messages: 7635 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.
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.02654 seconds