aGrUM  0.16.0
errors.cpp
Go to the documentation of this file.
1 
31 #include <agrum/PRM/o3prm/errors.h>
32 
33 #ifndef DOXYGEN_SHOULD_SKIP_THIS
34 
35 namespace gum {
36  namespace prm {
37  namespace o3prm {
38 
39  void O3PRM_TYPE_NOT_FOUND(const O3Label& val, ErrorsContainer& errors) {
40  auto pos = val.position();
41  std::stringstream msg;
42  msg << "Error : "
43  << "Unknown type " << val.label();
44  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
45  }
46 
47  void O3PRM_TYPE_AMBIGUOUS(const O3Label& val,
48  const std::vector< std::string >& matches,
49  ErrorsContainer& errors) {
50  const auto& pos = val.position();
51  std::stringstream msg;
52  msg << "Error : "
53  << "Ambiguous name " << val.label()
54  << ", found more than one elligible types: ";
55  for (std::size_t i = 0; i < matches.size() - 1; ++i) {
56  msg << matches[i] << ", ";
57  }
58  msg << matches.back();
59  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
60  }
61 
62  void O3PRM_TYPE_RESERVED(const O3Label& val, ErrorsContainer& errors) {
63  const auto& pos = val.position();
64  std::stringstream msg;
65  msg << "Error : "
66  << "Type name " << val.label() << " is reserved";
67  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
68  }
69 
70  void O3PRM_TYPE_DUPPLICATE(const O3Label& val, ErrorsContainer& errors) {
71  const auto& pos = val.position();
72  std::stringstream msg;
73  msg << "Error : "
74  << "Type " << val.label() << " exists already";
75  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
76  }
77 
78  void O3PRM_TYPE_CYCLIC_INHERITANCE(const O3Label& sub_type,
79  const O3Label& super_type,
80  ErrorsContainer& errors) {
81  const auto& pos = sub_type.position();
82  std::stringstream msg;
83  msg << "Error : "
84  << "Cyclic inheritance between type " << sub_type.label()
85  << " and type " << super_type.label();
86  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
87  }
88 
89  void O3PRM_TYPE_UNKNOWN_LABEL(const O3Label& type,
90  const O3Label& l,
91  ErrorsContainer& errors) {
92  const auto& pos = l.position();
93  std::stringstream msg;
94  msg << "Error : "
95  << "Unknown label " << l.label() << " in " << type.label();
96  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
97  }
98 
99  void O3PRM_TYPE_INVALID_RANGE(const O3IntType& val,
100  ErrorsContainer& errors) {
101  const auto& pos = val.position();
102  std::stringstream msg;
103  msg << "Error : "
104  << "Invalid range " << val.start().value() << " -> "
105  << val.end().value();
106  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
107  }
108 
109  void O3PRM_TYPE_INVALID_RANGE(const O3RealType& val,
110  ErrorsContainer& errors) {
111  const auto& pos = val.position();
112  std::stringstream msg;
113  msg << "Error : "
114  << "Found " << val.values().size()
115  << " values in range expected at least 3";
116  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
117  }
118 
119  void O3PRM_CLASS_NOT_FOUND(const O3Label& val, ErrorsContainer& errors) {
120  const auto& pos = val.position();
121  std::stringstream msg;
122  msg << "Error : "
123  << "Unknown class " << val.label();
124  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
125  GUM_ERROR(FatalError, msg.str());
126  }
127 
128  void O3PRM_CLASS_AMBIGUOUS(const O3Label& val,
129  const std::vector< std::string >& matches,
130  ErrorsContainer& errors) {
131  const auto& pos = val.position();
132  std::stringstream msg;
133  msg << "Error : "
134  << "Name " << val.label() << " is ambiguous: ";
135  for (std::size_t i = 0; i < matches.size() - 1; ++i) {
136  msg << matches[i] << ", ";
137  }
138  msg << matches.back();
139  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
140  }
141 
142  void O3PRM_CLASS_DUPLICATE(const O3Label& val, ErrorsContainer& errors) {
143  // Raised if duplicate type names
144  const auto& pos = val.position();
145  std::stringstream msg;
146  msg << "Error : "
147  << "Class name " << val.label() << " exists already";
148  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
149  }
150 
151  void O3PRM_CLASS_CYLIC_INHERITANCE(const O3Label& sub,
152  const O3Label& super,
153  ErrorsContainer& errors) {
154  // Cyclic inheritance
155  const auto& pos = sub.position();
156  std::stringstream msg;
157  msg << "Error : "
158  << "Cyclic inheritance between class " << sub.label() << " and class "
159  << super.label();
160  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
161  }
162 
163 
164  void O3PRM_CLASS_ATTR_IMPLEMENTATION(const O3Label& c,
165  const O3Label& i,
166  const O3Label& attr,
167  ErrorsContainer& errors) {
168  const auto& pos = attr.position();
169  std::stringstream msg;
170  msg << "Error : "
171  << "Class " << c.label() << " attribute " << attr.label()
172  << " does not respect interface " << i.label();
173  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
174  }
175 
176  void O3PRM_CLASS_AGG_IMPLEMENTATION(const O3Label& c,
177  const O3Label& i,
178  const O3Label& attr,
179  ErrorsContainer& errors) {
180  const auto& pos = attr.position();
181  std::stringstream msg;
182  msg << "Error : "
183  << "Class " << c.label() << " aggregate " << attr.label()
184  << " does not respect interface " << i.label();
185  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
186  }
187 
188  void O3PRM_CLASS_REF_IMPLEMENTATION(const O3Label& c,
189  const O3Label& i,
190  const O3Label& ref,
191  ErrorsContainer& errors) {
192  const auto& pos = ref.position();
193  std::stringstream msg;
194  msg << "Error : "
195  << "Class " << c.label() << " reference " << ref.label()
196  << " does not respect interface " << i.label();
197  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
198  }
199 
200 
201  void O3PRM_CLASS_MISSING_ATTRIBUTES(const O3Label& c,
202  const O3Label& i,
203  ErrorsContainer& errors) {
204  const auto& pos = c.position();
205  std::stringstream msg;
206  msg << "Error : "
207  << "Class " << c.label() << " does not implement all of interface "
208  << i.label() << " attributes";
209  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
210  }
211 
212  void O3PRM_CLASS_DUPLICATE_REFERENCE(const O3Label& ref,
213  ErrorsContainer& errors) {
214  const auto& pos = ref.position();
215  std::stringstream msg;
216  msg << "Error : "
217  << "Reference Slot name " << ref.label() << " exists already";
218  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
219  }
220 
221  void O3PRM_CLASS_SELF_REFERENCE(const O3Label& c,
222  const O3Label& ref,
223  ErrorsContainer& errors) {
224  const auto& pos = ref.position();
225  std::stringstream msg;
226  msg << "Error : "
227  << "Class " << c.label() << " cannot reference itself";
228  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
229  }
230 
231  void O3PRM_CLASS_ILLEGAL_SUB_REFERENCE(const O3Label& c,
232  const O3Label& sub,
233  ErrorsContainer& errors) {
234  const auto& pos = sub.position();
235  std::stringstream msg;
236  msg << "Error : "
237  << "Class " << c.label() << " cannot reference subclass "
238  << sub.label();
239  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
240  }
241 
242  void O3PRM_CLASS_PARENT_NOT_FOUND(const O3Label& parent,
243  ErrorsContainer& errors) {
244  const auto& pos = parent.position();
245  std::stringstream msg;
246  msg << "Error : "
247  << "Parent " << parent.label() << " not found";
248  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
249  }
250 
251  void O3PRM_CLASS_ILLEGAL_PARENT(const O3Label& parent,
252  ErrorsContainer& errors) {
253  const auto& pos = parent.position();
254  std::stringstream msg;
255  msg << "Error : "
256  << "Illegal parent " << parent.label();
257  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
258  }
259 
260  void O3PRM_CLASS_LINK_NOT_FOUND(const O3Label& chain,
261  const std::string& s,
262  ErrorsContainer& errors) {
263  const auto& pos = chain.position();
264  std::stringstream msg;
265  msg << "Error : "
266  << "Link " << s << " in chain " << chain.label() << " not found";
267  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
268  }
269 
270  void O3PRM_CLASS_ILLEGAL_CPT_SIZE(const std::string& c,
271  const O3Label& attr,
272  Size found,
273  Size expected,
274  ErrorsContainer& errors) {
275  const auto& pos = attr.position();
276  std::stringstream msg;
277  msg << "Error : "
278  << "Illegal CPT size, expected " << expected << " found " << found
279  << " for attribute " << c << "." << attr.label();
280  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
281  }
282 
283  void O3PRM_CLASS_ILLEGAL_CPT_VALUE(const std::string& c,
284  const O3Label& attr,
285  const O3Formula& f,
286  ErrorsContainer& errors) {
287  const auto& pos = f.position();
288  std::stringstream msg;
289  msg << "Error : "
290  << "Illegal CPT value \"" << f.formula().formula()
291  << "\" in attribute " << c << "." << attr.label();
292  try {
293  auto result = f.formula().result();
294  msg << ", formula resolve to " << result;
295  } catch (...) {
296  msg << ", could not resolve the following formula: "
297  << "\"" << f.formula().formula() << "\"";
298  }
299  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
300  }
301 
302  void O3PRM_CLASS_CPT_DOES_NOT_SUM_TO_1(const std::string& c,
303  const O3Label& attr,
304  float f,
305  ErrorsContainer& errors) {
306  const auto& pos = attr.position();
307  std::stringstream msg;
308  msg << "Error : "
309  << "PRMAttribute " << c << "." << attr.label()
310  << " CPT does not sum to 1, found " << f;
311  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
312  }
313 
314  void O3PRM_CLASS_CPT_DOES_NOT_SUM_TO_1_WARNING(const std::string& c,
315  const O3Label& attr,
316  float f,
317  ErrorsContainer& errors) {
318  const auto& pos = attr.position();
319  std::stringstream msg;
320  msg << "Warning : "
321  << "PRMAttribute " << c << "." << attr.label()
322  << " CPT does not sum to 1, found " << f;
323  errors.addWarning(msg.str(), pos.file(), pos.line(), pos.column());
324  }
325 
326  void O3PRM_CLASS_ILLEGAL_RULE_SIZE(const O3RuleCPT::O3Rule& rule,
327  size_t found,
328  size_t expected,
329  ErrorsContainer& errors) {
330  const auto& pos = rule.first.front().position();
331  std::stringstream msg;
332  msg << "Error : "
333  << "Expected " << expected << " value(s), found " << found;
334  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
335  }
336 
337  void O3PRM_CLASS_ILLEGAL_RULE_LABEL(const O3RuleCPT::O3Rule& rule,
338  const O3Label& label,
339  const O3Label& parent,
340  ErrorsContainer& errors) {
341  const auto& pos = label.position();
342  std::stringstream msg;
343  msg << "Error : "
344  << "Label " << label << " is not part of " << parent << " domain";
345  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
346  }
347 
348  void O3PRM_CLASS_WRONG_PARENT(const O3Label& prnt, ErrorsContainer& errors) {
349  const auto& pos = prnt.position();
350  std::stringstream msg;
351  msg << "Error : "
352  << "Illegal parent " << prnt;
353  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
354  }
355 
356  void O3PRM_CLASS_WRONG_PARENT_TYPE(const O3Label& prnt,
357  const std::string& expected,
358  const std::string& found,
359  ErrorsContainer& errors) {
360  const auto& pos = prnt.position();
361  std::stringstream msg;
362  msg << "Error : "
363  << "Expected type " << expected << " for parent " << prnt.label()
364  << ", found " << found;
365  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
366  }
367 
368  void O3PRM_CLASS_ILLEGAL_OVERLOAD(const O3Label& elt,
369  const O3Label& c,
370  ErrorsContainer& errors) {
371  const auto& pos = elt.position();
372  std::stringstream msg;
373  msg << "Error : "
374  << "Illegal overload of element " << elt.label() << " from class "
375  << c.label();
376  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
377  }
378 
379  void O3PRM_CLASS_AGG_PARAMETERS(const O3Label& agg,
380  Size expected,
381  Size found,
382  ErrorsContainer& errors) {
383  const auto& pos = agg.position();
384  std::stringstream msg;
385  msg << "Error : "
386  << "Expected " << expected << " parameters "
387  << ", found " << found;
388  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
389  }
390 
391  void O3PRM_CLASS_AGG_PARAMETER_NOT_FOUND(const O3Label& agg,
392  const O3Label& param,
393  ErrorsContainer& errors) {
394  const auto& pos = param.position();
395  std::stringstream msg;
396  msg << "Error : "
397  << "Parameter " << param.label() << " in aggregate " << agg.label()
398  << " does not match any expected values";
399  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
400  }
401 
402  void O3PRM_INTERFACE_ILLEGAL_ARRAY(const O3Label& val,
403  ErrorsContainer& errors) {
404  const auto& pos = val.position();
405  std::stringstream msg;
406  msg << "Error : "
407  << "PRMAttribute " << val.label() << " can not be an array";
408  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
409  }
410 
411  void O3PRM_INTERFACE_NOT_FOUND(const O3Label& val, ErrorsContainer& errors) {
412  const auto& pos = val.position();
413  std::stringstream msg;
414  msg << "Error : "
415  << "Interface " << val.label() << " not found";
416  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
417  }
418 
419  void O3PRM_INTERFACE_AMBIGUOUS(const O3Label& val,
420  const std::vector< std::string >& matches,
421  ErrorsContainer& errors) {
422  const auto& pos = val.position();
423  std::stringstream msg;
424  msg << "Error : "
425  << "Name " << val.label() << " is ambiguous: ";
426  for (std::size_t i = 0; i < matches.size() - 1; ++i) {
427  msg << matches[i] << ", ";
428  }
429  msg << matches.back();
430  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
431  }
432 
433  void O3PRM_INTERFACE_DUPLICATE(const O3Label& val, ErrorsContainer& errors) {
434  const auto& pos = val.position();
435  std::stringstream msg;
436  msg << "Error : "
437  << "Interface name " << val.label() << " exists already";
438  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
439  }
440 
441  void O3PRM_INTERFACE_DUPLICATE_ELEMENT(const O3InterfaceElement& elt,
442  ErrorsContainer& errors) {
443  const auto& pos = elt.type().position();
444  std::stringstream msg;
445  msg << "Error : "
446  << "Element " << elt.name().label() << " already exists";
447  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
448  }
449 
450  void O3PRM_INTERFACE_CYCLIC_INHERITANCE(const O3Label& sub,
451  const O3Label& super,
452  ErrorsContainer& errors) {
453  const auto& pos = super.position();
454  std::stringstream msg;
455  msg << "Error : "
456  << "Cyclic inheritance between interface " << sub.label()
457  << " and interface " << super.label();
458  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
459  }
460 
461  void O3PRM_INTERFACE_SELF_REFERENCE(const O3Interface& i,
462  const O3InterfaceElement& r,
463  ErrorsContainer& errors) {
464  const auto& pos = r.type().position();
465  std::stringstream msg;
466  msg << "Error : "
467  << "Interface " << i.name().label() << " cannot reference itself";
468  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
469  }
470 
471  void O3PRM_INTERFACE_ILLEGAL_SUB_REFERENCE(const O3Interface& i,
472  const O3InterfaceElement& ref,
473  ErrorsContainer& errors) {
474  const auto& pos = ref.type().position();
475  std::stringstream msg;
476  msg << "Error : "
477  << "Interface " << i.name().label()
478  << " cannot reference subinterface " << ref.type().label();
479  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
480  }
481 
482  void O3PRM_INTERFACE_ILLEGAL_OVERLOAD(const O3InterfaceElement& elt,
483  ErrorsContainer& errors) {
484  const auto& pos = elt.type().position();
485  std::stringstream msg;
486  msg << "Error : "
487  << "Illegal overload of element " << elt.name().label();
488  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
489  }
490 
491  void O3PRM_REFERENCE_NOT_FOUND(const O3Label& val, ErrorsContainer& errors) {
492  const auto& pos = val.position();
493  std::stringstream msg;
494  msg << "Error : "
495  << "Reference Slot type " << val.label() << " not found";
496  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
497  }
498 
499  void O3PRM_REFERENCE_AMBIGUOUS(const O3Label& val,
500  const std::vector< std::string >& matches,
501  ErrorsContainer& errors) {
502  const auto& pos = val.position();
503  std::stringstream msg;
504  msg << "Error : "
505  << "Name " << val.label() << " is ambiguous: ";
506  for (std::size_t i = 0; i < matches.size() - 1; ++i) {
507  msg << matches[i] << ", ";
508  }
509  msg << matches.back();
510  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
511  }
512 
513  void O3PRM_SYSTEM_INSTANTIATION_FAILED(const O3System& sys,
514  ErrorsContainer& errors) {
515  const auto& pos = sys.name().position();
516  std::stringstream msg;
517  msg << "Error : "
518  << "Could not instantiate the system, some reference slots must be "
519  "unassigned";
520  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
521  }
522 
523  void O3PRM_SYSTEM_NOT_A_CLASS(const O3Instance& i, ErrorsContainer& errors) {
524  const auto& pos = i.type().position();
525  std::stringstream msg;
526  msg << "Error : " << i.type().label() << " is not a class";
527  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
528  }
529 
530  void O3PRM_SYSTEM_DUPLICATE_INSTANCE(const O3Instance& i,
531  ErrorsContainer& errors) {
532  const auto& pos = i.type().position();
533  std::stringstream msg;
534  msg << "Error : "
535  << "Instance " << i.name().label() << " already exists";
536  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
537  }
538 
539  void O3PRM_SYSTEM_NOT_A_PARAMETER(const O3InstanceParameter& param,
540  ErrorsContainer& errors) {
541  const auto& pos = param.name().position();
542  std::stringstream msg;
543  msg << "Instance error : " << param.name().label()
544  << " is not a parameter";
545  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
546  }
547 
548  void O3PRM_SYSTEM_PARAMETER_NOT_FOUND(const O3InstanceParameter& param,
549  ErrorsContainer& errors) {
550  const auto& pos = param.name().position();
551  std::stringstream msg;
552  msg << "Error : "
553  << "Parameter " << param.name().label() << " not found";
554  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
555  }
556 
557  void O3PRM_SYSTEM_PARAMETER_NOT_INT(const O3InstanceParameter& param,
558  ErrorsContainer& errors) {
559  const auto& pos = param.value().position();
560  std::stringstream msg;
561  msg << "Error : "
562  << "Parameter " << param.name().label() << " is an integer";
563  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
564  }
565 
566  void O3PRM_SYSTEM_PARAMETER_NOT_FLOAT(const O3InstanceParameter& param,
567  ErrorsContainer& errors) {
568  const auto& pos = param.value().position();
569  std::stringstream msg;
570  msg << "Error : "
571  << "Parameter " << param.name().label() << " is a float";
572  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
573  }
574 
575  void O3PRM_SYSTEM_INVALID_LEFT_VALUE(const O3Label& val,
576  ErrorsContainer& errors) {
577  const auto& pos = val.position();
578  std::stringstream msg;
579  msg << "Error : "
580  << "Invalid left expression " << val.label();
581  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
582  }
583 
584  void O3PRM_SYSTEM_INSTANCE_NOT_FOUND(const O3Label& i,
585  ErrorsContainer& errors) {
586  const auto& pos = i.position();
587  std::stringstream msg;
588  msg << "Error : "
589  << "Instance " << i.label() << " not found";
590  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
591  }
592 
593  void O3PRM_SYSTEM_REFERENCE_NOT_FOUND(const O3Label& ref,
594  const std::string& type,
595  ErrorsContainer& errors) {
596  const auto& pos = ref.position();
597  std::stringstream msg;
598  msg << "Error : "
599  << "Reference " << ref.label() << " not found in class " << type;
600  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
601  }
602 
603  void O3PRM_SYSTEM_NOT_AN_ARRAY(const O3Label& val, ErrorsContainer& errors) {
604  const auto& pos = val.position();
605  std::stringstream msg;
606  msg << "Error : " << val.label() << " is not an array";
607  errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
608  }
609 
610  void O3PRM_DEPRECATED_TYPE_WARNING(const O3Label& val,
611  ErrorsContainer& errors) {
612  const auto& pos = val.position();
613  std::stringstream msg;
614  msg << "Warning : " << val.label()
615  << " is declared using a deprecated syntax.";
616  errors.addWarning(msg.str(), pos.file(), pos.line(), pos.column());
617  }
618 
619 
620  } // namespace o3prm
621  } // namespace prm
622 } // namespace gum
623 
624 #endif // DOXYGEN_SHOULD_SKIP_THIS
std::pair< O3LabelList, O3FormulaList > O3Rule
Definition: O3prm.h:546
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55