.NAME Comma operator

.DESCRIPTION
	The comma operator shall not be used. 

.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
  # Look for comma operator definitions
  utilities::filterTree $tree [list [namespace current]::check]
}

proc check { node } {
  set curOperator [::logiscope::treeOperator $node]
  set curOperatorName [::logiscope::opName $curOperator]

  # Look a expression with parentheses
  if {[string equal $curOperatorName parenth_expr]} {
    # Check that it only has one child
    if {[expr {[::logiscope::treeLength $node] == 1}]} {
	  set exprNode [::logiscope::treeDown $node 0]
	  set exprOperator [::logiscope::treeOperator $exprNode]
	  set exprOperatorName [::logiscope::opName $exprOperator]
	  # Check that this child is an expr
	  if {[string equal $exprOperatorName expr]} {
		# Check that the expr has only two parameters
		if {[expr {[::logiscope::treeLength $exprNode] == 2}]} {
   	      ::logiscope::addViolation $node
	      return 0
		}
	  }
	}
  }

  return 1
}
