24 #include "llvm/Support/raw_ostream.h" 25 using namespace clang;
34 std::unique_ptr<raw_ostream> Out;
39 HTMLPrinter(std::unique_ptr<raw_ostream> OS,
Preprocessor &pp,
40 bool _SyntaxHighlight,
bool _HighlightMacros)
41 : Out(
std::move(OS)), PP(pp), SyntaxHighlight(_SyntaxHighlight),
42 HighlightMacros(_HighlightMacros) {}
45 void HandleTranslationUnit(
ASTContext &Ctx)
override;
49 std::unique_ptr<ASTConsumer>
52 return llvm::make_unique<HTMLPrinter>(std::move(OS), PP,
SyntaxHighlight,
56 void HTMLPrinter::Initialize(
ASTContext &context) {
60 void HTMLPrinter::HandleTranslationUnit(
ASTContext &Ctx) {
61 if (PP.getDiagnostics().hasErrorOccurred())
65 FileID FID = R.getSourceMgr().getMainFileID();
66 const FileEntry* Entry = R.getSourceMgr().getFileEntryForID(FID);
74 Name = R.getSourceMgr().getBuffer(FID)->getBufferIdentifier();
89 std::unique_ptr<char[]> Buffer(
new char[RewriteBuf.
size()]);
90 std::copy(RewriteBuf.
begin(), RewriteBuf.
end(), Buffer.get());
91 Out->
write(Buffer.get(), RewriteBuf.
size());
Defines the clang::ASTContext interface.
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
Defines the clang::FileManager interface and associated types.
Defines the SourceManager interface.
RewriteBuffer - As code is rewritten, SourceBuffer's from the original input with modifications get a...
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...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
void HighlightMacros(Rewriter &R, FileID FID, const Preprocessor &PP)
HighlightMacros - This uses the macro table state from the end of the file, to reexpand macros and in...
void AddLineNumbers(Rewriter &R, FileID FID)
Defines the Diagnostic-related interfaces.
void SyntaxHighlight(Rewriter &R, FileID FID, const Preprocessor &PP)
SyntaxHighlight - Relex the specified FileID and annotate the HTML with information about keywords...
Defines the clang::Preprocessor interface.
raw_ostream & write(raw_ostream &Stream) const
Write to Stream the result of applying all changes to the original buffer.
StringRef getName() const
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 ...
Cached information about one file (either on disk or in the virtual file system). ...
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Dataflow Directional Tag Classes.
void AddHeaderFooterInternalBuiltinCSS(Rewriter &R, FileID FID, StringRef title)
SourceManager & getSourceManager()
Rewriter - This is the main interface to the rewrite buffers.
const LangOptions & getLangOpts() const
Engages in a tight little dance with the lexer to efficiently preprocess tokens.