finally got the changes, but it still seems to be problems.. when
I try to insert the pragma on a for loop (it works for
functions)
java.lang.NullPointerException
at
org.eclipse.cdt.internal.core.dom.rewrite.astwriter.StatementWriter.writeCompoundStatement(StatementWriter.java:380)
at
org.eclipse.cdt.internal.core.dom.rewrite.astwriter.StatementWriter.writeStatement(StatementWriter.java:123)
at
org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriterVisitor.visit(ASTWriterVisitor.java:185)
at
org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGeneratorWriterVisitor.visit(ChangeGeneratorWriterVisitor.java:326)
at
org.eclipse.cdt.internal.core.dom.parser.c.CASTCompoundStatement.accept(CASTCompoundStatement.java:53)
at
org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriter.write(ASTWriter.java:91)
at
org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.synthTreatment(ChangeGenerator.java:215)
at
org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.synthTreatment(ChangeGenerator.java:207)
at
org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.visit(ChangeGenerator.java:497)
at
org.eclipse.cdt.internal.core.dom.parser.c.CASTCompoundStatement.accept(CASTCompoundStatement.java:53)
at
org.eclipse.cdt.internal.core.dom.parser.c.CASTFunctionDefinition.accept(CASTFunctionDefinition.java:103)
at
org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit.accept(ASTTranslationUnit.java:241)
at
org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.generateChange(ChangeGenerator.java:115)
at
org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.generateChange(ChangeGenerator.java:107)
at
org.eclipse.cdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.rewriteAST(ASTRewriteAnalyzer.java:24)
at
org.eclipse.cdt.core.dom.rewrite.ASTRewrite.rewriteAST(ASTRewrite.java:177)
at modules.CodeNav.insertLiteral(CodeNav.java:207)
// the
StatementWriter.java file..
private void
writeCompoundStatement(IASTCompoundStatement compoundStatement)
{
scribe.printLBrace();
scribe.newLine();
for (IASTStatement
statements : getNestedStatements(compoundStatement)) {
statements.accept(visitor);
// can be null
sometimes! }
// the
C-program that I parse...
#include <stdio.h>
int
main(void) {
int i;
for(i = 0; i
< 4; i++) {
printf("%d\n",
i);
}
return
0;
}
/Jimmie
2008/7/21 Schorn, Markus
<Markus.Schorn@xxxxxxxxxxxxx>
The
following code should do the trick:
ASTRewrite re=
ASTRewrite.create(ast);
IASTNode lit=
re.createLiteralNode("#pragma
xxx\n");
re.insertBefore(belowNode, beforeNode
lit, null);
Change change= re.rewriteAST();
change.perform(new
NullProgressMonitor());
A quick
test showed that this does not work with 5.0. I have now corrected
the ASTWriter, such that the code above will work in 5.0.1 >
20080721.
Markus.
hi
I want to be able to insert a pragma (a
IASTPreprocessorPragmaStatement) in the middle of an existing AST and then
in I want to reflect the changes back to the sourcecode accordingly. I've
searched some and found the ASTRewrite somewhat interesting but can't get
it to work as I want. Can anyone give an example of how to use it or point
me somewhere else?
thanks in
advance
/Jimmie
_______________________________________________
cdt-dev
mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev