2008-02-27 08:28:13 -08:00
|
|
|
/**
|
|
|
|
* A script for GCC-dehydra to analyze the Mozilla codebase and catch
|
|
|
|
* patterns that are incorrect, but which cannot be detected by a compiler. */
|
|
|
|
|
2008-04-30 17:47:27 -07:00
|
|
|
/**
|
|
|
|
* Activate Treehydra outparams analysis if running in Treehydra.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function treehydra_enabled() {
|
|
|
|
return this.hasOwnProperty('TREE_CODE');
|
|
|
|
}
|
|
|
|
|
2008-06-06 12:31:11 -07:00
|
|
|
include('unstable/getopt.js');
|
|
|
|
[options, args] = getopt();
|
|
|
|
|
|
|
|
sys.include_path.push(options.topsrcdir);
|
|
|
|
|
2008-09-03 10:00:13 -07:00
|
|
|
include('string-format.js');
|
|
|
|
|
2008-06-06 12:31:11 -07:00
|
|
|
let modules = [];
|
|
|
|
|
|
|
|
function LoadModules(modulelist)
|
|
|
|
{
|
|
|
|
if (modulelist == "")
|
|
|
|
return;
|
|
|
|
|
|
|
|
let modulenames = modulelist.split(',');
|
|
|
|
for each (let modulename in modulenames) {
|
|
|
|
let module = { __proto__: this };
|
|
|
|
include(modulename, module);
|
|
|
|
modules.push(module);
|
|
|
|
}
|
2008-04-30 17:47:27 -07:00
|
|
|
}
|
|
|
|
|
2008-06-06 12:31:11 -07:00
|
|
|
LoadModules(options['dehydra-modules']);
|
|
|
|
if (treehydra_enabled())
|
|
|
|
LoadModules(options['treehydra-modules']);
|
|
|
|
|
2008-03-27 11:03:59 -07:00
|
|
|
function process_type(c)
|
2008-02-27 08:28:13 -08:00
|
|
|
{
|
2008-06-06 12:31:11 -07:00
|
|
|
for each (let module in modules)
|
|
|
|
if (module.hasOwnProperty('process_type'))
|
|
|
|
module.process_type(c);
|
2008-02-27 08:28:13 -08:00
|
|
|
}
|
|
|
|
|
2008-06-30 09:44:06 -07:00
|
|
|
function hasAttribute(c, attrname)
|
2008-02-27 08:28:13 -08:00
|
|
|
{
|
2008-06-30 09:44:06 -07:00
|
|
|
var attr;
|
2008-02-27 08:28:13 -08:00
|
|
|
|
2008-06-30 09:44:06 -07:00
|
|
|
if (c.attributes === undefined)
|
2008-02-27 08:28:13 -08:00
|
|
|
return false;
|
|
|
|
|
2008-06-30 09:44:06 -07:00
|
|
|
for each (attr in c.attributes)
|
|
|
|
if (attr.name == 'user' && attr.value[0] == attrname)
|
|
|
|
return true;
|
2008-02-27 08:28:13 -08:00
|
|
|
|
2008-06-30 09:44:06 -07:00
|
|
|
return false;
|
2008-02-27 08:28:13 -08:00
|
|
|
}
|
2008-09-03 10:00:13 -07:00
|
|
|
|
2009-09-18 10:26:13 -07:00
|
|
|
// This is useful for detecting method overrides
|
|
|
|
function signaturesMatch(m1, m2)
|
|
|
|
{
|
|
|
|
if (m1.shortName != m2.shortName)
|
|
|
|
return false;
|
2009-09-04 08:21:31 -07:00
|
|
|
|
2009-10-04 11:35:33 -07:00
|
|
|
if ((!!m1.isVirtual) != (!!m2.isVirtual))
|
2009-09-04 08:21:31 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (m1.isStatic != m2.isStatic)
|
|
|
|
return false;
|
2009-09-18 10:26:13 -07:00
|
|
|
|
|
|
|
let p1 = m1.type.parameters;
|
|
|
|
let p2 = m2.type.parameters;
|
|
|
|
|
|
|
|
if (p1.length != p2.length)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (let i = 0; i < p1.length; ++i)
|
|
|
|
if (p1[i] !== p2[i])
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-06-25 12:12:19 -07:00
|
|
|
const forward_functions = [
|
|
|
|
'process_type',
|
|
|
|
'process_tree_type',
|
|
|
|
'process_decl',
|
|
|
|
'process_tree_decl',
|
|
|
|
'process_function',
|
|
|
|
'process_tree',
|
|
|
|
'process_cp_pre_genericize',
|
|
|
|
'input_end'
|
|
|
|
];
|
|
|
|
|
|
|
|
function setup_forwarding(n)
|
2008-09-03 10:00:13 -07:00
|
|
|
{
|
2009-06-25 12:12:19 -07:00
|
|
|
this[n] = function() {
|
|
|
|
for each (let module in modules) {
|
|
|
|
if (module.hasOwnProperty(n)) {
|
|
|
|
module[n].apply(this, arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-06 12:31:11 -07:00
|
|
|
}
|
2008-02-27 08:28:13 -08:00
|
|
|
|
2009-06-25 12:12:19 -07:00
|
|
|
for each (let n in forward_functions)
|
|
|
|
setup_forwarding(n);
|