30 #include <agrum/PRM/o3prm/errors.h> 32 #ifndef DOXYGEN_SHOULD_SKIP_THIS 38 void O3PRM_TYPE_NOT_FOUND(
const O3Label& val, ErrorsContainer& errors) {
39 auto pos = val.position();
40 std::stringstream msg;
42 <<
"Unknown type " << val.label();
43 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
46 void O3PRM_TYPE_AMBIGUOUS(
const O3Label& val,
47 const std::vector< std::string >& matches,
48 ErrorsContainer& errors) {
49 const auto& pos = val.position();
50 std::stringstream msg;
52 <<
"Ambiguous name " << val.label()
53 <<
", found more than one elligible types: ";
54 for (std::size_t i = 0; i < matches.size() - 1; ++i) {
55 msg << matches[i] <<
", ";
57 msg << matches.back();
58 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
61 void O3PRM_TYPE_RESERVED(
const O3Label& val, ErrorsContainer& errors) {
62 const auto& pos = val.position();
63 std::stringstream msg;
65 <<
"Type name " << val.label() <<
" is reserved";
66 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
69 void O3PRM_TYPE_DUPPLICATE(
const O3Label& val, ErrorsContainer& errors) {
70 const auto& pos = val.position();
71 std::stringstream msg;
73 <<
"Type " << val.label() <<
" exists already";
74 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
77 void O3PRM_TYPE_CYCLIC_INHERITANCE(
const O3Label& sub_type,
78 const O3Label& super_type,
79 ErrorsContainer& errors) {
80 const auto& pos = sub_type.position();
81 std::stringstream msg;
83 <<
"Cyclic inheritance between type " << sub_type.label()
84 <<
" and type " << super_type.label();
85 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
88 void O3PRM_TYPE_UNKNOWN_LABEL(
const O3Label& type,
90 ErrorsContainer& errors) {
91 const auto& pos = l.position();
92 std::stringstream msg;
94 <<
"Unknown label " << l.label() <<
" in " << type.label();
95 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
98 void O3PRM_TYPE_INVALID_RANGE(
const O3IntType& val,
99 ErrorsContainer& errors) {
100 const auto& pos = val.position();
101 std::stringstream msg;
103 <<
"Invalid range " << val.start().value() <<
" -> " 104 << val.end().value();
105 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
108 void O3PRM_TYPE_INVALID_RANGE(
const O3RealType& val,
109 ErrorsContainer& errors) {
110 const auto& pos = val.position();
111 std::stringstream msg;
113 <<
"Found " << val.values().size()
114 <<
" values in range expected at least 3";
115 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
118 void O3PRM_CLASS_NOT_FOUND(
const O3Label& val, ErrorsContainer& errors) {
119 const auto& pos = val.position();
120 std::stringstream msg;
122 <<
"Unknown class " << val.label();
123 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
124 GUM_ERROR(FatalError, msg.str());
127 void O3PRM_CLASS_AMBIGUOUS(
const O3Label& val,
128 const std::vector< std::string >& matches,
129 ErrorsContainer& errors) {
130 const auto& pos = val.position();
131 std::stringstream msg;
133 <<
"Name " << val.label() <<
" is ambiguous: ";
134 for (std::size_t i = 0; i < matches.size() - 1; ++i) {
135 msg << matches[i] <<
", ";
137 msg << matches.back();
138 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
141 void O3PRM_CLASS_DUPLICATE(
const O3Label& val, ErrorsContainer& errors) {
143 const auto& pos = val.position();
144 std::stringstream msg;
146 <<
"Class name " << val.label() <<
" exists already";
147 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
150 void O3PRM_CLASS_CYLIC_INHERITANCE(
const O3Label& sub,
151 const O3Label& super,
152 ErrorsContainer& errors) {
154 const auto& pos = sub.position();
155 std::stringstream msg;
157 <<
"Cyclic inheritance between class " << sub.label() <<
" and class " 159 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
163 void O3PRM_CLASS_ATTR_IMPLEMENTATION(
const O3Label& c,
166 ErrorsContainer& errors) {
167 const auto& pos = attr.position();
168 std::stringstream msg;
170 <<
"Class " << c.label() <<
" attribute " << attr.label()
171 <<
" does not respect interface " << i.label();
172 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
175 void O3PRM_CLASS_AGG_IMPLEMENTATION(
const O3Label& c,
178 ErrorsContainer& errors) {
179 const auto& pos = attr.position();
180 std::stringstream msg;
182 <<
"Class " << c.label() <<
" aggregate " << attr.label()
183 <<
" does not respect interface " << i.label();
184 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
187 void O3PRM_CLASS_REF_IMPLEMENTATION(
const O3Label& c,
190 ErrorsContainer& errors) {
191 const auto& pos = ref.position();
192 std::stringstream msg;
194 <<
"Class " << c.label() <<
" reference " << ref.label()
195 <<
" does not respect interface " << i.label();
196 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
200 void O3PRM_CLASS_MISSING_ATTRIBUTES(
const O3Label& c,
202 ErrorsContainer& errors) {
203 const auto& pos = c.position();
204 std::stringstream msg;
206 <<
"Class " << c.label() <<
" does not implement all of interface " 207 << i.label() <<
" attributes";
208 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
211 void O3PRM_CLASS_DUPLICATE_REFERENCE(
const O3Label& ref,
212 ErrorsContainer& errors) {
213 const auto& pos = ref.position();
214 std::stringstream msg;
216 <<
"Reference Slot name " << ref.label() <<
" exists already";
217 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
220 void O3PRM_CLASS_SELF_REFERENCE(
const O3Label& c,
222 ErrorsContainer& errors) {
223 const auto& pos = ref.position();
224 std::stringstream msg;
226 <<
"Class " << c.label() <<
" cannot reference itself";
227 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
230 void O3PRM_CLASS_ILLEGAL_SUB_REFERENCE(
const O3Label& c,
232 ErrorsContainer& errors) {
233 const auto& pos = sub.position();
234 std::stringstream msg;
236 <<
"Class " << c.label() <<
" cannot reference subclass " 238 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
241 void O3PRM_CLASS_PARENT_NOT_FOUND(
const O3Label& parent,
242 ErrorsContainer& errors) {
243 const auto& pos = parent.position();
244 std::stringstream msg;
246 <<
"Parent " << parent.label() <<
" not found";
247 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
250 void O3PRM_CLASS_ILLEGAL_PARENT(
const O3Label& parent,
251 ErrorsContainer& errors) {
252 const auto& pos = parent.position();
253 std::stringstream msg;
255 <<
"Illegal parent " << parent.label();
256 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
259 void O3PRM_CLASS_LINK_NOT_FOUND(
const O3Label& chain,
260 const std::string& s,
261 ErrorsContainer& errors) {
262 const auto& pos = chain.position();
263 std::stringstream msg;
265 <<
"Link " << s <<
" in chain " << chain.label() <<
" not found";
266 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
269 void O3PRM_CLASS_ILLEGAL_CPT_SIZE(
const std::string& c,
273 ErrorsContainer& errors) {
274 const auto& pos = attr.position();
275 std::stringstream msg;
277 <<
"Illegal CPT size, expected " << expected <<
" found " << found
278 <<
" for attribute " << c <<
"." << attr.label();
279 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
282 void O3PRM_CLASS_ILLEGAL_CPT_VALUE(
const std::string& c,
285 ErrorsContainer& errors) {
286 const auto& pos = f.position();
287 std::stringstream msg;
289 <<
"Illegal CPT value \"" << f.formula().formula()
290 <<
"\" in attribute " << c <<
"." << attr.label();
292 auto result = f.formula().result();
293 msg <<
", formula resolve to " << result;
295 msg <<
", could not resolve the following formula: " 296 <<
"\"" << f.formula().formula() <<
"\"";
298 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
301 void O3PRM_CLASS_CPT_DOES_NOT_SUM_TO_1(
const std::string& c,
304 ErrorsContainer& errors) {
305 const auto& pos = attr.position();
306 std::stringstream msg;
308 <<
"PRMAttribute " << c <<
"." << attr.label()
309 <<
" CPT does not sum to 1, found " << f;
310 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
313 void O3PRM_CLASS_CPT_DOES_NOT_SUM_TO_1_WARNING(
const std::string& c,
316 ErrorsContainer& errors) {
317 const auto& pos = attr.position();
318 std::stringstream msg;
320 <<
"PRMAttribute " << c <<
"." << attr.label()
321 <<
" CPT does not sum to 1, found " << f;
322 errors.addWarning(msg.str(), pos.file(), pos.line(), pos.column());
325 void O3PRM_CLASS_ILLEGAL_RULE_SIZE(
const O3RuleCPT::O3Rule& rule,
328 ErrorsContainer& errors) {
329 const auto& pos = rule.first.front().position();
330 std::stringstream msg;
332 <<
"Expected " << expected <<
" value(s), found " << found;
333 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
336 void O3PRM_CLASS_ILLEGAL_RULE_LABEL(
const O3RuleCPT::O3Rule& rule,
337 const O3Label& label,
338 const O3Label& parent,
339 ErrorsContainer& errors) {
340 const auto& pos = label.position();
341 std::stringstream msg;
343 <<
"Label " << label <<
" is not part of " << parent <<
" domain";
344 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
347 void O3PRM_CLASS_WRONG_PARENT(
const O3Label& prnt, ErrorsContainer& errors) {
348 const auto& pos = prnt.position();
349 std::stringstream msg;
351 <<
"Illegal parent " << prnt;
352 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
355 void O3PRM_CLASS_WRONG_PARENT_TYPE(
const O3Label& prnt,
356 const std::string& expected,
357 const std::string& found,
358 ErrorsContainer& errors) {
359 const auto& pos = prnt.position();
360 std::stringstream msg;
362 <<
"Expected type " << expected <<
" for parent " << prnt.label()
363 <<
", found " << found;
364 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
367 void O3PRM_CLASS_ILLEGAL_OVERLOAD(
const O3Label& elt,
369 ErrorsContainer& errors) {
370 const auto& pos = elt.position();
371 std::stringstream msg;
373 <<
"Illegal overload of element " << elt.label() <<
" from class " 375 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
378 void O3PRM_CLASS_AGG_PARAMETERS(
const O3Label& agg,
381 ErrorsContainer& errors) {
382 const auto& pos = agg.position();
383 std::stringstream msg;
385 <<
"Expected " << expected <<
" parameters " 386 <<
", found " << found;
387 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
390 void O3PRM_CLASS_AGG_PARAMETER_NOT_FOUND(
const O3Label& agg,
391 const O3Label& param,
392 ErrorsContainer& errors) {
393 const auto& pos = param.position();
394 std::stringstream msg;
396 <<
"Parameter " << param.label() <<
" in aggregate " << agg.label()
397 <<
" does not match any expected values";
398 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
401 void O3PRM_INTERFACE_ILLEGAL_ARRAY(
const O3Label& val,
402 ErrorsContainer& errors) {
403 const auto& pos = val.position();
404 std::stringstream msg;
406 <<
"PRMAttribute " << val.label() <<
" can not be an array";
407 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
410 void O3PRM_INTERFACE_NOT_FOUND(
const O3Label& val, ErrorsContainer& errors) {
411 const auto& pos = val.position();
412 std::stringstream msg;
414 <<
"Interface " << val.label() <<
" not found";
415 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
418 void O3PRM_INTERFACE_AMBIGUOUS(
const O3Label& val,
419 const std::vector< std::string >& matches,
420 ErrorsContainer& errors) {
421 const auto& pos = val.position();
422 std::stringstream msg;
424 <<
"Name " << val.label() <<
" is ambiguous: ";
425 for (std::size_t i = 0; i < matches.size() - 1; ++i) {
426 msg << matches[i] <<
", ";
428 msg << matches.back();
429 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
432 void O3PRM_INTERFACE_DUPLICATE(
const O3Label& val, ErrorsContainer& errors) {
433 const auto& pos = val.position();
434 std::stringstream msg;
436 <<
"Interface name " << val.label() <<
" exists already";
437 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
440 void O3PRM_INTERFACE_DUPLICATE_ELEMENT(
const O3InterfaceElement& elt,
441 ErrorsContainer& errors) {
442 const auto& pos = elt.type().position();
443 std::stringstream msg;
445 <<
"Element " << elt.name().label() <<
" already exists";
446 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
449 void O3PRM_INTERFACE_CYCLIC_INHERITANCE(
const O3Label& sub,
450 const O3Label& super,
451 ErrorsContainer& errors) {
452 const auto& pos = super.position();
453 std::stringstream msg;
455 <<
"Cyclic inheritance between interface " << sub.label()
456 <<
" and interface " << super.label();
457 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
460 void O3PRM_INTERFACE_SELF_REFERENCE(
const O3Interface& i,
461 const O3InterfaceElement& r,
462 ErrorsContainer& errors) {
463 const auto& pos = r.type().position();
464 std::stringstream msg;
466 <<
"Interface " << i.name().label() <<
" cannot reference itself";
467 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
470 void O3PRM_INTERFACE_ILLEGAL_SUB_REFERENCE(
const O3Interface& i,
471 const O3InterfaceElement& ref,
472 ErrorsContainer& errors) {
473 const auto& pos = ref.type().position();
474 std::stringstream msg;
476 <<
"Interface " << i.name().label()
477 <<
" cannot reference subinterface " << ref.type().label();
478 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
481 void O3PRM_INTERFACE_ILLEGAL_OVERLOAD(
const O3InterfaceElement& elt,
482 ErrorsContainer& errors) {
483 const auto& pos = elt.type().position();
484 std::stringstream msg;
486 <<
"Illegal overload of element " << elt.name().label();
487 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
490 void O3PRM_REFERENCE_NOT_FOUND(
const O3Label& val, ErrorsContainer& errors) {
491 const auto& pos = val.position();
492 std::stringstream msg;
494 <<
"Reference Slot type " << val.label() <<
" not found";
495 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
498 void O3PRM_REFERENCE_AMBIGUOUS(
const O3Label& val,
499 const std::vector< std::string >& matches,
500 ErrorsContainer& errors) {
501 const auto& pos = val.position();
502 std::stringstream msg;
504 <<
"Name " << val.label() <<
" is ambiguous: ";
505 for (std::size_t i = 0; i < matches.size() - 1; ++i) {
506 msg << matches[i] <<
", ";
508 msg << matches.back();
509 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
512 void O3PRM_SYSTEM_INSTANTIATION_FAILED(
const O3System& sys,
513 ErrorsContainer& errors) {
514 const auto& pos = sys.name().position();
515 std::stringstream msg;
517 <<
"Could not instantiate the system, some reference slots must be " 519 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
522 void O3PRM_SYSTEM_NOT_A_CLASS(
const O3Instance& i, ErrorsContainer& errors) {
523 const auto& pos = i.type().position();
524 std::stringstream msg;
525 msg <<
"Error : " << i.type().label() <<
" is not a class";
526 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
529 void O3PRM_SYSTEM_DUPLICATE_INSTANCE(
const O3Instance& i,
530 ErrorsContainer& errors) {
531 const auto& pos = i.type().position();
532 std::stringstream msg;
534 <<
"Instance " << i.name().label() <<
" already exists";
535 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
538 void O3PRM_SYSTEM_NOT_A_PARAMETER(
const O3InstanceParameter& param,
539 ErrorsContainer& errors) {
540 const auto& pos = param.name().position();
541 std::stringstream msg;
542 msg <<
"Instance error : " << param.name().label()
543 <<
" is not a parameter";
544 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
547 void O3PRM_SYSTEM_PARAMETER_NOT_FOUND(
const O3InstanceParameter& param,
548 ErrorsContainer& errors) {
549 const auto& pos = param.name().position();
550 std::stringstream msg;
552 <<
"Parameter " << param.name().label() <<
" not found";
553 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
556 void O3PRM_SYSTEM_PARAMETER_NOT_INT(
const O3InstanceParameter& param,
557 ErrorsContainer& errors) {
558 const auto& pos = param.value().position();
559 std::stringstream msg;
561 <<
"Parameter " << param.name().label() <<
" is an integer";
562 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
565 void O3PRM_SYSTEM_PARAMETER_NOT_FLOAT(
const O3InstanceParameter& param,
566 ErrorsContainer& errors) {
567 const auto& pos = param.value().position();
568 std::stringstream msg;
570 <<
"Parameter " << param.name().label() <<
" is a float";
571 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
574 void O3PRM_SYSTEM_INVALID_LEFT_VALUE(
const O3Label& val,
575 ErrorsContainer& errors) {
576 const auto& pos = val.position();
577 std::stringstream msg;
579 <<
"Invalid left expression " << val.label();
580 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
583 void O3PRM_SYSTEM_INSTANCE_NOT_FOUND(
const O3Label& i,
584 ErrorsContainer& errors) {
585 const auto& pos = i.position();
586 std::stringstream msg;
588 <<
"Instance " << i.label() <<
" not found";
589 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
592 void O3PRM_SYSTEM_REFERENCE_NOT_FOUND(
const O3Label& ref,
593 const std::string& type,
594 ErrorsContainer& errors) {
595 const auto& pos = ref.position();
596 std::stringstream msg;
598 <<
"Reference " << ref.label() <<
" not found in class " << type;
599 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
602 void O3PRM_SYSTEM_NOT_AN_ARRAY(
const O3Label& val, ErrorsContainer& errors) {
603 const auto& pos = val.position();
604 std::stringstream msg;
605 msg <<
"Error : " << val.label() <<
" is not an array";
606 errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
609 void O3PRM_DEPRECATED_TYPE_WARNING(
const O3Label& val,
610 ErrorsContainer& errors) {
611 const auto& pos = val.position();
612 std::stringstream msg;
613 msg <<
"Warning : " << val.label()
614 <<
" is declared using a deprecated syntax.";
615 errors.addWarning(msg.str(), pos.file(), pos.line(), pos.column());
INLINE void emplace(Args &&... args)
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)