Fix GCC uninit-var warning (no bug, r=brendan).
[mozilla-central.git] / config / static-checking.js
blob7a64eeadb1ba819d4051ad40d80923f2a6af0954
1 /**
2  * A script for GCC-dehydra to analyze the Mozilla codebase and catch
3  * patterns that are incorrect, but which cannot be detected by a compiler. */
5 /**
6  * Activate Treehydra outparams analysis if running in Treehydra.
7  */
9 function treehydra_enabled() {
10   return this.hasOwnProperty('TREE_CODE');
13 include('unstable/getopt.js');
14 [options, args] = getopt();
16 sys.include_path.push(options.topsrcdir);
18 include('string-format.js');
20 let modules = [];
22 function LoadModules(modulelist)
24   if (modulelist == "")
25     return;
27   let modulenames = modulelist.split(',');
28   for each (let modulename in modulenames) {
29     let module = { __proto__: this };
30     include(modulename, module);
31     modules.push(module);
32   }
35 LoadModules(options['dehydra-modules']);
36 if (treehydra_enabled())
37   LoadModules(options['treehydra-modules']);
39 function process_type(c)
41   for each (let module in modules)
42     if (module.hasOwnProperty('process_type'))
43       module.process_type(c);
46 function hasAttribute(c, attrname)
48   var attr;
50   if (c.attributes === undefined)
51     return false;
53   for each (attr in c.attributes)
54     if (attr.name == 'user' && attr.value[0] == attrname)
55       return true;
57   return false;
60 // This is useful for detecting method overrides
61 function signaturesMatch(m1, m2)
63   if (m1.shortName != m2.shortName)
64     return false;
66   if ((!!m1.isVirtual) != (!!m2.isVirtual))
67     return false;
68   
69   if (m1.isStatic != m2.isStatic)
70     return false;
71   
72   let p1 = m1.type.parameters;
73   let p2 = m2.type.parameters;
74   
75   if (p1.length != p2.length)
76     return false;
77   
78   for (let i = 0; i < p1.length; ++i)
79     if (p1[i] !== p2[i])
80       return false;
81   
82   return true;
85 const forward_functions = [
86   'process_type',
87   'process_tree_type',
88   'process_decl',
89   'process_tree_decl',
90   'process_function',
91   'process_tree',
92   'process_cp_pre_genericize',
93   'input_end'
96 function setup_forwarding(n)
98   this[n] = function() {
99     for each (let module in modules) {
100       if (module.hasOwnProperty(n)) {
101         module[n].apply(this, arguments);
102       }
103     }
104   }
107 for each (let n in forward_functions)
108   setup_forwarding(n);