aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--site/user/api/catalog.htm36
-rw-r--r--tools/bookmaker/bookmaker.cpp51
-rw-r--r--tools/bookmaker/bookmaker.h44
-rw-r--r--tools/bookmaker/cataloger.cpp6
-rw-r--r--tools/bookmaker/fiddleParser.cpp141
-rw-r--r--tools/bookmaker/includeParser.cpp3
-rw-r--r--tools/bookmaker/parserCommon.cpp7
7 files changed, 160 insertions, 128 deletions
diff --git a/site/user/api/catalog.htm b/site/user/api/catalog.htm
index 601276638e..a443e99e70 100644
--- a/site/user/api/catalog.htm
+++ b/site/user/api/catalog.htm
@@ -159,7 +159,7 @@
"hash": "cb9a08e8ff779b6a1cf8bb54f3883aaf",
"file": "SkBitmap_Reference",
"name": "SkBitmap::getAddr8",
- "stdout": "\\u0026pixels[4][2] == bitmap.getAddr8(2, 4)\\n"
+ "stdout": "&pixels[4][2] == bitmap.getAddr8(2, 4)\\n"
},
"SkBitmap_getColor": {
"code": "void draw(SkCanvas* canvas) {\n const int w = 4;\n const int h = 4;\n SkColor colors[][w] = {\n { 0x00000000, 0x2a0e002a, 0x55380055, 0x7f7f007f },\n { 0x2a000e2a, 0x551c1c55, 0x7f542a7f, 0xaaaa38aa },\n { 0x55003855, 0x7f2a547f, 0xaa7171aa, 0xd4d48dd4 },\n { 0x7f007f7f, 0xaa38aaaa, 0xd48dd4d4, 0xffffffff }\n };\n SkDebugf(\"Premultiplied:\\n\");\n for (int y = 0; y < h; ++y) {\n SkDebugf(\"(0, %d) \", y);\n for (int x = 0; x < w; ++x) {\n SkDebugf(\"0x%08x%c\", colors[y][x], x == w - 1 ? '\\n' : ' ');\n }\n }\n SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), colors, w * 4);\n SkBitmap bitmap;\n bitmap.installPixels(pixmap);\n SkDebugf(\"Unpremultiplied:\\n\");\n for (int y = 0; y < h; ++y) {\n SkDebugf(\"(0, %d) \", y);\n for (int x = 0; x < w; ++x) {\n SkDebugf(\"0x%08x%c\", bitmap.getColor(x, y), x == w - 1 ? '\\n' : ' ');\n }\n }\n}",
@@ -1524,7 +1524,7 @@
"hash": "8a3f8c309533388b01aa66e1267f322d",
"file": "SkPaint_Reference",
"name": "SkPaint::getFlags",
- "stdout": "(SkPaint::kAntiAlias_Flag \\u0026 paint.getFlags()) != 0\\n"
+ "stdout": "(SkPaint::kAntiAlias_Flag & paint.getFlags()) != 0\\n"
},
"SkPaint_getFontBounds": {
"code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n SkPaint::FontMetrics fm;\n paint.getFontMetrics(&fm);\n SkRect fb = paint.getFontBounds();\n SkDebugf(\"metrics bounds = { %g, %g, %g, %g }\\n\", fm.fXMin, fm.fTop, fm.fXMax, fm.fBottom );\n SkDebugf(\"font bounds = { %g, %g, %g, %g }\\n\", fb.fLeft, fb.fTop, fb.fRight, fm.fBottom );\n}",
@@ -1664,42 +1664,42 @@
"hash": "d7d5f4f7da7acd5104a652f490c6f7b8",
"file": "SkPaint_Reference",
"name": "SkPaint::isAntiAlias",
- "stdout": "paint.isAntiAlias() == !!(paint.getFlags() \\u0026 SkPaint::kAntiAlias_Flag)\\npaint.isAntiAlias() == !!(paint.getFlags() \\u0026 SkPaint::kAntiAlias_Flag)\\n"
+ "stdout": "paint.isAntiAlias() == !!(paint.getFlags() & SkPaint::kAntiAlias_Flag)\\npaint.isAntiAlias() == !!(paint.getFlags() & SkPaint::kAntiAlias_Flag)\\n"
},
"SkPaint_isAutohinted": {
"code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n for (auto forceAutoHinting : { false, true} ) {\n paint.setAutohinted(forceAutoHinting);\n SkDebugf(\"paint.isAutohinted() %c=\"\n \" !!(paint.getFlags() & SkPaint::kAutoHinting_Flag)\\n\",\n paint.isAutohinted() ==\n !!(paint.getFlags() & SkPaint::kAutoHinting_Flag) ? '=' : '!');\n }\n}",
"hash": "aa4781afbe3b90e7ef56a287e5b9ce1e",
"file": "SkPaint_Reference",
"name": "SkPaint::isAutohinted",
- "stdout": "paint.isAutohinted() == !!(paint.getFlags() \\u0026 SkPaint::kAutoHinting_Flag)\\npaint.isAutohinted() == !!(paint.getFlags() \\u0026 SkPaint::kAutoHinting_Flag)\\n"
+ "stdout": "paint.isAutohinted() == !!(paint.getFlags() & SkPaint::kAutoHinting_Flag)\\npaint.isAutohinted() == !!(paint.getFlags() & SkPaint::kAutoHinting_Flag)\\n"
},
"SkPaint_isDither": {
"code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n SkDebugf(\"paint.isDither() %c= !!(paint.getFlags() & SkPaint::kDither_Flag)\\n\",\n paint.isDither() == !!(paint.getFlags() & SkPaint::kDither_Flag) ? '=' : '!');\n paint.setDither(true);\n SkDebugf(\"paint.isDither() %c= !!(paint.getFlags() & SkPaint::kDither_Flag)\\n\",\n paint.isDither() == !!(paint.getFlags() & SkPaint::kDither_Flag) ? '=' : '!');\n}",
"hash": "f4ce93f6c5e7335436a985377fd980c0",
"file": "SkPaint_Reference",
"name": "SkPaint::isDither",
- "stdout": "paint.isDither() == !!(paint.getFlags() \\u0026 SkPaint::kDither_Flag)\\npaint.isDither() == !!(paint.getFlags() \\u0026 SkPaint::kDither_Flag)\\n"
+ "stdout": "paint.isDither() == !!(paint.getFlags() & SkPaint::kDither_Flag)\\npaint.isDither() == !!(paint.getFlags() & SkPaint::kDither_Flag)\\n"
},
"SkPaint_isEmbeddedBitmapText": {
"code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n SkDebugf(\"paint.isEmbeddedBitmapText() %c=\"\n \" !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag)\\n\",\n paint.isEmbeddedBitmapText() ==\n !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag) ? '=' : '!');\n paint.setEmbeddedBitmapText(true);\n SkDebugf(\"paint.isEmbeddedBitmapText() %c=\"\n \" !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag)\\n\",\n paint.isEmbeddedBitmapText() ==\n !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag) ? '=' : '!');\n}",
"hash": "eba10b27b790e87183ae451b3fc5c4b1",
"file": "SkPaint_Reference",
"name": "SkPaint::isEmbeddedBitmapText",
- "stdout": "paint.isEmbeddedBitmapText() == !!(paint.getFlags() \\u0026 SkPaint::kEmbeddedBitmapText_Flag)\\npaint.isEmbeddedBitmapText() == !!(paint.getFlags() \\u0026 SkPaint::kEmbeddedBitmapText_Flag)\\n"
+ "stdout": "paint.isEmbeddedBitmapText() == !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag)\\npaint.isEmbeddedBitmapText() == !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag)\\n"
},
"SkPaint_isFakeBoldText": {
"code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n SkDebugf(\"paint.isFakeBoldText() %c= !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag)\\n\",\n paint.isFakeBoldText() == !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag) ? '=' : '!');\n paint.setFakeBoldText(true);\n SkDebugf(\"paint.isFakeBoldText() %c= !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag)\\n\",\n paint.isFakeBoldText() == !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag) ? '=' : '!');\n}",
"hash": "f54d1f85b16073b80b9eef2e1a1d151d",
"file": "SkPaint_Reference",
"name": "SkPaint::isFakeBoldText",
- "stdout": "paint.isFakeBoldText() == !!(paint.getFlags() \\u0026 SkPaint::kFakeBoldText_Flag)\\npaint.isFakeBoldText() == !!(paint.getFlags() \\u0026 SkPaint::kFakeBoldText_Flag)\\n"
+ "stdout": "paint.isFakeBoldText() == !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag)\\npaint.isFakeBoldText() == !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag)\\n"
},
"SkPaint_isLCDRenderText": {
"code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n SkDebugf(\"paint.isLCDRenderText() %c= !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag)\\n\",\n paint.isLCDRenderText() == !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag) ? '=' : '!');\n paint.setLCDRenderText(true);\n SkDebugf(\"paint.isLCDRenderText() %c= !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag)\\n\",\n paint.isLCDRenderText() == !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag) ? '=' : '!');\n}",
"hash": "68e1fd95dd2fd06a333899d2bd2396b9",
"file": "SkPaint_Reference",
"name": "SkPaint::isLCDRenderText",
- "stdout": "paint.isLCDRenderText() == !!(paint.getFlags() \\u0026 SkPaint::kLCDRenderText_Flag)\\npaint.isLCDRenderText() == !!(paint.getFlags() \\u0026 SkPaint::kLCDRenderText_Flag)\\n"
+ "stdout": "paint.isLCDRenderText() == !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag)\\npaint.isLCDRenderText() == !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag)\\n"
},
"SkPaint_isSrcOver": {
"code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n SkDebugf(\"isSrcOver %c= true\\n\", paint.isSrcOver() ? '=' : '!');\n paint.setBlendMode(SkBlendMode::kSrc);\n SkDebugf(\"isSrcOver %c= true\\n\", paint.isSrcOver() ? '=' : '!');\n}\n",
@@ -1713,14 +1713,14 @@
"hash": "abe9afc0932e2199324ae6cbb396e67c",
"file": "SkPaint_Reference",
"name": "SkPaint::isSubpixelText",
- "stdout": "paint.isSubpixelText() == !!(paint.getFlags() \\u0026 SkPaint::kSubpixelText_Flag)\\npaint.isSubpixelText() == !!(paint.getFlags() \\u0026 SkPaint::kSubpixelText_Flag)\\n"
+ "stdout": "paint.isSubpixelText() == !!(paint.getFlags() & SkPaint::kSubpixelText_Flag)\\npaint.isSubpixelText() == !!(paint.getFlags() & SkPaint::kSubpixelText_Flag)\\n"
},
"SkPaint_isVerticalText": {
"code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n SkDebugf(\"paint.isVerticalText() %c= !!(paint.getFlags() & SkPaint::kVerticalText_Flag)\\n\",\n paint.isVerticalText() == !!(paint.getFlags() & SkPaint::kVerticalText_Flag) ? '=' : '!');\n paint.setVerticalText(true);\n SkDebugf(\"paint.isVerticalText() %c= !!(paint.getFlags() & SkPaint::kVerticalText_Flag)\\n\",\n paint.isVerticalText() == !!(paint.getFlags() & SkPaint::kVerticalText_Flag) ? '=' : '!');\n}",
"hash": "4a269b16e644d473870ffa873396f139",
"file": "SkPaint_Reference",
"name": "SkPaint::isVerticalText",
- "stdout": "paint.isVerticalText() == !!(paint.getFlags() \\u0026 SkPaint::kVerticalText_Flag)\\npaint.isVerticalText() == !!(paint.getFlags() \\u0026 SkPaint::kVerticalText_Flag)\\n"
+ "stdout": "paint.isVerticalText() == !!(paint.getFlags() & SkPaint::kVerticalText_Flag)\\npaint.isVerticalText() == !!(paint.getFlags() & SkPaint::kVerticalText_Flag)\\n"
},
"SkPaint_measureText_2": {
"code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n SkDebugf(\"default width = %g\\n\", paint.measureText(\"!\", 1));\n paint.setTextSize(paint.getTextSize() * 2);\n SkDebugf(\"double width = %g\\n\", paint.measureText(\"!\", 1));\n}",
@@ -2399,7 +2399,7 @@
"hash": "2c0c88a546d4ef093ab63ff72dac00b9",
"file": "SkPixmap_Reference",
"name": "SkPixmap::addr16_2",
- "stdout": "pixmap.addr16(1, 2) == \\u0026storage[1 + 2 * w]\\n"
+ "stdout": "pixmap.addr16(1, 2) == &storage[1 + 2 * w]\\n"
},
"SkPixmap_addr32": {
"code": "void draw(SkCanvas* canvas) {\n const int w = 4;\n const int h = 4;\n uint32_t storage[w * h];\n SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType),\n storage, w * sizeof(storage[0]));\n SkDebugf(\"pixmap.addr32() %c= storage\\n\",\n pixmap.addr32() == storage ? '=' : '!');\n}",
@@ -2413,7 +2413,7 @@
"hash": "12f8b5ce9fb25604f33df336677f5d62",
"file": "SkPixmap_Reference",
"name": "SkPixmap::addr32_2",
- "stdout": "pixmap.addr32(1, 2) == \\u0026storage[1 + 2 * w]\\n"
+ "stdout": "pixmap.addr32(1, 2) == &storage[1 + 2 * w]\\n"
},
"SkPixmap_addr64": {
"code": "void draw(SkCanvas* canvas) {\n const int w = 4;\n const int h = 4;\n uint64_t storage[w * h];\n SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),\n storage, w * sizeof(storage[0]));\n SkDebugf(\"pixmap.addr64() %c= storage\\n\",\n pixmap.addr64() == storage ? '=' : '!');\n}",
@@ -2427,7 +2427,7 @@
"hash": "5449f65fd7673273b0b57807fd3117ff",
"file": "SkPixmap_Reference",
"name": "SkPixmap::addr64_2",
- "stdout": "pixmap.addr64(1, 2) == \\u0026storage[1 + 2 * w]\\n"
+ "stdout": "pixmap.addr64(1, 2) == &storage[1 + 2 * w]\\n"
},
"SkPixmap_addr8": {
"code": "void draw(SkCanvas* canvas) {\n const int w = 4;\n const int h = 4;\n uint8_t storage[w * h];\n SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType),\n storage, w * sizeof(storage[0]));\n SkDebugf(\"pixmap.addr8() %c= storage\\n\",\n pixmap.addr8() == storage ? '=' : '!');\n}",
@@ -2441,7 +2441,7 @@
"hash": "5b986272268ef2c52045c1856f8b6107",
"file": "SkPixmap_Reference",
"name": "SkPixmap::addr8_2",
- "stdout": "pixmap.addr8(1, 2) == \\u0026storage[1 + 2 * w]\\n"
+ "stdout": "pixmap.addr8(1, 2) == &storage[1 + 2 * w]\\n"
},
"SkPixmap_addrF16": {
"code": "void draw(SkCanvas* canvas) {\n const int w = 4;\n const int h = 4;\n uint16_t storage[w * h * 4];\n SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType),\n storage, w * 4 * sizeof(storage[0]));\n SkDebugf(\"pixmap.addrF16() %c= storage\\n\",\n pixmap.addrF16() == storage ? '=' : '!');\n}",
@@ -2455,14 +2455,14 @@
"hash": "f6076cad455bc80af5d06eb121d3b6f2",
"file": "SkPixmap_Reference",
"name": "SkPixmap::addrF16_2",
- "stdout": "pixmap.addrF16(1, 2) == \\u0026storage[1 * wordsPerPixel + 2 * rowWords]\\n"
+ "stdout": "pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords]\\n"
},
"SkPixmap_addr_2": {
"code": "void draw(SkCanvas* canvas) {\n const int w = 4;\n const int h = 4;\n std::vector<SkPMColor> storage;\n storage.resize(w * h);\n SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4);\n SkDebugf(\"pixmap.addr(1, 2) %c= &storage[1 + 2 * w]\\n\",\n pixmap.addr(1, 2) == &storage[1 + 2 * w] ? '=' : '!');\n}",
"hash": "6e6e29e860eafed77308c973400cc84d",
"file": "SkPixmap_Reference",
"name": "SkPixmap::addr_2",
- "stdout": "pixmap.addr(1, 2) == \\u0026storage[1 + 2 * w]\\n"
+ "stdout": "pixmap.addr(1, 2) == &storage[1 + 2 * w]\\n"
},
"SkPixmap_alphaType": {
"code": "void draw(SkCanvas* canvas) {\n const char* alphas[] = {\"Unknown\", \"Opaque\", \"Premul\", \"Unpremul\"};\n SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);\n SkDebugf(\"alpha type: k\" \"%s\" \"_SkAlphaType\\n\", alphas[pixmap.alphaType()]);\n}",
@@ -2819,7 +2819,7 @@
"hash": "e1ea5f949d80276f3637931eae93a07c",
"file": "SkRect_Reference",
"name": "SkRect::asScalars",
- "stdout": "rect.asScalars() == \\u0026rect.fLeft\\n"
+ "stdout": "rect.asScalars() == &rect.fLeft\\n"
},
"SkRect_bottom": {
"code": "void draw(SkCanvas* canvas) {\n SkRect unsorted = { 15, 25, 10, 5 };\n SkDebugf(\"unsorted.fBottom: %g unsorted.bottom(): %g\\n\", unsorted.fBottom, unsorted.bottom());\n SkRect sorted = unsorted.makeSorted();\n SkDebugf(\"sorted.fBottom: %g sorted.bottom(): %g\\n\", sorted.fBottom, sorted.bottom());\n}",
@@ -3246,7 +3246,7 @@
"hash": "99a54b814ccab7d2b1143c88581649ff",
"file": "SkSurface_Reference",
"name": "SkSurface::MakeNull",
- "stdout": "SkSurface::MakeNull(0, 0) == nullptr\\nsurf-\\u003emakeImageSnapshot() == nullptr\\n"
+ "stdout": "SkSurface::MakeNull(0, 0) == nullptr\\nsurf->makeImageSnapshot() == nullptr\\n"
},
"SkSurface_MakeRaster": {
"code": "void draw(SkCanvas* ) {\n SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3);\n const size_t rowBytes = 64;\n sk_sp<SkSurface> surface(SkSurface::MakeRaster(info, rowBytes, nullptr));\n SkCanvas* canvas = surface->getCanvas();\n canvas->clear(SK_ColorWHITE);\n SkPixmap pixmap;\n if (surface->peekPixels(&pixmap)) {\n const uint32_t* colorPtr = pixmap.addr32();\n SkPMColor pmWhite = colorPtr[0];\n SkPaint paint;\n canvas->drawPoint(1, 1, paint);\n canvas->flush(); // ensure that point was drawn\n for (int y = 0; y < info.height(); ++y) {\n for (int x = 0; x < info.width(); ++x) {\n SkDebugf(\"%c\", colorPtr[x] == pmWhite ? '-' : 'x');\n }\n colorPtr += rowBytes / sizeof(colorPtr[0]);\n SkDebugf(\"\\n\");\n }\n }\n}\n",
diff --git a/tools/bookmaker/bookmaker.cpp b/tools/bookmaker/bookmaker.cpp
index ffd3012e24..1b8e76ee33 100644
--- a/tools/bookmaker/bookmaker.cpp
+++ b/tools/bookmaker/bookmaker.cpp
@@ -703,6 +703,55 @@ Definition* BmhParser::findExample(string name) const {
return nullptr;
}
+static bool check_example_hashes(Definition* def) {
+ if (MarkType::kExample == def->fMarkType) {
+ if (def->fHash.length()) {
+ return true;
+ }
+ for (auto child : def->fChildren) {
+ if (MarkType::kPlatform == child->fMarkType) {
+ if (string::npos != string(child->fContentStart, child->length()).find("!fiddle")) {
+ return true;
+ }
+ }
+ }
+ return def->reportError<bool>("missing hash");
+ }
+ for (auto& child : def->fChildren) {
+ if (!check_example_hashes(child)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool BmhParser::checkExampleHashes() const {
+ for (const auto& topic : fTopicMap) {
+ if (!topic.second->fParent && !check_example_hashes(topic.second)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+static void reset_example_hashes(Definition* def) {
+ if (MarkType::kExample == def->fMarkType) {
+ def->fHash.clear();
+ return;
+ }
+ for (auto& child : def->fChildren) {
+ reset_example_hashes(child);
+ }
+}
+
+void BmhParser::resetExampleHashes() {
+ for (const auto& topic : fTopicMap) {
+ if (!topic.second->fParent) {
+ reset_example_hashes(topic.second);
+ }
+ }
+}
+
static void find_examples(const Definition& def, vector<string>* exampleNames) {
if (MarkType::kExample == def.fMarkType) {
exampleNames->push_back(def.fFiddle);
@@ -2640,7 +2689,7 @@ int main(int argc, char** const argv) {
}
if (!done && !FLAGS_fiddle.isEmpty() && FLAGS_examples.isEmpty()) {
FiddleParser fparser(&bmhParser);
- if (!fparser.parseFile(FLAGS_fiddle[0], ".txt", ParserCommon::OneFile::kNo)) {
+ if (!fparser.parseFromFile(FLAGS_fiddle[0])) {
return -1;
}
}
diff --git a/tools/bookmaker/bookmaker.h b/tools/bookmaker/bookmaker.h
index c695cff0e8..19ea86b68d 100644
--- a/tools/bookmaker/bookmaker.h
+++ b/tools/bookmaker/bookmaker.h
@@ -1328,19 +1328,29 @@ struct JsonStatus {
string fName;
};
-class StatusIter : public ParserCommon {
+class JsonCommon : public ParserCommon {
+public:
+ bool empty() { return fStack.empty(); }
+ bool parseFromFile(const char* path) override;
+
+ void reset() override {
+ fStack.clear();
+ INHERITED::resetCommon();
+ }
+
+ vector<JsonStatus> fStack;
+ Json::Value fRoot;
+private:
+ typedef ParserCommon INHERITED;
+};
+
+class StatusIter : public JsonCommon {
public:
StatusIter(const char* statusFile, const char* suffix, StatusFilter);
~StatusIter() override {}
string baseDir();
- bool empty() { return fStack.empty(); }
bool next(string* file);
-protected:
- bool parseFromFile(const char* path) override;
- void reset() override;
private:
- vector<JsonStatus> fStack;
- Json::Value fRoot;
const char* fSuffix;
StatusFilter fFilter;
};
@@ -1415,6 +1425,7 @@ public:
bool checkParamReturn(const Definition* definition) const;
bool dumpExamples(FILE* fiddleOut, Definition& def, bool* continuation) const;
bool dumpExamples(const char* fiddleJsonFileName) const;
+ bool checkExampleHashes() const;
bool childOf(MarkType markType) const;
string className(MarkType markType);
bool collectExternals();
@@ -1441,6 +1452,7 @@ public:
bool popParentStack(Definition* definition);
void reportDuplicates(const Definition& def, string dup) const;
+ void resetExampleHashes();
void reset() override {
INHERITED::resetCommon();
@@ -2084,10 +2096,10 @@ private:
typedef IncludeParser INHERITED;
};
-class FiddleBase : public ParserCommon {
+class FiddleBase : public JsonCommon {
protected:
- FiddleBase(BmhParser* bmh) : ParserCommon()
- , fBmhParser(bmh)
+ FiddleBase(BmhParser* bmh)
+ : fBmhParser(bmh)
, fContinuation(false)
, fTextOut(false)
, fPngOut(false)
@@ -2096,7 +2108,7 @@ protected:
}
void reset() override {
- INHERITED::resetCommon();
+ INHERITED::reset();
}
Definition* findExample(string name) const { return fBmhParser->findExample(name); }
@@ -2111,7 +2123,7 @@ protected:
bool fTextOut;
bool fPngOut;
private:
- typedef ParserCommon INHERITED;
+ typedef JsonCommon INHERITED;
};
class FiddleParser : public FiddleBase {
@@ -2121,10 +2133,14 @@ public:
}
bool parseFromFile(const char* path) override {
- if (!INHERITED::parseSetup(path)) {
+ if (!INHERITED::parseFromFile(path)) {
+ return false;
+ }
+ fBmhParser->resetExampleHashes();
+ if (!INHERITED::parseFiddles()) {
return false;
}
- return parseFiddles();
+ return fBmhParser->checkExampleHashes();
}
private:
diff --git a/tools/bookmaker/cataloger.cpp b/tools/bookmaker/cataloger.cpp
index 0e1e38ac45..c6aae74c30 100644
--- a/tools/bookmaker/cataloger.cpp
+++ b/tools/bookmaker/cataloger.cpp
@@ -79,14 +79,13 @@ bool Catalog::closeCatalog() {
}
bool Catalog::parseFromFile(const char* path) {
- if (!INHERITED::parseSetup(path)) {
+ if (!INHERITED::parseFromFile(path)) {
return false;
}
fIndent = 4;
this->writeString("var text = {");
this->lf(1);
fTextOut = true;
- TextParserSave save(this);
if (!parseFiddles()) {
return false;
}
@@ -96,7 +95,8 @@ bool Catalog::parseFromFile(const char* path) {
this->writeString("var pngs = {");
fTextOut = false;
fPngOut = true;
- save.restore();
+ JsonStatus* status = &fStack.back();
+ status->fIter = status->fObject.begin();
fContinuation = false;
return parseFiddles();
}
diff --git a/tools/bookmaker/fiddleParser.cpp b/tools/bookmaker/fiddleParser.cpp
index 524f89d020..990ff201fb 100644
--- a/tools/bookmaker/fiddleParser.cpp
+++ b/tools/bookmaker/fiddleParser.cpp
@@ -8,106 +8,73 @@
#include "bookmaker.h"
bool FiddleBase::parseFiddles() {
- if (!this->skipExact("{\n")) {
+ if (fStack.empty()) {
return false;
}
- while (!this->eof()) {
- if (!this->skipExact(" \"")) {
- return false;
- }
- const char* nameLoc = fChar;
- if (!this->skipToEndBracket("\"")) {
- return false;
- }
- string name(nameLoc, fChar - nameLoc);
- if (!this->skipExact("\": {\n")) {
- return false;
- }
- if (!this->skipExact(" \"compile_errors\": [")) {
- return false;
- }
- if (']' != this->peek()) {
- // report compiler errors
- int brackets = 1;
- do {
- if ('[' == this->peek()) {
- ++brackets;
- } else if (']' == this->peek()) {
- --brackets;
+ JsonStatus* status = &fStack.back();
+ while (status->fIter != status->fObject.end()) {
+ const char* blockName = status->fIter.memberName();
+ Definition* example = nullptr;
+ string textString;
+ if (!status->fObject.isObject()) {
+ return this->reportError<bool>("expected object");
+ }
+ for (auto iter = status->fIter->begin(); status->fIter->end() != iter; ++iter) {
+ const char* memberName = iter.memberName();
+ if (!strcmp("compile_errors", memberName)) {
+ if (!iter->isArray()) {
+ return this->reportError<bool>("expected array");
}
- } while (!this->eof() && this->next() && brackets > 0);
- this->reportError("fiddle compile error");
- }
- if (!this->skipExact("],\n")) {
- return false;
- }
- if (!this->skipExact(" \"runtime_error\": \"")) {
- return false;
- }
- if ('"' != this->peek()) {
- if (!this->skipToEndBracket('"')) {
- return false;
+ if (iter->size()) {
+ return this->reportError<bool>("fiddle compiler error");
+ }
+ continue;
}
- this->reportError("fiddle runtime error");
- }
- if (!this->skipExact("\",\n")) {
- return false;
- }
- if (!this->skipExact(" \"fiddleHash\": \"")) {
- return false;
- }
- const char* hashStart = fChar;
- if (!this->skipToEndBracket('"')) {
- return false;
- }
- Definition* example = this->findExample(name);
- if (!example) {
- this->reportError("missing example");
- }
- string hash(hashStart, fChar - hashStart);
- if (example) {
- example->fHash = hash;
- }
- if (!this->skipExact("\",\n")) {
- return false;
- }
- if (!this->skipExact(" \"text\": \"")) {
- return false;
- }
- if ('"' != this->peek()) {
- const char* stdOutStart = fChar;
- do {
- if ('\\' == this->peek()) {
- this->next();
- } else if ('"' == this->peek()) {
- break;
+ if (!strcmp("runtime_error", memberName)) {
+ if (!iter->isString()) {
+ return this->reportError<bool>("expected string 1");
+ }
+ if (iter->asString().length()) {
+ return this->reportError<bool>("fiddle runtime error");
}
- } while (!this->eof() && this->next());
- const char* stdOutEnd = fChar;
- if (example && fTextOut) {
- if (!this->textOut(example, stdOutStart, stdOutEnd)) {
- return false;
+ continue;
+ }
+ if (!strcmp("fiddleHash", memberName)) {
+ if (!iter->isString()) {
+ return this->reportError<bool>("expected string 2");
+ }
+ example = this->findExample(blockName);
+ if (!example) {
+ return this->reportError<bool>("missing example");
+ }
+ if (example->fHash.length() && example->fHash != iter->asString()) {
+ return example->reportError<bool>("mismatched hash");
}
+ example->fHash = iter->asString();
+ continue;
}
- } else {
- if (example && fPngOut) {
- if (!this->pngOut(example)) {
- return false;
+ if (!strcmp("text", memberName)) {
+ if (!iter->isString()) {
+ return this->reportError<bool>("expected string 3");
}
+ textString = iter->asString();
+ continue;
}
+ return this->reportError<bool>("unexpected key");
}
- if (!this->skipExact("\"\n")) {
- return false;
- }
- if (!this->skipExact(" }")) {
- return false;
- }
- if ('\n' == this->peek()) {
- break;
+ if (!example) {
+ return this->reportError<bool>("missing fiddleHash");
}
- if (!this->skipExact(",\n")) {
+ size_t strLen = textString.length();
+ if (strLen) {
+ if (fTextOut
+ && !this->textOut(example, textString.c_str(), textString.c_str() + strLen)) {
+ return false;
+ }
+ } else if (fPngOut && !this->pngOut(example)) {
return false;
}
+ status->fIter++;
}
return true;
}
diff --git a/tools/bookmaker/includeParser.cpp b/tools/bookmaker/includeParser.cpp
index fc378ddb45..d6594ea72c 100644
--- a/tools/bookmaker/includeParser.cpp
+++ b/tools/bookmaker/includeParser.cpp
@@ -2464,6 +2464,9 @@ bool IncludeParser::parseChar() {
if (!this->checkForWord()) {
return false;
}
+ if (!fParent->fTokens.size()) {
+ break;
+ }
{
const Definition& lastToken = fParent->fTokens.back();
if (lastToken.fType != Definition::Type::kWord) {
diff --git a/tools/bookmaker/parserCommon.cpp b/tools/bookmaker/parserCommon.cpp
index 33bf14918e..fb00b167a8 100644
--- a/tools/bookmaker/parserCommon.cpp
+++ b/tools/bookmaker/parserCommon.cpp
@@ -392,7 +392,7 @@ bool StatusIter::next(string* str) {
return true;
}
-bool StatusIter::parseFromFile(const char* path) {
+bool JsonCommon::parseFromFile(const char* path) {
sk_sp<SkData> json(SkData::MakeFromFileName(path));
if (!json) {
SkDebugf("file %s:\n", path);
@@ -400,7 +400,7 @@ bool StatusIter::parseFromFile(const char* path) {
}
Json::Reader reader;
const char* data = (const char*)json->data();
- if (!reader.parse(data, data+json->size(), fRoot)) {
+ if (!reader.parse(data, data + json->size(), fRoot)) {
SkDebugf("file %s:\n", path);
return this->reportError<bool>("file not parsable");
}
@@ -409,6 +409,3 @@ bool StatusIter::parseFromFile(const char* path) {
return true;
}
-void StatusIter::reset() {
- fStack.clear();
-}