|
| |
| Navigation |
Synopsis Compute use-def information for the variables in a Pico program.
Examples The definitions of a variable are the source code locations where a variable gets a value.
The uses of a variable are the location where the value of that variable is used.
Both concepts are relevant for program analysis and are defined here.
module demo::lang::Pico::UseDef
import Prelude;
import demo::lang::Pico::Abstract;
import demo::lang::Pico::ControlFlow;
set[Occurrence] usesExp(EXP e, STATEMENT s) =
u:id(PicoId Id) := e ? {< u@location, Id, s>}
: {< u@location, Id, s> | /u:id(PicoId Id) <- e };
set[Occurrence] usesStat(s:asgStat(PicoId Id, EXP e)) = usesExp(e, s);
set[Occurrence] usesStat(s: ifElseStat(EXP e,
list[STATEMENT] s1,
list[STATEMENT] s2)) =
usesExp(e, s) + usesStats(s1) + usesStats(s2);
set[Occurrence] usesStat(s: whileStat(EXP e,
list[STATEMENT] s1)) =
usesExp(e, s) + usesStats(s1);
set[Occurrence] usesStats(list[STATEMENT] stats) =
{*usesStat(s) | s <- stats};
public set[Occurrence] uses(PROGRAM p) = usesStats(p.stats);
public set[Occurrence] defs(PROGRAM p) =
{ < stat@location, v, stat > | /stat:asgStat(PicoId v, EXP e) <- p.stats};
Recall that Occurrence was introduced in Pico/Abstract; it is a parameterized container to associate
program entities with their location.
The function uses ( ) has a Pico program as argument and returns a set of occurrences (uses) of Pico identifiers:
defs ( ) has a Pico program as argument and returns a set of occurrences (definitions) of Pico identifiers.
The definition consists of a single set comprehension that consists of the following parts:
|