Introduced classes

class ReachingDefsAnalysis

nitc :: ReachingDefsAnalysis

Determines wich variables definitions reach each statement.
class VarDef

nitc :: VarDef

A Variable definition.

Redefined classes

redef class AForExpr

nitc :: reaching_defs $ AForExpr

A for statement
redef abstract class ANode

nitc :: reaching_defs $ ANode

Root of the AST class-hierarchy
redef class AVarAssignExpr

nitc :: reaching_defs $ AVarAssignExpr

A local variable simple assignment access
redef class AVarReassignExpr

nitc :: reaching_defs $ AVarReassignExpr

A local variable complex assignment access
redef class AVardeclExpr

nitc :: reaching_defs $ AVardeclExpr

A declaration of a local variable. eg var x: X = y

All class definitions

redef class AForExpr

nitc :: reaching_defs $ AForExpr

A for statement
redef abstract class ANode

nitc :: reaching_defs $ ANode

Root of the AST class-hierarchy
redef class AVarAssignExpr

nitc :: reaching_defs $ AVarAssignExpr

A local variable simple assignment access
redef class AVarReassignExpr

nitc :: reaching_defs $ AVarReassignExpr

A local variable complex assignment access
redef class AVardeclExpr

nitc :: reaching_defs $ AVardeclExpr

A declaration of a local variable. eg var x: X = y
class ReachingDefsAnalysis

nitc $ ReachingDefsAnalysis

Determines wich variables definitions reach each statement.
class VarDef

nitc $ VarDef

A Variable definition.
package_diagram nitc::reaching_defs reaching_defs nitc::saf_base saf_base nitc::reaching_defs->nitc::saf_base nitc::scope scope nitc::reaching_defs->nitc::scope nitc::modelbuilder modelbuilder nitc::saf_base->nitc::modelbuilder nitc::scope->nitc::modelbuilder ...nitc::modelbuilder ... ...nitc::modelbuilder->nitc::modelbuilder nitc::saf saf nitc::saf->nitc::reaching_defs nitc::nitsaf nitsaf nitc::nitsaf->nitc::saf nitc::nitsaf... ... nitc::nitsaf...->nitc::nitsaf

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module array

core :: array

This module introduces the standard array structure.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module caching

serialization :: caching

Services for caching serialization engines
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module console

console :: console

Defines some ANSI Terminal Control Escape Sequences.
module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
module digraph

graph :: digraph

Implementation of directed graphs, also called digraphs.
module engine_tools

serialization :: engine_tools

Advanced services for serialization engines
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module ini

ini :: ini

Read and write INI configuration files
module inspect

serialization :: inspect

Refine Serializable::inspect to show more useful information
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module lexer

nitc :: lexer

Lexer and its tokens.
module lexer_work

nitc :: lexer_work

Internal algorithm and data structures for the Nit lexer
module list

core :: list

This module handle double linked lists
module loader

nitc :: loader

Loading of Nit source files
module location

nitc :: location

Nit source-file and locations in source-file
module math

core :: math

Mathematical operations
module mdoc

nitc :: mdoc

Documentation of model entities
module meta

meta :: meta

Simple user-defined meta-level to manipulate types of instances as object.
module mmodule

nitc :: mmodule

modules and module hierarchies in the metamodel
module model

nitc :: model

Classes, types and properties
module model_base

nitc :: model_base

The abstract concept of model and related common things
module modelbuilder_base

nitc :: modelbuilder_base

Load nit source files and build the associated model
module more_collections

more_collections :: more_collections

Highly specific, but useful, collections-related classes.
module mpackage

nitc :: mpackage

Modelisation of a Nit package
module native

core :: native

Native structures for text and bytes
module nitpm_shared

nitc :: nitpm_shared

Services related to the Nit package manager
module numeric

core :: numeric

Advanced services for Numeric types
module opts

opts :: opts

Management of options on the command line
module ordered_tree

ordered_tree :: ordered_tree

Manipulation and presentation of ordered trees.
module parser

nitc :: parser

Parser.
module parser_nodes

nitc :: parser_nodes

AST nodes of the Nit language
module parser_prod

nitc :: parser_prod

Production AST nodes full definition.
module parser_work

nitc :: parser_work

Internal algorithm and data structures for the Nit parser
module phase

