Bug 767563 - Add a clang static checker, part 3: Move the MOZ_MUST_OVERRIDE macro to MFBT. r=Waldo

This commit is contained in:
Joshua Cranmer 2013-03-23 21:14:43 -05:00
parent 557e5bbac0
commit 5765d5aec4
15 changed files with 101 additions and 57 deletions

View File

@ -2942,10 +2942,10 @@ public:
// return storage used by this run, for memory reporter;
// nsTransformedTextRun needs to override this as it holds additional data
virtual NS_MUST_OVERRIDE size_t
SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf);
virtual NS_MUST_OVERRIDE size_t
SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf);
virtual size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf)
MOZ_MUST_OVERRIDE;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf)
MOZ_MUST_OVERRIDE;
// Get the size, if it hasn't already been gotten, marking as it goes.
size_t MaybeSizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) {

View File

@ -87,8 +87,8 @@
// memory is allocated for a frame object).
#define NS_DECL_FRAMEARENA_HELPERS \
NS_MUST_OVERRIDE void* operator new(size_t, nsIPresShell*); \
virtual NS_MUST_OVERRIDE nsQueryFrame::FrameIID GetFrameId();
void* operator new(size_t, nsIPresShell*) MOZ_MUST_OVERRIDE; \
virtual nsQueryFrame::FrameIID GetFrameId() MOZ_MUST_OVERRIDE;
#define NS_IMPL_FRAMEARENA_HELPERS(class) \
void* class::operator new(size_t sz, nsIPresShell* aShell) \

View File

@ -102,8 +102,8 @@ public:
}
// override the gfxTextRun impls to account for additional members here
virtual NS_MUST_OVERRIDE size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf);
virtual NS_MUST_OVERRIDE size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf);
virtual size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) MOZ_MUST_OVERRIDE;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) MOZ_MUST_OVERRIDE;
nsTransformingTextRunFactory *mFactory;
nsTArray<nsRefPtr<nsStyleContext> > mStyles;

View File

