.NAME Else clause

.DESCRIPTION
All "if" and "else if" constructs shall be terminated with an else clause. 

.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 if nodes
  utilities::filterTree $tree [list [namespace current]::check]
}

proc check { node } {
	if { [::utilities::isTreeOperator $node if] } {
		set elsePart [::logiscope::treeDown $node 2]
		if { ![::utilities::isTreeOperator $elsePart none] } {
			set elsePart [::logiscope::treeDown $elsePart 0]
			if { "$elsePart" != "NULL" && [::utilities::isTreeOperator $elsePart if] } {
				# ok, we are in a if else if structure
				set cont 1
				while { $cont } {
					set previous $elsePart
					set elsePart [::logiscope::treeDown $elsePart 2]
					if { "$elsePart" != "NULL" } {
						if { [::utilities::isTreeOperator $elsePart none] } {
							# wrong => else needed
							::logiscope::addViolation $previous
							set cont 0
						} else {
							set elsePart [::logiscope::treeDown $elsePart 0]
							if { ![::utilities::isTreeOperator $elsePart if] } {
								set cont 0
							}
						}
					}
				}
			}
		}
	}
 return 1
}
