diff options
author | Ying Yi <maggieyi666@gmail.com> | 2016-08-04 10:39:43 +0000 |
---|---|---|
committer | Ying Yi <maggieyi666@gmail.com> | 2016-08-04 10:39:43 +0000 |
commit | 0ef31b7960cad696f9d93fa50df3e2d2bee15413 (patch) | |
tree | 6542beae75a8741486be484315178e907d088aa9 /llvm/tools | |
parent | 3d88f0c3fb090aa2c72fbbf9f8ecea526911bdda (diff) | |
download | bcm5719-llvm-0ef31b7960cad696f9d93fa50df3e2d2bee15413.tar.gz bcm5719-llvm-0ef31b7960cad696f9d93fa50df3e2d2bee15413.zip |
[LLVM-COV]Replace tabs to the space indentations in the HTML coverage report.
When using orbis-llvm-cov.exe to generate the HTML report, the HTML report
can look quite different to the source file if it includes tabs.The default
tab size is 2 spaces instead of 8 spaces. A command line switch is
be added to set the tab size.
Differential Revision: https://reviews.llvm.org/D23087
llvm-svn: 277715
Diffstat (limited to 'llvm/tools')
-rw-r--r-- | llvm/tools/llvm-cov/CodeCoverage.cpp | 5 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/CoverageViewOptions.h | 1 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp | 36 |
3 files changed, 30 insertions, 12 deletions
diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp index 494912ed313..2853867aafb 100644 --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -584,6 +584,10 @@ int CodeCoverageTool::show(int argc, const char **argv, cl::alias ShowOutputDirectoryA("o", cl::desc("Alias for --output-dir"), cl::aliasopt(ShowOutputDirectory)); + cl::opt<uint32_t> TabSize( + "tab-size", cl::Hidden, cl::init(2), + cl::desc("Set tab size for the HTML coverage report (default = 2)")); + auto Err = commandLineParser(argc, argv); if (Err) return Err; @@ -596,6 +600,7 @@ int CodeCoverageTool::show(int argc, const char **argv, ViewOpts.ShowExpandedRegions = ShowExpansions; ViewOpts.ShowFunctionInstantiations = ShowInstantiations; ViewOpts.ShowOutputDirectory = ShowOutputDirectory; + ViewOpts.TabSize = TabSize; if (ViewOpts.hasOutputDirectory()) { if (auto E = sys::fs::create_directories(ViewOpts.ShowOutputDirectory)) { diff --git a/llvm/tools/llvm-cov/CoverageViewOptions.h b/llvm/tools/llvm-cov/CoverageViewOptions.h index 350c264a287..45f2d813987 100644 --- a/llvm/tools/llvm-cov/CoverageViewOptions.h +++ b/llvm/tools/llvm-cov/CoverageViewOptions.h @@ -34,6 +34,7 @@ struct CoverageViewOptions { OutputFormat Format; std::string ShowOutputDirectory; std::vector<std::string> DemanglerOpts; + uint32_t TabSize; /// \brief Change the output's stream color if the colors are enabled. ColoredRawOstream colored_ostream(raw_ostream &OS, diff --git a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp index 53a18b42505..588b83850ac 100644 --- a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp +++ b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp @@ -22,9 +22,11 @@ using namespace llvm; namespace { // Return a string with the special characters in \p Str escaped. -std::string escape(StringRef Str) { +std::string escape(StringRef Str, const CoverageViewOptions &Opts) { std::string Result; + unsigned ColNum = 0; // Record the column number. for (char C : Str) { + ++ColNum; if (C == '&') Result += "&"; else if (C == '<') @@ -33,7 +35,16 @@ std::string escape(StringRef Str) { Result += ">"; else if (C == '\"') Result += """; - else + else if (C == '\n' || C == '\r') { + Result += C; + ColNum = 0; + } else if (C == '\t') { + // Replace '\t' with TabSize spaces. + unsigned NumSpaces = Opts.TabSize - (--ColNum % Opts.TabSize); + for (unsigned I = 0; I < NumSpaces; ++I) + Result += " "; + ColNum += NumSpaces; + } else Result += C; } return Result; @@ -195,7 +206,8 @@ std::string getPathToStyle(StringRef ViewPath) { return PathToStyle + "style.css"; } -void emitPrelude(raw_ostream &OS, const std::string &PathToStyle = "") { +void emitPrelude(raw_ostream &OS, const CoverageViewOptions &Opts, + const std::string &PathToStyle = "") { OS << "<!doctype html>" "<html>" << BeginHeader; @@ -204,8 +216,8 @@ void emitPrelude(raw_ostream &OS, const std::string &PathToStyle = "") { if (PathToStyle.empty()) OS << "<style>" << CSSForCoverage << "</style>"; else - OS << "<link rel='stylesheet' type='text/css' href='" << escape(PathToStyle) - << "'>"; + OS << "<link rel='stylesheet' type='text/css' href='" + << escape(PathToStyle, Opts) << "'>"; OS << EndHeader << "<body>" << BeginCenteredDiv; } @@ -226,10 +238,10 @@ CoveragePrinterHTML::createViewFile(StringRef Path, bool InToplevel) { OwnedStream OS = std::move(OSOrErr.get()); if (!Opts.hasOutputDirectory()) { - emitPrelude(*OS.get()); + emitPrelude(*OS.get(), Opts); } else { std::string ViewPath = getOutputPath(Path, "html", InToplevel); - emitPrelude(*OS.get(), getPathToStyle(ViewPath)); + emitPrelude(*OS.get(), Opts, getPathToStyle(ViewPath)); } return std::move(OS); @@ -248,13 +260,13 @@ Error CoveragePrinterHTML::createIndexFile(ArrayRef<StringRef> SourceFiles) { // Emit a table containing links to reports for each file in the covmapping. assert(Opts.hasOutputDirectory() && "No output directory for index file"); - emitPrelude(OSRef, getPathToStyle("")); + emitPrelude(OSRef, Opts, getPathToStyle("")); OSRef << BeginSourceNameDiv << "Index" << EndSourceNameDiv; OSRef << BeginTable; for (StringRef SF : SourceFiles) { - std::string LinkText = escape(sys::path::relative_path(SF)); + std::string LinkText = escape(sys::path::relative_path(SF), Opts); std::string LinkTarget = - escape(getOutputPath(SF, "html", /*InToplevel=*/false)); + escape(getOutputPath(SF, "html", /*InToplevel=*/false), Opts); OSRef << tag("tr", tag("td", tag("pre", a(LinkTarget, LinkText), "code"))); } OSRef << EndTable; @@ -280,7 +292,7 @@ void SourceCoverageViewHTML::renderViewFooter(raw_ostream &OS) { } void SourceCoverageViewHTML::renderSourceName(raw_ostream &OS) { - OS << BeginSourceNameDiv << tag("pre", escape(getSourceName())) + OS << BeginSourceNameDiv << tag("pre", escape(getSourceName(), getOptions())) << EndSourceNameDiv; } @@ -336,7 +348,7 @@ void SourceCoverageViewHTML::renderLine( // 2. Escape all of the snippets. for (unsigned I = 0, E = Snippets.size(); I < E; ++I) - Snippets[I] = escape(Snippets[I]); + Snippets[I] = escape(Snippets[I], getOptions()); // 3. Use \p WrappedSegment to set the highlight for snippet 0. Use segment // 1 to set the highlight for snippet 2, segment 2 to set the highlight for |