diff --git a/main.cpp b/main.cpp index 0516fab..251383c 100644 --- a/main.cpp +++ b/main.cpp @@ -197,10 +197,7 @@ class INOPreprocessorMatcherCallback : public MatchFinder::MatchCallback { FullSourceLoc first = undeclaredIdentifiers.back()->location; if (first.isBeforeInTranslationUnitThan(begin)) { - if (debugOutput) { - outs() << " !! Insertion point found!\n"; - } - insertionPointFound = true; + markInsertionPointAsFound(); return; } @@ -216,10 +213,22 @@ class INOPreprocessorMatcherCallback : public MatchFinder::MatchCallback { } if (first.isBeforeInTranslationUnitThan(end)) { + markInsertionPointAsFound(); + } + } + + void markInsertionPointAsFound() { + if (debugOutput) { + outs() << " !! Insertion point found at "; + outs() << insertionPoint.getSpellingLineNumber() << ":" << insertionPoint.getSpellingColumnNumber() << "\n"; + } + insertionPointFound = true; + + if (insertionPoint.getSpellingColumnNumber() != 1) { if (debugOutput) { - outs() << " !! Insertion point found!\n"; + outs() << " Insertion point is not at the line beginning -> adding a newline\n"; } - insertionPointFound = true; + rewriter.InsertTextAfter(insertionPoint, "\n"); } } diff --git a/testsuite/testdata/test_issue_7.cpp b/testsuite/testdata/test_issue_7.cpp new file mode 100644 index 0000000..a52e355 --- /dev/null +++ b/testsuite/testdata/test_issue_7.cpp @@ -0,0 +1,9 @@ +// https://github.com/arduino/arduino-preprocessor/issues/7 + +#line 1 "issue_7.ino" + +int a; int b=f(); + +int f() { + return 1; +}