Problems with References

Hello

 

I have read most of the posts about bidirectional referencing, but it didnt really help me.

 

My Goal is to store further Data in an AST by referencing to Nodes "outside" the AST. (<- Not importent information for the description of my problem)

 

My First step was to create an annotation that can be applied to every node. This annotation is of concept  "Ann" and holds 1 reference on a node of concept B. B should have a reference back on Ann. The Problem is that B must hold multiple refs on nodes of type Ann. B is NOT inside the regular AST. It exists at the "side".

I think I have an understanding on how the multiple refs problem can be solved, but what I dont understand are 2 things.

1. The concept of smart References, it seems to me its kinda like a bidirectional ref but not really?!?! I am confused.

 

2. Simply assigning a reference . I would like to write somehting like : node.@Ann.reference =  new node<B>, but that doesnt work . Basicly I dont understand how to use the API at this point.

 

If someone could help me, I would really appreciate it.

 Here a little drawing that might help visualize my problem

 

                      ASTNode

                       /            \

           ASTNode          ASTNode (Ann) ---->      <--B-->   <--/

              |                                                                             /

         ASTNode                                                               / 

            /     \                                                               /

  AstNode   AstNode(Ann) -------->--------->------- /

 

 

 

4 comments

1. Smart references are not really bi-directional, but "transparent". They are only applicable to references of cardinality 1, in which cases MPS can substitute the references with the reference targets, for example in code-completion menus.

2. The "node.@attribute" syntax that you mention should work. Do you have any more details on what exactly fails when assigning a node to the reference in the attribute?

0

Thx for the answers.

About 2. . I had the Ann set to multiple annotations possible, MPS didnt know which Ann to assign the reference to. My fault, the assignment of a reference worked fine after I changed the occurance of the annotation to just one.

 

But now I ran into another problem. When I create that Node of Type B, like in my example above, via an Intention in my Sample Solution, it is not saved.

The Annotation is still there, but Node B is gone after I reload the Language Project? Is it that only Nodes that are reachable by the "child" relation are persistently saved ?

 

 

0

Since your annotation only refers to node B, node B is not part of the model and so gets deleted once the model reloads. Only containment links (parent-child) make the referents part of the model. References merely point to other parts of the model.

Perhaps you may make node B a child of the annotation. Or make sure it is a child of some other node in the model.

0

Ok, so it's like i thought. Well then I will have to find a way to connect it to the model. Thx again.

0

Please sign in to leave a comment.