summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-09-22 15:32:24 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-09-23 09:04:48 +0200
commitee6bdeec8d618f039e72d496dff44beb5b99abb2 (patch)
treeeabd23b280c8a819137b3a2b22507ed8f1bfb858 /compilerplugins
parenta8622c77d26ca7a635afc95bba9a5054dc31eb7c (diff)
loplugin:flatten in svl..svx
and implement a check in the plugin to prevent us modifying the same patch of source code twice. This logic should probably be moved into plugin.cxx at some point. Change-Id: I7ebff6424cc8733bb2c8f7dba75eaaec68649290 Reviewed-on: https://gerrit.libreoffice.org/42660 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/flatten.cxx15
1 files changed, 15 insertions, 0 deletions
diff --git a/compilerplugins/clang/flatten.cxx b/compilerplugins/clang/flatten.cxx
index fd5094940c3c..4ca9d4fc4382 100644
--- a/compilerplugins/clang/flatten.cxx
+++ b/compilerplugins/clang/flatten.cxx
@@ -38,6 +38,7 @@ private:
SourceRange extendOverComments(SourceRange range);
std::string getSourceAsString(SourceRange range);
std::string invertCondition(Expr const * condExpr, SourceRange conditionRange);
+ std::vector<std::pair<const char *, const char*>> mvModifiedRanges;
};
static const Stmt * containsSingleThrowExpr(const Stmt * stmt)
@@ -124,6 +125,20 @@ bool Flatten::rewrite(const IfStmt* ifStmt)
}
SourceRange elseKeywordRange = ifStmt->getElseLoc();
+ // If we overlap with a previous area we modified, we cannot perform this change
+ // without corrupting the source
+ SourceManager& SM = compiler.getSourceManager();
+ const char *p1 = SM.getCharacterData( ifStmt->getSourceRange().getBegin() );
+ const char *p2 = SM.getCharacterData( ifStmt->getSourceRange().getEnd() );
+ for (std::pair<const char*, const char *> 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);
+
thenRange = extendOverComments(thenRange);
elseRange = extendOverComments(elseRange);
elseKeywordRange = extendOverComments(elseKeywordRange);