How to properly transform IDL imports

196 views
Skip to first unread message

klau...@intel.com

unread,
May 9, 2014, 9:47:06 AM5/9/14
to franca-f...@googlegroups.com
Hi,

I am implementing a transformation from a proprietary IDL format into Franca IDL. I got everything runnig except IDL imports. I am currently running into two problems:

1.) When I add an import to the appropriate transformed Franca IDL file I get a NullPointerException when I try to save the transformed IDL.

The transformed Franca IDL itself is saved correctly. But then the ModelPersistenceHandler tries to recursively save all imported models. But at that point it is unable to find the imported model in the resource set although I see it loaded in the debugger. This happens in ModelPersistenceHandler.saveModel(EObject, String, String). It should be line 154 in the current Git HEAD.

When I open the transformed Franca IDL in the Eclipse editor the import is correctly resolved, so this may well be a bug.

2.) I am not sure how I should resolve references to types that are defined in the imported IDL. I was thinking about using the FrancaIDLScopeProvider but as far as I have seen that would require a resource set which is not available during the transformation.

Can somebody help me with this problem?

Kind regards
Klaus

Klaus Birken

unread,
May 9, 2014, 10:37:18 AM5/9/14
to franca-f...@googlegroups.com
Hi Klaus,


Am Freitag, 9. Mai 2014 15:47:06 UTC+2 schrieb klau...@intel.com:
Hi,

I am implementing a transformation from a proprietary IDL format into Franca IDL. I got everything runnig except IDL imports. I am currently running into two problems:

1.) When I add an import to the appropriate transformed Franca IDL file I get a NullPointerException when I try to save the transformed IDL.

The transformed Franca IDL itself is saved correctly. But then the ModelPersistenceHandler tries to recursively save all imported models. But at that point it is unable to find the imported model in the resource set although I see it loaded in the debugger. This happens in ModelPersistenceHandler.saveModel(EObject, String, String). It should be line 154 in the current Git HEAD.

When I open the transformed Franca IDL in the Eclipse editor the import is correctly resolved, so this may well be a bug.

I agree, that might be a bug; I quickly reviewed the code and compared it to the analogous part of loadModel(), which does some additional resolving, which might be needed during saveModel, too. 

Could you add an issue to the Franca issue list, please? Please also state the details about your import string (URI or plain path? abs or relative? ...), so that we can build a test case.


2.) I am not sure how I should resolve references to types that are defined in the imported IDL. I was thinking about using the FrancaIDLScopeProvider but as far as I have seen that would require a resource set which is not available during the transformation.

I am not sure I understand the requirement here. I would assume that you also transform the data types from the original IDL to Franca types, put them in a separate fidl-file and refer to this by using an import statement, right? Or do you want to refer to data types of the IDL from Franca interfaces definitions directly? The latter could be implemented (by mapping the types of the other IDL to synthetic Franca types), even without touching Franca code, but this is not for the faint-hearted. I would recommend to transform all elements of the other IDL to Franca elements, including types. Then you just have to ensure that all Franca resources created during the transformation are in the same resource set.

Regards,
Klaus

klau...@intel.com

unread,
May 9, 2014, 10:59:44 AM5/9/14
to franca-f...@googlegroups.com
Hi Klaus,

on 1) I will file a bug.

on 2) Ok, my description might have been a bit brief ;-)

I have two IDL files. One file (lets call it decl.idl) defines a set of common datatypes. The second file (lets call it iface.idl) defines an interface that imports decl.idl and uses some of the types declared there in its method signatures.

I have already successfully transformed decl.idl to decl.fidl. Now, I want to transform iface.idl to iface.fidl, using the already transfomed decl.fidl (and the type definitions therein) as import. I am currently using only the filename for the import because URI resolution does not work as I would need it (see https://groups.google.com/d/topic/franca-framework/i9mk19MfLbU/discussion), i.e. the transformed iface.fidl contains the definition
import model "decl.fidl"

Unfortunately, I cannot easily load the imported model because I do not "natively" have access to a resource set. My transformation is called from IFrancaConnector.toFranca() which returns an FModel that is created "in the air" (i.e. not connected to any Resource or ResourceSet) and is saved outside of the connector and transformation classes.

I could, of course, inject a FrancaPersistenceManager into my transformation class and create a local ResourceSet there but then I would have to pass the (parent) path of the iface.fidl into the transformation so that the URI resolution would work. I would definitely find a workaround to do that but it feels a bit clumsy in my opinion.

Therefore, I am asking if there is a best known method to handle this kind of transformation. Maybe it does not yet exist and maybe the Franca interfaces need to be extended at this point.

Kind regards
Klaus

Klaus Birken

unread,
May 13, 2014, 8:01:48 AM5/13/14
to franca-f...@googlegroups.com
Hi,

I suggest to create the ResourceSet in your connector class (implementing IFrancaConnector) and hand it over to the transformation in toFranca(). Additionally you could hand over a list of additional model files (e.g., decl.fidl) to the transformation, either as URIs or loaded FModels. The connector class could maintain a map from source-idl URIs (or resources) to the transformed ones. Thus you could determine all dependent files and load them as a preparation for the next transformation. I am not sure if this would meet your requirements in terms of passing pathes around, but I guess this could be implemented without violating the existing interfaces.

We were building a similar solution for transforming Franca to ROOM models (this is the opposite direction, but the code would be quite similar). In that use case, the generated ROOM models use a previously existing model and have to refer to it by an import statement. You can find the code here (see classes ROOMConnector, Franca2ETriceTransformation and Modellib): https://code.google.com/a/eclipselabs.org/p/franca/source/browse/plugins/org.franca.connectors.etrice/src/org/franca/connectors/etrice/?name=dev_etrice

Best regards,
Klaus

klau...@intel.com

unread,
May 16, 2014, 9:30:39 AM5/16/14
to franca-f...@googlegroups.com
Hi Klaus,

thank you for the hint.

Eventually, I ended up creating the ResourceSet directly in the transformation class because I wanted to have a new, empty resource set for each IDL file to be transformed. After having converted the imports from the source IDL into Franca IDL URIs I just loaded those models into the resource set from within the transformation method (using org.franca.core.utils.ModelPersistenceHandler).

To get the type references resolved I just built a lookup table of qualified type names and FType objects by iterating over all type collections and types in all loaded models.

This worked - at least for a first proof of concept implementation. However, it would be convenient if Franca provided utility classes which can be used by any toFranca() transformation that alredy provide this functionality.

Kind regards
Klaus

PS: After having all imported FModel's and the transformed FModel itself loaded into a common ResourceSet the NullPointerException I have reported in https://code.google.com/a/eclipselabs.org/p/franca/issues/detail?id=102 during saving the model is also gone. However, there should be no NullPointerException if the model to be saved is not completely valid.

Reply all
Reply to author
Forward
0 new messages