cloud9_root/src/third_party/stp/src/AST/NodeFactory/SimplifyingNodeFactory.cpp
// Constant children are accumulated in "accumconst".
Constant children are accumulated in "accumconst".
Constant children are accumulated in " accumconst " .
ASTNode SimplifyingNodeFactory::CreateSimpleXor(const ASTVec &children)
{
	if (debug_simplifyingNodeFactory)
	{
		cout << "========" << endl << "CreateSimpXor ";
		lpvec(children);
		cout << endl;
	}
	ASTVec flat_children; 
	flat_children = children;
	SortByExprNum(flat_children);
	bool accumconst = 0;
	ASTVec new_children;
	new_children.reserve(children.size());
	const ASTVec::const_iterator it_end = flat_children.end();
	ASTVec::iterator next_it;
	for (ASTVec::iterator it = flat_children.begin(); it != it_end; it++)
	{
		next_it = it + 1;
		bool nextexists = (next_it < it_end);
		if (ASTTrue == *it)
		{
			accumconst = !accumconst;
		}
		else if (ASTFalse == *it)
		{
		}
		else if (nextexists && (*next_it == *it))
		{
			*next_it = ASTFalse;
		}
		else if (nextexists && (next_it->GetKind() == BEEV::NOT)
				&& ((*next_it)[0] == *it))
		{
			*next_it = ASTTrue;
		}
		else if (BEEV::NOT == it->GetKind())
		{
			accumconst = !accumconst;
			new_children.push_back(CreateSimpleNot(*it));
		}
		else
		{
			new_children.push_back(*it);
		}
	}
	ASTNode retval;
	if (new_children.size() < 2)
	{
		if (0 == new_children.size())
		{
			if (accumconst)
			{
				retval = ASTTrue;
			}
			else
			{
				retval = ASTFalse;
			}
		}
		else
		{
			if (accumconst)
			{
				retval = CreateSimpleNot(new_children[0]);
			}
			else
			{
				retval = new_children[0];
			}
		}
	}
	else
	{
		if (accumconst)
		{
			new_children[0] = CreateSimpleNot(new_children[0]);
		}
		retval = hashing.CreateNode(BEEV::XOR, new_children);
	}
	if (debug_simplifyingNodeFactory)
	{
		cout << "returns " << retval << endl;
	}
	return retval;
}
ASTNode SimplifyingNodeFactory :: CreateSimpleXor ( const ASTVec & children ) { if ( debug_simplifyingNodeFactory ) { cout << " " << endl << " " ; lpvec ( children ) ; cout << endl ; } ASTVec flat_children ; flat_children = children ; SortByExprNum ( flat_children ) ; bool accumconst = 0 ; ASTVec new_children ; new_children . reserve ( children . size ( ) ) ; const ASTVec :: const_iterator it_end = flat_children . end ( ) ; ASTVec :: iterator next_it ; for ( ASTVec :: iterator it = flat_children . begin ( ) ; it != it_end ; it ++ ) { next_it = it + 1 ; bool nextexists = ( next_it < it_end ) ; if ( ASTTrue == * it ) { accumconst = ! accumconst ; } else if ( ASTFalse == * it ) { } else if ( nextexists && ( * next_it == * it ) ) { * next_it = ASTFalse ; } else if ( nextexists && ( next_it -> GetKind ( ) == BEEV :: NOT ) && ( ( * next_it ) [ 0 ] == * it ) ) { * next_it = ASTTrue ; } else if ( BEEV :: NOT == it -> GetKind ( ) ) { accumconst = ! accumconst ; new_children . push_back ( CreateSimpleNot ( * it ) ) ; } else { new_children . push_back ( * it ) ; } } ASTNode retval ; if ( new_children . size ( ) < 2 ) { if ( 0 == new_children . size ( ) ) { if ( accumconst ) { retval = ASTTrue ; } else { retval = ASTFalse ; } } else { if ( accumconst ) { retval = CreateSimpleNot ( new_children [ 0 ] ) ; } else { retval = new_children [ 0 ] ; } } } else { if ( accumconst ) { new_children [ 0 ] = CreateSimpleNot ( new_children [ 0 ] ) ; } retval = hashing . CreateNode ( BEEV :: XOR , new_children ) ; } if ( debug_simplifyingNodeFactory ) { cout << " " << retval << endl ; } return retval ; }
Constant children are accumulated in "accumconst".
Constant children are accumulated in " accumconst " .
// empty vector // sort so that identical nodes occur in sequential runs, followed by // their negations. // This is the C Boolean value of all constant args seen.  It is initially // 0.  TRUE children cause it to change value. // Ignore it // x XOR x = FALSE.  Skip current, write "false" into next_it // so that it gets tossed, too. // x XOR NOT x = TRUE.  Skip current, write "true" into next_it // so that it gets tossed, too. // If child is (NOT alpha), we can flip accumconst and use alpha. // This is ok because (NOT alpha) == TRUE XOR alpha // CreateSimpNot just takes child of not. // Children should be non-constant. // XOR(TRUE, FALSE) -- accumconst will be 1. // there is just one child // XOR(x, TRUE) -- accumconst will be 1. // negate first child if accumconst == 1