|Did you know ...||Search Documentation:|
|prolog_codewalk.pl -- Prolog code walker|
This module walks over the loaded program, searching for callable predicates. It started as part of library(prolog_autoload) and has been turned into a separate module to facilitate operations that require the same reachability analysis, such as finding references to a predicate, finding unreachable code, etc.
For example, the following determins the call graph of the loaded
program. By using
source(true), The exact location of the call in the
source file is passed into _Where.
:- dynamic calls/2. assert_call_graph :- retractall(calls(_, _)), prolog_walk_code([ trace_reference(_), on_trace(assert_edge), source(false) ]), predicate_property(calls(_,_), number_of_clauses(N)), format('Got ~D edges~n', [N]). assert_edge(Callee, Caller, _Where) :- calls(Caller, Callee), !. assert_edge(Callee, Caller, _Where) :- assertz(calls(Caller, Callee)).
source(false)and then process only interesting clauses with source information.
true(default), analysis is only restarted if the inferred meta-predicate contains a callable argument. If
all, it will be restarted until no more new meta-predicates can be found.
true), do not analyse the arguments of meta predicates. Standard Prolog control structures are always analysed.
trace_reference. Called as
call(Cond, Callee, Context), where Context is a dict containing the following keys:
File:Linerepresenting the location of the declaration.
trace_referenceis found, call
call(OnEdge, Callee, Caller, Location), where Location is a dict containing a subset of the keys
line_position. If full position information is available all keys are present. If the clause layout is unknown the only the
line_countare available and the line is the start line of the clause. For a dynamic clause, only the
clauseis present. If the position is associated to a directive, the
clauseis missing. If nothing is known the Location is an empty dict.
on_edge, but location is not translated and is one of these:
file(+File, +Line, -1, _)
Caller is the qualified head of the calling clause or the atom '<initialization>'.
true), to not try to obtain detailed source information for printed messages.
false), report derived meta-predicates and iterations.
@compat OnTrace was called using Caller-Location in older versions.