Handling XBase references to overloaded signatures outside of XBlockExpressions [message #1722622] |
Sun, 07 February 2016 08:24 |
Larry LeBron Messages: 124 Registered: October 2015 |
Senior Member |
|
|
This is a continuation of a question I asked recently, but stands on its own.
I'm writing a language using XBase, using the JVMModelInferrer.
In my language, I have entities which define parameters much like a java method:
Entity:
'entity' name=ID '(' (params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)* )?
Elsewhere in my code, I reference these entities and want to be able to pass arguments to them from outside of XBlockExpressions. Current grammar:
EntityReference:
'entRef' entity=[Entity] '(' (args+=XExpression (',' args+=XExpression)*)? ')' ';'
;
These are not standard function calls, so would not work in a standard XBlockExpression.
My Entity rule supports overloaded parameter signatures, however the EntityReference rule's [Entity] just matches the first instance of an entity with a matching name. How can I ensure that only entities with a valid parameter list will be referenced?
[Updated on: Sun, 07 February 2016 08:43] Report message to a moderator
|
|
|
Re: Handling XBase references to overloaded signatures outside of XBlockExpressions [message #1722625 is a reply to message #1722622] |
Sun, 07 February 2016 09:50 |
|
Polymorphic dispatch is the most compilcated thing you can actually do.
what you have to do in your scoping (and what xbase does for method calls)
- find the best linking candidate amoung all canidates
- therefore have a look at all potential candidates and pick the one that best meets the actually given parameters (you may use the type computer as help)
- i cannot say if this works well since your entity reference is nothing xbase knows about.
- therefor you have to do all on your own
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Re: Handling XBase references to overloaded signatures outside of XBlockExpressions [message #1722668 is a reply to message #1722626] |
Mon, 08 February 2016 07:42 |
Larry LeBron Messages: 124 Registered: October 2015 |
Senior Member |
|
|
Thanks for the suggestion.
After some research, it looks like the best means of customizing this is via:
In RuntimeModule:
/* Bind the delegate in the scope provider */
override configureIScopeProviderDelegate(Binder binder) {
binder.bind(IScopeProvider).
annotatedWith(Names.
named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).
to(MyDSLNamespaceAwareLocalScopeProvider);
}
In MyDSLNamespaceAwareLocalScopeProvider:
override IScope getScope(EObject context, EReference reference) {
getScopeCustom(context, reference)
}
/* For entity ref, choose the best linking candidate among all candidates to support polymorphic dispatch */
def private dispatch getScopeCustom(EntityRef entRef, EReference reference) {
// implement here
}
/* For other types, just use the super's scope calculation */
def private dispatch getScopeCustom(EObject context, EReference reference) {
super.getScope(context, reference)
}
Do you agree? While I need the linking to work in the end, I would like the content assist to suggest all potential options which could be linked based on the current list of arguments. If that means a separate solution for content assist in this case, that's fine.
As far as the specific implementation goes, is it then reasonable to just iterate through all Entity objects, choosing one Entity based on these criteria:
- Entity.parameters.size == EntityRef.args.size
- Each parameter type is assignable from the corresponding argument type
- A ranking function which then determines the best match amongst those that qualify
Is there some unforeseen risk in this approach, considering it'll be operating while the programmer is typing?
I've been trying to find XBase's implementation for this (e.g. for method calls in XExpressions), but I haven't been able to find it yet.
As far as the semantic meaning of this EntityRef, I've intentionally presented the simplest example here to get at the core of the problem. The language I'm writing is for a reactive planning system. The EntityRef call is used to find potential behaviors which correspond with a name and type signature. In the actual language, these are called Goals and they reference Behaviors. At runtime, the execution of this statement binds the arguments to their current values and places a node on a tree, containing those bound argument values, the target name and the type signature. When this node is chosen for execution, the potential behavior space is searched for options which match the name and type signature and fulfill execution preconditions. If a viable option exists, the arguments are used to call its constructor, which results in a child object being added to the tree for execution below this Goal (EntityRef) node. Since this statement can only reference a behavior (Entity), I assumed it would be easiest to implement this way, vs. using a generic XExpression and somehow allowing only behavior calls.
|
|
|
|
Re: Handling XBase references to overloaded signatures outside of XBlockExpressions [message #1722802 is a reply to message #1722668] |
Tue, 09 February 2016 09:24 |
Jan Koehnlein Messages: 760 Registered: July 2009 Location: Hamburg |
Senior Member |
|
|
Xbase's linking semantics and algorithm is rather different from plain Xtext, as it involves the typesystem, method overloading, type inference etc. I'd rather not mix both approaches.
It should be easier to map your entities to Java, e.g. implement a common marker interface, and do the linking with the Java semantics Xbase provides you. The matching algorithm you describe is pretty much what Xbase does for method calls anyway. So think about how you would implement that in Java in a typesafe manner, and then implement your JvmModelInferrer appropriately.
Iterating all Entities in your workspace is something that will kill performance in the long run, as all models containing entities have to be loaded (parsed, type resolved, linked...). Such an operation should never be performed in an interactive scenario such as content assist.
---
Get professional support from the Xtext committers at www.typefox.io
|
|
|
Powered by
FUDForum. Page generated in 0.03826 seconds