[cfe-dev] Rewriter::InsertText

Сергей Филиппов rolenof at gmail.com
Thu Aug 5 03:04:16 PDT 2010


Hi,
I'm facing strange bug with Rewriter::InsertText.
Here is the code:

void RewritingPass::Initialize(ASTContext &context)
{
    this->context = &context;
    SourceLocation L;
    mainFileId = context.getSourceManager().getMainFileID();
    rewriter = new Rewriter(context.getSourceManager(),
context.getLangOptions());
    const llvm::StringRef preamble(getPreamble());
    if (preamble.size() > 0)

rewriter->InsertText(context.getSourceManager().getLocForStartOfFile(mainFileId),
preamble, true);
}

const std::string CastRewritePass::getPreamble() const
{
    return " /* cast rewrite pass */\n\n";
}

after execution of RewritingPass::Initialize preamble changed it's not /*
cast rewrite pass*/, but 0\230\bast rewrite pass*/.
I found a solvation - use not string in getPreamble, but StringRef. If i do
so, it works ok.

Sergey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100805/dfbb3eca/attachment.html>


More information about the cfe-dev mailing list