示例#1
0
CValue* COperator2Expr::Calculate()
/*
pre:
ret: a new object containing the result of applying operator m_op to m_lhs
and m_rhs
*/
{

	bool leftmodified,rightmodified;
	leftmodified = m_lhs->NeedsRecalculated();
	rightmodified = m_rhs->NeedsRecalculated();

	// if no modifications on both left and right subtree, and result is already calculated
	// then just return cached result...
	if (!leftmodified && !rightmodified && (m_cached_calculate))
	{
		// not modified, just return m_cached_calculate
	} else {
		// if not yet calculated, or modified...


		if (m_cached_calculate) {
			m_cached_calculate->Release();
			m_cached_calculate=NULL;
		}

		CValue* ffleft = m_lhs->Calculate();
		CValue* ffright = m_rhs->Calculate();

		ffleft->SetOwnerExpression(this);//->m_pOwnerExpression=this;
		ffright->SetOwnerExpression(this);//->m_pOwnerExpression=this;

		m_cached_calculate = ffleft->Calc(m_op,ffright);

		//if (m_cached_calculate)
		//	m_cached_calculate->Action(CValue::SETOWNEREXPR,&CVoidValue(this,false,CValue::STACKVALUE));

		ffleft->Release();
		ffright->Release();
	}

	return m_cached_calculate->AddRef();

}