Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [cdt-dev] adding a new language to the CDT

Hi Michael,
just to make it clear, what you are trying to do cannot be done via public API and is thus not supported by CDT.
When using CDT to add PL8 support you first have to make the decision whether you are looking at language extension of c or c++. Only, then you can safely reuse the existing implementation of IAST... interfaces. In case your language is different, you should be creating your own AST that represents PL8. I guess you just want minimal support for PL8, so
you probably can get away with faking a CASTTranslationUnit.
If you do have a parser that creates a reasonable IASTTranslationUnit, you have to make sure that the language is registered with CDT (there is an extension point for that). Also the langauge needs to return the correct linkage-id, in
order to be considered for indexing. In your case you want the stuff to be added to the c-linkage, so you should return
You might have to use a debugger to figure out whether your parser get's called and whether stuff is added to
the index.

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Michael Rosenfelder
Sent: Tuesday, October 28, 2008 2:15 PM
To: cdt-dev@xxxxxxxxxxx
Subject: [cdt-dev] adding a new language to the CDT
Importance: Low

I'm working on an Eclipse Plug-In to support a procedural programming language called PL8, a PL/I variant for systems programming. We have PL8 and C source files in one source tree (project). Our compiler builds all files to object files and then they are linked together to one binary. It is possible to call a C-function from a PL8-function and vice versa. So our idea was to use the CDT and treat the source tree as a C/C++ project. The C/C++ files will be handled by CDT and the PL8 files are handled by a PL8 editor (Syntax highlighting, outline view). We also want to use the code navigation feature in the PL8 context. Therefore our idea was to add some informations like function definitions in the C-index. We created a Java class PL8Language implementing the ILanguage interface from the ILanguage Extension Point of the CDT. The parser of the PL8 should not create an own index, but should add the functions of PL8 language to the index, created by the CDT-Parser.
If I click e.g. on a PL8-function in a C-file, the C-indexer searches for the function in the now combined index for the location of the function and jumps to it. If I click in a PL8-file, my own indexer searchs for the function in the combined index.

I think the solution is to implement the getASTTranslationUnit and my own ModelBuilder.
I tried to implement the getASTTranslationUnit in this way.

public IASTTranslationUnit getASTTranslationUnit(CodeReader reader,
                        IScannerInfo scanInfo, ICodeReaderFactory fileCreator,
                        IIndex index, IParserLogService log) throws CoreException {
                final ISourceCodeParser parser= new PL8SourceCodeParser(index);
                // Parse
                IASTTranslationUnit ast= parser.parse();
                return ast;

The parse function of my SourceCodeParser looks like the following:

public IASTTranslationUnit parse() {
                IASTTranslationUnit result;
                //Create a new TranslationUnit
                translationUnit = new CASTTranslationUnit();
                //Name of the function
                char name_str[] = {'A', 'B'};
                CASTName declaratorName = new CASTName(name_str);
                //new SimpleDeclaration
                IASTSimpleDeclaration declaration = new CASTSimpleDeclaration();
                IASTStandardFunctionDeclarator declarator = new CASTFunctionDeclarator(declaratorName);
                CASTSimpleDeclSpecifier declSpec = new CASTSimpleDeclSpecifier();
                result = translationUnit;
                translationUnit = null;
                return result;

The goal is to add a function AB to the index. But the current situation is different. There is no function with the name AB in the index and at the moment I had no idea what the reason is. The return value of the parse function is the right one. The return value has the function included.
At the moment I found no other way to write into the index, which is used for the source code navigation.

I also searched for a solution in the CDT Wiki in the topic Design. It is clearly explained about the CDT works, but no explanation how I can implement my idea.

So my question to you, where is my mistake or is it generally possible to implement my idea?
Is there anything additional I have to do or can you point me to an example ?

Thank you in advance!

Kind regards


Back to the top