Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 334188

Summary: The refactoring infrastructure does not apply changes made to ASTNodes that are a part of a statement if any part of the statement is a macro
Product: [Tools] CDT Reporter: Fredrik Berg Kjolstad <fredrikbk>
Component: cdt-refactoringAssignee: Sergey Prigogin <eclipse.sprigogin>
Status: RESOLVED FIXED QA Contact: Sergey Prigogin <eclipse.sprigogin>
Severity: normal    
Priority: P3 CC: cdtdoug, emanuel, malaperle, mschorn.eclipse, yevshif
Version: 8.0   
Target Milestone: 8.1.0   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
Removes a check that directly prints verbatim statements with macro sub-nodes cdtdoug: iplog+

Description Fredrik Berg Kjolstad CLA 2011-01-12 20:55:47 EST
Build Identifier: M20100909-0800

If any child node of an IASTStatement (except for Compund statements) is a macro then the refactoring infrastructure will not apply any changes made to another child node.

The following function call demonstrates the bug. I want replace the last actual argument of the MPI_Isend function with another expression:
MPI_Isend(message, strlen(message) + 1, MPI_CHAR, 1, 42, MPI_COMM_WORLD, &waitreq2);

However, since MPI_CHAR is a macro the ASTWriterVisitor decides to write the statement directly, and aborts further processing in its sub-tree.

The code in question is line 185-187 in visit(IASTStatement statement) in ASTWriterVisitor.java.  Here, the method StatementWriter.writeMixedStatement is called to print the statement directly, without the modifications in its subtree, if it contains a macro.  On the next line, 188, provisions are made in the case where the statement itself is a macro.

I can not easily work around this by just replacing the whole statement, as I do not know which actual I need to modify (I discover this by searching for all variables for a binding).

Reproducible: Always

Steps to Reproduce:
1. Create a statement containing a macro in one actual argument
2. Use ASTRewriter.replace (remove works too) to replace one actual argument
3. Apply the rewriter and observe that the modification was lost
Comment 1 Fredrik Berg Kjolstad CLA 2011-01-12 21:07:48 EST
Created attachment 186696 [details]
Removes a check that directly prints verbatim statements with macro sub-nodes

Is the code to directly print statements containing various macros correct, and what is its purpose?  It seems that it may be unnecessary as the macros will be dealt with anyway when the sub-nodes are visited by the printer.

The attached patch removes this check altogether, which fixes my problem.  Does this break another case I have failed to anticipate?
Comment 2 Sergey Prigogin CLA 2011-12-14 15:40:47 EST
Fixed together with bug 363244.