void TypeConstraint::init() { if (m_typeName == nullptr || isTypeVar() || isTypeConstant()) { m_type = Type::Mixed; return; } TRACE(5, "TypeConstraint: this %p type %s, nullable %d\n", this, m_typeName->data(), isNullable()); auto const mptr = nameToAnnotType(m_typeName); if (mptr) { m_type = *mptr; assert(getAnnotDataType(m_type) != KindOfPersistentString); return; } TRACE(5, "TypeConstraint: this %p no such type %s, treating as object\n", this, m_typeName->data()); m_type = Type::Object; m_namedEntity = NamedEntity::get(m_typeName); TRACE(5, "TypeConstraint: NamedEntity: %p\n", m_namedEntity.get()); }
MaybeDataType TypeConstraint::underlyingDataTypeResolved() const { assert(!isSelf() && !isParent() && !isCallable()); assert(IMPLIES( !hasConstraint() || isTypeVar() || isTypeConstant(), isMixed())); if (!isPrecise()) return folly::none; auto t = underlyingDataType(); assert(t); // If we aren't a class or type alias, nothing special to do. if (!isObject()) return t; assert(t == KindOfObject); auto p = getTypeAliasOrClassWithAutoload(m_namedEntity, m_typeName); auto td = p.first; auto c = p.second; // See if this is a type alias. if (td) { if (td->type != Type::Object) { t = (getAnnotMetaType(td->type) != MetaType::Precise) ? folly::none : MaybeDataType(getAnnotDataType(td->type)); } else { c = td->klass; } } // If the underlying type is a class, see if it is an enum and get that. if (c && isEnum(c)) { t = c->enumBaseTy(); } return t; }
MaybeDataType nameToMaybeDataType(const std::string& typeName) { auto const* type = nameToAnnotType(typeName); return type ? MaybeDataType(getAnnotDataType(*type)) : folly::none; }