[cfe-dev] Rewriting Types

Stephan Creutz stephan.creutz at inf.tu-dresden.de
Tue May 13 05:55:10 PDT 2008


Hi,

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
follows:

void TypeVisitor::VisitDeclStmt(DeclStmt *ds)
{
    ScopedDecl *sd = ds->getDecl();
    while (sd) {
        if (VarDecl *vd = dyn_cast<VarDecl>(sd)) {
            vd->setType(context.LongTy);
        }
        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,
Stephan



More information about the cfe-dev mailing list