.NAME Length of bit-field

.DESCRIPTION
	Named bit-fields with signed integer type shall have a 
length of more than one bit. 

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

proc check { node } {
	variable allReservedIds
	if {[::utilities::isTreeOperator $node bit_field]} {
		set declarator [::logiscope::treeGetSon $node DECLARATOR_OPT]
		set expression [::logiscope::treeGetSon $node SIMPLE_EXPR]
		set declaratorName [::utilities::getName $declarator]
		set expressionName [::utilities::getName $expression]

		set identifier [::logiscope::treeGetSon $node DECLARATOR_OPT]
		set BFType [::Semantic::getTypeOf $identifier]
		set isSigned 0
		if  {[expr $BFType != -1]} {
			set BFRealType [::Semantic::getAttribute $BFType type]
			set BFRealTypeName [::Semantic::getAttribute $BFRealType name]
			if {[regexp {^signed} $BFRealTypeName]} {
				set isSigned 1
			}
		}
			
		scan $expressionName %d expressionValue
		if {![string equal $declaratorName none] && [expr $expressionValue <= 1] && [expr $isSigned == 1]} {
			::logiscope::addViolation $expression
		}
	}
	return 1
}