.NAME Standard library macros and objects

.DESCRIPTION
The names of standard library macros and objects shall not be reused. 

.COMMENT V7.0

.SEVERITY Required

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

.PARAMETERS LIST "NULL" "EXIT_SUCCESS" "EXIT_FAILURE" "RAND_MAX" "__max" "__min" "_MAX_PATH" "_MAX_DRIVE" "_MAX_DIR" "_MAX_FNAME" "_MAX_EXT" "_OUT_TO_DEFAULT" "_OUT_TO_STDERR" "_OUT_TO_MSGBOX" "_REPORT_ERRMODE" "errno" "_doserrno" "__argc" "__argv" "__wargv" "_environ" "_wenviron" "_pgmptr" "_wpgmptr" "size_t" "wchar_t" "_onexit_t" "div_t" "ldiv_t" END LIST 

.COMMAND tcl

.CODE

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

proc checkNameNode { nameNode } {
	variable CurrentParameterList
	if { "$nameNode" != "NULL" } {
		set name [::utilities::getName $nameNode]
		if { [lsearch $CurrentParameterList $name] >= 0 } {
			::logiscope::addViolation $nameNode
		}
	}
}

proc compute {standardName tree} {
  variable CurrentParameterList
  set CurrentParameterList [lindex $CurrentParameterList 0]
  # parameters of the rule are names which cannot be reused for another purpose
  # Check all #define nodes
  utilities::filterTree $tree [list [namespace current]::checkMacros]
  # Check all variable and typedef nodes 
  utilities::filterTree $tree [list [namespace current]::checkDeclar]
  # Check all procedure names and parameter names
  utilities::filterTree $tree [list [namespace current]::checkProc]
  # Check all class names
  utilities::filterTree $tree [list [namespace current]::checkClass]
}

# checking macro definitions
# the reserved names cannot be used
proc checkMacros { node } {
	if { [::utilities::isTreeOperator $node pp_define] } {
		set nameNode [::logiscope::treeDown $node 0]
		checkNameNode $nameNode
	}
	return 1
}

# checking macro definitions
# the reserved names cannot be used
proc checkDeclar { node } {
	if { [::utilities::isTreeOperator $node dcltr_noinit] ||
		 [::utilities::isTreeOperator $node dcltr_affinit]} {
		set nameNode [::logiscope::treeDown $node 0]
		checkNameNode $nameNode
	}
	return 1
}

# checking procedure names
# the reserved names cannot be used
proc checkProc { node } {
	if { [::utilities::isTreeOperator $node fndef] } {
		set func_dcltr [::logiscope::treeDown $node 1]
		set nameNode [::logiscope::treeDown $func_dcltr 0]
		checkNameNode $nameNode
		set parmlist [::logiscope::treeDown $func_dcltr 1]
		if { "$parmlist" != "NULL" } {
			::logiscope::forobj par $parmlist treeChild {
				set nameNode [::logiscope::treeDown $par 1]
				if { "$nameNode" != "NULL" } {
					checkNameNode $nameNode
				}
			}
		}
	}
	return 1
}

# checking class names
# the reserved names cannot be used
proc checkClass { node } {
	if { [::utilities::isTreeOperator $node class_head] } {
		set nameNode [::logiscope::treeDown $node 1]
		checkNameNode $nameNode
	}
	return 1
}
