From 89b1456b552dda6207d5ca432047965f7041cc48 Mon Sep 17 00:00:00 2001 From: Cary Clark Date: Mon, 19 Mar 2018 09:04:10 -0400 Subject: [PATCH] detect deprecated methods If a method in an include is marked deprecated, make sure that the documentation is marked deprecated. It's OK for the documentation to mark something deprecated that is not marked as such in the includes since the documentation may be ahead of the includes. Fix a couple of mistakes found around deprecated methods. Docs-Preview: https://skia.org/?cl=114184 TBR=caryclark@google.com Bug: skia:6898 Change-Id: I2bb4c293d7bf28e5d12f9ae01b7be49ce48b9ee4 Reviewed-on: https://skia-review.googlesource.com/114184 Commit-Queue: Cary Clark Reviewed-by: Cary Clark --- docs/SkBitmap_Reference.bmh | 14 +------- site/user/api/SkBitmap_Reference.md | 19 ----------- site/user/api/catalog.htm | 4 +-- tools/bookmaker/bookmaker.h | 7 ++-- tools/bookmaker/includeParser.cpp | 50 +++++++++++------------------ tools/bookmaker/includeWriter.cpp | 6 ++-- 6 files changed, 28 insertions(+), 72 deletions(-) diff --git a/docs/SkBitmap_Reference.bmh b/docs/SkBitmap_Reference.bmh index 0ffd16017a..598b9e904f 100644 --- a/docs/SkBitmap_Reference.bmh +++ b/docs/SkBitmap_Reference.bmh @@ -2416,19 +2416,7 @@ then r, g, and b are ignored. # ------------------------------------------------------------------------------ #Method void eraseRGB(U8CPU r, U8CPU g, U8CPU b) const -#In Draw -#Line # deprecated ## -Deprecated. Use eraseARGB or eraseColor. - -#Param r amount of red ## -#Param g amount of green ## -#Param b amount of blue ## - -#NoExample -## - -#SeeAlso eraseColor eraseARGB erase - +#Deprecated ## # ------------------------------------------------------------------------------ diff --git a/site/user/api/SkBitmap_Reference.md b/site/user/api/SkBitmap_Reference.md index f5498c917c..9038a34ba8 100644 --- a/site/user/api/SkBitmap_Reference.md +++ b/site/user/api/SkBitmap_Reference.md @@ -112,7 +112,6 @@ is useful to position one or more Bitmaps within a shared | erase | writes Color to rectangle of pixels | | eraseARGB | writes Color to pixels | | eraseColor | writes Color to pixels | -| eraseRGB | deprecated | | extractAlpha | creates Bitmap containing Alpha of pixels | | extractSubset | creates Bitmap, sharing pixels if possible | | getAddr | returns readable pixel address as void pointer | @@ -2571,7 +2570,6 @@ Marks that pixels in Pixel Ref have changed | erase | writes Color to rectangle of pixels | | eraseARGB | writes Color to pixels | | eraseColor | writes Color to pixels | -| eraseRGB | deprecated | ## eraseColor @@ -2645,23 +2643,6 @@ amount of Color RGB Blue, from no blue (0) t void eraseRGB(U8CPU r, U8CPU g, U8CPU b) const -Deprecated. Use eraseARGB or eraseColor. - -### Parameters - - - - - -
r -amount of red
g -amount of green
b -amount of blue
- -### See Also - -eraseColor eraseARGB erase - --- diff --git a/site/user/api/catalog.htm b/site/user/api/catalog.htm index 4584e136e0..6906dc95c9 100644 --- a/site/user/api/catalog.htm +++ b/site/user/api/catalog.htm @@ -3524,10 +3524,10 @@ "name": "Font_Metrics" }, "Paint_Image_Filter_Methods": { - "code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n paint.setStyle(SkPaint::kStroke_Style);\n paint.setStrokeWidth(2);\n SkRegion region;\n region.op( 10, 10, 50, 50, SkRegion::kUnion_Op);\n region.op( 10, 50, 90, 90, SkRegion::kUnion_Op);\n paint.setImageFilter(SkBlurImageFilter::Make(5.0f, 5.0f, nullptr));\n canvas->drawRegion(region, paint);\n paint.setImageFilter(nullptr);\n paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 5));\n canvas->translate(100, 100);\n canvas->drawRegion(region, paint);\n}\n", + "code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n paint.setStyle(SkPaint::kStroke_Style);\n paint.setStrokeWidth(2);\n SkRegion region;\n region.op( 10, 10, 50, 50, SkRegion::kUnion_Op);\n region.op( 10, 50, 90, 90, SkRegion::kUnion_Op);\n paint.setImageFilter(SkBlurImageFilter::Make(5.0f, 5.0f, nullptr));\n canvas->drawRegion(region, paint);\n paint.setImageFilter(nullptr);\n paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 5));\n canvas->translate(100, 100);\n canvas->drawRegion(region, paint);\n}\n", "width": 256, "height": 256, - "hash": "0b2eec148d6397d6231e1fa0b3d1496d", + "hash": "250e45c5935d54eac6aca775d1fe3475", "file": "SkPaint_Reference", "name": "Image_Filter_Methods" }, diff --git a/tools/bookmaker/bookmaker.h b/tools/bookmaker/bookmaker.h index b2654409d0..968644f8b1 100644 --- a/tools/bookmaker/bookmaker.h +++ b/tools/bookmaker/bookmaker.h @@ -1643,6 +1643,7 @@ public: fInBrace = nullptr; fIncludeWord = nullptr; fLastObject = nullptr; + fAttrDeprecated = nullptr; fPrev = '\0'; fInChar = false; fInCharCommentString = false; @@ -1815,6 +1816,9 @@ protected: MarkType fMarkType; }; + static const char gAttrDeprecated[]; + static const size_t kAttrDeprecatedLen; + DefinitionMap fMaps[Last_MarkType + 1]; unordered_map fIncludeMap; unordered_map fIClassMap; @@ -1829,6 +1833,7 @@ protected: Definition* fInBrace; Definition* fLastObject; Definition* fPriorEnum; + const Definition* fAttrDeprecated; int fPriorIndex; const char* fIncludeWord; char fPrev; @@ -1938,7 +1943,6 @@ public: fEnumDef = nullptr; fMethodDef = nullptr; fBmhStructDef = nullptr; - fAttrDeprecated = nullptr; fInStruct = false; fWroteMethod = false; fIndentNext = false; @@ -1961,7 +1965,6 @@ private: const Definition* fEnumDef; const Definition* fMethodDef; const Definition* fBmhStructDef; - const Definition* fAttrDeprecated; const char* fContinuation; // used to construct paren-qualified method name int fAnonymousEnumCount; int fEnumItemValueTab; diff --git a/tools/bookmaker/includeParser.cpp b/tools/bookmaker/includeParser.cpp index c69af7a05a..900617667c 100644 --- a/tools/bookmaker/includeParser.cpp +++ b/tools/bookmaker/includeParser.cpp @@ -9,6 +9,9 @@ #include "SkOSFile.h" #include "SkOSPath.h" +const char IncludeParser::gAttrDeprecated[] = "SK_ATTR_DEPRECATED"; +const size_t IncludeParser::kAttrDeprecatedLen = sizeof(gAttrDeprecated) - 1; + const IncludeKey kKeyWords[] = { { "", KeyWord::kNone, KeyProperty::kNone }, { "SK_API", KeyWord::kSK_API, KeyProperty::kModifier }, @@ -329,7 +332,8 @@ bool IncludeParser::crossCheck(BmhParser& bmhParser) { } } if (!def) { - if ("SK_ATTR_DEPRECATED" == token.fName) { + if (gAttrDeprecated == token.fName) { + fAttrDeprecated = &token; break; } if (0 == token.fName.find("SkDEBUGCODE")) { @@ -353,6 +357,9 @@ bool IncludeParser::crossCheck(BmhParser& bmhParser) { if (MarkType::kDefinedBy == def->fMarkType) { def->fParent->fVisited = true; } + if (token.fDeprecated && !def->fDeprecated) { + fFailed = !def->reportError("expect bmh to be marked deprecated"); + } } else { SkDebugf("method differs from bmh: %s\n", fullName.c_str()); fFailed = true; @@ -1749,7 +1756,8 @@ bool IncludeParser::parseObject(Definition* child, Definition* markupDef) { child->fStart, fLastObject->fLineCount); if (!checkDeprecated.eof()) { checkDeprecated.skipWhiteSpace(); - if (checkDeprecated.startsWith("SK_ATTR_DEPRECATED")) { + if (checkDeprecated.startsWith(gAttrDeprecated)) { + fAttrDeprecated = child; break; } } @@ -1759,7 +1767,8 @@ bool IncludeParser::parseObject(Definition* child, Definition* markupDef) { std::advance(tokenIter, child->fParentIndex); tokenIter = std::prev(tokenIter); TextParser previousToken(&*tokenIter); - if (previousToken.startsWith("SK_ATTR_DEPRECATED")) { + if (previousToken.startsWith(gAttrDeprecated)) { + fAttrDeprecated = &*tokenIter; break; } if (Bracket::kPound == child->fParent->fBracket && @@ -1774,6 +1783,11 @@ bool IncludeParser::parseObject(Definition* child, Definition* markupDef) { if (!this->parseMethod(child, markupDef)) { return child->reportError("failed to parse method"); } + if (fAttrDeprecated) { + Definition* lastMethod = &markupDef->fTokens.back(); + lastMethod->fDeprecated = true; + fAttrDeprecated = nullptr; + } break; case Bracket::kSlashSlash: case Bracket::kSlashStar: @@ -2047,35 +2061,7 @@ bool IncludeParser::parseChar() { ']' == test ? Bracket::kSquare : Bracket::kBrace) == this->topBracket()) { this->popBracket(); if (!fInFunction) { - bool deprecatedMacro = false; - if (')' == test) { - auto iter = fParent->fTokens.end(); - bool lookForWord = false; - while (fParent->fTokens.begin() != iter) { - --iter; - if (lookForWord) { - if (Definition::Type::kWord != iter->fType) { - break; - } - string word(iter->fContentStart, iter->length()); - if ("SK_ATTR_EXTERNALLY_DEPRECATED" == word) { - deprecatedMacro = true; - // remove macro paren (would confuse method parsing later) - fParent->fTokens.pop_back(); - fParent->fChildren.pop_back(); - } - break; - } - if (Definition::Type::kBracket != iter->fType) { - break; - } - if (Bracket::kParen != iter->fBracket) { - break; - } - lookForWord = true; - } - } - fInFunction = ')' == test && !deprecatedMacro; + fInFunction = ')' == test; } else { fInFunction = '}' != test; } diff --git a/tools/bookmaker/includeWriter.cpp b/tools/bookmaker/includeWriter.cpp index 2442138ea2..7af7202e8c 100644 --- a/tools/bookmaker/includeWriter.cpp +++ b/tools/bookmaker/includeWriter.cpp @@ -1533,10 +1533,8 @@ bool IncludeWriter::populate(Definition* def, ParentPair* prevPair, RootDefiniti memberStart = &child; staticOnly = false; } - const char attrDeprecated[] = "SK_ATTR_DEPRECATED"; - const size_t attrDeprecatedLen = sizeof(attrDeprecated) - 1; - if (attrDeprecatedLen == child.fContentEnd - child.fContentStart && - !strncmp(attrDeprecated, child.fStart, attrDeprecatedLen)) { + if (kAttrDeprecatedLen == (size_t) (child.fContentEnd - child.fContentStart) && + !strncmp(gAttrDeprecated, child.fStart, kAttrDeprecatedLen)) { fAttrDeprecated = &child; } continue;