1 /*
2 * Copyright 2017 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 #ifndef bookmaker_DEFINED
9 #define bookmaker_DEFINED
10
11 #include <algorithm>
12 #include <cmath>
13 #include <cctype>
14 #include <cstring>
15 #include <forward_list>
16 #include <list>
17 #include <sstream>
18 #include <string>
19 #include <unordered_map>
20 #include <vector>
21
22 #include "SkTypes.h"
23
24 using std::forward_list;
25 using std::list;
26 using std::string;
27 using std::unordered_map;
28 using std::vector;
29
30 class Definition;
31
32 class NonAssignable {
33 public:
34 NonAssignable(NonAssignable const&) = delete;
35 NonAssignable& operator=(NonAssignable const&) = delete;
NonAssignable()36 NonAssignable() {}
37 };
38
39 #define FPRINTF(...) \
40 if (fDebugOut) { \
41 SkDebugf(__VA_ARGS__); \
42 } \
43 fprintf(fOut, __VA_ARGS__)
44
45 // std::to_string isn't implemented on android
46 template <typename T>
to_string(T value)47 string to_string(T value)
48 {
49 std::ostringstream os ;
50 os << value ;
51 return os.str() ;
52 }
53
54 enum class KeyWord {
55 kNone,
56 kSK_API,
57 kSK_BEGIN_REQUIRE_DENSE,
58 kAlignAs,
59 kBool,
60 kChar,
61 kClass,
62 kConst,
63 kConstExpr,
64 kDefine,
65 kDouble,
66 kElif,
67 kElse,
68 kEndif,
69 kEnum,
70 kError,
71 kFloat,
72 kFriend,
73 kIf,
74 kIfdef,
75 kIfndef,
76 kInclude,
77 kInline,
78 kInt,
79 kOperator,
80 kPrivate,
81 kProtected,
82 kPublic,
83 kSigned,
84 kSize_t,
85 kStatic,
86 kStruct,
87 kTemplate,
88 kTypedef,
89 kTypename,
90 kUint16_t,
91 kUint32_t,
92 kUint64_t,
93 kUint8_t,
94 kUintPtr_t,
95 kUnion,
96 kUnsigned,
97 kUsing,
98 kVoid,
99 };
100
101 enum class MarkType {
102 kNone,
103 kAnchor,
104 kAlias,
105 kBug,
106 kClass,
107 kCode,
108 kColumn,
109 kComment,
110 kConst,
111 kDefine,
112 kDescription,
113 kDetails, // used by #Const to specify #Subtopic details with examples and so on
114 kDuration,
115 kEnum,
116 kEnumClass,
117 kExample,
118 kExternal,
119 kFile,
120 kFilter,
121 kFormula,
122 kFunction,
123 kHeight,
124 kIllustration,
125 kImage,
126 kIn,
127 kLegend,
128 kLine,
129 kLink, // used internally by #Anchor
130 kList,
131 kLiteral, // don't lookup hyperlinks, do substitution, etc
132 kMarkChar,
133 kMember,
134 kMethod,
135 kNoExample,
136 kNoJustify, // don't contribute this #Line to tabular comment measure, even if it fits
137 kOutdent,
138 kParam,
139 kPhraseDef,
140 kPhraseParam,
141 kPhraseRef,
142 kPlatform,
143 kPopulate,
144 kReturn,
145 kRow,
146 kSeeAlso,
147 kSet,
148 kStdOut,
149 kStruct,
150 kSubstitute,
151 kSubtopic,
152 kTable,
153 kTemplate,
154 kText,
155 kToDo,
156 kTopic,
157 kTypedef,
158 kUnion,
159 kUsing,
160 kVolatile,
161 kWidth,
162 };
163
164 enum {
165 Last_MarkType = (int) MarkType::kWidth,
166 };
167
168 enum class Bracket {
169 kNone,
170 kParen,
171 kSquare,
172 kBrace,
173 kAngle,
174 kString,
175 kChar,
176 kSlashStar,
177 kSlashSlash,
178 kPound,
179 kColon,
180 kDebugCode, // parens get special treatment so SkDEBUGCODE( isn't treated as method
181 };
182
183 enum class Punctuation { // catch-all for misc symbols tracked in C
184 kNone,
185 kAsterisk, // for pointer-to
186 kSemicolon, // e.g., to delinate xxx() const ; const int* yyy()
187 kLeftBrace,
188 kColon, // for foo() : bar(1), baz(2) {}
189 };
190
191 enum class KeyProperty {
192 kNone,
193 kClassSection,
194 kFunction,
195 kModifier,
196 kNumber,
197 kObject,
198 kPreprocessor,
199 };
200
201 struct IncludeKey {
202 const char* fName;
203 KeyWord fKeyWord;
204 KeyProperty fProperty;
205 };
206
207 extern const IncludeKey kKeyWords[];
208
209 struct NameMap {
210 void copyToParent(NameMap* parent) const;
211 void setParams(Definition* bmhDef, Definition* iMethod);
212
213 string fName;
214 NameMap* fParent = nullptr;
215 unordered_map<string, string> fLinkMap; // from SkRect to #Rect
216 // ref map includes "xxx", "xxx ", "xxx yyy", "xxx zzz", etc.
217 unordered_map<string, Definition*> fRefMap; // e.g., from #Substitute entry to #Topic entry
218 };
219
220 enum class Resolvable {
221 kNo, // neither resolved nor output
222 kYes, // resolved, output
223 kOut, // mostly resolved, output (FIXME: is this really different from kYes?)
224 kCode, // resolve methods as they are used, not as they are prototyped
225 kFormula, // kCode, plus make most spaces non-breaking
226 kLiteral, // output untouched
227 kClone, // resolved, output, with references to clones as well
228 kSimple, // resolve simple words (used to resolve method declarations)
229 kInclude, // like simple, plus reverse resolve SkXXX to XXX
230 };
231
232 #endif
233