summaryrefslogtreecommitdiffstats
path: root/compilerplugins/clang/plugin.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-07-21 15:01:44 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-07-22 08:46:34 +0200
commit0281b187752a6da62b801f4a4acf5cf74c2c31f2 (patch)
tree1a9dbdf2d44009aec94acc28b4b8716e4afe5093 /compilerplugins/clang/plugin.cxx
parentvcl: fix Unicode cast in mnemonic test (diff)
downloadcore-0281b187752a6da62b801f4a4acf5cf74c2c31f2.tar.gz
core-0281b187752a6da62b801f4a4acf5cf74c2c31f2.zip
make oncevar plugin ignore methods with #ifdef-ery
Change-Id: I8a9cf2c4b81b95bf654f7e90306328d72e3d3408 Reviewed-on: https://gerrit.libreoffice.org/40280 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/plugin.cxx')
-rw-r--r--compilerplugins/clang/plugin.cxx48
1 files changed, 48 insertions, 0 deletions
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx
index 66e22d507818..5bfdc4ed3a83 100644
--- a/compilerplugins/clang/plugin.cxx
+++ b/compilerplugins/clang/plugin.cxx
@@ -273,6 +273,54 @@ bool Plugin::isUnitTestMode()
return PluginHandler::isUnitTestMode();
}
+bool Plugin::containsPreprocessingConditionalInclusion(SourceRange range)
+{
+ auto const begin = compiler.getSourceManager().getExpansionLoc(
+ range.getBegin());
+ auto const end = compiler.getSourceManager().getExpansionLoc(
+ range.getEnd());
+ assert(begin.isFileID() && end.isFileID());
+ if (!(begin == end
+ || compiler.getSourceManager().isBeforeInTranslationUnit(
+ begin, end)))
+ {
+ // Conservatively assume "yes" if lexing fails (e.g., due to
+ // macros):
+ return true;
+ }
+ auto hash = false;
+ for (auto loc = begin;;) {
+ Token tok;
+ if (Lexer::getRawToken(
+ loc, tok, compiler.getSourceManager(),
+ compiler.getLangOpts(), true))
+ {
+ // Conservatively assume "yes" if lexing fails (e.g., due to
+ // macros):
+ return true;
+ }
+ if (hash && tok.is(tok::raw_identifier)) {
+ auto const id = tok.getRawIdentifier();
+ if (id == "if" || id == "ifdef" || id == "ifndef"
+ || id == "elif" || id == "else" || id == "endif")
+ {
+ return true;
+ }
+ }
+ if (loc == range.getEnd()) {
+ break;
+ }
+ hash = tok.is(tok::hash) && tok.isAtStartOfLine();
+ loc = loc.getLocWithOffset(
+ std::max<unsigned>(
+ Lexer::MeasureTokenLength(
+ loc, compiler.getSourceManager(),
+ compiler.getLangOpts()),
+ 1));
+ }
+ return false;
+}
+
RewritePlugin::RewritePlugin( const InstantiationData& data )
: Plugin( data )
, rewriter( data.rewriter )