xpcom/analysis/must-override.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     5 /*
     6  * Detect classes that should have overridden members of their parent
     7  * classes but didn't.
     8  *
     9  * Example:
    10  *
    11  * struct S {
    12  *   virtual NS_MUST_OVERRIDE void f();
    13  *   virtual void g();
    14  * };
    15  *
    16  * struct A : S { virtual void f(); }; // ok
    17  * struct B : S { virtual NS_MUST_OVERRIDE void f(); }; // also ok
    18  *
    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
    23  *
    24  * We don't care if you define the method or not.
    25  */
    27 function get_must_overrides(cls)
    28 {
    29   let mos = {};
    30   for each (let base in cls.bases)
    31     for each (let m in base.type.members)
    32       if (hasAttribute(m, 'NS_must_override')) 
    33        mos[m.shortName] = m;
    35   return mos;
    36 }
    38 function process_type(t)
    39 {
    40   if (t.isIncomplete || (t.kind != 'class' && t.kind != 'struct'))
    41     return;
    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];
    48   }
    50   for each (let u in mos)
    51     error(t.kind + " " + t.name + " must override " + u.name, t.loc);
    52 }

mercurial