1
%% -*- erlang-indent-level: 2 -*-
2
%%--------------------------------------------------------------------
5
%% Copyright Ericsson AB 2007-2009. All Rights Reserved.
7
%% The contents of this file are subject to the Erlang Public License,
8
%% Version 1.1, (the "License"); you may not use this file except in
9
%% compliance with the License. You should have received a copy of the
10
%% Erlang Public License along with this software. If not, it can be
11
%% retrieved online at http://www.erlang.org/.
13
%% Software distributed under the License is distributed on an "AS IS"
14
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
15
%% the License for the specific language governing rights and limitations
21
%%-----------------------------------------------------------------------------
22
%% File : dialyzer_callgraph.hrl
23
%% Author : Tobias Lindahl <tobiasl@it.uu.se>
24
%% Kostis Sagonas <kostis@it.uu.se>
25
%% Description : Header file for Dialyzer's call graph module.
27
%% Created : 23 Nov 2007 by Kostis Sagonas <kostis@it.uu.se>
28
%%-----------------------------------------------------------------------------
30
%%-----------------------------------------------------------------------------
31
%% A callgraph is a directed graph where the nodes are functions and a
32
%% call between two functions is an edge from the caller to the callee.
34
%% calls - A mapping from call site (and apply site) labels
35
%% to the possible functions that can be called.
36
%% digraph - A digraph representing the callgraph.
37
%% Nodes are represented as MFAs or labels.
38
%% esc - A set of all escaping functions as reported by dialyzer_dep.
39
%% postorder - A list of strongly connected components of the callgraph
40
%% sorted in a topological bottom-up order.
41
%% This is produced by calling finalize/1.
42
%% name_map - A mapping from label to MFA.
43
%% rev_name_map - A reverse mapping of the name_map.
44
%% rec_var_map - A dict mapping from letrec bound labels to function names.
45
%% Only for top level functions (from module defs).
46
%% self_rec - A set containing all self recursive functions.
47
%% Note that this contains MFAs for named functions and labels
48
%% whenever applicable.
49
%%-----------------------------------------------------------------------------
51
%%-----------------------------------------------------------------------
53
-define(no_arg, no_arg).
54
-define(no_label, no_label).
56
%%-----------------------------------------------------------------------
58
-type mfa_or_funlbl() :: label() | mfa().
59
-type scc() :: [mfa_or_funlbl()].
60
-type mfa_calls() :: [{mfa_or_funlbl(), mfa_or_funlbl()}].
62
%%-----------------------------------------------------------------------
64
%%-----------------------------------------------------------------------
65
%% Basic types used in the race analysis
66
%%-----------------------------------------------------------------------
68
-type label_type() :: label() | [label()] | {label()} | ?no_label.
69
-type args() :: 'empty' | [label_type() | [string()]].
70
-type core_vars() :: core_tree() | ?no_arg.
71
-type var_to_map() :: core_vars() | [core_tree()].
72
-type dep_calls() :: 'whereis' | 'ets_lookup' | 'mnesia_dirty_read'.
73
-type warn_calls() :: 'register' | 'ets_insert' | 'mnesia_dirty_write'.
74
-type race_tag() :: 'whereis_register' | 'ets_lookup_insert'
75
| 'mnesia_dirty_read_write'.
77
-record(beg_clause, {arg :: var_to_map(),
79
guard :: core_tree()}).
80
-record(end_clause, {arg :: var_to_map(),
82
guard :: core_tree()}).
83
-record(end_case, {clauses :: [#end_clause{}]}).
84
-record(curr_fun, {status :: 'in' | 'out',
85
mfa :: mfa_or_funlbl(),
87
def_vars :: [core_vars()],
88
arg_types :: [erl_types:erl_type()],
89
call_vars :: [core_vars()],
91
-record(dep_call, {call_name :: dep_calls(),
93
arg_types :: [erl_types:erl_type()],
94
vars :: [core_vars()],
96
file_line :: file_line(),
98
-record(fun_call, {caller :: mfa_or_funlbl(),
99
callee :: mfa_or_funlbl(),
100
arg_types :: [erl_types:erl_type()],
101
vars :: [core_vars()]}).
102
-record(let_tag, {var :: var_to_map(),
103
arg :: var_to_map()}).
104
-record(warn_call, {call_name :: warn_calls(),
108
-type case_tags() :: 'beg_case' | #beg_clause{} | #end_clause{} | #end_case{}.
109
-type code() :: [#dep_call{} | #warn_call{} | #fun_call{} |
110
#curr_fun{} | #let_tag{} | case_tags() | race_tag()]
113
%%----------------------------------------------------------------------
114
%% Record declarations used in various files
115
%%----------------------------------------------------------------------
117
-record(dialyzer_callgraph, {digraph = digraph:new() :: digraph(),
118
esc = sets:new() :: set(),
119
name_map = dict:new() :: dict(),
120
rev_name_map = dict:new() :: dict(),
121
postorder = [] :: [scc()],
122
rec_var_map = dict:new() :: dict(),
123
self_rec = sets:new() :: set(),
124
calls = dict:new() :: dict(),
125
race_code = dict:new() :: dict(),
126
public_tables = [] :: [label()],
127
named_tables = [] :: [string()],
128
race_detection = false :: boolean()}).