Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <iostream> |
| 18 | #include <sstream> |
| 19 | |
| 20 | #include "Generator.h" |
| 21 | #include "Specification.h" |
| 22 | #include "Utilities.h" |
| 23 | |
| 24 | using namespace std; |
| 25 | |
| 26 | struct DetailedFunctionEntry { |
| 27 | VersionInfo info; |
| 28 | string htmlDeclaration; |
| 29 | }; |
| 30 | |
| 31 | static void writeHtmlHeader(GeneratedFile* file) { |
| 32 | *file << "<!DOCTYPE html>\n"; |
| 33 | *file << "<!-- " << AUTO_GENERATED_WARNING << "-->\n"; |
| 34 | |
| 35 | *file << "<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n" |
| 36 | "<meta name='viewport' content='width=device-width'>\n" |
| 37 | "<link rel='shortcut icon' type='image/x-icon' " |
| 38 | "href='http://developer.android.com/favicon.ico'>\n" |
| 39 | "<title>android.renderscript | Android Developers</title>\n" |
| 40 | "<!-- STYLESHEETS -->\n" |
| 41 | "<link rel='stylesheet' " |
| 42 | "href='http://fonts.googleapis.com/css?family=Roboto+Condensed'>\n" |
| 43 | "<link rel='stylesheet' href='http://fonts.googleapis.com/" |
| 44 | "css?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold' " |
| 45 | "title='roboto'>\n" |
| 46 | "<link href='./test_files/default.css' rel='stylesheet' type='text/css'>\n" |
| 47 | "<!-- FULLSCREEN STYLESHEET -->\n" |
| 48 | "<link href='./test_files/fullscreen.css' rel='stylesheet' class='fullscreen' " |
| 49 | "type='text/css'>\n" |
| 50 | "<!-- JAVASCRIPT -->\n" |
| 51 | "<script src='./test_files/cb=gapi.loaded_0' async=''></script><script " |
| 52 | "type='text/javascript' async='' src='./test_files/plusone.js' " |
| 53 | "gapi_processed='true'></script><script async='' " |
| 54 | "src='./test_files/analytics.js'></script><script src='./test_files/jsapi' " |
| 55 | "type='text/javascript'></script>\n" |
| 56 | "<script src='./test_files/android_3p-bundle.js' type='text/javascript'></script>\n" |
| 57 | "<script type='text/javascript'>\n" |
| 58 | " var toRoot = '/';\n" |
| 59 | " var metaTags = [];\n" |
| 60 | " var devsite = false;\n" |
| 61 | "</script>\n" |
| 62 | "<script src='./test_files/docs.js' type='text/javascript'></script><script " |
| 63 | "type='text/javascript' src='./test_files/saved_resource'></script>\n" |
| 64 | "<script>\n" |
| 65 | " (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n" |
| 66 | " (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n" |
| 67 | " m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n" |
| 68 | " })(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n" |
| 69 | " ga('create', 'UA-5831155-1', 'android.com');\n" |
| 70 | " ga('create', 'UA-49880327-2', 'android.com', {'name': 'universal'}); // New " |
| 71 | "tracker);\n" |
| 72 | " ga('send', 'pageview');\n" |
| 73 | " ga('universal.send', 'pageview'); // Send page view for new tracker.\n" |
| 74 | "</script>\n" |
| 75 | "<link type='text/css' href='./test_files/default+en.css' rel='stylesheet'><script " |
| 76 | "type='text/javascript' src='./test_files/default+en.I.js'></script></head>\n" |
| 77 | "<body class='gc-documentation\n" |
| 78 | " develop reference'>\n"; |
| 79 | //" <div id='doc-api-level' class='11' style='display:none'></div>\n" |
| 80 | //" <a name='top'></a>\n"; |
| 81 | } |
| 82 | |
| 83 | static void writeHtmlFooter(GeneratedFile* file) { |
| 84 | *file << "</div> <!-- end body-content -->\n" |
| 85 | "</body></html>\n"; |
| 86 | } |
| 87 | |
| 88 | // If prefix starts input, copy it to stream and remove it from input. |
| 89 | static void skipPrefix(ostringstream* stream, string* input, const string& prefix) { |
| 90 | size_t size = prefix.size(); |
| 91 | if (input->compare(0, size, prefix) != 0) { |
| 92 | return; |
| 93 | } |
| 94 | input->erase(0, size); |
| 95 | *stream << prefix; |
| 96 | } |
| 97 | |
| 98 | // Merge b into a. Returns true if successful |
| 99 | static bool mergeVersionInfo(VersionInfo* a, const VersionInfo& b) { |
| 100 | if (a->intSize != b.intSize) { |
| 101 | cerr << "Error. We don't currently support versions that differ based on int size\n"; |
| 102 | return false; |
| 103 | } |
| 104 | if (b.minVersion != 0 && a->maxVersion == b.minVersion - 1) { |
| 105 | a->maxVersion = b.maxVersion; |
| 106 | } else if (b.maxVersion != 0 && a->minVersion == b.maxVersion + 1) { |
| 107 | a->minVersion = b.minVersion; |
| 108 | } else { |
| 109 | cerr << "Error. This code currently assume that all versions are contiguous. Don't know " |
| 110 | "how to merge versions (" << a->minVersion << " - " << a->maxVersion << ") and (" |
| 111 | << b.minVersion << " - " << b.maxVersion << ")\n"; |
| 112 | return false; |
| 113 | } |
| 114 | return true; |
| 115 | } |
| 116 | |
| 117 | static string getHtmlStringForType(const ParameterDefinition& parameter) { |
| 118 | string s = parameter.rsType; |
| 119 | ostringstream stream; |
| 120 | skipPrefix(&stream, &s, "const "); |
| 121 | skipPrefix(&stream, &s, "volatile "); |
| 122 | bool endsWithAsterisk = s.size() > 0 && s[s.size() - 1] == '*'; |
| 123 | if (endsWithAsterisk) { |
| 124 | s.erase(s.size() - 1, 1); |
| 125 | } |
| 126 | |
| 127 | string anchor = systemSpecification.getHtmlAnchor(s); |
| 128 | if (anchor.empty()) { |
| 129 | // Not a RenderScript specific type. |
| 130 | return parameter.rsType; |
| 131 | } else { |
| 132 | stream << anchor; |
| 133 | } |
| 134 | if (endsWithAsterisk) { |
| 135 | stream << "*"; |
| 136 | } |
| 137 | return stream.str(); |
| 138 | } |
| 139 | |
| 140 | static string getDetailedHtmlDeclaration(const FunctionPermutation& permutation) { |
| 141 | ostringstream stream; |
| 142 | auto ret = permutation.getReturn(); |
| 143 | if (ret) { |
| 144 | stream << getHtmlStringForType(*ret); |
| 145 | } else { |
| 146 | stream << "void"; |
| 147 | } |
| 148 | stream << " " << permutation.getName() << "("; |
| 149 | bool needComma = false; |
| 150 | for (auto p : permutation.getParams()) { |
| 151 | if (needComma) { |
| 152 | stream << ", "; |
| 153 | } |
| 154 | stream << getHtmlStringForType(*p); |
| 155 | if (p->isOutParameter) { |
| 156 | stream << "*"; |
| 157 | } |
| 158 | if (!p->specName.empty()) { |
| 159 | stream << " " << p->specName; |
| 160 | } |
| 161 | needComma = true; |
| 162 | } |
| 163 | stream << ");\n"; |
| 164 | return stream.str(); |
| 165 | } |
| 166 | |
| 167 | /* Some functions (like max) have changed implementations but not their |
| 168 | * declaration. We need to unify these so that we don't end up with entries |
| 169 | * like: |
| 170 | * char max(char a, char b); Removed from API level 20 |
| 171 | * char max(char a, char b); Added to API level 20 |
| 172 | */ |
| 173 | static bool getUnifiedFunctionPrototypes(Function* function, |
| 174 | map<string, DetailedFunctionEntry>* entries) { |
| 175 | for (auto f : function->getSpecifications()) { |
| 176 | DetailedFunctionEntry entry; |
| 177 | entry.info = f->getVersionInfo(); |
| 178 | for (auto p : f->getPermutations()) { |
| 179 | entry.htmlDeclaration = getDetailedHtmlDeclaration(*p); |
| 180 | const string s = stripHtml(entry.htmlDeclaration); |
| 181 | auto i = entries->find(s); |
| 182 | if (i == entries->end()) { |
| 183 | entries->insert(pair<string, DetailedFunctionEntry>(s, entry)); |
| 184 | } else { |
| 185 | if (!mergeVersionInfo(&i->second.info, entry.info)) { |
| 186 | return false; |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | return true; |
| 192 | } |
| 193 | |
| 194 | // Convert words starting with @ into HTML references. Returns false if error. |
| 195 | static bool convertDocumentationRefences(string* s) { |
| 196 | bool success = true; |
| 197 | size_t end = 0; |
| 198 | for (;;) { |
| 199 | size_t start = s->find('@', end); |
| 200 | if (start == string::npos) { |
| 201 | break; |
| 202 | } |
| 203 | // Find the end of the identifier |
| 204 | end = start; |
| 205 | char c; |
| 206 | do { |
| 207 | c = (*s)[++end]; |
| 208 | } while (isalnum(c) || c == '_'); |
| 209 | |
| 210 | const string id = s->substr(start + 1, end - start - 1); |
| 211 | string anchor = systemSpecification.getHtmlAnchor(id); |
| 212 | if (anchor.empty()) { |
| 213 | cerr << "Error: Can't convert the documentation reference @" << id << "\n"; |
| 214 | success = false; |
| 215 | } |
| 216 | s->replace(start, end - start, anchor); |
| 217 | } |
| 218 | return success; |
| 219 | } |
| 220 | |
| 221 | static bool generateHtmlParagraphs(GeneratedFile* file, const vector<string>& description) { |
| 222 | bool inParagraph = false; |
| 223 | for (auto s : description) { |
| 224 | // Empty lines in the .spec marks paragraphs. |
| 225 | if (s.empty()) { |
| 226 | if (inParagraph) { |
| 227 | *file << "</p>\n"; |
| 228 | inParagraph = false; |
| 229 | } |
| 230 | } else { |
| 231 | if (!inParagraph) { |
| 232 | *file << "<p> "; |
| 233 | inParagraph = true; |
| 234 | } |
| 235 | } |
| 236 | if (!convertDocumentationRefences(&s)) { |
| 237 | return false; |
| 238 | } |
| 239 | *file << s << "\n"; |
| 240 | } |
| 241 | if (inParagraph) { |
| 242 | *file << "</p>\n"; |
| 243 | } |
| 244 | return true; |
| 245 | } |
| 246 | |
| 247 | static void writeSummaryTableStart(GeneratedFile* file, const char* label, bool labelIsHeading) { |
| 248 | if (labelIsHeading) { |
| 249 | *file << "<h2 style='margin-bottom: 0px;'>" << label << "</h2><hr>\n"; |
| 250 | } |
| 251 | //#TODO promethods was the id. implication? |
| 252 | *file << "<table id='id" << label << "' class='jd-sumtable'><tbody>\n"; |
| 253 | if (!labelIsHeading) { |
| 254 | *file << " <tr><th colspan='12'>" << label << "</th></tr>\n"; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | static void writeSummaryTableEnd(GeneratedFile* file) { |
| 259 | *file << "</tbody></table>\n"; |
| 260 | } |
| 261 | |
| 262 | static void writeSummaryTableEntry(GeneratedFile* file, Constant* constant) { |
| 263 | if (constant->hidden()) { |
| 264 | return; |
| 265 | } |
| 266 | *file << " <tr class='alt-color api apilevel-1'>\n"; |
| 267 | *file << " <td class='jd-linkcol'><nobr>\n"; |
| 268 | *file << " <a href='" << constant->getUrl() << "'>" << constant->getName() |
| 269 | << "</a></nobr>\n"; |
| 270 | *file << " </td>\n"; |
| 271 | *file << " <td class='jd-descrcol' width='100%'><nobr>\n"; |
| 272 | *file << " " << constant->getSummary() << "\n"; |
| 273 | *file << " </td>\n"; |
| 274 | *file << " </tr>\n"; |
| 275 | } |
| 276 | |
| 277 | static void writeSummaryTableEntry(GeneratedFile* file, Type* type) { |
| 278 | if (type->hidden()) { |
| 279 | return; |
| 280 | } |
| 281 | *file << " <tr class='alt-color api apilevel-1'>\n"; |
| 282 | *file << " <td class='jd-linkcol'><nobr>\n"; |
| 283 | *file << " <a href='" << type->getUrl() << "'>" << type->getName() << "</a></nobr>\n"; |
| 284 | *file << " </td>\n"; |
| 285 | *file << " <td class='jd-descrcol' width='100%'><nobr>\n"; |
| 286 | *file << " " << type->getSummary() << "\n"; |
| 287 | *file << " </td>\n"; |
| 288 | *file << " </tr>\n"; |
| 289 | } |
| 290 | |
| 291 | static void writeSummaryTableEntry(GeneratedFile* file, Function* function) { |
| 292 | *file << " <tr class='alt-color api apilevel-1'>\n"; |
| 293 | *file << " <td class='jd-linkcol'>\n"; |
| 294 | *file << " <a href='" << function->getUrl() << "'>" << function->getName() << "</a>\n"; |
| 295 | *file << " </td>\n"; |
| 296 | *file << " <td class='jd-linkcol' width='100%'>\n"; // TODO jd-typecol |
| 297 | // *file << " <nobr><span class='sympad'></span></nobr>\n"; |
| 298 | *file << " <div class='jd-descrdiv'>\n"; |
| 299 | *file << " " << function->getSummary() << "\n"; |
| 300 | *file << " </div>\n"; |
| 301 | *file << " </td>\n"; |
| 302 | *file << " </tr>\n"; |
| 303 | } |
| 304 | |
| 305 | static void writeSummaryTables(GeneratedFile* file, const map<string, Constant*>& constants, |
| 306 | const map<string, Type*>& types, |
| 307 | const map<string, Function*>& functions, bool labelAsHeader) { |
| 308 | if (constants.size() > 0) { |
| 309 | writeSummaryTableStart(file, "Constants", labelAsHeader); |
| 310 | for (auto e : constants) { |
| 311 | writeSummaryTableEntry(file, e.second); |
| 312 | } |
| 313 | writeSummaryTableEnd(file); |
| 314 | } |
| 315 | |
| 316 | if (types.size() > 0) { |
| 317 | writeSummaryTableStart(file, "Types", labelAsHeader); |
| 318 | for (auto e : types) { |
| 319 | writeSummaryTableEntry(file, e.second); |
| 320 | } |
| 321 | writeSummaryTableEnd(file); |
| 322 | } |
| 323 | |
| 324 | if (functions.size() > 0) { |
| 325 | writeSummaryTableStart(file, "Functions", labelAsHeader); |
| 326 | for (auto e : functions) { |
| 327 | writeSummaryTableEntry(file, e.second); |
| 328 | } |
| 329 | writeSummaryTableEnd(file); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | static void writeHtmlVersionTag(GeneratedFile* file, VersionInfo info) { |
| 334 | if (info.intSize == 32) { |
| 335 | *file << "For 32 bits: "; |
| 336 | } else if (info.intSize == 64) { |
| 337 | *file << "For 64 bits: "; |
| 338 | } |
| 339 | |
| 340 | if (info.minVersion > 1 || info.maxVersion) { |
| 341 | *file << "<div>"; |
| 342 | const char* mid = |
| 343 | "<a " |
| 344 | "href='http://developer.android.com/guide/topics/manifest/" |
| 345 | "uses-sdk-element.html#ApiLevels'>API level "; |
| 346 | if (info.minVersion <= 1) { |
| 347 | // No minimum |
| 348 | if (info.maxVersion > 0) { |
| 349 | *file << "Removed from " << mid << info.maxVersion + 1; |
| 350 | } |
| 351 | } else { |
| 352 | if (info.maxVersion == 0) { |
| 353 | // No maximum |
| 354 | *file << "Added in " << mid << info.minVersion; |
| 355 | } else { |
| 356 | *file << mid << info.minVersion << " - " << info.maxVersion; |
| 357 | } |
| 358 | } |
| 359 | *file << "</a></div>\n"; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | static void writeDetailedType(GeneratedFile* file, const TypeSpecification* type) { |
| 364 | switch (type->getKind()) { |
| 365 | case SIMPLE: |
| 366 | *file << "Base type: " << type->getSimpleType() << "\n"; |
| 367 | break; |
| 368 | case ENUM: { |
| 369 | *file << "An enum<br>\n"; |
| 370 | *file << " <table class='jd-tagtable'><tbody>\n"; |
| 371 | |
| 372 | const vector<string>& values = type->getValues(); |
| 373 | const vector<string>& valueComments = type->getValueComments(); |
| 374 | for (size_t i = 0; i < values.size(); i++) { |
| 375 | *file << " <tr><th>" << values[i] << "</th>"; |
| 376 | if (valueComments.size() > i && !valueComments[i].empty()) { |
| 377 | *file << "<td>" << valueComments[i] << "</td>"; |
| 378 | } |
| 379 | *file << "</tr>\n"; |
| 380 | } |
| 381 | *file << " </tbody></table>\n"; |
| 382 | break; |
| 383 | } |
| 384 | case STRUCT: { |
| 385 | // TODO string mStructName; // The name found after the struct keyword |
| 386 | *file << "A structure<br>\n"; |
| 387 | *file << " <table class='jd-tagtable'><tbody>\n"; |
| 388 | const vector<string>& fields = type->getFields(); |
| 389 | const vector<string>& fieldComments = type->getFieldComments(); |
| 390 | for (size_t i = 0; i < fields.size(); i++) { |
| 391 | *file << " <tr><th>" << fields[i] << "</th>"; |
| 392 | if (fieldComments.size() > i && !fieldComments[i].empty()) { |
| 393 | *file << "<td>" << fieldComments[i] << "</td>"; |
| 394 | } |
| 395 | *file << "</tr>\n"; |
| 396 | } |
| 397 | *file << " </tbody></table>\n"; |
| 398 | break; |
| 399 | } |
| 400 | } |
| 401 | writeHtmlVersionTag(file, type->getVersionInfo()); |
| 402 | } |
| 403 | |
| 404 | static void writeDetailedConstant(GeneratedFile* file, ConstantSpecification* c) { |
| 405 | *file << "Value: " << c->getValue() << "\n"; |
| 406 | writeHtmlVersionTag(file, c->getVersionInfo()); |
| 407 | } |
| 408 | |
| 409 | static bool writeOverviewForFile(GeneratedFile* file, const SpecFile& specFile) { |
| 410 | bool success = true; |
| 411 | *file << "<h2>" << specFile.getBriefDescription() << "</h2>\n"; |
| 412 | if (!generateHtmlParagraphs(file, specFile.getFullDescription())) { |
| 413 | success = false; |
| 414 | } |
| 415 | |
| 416 | // Write the summary tables. |
| 417 | // file << "<h2>Summary</h2>\n"; |
Jean-Luc Brouillet | 7c07854 | 2015-03-23 16:16:08 -0700 | [diff] [blame] | 418 | writeSummaryTables(file, specFile.getDocumentedConstants(), specFile.getDocumentedTypes(), |
| 419 | specFile.getDocumentedFunctions(), false); |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 420 | return success; |
| 421 | } |
| 422 | |
Jean-Luc Brouillet | 62e0993 | 2015-03-22 11:14:07 -0700 | [diff] [blame] | 423 | static bool generateOverview(const string& directory) { |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 424 | GeneratedFile file; |
Jean-Luc Brouillet | 62e0993 | 2015-03-22 11:14:07 -0700 | [diff] [blame] | 425 | if (!file.start(directory, "index.html")) { |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 426 | return false; |
| 427 | } |
| 428 | bool success = true; |
| 429 | writeHtmlHeader(&file); |
| 430 | |
| 431 | file << "<h1 itemprop='name'>Overview</h1>\n"; |
| 432 | // TODO Have the overview text here! |
| 433 | |
| 434 | for (auto specFile : systemSpecification.getSpecFiles()) { |
| 435 | if (!writeOverviewForFile(&file, *specFile)) { |
| 436 | success = false; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | writeHtmlFooter(&file); |
| 441 | file.close(); |
| 442 | return success; |
| 443 | } |
| 444 | |
Jean-Luc Brouillet | 62e0993 | 2015-03-22 11:14:07 -0700 | [diff] [blame] | 445 | static bool generateAlphabeticalIndex(const string& directory) { |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 446 | GeneratedFile file; |
Jean-Luc Brouillet | 62e0993 | 2015-03-22 11:14:07 -0700 | [diff] [blame] | 447 | if (!file.start(directory, "alpha_index.html")) { |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 448 | return false; |
| 449 | } |
| 450 | writeHtmlHeader(&file); |
| 451 | |
| 452 | writeSummaryTables(&file, systemSpecification.getConstants(), systemSpecification.getTypes(), |
| 453 | systemSpecification.getFunctions(), true); |
| 454 | |
| 455 | writeHtmlFooter(&file); |
| 456 | file.close(); |
| 457 | return true; |
| 458 | } |
| 459 | |
| 460 | static bool writeDetailedConstant(GeneratedFile* file, Constant* constant) { |
| 461 | if (constant->hidden()) { |
| 462 | return true; |
| 463 | } |
| 464 | const string& name = constant->getName(); |
| 465 | |
| 466 | // TODO need names that distinguish fn.const. type |
| 467 | // TODO had attr_android:... |
| 468 | *file << "<a name='android_rs:" << name << "'></a>\n"; |
| 469 | *file << "<div class='jd-details'>\n"; |
| 470 | *file << " <h4 class='jd-details-title'>\n"; |
| 471 | *file << " <span class='sympad'>" << name << "</span>\n"; |
| 472 | *file << " <span class='normal'>: " << constant->getSummary() << "</span>\n"; |
| 473 | *file << " </h4>\n"; |
| 474 | |
| 475 | *file << " <div class='jd-details-descr'>\n"; |
| 476 | *file << " <table class='jd-tagtable'><tbody>\n"; |
| 477 | for (auto f : constant->getSpecifications()) { |
| 478 | *file << " <tr><td>"; |
| 479 | writeDetailedConstant(file, f); |
| 480 | *file << " </td></tr>\n"; |
| 481 | *file << "<br/>\n"; |
| 482 | } |
| 483 | *file << " </tbody></table>\n"; |
| 484 | *file << " </div>\n"; |
| 485 | |
| 486 | *file << " <div class='jd-tagdata jd-tagdescr'>\n"; |
| 487 | |
| 488 | if (!generateHtmlParagraphs(file, constant->getDescription())) { |
| 489 | return false; |
| 490 | } |
| 491 | *file << " </div>\n"; |
| 492 | |
| 493 | *file << "</div>\n"; |
| 494 | *file << "\n"; |
| 495 | return true; |
| 496 | } |
| 497 | |
| 498 | static bool writeDetailedType(GeneratedFile* file, Type* type) { |
| 499 | if (type->hidden()) { |
| 500 | return true; |
| 501 | } |
| 502 | const string& name = type->getName(); |
| 503 | |
| 504 | // TODO need names that distinguish fn.const. type |
| 505 | // TODO had attr_android:... |
| 506 | *file << "<a name='android_rs:" << name << "'></a>\n"; |
| 507 | *file << "<div class='jd-details'>\n"; |
| 508 | *file << " <h4 class='jd-details-title'>\n"; |
| 509 | *file << " <span class='sympad'>" << name << "</span>\n"; |
| 510 | *file << " <span class='normal'>: " << type->getSummary() << "</span>\n"; |
| 511 | *file << " </h4>\n"; |
| 512 | |
| 513 | *file << " <div class='jd-details-descr'>\n"; |
| 514 | *file << " <h5 class='jd-tagtitle'>Variants</h5>\n"; |
| 515 | *file << " <table class='jd-tagtable'><tbody>\n"; |
| 516 | for (auto f : type->getSpecifications()) { |
| 517 | *file << " <tr><td>"; |
| 518 | writeDetailedType(file, f); |
| 519 | *file << " </td></tr>\n"; |
| 520 | *file << "<br/>\n"; |
| 521 | } |
| 522 | *file << " </tbody></table>\n"; |
| 523 | *file << " </div>\n"; |
| 524 | |
| 525 | *file << " <div class='jd-tagdata jd-tagdescr'>\n"; |
| 526 | |
| 527 | if (!generateHtmlParagraphs(file, type->getDescription())) { |
| 528 | return false; |
| 529 | } |
| 530 | |
| 531 | *file << " </div>\n"; |
| 532 | |
| 533 | *file << "</div>\n"; |
| 534 | *file << "\n"; |
| 535 | return true; |
| 536 | } |
| 537 | |
| 538 | static bool writeDetailedFunction(GeneratedFile* file, Function* function) { |
| 539 | const string& name = function->getName(); |
| 540 | |
| 541 | // TODO need names that distinguish fn.const. type |
| 542 | // TODO had attr_android:... |
| 543 | *file << "<a name='android_rs:" << name << "'></a>\n"; |
| 544 | *file << "<div class='jd-details'>\n"; |
| 545 | *file << " <h4 class='jd-details-title'>\n"; |
| 546 | *file << " <span class='sympad'>" << name << "</span>\n"; |
| 547 | *file << " <span class='normal'>: " << function->getSummary() << "</span>\n"; |
| 548 | *file << " </h4>\n"; |
| 549 | |
| 550 | *file << " <div class='jd-details-descr'>\n"; |
| 551 | *file << " <table class='jd-tagtable'><tbody>\n"; |
| 552 | map<string, DetailedFunctionEntry> entries; |
| 553 | if (!getUnifiedFunctionPrototypes(function, &entries)) { |
| 554 | return false; |
| 555 | } |
| 556 | for (auto i : entries) { |
| 557 | *file << " <tr>\n"; |
| 558 | *file << " <td>" << i.second.htmlDeclaration << "<td/>\n"; |
| 559 | *file << " <td>"; |
| 560 | writeHtmlVersionTag(file, i.second.info); |
| 561 | *file << "</td>\n"; |
| 562 | *file << " </tr>\n"; |
| 563 | } |
| 564 | *file << " </tbody></table>\n"; |
| 565 | *file << " </div>\n"; |
| 566 | |
| 567 | if (function->someParametersAreDocumented()) { |
| 568 | *file << " <div class='jd-tagdata'>"; |
| 569 | *file << " <h5 class='jd-tagtitle'>Parameters</h5>\n"; |
| 570 | *file << " <table class='jd-tagtable'><tbody>\n"; |
| 571 | for (ParameterEntry* p : function->getParameters()) { |
| 572 | *file << " <tr><th>" << p->name << "</th><td>" << p->documentation << "</td></tr>\n"; |
| 573 | } |
| 574 | *file << " </tbody></table>\n"; |
| 575 | *file << " </div>\n"; |
| 576 | } |
| 577 | |
| 578 | string ret = function->getReturnDocumentation(); |
| 579 | if (!ret.empty()) { |
| 580 | *file << " <div class='jd-tagdata'>"; |
| 581 | *file << " <h5 class='jd-tagtitle'>Returns</h5>\n"; |
| 582 | *file << " <table class='jd-tagtable'><tbody>\n"; |
| 583 | *file << " <tr><td>" << ret << "</td></tr>\n"; |
| 584 | *file << " </tbody></table>\n"; |
| 585 | *file << " </div>\n"; |
| 586 | } |
| 587 | |
| 588 | *file << " <div class='jd-tagdata jd-tagdescr'>\n"; |
| 589 | if (!generateHtmlParagraphs(file, function->getDescription())) { |
| 590 | return false; |
| 591 | } |
| 592 | *file << " </div>\n"; |
| 593 | |
| 594 | *file << "</div>\n"; |
| 595 | *file << "\n"; |
| 596 | return true; |
| 597 | } |
| 598 | |
Jean-Luc Brouillet | 62e0993 | 2015-03-22 11:14:07 -0700 | [diff] [blame] | 599 | static bool writeDetailedDocumentationFile(const string& directory, const SpecFile& specFile) { |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 600 | GeneratedFile file; |
| 601 | const string htmlFileName = stringReplace(specFile.getSpecFileName(), ".spec", ".html"); |
Jean-Luc Brouillet | 62e0993 | 2015-03-22 11:14:07 -0700 | [diff] [blame] | 602 | if (!file.start(directory, htmlFileName)) { |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 603 | return false; |
| 604 | } |
| 605 | bool success = true; |
| 606 | |
| 607 | writeHtmlHeader(&file); |
| 608 | file << "<br/>"; |
| 609 | |
| 610 | // Write the file documentation. |
| 611 | file << "<h1 itemprop='name'>" << specFile.getBriefDescription() |
| 612 | << "</h1>\n"; // TODO not sure about itemprop |
| 613 | |
| 614 | file << "<h2>Overview</h2>\n"; |
| 615 | if (!generateHtmlParagraphs(&file, specFile.getFullDescription())) { |
| 616 | success = false; |
| 617 | } |
| 618 | |
| 619 | // Write the summary tables. |
| 620 | file << "<h2>Summary</h2>\n"; |
Jean-Luc Brouillet | 7c07854 | 2015-03-23 16:16:08 -0700 | [diff] [blame] | 621 | const auto& constants = specFile.getDocumentedConstants(); |
| 622 | const auto& types = specFile.getDocumentedTypes(); |
| 623 | const auto& functions = specFile.getDocumentedFunctions(); |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 624 | writeSummaryTables(&file, constants, types, functions, false); |
| 625 | |
| 626 | // Write the full details of each constant, type, and function. |
| 627 | if (!constants.empty()) { |
| 628 | file << "<h2>Constants</h2>\n"; |
| 629 | for (auto i : constants) { |
| 630 | if (!writeDetailedConstant(&file, i.second)) { |
| 631 | success = false; |
| 632 | } |
| 633 | } |
| 634 | } |
| 635 | if (!types.empty()) { |
| 636 | file << "<h2>Types</h2>\n"; |
| 637 | for (auto i : types) { |
| 638 | if (!writeDetailedType(&file, i.second)) { |
| 639 | success = false; |
| 640 | } |
| 641 | } |
| 642 | } |
| 643 | if (!functions.empty()) { |
| 644 | file << "<h2>Functions</h2>\n"; |
| 645 | for (auto i : functions) { |
| 646 | if (!writeDetailedFunction(&file, i.second)) { |
| 647 | success = false; |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | writeHtmlFooter(&file); |
| 653 | file.close(); |
| 654 | |
| 655 | if (!success) { |
| 656 | // If in error, write a final message to make it easier to figure out which file failed. |
| 657 | cerr << htmlFileName << ": Failed due to errors.\n"; |
| 658 | } |
| 659 | return success; |
| 660 | } |
| 661 | |
Jean-Luc Brouillet | 62e0993 | 2015-03-22 11:14:07 -0700 | [diff] [blame] | 662 | bool generateHtmlDocumentation(const string& directory) { |
| 663 | bool success = generateOverview(directory) && generateAlphabeticalIndex(directory); |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 664 | for (auto specFile : systemSpecification.getSpecFiles()) { |
Jean-Luc Brouillet | 62e0993 | 2015-03-22 11:14:07 -0700 | [diff] [blame] | 665 | if (!writeDetailedDocumentationFile(directory, *specFile)) { |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 666 | success = false; |
| 667 | } |
| 668 | } |
| 669 | return success; |
| 670 | } |