[CLOSED] How to optimize generated code? [message #1737558] |
Sat, 09 July 2016 19:12  |
Eclipse User |
|
|
|
Hi all.
In my DSL, I have:
protected def caller {
getSkill(C1).myfunction(Integer)
getSkill(C1).myfunction(Float, 1)
getSkill(C1).myfunction(String, 2, 3)
}
The generated Java code is:
protected void caller() {
C1 _skill = this.getSkill(C1.class);
_skill.myfunction(Integer.class);
C1 _skill_1 = this.getSkill(C1.class);
_skill_1.myfunction(Float.class, 1);
C1 _skill_2 = this.getSkill(C1.class);
_skill_2.myfunction(String.class, 2, 3);
}
In the generated code, the three variables _skill, _skill_1, _skill_2 are pointing to the same C1 instance; because there is no setSkill call.
I would like to know if the Xbase expression generator is able to optimize the generated Java code? Is a documentation that explain optimization of the generated code?
At the end I would like to obtain:
protected void caller() {
C1 _skill = this.getSkill(C1.class);
_skill.myfunction(Integer.class);
_skill.myfunction(Float.class, 1);
_skill.myfunction(String.class, 2, 3);
}
Thank you.
Stéphane.
[Updated on: Mon, 11 July 2016 07:09] by Moderator
|
|
|
Re: How to optimize generated code? [message #1737563 is a reply to message #1737558] |
Sun, 10 July 2016 01:28   |
Eclipse User |
|
|
|
Hi
In Java, the optimization you request is unsafe and so invalid for two
reasons:
a) getSkill() might have a side effect, e.g. a static counter of the
number of calls
b) there is no synchronize to inhibit a context switch to another thread
that mutates this (e.g. does setSkill())
If you want this CSE optimization to be reliable, you need to use a
technology such as OCL that is transitively side-effect free.
I think that Xbase has some abilities to exploit no side effects, but
they depend on programmer discipline rather than language principles.
Regards
Ed Willink
On 10/07/2016 00:12, Stephane Galland wrote:
> Hi all.
>
> In my DSL, I have:
>
> protected def caller {
> getSkill(C1).myfunction(Integer)
> getSkill(C1).myfunction(Float, 1)
> getSkill(C1).myfunction(String, 2, 3)
> }
>
>
> The generated Java code is:
>
> protected void caller() {
> C1 _skill = this.getSkill(C1.class);
> _skill.myfunction(Integer.class);
> C1 _skill_1 = this.getSkill(C1.class);
> _skill_1.myfunction(Float.class, 1);
> C1 _skill_2 = this.getSkill(C1.class);
> _skill_2.myfunction(String.class, 2, 3);
> }
>
>
> In the generated code, the three variables _skill, _skill_1, _skill_2
> are pointing to the same C1 instance; because there is no setSkill call.
>
> I would like to know if the Xbase expression generator is able to
> optimize the generated Java code? Is a documentation that explain
> optimization of the generated code?
>
> At the end I would like to obtain:
>
> protected void caller() {
> C1 _skill = this.getSkill(C1.class);
> _skill.myfunction(Integer.class);
> _skill.myfunction(Float.class, 1);
> _skill.myfunction(String.class, 2, 3);
> }
>
>
> Thank you.
> Stéphane.
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.49462 seconds