The visitor that determine flowcontext for nodes

Introduced properties

private var _first: nullable ANode

nitc :: FlowVisitor :: _first

private var _flows: Array[FlowContext]

nitc :: FlowVisitor :: _flows

private fun current_flow_context=(current_flow_context: FlowContext)

nitc :: FlowVisitor :: current_flow_context=

init defaultinit(toolcontext: ToolContext)

nitc :: FlowVisitor :: defaultinit

private fun first: nullable ANode

nitc :: FlowVisitor :: first

private fun first=(first: nullable ANode)

nitc :: FlowVisitor :: first=

private fun flows: Array[FlowContext]

nitc :: FlowVisitor :: flows

private fun flows=(flows: Array[FlowContext])

nitc :: FlowVisitor :: flows=

private fun merge_breaks(escapemark: nullable EscapeMark)

nitc :: FlowVisitor :: merge_breaks

private fun merge_continues_to(before_loop: FlowContext, escapemark: nullable EscapeMark)

nitc :: FlowVisitor :: merge_continues_to

private fun printflow

nitc :: FlowVisitor :: printflow

private fun toolcontext=(toolcontext: ToolContext)

nitc :: FlowVisitor :: toolcontext=

private fun visit_expr(node: AExpr): FlowContext

nitc :: FlowVisitor :: visit_expr

Redefined properties

redef type SELF: FlowVisitor

nitc $ FlowVisitor :: SELF

Type of this instance, automatically specialized in every class
redef init init

nitc $ FlowVisitor :: init

redef fun visit(node: ANode)

nitc $ FlowVisitor :: visit

What the visitor do when a node is visited

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
private var _current_node: nullable ANode

nitc :: Visitor :: _current_node

The current visited node
private var _first: nullable ANode

nitc :: FlowVisitor :: _first

private var _flows: Array[FlowContext]

nitc :: FlowVisitor :: _flows

protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
private fun current_flow_context=(current_flow_context: FlowContext)

nitc :: FlowVisitor :: current_flow_context=

fun current_node: nullable ANode

nitc :: Visitor :: current_node

The current visited node
fun current_node=(current_node: nullable ANode)

nitc :: Visitor :: current_node=

The current visited node
init defaultinit(toolcontext: ToolContext)

nitc :: FlowVisitor :: defaultinit

fun enter_visit(e: nullable ANode)

nitc :: Visitor :: enter_visit

Ask the visitor to visit a given node.
private fun first: nullable ANode

nitc :: FlowVisitor :: first

private fun first=(first: nullable ANode)

nitc :: FlowVisitor :: first=

private fun flows: Array[FlowContext]

nitc :: FlowVisitor :: flows

private fun flows=(flows: Array[FlowContext])

nitc :: FlowVisitor :: flows=

fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
private fun merge_breaks(escapemark: nullable EscapeMark)

nitc :: FlowVisitor :: merge_breaks

private fun merge_continues_to(before_loop: FlowContext, escapemark: nullable EscapeMark)

nitc :: FlowVisitor :: merge_continues_to

private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
private fun printflow

nitc :: FlowVisitor :: printflow

fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
private fun toolcontext=(toolcontext: ToolContext)

nitc :: FlowVisitor :: toolcontext=

protected abstract fun visit(e: ANode)

nitc :: Visitor :: visit

What the visitor do when a node is visited
private fun visit_expr(node: AExpr): FlowContext

nitc :: FlowVisitor :: visit_expr

package_diagram nitc::flow::FlowVisitor FlowVisitor nitc::Visitor Visitor nitc::flow::FlowVisitor->nitc::Visitor core::Object Object nitc::Visitor->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

abstract class Visitor

nitc :: Visitor

Abstract standard visitor on the AST

Class definitions

