Vuo 2.4.4
Loading...
Searching...
No Matches
VuoCompilerIssue.cc
Go to the documentation of this file.
1
10#include "VuoCompilerIssue.hh"
11
12#include <sstream>
13#include "VuoClangIssues.hh"
14#include "VuoModule.hh"
15#include "VuoShaderIssues.hh"
16#include "VuoStringUtilities.hh"
17
21static string getLineBreak(bool htmlFormatted, int count = 1)
22{
23 string lineBreak = (htmlFormatted ? "<br>" : "\n");
24 string ret;
25 for (int i = 0; i < count; ++i)
26 ret += lineBreak;
27 return ret;
28}
29
34{
35 issueType = VuoCompilerIssue::Error;
36 module = NULL;
37}
38
57VuoCompilerIssue::VuoCompilerIssue(IssueType issueType, const string &action, const string &filePath, const string &summary, const string &details)
58{
59 this->issueType = issueType;
60 this->action = action;
61 this->filePath = filePath;
62 this->summary = summary;
63 this->details = details;
64 module = NULL;
65}
66
70string VuoCompilerIssue::getIssueTypeString(void)
71{
72 string issueTypeStr;
73 switch (issueType)
74 {
75 case Error:
76 issueTypeStr = "Error";
77 break;
78 case Warning:
79 issueTypeStr = "Warning";
80 break;
81 }
82
83 return issueTypeStr;
84}
85
90string VuoCompilerIssue::fillInPlaceholders(const string &s, bool htmlFormatted) const
91{
92 string ret = s;
93
94 {
95 string moduleKeyFormatted = moduleKey;
96 if (htmlFormatted)
97 moduleKeyFormatted = "<code>" + moduleKeyFormatted + "</code>";
98 VuoStringUtilities::replaceAll(ret, "%moduleKey", moduleKeyFormatted);
99 }
100
101 if (module)
102 {
103 string moduleTitleFormatted = module->getDefaultTitle();
104 if (htmlFormatted)
105 moduleTitleFormatted = "<code>" + moduleTitleFormatted + "</code>";
106 string moduleKeyFormatted = module->getModuleKey();
107 if (htmlFormatted)
108 moduleKeyFormatted = "<code>" + moduleKeyFormatted + "</code>";
109 VuoStringUtilities::replaceAll(ret, "%module", moduleTitleFormatted + " (" + moduleKeyFormatted + ")");
110 }
111
112 {
113 string link = (htmlFormatted ?
114 "<a href=\"" + linkUrl + "\">" + linkText + "</a>" :
115 linkText + " (" + linkUrl + ")");
116 VuoStringUtilities::replaceAll(ret, "%link", link);
117 }
118
119 return ret;
120}
121
129
134{
135 return summary;
136}
137
143string VuoCompilerIssue::getDetails(bool htmlFormatted) const
144{
145 return fillInPlaceholders(details, htmlFormatted);
146}
147
153string VuoCompilerIssue::getShortDescription(bool htmlFormatted) const
154{
155 string description;
156
157 if (! summary.empty())
158 description += summary + " — ";
159
160 description += getDetails(htmlFormatted);
161
162 return description;
163}
164
170string VuoCompilerIssue::getLongDescription(bool htmlFormatted)
171{
172 string lineBreak = getLineBreak(htmlFormatted);
173
174 string description = getIssueTypeString() + " " + action;
175
176 if (! filePath.empty())
177 {
178 string location = filePath;
179
180 if (htmlFormatted)
181 location = "<code>" + location + "</code>";
182
183 description += " " + location;
184 }
185
186 description += ":" + lineBreak;
187
188 if (! summary.empty())
189 description += summary + " — ";
190
191 description += getDetails(htmlFormatted);
192
193 if (clangIssues && ! clangIssues->isEmpty())
194 description += lineBreak + clangIssues->getDescription(lineBreak);
195
196 if (shaderIssues && ! shaderIssues->issues().empty())
197 description += lineBreak + shaderIssues->getDescription(lineBreak);
198
199 return description;
200}
201
207void VuoCompilerIssue::setHint(const string &hint)
208{
209 this->hint = hint;
210}
211
217string VuoCompilerIssue::getHint(bool htmlFormatted)
218{
219 return fillInPlaceholders(hint, htmlFormatted);
220}
221
225void VuoCompilerIssue::setHelpPath(const string &path)
226{
227 this->helpPath = path;
228}
229
234{
235 return helpPath;
236}
237
241void VuoCompilerIssue::setFilePath(const string &filePath)
242{
243 this->filePath = filePath;
244}
245
250{
251 return filePath;
252}
253
257void VuoCompilerIssue::setModuleKey(const string &moduleKey)
258{
259 this->moduleKey = moduleKey;
260}
261
265void VuoCompilerIssue::setLink(const string &url, const string &text)
266{
267 linkUrl = url;
268 linkText = text;
269}
270
275{
276 this->module = module;
277}
278
283{
284 nodes.clear();
285 nodes.insert(node);
286}
287
291void VuoCompilerIssue::setNodes(const set<VuoNode *> &nodes)
292{
293 this->nodes = nodes;
294}
295
299set<VuoNode *> VuoCompilerIssue::getNodes(void)
300{
301 return nodes;
302}
303
307void VuoCompilerIssue::setCables(const set<VuoCable *> &cables)
308{
309 this->cables = cables;
310}
311
315set<VuoCable *> VuoCompilerIssue::getCables(void)
316{
317 return cables;
318}
319
323void VuoCompilerIssue::setClangIssues(shared_ptr<VuoClangIssues> clangIssues)
324{
325 this->clangIssues = clangIssues;
326}
327
331void VuoCompilerIssue::setShaderIssues(shared_ptr<VuoShaderIssues> shaderIssues)
332{
333 this->shaderIssues = shaderIssues;
334}
335
339shared_ptr<VuoShaderIssues> VuoCompilerIssue::getShaderIssues(void)
340{
341 return shaderIssues;
342}
343
348{
349 ostringstream s;
350
351 s << getLongDescription(false);
352
353 vector<string> nodeStrings;
354 for (set<VuoNode *>::iterator i = nodes.begin(); i != nodes.end(); ++i)
355 {
356 ostringstream ss;
357 ss << *i;
358 nodeStrings.push_back(ss.str());
359 }
360 sort(nodeStrings.begin(), nodeStrings.end());
361 s << "[" << VuoStringUtilities::join(nodeStrings, ',') << "]";
362
363 vector<string> cableStrings;
364 for (set<VuoCable *>::iterator i = cables.begin(); i != cables.end(); ++i)
365 {
366 ostringstream ss;
367 ss << *i;
368 cableStrings.push_back(ss.str());
369 }
370 s << "[" << VuoStringUtilities::join(cableStrings, ',') << "]";
371
372 return VuoStringUtilities::hash(s.str());
373}
374
375
382
387{
388 issues.push_back(issue);
389}
390
397{
398 vector<string> uniqueDescriptions;
399 for (vector<VuoCompilerIssue>::iterator i = issues.begin(); i != issues.end(); ++i)
400 {
401 string description = (*i).getShortDescription(htmlFormatted);
402 if (find(uniqueDescriptions.begin(), uniqueDescriptions.end(), description) == uniqueDescriptions.end())
403 uniqueDescriptions.push_back(description);
404 }
405
406 return VuoStringUtilities::join(uniqueDescriptions, getLineBreak(htmlFormatted, 2));
407}
408
415{
416 vector<string> uniqueDescriptions;
417 for (vector<VuoCompilerIssue>::iterator i = issues.begin(); i != issues.end(); ++i)
418 {
419 string description = (*i).getLongDescription(htmlFormatted);
420 if (find(uniqueDescriptions.begin(), uniqueDescriptions.end(), description) == uniqueDescriptions.end())
421 uniqueDescriptions.push_back(description);
422 }
423
424 return VuoStringUtilities::join(uniqueDescriptions, getLineBreak(htmlFormatted, 2));
425}
426
432string VuoCompilerIssues::getHint(bool htmlFormatted)
433{
434 vector<string> uniqueHints;
435 for (vector<VuoCompilerIssue>::iterator i = issues.begin(); i != issues.end(); ++i)
436 {
437 string hint = (*i).getHint(htmlFormatted);
438 if (! hint.empty() && find(uniqueHints.begin(), uniqueHints.end(), hint) == uniqueHints.end())
439 uniqueHints.push_back(hint);
440 }
441
442 return VuoStringUtilities::join(uniqueHints, getLineBreak(htmlFormatted, 2));
443}
444
448void VuoCompilerIssues::setFilePathIfEmpty(const string &filePath)
449{
450 for (VuoCompilerIssue &issue : issues)
451 if (issue.getFilePath().empty())
452 issue.setFilePath(filePath);
453}
454
458void VuoCompilerIssues::setFilePath(const string &filePath)
459{
460 for (VuoCompilerIssue &issue : issues)
461 issue.setFilePath(filePath);
462}
463
468void VuoCompilerIssues::setFilePath(std::function<string(const string &)> generateFilePath)
469{
470 for (VuoCompilerIssue &issue : issues)
471 issue.setFilePath( generateFilePath(issue.getFilePath()) );
472}
473
478{
479 issues.push_back(issue);
480}
481
486{
487 issues.insert(issues.end(), otherIssues->issues.begin(), otherIssues->issues.end());
488}
489
494{
495 return issues.empty();
496}
497
501vector<VuoCompilerIssue> VuoCompilerIssues::getList(void)
502{
503 return issues;
504}
505
510{
511 VuoCompilerIssues *errors = new VuoCompilerIssues();
512 for (vector<VuoCompilerIssue>::iterator i = issues.begin(); i != issues.end(); ++i)
513 if ((*i).getIssueType() == VuoCompilerIssue::Error)
514 errors->append(*i);
515
516 return errors;
517}
518
523{
524 auto isError = [](VuoCompilerIssue issue)
525 {
526 return issue.getIssueType() == VuoCompilerIssue::Error;
527 };
528
529 return std::find_if(issues.begin(), issues.end(), isError) != issues.end();
530}