Handling Keil C51 keywords in the Eclipse indexer

228 views Asked by At

According to Keil C51, the following is valid:

static void kernel(void) small interrupt 1 using 2
{
    /* do stuff */
}

According to the Eclipse indexer, however, it isn't. We can make the following definitions to help the case:

#define small /*small*/
#define interrupt /*interrupt*/

But unfortunately, we can't redefine the reserved keyword 'using' and it would be silly to redefine the numbers 1 or 2.

Is there a way to get the Eclipse indexer to parse ancient 8051 code in order to reap the benefits of a modern IDE? Is there an alternative to Eclipse that can offer an efficient way to navigate through such a C project? Something with an equivalent "Open Call Hierarchy" function?

2

There are 2 answers

2
Eugene Sh. On

You can redefine the problematic keywords for the CDT indexer only. When the indexer is running, the symbol __CDT_PARSER__ is defined. When compillation is running this symbol won't be defined. So you can do something like:

#ifdef __CDT_PARSER__
#undef small
#define small
//....etc
#endif

Or you can have a macro replacing the function definition:

#ifndef __CDT_PARSER__
#define KEIL_SPECIFIC_STUFF(param1, param2) small interrupt param1 using param2
#else 
#define KEIL_SPECIFIC_STUFF(param1, param2)
#endif

and then

static void kernel(void) KEIL_SPECIFIC_STUFF(1,2)
{
    /* do stuff */
}
0
aes79 On

In fact I created an Eclipse plugin exactly for this purpose a few years ago. I've uploaded the code to github. You may find a binary build of the plugin here: https://github.com/andersesbensen/eclipse-c51-plugin/blob/master/deployment/eclipse-c51-plugin.zip

You need to activate to plugin under "Language Mappings" in your C project.

The plugin may not be perfect, but its a good start. Feel free to contribute to the code if you find anything not working.

Best regards Anders