VerificationType VerificationType::get_component(ClassVerifier *context, TRAPS) const { assert(is_array() && name()->utf8_length() >= 2, "Must be a valid array"); Symbol* component; switch (name()->byte_at(1)) { case 'Z': return VerificationType(Boolean); case 'B': return VerificationType(Byte); case 'C': return VerificationType(Char); case 'S': return VerificationType(Short); case 'I': return VerificationType(Integer); case 'J': return VerificationType(Long); case 'F': return VerificationType(Float); case 'D': return VerificationType(Double); case '[': component = context->create_temporary_symbol( name(), 1, name()->utf8_length(), CHECK_(VerificationType::bogus_type())); return VerificationType::reference_type(component); case 'L': component = context->create_temporary_symbol( name(), 2, name()->utf8_length() - 1, CHECK_(VerificationType::bogus_type())); return VerificationType::reference_type(component); default: // Met an invalid type signature, e.g. [X return VerificationType::bogus_type(); } }
/** * Test that choice_option correctly reports its capabilities. */ TEST(choice_option_test, capabilities) { auto short_name = std::string("f"); auto name = std::string("foo"); auto option = qflags::choice_option(name.c_str(), short_name.c_str(), {"bar", "baz"}, "bar"); EXPECT_EQ(name, option.name()); EXPECT_EQ(short_name, option.short_name()); EXPECT_EQ(false, option.is_set()); EXPECT_EQ(false, option.is_flag()); EXPECT_EQ(false, option.is_command()); EXPECT_EQ(false, option.is_array()); EXPECT_EQ(false, option.is_boolean()); EXPECT_EQ(false, option.is_integer()); EXPECT_EQ(true, option.is_string()); EXPECT_EQ(0u, option.array_size()); EXPECT_THROW(option.value_boolean(), std::logic_error); EXPECT_THROW(option.value_integer(), std::logic_error); EXPECT_EQ("bar", option.value_string()); EXPECT_THROW(option.value_array(0), std::logic_error); EXPECT_THROW(static_cast<bool>(option), std::logic_error); EXPECT_THROW(static_cast<int64_t>(option), std::logic_error); EXPECT_THROW(static_cast<int>(option), std::logic_error); EXPECT_EQ("bar", static_cast<std::string>(option)); }
Exec_stat MCVariableValue::setprops(uint4 parid, MCObject *optr) { if (!is_array()) return ES_NORMAL; return array . setprops(parid, optr); }
Exec_stat MCVariableValue::store(MCExecPoint& ep) { switch(ep . getformat()) { case VF_UNDEFINED: clear(); break; case VF_STRING: assign_string(ep . getsvalue()); break; case VF_NUMBER: assign_real(ep . getnvalue()); break; case VF_BOTH: assign_both(ep . getsvalue(), ep . getnvalue()); break; case VF_ARRAY: // MW-2008-08-30: [[ Bug ]] Doing put tArray[x] into tArray causes badness since 'assign' // first deletes the current value then copies. if (!is_array() || ep . getdeletearray()) assign(*(ep . getarray())); else { MCVariableValue t_temp(*(ep . getarray())); exchange(t_temp); } break; } return ES_NORMAL; }
IO_stat MCVariableValue::savekeys(IO_header *stream) { if (is_array()) return array . savekeys(stream); return IO_write_uint4(0, stream); }
ValueType Object::get_property_value_impl(ContextType& ctx, const Property &property) { verify_attached(); size_t column = property.table_column; if (is_nullable(property.type) && m_row.is_null(column)) return ctx.null_value(); if (is_array(property.type) && property.type != PropertyType::LinkingObjects) return ctx.box(List(m_realm, *m_row.get_table(), column, m_row.get_index())); switch (property.type & ~PropertyType::Flags) { case PropertyType::Bool: return ctx.box(m_row.get_bool(column)); case PropertyType::Int: return ctx.box(m_row.get_int(column)); case PropertyType::Float: return ctx.box(m_row.get_float(column)); case PropertyType::Double: return ctx.box(m_row.get_double(column)); case PropertyType::String: return ctx.box(m_row.get_string(column)); case PropertyType::Data: return ctx.box(m_row.get_binary(column)); case PropertyType::Date: return ctx.box(m_row.get_timestamp(column)); case PropertyType::Any: return ctx.box(m_row.get_mixed(column)); case PropertyType::Object: { auto linkObjectSchema = m_realm->schema().find(property.object_type); TableRef table = ObjectStore::table_for_object_type(m_realm->read_group(), property.object_type); return ctx.box(Object(m_realm, *linkObjectSchema, table->get(m_row.get_link(column)))); } case PropertyType::LinkingObjects: { auto target_object_schema = m_realm->schema().find(property.object_type); auto link_property = target_object_schema->property_for_name(property.link_origin_property_name); TableRef table = ObjectStore::table_for_object_type(m_realm->read_group(), target_object_schema->name); auto tv = m_row.get_table()->get_backlink_view(m_row.get_index(), table.get(), link_property->table_column); return ctx.box(Results(m_realm, std::move(tv))); } default: REALM_UNREACHABLE(); } }
PyObject * next() { auto obj = read_next(); if( is_array( obj ) ) { if( obj.as.array_size ) { push_list( obj.as.array_size ); return nullptr; } return PyList_New( 0 ); } if( is_map( obj ) ) { if( obj.as.map_size ) { push_dict( obj.as.map_size ); return nullptr; } return PyDict_New(); } return read_simple( obj ); }
global_variable& global_variable::operator =(uint32_t v) { assert(is_vaild()); assert(!is_array()); ptr_->value_ = v; return *this; }
Exec_stat MCVariableValue::lookup_index(MCExecPoint& ep, uint32_t index, bool p_add, MCVariableValue*& r_value) { if (is_array()) ; else { if (!p_add) { r_value = nil; return ES_NORMAL; } assign_new_array(TABLE_SIZE); } MCHashentry *t_hashentry = array . lookupindex(index, p_add ? True : False); if (t_hashentry != nil) r_value = &(t_hashentry->value); else r_value = nil; if (p_add) set_dbg_mutated(true); return ES_NORMAL; }
/* Parse and emit initializer code for target variable in statements such as * int b[] = {0, 1, 2, 3}. Generate a series of assignment operations on * references to target variable. */ static struct block *initializer(struct block *block, struct var target) { assert(target.kind == DIRECT); /* Do not care about cv-qualifiers here. */ target.type = unwrapped(target.type); if (peek().token == '{') { block = object_initializer(block, target); } else { block = assignment_expression(block); if (!target.symbol->depth && block->expr.kind != IMMEDIATE) { error("Initializer must be computable at load time."); exit(1); } if (target.kind == DIRECT && !target.type->size) { assert(!target.offset); assert(is_string(block->expr)); assert(is_array(block->expr.type)); /* Complete type based on string literal. Evaluation does not have * the required context to do this logic. */ ((struct symbol *) target.symbol)->type.size = block->expr.type->size; target.type = block->expr.type; } eval_assign(block, target, block->expr); } return block; }
TEST(ArrayBuilder, WithAllInMultipleTimes) { cpp_redis::builders::array_builder builder; std::string buffer = "4\r\n+simple_string\r"; builder << buffer; buffer += "\n-error\r\n:42\r\n"; builder << buffer; buffer += "$5\r\nhello\r\n"; builder << buffer; EXPECT_EQ(true, builder.reply_ready()); EXPECT_EQ("", buffer); auto reply = builder.get_reply(); EXPECT_TRUE(reply.is_array()); auto array = reply.as_array(); EXPECT_EQ(4U, array.size()); auto row_1 = array[0]; EXPECT_TRUE(row_1.is_simple_string()); EXPECT_EQ("simple_string", row_1.as_string()); auto row_2 = array[1]; EXPECT_TRUE(row_2.is_error()); EXPECT_EQ("error", row_2.as_string()); auto row_3 = array[2]; EXPECT_TRUE(row_3.is_integer()); EXPECT_EQ(42, row_3.as_integer()); auto row_4 = array[3]; EXPECT_TRUE(row_4.is_bulk_string()); EXPECT_EQ("hello", row_4.as_string()); }
ConfUnit::const_iterator ConfUnit::end() const { if (is_array()) { return _vector.end(); } else { throw std::exception(); } }
inline basic_val<T>& basic_val<T>::operator[](std::size_t i) { if (!is_array(*this)) throw type_error("basic_val is not an array"); if (i >= a_.size()) a_.resize(i+1); return a_[i]; }
inline basic_val<T> const& basic_val<T>::operator[](std::size_t i) const { if (!is_array(*this)) throw type_error("basic_val is not an array"); if (i >= a_.size()) throw range_error("out of range"); return a_[i]; }
DexType* get_array_type(const DexType* type) { if (!is_array(type)) return nullptr; auto name = type->get_name()->c_str(); while (*name == '[') { name++; } return DexType::make_type(name); }
bool Class::is_instanceof(Class* clss) { assert(!is_interface()); #ifdef VM_STATS UNSAFE_REGION_START VM_Statistics::get_vm_stats().num_type_checks++; if(this == clss) VM_Statistics::get_vm_stats().num_type_checks_equal_type++; if(clss->m_is_suitable_for_fast_instanceof) VM_Statistics::get_vm_stats().num_type_checks_fast_decision++; else if(clss->is_array()) VM_Statistics::get_vm_stats().num_type_checks_super_is_array++; else if(clss->is_interface()) VM_Statistics::get_vm_stats().num_type_checks_super_is_interface ++; else if((unsigned)clss->m_depth >= vm_max_fast_instanceof_depth()) VM_Statistics::get_vm_stats().num_type_checks_super_is_too_deep++; UNSAFE_REGION_END #endif // VM_STATS if(this == clss) return true; Global_Env* env = VM_Global_State::loader_env; if(is_array()) { Class* object_class = env->JavaLangObject_Class; assert(object_class != NULL); if(clss == object_class) return true; if(clss == env->java_io_Serializable_Class) return true; if(clss == env->java_lang_Cloneable_Class) return true; if(!clss->is_array()) return false; return class_is_subtype(get_array_element_class(), clss->get_array_element_class()); } else { if(clss->m_is_suitable_for_fast_instanceof) { return m_vtable->superclasses[clss->m_depth - 1] == clss; } if(!clss->is_interface()) { for(Class *c = this; c; c = c->get_super_class()) { if(c == clss) return true; } } else { for(Class *c = this; c; c = c->get_super_class()) { unsigned n_intf = c->get_number_of_superinterfaces(); for(unsigned i = 0; i < n_intf; i++) { Class* intf = c->get_superinterface(i); assert(intf); assert(intf->is_interface()); if(class_is_subtype(intf, clss)) return true; } } } } return false; }
bool Type::array_requires_descriptor() const { if (is_array()) { return (array_type_with_descriptor(_type_info)); } return false; }
ConfUnit* ConfUnit::push_back(ConfUnit* punit) { if (is_array()) { _vector.push_back(punit); return punit; } else { throw std::exception(); } }
bool Type::array_has_size() const { if (is_array()) { return (!array_type_is_unknown_size(_type_info)); } return false; }
inline std::optional<nlohmann::json::const_iterator> find_array(const nlohmann::json& json, const std::string& key) { auto it = json.find(key); if (it != std::end(json)) { if (it->is_array()) { return it; } } return std::nullopt; }
Exec_stat MCVariableValue::factorarray(MCExecPoint& ep, Operators op) { if (!is_array()) assign_empty(); if (is_empty()) return ES_NORMAL; return array . factorarray(ep, op); }
int32_t ConfUnit::size() const { if (is_array()) { return (int32_t)_vector.size(); } else if (is_group()) { return (int32_t)_map.size(); } else { return 0; } }
void MCVariableValue::remove_hash(MCHashentry *p_entry) { if (is_array()) { array . removehash(p_entry); if (array . getnfilled() == 0) assign_empty(); else set_dbg_mutated(true); } }
stdx::string_view next_key() { if (is_array()) { _itoa_key = _stack.empty() ? _n++ : _stack.back().n++; _user_key_view = stdx::string_view{_itoa_key.c_str(), _itoa_key.length()}; } else if (!_has_user_key) { throw bsoncxx::exception{error_code::k_need_key}; } _has_user_key = false; return _user_key_view; }
bool MCVariableValue::fetch_element_if_exists(MCExecPoint& ep, const MCString& key, bool p_copy) { if (is_array()) { MCHashentry *e; e = array . lookuphash(key, ep . getcasesensitive(), False); if (e != NULL) return e -> value . fetch(ep, p_copy) == ES_NORMAL; } return false; }
Exec_stat MCVariableValue::remove_element(MCExecPoint& ep, const MCString& key) { if (is_array()) { array . removehash(key, ep . getcasesensitive()); if (array . getnfilled() == 0) assign_empty(); else set_dbg_mutated(true); } return ES_NORMAL; }
bool VerificationType::is_reference_assignable_from( const VerificationType& from, ClassVerifier* context, bool from_field_is_protected, TRAPS) const { instanceKlassHandle klass = context->current_class(); if (from.is_null()) { // null is assignable to any reference return true; } else if (is_null()) { return false; } else if (name() == from.name()) { return true; } else if (is_object()) { // We need check the class hierarchy to check assignability if (name() == vmSymbols::java_lang_Object()) { // any object or array is assignable to java.lang.Object return true; } Klass* obj = SystemDictionary::resolve_or_fail( name(), Handle(THREAD, klass->class_loader()), Handle(THREAD, klass->protection_domain()), true, CHECK_false); if (TraceClassResolution) { Verifier::trace_class_resolution(obj, klass()); } KlassHandle this_class(THREAD, obj); if (this_class->is_interface() && (!from_field_is_protected || from.name() != vmSymbols::java_lang_Object())) { // If we are not trying to access a protected field or method in // java.lang.Object then we treat interfaces as java.lang.Object, // including java.lang.Cloneable and java.io.Serializable. return true; } else if (from.is_object()) { Klass* from_class = SystemDictionary::resolve_or_fail( from.name(), Handle(THREAD, klass->class_loader()), Handle(THREAD, klass->protection_domain()), true, CHECK_false); if (TraceClassResolution) { Verifier::trace_class_resolution(from_class, klass()); } return InstanceKlass::cast(from_class)->is_subclass_of(this_class()); } } else if (is_array() && from.is_array()) { VerificationType comp_this = get_component(context, CHECK_false); VerificationType comp_from = from.get_component(context, CHECK_false); if (!comp_this.is_bogus() && !comp_from.is_bogus()) { return comp_this.is_component_assignable_from(comp_from, context, from_field_is_protected, CHECK_false); } } return false; }
TEST(ArrayBuilder, EmptyArray) { cpp_redis::builders::array_builder builder; std::string buffer = "0\r\n"; builder << buffer; EXPECT_EQ(true, builder.reply_ready()); EXPECT_EQ("", buffer); auto reply = builder.get_reply(); EXPECT_TRUE(reply.is_array()); auto array = reply.as_array(); EXPECT_EQ(0U, array.size()); }
void ConfUnit::pop_back() { if (is_array()) { if (_vector.size() > 0) { ConfUnit* pson = NULL; pson = _vector.back(); _vector.pop_back(); if (NULL != pson) { delete pson; } } } else { throw std::exception(); } }
symbol_t * make_symbol (const char *name, type_t *type, defspace_t *space, storage_class_t storage) { symbol_t *sym; struct reloc_s *relocs = 0; if (storage != sc_extern && storage != sc_global && storage != sc_static) internal_error (0, "invalid storage class for %s", __FUNCTION__); if (storage != sc_extern && !space) internal_error (0, "null space for non-external storage"); sym = symtab_lookup (pr.symtab, name); if (!sym) { sym = new_symbol_type (name, type); } if (sym->type != type) { if (is_array (sym->type) && is_array (type) && !sym->type->t.array.size) { sym->type = type; } else { error (0, "%s redefined", name); sym = new_symbol_type (name, type); } } if (sym->s.def && sym->s.def->external && storage != sc_extern) { //FIXME this really is not the right way relocs = sym->s.def->relocs; free_def (sym->s.def); sym->s.def = 0; } if (!sym->s.def) { sym->s.def = new_def (name, type, space, storage); reloc_attach_relocs (relocs, &sym->s.def->relocs); } return sym; }