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