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"
|
2018-06-08 15:54:32 +00:00
|
|
|
#include <chrono>
|
|
|
|
#include <ctime>
|
|
|
|
#include <string>
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
bool IncludeWriter::checkChildCommentLength(const Definition* parent, MarkType childType) const {
|
|
|
|
bool oneMember = false;
|
|
|
|
for (auto& item : parent->fChildren) {
|
|
|
|
if (childType != item->fMarkType) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
oneMember = true;
|
|
|
|
int lineLen = 0;
|
|
|
|
for (auto& itemChild : item->fChildren) {
|
|
|
|
if (MarkType::kExperimental == itemChild->fMarkType) {
|
|
|
|
lineLen = sizeof("experimental") - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (MarkType::kDeprecated == itemChild->fMarkType) {
|
|
|
|
lineLen = sizeof("deprecated") - 1;
|
|
|
|
// todo: look for 'soon'
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (MarkType::kLine == itemChild->fMarkType) {
|
|
|
|
lineLen = itemChild->length();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!lineLen) {
|
|
|
|
item->reportError<void>("missing #Line");
|
|
|
|
}
|
|
|
|
if (fEnumItemCommentTab + lineLen >= 100) {
|
|
|
|
// if too long, remove spaces until it fits, or wrap
|
|
|
|
// item->reportError<void>("#Line comment too long");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return oneMember;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IncludeWriter::checkEnumLengths(const Definition& child, string enumName, ItemLength* length) const {
|
|
|
|
const Definition* enumItem = this->matchMemberName(enumName, child);
|
|
|
|
if (std::any_of(enumItem->fChildren.begin(), enumItem->fChildren.end(),
|
|
|
|
[](Definition* child){return MarkType::kNoJustify == child->fMarkType;})) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
string comment = this->enumMemberComment(enumItem, child);
|
|
|
|
int lineLimit = 100 - fIndent - 7; // 7: , space //!< space
|
|
|
|
if (length->fCurValue) {
|
|
|
|
lineLimit -= 3; // space = space
|
|
|
|
}
|
|
|
|
if (length->fCurName + length->fCurValue + (int) comment.length() < lineLimit) {
|
|
|
|
length->fLongestName = SkTMax(length->fLongestName, length->fCurName);
|
|
|
|
length->fLongestValue = SkTMax(length->fLongestValue, length->fCurValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-30 13:21:49 +00:00
|
|
|
void IncludeWriter::constOut(const Definition* memberStart, const Definition* bmhConst) {
|
2018-02-20 15:35:29 +00:00
|
|
|
const char* bodyEnd = fDeferComment ? fDeferComment->fContentStart - 1 :
|
|
|
|
memberStart->fContentStart;
|
2018-06-07 13:59:07 +00:00
|
|
|
this->firstBlockTrim((int) (bodyEnd - fStart), fStart); // may write nothing
|
2018-02-20 15:35:29 +00:00
|
|
|
this->lf(2);
|
2018-06-07 13:59:07 +00:00
|
|
|
this->indentDeferred(IndentKind::kConstOut);
|
|
|
|
if (fStructEnded) {
|
|
|
|
fIndent = fICSStack.size() * 4;
|
|
|
|
fStructEnded = false;
|
|
|
|
}
|
|
|
|
// comment may be legitimately empty; typedef may not have separate comment (for now)
|
|
|
|
fReturnOnWrite = true;
|
|
|
|
bool commentHasLength = this->descriptionOut(bmhConst, SkipFirstLine::kYes, Phrase::kNo);
|
|
|
|
fReturnOnWrite = false;
|
|
|
|
if (commentHasLength) {
|
|
|
|
this->writeCommentHeader();
|
|
|
|
fIndent += 4;
|
|
|
|
if (!this->descriptionOut(bmhConst, SkipFirstLine::kYes, Phrase::kNo)) {
|
|
|
|
return memberStart->reportError<void>("expected description for const");
|
|
|
|
}
|
|
|
|
fIndent -= 4;
|
|
|
|
this->writeCommentTrailer(OneLine::kNo);
|
2018-05-30 13:21:49 +00:00
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
this->setStart(memberStart->fContentStart, memberStart);
|
2018-02-08 19:45:18 +00:00
|
|
|
}
|
|
|
|
|
2018-05-30 13:21:49 +00:00
|
|
|
bool IncludeWriter::descriptionOut(const Definition* def, SkipFirstLine skipFirstLine,
|
2018-03-05 18:26:16 +00:00
|
|
|
Phrase phrase) {
|
2018-05-30 13:21:49 +00:00
|
|
|
bool wroteSomething = false;
|
2017-09-21 16:31:06 +00:00
|
|
|
const char* commentStart = def->fContentStart;
|
2018-02-20 15:35:29 +00:00
|
|
|
if (SkipFirstLine::kYes == skipFirstLine) {
|
|
|
|
TextParser parser(def);
|
|
|
|
SkAssertResult(parser.skipLine());
|
|
|
|
commentStart = parser.fChar;
|
|
|
|
}
|
|
|
|
int commentLen = (int) (def->fContentEnd - commentStart);
|
|
|
|
bool breakOut = false;
|
2017-10-26 11:58:48 +00:00
|
|
|
SkDEBUGCODE(bool wroteCode = false);
|
2018-02-20 15:35:29 +00:00
|
|
|
if (def->fDeprecated) {
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fReturnOnWrite) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
string message = def->incompleteMessage(Definition::DetailsType::kSentence);
|
|
|
|
this->writeString(message);
|
2018-02-20 15:35:29 +00:00
|
|
|
this->lfcr();
|
2018-05-30 13:21:49 +00:00
|
|
|
wroteSomething = true;
|
2018-02-20 15:35:29 +00:00
|
|
|
}
|
2018-05-30 13:21:49 +00:00
|
|
|
const Definition* lastDescription = def;
|
2017-09-21 16:31:06 +00:00
|
|
|
for (auto prop : def->fChildren) {
|
2018-05-30 13:21:49 +00:00
|
|
|
fLastDescription = lastDescription;
|
|
|
|
lastDescription = prop;
|
2017-09-21 16:31:06 +00:00
|
|
|
switch (prop->fMarkType) {
|
2017-10-26 11:58:48 +00:00
|
|
|
case MarkType::kCode: {
|
|
|
|
bool literal = false;
|
|
|
|
bool literalOutdent = false;
|
|
|
|
commentLen = (int) (prop->fStart - commentStart);
|
|
|
|
if (commentLen > 0) {
|
|
|
|
SkASSERT(commentLen < 1000);
|
|
|
|
if (Wrote::kNone != this->rewriteBlock(commentLen, commentStart, Phrase::kNo)) {
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fReturnOnWrite) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-26 11:58:48 +00:00
|
|
|
this->lf(2);
|
2018-05-30 13:21:49 +00:00
|
|
|
wroteSomething = true;
|
2017-10-26 11:58:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
size_t childSize = prop->fChildren.size();
|
|
|
|
if (childSize) {
|
2018-06-08 15:54:32 +00:00
|
|
|
if (MarkType::kLiteral == prop->fChildren[0]->fMarkType) {
|
|
|
|
SkASSERT(1 == childSize || 2 == childSize); // incomplete
|
|
|
|
SkASSERT(1 == childSize || MarkType::kOutdent == prop->fChildren[1]->fMarkType);
|
|
|
|
commentStart = prop->fChildren[childSize - 1]->fContentStart;
|
|
|
|
literal = true;
|
|
|
|
literalOutdent = 2 == childSize &&
|
|
|
|
MarkType::kOutdent == prop->fChildren[1]->fMarkType;
|
|
|
|
}
|
2017-10-26 11:58:48 +00:00
|
|
|
}
|
|
|
|
commentLen = (int) (prop->fContentEnd - commentStart);
|
|
|
|
SkASSERT(commentLen > 0);
|
|
|
|
if (literal) {
|
2018-06-07 13:59:07 +00:00
|
|
|
if (!fReturnOnWrite && !literalOutdent) {
|
2017-10-26 11:58:48 +00:00
|
|
|
fIndent += 4;
|
|
|
|
}
|
2018-05-30 13:21:49 +00:00
|
|
|
wroteSomething |= this->writeBlockIndent(commentLen, commentStart);
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fReturnOnWrite) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!fReturnOnWrite) {
|
|
|
|
this->lf(2);
|
|
|
|
if (!literalOutdent) {
|
|
|
|
fIndent -= 4;
|
|
|
|
}
|
2017-10-26 11:58:48 +00:00
|
|
|
}
|
|
|
|
SkDEBUGCODE(wroteCode = true);
|
|
|
|
}
|
2018-05-30 13:21:49 +00:00
|
|
|
commentStart = prop->fTerminator;
|
2017-10-26 11:58:48 +00:00
|
|
|
} break;
|
2018-02-20 15:35:29 +00:00
|
|
|
case MarkType::kBug: {
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fReturnOnWrite) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-20 15:35:29 +00:00
|
|
|
string bugstr("(see skbug.com/" + string(prop->fContentStart,
|
|
|
|
prop->fContentEnd - prop->fContentStart) + ')');
|
|
|
|
this->writeString(bugstr);
|
|
|
|
this->lfcr();
|
2018-05-30 13:21:49 +00:00
|
|
|
wroteSomething = true;
|
2018-02-20 15:35:29 +00:00
|
|
|
}
|
2017-10-09 19:45:33 +00:00
|
|
|
case MarkType::kDeprecated:
|
2017-09-21 16:31:06 +00:00
|
|
|
case MarkType::kPrivate:
|
|
|
|
commentLen = (int) (prop->fStart - commentStart);
|
|
|
|
if (commentLen > 0) {
|
|
|
|
SkASSERT(commentLen < 1000);
|
|
|
|
if (Wrote::kNone != this->rewriteBlock(commentLen, commentStart, Phrase::kNo)) {
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fReturnOnWrite) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-09-21 16:31:06 +00:00
|
|
|
this->lfcr();
|
2018-05-30 13:21:49 +00:00
|
|
|
wroteSomething = true;
|
2017-09-21 16:31:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
commentStart = prop->fContentStart;
|
2018-05-30 13:21:49 +00:00
|
|
|
if (MarkType::kPrivate != prop->fMarkType && ' ' < commentStart[0]) {
|
2018-05-16 11:07:07 +00:00
|
|
|
commentStart = strchr(commentStart, '\n');
|
|
|
|
}
|
|
|
|
if (MarkType::kBug == prop->fMarkType) {
|
2018-02-20 15:35:29 +00:00
|
|
|
commentStart = prop->fContentEnd;
|
|
|
|
}
|
2017-09-21 16:31:06 +00:00
|
|
|
commentLen = (int) (prop->fContentEnd - commentStart);
|
|
|
|
if (commentLen > 0) {
|
2018-05-30 13:21:49 +00:00
|
|
|
wroteSomething |= this->writeBlockIndent(commentLen, commentStart);
|
2018-06-07 13:59:07 +00:00
|
|
|
if (wroteSomething && fReturnOnWrite) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-05 18:26:16 +00:00
|
|
|
const char* end = commentStart + commentLen;
|
|
|
|
while (end > commentStart && ' ' == end[-1]) {
|
|
|
|
--end;
|
|
|
|
}
|
|
|
|
if (end > commentStart && '\n' == end[-1]) {
|
2018-01-03 13:37:53 +00:00
|
|
|
this->lfcr();
|
|
|
|
}
|
2017-09-21 16:31:06 +00:00
|
|
|
}
|
|
|
|
commentStart = prop->fTerminator;
|
|
|
|
commentLen = (int) (def->fContentEnd - commentStart);
|
|
|
|
break;
|
|
|
|
case MarkType::kExperimental:
|
|
|
|
commentStart = prop->fContentStart;
|
2018-05-16 11:07:07 +00:00
|
|
|
if (' ' < commentStart[0]) {
|
|
|
|
commentStart = strchr(commentStart, '\n');
|
|
|
|
}
|
2017-09-21 16:31:06 +00:00
|
|
|
commentLen = (int) (prop->fContentEnd - commentStart);
|
|
|
|
if (commentLen > 0) {
|
|
|
|
if (Wrote::kNone != this->rewriteBlock(commentLen, commentStart, Phrase::kNo)) {
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fReturnOnWrite) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-09-21 16:31:06 +00:00
|
|
|
this->lfcr();
|
2018-05-30 13:21:49 +00:00
|
|
|
wroteSomething = true;
|
2017-09-21 16:31:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
commentStart = prop->fTerminator;
|
|
|
|
commentLen = (int) (def->fContentEnd - commentStart);
|
|
|
|
break;
|
2017-10-26 11:58:48 +00:00
|
|
|
case MarkType::kFormula: {
|
2017-09-21 16:31:06 +00:00
|
|
|
commentLen = prop->fStart - commentStart;
|
|
|
|
if (commentLen > 0) {
|
|
|
|
if (Wrote::kNone != this->rewriteBlock(commentLen, commentStart, Phrase::kNo)) {
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fReturnOnWrite) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-26 11:58:48 +00:00
|
|
|
if (commentLen > 1 && '\n' == prop->fStart[-1] &&
|
|
|
|
'\n' == prop->fStart[-2]) {
|
|
|
|
this->lf(1);
|
|
|
|
} else {
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
2018-05-30 13:21:49 +00:00
|
|
|
wroteSomething = true;
|
2017-09-21 16:31:06 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-26 11:58:48 +00:00
|
|
|
int saveIndent = fIndent;
|
|
|
|
if (fIndent < fColumn + 1) {
|
|
|
|
fIndent = fColumn + 1;
|
|
|
|
}
|
2018-05-30 13:21:49 +00:00
|
|
|
wroteSomething |= this->writeBlockIndent(prop->length(), prop->fContentStart);
|
2017-10-26 11:58:48 +00:00
|
|
|
fIndent = saveIndent;
|
2018-06-07 13:59:07 +00:00
|
|
|
if (wroteSomething && fReturnOnWrite) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-09-21 16:31:06 +00:00
|
|
|
commentStart = prop->fTerminator;
|
|
|
|
commentLen = (int) (def->fContentEnd - commentStart);
|
2018-06-07 13:59:07 +00:00
|
|
|
if (!fReturnOnWrite) {
|
|
|
|
if (commentLen > 1 && '\n' == commentStart[0] && '\n' == commentStart[1]) {
|
|
|
|
this->lf(2);
|
|
|
|
} else {
|
|
|
|
SkASSERT('\n' == prop->fTerminator[0]);
|
|
|
|
if ('.' != prop->fTerminator[1] && !fLinefeeds) {
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
2017-10-26 11:58:48 +00:00
|
|
|
}
|
2017-09-21 16:31:06 +00:00
|
|
|
}
|
2017-10-26 11:58:48 +00:00
|
|
|
} break;
|
2018-06-07 13:59:07 +00:00
|
|
|
case MarkType::kDetails:
|
2018-01-30 15:08:57 +00:00
|
|
|
case MarkType::kIn:
|
|
|
|
case MarkType::kLine:
|
2017-09-21 16:31:06 +00:00
|
|
|
case MarkType::kToDo:
|
|
|
|
commentLen = (int) (prop->fStart - commentStart);
|
|
|
|
if (commentLen > 0) {
|
|
|
|
SkASSERT(commentLen < 1000);
|
|
|
|
if (Wrote::kNone != this->rewriteBlock(commentLen, commentStart, Phrase::kNo)) {
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fReturnOnWrite) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-09-21 16:31:06 +00:00
|
|
|
this->lfcr();
|
2018-05-30 13:21:49 +00:00
|
|
|
wroteSomething = true;
|
2017-09-21 16:31:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
commentStart = prop->fTerminator;
|
|
|
|
commentLen = (int) (def->fContentEnd - commentStart);
|
|
|
|
break;
|
|
|
|
case MarkType::kList:
|
|
|
|
commentLen = prop->fStart - commentStart;
|
|
|
|
if (commentLen > 0) {
|
|
|
|
if (Wrote::kNone != this->rewriteBlock(commentLen, commentStart,
|
|
|
|
Phrase::kNo)) {
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fReturnOnWrite) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-09-21 16:31:06 +00:00
|
|
|
this->lfcr();
|
2018-05-30 13:21:49 +00:00
|
|
|
wroteSomething = true;
|
2017-09-21 16:31:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto row : prop->fChildren) {
|
|
|
|
SkASSERT(MarkType::kRow == row->fMarkType);
|
|
|
|
for (auto column : row->fChildren) {
|
|
|
|
SkASSERT(MarkType::kColumn == column->fMarkType);
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fReturnOnWrite) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-09-21 16:31:06 +00:00
|
|
|
this->writeString("-");
|
|
|
|
this->writeSpace();
|
2018-05-30 13:21:49 +00:00
|
|
|
wroteSomething |= this->descriptionOut(column, SkipFirstLine::kNo, Phrase::kNo);
|
2017-09-21 16:31:06 +00:00
|
|
|
this->lf(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
commentStart = prop->fTerminator;
|
|
|
|
commentLen = (int) (def->fContentEnd - commentStart);
|
|
|
|
if ('\n' == commentStart[0] && '\n' == commentStart[1]) {
|
|
|
|
this->lf(2);
|
|
|
|
}
|
|
|
|
break;
|
2018-03-05 18:26:16 +00:00
|
|
|
case MarkType::kPhraseRef: {
|
|
|
|
commentLen = prop->fStart - commentStart;
|
|
|
|
if (commentLen > 0) {
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fReturnOnWrite) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-05 18:26:16 +00:00
|
|
|
this->rewriteBlock(commentLen, commentStart, Phrase::kNo);
|
|
|
|
// ince we don't do line wrapping, always insert LF before phrase
|
|
|
|
this->lfcr(); // TODO: remove this once rewriteBlock rewraps paragraphs
|
2018-05-30 13:21:49 +00:00
|
|
|
wroteSomething = true;
|
2018-03-05 18:26:16 +00:00
|
|
|
}
|
|
|
|
auto iter = fBmhParser->fPhraseMap.find(prop->fName);
|
|
|
|
if (fBmhParser->fPhraseMap.end() == iter) {
|
2018-05-30 13:21:49 +00:00
|
|
|
return this->reportError<bool>("missing phrase definition");
|
2018-03-05 18:26:16 +00:00
|
|
|
}
|
|
|
|
Definition* phraseDef = iter->second;
|
2018-05-16 11:07:07 +00:00
|
|
|
// TODO: given TextParser(commentStart, prop->fStart + up to #) return if
|
|
|
|
// it ends with two of more linefeeds, ignoring other whitespace
|
|
|
|
Phrase defIsPhrase = '\n' == prop->fStart[0] && '\n' == prop->fStart[-1] ?
|
|
|
|
Phrase::kNo : Phrase::kYes;
|
|
|
|
if (Phrase::kNo == defIsPhrase) {
|
|
|
|
this->lf(2);
|
|
|
|
}
|
|
|
|
const char* start = phraseDef->fContentStart;
|
|
|
|
int length = phraseDef->length();
|
|
|
|
auto propParams = prop->fChildren.begin();
|
|
|
|
// can this share code or logic with mdout somehow?
|
|
|
|
for (auto child : phraseDef->fChildren) {
|
|
|
|
if (MarkType::kPhraseParam == child->fMarkType) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int localLength = child->fStart - start;
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fReturnOnWrite) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
this->rewriteBlock(localLength, start, defIsPhrase);
|
|
|
|
start += localLength;
|
|
|
|
length -= localLength;
|
|
|
|
SkASSERT(propParams != prop->fChildren.end());
|
|
|
|
if (fColumn > 0) {
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
|
|
|
this->writeString((*propParams)->fName);
|
|
|
|
localLength = child->fContentEnd - child->fStart;
|
|
|
|
start += localLength;
|
|
|
|
length -= localLength;
|
|
|
|
if (isspace(start[0])) {
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
|
|
|
defIsPhrase = Phrase::kYes;
|
2018-05-30 13:21:49 +00:00
|
|
|
wroteSomething = true;
|
2018-05-16 11:07:07 +00:00
|
|
|
}
|
|
|
|
if (length > 0) {
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fReturnOnWrite) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
this->rewriteBlock(length, start, defIsPhrase);
|
|
|
|
}
|
2018-03-05 18:26:16 +00:00
|
|
|
commentStart = prop->fContentStart;
|
|
|
|
commentLen = (int) (def->fContentEnd - commentStart);
|
2018-06-07 13:59:07 +00:00
|
|
|
if (!fReturnOnWrite) {
|
|
|
|
if ('\n' == commentStart[0] && '\n' == commentStart[1]) {
|
|
|
|
this->lf(2);
|
|
|
|
}
|
2018-05-30 13:21:49 +00:00
|
|
|
}
|
2018-03-05 18:26:16 +00:00
|
|
|
} break;
|
2017-09-21 16:31:06 +00:00
|
|
|
default:
|
|
|
|
commentLen = (int) (prop->fStart - commentStart);
|
|
|
|
breakOut = true;
|
|
|
|
}
|
|
|
|
if (breakOut) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
if (!breakOut) {
|
|
|
|
commentLen = (int) (def->fContentEnd - commentStart);
|
|
|
|
}
|
2018-02-06 14:41:53 +00:00
|
|
|
SkASSERT(wroteCode || (commentLen > 0 && commentLen < 1500) || def->fDeprecated);
|
2017-10-26 11:58:48 +00:00
|
|
|
if (commentLen > 0) {
|
2018-06-07 13:59:07 +00:00
|
|
|
if (Wrote::kNone != this->rewriteBlock(commentLen, commentStart, phrase)) {
|
|
|
|
if (fReturnOnWrite) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
wroteSomething = true;
|
|
|
|
}
|
2017-10-26 11:58:48 +00:00
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
SkASSERT(!fReturnOnWrite || !wroteSomething);
|
2018-05-30 13:21:49 +00:00
|
|
|
return wroteSomething;
|
2017-09-21 16:31:06 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
void IncludeWriter::enumHeaderOut(RootDefinition* root, const Definition& child) {
|
2017-07-28 15:04:54 +00:00
|
|
|
const Definition* enumDef = nullptr;
|
|
|
|
const char* bodyEnd = fDeferComment ? fDeferComment->fContentStart - 1 :
|
|
|
|
child.fContentStart;
|
2018-06-07 13:59:07 +00:00
|
|
|
this->firstBlockTrim((int) (bodyEnd - fStart), fStart); // may write nothing
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lf(2);
|
2018-06-07 13:59:07 +00:00
|
|
|
this->indentDeferred(IndentKind::kEnumHeader);
|
2017-07-28 15:04:54 +00:00
|
|
|
fDeferComment = nullptr;
|
2018-06-07 13:59:07 +00:00
|
|
|
this->setStart(child.fContentStart, &child);
|
2017-07-28 15:04:54 +00:00
|
|
|
const auto& nameDef = child.fTokens.front();
|
|
|
|
string fullName;
|
|
|
|
if (nullptr != nameDef.fContentEnd) {
|
2017-08-03 21:14:08 +00:00
|
|
|
TextParser enumClassCheck(&nameDef);
|
|
|
|
const char* start = enumClassCheck.fStart;
|
|
|
|
size_t len = (size_t) (enumClassCheck.fEnd - start);
|
|
|
|
bool enumClass = enumClassCheck.skipExact("class ");
|
|
|
|
if (enumClass) {
|
|
|
|
start = enumClassCheck.fChar;
|
|
|
|
const char* end = enumClassCheck.anyOf(" \n;{");
|
|
|
|
len = (size_t) (end - start);
|
|
|
|
}
|
|
|
|
string enumName(start, len);
|
|
|
|
if (enumClass) {
|
|
|
|
child.fChildren[0]->fName = enumName;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
fullName = root->fName + "::" + enumName;
|
2017-09-01 19:51:02 +00:00
|
|
|
enumDef = root->find(enumName, RootDefinition::AllowParens::kNo);
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!enumDef) {
|
2017-09-01 19:51:02 +00:00
|
|
|
enumDef = root->find(fullName, RootDefinition::AllowParens::kNo);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-03-20 19:53:27 +00:00
|
|
|
if (!enumDef) {
|
|
|
|
auto mapEntry = fBmhParser->fEnumMap.find(enumName);
|
|
|
|
if (fBmhParser->fEnumMap.end() != mapEntry) {
|
|
|
|
enumDef = &mapEntry->second;
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
SkASSERT(enumDef);
|
|
|
|
// child[0] should be #Code comment starts at child[0].fTerminator
|
|
|
|
// though skip until #Code is found (in case there's a #ToDo, etc)
|
|
|
|
// child[1] should be #Const comment ends at child[1].fStart
|
|
|
|
// comment becomes enum header (if any)
|
|
|
|
} else {
|
|
|
|
string enumName(root->fName);
|
|
|
|
enumName += "::_anonymous";
|
|
|
|
if (fAnonymousEnumCount > 1) {
|
|
|
|
enumName += '_' + to_string(fAnonymousEnumCount);
|
|
|
|
}
|
2017-09-01 19:51:02 +00:00
|
|
|
enumDef = root->find(enumName, RootDefinition::AllowParens::kNo);
|
2017-07-28 15:04:54 +00:00
|
|
|
SkASSERT(enumDef);
|
|
|
|
++fAnonymousEnumCount;
|
|
|
|
}
|
|
|
|
Definition* codeBlock = nullptr;
|
|
|
|
const char* commentStart = nullptr;
|
|
|
|
bool wroteHeader = false;
|
2017-09-21 16:31:06 +00:00
|
|
|
bool lastAnchor = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
SkDEBUGCODE(bool foundConst = false);
|
|
|
|
for (auto test : enumDef->fChildren) {
|
2018-05-16 11:07:07 +00:00
|
|
|
if (MarkType::kCode == test->fMarkType && !codeBlock) {
|
2017-07-28 15:04:54 +00:00
|
|
|
codeBlock = test;
|
|
|
|
commentStart = codeBlock->fTerminator;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!codeBlock) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const char* commentEnd = test->fStart;
|
|
|
|
if (!wroteHeader &&
|
|
|
|
!this->contentFree((int) (commentEnd - commentStart), commentStart)) {
|
2017-10-26 11:58:48 +00:00
|
|
|
if (fIndentNext) {
|
2018-06-07 13:59:07 +00:00
|
|
|
// FIXME: how can I tell where fIdentNext gets cleared?
|
|
|
|
this->indentIn(IndentKind::kEnumChild);
|
2017-10-26 11:58:48 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
this->writeCommentHeader();
|
|
|
|
this->writeString("\\enum");
|
2017-08-03 21:14:08 +00:00
|
|
|
if (fullName.length() > 0) {
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeString(fullName.c_str());
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
this->indentIn(IndentKind::kEnumChild2);
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lfcr();
|
|
|
|
wroteHeader = true;
|
|
|
|
}
|
2017-09-21 16:31:06 +00:00
|
|
|
if (lastAnchor) {
|
|
|
|
if (commentEnd - commentStart > 1) {
|
|
|
|
SkASSERT('\n' == commentStart[0]);
|
|
|
|
if (' ' == commentStart[1]) {
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastAnchor = false;
|
|
|
|
}
|
2017-09-14 15:25:39 +00:00
|
|
|
this->rewriteBlock((int) (commentEnd - commentStart), commentStart, Phrase::kNo);
|
2018-05-16 11:07:07 +00:00
|
|
|
if (MarkType::kAnchor == test->fMarkType || MarkType::kCode == test->fMarkType) {
|
2017-10-26 11:58:48 +00:00
|
|
|
bool newLine = commentEnd - commentStart > 1 &&
|
|
|
|
'\n' == commentEnd[-1] && '\n' == commentEnd[-2];
|
2017-07-28 15:04:54 +00:00
|
|
|
commentStart = test->fContentStart;
|
2018-05-16 11:07:07 +00:00
|
|
|
commentEnd = MarkType::kAnchor == test->fMarkType ? test->fChildren[0]->fStart :
|
|
|
|
test->fContentEnd;
|
2017-10-26 11:58:48 +00:00
|
|
|
if (newLine) {
|
|
|
|
this->lf(2);
|
|
|
|
} else {
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
if (MarkType::kAnchor == test->fMarkType) {
|
|
|
|
this->rewriteBlock((int) (commentEnd - commentStart), commentStart, Phrase::kNo);
|
|
|
|
} else {
|
|
|
|
this->writeBlock((int) (commentEnd - commentStart), commentStart);
|
|
|
|
this->lf(2);
|
|
|
|
}
|
2017-09-21 16:31:06 +00:00
|
|
|
lastAnchor = true; // this->writeSpace();
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
commentStart = test->fTerminator;
|
|
|
|
if (MarkType::kConst == test->fMarkType) {
|
|
|
|
SkASSERT(codeBlock); // FIXME: check enum for correct order earlier
|
|
|
|
SkDEBUGCODE(foundConst = true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkASSERT(codeBlock);
|
|
|
|
SkASSERT(foundConst);
|
|
|
|
if (wroteHeader) {
|
2018-06-07 13:59:07 +00:00
|
|
|
this->indentOut();
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lfcr();
|
2018-05-30 13:21:49 +00:00
|
|
|
this->writeCommentTrailer(OneLine::kNo);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2017-08-03 21:14:08 +00:00
|
|
|
Definition* braceHolder = child.fChildren[0];
|
|
|
|
if (KeyWord::kClass == braceHolder->fKeyWord) {
|
|
|
|
braceHolder = braceHolder->fChildren[0];
|
|
|
|
}
|
|
|
|
bodyEnd = braceHolder->fContentStart;
|
2017-07-28 15:04:54 +00:00
|
|
|
SkASSERT('{' == bodyEnd[0]);
|
|
|
|
++bodyEnd;
|
|
|
|
this->lfcr();
|
|
|
|
this->writeBlock((int) (bodyEnd - fStart), fStart); // write include "enum Name {"
|
2018-06-07 13:59:07 +00:00
|
|
|
this->indentIn(IndentKind::kEnumHeader2);
|
2017-07-28 15:04:54 +00:00
|
|
|
this->singleLF();
|
2018-06-07 13:59:07 +00:00
|
|
|
this->setStart(bodyEnd, braceHolder);
|
2017-07-28 15:04:54 +00:00
|
|
|
fEnumDef = enumDef;
|
|
|
|
}
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
const Definition* IncludeWriter::enumMemberForComment(const Definition* currentEnumItem) const {
|
|
|
|
for (auto constItem : currentEnumItem->fChildren) {
|
|
|
|
if (MarkType::kLine == constItem->fMarkType
|
|
|
|
|| MarkType::kExperimental == constItem->fMarkType
|
|
|
|
|| MarkType::kDeprecated == constItem->fMarkType) {
|
|
|
|
return constItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkASSERT(0);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
string IncludeWriter::enumMemberComment(const Definition* currentEnumItem,
|
|
|
|
const Definition& child) const {
|
|
|
|
// #Const should always be followed by #Line, so description follows that
|
|
|
|
string shortComment;
|
|
|
|
for (auto constItem : currentEnumItem->fChildren) {
|
|
|
|
if (MarkType::kLine == constItem->fMarkType) {
|
|
|
|
shortComment = string(constItem->fContentStart, constItem->length());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (IncompleteAllowed(constItem->fMarkType)) {
|
2018-05-30 13:21:49 +00:00
|
|
|
shortComment = constItem->fParent->incompleteMessage(Definition::DetailsType::kPhrase);
|
2018-05-16 11:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!shortComment.length()) {
|
|
|
|
currentEnumItem->reportError<void>("missing #Line or #Deprecated or #Experimental");
|
|
|
|
}
|
|
|
|
return shortComment;
|
|
|
|
}
|
|
|
|
|
|
|
|
IncludeWriter::ItemState IncludeWriter::enumMemberName(
|
|
|
|
const Definition& child, const Definition* token, Item* item, LastItem* last,
|
|
|
|
const Definition** currentEnumItem) {
|
|
|
|
TextParser parser(fFileName, last->fStart, last->fEnd, fLineCount);
|
|
|
|
parser.skipWhiteSpace();
|
|
|
|
item->fName = string(parser.fChar, (int) (last->fEnd - parser.fChar));
|
|
|
|
*currentEnumItem = this->matchMemberName(item->fName, child);
|
|
|
|
if (token) {
|
2018-06-07 13:59:07 +00:00
|
|
|
this->setStart(token->fContentEnd, token);
|
2018-05-16 11:07:07 +00:00
|
|
|
TextParser enumLine(token->fFileName, last->fEnd, token->fContentStart, token->fLineCount);
|
|
|
|
const char* end = enumLine.anyOf(",}=");
|
|
|
|
SkASSERT(end);
|
|
|
|
if ('=' == *end) { // write enum value
|
|
|
|
last->fEnd = token->fContentEnd;
|
|
|
|
item->fValue = string(token->fContentStart, (int) (last->fEnd - token->fContentStart));
|
|
|
|
return ItemState::kValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ItemState::kComment;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IncludeWriter::enumMemberOut(const Definition* currentEnumItem, const Definition& child,
|
|
|
|
const Item& item, Preprocessor& preprocessor) {
|
|
|
|
SkASSERT(currentEnumItem);
|
|
|
|
string shortComment = this->enumMemberComment(currentEnumItem, child);
|
|
|
|
int enumItemValueTab =
|
|
|
|
SkTMax((int) item.fName.length() + fIndent + 1, fEnumItemValueTab); // 1: ,
|
|
|
|
int valueLength = item.fValue.length();
|
|
|
|
int assignLength = valueLength ? valueLength + 3 : 0; // 3: space = space
|
|
|
|
int enumItemCommentTab = SkTMax(enumItemValueTab + assignLength, fEnumItemCommentTab);
|
|
|
|
int trimNeeded = enumItemCommentTab + shortComment.length() - (100 - (sizeof("//!< ") - 1));
|
|
|
|
bool crAfterName = false;
|
|
|
|
if (trimNeeded > 0) {
|
|
|
|
if (item.fValue.length()) {
|
|
|
|
int valueSpare = SkTMin(trimNeeded, // 3 below: space = space
|
|
|
|
(int) (enumItemCommentTab - enumItemValueTab - item.fValue.length() - 3));
|
|
|
|
SkASSERT(valueSpare >= 0);
|
|
|
|
trimNeeded -= valueSpare;
|
|
|
|
enumItemCommentTab -= valueSpare;
|
|
|
|
}
|
|
|
|
if (trimNeeded > 0) {
|
|
|
|
int nameSpare = SkTMin(trimNeeded, (int) (enumItemValueTab - item.fName.length()
|
|
|
|
- fIndent - 1)); // 1: ,
|
|
|
|
SkASSERT(nameSpare >= 0);
|
|
|
|
trimNeeded -= nameSpare;
|
|
|
|
enumItemValueTab -= nameSpare;
|
|
|
|
enumItemCommentTab -= nameSpare;
|
|
|
|
}
|
|
|
|
if (trimNeeded > 0) {
|
|
|
|
crAfterName = true;
|
|
|
|
if (!valueLength) {
|
|
|
|
this->enumMemberForComment(currentEnumItem)->reportError<void>("comment too long");
|
|
|
|
} else if (valueLength + fIndent + 8 + shortComment.length() > // 8: addtional indent
|
|
|
|
100 - (sizeof(", //!< ") - 1)) { // -1: zero-terminated string
|
|
|
|
this->enumMemberForComment(currentEnumItem)->reportError<void>("comment 2 long");
|
|
|
|
} // 2: = space
|
|
|
|
enumItemValueTab = fEnumItemValueTab + 2 // 2: , space
|
|
|
|
- SkTMax(0, fEnumItemValueTab + 2 + valueLength + 2 - fEnumItemCommentTab);
|
|
|
|
enumItemCommentTab = SkTMax(enumItemValueTab + valueLength + 2, fEnumItemCommentTab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->lfcr();
|
|
|
|
this->writeString(item.fName);
|
|
|
|
int saveIndent = fIndent;
|
|
|
|
if (item.fValue.length()) {
|
|
|
|
if (!crAfterName) {
|
|
|
|
this->indentToColumn(enumItemValueTab);
|
|
|
|
} else {
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
|
|
|
this->writeString("=");
|
|
|
|
if (crAfterName) {
|
|
|
|
this->lfcr();
|
|
|
|
fIndent = enumItemValueTab;
|
|
|
|
} else {
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
|
|
|
this->writeString(item.fValue);
|
|
|
|
}
|
|
|
|
this->writeString(",");
|
|
|
|
this->indentToColumn(enumItemCommentTab);
|
|
|
|
this->writeString("//!<");
|
|
|
|
this->writeSpace();
|
|
|
|
this->rewriteBlock(shortComment.length(), shortComment.c_str(), Phrase::kYes);
|
|
|
|
this->lfcr();
|
|
|
|
fIndent = saveIndent;
|
|
|
|
if (preprocessor.fStart) {
|
|
|
|
SkASSERT(preprocessor.fEnd);
|
|
|
|
int saveIndent = fIndent;
|
|
|
|
fIndent = SkTMax(0, fIndent - 8);
|
|
|
|
this->lf(2);
|
|
|
|
this->writeBlock(
|
|
|
|
(int) (preprocessor.fEnd - preprocessor.fStart), preprocessor.fStart);
|
|
|
|
this->lfcr();
|
|
|
|
fIndent = saveIndent;
|
|
|
|
preprocessor.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// iterate through include tokens and find how much remains for 1 line comments
|
|
|
|
// put ones that fit on same line, ones that are too big wrap
|
|
|
|
void IncludeWriter::enumMembersOut(Definition& child) {
|
|
|
|
ItemState state = ItemState::kNone;
|
|
|
|
const Definition* currentEnumItem;
|
|
|
|
LastItem last = { nullptr, nullptr };
|
|
|
|
auto brace = child.fChildren[0];
|
|
|
|
if (KeyWord::kClass == brace->fKeyWord) {
|
|
|
|
brace = brace->fChildren[0];
|
|
|
|
}
|
|
|
|
SkASSERT(Bracket::kBrace == brace->fBracket);
|
2017-08-03 21:14:08 +00:00
|
|
|
vector<IterState> iterStack;
|
2018-05-16 11:07:07 +00:00
|
|
|
iterStack.emplace_back(brace->fTokens.begin(), brace->fTokens.end());
|
2017-08-03 21:14:08 +00:00
|
|
|
IterState* iterState = &iterStack[0];
|
2018-04-03 12:43:27 +00:00
|
|
|
Preprocessor preprocessor;
|
2018-05-16 11:07:07 +00:00
|
|
|
Item item;
|
|
|
|
while (iterState->fDefIter != iterState->fDefEnd) {
|
|
|
|
auto& token = *iterState->fDefIter++;
|
|
|
|
if (this->enumPreprocessor(&token, MemberPass::kOut, iterStack, &iterState,
|
2018-04-03 12:43:27 +00:00
|
|
|
&preprocessor)) {
|
2017-08-03 21:14:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
if (ItemState::kName == state) {
|
|
|
|
state = this->enumMemberName(child, &token, &item, &last, ¤tEnumItem);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
if (ItemState::kValue == state) {
|
|
|
|
TextParser valueEnd(token.fFileName, last.fEnd, token.fContentStart, token.fLineCount);
|
2017-07-28 15:04:54 +00:00
|
|
|
const char* end = valueEnd.anyOf(",}");
|
|
|
|
if (!end) { // write expression continuation
|
2018-05-16 11:07:07 +00:00
|
|
|
item.fValue += string(last.fEnd, (int) (token.fContentEnd - last.fEnd));
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
if (ItemState::kNone != state) {
|
|
|
|
this->enumMemberOut(currentEnumItem, child, item, preprocessor);
|
2018-05-30 13:21:49 +00:00
|
|
|
item.reset();
|
2018-06-07 13:59:07 +00:00
|
|
|
this->setStartBack(token.fContentStart, &token);
|
2018-05-16 11:07:07 +00:00
|
|
|
state = ItemState::kNone;
|
|
|
|
last.fStart = nullptr;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
SkASSERT(ItemState::kNone == state);
|
|
|
|
if (!last.fStart) {
|
|
|
|
last.fStart = fStart;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
last.fEnd = token.fContentEnd;
|
|
|
|
state = ItemState::kName;
|
|
|
|
}
|
|
|
|
if (ItemState::kName == state) {
|
|
|
|
state = this->enumMemberName(child, nullptr, &item, &last, ¤tEnumItem);
|
|
|
|
}
|
|
|
|
if (ItemState::kValue == state || ItemState::kComment == state) {
|
|
|
|
this->enumMemberOut(currentEnumItem, child, item, preprocessor);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
this->indentOut();
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 12:43:27 +00:00
|
|
|
bool IncludeWriter::enumPreprocessor(Definition* token, MemberPass pass,
|
|
|
|
vector<IterState>& iterStack, IterState** iterState, Preprocessor* preprocessor) {
|
|
|
|
if (token && Definition::Type::kBracket == token->fType) {
|
|
|
|
if (Bracket::kSlashSlash == token->fBracket) {
|
|
|
|
if (MemberPass::kOut == pass) {
|
2018-06-07 13:59:07 +00:00
|
|
|
this->setStart(token->fContentEnd, token);
|
2018-04-03 12:43:27 +00:00
|
|
|
}
|
|
|
|
return true; // ignore old inline comments
|
|
|
|
}
|
|
|
|
if (Bracket::kSlashStar == token->fBracket) {
|
|
|
|
if (MemberPass::kOut == pass) {
|
2018-06-07 13:59:07 +00:00
|
|
|
this->setStart(token->fContentEnd + 1, token);
|
2018-04-03 12:43:27 +00:00
|
|
|
}
|
|
|
|
return true; // ignore old inline comments
|
|
|
|
}
|
|
|
|
if (Bracket::kPound == token->fBracket) { // preprocessor wraps member
|
2018-04-03 19:31:59 +00:00
|
|
|
preprocessor->fDefinition = token;
|
2018-04-03 12:43:27 +00:00
|
|
|
preprocessor->fStart = token->fContentStart;
|
|
|
|
if (KeyWord::kIf == token->fKeyWord || KeyWord::kIfdef == token->fKeyWord) {
|
|
|
|
iterStack.emplace_back(token->fTokens.begin(), token->fTokens.end());
|
|
|
|
*iterState = &iterStack.back();
|
|
|
|
preprocessor->fWord = true;
|
|
|
|
} else if (KeyWord::kEndif == token->fKeyWord || KeyWord::kElif == token->fKeyWord
|
|
|
|
|| KeyWord::kElse == token->fKeyWord) {
|
|
|
|
iterStack.pop_back();
|
|
|
|
*iterState = &iterStack.back();
|
|
|
|
preprocessor->fEnd = token->fContentEnd;
|
|
|
|
if (KeyWord::kElif == token->fKeyWord) {
|
|
|
|
iterStack.emplace_back(token->fTokens.begin(), token->fTokens.end());
|
|
|
|
*iterState = &iterStack.back();
|
|
|
|
preprocessor->fWord = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SkASSERT(0); // incomplete
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-04-03 19:31:59 +00:00
|
|
|
if (preprocessor->fDefinition) {
|
|
|
|
if (Bracket::kParen == token->fBracket) {
|
|
|
|
preprocessor->fEnd = token->fContentEnd;
|
|
|
|
SkASSERT(')' == *preprocessor->fEnd);
|
|
|
|
++preprocessor->fEnd;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
SkASSERT(0); // incomplete
|
|
|
|
}
|
2018-04-03 12:43:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (token && Definition::Type::kWord != token->fType) {
|
|
|
|
SkASSERT(0); // incomplete
|
|
|
|
}
|
|
|
|
if (preprocessor->fWord) {
|
|
|
|
preprocessor->fWord = false;
|
|
|
|
preprocessor->fEnd = token->fContentEnd;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
void IncludeWriter::enumSizeItems(const Definition& child) {
|
2018-05-16 11:07:07 +00:00
|
|
|
ItemState state = ItemState::kNone;
|
|
|
|
ItemLength lengths = { 0, 0, 0, 0 };
|
2017-07-28 15:04:54 +00:00
|
|
|
const char* lastEnd = nullptr;
|
|
|
|
auto brace = child.fChildren[0];
|
2017-08-03 21:14:08 +00:00
|
|
|
if (KeyWord::kClass == brace->fKeyWord) {
|
|
|
|
brace = brace->fChildren[0];
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
SkASSERT(Bracket::kBrace == brace->fBracket);
|
2017-08-03 21:14:08 +00:00
|
|
|
vector<IterState> iterStack;
|
|
|
|
iterStack.emplace_back(brace->fTokens.begin(), brace->fTokens.end());
|
|
|
|
IterState* iterState = &iterStack[0];
|
2018-04-03 12:43:27 +00:00
|
|
|
Preprocessor preprocessor;
|
2018-05-16 11:07:07 +00:00
|
|
|
string enumName;
|
2017-08-03 21:14:08 +00:00
|
|
|
while (iterState->fDefIter != iterState->fDefEnd) {
|
|
|
|
auto& token = *iterState->fDefIter++;
|
2018-04-03 12:43:27 +00:00
|
|
|
if (this->enumPreprocessor(&token, MemberPass::kCount, iterStack, &iterState,
|
|
|
|
&preprocessor)) {
|
2017-08-03 21:14:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
if (ItemState::kName == state) {
|
|
|
|
TextParser enumLine(token.fFileName, lastEnd, token.fContentStart, token.fLineCount);
|
2017-07-28 15:04:54 +00:00
|
|
|
const char* end = enumLine.anyOf(",}=");
|
|
|
|
SkASSERT(end);
|
2018-05-16 11:07:07 +00:00
|
|
|
state = '=' == *end ? ItemState::kValue : ItemState::kComment;
|
|
|
|
if (ItemState::kValue == state) {
|
2017-07-28 15:04:54 +00:00
|
|
|
lastEnd = token.fContentEnd;
|
2018-05-16 11:07:07 +00:00
|
|
|
lengths.fCurValue = (int) (lastEnd - token.fContentStart);
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
if (ItemState::kValue == state) {
|
|
|
|
TextParser valueEnd(token.fFileName, lastEnd, token.fContentStart, token.fLineCount);
|
2017-07-28 15:04:54 +00:00
|
|
|
const char* end = valueEnd.anyOf(",}");
|
|
|
|
if (!end) { // write expression continuation
|
2018-05-16 11:07:07 +00:00
|
|
|
lengths.fCurValue += (int) (token.fContentEnd - lastEnd);
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
if (ItemState::kNone != state) {
|
|
|
|
this->checkEnumLengths(child, enumName, &lengths);
|
|
|
|
lengths.fCurValue = 0;
|
|
|
|
state = ItemState::kNone;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
SkASSERT(ItemState::kNone == state);
|
2017-07-28 15:04:54 +00:00
|
|
|
lastEnd = token.fContentEnd;
|
2018-05-16 11:07:07 +00:00
|
|
|
lengths.fCurName = (int) (lastEnd - token.fContentStart);
|
|
|
|
enumName = string(token.fContentStart, lengths.fCurName);
|
|
|
|
state = ItemState::kName;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
if (ItemState::kNone != state) {
|
|
|
|
this->checkEnumLengths(child, enumName, &lengths);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
fEnumItemValueTab = lengths.fLongestName + fIndent + 1 /* 1: , */ ;
|
|
|
|
if (lengths.fLongestValue) {
|
|
|
|
lengths.fLongestValue += 3; // 3: space = space
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
fEnumItemCommentTab = fEnumItemValueTab + lengths.fLongestValue + 1 ; // 1: space before //!<
|
2017-07-28 15:04:54 +00:00
|
|
|
// iterate through bmh children and see which comments fit on include lines
|
2018-05-16 11:07:07 +00:00
|
|
|
if (!this->checkChildCommentLength(fEnumDef, MarkType::kConst)) {
|
|
|
|
fEnumDef->reportError<void>("expected at least one #Const in #Enum");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Definition* IncludeWriter::matchMemberName(string matchName, const Definition& child) const {
|
|
|
|
const Definition* parent = &child;
|
|
|
|
if (KeyWord::kEnum == child.fKeyWord && child.fChildren.size() > 0
|
|
|
|
&& KeyWord::kClass == child.fChildren[0]->fKeyWord) {
|
|
|
|
matchName = child.fChildren[0]->fName + "::" + matchName;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
if (KeyWord::kStruct == parent->fKeyWord || KeyWord::kClass == parent->fKeyWord) {
|
|
|
|
matchName = parent->fName + "::" + matchName;
|
|
|
|
}
|
|
|
|
} while ((parent = parent->fParent));
|
|
|
|
const Definition* enumItem = nullptr;
|
|
|
|
for (auto testItem : fEnumDef->fChildren) {
|
|
|
|
if (MarkType::kConst != testItem->fMarkType) {
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
if (matchName != testItem->fName) {
|
|
|
|
continue;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
enumItem = testItem;
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-05-16 11:07:07 +00:00
|
|
|
SkASSERT(enumItem);
|
|
|
|
return enumItem;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// walk children and output complete method doxygen description
|
2018-05-16 11:07:07 +00:00
|
|
|
void IncludeWriter::methodOut(Definition* method, const Definition& child) {
|
2017-10-26 11:58:48 +00:00
|
|
|
if (fPendingMethod) {
|
2018-06-07 13:59:07 +00:00
|
|
|
this->indentOut();
|
2017-10-26 11:58:48 +00:00
|
|
|
fPendingMethod = false;
|
|
|
|
}
|
2017-07-31 15:48:27 +00:00
|
|
|
fBmhMethod = method;
|
|
|
|
fMethodDef = &child;
|
2017-07-28 15:04:54 +00:00
|
|
|
fContinuation = nullptr;
|
|
|
|
fDeferComment = nullptr;
|
2018-05-16 11:07:07 +00:00
|
|
|
Definition* csParent = method->csParent();
|
2018-04-03 19:31:59 +00:00
|
|
|
if (csParent && (0 == fIndent || fIndentNext)) {
|
2018-06-07 13:59:07 +00:00
|
|
|
this->indentIn(IndentKind::kMethodOut);
|
2017-10-26 11:58:48 +00:00
|
|
|
fIndentNext = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
this->writeCommentHeader();
|
|
|
|
fIndent += 4;
|
2018-03-05 18:26:16 +00:00
|
|
|
this->descriptionOut(method, SkipFirstLine::kNo, Phrase::kNo);
|
2017-07-28 15:04:54 +00:00
|
|
|
// compute indention column
|
|
|
|
size_t column = 0;
|
|
|
|
bool hasParmReturn = false;
|
|
|
|
for (auto methodPart : method->fChildren) {
|
|
|
|
if (MarkType::kParam == methodPart->fMarkType) {
|
|
|
|
column = SkTMax(column, methodPart->fName.length());
|
|
|
|
hasParmReturn = true;
|
|
|
|
} else if (MarkType::kReturn == methodPart->fMarkType) {
|
|
|
|
hasParmReturn = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hasParmReturn) {
|
|
|
|
this->lf(2);
|
|
|
|
column += fIndent + sizeof("@return ");
|
|
|
|
int saveIndent = fIndent;
|
|
|
|
for (auto methodPart : method->fChildren) {
|
|
|
|
if (MarkType::kParam == methodPart->fMarkType) {
|
|
|
|
this->writeString("@param");
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeString(methodPart->fName.c_str());
|
|
|
|
} else if (MarkType::kReturn == methodPart->fMarkType) {
|
|
|
|
this->writeString("@return");
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
2018-03-05 18:26:16 +00:00
|
|
|
this->indentToColumn(column);
|
|
|
|
fIndent = column;
|
|
|
|
this->descriptionOut(methodPart, SkipFirstLine::kNo, Phrase::kYes);
|
2017-07-28 15:04:54 +00:00
|
|
|
fIndent = saveIndent;
|
|
|
|
this->lfcr();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this->lfcr();
|
|
|
|
}
|
|
|
|
fIndent -= 4;
|
|
|
|
this->lfcr();
|
2018-05-30 13:21:49 +00:00
|
|
|
this->writeCommentTrailer(OneLine::kNo);
|
2017-07-31 15:48:27 +00:00
|
|
|
fBmhMethod = nullptr;
|
|
|
|
fMethodDef = nullptr;
|
2018-02-09 21:49:09 +00:00
|
|
|
fEnumDef = nullptr;
|
2017-09-14 15:25:39 +00:00
|
|
|
fWroteMethod = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IncludeWriter::structOut(const Definition* root, const Definition& child,
|
|
|
|
const char* commentStart, const char* commentEnd) {
|
|
|
|
this->writeCommentHeader();
|
|
|
|
this->writeString("\\");
|
|
|
|
SkASSERT(MarkType::kClass == child.fMarkType || MarkType::kStruct == child.fMarkType);
|
|
|
|
this->writeString(MarkType::kClass == child.fMarkType ? "class" : "struct");
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeString(child.fName.c_str());
|
|
|
|
fIndent += 4;
|
|
|
|
this->lfcr();
|
2018-02-20 15:35:29 +00:00
|
|
|
if (child.fDeprecated) {
|
2018-05-16 11:07:07 +00:00
|
|
|
this->writeString(child.incompleteMessage(Definition::DetailsType::kSentence));
|
2018-02-20 15:35:29 +00:00
|
|
|
} else {
|
|
|
|
this->rewriteBlock((int)(commentEnd - commentStart), commentStart, Phrase::kNo);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
fIndent -= 4;
|
|
|
|
this->lfcr();
|
2018-05-30 13:21:49 +00:00
|
|
|
this->writeCommentTrailer(OneLine::kNo);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 12:43:27 +00:00
|
|
|
bool IncludeWriter::findEnumSubtopic(string undername, const Definition** rootDefPtr) const {
|
|
|
|
const Definition* subtopic = fEnumDef->fParent;
|
|
|
|
string subcheck = subtopic->fFiddle + '_' + undername;
|
|
|
|
auto iter = fBmhParser->fTopicMap.find(subcheck);
|
|
|
|
if (iter == fBmhParser->fTopicMap.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*rootDefPtr = iter->second;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-26 17:56:22 +00:00
|
|
|
Definition* IncludeWriter::findMemberCommentBlock(const vector<Definition*>& bmhChildren,
|
2018-04-16 12:37:38 +00:00
|
|
|
string name) const {
|
2018-02-20 15:35:29 +00:00
|
|
|
for (auto memberDef : bmhChildren) {
|
|
|
|
if (MarkType::kMember != memberDef->fMarkType) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
string match = memberDef->fName;
|
|
|
|
// if match.endsWith(name) ...
|
2018-02-20 17:50:35 +00:00
|
|
|
if (match.length() >= name.length() &&
|
2018-02-20 15:35:29 +00:00
|
|
|
0 == match.compare(match.length() - name.length(), name.length(), name)) {
|
|
|
|
return memberDef;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto memberDef : bmhChildren) {
|
|
|
|
if (MarkType::kSubtopic != memberDef->fMarkType && MarkType::kTopic != memberDef->fMarkType) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Definition* result = this->findMemberCommentBlock(memberDef->fChildren, name);
|
|
|
|
if (result) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
2018-01-26 17:56:22 +00:00
|
|
|
}
|
|
|
|
|
2018-06-07 13:59:07 +00:00
|
|
|
Definition* IncludeWriter::findMethod(string name, RootDefinition* root) const {
|
|
|
|
if (root) {
|
|
|
|
return root->find(name, RootDefinition::AllowParens::kNo);
|
|
|
|
}
|
|
|
|
auto methodIter = fBmhParser->fMethodMap.find(name);
|
|
|
|
if (fBmhParser->fMethodMap.end() == methodIter) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return &methodIter->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IncludeWriter::firstBlock(int size, const char* data) {
|
|
|
|
SkAssertResult(this->firstBlockTrim(size, data));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IncludeWriter::firstBlockTrim(int size, const char* data) {
|
|
|
|
bool result = this->writeBlockTrim(size, data);
|
|
|
|
if (fFirstWrite) {
|
|
|
|
auto fileInfo = std::find_if(fRootTopic->fChildren.begin(), fRootTopic->fChildren.end(),
|
|
|
|
[](const Definition* def){ return MarkType::kFile == def->fMarkType; } );
|
|
|
|
if (fRootTopic->fChildren.end() != fileInfo) {
|
|
|
|
this->writeCommentHeader();
|
|
|
|
this->writeString("\\file");
|
|
|
|
this->writeSpace();
|
|
|
|
size_t lastSlash = fFileName.rfind('/');
|
|
|
|
if (string::npos == lastSlash) {
|
|
|
|
lastSlash = fFileName.rfind('\\');
|
|
|
|
}
|
|
|
|
string fileName = fFileName.substr(lastSlash + 1);
|
|
|
|
this->writeString(fileName);
|
|
|
|
this->lf(2);
|
|
|
|
fIndent += 4;
|
|
|
|
this->descriptionOut(*fileInfo, SkipFirstLine::kNo, Phrase::kNo);
|
|
|
|
fIndent -= 4;
|
|
|
|
this->writeCommentTrailer(OneLine::kNo);
|
|
|
|
}
|
|
|
|
fFirstWrite = false;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IncludeWriter::setStart(const char* start, const Definition* def) {
|
|
|
|
SkASSERT(start >= fStart);
|
|
|
|
this->setStartBack(start, def);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IncludeWriter::setStartBack(const char* start, const Definition* def) {
|
|
|
|
fStartSetter = def;
|
|
|
|
fStart = start;
|
|
|
|
}
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Definition* IncludeWriter::structMemberOut(const Definition* memberStart, const Definition& child) {
|
2018-06-07 13:59:07 +00:00
|
|
|
const char* blockStart = !fWroteMethod && fDeferComment ? fDeferComment->fContentEnd : fStart;
|
2017-09-14 15:25:39 +00:00
|
|
|
const char* blockEnd = fWroteMethod && fDeferComment ? fDeferComment->fStart - 1 :
|
|
|
|
memberStart->fStart;
|
2018-06-07 13:59:07 +00:00
|
|
|
this->firstBlockTrim((int) (blockEnd - blockStart), blockStart);
|
|
|
|
this->indentDeferred(IndentKind::kStructMember);
|
2017-09-14 15:25:39 +00:00
|
|
|
fWroteMethod = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
string name(child.fContentStart, (int) (child.fContentEnd - child.fContentStart));
|
2018-01-26 17:56:22 +00:00
|
|
|
Definition* commentBlock = this->findMemberCommentBlock(fBmhStructDef->fChildren, name);
|
2018-02-20 15:35:29 +00:00
|
|
|
if (!commentBlock) {
|
2018-05-30 13:21:49 +00:00
|
|
|
return memberStart->reportError<Definition*>("member missing comment block 2");
|
2018-02-20 15:35:29 +00:00
|
|
|
}
|
2018-05-30 13:21:49 +00:00
|
|
|
auto lineIter = std::find_if(commentBlock->fChildren.begin(), commentBlock->fChildren.end(),
|
|
|
|
[](const Definition* def){ return MarkType::kLine == def->fMarkType; } );
|
|
|
|
SkASSERT(commentBlock->fChildren.end() != lineIter);
|
|
|
|
const Definition* lineDef = *lineIter;
|
|
|
|
if (fStructMemberLength > 100) {
|
2017-07-28 15:04:54 +00:00
|
|
|
this->writeCommentHeader();
|
2018-05-30 13:21:49 +00:00
|
|
|
this->writeSpace();
|
|
|
|
this->rewriteBlock(lineDef->length(), lineDef->fContentStart, Phrase::kYes);
|
|
|
|
this->writeCommentTrailer(OneLine::kYes);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
this->lfcr();
|
2017-08-03 21:14:08 +00:00
|
|
|
this->writeBlock((int) (child.fStart - memberStart->fContentStart),
|
2017-07-28 15:04:54 +00:00
|
|
|
memberStart->fContentStart);
|
|
|
|
this->indentToColumn(fStructMemberTab);
|
|
|
|
this->writeString(name.c_str());
|
2017-09-21 16:31:06 +00:00
|
|
|
auto tokenIter = child.fParent->fTokens.begin();
|
2017-08-03 21:14:08 +00:00
|
|
|
std::advance(tokenIter, child.fParentIndex + 1);
|
|
|
|
Definition* valueStart = &*tokenIter;
|
|
|
|
while (Definition::Type::kPunctuation != tokenIter->fType) {
|
|
|
|
std::advance(tokenIter, 1);
|
|
|
|
SkASSERT(child.fParent->fTokens.end() != tokenIter);
|
|
|
|
}
|
|
|
|
Definition* valueEnd = &*tokenIter;
|
|
|
|
if (valueStart != valueEnd) {
|
|
|
|
this->indentToColumn(fStructValueTab);
|
|
|
|
this->writeString("=");
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeBlock((int) (valueEnd->fStart - valueStart->fContentStart),
|
2017-10-09 19:45:33 +00:00
|
|
|
valueStart->fContentStart);
|
2017-08-03 21:14:08 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
this->writeString(";");
|
2018-05-30 13:21:49 +00:00
|
|
|
if (fStructMemberLength <= 100) {
|
2017-07-28 15:04:54 +00:00
|
|
|
this->indentToColumn(fStructCommentTab);
|
|
|
|
this->writeString("//!<");
|
|
|
|
this->writeSpace();
|
2018-05-30 13:21:49 +00:00
|
|
|
this->rewriteBlock(lineDef->length(), lineDef->fContentStart, Phrase::kYes);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-05-30 13:21:49 +00:00
|
|
|
this->lf(1);
|
2017-08-03 21:14:08 +00:00
|
|
|
return valueEnd;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-30 13:21:49 +00:00
|
|
|
// const and constexpr and #define aren't contained in a braces like struct and enum.
|
|
|
|
// use a bmh subtopic to group like ones together, then measure them in the include as if
|
|
|
|
// they were formally linked together
|
|
|
|
void IncludeWriter::constSizeMembers(const RootDefinition* root) {
|
|
|
|
// fBmhConst->fParent is subtopic containing all grouped const expressions
|
|
|
|
// fConstDef is token of const include name, hopefully on same line as const start
|
|
|
|
string rootPrefix = root ? root->fName + "::" : "";
|
|
|
|
const Definition* test = fConstDef;
|
|
|
|
int tokenIndex = test->fParentIndex;
|
|
|
|
int longestName = 0;
|
|
|
|
int longestValue = 0;
|
|
|
|
int longestComment = 0;
|
|
|
|
const Definition* subtopic = fBmhConst->fParent;
|
|
|
|
SkASSERT(subtopic);
|
|
|
|
SkASSERT(MarkType::kSubtopic == subtopic->fMarkType);
|
|
|
|
// back up to first token on line
|
|
|
|
size_t lineCount = test->fLineCount;
|
|
|
|
const Definition* last;
|
|
|
|
auto tokenIter = test->fParent->fTokens.begin();
|
|
|
|
std::advance(tokenIter, tokenIndex);
|
|
|
|
do {
|
|
|
|
last = test;
|
|
|
|
std::advance(tokenIter, -1);
|
|
|
|
test = &*tokenIter;
|
|
|
|
SkASSERT(test->fParentIndex == --tokenIndex);
|
|
|
|
} while (lineCount == test->fLineCount);
|
|
|
|
test = last;
|
|
|
|
for (auto child : subtopic->fChildren) {
|
|
|
|
if (MarkType::kConst != child->fMarkType) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// expect found name to be on the left of assign
|
|
|
|
// expect assign
|
|
|
|
// expect semicolon
|
|
|
|
// no parens, no braces
|
|
|
|
while (rootPrefix + test->fName != child->fName) {
|
|
|
|
std::advance(tokenIter, 1);
|
|
|
|
test = &*tokenIter;
|
|
|
|
SkASSERT(lineCount >= test->fLineCount);
|
|
|
|
}
|
|
|
|
++lineCount;
|
|
|
|
TextParser constText(test);
|
|
|
|
const char* nameEnd = constText.trimmedBracketEnd('=');
|
|
|
|
SkAssertResult(constText.skipToEndBracket('='));
|
|
|
|
const char* valueEnd = constText.trimmedBracketEnd(';');
|
|
|
|
auto lineIter = std::find_if(child->fChildren.begin(), child->fChildren.end(),
|
|
|
|
[](const Definition* def){ return MarkType::kLine == def->fMarkType; });
|
|
|
|
SkASSERT(child->fChildren.end() != lineIter);
|
|
|
|
longestName = SkTMax(longestName, (int) (nameEnd - constText.fStart));
|
|
|
|
longestValue = SkTMax(longestValue, (int) (valueEnd - constText.fChar));
|
|
|
|
longestComment = SkTMax(longestComment, (*lineIter)->length());
|
|
|
|
}
|
|
|
|
// write fStructValueTab, fStructCommentTab
|
|
|
|
fConstValueTab = longestName + fIndent + 1;
|
|
|
|
fConstCommentTab = fConstValueTab + longestValue + 2;
|
|
|
|
fConstLength = fConstCommentTab + longestComment + (int) sizeof("//!<");
|
|
|
|
}
|
|
|
|
|
2018-06-08 15:54:32 +00:00
|
|
|
bool IncludeWriter::defineOut(const Definition& def) {
|
|
|
|
if (def.fTokens.size() < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto& child = def.fTokens.front();
|
|
|
|
string name(child.fContentStart, child.length());
|
|
|
|
auto defIter = fBmhParser->fDefineMap.find(name);
|
|
|
|
if (fBmhParser->fDefineMap.end() == defIter) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const Definition& bmhDef = defIter->second;
|
|
|
|
this->constOut(&def, &bmhDef);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-11 14:37:52 +00:00
|
|
|
void IncludeWriter::structSizeMembers(const Definition& child) {
|
2017-07-28 15:04:54 +00:00
|
|
|
int longestType = 0;
|
|
|
|
Definition* typeStart = nullptr;
|
|
|
|
int longestName = 0;
|
2017-08-03 21:14:08 +00:00
|
|
|
int longestValue = 0;
|
2018-05-30 13:21:49 +00:00
|
|
|
int longestComment = 0;
|
2017-07-28 15:04:54 +00:00
|
|
|
SkASSERT(child.fChildren.size() == 1 || child.fChildren.size() == 2);
|
|
|
|
bool inEnum = false;
|
2017-08-03 21:14:08 +00:00
|
|
|
bool inMethod = false;
|
|
|
|
bool inMember = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
auto brace = child.fChildren[0];
|
|
|
|
SkASSERT(Bracket::kBrace == brace->fBracket);
|
|
|
|
for (auto& token : brace->fTokens) {
|
|
|
|
if (Definition::Type::kBracket == token.fType) {
|
|
|
|
if (Bracket::kSlashSlash == token.fBracket) {
|
|
|
|
continue; // ignore old inline comments
|
|
|
|
}
|
|
|
|
if (Bracket::kSlashStar == token.fBracket) {
|
|
|
|
continue; // ignore old inline comments
|
|
|
|
}
|
|
|
|
if (Bracket::kParen == token.fBracket) {
|
2017-08-03 21:14:08 +00:00
|
|
|
if (inMethod) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
SkASSERT(0); // incomplete
|
|
|
|
}
|
|
|
|
if (Definition::Type::kKeyWord == token.fType) {
|
|
|
|
switch (token.fKeyWord) {
|
|
|
|
case KeyWord::kEnum:
|
|
|
|
inEnum = true;
|
|
|
|
break;
|
|
|
|
case KeyWord::kConst:
|
|
|
|
case KeyWord::kConstExpr:
|
|
|
|
case KeyWord::kStatic:
|
|
|
|
case KeyWord::kInt:
|
2017-09-14 15:25:39 +00:00
|
|
|
case KeyWord::kUint8_t:
|
|
|
|
case KeyWord::kUint16_t:
|
2017-07-28 15:04:54 +00:00
|
|
|
case KeyWord::kUint32_t:
|
2017-09-14 15:25:39 +00:00
|
|
|
case KeyWord::kUint64_t:
|
2018-05-21 15:56:57 +00:00
|
|
|
case KeyWord::kUintPtr_t:
|
2017-07-28 15:04:54 +00:00
|
|
|
case KeyWord::kSize_t:
|
|
|
|
case KeyWord::kFloat:
|
|
|
|
case KeyWord::kBool:
|
|
|
|
case KeyWord::kVoid:
|
|
|
|
if (!typeStart) {
|
|
|
|
typeStart = &token;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Definition::Type::kPunctuation == token.fType) {
|
|
|
|
if (inEnum) {
|
|
|
|
SkASSERT(Punctuation::kSemicolon == token.fPunctuation);
|
|
|
|
inEnum = false;
|
|
|
|
}
|
2017-08-03 21:14:08 +00:00
|
|
|
if (inMethod) {
|
|
|
|
if (Punctuation::kColon == token.fPunctuation) {
|
|
|
|
inMethod = false;
|
|
|
|
} else if (Punctuation::kLeftBrace == token.fPunctuation) {
|
|
|
|
inMethod = false;
|
2017-08-29 21:36:51 +00:00
|
|
|
} else if (Punctuation::kSemicolon == token.fPunctuation) {
|
|
|
|
inMethod = false;
|
2017-08-03 21:14:08 +00:00
|
|
|
} else {
|
|
|
|
SkASSERT(0); // incomplete
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (inMember) {
|
|
|
|
SkASSERT(Punctuation::kSemicolon == token.fPunctuation);
|
|
|
|
typeStart = nullptr;
|
|
|
|
inMember = false;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Definition::Type::kWord != token.fType) {
|
|
|
|
SkASSERT(0); // incomplete
|
|
|
|
}
|
|
|
|
if (MarkType::kMember == token.fMarkType) {
|
|
|
|
TextParser typeStr(token.fFileName, typeStart->fContentStart, token.fContentStart,
|
|
|
|
token.fLineCount);
|
|
|
|
typeStr.trimEnd();
|
2017-08-03 21:14:08 +00:00
|
|
|
longestType = SkTMax(longestType, (int) (typeStr.fEnd - typeStr.fStart));
|
2017-07-28 15:04:54 +00:00
|
|
|
longestName = SkTMax(longestName, (int) (token.fContentEnd - token.fContentStart));
|
|
|
|
typeStart->fMemberStart = true;
|
2017-08-03 21:14:08 +00:00
|
|
|
inMember = true;
|
2018-05-30 13:21:49 +00:00
|
|
|
string tokenName(token.fContentStart, (int) (token.fContentEnd - token.fContentStart));
|
|
|
|
Definition* commentBlock = this->findMemberCommentBlock(fBmhStructDef->fChildren,
|
|
|
|
tokenName);
|
|
|
|
if (!commentBlock) {
|
|
|
|
return token.reportError<void>("member missing comment block 1");
|
|
|
|
}
|
|
|
|
auto lineIter = std::find_if(commentBlock->fChildren.begin(),
|
|
|
|
commentBlock->fChildren.end(),
|
|
|
|
[](const Definition* def){ return MarkType::kLine == def->fMarkType; } );
|
|
|
|
SkASSERT(commentBlock->fChildren.end() != lineIter);
|
|
|
|
const Definition* lineDef = *lineIter;
|
|
|
|
longestComment = SkTMax(longestComment, lineDef->length());
|
2017-08-03 21:14:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (MarkType::kMethod == token.fMarkType) {
|
|
|
|
inMethod = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SkASSERT(MarkType::kNone == token.fMarkType);
|
2017-08-03 21:14:08 +00:00
|
|
|
if (typeStart) {
|
|
|
|
if (inMember) {
|
|
|
|
longestValue =
|
|
|
|
SkTMax(longestValue, (int) (token.fContentEnd - token.fContentStart));
|
|
|
|
}
|
|
|
|
} else {
|
2017-07-28 15:04:54 +00:00
|
|
|
typeStart = &token;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fStructMemberTab = longestType + fIndent + 1 /* space before name */ ;
|
2017-08-03 21:14:08 +00:00
|
|
|
fStructValueTab = fStructMemberTab + longestName + 2 /* space ; */ ;
|
|
|
|
fStructCommentTab = fStructValueTab;
|
|
|
|
if (longestValue) {
|
|
|
|
fStructCommentTab += longestValue + 3 /* space = space */ ;
|
|
|
|
fStructValueTab -= 1 /* ; */ ;
|
|
|
|
}
|
2018-05-30 13:21:49 +00:00
|
|
|
fStructMemberLength = fStructCommentTab + longestComment;
|
2018-05-16 11:07:07 +00:00
|
|
|
// iterate through struct to ensure that members' comments fit on line
|
|
|
|
// struct or class may not have any members
|
|
|
|
(void) this->checkChildCommentLength(fBmhStructDef, MarkType::kMember);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
2017-10-26 11:58:48 +00:00
|
|
|
static bool find_start(const Definition* startDef, const char* start) {
|
|
|
|
for (const auto& child : startDef->fTokens) {
|
|
|
|
if (child.fContentStart == start) {
|
|
|
|
return MarkType::kMethod == child.fMarkType;
|
|
|
|
}
|
|
|
|
if (child.fContentStart >= start) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (find_start(&child, start)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:36:51 +00:00
|
|
|
bool IncludeWriter::populate(Definition* def, ParentPair* prevPair, RootDefinition* root) {
|
2018-02-20 15:35:29 +00:00
|
|
|
if (!def->fTokens.size()) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-08-29 21:36:51 +00:00
|
|
|
ParentPair pair = { def, prevPair };
|
2017-07-28 15:04:54 +00:00
|
|
|
// write bulk of original include up to class, method, enum, etc., excepting preceding comment
|
|
|
|
// find associated bmh object
|
|
|
|
// write any associated comments in Doxygen form
|
|
|
|
// skip include comment
|
|
|
|
// if there is a series of same named methods, write one set of comments, then write all methods
|
|
|
|
string methodName;
|
2018-05-16 11:07:07 +00:00
|
|
|
Definition* method = nullptr;
|
|
|
|
Definition* clonedMethod = nullptr;
|
2017-07-28 15:04:54 +00:00
|
|
|
const Definition* memberStart = nullptr;
|
2017-08-03 21:14:08 +00:00
|
|
|
const Definition* memberEnd = nullptr;
|
2017-07-28 15:04:54 +00:00
|
|
|
fContinuation = nullptr;
|
|
|
|
bool inStruct = false;
|
2017-08-03 21:14:08 +00:00
|
|
|
bool inConstructor = false;
|
2017-10-11 14:37:52 +00:00
|
|
|
bool inInline = false;
|
2017-10-26 11:58:48 +00:00
|
|
|
bool eatOperator = false;
|
2018-02-20 15:35:29 +00:00
|
|
|
bool sawConst = false;
|
|
|
|
bool staticOnly = false;
|
2018-06-07 13:59:07 +00:00
|
|
|
bool sawTypedef = false;
|
2018-06-08 19:57:37 +00:00
|
|
|
Definition* deferredTypedefComment = nullptr;
|
2017-10-26 11:58:48 +00:00
|
|
|
const Definition* requireDense = nullptr;
|
|
|
|
const Definition* startDef = nullptr;
|
2017-07-28 15:04:54 +00:00
|
|
|
for (auto& child : def->fTokens) {
|
2018-06-07 13:59:07 +00:00
|
|
|
if (KeyWord::kInline == child.fKeyWord) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-10-26 11:58:48 +00:00
|
|
|
if (KeyWord::kOperator == child.fKeyWord && method &&
|
|
|
|
Definition::MethodType::kOperator == method->fMethodType) {
|
|
|
|
eatOperator = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (eatOperator) {
|
|
|
|
if (Bracket::kSquare == child.fBracket || Bracket::kParen == child.fBracket) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
eatOperator = false;
|
|
|
|
fContinuation = nullptr;
|
|
|
|
if (KeyWord::kConst == child.fKeyWord) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2017-08-03 21:14:08 +00:00
|
|
|
if (memberEnd) {
|
|
|
|
if (memberEnd != &child) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-10-26 11:58:48 +00:00
|
|
|
startDef = &child;
|
2018-06-07 13:59:07 +00:00
|
|
|
this->setStart(child.fContentStart + 1, &child);
|
2017-08-03 21:14:08 +00:00
|
|
|
memberEnd = nullptr;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (child.fPrivate) {
|
2017-10-11 14:37:52 +00:00
|
|
|
if (MarkType::kMethod == child.fMarkType) {
|
|
|
|
inInline = true;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-10-11 14:37:52 +00:00
|
|
|
if (inInline) {
|
|
|
|
if (Definition::Type::kKeyWord == child.fType) {
|
|
|
|
SkASSERT(MarkType::kMethod != child.fMarkType);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Definition::Type::kPunctuation == child.fType) {
|
|
|
|
if (Punctuation::kLeftBrace == child.fPunctuation) {
|
|
|
|
inInline = false;
|
|
|
|
} else {
|
|
|
|
SkASSERT(Punctuation::kAsterisk == child.fPunctuation);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Definition::Type::kWord == child.fType) {
|
|
|
|
string name(child.fContentStart, child.fContentEnd - child.fContentStart);
|
|
|
|
SkASSERT(string::npos != name.find("::"));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Definition::Type::kBracket == child.fType) {
|
|
|
|
SkASSERT(Bracket::kParen == child.fBracket);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (fContinuation) {
|
|
|
|
if (Definition::Type::kKeyWord == child.fType) {
|
2017-09-14 15:25:39 +00:00
|
|
|
if (KeyWord::kFriend == child.fKeyWord ||
|
2017-08-29 21:36:51 +00:00
|
|
|
KeyWord::kSK_API == child.fKeyWord) {
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-09-14 15:25:39 +00:00
|
|
|
const IncludeKey& includeKey = kKeyWords[(int) child.fKeyWord];
|
|
|
|
if (KeyProperty::kNumber == includeKey.fProperty) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2017-12-01 16:49:58 +00:00
|
|
|
if (Definition::Type::kBracket == child.fType) {
|
|
|
|
if (Bracket::kAngle == child.fBracket) {
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-12-01 16:49:58 +00:00
|
|
|
if (Bracket::kParen == child.fBracket) {
|
|
|
|
if (!clonedMethod) {
|
|
|
|
if (inConstructor) {
|
|
|
|
fContinuation = child.fContentStart;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int alternate = 1;
|
|
|
|
ptrdiff_t childLen = child.fContentEnd - child.fContentStart;
|
|
|
|
SkASSERT(')' == child.fContentStart[childLen]);
|
|
|
|
++childLen;
|
|
|
|
do {
|
|
|
|
TextParser params(clonedMethod->fFileName, clonedMethod->fStart,
|
|
|
|
clonedMethod->fContentStart, clonedMethod->fLineCount);
|
|
|
|
params.skipToEndBracket('(');
|
|
|
|
if (params.startsWith(child.fContentStart, childLen)) {
|
|
|
|
this->methodOut(clonedMethod, child);
|
2018-05-30 13:21:49 +00:00
|
|
|
sawConst = false;
|
2017-12-01 16:49:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++alternate;
|
|
|
|
string alternateMethod = methodName + '_' + to_string(alternate);
|
2018-06-27 15:00:21 +00:00
|
|
|
clonedMethod = this->findMethod(alternateMethod, root);
|
2017-12-01 16:49:58 +00:00
|
|
|
} while (clonedMethod);
|
|
|
|
if (!clonedMethod) {
|
2018-06-07 13:59:07 +00:00
|
|
|
return child.reportError<bool>("cloned method not found");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2017-12-01 16:49:58 +00:00
|
|
|
clonedMethod = nullptr;
|
|
|
|
continue;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Definition::Type::kWord == child.fType) {
|
|
|
|
if (clonedMethod) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
size_t len = (size_t) (child.fContentEnd - child.fContentStart);
|
|
|
|
const char operatorStr[] = "operator";
|
|
|
|
size_t operatorLen = sizeof(operatorStr) - 1;
|
|
|
|
if (len >= operatorLen && !strncmp(child.fContentStart, operatorStr, operatorLen)) {
|
|
|
|
fContinuation = child.fContentEnd;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Definition::Type::kPunctuation == child.fType &&
|
|
|
|
(Punctuation::kSemicolon == child.fPunctuation ||
|
2017-09-21 16:31:06 +00:00
|
|
|
Punctuation::kLeftBrace == child.fPunctuation ||
|
|
|
|
(Punctuation::kColon == child.fPunctuation && inConstructor))) {
|
2017-07-28 15:04:54 +00:00
|
|
|
SkASSERT(fContinuation[0] == '(');
|
|
|
|
const char* continueEnd = child.fContentStart;
|
|
|
|
while (continueEnd > fContinuation && isspace(continueEnd[-1])) {
|
|
|
|
--continueEnd;
|
|
|
|
}
|
|
|
|
methodName += string(fContinuation, continueEnd - fContinuation);
|
2018-06-28 12:50:35 +00:00
|
|
|
if (string::npos != methodName.find('\n')) {
|
|
|
|
methodName.erase(std::remove(methodName.begin(), methodName.end(), '\n'),
|
|
|
|
methodName.end());
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
method = this->findMethod(methodName, root);
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!method) {
|
2018-02-08 19:45:18 +00:00
|
|
|
if (fBmhStructDef && fBmhStructDef->fDeprecated) {
|
2018-02-20 15:35:29 +00:00
|
|
|
fContinuation = nullptr;
|
2018-02-08 19:45:18 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-03-20 19:53:27 +00:00
|
|
|
return child.reportError<bool>("method not found");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2017-07-31 15:48:27 +00:00
|
|
|
this->methodOut(method, child);
|
2018-05-30 13:21:49 +00:00
|
|
|
sawConst = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-09-14 15:25:39 +00:00
|
|
|
if (Definition::Type::kPunctuation == child.fType &&
|
|
|
|
Punctuation::kAsterisk == child.fPunctuation &&
|
|
|
|
clonedMethod) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-08-03 21:14:08 +00:00
|
|
|
if (inConstructor) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
method = this->findMethod(methodName + "()", root);
|
2017-07-28 15:04:54 +00:00
|
|
|
if (method) {
|
2017-09-21 16:31:06 +00:00
|
|
|
if (method->fCloned) {
|
|
|
|
clonedMethod = method;
|
|
|
|
continue;
|
|
|
|
}
|
2017-07-31 15:48:27 +00:00
|
|
|
this->methodOut(method, child);
|
2018-05-30 13:21:49 +00:00
|
|
|
sawConst = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
2018-02-08 19:45:18 +00:00
|
|
|
} else if (fBmhStructDef && fBmhStructDef->fDeprecated) {
|
2018-02-20 15:35:29 +00:00
|
|
|
fContinuation = nullptr;
|
|
|
|
continue;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-03-20 19:53:27 +00:00
|
|
|
return child.reportError<bool>("method not found");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
if (Bracket::kSlashSlash == child.fBracket || Bracket::kSlashStar == child.fBracket) {
|
|
|
|
if (!fDeferComment) {
|
|
|
|
fDeferComment = &child;
|
|
|
|
}
|
|
|
|
continue;
|
2017-10-09 19:45:33 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (MarkType::kMethod == child.fMarkType) {
|
2018-04-16 12:37:38 +00:00
|
|
|
if (this->isInternalName(child)) {
|
2017-08-03 21:14:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
const char* bodyEnd = fDeferComment ? fDeferComment->fContentStart - 1 :
|
2017-10-26 11:58:48 +00:00
|
|
|
fAttrDeprecated ? fAttrDeprecated->fContentStart - 1 :
|
2017-07-28 15:04:54 +00:00
|
|
|
child.fContentStart;
|
2018-01-04 21:11:51 +00:00
|
|
|
if (Definition::Type::kBracket == def->fType && Bracket::kDebugCode == def->fBracket) {
|
|
|
|
auto tokenIter = def->fParent->fTokens.begin();
|
|
|
|
std::advance(tokenIter, def->fParentIndex - 1);
|
|
|
|
Definition* prior = &*tokenIter;
|
|
|
|
if (Definition::Type::kBracket == def->fType &&
|
|
|
|
Bracket::kSlashStar == prior->fBracket) {
|
|
|
|
bodyEnd = prior->fContentStart - 1;
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
// FIXME: roll end-trimming into writeBlockTrim call
|
|
|
|
while (fStart < bodyEnd && ' ' >= bodyEnd[-1]) {
|
|
|
|
--bodyEnd;
|
|
|
|
}
|
|
|
|
int blockSize = (int) (bodyEnd - fStart);
|
2018-04-16 12:37:38 +00:00
|
|
|
SkASSERT(blockSize >= 0);
|
2017-07-28 15:04:54 +00:00
|
|
|
if (blockSize) {
|
2018-01-04 21:11:51 +00:00
|
|
|
string debugstr(fStart, blockSize);
|
2017-07-28 15:04:54 +00:00
|
|
|
this->writeBlock(blockSize, fStart);
|
|
|
|
}
|
2017-10-26 11:58:48 +00:00
|
|
|
startDef = &child;
|
2018-06-07 13:59:07 +00:00
|
|
|
this->setStart(child.fContentStart, &child);
|
2018-03-20 19:53:27 +00:00
|
|
|
auto mapFind = fBmhParser->fMethodMap.find(child.fName);
|
|
|
|
if (fBmhParser->fMethodMap.end() != mapFind) {
|
|
|
|
inConstructor = false;
|
|
|
|
method = &mapFind->second;
|
2018-06-07 13:59:07 +00:00
|
|
|
methodName = child.fName;
|
2018-03-20 19:53:27 +00:00
|
|
|
} else {
|
|
|
|
methodName = root->fName + "::" + child.fName;
|
2018-06-27 15:00:21 +00:00
|
|
|
size_t lastName = root->fName.rfind(':');
|
|
|
|
lastName = string::npos == lastName ? 0 : lastName + 1;
|
|
|
|
inConstructor = root->fName.substr(lastName) == child.fName;
|
2018-03-20 19:53:27 +00:00
|
|
|
method = root->find(methodName, RootDefinition::AllowParens::kNo);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
fContinuation = child.fContentEnd;
|
|
|
|
if (!method) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (method->fCloned) {
|
|
|
|
clonedMethod = method;
|
|
|
|
continue;
|
|
|
|
}
|
2017-07-31 15:48:27 +00:00
|
|
|
this->methodOut(method, child);
|
2018-05-30 13:21:49 +00:00
|
|
|
sawConst = false;
|
2017-08-29 21:36:51 +00:00
|
|
|
if (fAttrDeprecated) {
|
2017-10-26 11:58:48 +00:00
|
|
|
startDef = fAttrDeprecated;
|
2018-06-07 13:59:07 +00:00
|
|
|
this->setStartBack(fAttrDeprecated->fContentStart, fAttrDeprecated);
|
2017-08-29 21:36:51 +00:00
|
|
|
fAttrDeprecated = nullptr;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
2017-10-09 19:45:33 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (Definition::Type::kKeyWord == child.fType) {
|
|
|
|
switch (child.fKeyWord) {
|
|
|
|
case KeyWord::kStruct:
|
2017-08-29 21:36:51 +00:00
|
|
|
case KeyWord::kClass:
|
2018-06-07 13:59:07 +00:00
|
|
|
fICSStack.push_back(&child);
|
|
|
|
fStructEnded = false;
|
2018-02-20 15:35:29 +00:00
|
|
|
fStructMemberTab = 0;
|
2017-07-28 15:04:54 +00:00
|
|
|
// if struct contains members, compute their name and comment tabs
|
2017-08-29 21:36:51 +00:00
|
|
|
if (child.fChildren.size() > 0) {
|
|
|
|
const ParentPair* testPair = &pair;
|
|
|
|
while ((testPair = testPair->fPrev)) {
|
|
|
|
if (KeyWord::kClass == testPair->fParent->fKeyWord) {
|
|
|
|
inStruct = fInStruct = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (fInStruct) {
|
2017-10-26 11:58:48 +00:00
|
|
|
// try child; root+child; root->parent+child; etc.
|
|
|
|
int trial = 0;
|
2018-05-16 11:07:07 +00:00
|
|
|
RootDefinition* search = root;
|
|
|
|
Definition* parent = search->fParent;
|
2017-10-26 11:58:48 +00:00
|
|
|
do {
|
|
|
|
string name;
|
|
|
|
if (0 == trial) {
|
|
|
|
name = child.fName;
|
|
|
|
} else if (1 == trial) {
|
|
|
|
name = root->fName + "::" + child.fName;
|
2018-05-30 13:21:49 +00:00
|
|
|
} else if (2 == trial) {
|
|
|
|
name = root->fName;
|
2017-10-26 11:58:48 +00:00
|
|
|
} else {
|
|
|
|
SkASSERT(parent);
|
|
|
|
name = parent->fName + "::" + child.fName;
|
|
|
|
search = parent->asRoot();
|
|
|
|
parent = search->fParent;
|
|
|
|
}
|
|
|
|
fBmhStructDef = search->find(name, RootDefinition::AllowParens::kNo);
|
|
|
|
} while (!fBmhStructDef && ++trial);
|
2018-05-16 11:07:07 +00:00
|
|
|
root = fBmhStructDef->asRoot();
|
2017-10-26 11:58:48 +00:00
|
|
|
SkASSERT(root);
|
2017-07-28 15:04:54 +00:00
|
|
|
fIndent += 4;
|
|
|
|
this->structSizeMembers(child);
|
|
|
|
fIndent -= 4;
|
2017-10-26 11:58:48 +00:00
|
|
|
SkASSERT(!fIndentNext);
|
|
|
|
fIndentNext = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
if (child.fChildren.size() > 0) {
|
|
|
|
const char* bodyEnd = fDeferComment ? fDeferComment->fContentStart - 1 :
|
|
|
|
child.fContentStart;
|
2017-08-29 21:36:51 +00:00
|
|
|
this->writeBlockTrim((int) (bodyEnd - fStart), fStart);
|
2017-10-26 11:58:48 +00:00
|
|
|
if (fPendingMethod) {
|
2018-06-08 19:57:37 +00:00
|
|
|
if (fIndent >= 4) {
|
|
|
|
this->indentOut();
|
|
|
|
}
|
2017-10-26 11:58:48 +00:00
|
|
|
fPendingMethod = false;
|
|
|
|
}
|
|
|
|
startDef = requireDense ? requireDense : &child;
|
2018-06-07 13:59:07 +00:00
|
|
|
if (requireDense) {
|
|
|
|
startDef = requireDense;
|
|
|
|
this->setStart(requireDense->fContentStart, requireDense);
|
|
|
|
} else {
|
|
|
|
startDef = &child;
|
|
|
|
this->setStart(child.fContentStart, &child);
|
|
|
|
}
|
2017-10-26 11:58:48 +00:00
|
|
|
requireDense = nullptr;
|
2018-06-07 13:59:07 +00:00
|
|
|
if (!fInStruct && (!root || child.fName != root->fName)) {
|
2017-10-26 11:58:48 +00:00
|
|
|
root = &fBmhParser->fClassMap[child.fName];
|
|
|
|
fRootTopic = root->fParent;
|
|
|
|
SkASSERT(!root->fVisited);
|
|
|
|
root->clearVisited();
|
2018-06-07 13:59:07 +00:00
|
|
|
#if 0
|
|
|
|
// this seems better balanced; but real problem is probably fInStruct
|
|
|
|
if (fIndentStack.size() > 0) {
|
|
|
|
this->indentOut();
|
|
|
|
}
|
|
|
|
SkASSERT(!fIndent);
|
|
|
|
#else
|
2017-10-26 11:58:48 +00:00
|
|
|
fIndent = 0;
|
2018-06-07 13:59:07 +00:00
|
|
|
#endif
|
2017-10-26 11:58:48 +00:00
|
|
|
fBmhStructDef = root;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (child.fName == root->fName) {
|
|
|
|
if (Definition* parent = root->fParent) {
|
|
|
|
if (MarkType::kTopic == parent->fMarkType ||
|
|
|
|
MarkType::kSubtopic == parent->fMarkType) {
|
2017-09-15 06:56:12 +00:00
|
|
|
const char* commentStart = root->fContentStart;
|
|
|
|
const char* commentEnd = root->fChildren[0]->fStart;
|
2017-07-28 15:04:54 +00:00
|
|
|
this->structOut(root, *root, commentStart, commentEnd);
|
|
|
|
} else {
|
|
|
|
SkASSERT(0); // incomplete
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SkASSERT(0); // incomplete
|
|
|
|
}
|
|
|
|
} else {
|
2017-10-26 11:58:48 +00:00
|
|
|
SkASSERT(fInStruct);
|
2018-05-30 13:21:49 +00:00
|
|
|
Definition* priorBlock = fBmhStructDef;
|
2017-07-28 15:04:54 +00:00
|
|
|
Definition* codeBlock = nullptr;
|
2017-10-26 11:58:48 +00:00
|
|
|
Definition* nextBlock = nullptr;
|
|
|
|
for (auto test : fBmhStructDef->fChildren) {
|
2017-07-28 15:04:54 +00:00
|
|
|
if (MarkType::kCode == test->fMarkType) {
|
2018-05-30 13:21:49 +00:00
|
|
|
SkASSERT(!codeBlock); // FIXME: check enum earlier
|
2017-07-28 15:04:54 +00:00
|
|
|
codeBlock = test;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (codeBlock) {
|
2017-10-26 11:58:48 +00:00
|
|
|
nextBlock = test;
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-05-30 13:21:49 +00:00
|
|
|
priorBlock = test;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-05-30 13:21:49 +00:00
|
|
|
// FIXME: trigger error earlier if inner #Struct or #Class is missing #Code
|
2018-02-08 19:45:18 +00:00
|
|
|
if (!fBmhStructDef->fDeprecated) {
|
|
|
|
SkASSERT(codeBlock);
|
|
|
|
SkASSERT(nextBlock); // FIXME: check enum for correct order earlier
|
2018-02-09 21:49:09 +00:00
|
|
|
const char* commentStart = codeBlock->fTerminator;
|
|
|
|
const char* commentEnd = nextBlock->fStart;
|
2018-05-30 13:21:49 +00:00
|
|
|
// FIXME: trigger error if #Code is present but comment is before it earlier
|
|
|
|
SkASSERT(priorBlock); // code always preceded by #Line (I think)
|
|
|
|
TextParser priorComment(priorBlock->fFileName,
|
|
|
|
priorBlock->fTerminator, codeBlock->fStart,
|
|
|
|
priorBlock->fLineCount);
|
|
|
|
priorComment.trimEnd();
|
|
|
|
if (!priorComment.eof()) {
|
|
|
|
return priorBlock->reportError<bool>(
|
|
|
|
"expect no comment before #Code");
|
|
|
|
}
|
|
|
|
TextParser nextComment(codeBlock->fFileName, commentStart,
|
|
|
|
commentEnd, codeBlock->fLineCount);
|
|
|
|
nextComment.trimEnd();
|
|
|
|
if (!priorComment.eof()) {
|
|
|
|
return priorBlock->reportError<bool>(
|
|
|
|
"expect comment after #Code");
|
|
|
|
}
|
|
|
|
if (!nextComment.eof()) {
|
|
|
|
|
|
|
|
}
|
2018-02-09 21:49:09 +00:00
|
|
|
fIndentNext = true;
|
|
|
|
this->structOut(root, *fBmhStructDef, commentStart, commentEnd);
|
2017-10-26 11:58:48 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
fDeferComment = nullptr;
|
|
|
|
} else {
|
2018-06-07 13:59:07 +00:00
|
|
|
// empty forward reference
|
|
|
|
bool writeTwo = '\n' == child.fContentStart[-1]
|
|
|
|
&& '\n' == child.fContentStart[-2];
|
|
|
|
if (writeTwo) {
|
|
|
|
const char* bodyEnd = fDeferComment ? fDeferComment->fContentStart - 1 :
|
|
|
|
child.fContentStart;
|
|
|
|
this->writeBlockTrim((int) (bodyEnd - fStart), fStart);
|
|
|
|
this->lf(writeTwo ? 2 : 1);
|
|
|
|
fIndent = 0;
|
|
|
|
this->writeBlockTrim(child.length() + 1, child.fContentStart);
|
|
|
|
writeTwo = '\n' == child.fContentEnd[1]
|
|
|
|
&& '\n' == child.fContentStart[2];
|
|
|
|
this->lf(writeTwo ? 2 : 1);
|
|
|
|
fStart = child.fContentEnd + 1;
|
|
|
|
fDeferComment = nullptr;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KeyWord::kEnum: {
|
2017-08-03 21:14:08 +00:00
|
|
|
fInEnum = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
this->enumHeaderOut(root, child);
|
|
|
|
this->enumSizeItems(child);
|
|
|
|
} break;
|
|
|
|
case KeyWord::kConst:
|
|
|
|
case KeyWord::kConstExpr:
|
2018-02-20 15:35:29 +00:00
|
|
|
sawConst = !memberStart || staticOnly;
|
|
|
|
if (!memberStart) {
|
|
|
|
memberStart = &child;
|
|
|
|
staticOnly = true;
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
if (MarkType::kConst == child.fMarkType) {
|
|
|
|
auto constIter = fBmhParser->fConstMap.find(child.fName);
|
|
|
|
if (fBmhParser->fConstMap.end() != constIter) {
|
|
|
|
const RootDefinition& bmhConst = constIter->second;
|
|
|
|
this->constOut(&child, &bmhConst);
|
|
|
|
fDeferComment = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2018-02-20 15:35:29 +00:00
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case KeyWord::kStatic:
|
2018-02-20 15:35:29 +00:00
|
|
|
if (!memberStart) {
|
|
|
|
memberStart = &child;
|
|
|
|
staticOnly = true;
|
|
|
|
}
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case KeyWord::kInt:
|
2017-09-14 15:25:39 +00:00
|
|
|
case KeyWord::kUint8_t:
|
|
|
|
case KeyWord::kUint16_t:
|
2017-07-28 15:04:54 +00:00
|
|
|
case KeyWord::kUint32_t:
|
2017-09-14 15:25:39 +00:00
|
|
|
case KeyWord::kUint64_t:
|
2018-05-21 15:56:57 +00:00
|
|
|
case KeyWord::kUintPtr_t:
|
2017-08-29 21:36:51 +00:00
|
|
|
case KeyWord::kUnsigned:
|
2017-07-28 15:04:54 +00:00
|
|
|
case KeyWord::kSize_t:
|
|
|
|
case KeyWord::kFloat:
|
|
|
|
case KeyWord::kBool:
|
2018-02-08 19:45:18 +00:00
|
|
|
case KeyWord::kChar:
|
2017-07-28 15:04:54 +00:00
|
|
|
case KeyWord::kVoid:
|
2018-02-20 15:35:29 +00:00
|
|
|
staticOnly = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!memberStart) {
|
|
|
|
memberStart = &child;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KeyWord::kPublic:
|
|
|
|
case KeyWord::kPrivate:
|
|
|
|
case KeyWord::kProtected:
|
|
|
|
case KeyWord::kFriend:
|
2017-08-29 21:36:51 +00:00
|
|
|
case KeyWord::kInline:
|
|
|
|
case KeyWord::kSK_API:
|
2018-03-09 20:32:01 +00:00
|
|
|
case KeyWord::kTemplate:
|
2018-06-07 13:59:07 +00:00
|
|
|
break;
|
2017-08-03 21:14:08 +00:00
|
|
|
case KeyWord::kTypedef:
|
2018-06-07 13:59:07 +00:00
|
|
|
SkASSERT(!memberStart);
|
|
|
|
memberStart = &child;
|
2018-06-08 19:57:37 +00:00
|
|
|
deferredTypedefComment = fDeferComment;
|
2018-06-07 13:59:07 +00:00
|
|
|
sawTypedef = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
2017-10-26 11:58:48 +00:00
|
|
|
case KeyWord::kSK_BEGIN_REQUIRE_DENSE:
|
|
|
|
requireDense = &child;
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
|
|
|
}
|
2018-04-26 12:32:37 +00:00
|
|
|
if (KeyWord::kUint8_t == child.fKeyWord || KeyWord::kUint32_t == child.fKeyWord) {
|
2017-09-14 15:25:39 +00:00
|
|
|
continue;
|
2017-07-28 15:04:54 +00:00
|
|
|
} else {
|
2017-08-03 21:14:08 +00:00
|
|
|
if (fInEnum && KeyWord::kClass == child.fChildren[0]->fKeyWord) {
|
2017-08-29 21:36:51 +00:00
|
|
|
if (!this->populate(child.fChildren[0], &pair, root)) {
|
2017-08-03 21:14:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-10-26 11:58:48 +00:00
|
|
|
} else {
|
|
|
|
if (!this->populate(&child, &pair, root)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (KeyWord::kClass == child.fKeyWord || KeyWord::kStruct == child.fKeyWord) {
|
2018-06-07 13:59:07 +00:00
|
|
|
fICSStack.pop_back();
|
|
|
|
fStructEnded = true;
|
2017-10-26 11:58:48 +00:00
|
|
|
if (fInStruct) {
|
|
|
|
fInStruct = false;
|
|
|
|
do {
|
|
|
|
SkASSERT(root);
|
|
|
|
root = const_cast<RootDefinition*>(root->fParent->asRoot());
|
|
|
|
} while (MarkType::kTopic == root->fMarkType ||
|
|
|
|
MarkType::kSubtopic == root->fMarkType);
|
2018-06-07 13:59:07 +00:00
|
|
|
#if 0
|
|
|
|
}
|
|
|
|
if (MarkType::kStruct == root->fMarkType ||
|
|
|
|
MarkType::kClass == root->fMarkType) {
|
|
|
|
#else
|
2017-10-26 11:58:48 +00:00
|
|
|
SkASSERT(MarkType::kStruct == root->fMarkType ||
|
2018-06-07 13:59:07 +00:00
|
|
|
MarkType::kClass == root->fMarkType);
|
|
|
|
#endif
|
2017-10-26 11:58:48 +00:00
|
|
|
fPendingMethod = false;
|
|
|
|
if (startDef) {
|
|
|
|
fPendingMethod = find_start(startDef, fStart);
|
|
|
|
}
|
|
|
|
fOutdentNext = !fPendingMethod;
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
2017-10-09 19:45:33 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (Definition::Type::kBracket == child.fType) {
|
2017-10-09 19:45:33 +00:00
|
|
|
if (KeyWord::kEnum == child.fParent->fKeyWord ||
|
2017-08-03 21:14:08 +00:00
|
|
|
(KeyWord::kClass == child.fParent->fKeyWord && child.fParent->fParent &&
|
|
|
|
KeyWord::kEnum == child.fParent->fParent->fKeyWord)) {
|
2017-09-14 15:25:39 +00:00
|
|
|
SkASSERT(Bracket::kBrace == child.fBracket);
|
2018-05-16 11:07:07 +00:00
|
|
|
this->enumMembersOut(*child.fParent);
|
2017-07-28 15:04:54 +00:00
|
|
|
this->writeString("};");
|
|
|
|
this->lf(2);
|
2017-10-26 11:58:48 +00:00
|
|
|
startDef = child.fParent;
|
2018-06-07 13:59:07 +00:00
|
|
|
this->setStart(child.fParent->fContentEnd, child.fParent);
|
2017-07-28 15:04:54 +00:00
|
|
|
SkASSERT(';' == fStart[0]);
|
|
|
|
++fStart;
|
|
|
|
fDeferComment = nullptr;
|
|
|
|
fInEnum = false;
|
2017-10-26 11:58:48 +00:00
|
|
|
if (fIndentNext) {
|
|
|
|
// fIndent -= 4;
|
|
|
|
fIndentNext = false;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
2017-08-29 21:36:51 +00:00
|
|
|
}
|
|
|
|
if (fAttrDeprecated) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-06-08 15:54:32 +00:00
|
|
|
if (KeyWord::kDefine == child.fKeyWord && this->defineOut(child)) {
|
|
|
|
fDeferComment = nullptr;
|
|
|
|
continue;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
fDeferComment = nullptr;
|
2017-10-26 11:58:48 +00:00
|
|
|
if (KeyWord::kClass == def->fKeyWord || KeyWord::kStruct == def->fKeyWord) {
|
|
|
|
fIndentNext = true;
|
|
|
|
}
|
2017-08-29 21:36:51 +00:00
|
|
|
if (!this->populate(&child, &pair, root)) {
|
2017-07-28 15:04:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
if (KeyWord::kClass == def->fKeyWord || KeyWord::kStruct == def->fKeyWord) {
|
|
|
|
if (def->iRootParent() && (!fStartSetter
|
|
|
|
|| MarkType::kMethod != fStartSetter->fMarkType)) {
|
|
|
|
this->setStart(child.fContentEnd, &child);
|
|
|
|
fDeferComment = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Definition::Type::kWord == child.fType) {
|
|
|
|
if (MarkType::kMember == child.fMarkType) {
|
2017-10-11 14:37:52 +00:00
|
|
|
if (!memberStart) {
|
|
|
|
auto iter = def->fTokens.begin();
|
|
|
|
std::advance(iter, child.fParentIndex - 1);
|
|
|
|
memberStart = &*iter;
|
2018-02-20 15:35:29 +00:00
|
|
|
staticOnly = false;
|
2018-06-07 13:59:07 +00:00
|
|
|
}
|
|
|
|
if (!fStructMemberTab) {
|
|
|
|
SkASSERT(KeyWord::kStruct == def->fParent->fKeyWord);
|
|
|
|
fIndent += 4;
|
|
|
|
this->structSizeMembers(*def->fParent);
|
|
|
|
fIndent -= 4;
|
|
|
|
fIndentNext = true;
|
2017-10-11 14:37:52 +00:00
|
|
|
}
|
2018-02-20 15:35:29 +00:00
|
|
|
SkASSERT(fBmhStructDef);
|
|
|
|
if (!fBmhStructDef->fDeprecated) {
|
|
|
|
memberEnd = this->structMemberOut(memberStart, child);
|
|
|
|
startDef = &child;
|
2018-06-07 13:59:07 +00:00
|
|
|
this->setStart(child.fContentEnd + 1, &child);
|
2018-02-20 15:35:29 +00:00
|
|
|
fDeferComment = nullptr;
|
|
|
|
}
|
2018-02-08 19:45:18 +00:00
|
|
|
} else if (MarkType::kNone == child.fMarkType && sawConst
|
2018-02-20 15:35:29 +00:00
|
|
|
&& fEnumDef && !fEnumDef->fDeprecated) {
|
|
|
|
const Definition* bmhConst = nullptr;
|
|
|
|
string match;
|
|
|
|
if (root) {
|
|
|
|
match = root->fName + "::";
|
|
|
|
}
|
|
|
|
match += string(child.fContentStart, child.fContentEnd - child.fContentStart);
|
|
|
|
for (auto enumChild : fEnumDef->fChildren) {
|
|
|
|
if (MarkType::kConst == enumChild->fMarkType && enumChild->fName == match) {
|
|
|
|
bmhConst = enumChild;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bmhConst) {
|
2018-05-30 13:21:49 +00:00
|
|
|
this->constOut(memberStart, bmhConst);
|
2018-02-20 15:35:29 +00:00
|
|
|
fDeferComment = nullptr;
|
|
|
|
sawConst = false;
|
|
|
|
}
|
2018-05-30 13:21:49 +00:00
|
|
|
} else if (MarkType::kNone == child.fMarkType && sawConst && !fEnumDef) {
|
|
|
|
string match;
|
|
|
|
if (root) {
|
|
|
|
match = root->fName + "::";
|
|
|
|
match += string(child.fContentStart, child.fContentEnd - child.fContentStart);
|
|
|
|
auto bmhClassIter = fBmhParser->fClassMap.find(root->fName);
|
|
|
|
if (fBmhParser->fClassMap.end() != bmhClassIter) {
|
|
|
|
RootDefinition& bmhClass = bmhClassIter->second;
|
|
|
|
auto constIter = std::find_if(bmhClass.fLeaves.begin(), bmhClass.fLeaves.end(),
|
|
|
|
[match](std::pair<const string, Definition>& leaf){ return match == leaf.second.fName; } );
|
|
|
|
if (bmhClass.fLeaves.end() != constIter) {
|
|
|
|
const Definition& bmhConst = constIter->second;
|
|
|
|
if (MarkType::kConst == bmhConst.fMarkType
|
|
|
|
&& MarkType::kSubtopic == bmhConst.fParent->fMarkType) {
|
|
|
|
fBmhConst = &bmhConst;
|
|
|
|
fConstDef = &child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-20 15:35:29 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (child.fMemberStart) {
|
|
|
|
memberStart = &child;
|
2018-02-20 15:35:29 +00:00
|
|
|
staticOnly = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-03-19 13:04:10 +00:00
|
|
|
if (kAttrDeprecatedLen == (size_t) (child.fContentEnd - child.fContentStart) &&
|
|
|
|
!strncmp(gAttrDeprecated, child.fStart, kAttrDeprecatedLen)) {
|
2017-08-29 21:36:51 +00:00
|
|
|
fAttrDeprecated = &child;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Definition::Type::kPunctuation == child.fType) {
|
|
|
|
if (Punctuation::kSemicolon == child.fPunctuation) {
|
2018-05-30 13:21:49 +00:00
|
|
|
if (sawConst && fBmhConst) { // find bmh documentation. Parent must be subtopic.
|
|
|
|
const Definition* subtopic = fBmhConst->fParent;
|
|
|
|
SkASSERT(subtopic);
|
|
|
|
SkASSERT(MarkType::kSubtopic == subtopic->fMarkType);
|
|
|
|
auto firstConst = std::find_if(subtopic->fChildren.begin(),
|
|
|
|
subtopic->fChildren.end(),
|
|
|
|
[](const Definition* def){ return MarkType::kConst == def->fMarkType;});
|
|
|
|
SkASSERT(firstConst != subtopic->fChildren.end());
|
|
|
|
bool constIsFirst = *firstConst == fBmhConst;
|
|
|
|
if (constIsFirst) { // If first #Const child, output subtopic description.
|
|
|
|
this->constOut(memberStart, subtopic);
|
|
|
|
// find member / value / comment tabs
|
|
|
|
// look for a one-to-one correspondence between bmh and include
|
|
|
|
this->constSizeMembers(root);
|
2018-06-07 13:59:07 +00:00
|
|
|
fDeferComment = nullptr;
|
2018-05-30 13:21:49 +00:00
|
|
|
}
|
|
|
|
// after const code, output #Line description as short comment
|
|
|
|
auto lineIter = std::find_if(fBmhConst->fChildren.begin(),
|
|
|
|
fBmhConst->fChildren.end(),
|
|
|
|
[](const Definition* def){ return MarkType::kLine == def->fMarkType; });
|
|
|
|
SkASSERT(fBmhConst->fChildren.end() != lineIter);
|
|
|
|
const Definition* lineDef = *lineIter;
|
|
|
|
if (fConstLength > 100) {
|
|
|
|
this->writeCommentHeader();
|
|
|
|
this->writeSpace();
|
|
|
|
this->rewriteBlock(lineDef->length(), lineDef->fContentStart, Phrase::kYes);
|
|
|
|
this->writeCommentTrailer(OneLine::kYes);
|
|
|
|
}
|
|
|
|
this->lfcr();
|
|
|
|
TextParser constText(memberStart);
|
|
|
|
const char* nameEnd = constText.trimmedBracketEnd('=');
|
|
|
|
SkAssertResult(constText.skipToEndBracket('='));
|
|
|
|
const char* valueEnd = constText.trimmedBracketEnd(';');
|
|
|
|
this->writeBlock((int) (nameEnd - memberStart->fContentStart),
|
|
|
|
memberStart->fContentStart);
|
|
|
|
this->indentToColumn(fConstValueTab);
|
|
|
|
this->writeBlock((int) (valueEnd - constText.fChar), constText.fChar);
|
|
|
|
this->writeString(";");
|
|
|
|
if (fConstLength <= 100) {
|
|
|
|
this->indentToColumn(fConstCommentTab);
|
|
|
|
this->writeString("//!<");
|
|
|
|
this->writeSpace();
|
|
|
|
this->rewriteBlock(lineDef->length(), lineDef->fContentStart, Phrase::kYes);
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
this->setStart(child.fContentStart + 1, &child);
|
2018-05-30 13:21:49 +00:00
|
|
|
fDeferComment = nullptr;
|
|
|
|
fBmhConst = nullptr;
|
|
|
|
sawConst = false;
|
2018-06-07 13:59:07 +00:00
|
|
|
} else if (sawTypedef) {
|
|
|
|
const Definition* bmhTypedef = nullptr;
|
|
|
|
if (root) {
|
|
|
|
SkDEBUGCODE(auto classIter = fBmhParser->fClassMap.find(root->fName));
|
|
|
|
SkASSERT(fBmhParser->fClassMap.end() != classIter);
|
|
|
|
RootDefinition& classDef = fBmhParser->fClassMap[root->fName];
|
|
|
|
auto leafIter = classDef.fLeaves.find(memberStart->fName);
|
|
|
|
if (classDef.fLeaves.end() != leafIter) {
|
|
|
|
bmhTypedef = &leafIter->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!bmhTypedef) {
|
|
|
|
auto typedefIter = fBmhParser->fTypedefMap.find(memberStart->fName);
|
|
|
|
SkASSERT(fBmhParser->fTypedefMap.end() != typedefIter);
|
|
|
|
bmhTypedef = &typedefIter->second;
|
|
|
|
}
|
2018-06-08 19:57:37 +00:00
|
|
|
fDeferComment = deferredTypedefComment;
|
2018-06-07 13:59:07 +00:00
|
|
|
this->constOut(memberStart, bmhTypedef);
|
|
|
|
fDeferComment = nullptr;
|
|
|
|
sawTypedef = false;
|
2018-05-30 13:21:49 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
memberStart = nullptr;
|
2018-02-20 15:35:29 +00:00
|
|
|
staticOnly = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
if (inStruct) {
|
|
|
|
fInStruct = false;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Punctuation::kLeftBrace == child.fPunctuation ||
|
|
|
|
Punctuation::kColon == child.fPunctuation ||
|
|
|
|
Punctuation::kAsterisk == child.fPunctuation
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IncludeWriter::populate(BmhParser& bmhParser) {
|
|
|
|
bool allPassed = true;
|
|
|
|
for (auto& includeMapper : fIncludeMap) {
|
|
|
|
size_t lastSlash = includeMapper.first.rfind('/');
|
2017-09-14 15:25:39 +00:00
|
|
|
if (string::npos == lastSlash) {
|
|
|
|
lastSlash = includeMapper.first.rfind('\\');
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (string::npos == lastSlash || lastSlash >= includeMapper.first.length() - 1) {
|
|
|
|
return this->reportError<bool>("malformed include name");
|
|
|
|
}
|
|
|
|
string fileName = includeMapper.first.substr(lastSlash + 1);
|
|
|
|
if (".h" != fileName.substr(fileName.length() - 2)) {
|
|
|
|
return this->reportError<bool>("expected fileName.h");
|
|
|
|
}
|
|
|
|
string skClassName = fileName.substr(0, fileName.length() - 2);
|
2018-07-11 20:18:41 +00:00
|
|
|
this->reset();
|
2017-07-28 15:04:54 +00:00
|
|
|
fOut = fopen(fileName.c_str(), "wb");
|
|
|
|
if (!fOut) {
|
|
|
|
SkDebugf("could not open output file %s\n", fileName.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
RootDefinition* root =
|
|
|
|
bmhParser.fClassMap.end() == bmhParser.fClassMap.find(skClassName) ?
|
|
|
|
nullptr : &bmhParser.fClassMap[skClassName];
|
2017-07-28 15:04:54 +00:00
|
|
|
fBmhParser = &bmhParser;
|
2018-06-07 13:59:07 +00:00
|
|
|
if (root) {
|
|
|
|
fRootTopic = root->fParent;
|
|
|
|
root->clearVisited();
|
|
|
|
} else {
|
|
|
|
SkASSERT("Sk" == skClassName.substr(0, 2));
|
|
|
|
string topicName = skClassName.substr(2);
|
|
|
|
auto topicIter = bmhParser.fTopicMap.find(topicName);
|
|
|
|
SkASSERT(bmhParser.fTopicMap.end() != topicIter);
|
|
|
|
fRootTopic = topicIter->second->asRoot();
|
|
|
|
fFirstWrite = true; // write file information after includes
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
fFileName = includeMapper.second.fFileName;
|
2018-06-07 13:59:07 +00:00
|
|
|
this->setStartBack(includeMapper.second.fContentStart, &includeMapper.second);
|
2017-07-28 15:04:54 +00:00
|
|
|
fEnd = includeMapper.second.fContentEnd;
|
2017-12-11 21:03:17 +00:00
|
|
|
fAnonymousEnumCount = 1;
|
2018-06-08 15:54:32 +00:00
|
|
|
this->writeHeader(includeMapper);
|
2017-08-29 21:36:51 +00:00
|
|
|
allPassed &= this->populate(&includeMapper.second, nullptr, root);
|
2017-07-28 15:04:54 +00:00
|
|
|
this->writeBlock((int) (fEnd - fStart), fStart);
|
2018-06-07 13:59:07 +00:00
|
|
|
#if 0
|
|
|
|
if (fIndentStack.size() > 0) {
|
|
|
|
this->indentOut();
|
|
|
|
}
|
|
|
|
SkASSERT(!fIndent);
|
|
|
|
#else
|
2017-07-28 15:04:54 +00:00
|
|
|
fIndent = 0;
|
2018-06-07 13:59:07 +00:00
|
|
|
#endif
|
2017-07-28 15:04:54 +00:00
|
|
|
this->lfcr();
|
|
|
|
this->writePending();
|
|
|
|
fclose(fOut);
|
2018-01-04 21:11:51 +00:00
|
|
|
fflush(fOut);
|
|
|
|
size_t slash = fFileName.find_last_of('/');
|
|
|
|
if (string::npos == slash) {
|
|
|
|
slash = 0;
|
|
|
|
}
|
|
|
|
size_t back = fFileName.find_last_of('\\');
|
|
|
|
if (string::npos == back) {
|
|
|
|
back = 0;
|
|
|
|
}
|
|
|
|
string dir = fFileName.substr(0, SkTMax(slash, back) + 1);
|
|
|
|
string readname = dir + fileName;
|
|
|
|
if (this->writtenFileDiffers(fileName, readname)) {
|
|
|
|
SkDebugf("wrote updated %s\n", fileName.c_str());
|
|
|
|
} else {
|
|
|
|
remove(fileName.c_str());
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
return allPassed;
|
|
|
|
}
|
|
|
|
|
|
|
|
// change Xxx_Xxx to xxx xxx
|
|
|
|
static string ConvertRef(const string str, bool first) {
|
|
|
|
string substitute;
|
|
|
|
for (char c : str) {
|
|
|
|
if ('_' == c) {
|
|
|
|
c = ' '; // change Xxx_Xxx to xxx xxx
|
|
|
|
} else if (isupper(c) && !first) {
|
|
|
|
c = tolower(c);
|
|
|
|
}
|
|
|
|
substitute += c;
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
return substitute;
|
|
|
|
}
|
|
|
|
|
|
|
|
string IncludeWriter::resolveMethod(const char* start, const char* end, bool first) {
|
|
|
|
string methodname(start, end - start);
|
2017-07-31 15:48:27 +00:00
|
|
|
if (string::npos != methodname.find("()")) {
|
|
|
|
return "";
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
string substitute;
|
|
|
|
auto rootDefIter = fBmhParser->fMethodMap.find(methodname);
|
|
|
|
if (fBmhParser->fMethodMap.end() != rootDefIter) {
|
|
|
|
substitute = methodname + "()";
|
|
|
|
} else {
|
2017-07-31 11:52:43 +00:00
|
|
|
RootDefinition* parent = nullptr;
|
|
|
|
for (auto candidate : fRootTopic->fChildren) {
|
|
|
|
if (MarkType::kClass == candidate->fMarkType
|
|
|
|
|| MarkType::kStruct == candidate->fMarkType) {
|
|
|
|
parent = candidate->asRoot();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
if (parent) {
|
|
|
|
auto defRef = parent->find(parent->fName + "::" + methodname,
|
|
|
|
RootDefinition::AllowParens::kNo);
|
|
|
|
if (defRef && MarkType::kMethod == defRef->fMarkType) {
|
|
|
|
substitute = methodname + "()";
|
|
|
|
} else {
|
|
|
|
auto defineIter = fBmhParser->fDefineMap.find(methodname);
|
|
|
|
if (fBmhParser->fDefineMap.end() != defineIter) {
|
|
|
|
const RootDefinition& defineDef = defineIter->second;
|
|
|
|
auto codeIter = std::find_if(defineDef.fChildren.begin(),
|
|
|
|
defineDef.fChildren.end(),
|
|
|
|
[](Definition* child){ return MarkType::kCode == child->fMarkType; } );
|
|
|
|
if (defineDef.fChildren.end() != codeIter) {
|
|
|
|
const Definition* codeDef = *codeIter;
|
|
|
|
string codeContents(codeDef->fContentStart, codeDef->length());
|
|
|
|
size_t namePos = codeContents.find(methodname);
|
|
|
|
if (string::npos != namePos) {
|
|
|
|
size_t parenPos = namePos + methodname.length();
|
|
|
|
if (parenPos < codeContents.length() && '(' == codeContents[parenPos]) {
|
|
|
|
substitute = methodname + "()";
|
|
|
|
}
|
2018-05-30 13:21:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-31 15:48:27 +00:00
|
|
|
if (fMethodDef && methodname == fMethodDef->fName) {
|
|
|
|
TextParser report(fBmhMethod);
|
|
|
|
report.reportError("method should not include references to itself");
|
|
|
|
return "";
|
|
|
|
}
|
2017-09-21 16:31:06 +00:00
|
|
|
if (fBmhMethod) {
|
|
|
|
for (auto child : fBmhMethod->fChildren) {
|
|
|
|
if (MarkType::kParam != child->fMarkType) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (methodname == child->fName) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
return substitute;
|
|
|
|
}
|
|
|
|
|
2018-05-30 13:21:49 +00:00
|
|
|
string IncludeWriter::resolveAlias(const Definition* def) {
|
|
|
|
for (auto child : def->fChildren) {
|
|
|
|
if (MarkType::kSubstitute == child->fMarkType) {
|
|
|
|
return string(child->fContentStart, (int) (child->fContentEnd - child->fContentStart));
|
|
|
|
}
|
|
|
|
if (MarkType::kAlias == child->fMarkType && def->fName == child->fName) {
|
|
|
|
return this->resolveAlias(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
string IncludeWriter::resolveRef(const char* start, const char* end, bool first,
|
|
|
|
RefType* refType) {
|
2017-10-09 19:45:33 +00:00
|
|
|
// look up Xxx_Xxx
|
2017-07-28 15:04:54 +00:00
|
|
|
string undername(start, end - start);
|
2017-09-01 19:51:02 +00:00
|
|
|
for (const auto& external : fBmhParser->fExternals) {
|
|
|
|
if (external.fName == undername) {
|
|
|
|
*refType = RefType::kExternal;
|
|
|
|
return external.fName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*refType = RefType::kNormal;
|
2017-07-28 15:04:54 +00:00
|
|
|
SkASSERT(string::npos == undername.find(' '));
|
|
|
|
const Definition* rootDef = nullptr;
|
2018-02-09 21:49:09 +00:00
|
|
|
string substitute;
|
2017-07-28 15:04:54 +00:00
|
|
|
{
|
|
|
|
auto rootDefIter = fBmhParser->fTopicMap.find(undername);
|
|
|
|
if (fBmhParser->fTopicMap.end() != rootDefIter) {
|
|
|
|
rootDef = rootDefIter->second;
|
|
|
|
} else {
|
|
|
|
string prefixedName = fRootTopic->fName + '_' + undername;
|
|
|
|
rootDefIter = fBmhParser->fTopicMap.find(prefixedName);
|
|
|
|
if (fBmhParser->fTopicMap.end() != rootDefIter) {
|
|
|
|
rootDef = rootDefIter->second;
|
2017-10-26 11:58:48 +00:00
|
|
|
} else if (fBmhStructDef) {
|
|
|
|
string localPrefix = fBmhStructDef->fFiddle + '_' + undername;
|
2017-08-03 21:14:08 +00:00
|
|
|
rootDefIter = fBmhParser->fTopicMap.find(localPrefix);
|
|
|
|
if (fBmhParser->fTopicMap.end() != rootDefIter) {
|
|
|
|
rootDef = rootDefIter->second;
|
|
|
|
}
|
2018-02-09 21:49:09 +00:00
|
|
|
if (!rootDef) {
|
|
|
|
size_t doubleColon = fBmhStructDef->fName.rfind("::");
|
|
|
|
if (string::npos != doubleColon && undername
|
|
|
|
== fBmhStructDef->fName.substr(doubleColon + 2)) {
|
|
|
|
substitute = fBmhStructDef->fName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-30 13:21:49 +00:00
|
|
|
if (!rootDef && fEnumDef && "Sk" + prefixedName == fEnumDef->fFiddle) {
|
|
|
|
rootDef = fEnumDef;
|
|
|
|
}
|
2018-02-09 21:49:09 +00:00
|
|
|
if (!rootDef && !substitute.length()) {
|
2017-07-28 15:04:54 +00:00
|
|
|
auto aliasIter = fBmhParser->fAliasMap.find(undername);
|
|
|
|
if (fBmhParser->fAliasMap.end() != aliasIter) {
|
2018-02-09 21:49:09 +00:00
|
|
|
rootDef = aliasIter->second;
|
2018-04-03 12:43:27 +00:00
|
|
|
} else if (fInEnum && fEnumDef && this->findEnumSubtopic(undername, &rootDef)) {
|
|
|
|
;
|
2017-07-28 15:04:54 +00:00
|
|
|
} else if (!first) {
|
2018-04-03 12:43:27 +00:00
|
|
|
this->fChar = start;
|
2018-05-17 16:17:28 +00:00
|
|
|
this->fLine = start;
|
2017-07-31 15:48:27 +00:00
|
|
|
this->reportError("reference unfound");
|
|
|
|
return "";
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rootDef) {
|
2018-02-09 21:49:09 +00:00
|
|
|
MarkType rootType = rootDef->fMarkType;
|
2018-05-30 13:21:49 +00:00
|
|
|
if (MarkType::kSubtopic == rootType || MarkType::kTopic == rootType
|
|
|
|
|| MarkType::kAlias == rootType) {
|
|
|
|
substitute = this->resolveAlias(rootDef);
|
2018-02-09 21:49:09 +00:00
|
|
|
}
|
|
|
|
if (!substitute.length()) {
|
|
|
|
string match = rootDef->fName;
|
|
|
|
size_t index;
|
|
|
|
while (string::npos != (index = match.find('_'))) {
|
|
|
|
match.erase(index, 1);
|
|
|
|
}
|
|
|
|
string skmatch = "Sk" + match;
|
2018-05-30 13:21:49 +00:00
|
|
|
auto parent = MarkType::kAlias == rootType ? rootDef->fParent : rootDef;
|
2018-02-09 21:49:09 +00:00
|
|
|
for (auto child : parent->fChildren) {
|
|
|
|
// there may be more than one
|
|
|
|
// prefer the one mostly closely matching in text
|
|
|
|
if ((MarkType::kClass == child->fMarkType ||
|
|
|
|
MarkType::kStruct == child->fMarkType ||
|
|
|
|
(MarkType::kEnum == child->fMarkType && !child->fAnonymous) ||
|
|
|
|
MarkType::kEnumClass == child->fMarkType) && (match == child->fName ||
|
|
|
|
skmatch == child->fName)) {
|
|
|
|
substitute = child->fName;
|
|
|
|
break;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2017-09-14 15:25:39 +00:00
|
|
|
}
|
|
|
|
if (!substitute.length()) {
|
|
|
|
for (auto child : rootDef->fChildren) {
|
2018-02-09 21:49:09 +00:00
|
|
|
// there may be more than one
|
|
|
|
// if so, it's a bug since it's unknown which is the right one
|
2017-09-14 15:25:39 +00:00
|
|
|
if (MarkType::kClass == child->fMarkType ||
|
|
|
|
MarkType::kStruct == child->fMarkType ||
|
|
|
|
(MarkType::kEnum == child->fMarkType && !child->fAnonymous) ||
|
|
|
|
MarkType::kEnumClass == child->fMarkType) {
|
2018-02-09 21:49:09 +00:00
|
|
|
SkASSERT("" == substitute);
|
2017-09-14 15:25:39 +00:00
|
|
|
substitute = child->fName;
|
2018-02-09 21:49:09 +00:00
|
|
|
if (MarkType::kEnum == child->fMarkType) {
|
2017-09-14 15:25:39 +00:00
|
|
|
size_t parentClassEnd = substitute.find("::");
|
|
|
|
SkASSERT(string::npos != parentClassEnd);
|
2018-02-09 21:49:09 +00:00
|
|
|
string subEnd = substitute.substr(parentClassEnd + 2);
|
|
|
|
if (fInEnum) {
|
|
|
|
substitute = subEnd;
|
|
|
|
}
|
|
|
|
if (subEnd == undername) {
|
|
|
|
break;
|
|
|
|
}
|
2017-09-14 15:25:39 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!substitute.length()) {
|
2018-02-09 21:49:09 +00:00
|
|
|
const Definition* parent = rootDef;
|
|
|
|
do {
|
|
|
|
parent = parent->fParent;
|
|
|
|
} while (parent && (MarkType::kSubtopic == parent->fMarkType
|
|
|
|
|| MarkType::kTopic == parent->fMarkType));
|
2017-07-28 15:04:54 +00:00
|
|
|
if (parent) {
|
|
|
|
if (MarkType::kClass == parent->fMarkType ||
|
|
|
|
MarkType::kStruct == parent->fMarkType ||
|
2017-09-14 15:25:39 +00:00
|
|
|
(MarkType::kEnum == parent->fMarkType && !parent->fAnonymous) ||
|
2017-07-28 15:04:54 +00:00
|
|
|
MarkType::kEnumClass == parent->fMarkType) {
|
|
|
|
if (parent->fParent != fRootTopic) {
|
|
|
|
substitute = parent->fName;
|
2018-02-15 22:31:24 +00:00
|
|
|
substitute += ' ';
|
2018-02-20 15:35:29 +00:00
|
|
|
substitute += ConvertRef(rootDef->fName, false);
|
2017-07-28 15:04:54 +00:00
|
|
|
} else {
|
2018-05-30 13:21:49 +00:00
|
|
|
size_t underpos = undername.find('_');
|
|
|
|
if (string::npos != underpos) {
|
|
|
|
string parentName = undername.substr(0, underpos);
|
|
|
|
string skName = "Sk" + parentName;
|
|
|
|
if (skName == parent->fName) {
|
|
|
|
SkASSERT(start >= fLastDescription->fContentStart);
|
|
|
|
string lastDescription = string(fLastDescription->fContentStart,
|
|
|
|
(int) (start - fLastDescription->fContentStart));
|
|
|
|
size_t lineStart = lastDescription.rfind('\n');
|
|
|
|
SkASSERT(string::npos != lineStart);
|
|
|
|
fLine = fLastDescription->fContentStart + lineStart + 1;
|
|
|
|
fChar = start;
|
|
|
|
fEnd = end;
|
|
|
|
return this->reportError<string>("remove underline");
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
substitute += ConvertRef(undername, first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-31 11:52:43 +00:00
|
|
|
// Ensure first word after period is capitalized if substitute is lower cased.
|
|
|
|
if (first && isupper(start[0]) && substitute.length() > 0 && islower(substitute[0])) {
|
|
|
|
substitute[0] = start[0];
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
return substitute;
|
|
|
|
}
|
2017-07-31 15:48:27 +00:00
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
int IncludeWriter::lookupMethod(const PunctuationState punctuation, const Word word,
|
2017-09-21 16:31:06 +00:00
|
|
|
const int lastSpace, const int run, int lastWrite, const char* data,
|
|
|
|
bool hasIndirection) {
|
2017-07-31 15:48:27 +00:00
|
|
|
int wordStart = lastSpace;
|
|
|
|
while (' ' >= data[wordStart]) {
|
|
|
|
++wordStart;
|
|
|
|
}
|
|
|
|
const int wordEnd = PunctuationState::kDelimiter == punctuation ||
|
2018-02-20 15:35:29 +00:00
|
|
|
PunctuationState::kParen == punctuation ||
|
2017-07-28 15:04:54 +00:00
|
|
|
PunctuationState::kPeriod == punctuation ? run - 1 : run;
|
2017-09-21 16:31:06 +00:00
|
|
|
string temp;
|
|
|
|
if (hasIndirection && '(' != data[wordEnd - 1] && ')' != data[wordEnd - 1]) {
|
|
|
|
// FIXME: hard-coded to assume a.b or a->b is a.b() or a->b().
|
|
|
|
// need to check class a for member b to see if this is so
|
|
|
|
TextParser parser(fFileName, &data[wordStart], &data[wordEnd], fLineCount);
|
|
|
|
const char* indirection = parser.anyOf(".>");
|
|
|
|
if (&data[wordEnd] <= &indirection[2] || 'f' != indirection[1] ||
|
|
|
|
!isupper(indirection[2])) {
|
|
|
|
temp = string(&data[wordStart], wordEnd - wordStart) + "()";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
temp = this->resolveMethod(&data[wordStart], &data[wordEnd], Word::kFirst == word);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (temp.length()) {
|
2017-07-31 15:48:27 +00:00
|
|
|
if (wordStart > lastWrite) {
|
|
|
|
SkASSERT(data[wordStart - 1] >= ' ');
|
2017-07-28 15:04:54 +00:00
|
|
|
if (' ' == data[lastWrite]) {
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
this->firstBlockTrim(wordStart - lastWrite, &data[lastWrite]);
|
2017-07-31 15:48:27 +00:00
|
|
|
if (' ' == data[wordStart - 1]) {
|
2017-07-28 15:04:54 +00:00
|
|
|
this->writeSpace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkASSERT(temp[temp.length() - 1] > ' ');
|
|
|
|
this->writeString(temp.c_str());
|
2017-07-31 15:48:27 +00:00
|
|
|
lastWrite = wordEnd;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
return lastWrite;
|
|
|
|
}
|
|
|
|
|
|
|
|
int IncludeWriter::lookupReference(const PunctuationState punctuation, const Word word,
|
|
|
|
const int start, const int run, int lastWrite, const char last, const char* data) {
|
|
|
|
const int end = PunctuationState::kDelimiter == punctuation ||
|
2018-02-20 15:35:29 +00:00
|
|
|
PunctuationState::kParen == punctuation ||
|
2017-07-28 15:04:54 +00:00
|
|
|
PunctuationState::kPeriod == punctuation ? run - 1 : run;
|
2017-09-01 19:51:02 +00:00
|
|
|
RefType refType = RefType::kUndefined;
|
|
|
|
string resolved = string(&data[start], (size_t) (end - start));
|
|
|
|
string temp = this->resolveRef(&data[start], &data[end], Word::kFirst == word, &refType);
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!temp.length()) {
|
|
|
|
if (Word::kFirst != word && '_' != last) {
|
2017-09-01 19:51:02 +00:00
|
|
|
temp = ConvertRef(resolved, false);
|
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 (temp.length()) {
|
|
|
|
if (start > lastWrite) {
|
|
|
|
SkASSERT(data[start - 1] >= ' ');
|
|
|
|
if (' ' == data[lastWrite]) {
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
this->firstBlockTrim(start - lastWrite, &data[lastWrite]);
|
2017-07-28 15:04:54 +00:00
|
|
|
if (' ' == data[start - 1]) {
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkASSERT(temp[temp.length() - 1] > ' ');
|
|
|
|
this->writeString(temp.c_str());
|
|
|
|
lastWrite = end;
|
|
|
|
}
|
|
|
|
return lastWrite;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns true if rewriteBlock wrote linefeeds */
|
2017-09-14 15:25:39 +00:00
|
|
|
IncludeWriter::Wrote IncludeWriter::rewriteBlock(int size, const char* data, Phrase phrase) {
|
2017-07-28 15:04:54 +00:00
|
|
|
bool wroteLineFeeds = false;
|
|
|
|
while (size > 0 && data[0] <= ' ') {
|
|
|
|
--size;
|
|
|
|
++data;
|
|
|
|
}
|
|
|
|
while (size > 0 && data[size - 1] <= ' ') {
|
|
|
|
--size;
|
|
|
|
}
|
|
|
|
if (0 == size) {
|
|
|
|
return Wrote::kNone;
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fReturnOnWrite) {
|
|
|
|
return Wrote::kChars;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
int run = 0;
|
|
|
|
Word word = Word::kStart;
|
2017-09-14 15:25:39 +00:00
|
|
|
PunctuationState punctuation = Phrase::kNo == phrase ?
|
|
|
|
PunctuationState::kStart : PunctuationState::kSpace;
|
2017-07-28 15:04:54 +00:00
|
|
|
int start = 0;
|
|
|
|
int lastWrite = 0;
|
|
|
|
int lineFeeds = 0;
|
|
|
|
int lastPrintable = 0;
|
2017-07-31 15:48:27 +00:00
|
|
|
int lastSpace = -1;
|
2017-07-28 15:04:54 +00:00
|
|
|
char c = 0;
|
2018-01-05 15:11:11 +00:00
|
|
|
char last = 0;
|
2017-09-21 16:31:06 +00:00
|
|
|
bool embeddedIndirection = false;
|
2017-07-31 15:48:27 +00:00
|
|
|
bool embeddedSymbol = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
bool hasLower = false;
|
|
|
|
bool hasUpper = false;
|
2017-09-21 16:31:06 +00:00
|
|
|
bool hasIndirection = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
bool hasSymbol = false;
|
|
|
|
while (run < size) {
|
|
|
|
last = c;
|
|
|
|
c = data[run];
|
|
|
|
SkASSERT(' ' <= c || '\n' == c);
|
|
|
|
if (lineFeeds && ' ' < c) {
|
|
|
|
if (lastPrintable >= lastWrite) {
|
|
|
|
if (' ' == data[lastWrite]) {
|
|
|
|
this->writeSpace();
|
2017-11-27 15:44:06 +00:00
|
|
|
lastWrite++;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
this->writeBlock(lastPrintable - lastWrite + 1, &data[lastWrite]);
|
|
|
|
}
|
|
|
|
if (lineFeeds > 1) {
|
|
|
|
this->lf(2);
|
|
|
|
}
|
|
|
|
this->lfcr(); // defer the indent until non-whitespace is seen
|
|
|
|
lastWrite = run;
|
|
|
|
lineFeeds = 0;
|
|
|
|
}
|
|
|
|
if (' ' < c) {
|
|
|
|
lastPrintable = run;
|
|
|
|
}
|
|
|
|
switch (c) {
|
|
|
|
case '\n':
|
|
|
|
++lineFeeds;
|
|
|
|
wroteLineFeeds = true;
|
|
|
|
case ' ':
|
|
|
|
switch (word) {
|
|
|
|
case Word::kStart:
|
|
|
|
break;
|
|
|
|
case Word::kUnderline:
|
|
|
|
case Word::kCap:
|
|
|
|
case Word::kFirst:
|
|
|
|
if (!hasLower) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lastWrite = this->lookupReference(punctuation, word, start, run,
|
|
|
|
lastWrite, last, data);
|
|
|
|
break;
|
|
|
|
case Word::kMixed:
|
2017-07-31 15:48:27 +00:00
|
|
|
if (hasUpper && hasLower && !hasSymbol && lastSpace > 0) {
|
|
|
|
lastWrite = this->lookupMethod(punctuation, word, lastSpace, run,
|
2018-02-20 15:35:29 +00:00
|
|
|
lastWrite, data, hasIndirection);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
|
|
|
}
|
2017-07-31 11:52:43 +00:00
|
|
|
punctuation = PunctuationState::kPeriod == punctuation ||
|
2017-10-09 19:45:33 +00:00
|
|
|
(PunctuationState::kStart == punctuation && ' ' >= last) ?
|
2017-07-31 11:52:43 +00:00
|
|
|
PunctuationState::kStart : PunctuationState::kSpace;
|
2017-07-28 15:04:54 +00:00
|
|
|
word = Word::kStart;
|
2017-09-21 16:31:06 +00:00
|
|
|
embeddedIndirection = false;
|
2017-07-31 15:48:27 +00:00
|
|
|
embeddedSymbol = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
hasLower = false;
|
|
|
|
hasUpper = false;
|
2017-09-21 16:31:06 +00:00
|
|
|
hasIndirection = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
hasSymbol = false;
|
2017-07-31 15:48:27 +00:00
|
|
|
lastSpace = run;
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
2018-02-20 15:35:29 +00:00
|
|
|
case '.': case ',': case ';': case ':': case ')':
|
2017-07-28 15:04:54 +00:00
|
|
|
switch (word) {
|
|
|
|
case Word::kStart:
|
|
|
|
punctuation = PunctuationState::kDelimiter;
|
|
|
|
case Word::kCap:
|
|
|
|
case Word::kFirst:
|
|
|
|
case Word::kUnderline:
|
|
|
|
case Word::kMixed:
|
|
|
|
if (PunctuationState::kDelimiter == punctuation ||
|
|
|
|
PunctuationState::kPeriod == punctuation) {
|
|
|
|
word = Word::kMixed;
|
|
|
|
}
|
2018-02-20 15:35:29 +00:00
|
|
|
punctuation = '.' == c ? PunctuationState::kPeriod :
|
|
|
|
PunctuationState::kDelimiter;
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
|
|
|
}
|
2018-02-20 15:35:29 +00:00
|
|
|
('.' == c ? embeddedIndirection : embeddedSymbol) = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
2017-09-21 16:31:06 +00:00
|
|
|
case '>':
|
|
|
|
if ('-' == last) {
|
|
|
|
embeddedIndirection = true;
|
|
|
|
break;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
case '\'': // possessive apostrophe isn't treated as delimiting punctation
|
2017-09-01 19:51:02 +00:00
|
|
|
case '\"': // quote is passed straight through
|
2017-07-28 15:04:54 +00:00
|
|
|
case '=':
|
|
|
|
case '!': // assumed not to be punctuation, but a programming symbol
|
2017-09-21 16:31:06 +00:00
|
|
|
case '&': case '<': case '{': case '}': case '/': case '*': case '[': case ']':
|
2017-07-28 15:04:54 +00:00
|
|
|
word = Word::kMixed;
|
2017-07-31 15:48:27 +00:00
|
|
|
embeddedSymbol = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
case '(':
|
|
|
|
if (' ' == last) {
|
2018-02-20 15:35:29 +00:00
|
|
|
punctuation = PunctuationState::kParen;
|
2017-07-28 15:04:54 +00:00
|
|
|
} else {
|
|
|
|
word = Word::kMixed;
|
|
|
|
}
|
2017-07-31 15:48:27 +00:00
|
|
|
embeddedSymbol = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
case '_':
|
|
|
|
switch (word) {
|
|
|
|
case Word::kStart:
|
|
|
|
word = Word::kMixed;
|
|
|
|
break;
|
|
|
|
case Word::kCap:
|
|
|
|
case Word::kFirst:
|
|
|
|
case Word::kUnderline:
|
|
|
|
word = Word::kUnderline;
|
|
|
|
break;
|
|
|
|
case Word::kMixed:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
|
|
|
}
|
2017-07-31 15:48:27 +00:00
|
|
|
hasSymbol |= embeddedSymbol;
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
2017-08-29 21:36:51 +00:00
|
|
|
case '+':
|
|
|
|
// hackery to allow C++
|
|
|
|
SkASSERT('C' == last || '+' == last); // FIXME: don't allow + outside of #Formula
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case 'A': case 'B': case 'C': case 'D': case 'E':
|
|
|
|
case 'F': case 'G': case 'H': case 'I': case 'J':
|
|
|
|
case 'K': case 'L': case 'M': case 'N': case 'O':
|
|
|
|
case 'P': case 'Q': case 'R': case 'S': case 'T':
|
|
|
|
case 'U': case 'V': case 'W': case 'X': case 'Y':
|
|
|
|
case 'Z':
|
|
|
|
switch (word) {
|
|
|
|
case Word::kStart:
|
|
|
|
word = PunctuationState::kStart == punctuation ? Word::kFirst : Word::kCap;
|
|
|
|
start = run;
|
|
|
|
break;
|
|
|
|
case Word::kCap:
|
|
|
|
case Word::kFirst:
|
2017-10-26 11:58:48 +00:00
|
|
|
if (!isupper(last) && '~' != last) {
|
2017-07-28 15:04:54 +00:00
|
|
|
word = Word::kMixed;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Word::kUnderline:
|
|
|
|
// some word in Xxx_XXX_Xxx can be all upper, but all can't: XXX_XXX
|
|
|
|
if ('_' != last && !isupper(last)) {
|
|
|
|
word = Word::kMixed;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Word::kMixed:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
|
|
|
}
|
|
|
|
hasUpper = true;
|
|
|
|
if (PunctuationState::kPeriod == punctuation ||
|
|
|
|
PunctuationState::kDelimiter == punctuation) {
|
|
|
|
word = Word::kMixed;
|
|
|
|
}
|
2017-09-21 16:31:06 +00:00
|
|
|
hasIndirection |= embeddedIndirection;
|
2017-07-31 15:48:27 +00:00
|
|
|
hasSymbol |= embeddedSymbol;
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
case 'a': case 'b': case 'c': case 'd': case 'e':
|
|
|
|
case 'f': case 'g': case 'h': case 'i': case 'j':
|
|
|
|
case 'k': case 'l': case 'm': case 'n': case 'o':
|
|
|
|
case 'p': case 'q': case 'r': case 's': case 't':
|
|
|
|
case 'u': case 'v': case 'w': case 'x': case 'y':
|
2017-10-09 19:45:33 +00:00
|
|
|
case 'z':
|
2017-07-28 15:04:54 +00:00
|
|
|
case '0': case '1': case '2': case '3': case '4':
|
|
|
|
case '5': case '6': case '7': case '8': case '9':
|
2018-05-16 11:07:07 +00:00
|
|
|
case '%': // to do : ensure that preceding is a number
|
2017-07-28 15:04:54 +00:00
|
|
|
case '-':
|
|
|
|
switch (word) {
|
|
|
|
case Word::kStart:
|
|
|
|
word = Word::kMixed;
|
|
|
|
break;
|
|
|
|
case Word::kMixed:
|
|
|
|
case Word::kCap:
|
|
|
|
case Word::kFirst:
|
|
|
|
case Word::kUnderline:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
|
|
|
}
|
|
|
|
hasLower = true;
|
|
|
|
punctuation = PunctuationState::kStart;
|
2017-09-21 16:31:06 +00:00
|
|
|
hasIndirection |= embeddedIndirection;
|
2017-07-31 15:48:27 +00:00
|
|
|
hasSymbol |= embeddedSymbol;
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
2017-10-26 11:58:48 +00:00
|
|
|
case '~':
|
|
|
|
SkASSERT(Word::kStart == word);
|
|
|
|
word = PunctuationState::kStart == punctuation ? Word::kFirst : Word::kCap;
|
|
|
|
start = run;
|
|
|
|
hasUpper = true;
|
|
|
|
hasIndirection |= embeddedIndirection;
|
|
|
|
hasSymbol |= embeddedSymbol;
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
|
|
|
}
|
|
|
|
++run;
|
|
|
|
}
|
|
|
|
if ((word == Word::kCap || word == Word::kFirst || word == Word::kUnderline) && hasLower) {
|
|
|
|
lastWrite = this->lookupReference(punctuation, word, start, run, lastWrite, last, data);
|
2017-07-31 15:48:27 +00:00
|
|
|
} else if (word == Word::kMixed && hasUpper && hasLower && !hasSymbol && lastSpace > 0) {
|
2017-09-21 16:31:06 +00:00
|
|
|
lastWrite = this->lookupMethod(punctuation, word, lastSpace, run, lastWrite, data,
|
|
|
|
hasIndirection && !hasSymbol);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
if (run > lastWrite) {
|
|
|
|
if (' ' == data[lastWrite]) {
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
|
|
|
this->writeBlock(run - lastWrite, &data[lastWrite]);
|
|
|
|
}
|
|
|
|
return wroteLineFeeds ? Wrote::kLF : Wrote::kChars;
|
|
|
|
}
|
2018-06-08 15:54:32 +00:00
|
|
|
|
|
|
|
static string paddedString(int num) {
|
|
|
|
auto padded = std::to_string(num);
|
|
|
|
padded.insert(0, 2U - std::min(string::size_type(2), padded.length()), '0');
|
|
|
|
return padded;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IncludeWriter::writeHeader(std::pair<const string, Definition>& include) {
|
|
|
|
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
|
|
|
time_t tt = std::chrono::system_clock::to_time_t(now);
|
|
|
|
tm local_tm = *localtime(&tt);
|
|
|
|
|
|
|
|
// find end of copyright header
|
|
|
|
fChar = fStart;
|
|
|
|
if (!this->skipExact(
|
|
|
|
"/*\n"
|
|
|
|
" * Copyright ")) {
|
|
|
|
return this->reportError<bool>("copyright mismatch 1");
|
|
|
|
}
|
|
|
|
const char* date = fChar;
|
|
|
|
this->skipToSpace();
|
|
|
|
string yearStr(date, fChar - date);
|
|
|
|
int year = stoi(yearStr);
|
|
|
|
if (year < 2005 || year > local_tm.tm_year + 1900) {
|
|
|
|
return this->reportError<bool>("copyright year out of range");
|
|
|
|
}
|
|
|
|
this->skipSpace();
|
|
|
|
const char android[] = "The Android Open Source Project";
|
|
|
|
const char google[] = "Google Inc.";
|
|
|
|
if (this->startsWith(android)) {
|
|
|
|
this->skipExact(android);
|
|
|
|
} else if (!this->skipExact(google)) {
|
|
|
|
return this->reportError<bool>("copyright mismatch 2");
|
|
|
|
}
|
|
|
|
if (!this->skipExact(
|
|
|
|
"\n"
|
|
|
|
" *\n"
|
|
|
|
" * Use of this source code is governed by a BSD-style license that can be\n"
|
|
|
|
" * found in the LICENSE file.\n"
|
|
|
|
" */\n"
|
|
|
|
"\n"
|
|
|
|
)) {
|
|
|
|
return this->reportError<bool>("copyright mismatch 2");
|
|
|
|
}
|
|
|
|
this->writeBlock(fChar - fStart, fStart);
|
|
|
|
this->lf(2);
|
|
|
|
this->writeString("/* Generated by tools/bookmaker from");
|
|
|
|
this->writeSpace();
|
|
|
|
string includeName = include.first;
|
|
|
|
std::replace(includeName.begin(), includeName.end(), '\\', '/');
|
|
|
|
this->writeString(includeName);
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeString("and");
|
|
|
|
this->writeSpace();
|
|
|
|
string bmhName = fRootTopic->fFileName;
|
|
|
|
std::replace(bmhName.begin(), bmhName.end(), '\\', '/');
|
|
|
|
this->writeString(bmhName);
|
|
|
|
this->lfcr();
|
|
|
|
fIndent = 3;
|
|
|
|
string dateTimeStr = std::to_string(local_tm.tm_year + 1900) + "-"
|
|
|
|
+ paddedString(local_tm.tm_mon + 1) + "-"
|
|
|
|
+ paddedString(local_tm.tm_mday) + " "
|
|
|
|
+ paddedString(local_tm.tm_hour) + ":"
|
|
|
|
+ paddedString(local_tm.tm_min) + ":"
|
|
|
|
+ paddedString(local_tm.tm_sec);
|
|
|
|
this->writeString("on");
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeString(dateTimeStr);
|
|
|
|
this->writeString(". Additional documentation and examples can be found at:");
|
|
|
|
this->lfcr();
|
|
|
|
this->writeString("https://skia.org/user/api/");
|
|
|
|
size_t bmhPageStart = bmhName.rfind('/');
|
|
|
|
size_t bmhPageEnd = bmhName.rfind('.');
|
|
|
|
if (string::npos == bmhPageStart || string::npos == bmhPageEnd) {
|
|
|
|
return this->reportError<bool>("badly formed bmh page name");
|
|
|
|
}
|
|
|
|
++bmhPageStart;
|
|
|
|
string bmhPage = bmhName.substr(bmhPageStart, bmhPageEnd - bmhPageStart);
|
|
|
|
this->writeString(bmhPage);
|
|
|
|
this->lf(2);
|
|
|
|
this->writeString("You may edit either file directly. Structural changes to public interfaces require");
|
|
|
|
this->lfcr();
|
|
|
|
this->writeString("editing both files. After editing");
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeString(bmhName);
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeString(", run:");
|
|
|
|
this->lfcr();
|
|
|
|
fIndent += 4;
|
|
|
|
this->writeString("bookmaker -b docs -i");
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeString(includeName);
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeString("-p");
|
|
|
|
this->lfcr();
|
|
|
|
fIndent -= 4;
|
|
|
|
this->writeString("to create an updated version of this file.");
|
|
|
|
this->lfcr();
|
|
|
|
fIndent = 1;
|
|
|
|
this->writeString("*/");
|
|
|
|
this->lf(2);
|
|
|
|
fIndent = 0;
|
2018-06-08 19:57:37 +00:00
|
|
|
if (this->startsWith("/* Generated by tools/bookmaker from")) {
|
|
|
|
this->skipToEndBracket("*/");
|
|
|
|
if (!this->skipExact("*/\n\n")) {
|
|
|
|
return this->reportError<bool>("malformed generated comment");
|
|
|
|
}
|
|
|
|
}
|
2018-06-08 15:54:32 +00:00
|
|
|
fStart = fChar;
|
2018-06-08 19:57:37 +00:00
|
|
|
|
2018-06-08 15:54:32 +00:00
|
|
|
return true;
|
|
|
|
}
|