Rewriting Types


I'm trying to rewrite types in declaration statements, e.g. "int a, b,
c" to "long a; long b; long c;". To do this I use the rewriter as

void TypeVisitor::VisitDeclStmt(DeclStmt *ds)
    ScopedDecl *sd = ds->getDecl();
    while (sd) {
        if (VarDecl *vd = dyn_cast<VarDecl>(sd)) {
        sd = sd->getNextDeclarator();

    if (rewriter.ReplaceStmt(ds, ds))
        llvm::cerr << "cannot rewrite\n";

In my resulting file I get something like this: "long a; long b; long c;
a, b, c;". That is almost the expected output except the extra
"a, b, c;".

What is wrong in my code? Or is it in general the wrong approach to
rewrite types?

Thank you very much in advance,

(Resend; I forgot to cc the list.)

In clang/lib/Parse/ParseStmt.cpp, I see a comment "// FIXME: Pass in
the right location for the end of the declstmt.". That seems likely
to be causing your issue.