.NAME increment and decrement operators

.DESCRIPTION
	The increment (++) and decrement (--) operators 
should not be mixed with other operators in an 
expression. 

.COMMENT V7.0

.SEVERITY Advisory

.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 incrDecr [list pre_incr post_incr pre_decr post_decr]
	# Look for ++ and -- operators
	if {[expr [lsearch $incrDecr [::utilities::getName $node]] != -1]} {
		# Check if an ancestor is an arithmetic operator
		if {[expr [hasArithmeticAncestor $node] == 1]} {
			::logiscope::addViolation $node
		}
	}
return 1
}

# This procedure checks if any ancestor of the current node is an arithmetic operator
proc hasArithmeticAncestor {node} {
	set arithmetic [list plus minus mul div rem]
	if {[expr [lsearch $arithmetic [::utilities::getName $node]] != -1]} {
		return 1
	}
	if {[expr [::logiscope::treeRank $node] != -1]} {
		return [hasArithmeticAncestor  [::logiscope::treeUp $node]]
	}
	return 0
}
