TypeStructure::Kind TypeAnnotation::getKind() const { if (isVoid()) { return TypeStructure::Kind::T_void; } // Primitive types if (isPrimType("HH\\int")) { return TypeStructure::Kind::T_int; } if (isPrimType("HH\\bool")) { return TypeStructure::Kind::T_bool; } if (isPrimType("HH\\float")) { return TypeStructure::Kind::T_float; } if (isPrimType("HH\\string")) { return TypeStructure::Kind::T_string; } if (isPrimType("HH\\resource")) { return TypeStructure::Kind::T_resource; } if (isPrimType("HH\\num")) { return TypeStructure::Kind::T_num; } if (isPrimType("HH\\arraykey")) { return TypeStructure::Kind::T_arraykey; } if (isPrimType("HH\\noreturn")) { return TypeStructure::Kind::T_noreturn; } if (isMixed()) { return TypeStructure::Kind::T_mixed; } if (m_tuple) { return TypeStructure::Kind::T_tuple; } if (m_function) { return TypeStructure::Kind::T_fun; } if (!strcasecmp(m_name.c_str(), "array")) { return (m_shape) ? TypeStructure::Kind::T_shape : TypeStructure::Kind::T_array; } if (m_typevar) { return TypeStructure::Kind::T_typevar; } if (m_typeaccess) { return TypeStructure::Kind::T_typeaccess; } if (m_xhp) { // TODO(7657500): in the runtime, resolve this type to a class. return TypeStructure::Kind::T_xhp; } return TypeStructure::Kind::T_unresolved; }
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; }
bool TypeConstraint::check(TypedValue* tv, const Func* func) const { assert(hasConstraint() && !isTypeVar() && !isMixed() && !isTypeConstant()); // This is part of the interpreter runtime; perf matters. if (tv->m_type == KindOfRef) { tv = tv->m_data.pref->tv(); } if (isNullable() && tv->m_type == KindOfNull) { return true; } if (tv->m_type == KindOfObject) { // Perfect match seems common enough to be worth skipping the hash // table lookup. const Class *c = nullptr; if (isObject()) { if (m_typeName->isame(tv->m_data.pobj->getVMClass()->name())) { if (isProfileRequest()) InstanceBits::profile(m_typeName); return true; } // We can't save the Class* since it moves around from request // to request. assert(m_namedEntity); c = Unit::lookupClass(m_namedEntity); } else { switch (metaType()) { case MetaType::Self: selfToClass(func, &c); break; case MetaType::Parent: parentToClass(func, &c); break; case MetaType::Callable: return is_callable(tvAsCVarRef(tv)); case MetaType::Precise: case MetaType::Number: case MetaType::ArrayKey: case MetaType::Dict: case MetaType::Vec: return false; case MetaType::Mixed: // We assert'd at the top of this function that the // metatype cannot be Mixed not_reached(); } } if (isProfileRequest() && c) { InstanceBits::profile(c->preClass()->name()); } if (c && tv->m_data.pobj->instanceof(c)) { return true; } return isObject() && checkTypeAliasObj(tv->m_data.pobj->getVMClass()); } auto const result = annotCompat(tv->m_type, m_type, m_typeName); switch (result) { case AnnotAction::Pass: return true; case AnnotAction::Fail: return false; case AnnotAction::CallableCheck: return is_callable(tvAsCVarRef(tv)); case AnnotAction::DictCheck: return tv->m_data.parr->isDict(); case AnnotAction::VecCheck: return tv->m_data.parr->isVecArray(); case AnnotAction::ObjectCheck: assert(isObject()); return checkTypeAliasNonObj(tv); } not_reached(); }
int32_t CBC_PDF417HighLevelEncoder::encodeText(CFX_WideString msg, int32_t startpos, int32_t count, CFX_WideString& sb, int32_t initialSubmode) { CFX_WideString tmp; int32_t submode = initialSubmode; int32_t idx = 0; while (true) { FX_WCHAR ch = msg.GetAt(startpos + idx); switch (submode) { case SUBMODE_ALPHA: if (isAlphaUpper(ch)) { if (ch == ' ') { tmp += (FX_WCHAR)26; } else { tmp += (FX_WCHAR)(ch - 65); } } else { if (isAlphaLower(ch)) { submode = SUBMODE_LOWER; tmp += (FX_WCHAR)27; continue; } else if (isMixed(ch)) { submode = SUBMODE_MIXED; tmp += (FX_WCHAR)28; continue; } else { tmp += (FX_WCHAR)29; tmp += PUNCTUATION[ch]; break; } } break; case SUBMODE_LOWER: if (isAlphaLower(ch)) { if (ch == ' ') { tmp += (FX_WCHAR)26; } else { tmp += (FX_WCHAR)(ch - 97); } } else { if (isAlphaUpper(ch)) { tmp += (FX_WCHAR)27; tmp += (FX_WCHAR)(ch - 65); break; } else if (isMixed(ch)) { submode = SUBMODE_MIXED; tmp += (FX_WCHAR)28; continue; } else { tmp += (FX_WCHAR)29; tmp += PUNCTUATION[ch]; break; } } break; case SUBMODE_MIXED: if (isMixed(ch)) { tmp += MIXED[ch]; } else { if (isAlphaUpper(ch)) { submode = SUBMODE_ALPHA; tmp += (FX_WCHAR)28; continue; } else if (isAlphaLower(ch)) { submode = SUBMODE_LOWER; tmp += (FX_WCHAR)27; continue; } else { if (startpos + idx + 1 < count) { FX_WCHAR next = msg.GetAt(startpos + idx + 1); if (isPunctuation(next)) { submode = SUBMODE_PUNCTUATION; tmp += (FX_WCHAR)25; continue; } } tmp += (FX_WCHAR)29; tmp += PUNCTUATION[ch]; } } break; default: if (isPunctuation(ch)) { tmp += PUNCTUATION[ch]; } else { submode = SUBMODE_ALPHA; tmp += (FX_WCHAR)29; continue; } } idx++; if (idx >= count) { break; } } FX_WCHAR h = 0; int32_t len = tmp.GetLength(); for (int32_t i = 0; i < len; i++) { bool odd = (i % 2) != 0; if (odd) { h = (FX_WCHAR)((h * 30) + tmp.GetAt(i)); sb += h; } else { h = tmp.GetAt(i); } } if ((len % 2) != 0) { sb += (FX_WCHAR)((h * 30) + 29); } return submode; }