Skip to content

Commit 9f6cf45

Browse files
committed
Always output preprocessed sketch (even when there are no changes)
1 parent 9faaa35 commit 9f6cf45

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

main.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ class INOPreprocessorMatcherCallback : public MatchFinder::MatchCallback {
218218
}
219219
};
220220

221+
static string preprocessedSketch;
222+
221223
class INOPreprocessAction : public ASTFrontendAction {
222224
MatchFinder finder;
223225
INOPreprocessorMatcherCallback funcDeclaredCB;
@@ -241,16 +243,14 @@ class INOPreprocessAction : public ASTFrontendAction {
241243
outs() << out.str();
242244
}
243245

244-
if (!outputPreprocessedSketch) {
245-
return;
246-
}
247-
248246
const FileID mainFileID = rewriter.getSourceMgr().getMainFileID();
249247
const RewriteBuffer *buf = rewriter.getRewriteBufferFor(mainFileID);
250248
if (buf == nullptr) {
251-
errs() << "No changes needed!\n";
249+
// No changes needed, output the source file as-is
250+
auto buff = rewriter.getSourceMgr().getBuffer(mainFileID);
251+
preprocessedSketch = buff->getBuffer().str();
252252
} else {
253-
outs() << string(buf->begin(), buf->end());
253+
preprocessedSketch = string(buf->begin(), buf->end());
254254
}
255255
}
256256
};
@@ -267,5 +267,10 @@ int main(int argc, const char **argv) {
267267
tool.setDiagnosticConsumer(&dc);
268268

269269
int res = tool.run(newFrontendActionFactory<INOPreprocessAction>().get());
270+
271+
if (outputPreprocessedSketch) {
272+
cout << preprocessedSketch;
273+
}
274+
270275
return res;
271276
}

0 commit comments

Comments
 (0)