Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] issue with ASTRewrite and assert macro

You can get macro expansions by calling org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.getMacroExpansions(). Node locations returned by org.eclipse.cdt.internal.core.dom.parser.ASTNode.getNodeLocations() link AST nodes to macro expansions (see org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation).

-sergey


On Mon, Jul 22, 2013 at 3:06 PM, Ayupov, Andrey <andrey.ayupov@xxxxxxxxx> wrote:

I don’t see any macro related nodes, e.g. IASTPreprocessorMacroExpansion, in my AST.

For this chunk of code:

assert(n>0);

 

I see this representation in AST:

 

This is from the DOM AST Viewer. Not sure if it is accurate.

 

I’ll take a look at the code you pointed to. Thanks!

 

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Sergey Prigogin
Sent: Monday, July 22, 2013 2:41 PM


To: CDT General developers list.
Subject: Re: [cdt-dev] issue with ASTRewrite and assert macro

 

The AST contains more than just preprocessed code. The process of macro expansion, possibly involving multiple steps, is represented too. org.eclipse.cdt.internal.formatter.CodeFormatterVisitor contains many examples of dealing with that information. CodeFormatterVisitor.formatFunctionStyleMacroExpansion(IASTPreprocessorMacroExpansion) and CodeFormatterVisitor.getMacroArguments(int) methods can be of particular interest.

 

-sergey

 

On Mon, Jul 22, 2013 at 2:30 PM, Ayupov, Andrey <andrey.ayupov@xxxxxxxxx> wrote:

Sergey,

 

I am trying to understand what the correct behavior would be in this case. I believe when you generate the AST you’re already dealing with the code after preprocessor, so you don’t have any idea about whether it was a macro or not in the original code. Is that correct? If so, then the only possible thing to generate is the expanded version of the macro, i.e. code under the macro definition, right? How is that different from any other code then and why it is not working now… Any suggestions what I should look for?

 

Thanks,

Andrey

 

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Sergey Prigogin
Sent: Friday, July 19, 2013 5:32 PM
To: CDT General developers list.
Subject: Re: [cdt-dev] issue with ASTRewrite and assert macro

 

I don't think ASTRewrite can handle changes affecting macro arguments. Could you please file a bug. I'll gladly review any patch that comes with it.

 

-sergey

 

On Fri, Jul 19, 2013 at 5:12 PM, Ayupov, Andrey <andrey.ayupov@xxxxxxxxx> wrote:

Just wanted to check if the issue that I am hitting is a known one and would appreciate any feedback on whether there are plans to fix it.

ASTRewrite does not generate assert macro from AST correctly. I made an experiment, where for the following code

 

assert(a>0);

 

I just replaced IASTIdExpression (corresponding to variable ‘a’ in the _expression_ above a>0) by its copy, presumably without changing the AST structure:

rewriter.replace(orig, orig.copy(), null);

 

The code that’s being generated looks like this:

a;

 

Just for reference, the assert macro is taken from assert.h that looks like this:

# define assert(expr) \

  (__ASSERT_VOID_CAST ((expr) ? 0 :                                                                           \

                                     (__assert_fail (__STRING(expr), __FILE__, __LINE__,    \

                                                                   __ASSERT_FUNCTION), 0)))

 

Thanks,

Andrey

 


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

 


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

 


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



Back to the top