18
18
// ===----------------------------------------------------------------------===//
19
19
20
20
#include " BitcodeReader.h"
21
- #include " BitcodeWriter.h"
22
21
#include " ClangDoc.h"
23
22
#include " Generators.h"
24
23
#include " Representation.h"
25
- #include " clang/AST/AST.h"
26
- #include " clang/AST/Decl.h"
27
- #include " clang/ASTMatchers/ASTMatchFinder.h"
28
24
#include " clang/ASTMatchers/ASTMatchersInternal.h"
29
- #include " clang/Driver/Options.h"
30
- #include " clang/Frontend/FrontendActions.h"
31
25
#include " clang/Tooling/AllTUsExecution.h"
32
26
#include " clang/Tooling/CommonOptionsParser.h"
33
27
#include " clang/Tooling/Execution.h"
34
- #include " clang/Tooling/Tooling.h"
35
28
#include " llvm/ADT/APFloat.h"
36
29
#include " llvm/Support/CommandLine.h"
37
30
#include " llvm/Support/Error.h"
@@ -110,11 +103,7 @@ static llvm::cl::opt<std::string> RepositoryCodeLinePrefix(
110
103
llvm::cl::desc (" Prefix of line code for repository." ),
111
104
llvm::cl::cat(ClangDocCategory));
112
105
113
- enum OutputFormatTy {
114
- md,
115
- yaml,
116
- html,
117
- };
106
+ enum OutputFormatTy { md, yaml, html, mhtml };
118
107
119
108
static llvm::cl::opt<OutputFormatTy>
120
109
FormatEnum (" format" , llvm::cl::desc(" Format for outputted docs." ),
@@ -123,7 +112,9 @@ static llvm::cl::opt<OutputFormatTy>
123
112
clEnumValN(OutputFormatTy::md, " md" ,
124
113
" Documentation in MD format." ),
125
114
clEnumValN(OutputFormatTy::html, " html" ,
126
- " Documentation in HTML format." )),
115
+ " Documentation in HTML format." ),
116
+ clEnumValN(OutputFormatTy::mhtml, " mhtml" ,
117
+ " Documentation in mHTML format" )),
127
118
llvm::cl::init(OutputFormatTy::yaml),
128
119
llvm::cl::cat(ClangDocCategory));
129
120
@@ -135,6 +126,8 @@ static std::string getFormatString() {
135
126
return " md" ;
136
127
case OutputFormatTy::html:
137
128
return " html" ;
129
+ case OutputFormatTy::mhtml:
130
+ return " mhtml" ;
138
131
}
139
132
llvm_unreachable (" Unknown OutputFormatTy" );
140
133
}
@@ -168,6 +161,14 @@ static llvm::Error getAssetFiles(clang::doc::ClangDocContext &CDCtx) {
168
161
return llvm::Error::success ();
169
162
}
170
163
164
+ static llvm::SmallString<128 > appendPathNative (StringRef Path,
165
+ StringRef Asset) {
166
+ llvm::SmallString<128 > Default;
167
+ llvm::sys::path::native (Path, Default);
168
+ llvm::sys::path::append (Default, Asset);
169
+ return Default;
170
+ }
171
+
171
172
static llvm::Error getDefaultAssetFiles (const char *Argv0,
172
173
clang::doc::ClangDocContext &CDCtx) {
173
174
void *MainAddr = (void *)(intptr_t )getExecutablePath;
@@ -178,13 +179,9 @@ static llvm::Error getDefaultAssetFiles(const char *Argv0,
178
179
llvm::SmallString<128 > AssetsPath;
179
180
AssetsPath = llvm::sys::path::parent_path (NativeClangDocPath);
180
181
llvm::sys::path::append (AssetsPath, " .." , " share" , " clang-doc" );
181
- llvm::SmallString<128 > DefaultStylesheet;
182
- llvm::sys::path::native (AssetsPath, DefaultStylesheet);
183
- llvm::sys::path::append (DefaultStylesheet,
184
- " clang-doc-default-stylesheet.css" );
185
- llvm::SmallString<128 > IndexJS;
186
- llvm::sys::path::native (AssetsPath, IndexJS);
187
- llvm::sys::path::append (IndexJS, " index.js" );
182
+ llvm::SmallString<128 > DefaultStylesheet =
183
+ appendPathNative (AssetsPath, " clang-doc-default-stylesheet.css" );
184
+ llvm::SmallString<128 > IndexJS = appendPathNative (AssetsPath, " index.js" );
188
185
189
186
if (!llvm::sys::fs::is_regular_file (IndexJS))
190
187
return llvm::createStringError (llvm::inconvertibleErrorCode (),
@@ -215,6 +212,54 @@ static llvm::Error getHtmlAssetFiles(const char *Argv0,
215
212
return getDefaultAssetFiles (Argv0, CDCtx);
216
213
}
217
214
215
+ static llvm::Error getMustacheHtmlFiles (const char *Argv0,
216
+ clang::doc::ClangDocContext &CDCtx) {
217
+ if (!UserAssetPath.empty () &&
218
+ !llvm::sys::fs::is_directory (std::string (UserAssetPath)))
219
+ llvm::outs () << " Asset path supply is not a directory: " << UserAssetPath
220
+ << " falling back to default\n " ;
221
+ if (llvm::sys::fs::is_directory (std::string (UserAssetPath)))
222
+ return getAssetFiles (CDCtx);
223
+
224
+ void *MainAddr = (void *)(intptr_t )getExecutablePath;
225
+ std::string ClangDocPath = getExecutablePath (Argv0, MainAddr);
226
+ llvm::SmallString<128 > NativeClangDocPath;
227
+ llvm::sys::path::native (ClangDocPath, NativeClangDocPath);
228
+
229
+ llvm::SmallString<128 > AssetsPath;
230
+ AssetsPath = llvm::sys::path::parent_path (NativeClangDocPath);
231
+ llvm::sys::path::append (AssetsPath, " .." , " share" , " clang-doc" );
232
+
233
+ llvm::SmallString<128 > DefaultStylesheet =
234
+ appendPathNative (AssetsPath, " clang-doc-mustache.css" );
235
+ llvm::SmallString<128 > NamespaceTemplate =
236
+ appendPathNative (AssetsPath, " namespace-template.mustache" );
237
+ llvm::SmallString<128 > ClassTemplate =
238
+ appendPathNative (AssetsPath, " class-template.mustache" );
239
+ llvm::SmallString<128 > EnumTemplate =
240
+ appendPathNative (AssetsPath, " enum-template.mustache" );
241
+ llvm::SmallString<128 > FunctionTemplate =
242
+ appendPathNative (AssetsPath, " function-template.mustache" );
243
+ llvm::SmallString<128 > CommentTemplate =
244
+ appendPathNative (AssetsPath, " comments-template.mustache" );
245
+ llvm::SmallString<128 > IndexJS =
246
+ appendPathNative (AssetsPath, " mustache-index.js" );
247
+
248
+ CDCtx.JsScripts .insert (CDCtx.JsScripts .begin (), IndexJS.c_str ());
249
+ CDCtx.UserStylesheets .insert (CDCtx.UserStylesheets .begin (),
250
+ std::string (DefaultStylesheet));
251
+ CDCtx.MustacheTemplates .insert (
252
+ {" namespace-template" , NamespaceTemplate.c_str ()});
253
+ CDCtx.MustacheTemplates .insert ({" class-template" , ClassTemplate.c_str ()});
254
+ CDCtx.MustacheTemplates .insert ({" enum-template" , EnumTemplate.c_str ()});
255
+ CDCtx.MustacheTemplates .insert (
256
+ {" function-template" , FunctionTemplate.c_str ()});
257
+ CDCtx.MustacheTemplates .insert (
258
+ {" comments-template" , CommentTemplate.c_str ()});
259
+
260
+ return llvm::Error::success ();
261
+ }
262
+
218
263
// / Make the output of clang-doc deterministic by sorting the children of
219
264
// / namespaces and records.
220
265
static void
@@ -290,6 +335,13 @@ Example usage for a project using a compile commands database:
290
335
}
291
336
}
292
337
338
+ if (Format == " mhtml" ) {
339
+ if (auto Err = getMustacheHtmlFiles (argv[0 ], CDCtx)) {
340
+ llvm::errs () << toString (std::move (Err)) << " \n " ;
341
+ return 1 ;
342
+ }
343
+ }
344
+
293
345
// Mapping phase
294
346
llvm::outs () << " Mapping decls...\n " ;
295
347
auto Err =
0 commit comments