-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-doc] Add HTMLMustacheGenerator.cpp #138060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang-tools-extra Author: Paul Kirth (ilovepi) ChangesSplit from #133161. This patch adds HTMLMustacheGenerator.cpp, and Co-authored-by: Peter Chou <[email protected]> Full diff: https://github.com/llvm/llvm-project/pull/138060.diff 5 Files Affected:
diff --git a/clang-tools-extra/clang-doc/CMakeLists.txt b/clang-tools-extra/clang-doc/CMakeLists.txt
index 915e14c3ee16d..79563c41435eb 100644
--- a/clang-tools-extra/clang-doc/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/CMakeLists.txt
@@ -16,6 +16,7 @@ add_clang_library(clangDoc STATIC
Representation.cpp
Serialize.cpp
YAMLGenerator.cpp
+ HTMLMustacheGenerator.cpp
DEPENDS
omp_gen
@@ -24,7 +25,7 @@ add_clang_library(clangDoc STATIC
clang_target_link_libraries(clangDoc
PRIVATE
- clangDocSupport
+ clangDocSupport
clangAnalysis
clangAST
clangASTMatchers
diff --git a/clang-tools-extra/clang-doc/Generators.cpp b/clang-tools-extra/clang-doc/Generators.cpp
index 4bb5366800f7f..a3c2773412cff 100644
--- a/clang-tools-extra/clang-doc/Generators.cpp
+++ b/clang-tools-extra/clang-doc/Generators.cpp
@@ -103,6 +103,7 @@ static int LLVM_ATTRIBUTE_UNUSED MDGeneratorAnchorDest =
MDGeneratorAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED HTMLGeneratorAnchorDest =
HTMLGeneratorAnchorSource;
-
+static int LLVM_ATTRIBUTE_UNUSED MHTMLGeneratorAnchorDest =
+ MHTMLGeneratorAnchorSource;
} // namespace doc
} // namespace clang
diff --git a/clang-tools-extra/clang-doc/Generators.h b/clang-tools-extra/clang-doc/Generators.h
index 2e71890389256..aee04b9d58d9d 100644
--- a/clang-tools-extra/clang-doc/Generators.h
+++ b/clang-tools-extra/clang-doc/Generators.h
@@ -57,6 +57,7 @@ std::string getTagType(TagTypeKind AS);
extern volatile int YAMLGeneratorAnchorSource;
extern volatile int MDGeneratorAnchorSource;
extern volatile int HTMLGeneratorAnchorSource;
+extern volatile int MHTMLGeneratorAnchorSource;
} // namespace doc
} // namespace clang
diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
new file mode 100644
index 0000000000000..65e8e34b581d2
--- /dev/null
+++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
@@ -0,0 +1,83 @@
+//===-- HTMLMustacheGenerator.cpp - HTML Mustache Generator -----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#include "Generators.h"
+#include "Representation.h"
+#include "support/File.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Mustache.h"
+
+using namespace llvm;
+using namespace llvm::json;
+using namespace llvm::mustache;
+
+namespace clang {
+namespace doc {
+
+class MustacheHTMLGenerator : public Generator {
+public:
+ static const char *Format;
+ Error generateDocs(StringRef RootDir,
+ StringMap<std::unique_ptr<doc::Info>> Infos,
+ const ClangDocContext &CDCtx) override;
+ Error createResources(ClangDocContext &CDCtx) override;
+ Error generateDocForInfo(Info *I, raw_ostream &OS,
+ const ClangDocContext &CDCtx) override;
+};
+
+class MustacheTemplateFile : public Template {
+public:
+ static ErrorOr<std::unique_ptr<MustacheTemplateFile>>
+ createMustacheFile(StringRef FileName) {
+ ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrError =
+ MemoryBuffer::getFile(FileName);
+ if (auto EC = BufferOrError.getError())
+ return EC;
+
+ std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrError.get());
+ StringRef FileContent = Buffer->getBuffer();
+ return std::make_unique<MustacheTemplateFile>(FileContent);
+ }
+
+ Error registerPartialFile(StringRef Name, StringRef FileName) {
+ ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrError =
+ MemoryBuffer::getFile(FileName);
+ if (auto EC = BufferOrError.getError())
+ return createFileError("cannot open file", EC);
+ std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrError.get());
+ StringRef FileContent = Buffer->getBuffer();
+ registerPartial(Name.str(), FileContent.str());
+ return Error::success();
+ }
+
+ MustacheTemplateFile(StringRef TemplateStr) : Template(TemplateStr) {}
+};
+Error MustacheHTMLGenerator::generateDocs(
+ StringRef RootDir, StringMap<std::unique_ptr<doc::Info>> Infos,
+ const clang::doc::ClangDocContext &CDCtx) {
+ return Error::success();
+}
+Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
+ const ClangDocContext &CDCtx) {
+ return Error::success();
+}
+Error MustacheHTMLGenerator::createResources(ClangDocContext &CDCtx) {
+ Error Err = Error::success();
+ return Error::success();
+}
+
+const char *MustacheHTMLGenerator::Format = "mhtml";
+
+static GeneratorRegistry::Add<MustacheHTMLGenerator>
+ MHTML(MustacheHTMLGenerator::Format, "Generator for mustache HTML output.");
+
+// This anchor is used to force the linker to link in the generated object
+// file and thus register the generator.
+volatile int MHTMLGeneratorAnchorSource = 0;
+
+} // namespace doc
+} // namespace clang
diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h
index 1d5c4dcaeaf37..71377d10b2f40 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -535,6 +535,8 @@ struct ClangDocContext {
// JavaScript files that will be imported in all HTML files.
std::vector<std::string> JsScripts;
StringRef Base;
+ // Mustache Template files
+ llvm::StringMap<std::string> MustacheTemplates;
Index Idx;
};
|
Testing in this patch will have to be limited to unit tests, if we can bootstrap anything at all. |
397d5dc
to
5773942
Compare
1f869c4
to
162890b
Compare
5773942
to
6098ca3
Compare
ca97d97
to
fa703d6
Compare
77d9ece
to
c4fd639
Compare
1ea7bcc
to
abfa665
Compare
c4fd639
to
d5b198f
Compare
d5b198f
to
a4ebe3e
Compare
a4ebe3e
to
027a37d
Compare
027a37d
to
ba7721e
Compare
Split from #133161. This patch adds HTMLMustacheGenerator.cpp, and the most basic class definition for the generator. Future patches will add functionality. Co-authored-by: Peter Chou <[email protected]>
ba7721e
to
88e7057
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/202/builds/1199 Here is the relevant piece of the build log for the reference
|
Split from #133161. This patch adds HTMLMustacheGenerator.cpp, and
the most basic class defintion for the generator. Future patches will
add functionality.
Co-authored-by: Peter Chou [email protected]