Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 1 | //===--- HTMLDiagnostics.cpp - HTML Diagnostics for Paths ----*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the HTMLDiagnostics object. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Daniel Dunbar | e1bd4e6 | 2009-03-02 06:16:29 +0000 | [diff] [blame] | 14 | #include "clang/Frontend/PathDiagnosticClients.h" |
Daniel Dunbar | e91593e | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 15 | #include "clang/Analysis/PathDiagnostic.h" |
| 16 | #include "clang/AST/ASTContext.h" |
| 17 | #include "clang/AST/Decl.h" |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 18 | #include "clang/Basic/SourceManager.h" |
Ted Kremenek | 2e93981 | 2008-03-27 07:35:49 +0000 | [diff] [blame] | 19 | #include "clang/Basic/FileManager.h" |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 20 | #include "clang/Rewrite/Rewriter.h" |
| 21 | #include "clang/Rewrite/HTMLRewrite.h" |
| 22 | #include "clang/Lex/Lexer.h" |
Ted Kremenek | 0e5c8d4 | 2009-03-10 05:16:17 +0000 | [diff] [blame] | 23 | #include "clang/Lex/Preprocessor.h" |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Compiler.h" |
| 25 | #include "llvm/Support/MemoryBuffer.h" |
| 26 | #include "llvm/Support/Streams.h" |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 27 | #include "llvm/Support/raw_ostream.h" |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 28 | #include "llvm/System/Path.h" |
| 29 | #include <fstream> |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 30 | using namespace clang; |
| 31 | |
| 32 | //===----------------------------------------------------------------------===// |
| 33 | // Boilerplate. |
| 34 | //===----------------------------------------------------------------------===// |
| 35 | |
| 36 | namespace { |
| 37 | |
| 38 | class VISIBILITY_HIDDEN HTMLDiagnostics : public PathDiagnosticClient { |
| 39 | llvm::sys::Path Directory, FilePrefix; |
| 40 | bool createdDir, noDir; |
Ted Kremenek | 47abe76 | 2008-04-16 16:39:56 +0000 | [diff] [blame] | 41 | Preprocessor* PP; |
Ted Kremenek | 339b9c2 | 2008-04-17 22:31:54 +0000 | [diff] [blame] | 42 | PreprocessorFactory* PPF; |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 43 | std::vector<const PathDiagnostic*> BatchedDiags; |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 44 | public: |
Ted Kremenek | 339b9c2 | 2008-04-17 22:31:54 +0000 | [diff] [blame] | 45 | HTMLDiagnostics(const std::string& prefix, Preprocessor* pp, |
| 46 | PreprocessorFactory* ppf); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 47 | |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 48 | virtual ~HTMLDiagnostics(); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 49 | |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 50 | virtual void HandlePathDiagnostic(const PathDiagnostic* D); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 51 | |
Ted Kremenek | 0e5c8d4 | 2009-03-10 05:16:17 +0000 | [diff] [blame] | 52 | unsigned ProcessMacroPiece(llvm::raw_ostream& os, |
| 53 | const PathDiagnosticMacroPiece& P, |
| 54 | unsigned num); |
| 55 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 56 | void HandlePiece(Rewriter& R, FileID BugFileID, |
Ted Kremenek | fd8fc4e | 2008-07-23 23:18:15 +0000 | [diff] [blame] | 57 | const PathDiagnosticPiece& P, unsigned num, unsigned max); |
Ted Kremenek | 33bd942 | 2008-03-31 23:30:12 +0000 | [diff] [blame] | 58 | |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 59 | void HighlightRange(Rewriter& R, FileID BugFileID, SourceRange Range, |
| 60 | const char *HighlightStart = "<span class=\"mrange\">", |
| 61 | const char *HighlightEnd = "</span>"); |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 62 | |
| 63 | void ReportDiag(const PathDiagnostic& D); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | } // end anonymous namespace |
| 67 | |
Ted Kremenek | 339b9c2 | 2008-04-17 22:31:54 +0000 | [diff] [blame] | 68 | HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix, Preprocessor* pp, |
| 69 | PreprocessorFactory* ppf) |
Ted Kremenek | 47abe76 | 2008-04-16 16:39:56 +0000 | [diff] [blame] | 70 | : Directory(prefix), FilePrefix(prefix), createdDir(false), noDir(false), |
Ted Kremenek | 339b9c2 | 2008-04-17 22:31:54 +0000 | [diff] [blame] | 71 | PP(pp), PPF(ppf) { |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 72 | |
| 73 | // All html files begin with "report" |
| 74 | FilePrefix.appendComponent("report"); |
| 75 | } |
| 76 | |
| 77 | PathDiagnosticClient* |
Ted Kremenek | 339b9c2 | 2008-04-17 22:31:54 +0000 | [diff] [blame] | 78 | clang::CreateHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP, |
| 79 | PreprocessorFactory* PPF) { |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 80 | |
Ted Kremenek | 339b9c2 | 2008-04-17 22:31:54 +0000 | [diff] [blame] | 81 | return new HTMLDiagnostics(prefix, PP, PPF); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | //===----------------------------------------------------------------------===// |
| 85 | // Report processing. |
| 86 | //===----------------------------------------------------------------------===// |
| 87 | |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 88 | void HTMLDiagnostics::HandlePathDiagnostic(const PathDiagnostic* D) { |
| 89 | if (!D) |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 90 | return; |
| 91 | |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 92 | if (D->empty()) { |
| 93 | delete D; |
| 94 | return; |
| 95 | } |
| 96 | |
Ted Kremenek | 7db0a94 | 2009-04-02 05:17:38 +0000 | [diff] [blame] | 97 | const_cast<PathDiagnostic*>(D)->flattenLocations(); |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 98 | BatchedDiags.push_back(D); |
| 99 | } |
| 100 | |
| 101 | HTMLDiagnostics::~HTMLDiagnostics() { |
| 102 | |
| 103 | while (!BatchedDiags.empty()) { |
| 104 | const PathDiagnostic* D = BatchedDiags.back(); |
| 105 | BatchedDiags.pop_back(); |
| 106 | ReportDiag(*D); |
| 107 | delete D; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) { |
| 112 | |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 113 | // Create the HTML directory if it is missing. |
| 114 | |
| 115 | if (!createdDir) { |
| 116 | createdDir = true; |
Ted Kremenek | 344f7e3 | 2008-04-03 17:55:57 +0000 | [diff] [blame] | 117 | std::string ErrorMsg; |
| 118 | Directory.createDirectoryOnDisk(true, &ErrorMsg); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 119 | |
| 120 | if (!Directory.isDirectory()) { |
| 121 | llvm::cerr << "warning: could not create directory '" |
Ted Kremenek | 344f7e3 | 2008-04-03 17:55:57 +0000 | [diff] [blame] | 122 | << Directory.toString() << "'\n" |
| 123 | << "reason: " << ErrorMsg << '\n'; |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 124 | |
| 125 | noDir = true; |
| 126 | |
| 127 | return; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | if (noDir) |
| 132 | return; |
| 133 | |
Ted Kremenek | 5fb5dfb | 2009-04-01 06:13:56 +0000 | [diff] [blame] | 134 | const SourceManager &SMgr = D.begin()->getLocation().getManager(); |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 135 | FileID FID; |
Ted Kremenek | fd8fc4e | 2008-07-23 23:18:15 +0000 | [diff] [blame] | 136 | |
| 137 | // Verify that the entire path is from the same FileID. |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 138 | for (PathDiagnostic::const_iterator I = D.begin(), E = D.end(); I != E; ++I) { |
Ted Kremenek | 5fb5dfb | 2009-04-01 06:13:56 +0000 | [diff] [blame] | 139 | FullSourceLoc L = I->getLocation().asLocation().getInstantiationLoc(); |
Ted Kremenek | fd8fc4e | 2008-07-23 23:18:15 +0000 | [diff] [blame] | 140 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 141 | if (FID.isInvalid()) { |
Chris Lattner | a11d617 | 2009-01-19 07:46:45 +0000 | [diff] [blame] | 142 | FID = SMgr.getFileID(L); |
| 143 | } else if (SMgr.getFileID(L) != FID) |
Ted Kremenek | fd8fc4e | 2008-07-23 23:18:15 +0000 | [diff] [blame] | 144 | return; // FIXME: Emit a warning? |
| 145 | |
| 146 | // Check the source ranges. |
| 147 | for (PathDiagnosticPiece::range_iterator RI=I->ranges_begin(), |
| 148 | RE=I->ranges_end(); RI!=RE; ++RI) { |
| 149 | |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 150 | SourceLocation L = SMgr.getInstantiationLoc(RI->getBegin()); |
Ted Kremenek | fd8fc4e | 2008-07-23 23:18:15 +0000 | [diff] [blame] | 151 | |
Chris Lattner | a11d617 | 2009-01-19 07:46:45 +0000 | [diff] [blame] | 152 | if (!L.isFileID() || SMgr.getFileID(L) != FID) |
Ted Kremenek | fd8fc4e | 2008-07-23 23:18:15 +0000 | [diff] [blame] | 153 | return; // FIXME: Emit a warning? |
| 154 | |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 155 | L = SMgr.getInstantiationLoc(RI->getEnd()); |
Ted Kremenek | fd8fc4e | 2008-07-23 23:18:15 +0000 | [diff] [blame] | 156 | |
Chris Lattner | a11d617 | 2009-01-19 07:46:45 +0000 | [diff] [blame] | 157 | if (!L.isFileID() || SMgr.getFileID(L) != FID) |
Ted Kremenek | fd8fc4e | 2008-07-23 23:18:15 +0000 | [diff] [blame] | 158 | return; // FIXME: Emit a warning? |
Ted Kremenek | fd8fc4e | 2008-07-23 23:18:15 +0000 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 162 | if (FID.isInvalid()) |
Ted Kremenek | fd8fc4e | 2008-07-23 23:18:15 +0000 | [diff] [blame] | 163 | return; // FIXME: Emit a warning? |
| 164 | |
| 165 | // Create a new rewriter to generate HTML. |
Ted Kremenek | 5fb5dfb | 2009-04-01 06:13:56 +0000 | [diff] [blame] | 166 | Rewriter R(const_cast<SourceManager&>(SMgr)); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 167 | |
Ted Kremenek | 0008683 | 2009-03-10 02:49:29 +0000 | [diff] [blame] | 168 | // Process the path. |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 169 | unsigned n = D.size(); |
Ted Kremenek | 33bd942 | 2008-03-31 23:30:12 +0000 | [diff] [blame] | 170 | unsigned max = n; |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 171 | |
| 172 | for (PathDiagnostic::const_reverse_iterator I=D.rbegin(), E=D.rend(); |
| 173 | I!=E; ++I, --n) { |
| 174 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 175 | HandlePiece(R, FID, *I, n, max); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | // Add line numbers, header, footer, etc. |
Ted Kremenek | 2e93981 | 2008-03-27 07:35:49 +0000 | [diff] [blame] | 179 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 180 | // unsigned FID = R.getSourceMgr().getMainFileID(); |
| 181 | html::EscapeText(R, FID); |
| 182 | html::AddLineNumbers(R, FID); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 183 | |
Ted Kremenek | 47abe76 | 2008-04-16 16:39:56 +0000 | [diff] [blame] | 184 | // If we have a preprocessor, relex the file and syntax highlight. |
| 185 | // We might not have a preprocessor if we come from a deserialized AST file, |
| 186 | // for example. |
| 187 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 188 | if (PP) html::SyntaxHighlight(R, FID, *PP); |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 189 | |
| 190 | // FIXME: We eventually want to use PPF to create a fresh Preprocessor, |
| 191 | // once we have worked out the bugs. |
| 192 | // |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 193 | // if (PPF) html::HighlightMacros(R, FID, *PPF); |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 194 | // |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 195 | if (PP) html::HighlightMacros(R, FID, *PP); |
Ted Kremenek | 47abe76 | 2008-04-16 16:39:56 +0000 | [diff] [blame] | 196 | |
Ted Kremenek | b947639 | 2008-04-02 20:44:16 +0000 | [diff] [blame] | 197 | // Get the full directory name of the analyzed file. |
| 198 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 199 | const FileEntry* Entry = SMgr.getFileEntryForID(FID); |
Ted Kremenek | 2e93981 | 2008-03-27 07:35:49 +0000 | [diff] [blame] | 200 | |
Ted Kremenek | 7fc8957 | 2008-04-24 23:37:03 +0000 | [diff] [blame] | 201 | // This is a cludge; basically we want to append either the full |
| 202 | // working directory if we have no directory information. This is |
| 203 | // a work in progress. |
| 204 | |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 205 | std::string DirName = ""; |
| 206 | |
| 207 | if (!llvm::sys::Path(Entry->getName()).isAbsolute()) { |
| 208 | llvm::sys::Path P = llvm::sys::Path::GetCurrentDirectory(); |
| 209 | DirName = P.toString() + "/"; |
| 210 | } |
Ted Kremenek | b947639 | 2008-04-02 20:44:16 +0000 | [diff] [blame] | 211 | |
Ted Kremenek | 4b0f813 | 2008-04-15 21:25:08 +0000 | [diff] [blame] | 212 | // Add the name of the file as an <h1> tag. |
| 213 | |
Ted Kremenek | 2e93981 | 2008-03-27 07:35:49 +0000 | [diff] [blame] | 214 | { |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 215 | std::string s; |
| 216 | llvm::raw_string_ostream os(s); |
Ted Kremenek | 2e93981 | 2008-03-27 07:35:49 +0000 | [diff] [blame] | 217 | |
Ted Kremenek | 778246a | 2008-09-22 17:33:32 +0000 | [diff] [blame] | 218 | os << "<!-- REPORTHEADER -->\n" |
Ted Kremenek | 5fb5dfb | 2009-04-01 06:13:56 +0000 | [diff] [blame] | 219 | << "<h3>Bug Summary</h3>\n<table class=\"simpletable\">\n" |
Ted Kremenek | 4b0f813 | 2008-04-15 21:25:08 +0000 | [diff] [blame] | 220 | "<tr><td class=\"rowname\">File:</td><td>" |
Ted Kremenek | 5fb5dfb | 2009-04-01 06:13:56 +0000 | [diff] [blame] | 221 | << html::EscapeText(DirName) |
| 222 | << html::EscapeText(Entry->getName()) |
| 223 | << "</td></tr>\n<tr><td class=\"rowname\">Location:</td><td>" |
| 224 | "<a href=\"#EndPath\">line " |
| 225 | << (*D.rbegin()).getLocation().asLocation().getInstantiationLineNumber() |
| 226 | << ", column " |
| 227 | << (*D.rbegin()).getLocation().asLocation().getInstantiationColumnNumber() |
| 228 | << "</a></td></tr>\n" |
| 229 | "<tr><td class=\"rowname\">Description:</td><td>" |
| 230 | << D.getDescription() << "</td></tr>\n"; |
Ted Kremenek | 072192b | 2008-04-30 23:47:44 +0000 | [diff] [blame] | 231 | |
| 232 | // Output any other meta data. |
| 233 | |
| 234 | for (PathDiagnostic::meta_iterator I=D.meta_begin(), E=D.meta_end(); |
| 235 | I!=E; ++I) { |
| 236 | os << "<tr><td></td><td>" << html::EscapeText(*I) << "</td></tr>\n"; |
| 237 | } |
| 238 | |
Ted Kremenek | 778246a | 2008-09-22 17:33:32 +0000 | [diff] [blame] | 239 | os << "</table>\n<!-- REPORTSUMMARYEXTRA -->\n" |
| 240 | "<h3>Annotated Source Code</h3>\n"; |
Ted Kremenek | 4b0f813 | 2008-04-15 21:25:08 +0000 | [diff] [blame] | 241 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 242 | R.InsertStrBefore(SMgr.getLocForStartOfFile(FID), os.str()); |
Ted Kremenek | 0761540 | 2008-04-02 07:04:46 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Ted Kremenek | b947639 | 2008-04-02 20:44:16 +0000 | [diff] [blame] | 245 | // Embed meta-data tags. |
Ted Kremenek | 0761540 | 2008-04-02 07:04:46 +0000 | [diff] [blame] | 246 | |
| 247 | const std::string& BugDesc = D.getDescription(); |
| 248 | |
| 249 | if (!BugDesc.empty()) { |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 250 | std::string s; |
| 251 | llvm::raw_string_ostream os(s); |
Ted Kremenek | 86b4381 | 2008-04-02 18:03:20 +0000 | [diff] [blame] | 252 | os << "\n<!-- BUGDESC " << BugDesc << " -->\n"; |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 253 | R.InsertStrBefore(SMgr.getLocForStartOfFile(FID), os.str()); |
Ted Kremenek | b947639 | 2008-04-02 20:44:16 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Ted Kremenek | a26ddab | 2009-01-27 01:53:39 +0000 | [diff] [blame] | 256 | const std::string& BugType = D.getBugType(); |
| 257 | if (!BugType.empty()) { |
| 258 | std::string s; |
| 259 | llvm::raw_string_ostream os(s); |
| 260 | os << "\n<!-- BUGTYPE " << BugType << " -->\n"; |
| 261 | R.InsertStrBefore(SMgr.getLocForStartOfFile(FID), os.str()); |
| 262 | } |
| 263 | |
Ted Kremenek | 8c036c7 | 2008-09-20 04:23:38 +0000 | [diff] [blame] | 264 | const std::string& BugCategory = D.getCategory(); |
| 265 | |
| 266 | if (!BugCategory.empty()) { |
| 267 | std::string s; |
| 268 | llvm::raw_string_ostream os(s); |
| 269 | os << "\n<!-- BUGCATEGORY " << BugCategory << " -->\n"; |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 270 | R.InsertStrBefore(SMgr.getLocForStartOfFile(FID), os.str()); |
Ted Kremenek | 8c036c7 | 2008-09-20 04:23:38 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Ted Kremenek | b947639 | 2008-04-02 20:44:16 +0000 | [diff] [blame] | 273 | { |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 274 | std::string s; |
| 275 | llvm::raw_string_ostream os(s); |
Ted Kremenek | 7fc8957 | 2008-04-24 23:37:03 +0000 | [diff] [blame] | 276 | os << "\n<!-- BUGFILE " << DirName << Entry->getName() << " -->\n"; |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 277 | R.InsertStrBefore(SMgr.getLocForStartOfFile(FID), os.str()); |
Ted Kremenek | b947639 | 2008-04-02 20:44:16 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | { |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 281 | std::string s; |
| 282 | llvm::raw_string_ostream os(s); |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 283 | os << "\n<!-- BUGLINE " |
Ted Kremenek | 5fb5dfb | 2009-04-01 06:13:56 +0000 | [diff] [blame] | 284 | << D.back()->getLocation().asLocation().getInstantiationLineNumber() |
| 285 | << " -->\n"; |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 286 | R.InsertStrBefore(SMgr.getLocForStartOfFile(FID), os.str()); |
Ted Kremenek | b947639 | 2008-04-02 20:44:16 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | { |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 290 | std::string s; |
| 291 | llvm::raw_string_ostream os(s); |
Ted Kremenek | b947639 | 2008-04-02 20:44:16 +0000 | [diff] [blame] | 292 | os << "\n<!-- BUGPATHLENGTH " << D.size() << " -->\n"; |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 293 | R.InsertStrBefore(SMgr.getLocForStartOfFile(FID), os.str()); |
Ted Kremenek | b947639 | 2008-04-02 20:44:16 +0000 | [diff] [blame] | 294 | } |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 295 | |
| 296 | // Add CSS, header, and footer. |
| 297 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 298 | html::AddHeaderFooterInternalBuiltinCSS(R, FID, Entry->getName()); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 299 | |
| 300 | // Get the rewrite buffer. |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 301 | const RewriteBuffer *Buf = R.getRewriteBufferFor(FID); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 302 | |
| 303 | if (!Buf) { |
| 304 | llvm::cerr << "warning: no diagnostics generated for main file.\n"; |
| 305 | return; |
| 306 | } |
| 307 | |
| 308 | // Create the stream to write out the HTML. |
| 309 | std::ofstream os; |
| 310 | |
| 311 | { |
| 312 | // Create a path for the target HTML file. |
| 313 | llvm::sys::Path F(FilePrefix); |
| 314 | F.makeUnique(false, NULL); |
| 315 | |
| 316 | // Rename the file with an HTML extension. |
| 317 | llvm::sys::Path H(F); |
| 318 | H.appendSuffix("html"); |
| 319 | F.renamePathOnDisk(H, NULL); |
| 320 | |
| 321 | os.open(H.toString().c_str()); |
| 322 | |
| 323 | if (!os) { |
| 324 | llvm::cerr << "warning: could not create file '" << F.toString() << "'\n"; |
| 325 | return; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | // Emit the HTML to disk. |
| 330 | |
Ted Kremenek | 7414dc0 | 2008-04-20 01:02:33 +0000 | [diff] [blame] | 331 | for (RewriteBuffer::iterator I = Buf->begin(), E = Buf->end(); I!=E; ++I) |
Ted Kremenek | fa5be36 | 2008-04-08 22:37:58 +0000 | [diff] [blame] | 332 | os << *I; |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 335 | void HTMLDiagnostics::HandlePiece(Rewriter& R, FileID BugFileID, |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 336 | const PathDiagnosticPiece& P, |
Ted Kremenek | 33bd942 | 2008-03-31 23:30:12 +0000 | [diff] [blame] | 337 | unsigned num, unsigned max) { |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 338 | |
| 339 | // For now, just draw a box above the line in question, and emit the |
| 340 | // warning. |
Ted Kremenek | 5fb5dfb | 2009-04-01 06:13:56 +0000 | [diff] [blame] | 341 | FullSourceLoc Pos = P.getLocation().asLocation(); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 342 | |
| 343 | if (!Pos.isValid()) |
| 344 | return; |
| 345 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 346 | SourceManager &SM = R.getSourceMgr(); |
Chris Lattner | 7da5aea | 2009-02-04 00:55:58 +0000 | [diff] [blame] | 347 | assert(&Pos.getManager() == &SM && "SourceManagers are different!"); |
| 348 | std::pair<FileID, unsigned> LPosInfo = SM.getDecomposedInstantiationLoc(Pos); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 349 | |
Chris Lattner | 7da5aea | 2009-02-04 00:55:58 +0000 | [diff] [blame] | 350 | if (LPosInfo.first != BugFileID) |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 351 | return; |
| 352 | |
Chris Lattner | 7da5aea | 2009-02-04 00:55:58 +0000 | [diff] [blame] | 353 | const llvm::MemoryBuffer *Buf = SM.getBuffer(LPosInfo.first); |
Ted Kremenek | ea17d6a | 2008-05-06 23:42:18 +0000 | [diff] [blame] | 354 | const char* FileStart = Buf->getBufferStart(); |
Ted Kremenek | ea17d6a | 2008-05-06 23:42:18 +0000 | [diff] [blame] | 355 | |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 356 | // Compute the column number. Rewind from the current position to the start |
| 357 | // of the line. |
Chris Lattner | 7da5aea | 2009-02-04 00:55:58 +0000 | [diff] [blame] | 358 | unsigned ColNo = SM.getColumnNumber(LPosInfo.first, LPosInfo.second); |
| 359 | const char *TokInstantiationPtr =Pos.getInstantiationLoc().getCharacterData(); |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 360 | const char *LineStart = TokInstantiationPtr-ColNo; |
Ted Kremenek | ea17d6a | 2008-05-06 23:42:18 +0000 | [diff] [blame] | 361 | |
Ted Kremenek | 3f0b656 | 2009-02-18 22:10:00 +0000 | [diff] [blame] | 362 | // Compute LineEnd. |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 363 | const char *LineEnd = TokInstantiationPtr; |
Ted Kremenek | 3f0b656 | 2009-02-18 22:10:00 +0000 | [diff] [blame] | 364 | const char* FileEnd = Buf->getBufferEnd(); |
| 365 | while (*LineEnd != '\n' && LineEnd != FileEnd) |
| 366 | ++LineEnd; |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 367 | |
Ted Kremenek | 2aa13b5 | 2008-03-31 21:40:14 +0000 | [diff] [blame] | 368 | // Compute the margin offset by counting tabs and non-tabs. |
Ted Kremenek | 3f0b656 | 2009-02-18 22:10:00 +0000 | [diff] [blame] | 369 | unsigned PosNo = 0; |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 370 | for (const char* c = LineStart; c != TokInstantiationPtr; ++c) |
Ted Kremenek | ea17d6a | 2008-05-06 23:42:18 +0000 | [diff] [blame] | 371 | PosNo += *c == '\t' ? 8 : 1; |
Ted Kremenek | 2aa13b5 | 2008-03-31 21:40:14 +0000 | [diff] [blame] | 372 | |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 373 | // Create the html for the message. |
Ted Kremenek | 0e5c8d4 | 2009-03-10 05:16:17 +0000 | [diff] [blame] | 374 | |
| 375 | const char *Kind = 0; |
| 376 | switch (P.getKind()) { |
| 377 | case PathDiagnosticPiece::Event: Kind = "Event"; break; |
| 378 | case PathDiagnosticPiece::ControlFlow: Kind = "Control"; break; |
| 379 | // Setting Kind to "Control" is intentional. |
| 380 | case PathDiagnosticPiece::Macro: Kind = "Control"; break; |
| 381 | } |
| 382 | |
| 383 | std::string sbuf; |
| 384 | llvm::raw_string_ostream os(sbuf); |
| 385 | |
| 386 | os << "\n<tr><td class=\"num\"></td><td class=\"line\"><div id=\""; |
| 387 | |
| 388 | if (num == max) |
| 389 | os << "EndPath"; |
| 390 | else |
| 391 | os << "Path" << num; |
| 392 | |
| 393 | os << "\" class=\"msg"; |
| 394 | if (Kind) |
| 395 | os << " msg" << Kind; |
| 396 | os << "\" style=\"margin-left:" << PosNo << "ex"; |
| 397 | |
| 398 | // Output a maximum size. |
| 399 | if (!isa<PathDiagnosticMacroPiece>(P)) { |
Ted Kremenek | a6aa83e | 2008-09-21 18:52:59 +0000 | [diff] [blame] | 400 | // Get the string and determining its maximum substring. |
| 401 | const std::string& Msg = P.getString(); |
| 402 | unsigned max_token = 0; |
| 403 | unsigned cnt = 0; |
| 404 | unsigned len = Msg.size(); |
Ted Kremenek | ea17d6a | 2008-05-06 23:42:18 +0000 | [diff] [blame] | 405 | |
Ted Kremenek | a6aa83e | 2008-09-21 18:52:59 +0000 | [diff] [blame] | 406 | for (std::string::const_iterator I=Msg.begin(), E=Msg.end(); I!=E; ++I) |
| 407 | switch (*I) { |
| 408 | default: |
| 409 | ++cnt; |
Ted Kremenek | 0008683 | 2009-03-10 02:49:29 +0000 | [diff] [blame] | 410 | continue; |
Ted Kremenek | a6aa83e | 2008-09-21 18:52:59 +0000 | [diff] [blame] | 411 | case ' ': |
| 412 | case '\t': |
| 413 | case '\n': |
| 414 | if (cnt > max_token) max_token = cnt; |
| 415 | cnt = 0; |
| 416 | } |
| 417 | |
Ted Kremenek | 0e5c8d4 | 2009-03-10 05:16:17 +0000 | [diff] [blame] | 418 | if (cnt > max_token) |
| 419 | max_token = cnt; |
Ted Kremenek | a6aa83e | 2008-09-21 18:52:59 +0000 | [diff] [blame] | 420 | |
Ted Kremenek | 0e5c8d4 | 2009-03-10 05:16:17 +0000 | [diff] [blame] | 421 | // Determine the approximate size of the message bubble in em. |
Ted Kremenek | a6aa83e | 2008-09-21 18:52:59 +0000 | [diff] [blame] | 422 | unsigned em; |
Ted Kremenek | 4e25ee3 | 2009-03-02 23:06:15 +0000 | [diff] [blame] | 423 | const unsigned max_line = 120; |
Ted Kremenek | a6aa83e | 2008-09-21 18:52:59 +0000 | [diff] [blame] | 424 | |
| 425 | if (max_token >= max_line) |
| 426 | em = max_token / 2; |
| 427 | else { |
| 428 | unsigned characters = max_line; |
| 429 | unsigned lines = len / max_line; |
Ted Kremenek | 0e5c8d4 | 2009-03-10 05:16:17 +0000 | [diff] [blame] | 430 | |
Ted Kremenek | a6aa83e | 2008-09-21 18:52:59 +0000 | [diff] [blame] | 431 | if (lines > 0) { |
| 432 | for (; characters > max_token; --characters) |
| 433 | if (len / characters > lines) { |
| 434 | ++characters; |
| 435 | break; |
| 436 | } |
| 437 | } |
Ted Kremenek | 0e5c8d4 | 2009-03-10 05:16:17 +0000 | [diff] [blame] | 438 | |
Ted Kremenek | a6aa83e | 2008-09-21 18:52:59 +0000 | [diff] [blame] | 439 | em = characters / 2; |
| 440 | } |
Ted Kremenek | 0e5c8d4 | 2009-03-10 05:16:17 +0000 | [diff] [blame] | 441 | |
| 442 | if (em < max_line/2) |
| 443 | os << "; max-width:" << em << "em"; |
| 444 | } |
| 445 | else |
| 446 | os << "; max-width:100em"; |
| 447 | |
| 448 | os << "\">"; |
| 449 | |
| 450 | if (max > 1) { |
| 451 | os << "<table class=\"msgT\"><tr><td valign=\"top\">"; |
| 452 | os << "<div class=\"PathIndex"; |
| 453 | if (Kind) os << " PathIndex" << Kind; |
| 454 | os << "\">" << num << "</div>"; |
| 455 | os << "</td><td>"; |
| 456 | } |
| 457 | |
| 458 | if (const PathDiagnosticMacroPiece *MP = |
| 459 | dyn_cast<PathDiagnosticMacroPiece>(&P)) { |
| 460 | |
| 461 | os << "Within the expansion of the macro '"; |
Ted Kremenek | a6aa83e | 2008-09-21 18:52:59 +0000 | [diff] [blame] | 462 | |
Ted Kremenek | 0e5c8d4 | 2009-03-10 05:16:17 +0000 | [diff] [blame] | 463 | // Get the name of the macro by relexing it. |
| 464 | { |
Ted Kremenek | 5fb5dfb | 2009-04-01 06:13:56 +0000 | [diff] [blame] | 465 | FullSourceLoc L = MP->getLocation().asLocation().getInstantiationLoc(); |
Ted Kremenek | 0e5c8d4 | 2009-03-10 05:16:17 +0000 | [diff] [blame] | 466 | assert(L.isFileID()); |
| 467 | std::pair<const char*, const char*> BufferInfo = L.getBufferData(); |
| 468 | const char* MacroName = L.getDecomposedLoc().second + BufferInfo.first; |
| 469 | Lexer rawLexer(L, PP->getLangOptions(), BufferInfo.first, |
| 470 | MacroName, BufferInfo.second); |
| 471 | |
| 472 | Token TheTok; |
| 473 | rawLexer.LexFromRawLexer(TheTok); |
| 474 | for (unsigned i = 0, n = TheTok.getLength(); i < n; ++i) |
| 475 | os << MacroName[i]; |
Ted Kremenek | 80bae76 | 2009-03-02 23:05:40 +0000 | [diff] [blame] | 476 | } |
Ted Kremenek | 0e5c8d4 | 2009-03-10 05:16:17 +0000 | [diff] [blame] | 477 | |
| 478 | os << "':\n"; |
Ted Kremenek | 80bae76 | 2009-03-02 23:05:40 +0000 | [diff] [blame] | 479 | |
Ted Kremenek | 0e5c8d4 | 2009-03-10 05:16:17 +0000 | [diff] [blame] | 480 | if (max > 1) |
Ted Kremenek | 80bae76 | 2009-03-02 23:05:40 +0000 | [diff] [blame] | 481 | os << "</td></tr></table>"; |
Ted Kremenek | 0e5c8d4 | 2009-03-10 05:16:17 +0000 | [diff] [blame] | 482 | |
| 483 | // Within a macro piece. Write out each event. |
| 484 | ProcessMacroPiece(os, *MP, 0); |
| 485 | } |
| 486 | else { |
| 487 | os << html::EscapeText(P.getString()); |
Ted Kremenek | 80bae76 | 2009-03-02 23:05:40 +0000 | [diff] [blame] | 488 | |
Ted Kremenek | 0e5c8d4 | 2009-03-10 05:16:17 +0000 | [diff] [blame] | 489 | if (max > 1) |
| 490 | os << "</td></tr></table>"; |
Ted Kremenek | a6aa83e | 2008-09-21 18:52:59 +0000 | [diff] [blame] | 491 | } |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 492 | |
Ted Kremenek | 0e5c8d4 | 2009-03-10 05:16:17 +0000 | [diff] [blame] | 493 | os << "</div></td></tr>"; |
| 494 | |
| 495 | // Insert the new html. |
| 496 | unsigned DisplayPos = LineEnd - FileStart; |
| 497 | SourceLocation Loc = |
| 498 | SM.getLocForStartOfFile(LPosInfo.first).getFileLocWithOffset(DisplayPos); |
| 499 | |
| 500 | R.InsertStrBefore(Loc, os.str()); |
| 501 | |
| 502 | // Now highlight the ranges. |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 503 | for (const SourceRange *I = P.ranges_begin(), *E = P.ranges_end(); |
| 504 | I != E; ++I) |
Chris Lattner | 7da5aea | 2009-02-04 00:55:58 +0000 | [diff] [blame] | 505 | HighlightRange(R, LPosInfo.first, *I); |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 506 | |
| 507 | #if 0 |
| 508 | // If there is a code insertion hint, insert that code. |
| 509 | // FIXME: This code is disabled because it seems to mangle the HTML |
| 510 | // output. I'm leaving it here because it's generally the right idea, |
| 511 | // but needs some help from someone more familiar with the rewriter. |
| 512 | for (const CodeModificationHint *Hint = P.code_modifications_begin(), |
| 513 | *HintEnd = P.code_modifications_end(); |
| 514 | Hint != HintEnd; ++Hint) { |
| 515 | if (Hint->RemoveRange.isValid()) { |
| 516 | HighlightRange(R, LPosInfo.first, Hint->RemoveRange, |
| 517 | "<span class=\"CodeRemovalHint\">", "</span>"); |
| 518 | } |
| 519 | if (Hint->InsertionLoc.isValid()) { |
| 520 | std::string EscapedCode = html::EscapeText(Hint->CodeToInsert, true); |
| 521 | EscapedCode = "<span class=\"CodeInsertionHint\">" + EscapedCode |
| 522 | + "</span>"; |
| 523 | R.InsertStrBefore(Hint->InsertionLoc, EscapedCode); |
| 524 | } |
| 525 | } |
| 526 | #endif |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Ted Kremenek | 0e5c8d4 | 2009-03-10 05:16:17 +0000 | [diff] [blame] | 529 | static void EmitAlphaCounter(llvm::raw_ostream& os, unsigned n) { |
| 530 | llvm::SmallVector<char, 10> buf; |
| 531 | |
| 532 | do { |
| 533 | unsigned x = n % ('z' - 'a'); |
| 534 | buf.push_back('a' + x); |
| 535 | n = n / ('z' - 'a'); |
| 536 | } while (n); |
| 537 | |
| 538 | assert(!buf.empty()); |
| 539 | |
| 540 | for (llvm::SmallVectorImpl<char>::reverse_iterator I=buf.rbegin(), |
| 541 | E=buf.rend(); I!=E; ++I) |
| 542 | os << *I; |
| 543 | } |
| 544 | |
| 545 | unsigned HTMLDiagnostics::ProcessMacroPiece(llvm::raw_ostream& os, |
| 546 | const PathDiagnosticMacroPiece& P, |
| 547 | unsigned num) { |
| 548 | |
| 549 | for (PathDiagnosticMacroPiece::const_iterator I=P.begin(), E=P.end(); |
| 550 | I!=E; ++I) { |
| 551 | |
| 552 | if (const PathDiagnosticMacroPiece *MP = |
| 553 | dyn_cast<PathDiagnosticMacroPiece>(*I)) { |
| 554 | num = ProcessMacroPiece(os, *MP, num); |
| 555 | continue; |
| 556 | } |
| 557 | |
| 558 | if (PathDiagnosticEventPiece *EP = dyn_cast<PathDiagnosticEventPiece>(*I)) { |
| 559 | os << "<div class=\"msg msgEvent\" style=\"width:94%; " |
| 560 | "margin-left:5px\">" |
| 561 | "<table class=\"msgT\"><tr>" |
| 562 | "<td valign=\"top\"><div class=\"PathIndex PathIndexEvent\">"; |
| 563 | EmitAlphaCounter(os, num++); |
| 564 | os << "</div></td><td valign=\"top\">" |
| 565 | << html::EscapeText(EP->getString()) |
| 566 | << "</td></tr></table></div>\n"; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | return num; |
| 571 | } |
| 572 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 573 | void HTMLDiagnostics::HighlightRange(Rewriter& R, FileID BugFileID, |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 574 | SourceRange Range, |
| 575 | const char *HighlightStart, |
| 576 | const char *HighlightEnd) { |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 577 | |
Ted Kremenek | 5dd0041 | 2008-04-14 21:06:04 +0000 | [diff] [blame] | 578 | SourceManager& SM = R.getSourceMgr(); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 579 | |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 580 | SourceLocation InstantiationStart = SM.getInstantiationLoc(Range.getBegin()); |
Chris Lattner | 30fc933 | 2009-02-04 01:06:56 +0000 | [diff] [blame] | 581 | unsigned StartLineNo = SM.getInstantiationLineNumber(InstantiationStart); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 582 | |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 583 | SourceLocation InstantiationEnd = SM.getInstantiationLoc(Range.getEnd()); |
Chris Lattner | 30fc933 | 2009-02-04 01:06:56 +0000 | [diff] [blame] | 584 | unsigned EndLineNo = SM.getInstantiationLineNumber(InstantiationEnd); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 585 | |
| 586 | if (EndLineNo < StartLineNo) |
| 587 | return; |
| 588 | |
Chris Lattner | a11d617 | 2009-01-19 07:46:45 +0000 | [diff] [blame] | 589 | if (SM.getFileID(InstantiationStart) != BugFileID || |
| 590 | SM.getFileID(InstantiationEnd) != BugFileID) |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 591 | return; |
| 592 | |
| 593 | // Compute the column number of the end. |
Chris Lattner | 7da5aea | 2009-02-04 00:55:58 +0000 | [diff] [blame] | 594 | unsigned EndColNo = SM.getInstantiationColumnNumber(InstantiationEnd); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 595 | unsigned OldEndColNo = EndColNo; |
| 596 | |
| 597 | if (EndColNo) { |
| 598 | // Add in the length of the token, so that we cover multi-char tokens. |
Ted Kremenek | 12fc014 | 2008-04-18 05:01:33 +0000 | [diff] [blame] | 599 | EndColNo += Lexer::MeasureTokenLength(Range.getEnd(), SM) - 1; |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | // Highlight the range. Make the span tag the outermost tag for the |
| 603 | // selected range. |
Ted Kremenek | dab4ead | 2008-04-08 21:29:14 +0000 | [diff] [blame] | 604 | |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 605 | SourceLocation E = |
| 606 | InstantiationEnd.getFileLocWithOffset(EndColNo - OldEndColNo); |
Ted Kremenek | b747814 | 2008-04-17 18:37:23 +0000 | [diff] [blame] | 607 | |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 608 | html::HighlightRange(R, InstantiationStart, E, HighlightStart, HighlightEnd); |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 609 | } |