.NAME Single exit point

.DESCRIPTION 
A function shall have a single point of exit at the end of the function. 

.COMMENT V7.0

.SEVERITY Required

.COMMENT
Please refer to the MISRA C++:2008 document for further details (www.misra-cpp.com)

.COMMAND tcl

.CODE

::logiscope::include -once common utilities.tcl

proc compute {standardName tree} {
  variable CurrentParameterList
  # Check all fndef nodes
  utilities::filterTree $tree [list [namespace current]::check]
}

proc check { node } {
	if { [::utilities::isTreeOperator $node fndef] } {
		set nbRet 0
		set compound [::logiscope::treeDown $node 3]
		set stmts [::logiscope::treeDown $compound 0]
		set nb 0
		set l [::logiscope::treeLength $stmts]
		if { $l > 0 } {
			incr l -1
			set last [::logiscope::treeDown $stmts $l]
			if { ![::utilities::isTreeOperator $last return] } {
				set nb 1
			}
		}
		incr nb [howManyReturnLevel0 $compound]
		if { $nb > 1 } {
			::logiscope::addViolation $node
		}
		return 0
	}
	return 1
}

proc howManyReturnLevel0 { node } {
	if { "$node" == "NULL" } {
		return 0
	}
	switch -- [::utilities::treeOperatorName $node] {
		return {
			set nb 1
		}
		try_block {
			set nb [howManyReturnLevel0 [::logiscope::treeDown $node 0]]
			if { $nb <= 1 } {
				set try_handlers [::logiscope::treeDown $node 0]
				set nb 0
				::logiscope::forobj hand $try_handlers treeChild {
					set comp [::logiscope::treeDown $hand 1]
					set n [howManyReturnLevel0 $comp]
					if { $n > 1 } {
						incr nb 2
					}
				}
			}
		}
		default {
			set nb 0
			::logiscope::forobj stm $node treeChild {
				incr nb [howManyReturnLevel0 $stm]
			}
		}
	}
	return $nb
}
