1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 * Detect classes that should have overridden members of their parent
12 * virtual NS_MUST_OVERRIDE void f();
16 * struct A : S { virtual void f(); }; // ok
17 * struct B : S { virtual NS_MUST_OVERRIDE void f(); }; // also ok
19 * struct C : S { virtual void g(); }; // ERROR: must override f()
20 * struct D : S { virtual void f(int); }; // ERROR: different overload
21 * struct E : A { }; // ok: A's definition of f() is good for subclasses
22 * struct F : B { }; // ERROR: B's definition of f() is still must-override
24 * We don't care if you define the method or not.
27 function get_must_overrides(cls)
30 for each (let base in cls.bases)
31 for each (let m in base.type.members)
32 if (hasAttribute(m, 'NS_must_override'))
38 function process_type(t)
40 if (t.isIncomplete || (t.kind != 'class' && t.kind != 'struct'))
43 let mos = get_must_overrides(t);
44 for each (let m in t.members) {
45 let mos_m = mos[m.shortName]
46 if (mos_m && signaturesMatch(mos_m, m))
47 delete mos[m.shortName];
50 for each (let u in mos)
51 error(t.kind + " " + t.name + " must override " + u.name, t.loc);