• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdevelop API Reference
  • KDE Home
  • Contact Us
 

kdevplatform/language/duchain

  • sources
  • kfour-appscomplete
  • kdevelop
  • kdevplatform
  • language
  • duchain
problem.cpp
Go to the documentation of this file.
1 /* This file is part of KDevelop
2  Copyright 2007 Hamish Rodda <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18  */
19 
20 #include "problem.h"
21 
22 #include "duchainregister.h"
23 #include "topducontextdynamicdata.h"
24 #include "topducontext.h"
25 #include "topducontextdata.h"
26 #include "duchain.h"
27 #include "duchainlock.h"
28 
29 #include <editor/documentrange.h>
30 
31 #include <interfaces/iassistant.h>
32 
33 #include <KLocalizedString>
34 
35 namespace KDevelop {
36 REGISTER_DUCHAIN_ITEM(Problem);
37 DEFINE_LIST_MEMBER_HASH(ProblemData, diagnostics, LocalIndexedProblem)
38 }
39 
40 using namespace KDevelop;
41 
42 LocalIndexedProblem::LocalIndexedProblem(const ProblemPointer& problem, const TopDUContext* top)
43  : m_index(problem->m_indexInTopContext)
44 {
45  ENSURE_CHAIN_READ_LOCKED
46  // ensure child problems are properly serialized before we serialize the parent problem
47  // see below, the diagnostic size is kept in sync by the mutable API of Problem
48  // the const cast is ugly but we don't really "change" the state as observed from the outside
49  auto& serialized = const_cast<Problem*>(problem.data())->d_func_dynamic()->diagnosticsList();
50  serialized.clear();
51  serialized.reserve(problem->m_diagnostics.size());
52  for (const ProblemPointer& child : qAsConst(problem->m_diagnostics)) {
53  serialized << LocalIndexedProblem(child, top);
54  }
55 
56  if (!m_index) {
57  m_index = top->m_dynamicData->allocateProblemIndex(problem);
58  }
59 }
60 
61 ProblemPointer LocalIndexedProblem::data(const TopDUContext* top) const
62 {
63  if (!m_index) {
64  return {};
65  }
66  return top->m_dynamicData->problemForIndex(m_index);
67 }
68 
69 Problem::Problem()
70  : DUChainBase(*new ProblemData)
71 {
72  d_func_dynamic()->setClassId(this);
73 }
74 
75 Problem::Problem(ProblemData& data)
76  : DUChainBase(data)
77 {
78 }
79 
80 Problem::~Problem()
81 {
82 }
83 
84 TopDUContext* Problem::topContext() const
85 {
86  return m_topContext.data();
87 }
88 
89 IndexedString Problem::url() const
90 {
91  return d_func()->url;
92 }
93 
94 DocumentRange Problem::finalLocation() const
95 {
96  return DocumentRange(d_func()->url, d_func()->m_range.castToSimpleRange());
97 }
98 
99 void Problem::setFinalLocation(const DocumentRange& location)
100 {
101  setRange(RangeInRevision::castFromSimpleRange(location));
102  d_func_dynamic()->url = location.document;
103 }
104 
105 IProblem::FinalLocationMode Problem::finalLocationMode() const
106 {
107  return d_func()->finalLocationMode;
108 }
109 
110 void Problem::setFinalLocationMode(IProblem::FinalLocationMode mode)
111 {
112  d_func_dynamic()->finalLocationMode = mode;
113 }
114 
115 void Problem::clearDiagnostics()
116 {
117  m_diagnostics.clear();
118  // keep serialization in sync, see also LocalIndexedProblem ctor above
119  d_func_dynamic()->diagnosticsList().clear();
120 }
121 
122 QVector<IProblem::Ptr> Problem::diagnostics() const
123 {
124  QVector<IProblem::Ptr> vector;
125 
126  for (const auto& ptr : qAsConst(m_diagnostics)) {
127  vector.push_back(ptr);
128  }
129 
130  return vector;
131 }
132 
133 void Problem::setDiagnostics(const QVector<IProblem::Ptr>& diagnostics)
134 {
135  clearDiagnostics();
136 
137  for (const IProblem::Ptr& problem : diagnostics) {
138  addDiagnostic(problem);
139  }
140 }
141 
142 void Problem::addDiagnostic(const IProblem::Ptr& diagnostic)
143 {
144  auto* problem = dynamic_cast<Problem*>(diagnostic.data());
145  Q_ASSERT(problem != nullptr);
146 
147  ProblemPointer ptr(problem);
148 
149  m_diagnostics << ptr;
150 }
151 
152 QString Problem::description() const
153 {
154  return d_func()->description.str();
155 }
156 
157 void Problem::setDescription(const QString& description)
158 {
159  d_func_dynamic()->description = IndexedString(description);
160 }
161 
162 QString Problem::explanation() const
163 {
164  return d_func()->explanation.str();
165 }
166 
167 void Problem::setExplanation(const QString& explanation)
168 {
169  d_func_dynamic()->explanation = IndexedString(explanation);
170 }
171 
172 IProblem::Source Problem::source() const
173 {
174  return d_func()->source;
175 }
176 
177 void Problem::setSource(IProblem::Source source)
178 {
179  d_func_dynamic()->source = source;
180 }
181 
182 QExplicitlySharedDataPointer<IAssistant> Problem::solutionAssistant() const
183 {
184  return {};
185 }
186 
187 IProblem::Severity Problem::severity() const
188 {
189  return d_func()->severity;
190 }
191 
192 void Problem::setSeverity(Severity severity)
193 {
194  d_func_dynamic()->severity = severity;
195 }
196 
197 QString Problem::severityString() const
198 {
199  switch (severity()) {
200  case IProblem::NoSeverity:
201  return {};
202  case IProblem::Error:
203  return i18n("Error");
204  case IProblem::Warning:
205  return i18n("Warning");
206  case IProblem::Hint:
207  return i18n("Hint");
208  }
209  return QString();
210 }
211 
212 QString Problem::sourceString() const
213 {
214  switch (source()) {
215  case IProblem::Disk:
216  return i18n("Disk");
217  case IProblem::Preprocessor:
218  return i18n("Preprocessor");
219  case IProblem::Lexer:
220  return i18n("Lexer");
221  case IProblem::Parser:
222  return i18n("Parser");
223  case IProblem::DUChainBuilder:
224  return i18n("Definition-Use Chain");
225  case IProblem::SemanticAnalysis:
226  return i18n("Semantic analysis");
227  case IProblem::ToDo:
228  return i18n("To-do");
229  case IProblem::Unknown:
230  default:
231  return i18n("Unknown");
232  }
233 }
234 
235 QString Problem::toString() const
236 {
237  return i18nc("<severity>: <description> in <url>:[<range>]: <explanation> (found by <source>)",
238  "%1: %2 in %3:[(%4,%5),(%6,%7)]: %8 (found by %9)",
239  severityString(),
240  description(),
241  url().str(),
242  range().start.line,
243  range().start.column,
244  range().end.line,
245  range().end.column,
246  (explanation().isEmpty() ? i18n("<no explanation>") : explanation()),
247  sourceString());
248 }
249 
250 void Problem::rebuildDynamicData(DUContext* parent, uint ownIndex)
251 {
252  auto top = dynamic_cast<TopDUContext*>(parent);
253  Q_ASSERT(top);
254 
255  m_topContext = top;
256  m_indexInTopContext = ownIndex;
257 
258  // deserialize child diagnostics here, as the top-context might get unloaded
259  // but we still want to keep the child-diagnostics in-tact, as one would assume
260  // a shared-ptr works.
261  const auto data = d_func();
262  m_diagnostics.reserve(data->diagnosticsSize());
263  for (uint i = 0; i < data->diagnosticsSize(); ++i) {
264  m_diagnostics << ProblemPointer(data->diagnostics()[i].data(top));
265  }
266 
267  DUChainBase::rebuildDynamicData(parent, ownIndex);
268 }
269 
270 QDebug operator<<(QDebug s, const Problem& problem)
271 {
272  s.nospace() << problem.toString();
273  return s.space();
274 }
275 
276 QDebug operator<<(QDebug s, const ProblemPointer& problem)
277 {
278  if (!problem) {
279  s.nospace() << "<invalid problem>";
280  } else {
281  s.nospace() << problem->toString();
282  }
283  return s.space();
284 }
duchainlock.h
KDevelop::Problem::setSeverity
void setSeverity(Severity severity) override
Set the severity of this problem.
Definition: problem.cpp:192
KDevelop::Problem
An object representing a problem in preprocessing, parsing, definition-use chain compilation,...
Definition: problem.h:129
KDevelop::Problem::setExplanation
void setExplanation(const QString &explanation) override
Definition: problem.cpp:167
KDevelop::Problem::~Problem
~Problem() override
Definition: problem.cpp:80
KDevelop::DUChainBase
Base class for definition-use chain objects.
Definition: duchainbase.h:131
DEFINE_LIST_MEMBER_HASH
#define DEFINE_LIST_MEMBER_HASH(container, member, type)
Definition: appendedlist.h:218
KDevelop::REGISTER_DUCHAIN_ITEM
REGISTER_DUCHAIN_ITEM(AliasDeclaration)
KDevelop::Problem::setDiagnostics
void setDiagnostics(const QVector< IProblem::Ptr > &diagnostics) override
Definition: problem.cpp:133
QDebug::nospace
QDebug & nospace()
QVector::push_back
void push_back(const T &value)
KDevelop::Problem::finalLocation
DocumentRange finalLocation() const override
Location where this problem occurred.
Definition: problem.cpp:94
QExplicitlySharedDataPointer::data
T * data() const
QDebug::space
QDebug & space()
QDebug
KDevelop::Problem::severityString
QString severityString() const override
Returns a string representation of the severity.
Definition: problem.cpp:197
KDevelop::Problem::toString
virtual QString toString() const
Returns a string representation of this problem, useful for debugging.
Definition: problem.cpp:235
KDevelop::Problem::Problem
Problem()
Definition: problem.cpp:69
topducontext.h
problem.h
QExplicitlySharedDataPointer
Definition: topducontext.h:28
KDevelop::Problem::explanation
QString explanation() const override
A (detailed) explanation of why the problem occurred.
Definition: problem.cpp:162
ENSURE_CHAIN_READ_LOCKED
#define ENSURE_CHAIN_READ_LOCKED
Macros for ensuring the DUChain is locked properly.
Definition: duchainlock.h:37
QString
KDevelop::DUChainBase::range
RangeInRevision range() const
Returns the range assigned to this object, in the document revision when this document was last parse...
Definition: duchainbase.cpp:152
KDevelop::Problem::severity
Severity severity() const override
Get the severity of this problem.
Definition: problem.cpp:187
KDevelop::Problem::url
KDevelop::IndexedString url() const override
Definition: problem.cpp:89
KDevelop::Problem::addDiagnostic
void addDiagnostic(const IProblem::Ptr &diagnostic) override
Definition: problem.cpp:142
KDevelop::Problem::finalLocationMode
FinalLocationMode finalLocationMode() const override
Definition: problem.cpp:105
KDevelop::TopDUContext
The top context in a definition-use chain for one source file.
Definition: topducontext.h:113
KDevelop::Problem::source
Source source() const override
Definition: problem.cpp:172
KDevelop::Problem::setDescription
void setDescription(const QString &description) override
Definition: problem.cpp:157
KDevelop::Problem::setSource
void setSource(IProblem::Source source) override
Definition: problem.cpp:177
KDevelop::TopDUContextDynamicData::allocateProblemIndex
uint allocateProblemIndex(const ProblemPointer &problem)
Allocates an index for the given problem in this top-context.
Definition: topducontextdynamicdata.cpp:811
KDevelop::TopDUContextDynamicData::problemForIndex
ProblemPointer problemForIndex(uint index) const
Definition: topducontextdynamicdata.cpp:856
KDevelop::DUChainBase::setRange
void setRange(const RangeInRevision &range)
Changes the range assigned to this object, in the document revision when this document is parsed.
Definition: duchainbase.cpp:224
KDevelop::ProblemPointer
QExplicitlySharedDataPointer< Problem > ProblemPointer
Definition: problem.h:37
KDevelop::LocalIndexedProblem::LocalIndexedProblem
LocalIndexedProblem(const ProblemPointer &problem, const TopDUContext *top)
Definition: problem.cpp:42
topducontextdynamicdata.h
duchain.h
KDevelop::Problem::topContext
TopDUContext * topContext() const override
Determine the top context to which this object belongs.
Definition: problem.cpp:84
KDevelop::Problem::setFinalLocationMode
void setFinalLocationMode(FinalLocationMode mode) override
Definition: problem.cpp:110
KDevelop
Definition: abstractfunctiondeclaration.cpp:27
KDevelop::LocalIndexedProblem
Represents a problem only by its index within the top-context.
Definition: problem.h:44
KDevelop::Problem::clearDiagnostics
void clearDiagnostics() override
Returns child diagnostics of this particular problem.
Definition: problem.cpp:115
KDevelop::DUContext
A single context in source code, represented as a node in a directed acyclic graph.
Definition: ducontext.h:72
KDevelop::Problem::solutionAssistant
QExplicitlySharedDataPointer< IAssistant > solutionAssistant() const override
If this problem can be solved, this may return an assistant for the solution.
Definition: problem.cpp:182
KDevelop::DUChainPointer::data
Type * data() const
Definition: duchainpointer.h:173
QVector< IProblem::Ptr >
duchainregister.h
KDevelop::Problem::setFinalLocation
void setFinalLocation(const DocumentRange &location) override
Definition: problem.cpp:99
KDevelop::Problem::sourceString
QString sourceString() const override
Returns a string version of the problem source.
Definition: problem.cpp:212
KDevelop::TopDUContext::m_dynamicData
class TopDUContextDynamicData * m_dynamicData
Definition: topducontext.h:381
topducontextdata.h
KDevelop::Problem::diagnostics
QVector< IProblem::Ptr > diagnostics() const override
Definition: problem.cpp:122
KDevelop::Problem::description
QString description() const override
A brief description of the problem.
Definition: problem.cpp:152
KDevelop::DUChainBase::rebuildDynamicData
virtual void rebuildDynamicData(DUContext *parent, uint ownIndex)
Called after loading to rebuild the dynamic data. If this is a context, this should recursively work ...
Definition: duchainbase.cpp:126
KDevelop::LocalIndexedProblem::data
ProblemPointer data(const TopDUContext *top) const
Definition: problem.cpp:61
KDevelop::operator<<
QDebug operator<<(QDebug s, const QExplicitlySharedDataPointer< ParsingEnvironmentFile > &p)
Definition: parsingenvironment.h:226
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jan 20 2021 23:38:35 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdevplatform/language/duchain

Skip menu "kdevplatform/language/duchain"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdevelop API Reference

Skip menu "kdevelop API Reference"
  • kdevplatform
  •   debugger
  •   documentation
  •   interfaces
  •   language
  •     assistant
  •     backgroundparser
  •     checks
  •     classmodel
  •     codecompletion
  •     codegen
  •     duchain
  •     editor
  •     highlighting
  •     interfaces
  •     util
  •   outputview
  •   project
  •   serialization
  •   shell
  •   sublime
  •   tests
  •   util
  •   vcs

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal