Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Scope for custom XVariableDeclaration
Scope for custom XVariableDeclaration [message #1758721] Sat, 01 April 2017 00:04 Go to next message
Daniel Cardin is currently offline Daniel CardinFriend
Messages: 109
Registered: July 2009
Senior Member
Hello everyone,

This is a fragment of my grammar:

Const returns xbase::XVariableDeclaration:
	(=>(type=JvmTypeReference name=ValidID) | name=ValidID) '=' right=XExpression
	;


And my inferrer

// Constants
rule.consts.forEach[ const | 
	inferredClass.members += rule.toField(const.name, const.type) => [
		initializer = const.right
		final = true
	]	
]


This works exactly as expected. The generated code is perfect. But even if I used the constant in some code generated within the class, the editor shows "The value of the local variable XYZ is not used" because in the scope of the dsl model there are no references to it. But in the generated code the warning does not exist, because the const is actually used.

So it's clearly looks to me like a scope validation that fails. But I don't know where I could change it so that the warning disappears.

Thanks for your suggestions

Re: Scope for custom XVariableDeclaration [message #1758729 is a reply to message #1758721] Sat, 01 April 2017 06:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
You may debug at XExpressionHelper hasSideEffects

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Scope for custom XVariableDeclaration [message #1758734 is a reply to message #1758729] Sat, 01 April 2017 12:32 Go to previous messageGo to next message
Daniel Cardin is currently offline Daniel CardinFriend
Messages: 109
Registered: July 2009
Senior Member
Some time ago, this would have needed much more explanations than that!

Thanks for your help Christian Smile
Re: Scope for custom XVariableDeclaration [message #1758735 is a reply to message #1758734] Sat, 01 April 2017 12:47 Go to previous messageGo to next message
Daniel Cardin is currently offline Daniel CardinFriend
Messages: 109
Registered: July 2009
Senior Member
Well, even if I knew exactly what you were talking about, it seems like it has no incidence on the warning.
I'll ask the question in another way that might point you in the right direction.

In an XBlockExpression:
{
val a = 3
println('something else')
}

In that block, the value a will be flagged as unused. How does that happen? Where is the scoping done that checks that a is declared but not used in the following statements?

Thanks!
Re: Scope for custom XVariableDeclaration [message #1758739 is a reply to message #1758735] Sat, 01 April 2017 14:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
No scoping . Have a look where the expression helper is used in the validator

and org.eclipse.xtext.xbase.validation.XbaseValidator.isLocallyUsed(EObject, EObject) and its usages


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 01 April 2017 14:21]

Report message to a moderator

Re: Scope for custom XVariableDeclaration [message #1758749 is a reply to message #1758739] Sat, 01 April 2017 16:46 Go to previous messageGo to next message
Daniel Cardin is currently offline Daniel CardinFriend
Messages: 109
Registered: July 2009
Senior Member
I'll have a look at that. Thanks Christian
Re: Scope for custom XVariableDeclaration [message #1758750 is a reply to message #1758729] Sat, 01 April 2017 17:53 Go to previous messageGo to next message
Daniel Cardin is currently offline Daniel CardinFriend
Messages: 109
Registered: July 2009
Senior Member
I thought I understood why you wanted me to look at the ExpressionHelper, but seriously, I don't.

However, for the record, this does the trick:
In my validator :

override checkLocalUsageOfDeclared(XVariableDeclaration variableDeclaration) {
	if (variableDeclaration.eContainer instanceof Rule == false) {
		super.checkLocalUsageOfDeclared(variableDeclaration);
	}
}


I check that the container is the one I'm expecting and I simply disable the validation if it's in that context. I cannot think of any simpler way to do it.

Thanks for your time, though.

Re: Scope for custom XVariableDeclaration [message #1758751 is a reply to message #1758750] Sat, 01 April 2017 18:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i pointed you to ExpressionHelper since i missunderstood the error message ypu got

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Scope for custom XVariableDeclaration [message #1758752 is a reply to message #1758751] Sat, 01 April 2017 18:22 Go to previous message
Daniel Cardin is currently offline Daniel CardinFriend
Messages: 109
Registered: July 2009
Senior Member
oh ok, so at least I didn't miss anything obvious!!

keep up the good work Very Happy
Previous Topic:I lost my arithmetics ;)
Next Topic:IJvmModelAssociations across models
Goto Forum:
  


Current Time: Tue Apr 23 10:58:05 GMT 2024

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

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

Back to the top