diff options
| author | Ted Kremenek <kremenek@apple.com> | 2008-09-21 18:52:59 +0000 | 
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2008-09-21 18:52:59 +0000 | 
| commit | 80b2b16540f3edf5bf6d8d80cc608345277ab5b7 (patch) | |
| tree | 3276396e09177eda5f835039841723802f91697b /clang/lib/Driver/HTMLDiagnostics.cpp | |
| parent | 43f5449c48be7d5af565685b9545185c429228d1 (diff) | |
| download | bcm5719-llvm-80b2b16540f3edf5bf6d8d80cc608345277ab5b7.tar.gz bcm5719-llvm-80b2b16540f3edf5bf6d8d80cc608345277ab5b7.zip | |
Added experimental "intelligent-sizing" of HTML message bubbles based on the contents of the message.
llvm-svn: 56400
Diffstat (limited to 'clang/lib/Driver/HTMLDiagnostics.cpp')
| -rw-r--r-- | clang/lib/Driver/HTMLDiagnostics.cpp | 112 | 
1 files changed, 77 insertions, 35 deletions
| diff --git a/clang/lib/Driver/HTMLDiagnostics.cpp b/clang/lib/Driver/HTMLDiagnostics.cpp index 22d3da9320e..c9739c40816 100644 --- a/clang/lib/Driver/HTMLDiagnostics.cpp +++ b/clang/lib/Driver/HTMLDiagnostics.cpp @@ -378,42 +378,84 @@ void HTMLDiagnostics::HandlePiece(Rewriter& R, unsigned BugFileID,      PosNo += *c == '\t' ? 8 : 1;    // Create the html for the message. -   -  std::string s; -  llvm::raw_string_ostream os(s); -   -  os << "\n<tr><td class=\"num\"></td><td class=\"line\">" -     << "<div id=\""; -   -  if (num == max) -    os << "EndPath"; -  else -    os << "Path" << num; -   -  os << "\" class=\"msg\" style=\"margin-left:" -     << PosNo << "ex\">"; -   -  if (max > 1) -    os << "<span class=\"PathIndex\">[" << num << "]</span> "; -   -  os << html::EscapeText(P.getString()) << "</div></td></tr>"; -   -  // Insert the new html. -   -  unsigned DisplayPos = 0; -   -  switch (P.getDisplayHint()) { -    case PathDiagnosticPiece::Above: -      DisplayPos = LineStart - FileStart; -      break; -    case PathDiagnosticPiece::Below: -      DisplayPos = LineEnd - FileStart; -      break; -    default: -      assert (false && "Unhandled hint."); -  } +  { +    // Get the string and determining its maximum substring. +    const std::string& Msg = P.getString(); +    unsigned max_token = 0; +    unsigned cnt = 0; +    unsigned len = Msg.size(); +     +    for (std::string::const_iterator I=Msg.begin(), E=Msg.end(); I!=E; ++I) +      switch (*I) { +        default: +          ++cnt; +          continue;           +        case ' ': +        case '\t': +        case '\n': +          if (cnt > max_token) max_token = cnt; +          cnt = 0; +      } +     +    if (cnt > max_token) max_token = cnt; +     +    // Next, determine the approximate size of the message bubble in em. +    unsigned em; +    const unsigned max_line = 80; +     +    if (max_token >= max_line) +      em = max_token / 2; +    else { +      unsigned characters = max_line; +      unsigned lines = len / max_line; +       +      if (lines > 0) { +        for (; characters > max_token; --characters) +          if (len / characters > lines) { +            ++characters; +            break; +          } +      } +       +      em = characters / 2; +    } +     +    // Now generate the message bubble.     +    std::string s; +    llvm::raw_string_ostream os(s); +     +    os << "\n<tr><td class=\"num\"></td><td class=\"line\"><div id=\""; +     +    if (num == max) +      os << "EndPath"; +    else +      os << "Path" << num; -  R.InsertStrBefore(SourceLocation::getFileLoc(FileID, DisplayPos), os.str()); +    os << "\" class=\"msg\" style=\"margin-left:" << PosNo << "ex"; +    if (em < max_line/2) os << "; max-width:" << em << "em"; +    os << "\">"; +     +    if (max > 1) +      os << "<span class=\"PathIndex\">[" << num << "]</span> "; +     +    os << html::EscapeText(Msg) << "</div></td></tr>"; + +    // Insert the new html. +    unsigned DisplayPos = 0; +     +    switch (P.getDisplayHint()) { +      case PathDiagnosticPiece::Above: +        DisplayPos = LineStart - FileStart; +        break; +      case PathDiagnosticPiece::Below: +        DisplayPos = LineEnd - FileStart; +        break; +      default: +        assert (false && "Unhandled hint."); +    } +       +    R.InsertStrBefore(SourceLocation::getFileLoc(FileID, DisplayPos), os.str()); +  }    // Now highlight the ranges. | 

