+void Buffer::listMacroNames(MacroNameSet & macros) const
+{
+ if (d->macro_lock)
+ return;
+
+ d->macro_lock = true;
+
+ // loop over macro names
+ Impl::NamePositionScopeMacroMap::iterator nameIt = d->macros.begin();
+ Impl::NamePositionScopeMacroMap::iterator nameEnd = d->macros.end();
+ for (; nameIt != nameEnd; ++nameIt)
+ macros.insert(nameIt->first);
+
+ // loop over children
+ Impl::BufferPositionMap::iterator it = d->children_positions.begin();
+ Impl::BufferPositionMap::iterator end = d->children_positions.end();
+ for (; it != end; ++it)
+ it->first->listMacroNames(macros);
+
+ // call parent
+ if (d->parent_buffer)
+ d->parent_buffer->listMacroNames(macros);
+
+ d->macro_lock = false;
+}
+
+
+void Buffer::writeParentMacros(odocstream & os) const
+{
+ if (!d->parent_buffer)
+ return;
+
+ // collect macro names
+ MacroNameSet names;
+ d->parent_buffer->listMacroNames(names);
+
+ // resolve and output them
+ MacroNameSet::iterator it = names.begin();
+ MacroNameSet::iterator end = names.end();
+ for (; it != end; ++it) {
+ // defined?
+ MacroData const * data =
+ d->parent_buffer->getMacro(*it, *this, false);
+ if (data)
+ data->write(os, true);
+ }
+}
+
+
+Buffer::References & Buffer::references(docstring const & label)
+{
+ if (d->parent_buffer)
+ return const_cast<Buffer *>(masterBuffer())->references(label);
+
+ RefCache::iterator it = d->ref_cache_.find(label);
+ if (it != d->ref_cache_.end())
+ return it->second.second;
+
+ static InsetLabel const * dummy_il = 0;
+ static References const dummy_refs;
+ it = d->ref_cache_.insert(
+ make_pair(label, make_pair(dummy_il, dummy_refs))).first;
+ return it->second.second;
+}
+
+
+Buffer::References const & Buffer::references(docstring const & label) const
+{
+ return const_cast<Buffer *>(this)->references(label);
+}
+
+
+void Buffer::setInsetLabel(docstring const & label, InsetLabel const * il)
+{
+ masterBuffer()->d->ref_cache_[label].first = il;
+}
+
+
+InsetLabel const * Buffer::insetLabel(docstring const & label) const
+{
+ return masterBuffer()->d->ref_cache_[label].first;
+}
+
+
+void Buffer::clearReferenceCache() const
+{
+ if (!d->parent_buffer)
+ d->ref_cache_.clear();
+}
+
+