bool Type::isUltimatelyNull() const { AssertNR(m_top); TypeConcept* t = m_top; while (t->isKind<ModifyingType>()) t = t->asKind<ModifyingType>()->original(); return t->isPlaceholder(); }
Type& Type::operator=(Type const& _t) { AssertNR(m_top); if (m_top == _t.m_top) return *this; TypeConcept* buf = _t.m_top->clone(this); m_top->killAndDelete(); m_top = buf; return *this; }
Types SimpleBinaryOperation::allowedTypes(int _index) const { if (_index == FirstOperand || _index == SecondOperand) { if (!m_symbolCache) return Types(); // mDebug() << prototypeOf(FirstOperand)->code() << prototypeOf(SecondOperand)->code() << " " << _index << " " << typeOf(FirstOperand)->code(); if (_index == SecondOperand && prototypeOf(SecondOperand).isUltimatelyNull() && !typeOf(FirstOperand).isNull()) return typeOf(FirstOperand).strippedTo(prototypeOf(SecondOperand)); if (_index == SecondOperand && prototypeOf(SecondOperand).isUltimatelyNull()) return Types(); AssertNR(!prototypeOf(_index).isNull()); return prototypeOf(_index); } return Super::allowedTypes(_index); }
/** * Usage: full.strippedTo(empty) * empty must be ultimately null. * * Will identify empty (ignoring Type()) with some portion in centre of full. * Everything between root and this portion will replace the Type() at root of empty. * * e.g. * <<int const*&>>.strippedTo(<<?*>>) == <<int const*>> * <<int*&>>.strippedTo(<<? const*>>) == <<?>> */ Type Type::strippedTo(Type const& _t) const { AssertNR(_t.isUltimatelyNull()); Type ret = *this; while (ret.m_top) { ModifyingType* j = _t.m_top->tryKind<ModifyingType>(); for (ModifyingType* i = ret.m_top->tryKind<ModifyingType>(); i && j; i = i->original()->tryKind<ModifyingType>(), j = j->original()->tryKind<ModifyingType>()) if (i->kind() != j->kind()) goto BAD; if (!j) break; BAD: if (ret.m_top->isKind<ModifyingType>()) ret.m_top->asKind<ModifyingType>()->unknit(); else return Type(); } return ret; }
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; }