.NAME Accessible entities in multiple inheritance hierarchy

.DESCRIPTION
	All accessible entity names within a multiple 
inheritance hierarchy should be unique. 

.COMMENT V7.0

.SEVERITY Advisory

.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]]} {
		checkClasses
	}	
}

proc checkClasses {} {
	foreach curClass [::Scopes::getAllScopes CLASS] {
		set classAncestors [::Semantic::getAttribute $curClass ancestors]
		if {[expr [llength $classAncestors] > 1]} {
			foreach curUpClass $classAncestors {
				set curClass [lindex $curUpClass 1]
				checkEntity functions $curClass $classAncestors
				checkEntity variables $curClass $classAncestors				
			}
		}
	}
}

proc checkEntity {entityName curClass classAncestors} {
	foreach curFunc [::Semantic::getAttribute $curClass $entityName] {
		set curFuncName [::Semantic::getAttribute $curFunc name]
		foreach comparedClass $classAncestors {
			set curComparedClass [lindex $comparedClass 1]
			if {[expr $curClass != $curComparedClass]} {
				set foundDuplicateFunc [::Scopes::getWithName $curComparedClass $entityName $curFuncName -1] 
				if {[expr $foundDuplicateFunc != -1]} {
					::Semantic::violation $foundDuplicateFunc "MISRA_Rule10-2-1" "MISRA_Rule10-2-1 - All accessible entity names within a multiple inheritance hierarchy should be unique."
				}
			}
		}
	}
}
