.NAME Default arguments for overrided function

.DESCRIPTION
Parameters in an overriding virtual function shall 
either use the same default arguments as the function 
they override, or else shall not specify any default 
arguments. 

.COMMENT V7.0

.SEVERITY Required

.COMMENT
Please refer to the MISRA C++:2008 document for further details (www.misra-cpp.com)

.COMMAND tcl

.REQUIRED cpp_semantic

.CODE

::logiscope::include -once common utilities.tcl

proc compute {standardName tree} {
  variable CurrentParameterList
  variable stdn $standardName
  set stdn 
  # Check all class nodes
  utilities::filterTree $tree [list [namespace current]::check]
}

proc check { node } {
	if { [::utilities::isTreeOperator $node class] } {
		set scope [::Semantic::getScopeOfNode $node]
		if { [::Scopes::isScopeKind $scope CLASS] && "[::Semantic::getAttribute $scope classKind]" == "class_kw" } {
			set ancestors [::Semantic::getAttribute $scope ancestors]
			set functions [::Semantic::getAttribute $scope functions]
			if { [llength $ancestors] > 0  && [llength $functions] > 0} {
				# at least one ancestor and one method ; check methods
				foreach f1 $functions {
					foreach sco $ancestors {
						checkFunction $f1 [lindex $sco 1]
					}
				}
			}
		}
	}
	return 1
}

proc checkFunction { func scope } {
	variable stdn
	foreach f2 [::Semantic::getAttribute $scope functions] {
		if { [::Scopes::areSameFunctions $func $f2] } {
			# overloaded function ; checking default values of parameters
			set param1 [::Semantic::getAttribute $func variables]
			set param2 [::Semantic::getAttribute $f2 variables]
			set i 0
			foreach par1 $param1 {
				set def1 [::Semantic::getAttribute $par1 defaultValue]
				if { "$def1" != "" } {
					set par2 [lindex $param2 $i]
					set def2 [::Semantic::getAttribute $par2 defaultValue]
					if { "$def1" != "$def2" } {
						::Semantic::violation $par1 $stdn "Not same default value for parameter [::Semantic::getAttribute $par1 name] of overloaded function"
					}
				}
				incr i
			}
		}
	}
	foreach ancestor [::Semantic::getAttribute $scope ancestors] {
		if {[lindex $ancestor 1] ne $scope} {
			checkFunction $func [lindex $ancestor 1]
		}	
	}
}
