Scoping & "Cyclic resolution of lazy links" error [message #704285] |
Thu, 28 July 2011 09:09  |
Eclipse User |
|
|
|
Hi,
I am implementing a language where I have implementation dissociated from declaration.
basically something like
struct_decl S {
int public_var;
}
stuct_impl S {
int private_var = 3;
public_var = private_var;
}
i.e. The struct_impl references its associated struct_decl. The elements declared in the struct_decl are accessible from the associated stuct_impl.
For scoping, I use nested scopes with basically this code:
IScope getScope(EObject context, EReference reference) {
return createScope(getScope(context.eContainer(), reference), context, reference);
}
IScope createScope(IScope parent, EObject context, EReference reference) {
return SelectableBasedScope.createScope(
parent,
new MultimapBasedSelectable(Scopes.scopedElementsFor(context.eContents(), qualifiedNameProvider)),
reference.getEReferenceType(),
isIgnoreCase(reference)
);
};
In addition I handle the top level element and I cache the MultimapBasedSelectable.
In the case of stuct_impl however, this simple scheme isn't enough. I have to allow referencing the elements of the struct_decl.
In order to do that I simply introduced the content of the struct_decl just after that of the stuct_imp, i.e.
IScope getScope(EObject context, EReference reference) {
IScope parent = getScope(context.eContainer(), reference);
if ( context instanceof StructImpl ) {
parent = createScope(parent, context.getDeclaration(), reference);
}
return createScope(parent, context, reference);
}
However with this code I get a "Cyclic resolution of lazy links" error. From the call stack, it seems that accessing the declaration reference starts the reference resolution process that launch the scoping process thus inducing a cycle ...
|
|
|
Re: Scoping & "Cyclic resolution of lazy links" error [message #704344 is a reply to message #704285] |
Thu, 28 July 2011 10:18  |
Eclipse User |
|
|
|
I managed to get rid of the error by replacing the call to "getDeclaration()" by a call to "eGet(HlaPackage.eINSTANCE.getStructImpl_Declaration(), false)" and only inserting the intermediate scope if "eIsProxy()" is false.
The resulting code looks like:
IScope getScope(EObject context, EReference reference) {
IScope parent = getScope(context.eContainer(), reference);
if ( context instanceof StructImpl ) {
EObject declaration = (EObject) context.eGet(HlaPackage.eINSTANCE.getStructImpl_Declaration(), false);
if ( !declaration.eIsProxy() ) parent = createScope(parent, context.getDeclaration(), reference);
}
return createScope(parent, context, reference);
}
I don't know if it's the right way to do it or if there's a cleaner way ...
|
|
|
Powered by
FUDForum. Page generated in 0.02764 seconds