Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Acquire the body of preprocessor #if()/#elseif()statements

Hi Markus,

first of all thanks for the very fast response. 
I had looked inside ITranslationUnit.AST_PARSE_INACTIVE_CODE and have some further questions. I tried the following code

ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file);
IIndex index = CCorePlugin.getIndexManager().getIndex(tu.getCProject());
IASTTranslationUnit ast = tu.getAST(index, ITranslationUnit.AST_PARSE_INACTIVE_CODE);
IASTDeclaration[] declarations = ast.getDeclarations(true);

If I run this code with the sample below I don't get the declaration inside the #if(x).

Is there something wrong with my code or depends this to the following:
* The parser makes its best effort to create ast for the inactive code branches but may decide to skip parts
* of the inactive code (e.g. function bodies, entire code branches, etc.). 


I get the same result if I use the visitor.

ASTVisitor astVisitor = new ASTVisitor(true) {
@Override
public int visit(IASTName name) {
System.out.println("Visit node: " + name.getRawSignature());
return super.visit(name);
}
};


astVisitor.includeInactiveNodes = true;
ast.accept(astVisitor);

Cheers,
Markus 



Am 14.01.2010 um 17:48 schrieb Schorn, Markus:

Hi Markus,
The preprocessor constructs do not have a body in the sense of IASTNodes, they can intersect with ast-nodes at
arbitrary points. Very often this is not the case, however we have to deal with those cases as well.
 
CDT cannot provide you with code completion in inactive code.
You can figure out a reasonable settting for the macros used in your preprocessor conditionals and configure your
project accordingly. You can also have different settings associated with different build configurations and switch back and forth between them.
 
There is some limited support to get AST for inactive code. Please consult the java-doc of ITranslationUnit.AST_PARSE_INACTIVE_CODE for that.
 
Markus.


From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Markus Kopf
Sent: Thursday, January 14, 2010 5:16 PM
To: cdt-dev@xxxxxxxxxxx
Subject: [cdt-dev] Acquire the body of preprocessor #if()/#elseif()statements
Importance: Low

Hi together,

my name is Markus and I am currently working at a solution which can find the elements inside of a preprocessor #if() body. 
Here a small sample what I mean:
void foo(void){
     #if(x) {
        int a;
     }
     #else ......  
}

With this part of code in the code completion list of the cdt editor the element "a" isn't listed. Important to know is that the element "x" has in my scope of the project no value. So it isn't possible for the parser/preprocessor to know if the _expression_ is true or false and will add the elements of the #else part to the ast. As I can get all preprocessor statements from the IASTTranslationUnit I think there should be a way to acquire also the body of such preprocessor #if statements with unknown _expression_ result, isn't it. And that is the point for my idea. If I can get out the preprocessor #if body of the cdt everything would be fine. 
Is there a possibility to get this skiped part? 

Thanks in advance for all your support!!!!

Cheers,
Markus

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

Viele Grüsse / Kind regards,

----------------------------------

Dipl.-Inf. (FH) Markus Kopf 

Tel.:     07231 / 15 471-12
Fax.:    07231 / 15 471-29 
Mobil:  +49 151 / 10 86 04 65
Web:    www.itemis.de
Skype: kopf_markus
ICQ:     292034030

itemis GmbH
Blücherstrasse 32
75177 Pforzheim

Rechtlicher Hinweis:
Amtsgericht Mannheim, HRB 50700996

Ust.Id.Nr.: DE250574762
Geschäftsführer: Sebastian Neus





Back to the top