Given code such as:
auto r = func(std::move(a));
I’m trying to use the writer to add a new if block while introducing a new variable. The expected new code would be:
if (condition) {
r = func(std::move(newA));
} else {
r = func(std::move(a));
}
I’m able to add the if block, but I haven’t found a way to copy the original expression and change the argument name in the new if block.
Current code to add if block:
void addGaterBlock(
const clang::SourceManager* sm,
Writer* writer,
const VarDecl* call) {
std::stringstream ss;
ss << "if (condition) {n";
writer->insertBefore(call, ss.str());
auto loc = clang::Lexer::findLocationAfterToken(
call->getEndLoc(), clang::tok::semi, *sm, clang::LangOptions(), false);
writer->insertAt(loc, "n}");
}
Any guidance would be appreciated.