.NAME Switch label

.DESCRIPTION
A switch-label shall only be used when the most closely- 
enclosing compound statement is the body of a switch 
statement. 

.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 } {
  # Look for a case or a default
  set curOperator [::logiscope::treeOperator $node]
  set curOperatorName [::logiscope::opName $curOperator]
  if { [expr [lsearch "case default" $curOperatorName] != -1]} {
    # Check that the case/default is indeed at the right level
	# It must be a direct child of a switch>stmts>compound>stmts node
	set correctCase 0
	set f1 [::logiscope::treeUp $node]
	if {[::utilities::isTreeOperator $f1 stmts]} {
	  set f2 [::logiscope::treeUp $f1]
		if {[::utilities::isTreeOperator $f2 compound]} {
		  set f3 [::logiscope::treeUp $f2]
			if {[::utilities::isTreeOperator $f3 stmts]} {
			  set f4 [::logiscope::treeUp $f3]
				if {[::utilities::isTreeOperator $f4 switch]} {
				  set correctCase 1
				}
			}
		}
	}
	
	if {[expr $correctCase == 0]} {
	  ::logiscope::addViolation [::logiscope::treeUp $node]
	  return 0
	}
  }
return 1
}
