Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext, Xbase 2.3 - expressions with no side effects
Xtext, Xbase 2.3 - expressions with no side effects [message #827551] Fri, 23 March 2012 13:40 Go to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1762
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi

I see that in the current version the xbase generation is slightly
changed and as an additional validation it checks whether an expression
has actually side effects (mustBeJavaStatementExpression)

in the xbase validator we have

@Check
public void checkInnerExpressions(XBlockExpression block) {
for (int i = 0; i < block.getExpressions().size() - 1; ++i) {
XExpression expr = block.getExpressions().get(i);
mustBeJavaStatementExpression(expr);
}
}

which does not check the last expression in a block

however, xbase generation for XBlockExpression performs

protected void _toJavaStatement(XBlockExpression expr, ITreeAppendable
b, boolean isReferenced) {
b = b.trace(expr, false);
if (expr.getExpressions().isEmpty())
return;
if (expr.getExpressions().size()==1) {
internalToJavaStatement(expr.getExpressions().get(0), b, isReferenced);
return;
}

thus, in case there's only one expression in a block it treats it like a
statement assuming it does have side effects, but this has not been
checked during the validation...

Indeed, an xbase expression like

val EClass eClass = ...
eClass.EStructuralFeatures.forEach [
it.name != "foo"
]

generates this Java code

final Procedure1<EStructuralFeature> _function = new
Procedure1<EStructuralFeature>() {
public void apply(final EStructuralFeature it) {
String _name = it.getName();
(!Objects.equal(_name, "foo"));
}
};

which does not compile, since

(!Objects.equal(_name, "foo"));

has no side effect...

probably, the generation in case there's only one expression should do

internalToJavaStatement(expr.getExpressions().get(0), b, isReferenced);

with isReferenced set to true?

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: Xtext, Xbase 2.3 - expressions with no side effects [message #827946 is a reply to message #827551] Sat, 24 March 2012 01:40 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Hi Lorenzo,

please file a bugzilla.

Sven

Am 3/23/12 9:40 AM, schrieb Lorenzo Bettini:
> Hi
>
> I see that in the current version the xbase generation is slightly
> changed and as an additional validation it checks whether an expression
> has actually side effects (mustBeJavaStatementExpression)
>
> in the xbase validator we have
>
> @Check
> public void checkInnerExpressions(XBlockExpression block) {
> for (int i = 0; i < block.getExpressions().size() - 1; ++i) {
> XExpression expr = block.getExpressions().get(i);
> mustBeJavaStatementExpression(expr);
> }
> }
>
> which does not check the last expression in a block
>
> however, xbase generation for XBlockExpression performs
>
> protected void _toJavaStatement(XBlockExpression expr, ITreeAppendable
> b, boolean isReferenced) {
> b = b.trace(expr, false);
> if (expr.getExpressions().isEmpty())
> return;
> if (expr.getExpressions().size()==1) {
> internalToJavaStatement(expr.getExpressions().get(0), b,
> isReferenced);
> return;
> }
>
> thus, in case there's only one expression in a block it treats it like a
> statement assuming it does have side effects, but this has not been
> checked during the validation...
>
> Indeed, an xbase expression like
>
> val EClass eClass = ...
> eClass.EStructuralFeatures.forEach [
> it.name != "foo"
> ]
>
> generates this Java code
>
> final Procedure1<EStructuralFeature> _function = new
> Procedure1<EStructuralFeature>() {
> public void apply(final EStructuralFeature it) {
> String _name = it.getName();
> (!Objects.equal(_name, "foo"));
> }
> };
>
> which does not compile, since
>
> (!Objects.equal(_name, "foo"));
>
> has no side effect...
>
> probably, the generation in case there's only one expression should do
>
> internalToJavaStatement(expr.getExpressions().get(0), b, isReferenced);
>
> with isReferenced set to true?
>
> cheers
> Lorenzo
>


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: Xtext, Xbase 2.3 - expressions with no side effects [message #828155 is a reply to message #827946] Sat, 24 March 2012 09:32 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1762
Registered: July 2009
Location: Firenze, Italy
Senior Member
Done

https://bugs.eclipse.org/bugs/show_bug.cgi?id=375230

though I see that the domain model example is not affected: the
generated Java code is

final Procedure1<EStructuralFeature> _function = new
Procedure1<EStructuralFeature>() {
public void apply(final EStructuralFeature it) {
String _name = it.getName();
/*(!Objects.equal(_name, "foo"));*/
}
};

note that the not valid Java statement is commented out...

the problem comes up in my case since I call xbase compiler
programmatically... should I set some kind of flag for that?

thanks in advance
Lorenzo

On 03/24/2012 02:40 AM, Sven Efftinge wrote:
> Hi Lorenzo,
>
> please file a bugzilla.
>
> Sven
>
> Am 3/23/12 9:40 AM, schrieb Lorenzo Bettini:
>> Hi
>>
>> I see that in the current version the xbase generation is slightly
>> changed and as an additional validation it checks whether an expression
>> has actually side effects (mustBeJavaStatementExpression)
>>
>> in the xbase validator we have
>>
>> @Check
>> public void checkInnerExpressions(XBlockExpression block) {
>> for (int i = 0; i< block.getExpressions().size() - 1; ++i) {
>> XExpression expr = block.getExpressions().get(i);
>> mustBeJavaStatementExpression(expr);
>> }
>> }
>>
>> which does not check the last expression in a block
>>
>> however, xbase generation for XBlockExpression performs
>>
>> protected void _toJavaStatement(XBlockExpression expr, ITreeAppendable
>> b, boolean isReferenced) {
>> b = b.trace(expr, false);
>> if (expr.getExpressions().isEmpty())
>> return;
>> if (expr.getExpressions().size()==1) {
>> internalToJavaStatement(expr.getExpressions().get(0), b,
>> isReferenced);
>> return;
>> }
>>
>> thus, in case there's only one expression in a block it treats it like a
>> statement assuming it does have side effects, but this has not been
>> checked during the validation...
>>
>> Indeed, an xbase expression like
>>
>> val EClass eClass = ...
>> eClass.EStructuralFeatures.forEach [
>> it.name != "foo"
>> ]
>>
>> generates this Java code
>>
>> final Procedure1<EStructuralFeature> _function = new
>> Procedure1<EStructuralFeature>() {
>> public void apply(final EStructuralFeature it) {
>> String _name = it.getName();
>> (!Objects.equal(_name, "foo"));
>> }
>> };
>>
>> which does not compile, since
>>
>> (!Objects.equal(_name, "foo"));
>>
>> has no side effect...
>>
>> probably, the generation in case there's only one expression should do
>>
>> internalToJavaStatement(expr.getExpressions().get(0), b, isReferenced);
>>
>> with isReferenced set to true?
>>
>> cheers
>> Lorenzo
>>
>
>


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Previous Topic:grammar with imported model
Next Topic:Complete keyword with lookahead
Goto Forum:
  


Current Time: Mon Apr 06 21:35:09 GMT 2020

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

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

Back to the top