]> granicus.if.org Git - clang/commitdiff
Added HTML highlighting for ranges.
authorTed Kremenek <kremenek@apple.com>
Wed, 19 Mar 2008 23:55:53 +0000 (23:55 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 19 Mar 2008 23:55:53 +0000 (23:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48572 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/HTMLPrint.cpp
lib/Rewrite/HTMLRewrite.cpp

index a6b90fafdfff3fa5e948c7df2df314ed68d273cf..b30f1e80ef2f53f63e7c529bb89439505744355e 100644 (file)
@@ -154,10 +154,16 @@ void HTMLDiagnostic::HandleDiagnostic(Diagnostic &Diags,
   if (!Pos.isValid())
     return;  
   
+  SourceManager& SM = R.getSourceMgr();
+  
   FullSourceLoc LPos = Pos.getLogicalLoc();
   unsigned FileID = LPos.getLocation().getFileID();
   
-  if (FileID != LPos.getManager().getMainFileID())
+  assert (&LPos.getManager() == &SM && "SourceManagers are different!");
+  
+  unsigned MainFileID = SM.getMainFileID();
+  
+  if (FileID != MainFileID)
     return;
   
   
@@ -202,9 +208,33 @@ void HTMLDiagnostic::HandleDiagnostic(Diagnostic &Diags,
   
   // Insert the new html.
   
-  const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FileID);
+  const llvm::MemoryBuffer *Buf = SM.getBuffer(FileID);
   const char* FileStart = Buf->getBufferStart();
   
   R.InsertStrBefore(SourceLocation::getFileLoc(FileID, LineStart - FileStart),
                     os.str());
+  
+  // Now highlight the ranges.
+  
+  for (unsigned i = 0; i < NumRanges; ++i) {
+    
+    SourceLocation B = SM.getLogicalLoc(Ranges->getBegin());
+    SourceLocation E = SM.getLogicalLoc(Ranges->getEnd());
+    
+    // We do this because the position seems to point to the beginning of
+    // the last character.  FIXME: Is this what is suppose to happen?
+    std::pair<unsigned,unsigned> X = SM.getDecomposedFileLoc(E);
+    E = SourceLocation::getFileLoc(X.first, X.second+1);
+
+    ++Ranges;
+    
+    if (B.getFileID() != MainFileID || E.getFileID() != MainFileID)
+      continue;
+    
+    // Highlight the range.  Make the span tag the outermost tag for the
+    // selected range.
+    R.InsertCStrBefore(B, "<span class=\"mrange\">");
+    R.InsertCStrAfter(E, "</span>");
+  }
+  
 }
index 76c44b718cf30337e9902b52c92ecfe79795f01f..788b41bd0ea7b647e97f6a9494b0f762fdd804f5 100644 (file)
@@ -143,6 +143,7 @@ void html::AddHeaderFooterInternalBuiltinCSS(Rewriter& R, unsigned FileID) {
        << " .code { line-height: 1.2em }\n"
        << " .num { width:2.5em; padding-right:2ex; background-color:#eeeeee }\n"
        << " .num { text-align:right; font-size: smaller }\n"
+       << " .num { color:#444444 }\n"
        << " .line { padding-left: 1ex; border-left: 3px solid #ccc }\n"
        << " .line { white-space: pre }\n"
        << " .msg { background-color:#ff8000; color:#000000 }\n"
@@ -152,6 +153,8 @@ void html::AddHeaderFooterInternalBuiltinCSS(Rewriter& R, unsigned FileID) {
        << " .msg { float:left }\n"
        << " .msg { padding:0.5em 1ex 0.5em 1ex }\n"
        << " .msg { margin-top:10px; margin-bottom:10px }\n"
+       << " .mrange { color:#ff8000 }\n"
+       << " .mrange { border-bottom: 1px dotted #ff8000 }\n"
        << "</style>\n</head>\n<body>";
     
     R.InsertStrBefore(StartLoc, os.str());