forked from OSchip/llvm-project
Remove "--html-test" driver option and its corresponding code; all of this
functionality has been migrated into "--emit-html" and "--html-diags". llvm-svn: 49776
This commit is contained in:
parent
c326f7e860
commit
088d12e741
|
@ -58,7 +58,6 @@ ASTConsumer *CreateCodeRewriterTest(const std::string& InFile,
|
|||
const LangOptions &LOpts);
|
||||
|
||||
ASTConsumer* CreateHTMLPrinter();
|
||||
ASTConsumer* CreateHTMLTest();
|
||||
|
||||
ASTConsumer *CreateSerializationTest(Diagnostic &Diags,
|
||||
FileManager& FMgr,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//===--- HTMLPrint.cpp - Playground for the HTML code rewriter ------------===//
|
||||
//===--- HTMLPrint.cpp - Source code -> HTML pretty-printing --------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
|
@ -7,7 +7,7 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Hacks and fun related to the code rewriter.
|
||||
// Pretty-printing of source code to HTML.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
@ -16,12 +16,7 @@
|
|||
#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"
|
||||
#include "clang/Basic/Diagnostic.h"
|
||||
#include "clang/Analysis/LocalCheckers.h"
|
||||
#include "clang/AST/CFG.h"
|
||||
#include <sstream>
|
||||
|
||||
using namespace clang;
|
||||
|
||||
|
@ -62,177 +57,3 @@ HTMLPrinter::~HTMLPrinter() {
|
|||
free(Buffer);
|
||||
}
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Other HTML pretty-printing code used to test new features.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
namespace {
|
||||
class HTMLTest : public ASTConsumer {
|
||||
Rewriter R;
|
||||
ASTContext* Ctx;
|
||||
public:
|
||||
HTMLTest() : Ctx(NULL) {}
|
||||
virtual ~HTMLTest();
|
||||
virtual void HandleTopLevelDecl(Decl* D);
|
||||
|
||||
void Initialize(ASTContext &context);
|
||||
void ProcessBody(Stmt* S);
|
||||
};
|
||||
}
|
||||
|
||||
ASTConsumer* clang::CreateHTMLTest() { return new HTMLTest(); }
|
||||
|
||||
void HTMLTest::Initialize(ASTContext &context) {
|
||||
Ctx = &context;
|
||||
R.setSourceMgr(context.getSourceManager());
|
||||
}
|
||||
|
||||
void HTMLTest::HandleTopLevelDecl(Decl* D) {
|
||||
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
|
||||
if (Stmt* B = FD->getBody()) {
|
||||
SourceLocation L = B->getLocStart();
|
||||
|
||||
if (L.isFileID() && L.getFileID() == R.getSourceMgr().getMainFileID())
|
||||
ProcessBody(B);
|
||||
}
|
||||
}
|
||||
|
||||
HTMLTest::~HTMLTest() {
|
||||
|
||||
unsigned FileID = R.getSourceMgr().getMainFileID();
|
||||
html::EscapeText(R, FileID);
|
||||
html::AddLineNumbers(R, FileID);
|
||||
html::AddHeaderFooterInternalBuiltinCSS(R, FileID);
|
||||
|
||||
// Emit the HTML.
|
||||
|
||||
if (const RewriteBuffer *RewriteBuf = R.getRewriteBufferFor(FileID)) {
|
||||
std::string S(RewriteBuf->begin(), RewriteBuf->end());
|
||||
printf("%s\n", S.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
class HTMLDiagnostic : public DiagnosticClient {
|
||||
Rewriter& R;
|
||||
public:
|
||||
HTMLDiagnostic(Rewriter& r) : R(r) {}
|
||||
virtual void HandleDiagnostic(Diagnostic &Diags,
|
||||
Diagnostic::Level DiagLevel,
|
||||
FullSourceLoc Pos,
|
||||
diag::kind ID,
|
||||
const std::string *Strs,
|
||||
unsigned NumStrs,
|
||||
const SourceRange *Ranges,
|
||||
unsigned NumRanges);
|
||||
};
|
||||
}
|
||||
|
||||
void HTMLTest::ProcessBody(Stmt* S) {
|
||||
CFG* cfg = CFG::buildCFG(S);
|
||||
|
||||
if (!cfg)
|
||||
return;
|
||||
|
||||
HTMLDiagnostic HD(R);
|
||||
Diagnostic D(HD);
|
||||
|
||||
CheckDeadStores(*cfg, *Ctx, D);
|
||||
}
|
||||
|
||||
void HTMLDiagnostic::HandleDiagnostic(Diagnostic &Diags,
|
||||
Diagnostic::Level DiagLevel,
|
||||
FullSourceLoc Pos,
|
||||
diag::kind ID,
|
||||
const std::string *Strs,
|
||||
unsigned NumStrs,
|
||||
const SourceRange *Ranges,
|
||||
unsigned NumRanges) {
|
||||
|
||||
// For now, just draw a box above the line in question, and emit the
|
||||
// warning.
|
||||
|
||||
if (!Pos.isValid())
|
||||
return;
|
||||
|
||||
SourceManager& SM = R.getSourceMgr();
|
||||
|
||||
FullSourceLoc LPos = Pos.getLogicalLoc();
|
||||
unsigned FileID = SM.getCanonicalFileID(LPos.getLocation());
|
||||
|
||||
assert (&LPos.getManager() == &SM && "SourceManagers are different!");
|
||||
|
||||
if (!SM.isFromMainFile(LPos.getLocation()))
|
||||
return;
|
||||
|
||||
// Compute the column number. Rewind from the current position to the start
|
||||
// of the line.
|
||||
|
||||
unsigned ColNo = LPos.getColumnNumber();
|
||||
const char *TokLogicalPtr = LPos.getCharacterData();
|
||||
const char *LineStart = TokLogicalPtr-ColNo;
|
||||
|
||||
// Ripped from TextDiagnostics::FormatDiagnostic:
|
||||
|
||||
std::string Msg = Diags.getDescription(ID);
|
||||
|
||||
for (unsigned i = 0; i < Msg.size() - 1; ++i) {
|
||||
if (Msg[i] == '%' && isdigit(Msg[i + 1])) {
|
||||
unsigned StrNo = Msg[i + 1] - '0';
|
||||
Msg = std::string(Msg.begin(), Msg.begin() + i) +
|
||||
(StrNo < NumStrs ? Strs[StrNo] : "<<<INTERNAL ERROR>>>") +
|
||||
std::string(Msg.begin() + i + 2, Msg.end());
|
||||
}
|
||||
}
|
||||
|
||||
// Create the html for the message.
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
os << "\n<tr><td class=\"num\"></td><td class=\"line\">"
|
||||
<< "<div class=\"msg\" style=\"margin-left:"
|
||||
<< ColNo << "ex\">";
|
||||
|
||||
switch (DiagLevel) {
|
||||
default: assert(0 && "Unknown diagnostic type!");
|
||||
case Diagnostic::Note: os << "note: "; break;
|
||||
case Diagnostic::Warning: os << "warning: "; break;
|
||||
case Diagnostic::Error: os << "error: "; break;
|
||||
case Diagnostic::Fatal: os << "fatal error: "; break;
|
||||
break;
|
||||
}
|
||||
|
||||
os << Msg << "</div></td></tr>";
|
||||
|
||||
// Insert the new html.
|
||||
|
||||
const llvm::MemoryBuffer *Buf = SM.getBuffer(FileID);
|
||||
const char* FileStart = Buf->getBufferStart();
|
||||
|
||||
R.InsertStrBefore(SourceLocation::getFileLoc(FileID, LineStart - FileStart),
|
||||
os.str());
|
||||
|
||||
// Now highlight the ranges.
|
||||
|
||||
for (unsigned i = 0; i < NumRanges; ++i) {
|
||||
|
||||
SourceLocation B = SM.getLogicalLoc(Ranges->getBegin());
|
||||
SourceLocation E = SM.getLogicalLoc(Ranges->getEnd());
|
||||
|
||||
// We do this because the position seems to point to the beginning of
|
||||
// the last character. FIXME: Is this what is suppose to happen?
|
||||
std::pair<unsigned,unsigned> X = SM.getDecomposedFileLoc(E);
|
||||
E = SourceLocation::getFileLoc(X.first, X.second+1);
|
||||
|
||||
++Ranges;
|
||||
|
||||
if (!SM.isFromMainFile(B) || !SM.isFromMainFile(E))
|
||||
continue;
|
||||
|
||||
// Highlight the range. Make the span tag the outermost tag for the
|
||||
// selected range.
|
||||
R.InsertCStrBefore(B, "<span class=\"mrange\">");
|
||||
R.InsertCStrAfter(E, "</span>");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,10 +135,7 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
|
|||
clEnumValN(SerializeAST, "serialize",
|
||||
"Build ASTs and emit .ast file"),
|
||||
clEnumValN(RewriteObjC, "rewrite-objc",
|
||||
"Playground for the code rewriter"),
|
||||
clEnumValN(HTMLTest, "html-test",
|
||||
"Playground for the HTML displayer"),
|
||||
|
||||
"Playground for the code rewriter"),
|
||||
clEnumValEnd));
|
||||
|
||||
|
||||
|
@ -1051,9 +1048,6 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
|
|||
case EmitHTML:
|
||||
return CreateHTMLPrinter();
|
||||
|
||||
case HTMLTest:
|
||||
return CreateHTMLTest();
|
||||
|
||||
case ParseCFGDump:
|
||||
case ParseCFGView:
|
||||
return CreateCFGDumper(ProgAction == ParseCFGView,
|
||||
|
|
Loading…
Reference in New Issue