Context node not found when using label Follow
OK, so I'm finally starting on the generation phase of my test language. Let's say I have the following:
record RGB
Red : UnsignedInteger8
Green : UnsignedInteger8
Blue : UnsignedInteger8
end record
Lines like "Red : UnsignedInteger8" are FieldDeclarations. There are a number of primitive types that a field can be defined as, so I'm using weaving rules to generate read/write method calls to my binary stream runtime lib. However, I'm getting an error that the context node for the weaving rule cannot be found. I've defined a mapping label:
label statement : <no input concept> -> ClassConcept
and I've attached that to a root mapping rule:
concept Record --> statement : map_Statement
inheritors false
condition <always>
keep input root default
then in my weaving rule, I select the FieldDeclaration by the type and forward that to a template using "statement" as the context:
concept FieldDeclaration -->weave_UI8
inheritors false context: (node, genContext, operationContext)->node< > {
condition (node, genContext, operationContext)->boolean { genContext . get output statement ;
node . type . isInstanceOf ( UnsignedInteger8 ) ; }
}
but apparently "statement" cannot be found. FWIW, map_Statement is a ClassConcept and I want to use a template fragment to define the body of two methods in that Class. Any suggestions as to why that label is not working?
Thanks,
Kevin
Please sign in to leave a comment.
Hello, Kevin.
In order to find node by label you should provide an input node, for example
genContext . get output statement for (node.ancestor<concept = Record>);
Finding a node by label only works for labels attached to conditional rules (i.e. when input node does not exist at all).
Hi Julia,
Thanks for the info. I'm not sure I see why a label would work in one situation and not another, but your suggestion has gotten me past the error I described and now I'm on to the next set of errors :-)
-Kevin
Kevin,
For example, if you had a model with several roots of concept Record, MPS would generate a class for each of them. So without knowing an input node MPS won't be able to decide, which class to choose for a label.
A conditional rule generates only one node, that eliminates the above problem.
Regards,
Julia
Julia,
Thank you for the explanation. I had thought the transforms were serial in nature, thus the current RecordDeclaration that was being processed would be the active "statement" value. However, it sounds like I should view transforms as possibly occurring in parallel.
Thanks,
Kevin