blob: 30b48d8e5594de5fcc04b48180c57de19b0ba6a4 [file] [log] [blame]
Cary Clark2da9fb82018-11-01 09:29:36 -04001/*
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#ifndef mdOut_DEFINED
9#define mdOut_DEFINED
10
11#include "parserCommon.h"
12
13class IncludeParser;
14
15class MdOut : public ParserCommon {
16public:
17 struct SubtopicDescriptions {
18 string fSingular;
19 string fPlural;
20 string fOneLiner;
21 string fDetails;
22 };
23
24 MdOut(BmhParser& bmh, IncludeParser& inc) : ParserCommon()
25 , fBmhParser(bmh)
26 , fIncludeParser(inc) {
27 this->reset();
28 this->addPopulators();
29 fBmhParser.setUpGlobalSubstitutes();
30 }
31
32 bool buildReferences(const char* docDir, const char* mdOutDirOrFile);
33 bool buildStatus(const char* docDir, const char* mdOutDir);
34 void checkAnchors();
35
36private:
37 enum class TableState {
38 kNone,
39 kRow,
40 kColumn,
41 };
42
43 struct AnchorDef {
44 string fDef;
45 MarkType fMarkType;
46 };
47
48 void addCodeBlock(const Definition* def, string& str) const;
49 void addPopulators();
50 string addIncludeReferences(const char* refStart, const char* refEnd);
51 string addReferences(const char* start, const char* end, Resolvable );
52 string anchorDef(string def, string name);
53 string anchorLocalRef(string ref, string name);
54 string anchorRef(string def, string name);
55 bool buildRefFromFile(const char* fileName, const char* outDir);
56 bool checkParamReturnBody(const Definition* def);
57 Definition* checkParentsForMatch(Definition* test, string ref) const;
58 void childrenOut(Definition* def, const char* contentStart);
59 Definition* csParent();
60 bool findLink(string ref, string* link);
61 Definition* findParamType();
62 string getMemberTypeName(const Definition* def, string* memberType);
63 static bool HasDetails(const Definition* def);
64 bool hasWordSpace(string ) const;
65 void htmlOut(string );
66 Definition* isDefined(const TextParser& , string ref, Resolvable );
67 Definition* isDefinedByParent(RootDefinition* root, string ref);
68 string linkName(const Definition* ) const;
69 string linkRef(string leadingSpaces, Definition*, string ref, Resolvable );
70 void markTypeOut(Definition* , const Definition** prior);
71 void mdHeaderOut(int depth) { mdHeaderOutLF(depth, 2); }
72 void mdHeaderOutLF(int depth, int lf);
73 void parameterHeaderOut(TextParser& paramParser, const Definition** prior, Definition* def);
74 void parameterTrailerOut();
75 bool parseFromFile(const char* path) override { return true; }
76 bool phraseContinues(string phrase, string* priorWord, string* priorLink) const;
77 void populateOne(Definition* def,
78 unordered_map<string, RootDefinition::SubtopicContents>& populator);
79 void populateTables(const Definition* def, RootDefinition* );
80
81 SubtopicDescriptions& populator(string key) {
82 auto entry = fPopulators.find(key);
83 // FIXME: this should have been detected earlier
84 SkASSERT(fPopulators.end() != entry);
85 return entry->second;
86 }
87
88 void reset() override {
89 INHERITED::resetCommon();
90 fEnumClass = nullptr;
91 fMethod = nullptr;
92 fRoot = nullptr;
93 fSubtopic = nullptr;
94 fLastParam = nullptr;
95 fTableState = TableState::kNone;
96 fAddRefFailed = false;
97 fHasFiddle = false;
98 fInDescription = false;
99 fInList = false;
100 fResolveAndIndent = false;
101 fLiteralAndIndent = false;
102 fLastDef = nullptr;
103 fParamEnd = nullptr;
104 fInProgress = false;
105 }
106
107 Resolvable resolvable(const Definition* definition) const {
108 MarkType markType = definition->fMarkType;
109 if (MarkType::kCode == markType) {
110 for (auto child : definition->fChildren) {
111 if (MarkType::kLiteral == child->fMarkType) {
112 return Resolvable::kLiteral;
113 }
114 }
115 }
116 if ((MarkType::kExample == markType
117 || MarkType::kFunction == markType) && fHasFiddle) {
118 return Resolvable::kNo;
119 }
120 return BmhParser::kMarkProps[(int) markType].fResolve;
121 }
122
123 void resolveOut(const char* start, const char* end, Resolvable );
124 void returnHeaderOut(const Definition** prior, Definition* def);
125 void rowOut(string col1, const Definition* col2);
126 void rowOut(const char * name, string description, bool literalName);
127
128 void subtopicOut(string name);
129 void subtopicsOut(Definition* def);
130 void subtopicOut(string key, const vector<Definition*>& data, const Definition* csParent,
131 const Definition* topicParent, bool showClones);
132 bool subtopicRowOut(string keyName, const Definition* entry);
133 void summaryOut(const Definition* def, MarkType , string name);
134 string tableDataCodeDef(const Definition* def);
135 string tableDataCodeDef(string def, string name);
136 string tableDataCodeLocalRef(string name);
137 string tableDataCodeLocalRef(string ref, string name);
138 string tableDataCodeRef(const Definition* ref);
139 string tableDataCodeRef(string ref, string name);
140 void writeSubtopicTableHeader(string key);
141
142 vector<const Definition*> fClassStack;
143 unordered_map<string, vector<AnchorDef> > fAllAnchorDefs;
144 unordered_map<string, vector<string> > fAllAnchorRefs;
145 NameMap* fNames;
146 BmhParser& fBmhParser;
147 IncludeParser& fIncludeParser;
148 const Definition* fEnumClass;
149 const Definition* fLastDef;
150 Definition* fMethod;
151 RootDefinition* fRoot; // used in generating populated tables; always struct or class
152 RootDefinition* fSubtopic; // used in resolving symbols
153 const Definition* fLastParam;
154 TableState fTableState;
155 unordered_map<string, SubtopicDescriptions> fPopulators;
156 unordered_map<string, string> fPhraseParams;
157 const char* fParamEnd;
158 bool fAddRefFailed;
159 bool fHasFiddle;
160 bool fInDescription; // FIXME: for now, ignore unfound camelCase in description since it may
161 // be defined in example which at present cannot be linked to
162 bool fInList;
163 bool fLiteralAndIndent;
164 bool fResolveAndIndent;
165 bool fOddRow;
166 bool fHasDetails;
167 bool fInProgress;
168 typedef ParserCommon INHERITED;
169};
170
171#endif