| 449 | static bool isNonASCII(char c) { return c & 0x80; } |
| 450 | |
| 451 | void SMDiagnostic::print(const char *ProgName, raw_ostream &OS, bool ShowColors, |
| 452 | bool ShowKindLabel) const { |
| 453 | { |
| 454 | WithColor S(OS, raw_ostream::SAVEDCOLOR, true, false, !ShowColors); |
| 455 | |
| 456 | if (ProgName && ProgName[0]) |
| 457 | S << ProgName << ": "; |
| 458 | |
| 459 | if (!Filename.empty()) { |
| 460 | if (Filename == "-") |
| 461 | S << "<stdin>"; |
| 462 | else |
| 463 | S << Filename; |
| 464 | |
| 465 | if (LineNo != -1) { |
| 466 | S << ':' << LineNo; |
| 467 | if (ColumnNo != -1) |
| 468 | S << ':' << (ColumnNo + 1); |
| 469 | } |
| 470 | S << ": "; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | if (ShowKindLabel) { |
| 475 | switch (Kind) { |
| 476 | case SourceMgr::DK_Error: |
| 477 | WithColor::error(OS, "", !ShowColors); |
| 478 | break; |
| 479 | case SourceMgr::DK_Warning: |
| 480 | WithColor::warning(OS, "", !ShowColors); |
| 481 | break; |
| 482 | case SourceMgr::DK_Note: |
| 483 | WithColor::note(OS, "", !ShowColors); |
| 484 | break; |
| 485 | case SourceMgr::DK_Remark: |
| 486 | WithColor::remark(OS, "", !ShowColors); |
| 487 | break; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | WithColor(OS, raw_ostream::SAVEDCOLOR, true, false, !ShowColors) |
| 492 | << Message << '\n'; |
| 493 | |
| 494 | if (LineNo == -1 || ColumnNo == -1) |
| 495 | return; |
| 496 | |
| 497 | // FIXME: If there are multibyte or multi-column characters in the source, all |
| 498 | // our ranges will be wrong. To do this properly, we'll need a byte-to-column |
| 499 | // map like Clang's TextDiagnostic. For now, we'll just handle tabs by |
| 500 | // expanding them later, and bail out rather than show incorrect ranges and |
| 501 | // misaligned fixits for any other odd characters. |
| 502 | if (find_if(LineContents, isNonASCII) != LineContents.end()) { |
| 503 | printSourceLine(OS, LineContents); |
| 504 | return; |
| 505 | } |
| 506 | size_t NumColumns = LineContents.size(); |
| 507 | |
| 508 | // Build the line with the caret and ranges. |
no test coverage detected