.NAME At least one case in switch

.DESCRIPTION
Every switch statement shall have at least one case-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 ... nodes
  utilities::filterTree $tree [list [namespace current]::check]
}

proc check { node } {
  set curOperator [::logiscope::treeOperator $node]
  set curOperatorName [::logiscope::opName $curOperator]
  # Look for a switch
  if {[string equal $curOperatorName switch]} {
    # Check if the switch has at least one case
	# To reach the switch statements, we need to explore the tree three levels down
	set switchNodes [::logiscope::treeDown [::logiscope::treeDown [::logiscope::treeDown $node 1] 0] 0]
	# Count the number of statements in the switch
	set nbCases 0
	# If there are statements, count the number of "case" statements
	::logiscope::forobj son $switchNodes treeChild {
		set operatorValue [::utilities::getName $son]
		if {[string equal $operatorValue case]} {
		  incr nbCases
		}
	}

	# The rule is violated is there are no "case" statements in the switch
	if {[expr $nbCases == 0]} {
	  ::logiscope::addViolation $node
	  return 0
	}
  }
  return 1;
}
