summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Slice/Grammer.y26
-rw-r--r--cpp/src/Slice/Parser.cpp164
-rw-r--r--cpp/src/Slice/Parser.h9
-rw-r--r--cpp/src/slice2docbook/Gen.cpp101
-rw-r--r--cpp/src/slice2docbook/Gen.h3
-rw-r--r--cpp/src/slice2docbook/GenUtil.cpp114
-rw-r--r--cpp/src/slice2docbook/GenUtil.h2
-rw-r--r--cpp/src/slice2docbook/Main.cpp12
8 files changed, 300 insertions, 131 deletions
diff --git a/cpp/src/Slice/Grammer.y b/cpp/src/Slice/Grammer.y
index 32cc26d8504..78228e729e7 100644
--- a/cpp/src/Slice/Grammer.y
+++ b/cpp/src/Slice/Grammer.y
@@ -21,12 +21,6 @@ yyerror(const char* s)
unit -> error(s);
}
-void
-yyerror(const string& s)
-{
- unit -> error(s.c_str());
-}
-
%}
%token ICE_SCOPE_DELIMITOR
@@ -77,7 +71,7 @@ definitions
}
| definition
{
- yyerror("`;' missing after definition");
+ unit -> error("`;' missing after definition");
}
|
{
@@ -124,7 +118,7 @@ class_exports
}
| class_export
{
- yyerror("`;' missing after definition");
+ unit -> error("`;' missing after definition");
}
|
{
@@ -153,7 +147,7 @@ interface_exports
}
| interface_export
{
- yyerror("`;' missing after definition");
+ unit -> error("`;' missing after definition");
}
|
{
@@ -260,7 +254,7 @@ class_extends
string msg = "`";
msg += scoped -> v;
msg += "' is not a class";
- yyerror(msg);
+ unit -> error(msg);
}
else
{
@@ -270,7 +264,7 @@ class_extends
string msg = "`";
msg += scoped -> v;
msg += "' has been declared but not defined";
- yyerror(msg);
+ unit -> error(msg);
}
else
{
@@ -353,7 +347,7 @@ interface_list
string msg = "`";
msg += scoped -> v;
msg += "' is not an interface";
- yyerror(msg);
+ unit -> error(msg);
}
else
{
@@ -363,7 +357,7 @@ interface_list
string msg = "`";
msg += scoped -> v;
msg += "' has been declared but not defined";
- yyerror(msg);
+ unit -> error(msg);
}
else
{
@@ -387,7 +381,7 @@ interface_list
string msg = "`";
msg += scoped -> v;
msg += "' is not an interface";
- yyerror(msg);
+ unit -> error(msg);
}
else
{
@@ -397,7 +391,7 @@ interface_list
string msg = "`";
msg += scoped -> v;
msg += "' has been declared but not defined";
- yyerror(msg);
+ unit -> error(msg);
}
else
{
@@ -576,7 +570,7 @@ type
string msg = "`";
msg += scoped -> v;
msg += "' must be class or interface";
- yyerror(msg);
+ unit -> error(msg);
YYERROR; // Can't continue, jump to next yyerrok
}
*p = new Proxy(cl);
diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp
index 3924a2cace1..0136ff47565 100644
--- a/cpp/src/Slice/Parser.cpp
+++ b/cpp/src/Slice/Parser.cpp
@@ -207,7 +207,7 @@ Slice::Container::createModule(const string& name)
string msg = "redefinition of `";
msg += name;
msg += "' as module";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
@@ -250,7 +250,7 @@ Slice::Container::createClassDef(const string& name, bool local, bool intf,
msg += " `";
msg += name;
msg += "'";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
@@ -261,7 +261,7 @@ Slice::Container::createClassDef(const string& name, bool local, bool intf,
msg += "interface";
else
msg += "class";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
@@ -329,7 +329,7 @@ Slice::Container::createClassDecl(const string& name, bool local, bool intf)
msg += "interface";
else
msg += "class";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
@@ -376,14 +376,14 @@ Slice::Container::createVector(const string& name, const Type_ptr& type)
string msg = "redefinition of vector `";
msg += name;
msg += "'";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
string msg = "redefinition of `";
msg += name;
msg += "' as vector";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
@@ -407,14 +407,14 @@ Slice::Container::createEnum(const string& name, const StringList& enumerators)
string msg = "redefinition of enum `";
msg += name;
msg += "'";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
string msg = "redefinition of `";
msg += name;
msg += "' as enum";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
@@ -438,14 +438,14 @@ Slice::Container::createEnumerator(const std::string& name)
string msg = "redefinition of enumerator `";
msg += name;
msg += "'";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
string msg = "redefinition of `";
msg += name;
msg += "' as enumerator";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
@@ -469,14 +469,14 @@ Slice::Container::createNative(const string& name)
string msg = "redefinition of native `";
msg += name;
msg += "'";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
string msg = "redefinition of `";
msg += name;
msg += "' as native";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
@@ -486,12 +486,48 @@ Slice::Container::createNative(const string& name)
}
TypeList
-Slice::Container::lookupType(const string& scoped)
+Slice::Container::lookupType(const string& scoped, bool printError)
+{
+ assert(!scoped.empty());
+
+ static const char* builtinTable[] =
+ {
+ "byte",
+ "bool",
+ "short",
+ "int",
+ "long",
+ "float",
+ "double",
+ "string",
+ "wstring",
+ "Object",
+ "Object*",
+ "LocalObject"
+ };
+
+ for(unsigned int i = 0;
+ i < sizeof(builtinTable) / sizeof(const char*);
+ ++i)
+ {
+ if(scoped == builtinTable[i])
+ {
+ TypeList result;
+ result.push_back(unit_ -> builtin(static_cast<Builtin::Kind>(i)));
+ return result;
+ }
+ }
+
+ return lookupTypeNoBuiltin(scoped, printError);
+}
+
+TypeList
+Slice::Container::lookupTypeNoBuiltin(const string& scoped, bool printError)
{
assert(!scoped.empty());
if(scoped[0] == ':')
- return unit_ -> lookupType(scoped.substr(2));
+ return unit_ -> lookupTypeNoBuiltin(scoped.substr(2), printError);
ContainedList matches =
unit_ -> findContents(thisScope() + scoped);
@@ -500,13 +536,17 @@ Slice::Container::lookupType(const string& scoped)
Contained_ptr contained = Contained_ptr::dynamicCast(this);
if(!contained)
{
- string msg = "`";
- msg += scoped;
- msg += "' is not defined";
- yyerror(msg);
+ if(printError)
+ {
+ string msg = "`";
+ msg += scoped;
+ msg += "' is not defined";
+ unit_ -> error(msg);
+ }
return TypeList();
}
- return contained -> container() -> lookupType(scoped);
+ return contained -> container() -> lookupTypeNoBuiltin(scoped,
+ printError);
}
else
{
@@ -522,10 +562,13 @@ Slice::Container::lookupType(const string& scoped)
Type_ptr type = Type_ptr::dynamicCast(*p);
if(!type)
{
- string msg = "`";
- msg += scoped;
- msg += "' is not a type";
- yyerror(msg);
+ if(printError)
+ {
+ string msg = "`";
+ msg += scoped;
+ msg += "' is not a type";
+ unit_ -> error(msg);
+ }
return TypeList();
}
results.push_back(type);
@@ -534,6 +577,47 @@ Slice::Container::lookupType(const string& scoped)
}
}
+ContainedList
+Slice::Container::lookupContained(const string& scoped, bool printError)
+{
+ assert(!scoped.empty());
+
+ if(scoped[0] == ':')
+ return unit_ -> lookupContained(scoped.substr(2), printError);
+
+ ContainedList matches =
+ unit_ -> findContents(thisScope() + scoped);
+ if(matches.empty())
+ {
+ Contained_ptr contained = Contained_ptr::dynamicCast(this);
+ if(!contained)
+ {
+ if(printError)
+ {
+ string msg = "`";
+ msg += scoped;
+ msg += "' is not defined";
+ unit_ -> error(msg);
+ }
+ return ContainedList();
+ }
+ return contained -> container() -> lookupContained(scoped,
+ printError);
+ }
+ else
+ {
+ ContainedList results;
+ for(ContainedList::iterator p = matches.begin();
+ p != matches.end();
+ ++p)
+ {
+ if(!ClassDef_ptr::dynamicCast(*p)) // Ignore class definitions
+ results.push_back(*p);
+ }
+ return results;
+ }
+}
+
ModuleList
Slice::Container::modules()
{
@@ -796,7 +880,7 @@ Slice::Container::checkInterfaceAndLocal(const string& name, bool defined,
msg += "' was ";
msg += definedOrDeclared;
msg += " as interface";
- yyerror(msg);
+ unit_ -> error(msg);
return false;
}
@@ -807,7 +891,7 @@ Slice::Container::checkInterfaceAndLocal(const string& name, bool defined,
msg += "' was ";
msg += definedOrDeclared;
msg += " as class";
- yyerror(msg);
+ unit_ -> error(msg);
return false;
}
@@ -818,7 +902,7 @@ Slice::Container::checkInterfaceAndLocal(const string& name, bool defined,
msg += "' was ";
msg += definedOrDeclared;
msg += " local";
- yyerror(msg);
+ unit_ -> error(msg);
return false;
}
@@ -829,7 +913,7 @@ Slice::Container::checkInterfaceAndLocal(const string& name, bool defined,
msg += "' was ";
msg += definedOrDeclared;
msg += " non-local";
- yyerror(msg);
+ unit_ -> error(msg);
return false;
}
@@ -954,14 +1038,14 @@ Slice::ClassDef::createOperation(const string& name,
string msg = "redefinition of operation `";
msg += name;
msg += "'";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
string msg = "redefinition of `";
msg += name;
msg += "' as operation";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
@@ -981,7 +1065,7 @@ Slice::ClassDef::createOperation(const string& name,
string msg = "duplicate parameter `";
msg += p -> second;
msg += "'";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
++q;
@@ -999,7 +1083,7 @@ Slice::ClassDef::createOperation(const string& name,
msg = "class name `";
msg += name;
msg += "' can not be used as operation";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
@@ -1026,14 +1110,14 @@ Slice::ClassDef::createDataMember(const string& name, const Type_ptr& type)
string msg = "redefinition of data member `";
msg += name;
msg += "'";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
string msg = "redefinition of `";
msg += name;
msg += "' as data member";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
@@ -1046,7 +1130,7 @@ Slice::ClassDef::createDataMember(const string& name, const Type_ptr& type)
msg = "class name `";
msg += name;
msg += "' can not be used as data member";
- yyerror(msg);
+ unit_ -> error(msg);
return 0;
}
@@ -1538,11 +1622,23 @@ Slice::Unit::error(const char* s)
}
void
+Slice::Unit::error(const string& s)
+{
+ error(s.c_str());
+}
+
+void
Slice::Unit::warning(const char* s)
{
cerr << currentFile_ << ':' << currentLine_ << " warning: " << s << endl;
}
+void
+Slice::Unit::warning(const string& s)
+{
+ warning(s.c_str());
+}
+
Container_ptr
Slice::Unit::currentContainer()
{
diff --git a/cpp/src/Slice/Parser.h b/cpp/src/Slice/Parser.h
index 8c4d4c7a4ec..dbea3b36af2 100644
--- a/cpp/src/Slice/Parser.h
+++ b/cpp/src/Slice/Parser.h
@@ -21,8 +21,6 @@ extern int yynerrs;
int yyparse();
int yylex();
-void yyerror(const char* s);
-void yyerror(const std::string& s);
namespace Slice
{
@@ -287,7 +285,9 @@ public:
Enum_ptr createEnum(const std::string&, const StringList&);
Enumerator_ptr createEnumerator(const std::string&);
Native_ptr createNative(const std::string&);
- TypeList lookupType(const std::string&);
+ TypeList lookupType(const std::string&, bool = true);
+ TypeList lookupTypeNoBuiltin(const std::string&, bool = true);
+ ContainedList lookupContained(const std::string&, bool = true);
ModuleList modules();
ClassList classes();
VectorList vectors();
@@ -581,7 +581,10 @@ public:
int currentIncludeLevel();
void error(const char*);
+ void error(const std::string&);
+
void warning(const char*);
+ void warning(const std::string&);
Container_ptr currentContainer();
void pushContainer(const Container_ptr&);
diff --git a/cpp/src/slice2docbook/Gen.cpp b/cpp/src/slice2docbook/Gen.cpp
index 4402831102c..da6ed2415bd 100644
--- a/cpp/src/slice2docbook/Gen.cpp
+++ b/cpp/src/slice2docbook/Gen.cpp
@@ -15,7 +15,8 @@
using namespace std;
using namespace Slice;
-Slice::Gen::Gen(const string& name, const string& file)
+Slice::Gen::Gen(const string& name, const string& file, bool standAlone)
+ : standAlone_(standAlone)
{
O.open(file.c_str());
if(!O)
@@ -47,8 +48,11 @@ Slice::Gen::generate(const Unit_ptr& unit)
void
Slice::Gen::visitUnitStart(const Unit_ptr& p)
{
-// O << "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook V3.1//EN\">";
-// start("book");
+ if(standAlone_)
+ {
+ O << "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook V3.1//EN\">";
+ start("book");
+ }
printHeader();
start("chapter", "Global Module");
@@ -59,13 +63,14 @@ Slice::Gen::visitUnitStart(const Unit_ptr& p)
void
Slice::Gen::visitUnitEnd(const Unit_ptr& p)
{
-// end();
+ if(standAlone_)
+ end();
}
void
Slice::Gen::visitModuleStart(const Module_ptr& p)
{
- start("chapter", p -> scoped().substr(2));
+ start("chapter id=" + scopedToId(p -> scoped()), p -> scoped().substr(2));
start("section", "Overview");
O.zeroIndent();
O << nl << "<synopsis>module <classname>" << p -> name()
@@ -91,9 +96,7 @@ Slice::Gen::visitContainer(const Container_ptr& p)
{
start("varlistentry");
start("term");
- start("classname");
- O << nl << (*q) -> name();
- end();
+ O << nl << addLink((*q) -> name(), p);
end();
start("listitem");
printSummary(*q);
@@ -124,9 +127,7 @@ Slice::Gen::visitContainer(const Container_ptr& p)
{
start("varlistentry");
start("term");
- start("classname");
- O << nl << (*q) -> name();
- end();
+ O << nl << addLink((*q) -> name(), p);
end();
start("listitem");
printSummary(*q);
@@ -150,9 +151,7 @@ Slice::Gen::visitContainer(const Container_ptr& p)
{
start("varlistentry");
start("term");
- start("classname");
- O << nl << (*q) -> name();
- end();
+ O << nl << addLink((*q) -> name(), p);
end();
start("listitem");
printSummary(*q);
@@ -177,9 +176,7 @@ Slice::Gen::visitContainer(const Container_ptr& p)
{
start("varlistentry");
start("term");
- start("type");
- O << nl << (*q) -> name();
- end();
+ O << nl << addLink((*q) -> name(), p);
end();
start("listitem");
printSummary(*q);
@@ -204,9 +201,7 @@ Slice::Gen::visitContainer(const Container_ptr& p)
{
start("varlistentry");
start("term");
- start("type");
- O << nl << (*q) -> name();
- end();
+ O << nl << addLink((*q) -> name(), p);
end();
start("listitem");
printSummary(*q);
@@ -231,9 +226,7 @@ Slice::Gen::visitContainer(const Container_ptr& p)
{
start("varlistentry");
start("term");
- start("type");
- O << nl << (*q) -> name();
- end();
+ O << nl << addLink((*q) -> name(), p);
end();
start("listitem");
printSummary(*q);
@@ -253,7 +246,7 @@ Slice::Gen::visitContainer(const Container_ptr& p)
{
Type_ptr type = (*q) -> type();
- start("section", (*q) -> name());
+ start("section id=" + scopedToId((*q) -> scoped()), (*q) -> name());
O.zeroIndent();
O << nl << "<synopsis>vector&lt; "
@@ -270,7 +263,7 @@ Slice::Gen::visitContainer(const Container_ptr& p)
q != enums.end();
++q)
{
- start("section", (*q) -> name());
+ start("section id=" + scopedToId((*q) -> scoped()), (*q) -> name());
O.zeroIndent();
O << nl << "<synopsis>enum <type>" << (*q) -> name() << "</type>";
@@ -295,7 +288,7 @@ Slice::Gen::visitContainer(const Container_ptr& p)
q != natives.end();
++q)
{
- start("section", (*q) -> name());
+ start("section id=" + scopedToId((*q) -> scoped()), (*q) -> name());
O.zeroIndent();
O << nl << "<synopsis>native <type>" << (*q) -> name()
@@ -313,7 +306,7 @@ Slice::Gen::visitContainer(const Container_ptr& p)
void
Slice::Gen::visitClassDefStart(const ClassDef_ptr& p)
{
- start("chapter", p -> scoped().substr(2));
+ start("chapter id=" + scopedToId(p -> scoped()), p -> scoped().substr(2));
start("section", "Overview");
O.zeroIndent();
@@ -374,9 +367,7 @@ Slice::Gen::visitClassDefStart(const ClassDef_ptr& p)
{
start("varlistentry");
start("term");
- start("function");
- O << nl << (*q) -> name();
- end();
+ O << nl << addLink((*q) -> name(), p);
end();
start("listitem");
printSummary(*q);
@@ -401,9 +392,7 @@ Slice::Gen::visitClassDefStart(const ClassDef_ptr& p)
{
start("varlistentry");
start("term");
- start("function");
- O << nl << (*q) -> name();
- end();
+ O << nl << addLink((*q) -> name(), p);
end();
start("listitem");
printSummary(*q);
@@ -426,7 +415,7 @@ Slice::Gen::visitClassDefStart(const ClassDef_ptr& p)
TypeStringList outputParams = (*q) -> outputParameters();
TypeList throws = (*q) -> throws();
- start("section", (*q) -> name());
+ start("section id=" + scopedToId((*q) -> scoped()), (*q) -> name());
O.zeroIndent();
O << nl << "<synopsis>"
@@ -484,7 +473,7 @@ Slice::Gen::visitClassDefStart(const ClassDef_ptr& p)
{
Type_ptr type = (*q) -> type();
- start("section", (*q) -> name());
+ start("section id=" + scopedToId((*q) -> scoped()), (*q) -> name());
O.zeroIndent();
O << nl << "<synopsis>"
@@ -556,6 +545,10 @@ Slice::Gen::getTagged(const string& tag, string& comment)
void
Slice::Gen::printComment(const Contained_ptr& p)
{
+ Container_ptr container = Container_ptr::dynamicCast(p);
+ if(!container)
+ container = p -> container();
+
string comment = p -> comment();
StringList par = getTagged("param", comment);
StringList ret = getTagged("return", comment);
@@ -577,19 +570,19 @@ Slice::Gen::printComment(const Contained_ptr& p)
{
start("section", "Parameters");
start("variablelist");
- for(StringList::iterator p = par.begin();
- p != par.end();
- ++p)
+ for(StringList::iterator q = par.begin();
+ q != par.end();
+ ++q)
{
string::size_type pos;
string term;
- pos = p -> find_first_of(" \t\r\n");
+ pos = q -> find_first_of(" \t\r\n");
if(pos != string::npos)
- term = p -> substr(0, pos);
+ term = q -> substr(0, pos);
string item;
- pos = p -> find_first_not_of(" \t\r\n", pos);
+ pos = q -> find_first_not_of(" \t\r\n", pos);
if(pos != string::npos)
- item = p -> substr(pos);
+ item = q -> substr(pos);
start("varlistentry");
start("term");
@@ -623,23 +616,23 @@ Slice::Gen::printComment(const Contained_ptr& p)
start("section", "Exceptions");
start("variablelist");
- for(StringList::iterator p = throws.begin();
- p != throws.end();
- ++p)
+ for(StringList::iterator q = throws.begin();
+ q != throws.end();
+ ++q)
{
string::size_type pos;
string term;
- pos = p -> find_first_of(" \t\r\n");
+ pos = q -> find_first_of(" \t\r\n");
if(pos != string::npos)
- term = p -> substr(0, pos);
+ term = q -> substr(0, pos);
string item;
- pos = p -> find_first_not_of(" \t\r\n", pos);
+ pos = q -> find_first_not_of(" \t\r\n", pos);
if(pos != string::npos)
- item = p -> substr(pos);
+ item = q -> substr(pos);
start("varlistentry");
start("term");
- O << nl << term;
+ O << nl << addLink(term, container);
end();
start("listitem");
start("para");
@@ -659,12 +652,12 @@ Slice::Gen::printComment(const Contained_ptr& p)
start("para");
start("simplelist type=\"inline\"");
- for(StringList::iterator p = see.begin();
- p != see.end();
- ++p)
+ for(StringList::iterator q = see.begin();
+ q != see.end();
+ ++q)
{
start("member");
- O << nl << *p;
+ O << nl << addLink(*q, container);
end();
}
diff --git a/cpp/src/slice2docbook/Gen.h b/cpp/src/slice2docbook/Gen.h
index 45271ff0640..3e309a143c2 100644
--- a/cpp/src/slice2docbook/Gen.h
+++ b/cpp/src/slice2docbook/Gen.h
@@ -22,7 +22,7 @@ class Gen : ::__Ice::noncopyable, public ParserVisitor
{
public:
- Gen(const std::string&, const std::string&);
+ Gen(const std::string&, const std::string&, bool);
virtual ~Gen();
bool operator!() const; // Returns true if there was a constructor error
@@ -47,6 +47,7 @@ private:
Output O;
+ bool standAlone_;
std::stack<std::string> elementStack_;
};
diff --git a/cpp/src/slice2docbook/GenUtil.cpp b/cpp/src/slice2docbook/GenUtil.cpp
index 5d1ca9933c3..0c00efcd0be 100644
--- a/cpp/src/slice2docbook/GenUtil.cpp
+++ b/cpp/src/slice2docbook/GenUtil.cpp
@@ -9,6 +9,7 @@
// **********************************************************************
#include <GenUtil.h>
+#include <sstream>
using namespace std;
using namespace Slice;
@@ -32,36 +33,81 @@ Slice::typeToString(const Type_ptr& type)
"LocalObject"
};
- string result = "<type>";
-
+ string result;
+
Builtin_ptr builtin = Builtin_ptr::dynamicCast(type);
if(builtin)
- result += builtinTable[builtin -> kind()];
- else
+ result = "<type>" + string(builtinTable[builtin -> kind()])
+ + "</type>";
+
+ Proxy_ptr proxy = Proxy_ptr::dynamicCast(type);
+ if(proxy)
+ result = "<classname>" + proxy -> _class() -> scoped().substr(2) +
+ "*</classname>";
+
+ ClassDecl_ptr cl = ClassDecl_ptr::dynamicCast(type);
+ if(cl)
+ result = "<classname>" + cl -> scoped().substr(2) + "</classname>";
+
+ Contained_ptr contained = Contained_ptr::dynamicCast(type);
+ if(contained)
{
- ClassDecl_ptr cl = ClassDecl_ptr::dynamicCast(type);
- if(cl)
- result += cl -> scoped().substr(2);
- else
- {
- Proxy_ptr proxy = Proxy_ptr::dynamicCast(type);
- if(proxy)
- result += proxy -> _class() -> scoped().substr(2) + "*";
- else
- {
- Contained_ptr contained = Contained_ptr::dynamicCast(type);
- if(contained)
- result += contained -> scoped().substr(2);
- else
- result += "???";
- }
- }
+ if(result.empty())
+ result = "<type>" + contained -> scoped().substr(2) + "</type>";
+
+ result = "<link linkend=" + scopedToId(contained -> scoped()) + ">"
+ + result + "</link>";
}
- result += "</type>";
+ if(result.empty())
+ result = "???";
+
return result;
}
+string
+Slice::addLink(const string& s, const Container_ptr& container)
+{
+ TypeList types = container -> lookupType(s, false);
+ if(!types.empty())
+ {
+ string result;
+
+ if(ClassDecl_ptr::dynamicCast(types.front()))
+ result = "<classname>" + s + "</classname>";
+ else
+ result = "<type>" + s + "</type>";
+
+ Contained_ptr p = Contained_ptr::dynamicCast(types.front());
+ if(p)
+ result = "<link linkend=" + scopedToId(p -> scoped()) + ">"
+ + result + "</link>";
+
+ return result;
+ }
+
+ ContainedList contList = container -> lookupContained(s, false);
+ if(!contList.empty())
+ {
+ string result = "<link linkend=" +
+ scopedToId(contList.front() -> scoped()) + ">";
+
+ if(Module_ptr::dynamicCast(contList.front()))
+ result += "<classname>" + s + "</classname>";
+ else if(Operation_ptr::dynamicCast(contList.front()))
+ result += "<function>" + s + "</function>";
+ else if(DataMember_ptr::dynamicCast(contList.front()))
+ result += "<structfield>" + s + "</structfield>";
+ else
+ assert(false);
+
+ result += "</link>";
+ return result;
+ }
+
+ return s;
+}
+
struct ToFile
{
char operator()(char c)
@@ -85,3 +131,27 @@ Slice::scopedToFile(const string& scoped)
result += ".sgml";
return result;
}
+
+string
+Slice::scopedToId(const string& scoped)
+{
+ static map<string, int> idMap;
+ static int nextId_ = 0;
+
+ string s;
+ if(scoped[0] == ':')
+ s = scoped.substr(2);
+ else
+ s = scoped;
+
+ int id = idMap[s];
+ if(id == 0)
+ {
+ id = ++nextId_;
+ idMap[s] = id;
+ }
+
+ ostringstream result;
+ result << "\"slice2docbook." << id << '"';
+ return result.str();
+}
diff --git a/cpp/src/slice2docbook/GenUtil.h b/cpp/src/slice2docbook/GenUtil.h
index dda7183a4b1..4ecb768f497 100644
--- a/cpp/src/slice2docbook/GenUtil.h
+++ b/cpp/src/slice2docbook/GenUtil.h
@@ -18,7 +18,9 @@ namespace Slice
{
std::string typeToString(const Type_ptr&);
+std::string addLink(const std::string&, const Container_ptr&);
std::string scopedToFile(const std::string&);
+std::string scopedToId(const std::string&);
}
diff --git a/cpp/src/slice2docbook/Main.cpp b/cpp/src/slice2docbook/Main.cpp
index 498b68ed6fb..1811b8ed8be 100644
--- a/cpp/src/slice2docbook/Main.cpp
+++ b/cpp/src/slice2docbook/Main.cpp
@@ -20,6 +20,7 @@ usage(const char* n)
cerr << "Usage: " << n << " [options] docbook-file slice-files ...\n";
cerr <<
"Options:\n"
+"-s, --stand-alone Create stand-alone docbook file.\n"
"-h, --help Show this message.\n"
"-DNAME Define NAME as 1.\n"
"-DNAME=DEF Define NAME as DEF.\n"
@@ -35,6 +36,7 @@ main(int argc, char* argv[])
string cpp("cpp -C");
vector<string> includePaths;
bool debug = false;
+ bool standAlone = false;
int idx = 1;
while(idx < argc)
@@ -62,6 +64,14 @@ main(int argc, char* argv[])
argv[i] = argv[i + 1];
--argc;
}
+ else if(strcmp(argv[idx], "-s") == 0 ||
+ strcmp(argv[idx], "--stand-alone") == 0)
+ {
+ standAlone = true;
+ for(int i = idx ; i + 1 < argc ; ++i)
+ argv[i] = argv[i + 1];
+ --argc;
+ }
else if(strcmp(argv[idx], "-h") == 0 ||
strcmp(argv[idx], "--help") == 0)
{
@@ -179,7 +189,7 @@ main(int argc, char* argv[])
if(status == EXIT_SUCCESS)
{
- Gen gen(argv[0], docbook);
+ Gen gen(argv[0], docbook, standAlone);
if(!gen)
{
unit -> destroy();