fix more include generation bugs

Recent changes to generate tables of methods
require more parsing to figure things like
indention params for structs.

Fix other stuff that got broken since the last
time all includes were generated.

TBR=caryclark@google.com
Bug: skia:6898
Change-Id: Icd6f5feb5324eb4e0feb307400aa53207109cb29
Reviewed-on: https://skia-review.googlesource.com/108182
Commit-Queue: Cary Clark <caryclark@skia.org>
Reviewed-by: Cary Clark <caryclark@skia.org>
This commit is contained in:
Cary Clark 2018-02-20 10:35:29 -05:00 committed by Skia Commit-Bot
parent b5d82b4bde
commit c68ba1d7d9
3 changed files with 174 additions and 189 deletions

View File

@ -1136,6 +1136,7 @@ SkDebugf("paint.isSubpixelText() %c= !!(paint.getFlags() & SkPaint::kSubpixelTex
#Subtopic Subpixel_Text ##
#Subtopic LCD_Text
#Substitute LCD text
#Line # text relying on the order of Color_RGB stripes ##
#Alias LCD_Text # makes this a top level name, since it is under subtopic Device_Text

View File

@ -1823,6 +1823,7 @@ public:
enum class PunctuationState {
kStart,
kDelimiter,
kParen, // treated as a delimiter unless following a space, and followed by word
kPeriod,
kSpace,
};
@ -1912,6 +1913,7 @@ public:
Definition* structMemberOut(const Definition* memberStart, const Definition& child);
void structOut(const Definition* root, const Definition& child,
const char* commentStart, const char* commentEnd);
void structSetMembersShort(const vector<Definition*>& bmhChildren);
void structSizeMembers(const Definition& child);
private:
BmhParser* fBmhParser;

View File

@ -732,18 +732,25 @@ void IncludeWriter::structOut(const Definition* root, const Definition& child,
Definition* IncludeWriter::findMemberCommentBlock(const vector<Definition*>& bmhChildren,
const string& name) const {
for (auto memberDef : bmhChildren) {
if (memberDef->fName.length() - name.length() == memberDef->fName.find(name)) {
if (MarkType::kMember != memberDef->fMarkType) {
continue;
}
string match = memberDef->fName;
// if match.endsWith(name) ...
if (match.length() >= name.length() &&
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) {
if (MarkType::kSubtopic != memberDef->fMarkType && MarkType::kTopic != memberDef->fMarkType) {
continue;
}
Definition* result = this->findMemberCommentBlock(memberDef->fChildren, name);
if (result) {
return result;
}
}
}
return nullptr;
}
@ -762,12 +769,9 @@ Definition* IncludeWriter::structMemberOut(const Definition* memberStart, const
if (!commentBlock) {
return memberStart->reportError<Definition*>("member missing comment block");
}
if (!commentBlock->fShort) {
const char* commentStart = commentBlock->fContentStart;
ptrdiff_t commentLen = commentBlock->fContentEnd - commentStart;
bool isShort = commentBlock->fShort;
SkASSERT(!isShort || commentBlock->fChildren.size() == 0);
if (!isShort) {
this->writeCommentHeader();
bool wroteLineFeed = false;
fIndent += 4;
@ -812,16 +816,40 @@ Definition* IncludeWriter::structMemberOut(const Definition* memberStart, const
valueStart->fContentStart);
}
this->writeString(";");
if (isShort) {
if (commentBlock->fShort) {
this->indentToColumn(fStructCommentTab);
this->writeString("//!<");
this->writeSpace();
this->rewriteBlock(commentLen, commentStart, Phrase::kNo);
string extract = commentBlock->extractText(Definition::TrimExtract::kYes);
this->rewriteBlock(extract.length(), &extract.front(), Phrase::kNo);
}
this->lf(2);
return valueEnd;
}
// iterate through bmh children and see which comments fit on include lines
void IncludeWriter::structSetMembersShort(const vector<Definition*>& bmhChildren) {
for (auto memberDef : bmhChildren) {
if (MarkType::kMember != memberDef->fMarkType) {
continue;
}
string extract = memberDef->extractText(Definition::TrimExtract::kYes);
bool multiline = string::npos != extract.find('\n');
if (multiline) {
memberDef->fShort = false;
} else {
ptrdiff_t lineLen = extract.length() + 5 /* //!< space */ ;
memberDef->fShort = fStructCommentTab + lineLen < 100;
}
}
for (auto memberDef : bmhChildren) {
if (MarkType::kSubtopic != memberDef->fMarkType && MarkType::kTopic != memberDef->fMarkType) {
continue;
}
this->structSetMembersShort(memberDef->fChildren);
}
}
void IncludeWriter::structSizeMembers(const Definition& child) {
int longestType = 0;
Definition* typeStart = nullptr;
@ -933,20 +961,7 @@ void IncludeWriter::structSizeMembers(const Definition& child) {
fStructValueTab -= 1 /* ; */ ;
}
// iterate through bmh children and see which comments fit on include lines
for (auto& member : fBmhStructDef->fChildren) {
if (MarkType::kMember != member->fMarkType) {
continue;
}
TextParser memberLine(member);
memberLine.trimEnd();
const char* commentStart = memberLine.fChar;
memberLine.skipLine();
ptrdiff_t lineLen = memberLine.fChar - commentStart + 5 /* //!< space */ ;
if (!memberLine.eof()) {
memberLine.skipWhiteSpace();
}
member->fShort = memberLine.eof() && fStructCommentTab + lineLen < 100;
}
this->structSetMembersShort(fBmhStructDef->fChildren);
}
static bool find_start(const Definition* startDef, const char* start) {
@ -1215,10 +1230,13 @@ bool IncludeWriter::populate(Definition* def, ParentPair* prevPair, RootDefiniti
}
#endif
}
const Definition* cIncludeStructDef = nullptr;
switch (child.fKeyWord) {
case KeyWord::kStruct:
case KeyWord::kClass:
fStructMemberTab = 0;
if ("FontMetrics" == child.fName) {
SkDebugf("");
}
// if struct contains members, compute their name and comment tabs
if (child.fChildren.size() > 0) {
const ParentPair* testPair = &pair;
@ -1381,28 +1399,7 @@ bool IncludeWriter::populate(Definition* def, ParentPair* prevPair, RootDefiniti
default:
SkASSERT(0);
}
if (cIncludeStructDef) {
TextParser structName(&child);
SkAssertResult(structName.skipToEndBracket('{'));
startDef = &child;
fStart = structName.fChar + 1;
this->writeBlock((int) (fStart - child.fStart), child.fStart);
this->lf(2);
fIndent += 4;
if (!this->populate(&child, &pair, const_cast<Definition*>(cIncludeStructDef)->asRoot())) {
return false;
}
// output any remaining definitions at current indent level
const char* structEnd = child.fContentEnd;
SkAssertResult('}' == structEnd[-1]);
--structEnd;
this->writeBlockTrim((int) (structEnd - fStart), fStart);
this->lf(2);
fStart = structEnd;
fIndent -= 4;
fContinuation = nullptr;
fDeferComment = nullptr;
} else if (KeyWord::kUint8_t == child.fKeyWord) {
if (KeyWord::kUint8_t == child.fKeyWord) {
continue;
} else {
if (fInEnum && KeyWord::kClass == child.fChildren[0]->fKeyWord) {
@ -1410,11 +1407,13 @@ bool IncludeWriter::populate(Definition* def, ParentPair* prevPair, RootDefiniti
return false;
}
} else {
if ("FontMetrics" == child.fName) {
SkDebugf("");
}
if (!this->populate(&child, &pair, root)) {
return false;
}
if (KeyWord::kClass == child.fKeyWord || KeyWord::kStruct == child.fKeyWord) {
fStructMemberTab = 0;
if (fInStruct) {
fInStruct = false;
do {
@ -1661,6 +1660,9 @@ string IncludeWriter::resolveRef(const char* start, const char* end, bool first,
RefType* refType) {
// look up Xxx_Xxx
string undername(start, end - start);
if ("Paint_Stroke_Width" == undername) {
SkDebugf("");
}
for (const auto& external : fBmhParser->fExternals) {
if (external.fName == undername) {
*refType = RefType::kExternal;
@ -1779,7 +1781,7 @@ string IncludeWriter::resolveRef(const char* start, const char* end, bool first,
if (parent->fParent != fRootTopic) {
substitute = parent->fName;
substitute += ' ';
substitute += ConvertRef(undername, false);
substitute += ConvertRef(rootDef->fName, false);
} else {
substitute += ConvertRef(undername, first);
}
@ -1802,6 +1804,7 @@ int IncludeWriter::lookupMethod(const PunctuationState punctuation, const Word w
++wordStart;
}
const int wordEnd = PunctuationState::kDelimiter == punctuation ||
PunctuationState::kParen == punctuation ||
PunctuationState::kPeriod == punctuation ? run - 1 : run;
string temp;
if (hasIndirection && '(' != data[wordEnd - 1] && ')' != data[wordEnd - 1]) {
@ -1837,6 +1840,7 @@ int IncludeWriter::lookupMethod(const PunctuationState punctuation, const Word w
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 ||
PunctuationState::kParen == punctuation ||
PunctuationState::kPeriod == punctuation ? run - 1 : run;
RefType refType = RefType::kUndefined;
string resolved = string(&data[start], (size_t) (end - start));
@ -1936,7 +1940,7 @@ IncludeWriter::Wrote IncludeWriter::rewriteBlock(int size, const char* data, Phr
case Word::kMixed:
if (hasUpper && hasLower && !hasSymbol && lastSpace > 0) {
lastWrite = this->lookupMethod(punctuation, word, lastSpace, run,
lastWrite, data, hasIndirection && !hasSymbol);
lastWrite, data, hasIndirection);
}
break;
default:
@ -1954,7 +1958,7 @@ IncludeWriter::Wrote IncludeWriter::rewriteBlock(int size, const char* data, Phr
hasSymbol = false;
lastSpace = run;
break;
case '.':
case '.': case ',': case ';': case ':': case ')':
switch (word) {
case Word::kStart:
punctuation = PunctuationState::kDelimiter;
@ -1966,31 +1970,13 @@ IncludeWriter::Wrote IncludeWriter::rewriteBlock(int size, const char* data, Phr
PunctuationState::kPeriod == punctuation) {
word = Word::kMixed;
}
punctuation = PunctuationState::kPeriod;
punctuation = '.' == c ? PunctuationState::kPeriod :
PunctuationState::kDelimiter;
break;
default:
SkASSERT(0);
}
embeddedIndirection = true;
break;
case ',': case ';': case ':':
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;
}
punctuation = PunctuationState::kDelimiter;
break;
default:
SkASSERT(0);
}
embeddedSymbol = true;
('.' == c ? embeddedIndirection : embeddedSymbol) = true;
break;
case '>':
if ('-' == last) {
@ -2007,16 +1993,12 @@ IncludeWriter::Wrote IncludeWriter::rewriteBlock(int size, const char* data, Phr
break;
case '(':
if (' ' == last) {
punctuation = PunctuationState::kDelimiter;
punctuation = PunctuationState::kParen;
} else {
word = Word::kMixed;
}
embeddedSymbol = true;
break;
case ')': // assume word type has already been set
punctuation = PunctuationState::kDelimiter;
embeddedSymbol = true;
break;
case '_':
switch (word) {
case Word::kStart: