.NAME Parameters of function like macro

.DESCRIPTION
In the definition of a function-like macro, each instance 
of a parameter shall be enclosed in parentheses, unless 
it is used as the operand of # or ##. 

.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} {
  # Look for an define nodes
  utilities::filterTree $tree [list [namespace current]::check]
}

proc check { node } {
	if { [::utilities::isTreeOperator $node pp_define] } {
		set parameters [::logiscope::treeDown $node 1]
		if { "$parameters" != "none" } {
			set lparam {}
			::logiscope::forobj par $parameters treeChild {
				lappend lparam [::utilities::treeAtomString $par]
			}
			set content ""
			set pp_text [::logiscope::treeDown $node 2]
			::logiscope::forobj line $pp_text treeChild {
				append content [::utilities::treeAtomString $line]
			}
			# Rewrite $content to eliminate "id ## id"
			# and "# id"
			regsub -all -- {\w*\s*##\s*\w*} $content {+} content
			regsub -all -- {(\A|[^#])#\s*\w+} $content {+} content
			# Rewrite $content to eliminate "(id)"
			regsub -all -- {\(\s*\w+\s*\)} $content {+} content
			foreach par $lparam {
				# Searching usage of param without parenthesis
				# (only usage that is left in $content)
				regsub -all -- {\W} $par {\\&} par
				if {[regexp -- \\y$par\\y $content]} {
					::logiscope::addViolation $node
				}
			}
		}
	}
	return 1
}
