TypeSet getGreatestCommonSubtypes(const TypeSet& set) { // handle the empty set if (set.empty()) return set; // handle the all set => empty set (since no common sub-type) if (set.isAll()) return TypeSet(); TypeSet res; auto it = set.begin(); res.insert(*it); ++it; // refine sub-set step by step for(;it != set.end(); ++it) { TypeSet tmp; for(const Type& cur : res) { tmp.insert(getGreatestCommonSubtypes(cur, *it)); } res = tmp; } // done return res; }
void IConnectionLoader::addConnection( VertexMap& vertices, SystemTypeGetter* info, int from, int to, TypeSet tags) { TypeSet toType, fromType; toType.insert(info->getType(to)); toType.insert(tags.begin(), tags.end()); fromType.insert(info->getType(from)); fromType.insert(tags.begin(), tags.end()); //Add vertices if they dont exists already //this will fail if it already exists vertices.insert(std::make_pair(from, Vertex(from))); vertices.insert(std::make_pair(to, Vertex(to))); //Add edges to the vertices vertices.find(from)->second.addEdge(to, toType); vertices.find(to)->second.addEdge(from, fromType); }
/******************************************************************* * Function: ArrayIndexAnalysis::getTypeInfo * Purpose : Get an array dimensions' information * Initial : Nurudeen A. Lameed on July 21, 2009 ******************************************************************** Revisions and bug fixes: */ inline TypeInfo ArrayIndexAnalysis::getTypeInfo(const IIRNode* node, const SymbolExpr* symbol) const { // retrieve the type set TypeInfoMap post = typeInferenceInfo->postTypeMap; TypeSet tSet = (post[node])[symbol]; // look for one with bounds information // if none has the info, return an empty type info. for (TypeSet::const_iterator it = tSet.begin(), iEnd = tSet.end(); it != iEnd; ++it) { TypeInfo typ = *it; if ( typ.getSizeKnown() ) { return *it; } } return TypeInfo(); // return an empty type info }
/** * Move all single impl in a single impl method signature to next pass. * We make a single optimization per pass over any given single impl so * I1, I2 and void I1.m(I2) * the first optimization (I1 or I2) moves the other interface to next pass. * That is not the case for methods on non optimizable classes, so for * I1, I2 and void C.m(I1, I2) * then m is changed in a single pass for both I1 and I2. */ void OptimizationImpl::drop_single_impl_collision(DexType* intf, SingleImplData& data, DexMethod* method) { auto check_type = [&](DexType* type) { if (type != intf && single_impls->is_single_impl(type) && !single_impls->is_escaped(type)) { single_impls->escape_interface(type, NEXT_PASS); assert(optimized.find(type) == optimized.end()); } }; auto owner = method->get_class(); if (!single_impls->is_single_impl(owner)) return; check_type(owner); auto proto = method->get_proto(); check_type(proto->get_rtype()); auto args_list = proto->get_args(); for (auto arg : args_list->get_type_list()) { check_type(arg); } }
void RenameClassesPass::run_pass(DexStoresVector& stores, ConfigFiles& cfg, PassManager& mgr) { const JsonWrapper& json_cfg = cfg.get_json_config(); if (json_cfg.get("emit_name_based_locators", false)) { // TODO: Purge the old RenameClassesPass entirely everywhere. fprintf(stderr, "[RenameClassesPass] error: Configuration option " "emit_locator_strings is not compatible with RenameClassesPass. " "Upgrade to RenameClassesPassV2 instead.\n"); exit(EXIT_FAILURE); } auto scope = build_class_scope(stores); ClassHierarchy ch = build_type_hierarchy(scope); std::unordered_set<const DexType*> untouchables; for (const auto& base : m_untouchable_hierarchies) { auto base_type = DexType::get_type(base.c_str()); if (base_type != nullptr) { untouchables.insert(base_type); TypeSet children; get_all_children(ch, base_type, children); untouchables.insert(children.begin(), children.end()); } } mgr.incr_metric(METRIC_CLASSES_IN_SCOPE, scope.size()); rename_classes( scope, m_pre_filter_whitelist, m_post_filter_whitelist, untouchables, m_rename_annotations, mgr); TRACE(RENAME, 1, "renamed classes: %d anon classes, %d from single char patterns, " "%d from multi char patterns\n", match_inner, match_short, match_long); TRACE(RENAME, 1, "String savings, at least %d bytes \n", base_strings_size - ren_strings_size); }
/** * Run an optimization step. */ size_t OptimizationImpl::optimize(Scope& scope) { TypeList to_optimize; single_impls->get_interfaces(to_optimize); for (auto intf : to_optimize) { auto& intf_data = single_impls->get_single_impl_data(intf); TRACE(INTF, 3, "(OPT) %s => %s\n", SHOW(intf), SHOW(intf_data.cls)); if (intf_data.is_escaped()) continue; auto escape = can_optimize(intf, intf_data); if (escape != EscapeReason::NO_ESCAPE) { single_impls->escape_interface(intf, escape); continue; } do_optimize(intf, intf_data); optimized.insert(intf); } // make a new scope deleting all single impl interfaces Scope new_scope; for (auto cls : scope) { if (optimized.find(cls->get_type()) != optimized.end()) continue; new_scope.push_back(cls); } scope.swap(new_scope); return optimized.size(); }
bool CalculateAmplitudes::process() { //_ui.btnOK->setEnabled(false); _processors.clear(); _ui.table->setRowCount(0); Core::TimeWindow acTimeWindow; if ( !_origin || (_recomputeAmplitudes && !_thread) ) return false; if ( _amplitudeTypes.empty() ) return false; _timeWindow = Core::TimeWindow(); /* TypeSet wantedAmpTypes; wantedAmpTypes.insert("MLv"); wantedAmpTypes.insert("mb"); wantedAmpTypes.insert("mB"); wantedAmpTypes.insert("Mwp"); try { vector<string> amps = SCApp->configGetStrings("amplitudes"); wantedAmpTypes.clear(); wantedAmpTypes.insert(amps.begin(), amps.end()); } catch (...) {} */ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); if ( _thread ) _thread->connect(); typedef pair<PickCPtr, double> PickStreamEntry; // Typedef a pickmap that maps a streamcode to a pick typedef map<string, PickStreamEntry> PickStreamMap; // This map is needed to find the earliest P pick of // a certain stream PickStreamMap pickStreamMap; for ( size_t i = 0; i < _origin->arrivalCount(); ++i ) { Arrival *ar = _origin->arrival(i); double weight = 1.; try { weight = ar->weight(); } catch (Seiscomp::Core::ValueException) {} if ( Util::getShortPhaseName(ar->phase().code()) != 'P' || weight < 0.5 ) { continue; } Pick *pick = Pick::Find(ar->pickID()); if ( !pick ) { // cerr << " - Skipping arrival " << i << " -> no pick found" << endl; continue; } double dist = -1; try { dist = ar->distance(); } catch ( Core::ValueError &e ) { try { Client::StationLocation loc; double azi1, azi2; loc = Client::Inventory::Instance()->stationLocation(pick->waveformID().networkCode(), pick->waveformID().stationCode(), pick->time().value()); Math::Geo::delazi(loc.latitude, loc.longitude, _origin->latitude(), _origin->longitude(), &dist, &azi1, &azi2); } catch ( Core::GeneralException &e ) {} } DataModel::WaveformStreamID wfid = pick->waveformID(); // Strip the component code because every AmplitudeProcessor // will use its own component to pick the amplitude on wfid.setChannelCode(wfid.channelCode().substr(0,2)); string streamID = waveformIDToStdString(wfid); PickStreamEntry &e = pickStreamMap[streamID]; // When there is already a pick registered for this stream which has // been picked earlier, ignore the current pick if ( e.first && e.first->time().value() < pick->time().value() ) continue; e.first = pick; e.second = dist; } for ( PickStreamMap::iterator it = pickStreamMap.begin(); it != pickStreamMap.end(); ++it ) { PickCPtr pick = it->second.first; double dist = it->second.second; _ui.comboFilterType->clear(); _ui.comboFilterType->addItem("- Any -"); for ( TypeSet::iterator ita = _amplitudeTypes.begin(); ita != _amplitudeTypes.end(); ++ita ) _ui.comboFilterType->addItem(ita->c_str()); if ( _recomputeAmplitudes ) { for ( TypeSet::iterator ita = _amplitudeTypes.begin(); ita != _amplitudeTypes.end(); ++ita ) addProcessor(*ita, pick.get(), dist); } else { string streamID = waveformIDToStdString(pick->waveformID()); TypeSet usedTypes; if ( !_amplitudes.empty() ) { iterator_range itp; itp = _amplitudes.equal_range(pick->publicID()); for ( iterator it = itp.first; it != itp.second; ) { AmplitudePtr amp = it->second.first; // The amplitude type is not one of the wanted types if ( _amplitudeTypes.find(amp->type()) == _amplitudeTypes.end() ) { ++it; continue; } // Already has an amplitude of this type processed if ( usedTypes.find(amp->type()) != usedTypes.end() ) { ++it; continue; } usedTypes.insert(amp->type()); int row = addProcessingRow(waveformIDToStdString(amp->waveformID()), amp->type()); setMessage(row, "read from cache"); setValue(row, amp->amplitude().value()); ++it; } } bool foundAmplitudes = false; if ( _externalAmplitudeCache ) { iterator_range itp; itp = _externalAmplitudeCache->equal_range(pick->publicID()); for ( iterator ita = itp.first; ita != itp.second; ++ita ) { AmplitudePtr amp = ita->second.first; // The amplitude type is not one of the wanted types if ( _amplitudeTypes.find(amp->type()) == _amplitudeTypes.end() ) continue; // Already has an amplitude of this type processed if ( usedTypes.find(amp->type()) != usedTypes.end() ) { checkPriority(ita->second); continue; } usedTypes.insert(amp->type()); int row = addProcessingRow(waveformIDToStdString(amp->waveformID()), amp->type()); setMessage(row, "read from cache"); setValue(row, amp->amplitude().value()); _amplitudes.insert(PickAmplitudeMap::value_type(ita->first, ita->second)); } } if ( _query && !foundAmplitudes ) { DatabaseIterator it = _query->getAmplitudesForPick(pick->publicID()); for ( ; *it; ++it ) { AmplitudePtr amp = Amplitude::Cast(*it); if ( !amp ) continue; foundAmplitudes = true; // The amplitude type is not one of the wanted types if ( _amplitudeTypes.find(amp->type()) == _amplitudeTypes.end() ) continue; // Already has an amplitude of this type processed if ( usedTypes.find(amp->type()) != usedTypes.end() ) { checkPriority(AmplitudeEntry(amp, false)); continue; } usedTypes.insert(amp->type()); int row = addProcessingRow(waveformIDToStdString(amp->waveformID()), amp->type()); setMessage(row, "read from database"); setValue(row, amp->amplitude().value()); _amplitudes.insert(PickAmplitudeMap::value_type(pick->publicID(), AmplitudeEntry(amp, false))); } } if ( !foundAmplitudes ) { EventParameters *ep = EventParameters::Cast(PublicObject::Find("EventParameters")); if ( ep ) { for ( size_t i = 0; i < ep->amplitudeCount(); ++i ) { Amplitude *amp = ep->amplitude(i); if ( amp->pickID() != pick->publicID() ) continue; // The amplitude type is not one of the wanted types if ( _amplitudeTypes.find(amp->type()) == _amplitudeTypes.end() ) continue; // Already has an amplitude of this type processed if ( usedTypes.find(amp->type()) != usedTypes.end() ) { checkPriority(AmplitudeEntry(amp, false)); continue; } usedTypes.insert(amp->type()); int row = addProcessingRow(waveformIDToStdString(amp->waveformID()), amp->type()); setMessage(row, "read from memory"); setValue(row, amp->amplitude().value()); _amplitudes.insert(PickAmplitudeMap::value_type(pick->publicID(), AmplitudeEntry(amp, false))); } } } TypeSet remainingTypes; set_difference(_amplitudeTypes.begin(), _amplitudeTypes.end(), usedTypes.begin(), usedTypes.end(), inserter(remainingTypes, remainingTypes.begin())); for ( TypeSet::iterator ita = remainingTypes.begin(); ita != remainingTypes.end(); ++ita ) { if ( _thread ) addProcessor(*ita, pick.get(), dist); else { int row = addProcessingRow(streamID, *ita); setError(row, "missing"); } } } } _ui.table->resizeColumnsToContents(); _ui.table->resizeRowsToContents(); if ( _thread && _timeWindow ) { _thread->setTimeWindow(_timeWindow); _thread->start(); } //else // _ui.btnOK->setEnabled(true); QApplication::restoreOverrideCursor(); return true; }