2017-07-28 15:04:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bookmaker.h"
|
|
|
|
|
|
|
|
#include "SkOSFile.h"
|
|
|
|
#include "SkOSPath.h"
|
|
|
|
|
2018-01-04 21:11:51 +00:00
|
|
|
#define FPRINTF(...) \
|
|
|
|
if (fDebugOut) { \
|
|
|
|
SkDebugf(__VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
fprintf(fOut, __VA_ARGS__)
|
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
static void add_ref(string leadingSpaces, string ref, string* result) {
|
2017-07-28 15:04:54 +00:00
|
|
|
*result += leadingSpaces + ref;
|
|
|
|
}
|
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
static string preformat(string orig) {
|
2017-10-04 18:31:33 +00:00
|
|
|
string result;
|
|
|
|
for (auto c : orig) {
|
|
|
|
if ('<' == c) {
|
|
|
|
result += "<";
|
|
|
|
} else if ('>' == c) {
|
|
|
|
result += ">";
|
|
|
|
} else {
|
|
|
|
result += c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
static bool all_lower(string ref) {
|
2018-01-26 17:56:22 +00:00
|
|
|
for (auto ch : ref) {
|
|
|
|
if (!islower(ch)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
// FIXME: preserve inter-line spaces and don't add new ones
|
|
|
|
string MdOut::addReferences(const char* refStart, const char* refEnd,
|
|
|
|
BmhParser::Resolvable resolvable) {
|
|
|
|
string result;
|
|
|
|
MethodParser t(fRoot ? fRoot->fName : string(), fFileName, refStart, refEnd, fLineCount);
|
|
|
|
bool lineStart = true;
|
|
|
|
string ref;
|
|
|
|
string leadingSpaces;
|
2017-09-14 15:25:39 +00:00
|
|
|
int distFromParam = 99;
|
2017-07-28 15:04:54 +00:00
|
|
|
do {
|
2017-09-14 15:25:39 +00:00
|
|
|
++distFromParam;
|
2017-07-28 15:04:54 +00:00
|
|
|
const char* base = t.fChar;
|
|
|
|
t.skipWhiteSpace();
|
|
|
|
const char* wordStart = t.fChar;
|
2018-04-16 12:37:38 +00:00
|
|
|
if (BmhParser::Resolvable::kFormula == resolvable && !t.eof() && '"' == t.peek()) {
|
|
|
|
t.next();
|
|
|
|
t.skipToEndBracket('"');
|
|
|
|
t.next();
|
|
|
|
continue;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
t.skipToMethodStart();
|
|
|
|
const char* start = t.fChar;
|
|
|
|
if (wordStart < start) {
|
|
|
|
if (lineStart) {
|
|
|
|
lineStart = false;
|
|
|
|
} else {
|
|
|
|
wordStart = base;
|
|
|
|
}
|
|
|
|
result += string(wordStart, start - wordStart);
|
|
|
|
if ('\n' != result.back()) {
|
|
|
|
while (start > wordStart && '\n' == start[-1]) {
|
|
|
|
result += '\n';
|
|
|
|
--start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lineStart) {
|
|
|
|
lineStart = false;
|
|
|
|
} else {
|
|
|
|
leadingSpaces = string(base, wordStart - base);
|
2017-11-27 15:44:06 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
t.skipToMethodEnd();
|
|
|
|
if (base == t.fChar) {
|
2018-01-04 21:11:51 +00:00
|
|
|
if (!t.eof() && '~' == base[0] && !isalnum(base[1])) {
|
|
|
|
t.next();
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
if (start >= t.fChar) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!t.eof() && '"' == t.peek() && start > wordStart && '"' == start[-1]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ref = string(start, t.fChar - start);
|
2018-04-03 12:43:27 +00:00
|
|
|
if (const Definition* def = this->isDefined(t, ref, resolvable)) {
|
2018-01-04 21:11:51 +00:00
|
|
|
if (MarkType::kExternal == def->fMarkType) {
|
|
|
|
add_ref(leadingSpaces, ref, &result);
|
|
|
|
continue;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
SkASSERT(def->fFiddle.length());
|
|
|
|
if (!t.eof() && '(' == t.peek() && t.strnchr(')', t.fEnd)) {
|
|
|
|
if (!t.skipToEndBracket(')')) {
|
|
|
|
t.reportError("missing close paren");
|
2018-03-12 12:26:45 +00:00
|
|
|
fAddRefFailed = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
t.next();
|
|
|
|
string fullRef = string(start, t.fChar - start);
|
|
|
|
// if _2 etc alternates are defined, look for paren match
|
|
|
|
// may ignore () if ref is all lower case
|
|
|
|
// otherwise flag as error
|
|
|
|
int suffix = '2';
|
|
|
|
bool foundMatch = false;
|
|
|
|
const Definition* altDef = def;
|
|
|
|
while (altDef && suffix <= '9') {
|
|
|
|
if ((foundMatch = altDef->paramsMatch(fullRef, ref))) {
|
|
|
|
def = altDef;
|
|
|
|
ref = fullRef;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
string altTest = ref + '_';
|
|
|
|
altTest += suffix++;
|
2018-04-03 12:43:27 +00:00
|
|
|
altDef = this->isDefined(t, altTest, BmhParser::Resolvable::kOut);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
if (suffix > '9') {
|
|
|
|
t.reportError("too many alts");
|
2018-03-12 12:26:45 +00:00
|
|
|
fAddRefFailed = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (!foundMatch) {
|
2018-04-03 12:43:27 +00:00
|
|
|
if (!(def = this->isDefined(t, fullRef, resolvable))) {
|
|
|
|
if (BmhParser::Resolvable::kFormula == resolvable) {
|
|
|
|
// TODO: look for looser mapping -- if methods name match, look for
|
|
|
|
// unique mapping based on number of parameters
|
|
|
|
// for now, just look for function name match
|
|
|
|
def = this->isDefined(t, ref, resolvable);
|
|
|
|
}
|
|
|
|
if (!def && !result.size()) {
|
2017-08-04 16:48:24 +00:00
|
|
|
t.reportError("missing method");
|
2018-03-12 12:26:45 +00:00
|
|
|
fAddRefFailed = true;
|
2018-04-03 12:43:27 +00:00
|
|
|
return result;
|
2017-08-04 16:48:24 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
ref = fullRef;
|
|
|
|
}
|
2018-01-26 17:56:22 +00:00
|
|
|
} else if (BmhParser::Resolvable::kClone != resolvable &&
|
|
|
|
all_lower(ref) && (t.eof() || '(' != t.peek())) {
|
|
|
|
add_ref(leadingSpaces, ref, &result);
|
|
|
|
continue;
|
|
|
|
}
|
2018-04-03 12:43:27 +00:00
|
|
|
if (!def) {
|
|
|
|
t.reportError("missing method");
|
|
|
|
fAddRefFailed = true;
|
|
|
|
return result;
|
|
|
|
}
|
2018-01-26 17:56:22 +00:00
|
|
|
result += linkRef(leadingSpaces, def, ref, resolvable);
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!t.eof() && '(' == t.peek()) {
|
|
|
|
if (!t.skipToEndBracket(')')) {
|
|
|
|
t.reportError("missing close paren");
|
2018-03-12 12:26:45 +00:00
|
|
|
fAddRefFailed = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
t.next();
|
|
|
|
ref = string(start, t.fChar - start);
|
2018-04-03 12:43:27 +00:00
|
|
|
if (const Definition* def = this->isDefined(t, ref, BmhParser::Resolvable::kYes)) {
|
2017-07-28 15:04:54 +00:00
|
|
|
SkASSERT(def->fFiddle.length());
|
2018-01-26 17:56:22 +00:00
|
|
|
result += linkRef(leadingSpaces, def, ref, resolvable);
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// class, struct, and enum start with capitals
|
|
|
|
// methods may start with upper (static) or lower (most)
|
|
|
|
|
|
|
|
// see if this should have been a findable reference
|
2017-10-09 19:45:33 +00:00
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
// look for Sk / sk / SK ..
|
|
|
|
if (!ref.compare(0, 2, "Sk") && ref != "Skew" && ref != "Skews" &&
|
|
|
|
ref != "Skip" && ref != "Skips") {
|
2018-04-16 12:37:38 +00:00
|
|
|
if (BmhParser::Resolvable::kOut != resolvable &&
|
|
|
|
BmhParser::Resolvable::kFormula != resolvable) {
|
2018-03-05 18:26:16 +00:00
|
|
|
t.reportError("missed Sk prefixed");
|
2018-03-12 12:26:45 +00:00
|
|
|
fAddRefFailed = true;
|
2018-04-03 12:43:27 +00:00
|
|
|
return result;
|
2018-03-05 18:26:16 +00:00
|
|
|
}
|
2017-10-09 19:45:33 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!ref.compare(0, 2, "SK")) {
|
2018-04-16 12:37:38 +00:00
|
|
|
if (BmhParser::Resolvable::kOut != resolvable &&
|
|
|
|
BmhParser::Resolvable::kFormula != resolvable) {
|
2017-07-28 15:04:54 +00:00
|
|
|
t.reportError("missed SK prefixed");
|
2018-03-12 12:26:45 +00:00
|
|
|
fAddRefFailed = true;
|
2018-04-03 12:43:27 +00:00
|
|
|
return result;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2017-10-09 19:45:33 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!isupper(start[0])) {
|
|
|
|
// TODO:
|
|
|
|
// look for all lowercase w/o trailing parens as mistaken method matches
|
|
|
|
// will also need to see if Example Description matches var in example
|
2018-04-16 12:37:38 +00:00
|
|
|
const Definition* def = nullptr;
|
2017-07-28 15:04:54 +00:00
|
|
|
if (fMethod && (def = fMethod->hasParam(ref))) {
|
2018-01-26 17:56:22 +00:00
|
|
|
result += linkRef(leadingSpaces, def, ref, resolvable);
|
2017-09-14 15:25:39 +00:00
|
|
|
fLastParam = def;
|
|
|
|
distFromParam = 0;
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
2017-10-09 19:45:33 +00:00
|
|
|
} else if (!fInDescription && ref[0] != '0'
|
2017-07-28 15:04:54 +00:00
|
|
|
&& string::npos != ref.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ")) {
|
|
|
|
// FIXME: see isDefined(); check to see if fXX is a member of xx.fXX
|
|
|
|
if (('f' != ref[0] && string::npos == ref.find("()"))
|
2017-08-03 21:14:08 +00:00
|
|
|
// || '.' != t.backup(ref.c_str())
|
|
|
|
&& ('k' != ref[0] && string::npos == ref.find("_Private"))) {
|
2017-10-04 18:31:33 +00:00
|
|
|
if ('.' == wordStart[0] && (distFromParam >= 1 && distFromParam <= 16)) {
|
2017-09-14 15:25:39 +00:00
|
|
|
const Definition* paramType = this->findParamType();
|
|
|
|
if (paramType) {
|
|
|
|
string fullName = paramType->fName + "::" + ref;
|
2018-01-11 15:35:44 +00:00
|
|
|
if (paramType->hasMatch(fullName)) {
|
2018-01-26 17:56:22 +00:00
|
|
|
result += linkRef(leadingSpaces, paramType, ref, resolvable);
|
2017-09-14 15:25:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-03 12:43:27 +00:00
|
|
|
if (BmhParser::Resolvable::kOut != resolvable &&
|
|
|
|
BmhParser::Resolvable::kFormula != resolvable) {
|
2017-07-28 15:04:54 +00:00
|
|
|
t.reportError("missed camelCase");
|
2018-03-12 12:26:45 +00:00
|
|
|
fAddRefFailed = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_ref(leadingSpaces, ref, &result);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto topicIter = fBmhParser.fTopicMap.find(ref);
|
|
|
|
if (topicIter != fBmhParser.fTopicMap.end()) {
|
2018-01-26 17:56:22 +00:00
|
|
|
result += linkRef(leadingSpaces, topicIter->second, ref, resolvable);
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bool startsSentence = t.sentenceEnd(start);
|
|
|
|
if (!t.eof() && ' ' != t.peek()) {
|
2018-01-26 17:56:22 +00:00
|
|
|
add_ref(leadingSpaces, ref, &result);
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (t.fChar + 1 >= t.fEnd || (!isupper(t.fChar[1]) && startsSentence)) {
|
2018-01-26 17:56:22 +00:00
|
|
|
add_ref(leadingSpaces, ref, &result);
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isupper(t.fChar[1]) && startsSentence) {
|
|
|
|
TextParser next(t.fFileName, &t.fChar[1], t.fEnd, t.fLineCount);
|
|
|
|
string nextWord(next.fChar, next.wordEnd() - next.fChar);
|
2018-04-03 12:43:27 +00:00
|
|
|
if (this->isDefined(t, nextWord, BmhParser::Resolvable::kYes)) {
|
2018-01-26 17:56:22 +00:00
|
|
|
add_ref(leadingSpaces, ref, &result);
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2018-02-01 14:37:32 +00:00
|
|
|
const Definition* test = fRoot;
|
2017-07-28 15:04:54 +00:00
|
|
|
do {
|
|
|
|
if (!test->isRoot()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (string prefix : { "_", "::" } ) {
|
2018-02-01 14:37:32 +00:00
|
|
|
const RootDefinition* root = test->asRoot();
|
2017-07-28 15:04:54 +00:00
|
|
|
string prefixed = root->fName + prefix + ref;
|
2017-09-01 19:51:02 +00:00
|
|
|
if (const Definition* def = root->find(prefixed,
|
|
|
|
RootDefinition::AllowParens::kYes)) {
|
2018-01-26 17:56:22 +00:00
|
|
|
result += linkRef(leadingSpaces, def, ref, resolvable);
|
2017-07-28 15:04:54 +00:00
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while ((test = test->fParent));
|
|
|
|
found:
|
|
|
|
if (!test) {
|
2018-04-16 12:37:38 +00:00
|
|
|
if (BmhParser::Resolvable::kOut != resolvable &&
|
|
|
|
BmhParser::Resolvable::kFormula != resolvable) {
|
2017-07-28 15:04:54 +00:00
|
|
|
t.reportError("undefined reference");
|
2018-03-12 12:26:45 +00:00
|
|
|
fAddRefFailed = true;
|
2018-04-03 12:43:27 +00:00
|
|
|
} else {
|
|
|
|
add_ref(leadingSpaces, ref, &result);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (!t.eof());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-02-27 14:54:21 +00:00
|
|
|
|
|
|
|
|
2018-04-03 12:43:27 +00:00
|
|
|
bool MdOut::buildReferences(const IncludeParser& includeParser, const char* docDir,
|
|
|
|
const char* mdFileOrPath) {
|
2018-01-04 21:11:51 +00:00
|
|
|
if (!sk_isdir(mdFileOrPath)) {
|
2018-04-03 12:43:27 +00:00
|
|
|
SkDebugf("must pass directory %s\n", mdFileOrPath);
|
|
|
|
SkDebugf("pass -i SkXXX.h to build references for a single include\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
SkOSFile::Iter it(docDir, ".bmh");
|
|
|
|
for (SkString file; it.next(&file); ) {
|
|
|
|
if (!includeParser.references(file)) {
|
|
|
|
continue;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-04-03 12:43:27 +00:00
|
|
|
SkString p = SkOSPath::Join(docDir, file.c_str());
|
|
|
|
if (!this->buildRefFromFile(p.c_str(), mdFileOrPath)) {
|
|
|
|
SkDebugf("failed to parse %s\n", p.c_str());
|
|
|
|
return false;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-11 21:03:17 +00:00
|
|
|
bool MdOut::buildStatus(const char* statusFile, const char* outDir) {
|
|
|
|
StatusIter iter(statusFile, ".bmh", StatusFilter::kInProgress);
|
|
|
|
for (string file; iter.next(&file); ) {
|
|
|
|
SkString p = SkOSPath::Join(iter.baseDir().c_str(), file.c_str());
|
|
|
|
const char* hunk = p.c_str();
|
|
|
|
if (!this->buildRefFromFile(hunk, outDir)) {
|
|
|
|
SkDebugf("failed to parse %s\n", hunk);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
bool MdOut::buildRefFromFile(const char* name, const char* outDir) {
|
2018-02-27 14:54:21 +00:00
|
|
|
if (!SkStrEndsWith(name, ".bmh")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (SkStrEndsWith(name, "markup.bmh")) { // don't look inside this for now
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (SkStrEndsWith(name, "illustrations.bmh")) { // don't look inside this for now
|
|
|
|
return true;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
fFileName = string(name);
|
|
|
|
string filename(name);
|
|
|
|
if (filename.substr(filename.length() - 4) == ".bmh") {
|
|
|
|
filename = filename.substr(0, filename.length() - 4);
|
|
|
|
}
|
|
|
|
size_t start = filename.length();
|
|
|
|
while (start > 0 && (isalnum(filename[start - 1]) || '_' == filename[start - 1])) {
|
|
|
|
--start;
|
|
|
|
}
|
|
|
|
string match = filename.substr(start);
|
|
|
|
string header = match;
|
2017-07-28 19:27:45 +00:00
|
|
|
filename = match + ".md";
|
2017-07-28 15:04:54 +00:00
|
|
|
match += ".bmh";
|
|
|
|
fOut = nullptr;
|
2017-09-14 15:25:39 +00:00
|
|
|
string fullName;
|
2017-12-11 21:03:17 +00:00
|
|
|
|
|
|
|
vector<string> keys;
|
|
|
|
keys.reserve(fBmhParser.fTopicMap.size());
|
|
|
|
for (const auto& it : fBmhParser.fTopicMap) {
|
|
|
|
keys.push_back(it.first);
|
|
|
|
}
|
|
|
|
std::sort(keys.begin(), keys.end());
|
|
|
|
for (auto key : keys) {
|
|
|
|
string s(key);
|
|
|
|
auto topicDef = fBmhParser.fTopicMap.at(s);
|
2017-07-28 15:04:54 +00:00
|
|
|
if (topicDef->fParent) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!topicDef->isRoot()) {
|
2018-03-12 12:26:45 +00:00
|
|
|
fAddRefFailed = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
return this->reportError<bool>("expected root topic");
|
|
|
|
}
|
|
|
|
fRoot = topicDef->asRoot();
|
|
|
|
if (string::npos == fRoot->fFileName.rfind(match)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!fOut) {
|
2017-09-14 15:25:39 +00:00
|
|
|
fullName = outDir;
|
2017-07-28 15:04:54 +00:00
|
|
|
if ('/' != fullName.back()) {
|
|
|
|
fullName += '/';
|
|
|
|
}
|
|
|
|
fullName += filename;
|
2018-01-04 21:11:51 +00:00
|
|
|
fOut = fopen(filename.c_str(), "wb");
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!fOut) {
|
|
|
|
SkDebugf("could not open output file %s\n", fullName.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-09 18:43:00 +00:00
|
|
|
size_t underscorePos = header.find('_');
|
|
|
|
if (string::npos != underscorePos) {
|
2017-07-28 19:27:45 +00:00
|
|
|
header.replace(underscorePos, 1, " ");
|
|
|
|
}
|
|
|
|
SkASSERT(string::npos == header.find('_'));
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("%s", header.c_str());
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lfAlways(1);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("===");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-02-07 12:27:09 +00:00
|
|
|
fPopulators.clear();
|
2018-02-01 14:37:32 +00:00
|
|
|
fPopulators[kClassesAndStructs].fDescription = "embedded struct and class members";
|
|
|
|
fPopulators[kConstants].fDescription = "enum and enum class, const values";
|
|
|
|
fPopulators[kConstructors].fDescription = "functions that construct";
|
2018-04-16 12:37:38 +00:00
|
|
|
fPopulators[kDefines].fDescription = "preprocessor definitions of functions, values";
|
2018-02-01 14:37:32 +00:00
|
|
|
fPopulators[kMemberFunctions].fDescription = "static functions and member methods";
|
|
|
|
fPopulators[kMembers].fDescription = "member values";
|
|
|
|
fPopulators[kOperators].fDescription = "operator overloading methods";
|
|
|
|
fPopulators[kRelatedFunctions].fDescription = "similar methods grouped together";
|
|
|
|
fPopulators[kSubtopics].fDescription = "";
|
2018-04-16 12:37:38 +00:00
|
|
|
fPopulators[kTypedefs].fDescription = "types defined by other types";
|
2018-02-01 14:37:32 +00:00
|
|
|
this->populateTables(fRoot);
|
2017-07-28 15:04:54 +00:00
|
|
|
this->markTypeOut(topicDef);
|
|
|
|
}
|
|
|
|
if (fOut) {
|
|
|
|
this->writePending();
|
|
|
|
fclose(fOut);
|
2018-01-04 21:11:51 +00:00
|
|
|
fflush(fOut);
|
|
|
|
if (this->writtenFileDiffers(filename, fullName)) {
|
|
|
|
fOut = fopen(fullName.c_str(), "wb");
|
|
|
|
int writtenSize;
|
|
|
|
const char* written = ReadToBuffer(filename, &writtenSize);
|
|
|
|
fwrite(written, 1, writtenSize, fOut);
|
|
|
|
fclose(fOut);
|
|
|
|
fflush(fOut);
|
|
|
|
SkDebugf("wrote updated %s\n", fullName.c_str());
|
|
|
|
}
|
|
|
|
remove(filename.c_str());
|
2017-07-28 15:04:54 +00:00
|
|
|
fOut = nullptr;
|
|
|
|
}
|
2018-03-12 12:26:45 +00:00
|
|
|
return !fAddRefFailed;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
2018-03-12 12:26:45 +00:00
|
|
|
bool MdOut::checkParamReturnBody(const Definition* def) {
|
2017-08-30 12:58:10 +00:00
|
|
|
TextParser paramBody(def);
|
|
|
|
const char* descriptionStart = paramBody.fChar;
|
2017-10-26 11:58:48 +00:00
|
|
|
if (!islower(descriptionStart[0]) && !isdigit(descriptionStart[0])) {
|
2018-04-16 12:37:38 +00:00
|
|
|
paramBody.skipToNonName();
|
2017-08-30 12:58:10 +00:00
|
|
|
string ref = string(descriptionStart, paramBody.fChar - descriptionStart);
|
2018-04-03 12:43:27 +00:00
|
|
|
if (!this->isDefined(paramBody, ref, BmhParser::Resolvable::kYes)) {
|
2017-08-30 12:58:10 +00:00
|
|
|
string errorStr = MarkType::kReturn == def->fMarkType ? "return" : "param";
|
|
|
|
errorStr += " description must start with lower case";
|
|
|
|
paramBody.reportError(errorStr.c_str());
|
2018-03-12 12:26:45 +00:00
|
|
|
fAddRefFailed = true;
|
2017-08-30 12:58:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ('.' == paramBody.fEnd[-1]) {
|
|
|
|
paramBody.reportError("make param description a phrase; should not end with period");
|
2018-03-12 12:26:45 +00:00
|
|
|
fAddRefFailed = true;
|
2017-08-30 12:58:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
void MdOut::childrenOut(const Definition* def, const char* start) {
|
|
|
|
const char* end;
|
|
|
|
fLineCount = def->fLineCount;
|
|
|
|
if (def->isRoot()) {
|
|
|
|
fRoot = const_cast<RootDefinition*>(def->asRoot());
|
2017-08-03 21:14:08 +00:00
|
|
|
} else if (MarkType::kEnumClass == def->fMarkType) {
|
|
|
|
fEnumClass = def;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2017-10-26 11:58:48 +00:00
|
|
|
BmhParser::Resolvable resolvable = this->resolvable(def);
|
2017-07-28 15:04:54 +00:00
|
|
|
for (auto& child : def->fChildren) {
|
|
|
|
end = child->fStart;
|
|
|
|
if (BmhParser::Resolvable::kNo != resolvable) {
|
|
|
|
this->resolveOut(start, end, resolvable);
|
|
|
|
}
|
|
|
|
this->markTypeOut(child);
|
|
|
|
start = child->fTerminator;
|
|
|
|
}
|
|
|
|
if (BmhParser::Resolvable::kNo != resolvable) {
|
|
|
|
end = def->fContentEnd;
|
|
|
|
this->resolveOut(start, end, resolvable);
|
|
|
|
}
|
2017-08-03 21:14:08 +00:00
|
|
|
if (MarkType::kEnumClass == def->fMarkType) {
|
|
|
|
fEnumClass = nullptr;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-01 14:37:32 +00:00
|
|
|
const Definition* MdOut::csParent() const {
|
|
|
|
const Definition* csParent = fRoot->csParent();
|
|
|
|
if (!csParent) {
|
|
|
|
const Definition* topic = fRoot;
|
|
|
|
while (topic && MarkType::kTopic != topic->fMarkType) {
|
|
|
|
topic = topic->fParent;
|
|
|
|
}
|
|
|
|
for (auto child : topic->fChildren) {
|
|
|
|
if (child->isStructOrClass() || MarkType::kTypedef == child->fMarkType) {
|
|
|
|
csParent = child;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkASSERT(csParent || string::npos == fRoot->fFileName.find("Sk"));
|
|
|
|
}
|
|
|
|
return csParent;
|
|
|
|
}
|
|
|
|
|
2017-09-14 15:25:39 +00:00
|
|
|
const Definition* MdOut::findParamType() {
|
|
|
|
SkASSERT(fMethod);
|
|
|
|
TextParser parser(fMethod->fFileName, fMethod->fStart, fMethod->fContentStart,
|
|
|
|
fMethod->fLineCount);
|
|
|
|
string lastFull;
|
|
|
|
do {
|
|
|
|
parser.skipToAlpha();
|
|
|
|
if (parser.eof()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const char* word = parser.fChar;
|
|
|
|
parser.skipFullName();
|
|
|
|
SkASSERT(!parser.eof());
|
|
|
|
string name = string(word, parser.fChar - word);
|
|
|
|
if (fLastParam->fName == name) {
|
2018-04-03 12:43:27 +00:00
|
|
|
const Definition* paramType = this->isDefined(parser, lastFull,
|
|
|
|
BmhParser::Resolvable::kOut);
|
2017-09-14 15:25:39 +00:00
|
|
|
return paramType;
|
|
|
|
}
|
|
|
|
if (isupper(name[0])) {
|
2017-10-09 19:45:33 +00:00
|
|
|
lastFull = name;
|
2017-09-14 15:25:39 +00:00
|
|
|
}
|
|
|
|
} while (true);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
const Definition* MdOut::isDefined(const TextParser& parser, string ref,
|
2018-04-03 12:43:27 +00:00
|
|
|
BmhParser::Resolvable resolvable) {
|
2017-07-28 15:04:54 +00:00
|
|
|
auto rootIter = fBmhParser.fClassMap.find(ref);
|
|
|
|
if (rootIter != fBmhParser.fClassMap.end()) {
|
|
|
|
return &rootIter->second;
|
|
|
|
}
|
|
|
|
auto typedefIter = fBmhParser.fTypedefMap.find(ref);
|
|
|
|
if (typedefIter != fBmhParser.fTypedefMap.end()) {
|
|
|
|
return &typedefIter->second;
|
|
|
|
}
|
|
|
|
auto enumIter = fBmhParser.fEnumMap.find(ref);
|
|
|
|
if (enumIter != fBmhParser.fEnumMap.end()) {
|
|
|
|
return &enumIter->second;
|
|
|
|
}
|
|
|
|
auto constIter = fBmhParser.fConstMap.find(ref);
|
|
|
|
if (constIter != fBmhParser.fConstMap.end()) {
|
|
|
|
return &constIter->second;
|
|
|
|
}
|
|
|
|
auto methodIter = fBmhParser.fMethodMap.find(ref);
|
|
|
|
if (methodIter != fBmhParser.fMethodMap.end()) {
|
|
|
|
return &methodIter->second;
|
|
|
|
}
|
|
|
|
auto aliasIter = fBmhParser.fAliasMap.find(ref);
|
|
|
|
if (aliasIter != fBmhParser.fAliasMap.end()) {
|
|
|
|
return aliasIter->second;
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
auto defineIter = fBmhParser.fDefineMap.find(ref);
|
|
|
|
if (defineIter != fBmhParser.fDefineMap.end()) {
|
|
|
|
return &defineIter->second;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
for (const auto& external : fBmhParser.fExternals) {
|
|
|
|
if (external.fName == ref) {
|
|
|
|
return &external;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fRoot) {
|
|
|
|
if (ref == fRoot->fName) {
|
|
|
|
return fRoot;
|
|
|
|
}
|
2017-09-01 19:51:02 +00:00
|
|
|
if (const Definition* definition = fRoot->find(ref, RootDefinition::AllowParens::kYes)) {
|
2017-07-28 15:04:54 +00:00
|
|
|
return definition;
|
|
|
|
}
|
2018-02-01 14:37:32 +00:00
|
|
|
const Definition* test = fRoot;
|
2017-07-28 15:04:54 +00:00
|
|
|
do {
|
|
|
|
if (!test->isRoot()) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-02-01 14:37:32 +00:00
|
|
|
const RootDefinition* root = test->asRoot();
|
2017-07-28 15:04:54 +00:00
|
|
|
for (auto& leaf : root->fBranches) {
|
|
|
|
if (ref == leaf.first) {
|
|
|
|
return leaf.second;
|
|
|
|
}
|
2017-09-01 19:51:02 +00:00
|
|
|
const Definition* definition = leaf.second->find(ref,
|
|
|
|
RootDefinition::AllowParens::kYes);
|
2017-07-28 15:04:54 +00:00
|
|
|
if (definition) {
|
|
|
|
return definition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (string prefix : { "::", "_" } ) {
|
|
|
|
string prefixed = root->fName + prefix + ref;
|
2017-09-01 19:51:02 +00:00
|
|
|
if (const Definition* definition = root->find(prefixed,
|
|
|
|
RootDefinition::AllowParens::kYes)) {
|
2017-07-28 15:04:54 +00:00
|
|
|
return definition;
|
|
|
|
}
|
|
|
|
if (isupper(prefixed[0])) {
|
|
|
|
auto topicIter = fBmhParser.fTopicMap.find(prefixed);
|
|
|
|
if (topicIter != fBmhParser.fTopicMap.end()) {
|
|
|
|
return topicIter->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-22 12:55:48 +00:00
|
|
|
string fiddlePrefixed = root->fFiddle + "_" + ref;
|
|
|
|
auto topicIter = fBmhParser.fTopicMap.find(fiddlePrefixed);
|
|
|
|
if (topicIter != fBmhParser.fTopicMap.end()) {
|
|
|
|
return topicIter->second;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
} while ((test = test->fParent));
|
|
|
|
}
|
|
|
|
size_t doubleColon = ref.find("::");
|
|
|
|
if (string::npos != doubleColon) {
|
|
|
|
string className = ref.substr(0, doubleColon);
|
|
|
|
auto classIter = fBmhParser.fClassMap.find(className);
|
|
|
|
if (classIter != fBmhParser.fClassMap.end()) {
|
|
|
|
const RootDefinition& classDef = classIter->second;
|
2017-09-01 19:51:02 +00:00
|
|
|
const Definition* result = classDef.find(ref, RootDefinition::AllowParens::kYes);
|
2017-07-28 15:04:54 +00:00
|
|
|
if (result) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!ref.compare(0, 2, "SK") || !ref.compare(0, 3, "sk_")
|
|
|
|
|| (('k' == ref[0] || 'g' == ref[0] || 'f' == ref[0]) &&
|
|
|
|
ref.length() > 1 && isupper(ref[1]))) {
|
|
|
|
// try with a prefix
|
|
|
|
if ('k' == ref[0]) {
|
|
|
|
for (auto const& iter : fBmhParser.fEnumMap) {
|
2018-02-15 22:31:24 +00:00
|
|
|
auto def = iter.second.find(ref, RootDefinition::AllowParens::kYes);
|
|
|
|
if (def) {
|
|
|
|
return def;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-03 21:14:08 +00:00
|
|
|
if (fEnumClass) {
|
|
|
|
string fullName = fEnumClass->fName + "::" + ref;
|
|
|
|
for (auto child : fEnumClass->fChildren) {
|
|
|
|
if (fullName == child->fName) {
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (string::npos != ref.find("_Private")) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
if ('f' == ref[0]) {
|
|
|
|
// FIXME : find def associated with prior, e.g.: r.fX where 'SkPoint r' was earlier
|
|
|
|
// need to have pushed last resolve on stack to do this
|
|
|
|
// for now, just try to make sure that it's there and error if not
|
|
|
|
if ('.' != parser.backup(ref.c_str())) {
|
|
|
|
parser.reportError("fX member undefined");
|
2018-03-12 12:26:45 +00:00
|
|
|
fAddRefFailed = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
} else {
|
2018-04-03 12:43:27 +00:00
|
|
|
if (BmhParser::Resolvable::kOut != resolvable &&
|
|
|
|
BmhParser::Resolvable::kFormula != resolvable) {
|
2017-07-28 15:04:54 +00:00
|
|
|
parser.reportError("SK undefined");
|
2018-03-12 12:26:45 +00:00
|
|
|
fAddRefFailed = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isupper(ref[0])) {
|
|
|
|
auto topicIter = fBmhParser.fTopicMap.find(ref);
|
|
|
|
if (topicIter != fBmhParser.fTopicMap.end()) {
|
|
|
|
return topicIter->second;
|
|
|
|
}
|
|
|
|
size_t pos = ref.find('_');
|
|
|
|
if (string::npos != pos) {
|
|
|
|
// see if it is defined by another base class
|
|
|
|
string className(ref, 0, pos);
|
|
|
|
auto classIter = fBmhParser.fClassMap.find(className);
|
|
|
|
if (classIter != fBmhParser.fClassMap.end()) {
|
2017-09-01 19:51:02 +00:00
|
|
|
if (const Definition* definition = classIter->second.find(ref,
|
|
|
|
RootDefinition::AllowParens::kYes)) {
|
2017-07-28 15:04:54 +00:00
|
|
|
return definition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto enumIter = fBmhParser.fEnumMap.find(className);
|
|
|
|
if (enumIter != fBmhParser.fEnumMap.end()) {
|
2017-09-01 19:51:02 +00:00
|
|
|
if (const Definition* definition = enumIter->second.find(ref,
|
|
|
|
RootDefinition::AllowParens::kYes)) {
|
2017-07-28 15:04:54 +00:00
|
|
|
return definition;
|
|
|
|
}
|
|
|
|
}
|
2018-04-03 12:43:27 +00:00
|
|
|
if (BmhParser::Resolvable::kOut != resolvable &&
|
|
|
|
BmhParser::Resolvable::kFormula != resolvable) {
|
2017-07-28 15:04:54 +00:00
|
|
|
parser.reportError("_ undefined");
|
2018-03-12 12:26:45 +00:00
|
|
|
fAddRefFailed = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
string MdOut::linkName(const Definition* ref) const {
|
|
|
|
string result = ref->fName;
|
|
|
|
size_t under = result.find('_');
|
|
|
|
if (string::npos != under) {
|
|
|
|
string classPart = result.substr(0, under);
|
|
|
|
string namePart = result.substr(under + 1, result.length());
|
|
|
|
if (fRoot && (fRoot->fName == classPart
|
|
|
|
|| (fRoot->fParent && fRoot->fParent->fName == classPart))) {
|
|
|
|
result = namePart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// for now, hard-code to html links
|
|
|
|
// def should not include SkXXX_
|
2018-04-16 12:37:38 +00:00
|
|
|
string MdOut::linkRef(string leadingSpaces, const Definition* def,
|
|
|
|
string ref, BmhParser::Resolvable resolvable) const {
|
2018-02-15 22:31:24 +00:00
|
|
|
string buildup;
|
|
|
|
string refName;
|
2017-07-28 15:04:54 +00:00
|
|
|
const string* str = &def->fFiddle;
|
|
|
|
SkASSERT(str->length() > 0);
|
2018-02-15 22:31:24 +00:00
|
|
|
string classPart = *str;
|
|
|
|
bool globalEnumMember = false;
|
|
|
|
if (MarkType::kAlias == def->fMarkType) {
|
|
|
|
def = def->fParent;
|
|
|
|
SkASSERT(def);
|
|
|
|
SkASSERT(MarkType::kSubtopic == def->fMarkType ||MarkType::kTopic == def->fMarkType);
|
|
|
|
}
|
|
|
|
if (MarkType::kSubtopic == def->fMarkType) {
|
|
|
|
const Definition* topic = def->topicParent();
|
|
|
|
SkASSERT(topic);
|
|
|
|
classPart = topic->fName;
|
|
|
|
refName = def->fName;
|
|
|
|
} else if (MarkType::kTopic == def->fMarkType) {
|
|
|
|
refName = def->fName;
|
|
|
|
} else {
|
|
|
|
if ('k' == (*str)[0] && string::npos != str->find("_Sk")) {
|
|
|
|
globalEnumMember = true;
|
|
|
|
} else {
|
|
|
|
SkASSERT("Sk" == str->substr(0, 2) || "SK" == str->substr(0, 2)
|
|
|
|
// FIXME: kitchen sink catch below, need to do better
|
|
|
|
|| string::npos != def->fFileName.find("undocumented"));
|
|
|
|
size_t under = str->find('_');
|
|
|
|
classPart = string::npos != under ? str->substr(0, under) : *str;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-02-15 22:31:24 +00:00
|
|
|
refName = def->fFiddle;
|
|
|
|
}
|
|
|
|
bool classMatch = fRoot->fFileName == def->fFileName;
|
2017-07-28 15:04:54 +00:00
|
|
|
SkASSERT(fRoot);
|
|
|
|
SkASSERT(fRoot->fFileName.length());
|
2018-02-15 22:31:24 +00:00
|
|
|
if (!classMatch) {
|
|
|
|
string filename = def->fFileName;
|
2017-07-28 15:04:54 +00:00
|
|
|
if (filename.substr(filename.length() - 4) == ".bmh") {
|
|
|
|
filename = filename.substr(0, filename.length() - 4);
|
|
|
|
}
|
|
|
|
size_t start = filename.length();
|
|
|
|
while (start > 0 && (isalnum(filename[start - 1]) || '_' == filename[start - 1])) {
|
|
|
|
--start;
|
|
|
|
}
|
2018-02-15 22:31:24 +00:00
|
|
|
buildup = filename.substr(start);
|
2017-08-25 15:51:49 +00:00
|
|
|
}
|
2018-02-15 22:31:24 +00:00
|
|
|
buildup += "#" + refName;
|
2017-08-25 15:51:49 +00:00
|
|
|
if (MarkType::kParam == def->fMarkType) {
|
|
|
|
const Definition* parent = def->fParent;
|
|
|
|
SkASSERT(MarkType::kMethod == parent->fMarkType);
|
|
|
|
buildup = '#' + parent->fFiddle + '_' + ref;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
string refOut(ref);
|
2018-02-15 22:31:24 +00:00
|
|
|
if (!globalEnumMember) {
|
|
|
|
std::replace(refOut.begin(), refOut.end(), '_', ' ');
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (ref.length() > 2 && islower(ref[0]) && "()" == ref.substr(ref.length() - 2)) {
|
|
|
|
refOut = refOut.substr(0, refOut.length() - 2);
|
|
|
|
}
|
2018-01-26 17:56:22 +00:00
|
|
|
string result = leadingSpaces + "<a href=\"" + buildup + "\">" + refOut + "</a>";
|
|
|
|
if (BmhParser::Resolvable::kClone == resolvable && MarkType::kMethod == def->fMarkType &&
|
|
|
|
def->fCloned && !def->fClone) {
|
|
|
|
bool found = false;
|
|
|
|
string match = def->fName;
|
|
|
|
if ("()" == match.substr(match.length() - 2)) {
|
|
|
|
match = match.substr(0, match.length() - 2);
|
|
|
|
}
|
|
|
|
match += '_';
|
|
|
|
auto classIter = fBmhParser.fClassMap.find(classPart);
|
|
|
|
if (fBmhParser.fClassMap.end() != classIter) {
|
|
|
|
for (char num = '2'; num <= '9'; ++num) {
|
|
|
|
string clone = match + num;
|
|
|
|
const auto& leafIter = classIter->second.fLeaves.find(clone);
|
|
|
|
if (leafIter != classIter->second.fLeaves.end()) {
|
|
|
|
result += "<sup><a href=\"" + buildup + "_" + num + "\">[" + num + "]</a></sup>";
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
2018-01-30 15:08:57 +00:00
|
|
|
SkDebugf(""); // convenient place to set a breakpoint
|
2018-01-26 17:56:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MdOut::markTypeOut(Definition* def) {
|
|
|
|
string printable = def->printableName();
|
|
|
|
const char* textStart = def->fContentStart;
|
|
|
|
if (MarkType::kParam != def->fMarkType && MarkType::kConst != def->fMarkType &&
|
|
|
|
(!def->fParent || MarkType::kConst != def->fParent->fMarkType) &&
|
2018-03-05 18:26:16 +00:00
|
|
|
TableState::kNone != fTableState &&
|
|
|
|
(MarkType::kPhraseRef != def->fMarkType || !def->fParent ||
|
|
|
|
MarkType::kParam != def->fParent->fMarkType)) {
|
2017-07-28 15:04:54 +00:00
|
|
|
this->writePending();
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("</table>");
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(2);
|
|
|
|
fTableState = TableState::kNone;
|
|
|
|
}
|
|
|
|
switch (def->fMarkType) {
|
|
|
|
case MarkType::kAlias:
|
|
|
|
break;
|
2018-01-04 21:11:51 +00:00
|
|
|
case MarkType::kAnchor: {
|
|
|
|
if (fColumn > 0) {
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
|
|
|
this->writePending();
|
|
|
|
TextParser parser(def);
|
|
|
|
const char* start = parser.fChar;
|
|
|
|
parser.skipToEndBracket(" # ");
|
|
|
|
string anchorText(start, parser.fChar - start);
|
|
|
|
parser.skipExact(" # ");
|
|
|
|
string anchorLink(parser.fChar, parser.fEnd - parser.fChar);
|
|
|
|
FPRINTF("<a href=\"%s\">%s", anchorLink.c_str(), anchorText.c_str());
|
|
|
|
} break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case MarkType::kBug:
|
|
|
|
break;
|
|
|
|
case MarkType::kClass:
|
|
|
|
this->mdHeaderOut(1);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("<a name=\"%s\"></a> Class %s", this->linkName(def).c_str(),
|
2017-07-28 15:04:54 +00:00
|
|
|
def->fName.c_str());
|
|
|
|
this->lf(1);
|
|
|
|
break;
|
|
|
|
case MarkType::kCode:
|
|
|
|
this->lfAlways(2);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("<pre style=\"padding: 1em 1em 1em 1em;"
|
2017-11-27 15:44:06 +00:00
|
|
|
"width: 62.5em; background-color: #f0f0f0\">");
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(1);
|
2018-04-03 12:43:27 +00:00
|
|
|
fResolveAndIndent = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
case MarkType::kColumn:
|
|
|
|
this->writePending();
|
|
|
|
if (fInList) {
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF(" <td>");
|
2017-07-28 15:04:54 +00:00
|
|
|
} else {
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("| ");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MarkType::kComment:
|
|
|
|
break;
|
|
|
|
case MarkType::kConst: {
|
|
|
|
if (TableState::kNone == fTableState) {
|
|
|
|
this->mdHeaderOut(3);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("Constants\n"
|
2017-07-28 15:04:54 +00:00
|
|
|
"\n"
|
|
|
|
"<table>");
|
|
|
|
fTableState = TableState::kRow;
|
|
|
|
this->lf(1);
|
|
|
|
}
|
|
|
|
if (TableState::kRow == fTableState) {
|
|
|
|
this->writePending();
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF(" <tr>");
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(1);
|
|
|
|
fTableState = TableState::kColumn;
|
|
|
|
}
|
|
|
|
this->writePending();
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF(" <td><a name=\"%s\"> <code><strong>%s </strong></code> </a></td>",
|
2017-08-25 15:51:49 +00:00
|
|
|
def->fFiddle.c_str(), def->fName.c_str());
|
2017-07-28 15:04:54 +00:00
|
|
|
const char* lineEnd = strchr(textStart, '\n');
|
|
|
|
SkASSERT(lineEnd < def->fTerminator);
|
|
|
|
SkASSERT(lineEnd > textStart);
|
|
|
|
SkASSERT((int) (lineEnd - textStart) == lineEnd - textStart);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("<td>%.*s</td>", (int) (lineEnd - textStart), textStart);
|
|
|
|
FPRINTF("<td>");
|
2017-07-28 15:04:54 +00:00
|
|
|
textStart = lineEnd;
|
|
|
|
} break;
|
|
|
|
case MarkType::kDefine:
|
|
|
|
break;
|
|
|
|
case MarkType::kDefinedBy:
|
|
|
|
break;
|
|
|
|
case MarkType::kDeprecated:
|
|
|
|
break;
|
|
|
|
case MarkType::kDescription:
|
|
|
|
fInDescription = true;
|
|
|
|
this->writePending();
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("<div>");
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
case MarkType::kDoxygen:
|
|
|
|
break;
|
2018-01-11 15:35:44 +00:00
|
|
|
case MarkType::kDuration:
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case MarkType::kEnum:
|
|
|
|
case MarkType::kEnumClass:
|
|
|
|
this->mdHeaderOut(2);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("<a name=\"%s\"></a> Enum %s", def->fFiddle.c_str(), def->fName.c_str());
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(2);
|
|
|
|
break;
|
|
|
|
case MarkType::kExample: {
|
|
|
|
this->mdHeaderOut(3);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("Example\n"
|
2017-07-28 15:04:54 +00:00
|
|
|
"\n");
|
|
|
|
fHasFiddle = true;
|
2017-11-27 15:44:06 +00:00
|
|
|
bool showGpu = false;
|
|
|
|
bool gpuAndCpu = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
const Definition* platform = def->hasChild(MarkType::kPlatform);
|
|
|
|
if (platform) {
|
|
|
|
TextParser platParse(platform);
|
|
|
|
fHasFiddle = !platParse.strnstr("!fiddle", platParse.fEnd);
|
2017-11-27 15:44:06 +00:00
|
|
|
showGpu = platParse.strnstr("gpu", platParse.fEnd);
|
|
|
|
if (showGpu) {
|
|
|
|
gpuAndCpu = platParse.strnstr("cpu", platParse.fEnd);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-02-01 14:37:32 +00:00
|
|
|
if (fHasFiddle) {
|
2017-12-11 21:03:17 +00:00
|
|
|
SkASSERT(def->fHash.length() > 0);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("<div><fiddle-embed name=\"%s\"", def->fHash.c_str());
|
2017-11-27 15:44:06 +00:00
|
|
|
if (showGpu) {
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF(" gpu=\"true\"");
|
2017-11-27 15:44:06 +00:00
|
|
|
if (gpuAndCpu) {
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF(" cpu=\"true\"");
|
2017-11-27 15:44:06 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF(">");
|
2017-07-28 15:04:54 +00:00
|
|
|
} else {
|
2017-12-11 21:03:17 +00:00
|
|
|
SkASSERT(def->fHash.length() == 0);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("<pre style=\"padding: 1em 1em 1em 1em; font-size: 13px"
|
2017-11-27 15:44:06 +00:00
|
|
|
" width: 62.5em; background-color: #f0f0f0\">");
|
|
|
|
this->lfAlways(1);
|
|
|
|
if (def->fWrapper.length() > 0) {
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("%s", def->fWrapper.c_str());
|
2017-11-27 15:44:06 +00:00
|
|
|
}
|
2018-04-03 12:43:27 +00:00
|
|
|
fLiteralAndIndent = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case MarkType::kExperimental:
|
|
|
|
break;
|
|
|
|
case MarkType::kExternal:
|
|
|
|
break;
|
|
|
|
case MarkType::kFile:
|
|
|
|
break;
|
|
|
|
case MarkType::kFormula:
|
|
|
|
break;
|
|
|
|
case MarkType::kFunction:
|
|
|
|
break;
|
|
|
|
case MarkType::kHeight:
|
|
|
|
break;
|
2018-02-27 14:54:21 +00:00
|
|
|
case MarkType::kIllustration: {
|
|
|
|
string illustName = "Illustrations_" + def->fParent->fFiddle;
|
|
|
|
auto illustIter = fBmhParser.fTopicMap.find(illustName);
|
|
|
|
SkASSERT(fBmhParser.fTopicMap.end() != illustIter);
|
|
|
|
Definition* illustDef = illustIter->second;
|
|
|
|
SkASSERT(MarkType::kSubtopic == illustDef->fMarkType);
|
|
|
|
SkASSERT(1 == illustDef->fChildren.size());
|
|
|
|
Definition* illustExample = illustDef->fChildren[0];
|
|
|
|
SkASSERT(MarkType::kExample == illustExample->fMarkType);
|
|
|
|
string hash = illustExample->fHash;
|
|
|
|
SkASSERT("" != hash);
|
|
|
|
string title;
|
|
|
|
this->writePending();
|
|
|
|
FPRINTF("![%s](https://fiddle.skia.org/i/%s_raster.png \"%s\")",
|
|
|
|
def->fName.c_str(), hash.c_str(), title.c_str());
|
|
|
|
this->lf(2);
|
|
|
|
} break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case MarkType::kImage:
|
|
|
|
break;
|
2018-01-30 15:08:57 +00:00
|
|
|
case MarkType::kIn:
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case MarkType::kLegend:
|
|
|
|
break;
|
2018-01-30 15:08:57 +00:00
|
|
|
case MarkType::kLine:
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case MarkType::kLink:
|
|
|
|
break;
|
|
|
|
case MarkType::kList:
|
|
|
|
fInList = true;
|
|
|
|
this->lfAlways(2);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("<table>");
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(1);
|
|
|
|
break;
|
2017-10-26 11:58:48 +00:00
|
|
|
case MarkType::kLiteral:
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case MarkType::kMarkChar:
|
|
|
|
fBmhParser.fMC = def->fContentStart[0];
|
|
|
|
break;
|
|
|
|
case MarkType::kMember: {
|
|
|
|
TextParser tp(def->fFileName, def->fStart, def->fContentStart, def->fLineCount);
|
|
|
|
tp.skipExact("#Member");
|
|
|
|
tp.skipWhiteSpace();
|
2017-09-01 19:51:02 +00:00
|
|
|
const char* end = tp.trimmedBracketEnd('\n');
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lfAlways(2);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("<a name=\"%s\"> <code><strong>%.*s</strong></code> </a>",
|
2017-08-25 15:51:49 +00:00
|
|
|
def->fFiddle.c_str(), (int) (end - tp.fChar), tp.fChar);
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(2);
|
|
|
|
} break;
|
|
|
|
case MarkType::kMethod: {
|
|
|
|
string method_name = def->methodName();
|
2018-02-07 12:27:09 +00:00
|
|
|
string formattedStr = def->formatFunction(Definition::Format::kIncludeReturn);
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-26 17:56:22 +00:00
|
|
|
this->lfAlways(2);
|
|
|
|
FPRINTF("<a name=\"%s\"></a>", def->fFiddle.c_str());
|
|
|
|
if (!def->isClone()) {
|
2017-07-28 15:04:54 +00:00
|
|
|
this->mdHeaderOutLF(2, 1);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("%s", method_name.c_str());
|
2018-01-26 17:56:22 +00:00
|
|
|
}
|
|
|
|
this->lf(2);
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
// TODO: put in css spec that we can define somewhere else (if markup supports that)
|
2017-10-26 11:58:48 +00:00
|
|
|
// TODO: 50em below should match limit = 80 in formatFunction()
|
2017-07-28 15:04:54 +00:00
|
|
|
this->writePending();
|
2017-10-04 18:31:33 +00:00
|
|
|
string preformattedStr = preformat(formattedStr);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("<pre style=\"padding: 1em 1em 1em 1em;"
|
2017-11-27 15:44:06 +00:00
|
|
|
"width: 62.5em; background-color: #f0f0f0\">\n"
|
2017-07-28 15:04:54 +00:00
|
|
|
"%s\n"
|
2017-10-04 18:31:33 +00:00
|
|
|
"</pre>", preformattedStr.c_str());
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(2);
|
|
|
|
fTableState = TableState::kNone;
|
|
|
|
fMethod = def;
|
|
|
|
} break;
|
|
|
|
case MarkType::kNoExample:
|
|
|
|
break;
|
2017-10-26 11:58:48 +00:00
|
|
|
case MarkType::kOutdent:
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case MarkType::kParam: {
|
|
|
|
if (TableState::kNone == fTableState) {
|
|
|
|
this->mdHeaderOut(3);
|
2017-10-09 19:45:33 +00:00
|
|
|
fprintf(fOut,
|
2017-07-28 15:04:54 +00:00
|
|
|
"Parameters\n"
|
|
|
|
"\n"
|
|
|
|
"<table>"
|
|
|
|
);
|
|
|
|
this->lf(1);
|
|
|
|
fTableState = TableState::kRow;
|
|
|
|
}
|
|
|
|
if (TableState::kRow == fTableState) {
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF(" <tr>");
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(1);
|
|
|
|
fTableState = TableState::kColumn;
|
|
|
|
}
|
|
|
|
TextParser paramParser(def->fFileName, def->fStart, def->fContentStart,
|
|
|
|
def->fLineCount);
|
|
|
|
paramParser.skipWhiteSpace();
|
|
|
|
SkASSERT(paramParser.startsWith("#Param"));
|
|
|
|
paramParser.next(); // skip hash
|
2018-04-16 12:37:38 +00:00
|
|
|
paramParser.skipToNonName(); // skip Param
|
2017-07-28 15:04:54 +00:00
|
|
|
paramParser.skipSpace();
|
|
|
|
const char* paramName = paramParser.fChar;
|
|
|
|
paramParser.skipToSpace();
|
2017-08-25 15:51:49 +00:00
|
|
|
string paramNameStr(paramName, (int) (paramParser.fChar - paramName));
|
2017-08-30 12:58:10 +00:00
|
|
|
if (!this->checkParamReturnBody(def)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-25 15:51:49 +00:00
|
|
|
string refNameStr = def->fParent->fFiddle + "_" + paramNameStr;
|
2017-10-09 19:45:33 +00:00
|
|
|
fprintf(fOut,
|
2017-08-25 15:51:49 +00:00
|
|
|
" <td><a name=\"%s\"> <code><strong>%s </strong></code> </a></td> <td>",
|
|
|
|
refNameStr.c_str(), paramNameStr.c_str());
|
2017-07-28 15:04:54 +00:00
|
|
|
} break;
|
|
|
|
case MarkType::kPlatform:
|
|
|
|
break;
|
2018-02-01 14:37:32 +00:00
|
|
|
case MarkType::kPopulate: {
|
|
|
|
SkASSERT(MarkType::kSubtopic == def->fParent->fMarkType);
|
|
|
|
string name = def->fParent->fName;
|
|
|
|
if (kSubtopics == name) {
|
|
|
|
this->subtopicsOut();
|
|
|
|
} else {
|
|
|
|
this->subtopicOut(this->populator(name.c_str()));
|
|
|
|
}
|
|
|
|
} break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case MarkType::kPrivate:
|
|
|
|
break;
|
|
|
|
case MarkType::kReturn:
|
|
|
|
this->mdHeaderOut(3);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("Return Value");
|
2017-08-30 12:58:10 +00:00
|
|
|
if (!this->checkParamReturnBody(def)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(2);
|
|
|
|
break;
|
|
|
|
case MarkType::kRow:
|
|
|
|
if (fInList) {
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF(" <tr>");
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MarkType::kSeeAlso:
|
|
|
|
this->mdHeaderOut(3);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("See Also");
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(2);
|
|
|
|
break;
|
2018-01-03 13:37:53 +00:00
|
|
|
case MarkType::kSet:
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case MarkType::kStdOut: {
|
|
|
|
TextParser code(def);
|
|
|
|
this->mdHeaderOut(4);
|
2017-10-09 19:45:33 +00:00
|
|
|
fprintf(fOut,
|
2017-07-28 15:04:54 +00:00
|
|
|
"Example Output\n"
|
|
|
|
"\n"
|
|
|
|
"~~~~");
|
|
|
|
this->lfAlways(1);
|
|
|
|
code.skipSpace();
|
|
|
|
while (!code.eof()) {
|
|
|
|
const char* end = code.trimmedLineEnd();
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("%.*s\n", (int) (end - code.fChar), code.fChar);
|
2017-07-28 15:04:54 +00:00
|
|
|
code.skipToLineStart();
|
|
|
|
}
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("~~~~");
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(2);
|
|
|
|
} break;
|
|
|
|
case MarkType::kStruct:
|
|
|
|
fRoot = def->asRoot();
|
|
|
|
this->mdHeaderOut(1);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("<a name=\"%s\"></a> Struct %s", def->fFiddle.c_str(), def->fName.c_str());
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(1);
|
|
|
|
break;
|
|
|
|
case MarkType::kSubstitute:
|
|
|
|
break;
|
|
|
|
case MarkType::kSubtopic:
|
|
|
|
this->mdHeaderOut(2);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("<a name=\"%s\"></a> %s", def->fName.c_str(), printable.c_str());
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(2);
|
|
|
|
break;
|
|
|
|
case MarkType::kTable:
|
|
|
|
this->lf(2);
|
|
|
|
break;
|
|
|
|
case MarkType::kTemplate:
|
|
|
|
break;
|
|
|
|
case MarkType::kText:
|
|
|
|
break;
|
|
|
|
case MarkType::kTime:
|
|
|
|
break;
|
|
|
|
case MarkType::kToDo:
|
|
|
|
break;
|
|
|
|
case MarkType::kTopic:
|
|
|
|
this->mdHeaderOut(1);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("<a name=\"%s\"></a> %s", this->linkName(def).c_str(),
|
2017-07-28 15:04:54 +00:00
|
|
|
printable.c_str());
|
|
|
|
this->lf(1);
|
|
|
|
break;
|
|
|
|
case MarkType::kTrack:
|
|
|
|
// don't output children
|
|
|
|
return;
|
|
|
|
case MarkType::kTypedef:
|
|
|
|
break;
|
|
|
|
case MarkType::kUnion:
|
|
|
|
break;
|
|
|
|
case MarkType::kVolatile:
|
|
|
|
break;
|
|
|
|
case MarkType::kWidth:
|
|
|
|
break;
|
2018-03-05 18:26:16 +00:00
|
|
|
case MarkType::kPhraseDef:
|
2018-04-03 12:43:27 +00:00
|
|
|
// skip text and children
|
|
|
|
return;
|
2018-03-05 18:26:16 +00:00
|
|
|
case MarkType::kPhraseRef:
|
|
|
|
if (fBmhParser.fPhraseMap.end() == fBmhParser.fPhraseMap.find(def->fName)) {
|
|
|
|
def->reportError<void>("missing phrase definition");
|
2018-03-12 12:26:45 +00:00
|
|
|
fAddRefFailed = true;
|
2018-03-05 18:26:16 +00:00
|
|
|
} else {
|
|
|
|
if (fColumn && ' ' >= def->fStart[0]) {
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
|
|
|
Definition* phraseRef = fBmhParser.fPhraseMap.find(def->fName)->second;
|
|
|
|
this->childrenOut(phraseRef, phraseRef->fContentStart);
|
|
|
|
if (' ' >= def->fContentStart[0]) {
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
default:
|
|
|
|
SkDebugf("fatal error: MarkType::k%s unhandled in %s()\n",
|
2018-04-16 12:37:38 +00:00
|
|
|
BmhParser::kMarkProps[(int) def->fMarkType].fName, __func__);
|
2017-07-28 15:04:54 +00:00
|
|
|
SkASSERT(0); // handle everything
|
|
|
|
break;
|
|
|
|
}
|
2018-03-20 19:53:27 +00:00
|
|
|
TableState saveState = fTableState;
|
2017-07-28 15:04:54 +00:00
|
|
|
this->childrenOut(def, textStart);
|
2018-03-20 19:53:27 +00:00
|
|
|
fTableState = saveState;
|
2017-07-28 15:04:54 +00:00
|
|
|
switch (def->fMarkType) { // post child work, at least for tables
|
2018-01-04 21:11:51 +00:00
|
|
|
case MarkType::kAnchor:
|
|
|
|
if (fColumn > 0) {
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case MarkType::kCode:
|
2018-04-03 12:43:27 +00:00
|
|
|
fIndent = 0;
|
|
|
|
this->lf(1);
|
2017-07-28 15:04:54 +00:00
|
|
|
this->writePending();
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("</pre>");
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(2);
|
2018-04-03 12:43:27 +00:00
|
|
|
fResolveAndIndent = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
case MarkType::kColumn:
|
|
|
|
if (fInList) {
|
|
|
|
this->writePending();
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("</td>");
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(1);
|
|
|
|
} else {
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF(" ");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MarkType::kDescription:
|
|
|
|
this->writePending();
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("</div>");
|
2017-07-28 15:04:54 +00:00
|
|
|
fInDescription = false;
|
|
|
|
break;
|
|
|
|
case MarkType::kEnum:
|
|
|
|
case MarkType::kEnumClass:
|
|
|
|
this->lfAlways(2);
|
|
|
|
break;
|
|
|
|
case MarkType::kExample:
|
|
|
|
this->writePending();
|
|
|
|
if (fHasFiddle) {
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("</fiddle-embed></div>");
|
2017-07-28 15:04:54 +00:00
|
|
|
} else {
|
2017-11-27 15:44:06 +00:00
|
|
|
this->lfAlways(1);
|
|
|
|
if (def->fWrapper.length() > 0) {
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("}");
|
2017-11-27 15:44:06 +00:00
|
|
|
this->lfAlways(1);
|
|
|
|
}
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("</pre>");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
this->lf(2);
|
2018-04-03 12:43:27 +00:00
|
|
|
fLiteralAndIndent = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
2018-01-04 21:11:51 +00:00
|
|
|
case MarkType::kLink:
|
|
|
|
this->writeString("</a>");
|
|
|
|
this->writeSpace();
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case MarkType::kList:
|
|
|
|
fInList = false;
|
|
|
|
this->writePending();
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("</table>");
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(2);
|
|
|
|
break;
|
|
|
|
case MarkType::kLegend: {
|
|
|
|
SkASSERT(def->fChildren.size() == 1);
|
|
|
|
const Definition* row = def->fChildren[0];
|
|
|
|
SkASSERT(MarkType::kRow == row->fMarkType);
|
|
|
|
size_t columnCount = row->fChildren.size();
|
|
|
|
SkASSERT(columnCount > 0);
|
|
|
|
this->writePending();
|
|
|
|
for (size_t index = 0; index < columnCount; ++index) {
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("| --- ");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF(" |");
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(1);
|
|
|
|
} break;
|
|
|
|
case MarkType::kMethod:
|
|
|
|
fMethod = nullptr;
|
|
|
|
this->lfAlways(2);
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("---");
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(2);
|
|
|
|
break;
|
|
|
|
case MarkType::kConst:
|
|
|
|
case MarkType::kParam:
|
|
|
|
SkASSERT(TableState::kColumn == fTableState);
|
|
|
|
fTableState = TableState::kRow;
|
|
|
|
this->writePending();
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("</td>\n");
|
|
|
|
FPRINTF(" </tr>");
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(1);
|
|
|
|
break;
|
|
|
|
case MarkType::kReturn:
|
|
|
|
case MarkType::kSeeAlso:
|
|
|
|
this->lf(2);
|
|
|
|
break;
|
|
|
|
case MarkType::kRow:
|
|
|
|
if (fInList) {
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF(" </tr>");
|
2017-07-28 15:04:54 +00:00
|
|
|
} else {
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("|");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
this->lf(1);
|
|
|
|
break;
|
|
|
|
case MarkType::kStruct:
|
|
|
|
fRoot = fRoot->rootParent();
|
|
|
|
break;
|
|
|
|
case MarkType::kTable:
|
|
|
|
this->lf(2);
|
|
|
|
break;
|
2018-03-05 18:26:16 +00:00
|
|
|
case MarkType::kPhraseDef:
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case MarkType::kPrivate:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MdOut::mdHeaderOutLF(int depth, int lf) {
|
|
|
|
this->lfAlways(lf);
|
|
|
|
for (int index = 0; index < depth; ++index) {
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF("#");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-01-04 21:11:51 +00:00
|
|
|
FPRINTF(" ");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-01 14:37:32 +00:00
|
|
|
void MdOut::populateTables(const Definition* def) {
|
|
|
|
const Definition* csParent = this->csParent();
|
2018-02-07 12:27:09 +00:00
|
|
|
if (!csParent) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-01 14:37:32 +00:00
|
|
|
for (auto child : def->fChildren) {
|
|
|
|
if (MarkType::kTopic == child->fMarkType || MarkType::kSubtopic == child->fMarkType) {
|
2018-02-07 12:27:09 +00:00
|
|
|
string name = child->fName;
|
|
|
|
bool builtInTopic = name == kClassesAndStructs || name == kConstants
|
2018-04-16 12:37:38 +00:00
|
|
|
|| name == kConstructors || name == kDefines || name == kMemberFunctions
|
|
|
|
|| name == kMembers || name == kOperators || name == kOverview
|
|
|
|
|| name == kRelatedFunctions || name == kSubtopics || name == kTypedefs;
|
2018-02-07 12:27:09 +00:00
|
|
|
if (!builtInTopic && child->fName != kOverview) {
|
2018-02-06 14:41:53 +00:00
|
|
|
this->populator(kRelatedFunctions).fMembers.push_back(child);
|
2018-02-01 14:37:32 +00:00
|
|
|
}
|
|
|
|
this->populateTables(child);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (child->isStructOrClass()) {
|
|
|
|
if (fClassStack.size() > 0) {
|
2018-02-06 14:41:53 +00:00
|
|
|
this->populator(kClassesAndStructs).fMembers.push_back(child);
|
2018-02-01 14:37:32 +00:00
|
|
|
}
|
|
|
|
fClassStack.push_back(child);
|
|
|
|
this->populateTables(child);
|
|
|
|
fClassStack.pop_back();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (MarkType::kEnum == child->fMarkType || MarkType::kEnumClass == child->fMarkType) {
|
2018-02-06 14:41:53 +00:00
|
|
|
this->populator(kConstants).fMembers.push_back(child);
|
2018-02-01 14:37:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
if (MarkType::kDefine == child->fMarkType) {
|
|
|
|
this->populator(kDefines).fMembers.push_back(child);
|
|
|
|
}
|
2018-02-01 14:37:32 +00:00
|
|
|
if (MarkType::kMember == child->fMarkType) {
|
2018-02-06 14:41:53 +00:00
|
|
|
this->populator(kMembers).fMembers.push_back(child);
|
2018-02-01 14:37:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
if (MarkType::kTypedef == child->fMarkType) {
|
|
|
|
this->populator(kTypedefs).fMembers.push_back(child);
|
|
|
|
}
|
2018-02-01 14:37:32 +00:00
|
|
|
if (MarkType::kMethod != child->fMarkType) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (child->fClone) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Definition::MethodType::kConstructor == child->fMethodType
|
|
|
|
|| Definition::MethodType::kDestructor == child->fMethodType) {
|
2018-02-06 14:41:53 +00:00
|
|
|
this->populator(kConstructors).fMembers.push_back(child);
|
2018-02-01 14:37:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Definition::MethodType::kOperator == child->fMethodType) {
|
2018-02-06 14:41:53 +00:00
|
|
|
this->populator(kOperators).fMembers.push_back(child);
|
2018-02-01 14:37:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-02-06 14:41:53 +00:00
|
|
|
this->populator(kMemberFunctions).fMembers.push_back(child);
|
2018-02-01 14:37:32 +00:00
|
|
|
if (csParent && (0 == child->fName.find(csParent->fName + "::Make")
|
|
|
|
|| 0 == child->fName.find(csParent->fName + "::make"))) {
|
2018-02-06 14:41:53 +00:00
|
|
|
this->populator(kConstructors).fMembers.push_back(child);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (auto item : child->fChildren) {
|
|
|
|
if (MarkType::kIn == item->fMarkType) {
|
|
|
|
string name(item->fContentStart, item->fContentEnd - item->fContentStart);
|
|
|
|
fPopulators[name].fMembers.push_back(child);
|
|
|
|
fPopulators[name].fShowClones = true;
|
|
|
|
break;
|
|
|
|
}
|
2018-02-01 14:37:32 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-30 15:08:57 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
void MdOut::resolveOut(const char* start, const char* end, BmhParser::Resolvable resolvable) {
|
2018-04-03 12:43:27 +00:00
|
|
|
if ((BmhParser::Resolvable::kLiteral == resolvable || fLiteralAndIndent ||
|
|
|
|
fResolveAndIndent) && end > start) {
|
|
|
|
int linefeeds = 0;
|
2017-10-26 11:58:48 +00:00
|
|
|
while ('\n' == *start) {
|
2018-04-03 12:43:27 +00:00
|
|
|
++linefeeds;
|
2017-10-26 11:58:48 +00:00
|
|
|
++start;
|
|
|
|
}
|
2018-04-03 12:43:27 +00:00
|
|
|
if (fResolveAndIndent && linefeeds) {
|
|
|
|
this->lf(linefeeds);
|
|
|
|
}
|
2017-10-26 11:58:48 +00:00
|
|
|
const char* spaceStart = start;
|
|
|
|
while (' ' == *start) {
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
if (start > spaceStart) {
|
2017-11-27 15:44:06 +00:00
|
|
|
fIndent = start - spaceStart;
|
2017-10-26 11:58:48 +00:00
|
|
|
}
|
2018-04-03 12:43:27 +00:00
|
|
|
}
|
|
|
|
if (BmhParser::Resolvable::kLiteral == resolvable || fLiteralAndIndent) {
|
2017-10-26 11:58:48 +00:00
|
|
|
this->writeBlockTrim(end - start, start);
|
|
|
|
if ('\n' == end[-1]) {
|
|
|
|
this->lf(1);
|
|
|
|
}
|
|
|
|
fIndent = 0;
|
|
|
|
return;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
// FIXME: this needs the markdown character present when the def was defined,
|
|
|
|
// not the last markdown character the parser would have seen...
|
|
|
|
while (fBmhParser.fMC == end[-1]) {
|
|
|
|
--end;
|
|
|
|
}
|
|
|
|
if (start >= end) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
string resolved = this->addReferences(start, end, resolvable);
|
|
|
|
trim_end_spaces(resolved);
|
|
|
|
if (resolved.length()) {
|
|
|
|
TextParser paragraph(fFileName, &*resolved.begin(), &*resolved.end(), fLineCount);
|
|
|
|
while (!paragraph.eof()) {
|
2018-04-03 12:43:27 +00:00
|
|
|
while ('\n' == paragraph.peek()) {
|
|
|
|
paragraph.next();
|
|
|
|
if (paragraph.eof()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const char* lineStart = paragraph.fChar;
|
2017-07-28 15:04:54 +00:00
|
|
|
paragraph.skipWhiteSpace();
|
|
|
|
const char* contentStart = paragraph.fChar;
|
2018-04-03 12:43:27 +00:00
|
|
|
if (fResolveAndIndent && contentStart > lineStart) {
|
|
|
|
this->writePending();
|
|
|
|
this->indentToColumn(contentStart - lineStart);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
paragraph.skipToEndBracket('\n');
|
|
|
|
ptrdiff_t lineLength = paragraph.fChar - contentStart;
|
|
|
|
if (lineLength) {
|
2018-01-04 21:11:51 +00:00
|
|
|
while (lineLength && contentStart[lineLength - 1] <= ' ') {
|
|
|
|
--lineLength;
|
|
|
|
}
|
|
|
|
string str(contentStart, lineLength);
|
|
|
|
this->writeString(str.c_str());
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
if (paragraph.eof()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ('\n' == paragraph.next()) {
|
2018-01-04 21:11:51 +00:00
|
|
|
int linefeeds = 1;
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!paragraph.eof() && '\n' == paragraph.peek()) {
|
|
|
|
linefeeds = 2;
|
|
|
|
}
|
|
|
|
this->lf(linefeeds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-01 14:37:32 +00:00
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
void MdOut::rowOut(const char* name, string description) {
|
2018-02-01 14:37:32 +00:00
|
|
|
this->lfAlways(1);
|
|
|
|
FPRINTF("| ");
|
|
|
|
this->resolveOut(name, name + strlen(name), BmhParser::Resolvable::kYes);
|
|
|
|
FPRINTF(" | ");
|
|
|
|
this->resolveOut(&description.front(), &description.back() + 1, BmhParser::Resolvable::kYes);
|
|
|
|
FPRINTF(" |");
|
|
|
|
this->lf(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MdOut::subtopicsOut() {
|
|
|
|
const Definition* csParent = this->csParent();
|
|
|
|
SkASSERT(csParent);
|
|
|
|
this->rowOut("name", "description");
|
|
|
|
this->rowOut("---", "---");
|
2018-04-16 12:37:38 +00:00
|
|
|
for (auto item : { kClassesAndStructs, kConstants, kConstructors, kDefines,
|
|
|
|
kMemberFunctions, kMembers, kOperators, kRelatedFunctions, kTypedefs } ) {
|
2018-02-06 14:41:53 +00:00
|
|
|
for (auto entry : this->populator(item).fMembers) {
|
2018-02-01 14:37:32 +00:00
|
|
|
if (entry->csParent() == csParent) {
|
|
|
|
string description = fPopulators.find(item)->second.fDescription;
|
|
|
|
if (kConstructors == item) {
|
|
|
|
description += " " + csParent->fName;
|
|
|
|
}
|
|
|
|
this->rowOut(item, description);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-06 14:41:53 +00:00
|
|
|
void MdOut::subtopicOut(const TableContents& tableContents) {
|
|
|
|
const auto& data = tableContents.fMembers;
|
2018-02-01 14:37:32 +00:00
|
|
|
const Definition* csParent = this->csParent();
|
|
|
|
SkASSERT(csParent);
|
|
|
|
fRoot = csParent->asRoot();
|
|
|
|
this->rowOut("name", "description");
|
|
|
|
this->rowOut("---", "---");
|
|
|
|
std::map<string, const Definition*> items;
|
|
|
|
for (auto entry : data) {
|
|
|
|
if (entry->csParent() != csParent) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
size_t start = entry->fName.find_last_of("::");
|
|
|
|
string name = entry->fName.substr(string::npos == start ? 0 : start + 1);
|
|
|
|
items[name] = entry;
|
|
|
|
}
|
|
|
|
for (auto entry : items) {
|
2018-02-06 14:41:53 +00:00
|
|
|
if (entry.second->fDeprecated) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-02-01 14:37:32 +00:00
|
|
|
const Definition* oneLiner = nullptr;
|
|
|
|
for (auto child : entry.second->fChildren) {
|
|
|
|
if (MarkType::kLine == child->fMarkType) {
|
|
|
|
oneLiner = child;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-02-20 19:33:13 +00:00
|
|
|
if (!oneLiner) {
|
2018-03-20 19:53:27 +00:00
|
|
|
TextParser parser(entry.second->fFileName, entry.second->fStart,
|
|
|
|
entry.second->fContentStart, entry.second->fLineCount);
|
|
|
|
parser.reportError("missing #Line");
|
|
|
|
continue;
|
2018-02-20 19:33:13 +00:00
|
|
|
}
|
2018-02-01 14:37:32 +00:00
|
|
|
this->rowOut(entry.first.c_str(), string(oneLiner->fContentStart,
|
|
|
|
oneLiner->fContentEnd - oneLiner->fContentStart));
|
2018-02-06 14:41:53 +00:00
|
|
|
if (tableContents.fShowClones && entry.second->fCloned) {
|
|
|
|
int cloneNo = 2;
|
|
|
|
string builder = entry.second->fName;
|
|
|
|
if ("()" == builder.substr(builder.length() - 2)) {
|
|
|
|
builder = builder.substr(0, builder.length() - 2);
|
|
|
|
}
|
|
|
|
builder += '_';
|
2018-02-07 12:27:09 +00:00
|
|
|
this->rowOut("",
|
|
|
|
preformat(entry.second->formatFunction(Definition::Format::kOmitReturn)));
|
2018-02-06 14:41:53 +00:00
|
|
|
do {
|
|
|
|
string match = builder + to_string(cloneNo);
|
|
|
|
auto child = csParent->findClone(match);
|
|
|
|
if (!child) {
|
|
|
|
break;
|
|
|
|
}
|
2018-02-07 12:27:09 +00:00
|
|
|
this->rowOut("", preformat(child->formatFunction(Definition::Format::kOmitReturn)));
|
2018-02-06 14:41:53 +00:00
|
|
|
} while (++cloneNo);
|
|
|
|
}
|
2018-02-01 14:37:32 +00:00
|
|
|
}
|
|
|
|
}
|