michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * Detect classes that should have overridden members of their parent michael@0: * classes but didn't. michael@0: * michael@0: * Example: michael@0: * michael@0: * struct S { michael@0: * virtual NS_MUST_OVERRIDE void f(); michael@0: * virtual void g(); michael@0: * }; michael@0: * michael@0: * struct A : S { virtual void f(); }; // ok michael@0: * struct B : S { virtual NS_MUST_OVERRIDE void f(); }; // also ok michael@0: * michael@0: * struct C : S { virtual void g(); }; // ERROR: must override f() michael@0: * struct D : S { virtual void f(int); }; // ERROR: different overload michael@0: * struct E : A { }; // ok: A's definition of f() is good for subclasses michael@0: * struct F : B { }; // ERROR: B's definition of f() is still must-override michael@0: * michael@0: * We don't care if you define the method or not. michael@0: */ michael@0: michael@0: function get_must_overrides(cls) michael@0: { michael@0: let mos = {}; michael@0: for each (let base in cls.bases) michael@0: for each (let m in base.type.members) michael@0: if (hasAttribute(m, 'NS_must_override')) michael@0: mos[m.shortName] = m; michael@0: michael@0: return mos; michael@0: } michael@0: michael@0: function process_type(t) michael@0: { michael@0: if (t.isIncomplete || (t.kind != 'class' && t.kind != 'struct')) michael@0: return; michael@0: michael@0: let mos = get_must_overrides(t); michael@0: for each (let m in t.members) { michael@0: let mos_m = mos[m.shortName] michael@0: if (mos_m && signaturesMatch(mos_m, m)) michael@0: delete mos[m.shortName]; michael@0: } michael@0: michael@0: for each (let u in mos) michael@0: error(t.kind + " " + t.name + " must override " + u.name, t.loc); michael@0: }