int irept::compare(const irept &i) const { int r; r=id().compare(i.id()); if(r!=0) return r; const subt::size_type size=get_sub().size(), i_size=i.get_sub().size(); if(size<i_size) return -1; if(size>i_size) return 1; { irept::subt::const_iterator it1, it2; for(it1=get_sub().begin(), it2=i.get_sub().begin(); it1!=get_sub().end() && it2!=i.get_sub().end(); it1++, it2++) { r=it1->compare(*it2); if(r!=0) return r; } assert(it1==get_sub().end() && it2==i.get_sub().end()); } const named_subt::size_type n_size=get_named_sub().size(), i_n_size=i.get_named_sub().size(); if(n_size<i_n_size) return -1; if(n_size>i_n_size) return 1; { irept::named_subt::const_iterator it1, it2; for(it1=get_named_sub().begin(), it2=i.get_named_sub().begin(); it1!=get_named_sub().end() && it2!=i.get_named_sub().end(); it1++, it2++) { r=it1->first.compare(it2->first); if(r!=0) return r; r=it1->second.compare(it2->second); if(r!=0) return r; } assert(it1==get_named_sub().end() && it2==i.get_named_sub().end()); } // equal return 0; }
irept &irept::add(const irep_namet &name) { named_subt &s= is_comment(name)?get_comments():get_named_sub(); return s[name]; }
irept &irept::add(const irep_namet &name, const irept &irep) { named_subt &s= is_comment(name)?get_comments():get_named_sub(); #ifdef SUB_IS_LIST named_subt::iterator it=named_subt_lower_bound(s, name); if(it==s.end() || it->first!=name) it=s.insert(it, std::make_pair(name, irep)); else it->second=irep; return it->second; #else std::pair<named_subt::iterator, bool> entry= s.insert(std::make_pair(name, irep)); if(!entry.second) entry.first->second=irep; return entry.first->second; #endif }
const irep_idt &irept::get(const irep_namet &name) const { const named_subt &s= is_comment(name)?get_comments():get_named_sub(); #ifdef SUB_IS_LIST named_subt::const_iterator it=named_subt_lower_bound(s, name); if(it==s.end() || it->first!=name) { const static irep_idt empty; return empty; } #else named_subt::const_iterator it=s.find(name); if(it==s.end()) { const static irep_idt empty; return empty; } #endif return it->second.id(); }
void irept::remove(const irep_namet &name) { named_subt &s= is_comment(name)?get_comments():get_named_sub(); named_subt::iterator it=s.find(name); if(it!=s.end()) s.erase(it); }
size_t irept::hash() const { size_t result=hash_string(id()); forall_irep(it, get_sub()) result=result^it->hash(); forall_named_irep(it, get_named_sub()) { result=result^hash_string(it->first); result=result^it->second.hash(); }
const irept &irept::find(const irep_namet &name) const { const named_subt &s= is_comment(name)?get_comments():get_named_sub(); named_subt::const_iterator it=s.find(name); if(it==s.end()) return get_nil_irep(); return it->second; }
void irept::remove(const irep_namet &name) { named_subt &s= is_comment(name)?get_comments():get_named_sub(); #ifdef SUB_IS_LIST named_subt::iterator it=named_subt_lower_bound(s, name); if(it!=s.end() && it->first==name) s.erase(it); #else s.erase(name); #endif }
const irep_idt &irept::get(const irep_namet &name) const { const named_subt &s= is_comment(name)?get_comments():get_named_sub(); named_subt::const_iterator it=s.find(name); if(it==s.end()) { const static irep_idt empty; return empty; } return it->second.id(); }
std::size_t to_be_merged_irept::hash() const { std::size_t result=hash_string(id()); const irept::subt &sub=get_sub(); const irept::named_subt &named_sub=get_named_sub(); forall_irep(it, sub) result=hash_combine(result, static_cast<const merged_irept &>(*it).hash()); forall_named_irep(it, named_sub) { result=hash_combine(result, hash_string(it->first)); result=hash_combine(result, static_cast<const merged_irept &>(it->second).hash()); }
irept &irept::add(const irep_namet &name) { named_subt &s= is_comment(name)?get_comments():get_named_sub(); #ifdef SUB_IS_LIST named_subt::iterator it=named_subt_lower_bound(s, name); if(it==s.end() || it->first!=name) it=s.insert(it, std::make_pair(name, irept())); return it->second; #else return s[name]; #endif }
std::size_t irept::hash() const { #ifdef HASH_CODE if(read().hash_code!=0) return read().hash_code; #endif const irept::subt &sub=get_sub(); const irept::named_subt &named_sub=get_named_sub(); std::size_t result=hash_string(id()); forall_irep(it, sub) result=hash_combine(result, it->hash()); forall_named_irep(it, named_sub) { result=hash_combine(result, hash_string(it->first)); result=hash_combine(result, it->second.hash()); }
const irept &irept::find(const irep_namet &name) const { const named_subt &s= is_comment(name)?get_comments():get_named_sub(); #ifdef SUB_IS_LIST named_subt::const_iterator it=named_subt_lower_bound(s, name); if(it==s.end() || it->first!=name) return get_nil_irep(); #else named_subt::const_iterator it=s.find(name); if(it==s.end()) return get_nil_irep(); #endif return it->second; }
void basic_regex_formatter<OutputIterator, Results, traits, ForwardIter>::format_perl() { // // On entry *m_position points to a '$' character // output the information that goes with it: // BOOST_ASSERT(*m_position == '$'); // // see if this is a trailing '$': // if(++m_position == m_end) { --m_position; put(*m_position); ++m_position; return; } // // OK find out what kind it is: // bool have_brace = false; ForwardIter save_position = m_position; switch(*m_position) { case '&': ++m_position; put(this->m_results[0]); break; case '`': ++m_position; put(this->m_results.prefix()); break; case '\'': ++m_position; put(this->m_results.suffix()); break; case '$': put(*m_position++); break; case '+': if((++m_position != m_end) && (*m_position == '{')) { ForwardIter base = ++m_position; while((m_position != m_end) && (*m_position != '}')) ++m_position; if(m_position != m_end) { // Named sub-expression: put(get_named_sub(base, m_position)); ++m_position; break; } else { m_position = --base; } } put((this->m_results)[this->m_results.size() > 1 ? static_cast<int>(this->m_results.size() - 1) : 1]); break; case '{': have_brace = true; ++m_position; // fall through.... default: // see if we have a number: { std::ptrdiff_t len = ::boost::re_detail::distance(m_position, m_end); //len = (std::min)(static_cast<std::ptrdiff_t>(2), len); int v = this->toi(m_position, m_position + len, 10); if((v < 0) || (have_brace && ((m_position == m_end) || (*m_position != '}')))) { // Look for a Perl-5.10 verb: if(!handle_perl_verb(have_brace)) { // leave the $ as is, and carry on: m_position = --save_position; put(*m_position); ++m_position; } break; } // otherwise output sub v: put(this->m_results[v]); if(have_brace) ++m_position; } } }
inline typename Results::value_type const& get_named_sub(ForwardIter i, ForwardIter j) { typedef typename boost::is_convertible<ForwardIter, const char_type*>::type tag_type; return get_named_sub(i, j, tag_type()); }