.NAME Overriding a virtual function

.DESCRIPTION
	A virtual function shall only be overridden by a pure 
virtual function if it is itself declared as pure virtual. 

.COMMENT V7.0

.SEVERITY Required

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

.REQUIRED cpp_semantic

.COMMAND tcl

.CODE

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

proc compute {standardName tree} {
	if {[string equal [::logiscope::fileName] [::logiscope::firstFile]]} {
		checkFunctions
	}
}


proc checkFunctions {} {
	foreach curScope [::Scopes::getAllScopes] {
		foreach curFunc [::Semantic::getAttribute $curScope functions] {
			set funcName [::Semantic::getAttribute $curFunc name]
			if {[::Semantic::exists $curFunc class]} {
				set funcClass [::Semantic::getAttribute $curFunc class]
				set funcClassName [::Semantic::getAttribute $funcClass name]
				set funcClassAncestors [::Semantic::getAttribute $funcClass ancestors]
				set pureVirtual 0
				if { [::Semantic::exists $curFunc pureVirtual] } {
					set pureVirtual 1
				}
				set allAncestorsVirtual 1
				foreach curAncestor $funcClassAncestors {
					set curClass [lindex $curAncestor 1]
					set ancestorFunc [::Scopes::getWithName $curClass functions $funcName -1]
					if {[expr $ancestorFunc != -1]} {
						set isAncestorVirtual [::Semantic::exists $ancestorFunc pureVirtual]
						set allAncestorsVirtual [expr $allAncestorsVirtual && $isAncestorVirtual]
					}
				}
				
				if {[expr [expr $pureVirtual == 1] && [expr $allAncestorsVirtual == 0]]} {
					::Semantic::violation $curFunc "MISRA_Rule10-3-3" "MISRA_Rule10-3-3 - A virtual function shall only be overridden by a pure virtual function if it is itself declared as pure virtual."
				}
			}
		}
	}
}

proc check { node } {
	return 1
}
