From 368ed462dd6e5e63977ca2b2e56a7e83b3a3bdda Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 13 Aug 2014 17:12:28 -0700 Subject: Add FX_OVERRIDE and use it for virtual functions of FX_FINAL classes. Should there be cases where this fails to compile, it indicates a mistake, either an incorrectly declared overrriden virtual method, or a method that should be declared non-virtual. The only issues were with CPDF_CustomAccess::GetBlock(), CPDF_CustomAccess::GetByte(), and CPDF_CustomAccess::GetFullPath(). These don't appear to be used anywhere, and are removed. Two members are removed that are no longer needed once those methods are removed. R=jam@chromium.org, jun_fang@foxitsoftware.com Review URL: https://codereview.chromium.org/454983003 --- core/include/fpdfapi/fpdf_parser.h | 32 +++++++++---------- core/include/fxcrt/fx_system.h | 4 +++ core/src/fpdfapi/fpdf_font/ttgsubtable.h | 4 +-- core/src/fxcrt/extension.h | 54 ++++++++++++++++---------------- core/src/fxcrt/fx_arabic.h | 12 +++---- core/src/fxge/apple/apple_int.h | 12 +++---- fpdfsdk/include/fsdk_define.h | 12 +++---- fpdfsdk/src/fpdf_sysfontinfo.cpp | 16 +++++----- fpdfsdk/src/fpdfsave.cpp | 4 +-- fpdfsdk/src/fpdfview.cpp | 30 ++---------------- 10 files changed, 77 insertions(+), 103 deletions(-) diff --git a/core/include/fpdfapi/fpdf_parser.h b/core/include/fpdfapi/fpdf_parser.h index feac6c67dc..7cab2117a2 100644 --- a/core/include/fpdfapi/fpdf_parser.h +++ b/core/include/fpdfapi/fpdf_parser.h @@ -413,9 +413,9 @@ public: void CloseParser(FX_BOOL bReParse = FALSE); - virtual FX_DWORD GetPermissions(FX_BOOL bCheckRevision = FALSE); + virtual FX_DWORD GetPermissions(FX_BOOL bCheckRevision = FALSE) FX_OVERRIDE; - virtual FX_BOOL IsOwner(); + virtual FX_BOOL IsOwner() FX_OVERRIDE; void SetPassword(const FX_CHAR* password) { @@ -463,16 +463,16 @@ public: return &m_Trailers; } - virtual FX_DWORD GetRootObjNum(); - virtual FX_DWORD GetInfoObjNum(); - virtual CPDF_Array* GetIDArray(); - virtual CPDF_Dictionary* GetEncryptDict() + virtual FX_DWORD GetRootObjNum() FX_OVERRIDE; + virtual FX_DWORD GetInfoObjNum() FX_OVERRIDE; + virtual CPDF_Array* GetIDArray() FX_OVERRIDE; + virtual CPDF_Dictionary* GetEncryptDict() FX_OVERRIDE { return m_pEncryptDict; } - virtual CPDF_Object* ParseIndirectObject(CPDF_IndirectObjects* pObjList, FX_DWORD objnum, PARSE_CONTEXT* pContext = NULL); - virtual FX_DWORD GetLastObjNum(); - virtual FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm); + virtual CPDF_Object* ParseIndirectObject(CPDF_IndirectObjects* pObjList, FX_DWORD objnum, PARSE_CONTEXT* pContext = NULL) FX_OVERRIDE; + virtual FX_DWORD GetLastObjNum() FX_OVERRIDE; + virtual FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) FX_OVERRIDE; FX_FILESIZE GetObjectOffset(FX_DWORD objnum); @@ -952,24 +952,24 @@ public: CPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead); ~CPDF_DataAvail(); - virtual FX_BOOL IsDocAvail(IFX_DownloadHints* pHints); + virtual FX_BOOL IsDocAvail(IFX_DownloadHints* pHints) FX_OVERRIDE; - virtual void SetDocument(CPDF_Document* pDoc); + virtual void SetDocument(CPDF_Document* pDoc) FX_OVERRIDE; - virtual FX_BOOL IsPageAvail(int iPage, IFX_DownloadHints* pHints); + virtual FX_BOOL IsPageAvail(int iPage, IFX_DownloadHints* pHints) FX_OVERRIDE; - virtual FX_INT32 IsFormAvail(IFX_DownloadHints *pHints); + virtual FX_INT32 IsFormAvail(IFX_DownloadHints *pHints) FX_OVERRIDE; - virtual FX_INT32 IsLinearizedPDF(); + virtual FX_INT32 IsLinearizedPDF() FX_OVERRIDE; - virtual FX_BOOL IsLinearized() + virtual FX_BOOL IsLinearized() FX_OVERRIDE { return m_bLinearized; } - virtual void GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSize); + virtual void GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSize) FX_OVERRIDE; IFX_FileRead* GetFileRead() const { return m_pFileRead; diff --git a/core/include/fxcrt/fx_system.h b/core/include/fxcrt/fx_system.h index 6d659e2c10..36050f35dc 100644 --- a/core/include/fxcrt/fx_system.h +++ b/core/include/fxcrt/fx_system.h @@ -280,13 +280,17 @@ int FXSYS_round(FX_FLOAT f); typedef base::CheckedNumeric FX_SAFE_DWORD; typedef base::CheckedNumeric FX_SAFE_INT32; typedef base::CheckedNumeric FX_SAFE_SIZE_T; + #if defined(__clang__) || _MSC_VER >= 1700 #define FX_FINAL final +#define FX_OVERRIDE override #elif defined(__GNUC__) && __cplusplus >= 201103 && \ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= 40700 #define FX_FINAL final +#define FX_OVERRIDE override #else #define FX_FINAL +#define FX_OVERRIDE #endif #endif #endif diff --git a/core/src/fpdfapi/fpdf_font/ttgsubtable.h b/core/src/fpdfapi/fpdf_font/ttgsubtable.h index cc7f8c8752..515b9f9242 100644 --- a/core/src/fpdfapi/fpdf_font/ttgsubtable.h +++ b/core/src/fpdfapi/fpdf_font/ttgsubtable.h @@ -409,11 +409,11 @@ private: class CFX_GSUBTable FX_FINAL : public IFX_GSUBTable, public CFX_Object { public: - virtual void Release() + virtual void Release() FX_OVERRIDE { delete this; } - virtual FX_BOOL GetVerticalGlyph(FX_DWORD glyphnum, FX_DWORD* vglyphnum); + virtual FX_BOOL GetVerticalGlyph(FX_DWORD glyphnum, FX_DWORD* vglyphnum) FX_OVERRIDE; CFX_CTTGSUBTable m_GsubImp; }; #endif diff --git a/core/src/fxcrt/extension.h b/core/src/fxcrt/extension.h index bb2a79b9f9..c23a2e3369 100644 --- a/core/src/fxcrt/extension.h +++ b/core/src/fxcrt/extension.h @@ -36,27 +36,27 @@ public: m_pFile->Release(); } } - virtual IFX_FileStream* Retain() + virtual IFX_FileStream* Retain() FX_OVERRIDE { m_dwCount ++; return this; } - virtual void Release() + virtual void Release() FX_OVERRIDE { FX_DWORD nCount = -- m_dwCount; if (!nCount) { delete this; } } - virtual FX_FILESIZE GetSize() + virtual FX_FILESIZE GetSize() FX_OVERRIDE { return m_bUseRange ? m_nSize : m_pFile->GetSize(); } - virtual FX_BOOL IsEOF() + virtual FX_BOOL IsEOF() FX_OVERRIDE { return GetPosition() >= GetSize(); } - virtual FX_FILESIZE GetPosition() + virtual FX_FILESIZE GetPosition() FX_OVERRIDE { FX_FILESIZE pos = m_pFile->GetPosition(); if (m_bUseRange) { @@ -64,7 +64,7 @@ public: } return pos; } - virtual FX_BOOL SetRange(FX_FILESIZE offset, FX_FILESIZE size) + virtual FX_BOOL SetRange(FX_FILESIZE offset, FX_FILESIZE size) FX_OVERRIDE { if (offset < 0 || size < 0) { return FALSE; @@ -82,11 +82,11 @@ public: m_pFile->SetPosition(m_nOffset); return TRUE; } - virtual void ClearRange() + virtual void ClearRange() FX_OVERRIDE { m_bUseRange = FALSE; } - virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) + virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) FX_OVERRIDE { if (m_bUseRange && offset < 0) { return FALSE; @@ -101,7 +101,7 @@ public: } return (FX_BOOL)m_pFile->ReadPos(buffer, size, pos.ValueOrDie()); } - virtual size_t ReadBlock(void* buffer, size_t size) + virtual size_t ReadBlock(void* buffer, size_t size) FX_OVERRIDE { if (m_bUseRange) { FX_FILESIZE availSize = m_nOffset + m_nSize - m_pFile->GetPosition(); @@ -111,14 +111,14 @@ public: } return m_pFile->Read(buffer, size); } - virtual FX_BOOL WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) + virtual FX_BOOL WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) FX_OVERRIDE { if (m_bUseRange) { offset += m_nOffset; } return (FX_BOOL)m_pFile->WritePos(buffer, size, offset); } - virtual FX_BOOL Flush() + virtual FX_BOOL Flush() FX_OVERRIDE { return m_pFile->Flush(); } @@ -164,12 +164,12 @@ public: } m_Blocks.RemoveAll(); } - virtual IFX_FileStream* Retain() + virtual IFX_FileStream* Retain() FX_OVERRIDE { m_dwCount ++; return this; } - virtual void Release() + virtual void Release() FX_OVERRIDE { FX_DWORD nCount = -- m_dwCount; if (nCount) { @@ -177,15 +177,15 @@ public: } delete this; } - virtual FX_FILESIZE GetSize() + virtual FX_FILESIZE GetSize() FX_OVERRIDE { return m_bUseRange ? (FX_FILESIZE) m_nSize : (FX_FILESIZE)m_nCurSize; } - virtual FX_BOOL IsEOF() + virtual FX_BOOL IsEOF() FX_OVERRIDE { return m_nCurPos >= (size_t)GetSize(); } - virtual FX_FILESIZE GetPosition() + virtual FX_FILESIZE GetPosition() FX_OVERRIDE { FX_FILESIZE pos = (FX_FILESIZE)m_nCurPos; if (m_bUseRange) { @@ -193,7 +193,7 @@ public: } return pos; } - virtual FX_BOOL SetRange(FX_FILESIZE offset, FX_FILESIZE size) + virtual FX_BOOL SetRange(FX_FILESIZE offset, FX_FILESIZE size) FX_OVERRIDE { if (offset < 0 || size < 0) { return FALSE; @@ -209,11 +209,11 @@ public: m_nCurPos = m_nOffset; return TRUE; } - virtual void ClearRange() + virtual void ClearRange() FX_OVERRIDE { m_bUseRange = FALSE; } - virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) + virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) FX_OVERRIDE { if (!buffer || !size) { return FALSE; @@ -256,7 +256,7 @@ public: } return TRUE; } - virtual size_t ReadBlock(void* buffer, size_t size) + virtual size_t ReadBlock(void* buffer, size_t size) FX_OVERRIDE { if (m_nCurPos >= m_nCurSize) { return 0; @@ -273,7 +273,7 @@ public: } return nRead; } - virtual FX_BOOL WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) + virtual FX_BOOL WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) FX_OVERRIDE { if (!buffer || !size) { return FALSE; @@ -333,15 +333,15 @@ public: } return TRUE; } - virtual FX_BOOL Flush() + virtual FX_BOOL Flush() FX_OVERRIDE { return TRUE; } - virtual FX_BOOL IsConsecutive() const + virtual FX_BOOL IsConsecutive() const FX_OVERRIDE { return m_dwFlags & FX_MEMSTREAM_Consecutive; } - virtual void EstimateSize(size_t nInitSize, size_t nGrowSize) + virtual void EstimateSize(size_t nInitSize, size_t nGrowSize) FX_OVERRIDE { if (m_dwFlags & FX_MEMSTREAM_Consecutive) { if (m_Blocks.GetSize() < 1) { @@ -355,11 +355,11 @@ public: m_nGrowSize = FX_MAX(nGrowSize, 4096); } } - virtual FX_LPBYTE GetBuffer() const + virtual FX_LPBYTE GetBuffer() const FX_OVERRIDE { return m_Blocks.GetSize() ? (FX_LPBYTE)m_Blocks[0] : NULL; } - virtual void AttachBuffer(FX_LPBYTE pBuffer, size_t nSize, FX_BOOL bTakeOver = FALSE) + virtual void AttachBuffer(FX_LPBYTE pBuffer, size_t nSize, FX_BOOL bTakeOver = FALSE) FX_OVERRIDE { if (!(m_dwFlags & FX_MEMSTREAM_Consecutive)) { return; @@ -371,7 +371,7 @@ public: m_dwFlags = FX_MEMSTREAM_Consecutive | (bTakeOver ? FX_MEMSTREAM_TakeOver : 0); ClearRange(); } - virtual void DetachBuffer() + virtual void DetachBuffer() FX_OVERRIDE { if (!(m_dwFlags & FX_MEMSTREAM_Consecutive)) { return; diff --git a/core/src/fxcrt/fx_arabic.h b/core/src/fxcrt/fx_arabic.h index 1dc275b8c3..c404449af0 100644 --- a/core/src/fxcrt/fx_arabic.h +++ b/core/src/fxcrt/fx_arabic.h @@ -10,18 +10,18 @@ class CFX_BidiChar FX_FINAL : public IFX_BidiChar, public CFX_Object { public: CFX_BidiChar(); - virtual void Release() + virtual void Release() FX_OVERRIDE { delete this; } - virtual void SetPolicy(FX_BOOL bSeparateNeutral = TRUE) + virtual void SetPolicy(FX_BOOL bSeparateNeutral = TRUE) FX_OVERRIDE { m_bSeparateNeutral = bSeparateNeutral; } - virtual FX_BOOL AppendChar(FX_WCHAR wch); - virtual FX_BOOL EndChar(); - virtual FX_INT32 GetBidiInfo(FX_INT32 &iStart, FX_INT32 &iCount); - virtual void Reset(); + virtual FX_BOOL AppendChar(FX_WCHAR wch) FX_OVERRIDE; + virtual FX_BOOL EndChar() FX_OVERRIDE; + virtual FX_INT32 GetBidiInfo(FX_INT32 &iStart, FX_INT32 &iCount) FX_OVERRIDE; + virtual void Reset() FX_OVERRIDE; protected: FX_BOOL m_bSeparateNeutral; FX_INT32 m_iCurStart; diff --git a/core/src/fxge/apple/apple_int.h b/core/src/fxge/apple/apple_int.h index a8fbe2fbaa..e3794159b8 100644 --- a/core/src/fxge/apple/apple_int.h +++ b/core/src/fxge/apple/apple_int.h @@ -188,25 +188,25 @@ protected: class CFX_FontProvider FX_FINAL : public IFX_FileRead { public: - virtual void Release() + virtual void Release() FX_OVERRIDE { delete this; } - virtual FX_FILESIZE GetSize() + virtual FX_FILESIZE GetSize() FX_OVERRIDE { return (FX_FILESIZE)_totalSize; } - virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size); + virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) FX_OVERRIDE; - virtual FX_BOOL IsEOF() + virtual FX_BOOL IsEOF() FX_OVERRIDE { return _offSet == _totalSize; } - virtual FX_FILESIZE GetPosition() + virtual FX_FILESIZE GetPosition() FX_OVERRIDE { return (FX_FILESIZE)_offSet; } - virtual size_t ReadBlock(void* buffer, size_t size); + virtual size_t ReadBlock(void* buffer, size_t size) FX_OVERRIDE; public: CFX_FontProvider(CGFontRef cgFont); ~CFX_FontProvider(); diff --git a/fpdfsdk/include/fsdk_define.h b/fpdfsdk/include/fsdk_define.h index 433ff4c184..d249f0887f 100644 --- a/fpdfsdk/include/fsdk_define.h +++ b/fpdfsdk/include/fsdk_define.h @@ -107,18 +107,14 @@ public: CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess); ~CPDF_CustomAccess() {} - virtual CFX_ByteString GetFullPath() { return ""; } - virtual FX_FILESIZE GetSize() { return m_FileAccess.m_FileLen; } + virtual FX_FILESIZE GetSize() FX_OVERRIDE { return m_FileAccess.m_FileLen; } - virtual FX_BOOL GetByte(FX_DWORD pos, FX_BYTE& ch); - virtual FX_BOOL GetBlock(FX_DWORD pos, FX_LPBYTE pBuf, FX_DWORD size); - virtual void Release() { delete this; } + virtual void Release() FX_OVERRIDE { delete this; } - virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size); + virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) FX_OVERRIDE; +private: FPDF_FILEACCESS m_FileAccess; - FX_BYTE m_Buffer[512]; - FX_DWORD m_BufferOffset; }; void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable); diff --git a/fpdfsdk/src/fpdf_sysfontinfo.cpp b/fpdfsdk/src/fpdf_sysfontinfo.cpp index cc75e635b3..0e0114b372 100644 --- a/fpdfsdk/src/fpdf_sysfontinfo.cpp +++ b/fpdfsdk/src/fpdf_sysfontinfo.cpp @@ -12,14 +12,14 @@ class CSysFontInfo_Ext FX_FINAL : public IFX_SystemFontInfo public: FPDF_SYSFONTINFO* m_pInfo; - virtual void Release() + virtual void Release() FX_OVERRIDE { if (m_pInfo->Release) m_pInfo->Release(m_pInfo); delete this; } - virtual FX_BOOL EnumFontList(CFX_FontMapper* pMapper) + virtual FX_BOOL EnumFontList(CFX_FontMapper* pMapper) FX_OVERRIDE { if (m_pInfo->EnumFonts) { m_pInfo->EnumFonts(m_pInfo, pMapper); @@ -28,28 +28,28 @@ public: return FALSE; } - virtual void* MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, FX_LPCSTR family, FX_BOOL& bExact) + virtual void* MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, FX_LPCSTR family, FX_BOOL& bExact) FX_OVERRIDE { if (m_pInfo->MapFont) return m_pInfo->MapFont(m_pInfo, weight, bItalic, charset, pitch_family, family, &bExact); return NULL; } - virtual void* GetFont(FX_LPCSTR family) + virtual void* GetFont(FX_LPCSTR family) FX_OVERRIDE { if (m_pInfo->GetFont) return m_pInfo->GetFont(m_pInfo, family); return NULL; } - virtual FX_DWORD GetFontData(void* hFont, FX_DWORD table, FX_LPBYTE buffer, FX_DWORD size) + virtual FX_DWORD GetFontData(void* hFont, FX_DWORD table, FX_LPBYTE buffer, FX_DWORD size) FX_OVERRIDE { if (m_pInfo->GetFontData) return m_pInfo->GetFontData(m_pInfo, hFont, table, buffer, size); return 0; } - virtual FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) + virtual FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) FX_OVERRIDE { if (m_pInfo->GetFaceName == NULL) return FALSE; FX_DWORD size = m_pInfo->GetFaceName(m_pInfo, hFont, NULL, 0); @@ -61,7 +61,7 @@ public: return TRUE; } - virtual FX_BOOL GetFontCharset(void* hFont, int& charset) + virtual FX_BOOL GetFontCharset(void* hFont, int& charset) FX_OVERRIDE { if (m_pInfo->GetFontCharset) { charset = m_pInfo->GetFontCharset(m_pInfo, hFont); @@ -70,7 +70,7 @@ public: return FALSE; } - virtual void DeleteFont(void* hFont) + virtual void DeleteFont(void* hFont) FX_OVERRIDE { if (m_pInfo->DeleteFont) m_pInfo->DeleteFont(m_pInfo, hFont); diff --git a/fpdfsdk/src/fpdfsave.cpp b/fpdfsdk/src/fpdfsave.cpp index 8025946ba8..45dfbf7214 100644 --- a/fpdfsdk/src/fpdfsave.cpp +++ b/fpdfsdk/src/fpdfsave.cpp @@ -19,8 +19,8 @@ class CFX_IFileWrite FX_FINAL : public IFX_StreamWrite public: CFX_IFileWrite(); FX_BOOL Init( FPDF_FILEWRITE * pFileWriteStruct ); - virtual FX_BOOL WriteBlock(const void* pData, size_t size); - virtual void Release(){}; + virtual FX_BOOL WriteBlock(const void* pData, size_t size) FX_OVERRIDE; + virtual void Release() FX_OVERRIDE {} protected: FPDF_FILEWRITE* m_pFileWriteStruct; diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp index 2e1bca3a66..70494e02a2 100644 --- a/fpdfsdk/src/fpdfview.cpp +++ b/fpdfsdk/src/fpdfview.cpp @@ -13,34 +13,8 @@ CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { - m_FileAccess = *pFileAccess; - m_BufferOffset = (FX_DWORD)-1; -} - -FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, FX_BYTE& ch) -{ - if (pos >= m_FileAccess.m_FileLen) return FALSE; - if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || pos >= m_BufferOffset + 512) { - // Need to read from file access - m_BufferOffset = pos; - int size = 512; - if (pos + 512 > m_FileAccess.m_FileLen) - size = m_FileAccess.m_FileLen - pos; - if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffset, m_Buffer, size)) - return FALSE; - } - ch = m_Buffer[pos - m_BufferOffset]; - return TRUE; -} - -FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos, FX_LPBYTE pBuf, FX_DWORD size) -{ - FX_SAFE_DWORD newPos = size; - newPos += pos; - if (!newPos.IsValid() || newPos.ValueOrDie() > m_FileAccess.m_FileLen) { - return FALSE; - } - return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size); + if (pFileAccess) + m_FileAccess = *pFileAccess; } FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) -- cgit v1.2.3