diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-03-18 22:21:07 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-03-18 22:21:07 +0000 |
commit | b0c409a235c06bec6374e009d147e760a9dcefa1 (patch) | |
tree | 9674287833af575bdf57446cae8942c3332e54a8 /clang | |
parent | 1b580f98aacb3ad89d6e7e5431c00c1fa7577b2a (diff) | |
download | bcm5719-llvm-b0c409a235c06bec6374e009d147e760a9dcefa1.tar.gz bcm5719-llvm-b0c409a235c06bec6374e009d147e760a9dcefa1.zip |
Added HTML pretty-printer.
llvm-svn: 48507
Diffstat (limited to 'clang')
-rw-r--r-- | clang/Driver/HTMLPrint.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/clang/Driver/HTMLPrint.cpp b/clang/Driver/HTMLPrint.cpp new file mode 100644 index 00000000000..d347901e8b5 --- /dev/null +++ b/clang/Driver/HTMLPrint.cpp @@ -0,0 +1,62 @@ +//===--- RewriteTest.cpp - Playground for the code rewriter ---------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Hacks and fun related to the code rewriter. +// +//===----------------------------------------------------------------------===// + +#include "ASTConsumers.h" +#include "clang/AST/ASTConsumer.h" +#include "clang/Rewrite/Rewriter.h" +#include "clang/Rewrite/HTMLRewrite.h" +#include "clang/Basic/SourceManager.h" +#include "llvm/Support/MemoryBuffer.h" +#include "clang/AST/ASTContext.h" + +using namespace clang; + +namespace { + class HTMLPrinter : public ASTConsumer { + Rewriter R; + public: + HTMLPrinter() {} + virtual ~HTMLPrinter(); + + void Initialize(ASTContext &context); + }; +} + +ASTConsumer* clang::CreateHTMLPrinter() { return new HTMLPrinter(); } + +void HTMLPrinter::Initialize(ASTContext &context) { + R.setSourceMgr(context.getSourceManager()); +} + +HTMLPrinter::~HTMLPrinter() { + unsigned FileID = R.getSourceMgr().getMainFileID(); + + const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FileID); + const char* FileStart = Buf->getBufferStart(); + const char* FileEnd = Buf->getBufferEnd(); + SourceLocation StartLoc = SourceLocation::getFileLoc(FileID, 0); + SourceLocation EndLoc = SourceLocation::getFileLoc(FileID, FileEnd-FileStart); + + html::EscapeText(R, FileID); + html::AddLineNumbers(R, FileID); +// html::InsertTag(R, html::HEAD, StartLoc, EndLoc, true); +// html::InsertTag(R, html::BODY, StartLoc, EndLoc, true); +// html::InsertTag(R, html::PRE, StartLoc, EndLoc); + + // Emit the HTML. + + if (const RewriteBuffer *RewriteBuf = R.getRewriteBufferFor(FileID)) { + std::string S(RewriteBuf->begin(), RewriteBuf->end()); + printf("%s\n", S.c_str()); + } +} |