Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Parsing code under inactive #if or #ifdef

On the surface it may seem like a simple thing to parse code in inactive regions, but in reality it can become very tricky. For example how would you parse the following code:

#define x 42
int x = 42;
y = x;

In one branch x is a macro, in the other x is a variable. If both branches are parsed then the x in the last statement is ambiguous.

The problem is that there is no relationship between the preprocessor language and the programming language. Preprocessor conditionals can appear anywhere, and can break language constructs. So in reality this is actually an incredibly difficult problem to solve.

Mike Kucera
Software Developer
IBM Eclipse CDT Team

Inactive hide details for "Dmitry Smirnov" ---09/11/2008 09:00:50 AM---Hi,"Dmitry Smirnov" ---09/11/2008 09:00:50 AM---Hi,


"Dmitry Smirnov" <divis1969@xxxxxxxxx>




09/11/2008 09:00 AM


[cdt-dev] Parsing code under inactive #if or #ifdef


I'm trying to use AST/PDOM for parsing a project in goal to build
browsable view of the code (outside of Eclipse, some set of WEB

For this purpose I would like to have inactive code to be parsed too.
As I can see, now this is prevented by CPreprocessor class. Method
executeIfdef() and other similar methods call

I would like to propose some enchancement for this. I believe some
scanner options could be added that changes default behaviour. If this
option is active, CPreprocessor will not call
skipOverConditionalCode() thus making parser to handle all the code.

I suppose, some methods should also be changed (like values of macro
defined inside active/inactive branches).

What do you think about such feature? Perhaps, CDT already have some
plans for similar enchancement?

I'm going to test this approach with CDT 5.0. If you have some
thoughts that could help me with it, please let me know.

cdt-dev mailing list

GIF image

GIF image

Back to the top