Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Global variables in EGL(Definition of EGL global variables )
Global variables in EGL [message #1750608] Fri, 23 December 2016 09:30 Go to next message
Víctor López is currently offline Víctor LópezFriend
Messages: 22
Registered: June 2014
Junior Member
Hi all!,
I wonder if it is possible to specify a global variable in an EGL file so that variable is available in both the templates and the rest of the EGL file. For instance, imagine defining an enumeration to be used in both templates and the rest of the EGL.
I don't know how to do it (if it is possible) so the global variable is available also in the templates.

Best,

Víctor
Re: Global variables in EGL [message #1750615 is a reply to message #1750608] Fri, 23 December 2016 11:04 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1498
Registered: July 2009
Location: York, UK
Senior Member

Hi Victor,

Global variables can be defined in the pre section of your EGX specification and then passed on to templates using the parameters {} block of EGX rules (see [1] for an example).

Cheers,
Dimitris

[1] https://www.eclipse.org/epsilon/doc/articles/code-generation-tutorial-egl/
Re: Global variables in EGL [message #1750619 is a reply to message #1750615] Fri, 23 December 2016 11:22 Go to previous messageGo to next message
Víctor López is currently offline Víctor LópezFriend
Messages: 22
Registered: June 2014
Junior Member
Thanks Dimitris, but I still have the same problem.
When I specify the global variable as a param (as you explained) it is available to the general body of the EGL file, but not in the templates I call to make the generation more modular. That is, it is similar to specifying a variable at the beginning of the EGL file.
Is there any special way of referencing these global variables from a template?
I just use the name of the variable as in the rest of the code, but I get the Undefined variable error.

Best,

Víctor López


Dimitris Kolovos wrote on Fri, 23 December 2016 12:04
Hi Victor,

Global variables can be defined in the pre section of your EGX specification and then passed on to templates using the parameters {} block of EGX rules (see [1] for an example).

Cheers,
Dimitris

[1] https://www.eclipse.org/epsilon/doc/articles/code-generation-tutorial-egl/

Re: Global variables in EGL [message #1750622 is a reply to message #1750619] Fri, 23 December 2016 12:09 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1498
Registered: July 2009
Location: York, UK
Senior Member

Hi Victor,

I see what you mean. I've fixed this in [1] so top-level variables should now be accessible from sub-templates invoked using [%include("foo.egl");%]. Once Hudson has finished building the new interim version [2] you can pick up a copy from [3]. Many thanks for reporting this!

Cheers,
Dimitris

[1] https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/commit/?id=d04d07b8d7da9febfd96729ca9ec14be6886c299
[2] https://hudson.eclipse.org/epsilon/job/epsilon-interim-update-site/189/
[3] http://download.eclipse.org/epsilon/interim/
Re: Global variables in EGL [message #1750624 is a reply to message #1750622] Fri, 23 December 2016 12:36 Go to previous messageGo to next message
Víctor López is currently offline Víctor LópezFriend
Messages: 22
Registered: June 2014
Junior Member
Thanks a lot Dimitris.
I found another scenario closely related where global variables are not working as I expected.

Imagine this egx file to transform an UML Class:

rule testCase

transform aClass: Class {
	template: "test.egl"
	target: "gen/src/" + aClass.name.firstToUpperCase() + ".java" 
	parameters {
    // These parameters will be made available
    // to the invoked template as variables
	    var params : new Map;
	    params.put("allIntegerTypes", Set{'int', 'integer', 'tinyint', 'smallint', 'mediumint', 'bigint', 'long', 'unsigned int', 'unsigned long', 'short', 'byte'});
	    return params;
    }
}


An this egl file:

/********************************************************/
/*  Class: [%=aClass.name.concat('.java').pad(45,' ',true)%]*/
/*  Testing global variables                            */
/********************************************************/

{
 The size of the set is: [%=allIntegerTypes.size() %] [this is working]
 
 [%= aClass.test()%] [this is not working, allIntegerTypes is undefined in the template ]
}


[% @template
 operation Class test() { %]
 	The size of the set in this templates is: [%=allIntegerTypes.size() %]
[% } %]


I was expecting allIntegerTypes to be available within the template, but it isn't. Is it the expected behaviour?

Best,

Víctor López

Dimitris Kolovos wrote on Fri, 23 December 2016 13:09
Hi Victor,

I see what you mean. I've fixed this in [1] so top-level variables should now be accessible from sub-templates invoked using [%include("foo.egl");%]. Once Hudson has finished building the new interim version [2] you can pick up a copy from [3]. Many thanks for reporting this!

Cheers,
Dimitris

[1] https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/commit/?id=d04d07b8d7da9febfd96729ca9ec14be6886c299
[2] https://hudson.eclipse.org/epsilon/job/epsilon-interim-update-site/189/
[3] http://download.eclipse.org/epsilon/interim/

Re: Global variables in EGL [message #1750626 is a reply to message #1750624] Fri, 23 December 2016 12:45 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1498
Registered: July 2009
Location: York, UK
Senior Member

Hi Victor,

With a quick test, this seems to be working fine on my side with the latest interim version (i.e. global variables are visible within @template operations). Could you please put together a minimal example [1] I can use to reproduce this?

Cheers,
Dimitris

[1] https://www.eclipse.org/epsilon/doc/articles/minimal-examples/

[Updated on: Fri, 23 December 2016 12:46]

Report message to a moderator

Re: Global variables in EGL [message #1750628 is a reply to message #1750626] Fri, 23 December 2016 12:55 Go to previous message
Víctor López is currently offline Víctor LópezFriend
Messages: 22
Registered: June 2014
Junior Member
Hi Dimitris,
Thanks for your quick reply.
Yes it is working on Interim version, but it isn't on 1.4 version.
I'll use the interim version in the meantime.

Best,

Víctor López

Dimitris Kolovos wrote on Fri, 23 December 2016 13:45
Hi Victor,

With a quick test, this seems to be working fine on my side with the latest interim version (i.e. global variables are visible within @template operations). Could you please put together a minimal example [1] I can use to reproduce this?

Cheers,
Dimitris

[1] https://www.eclipse.org/epsilon/doc/articles/minimal-examples/

Previous Topic:How Can I change the icons on pop-up tool palette with Eugenia?
Next Topic:Populate method in Template: Not working as expected
Goto Forum:
  


Current Time: Fri Jan 19 11:55:35 GMT 2018

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

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