简体   繁体   中英

Referencing C++ Types in Xtext Grammar/DSL

I've spent several days trying to come up with a solution for referencing C++ types in an Xtext DSL. At this point, I'm quite familiar with the Xtext/Eclipse mechanism for reference Java/JVM types.

Presumably to do something similar to the JVM import mechanism, I would have to save an existing (possibly quite large) CDT index as an Ecore and the import that Ecore into my Xtext Grammar.

The other alternative I'm considering is some programatic hook into the existing CDT Index. It seems this option may be more difficult in that it would likely involve more custom code to implement.

Has anyone out there discovered and successfully implemented reference of C++ types in Xtext grammar/DSL? Any examples? Any suggestions for better solution? For that matter do either of my proposed solutions seem reasonable/doable?

Thank you.

To actually be able to reference C++ or any non-Xtext element in Xtext DSLs, you have to bring the referrable elements into Xtext's index.

The right way to do would be to have an IAllContainerState that includes the CDT index and create an IResourceDescription per C++ file. The CDT index should contain the information about the contained resources, types and names, this could be mapped to the concepts described in the scoping chapter: https://eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping

The GenericResourceServiceProvider could be used to an IResourceServiceProvider for C++ resources.

Have a look at the org.eclipse.xtext.resource.generic package and how it is used to index .ecore models.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM