diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-02-09 15:28:41 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-02-10 06:54:27 +0100 |
commit | 94ab8e4360a2a7a932656e99f718244321d0f923 (patch) | |
tree | da3c87614acb2790fed0b1be4bfb389248f657c9 /compilerplugins/clang/pluginhandler.cxx | |
parent | 5853b0b25d439caa619cac2edd9853ac76f84217 (diff) |
improve loplugin rewriter double source modification detection
because my new rewriter easily generates overlapping rewriting.
Move the code from flatten and salcall up into the pluginhandler, and
drop the simpler detection logic.
Change-Id: I3da51ac510954a5d4276cee0924cc5dc1fc9a734
Reviewed-on: https://gerrit.libreoffice.org/49493
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/pluginhandler.cxx')
-rw-r--r-- | compilerplugins/clang/pluginhandler.cxx | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/compilerplugins/clang/pluginhandler.cxx b/compilerplugins/clang/pluginhandler.cxx index 150bc4d1ef4d..3e78030993be 100644 --- a/compilerplugins/clang/pluginhandler.cxx +++ b/compilerplugins/clang/pluginhandler.cxx @@ -236,9 +236,22 @@ bool PluginHandler::checkIgnoreLocation(SourceLocation loc) return true; } -bool PluginHandler::addRemoval( SourceLocation loc ) +// If we overlap with a previous area we modified, we cannot perform this change +// without corrupting the source +bool PluginHandler::checkOverlap(SourceRange range) { - return removals.insert( loc ).second; + SourceManager& SM = compiler.getSourceManager(); + char const *p1 = SM.getCharacterData( range.getBegin() ); + char const *p2 = SM.getCharacterData( range.getEnd() ); + for (std::pair<char const *, char const *> const & rPair : mvModifiedRanges) + { + if (rPair.first <= p1 && p1 <= rPair.second) + return false; + if (p1 <= rPair.second && rPair.first <= p2) + return false; + } + mvModifiedRanges.emplace_back(p1, p2); + return true; } void PluginHandler::HandleTranslationUnit( ASTContext& context ) |