& functions,
DeprecatedSelector deprecatedSelector, bool labelAsHeader) {
ostringstream constantStream;
for (auto e : constants) {
writeSummaryTableEntry(&constantStream, e.second, deprecatedSelector);
}
writeSummaryTable(file, &constantStream, "Constants", deprecatedSelector, labelAsHeader);
ostringstream typeStream;
for (auto e : types) {
writeSummaryTableEntry(&typeStream, e.second, deprecatedSelector);
}
writeSummaryTable(file, &typeStream, "Types", deprecatedSelector, labelAsHeader);
ostringstream functionStream;
for (auto e : functions) {
writeSummaryTableEntry(&functionStream, e.second, deprecatedSelector);
}
writeSummaryTable(file, &functionStream, "Functions", deprecatedSelector, labelAsHeader);
}
static void writeHtmlVersionTag(GeneratedFile* file, VersionInfo info,
bool addSpacing) {
ostringstream stream;
if (info.intSize == 32) {
stream << "When compiling for 32 bits. ";
} else if (info.intSize == 64) {
stream << "When compiling for 64 bits. ";
}
if (info.minVersion > 1 || info.maxVersion) {
const char* mid =
"API level ";
if (info.minVersion <= 1) {
// No minimum
if (info.maxVersion > 0) {
stream << "Removed from " << mid << info.maxVersion + 1 << " and higher";
}
} else {
if (info.maxVersion == 0) {
// No maximum
stream << "Added in " << mid << info.minVersion;
} else {
stream << mid << info.minVersion << " - " << info.maxVersion;
}
}
stream << "";
}
string s = stream.str();
// Remove any trailing whitespace
while (s.back() == ' ') {
s.pop_back();
}
if (!s.empty()) {
*file << (addSpacing ? " " : "") << s << "\n";
}
}
static void writeDetailedTypeSpecification(GeneratedFile* file, const TypeSpecification* spec) {
switch (spec->getKind()) {
case SIMPLE: {
Type* type = spec->getType();
*file << "A typedef of: " << spec->getSimpleType()
<< makeAttributeTag(spec->getAttribute(), "", type->getDeprecatedApiLevel(),
type->getDeprecatedMessage())
<< " ";
writeHtmlVersionTag(file, spec->getVersionInfo(), false);
*file << "
\n";
break;
}
case RS_OBJECT: {
*file << "";
writeHtmlVersionTag(file, spec->getVersionInfo(), false);
*file << "
\n";
break;
}
case ENUM: {
*file << "An enum with the following values: \n";
writeHtmlVersionTag(file, spec->getVersionInfo(), false);
*file << "
\n";
*file << " \n";
const vector& values = spec->getValues();
const vector& valueComments = spec->getValueComments();
for (size_t i = 0; i < values.size(); i++) {
*file << " " << values[i] << " | ";
if (valueComments.size() > i) {
*file << valueComments[i];
}
*file << " |
\n";
}
*file << "
\n";
break;
}
case STRUCT: {
*file << "A structure with the following fields: ";
writeHtmlVersionTag(file, spec->getVersionInfo(), false);
*file << "
\n";
*file << " \n";
const vector& fields = spec->getFields();
const vector& fieldComments = spec->getFieldComments();
for (size_t i = 0; i < fields.size(); i++) {
*file << " " << fields[i] << " | ";
if (fieldComments.size() > i && !fieldComments[i].empty()) {
*file << fieldComments[i];
}
*file << " |
\n";
}
*file << "
\n";
break;
}
}
}
static void writeDetailedConstantSpecification(GeneratedFile* file, ConstantSpecification* c) {
*file << " ";
*file << "Value: " << c->getValue() << "\n";
writeHtmlVersionTag(file, c->getVersionInfo(), true);
*file << " |
\n";
*file << "
\n";
}
static bool writeOverviewForFile(GeneratedFile* file, const SpecFile& specFile) {
bool success = true;
*file << "" << specFile.getBriefDescription() << "
\n";
if (!generateHtmlParagraphs(file, specFile.getFullDescription())) {
success = false;
}
// Write the summary tables.
// file << "Summary
\n";
writeSummaryTables(file, specFile.getDocumentedConstants(), specFile.getDocumentedTypes(),
specFile.getDocumentedFunctions(), NON_DEPRECATED_ONLY, false);
return success;
}
static bool generateOverview(const string& directory) {
GeneratedFile file;
if (!file.start(directory, OVERVIEW_HTML_FILE_NAME)) {
return false;
}
bool success = true;
// Take the description from the first spec file (rs_core.spec, based on how
// currently this generator is called)
writeHeader(&file, "Runtime API Reference",
*(systemSpecification.getSpecFiles()[0]));
for (auto specFile : systemSpecification.getSpecFiles()) {
if (!writeOverviewForFile(&file, *specFile)) {
success = false;
}
}
writeFooter(&file);
file.close();
return success;
}
static bool generateAlphabeticalIndex(const string& directory) {
GeneratedFile file;
if (!file.start(directory, INDEX_HTML_FILE_NAME)) {
return false;
}
writeHeader(&file, "Index", SpecFile(""));
writeSummaryTables(&file, systemSpecification.getConstants(), systemSpecification.getTypes(),
systemSpecification.getFunctions(), NON_DEPRECATED_ONLY, true);
writeSummaryTables(&file, systemSpecification.getConstants(), systemSpecification.getTypes(),
systemSpecification.getFunctions(), DEPRECATED_ONLY, true);
writeFooter(&file);
file.close();
return true;
}
static void writeDeprecatedWarning(GeneratedFile* file, Definition* definition) {
if (definition->deprecated()) {
*file << " Deprecated. ";
string s = definition->getDeprecatedMessage();
convertDocumentationRefences(&s);
if (!s.empty()) {
*file << s;
} else {
*file << "Do not use.";
}
*file << "
\n";
}
}
static bool writeDetailedConstant(GeneratedFile* file, Constant* constant) {
if (constant->hidden()) {
return true;
}
const string& name = constant->getName();
*file << "\n";
*file << "\n";
*file << "
\n";
*file << " " << name << "\n";
*file << " : " << constant->getSummary() << "\n";
*file << "
\n";
*file << "
\n";
*file << "
\n";
auto specifications = constant->getSpecifications();
bool addSeparator = specifications.size() > 1;
for (auto spec : specifications) {
if (addSeparator) {
*file << " Variant:
\n";
}
writeDetailedConstantSpecification(file, spec);
}
*file << "
\n";
*file << "
\n";
*file << "
\n";
writeDeprecatedWarning(file, constant);
if (!generateHtmlParagraphs(file, constant->getDescription())) {
return false;
}
*file << "
\n";
*file << "
\n";
*file << "\n";
return true;
}
static bool writeDetailedType(GeneratedFile* file, Type* type) {
if (type->hidden()) {
return true;
}
const string& name = type->getName();
*file << "\n";
*file << "\n";
*file << "
\n";
*file << " " << name << "\n";
*file << " : " << type->getSummary() << "\n";
*file << "
\n";
*file << "
\n";
for (auto spec : type->getSpecifications()) {
writeDetailedTypeSpecification(file, spec);
}
writeDeprecatedWarning(file, type);
if (!generateHtmlParagraphs(file, type->getDescription())) {
return false;
}
*file << "
\n";
*file << "
\n";
*file << "\n";
return true;
}
static bool writeDetailedFunction(GeneratedFile* file, Function* function) {
if (function->hidden()) {
return true;
}
const string& name = function->getName();
*file << "\n";
*file << "\n";
*file << "
\n";
*file << " " << name << "\n";
*file << " : " << function->getSummary() << "\n";
*file << "
\n";
*file << "
\n";
map
entries;
if (!getUnifiedFunctionPrototypes(function, &entries)) {
return false;
}
*file << " \n";
for (auto i : entries) {
*file << " \n";
*file << " " << i.second.htmlDeclaration << " | \n";
*file << " ";
writeHtmlVersionTag(file, i.second.info, true);
*file << " | \n";
*file << "
\n";
}
*file << "
\n";
*file << " \n";
if (function->someParametersAreDocumented()) {
*file << "
";
*file << "
Parameters
\n";
*file << "
\n";
for (ParameterEntry* p : function->getParameters()) {
*file << " " << p->name << " | " << p->documentation << " |
\n";
}
*file << "
\n";
*file << "
\n";
}
string ret = function->getReturnDocumentation();
if (!ret.empty()) {
*file << "
";
*file << "
Returns
\n";
*file << "
\n";
*file << " " << ret << " |
\n";
*file << "
\n";
*file << "
\n";
}
*file << "
\n";
writeDeprecatedWarning(file, function);
if (!generateHtmlParagraphs(file, function->getDescription())) {
return false;
}
*file << "
\n";
*file << "
\n";
*file << "\n";
return true;
}
static bool writeDetailedDocumentationFile(const string& directory,
const SpecFile& specFile) {
if (!specFile.hasSpecifications()) {
// This is true for rs_core.spec
return true;
}
GeneratedFile file;
const string fileName = stringReplace(specFile.getSpecFileName(), ".spec",
".html");
if (!file.start(directory, fileName)) {
return false;
}
bool success = true;
string title = specFile.getBriefDescription();
writeHeader(&file, title, specFile);
file << "Overview
\n";
if (!generateHtmlParagraphs(&file, specFile.getFullDescription())) {
success = false;
}
// Write the summary tables.
file << "Summary
\n";
const auto& constants = specFile.getDocumentedConstants();
const auto& types = specFile.getDocumentedTypes();
const auto& functions = specFile.getDocumentedFunctions();
writeSummaryTables(&file, constants, types, functions, NON_DEPRECATED_ONLY, false);
writeSummaryTables(&file, constants, types, functions, DEPRECATED_ONLY, false);
// Write the full details of each constant, type, and function.
if (!constants.empty()) {
file << "Constants
\n";
for (auto i : constants) {
if (!writeDetailedConstant(&file, i.second)) {
success = false;
}
}
}
if (!types.empty()) {
file << "Types
\n";
for (auto i : types) {
if (!writeDetailedType(&file, i.second)) {
success = false;
}
}
}
if (!functions.empty()) {
file << "Functions
\n";
for (auto i : functions) {
if (!writeDetailedFunction(&file, i.second)) {
success = false;
}
}
}
writeFooter(&file);
file.close();
if (!success) {
// If in error, write a final message to make it easier to figure out which file failed.
cerr << fileName << ": Failed due to errors.\n";
}
return success;
}
static void generateSnippet(GeneratedFile* file, const string& fileName, const string& title) {
const char offset[] = " ";
*file << offset << "guide/topics/renderscript/reference/"
<< fileName << "\">\n";
*file << offset << " " << title << "\n";
*file << offset << "\n";
}
/* Generate a partial file of links that should be cut & pasted into the proper section of the
* guide_toc.cs file.
*/
static bool generateAndroidTableOfContentSnippet(const string& directory) {
GeneratedFile file;
if (!file.start(directory, "guide_toc.cs")) {
return false;
}
file << "
您还没有登录,登录后您可以:
-
收藏Android系统代码
-
收藏喜欢的文章
-
多个平台共享账号
去登录
首次使用?从这里 注册