blob: 3392945a9febc351d0e8c459e6a51c07680fc0b9 [file] [log] [blame]
Cary Clarkac47b882018-01-11 10:35:44 -05001/*
2 * Copyright 2018 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "bookmaker.h"
9
Cary Clark4855f782018-02-06 09:41:53 -050010#ifdef SK_BUILD_FOR_WIN
11#include <windows.h>
12#endif
Cary Clarkac47b882018-01-11 10:35:44 -050013
14// Check that mutiple like-named methods are under one Subtopic
15
Cary Clarkac47b882018-01-11 10:35:44 -050016// Check that SeeAlso reference each other
17
18// Would be nice to check if other classes have 'create' methods that are included
19// SkSurface::makeImageSnapShot should be referenced under SkImage 'creators'
20
21class SelfChecker {
22public:
23 SelfChecker(const BmhParser& bmh)
24 : fBmhParser(bmh)
25 {}
26
27 bool check() {
28 for (const auto& topic : fBmhParser.fTopicMap) {
29 Definition* topicDef = topic.second;
30 if (topicDef->fParent) {
31 continue;
32 }
33 if (!topicDef->isRoot()) {
34 return fBmhParser.reportError<bool>("expected root topic");
35 }
36 fRoot = topicDef->asRoot();
Cary Clarkac47b882018-01-11 10:35:44 -050037 if (!this->checkSeeAlso()) {
38 return false;
39 }
Cary Clark4855f782018-02-06 09:41:53 -050040 // report functions that are not covered by related hierarchy
Cary Clarkab2621d2018-01-30 10:08:57 -050041 if (!this->checkRelatedFunctions()) {
42 return false;
43 }
Cary Clarkac47b882018-01-11 10:35:44 -050044 }
45 return true;
46 }
47
48protected:
Cary Clarkac47b882018-01-11 10:35:44 -050049
Cary Clarkab2621d2018-01-30 10:08:57 -050050 bool checkRelatedFunctions() {
Cary Clarkab2621d2018-01-30 10:08:57 -050051 const Definition* cs = this->classOrStruct();
52 vector<string> methodNames;
53 if (cs) {
54 string prefix = cs->fName + "::";
55 for (auto& csChild : cs->fChildren) {
56 if (MarkType::kMethod != csChild->fMarkType) {
57 // only check methods for now
58 continue;
59 }
60 if (Definition::MethodType::kConstructor == csChild->fMethodType) {
61 continue;
62 }
63 if (Definition::MethodType::kDestructor == csChild->fMethodType) {
64 continue;
65 }
66 if (Definition::MethodType::kOperator == csChild->fMethodType) {
67 continue;
68 }
69 if (csChild->fClone) {
70 // FIXME: check to see if all cloned methods are in table
71 // since format of clones is in flux, defer this check for now
72 continue;
73 }
Cary Clark4855f782018-02-06 09:41:53 -050074 bool containsMarkTypeIn = csChild->fDeprecated; // no markup for deprecated
75 for (auto child : csChild->fChildren) {
76 if (MarkType::kIn == child->fMarkType) {
77 containsMarkTypeIn = true;
78 break;
79 }
80 }
81 if (!containsMarkTypeIn) {
82#ifdef SK_BUILD_FOR_WIN
83 /* SkDebugf works in both visual studio and git shell, but
84 in git shell output is not piped to grep.
85 printf does not generate output in visual studio, but
86 does in git shell and can be piped.
87 */
88 if (IsDebuggerPresent()) {
89 SkDebugf("No #In: %s\n", csChild->fName.c_str());
90 } else
91#endif
92 printf("No #In: %s\n", csChild->fName.c_str());
93 }
Cary Clarkab2621d2018-01-30 10:08:57 -050094 }
95 }
Cary Clarkab2621d2018-01-30 10:08:57 -050096 return true;
97 }
98
Cary Clarkac47b882018-01-11 10:35:44 -050099 bool checkSeeAlso() {
100 return true;
101 }
102
Cary Clarkab2621d2018-01-30 10:08:57 -0500103 const Definition* classOrStruct() {
104 for (auto& rootChild : fRoot->fChildren) {
Cary Clark08895c42018-02-01 09:37:32 -0500105 if (rootChild->isStructOrClass()) {
Cary Clarkab2621d2018-01-30 10:08:57 -0500106 return rootChild;
107 }
108 }
109 return nullptr;
110 }
111
Cary Clark2dc84ad2018-01-26 12:56:22 -0500112 enum class Optional {
113 kNo,
114 kYes,
115 };
116
Cary Clarkac47b882018-01-11 10:35:44 -0500117private:
118 const BmhParser& fBmhParser;
119 RootDefinition* fRoot;
120};
121
122bool SelfCheck(const BmhParser& bmh) {
123 SelfChecker checker(bmh);
124 return checker.check();
125}