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