diff options
author | Cary Clark <caryclark@skia.org> | 2018-03-19 09:04:10 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-19 13:30:16 +0000 |
commit | 89b1456b552dda6207d5ca432047965f7041cc48 (patch) | |
tree | d75122f8b46494c43965f57a28f12543c005d683 /tools | |
parent | a7d661a6813924d73319a1d7f0cf0a5cb5343c50 (diff) |
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 <caryclark@skia.org>
Reviewed-by: Cary Clark <caryclark@skia.org>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/bookmaker/bookmaker.h | 7 | ||||
-rw-r--r-- | tools/bookmaker/includeParser.cpp | 50 | ||||
-rw-r--r-- | tools/bookmaker/includeWriter.cpp | 6 |
3 files changed, 25 insertions, 38 deletions
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<string, Definition> fIncludeMap; unordered_map<string, IClassDefinition> 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<bool>("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<bool>("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; |