Bug 252358 - QVTO grammar: Support expressions in the (implicit) population section
Summary: QVTO grammar: Support expressions in the (implicit) population section
Status: RESOLVED FIXED
Alias: None
Product: QVTo
Classification: Modeling
Component: Engine (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 2.0 M4   Edit
Assignee: Alexander Igdalov CLA
QA Contact:
URL:
Whiteboard:
Keywords: Documentation, noteworthy
Depends on:
Blocks:
 
Reported: 2008-10-28 09:50 EDT by Alexander Igdalov CLA
Modified: 2008-11-13 14:51 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Igdalov CLA 2008-10-28 09:50:26 EDT
Currently, the implicit population section in mappings can only consist of so called patternPropertyOrAddition elements, which are in fact assignment to properties. The explicit population section currently supports a list of oclExpressionCS, i.e. it enables all expressions from OCL and most of the imperative expressions from QVTO, except assignments, variable initializations, log and assert expressions. The end section enables all kinds of imperative expressions.

That would be great if not the spec! It says we can have any kinds of expressions in the population section. It is allowed by the grammar:

<population_section> ::= <expression_list> | 'population' <expression_block>
<expression_list> ::= <expression_semi_list> ';'? 
<expression_semi_list> ::= <expression> (';' <expression>)* 
<expression_block> ::= '{' <expression_list>? '}'
<expression> ::= <assign_exp> | <let_exp>  <var_init_exp> 
and so forth to any other expressions.

The spec also drops the following hint. In the simplest case of a single result the contents of an implicit population section are considered to be the contents of an implicit object expression. (8.2.1.19). Thus, all expressions allowed in ObjectExp body are allowed in the population section. The ObjectExp permits any expressions, including arbitrary assignments. This is proved in the examples in 8.2.1.18 and 8.1.5 and by the grammar rule: 
<object_exp> ::= 'object' ('(' <iter_declarator > ')')? <object_declarator> <expression_block>
Judging by what is written above, I consider that any kinds of expressions should be allowed in implicit and explicit population sections.
Comment 1 Alexander Igdalov CLA 2008-10-28 10:13:29 EDT
Another technical question is name clashing. What if a local variable clashes with some property? There are three ways to deal with that:
1. Resolve the ambiguity to the property
2. Report an error
3. Resolve to the variable
I think the first approach is definitely wrong. Consider a metamodel update which adds or removes some clashing property - the QVTO script might unexpectedly change its behaviour.
The second variant is better. But in case of a metamodel update (adding some new property) some scripts that used to work correctly would not compile.
I prefer the third variant. Metamodel updates would be transparent to legacy scripts. It is closer to Java where local variables in scope hide fields.
Comment 2 Sergey Boyko CLA 2008-10-28 11:31:27 EDT
I'd also prefer variant 3) since it provides most robustness to external influence like metamodel changes.
Comment 3 Radomil Dvorak CLA 2008-10-28 13:03:28 EDT
(In reply to comment #1)
variant 3 sound best to me too.
Comment 4 Alexander Igdalov CLA 2008-11-13 13:54:47 EST
Fixed.