diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/slice2html/Gen.cpp | 46 | ||||
-rw-r--r-- | cpp/src/slice2html/Gen.h | 10 | ||||
-rw-r--r-- | cpp/src/slice2html/Main.cpp | 18 |
3 files changed, 62 insertions, 12 deletions
diff --git a/cpp/src/slice2html/Gen.cpp b/cpp/src/slice2html/Gen.cpp index 05ccdd14f60..7a8e8847f02 100644 --- a/cpp/src/slice2html/Gen.cpp +++ b/cpp/src/slice2html/Gen.cpp @@ -33,7 +33,7 @@ namespace Slice void generate(const UnitPtr& unit, const ::std::string& dir, - const ::std::string& header, const ::std::string& footer, unsigned indexCount) + const ::std::string& header, const ::std::string& footer, unsigned indexCount, unsigned warnSummary) { unit->mergeModules(); @@ -47,6 +47,7 @@ generate(const UnitPtr& unit, const ::std::string& dir, GeneratorBase::setHeader(header); GeneratorBase::setFooter(footer); GeneratorBase::setIndexCount(indexCount); + GeneratorBase::warnSummary(warnSummary); // // The types visitor first runs over the tree and records @@ -81,6 +82,7 @@ string Slice::GeneratorBase::_header1; string Slice::GeneratorBase::_header2; string Slice::GeneratorBase::_footer; unsigned Slice::GeneratorBase::_indexCount = 0; +unsigned Slice::GeneratorBase::_warnSummary = 0; // // Set the output directory, creating it if necessary. @@ -173,6 +175,16 @@ Slice::GeneratorBase::setIndexCount(int ic) _indexCount = ic; } +// +// If n > 0, we print a warning if a summary sentence exceeds n characters. +// + +void +Slice::GeneratorBase::warnSummary(int n) +{ + _warnSummary = n; +} + Slice::GeneratorBase::GeneratorBase(XMLOutput& o, const Files& files) : _out(o), _files(files) { @@ -551,7 +563,8 @@ Slice::GeneratorBase::printSummary(const ContainedPtr& p, const ContainerPtr& mo } string -Slice::GeneratorBase::toString(const SyntaxTreeBasePtr& p, const ContainerPtr& container, bool asTarget, bool inIndex) +Slice::GeneratorBase::toString(const SyntaxTreeBasePtr& p, const ContainerPtr& container, bool asTarget, bool inIndex, + unsigned* summarySize) { string anchor; string linkpath; @@ -686,11 +699,17 @@ Slice::GeneratorBase::toString(const SyntaxTreeBasePtr& p, const ContainerPtr& c s = getScopedMinimized(contained, container); } + if(summarySize) + { + *summarySize = s.size(); + } + if(linkpath.empty() && anchor.empty()) { if(ProxyPtr::dynamicCast(p)) { s += '*'; + ++(*summarySize); } return s; } @@ -725,20 +744,21 @@ Slice::GeneratorBase::toString(const SyntaxTreeBasePtr& p, const ContainerPtr& c } string -Slice::GeneratorBase::toString(const string& str, const ContainerPtr& container, bool asTarget, bool inIndex) +Slice::GeneratorBase::toString(const string& str, const ContainerPtr& container, bool asTarget, bool inIndex, + unsigned* summarySize) { string s = str; TypeList types = container->lookupType(s, false); if(!types.empty()) { - return toString(types.front(), container, asTarget, inIndex); + return toString(types.front(), container, asTarget, inIndex, summarySize); } ContainedList contList = container->lookupContained(s, false); if(!contList.empty()) { - return toString(contList.front(), container, asTarget, inIndex); + return toString(contList.front(), container, asTarget, inIndex, summarySize); } // @@ -752,6 +772,7 @@ string Slice::GeneratorBase::getComment(const ContainedPtr& contained, const ContainerPtr& container, bool summary, bool inIndex) { + unsigned summarySize = 0; string s = contained->comment(); string comment; for(unsigned int i = 0; i < s.size(); ++i) @@ -759,6 +780,7 @@ Slice::GeneratorBase::getComment(const ContainedPtr& contained, const ContainerP if(s[i] == '\\' && i + 1 < s.size() && s[i + 1] == '[') { comment += '['; + ++summarySize; ++i; } else if(s[i] == '[') @@ -773,19 +795,29 @@ Slice::GeneratorBase::getComment(const ContainedPtr& contained, const ContainerP literal += s[i]; } - comment += toString(literal, container, false, inIndex); + unsigned sz = 0; + comment += toString(literal, container, false, inIndex, summary ? &sz : 0); + summarySize += sz; } else if(summary && s[i] == '.' && (i + 1 >= s.size() || isspace(s[i + 1]))) { comment += '.'; + ++summarySize; break; } else { comment += s[i]; + ++summarySize; } + } + if(summary && _warnSummary && summarySize > _warnSummary) + { + cerr << contained->definitionContext()->filename() << ": summary size (" << summarySize << ") exceeds " + << _warnSummary << " characters: `" << comment << "'" << endl; } + return comment; } @@ -1288,7 +1320,7 @@ Slice::ModuleGenerator::generate(const ModulePtr& m) openDoc(m); start("h1", "Symbol"); - _out << toString(m, m, true); + _out << toString(m, m->container(), true); end(); string metadata, deprecateReason; diff --git a/cpp/src/slice2html/Gen.h b/cpp/src/slice2html/Gen.h index 2f459431078..a4a2ad1edbc 100644 --- a/cpp/src/slice2html/Gen.h +++ b/cpp/src/slice2html/Gen.h @@ -16,7 +16,7 @@ namespace Slice { -void generate(const UnitPtr&, const ::std::string&, const ::std::string&, const ::std::string&, unsigned); +void generate(const UnitPtr&, const ::std::string&, const ::std::string&, const ::std::string&, unsigned, unsigned); typedef ::std::set< ::std::string> Files; @@ -27,7 +27,8 @@ public: static void setOutputDir(const ::std::string&); static void setHeader(const ::std::string&); static void setFooter(const ::std::string&); - static void setIndexCount(const int); + static void setIndexCount(int); + static void warnSummary(int); protected: @@ -45,8 +46,8 @@ protected: void printMetaData(const ContainedPtr&); void printSummary(const ContainedPtr&, const ContainerPtr&, bool); - ::std::string toString(const SyntaxTreeBasePtr&, const ContainerPtr&, bool = true, bool = false); - ::std::string toString(const ::std::string&, const ContainerPtr&, bool = true, bool = false); + ::std::string toString(const SyntaxTreeBasePtr&, const ContainerPtr&, bool = true, bool = false, unsigned* = 0); + ::std::string toString(const ::std::string&, const ContainerPtr&, bool = true, bool = false, unsigned* = 0); ::std::string getComment(const ContainedPtr&, const ContainerPtr&, bool, bool = false); static ::std::string getAnchor(const SyntaxTreeBasePtr&); @@ -55,6 +56,7 @@ protected: ::IceUtil::XMLOutput& _out; static unsigned _indexCount; + static unsigned _warnSummary; private: diff --git a/cpp/src/slice2html/Main.cpp b/cpp/src/slice2html/Main.cpp index dd3d4393ab6..a230bd0eb47 100644 --- a/cpp/src/slice2html/Main.cpp +++ b/cpp/src/slice2html/Main.cpp @@ -33,6 +33,7 @@ usage(const char* n) "--header FILE Use the contents of FILE as the header.\n" "--footer FILe Use the contents of FILE as the footer.\n" "--index NUM Generate subindex if it has at least NUM entries (0 for no index, default=1).\n" + "--summary NUM Print a warning if a summary sentence exceeds NUM characters.\n" "-d, --debug Print debug messages.\n" "--ice Permit `Ice' prefix (for building Ice source code only).\n" ; @@ -52,6 +53,7 @@ main(int argc, char* argv[]) opts.addOpt("", "header", IceUtil::Options::NeedArg); opts.addOpt("", "footer", IceUtil::Options::NeedArg); opts.addOpt("", "index", IceUtil::Options::NeedArg, "1"); + opts.addOpt("", "summary", IceUtil::Options::NeedArg, "0"); opts.addOpt("d", "debug"); opts.addOpt("", "ice"); @@ -121,6 +123,20 @@ main(int argc, char* argv[]) } } + string warnSummary = opts.optArg("summary"); + unsigned summaryCount; + if(!warnSummary.empty()) + { + istringstream s(warnSummary); + s >> summaryCount; + if(!s) + { + cerr << argv[0] << ": the --summary operation requires a positive integer argument" << endl; + usage(argv[0]); + return EXIT_FAILURE; + } + } + bool debug = opts.isSet("debug"); bool ice = opts.isSet("ice"); @@ -174,7 +190,7 @@ main(int argc, char* argv[]) { try { - Slice::generate(p, output, header, footer, indexCount); + Slice::generate(p, output, header, footer, indexCount, summaryCount); } catch(const string& err) { |