Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Logical containers for expressions (again)
Logical containers for expressions (again) [message #1022358] Thu, 21 March 2013 18:25 Go to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 671
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Hi,

I have a model with lots of xbase expressions, which are spread across
many methods in the inferred and generated Java code. E.g. all
expressions for initializing my variable-like construct end up in a
single initialize method. E.g. the following DSL code

var Double d1 = new Double(1);
var Double d2 = new Double(2);

generates the following initialize code:

Double d1;
Double d2;

void initialize() throws IllegalActionException {
Double _d1 = new Double(1);
this.d1 = _d1;
Double _d2 = new Double(2);
this.d2 = _d2;
}

Each of the initial value expressions are all assigned to the initialize
method as their logical container. This will ensure that they are
properly scoped. However, after moving to xbase 2.4, this stopped
working. In this particular example, the Double constructor in the
second expression (new Double(2)) didn't resolve, but the one in the
first did. In other examples, the problem is always that something in
all but the first expression assigned to a logical container does not
resolve.

When I created a separate method that wrapped (was assigned as the
logical container of) each expression it worked again. I.e.

Double initD1() throws IllegalActionException {
Double _d1 = new Double(1);
return _d1;
}
Double initD2() throws IllegalActionException {
Double _d2 = new Double(2);
return _d2;
}

void initialize() throws IllegalActionException {
this.d1 = initD1();
this.d2 = initD2();
}

Is it a (new) constraint in xbase 2.4. that a method can only be the
logical container of a single expression?

Hallvard
Re: Logical containers for expressions (again) [message #1022789 is a reply to message #1022358] Fri, 22 March 2013 14:28 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3107
Registered: July 2009
Senior Member
Hi Hallvard,

the logically contained expression is actually the body of the method,
so each method can only have one contained *root* expression. This was a
bug in the previous version that could have cause trouble and
inconsistencies in the compiler if this *feature* was used by accident.

Why did you want to initialize all variable in one separate method? This
will most likely confuse the Java compiler, too, e.g. when it tries to
verify definite assignment / initialization.

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 21.03.13 19:25, schrieb Hallvard Trætteberg:
> Hi,
>
> I have a model with lots of xbase expressions, which are spread across
> many methods in the inferred and generated Java code. E.g. all
> expressions for initializing my variable-like construct end up in a
> single initialize method. E.g. the following DSL code
>
> var Double d1 = new Double(1);
> var Double d2 = new Double(2);
>
> generates the following initialize code:
>
> Double d1;
> Double d2;
>
> void initialize() throws IllegalActionException {
> Double _d1 = new Double(1);
> this.d1 = _d1;
> Double _d2 = new Double(2);
> this.d2 = _d2;
> }
>
> Each of the initial value expressions are all assigned to the initialize
> method as their logical container. This will ensure that they are
> properly scoped. However, after moving to xbase 2.4, this stopped
> working. In this particular example, the Double constructor in the
> second expression (new Double(2)) didn't resolve, but the one in the
> first did. In other examples, the problem is always that something in
> all but the first expression assigned to a logical container does not
> resolve.
>
> When I created a separate method that wrapped (was assigned as the
> logical container of) each expression it worked again. I.e.
>
> Double initD1() throws IllegalActionException {
> Double _d1 = new Double(1);
> return _d1;
> }
> Double initD2() throws IllegalActionException {
> Double _d2 = new Double(2);
> return _d2;
> }
>
> void initialize() throws IllegalActionException {
> this.d1 = initD1();
> this.d2 = initD2();
> }
>
> Is it a (new) constraint in xbase 2.4. that a method can only be the
> logical container of a single expression?
>
> Hallvard
Re: Logical containers for expressions (again) [message #1022851 is a reply to message #1022789] Fri, 22 March 2013 16:35 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 671
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 22.03.13 07.28, Sebastian Zarnekow wrote:
>
> the logically contained expression is actually the body of the method,
> so each method can only have one contained *root* expression. This was a
> bug in the previous version that could have cause trouble and
> inconsistencies in the compiler if this *feature* was used by accident.

Which I apparently did. I've now defined a method for each of the
expressions, which is called where the expressions previously were
placed. This results in very verbose classes, and worse, the methods are
visible everywhere, so it clutters the completion proposals.

If several expressions in a DSL are supposed to end up as *part* of a
method's body, what is the best way to do it, to get scoping etc. right?

> Why did you want to initialize all variable in one separate method? This
> will most likely confuse the Java compiler, too, e.g. when it tries to
> verify definite assignment / initialization.

In know, but the life-cycle of the instances is controlled by a
framework/protocol that requires initialization to be in a specific
method. There are also issues with exceptions.

Hallvard
Re: Logical containers for expressions (again) [message #1023263 is a reply to message #1022851] Sat, 23 March 2013 19:58 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3107
Registered: July 2009
Senior Member
Am 22.03.13 12:35, schrieb Hallvard Trætteberg:
> On 22.03.13 07.28, Sebastian Zarnekow wrote:
>>
>> the logically contained expression is actually the body of the method,
>> so each method can only have one contained *root* expression. This was a
>> bug in the previous version that could have cause trouble and
>> inconsistencies in the compiler if this *feature* was used by accident.
>
> Which I apparently did. I've now defined a method for each of the
> expressions, which is called where the expressions previously were
> placed. This results in very verbose classes, and worse, the methods are
> visible everywhere, so it clutters the completion proposals.
>
> If several expressions in a DSL are supposed to end up as *part* of a
> method's body, what is the best way to do it, to get scoping etc. right?
>
>> Why did you want to initialize all variable in one separate method? This
>> will most likely confuse the Java compiler, too, e.g. when it tries to
>> verify definite assignment / initialization.
>
> In know, but the life-cycle of the instances is controlled by a
> framework/protocol that requires initialization to be in a specific
> method. There are also issues with exceptions.
>
> Hallvard
>

Hi Hallvard,

if you make the synthesized methods private and start their names with
an underscore, they will not be visible from content assist.

In the future we'll likely (no promises, though) offer an API that'll
allow to delegate to existing expression from new ones, e.g. you could
create a block as the body of the initializer method, and nest these
delegators in the block that will cover your init expressions.

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Previous Topic:Updating completely hosed my environment
Next Topic:[Xtext 2.3] Cross references in DSL across multiple DSL files?
Goto Forum:
  


Current Time: Sat Jan 18 01:26:09 GMT 2020

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

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

Back to the top