@ -42,10 +42,10 @@ public:
virtual nsRestyleHint
HasAttributeDependentStyle(AttributeRuleProcessorData* aData) MOZ_OVERRIDE;
virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) MOZ_OVERRIDE;
virtual NS_MUST_OVERRIDE size_t
SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
virtual NS_MUST_OVERRIDE size_t
SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
virtual size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf)
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf)
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
/**
* Notify the manager that the pres context is going away.

View File

@ -67,10 +67,9 @@ public:
virtual bool UseForPresentation(nsPresContext* aPresContext,
nsMediaQueryResultCacheKey& aKey) = 0;
NS_MUST_OVERRIDE size_t // non-virtual -- it is only called by subclasses
SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
virtual size_t
SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const = 0;
// non-virtual -- it is only called by subclasses
size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const = 0;
protected:
// to help implement nsIDOMCSSRule

View File

@ -52,8 +52,8 @@ public:
void GetURLSpec(nsString& aURLSpec) const { aURLSpec = mURLSpec; }
virtual NS_MUST_OVERRIDE size_t
SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
MOZ_MUST_OVERRIDE;
// nsIDOMCSSRule interface
NS_DECL_NSIDOMCSSRULE

View File

@ -110,8 +110,8 @@ public:
// This is pure virtual because all of Rule's data members are non-owning and
// thus measured elsewhere.
virtual NS_MUST_OVERRIDE size_t
SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const = 0;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf)
const MOZ_MUST_OVERRIDE = 0;
// This is used to measure nsCOMArray<Rule>s.
static size_t SizeOfCOMArrayElementIncludingThis(css::Rule* aElement,

View File

@ -222,10 +222,10 @@ public:
#ifdef MOZ_XUL
virtual void RulesMatching(XULTreeRuleProcessorData* aData) MOZ_OVERRIDE;
#endif
virtual NS_MUST_OVERRIDE size_t
SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
virtual NS_MUST_OVERRIDE size_t
SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
virtual size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf)
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf)
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
// nsARefreshObserver
virtual void WillRefresh(mozilla::TimeStamp aTime) MOZ_OVERRIDE;

View File

@ -112,10 +112,10 @@ public:
virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) MOZ_OVERRIDE;
virtual NS_MUST_OVERRIDE size_t
SizeOfExcludingThis(nsMallocSizeOfFun mallocSizeOf) const MOZ_OVERRIDE;
virtual NS_MUST_OVERRIDE size_t
SizeOfIncludingThis(nsMallocSizeOfFun mallocSizeOf) const MOZ_OVERRIDE;
virtual size_t SizeOfExcludingThis(nsMallocSizeOfFun mallocSizeOf)
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun mallocSizeOf)
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
// Append all the currently-active font face rules to aArray. Return
// true for success and false for failure.

View File

@ -89,8 +89,8 @@ public:
// @media rule methods
nsresult SetMedia(nsMediaList* aMedia);
virtual NS_MUST_OVERRIDE size_t
SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf)
const MOZ_MUST_OVERRIDE;
protected:
void AppendConditionText(nsAString& aOutput);
@ -167,8 +167,8 @@ public:
void SetURLs(URL *aURLs) { mURLs = aURLs; }
virtual NS_MUST_OVERRIDE size_t
SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf)
const MOZ_MUST_OVERRIDE;
protected:
void AppendConditionText(nsAString& aOutput);

View File

@ -59,10 +59,10 @@ public:
virtual nsRestyleHint
HasAttributeDependentStyle(AttributeRuleProcessorData* aData) MOZ_OVERRIDE;
virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) MOZ_OVERRIDE;
virtual NS_MUST_OVERRIDE size_t
SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
virtual NS_MUST_OVERRIDE size_t
SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
virtual size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf)
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf)
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
void CacheStyleAttr(const nsAString& aSerialized, MiscContainer* aValue);
void EvictStyleAttr(const nsAString& aSerialized, MiscContainer* aValue);

View File

@ -60,10 +60,10 @@ public:
virtual nsRestyleHint
HasAttributeDependentStyle(AttributeRuleProcessorData* aData) MOZ_OVERRIDE;
virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) MOZ_OVERRIDE;
virtual NS_MUST_OVERRIDE size_t
SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
virtual NS_MUST_OVERRIDE size_t
SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
virtual size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf)
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf)
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
size_t DOMSizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
void Reset(nsIURI* aURL);

View File

@ -170,10 +170,10 @@ public:
#ifdef MOZ_XUL
virtual void RulesMatching(XULTreeRuleProcessorData* aData) MOZ_OVERRIDE;
#endif
virtual NS_MUST_OVERRIDE size_t
SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
virtual NS_MUST_OVERRIDE size_t
SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
virtual size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
// nsARefreshObserver
virtual void WillRefresh(mozilla::TimeStamp aTime) MOZ_OVERRIDE;

View File

@ -319,6 +319,64 @@
# define MOZ_WARN_UNUSED_RESULT
#endif
/*
* The following macros are attributes that support the static analysis plugin
* included with Mozilla, and will be implemented (when such support is enabled)
* as C++11 attributes. Since such attributes are legal pretty much everywhere
* and have subtly different semantics depending on their placement, the
* following is a guide on where to place the attributes.
*
* Attributes that apply to a struct or class precede the name of the class:
* (Note that this is different from the placement of MOZ_FINAL for classes!)
*
* class MOZ_CLASS_ATTRIBUTE SomeClass {};
*
* Attributes that apply to functions follow the parentheses and const
* qualifiers but precede MOZ_FINAL, MOZ_OVERRIDE and the function body:
*
* void DeclaredFunction() MOZ_FUNCTION_ATTRIBUTE;
* void SomeFunction() MOZ_FUNCTION_ATTRIBUTE {}
* void PureFunction() const MOZ_FUNCTION_ATTRIBUTE = 0;
* void OverriddenFunction() MOZ_FUNCTION_ATTIRBUTE MOZ_OVERRIDE;
*
* Attributes that apply to variables or parameters follow the variable's name:
*
* int variable MOZ_VARIABLE_ATTRIBUTE;
*
* Attributes that apply to types follow the type name:
*
* typedef int MOZ_TYPE_ATTRIBUTE MagicInt;
* int MOZ_TYPE_ATTRIBUTE someVariable;
* int * MOZ_TYPE_ATTRIBUTE magicPtrInt;
* int MOZ_TYPE_ATTRIBUTE * ptrToMagicInt;
*
* Attributes that apply to statements precede the statement:
*
* MOZ_IF_ATTRIBUTE if (x == 0)
* MOZ_DO_ATTRIBUTE do { } while(0);
*
* Attributes that apply to labels precede the label:
*
* MOZ_LABEL_ATTRIBUTE target:
* goto target;
* MOZ_CASE_ATTRIBUTE case 5:
* MOZ_DEFAULT_ATTRIBUTE default:
*
* The static analyses that are performed by the plugin are as follows:
*
* MOZ_MUST_OVERRIDE: Applies to all C++ member functions. All immediate
* subclasses must provide an exact override of this method; if a subclass
* does not override this method, the compiler will emit an error. This
* attribute is not limited to virtual methods, so if it is applied to a
* nonvirtual method and the subclass does not provide an equivalent
* definition, the compiler will emit an error.
*/
#ifdef MOZ_CLANG_PLUGIN
# define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override")))
#else
# define MOZ_MUST_OVERRIDE /* nothing */
#endif /* MOZ_CLANG_PLUGIN */
#endif /* __cplusplus */
#endif /* mozilla_Attributes_h_ */

View File

@ -377,28 +377,15 @@ typedef uint32_t nsrefcnt;
* Static type annotations, enforced when static-checking is enabled:
*
* NS_STACK_CLASS: a class which must only be instantiated on the stack
*
* NS_MUST_OVERRIDE:
* a method which every immediate subclass of this class must
* override. A subclass override can itself be NS_MUST_OVERRIDE, in
* which case its own subclasses must override the method as well.
*
* This is similar to, but not the same as, marking a method pure
* virtual. It has no effect on the class in which the annotation
* appears, you can still provide a definition for the method, and
* it objects to the mere existence of a subclass that doesn't
* override the method. See examples in analysis/must-override.js.
*/
#ifdef NS_STATIC_CHECKING
#define NS_STACK_CLASS __attribute__((user("NS_stack")))
#define NS_OKONHEAP __attribute__((user("NS_okonheap")))
#define NS_SUPPRESS_STACK_CHECK __attribute__((user("NS_suppress_stackcheck")))
#define NS_MUST_OVERRIDE __attribute__((user("NS_must_override")))
#else
#define NS_STACK_CLASS
#define NS_OKONHEAP
#define NS_SUPPRESS_STACK_CHECK
#define NS_MUST_OVERRIDE
#endif
/*