cross references to function definitions with same names but different signatures [message #907974] |
Tue, 04 September 2012 13:51 |
Tobias Mayer Messages: 8 Registered: August 2012 |
Junior Member |
|
|
Hello everybody,
my question is about cross references to function definitions with same names but different signatures.
Here is a little language to better describe my concern:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl ""
Model:
elements+=element*;
element:
FunctionDefinition
| RefFunction
| IntVariable
;
IntVariable:
'int' name = ID
;
FunctionDefinition:
'void' name = ID
'(' (argDefList = ArgumentDefinitionList)? ')'
;
RefFunction:
'RefFunction' el = [FunctionDefinition|FunctionDefinitionFormat]
;
ArgumentDefinitionList:
List += ArgumentDefinition ( ',' List += ArgumentDefinition)*
;
ArgumentDefinition:
TypeQualifier id = ID
;
FunctionDefinitionFormat:
ID '(' (ParameterFormat)? ')'
;
ParameterFormat:
ID (',' ID)*
;
TypeQualifier:
'int'
;
. The following code shows a word of this language:
void Funcb(int a, int b)
void Funcb(int a)
int x
int y
. The goal is to extend the code to:
1. void Funcb(int a, int b)
2. void Funcb(int a)
3. int x
4. int y
5. RefFunction Funcb(x,y)
6. RefFunction Funcb(y)
. The editor shell link the name in line 5 to the function definition in line 1 and the name in line 6 to the function definition in line 2. The arguments of a RefFunction shell also be linked to their variable definitions.
First of all, I want to decribe my current idea:
I have extended the DefaultDeclarativeQualifiedNameProvider with the Method "protected QualifiedName qualifiedName(FunctionDefinition funcDef)". The method adds an open and a close bracket at the end of the name of a function. If there are parameters, the datatypes of the parameters are listed between the brackets seperated by commas.
For both functions in the example above the provided qualified names are:
Funcb(int,int)
Funcb(int)
I have also extended the class DefaultLinkingService by overriding the method "List<EObject> getLinkedObjects(EObject context, EReference ref, INode node)". This method is called to solve the cross reference.
The idea is to compare the cross reference string (Funcb(x,y) and Funcb(x)) with the signatures of the function definitions delivered by my qualified name provider. If there is a match, the corresponding EObject to a signature is returned.
With this approach the editor nearly behaves as desired. When I press "F3" the cursor jumps to the right Functiondefinition, too. This also happens when the cursor is on the argument "x" in the RefFunction "RefFunction Funcb(x,y)".
What do I have to do that also the arguments are linked to their variable definitions?
Is there a better way?
Best Regards,
Tobias
|
|
|
|
Powered by
FUDForum. Page generated in 0.02625 seconds