nitc :: phase

Phases of the processing of nit programs
module poset

poset :: poset

Pre order sets and partial order set (ie hierarchies)
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module serialization

serialization :: serialization

General serialization services
module serialization_core

serialization :: serialization_core

Abstract services to serialize Nit objects to different formats
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module tables

nitc :: tables

Module that interfaces the parsing tables.
module template

template :: template

Basic template system
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module toolcontext

nitc :: toolcontext

Common command-line tool infrastructure than handle options and error messages
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O
module version

nitc :: version

This file was generated by git-gen-version.sh

Parents

module saf_base

nitc :: saf_base

Static Analysis Framework base
module scope

nitc :: scope

Identification and scoping of local variables and labels.

Children

module saf

nitc :: saf

Nit Static Analysis Framework.

Descendants

module a_star-m

a_star-m

module nitsaf

nitc :: nitsaf

Nit Static Analysis Framework client example.
import saf_base

import scope

# Determines wich variables definitions reach each statement.
class ReachingDefsAnalysis
	super ForwardAnalysis

	redef type FLOW: FlowHashSet[VarDef]

	# New initial flows are empty (conservative analysis).
	redef fun new_initial_flow do return new FlowHashSet[VarDef]

	# New initial flows for methods contains the parameters.
	redef fun new_initial_method_flow(n) do
		var flow = new_initial_flow
		var n_signature = n.n_signature
		if n_signature == null then return flow
		for n_param in n_signature.n_params do
			var variable = n_param.variable
			if variable == null then continue
			flow.add(new VarDef(variable, n_param.location))
		end
		return flow
	end

	# Perform set union (used for **some path** analysis).
	redef fun merge(s1, s2) do return s1.flow_union(s2)

	redef fun visit(n) do n.accept_reaching_defs(self)

	# Generate a new variable definition in the `current_outset`.
	fun gen(variable: Variable, location: Location) do
		current_outset.add(new VarDef(variable, location))
	end

	# Kill a variable definition in the `current_outset`.
	fun kill(variable: Variable) do
		for vardef in current_outset.to_a do
			if vardef.variable == variable then current_outset.remove(vardef)
		end
	end

	redef fun pretty_print do
		for node, outset in outsets do
			if outset.is_empty then continue
			var values = outset.to_a
			default_comparator.sort(values)
			print "{node.location.line_end}: {values.join(", ")} out of {node.class_name}"
		end
	end
end

redef class ANode

	# Apply a ReachingDefsAnalysis to `self`.
	fun accept_reaching_defs(v: ReachingDefsAnalysis) do accept_forward_analysis(v)
end

redef class AVardeclExpr
	redef fun accept_reaching_defs(v) do
		super
		v.kill(variable.as(not null))
		v.gen(variable.as(not null), location)
	end
end

redef class AVarAssignExpr
	redef fun accept_reaching_defs(v) do
		super
		v.kill(variable.as(not null))
		v.gen(variable.as(not null), location)
	end
end

redef class AVarReassignExpr
	redef fun accept_reaching_defs(v) do
		super
		v.kill(variable.as(not null))
		v.gen(variable.as(not null), location)
	end
end

redef class AForExpr
	redef fun accept_reaching_defs(v) do
		# add variables from `for` declaration
		for n_group in n_groups do
			var variables = n_group.variables
			if variables == null then continue
			for variable in variables do v.gen(variable, n_group.location)
		end
		super
		# remove variables from `for` declaration
		for n_group in n_groups do
			var variables = n_group.variables
			if variables == null then continue
			for variable in variables do v.kill(variable)
		end
	end
end

# A Variable definition.
#
# Associates a variable to the location of its definition.
class VarDef
	super Comparable

	redef type OTHER: VarDef

	# Variable this definition is about.
	var variable: Variable

	# Location of this definition in the source code.
	var location: Location

	redef fun ==(o) do
		return o isa OTHER and variable == o.variable and location == o.location
	end

	redef fun <=>(o) do
		if variable.name == o.variable.name then
			return location.line_start <=> o.location.line_start
		else
			return variable.name <=> o.variable.name
		end
	end

	redef fun hash do return variable.hash + location.hash
	redef fun to_s do return "\{{variable}: {location.line_start}\}"
end
src/saf/reaching_defs.nit:16,1--145,3