proper way to enrich model [message #1385797] |
Wed, 11 June 2014 09:29 |
Yoel Pinhas Messages: 17 Registered: October 2013 |
Junior Member |
|
|
Hi,
I have a grammar that accepts something that looks like this:
entity A {
int i = 1
int j
}
entity B extends A {
int j = 2
}
entity C extends B {
int k = 3
}
When I generate code from 'entity C' it actually have 3 fields: i, j and k, and, the values are: 1, 2, 3 correspondingly.
However, the emf model only contain k
What is the 'proper' way of handling this?
- sure, it's easy to evaluate the values - but i want to do this only once
I can think of several solutions:
1) Effect the creation of the emf model somehow (how?) and manually add the missing i and j to C (and j to B) while xtext is creating the model
2) 'piggyback' the extra fields on the resource/emf model while in doGenerate (am i allowed to do that?)
3) Use cache to cache fields references and values once calculated/deduced
4) Create my own model (bahh!)
Option 4 - is my least favorite.
Option 3 - looks nicer, but I don't think it's elegant
Option 2 - I don't know if I'm allowed to do that at all?
Option 1 - Sounds promising, I think that a good starting point is this: xtextcasts.org/episodes/18-model-optimization
So, what is the 'proper' xtext way to do this? is there a proper way?
Any comment will be warmly accepted
Yoel.
|
|
|
|
|
|
Re: proper way to enrich model [message #1385902 is a reply to message #1385835] |
Thu, 12 June 2014 08:20 |
Yoel Pinhas Messages: 17 Registered: October 2013 |
Junior Member |
|
|
Christian:
Thank you for your reply. Yes, I'm traversing the model using extension methods. this covers some of my problem.
Uli:
Thank you very much, yes! your snippet is helping me with the scoping aspect
I will order Lorenzo's book, it seems like a very good book
Consider the following example (a little more complex)
entity Doll {
int height
Cuteness cutenessLevel
Color eyeColor
Color hairColor
Gender gender
}
Entity BlondDoll extends Doll {
Color hairColor = Color.BLONDE
}
Entity VeryCuteDoll extends {
Cuteness cutenessLevel = Cuteness.VERY_CUTE
}
Entity MaleDoll extends Doll {
Gender gender = Gender.MALE
}
Entity VeryCuteBlondeDoll extends VeryCuteDoll, BlondDoll {
}
Entity DollHouse {
MaleDoll veryCuteBlondeMaleDoll42 = new VeryCuteBlondeDoll(height=42)
}
When I evaluate 'veryCuteBlondeMaleDoll42' I have to find the assignment for all of its values (height, cutenessLevel, eyeColor, hairColor and gender)
they come from different places, some stem from weird inheritance (blond) some from C'tor (height) and some from the value type (male)
This example sheds some more light on the grammar and the correct phrases in it.
Furthermore, things in real world scenario are a little more complicated than this.
Finding the assignment for each value of Doll is not hard.
But it does take some time and effort. And when I have of large number of values which are referenced from pre-compiled parts I want to use that.
My question is how to 'store' the data once I found it, once I traced its origin?
Can I store data in the EMF? should I?
Perhaps cache is answer?
Thanks again, Yoel
p.s.
Perhaps I'm going on a limb here, but I'm new to Xtext. I presume that there is a standard approach that is best practice in compilation of structures of this sort - I could be all wrong :0)
[Updated on: Thu, 12 June 2014 11:22] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03287 seconds