Kaydet (Commit) f541b998 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

loplugin:nullptr: Better heuristic to determine code shared between C and C++

Change-Id: I51e1c5fa4639e51fac90f92adf3d87d12960d589
üst 545d5157
......@@ -91,7 +91,7 @@ public:
inline void ensure_no_exception() const; // throws BridgeRuntimeError
inline bool assert_no_exception() const; // asserts and clears exception
OUString get_stack_trace( jobject jo_exc = NULL ) const;
OUString get_stack_trace( jobject jo_exc = nullptr ) const;
};
inline void JNI_context::ensure_no_exception() const
......@@ -144,7 +144,7 @@ class JLocalAutoRef
public:
explicit JLocalAutoRef( JNI_context const & jni )
: m_jni( jni ),
m_jo( NULL )
m_jo( nullptr )
{}
explicit JLocalAutoRef( JNI_context const & jni, jobject jo )
: m_jni( jni ),
......@@ -156,7 +156,7 @@ public:
jobject get() const
{ return m_jo; }
bool is() const
{ return (NULL != m_jo); }
{ return (nullptr != m_jo); }
inline jobject release();
inline void reset( jobject jo );
inline JLocalAutoRef & operator = ( JLocalAutoRef & auto_ref );
......@@ -164,7 +164,7 @@ public:
inline JLocalAutoRef::~JLocalAutoRef()
{
if (NULL != m_jo)
if (nullptr != m_jo)
m_jni->DeleteLocalRef( m_jo );
}
......@@ -172,13 +172,13 @@ inline JLocalAutoRef::JLocalAutoRef( JLocalAutoRef & auto_ref )
: m_jni( auto_ref.m_jni ),
m_jo( auto_ref.m_jo )
{
auto_ref.m_jo = NULL;
auto_ref.m_jo = nullptr;
}
inline jobject JLocalAutoRef::release()
{
jobject jo = m_jo;
m_jo = NULL;
m_jo = nullptr;
return jo;
}
......@@ -186,7 +186,7 @@ inline void JLocalAutoRef::reset( jobject jo )
{
if (jo != m_jo)
{
if (NULL != m_jo)
if (nullptr != m_jo)
m_jni->DeleteLocalRef( m_jo );
m_jo = jo;
}
......@@ -196,7 +196,7 @@ inline JLocalAutoRef & JLocalAutoRef::operator = ( JLocalAutoRef & auto_ref )
{
assert( m_jni.get_jni_env() == auto_ref.m_jni.get_jni_env() );
reset( auto_ref.m_jo );
auto_ref.m_jo = NULL;
auto_ref.m_jo = nullptr;
return *this;
}
......@@ -219,7 +219,7 @@ struct rtl_mem
inline rtl_mem * rtl_mem::allocate( ::std::size_t bytes )
{
void * p = rtl_allocateMemory( bytes );
if (NULL == p)
if (nullptr == p)
throw BridgeRuntimeError( "out of memory!" );
return static_cast<rtl_mem *>(p);
}
......@@ -242,10 +242,10 @@ public:
};
inline TypeDescr::TypeDescr( typelib_TypeDescriptionReference * td_ref )
: m_td( NULL )
: m_td( nullptr )
{
TYPELIB_DANGER_GET( &m_td, td_ref );
if (NULL == m_td)
if (nullptr == m_td)
{
throw BridgeRuntimeError(
"cannot get comprehensive type description for " +
......
......@@ -34,7 +34,7 @@ namespace jni_uno
inline void jstring_to_ustring(
JNI_context const & jni, rtl_uString ** out_ustr, jstring jstr )
{
if (NULL == jstr)
if (nullptr == jstr)
{
rtl_uString_new( out_ustr );
}
......@@ -51,7 +51,7 @@ inline void jstring_to_ustring(
ustr->length = len;
ustr->buffer[ len ] = '\0';
mem.release();
if (NULL != *out_ustr)
if (nullptr != *out_ustr)
rtl_uString_release( *out_ustr );
*out_ustr = ustr;
}
......@@ -60,7 +60,7 @@ inline void jstring_to_ustring(
inline OUString jstring_to_oustring(
JNI_context const & jni, jstring jstr )
{
rtl_uString * ustr = NULL;
rtl_uString * ustr = nullptr;
jstring_to_ustring( jni, &ustr, jstr );
return OUString( ustr, SAL_NO_ACQUIRE );
}
......@@ -80,14 +80,14 @@ inline jclass find_class(
JNI_context const & jni, char const * class_name, bool inException = false )
{
// find_class may be called before the JNI_info is set:
jclass c=NULL;
jclass c=nullptr;
jmethodID m;
JNI_info const * info = jni.get_info();
if (info == NULL) {
if (info == nullptr) {
jni.getClassForName(&c, &m);
if (c == NULL) {
if (c == nullptr) {
if (inException) {
return NULL;
return nullptr;
}
jni.ensure_no_exception();
}
......
......@@ -9,6 +9,7 @@
#include <cassert>
#include <cstdlib>
#include <limits>
#include <set>
#include "plugin.hxx"
......@@ -59,6 +60,8 @@ public:
bool TraverseConstructorInitializer(CXXCtorInitializer * init);
bool TraverseLinkageSpecDecl(LinkageSpecDecl * decl);
// bool shouldVisitTemplateInstantiations() const { return true; }
private:
......@@ -66,6 +69,8 @@ private:
bool isFromCIncludeFile(SourceLocation spellingLocation) const;
bool isSharedCAndCppCode(SourceLocation location) const;
void visitCXXCtorInitializer(CXXCtorInitializer const * init);
void handleZero(Expr const * expr);
......@@ -80,6 +85,7 @@ private:
char const * replacement);
std::set<Expr const *> gnuNulls_;
unsigned int externCContexts_ = 0;
};
bool Nullptr::VisitImplicitCastExpr(CastExpr const * expr) {
......@@ -202,6 +208,15 @@ bool Nullptr::TraverseConstructorInitializer(CXXCtorInitializer * init) {
return RecursiveASTVisitor::TraverseConstructorInitializer(init);
}
bool Nullptr::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 Nullptr::isInLokIncludeFile(SourceLocation spellingLocation) const {
return compiler.getSourceManager().getFilename(spellingLocation)
.startswith(SRCDIR "/include/LibreOfficeKit/");
......@@ -215,6 +230,16 @@ bool Nullptr::isFromCIncludeFile(SourceLocation spellingLocation) const {
.endswith(".h"));
}
bool Nullptr::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));
}
void Nullptr::visitCXXCtorInitializer(CXXCtorInitializer const * init) {
if (!init->isWritten()) {
return;
......@@ -273,12 +298,16 @@ void Nullptr::handleNull(
}
loc = compiler.getSourceManager()
.getImmediateExpansionRange(loc).first;
if (ignoreLocation(
compiler.getSourceManager().getSpellingLoc(loc)))
{
return;
}
if (isInUnoIncludeFile(
compiler.getSourceManager().getSpellingLoc(loc))
|| isInLokIncludeFile(
compiler.getSourceManager().getSpellingLoc(loc))
|| isFromCIncludeFile(
compiler.getSourceManager().getSpellingLoc(loc)))
|| isSharedCAndCppCode(loc))
{
//TODO: if !castKind, warn if NULL is passed into fn call
// ellipsis, cast to void*
......@@ -309,7 +338,7 @@ void Nullptr::handleNull(
auto const asMacro = !compiler.getLangOpts().CPlusPlus
|| isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(loc))
|| isInLokIncludeFile(compiler.getSourceManager().getSpellingLoc(loc))
|| isFromCIncludeFile(compiler.getSourceManager().getSpellingLoc(loc));
|| isSharedCAndCppCode(loc);
assert(!asMacro || nullPointerKind != Expr::NPCK_GNUNull);
rewriteOrWarn(e, castKind, nullPointerKind, asMacro ? "NULL" : "nullptr");
}
......
......@@ -97,7 +97,7 @@ DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
css::uno::Reference< css::uno::XInterface> resolveUnoURL(
OUString const & connectString,
css::uno::Reference< css::uno::XComponentContext> const & xLocalContext,
AbortChannel * abortChannel = NULL );
AbortChannel * abortChannel = nullptr );
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool office_is_running();
......
......@@ -74,7 +74,7 @@ inline bool readOption(
bool * flag, OptionInfo const * option_info, sal_uInt32 * pIndex )
{
if (isOption( option_info, pIndex )) {
OSL_ASSERT( flag != NULL );
OSL_ASSERT( flag != nullptr );
*flag = true;
return true;
}
......
......@@ -85,7 +85,7 @@ HWPDOFuncType HWPDOFuncTbl[] =
HWPDOFreeFormFunc,
};
static HMemIODev *hmem = NULL;
static HMemIODev *hmem = nullptr;
static int count = 0;
......@@ -299,7 +299,7 @@ static bool LoadCommonHeader(HWPDrawingObject * hdo, unsigned short * link_info)
hdo->property.contrast = 0;
hdo->property.greyscale = 0;
}
hdo->property.pPara = NULL;
hdo->property.pPara = nullptr;
if( ( size > common_size ) && (hdo->property.flag & HWPDO_FLAG_AS_TEXTBOX) )
{
......@@ -324,7 +324,7 @@ static HWPDrawingObject *LoadDrawingObject(void)
unsigned short link_info;
head = prev = NULL;
head = prev = nullptr;
do
{
hdo = new HWPDrawingObject;
......@@ -342,7 +342,7 @@ static HWPDrawingObject *LoadDrawingObject(void)
}
else
{
switch (int res = HWPDOFunc(hdo, OBJFUNC_LOAD, NULL, 0))
switch (int res = HWPDOFunc(hdo, OBJFUNC_LOAD, nullptr, 0))
{
case OBJRET_FILE_ERROR:
goto error;
......@@ -358,12 +358,12 @@ static HWPDrawingObject *LoadDrawingObject(void)
if (link_info & HDOFILE_HAS_CHILD)
{
hdo->child = LoadDrawingObject();
if (hdo->child == NULL)
if (hdo->child == nullptr)
{
goto error;
}
}
if (prev == NULL)
if (prev == nullptr)
head = hdo;
else
prev->next = hdo;
......@@ -376,23 +376,23 @@ static HWPDrawingObject *LoadDrawingObject(void)
// drawing object can be list.
// hdo = current item, head = list;
if (hdo != NULL)
if (hdo != nullptr)
{
if (hdo->type < 0 || hdo->type >= HWPDO_NITEMS)
{
hdo->type = HWPDO_RECT;
}
HWPDOFunc(hdo, OBJFUNC_FREE, NULL, 0);
HWPDOFunc(hdo, OBJFUNC_FREE, nullptr, 0);
delete hdo;
}
if( prev )
{
prev->next = NULL;
prev->next = nullptr;
return head;
}
else
return NULL;
return nullptr;
}
......@@ -423,7 +423,7 @@ static bool LoadDrawingObjectBlock(Picture * pic)
return false;
pic->picinfo.picdraw.hdo = LoadDrawingObject();
if (pic->picinfo.picdraw.hdo == NULL)
if (pic->picinfo.picdraw.hdo == nullptr)
return false;
return true;
}
......@@ -557,7 +557,7 @@ int cmd, void *argp, int argv)
{
case OBJFUNC_LOAD:
{
hdo->u.freeform.pt = NULL;
hdo->u.freeform.pt = nullptr;
if (ReadSizeField(4) < 4)
return OBJRET_FILE_ERROR;
if (!hmem->read4b(hdo->u.freeform.npt))
......@@ -575,7 +575,7 @@ int cmd, void *argp, int argv)
{
hdo->u.freeform.pt =
::comphelper::newArray_null<ZZPoint>(hdo->u.freeform.npt);
if (hdo->u.freeform.pt == NULL)
if (hdo->u.freeform.pt == nullptr)
{
hdo->u.freeform.npt = 0;
return OBJRET_FILE_ERROR;
......@@ -625,7 +625,7 @@ static void FreeParaList(HWPPara * para)
static HWPPara *LoadParaList()
{
if (!hmem)
return NULL;
return nullptr;
HWPFile *hwpf = GetCurrentDoc();
HIODev *hio = hwpf->SetIODevice(hmem);
......@@ -635,7 +635,7 @@ static HWPPara *LoadParaList()
hwpf->ReadParaList(plist);
hwpf->SetIODevice(hio);
return plist.size()? plist.front() : NULL;
return plist.size()? plist.front() : nullptr;
}
......@@ -656,7 +656,7 @@ int cmd, void *argp, int argv)
if (hdo->u.textbox.h)
{
FreeParaList(hdo->u.textbox.h);
hdo->u.textbox.h = NULL;
hdo->u.textbox.h = nullptr;
}
break;
default:
......@@ -690,7 +690,7 @@ HWPDrawingObject::~HWPDrawingObject()
if (next)
delete next;
HWPDOFunc(this, OBJFUNC_FREE, NULL, 0);
HWPDOFunc(this, OBJFUNC_FREE, nullptr, 0);
}
#endif
......
......@@ -281,7 +281,7 @@ struct FBoxStyle
, boxnum(0)
, boxtype(0)
, cap_len(0)
, cell(NULL)
, cell(nullptr)
{
memset(margin, 0, sizeof(margin));
}
......@@ -521,7 +521,7 @@ struct TCell
struct Table
{
Table() : box(NULL) {};
Table() : box(nullptr) {};
~Table() {
std::list<TCell*>::iterator it = cells.begin();
for( ; it != cells.end(); ++it)
......
......@@ -87,7 +87,7 @@ struct PaperBackInfo
, flag(0)
, range(0)
, size(0)
, data(NULL)
, data(nullptr)
, isset(false)
{
memset(reserved1, 0, sizeof(reserved1));
......
......@@ -73,7 +73,7 @@ struct ColumnInfo{
explicit ColumnInfo(int num){
start_page = num;
bIsSet = false;
coldef = NULL;
coldef = nullptr;
}
};
......
......@@ -64,9 +64,9 @@ class Node{
public:
explicit Node(int _id) : id(_id)
{
value = NULL;
child = NULL;
next = NULL;
value = nullptr;
child = nullptr;
next = nullptr;
#ifdef NODE_DEBUG
count++;
printf("Node count : [%d]\n",count);
......@@ -77,8 +77,8 @@ public:
if( value ) free( value );
// if( child ) delete child;
// if( next ) delete next;
next = NULL;
child = NULL;
next = nullptr;
child = nullptr;
#ifdef NODE_DEBUG
count--;
printf("Node count : [%d]\n",count);
......
......@@ -146,18 +146,18 @@ inline ds_status initDSProfile(std::unique_ptr<ds_profile>& rProfile, OString co
rProfile = std::unique_ptr<ds_profile>(new ds_profile(rVersion));
clGetPlatformIDs(0, NULL, &numPlatforms);
clGetPlatformIDs(0, nullptr, &numPlatforms);
if (numPlatforms != 0)
{
platforms.resize(numPlatforms);
clGetPlatformIDs(numPlatforms, platforms.data(), NULL);
clGetPlatformIDs(numPlatforms, platforms.data(), nullptr);
}
numDevices = 0;
for (i = 0; i < (unsigned int)numPlatforms; i++)
{
cl_uint num = 0;
cl_int err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &num);
cl_int err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, nullptr, &num);
if (err != CL_SUCCESS)
{
/* we want to catch at least the case when the call returns
......
......@@ -78,19 +78,19 @@ struct RSCINST
RscTop * pClass;
CLASS_DATA pData;
RSCINST(){ pClass = NULL; pData = NULL; }
RSCINST(){ pClass = nullptr; pData = nullptr; }
RSCINST( RscTop * pCl, CLASS_DATA pClassData )
{
pClass = pCl;
pData = pClassData;
}
bool IsInst() const { return( pData != NULL ); }
bool IsInst() const { return( pData != nullptr ); }
};
/********************** S U B I N F O S T R U C T ************************/
struct SUBINFO_STRUCT
{
SUBINFO_STRUCT(){ nPos = 0; pClass = NULL; };
SUBINFO_STRUCT(){ nPos = 0; pClass = nullptr; };
RscId aId; // Identifier der Resource
sal_uInt32 nPos; // Position der Resource
RscTop * pClass; // Klasse des Eintrages
......
......@@ -127,7 +127,7 @@ public:
sal_uInt32 nErrors;// Anzahl der Fehler
RscError( RscVerbosity _verbosity )
{
fListing = NULL;
fListing = nullptr;
nErrors = 0;
m_verbosity = _verbosity;
}
......@@ -138,11 +138,11 @@ public:
static void StdErr( const char * );
void LstOut( const char * );
void Error( const ERRTYPE& rError, RscTop* pClass, const RscId &aId,
const char * pMessage = NULL );
const char * pMessage = nullptr );
// Dieser Fehler sollte nur im Compilermodus auftreten,
// das Programm wird mit exit() verlassen
void FatalError( const ERRTYPE& rError, const RscId &aId,
const char * pMessage = NULL );
const char * pMessage = nullptr );
};
#endif // INCLUDED_RSC_INC_RSCERROR_H
......
......@@ -53,7 +53,7 @@ public:
FormIdent( void )
{
nStamp = 0;
pAttr = NULL;
pAttr = nullptr;
}
FormIdent( sal_uInt8 nFormat, sal_uInt8 nSt, SfxUInt32Item& rAttr )
......
......@@ -90,7 +90,7 @@ inline void lru_cache< t_key, t_val, t_hashKey, t_equalKey >::setSize(
{
m_key2element.clear();
delete [] m_block;
m_block = NULL;
m_block = nullptr;
m_size = size;
if (0 < m_size)
......
......@@ -36,13 +36,13 @@ class SAL_WARN_UNUSED ImplPolygon : public ImplPolygonData
{
public:
ImplPolygon( sal_uInt16 nInitSize, bool bFlags = false );
ImplPolygon( sal_uInt16 nPoints, const Point* pPtAry, const sal_uInt8* pInitFlags = NULL );
ImplPolygon( sal_uInt16 nPoints, const Point* pPtAry, const sal_uInt8* pInitFlags = nullptr );
ImplPolygon( const ImplPolygon& rImplPoly );
~ImplPolygon();
void ImplSetSize( sal_uInt16 nSize, bool bResize = true );
void ImplCreateFlagArray();
void ImplSplit( sal_uInt16 nPos, sal_uInt16 nSpace, ImplPolygon* pInitPoly = NULL );
void ImplSplit( sal_uInt16 nPos, sal_uInt16 nSpace, ImplPolygon* pInitPoly = nullptr );
};
#define MAX_POLYGONS ((sal_uInt16)0x3FF0)
......@@ -61,7 +61,7 @@ public:
sal_uInt16 mnResize;
ImplPolyPolygon( sal_uInt16 nInitSize, sal_uInt16 nResize )
{ mpPolyAry = NULL; mnCount = 0; mnRefCount = 1;
{ mpPolyAry = nullptr; mnCount = 0; mnRefCount = 1;
mnSize = nInitSize; mnResize = nResize; }
ImplPolyPolygon( sal_uInt16 nInitSize );
ImplPolyPolygon( const ImplPolyPolygon& rImplPolyPoly );
......
......@@ -122,7 +122,7 @@ struct ImplToolBoxPrivateData
ImplToolBoxPrivateData();
~ImplToolBoxPrivateData();
void ImplClearLayoutData() { delete m_pLayoutData; m_pLayoutData = NULL; }
void ImplClearLayoutData() { delete m_pLayoutData; m_pLayoutData = nullptr; }
// called when dropdown items are clicked
Link<ToolBox *, void> maDropdownClickHdl;
......
......@@ -75,7 +75,7 @@ public:
const psp::FastPrintFontInfo& );
// override all pure virtual methods
virtual SalGraphicsImpl*GetImpl() const override { return NULL; };
virtual SalGraphicsImpl*GetImpl() const override { return nullptr; };
virtual void GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ) override;
virtual sal_uInt16 GetBitCount() const override;
virtual long GetGraphicsWidth() const override;
......
......@@ -158,12 +158,12 @@ class VCLPLUG_GEN_PUBLIC X11SalFrame : public SalFrame, public NativeWindowHandl
void updateWMClass();
public:
X11SalFrame( SalFrame* pParent, SalFrameStyleFlags nSalFrameStyle, SystemParentData* pSystemParent = NULL );
X11SalFrame( SalFrame* pParent, SalFrameStyleFlags nSalFrameStyle, SystemParentData* pSystemParent = nullptr );
virtual ~X11SalFrame();
long Dispatch( XEvent *pEvent );
void Init( SalFrameStyleFlags nSalFrameStyle, SalX11Screen nScreen = SalX11Screen( -1 ),
SystemParentData* pParentData = NULL, bool bUseGeometry = false );
SystemParentData* pParentData = nullptr, bool bUseGeometry = false );
SalDisplay* GetDisplay() const
{
......@@ -178,7 +178,7 @@ public:
::Window GetShellWindow() const { return mhShellWindow; }
::Window GetForeignParent() const { return mhForeignParent; }
::Window GetStackingWindow() const { return mhStackingWindow; }
void Close() const { CallCallback( SalEvent::Close, NULL ); }
void Close() const { CallCallback( SalEvent::Close, nullptr ); }
SalFrameStyleFlags GetStyle() const { return nStyle_; }
Cursor GetCursor() const { return hCursor_; }
......
......@@ -76,7 +76,7 @@ public:
virtual ~X11SalGraphics();
void Init( SalFrame *pFrame, Drawable aDrawable, SalX11Screen nXScreen );
void Init( X11SalVirtualDevice *pVirtualDevice, SalColormap* pColormap = NULL, bool bDeleteColormap = false );
void Init( X11SalVirtualDevice *pVirtualDevice, SalColormap* pColormap = nullptr, bool bDeleteColormap = false );
void Init( X11OpenGLSalVirtualDevice *pVirtualDevice );
void DeInit();
......@@ -312,7 +312,7 @@ public:
protected:
using SalGraphics::SetClipRegion;
void SetClipRegion( GC pGC, Region pXReg = NULL ) const;
void SetClipRegion( GC pGC, Region pXReg = nullptr ) const;
bool GetDitherPixmap ( SalColor nSalColor );
using SalGraphics::DrawBitmap;
......
......@@ -60,7 +60,7 @@ public:
virtual SalVirtualDevice* CreateVirtualDevice( SalGraphics* pGraphics,
long &nDX, long &nDY,
DeviceFormat eFormat, const SystemGraphicsData *pData = NULL ) override;
DeviceFormat eFormat, const SystemGraphicsData *pData = nullptr ) override;
virtual void PostPrintersChanged() override;
virtual GenPspGraphics *CreatePrintGraphics() override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment