.NAME Exit with a label

.DESCRIPTION
An exit must be followed by a label

.SEVERITY Advisory

.COMMAND tcl

.CODE

proc compute {standardName tree} {
	
	set formalism [::logiscope::treeFormalism $tree]

	set opList {}
	::logiscope::forobj op $formalism formalismOperator {
		lappend opList [::logiscope::opName $op]
	}
	# find the operators in the tree that are exit operators
	# without a label (void operator as a first son of the exit operator)
	filterTree $tree [list opNamesAre exit_statement void]
}

#------------------------------------------------------------------
# opNamesAre adds a violation if the tree operator is opName 
# and the first son of tree has the operator sonOpName
#------------------------------------------------------------------
proc opNamesAre {opName sonOpName tree} {
	set op [::logiscope::treeOperator $tree]
	if {[string equal [::logiscope::opName $op] $opName]} {
		return [checkFirstSon $tree $sonOpName]
	}
	return 1
}

#------------------------------------------------------------------
# opNameIs adds a rule violation if the operator of tree is opName
#------------------------------------------------------------------
proc opNameIs {opName tree} {
	set op [::logiscope::treeOperator $tree]
	if {[string equal [::logiscope::opName $op] $opName]} {
		# the operator has been identified: add a violation
		::logiscope::addViolation $tree
		return 0
	}
	return 1
}


#------------------------------------------------------------------
# checkFirstSon gets the first son of tree and calls 
# opNameIs to check for violations on the son
#------------------------------------------------------------------
proc checkFirstSon {tree opName} {
	set son [logiscope::treeDown $tree 0]
	return [opNameIs $opName $son]
}

#------------------------------------------------------------------
# filterTree applies callback to tree, and recurs on tree's sons
#------------------------------------------------------------------
proc filterTree {tree callback} {
	if {[eval $callback [list $tree]]} {
		::logiscope::forobj son $tree treeChild {
			filterTree $son $callback
    		}
	}
}

