Bug 437647 - Dispatch outparams and other analyses explicitly, so it's easier to add various analyses, r=dmandelin

This commit is contained in:
Benjamin Smedberg 2008-06-06 15:31:11 -04:00
Родитель f4b0e442f4
Коммит 1829cc61f7
3 изменённых файлов: 98 добавлений и 27 удалений

Просмотреть файл

@ -62,6 +62,8 @@ include $(topsrcdir)/config/insure.mk
endif
endif
COMMA = ,
# Sanity check some variables
CHECK_VARS := \
XPI_NAME \
@ -522,10 +524,26 @@ endif
# The entire tree should be subject to static analysis using the XPCOM
# script. Additional scripts may be added by specific subdirectories.
DEHYDRA_SCRIPTS = $(topsrcdir)/xpcom/analysis/static-checking.js
DEHYDRA_SCRIPT = $(topsrcdir)/xpcom/analysis/static-checking.js
DEHYDRA_MODULES = \
$(topsrcdir)/xpcom/analysis/stack.js \
$(NULL)
TREEHYDRA_MODULES = \
$(topsrcdir)/xpcom/analysis/outparams.js \
$(NULL)
DEHYDRA_ARGS = \
--topsrcdir=$(topsrcdir) \
--objdir=$(DEPTH) \
--dehydra-modules=$(subst $(NULL) ,$(COMMA),$(strip $(DEHYDRA_MODULES))) \
--treehydra-modules=$(subst $(NULL) ,$(COMMA),$(strip $(TREEHYDRA_MODULES))) \
$(NULL)
DEHYDRA_FLAGS = -fplugin=$(DEHYDRA_PATH) -fplugin-arg="$(DEHYDRA_SCRIPT) $(DEHYDRA_ARGS)"
ifdef DEHYDRA_PATH
DEHYDRA_FLAGS = -fplugin=$(DEHYDRA_PATH) $(foreach script,$(DEHYDRA_SCRIPTS),-fplugin-arg=$(script))
OS_CXXFLAGS += $(DEHYDRA_FLAGS)
endif

26
xpcom/analysis/stack.js Normal file
Просмотреть файл

@ -0,0 +1,26 @@
function process_function(f, stmts)
{
var stmt;
function getLocation()
{
if (stmt.loc)
return stmt.loc;
return f.loc;
}
function processVar(v)
{
if (v.isConstructor &&
v.fieldOf &&
get_class(v.memberOf, false).stack &&
v.fieldOf.type.isPointer) {
error(getLocation() + ": constructed object of type '" +
v.memberOf.name + "' not on the stack.");
}
}
for each (stmt in stmts) {
iter(processVar, stmt.statements);
}
}

Просмотреть файл

@ -10,10 +10,32 @@ function treehydra_enabled() {
return this.hasOwnProperty('TREE_CODE');
}
if (treehydra_enabled()) {
include('outparams.js');
include('unstable/getopt.js');
[options, args] = getopt();
// XXXbugfix: when you pass arguments to -fplugin-arg, include_path[0] is bad
sys.include_path[0] = options.topsrcdir + "/xpcom/analysis";
sys.include_path.push(options.topsrcdir);
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);
}
}
LoadModules(options['dehydra-modules']);
if (treehydra_enabled())
LoadModules(options['treehydra-modules']);
/**
* gClassMap maps class names to an object with the following properties:
*
@ -38,6 +60,10 @@ function process_type(c)
{
if (c.kind == 'class' || c.kind == 'struct')
get_class(c, true);
for each (let module in modules)
if (module.hasOwnProperty('process_type'))
module.process_type(c);
}
/**
@ -200,27 +226,28 @@ function unwrapArray(t)
function process_function(f, stmts)
{
var stmt;
function getLocation()
{
if (stmt.loc)
return stmt.loc;
return f.loc;
}
function processVar(v)
{
if (v.isConstructor &&
v.fieldOf &&
get_class(v.methodOf, false).stack &&
v.fieldOf.type.isPointer) {
error(getLocation() + ": constructed object of type '" +
v.methodOf.name + "' not on the stack.");
}
}
for each (stmt in stmts) {
iter(processVar, stmt.statements);
}
for each (let module in modules)
if (module.hasOwnProperty('process_function'))
module.process_function(f, stmts);
}
function process_tree(fndecl)
{
for each (let module in modules)
if (module.hasOwnProperty('process_tree'))
module.process_tree(fndecl);
}
function process_var(decl)
{
for each (let module in modules)
if (module.hasOwnProperty('process_var'))
module.process_var(decl);
}
function input_end()
{
for each (let module in modules)
if (module.hasOwnProperty('input_end'))
module.input_end();
}