| OLD | NEW |
| 1 //===--- Diagnostic.cpp - C Language Family Diagnostic Handling -----------===// | 1 //===--- Diagnostic.cpp - C Language Family Diagnostic Handling -----------===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This file implements the Diagnostic-related interfaces. | 10 // This file implements the Diagnostic-related interfaces. |
| (...skipping 19 matching lines...) Loading... |
| 30 SmallVectorImpl<intptr_t> &QualTypeVals) { | 30 SmallVectorImpl<intptr_t> &QualTypeVals) { |
| 31 const char *Str = "<can't format argument>"; | 31 const char *Str = "<can't format argument>"; |
| 32 Output.append(Str, Str+strlen(Str)); | 32 Output.append(Str, Str+strlen(Str)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 | 35 |
| 36 DiagnosticsEngine::DiagnosticsEngine( | 36 DiagnosticsEngine::DiagnosticsEngine( |
| 37 const llvm::IntrusiveRefCntPtr<DiagnosticIDs> &diags, | 37 const llvm::IntrusiveRefCntPtr<DiagnosticIDs> &diags, |
| 38 DiagnosticConsumer *client, bool ShouldOwnClient) | 38 DiagnosticConsumer *client, bool ShouldOwnClient) |
| 39 : Diags(diags), Client(client), OwnsDiagClient(ShouldOwnClient), | 39 : Diags(diags), Client(client), OwnsDiagClient(ShouldOwnClient), |
| 40 SourceMgr(0) { | 40 SourceMgr(0), FromType(0), ToType(0) { |
| 41 ArgToStringFn = DummyArgToStringFn; | 41 ArgToStringFn = DummyArgToStringFn; |
| 42 ArgToStringCookie = 0; | 42 ArgToStringCookie = 0; |
| 43 | 43 |
| 44 AllExtensionsSilenced = 0; | 44 AllExtensionsSilenced = 0; |
| 45 IgnoreAllWarnings = false; | 45 IgnoreAllWarnings = false; |
| 46 WarningsAsErrors = false; | 46 WarningsAsErrors = false; |
| 47 EnableAllWarnings = false; | 47 EnableAllWarnings = false; |
| 48 ErrorsAsFatal = false; | 48 ErrorsAsFatal = false; |
| 49 SuppressSystemWarnings = false; | 49 SuppressSystemWarnings = false; |
| 50 SuppressAllDiagnostics = false; | 50 SuppressAllDiagnostics = false; |
| 51 ElideType = true; |
| 52 PrintTemplateTree = false; |
| 53 ShowColors = false; |
| 51 ShowOverloads = Ovl_All; | 54 ShowOverloads = Ovl_All; |
| 52 ExtBehavior = Ext_Ignore; | 55 ExtBehavior = Ext_Ignore; |
| 53 | 56 |
| 54 ErrorLimit = 0; | 57 ErrorLimit = 0; |
| 55 TemplateBacktraceLimit = 0; | 58 TemplateBacktraceLimit = 0; |
| 56 | 59 |
| 57 Reset(); | 60 Reset(); |
| 58 } | 61 } |
| 59 | 62 |
| 60 DiagnosticsEngine::~DiagnosticsEngine() { | 63 DiagnosticsEngine::~DiagnosticsEngine() { |
| (...skipping 560 matching lines...) | | Loading... |
| 621 SmallVectorImpl<char> &OutStr) const { | 624 SmallVectorImpl<char> &OutStr) const { |
| 622 | 625 |
| 623 /// FormattedArgs - Keep track of all of the arguments formatted by | 626 /// FormattedArgs - Keep track of all of the arguments formatted by |
| 624 /// ConvertArgToString and pass them into subsequent calls to | 627 /// ConvertArgToString and pass them into subsequent calls to |
| 625 /// ConvertArgToString, allowing the implementation to avoid redundancies in | 628 /// ConvertArgToString, allowing the implementation to avoid redundancies in |
| 626 /// obvious cases. | 629 /// obvious cases. |
| 627 SmallVector<DiagnosticsEngine::ArgumentValue, 8> FormattedArgs; | 630 SmallVector<DiagnosticsEngine::ArgumentValue, 8> FormattedArgs; |
| 628 | 631 |
| 629 /// QualTypeVals - Pass a vector of arrays so that QualType names can be | 632 /// QualTypeVals - Pass a vector of arrays so that QualType names can be |
| 630 /// compared to see if more information is needed to be printed. | 633 /// compared to see if more information is needed to be printed. |
| 634 SmallVector<char, 10> Tree; |
| 631 SmallVector<intptr_t, 2> QualTypeVals; | 635 SmallVector<intptr_t, 2> QualTypeVals; |
| 636 |
| 637 // When there is a type difference, put the two types at the first two |
| 638 // indices of QualTypeVals. |
| 639 if (getFromDiffType()) QualTypeVals.push_back(getFromDiffType());· |
| 640 if (getToDiffType()) QualTypeVals.push_back(getToDiffType());· |
| 632 for (unsigned i = 0, e = getNumArgs(); i < e; ++i) | 641 for (unsigned i = 0, e = getNumArgs(); i < e; ++i) |
| 633 if (getArgKind(i) == DiagnosticsEngine::ak_qualtype) | 642 if (getArgKind(i) == DiagnosticsEngine::ak_qualtype) |
| 634 QualTypeVals.push_back(getRawArg(i)); | 643 QualTypeVals.push_back(getRawArg(i)); |
| 635 | 644 |
| 636 while (DiagStr != DiagEnd) { | 645 while (DiagStr != DiagEnd) { |
| 637 if (DiagStr[0] != '%') { | 646 if (DiagStr[0] != '%') { |
| 638 // Append non-%0 substrings to Str if we have one. | 647 // Append non-%0 substrings to Str if we have one. |
| 639 const char *StrEnd = std::find(DiagStr, DiagEnd, '%'); | 648 const char *StrEnd = std::find(DiagStr, DiagEnd, '%'); |
| 640 OutStr.append(DiagStr, StrEnd); | 649 OutStr.append(DiagStr, StrEnd); |
| 641 DiagStr = StrEnd; | 650 DiagStr = StrEnd; |
| (...skipping 116 matching lines...) | | Loading... |
| 758 case DiagnosticsEngine::ak_declarationname: | 767 case DiagnosticsEngine::ak_declarationname: |
| 759 case DiagnosticsEngine::ak_nameddecl: | 768 case DiagnosticsEngine::ak_nameddecl: |
| 760 case DiagnosticsEngine::ak_nestednamespec: | 769 case DiagnosticsEngine::ak_nestednamespec: |
| 761 case DiagnosticsEngine::ak_declcontext: | 770 case DiagnosticsEngine::ak_declcontext: |
| 762 getDiags()->ConvertArgToString(Kind, getRawArg(ArgNo), | 771 getDiags()->ConvertArgToString(Kind, getRawArg(ArgNo), |
| 763 Modifier, ModifierLen, | 772 Modifier, ModifierLen, |
| 764 Argument, ArgumentLen, | 773 Argument, ArgumentLen, |
| 765 FormattedArgs.data(), FormattedArgs.size(), | 774 FormattedArgs.data(), FormattedArgs.size(), |
| 766 OutStr, QualTypeVals); | 775 OutStr, QualTypeVals); |
| 767 break; | 776 break; |
| 777 case DiagnosticsEngine::ak_qualtype_pair: |
| 778 assert(QualTypeVals.size() >= 2 && "Missing types to compare"); |
| 779 assert(ModifierIs(Modifier, ModifierLen, "diff") && |
| 780 "A QualType pair can only be used with a diff modifier"); |
| 781 |
| 782 bool ElideType = getDiags()->ElideType; |
| 783 bool ShowColor = getDiags()->ShowColors; |
| 784 // For template diffing, the· |
| 785 intptr_t val; |
| 786 |
| 787 // Print the tree. |
| 788 if (getDiags()->PrintTemplateTree) { |
| 789 val = TD_PrintTree | (ElideType ? TD_ElideType : 0) | |
| 790 (ShowColor ? TD_ShowColors : 0); |
| 791 getDiags()->ConvertArgToString(Kind, val, |
| 792 Modifier, ModifierLen, |
| 793 Argument, ArgumentLen, |
| 794 FormattedArgs.data(), |
| 795 FormattedArgs.size(), |
| 796 Tree, QualTypeVals); |
| 797 // If there is no tree information, fall back to regular printing. |
| 798 if (!Tree.empty()) |
| 799 break; |
| 800 } |
| 801 |
| 802 // Non-tree printing, also the fall-back when tree printing fails. |
| 803 // The fall-back is triggered when the types compared are not templates. |
| 804 const char *ArgumentEnd = Argument + ArgumentLen; |
| 805 const char *FirstPipe = ScanFormat(Argument, ArgumentEnd, '|'); |
| 806 const char *SecondPipe = ScanFormat(FirstPipe + 1, ArgumentEnd, '|'); |
| 807 |
| 808 // Append before text |
| 809 FormatDiagnostic(Argument, FirstPipe, OutStr); |
| 810 |
| 811 // Append first type |
| 812 val = TD_PrintFromType | (ElideType ? TD_ElideType : 0) | |
| 813 (ShowColor ? TD_ShowColors : 0); |
| 814 getDiags()->ConvertArgToString(Kind, val, |
| 815 Modifier, ModifierLen, |
| 816 Argument, ArgumentLen, |
| 817 FormattedArgs.data(), FormattedArgs.size(), |
| 818 OutStr, QualTypeVals); |
| 819 // Append middle text |
| 820 FormatDiagnostic(FirstPipe + 1, SecondPipe, OutStr); |
| 821 |
| 822 // Append second type |
| 823 val = (ElideType ? TD_ElideType : 0) | (ShowColor ? TD_ShowColors : 0); |
| 824 getDiags()->ConvertArgToString(Kind, val, |
| 825 Modifier, ModifierLen, |
| 826 Argument, ArgumentLen, |
| 827 FormattedArgs.data(), FormattedArgs.size(), |
| 828 OutStr, QualTypeVals); |
| 829 // Append end text |
| 830 FormatDiagnostic(SecondPipe + 1, ArgumentEnd, OutStr); |
| 831 break; |
| 768 } | 832 } |
| 769 ···· | 833 ···· |
| 770 // Remember this argument info for subsequent formatting operations. Turn | 834 // Remember this argument info for subsequent formatting operations. Turn |
| 771 // std::strings into a null terminated string to make it be the same case as | 835 // std::strings into a null terminated string to make it be the same case as |
| 772 // all the other ones. | 836 // all the other ones. |
| 773 if (Kind != DiagnosticsEngine::ak_std_string) | 837 if (Kind == DiagnosticsEngine::ak_qualtype_pair) |
| 838 continue; |
| 839 else if (Kind != DiagnosticsEngine::ak_std_string) |
| 774 FormattedArgs.push_back(std::make_pair(Kind, getRawArg(ArgNo))); | 840 FormattedArgs.push_back(std::make_pair(Kind, getRawArg(ArgNo))); |
| 775 else | 841 else |
| 776 FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_c_string, | 842 FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_c_string, |
| 777 (intptr_t)getArgStdStr(ArgNo).c_str())); | 843 (intptr_t)getArgStdStr(ArgNo).c_str())); |
| 778 ···· | 844 ···· |
| 779 } | 845 } |
| 846 |
| 847 // Append the type tree to the end of the diagnostics. |
| 848 OutStr.append(Tree.begin(), Tree.end()); |
| 780 } | 849 } |
| 781 | 850 |
| 782 StoredDiagnostic::StoredDiagnostic() { } | 851 StoredDiagnostic::StoredDiagnostic() { } |
| 783 | 852 |
| 784 StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID, | 853 StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID, |
| 785 StringRef Message) | 854 StringRef Message) |
| 786 : ID(ID), Level(Level), Loc(), Message(Message) { } | 855 : ID(ID), Level(Level), Loc(), Message(Message) { } |
| 787 | 856 |
| 788 StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level,· | 857 StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level,· |
| 789 const Diagnostic &Info) | 858 const Diagnostic &Info) |
| (...skipping 38 matching lines...) | | Loading... |
| 828 for (unsigned I = 0; I != NumCached; ++I) | 897 for (unsigned I = 0; I != NumCached; ++I) |
| 829 FreeList[I] = Cached + I; | 898 FreeList[I] = Cached + I; |
| 830 NumFreeListEntries = NumCached; | 899 NumFreeListEntries = NumCached; |
| 831 } | 900 } |
| 832 | 901 |
| 833 PartialDiagnostic::StorageAllocator::~StorageAllocator() { | 902 PartialDiagnostic::StorageAllocator::~StorageAllocator() { |
| 834 // Don't assert if we are in a CrashRecovery context, as this | 903 // Don't assert if we are in a CrashRecovery context, as this |
| 835 // invariant may be invalidated during a crash. | 904 // invariant may be invalidated during a crash. |
| 836 assert((NumFreeListEntries == NumCached || llvm::CrashRecoveryContext::isRecov
eringFromCrash()) && "A partial is on the lamb"); | 905 assert((NumFreeListEntries == NumCached || llvm::CrashRecoveryContext::isRecov
eringFromCrash()) && "A partial is on the lamb"); |
| 837 } | 906 } |
| OLD | NEW |