nitc $ FlowVisitor
# The visitor that determine flowcontext for nodes
private class FlowVisitor
	super Visitor

	var current_flow_context = new FlowContext

	var toolcontext: ToolContext

	init
	do
		flows.add(current_flow_context)
		current_flow_context.is_start = true
	end

	var first: nullable ANode = null

	redef fun visit(node)
	do
		if first == null then first = node

		if current_flow_context.node == null then current_flow_context.node = node
		node.accept_flow_visitor(self)
		if node isa AExpr then
			var flow = self.current_flow_context
			node.after_flow_context = flow
			# Force the creation of a specific merge after the analysis of the node.
			if flow.when_true != flow or flow.when_false != flow then
				self.make_sub_flow
				self.current_flow_context.name = "AUTOSUB"
			end
		end

		if first == node then
			#self.printflow
		end
	end

	fun visit_expr(node: AExpr): FlowContext
	do
		self.enter_visit(node)
		return node.after_flow_context.as(not null)
	end

	var flows = new Array[FlowContext]

	fun printflow
	do
		var file = new FileWriter.open("flow.dot")
		file.write("digraph \{\nnode[shape=box];")
		for f in flows do
			var s = ""
			if f.node isa AExpr then
				s = "\\nmain={f.node.as(AExpr).after_flow_context.object_id}"
			end
			file.write "F{f.object_id} [label=\"{f.object_id}\\n{f.node.location}\\n{f.node.class_name}\\n{f.name}{s}\"];\n"
			for p in f.previous do
				s = ""
				if f.when_true == p then s = "[label=TRUE, style=dotted]"
				if f.when_false == p then s = "[label=FALSE, style=dotted]"
				if f.when_true == p and f.when_false == p then s = "[label=TRUE_FALSE, style=dotted]"
				file.write "F{p.object_id} -> F{f.object_id}{s};\n"
			end
			for p in f.loops do
				file.write "F{p.object_id} -> F{f.object_id}[label=LOOP, style=dashed, constraint=false];\n"
			end
		end
		file.write("\}\n")
		file.close
	end


	fun make_sub_flow: FlowContext
	do
		var flow = new FlowContext
		flows.add(flow)
		flow.node = current_node
		flow.add_previous(self.current_flow_context)
		self.current_flow_context = flow
		return flow
	end

	fun make_merge_flow(flow1, flow2: FlowContext): FlowContext
	do
		var flow = new FlowContext
		flows.add(flow)
		flow.node = current_node
		flow.add_previous(flow1)
		flow.add_previous(flow2)
		self.current_flow_context = flow
		return flow
	end

	fun make_true_false_flow(true_flow, false_flow: FlowContext): FlowContext
	do
		var flow = new FlowContext
		flows.add(flow)
		flow.node = current_node
		flow.add_previous(true_flow)
		flow.add_previous(false_flow)
		flow.when_true = true_flow
		flow.when_false = false_flow
		self.current_flow_context = flow
		return flow
	end

	fun make_sub_true_false_flow: FlowContext
	do
		var orig_flow = self.current_flow_context
		var true_flow = new FlowContext
		flows.add(true_flow)
		true_flow.node = current_node
		true_flow.add_previous(orig_flow)
		true_flow.name = "TRUE"
		var false_flow = new FlowContext
		flows.add(false_flow)
		false_flow.node = current_node
		false_flow.add_previous(orig_flow)
		false_flow.name = "FALSE"
		return make_true_false_flow(true_flow, false_flow)
	end

	fun make_unreachable_flow: FlowContext
	do
		var flow = new FlowContext
		flows.add(flow)
		flow.node = current_node
		flow.add_previous(self.current_flow_context)
		flow.is_marked_unreachable = true
		self.current_flow_context = flow
		return flow
	end

	fun merge_continues_to(before_loop: FlowContext, escapemark: nullable EscapeMark)
	do
		if escapemark == null then return
		for b in escapemark.escapes do
			var before = b.before_flow_context
			if before == null then continue # Forward error
			before_loop.add_loop(before)
		end
	end

	fun merge_breaks(escapemark: nullable EscapeMark)
	do
		if escapemark == null then return
		for b in escapemark.escapes do
			var before = b.before_flow_context
			if before == null then continue # Forward error
			self.make_merge_flow(self.current_flow_context, before)
		end
	end
end
src/semantize/flow.nit:33,1--184,3