File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -218,6 +218,8 @@ class INOPreprocessorMatcherCallback : public MatchFinder::MatchCallback {
218218 }
219219};
220220
221+ static string preprocessedSketch;
222+
221223class 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}
You can’t perform that action at this time.
0 commit comments