コード例 #1
0
bool SimpleUnaryOperation::keyPressedOnPosition(Position const& _p, KeyEvent const* _e)
{
	if (!_p.exists())
		return false;

	bool pre;
	if (!Operator(_e->text(), Operator::UnaryPrefix).isNull() && (_p->isPlaceholder()/* || _e->isInserting()*/))
		pre = true;
	else if (!Operator(_e->text(), Operator::UnaryPostfix).isNull() && (!Operator(_e->text(), Operator::UnaryPrefix).isNull() || !_p->isPlaceholder()))
		pre = false;
	else
		return false;

	Operator o(_e->text(), pre ? Operator::UnaryPrefix : Operator::UnaryPostfix);
	Position p = slideOnPrecedence(_p, o.precedence(), o.associativity(), _e->nearestBracket(_p));
	bool b = findOperators(o, p->isKind<Typed>() ? p->asKind<Typed>()->apparentType() : Type()).size();
	if (b && !isTemporary(p.concept()))
	{
		SimpleUnaryOperation* n = new SimpleUnaryOperation(o, p->isKind<Typed>() ? p->asKind<Typed>()->apparentType() : Type());
		_e->noteStrobeCreation(n, &*p);
		p->insert(n, TheOperand);
		n->validifyChildren();
		_e->codeScene()->dropCursor(n);
		return true;
	}
	return false;
}
コード例 #2
0
bool SimpleBinaryOperation::keyPressedOnPosition(Position const& _p, KeyEvent const* _e)
{
	Operator o(_e->text(), Operator::Binary);
	if (!_p.exists() || _p->isPlaceholder() || o.isNull())
		return false;

	Position p = slideOnPrecedence(_p, o.precedence(), o.associativity(), _e->nearestBracket(_p));
	AssertNR(!p.concept()->isEditing());

	// Try condition for p, then _p if p fails, then bail if _p fails. p is the one that succeeded first.
	for (; !(p->isKind<Typed>() && findOperators(o, p->asKind<Typed>()->apparentType()).size()); p = _p)
		if (p == _p)
			return false;

	SimpleBinaryOperation* n = new SimpleBinaryOperation(o, p->asKind<Typed>()->apparentType());
	_e->noteStrobeCreation(n, &*p);
	p->insert(n, FirstOperand);
	n->validifyChildren();
	_e->codeScene()->dropCursor(n);
	return true;
}