.NAME Empty throw

.DESCRIPTION
	An empty throw (throw;) shall only be used in the 
compound-statement of a catch handler. 

.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 throw
  if {[string equal $curOperatorName throw]} {
    # Check that there is only one child, and that it's value is "none"
	if {[expr [::logiscope::treeLength $node] == 1]} {
	  set firstChild [::logiscope::treeDown $node 0]
	  set firstChildName [::utilities::getName $firstChild]
	  if {[string equal $firstChildName none]} {
	    # Check that one of the predecessor nodes is a "catch"
		if {[expr [hasCatchAncestor $node] == 0]} {
		  ::logiscope::addViolation $node
		  return 0		
		}
	  }
	}
  }
  return 1
}

proc hasCatchAncestor {tree} {
  # Check the current tree node: is it a "catch" node?
  set curOperator [::logiscope::treeOperator $tree]
  set curOperatorName [::logiscope::opName $curOperator]
  # Look for a catch
  if {[string equal $curOperatorName try_handlers]} {
    return 1
  }
  
  # If the current node is the tree root, don't recurse upwards anymore
  # Since we reached this code without having returned 1, this means we couldn't find a catch node, and must return 0
  if ([::logiscope::treeEqual $tree [::logiscope::treeRoot $tree]]) {
    return 0
  } else {
    return [hasCatchAncestor [::logiscope::treeUp $tree]]
  }
}
