1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #pragma once
27 
28 #include "sourcerangecontainer.h"
29 #include "fixitcontainer.h"
30 
31 #include <QDataStream>
32 #include <QVector>
33 
34 #include <utility>
35 
36 namespace ClangBackEnd {
37 
38 class DiagnosticContainer
39 {
40 public:
41     DiagnosticContainer() = default;
DiagnosticContainer(const Utf8String & text,const Utf8String & category,const std::pair<Utf8String,Utf8String> & options,DiagnosticSeverity severity,const SourceLocationContainer & location,const QVector<SourceRangeContainer> & ranges,const QVector<FixItContainer> & fixIts,const QVector<DiagnosticContainer> & children)42     DiagnosticContainer(const Utf8String &text,
43                         const Utf8String &category,
44                         const std::pair<Utf8String,Utf8String> &options,
45                         DiagnosticSeverity severity,
46                         const SourceLocationContainer &location,
47                         const QVector<SourceRangeContainer> &ranges,
48                         const QVector<FixItContainer> &fixIts,
49                         const QVector<DiagnosticContainer> &children)
50         : location(location),
51           ranges(ranges),
52           text(text),
53           category(category),
54           enableOption(options.first),
55           disableOption(options.second),
56           children(children),
57           fixIts(fixIts),
58           severity(severity)
59     {
60         for (auto it = this->children.begin(); it != this->children.end(); ++it) {
61             if (it->text == "note: remove constant to silence this warning") {
62                 this->children.erase(it);
63                 break;
64             }
65         }
66     }
67 
68     friend QDataStream &operator<<(QDataStream &out, const DiagnosticContainer &container)
69     {
70         out << container.text;
71         out << container.category;
72         out << container.enableOption;
73         out << container.disableOption;
74         out << container.location;
75         out << static_cast<quint32>(container.severity);
76         out << container.ranges;
77         out << container.fixIts;
78         out << container.children;
79 
80         return out;
81     }
82 
83     friend QDataStream &operator>>(QDataStream &in, DiagnosticContainer &container)
84     {
85         quint32 severity;
86 
87         in >> container.text;
88         in >> container.category;
89         in >> container.enableOption;
90         in >> container.disableOption;
91         in >> container.location;
92         in >> severity;
93         in >> container.ranges;
94         in >> container.fixIts;
95         in >> container.children;
96 
97         container.severity = static_cast<DiagnosticSeverity>(severity);
98 
99         return in;
100     }
101 
102     friend bool operator==(const DiagnosticContainer &first, const DiagnosticContainer &second)
103     {
104         return first.text == second.text
105             && first.location == second.location;
106     }
107 
108     friend bool operator!=(const DiagnosticContainer &first, const DiagnosticContainer &second)
109     {
110         return !(first == second);
111     }
112 
113 public:
114     SourceLocationContainer location;
115     QVector<SourceRangeContainer> ranges;
116     Utf8String text;
117     Utf8String category;
118     Utf8String enableOption;
119     Utf8String disableOption;
120     QVector<DiagnosticContainer> children;
121     QVector<FixItContainer> fixIts;
122     DiagnosticSeverity severity = DiagnosticSeverity::Ignored;
123 };
124 
125 CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const DiagnosticContainer &container);
126 
127 } // namespace ClangBackEnd
128