23#include "llvm/ADT/RewriteBuffer.h"
24#include "llvm/Support/raw_ostream.h"
26using llvm::RewriteBuffer;
35 std::unique_ptr<raw_ostream> Out;
40 HTMLPrinter(std::unique_ptr<raw_ostream> OS,
Preprocessor &pp,
41 bool _SyntaxHighlight,
bool _HighlightMacros)
50std::unique_ptr<ASTConsumer>
52 bool SyntaxHighlight,
bool HighlightMacros) {
53 return std::make_unique<HTMLPrinter>(std::move(OS), PP, SyntaxHighlight,
57void HTMLPrinter::Initialize(
ASTContext &context) {
61void HTMLPrinter::HandleTranslationUnit(
ASTContext &Ctx) {
62 if (PP.getDiagnostics().hasErrorOccurred())
66 FileID FID = R.getSourceMgr().getMainFileID();
75 Name = R.getSourceMgr().getBufferOrFake(FID).getBufferIdentifier();
89 const RewriteBuffer &RewriteBuf = R.getEditBuffer(FID);
90 std::unique_ptr<char[]> Buffer(
new char[RewriteBuf.size()]);
91 std::copy(RewriteBuf.begin(), RewriteBuf.end(), Buffer.get());
92 Out->write(Buffer.get(), RewriteBuf.size());
Defines the clang::ASTContext interface.
Defines the Diagnostic-related interfaces.
Defines the clang::FileManager interface and associated types.
Defines the clang::Preprocessor interface.
Defines the SourceManager interface.
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
virtual void HandleTranslationUnit(ASTContext &Ctx)
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
virtual void Initialize(ASTContext &Context)
Initialize - This is called to initialize the consumer, providing the ASTContext.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
const LangOptions & getLangOpts() const
StringRef getName() const
The name of this FileEntry.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Rewriter - This is the main interface to the rewrite buffers.
void AddHeaderFooterInternalBuiltinCSS(Rewriter &R, FileID FID, StringRef title)
void AddLineNumbers(Rewriter &R, FileID FID)
void SyntaxHighlight(Rewriter &R, FileID FID, const Preprocessor &PP, RelexRewriteCacheRef Cache=nullptr)
SyntaxHighlight - Relex the specified FileID and annotate the HTML with information about keywords,...
void HighlightMacros(Rewriter &R, FileID FID, const Preprocessor &PP, RelexRewriteCacheRef Cache=nullptr)
HighlightMacros - This uses the macro table state from the end of the file, to reexpand macros and in...
void EscapeText(Rewriter &R, FileID FID, bool EscapeSpaces=false, bool ReplaceTabs=false)
EscapeText - HTMLize a specified file so that special characters are are translated so that they are ...
The JSON file list parser is used to communicate input to InstallAPI.
std::unique_ptr< ASTConsumer > CreateHTMLPrinter(std::unique_ptr< raw_ostream > OS, Preprocessor &PP, bool SyntaxHighlight=true, bool HighlightMacros=true)
CreateHTMLPrinter - Create an AST consumer which rewrites source code to HTML with syntax highlightin...