Bug in my code or in OCL [message #658220] |
Mon, 07 March 2011 08:14  |
Eclipse User |
|
|
|
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 08:29] by Moderator
|
|
|
Re: Bug in my code or in OCL [message #658224 is a reply to message #658220] |
Mon, 07 March 2011 08:31   |
Eclipse User |
|
|
|
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 08:58  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.05344 seconds