aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/bookmaker
diff options
context:
space:
mode:
authorGravatar Cary Clark <caryclark@skia.org>2018-02-27 09:54:21 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-27 15:12:59 +0000
commitf895a420c93f18df10dc95da182025847a0e061a (patch)
tree8108cfdf8afa28275f7abc3df54d428973ae0dda /tools/bookmaker
parent0a3b12bbcec77cb7007e0c3421a84affdc27a146 (diff)
work on skimageinfo
work on skimageinfo Docs-Preview: https://skia.org/?cl=109081 TBR=caryclark@google.com Bug: skia:6898 Change-Id: I4d1734647ef1fa879d08b04c64142c7f16abc858 Reviewed-on: https://skia-review.googlesource.com/109081 Commit-Queue: Cary Clark <caryclark@skia.org> Reviewed-by: Cary Clark <caryclark@skia.org>
Diffstat (limited to 'tools/bookmaker')
-rw-r--r--tools/bookmaker/bookmaker.cpp95
-rw-r--r--tools/bookmaker/bookmaker.h21
-rw-r--r--tools/bookmaker/fiddleParser.cpp26
-rw-r--r--tools/bookmaker/includeWriter.cpp9
-rw-r--r--tools/bookmaker/mdOut.cpp39
-rw-r--r--tools/bookmaker/spellCheck.cpp2
6 files changed, 137 insertions, 55 deletions
diff --git a/tools/bookmaker/bookmaker.cpp b/tools/bookmaker/bookmaker.cpp
index f3641a92d5..02dbbc1961 100644
--- a/tools/bookmaker/bookmaker.cpp
+++ b/tools/bookmaker/bookmaker.cpp
@@ -48,6 +48,7 @@ enum comments should be disallowed unless after #Enum and before first #Const
trouble with aliases, plurals
need to keep first letter of includeWriter @param / @return lowercase
Quad -> quad, Quads -> quads
+deprecated methods should be sorted down in md out, and show include "Deprecated." text body.
see head of selfCheck.cpp for additional todos
*/
@@ -60,7 +61,7 @@ see head of selfCheck.cpp for additional todos
*/
bool BmhParser::addDefinition(const char* defStart, bool hasEnd, MarkType markType,
- const vector<string>& typeNameBuilder) {
+ const vector<string>& typeNameBuilder, HasTag hasTag) {
Definition* definition = nullptr;
switch (markType) {
case MarkType::kComment:
@@ -144,6 +145,11 @@ bool BmhParser::addDefinition(const char* defStart, bool hasEnd, MarkType markTy
return false;
}
}
+ if (HasTag::kYes == hasTag) {
+ if (!this->checkEndMarker(markType, definition->fName)) {
+ return false;
+ }
+ }
if (!this->popParentStack(definition)) {
return false;
}
@@ -221,6 +227,9 @@ bool BmhParser::addDefinition(const char* defStart, bool hasEnd, MarkType markTy
string fullTopic = hasEnd ? fParent->fFiddle : definition->fFiddle;
Definition* defPtr = fTopicMap[fullTopic];
if (hasEnd) {
+ if (HasTag::kYes == hasTag && !this->checkEndMarker(markType, fullTopic)) {
+ return false;
+ }
if (!definition) {
definition = defPtr;
} else if (definition != defPtr) {
@@ -366,6 +375,7 @@ bool BmhParser::addDefinition(const char* defStart, bool hasEnd, MarkType markTy
case MarkType::kDuration:
case MarkType::kFile:
case MarkType::kHeight:
+ case MarkType::kIllustration:
case MarkType::kImage:
case MarkType::kIn:
case MarkType::kLine:
@@ -469,6 +479,33 @@ void BmhParser::reportDuplicates(const Definition& def, const string& dup) const
}
}
+
+static Definition* find_fiddle(Definition* def, string name) {
+ if (MarkType::kExample == def->fMarkType && name == def->fFiddle) {
+ return def;
+ }
+ for (auto& child : def->fChildren) {
+ Definition* result = find_fiddle(child, name);
+ if (result) {
+ return result;
+ }
+ }
+ return nullptr;
+}
+
+Definition* BmhParser::findExample(string name) const {
+ for (const auto& topic : fTopicMap) {
+ if (topic.second->fParent) {
+ continue;
+ }
+ Definition* def = find_fiddle(topic.second, name);
+ if (def) {
+ return def;
+ }
+ }
+ return nullptr;
+}
+
static void find_examples(const Definition& def, vector<string>* exampleNames) {
if (MarkType::kExample == def.fMarkType) {
exampleNames->push_back(def.fFiddle);
@@ -478,6 +515,39 @@ static void find_examples(const Definition& def, vector<string>* exampleNames) {
}
}
+bool BmhParser::checkEndMarker(MarkType markType, string match) const {
+ TextParser tp(fFileName, fLine, fChar, fLineCount);
+ tp.skipSpace();
+ if (fMC != tp.next()) {
+ return this->reportError<bool>("mismatched end marker expect #");
+ }
+ const char* nameStart = tp.fChar;
+ tp.skipToNonAlphaNum();
+ string markName(nameStart, tp.fChar - nameStart);
+ if (fMaps[(int) markType].fName != markName) {
+ return this->reportError<bool>("expected #XXX ## to match");
+ }
+ tp.skipSpace();
+ nameStart = tp.fChar;
+ tp.skipToNonAlphaNum();
+ markName = string(nameStart, tp.fChar - nameStart);
+ if ("" == markName) {
+ if (fMC != tp.next() || fMC != tp.next()) {
+ return this->reportError<bool>("expected ##");
+ }
+ return true;
+ }
+ std::replace(markName.begin(), markName.end(), '-', '_');
+ auto defPos = match.rfind(markName);
+ if (string::npos == defPos) {
+ return this->reportError<bool>("mismatched end marker v1");
+ }
+ if (markName.size() != match.size() - defPos) {
+ return this->reportError<bool>("mismatched end marker v2");
+ }
+ return true;
+}
+
bool BmhParser::checkExamples() const {
vector<string> exampleNames;
for (const auto& topic : fTopicMap) {
@@ -731,7 +801,8 @@ bool BmhParser::findDefinitions() {
} else {
vector<string> parentName;
parentName.push_back(fParent->fName);
- if (!this->addDefinition(fChar - 1, true, fParent->fMarkType, parentName)) {
+ if (!this->addDefinition(fChar - 1, true, fParent->fMarkType, parentName,
+ HasTag::kNo)) {
return false;
}
}
@@ -775,7 +846,8 @@ bool BmhParser::findDefinitions() {
if (hasEnd && expectEnd) {
SkASSERT(fMC != this->peek());
}
- if (!this->addDefinition(defStart, hasEnd, markType, typeNameBuilder)) {
+ if (!this->addDefinition(defStart, hasEnd, markType, typeNameBuilder,
+ HasTag::kYes)) {
return false;
}
continue;
@@ -1527,6 +1599,7 @@ vector<string> BmhParser::typeName(MarkType markType, bool* checkEnd) {
case MarkType::kDuration:
case MarkType::kFile:
case MarkType::kHeight:
+ case MarkType::kIllustration:
case MarkType::kImage:
case MarkType::kIn:
case MarkType::kLiteral:
@@ -1613,10 +1686,14 @@ string BmhParser::uniqueName(const string& base, MarkType markType) {
int number = 2;
string numBuilder(builder);
do {
- for (const auto& iter : fParent->fChildren) {
+ for (auto& iter : fParent->fChildren) {
if (markType == iter->fMarkType) {
if (iter->fName == numBuilder) {
- fCloned = true;
+ if (iter->fDeprecated) {
+ iter->fClone = true;
+ } else {
+ fCloned = true;
+ }
numBuilder = builder + '_' + to_string(number);
goto tryNext;
}
@@ -1669,8 +1746,14 @@ tryNext: ;
}
if (MarkType::kMethod == markType) {
cloned->fCloned = true;
+ if (cloned->fDeprecated) {
+ cloned->fClone = true;
+ } else {
+ fCloned = true;
+ }
+ } else {
+ fCloned = true;
}
- fCloned = true;
numBuilder = builder + '_' + to_string(number);
} while (++number);
return numBuilder;
diff --git a/tools/bookmaker/bookmaker.h b/tools/bookmaker/bookmaker.h
index bc7e0a1b21..7bb743c9cb 100644
--- a/tools/bookmaker/bookmaker.h
+++ b/tools/bookmaker/bookmaker.h
@@ -106,6 +106,7 @@ enum class MarkType {
kFormula,
kFunction,
kHeight,
+ kIllustration,
kImage,
kIn,
kLegend,
@@ -1216,6 +1217,11 @@ public:
kColumnEnd,
};
+ enum class HasTag {
+ kNo,
+ kYes,
+ };
+
#define M(mt) (1LL << (int) MarkType::k##mt)
#define M_D M(Description)
#define M_CS M(Class) | M(Struct)
@@ -1247,7 +1253,7 @@ public:
, { "Code", nullptr, MarkType::kCode, R_O, E_N, M_CSST | M_E | M(Method) }
, { "", nullptr, MarkType::kColumn, R_Y, E_N, M(Row) }
, { "", nullptr, MarkType::kComment, R_N, E_N, 0 }
-, { "Const", &fConstMap, MarkType::kConst, R_Y, E_N, M_E | M_ST }
+, { "Const", &fConstMap, MarkType::kConst, R_Y, E_O, M_E | M_ST }
, { "Define", nullptr, MarkType::kDefine, R_O, E_N, M_ST }
, { "DefinedBy", nullptr, MarkType::kDefinedBy, R_N, E_N, M(Method) }
, { "Deprecated", nullptr, MarkType::kDeprecated, R_Y, E_N, 0 }
@@ -1256,14 +1262,16 @@ public:
, { "Duration", nullptr, MarkType::kDuration, R_N, E_N, M(Example) | M(NoExample) }
, { "Enum", &fEnumMap, MarkType::kEnum, R_Y, E_O, M_CSST | M(Root) }
, { "EnumClass", &fClassMap, MarkType::kEnumClass, R_Y, E_O, M_CSST | M(Root) }
-, { "Example", nullptr, MarkType::kExample, R_O, E_N, M_CSST | M_E | M(Method) }
+, { "Example", nullptr, MarkType::kExample,
+ R_O, E_N, M_CSST | M_E | M(Method) | M(Const) }
, { "Experimental", nullptr, MarkType::kExperimental, R_Y, E_N, 0 }
, { "External", nullptr, MarkType::kExternal, R_Y, E_N, M(Root) }
, { "File", nullptr, MarkType::kFile, R_N, E_N, M(Track) }
, { "Formula", nullptr, MarkType::kFormula, R_O, E_N,
- M(Column) | M_ST | M(Member) | M(Method) | M_D }
+ M(Column) | M_E | M_ST | M(Member) | M(Method) | M_D }
, { "Function", nullptr, MarkType::kFunction, R_O, E_N, M(Example) | M(NoExample) }
, { "Height", nullptr, MarkType::kHeight, R_N, E_N, M(Example) | M(NoExample) }
+, { "Illustration", nullptr, MarkType::kIllustration, R_N, E_N, M(Subtopic) }
, { "Image", nullptr, MarkType::kImage, R_N, E_N, M(Example) | M(NoExample) }
, { "In", nullptr, MarkType::kIn, R_N, E_N,
M_CSST | M_E | M(Method) | M(Typedef) }
@@ -1322,7 +1330,8 @@ public:
~BmhParser() override {}
bool addDefinition(const char* defStart, bool hasEnd, MarkType markType,
- const vector<string>& typeNameBuilder);
+ const vector<string>& typeNameBuilder, HasTag hasTag);
+ bool checkEndMarker(MarkType markType, string name) const;
bool checkExamples() const;
bool checkParamReturn(const Definition* definition) const;
bool dumpExamples(const char* fiddleJsonFileName) const;
@@ -1341,6 +1350,7 @@ public:
}
bool findDefinitions();
+ Definition* findExample(string name) const;
MarkType getMarkType(MarkLookup lookup) const;
bool hasEndToken() const;
string memberName();
@@ -1461,6 +1471,7 @@ public:
, { nullptr, MarkType::kFormula }
, { nullptr, MarkType::kFunction }
, { nullptr, MarkType::kHeight }
+ , { nullptr, MarkType::kIllustration }
, { nullptr, MarkType::kImage }
, { nullptr, MarkType::kIn }
, { nullptr, MarkType::kLegend }
@@ -1954,7 +1965,7 @@ protected:
INHERITED::resetCommon();
}
- Definition* findExample(const string& name) const;
+ Definition* findExample(string name) const { return fBmhParser->findExample(name); }
bool parseFiddles();
virtual bool pngOut(Definition* example) = 0;
virtual bool textOut(Definition* example, const char* stdOutStart,
diff --git a/tools/bookmaker/fiddleParser.cpp b/tools/bookmaker/fiddleParser.cpp
index faf551006f..682c87c845 100644
--- a/tools/bookmaker/fiddleParser.cpp
+++ b/tools/bookmaker/fiddleParser.cpp
@@ -7,32 +7,6 @@
#include "bookmaker.h"
-static Definition* find_fiddle(Definition* def, const string& name) {
- if (MarkType::kExample == def->fMarkType && name == def->fFiddle) {
- return def;
- }
- for (auto& child : def->fChildren) {
- Definition* result = find_fiddle(child, name);
- if (result) {
- return result;
- }
- }
- return nullptr;
-}
-
-Definition* FiddleBase::findExample(const string& name) const {
- for (const auto& topic : fBmhParser->fTopicMap) {
- if (topic.second->fParent) {
- continue;
- }
- Definition* def = find_fiddle(topic.second, name);
- if (def) {
- return def;
- }
- }
- return nullptr;
-}
-
bool FiddleBase::parseFiddles() {
if (!this->skipExact("{\n")) {
return false;
diff --git a/tools/bookmaker/includeWriter.cpp b/tools/bookmaker/includeWriter.cpp
index 0b77cface0..328e9412cb 100644
--- a/tools/bookmaker/includeWriter.cpp
+++ b/tools/bookmaker/includeWriter.cpp
@@ -1234,9 +1234,6 @@ bool IncludeWriter::populate(Definition* def, ParentPair* prevPair, RootDefiniti
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;
@@ -1407,9 +1404,6 @@ bool IncludeWriter::populate(Definition* def, ParentPair* prevPair, RootDefiniti
return false;
}
} else {
- if ("FontMetrics" == child.fName) {
- SkDebugf("");
- }
if (!this->populate(&child, &pair, root)) {
return false;
}
@@ -1660,9 +1654,6 @@ 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;
diff --git a/tools/bookmaker/mdOut.cpp b/tools/bookmaker/mdOut.cpp
index 61692aa69c..f74853b470 100644
--- a/tools/bookmaker/mdOut.cpp
+++ b/tools/bookmaker/mdOut.cpp
@@ -257,6 +257,8 @@ string MdOut::addReferences(const char* refStart, const char* refEnd,
return result;
}
+
+
bool MdOut::buildReferences(const char* docDir, const char* mdFileOrPath) {
if (!sk_isdir(mdFileOrPath)) {
SkString mdFile = SkOSPath::Basename(mdFileOrPath);
@@ -272,15 +274,8 @@ bool MdOut::buildReferences(const char* docDir, const char* mdFileOrPath) {
SkOSFile::Iter it(docDir, ".bmh");
for (SkString file; it.next(&file); ) {
SkString p = SkOSPath::Join(docDir, file.c_str());
- const char* hunk = p.c_str();
- if (!SkStrEndsWith(hunk, ".bmh")) {
- continue;
- }
- if (SkStrEndsWith(hunk, "markup.bmh")) { // don't look inside this for now
- continue;
- }
- if (!this->buildRefFromFile(hunk, mdFileOrPath)) {
- SkDebugf("failed to parse %s\n", hunk);
+ if (!this->buildRefFromFile(p.c_str(), mdFileOrPath)) {
+ SkDebugf("failed to parse %s\n", p.c_str());
return false;
}
}
@@ -302,6 +297,15 @@ bool MdOut::buildStatus(const char* statusFile, const char* outDir) {
}
bool MdOut::buildRefFromFile(const char* name, const char* outDir) {
+ if (!SkStrEndsWith(name, ".bmh")) {
+ return true;
+ }
+ if (SkStrEndsWith(name, "markup.bmh")) { // don't look inside this for now
+ return true;
+ }
+ if (SkStrEndsWith(name, "illustrations.bmh")) { // don't look inside this for now
+ return true;
+ }
fFileName = string(name);
string filename(name);
if (filename.substr(filename.length() - 4) == ".bmh") {
@@ -882,6 +886,23 @@ void MdOut::markTypeOut(Definition* def) {
break;
case MarkType::kHeight:
break;
+ case MarkType::kIllustration: {
+ string illustName = "Illustrations_" + def->fParent->fFiddle;
+ auto illustIter = fBmhParser.fTopicMap.find(illustName);
+ SkASSERT(fBmhParser.fTopicMap.end() != illustIter);
+ Definition* illustDef = illustIter->second;
+ SkASSERT(MarkType::kSubtopic == illustDef->fMarkType);
+ SkASSERT(1 == illustDef->fChildren.size());
+ Definition* illustExample = illustDef->fChildren[0];
+ SkASSERT(MarkType::kExample == illustExample->fMarkType);
+ string hash = illustExample->fHash;
+ SkASSERT("" != hash);
+ string title;
+ this->writePending();
+ FPRINTF("![%s](https://fiddle.skia.org/i/%s_raster.png \"%s\")",
+ def->fName.c_str(), hash.c_str(), title.c_str());
+ this->lf(2);
+ } break;
case MarkType::kImage:
break;
case MarkType::kIn:
diff --git a/tools/bookmaker/spellCheck.cpp b/tools/bookmaker/spellCheck.cpp
index 3cb62be3ef..e5ad746379 100644
--- a/tools/bookmaker/spellCheck.cpp
+++ b/tools/bookmaker/spellCheck.cpp
@@ -191,6 +191,8 @@ bool SpellCheck::check(Definition* def) {
break;
case MarkType::kHeight:
break;
+ case MarkType::kIllustration:
+ break;
case MarkType::kImage:
break;
case MarkType::kIn: