chicken-or-egg problem with reduction rules


I have a concept A and a concept B with a smart reference to A. Both concepts are extensions to a given language and should be replaced by concepts from that language. So an A node should be replaced by a node of concept A' and B should be replaced by a node of concept B' while the latter has a smart reference to A'. Apparently a job for two reduction rules, right?

If I apply the reduction of A to A' first, in the resulting (transient) model the smart reference of the B node is broken because the A' node does not exist any more. As I need to find the right A' node by its name which is derived from the name of the original A node, I don't see how the reduction rule for B->B' can create the right smart reference.

On the other hand, if I apply the B->B' reduction first then the proper A' node does not exist yet and again I cannot create the smart reference.

How can I solve this problem?

In case you are interested: I want to introduce C++-style templates to a C-style base language. A is a template instantiation, B is the usage of the instantiated template as a type, A' is a struct declaration and B' is the usage of this struct as a type. The code can be found here: revision 139. The problem shows up when generating the stack model of the sandbox solution.



Comment actions Permalink

Hi Alex,

If B’ requires A’, then I believe, you should let those reductions (A->A’, B->B’) to be applied on the same step, so that A’ and B’ appear at the same time in the same transient model.

This way you won’t have this referencing problem.

Regards, Igor.
Comment actions Permalink

Hi Igor

thanks for your reply. I am not sure if I understand it.

The B->B' reduction on the one hand needs the A' node in it's input model so that it can establish the smart reference of the resulting B' node. And on the other hand it needs the smart reference of the B node to the A node to exist, because it looks for the A' node by its name which is derived from the name of the A node.

This might be confusing, so let me state clear:

- The A->A' reduction replaces A nodes with corresponding A' nodes

- The name of the A' node is derived from the name of the A node.

- The B->B' reduction replaces B nodes with corresponding B' nodes

- Each B node has a smart reference to a A node. (B=>A)

- Each B' node has a smart reference to the corresponding A' node. (B'=>A').

- "corresponding" hereby means that the A' was generated from the A node to which the B node refers to.

- The B->B' reduction needs a valid B=>A reference, to get the A node's name in order to be able to query the corresponding A' node from the input model by its name.

So, the B->B' reduction needs both the A and the A' node to exist. But the A node exists only before the A->A' reduction and the A' node only afterwards. How does running both reductions on the same time makes both the A and the A' node available for the B->B' transformation?

If it doesn't, maybe the solution lies in finding the corresponding A' node by other means than it's name. But what could I use as an idendifying feature?



Comment actions Permalink

The B->B' reduction .. needs the A' node in its input model

Nop, it doesn’t. Not in input model.
I suppose you are using reference macro to establish reference B’=>A’.
Reference macros are commonly executed in the very end of a generation step, i.e. after all reductions (of this step) have already been done and the output model already contains B’ nodes as well as A’ nodes.

Parameter ‘node’ in reference macro will give you input node, which is B, and via reference B=>A you can get node A (both A and B are in the input model).

Parameter ‘outputNode’ gives you B’ node, and with some affords you also can find A’ node (using genContext.get output.. operations). But, since you are using smart reference, you don’t need to know B’ or A’ here.

To sum up, providing that both reductions A->A’ and B->B’ go on the same step, your reference macro, by the time of its execution, has all the needed: nodes A,B in the input model and nodes A’,B’ in the output model.

Regards, Igor.

Doc on reference macro and others :
About generation process:


Please sign in to leave a comment.