Bug 704127 - Implement MOZ_FINAL as a modifier for classes and virtual member functions. r=cjones

--HG--
extra : rebase_source : d95a3b3e726f810f299314358ba8c5e23557698e
This commit is contained in:
Jeff Walden 2011-11-20 22:21:16 -08:00
parent 4f3f8250ea
commit 19f38bafe5
23 changed files with 159 additions and 50 deletions

View File

@ -43,6 +43,8 @@
#ifndef nsTextFragment_h___
#define nsTextFragment_h___
#include "mozilla/Attributes.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsTraceRefcnt.h"
@ -80,7 +82,7 @@ class nsCString;
* This class does not have a virtual destructor therefore it is not
* meant to be subclassed.
*/
class NS_FINAL_CLASS nsTextFragment {
class nsTextFragment MOZ_FINAL {
public:
static nsresult Init();
static void Shutdown();

View File

@ -41,6 +41,8 @@
#ifndef mozilla_ipc_Shmem_h
#define mozilla_ipc_Shmem_h
#include "mozilla/Attributes.h"
#include "base/basictypes.h"
#include "base/process.h"
@ -87,7 +89,7 @@
namespace mozilla {
namespace ipc {
class NS_FINAL_CLASS Shmem
class Shmem MOZ_FINAL
{
friend struct IPC::ParamTraits<mozilla::ipc::Shmem>;

View File

@ -92,6 +92,7 @@ Types = (
Includes = (
'mozilla/Attributes.h',
'base/basictypes.h',
'prtime.h',
'nscore.h',

View File

@ -161,9 +161,9 @@ class CxxCodeGen(CodePrinter, Visitor):
if c.abstract:
# FIXME/cjones: turn this "on" when we get the analysis
self.write(' /*NS_ABSTRACT_CLASS*/')
if c.final:
self.write(' NS_FINAL_CLASS')
self.write(' '+ c.name)
if c.final:
self.write(' MOZ_FINAL')
if c.specializes is not None:
self.write(' <')

View File

@ -40,6 +40,8 @@
#ifdef JS_THREADSAFE
#include "mozilla/Attributes.h"
#include <string.h>
#include "prthread.h"
#include "prlock.h"
@ -351,7 +353,7 @@ class Event
typedef ThreadSafeQueue<Event *> EventQueue;
class MainQueue : public EventQueue, public WorkerParent
class MainQueue MOZ_FINAL : public EventQueue, public WorkerParent
{
private:
ThreadPool *threadPool;
@ -430,7 +432,7 @@ class MainQueue : public EventQueue, public WorkerParent
* We keep a queue of workers with pending events, rather than a queue of
* events, so that two threads won't try to run a Worker at the same time.
*/
class WorkerQueue : public ThreadSafeQueue<Worker *>
class WorkerQueue MOZ_FINAL : public ThreadSafeQueue<Worker *>
{
private:
MainQueue *main;
@ -588,7 +590,7 @@ class ThreadPool
* Separately, there is a terminateFlag that other threads can set
* asynchronously to tell the Worker to terminate.
*/
class Worker : public WorkerParent
class Worker MOZ_FINAL : public WorkerParent
{
private:
ThreadPool *threadPool;

View File

@ -37,7 +37,7 @@
#ifndef nsFrameSelection_h___
#define nsFrameSelection_h___
#include "nsIFrame.h"
#include "nsIContent.h"
#include "nsISelectionController.h"
@ -210,7 +210,7 @@ class nsIScrollableFrame;
* or they may cause other objects to be deleted.
*/
class NS_FINAL_CLASS nsFrameSelection : public nsISupports {
class nsFrameSelection : public nsISupports {
public:
enum HINT { HINTLEFT = 0, HINTRIGHT = 1}; //end of this line or beginning of next
/*interfaces for addref and release and queryinterface*/

View File

@ -43,6 +43,8 @@
#ifndef nsLineBox_h___
#define nsLineBox_h___
#include "mozilla/Attributes.h"
#include "nsILineIterator.h"
#include "nsIFrame.h"
@ -1566,7 +1568,7 @@ nsLineList_const_reverse_iterator::operator=(const nsLineList_const_reverse_iter
//----------------------------------------------------------------------
class NS_FINAL_CLASS nsLineIterator : public nsILineIterator
class nsLineIterator MOZ_FINAL : public nsILineIterator
{
public:
nsLineIterator();

View File

@ -41,6 +41,8 @@
* Implementation of selection: nsISelection,nsISelectionPrivate and nsFrameSelection
*/
#include "mozilla/Attributes.h"
#include "nsCOMPtr.h"
#include "nsWeakReference.h"
#include "nsIFactory.h"
@ -357,7 +359,7 @@ private:
};
// Stack-class to turn on/off selection batching for table selection
class NS_STACK_CLASS NS_FINAL_CLASS nsSelectionBatcher
class NS_STACK_CLASS nsSelectionBatcher MOZ_FINAL
{
private:
nsCOMPtr<nsISelectionPrivate> mSelection;

View File

@ -40,6 +40,8 @@
#ifndef mozilla_css_ImportRule_h__
#define mozilla_css_ImportRule_h__
#include "mozilla/Attributes.h"
#include "mozilla/css/Rule.h"
#include "nsIDOMCSSImportRule.h"
#include "nsCSSRules.h"
@ -50,8 +52,8 @@ class nsString;
namespace mozilla {
namespace css {
class NS_FINAL_CLASS ImportRule : public Rule,
public nsIDOMCSSImportRule
class ImportRule MOZ_FINAL : public Rule,
public nsIDOMCSSImportRule
{
public:
ImportRule(nsMediaList* aMedia, const nsString& aURLSpec);

View File

@ -53,8 +53,8 @@ class nsIAtom;
namespace mozilla {
namespace css {
class NS_FINAL_CLASS NameSpaceRule : public Rule,
public nsIDOMCSSRule
class NameSpaceRule : public Rule,
public nsIDOMCSSRule
{
public:
NameSpaceRule(nsIAtom* aPrefix, const nsString& aURLSpec);

View File

@ -318,7 +318,7 @@ protected:
friend class StyleRule;
};
class NS_FINAL_CLASS StyleRule : public Rule
class StyleRule : public Rule
{
public:
StyleRule(nsCSSSelectorList* aSelector,

View File

@ -120,7 +120,7 @@ Rule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
// Style Rule List for group rules
//
class NS_FINAL_CLASS GroupRuleRuleList : public nsICSSRuleList
class GroupRuleRuleList : public nsICSSRuleList
{
public:
GroupRuleRuleList(GroupRule *aGroupRule);

View File

@ -43,6 +43,8 @@
#ifndef nsCSSRules_h_
#define nsCSSRules_h_
#include "mozilla/Attributes.h"
#include "mozilla/css/GroupRule.h"
#include "nsIDOMCSSMediaRule.h"
#include "nsIDOMCSSMozDocumentRule.h"
@ -70,8 +72,8 @@ class nsMediaList;
namespace mozilla {
namespace css {
class NS_FINAL_CLASS MediaRule : public GroupRule,
public nsIDOMCSSMediaRule
class MediaRule : public GroupRule,
public nsIDOMCSSMediaRule
{
public:
MediaRule();
@ -113,8 +115,8 @@ protected:
nsRefPtr<nsMediaList> mMedia;
};
class NS_FINAL_CLASS DocumentRule : public GroupRule,
public nsIDOMCSSMozDocumentRule
class DocumentRule : public GroupRule,
public nsIDOMCSSMozDocumentRule
{
public:
DocumentRule();
@ -212,8 +214,8 @@ private:
void* operator new(size_t size) CPP_THROW_NEW;
};
class NS_FINAL_CLASS nsCSSFontFaceRule : public mozilla::css::Rule,
public nsIDOMCSSFontFaceRule
class nsCSSFontFaceRule MOZ_FINAL : public mozilla::css::Rule,
public nsIDOMCSSFontFaceRule
{
public:
nsCSSFontFaceRule() {}
@ -273,8 +275,8 @@ nsCSSFontFaceStyleDecl::ContainingRule() const
namespace mozilla {
namespace css {
class NS_FINAL_CLASS CharsetRule : public Rule,
public nsIDOMCSSCharsetRule
class CharsetRule MOZ_FINAL : public Rule,
public nsIDOMCSSCharsetRule
{
public:
CharsetRule(const nsAString& aEncoding);
@ -313,8 +315,7 @@ private:
class nsCSSKeyframeRule;
class NS_FINAL_CLASS nsCSSKeyframeStyleDeclaration
: public nsDOMCSSDeclaration
class nsCSSKeyframeStyleDeclaration : public nsDOMCSSDeclaration
{
public:
nsCSSKeyframeStyleDeclaration(nsCSSKeyframeRule *aRule);
@ -344,8 +345,8 @@ protected:
nsCSSKeyframeRule *mRule;
};
class NS_FINAL_CLASS nsCSSKeyframeRule : public mozilla::css::Rule,
public nsIDOMMozCSSKeyframeRule
class nsCSSKeyframeRule MOZ_FINAL : public mozilla::css::Rule,
public nsIDOMMozCSSKeyframeRule
{
public:
// WARNING: Steals the contents of aKeys *and* aDeclaration
@ -389,8 +390,8 @@ private:
nsRefPtr<nsCSSKeyframeStyleDeclaration> mDOMDeclaration;
};
class NS_FINAL_CLASS nsCSSKeyframesRule : public mozilla::css::GroupRule,
public nsIDOMMozCSSKeyframesRule
class nsCSSKeyframesRule : public mozilla::css::GroupRule,
public nsIDOMMozCSSKeyframesRule
{
public:
nsCSSKeyframesRule(const nsSubstring& aName)

View File

@ -44,6 +44,8 @@
#ifndef nsCSSStyleSheet_h_
#define nsCSSStyleSheet_h_
#include "mozilla/Attributes.h"
#include "nscore.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
@ -132,9 +134,9 @@ struct ChildSheetListBuilder;
{ 0x84, 0x67, 0x80, 0x3f, 0xb3, 0x2a, 0xf2, 0x0a } }
class NS_FINAL_CLASS nsCSSStyleSheet : public nsIStyleSheet,
public nsIDOMCSSStyleSheet,
public nsICSSLoaderObserver
class nsCSSStyleSheet : public nsIStyleSheet,
public nsIDOMCSSStyleSheet,
public nsICSSLoaderObserver
{
public:
nsCSSStyleSheet();
@ -271,9 +273,8 @@ private:
nsIDocument* aDocumentToUse,
nsIDOMNode* aOwningNodeToUse);
// These are not supported and are not implemented!
nsCSSStyleSheet(const nsCSSStyleSheet& aCopy);
nsCSSStyleSheet& operator=(const nsCSSStyleSheet& aCopy);
nsCSSStyleSheet(const nsCSSStyleSheet& aCopy) MOZ_DELETE;
nsCSSStyleSheet& operator=(const nsCSSStyleSheet& aCopy) MOZ_DELETE;
protected:
virtual ~nsCSSStyleSheet();

View File

@ -44,6 +44,8 @@
#ifndef nsTreeBodyFrame_h
#define nsTreeBodyFrame_h
#include "mozilla/Attributes.h"
#include "nsLeafBoxFrame.h"
#include "nsITreeView.h"
#include "nsICSSPseudoComparator.h"
@ -77,7 +79,7 @@ struct nsTreeImageCacheEntry
};
// The actual frame that paints the cells and rows.
class NS_FINAL_CLASS nsTreeBodyFrame
class nsTreeBodyFrame MOZ_FINAL
: public nsLeafBoxFrame
, public nsICSSPseudoComparator
, public nsIScrollbarMediator

View File

@ -64,6 +64,7 @@
# if __clang_major__ >= 3
# define MOZ_HAVE_CXX11_DELETE
# define MOZ_HAVE_CXX11_OVERRIDE
# define MOZ_HAVE_CXX11_FINAL final
# elif __clang_major__ == 2
# if __clang_minor__ >= 9
# define MOZ_HAVE_CXX11_DELETE
@ -74,6 +75,7 @@
# if __GNUC__ > 4
# define MOZ_HAVE_CXX11_DELETE
# define MOZ_HAVE_CXX11_OVERRIDE
# define MOZ_HAVE CXX11_FINAL final
# elif __GNUC__ == 4
# if __GNUC_MINOR__ >= 7
# define MOZ_HAVE_CXX11_OVERRIDE
@ -82,10 +84,21 @@
# define MOZ_HAVE_CXX11_DELETE
# endif
# endif
# else
/* __final is a non-C++11 GCC synonym for 'final', per GCC r176655. */
# if __GNUC__ > 4
# define MOZ_HAVE_CXX11_FINAL __final
# elif __GNUC__ == 4
# if __GNUC_MINOR__ >= 7
# define MOZ_HAVE_CXX11_FINAL __final
# endif
# endif
# endif
#elif defined(_MSC_VER)
# if _MSC_VER >= 1400
# define MOZ_HAVE_CXX11_OVERRIDE
/* MSVC currently spells "final" as "sealed". */
# define MOZ_HAVE_CXX11_FINAL sealed
# endif
#endif
@ -158,4 +171,73 @@
# define MOZ_OVERRIDE /* no support */
#endif
/*
* MOZ_FINAL indicates that some functionality cannot be overridden through
* inheritance. It can be used to annotate either classes/structs or virtual
* member functions.
*
* To annotate a class/struct with MOZ_FINAL, place MOZ_FINAL immediately after
* the name of the class, before the list of classes from which it derives (if
* any) and before its opening brace. MOZ_FINAL must not be used to annotate
* unnamed classes or structs. (With some compilers, and with C++11 proper, the
* underlying expansion is ambiguous with specifying a class name.)
*
* class Base MOZ_FINAL
* {
* public:
* Base();
* ~Base();
* virtual void f() { }
* };
* // This will be an error in some compilers:
* class Derived : public Base
* {
* public:
* ~Derived() { }
* };
*
* One particularly common reason to specify MOZ_FINAL upon a class is to tell
* the compiler that it's not dangerous for it to have a non-virtual destructor
* yet have one or more virtual functions, silencing the warning it might emit
* in this case. Suppose Base above weren't annotated with MOZ_FINAL. Because
* ~Base() is non-virtual, an attempt to delete a Derived* through a Base*
* wouldn't call ~Derived(), so any cleanup ~Derived() might do wouldn't happen.
* (Formally C++ says behavior is undefined, but compilers will likely just call
* ~Base() and not ~Derived().) Specifying MOZ_FINAL tells the compiler that
* it's safe for the destructor to be non-virtual.
*
* In compilers implementing final controls, it is an error to inherit from a
* class annotated with MOZ_FINAL. In other compilers it serves only as
* documentation.
*
* To annotate a virtual member function with MOZ_FINAL, place MOZ_FINAL
* immediately before the ';' terminating the member function's declaration, or
* before '= 0;' if the member function is pure. If the member function is
* defined in the class definition, it should appear before the opening brace of
* the function body. (This placement is identical to that for MOZ_OVERRIDE.
* If both are used, they should appear in the order 'MOZ_FINAL MOZ_OVERRIDE'
* for consistency.)
*
* class Base
* {
* public:
* virtual void f() MOZ_FINAL;
* };
* class Derived
* {
* public:
* // This will be an error in some compilers:
* virtual void f();
* };
*
* In compilers implementing final controls, it is an error for a derived class
* to override a method annotated with MOZ_FINAL. In other compilers it serves
* only as documentation.
*/
#if defined(MOZ_HAVE_CXX11_FINAL)
# define MOZ_FINAL MOZ_HAVE_CXX11_FINAL
#else
# define MOZ_FINAL /* no support */
#endif
#endif /* mozilla_Attributes_h_ */

View File

@ -38,10 +38,12 @@
#ifndef __nsconsolemessage_h__
#define __nsconsolemessage_h__
#include "mozilla/Attributes.h"
#include "nsIConsoleMessage.h"
#include "nsString.h"
class nsConsoleMessage : public nsIConsoleMessage {
class nsConsoleMessage MOZ_FINAL : public nsIConsoleMessage {
public:
nsConsoleMessage();
nsConsoleMessage(const PRUnichar *message);

View File

@ -38,6 +38,8 @@
#ifndef nsErrorService_h__
#define nsErrorService_h__
#include "mozilla/Attributes.h"
#include "nsIErrorService.h"
#include "nsHashtable.h"
@ -54,7 +56,7 @@ protected:
nsObjectHashtable mHashtable;
};
class nsErrorService : public nsIErrorService
class nsErrorService MOZ_FINAL : public nsIErrorService
{
public:
NS_DECL_ISUPPORTS

View File

@ -38,6 +38,8 @@
#ifndef mozilla_GenericFactory_h
#define mozilla_GenericFactory_h
#include "mozilla/Attributes.h"
#include "mozilla/Module.h"
namespace mozilla {
@ -47,7 +49,7 @@ namespace mozilla {
* This class is intended for use by the component manager and the generic
* module.
*/
class GenericFactory : public nsIFactory
class GenericFactory MOZ_FINAL : public nsIFactory
{
public:
typedef Module::ConstructorProcPtr ConstructorProcPtr;

View File

@ -36,6 +36,8 @@
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/Attributes.h"
#include "nsArrayEnumerator.h"
#include "nsIArray.h"
@ -44,7 +46,7 @@
#include "nsCOMArray.h"
#include "nsCOMPtr.h"
class nsSimpleArrayEnumerator : public nsISimpleEnumerator
class nsSimpleArrayEnumerator MOZ_FINAL : public nsISimpleEnumerator
{
public:
// nsISupports interface
@ -126,7 +128,7 @@ NS_NewArrayEnumerator(nsISimpleEnumerator* *result,
// creates a snapshot of the array in question
// you MUST use NS_NewArrayEnumerator to create this, so that
// allocation is done correctly
class nsCOMArrayEnumerator : public nsISimpleEnumerator
class nsCOMArrayEnumerator MOZ_FINAL : public nsISimpleEnumerator
{
public:
// nsISupports interface

View File

@ -53,6 +53,7 @@
-- scc
*/
#include "mozilla/Attributes.h"
// Wrapping includes can speed up compiles (see "Large Scale C++ Software Design")
#ifndef nsDebug_h___
@ -277,8 +278,7 @@ class nsCOMPtr_helper
class
NS_COM_GLUE
NS_STACK_CLASS
NS_FINAL_CLASS
nsQueryInterface
nsQueryInterface MOZ_FINAL
{
public:
explicit
@ -513,9 +513,7 @@ nsCOMPtr_base
// template <class T> class nsGetterAddRefs;
template <class T>
class
NS_FINAL_CLASS
nsCOMPtr
class nsCOMPtr MOZ_FINAL
#ifdef NSCAP_FEATURE_USE_BASE
: private nsCOMPtr_base
#endif

View File

@ -40,6 +40,8 @@
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/Attributes.h"
#include "nsEnumeratorUtils.h"
#include "nsISimpleEnumerator.h"
@ -124,7 +126,7 @@ NS_NewEmptyEnumerator(nsISimpleEnumerator** aResult)
////////////////////////////////////////////////////////////////////////////////
class nsSingletonEnumerator : public nsISimpleEnumerator
class nsSingletonEnumerator MOZ_FINAL : public nsISimpleEnumerator
{
public:
NS_DECL_ISUPPORTS

View File

@ -40,10 +40,12 @@
// nsWeakReference.cpp
#include "mozilla/Attributes.h"
#include "nsWeakReference.h"
#include "nsCOMPtr.h"
class nsWeakReference : public nsIWeakReference
class nsWeakReference MOZ_FINAL : public nsIWeakReference
{
public:
// nsISupports...