[Libreoffice-commits] core.git: compilerplugins/clang framework/inc include/cppuhelper sal/qa
Stephan Bergmann
sbergman at redhat.com
Mon Jul 11 14:32:54 UTC 2016
compilerplugins/clang/salbool.cxx | 40 +++++++++++++++++++++++++------
framework/inc/properties.h | 2 -
framework/inc/protocols.h | 4 +--
include/cppuhelper/interfacecontainer.h | 4 +--
sal/qa/osl/security/osl_Security_Const.h | 2 -
5 files changed, 39 insertions(+), 13 deletions(-)
New commits:
commit 6f8d047519c8e80371a646ce4bad8f7304aab6ea
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Mon Jul 11 16:32:28 2016 +0200
loplugin:salbool: Better heuristic to determine code shared between C and C++
Change-Id: I09c9c57d5adeb665cc2508fad9727085a3289bfb
diff --git a/compilerplugins/clang/salbool.cxx b/compilerplugins/clang/salbool.cxx
index 4b123c7..e5e9754 100644
--- a/compilerplugins/clang/salbool.cxx
+++ b/compilerplugins/clang/salbool.cxx
@@ -9,6 +9,7 @@
#include <algorithm>
#include <cassert>
+#include <limits>
#include <set>
#include <string>
@@ -144,14 +145,19 @@ public:
bool TraverseStaticAssertDecl(StaticAssertDecl * decl);
+ bool TraverseLinkageSpecDecl(LinkageSpecDecl * decl);
+
private:
bool isFromCIncludeFile(SourceLocation spellingLocation) const;
+ bool isSharedCAndCppCode(SourceLocation location) const;
+
bool isInSpecialMainFile(SourceLocation spellingLocation) const;
bool rewrite(SourceLocation location);
std::set<VarDecl const *> varDecls_;
+ unsigned int externCContexts_ = 0;
};
void SalBool::run() {
@@ -282,10 +288,9 @@ bool SalBool::VisitCStyleCastExpr(CStyleCastExpr * expr) {
StringRef name { Lexer::getImmediateMacroName(
loc, compiler.getSourceManager(), compiler.getLangOpts()) };
if (name == "sal_False" || name == "sal_True") {
- auto callLoc = compiler.getSourceManager().getSpellingLoc(
- compiler.getSourceManager().getImmediateMacroCallerLoc(
- loc));
- if (!isFromCIncludeFile(callLoc)) {
+ auto callLoc = compiler.getSourceManager()
+ .getImmediateMacroCallerLoc(loc);
+ if (!isSharedCAndCppCode(callLoc)) {
SourceLocation argLoc;
if (compat::isMacroArgExpansion(
compiler, expr->getLocStart(), &argLoc)
@@ -301,17 +306,19 @@ bool SalBool::VisitCStyleCastExpr(CStyleCastExpr * expr) {
}
bool b = name == "sal_True";
if (rewriter != nullptr) {
+ auto callSpellLoc = compiler.getSourceManager()
+ .getSpellingLoc(callLoc);
unsigned n = Lexer::MeasureTokenLength(
- callLoc, compiler.getSourceManager(),
+ callSpellLoc, compiler.getSourceManager(),
compiler.getLangOpts());
if (StringRef(
compiler.getSourceManager().getCharacterData(
- callLoc),
+ callSpellLoc),
n)
== name)
{
return replaceText(
- callLoc, n, b ? "true" : "false");
+ callSpellLoc, n, b ? "true" : "false");
}
}
report(
@@ -725,6 +732,15 @@ bool SalBool::TraverseStaticAssertDecl(StaticAssertDecl * decl) {
|| RecursiveASTVisitor::TraverseStaticAssertDecl(decl);
}
+bool SalBool::TraverseLinkageSpecDecl(LinkageSpecDecl * decl) {
+ assert(externCContexts_ != std::numeric_limits<unsigned int>::max()); //TODO
+ ++externCContexts_;
+ bool ret = RecursiveASTVisitor::TraverseLinkageSpecDecl(decl);
+ assert(externCContexts_ != 0);
+ --externCContexts_;
+ return ret;
+}
+
bool SalBool::isFromCIncludeFile(SourceLocation spellingLocation) const {
return !compiler.getSourceManager().isInMainFile(spellingLocation)
&& (StringRef(
@@ -733,6 +749,16 @@ bool SalBool::isFromCIncludeFile(SourceLocation spellingLocation) const {
.endswith(".h"));
}
+bool SalBool::isSharedCAndCppCode(SourceLocation location) const {
+ // Assume that code is intended to be shared between C and C++ if it comes
+ // from an include file ending in .h, and is either in an extern "C" context
+ // or the body of a macro definition:
+ return
+ isFromCIncludeFile(compiler.getSourceManager().getSpellingLoc(location))
+ && (externCContexts_ != 0
+ || compiler.getSourceManager().isMacroBodyExpansion(location));
+}
+
bool SalBool::isInSpecialMainFile(SourceLocation spellingLocation) const {
if (!compiler.getSourceManager().isInMainFile(spellingLocation)) {
return false;
diff --git a/framework/inc/properties.h b/framework/inc/properties.h
index 383225f..78f4701 100644
--- a/framework/inc/properties.h
+++ b/framework/inc/properties.h
@@ -157,7 +157,7 @@ class PropHelper
css::uno::Any& aOldValue ,
css::uno::Any& aChangedValue )
{
- bool bChanged = sal_False;
+ bool bChanged = false;
// clear return parameter to be sure, to put out only valid values ...
aOldValue.clear();
diff --git a/framework/inc/protocols.h b/framework/inc/protocols.h
index d729d6f..b93f292 100644
--- a/framework/inc/protocols.h
+++ b/framework/inc/protocols.h
@@ -82,7 +82,7 @@ class ProtocolCheck
*/
static bool isProtocol( const OUString& sURL, EProtocol eRequired )
{
- bool bRet = sal_False;
+ bool bRet = false;
switch(eRequired)
{
case E_PRIVATE:
@@ -116,7 +116,7 @@ class ProtocolCheck
bRet = sURL.startsWith(SPECIALPROTOCOL_NEWS);
break;
default:
- bRet = sal_False;
+ bRet = false;
break;
}
return bRet;
diff --git a/include/cppuhelper/interfacecontainer.h b/include/cppuhelper/interfacecontainer.h
index 07b296e..2a88f39 100644
--- a/include/cppuhelper/interfacecontainer.h
+++ b/include/cppuhelper/interfacecontainer.h
@@ -450,8 +450,8 @@ struct OBroadcastHelperVar
OBroadcastHelperVar( ::osl::Mutex & rMutex_ )
: rMutex( rMutex_ )
, aLC( rMutex_ )
- , bDisposed( sal_False )
- , bInDispose( sal_False )
+ , bDisposed( false )
+ , bInDispose( false )
{}
/**
diff --git a/sal/qa/osl/security/osl_Security_Const.h b/sal/qa/osl/security/osl_Security_Const.h
index 84619f0..83dd21f 100644
--- a/sal/qa/osl/security/osl_Security_Const.h
+++ b/sal/qa/osl/security/osl_Security_Const.h
@@ -51,7 +51,7 @@ const char pTestString[17] = "Sun Microsystems";
::rtl::OUString strUserName, strComputerName, strHomeDirectory;
::rtl::OUString strConfigDirectory, strUserID;
-bool isAdmin = sal_False;
+bool isAdmin = false;
#endif // INCLUDED_SAL_QA_OSL_SECURITY_OSL_SECURITY_CONST_H
More information about the Libreoffice-commits
mailing list