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:

#ifdef USE_MACRO_CONSTANTS
#define x 42
#else
int x = 42;
#endif
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
mkucera@xxxxxxxxxx

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


From:

"Dmitry Smirnov" <divis1969@xxxxxxxxx>

To:

cdt-dev@xxxxxxxxxxx

Date:

09/11/2008 09:00 AM

Subject:

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




Hi,

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
pages).

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
skipOverConditionalCode().

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.

Dmitry
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev


GIF image

GIF image


Back to the top