Help convince clang that 'this' can be NULL in some cases. Closes #65

This commit is contained in:
Michael Hansen
2015-10-02 23:00:07 -07:00
parent badd17bd21
commit 888882c743
2 changed files with 28 additions and 4 deletions

View File

@@ -23,15 +23,33 @@ public:
ASTNode(int type = NODE_INVALID) : m_refs(0), m_type(type) { }
virtual ~ASTNode() { }
int type() const { return (this) ? m_type : NODE_INVALID; }
int type() const { return internalGetType(this); }
private:
int m_refs;
int m_type;
// Hack to make clang happy :(
static int internalGetType(const ASTNode *node)
{
return node ? node->m_type : NODE_INVALID;
}
static void internalAddRef(ASTNode *node)
{
if (node)
++node->m_refs;
}
static void internalDelRef(ASTNode *node)
{
if (node && --node->m_refs == 0)
delete node;
}
public:
void addRef() { if (this) ++m_refs; }
void delRef() { if (this && --m_refs == 0) delete this; }
void addRef() { internalAddRef(this); }
void delRef() { internalDelRef(this); }
};
/* A NULL node for comparison */

View File

@@ -106,7 +106,7 @@ public:
PycObject(int type = TYPE_UNKNOWN) : m_refs(0), m_type(type) { }
virtual ~PycObject() { }
int type() const { return (this) ? m_type : TYPE_NULL; }
int type() const { return internalGetType(this); }
virtual bool isEqual(PycRef<PycObject> obj) const
{ return (this == (PycObject*)obj); }
@@ -117,6 +117,12 @@ private:
int m_refs;
int m_type;
// Hack to make clang happy :(
static int internalGetType(const PycObject *obj)
{
return obj ? obj->m_type : TYPE_NULL;
}
public:
void addRef() { ++m_refs; }
void delRef() { if (--m_refs == 0) delete this; }