diff options
author | Marc Laukien <marc@zeroc.com> | 2001-09-19 04:34:00 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2001-09-19 04:34:00 +0000 |
commit | dc4709557bdda23892237a6301fff159bc1bd452 (patch) | |
tree | 043f95608acad51e1e18d7dad472e9ee559cee64 /cpp/src | |
parent | fixes (diff) | |
download | ice-dc4709557bdda23892237a6301fff159bc1bd452.tar.bz2 ice-dc4709557bdda23892237a6301fff159bc1bd452.tar.xz ice-dc4709557bdda23892237a6301fff159bc1bd452.zip |
slice2docbook fixes, Evictor for Freeze
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Freeze/.depend | 6 | ||||
-rw-r--r-- | cpp/src/Freeze/DBI.cpp | 22 | ||||
-rw-r--r-- | cpp/src/Freeze/DBI.h | 2 | ||||
-rw-r--r-- | cpp/src/Freeze/EvictorI.cpp | 192 | ||||
-rw-r--r-- | cpp/src/Freeze/EvictorI.h | 59 | ||||
-rw-r--r-- | cpp/src/Freeze/Makefile | 21 | ||||
-rw-r--r-- | cpp/src/IcePack/Parser.cpp | 4 | ||||
-rw-r--r-- | cpp/src/Slice/Parser.cpp | 92 | ||||
-rw-r--r-- | cpp/src/slice2docbook/Gen.cpp | 114 | ||||
-rw-r--r-- | cpp/src/slice2docbook/Gen.h | 5 | ||||
-rw-r--r-- | cpp/src/slice2docbook/Main.cpp | 2 |
11 files changed, 455 insertions, 64 deletions
diff --git a/cpp/src/Freeze/.depend b/cpp/src/Freeze/.depend index fd17057271f..3391e6fe15d 100644 --- a/cpp/src/Freeze/.depend +++ b/cpp/src/Freeze/.depend @@ -1,2 +1,4 @@ -DB.o: DB.cpp ../../include/Freeze/DB.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Config.h ../../include/IceUtil/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/Stream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h -DBI.o: DBI.cpp ../Freeze/DBI.h ../../include/IceUtil/IceUtil.h ../../include/IceUtil/Functional.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Config.h ../../include/IceUtil/Shared.h ../../include/Ice/Ice.h ../../include/Ice/Communicator.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/PicklerF.h ../../include/Ice/PropertiesF.h ../../include/Ice/ServantFactoryF.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/ServantFactory.h ../../include/Ice/Pickler.h ../../include/Ice/Initialize.h ../../include/Ice/InstanceF.h ../../include/Freeze/Initialize.h ../../include/Freeze/DBF.h ../../include/Freeze/DB.h ../../include/Ice/Stream.h ../../include/Ice/Buffer.h +DB.o: DB.cpp ../../include/Freeze/DB.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Config.h ../../include/IceUtil/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Freeze/EvictorF.h ../../include/Ice/Stream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h +DBI.o: DBI.cpp ../../include/Ice/Stream.h ../../include/Ice/InstanceF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Buffer.h ../Freeze/DBI.h ../../include/IceUtil/IceUtil.h ../../include/IceUtil/Functional.h ../../include/IceUtil/Shared.h ../../include/Ice/Ice.h ../../include/Ice/Communicator.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/PicklerF.h ../../include/Ice/PropertiesF.h ../../include/Ice/ServantFactoryF.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/ServantFactory.h ../../include/Ice/Pickler.h ../../include/Ice/Initialize.h ../../include/Freeze/DB.h ../../include/Freeze/EvictorF.h ../Freeze/EvictorI.h ../../include/Freeze/Evictor.h ../../include/Freeze/Initialize.h ../../include/Freeze/DBF.h +Evictor.o: Evictor.cpp ../../include/Freeze/Evictor.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Config.h ../../include/IceUtil/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/CommunicatorF.h ../../include/Ice/Stream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h +EvictorI.o: EvictorI.cpp ../Freeze/EvictorI.h ../../include/IceUtil/IceUtil.h ../../include/IceUtil/Functional.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Config.h ../../include/IceUtil/Shared.h ../../include/Ice/Ice.h ../../include/Ice/Communicator.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/PicklerF.h ../../include/Ice/PropertiesF.h ../../include/Ice/ServantFactoryF.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/ServantFactory.h ../../include/Ice/Pickler.h ../../include/Ice/Initialize.h ../../include/Ice/InstanceF.h ../../include/Freeze/DB.h ../../include/Freeze/EvictorF.h ../../include/Freeze/Evictor.h diff --git a/cpp/src/Freeze/DBI.cpp b/cpp/src/Freeze/DBI.cpp index e2f941961ad..6a47191d8cb 100644 --- a/cpp/src/Freeze/DBI.cpp +++ b/cpp/src/Freeze/DBI.cpp @@ -8,8 +8,10 @@ // // ********************************************************************** +#include <Ice/Stream.h> // Not included in Ice/Ice.h #include <Freeze/DBI.h> -#include <Ice/Stream.h> +#include <Freeze/EvictorI.h> +#include <Freeze/Initialize.h> #include <sys/stat.h> #include <sstream> @@ -285,6 +287,24 @@ Freeze::DBI::close() _db = 0; } +EvictorPtr +Freeze::DBI::createEvictor() +{ + JTCSyncT<JTCMutex> sync(*this); + + if(!_db) + { + ostringstream s; + s << "Freeze::DB(\"" << _name << "\"): "; + s << "\"" << _name << "\" has been closed"; + DBException ex; + ex.message = s.str(); + throw ex; + } + + return new EvictorI(this); +} + Freeze::DBEnvI::DBEnvI(const CommunicatorPtr& communicator, const string& directory) : _communicator(communicator), _directory(directory), diff --git a/cpp/src/Freeze/DBI.h b/cpp/src/Freeze/DBI.h index 6959b6f8f87..f0149e6463d 100644 --- a/cpp/src/Freeze/DBI.h +++ b/cpp/src/Freeze/DBI.h @@ -13,7 +13,6 @@ #include <IceUtil/IceUtil.h> #include <Ice/Ice.h> -#include <Freeze/Initialize.h> #include <Freeze/DB.h> #include <db.h> @@ -34,6 +33,7 @@ public: virtual ::Ice::ObjectPtr get(const std::string&); virtual void del(const std::string&); virtual void close(); + virtual EvictorPtr createEvictor(); private: diff --git a/cpp/src/Freeze/EvictorI.cpp b/cpp/src/Freeze/EvictorI.cpp new file mode 100644 index 00000000000..d6cc72b47ed --- /dev/null +++ b/cpp/src/Freeze/EvictorI.cpp @@ -0,0 +1,192 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Freeze/EvictorI.h> +#include <sstream> + +using namespace std; +using namespace Ice; +using namespace Freeze; + +Freeze::EvictorI::EvictorI(const DBPtr& db) : + _db(db), + _evictorSize(static_cast<map<string, EvictorElement>::size_type>(10)) +{ +} + +void +Freeze::EvictorI::createObject(const string& identity, const ObjectPtr& servant) +{ + // + // Save the new Ice Object to the database. + // + _db->put(identity, servant); + + // + // Evict one element, if necessary, to make room for a new + // one. Then add the new Ice Object to the evictor. + // + evict(); + add(identity, servant); +} + +void +Freeze::EvictorI::destroyObject(const string& identity) +{ + // + // Delete the Ice Object from the database. + // + _db->del(identity); + + // + // If the Ice Object is currently in the evictor, remove it. + // + map<string, EvictorElement>::iterator p = _evictorMap.find(identity); + if (p != _evictorMap.end()) + { + _evictorList.erase(p->second.position); + _evictorMap.erase(p); + } +} + +ObjectPtr +Freeze::EvictorI::locate(const ObjectAdapterPtr&, const string& identity, ObjectPtr&) +{ + JTCSyncT<JTCMutex> sync(*this); + + map<string, EvictorElement>::iterator p = _evictorMap.find(identity); + if (p != _evictorMap.end()) + { + // + // Ice Object found in evictor map. Push it to the front of + // the evictor list, so that it will be evicted last. + // + _evictorList.erase(p->second.position); + _evictorList.push_front(identity); + p->second.position = _evictorList.begin(); + + // + // Return the servant for the Ice Object. + // + return p->second.servant; + } + else + { + // + // Evict one element, if necessary, to make room for a new + // one. + // + evict(); + + // + // Find the Ice Object in the database and create a servant + // for it. + // + ObjectPtr servant = _db->get(identity); + if (!servant) + { + // + // Ice object with the given identity does not exist, + // client will get an ObjectNotExistException. + // + return 0; + } + +/* + // + // TODO: That's the only PhoneBook specific stuff! + // + ContactIPtr entry = ContactIPtr::dynamicCast(servant); + assert(entry); + entry->setIdentity(identity); +*/ + + // + // Add the new Ice Object and its Servant + // + add(identity, servant); + + // + // Return the new servant for the Ice Object from the database. + // + return servant; + } +} + +void +Freeze::EvictorI::finished(const ObjectAdapterPtr&, const string&, const ObjectPtr&, const ObjectPtr&) +{ + //JTCSyncT<JTCMutex> sync(*this); +} + +void +Freeze::EvictorI::deactivate() +{ + JTCSyncT<JTCMutex> sync(*this); + + // + // Save all Ice Objects in the database upon deactivation, and + // clear the evictor map and list. + // + for (map<string, EvictorElement>::iterator p = _evictorMap.begin(); p != _evictorMap.end(); ++p) + { + _db->put(*(p->second.position), p->second.servant); + } + _evictorMap.clear(); + _evictorList.clear(); +} + +void +Freeze::EvictorI::evict() +{ + // + // With most STL implementations, _evictorMap.size() is faster + // than _evictorList.size(). + // + if (_evictorMap.size() > _evictorSize) + { + // + // EvictorI size exceeded. Remove last element from the evictor list. + // + string identity = _evictorList.back(); + _evictorList.pop_back(); + + // + // Find corresponding element in the evictor map + // + map<string, EvictorElement>::iterator p = _evictorMap.find(identity); + assert(p != _evictorMap.end()); + + // + // Save the evicted Ice Object to the database. + // + _db->put(identity, p->second.servant); + + // + // Remove the element from the evictor map. + // + _evictorMap.erase(identity); + assert(_evictorMap.size() == _evictorSize); + } +} + +void +Freeze::EvictorI::add(const string& identity, const ObjectPtr& servant) +{ + // + // Add an Ice Object with its Servant to the evictor list and + // evictor map. + // + _evictorList.push_front(identity); + EvictorElement evictorElement; + evictorElement.servant = servant; + evictorElement.position = _evictorList.begin(); + _evictorMap[identity] = evictorElement; +} diff --git a/cpp/src/Freeze/EvictorI.h b/cpp/src/Freeze/EvictorI.h new file mode 100644 index 00000000000..7e4380d4f6a --- /dev/null +++ b/cpp/src/Freeze/EvictorI.h @@ -0,0 +1,59 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef FREEZE_EVICTOR_I_H +#define FREEZE_EVICTOR_I_H + +#include <IceUtil/IceUtil.h> +#include <Ice/Ice.h> +#include <Freeze/DB.h> +#include <Freeze/Evictor.h> +#include <list> + +namespace Freeze +{ + +class EvictorI; +typedef IceUtil::Handle<EvictorI> EvictorIPtr; + +class EvictorI : public Evictor, public JTCMutex +{ +public: + + EvictorI(const Freeze::DBPtr&); + + virtual void createObject(const std::string&, const Ice::ObjectPtr&); + virtual void destroyObject(const std::string&); + + virtual Ice::ObjectPtr locate(const Ice::ObjectAdapterPtr&, const std::string&, Ice::ObjectPtr&); + virtual void finished(const Ice::ObjectAdapterPtr&, const std::string&, const Ice::ObjectPtr&, + const Ice::ObjectPtr&); + virtual void deactivate(); + +private: + + void evict(); + void add(const std::string&, const Ice::ObjectPtr&); + + Freeze::DBPtr _db; + + struct EvictorElement + { + Ice::ObjectPtr servant; + std::list<std::string>::iterator position; + }; + std::map<std::string, EvictorElement> _evictorMap; + std::list<std::string> _evictorList; + std::map<std::string, EvictorElement>::size_type _evictorSize; +}; + +} + +#endif diff --git a/cpp/src/Freeze/Makefile b/cpp/src/Freeze/Makefile index ab888b45551..fcd6d5527db 100644 --- a/cpp/src/Freeze/Makefile +++ b/cpp/src/Freeze/Makefile @@ -19,7 +19,9 @@ VERSIONED_NAME = $(top_srcdir)/lib/$(VERSIONED_BASE) TARGETS = $(NAME) $(VERSIONED_NAME) OBJS = DB.o \ - DBI.o + DBI.o \ + Evictor.o \ + EvictorI.o SRCS = $(OBJS:.o=.cpp) @@ -57,4 +59,21 @@ $(HDIR)/DBF.h: $(IDIR)/DBF.ice $(SLICE) clean:: rm -f $(HDIR)/DBF.h +$(HDIR)/Evictor.h Evictor.cpp: $(IDIR)/Evictor.ice $(SLICE) + rm -f $(HDIR)/Evictor.h Evictor.cpp + $(SLICECMD) $(IDIR)/Evictor.ice + mv Evictor.h $(HDIR) + +clean:: + rm -f $(HDIR)/Evictor.h Evictor.cpp + +$(HDIR)/EvictorF.h: $(IDIR)/EvictorF.ice $(SLICE) + rm -f $(HDIR)/EvictorF.h EvictorF.cpp + $(SLICECMD) $(IDIR)/EvictorF.ice + mv EvictorF.h $(HDIR) + rm -f EvictorF.cpp + +clean:: + rm -f $(HDIR)/EvictorF.h + include .depend diff --git a/cpp/src/IcePack/Parser.cpp b/cpp/src/IcePack/Parser.cpp index 821ded8ead3..4f174bb1246 100644 --- a/cpp/src/IcePack/Parser.cpp +++ b/cpp/src/IcePack/Parser.cpp @@ -375,7 +375,7 @@ IcePack::Parser::parse(FILE* file, bool debug) yyin = file; assert(yyin); - _currentFile = "<standard input>"; + _currentFile = ""; _currentLine = 0; _continue = false; nextLine(); @@ -404,7 +404,7 @@ IcePack::Parser::parse(const std::string& commands, bool debug) assert(!_commands.empty()); yyin = 0; - _currentFile = "<command line>"; + _currentFile.clear(); _currentLine = 0; _continue = false; nextLine(); diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 5e187eca9be..c2580ba2e78 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -11,6 +11,16 @@ #include <IceUtil/Functional.h> #include <Slice/Parser.h> +// +// Stupid Visual C++ defines min and max as macros :-( +// +#ifdef min +# undef min +#endif +#ifdef max +# undef max +#endif + using namespace std; using namespace Slice; @@ -109,6 +119,12 @@ Slice::Contained::comment() return _comment; } +string +Slice::Contained::file() +{ + return _file; +} + Slice::Contained::Contained(const ContainerPtr& container, const string& name) : SyntaxTreeBase(container->unit()), _container(container), @@ -123,6 +139,7 @@ Slice::Contained::Contained(const ContainerPtr& container, const string& name) : assert(_unit); _unit->addContent(this); _comment = _unit->currentComment(); + _file = _unit->currentFile(); } bool @@ -133,13 +150,59 @@ Slice::operator<(Contained& l, Contained& r) return static_cast<int>(l.containedType()) < static_cast<int>(r.containedType()); } - return l.scoped() < r.scoped(); + if(l.scoped() < r.scoped()) + { + return true; + } + else if(l.scoped() != r.scoped()) + { + return false; + } + +/* + if(l.comment() < r.comment()) + { + return true; + } + else if(l.comment() != r.comment()) + { + return false; + } + + if(l.file() < r.file()) + { + return true; + } + else if(l.file() != r.file()) + { + return false; + } +*/ + + return false; } bool Slice::operator==(Contained& l, Contained& r) { - return l.scoped() == r.scoped(); + if(l.scoped() != r.scoped()) + { + return false; + } + +/* + if(l.comment() != r.comment()) + { + return false; + } + + if(l.file() != r.file()) + { + return false; + } +*/ + + return true; } // ---------------------------------------------------------------------- @@ -200,6 +263,7 @@ Slice::Container::createClassDef(const string& name, bool local, bool intf, cons { if (_unit->ignRedefs()) { + def->updateIncludeLevel(); return def; } @@ -463,7 +527,7 @@ Slice::Container::createEnum(const string& name, const StringList& enumerators) } EnumeratorPtr -Slice::Container::createEnumerator(const std::string& name) +Slice::Container::createEnumerator(const string& name) { ContainedList matches = _unit->findContents(thisScope() + name); if (!matches.empty()) @@ -769,6 +833,12 @@ Slice::Container::includeLevel() return _includeLevel; } +void +Slice::Container::updateIncludeLevel() +{ + _includeLevel = min(_includeLevel, _unit->currentIncludeLevel()); +} + bool Slice::Container::hasProxies() { @@ -898,6 +968,8 @@ Slice::Container::mergeModules() mod1->_comment.swap(mod2->_comment); } + mod1->_includeLevel = min(mod1->_includeLevel, mod2->_includeLevel); + _unit->removeContent(*q); q = _contents.erase(q); } @@ -1744,7 +1816,7 @@ Slice::Unit::ignRedefs() } void -Slice::Unit::setComment(const std::string& comment) +Slice::Unit::setComment(const string& comment) { _currentComment = ""; @@ -1762,7 +1834,7 @@ Slice::Unit::setComment(const std::string& comment) } } -std::string +string Slice::Unit::currentComment() { string comment; @@ -1770,6 +1842,12 @@ Slice::Unit::currentComment() return comment; } +string +Slice::Unit::currentFile() +{ + return _currentFile; +} + void Slice::Unit::nextLine() { @@ -1968,8 +2046,8 @@ Slice::Unit::parse(FILE* file, bool debug) _currentComment = ""; _currentLine = 1; _currentIncludeLevel = 0; - _currentFile = "<standard input>"; - _topLevelFile = _currentFile; + _currentFile.clear(); + _topLevelFile.clear(); _includeFiles.clear(); pushContainer(this); diff --git a/cpp/src/slice2docbook/Gen.cpp b/cpp/src/slice2docbook/Gen.cpp index 706950f6080..f14fcc7c63b 100644 --- a/cpp/src/slice2docbook/Gen.cpp +++ b/cpp/src/slice2docbook/Gen.cpp @@ -17,8 +17,7 @@ using namespace Slice; Slice::Gen::Gen(const string& name, const string& file, bool standAlone, bool noGlobals) : _standAlone(standAlone), _noGlobals(noGlobals), - _chapter("section"), // Could also be "chapter" - _nextId(0) + _chapter("section") // Could also be "chapter" { O.open(file.c_str()); if (!O) @@ -26,13 +25,6 @@ Slice::Gen::Gen(const string& name, const string& file, bool standAlone, bool no cerr << name << ": can't open `" << file << "' for writing: " << strerror(errno) << endl; return; } - - _idPrefix = file; - string::size_type pos = _idPrefix.find_last_of("/\\"); - if(pos != string::npos) - { - _idPrefix.erase(0, pos + 1); - } } Slice::Gen::~Gen() @@ -89,7 +81,7 @@ Slice::Gen::visitUnitEnd(const UnitPtr& p) bool Slice::Gen::visitModuleStart(const ModulePtr& p) { - start(_chapter + " id=" + scopedToId(p->scoped()), p->scoped().substr(2)); + start(_chapter + " id=" + containedToId(p), p->scoped().substr(2)); start("section", "Overview"); O.zeroIndent(); O << nl << "<synopsis>module <classname>" << p->name() << "</classname></synopsis>"; @@ -299,7 +291,7 @@ Slice::Gen::visitContainer(const ContainerPtr& p) { TypePtr type = (*q)->type(); - start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); + start("section id=" + containedToId(*q), (*q)->name()); O.zeroIndent(); O << nl << "<synopsis>sequence< " << toString(type, p) << " > <type>" << (*q)->name() @@ -318,7 +310,7 @@ Slice::Gen::visitContainer(const ContainerPtr& p) TypePtr keyType = (*q)->keyType(); TypePtr valueType = (*q)->valueType(); - start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); + start("section id=" + containedToId(*q), (*q)->name()); O.zeroIndent(); O << nl << "<synopsis>dictionary< " << toString(keyType, p) << ", " << toString(valueType, p) @@ -334,7 +326,7 @@ Slice::Gen::visitContainer(const ContainerPtr& p) { for (EnumList::iterator q = enums.begin(); q != enums.end(); ++q) { - start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); + start("section id=" + containedToId(*q), (*q)->name()); O.zeroIndent(); O << nl << "<synopsis>enum <type>" << (*q)->name() << "</type>"; @@ -361,7 +353,7 @@ Slice::Gen::visitContainer(const ContainerPtr& p) { for (NativeList::iterator q = natives.begin(); q != natives.end(); ++q) { - start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); + start("section id=" + containedToId(*q), (*q)->name()); O.zeroIndent(); O << nl << "<synopsis>native <type>" << (*q)->name() << "</type>;</synopsis>"; @@ -379,7 +371,7 @@ Slice::Gen::visitContainer(const ContainerPtr& p) bool Slice::Gen::visitClassDefStart(const ClassDefPtr& p) { - start(_chapter + " id=" + scopedToId(p->scoped()), p->scoped().substr(2)); + start(_chapter + " id=" + containedToId(p), p->scoped().substr(2)); start("section", "Overview"); O.zeroIndent(); @@ -494,7 +486,7 @@ Slice::Gen::visitClassDefStart(const ClassDefPtr& p) TypeStringList outputParams = (*q)->outputParameters(); TypeList throws = (*q)->throws(); - start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); + start("section id=" + containedToId(*q), (*q)->name()); O.zeroIndent(); O << nl << "<synopsis>" << (nonmutating ? "nonmutating " : "") @@ -556,7 +548,7 @@ Slice::Gen::visitClassDefStart(const ClassDefPtr& p) { TypePtr type = (*q)->type(); - start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); + start("section id=" + containedToId(*q), (*q)->name()); O.zeroIndent(); O << nl << "<synopsis>" << toString(type, p) << " <structfield>" << (*q)->name() @@ -577,7 +569,7 @@ Slice::Gen::visitClassDefStart(const ClassDefPtr& p) bool Slice::Gen::visitStructStart(const StructPtr& p) { - start(_chapter + " id=" + scopedToId(p->scoped()), p->scoped().substr(2)); + start(_chapter + " id=" + containedToId(p), p->scoped().substr(2)); start("section", "Overview"); O.zeroIndent(); @@ -618,7 +610,7 @@ Slice::Gen::visitStructStart(const StructPtr& p) { TypePtr type = (*q)->type(); - start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); + start("section id=" + containedToId(*q), (*q)->name()); O.zeroIndent(); O << nl << "<synopsis>" << toString(type, p) << " <structfield>" << (*q)->name() @@ -876,28 +868,44 @@ Slice::Gen::end() } string -Slice::Gen::scopedToId(const string& scoped) +Slice::Gen::containedToId(const ContainedPtr& contained) { - string s; + assert(contained); + + string scoped = contained->scoped(); if (scoped[0] == ':') { - s = scoped.substr(2); + scoped.erase(0, 2); } - else + + string id = "\""; + + id.reserve(scoped.size() + 2); // Also reserve space for the two '"' + + for (unsigned int i = 0; i < scoped.size(); ++i) { - s = scoped; + if (scoped[i] == ':') + { + id.push_back('.'); + ++i; + } + else + { + id.push_back(scoped[i]); + } } - int id = _idMap[s]; - if (id == 0) + // + // TODO: At present, docbook tools limit link names (NAMELEN) to + // 44 characters. + // + if(id.size() > 1 + 44) { - id = ++_nextId; - _idMap[s] = id; + id.erase(1 + 44); } - ostringstream result; - result << '"' << _idPrefix << '.' << id << '"'; - return result.str(); + id.push_back('"'); + return id; } string @@ -926,6 +934,10 @@ Slice::Gen::getScopedMinimized(const ContainedPtr& contained, const ContainerPtr string Slice::Gen::toString(const SyntaxTreeBasePtr& p, const ContainerPtr& container) { + string tag; + string linkend; + string s; + static const char* builtinTable[] = { "byte", @@ -945,48 +957,60 @@ Slice::Gen::toString(const SyntaxTreeBasePtr& p, const ContainerPtr& container) BuiltinPtr builtin = BuiltinPtr::dynamicCast(p); if (builtin) { - return "<type>" + string(builtinTable[builtin->kind()]) + "</type>"; + s = builtinTable[builtin->kind()]; + tag = "type"; } - string tag; - string linkend; - string s; - ProxyPtr proxy = ProxyPtr::dynamicCast(p); if (proxy) { - tag = "classname"; - linkend = scopedToId(proxy->_class()->scoped()); + linkend = containedToId(proxy->_class()); s = getScopedMinimized(proxy->_class(), container); s += "*"; + tag = "classname"; } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(p); if (cl) { - tag = "classname"; - linkend = scopedToId(cl->scoped()); + // + // We must generate the id from the definition, not from the + // declaration, provided that a definition is available. + // + ContainedPtr definition = cl->definition(); + if (definition) + { + linkend = containedToId(definition); + } s = getScopedMinimized(cl, container); + tag = "classname"; } StructPtr st = StructPtr::dynamicCast(p); if (st) { - tag = "structname"; - linkend = scopedToId(st->scoped()); + linkend = containedToId(st); s = getScopedMinimized(st, container); + tag = "structname"; } if (s.empty()) { ContainedPtr contained = ContainedPtr::dynamicCast(p); assert(contained); - tag = "type"; - linkend = scopedToId(contained->scoped()); + linkend = containedToId(contained); s = getScopedMinimized(contained, container); + tag = "type"; } - return "<link linkend=" + linkend + "><" + tag + ">" + s + "</" + tag + "></link>"; + if (linkend.empty()) + { + return "<" + tag + ">" + s + "</" + tag + ">"; + } + else + { + return "<link linkend=" + linkend + "><" + tag + ">" + s + "</" + tag + "></link>"; + } } string diff --git a/cpp/src/slice2docbook/Gen.h b/cpp/src/slice2docbook/Gen.h index c463c199be5..3d005d1f6c7 100644 --- a/cpp/src/slice2docbook/Gen.h +++ b/cpp/src/slice2docbook/Gen.h @@ -46,7 +46,7 @@ private: void start(const std::string&, const std::string&); void end(); - std::string scopedToId(const std::string&); + std::string containedToId(const ContainedPtr&); std::string getScopedMinimized(const ContainedPtr&, const ContainerPtr&); std::string toString(const SyntaxTreeBasePtr&, const ContainerPtr&); std::string toString(const std::string&, const ContainerPtr&); @@ -57,9 +57,6 @@ private: bool _noGlobals; std::string _chapter; std::stack<std::string> _elementStack; - std::string _idPrefix; - std::map<std::string, int> _idMap; - int _nextId; }; } diff --git a/cpp/src/slice2docbook/Main.cpp b/cpp/src/slice2docbook/Main.cpp index 0d5c380049c..ce1a2b7414f 100644 --- a/cpp/src/slice2docbook/Main.cpp +++ b/cpp/src/slice2docbook/Main.cpp @@ -149,7 +149,7 @@ main(int argc, char* argv[]) return EXIT_FAILURE; } - UnitPtr unit = Unit::createUnit(true, true); + UnitPtr unit = Unit::createUnit(true, false); int status = EXIT_SUCCESS; |