OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [libcdl/] [conflict.cxx] - Blame information for rev 857

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//{{{  Banner                           
2
 
3
//============================================================================
4
//
5
//      conflict.cxx
6
//
7
//      The CdlConflict class
8
//
9
//============================================================================
10
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
11
// -------------------------------------------                              
12
// This file is part of the eCos host tools.                                
13
// Copyright (C) 1999, 2000 Free Software Foundation, Inc.                  
14
//
15
// This program is free software; you can redistribute it and/or modify     
16
// it under the terms of the GNU General Public License as published by     
17
// the Free Software Foundation; either version 2 or (at your option) any   
18
// later version.                                                           
19
//
20
// This program is distributed in the hope that it will be useful, but      
21
// WITHOUT ANY WARRANTY; without even the implied warranty of               
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
23
// General Public License for more details.                                 
24
//
25
// You should have received a copy of the GNU General Public License        
26
// along with this program; if not, write to the                            
27
// Free Software Foundation, Inc., 51 Franklin Street,                      
28
// Fifth Floor, Boston, MA  02110-1301, USA.                                
29
// -------------------------------------------                              
30
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
31
//============================================================================
32
//#####DESCRIPTIONBEGIN####
33
//
34
// Author(s):   bartv
35
// Contact(s):  bartv
36
// Date:        1999/01/28
37
// Version:     0.02
38
//
39
//####DESCRIPTIONEND####
40
//============================================================================
41
 
42
//}}}
43
//{{{  #include's                       
44
 
45
// ----------------------------------------------------------------------------
46
#include "cdlconfig.h"
47
 
48
// Get the infrastructure types, assertions, tracing and similar
49
// facilities.
50
#include <cyg/infra/cyg_ass.h>
51
#include <cyg/infra/cyg_trac.h>
52
 
53
// <cdlcore.hxx> defines everything implemented in this module.
54
// It implicitly supplies <string>, <vector> and <map> because
55
// the class definitions rely on these headers. It also brings
56
// in <tcl.h>
57
#include <cdlcore.hxx>
58
 
59
//}}}
60
 
61
//{{{  Statics                          
62
 
63
// ----------------------------------------------------------------------------
64
CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlConflictBody);
65
CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlConflict_UnresolvedBody);
66
CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlConflict_IllegalValueBody);
67
CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlConflict_EvalExceptionBody);
68
CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlConflict_RequiresBody);
69
CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlConflict_DataBody);
70
 
71
//}}}
72
//{{{  CdlConflict                      
73
 
74
//{{{  Creation and destruction                 
75
 
76
// ----------------------------------------------------------------------------
77
// The basic conflicts. Conflicts are created in the context of a transaction.
78
// If the transaction gets committed then they are transferred to a toplevel.
79
// If the transaction gets cancelled then they just disappear.
80
//
81
// A conflict that is only part of a transaction may go away as that
82
// transaction proceeds, in which case it can be deleted immediately.
83
// A conflict that is already part of the toplevel cannot be
84
// destroyed, instead it gets marked in the transaction object. Only
85
// when the transaction is committed does the object get deleted.
86
// In addition within the context of a transaction old conflicts
87
// may hang around for a while.
88
//
89
 
90
CdlConflictBody::CdlConflictBody(CdlTransaction trans_arg, CdlNode node_arg, CdlProperty property_arg, bool structural_arg)
91
{
92
    CYG_REPORT_FUNCNAME("CdlConflict:: constructor");
93
    CYG_REPORT_FUNCARG4XV(this, trans_arg, node_arg, property_arg);
94
    CYG_PRECONDITION_CLASSC(trans_arg);
95
    CYG_PRECONDITION_CLASSC(node_arg);
96
    CYG_PRECONDITION_CLASSC(property_arg);
97
 
98
    node        = node_arg;
99
    property    = property_arg;
100
    transaction = trans_arg;
101
    structural  = structural_arg;
102
    no_solution = false;
103
    // The vectors take care of themselves
104
    enabled     = true;
105
    reason      = "";
106
 
107
    transaction->dirty = true;
108
    if (structural_arg) {
109
        transaction->new_structural_conflicts.push_back(this);
110
    } else {
111
        transaction->new_conflicts.push_back(this);
112
    }
113
 
114
    cdlconflictbody_cookie      = CdlConflictBody_Magic;
115
    CYGDBG_MEMLEAK_CONSTRUCTOR();
116
 
117
    CYG_POSTCONDITION_THISC();
118
    CYG_REPORT_RETURN();
119
}
120
 
121
 
122
// ----------------------------------------------------------------------------
123
// The destructor can get invoked during a transaction commit, in the
124
// case of a global conflict, or from inside clear() for a per-transaction
125
// conflict. In all cases the calling code is responsible for removing
126
// the conflict from any STL containers.
127
 
128
CdlConflictBody::~CdlConflictBody()
129
{
130
    CYG_REPORT_FUNCNAME("CdlConflict:: destructor");
131
    CYG_REPORT_FUNCARG1XV(this);
132
    CYG_PRECONDITION_THISC();
133
 
134
    cdlconflictbody_cookie      = CdlConflictBody_Invalid;
135
    reason                      = "";
136
    enabled                     = false;
137
    no_solution                 = false;
138
    solution.clear();
139
    solution_references.clear();
140
    structural                  = false;
141
    transaction                 = 0;
142
    property                    = 0;
143
    node                        = 0;
144
    CYGDBG_MEMLEAK_DESTRUCTOR();
145
 
146
    CYG_REPORT_RETURN();
147
}
148
 
149
//}}}
150
//{{{  Solution support                         
151
 
152
// ----------------------------------------------------------------------------
153
bool
154
CdlConflictBody::has_known_solution() const
155
{
156
    CYG_REPORT_FUNCNAMETYPE("CdlConflict::has_solution", "result %d");
157
    CYG_REPORT_FUNCARG1XV(this);
158
    CYG_PRECONDITION_THISC();
159
 
160
    bool result = (0 != solution.size());
161
 
162
    CYG_REPORT_RETVAL(result);
163
    return result;
164
}
165
 
166
bool
167
CdlConflictBody::has_no_solution() const
168
{
169
    CYG_REPORT_FUNCNAMETYPE("CdlConflict::has_no_solution", "result %d");
170
    CYG_REPORT_FUNCARG1XV(this);
171
    CYG_PRECONDITION_THISC();
172
 
173
    bool result = no_solution;
174
 
175
    CYG_REPORT_RETVAL(result);
176
    return result;
177
}
178
 
179
const std::vector<std::pair<CdlValuable, CdlValue> >&
180
CdlConflictBody::get_solution() const
181
{
182
    CYG_REPORT_FUNCNAME("CdlConflict::get_solution");
183
    CYG_REPORT_FUNCARG1XV(this);
184
    CYG_PRECONDITION_THISC();
185
 
186
    CYG_REPORT_RETURN();
187
    return solution;
188
}
189
 
190
const std::set<CdlValuable>&
191
CdlConflictBody::get_solution_references() const
192
{
193
    CYG_REPORT_FUNCNAME("CdlConflict::get_solution_references");
194
    CYG_REPORT_FUNCARG1XV(this);
195
    CYG_PRECONDITION_THISC();
196
 
197
    CYG_REPORT_RETURN();
198
    return solution_references;
199
}
200
 
201
// ----------------------------------------------------------------------------
202
// Try to resolve a conflict. If the conflict was created in a transaction,
203
// use that transaction. More commonly the conflict will be global and
204
// a new transaction will have to be created specially for it. Either
205
// way the conflict may cease to exist.
206
void
207
CdlConflictBody::resolve()
208
{
209
    CYG_REPORT_FUNCNAME("CdlConflict::resolve");
210
    CYG_REPORT_FUNCARG1XV(this);
211
    CYG_PRECONDITION_THISC();
212
    CYG_PRECONDITIONC(0 == transaction);
213
 
214
    if (this->resolution_implemented()) {
215
        CdlTransaction transact = CdlTransactionBody::make(this->get_node()->get_toplevel());
216
        transact->resolve(this);
217
        transact->body();
218
        delete transact;
219
    }
220
 
221
    CYG_REPORT_RETURN();
222
}
223
 
224
// ----------------------------------------------------------------------------
225
// A valuable has just been changed. If this value was relevant to the
226
// current solution (or lack thereof) then an update is necessary.
227
void
228
CdlConflictBody::update_solution_validity(CdlValuable valuable)
229
{
230
    CYG_REPORT_FUNCNAME("CdlConflict::update_solution_validity");
231
    CYG_REPORT_FUNCARG2XV(this, valuable);
232
    CYG_PRECONDITION_THISC();
233
 
234
    if (solution_references.find(valuable) != solution_references.end()) {
235
        no_solution = false;
236
        solution.clear();
237
        solution_references.clear();
238
    }
239
 
240
    CYG_REPORT_RETURN();
241
}
242
 
243
// ----------------------------------------------------------------------------
244
// Default implementations of the inference engine do not do a lot...
245
bool
246
CdlConflictBody::inner_resolve(CdlTransaction trans_arg, int level)
247
{
248
    CYG_REPORT_FUNCNAMETYPE("CdlConflict::inner_resolve", "result false");
249
    CYG_REPORT_FUNCARG3XV(this, trans_arg, level);
250
    CYG_PRECONDITION_THISC();
251
    CYG_PRECONDITION_CLASSC(trans_arg);
252
 
253
    // Setting the no_solution flag while keeping a clear
254
    // solution_accessed vector means that the no_solution flag should
255
    // always remain set, and hence no further inference attempts will be made.
256
    no_solution = true;
257
 
258
    CYG_REPORT_RETURN();
259
    return false;
260
}
261
 
262
bool
263
CdlConflictBody::resolution_implemented() const
264
{
265
    CYG_REPORT_FUNCNAMETYPE("CdlConflict::resolution_implemented", "result %d");
266
    CYG_REPORT_FUNCARG1XV(this);
267
    CYG_PRECONDITION_THISC();
268
 
269
    CYG_REPORT_RETVAL(false);
270
    return false;
271
}
272
 
273
// ----------------------------------------------------------------------------
274
// Clearing a solution. This is needed if the inference engine has
275
// failed to find a complete solution, because in attempting this the
276
// solution_references vector will have been filled in anyway. It may
277
// have some other uses as well.
278
void
279
CdlConflictBody::clear_solution()
280
{
281
    CYG_REPORT_FUNCNAME("CdlConflict::clear_solution");
282
    CYG_REPORT_FUNCARG1XV(this);
283
    CYG_PRECONDITION_THISC();
284
 
285
    no_solution = false;
286
    solution.clear();
287
    solution_references.clear();
288
 
289
    CYG_REPORT_RETURN();
290
}
291
 
292
//}}}
293
//{{{  Basics                                   
294
 
295
// ----------------------------------------------------------------------------
296
 
297
CdlNode
298
CdlConflictBody::get_node() const
299
{
300
    CYG_REPORT_FUNCNAMETYPE("CdlConflict::get_node", "result %p");
301
    CYG_REPORT_FUNCARG1XV(this);
302
    CYG_PRECONDITION_THISC();
303
 
304
    CdlNode result = node;
305
    CYG_REPORT_RETVAL(result);
306
    return result;
307
}
308
 
309
CdlProperty
310
CdlConflictBody::get_property() const
311
{
312
    CYG_REPORT_FUNCNAMETYPE("CdlConflict::get_property", "result %p");
313
    CYG_REPORT_FUNCARG1XV(this);
314
    CYG_PRECONDITION_THISC();
315
 
316
    CdlProperty result  = property;
317
    CYG_REPORT_RETVAL(result);
318
    return result;
319
}
320
 
321
bool
322
CdlConflictBody::is_structural() const
323
{
324
    CYG_REPORT_FUNCNAMETYPE("CdlConflict::is_structural", "result %d");
325
    CYG_REPORT_FUNCARG1XV(this);
326
    CYG_PRECONDITION_THISC();
327
 
328
    bool result = structural;
329
    CYG_REPORT_RETVAL(result);
330
    return result;
331
}
332
 
333
CdlTransaction
334
CdlConflictBody::get_transaction() const
335
{
336
    CYG_REPORT_FUNCNAMETYPE("CdlConflict::get_transaction", "result %p");
337
    CYG_REPORT_FUNCARG1XV(this);
338
    CYG_PRECONDITION_THISC();
339
 
340
    CdlTransaction result = transaction;
341
    CYG_REPORT_RETVAL(result);
342
    return result;
343
}
344
 
345
// FIXME: these are not currently implemented. It would be necessary
346
// to store the information in the savefile, which requires an
347
// unambiguous way of identifying a conflict that is likely to
348
// survice package version changes.
349
 
350
bool
351
CdlConflictBody::is_enabled() const
352
{
353
    CYG_REPORT_FUNCNAMETYPE("CdlConflict::is_enabled", "result %d");
354
    CYG_REPORT_FUNCARG1XV(this);
355
    CYG_PRECONDITION_THISC();
356
 
357
    bool result = enabled;
358
    CYG_REPORT_RETVAL(result);
359
    return result;
360
}
361
 
362
std::string
363
CdlConflictBody::get_disabled_reason() const
364
{
365
    CYG_REPORT_FUNCNAME("CdlConflict::get_disabled_reason");
366
    CYG_REPORT_FUNCARG1XV(this);
367
    CYG_PRECONDITION_THISC();
368
 
369
    // Possibly there should be a check that the conflict is currently
370
    // disabled, but it might be useful. 
371
    CYG_REPORT_RETURN();
372
    return reason;
373
}
374
 
375
void
376
CdlConflictBody::disable(std::string reason_arg)
377
{
378
    CYG_REPORT_FUNCNAME("CdlConflict::disable");
379
    CYG_REPORT_FUNCARG1XV(this);
380
    CYG_PRECONDITION_THISC();
381
 
382
    reason      = reason_arg;
383
    enabled     = false;
384
 
385
    CYG_REPORT_RETURN();
386
}
387
 
388
void
389
CdlConflictBody::enable()
390
{
391
    CYG_REPORT_FUNCNAME("CdlConflict::enable");
392
    CYG_REPORT_FUNCARG1XV(this);
393
    CYG_PRECONDITION_THISC();
394
 
395
    enabled     = true;
396
    // Leave "reason" alone, it may still be useful
397
 
398
    CYG_REPORT_RETURN();
399
}
400
 
401
//}}}
402
//{{{  check_this()                             
403
 
404
// ----------------------------------------------------------------------------
405
bool
406
CdlConflictBody::check_this(cyg_assert_class_zeal zeal) const
407
{
408
    if (CdlConflictBody_Magic != cdlconflictbody_cookie) {
409
        return false;
410
    }
411
    CYGDBG_MEMLEAK_CHECKTHIS();
412
    if ((0 == node) || (0 == property)) {
413
        return false;
414
    }
415
    switch(zeal) {
416
      case cyg_system_test :
417
      case cyg_extreme :
418
      {
419
          if (!node->check_this(cyg_quick)) {
420
              return false;
421
          }
422
          // Accessing the properties would involve a function call.
423
 
424
          if (0 != transaction) {
425
              if (!transaction->check_this(cyg_quick)) {
426
                  return false;
427
              }
428
              if (structural) {
429
                  // The conflict should exist in the new_structural_conflicts vector
430
                  // deleted_structural_conflicts is for toplevel ones.
431
                  if (std::find(transaction->new_structural_conflicts.begin(),
432
                                transaction->new_structural_conflicts.end(), this) ==
433
                      transaction->new_structural_conflicts.end()) {
434
                      return false;
435
                  }
436
              } else {
437
                  // The conflict may appear on the new_conflicts list
438
                  // or in the resolved_conflicts vector.
439
                  if (std::find(transaction->new_conflicts.begin(), transaction->new_conflicts.end(), this) ==
440
                      transaction->new_conflicts.end()) {
441
 
442
                      if (std::find(transaction->resolved_conflicts.begin(), transaction->resolved_conflicts.end(), this) ==
443
                          transaction->resolved_conflicts.end()) {
444
 
445
                          return false;
446
                      }
447
                  }
448
              }
449
          }
450
          // Checking the toplevel lists would be good, but involves a
451
          // further function call and hence nested assertions.
452
      }
453
      case cyg_thorough :
454
      {
455
          if (!node->check_this(cyg_quick)) {
456
              return false;
457
          }
458
          if (!property->check_this(cyg_quick)) {
459
              return false;
460
          }
461
      }
462
      case cyg_quick :
463
      {
464
          if (no_solution && (0 != solution.size())) {
465
              return false;
466
          }
467
      }
468
      case cyg_trivial :
469
      case cyg_none :
470
      default:
471
          break;
472
    }
473
 
474
    return true;
475
}
476
 
477
//}}}
478
 
479
//}}}
480
//{{{  CdlConflict_Unresolved           
481
 
482
// ----------------------------------------------------------------------------
483
// Unresolved references. Usually unresolved references occur inside
484
// expressions, but other properties that may be affected are parent,
485
// dialog and wizard.
486
//
487
// It is possible for a single expression to have multiple unresolved
488
// references, each of which will result in a separate conflict
489
// object. It is also possible for an expression to refer to the same
490
// unknown entity twice or more, in which case there would also be
491
// separate conflict objects. Unresolved references may also result in
492
// eval exceptions and in failed requires statements. Trying to cope
493
// with the various combinations as a single conflict seems too
494
// error-prone.
495
 
496
void
497
CdlConflict_UnresolvedBody::make(CdlTransaction trans, CdlNode node_arg, CdlProperty prop_arg, std::string name_arg)
498
{
499
    CdlConflict_Unresolved tmp = new CdlConflict_UnresolvedBody(trans, node_arg, prop_arg, name_arg);
500
    CYG_UNUSED_PARAM(CdlConflict_Unresolved, tmp);
501
}
502
 
503
CdlConflict_UnresolvedBody::CdlConflict_UnresolvedBody(CdlTransaction trans_arg, CdlNode node_arg, CdlProperty prop_arg,
504
                                                       std::string target_name_arg)
505
    : CdlConflictBody(trans_arg, node_arg, prop_arg, true)
506
{
507
    CYG_REPORT_FUNCNAME("CdlConflict_Unresolved:: constructor");
508
    CYG_REPORT_FUNCARG1XV(this);
509
    CYG_PRECONDITIONC("" != target_name_arg);
510
 
511
    target_name = target_name_arg;
512
    cdlconflict_unresolvedbody_cookie = CdlConflict_UnresolvedBody_Magic;
513
    CYGDBG_MEMLEAK_CONSTRUCTOR();
514
 
515
    CYG_POSTCONDITION_THISC();
516
    CYG_REPORT_RETURN();
517
}
518
 
519
CdlConflict_UnresolvedBody::~CdlConflict_UnresolvedBody()
520
{
521
    CYG_REPORT_FUNCNAME("CdlConflict_Unresolved:: destructor");
522
    CYG_REPORT_FUNCARG1XV(this);
523
    CYG_PRECONDITION_THISC();
524
 
525
    cdlconflict_unresolvedbody_cookie = CdlConflict_UnresolvedBody_Invalid;
526
    target_name = "";
527
    CYGDBG_MEMLEAK_DESTRUCTOR();
528
 
529
    CYG_REPORT_RETURN();
530
}
531
 
532
std::string
533
CdlConflict_UnresolvedBody::get_target_name() const
534
{
535
    CYG_REPORT_FUNCNAME("CdlConflict_Unresolved::get_target_name");
536
    CYG_REPORT_FUNCARG1XV(this);
537
    CYG_PRECONDITION_THISC();
538
 
539
    CYG_REPORT_RETURN();
540
    return target_name;
541
}
542
 
543
// For now, just report the node and property name, a brief text, and the
544
// entity being referenced. 
545
//
546
// Eventually we can do clever things like looking up the name in a
547
// database.
548
 
549
std::string
550
CdlConflict_UnresolvedBody::get_explanation() const
551
{
552
    CYG_REPORT_FUNCNAME("CdlConflict_Unresolved::get_explanation");
553
    CYG_REPORT_FUNCARG1XV(this);
554
    CYG_PRECONDITION_THISC();
555
 
556
    std::string result;
557
    result = node->get_name() + ", property " + property->get_property_name() +
558
        ":\nReference to unknown object " + target_name;
559
 
560
    CYG_REPORT_RETURN();
561
    return result;
562
}
563
 
564
bool
565
CdlConflict_UnresolvedBody::check_this(cyg_assert_class_zeal zeal) const
566
{
567
    if (CdlConflict_UnresolvedBody_Magic != cdlconflict_unresolvedbody_cookie) {
568
        return false;
569
    }
570
    CYGDBG_MEMLEAK_CHECKTHIS();
571
 
572
    // There is not a lot of checking that can be done on the name.
573
 
574
    return CdlConflictBody::check_this(zeal);
575
}
576
 
577
bool
578
CdlConflict_UnresolvedBody::test(CdlConflict conf)
579
{
580
    CYG_REPORT_FUNCNAMETYPE("CdlConflict_Unresolved::test", "result %d");
581
    CYG_REPORT_FUNCARG1XV(conf);
582
    CYG_PRECONDITION_CLASSC(conf);
583
 
584
    bool result = false;
585
    CdlConflict_Unresolved tmp = dynamic_cast<CdlConflict_Unresolved>(conf);
586
    if (0 != tmp) {
587
        result = true;
588
    }
589
 
590
    CYG_REPORT_RETVAL(result);
591
    return result;
592
}
593
 
594
//}}}
595
//{{{  CdlConflict_IllegalValue         
596
 
597
// ----------------------------------------------------------------------------
598
// A valuable object has an illegal value. This can happen because the
599
// current value is not within the legal_values list, or because of a
600
// failure of check_proc or entry_proc. In the latter two cases the
601
// Tcl code should supply an explanation as to why the value is illegal.
602
//
603
// Note: if future variants of CDL implement some concept of a value
604
// that does not match the CdlValuable class then that will need a
605
// separate CdlConflict derived class.
606
 
607
void
608
CdlConflict_IllegalValueBody::make(CdlTransaction trans, CdlNode node_arg, CdlProperty prop_arg)
609
{
610
    CdlConflict_IllegalValue tmp = new CdlConflict_IllegalValueBody(trans, node_arg, prop_arg);
611
    CYG_UNUSED_PARAM(CdlConflict_IllegalValue, tmp);
612
}
613
 
614
CdlConflict_IllegalValueBody::CdlConflict_IllegalValueBody(CdlTransaction trans, CdlNode node_arg, CdlProperty prop_arg)
615
    : CdlConflictBody(trans, node_arg, prop_arg, false)
616
{
617
    CYG_REPORT_FUNCNAME("CdlConflict_IllegalValue:: constructor");
618
    CYG_REPORT_FUNCARG1XV(this);
619
    CYG_PRECONDITIONC(0 != dynamic_cast<CdlValuable>(node_arg));
620
 
621
    explanation = "";
622
    cdlconflict_illegalvaluebody_cookie = CdlConflict_IllegalValueBody_Magic;
623
    CYGDBG_MEMLEAK_CONSTRUCTOR();
624
 
625
    CYG_POSTCONDITION_THISC();
626
    CYG_REPORT_RETURN();
627
}
628
 
629
CdlConflict_IllegalValueBody::~CdlConflict_IllegalValueBody()
630
{
631
    CYG_REPORT_FUNCNAME("CdlConflict_IllegalValue:: destructor");
632
    CYG_REPORT_FUNCARG1XV(this);
633
    CYG_PRECONDITION_THISC();
634
 
635
    cdlconflict_illegalvaluebody_cookie = CdlConflict_IllegalValueBody_Invalid;
636
    explanation = "";
637
    CYGDBG_MEMLEAK_DESTRUCTOR();
638
 
639
    CYG_REPORT_RETURN();
640
}
641
 
642
// ----------------------------------------------------------------------------
643
// If the property is legal_values then it should be a list expression
644
// property. Display the current value and the original expression.
645
//
646
// If the property is check_proc or entry_proc, the Tcl code should
647
// have produced an explanation string and stored it in the conflict
648
// object.
649
std::string
650
CdlConflict_IllegalValueBody::get_explanation() const
651
{
652
    CYG_REPORT_FUNCNAME("CdlConflict_IllegalValue::get_explanation()");
653
    CYG_REPORT_FUNCARG1XV(this);
654
    CYG_PRECONDITION_THISC();
655
 
656
    CdlConstValuable valuable = dynamic_cast<CdlConstValuable>(node);
657
    CYG_ASSERTC(0 != valuable);
658
 
659
    std::string result = "";
660
 
661
    // FIXME: analyse the current value and flavor a bit more
662
    result += "Illegal current value " + valuable->get_value() + "\n";
663
 
664
    if (CdlPropertyId_LegalValues == property->get_property_name()) {
665
 
666
        CdlConstProperty_ListExpression expr = dynamic_cast<CdlConstProperty_ListExpression>(property);
667
        CYG_ASSERTC(0 != expr);
668
        result += "Legal values are: " + expr->get_original_string();
669
 
670
    } else if (explanation != "") {
671
 
672
        result += explanation;
673
    } else {
674
 
675
        CYG_FAIL("Inexplicable illegal value");
676
    }
677
 
678
    CYG_REPORT_RETURN();
679
    return result;
680
}
681
 
682
void
683
CdlConflict_IllegalValueBody::set_explanation(std::string explanation_arg)
684
{
685
    CYG_REPORT_FUNCNAME("CdlConflict_IllegalValue::set_explanation");
686
    CYG_REPORT_FUNCARG1XV(this);
687
    CYG_PRECONDITION_THISC();
688
 
689
    explanation = explanation_arg;
690
 
691
    CYG_REPORT_RETURN();
692
}
693
 
694
// ----------------------------------------------------------------------------
695
// Inference is implemented. The actual inference code is in infer.cxx
696
bool
697
CdlConflict_IllegalValueBody::resolution_implemented() const
698
{
699
    CYG_REPORT_FUNCNAME("CdlConflict_IllegalValue::resolution_implemented");
700
    CYG_REPORT_FUNCARG1XV(this);
701
    CYG_PRECONDITION_THISC();
702
 
703
    CYG_REPORT_RETURN();
704
    return true;
705
}
706
 
707
// ----------------------------------------------------------------------------
708
bool
709
CdlConflict_IllegalValueBody::check_this(cyg_assert_class_zeal zeal) const
710
{
711
    if (CdlConflict_IllegalValueBody_Magic != cdlconflict_illegalvaluebody_cookie) {
712
        return false;
713
    }
714
    CYGDBG_MEMLEAK_CHECKTHIS();
715
 
716
    return CdlConflictBody::check_this(zeal);
717
}
718
 
719
bool
720
CdlConflict_IllegalValueBody::test(CdlConflict conf)
721
{
722
    CYG_REPORT_FUNCNAMETYPE("CdlConflict_IllegalValue::test", "result %d");
723
    CYG_REPORT_FUNCARG1XV(conf);
724
    CYG_PRECONDITION_CLASSC(conf);
725
 
726
    bool result = false;
727
    CdlConflict_IllegalValue tmp = dynamic_cast<CdlConflict_IllegalValue>(conf);
728
    if (0 != tmp) {
729
        result = true;
730
    }
731
 
732
    CYG_REPORT_RETVAL(result);
733
    return result;
734
}
735
 
736
//}}}
737
//{{{  CdlConflict_EvalException        
738
 
739
// ----------------------------------------------------------------------------
740
// Run-time expression failures are possible because of division by
741
// zero, if for no other reason. The evaluation code should have
742
// stored a suitable diagnostic with the conflict. This is not part
743
// of the constructor, allowing the conflict object to be re-used
744
// if the detailed reason changes
745
 
746
void
747
CdlConflict_EvalExceptionBody::make(CdlTransaction trans, CdlNode node_arg, CdlProperty prop_arg, std::string msg_arg)
748
{
749
    CdlConflict_EvalException tmp = new CdlConflict_EvalExceptionBody(trans, node_arg, prop_arg, msg_arg);
750
    CYG_UNUSED_PARAM(CdlConflict_EvalException, tmp);
751
}
752
 
753
CdlConflict_EvalExceptionBody::CdlConflict_EvalExceptionBody(CdlTransaction trans, CdlNode node_arg, CdlProperty prop_arg,
754
                                                             std::string msg_arg)
755
    : CdlConflictBody(trans, node_arg, prop_arg, false)
756
{
757
    CYG_REPORT_FUNCNAME("CdlConflict_EvalException");
758
    CYG_REPORT_FUNCARG1XV(this);
759
 
760
    explanation = msg_arg;
761
    cdlconflict_evalexceptionbody_cookie = CdlConflict_EvalExceptionBody_Magic;
762
    CYGDBG_MEMLEAK_CONSTRUCTOR();
763
 
764
    CYG_POSTCONDITION_THISC();
765
    CYG_REPORT_RETURN();
766
}
767
 
768
CdlConflict_EvalExceptionBody::~CdlConflict_EvalExceptionBody()
769
{
770
    CYG_REPORT_FUNCNAME("CdlConflict_EvalException");
771
    CYG_REPORT_FUNCARG1XV(this);
772
    CYG_PRECONDITION_THISC();
773
 
774
    cdlconflict_evalexceptionbody_cookie = CdlConflict_EvalExceptionBody_Invalid;
775
    explanation = "";
776
    CYGDBG_MEMLEAK_DESTRUCTOR();
777
 
778
    CYG_REPORT_RETURN();
779
}
780
 
781
// If there has been an eval exception then the property must be an
782
// ordinary expression, a list expression, or a goal expression
783
std::string
784
CdlConflict_EvalExceptionBody::get_explanation() const
785
{
786
    CYG_REPORT_FUNCNAME("CdlConflict_EvalException::get_explanation");
787
    CYG_REPORT_FUNCARG1XV(this);
788
    CYG_PRECONDITION_THISC();
789
 
790
    std::string result = node->get_name() + ", property " + property->get_property_name() + "\n";
791
    result += "Error while evaluating expression: ";
792
    if ("" != explanation) {
793
        result += explanation;
794
    }
795
    result += "\n";
796
 
797
    if (CdlConstProperty_Expression expr = dynamic_cast<CdlConstProperty_Expression>(property)) {
798
 
799
        result += "Expression: " + expr->get_original_string();
800
 
801
    } else if (CdlConstProperty_ListExpression lexpr = dynamic_cast<CdlConstProperty_ListExpression>(property)) {
802
 
803
        result += "List expression: " + lexpr->get_original_string();
804
 
805
    } else if (CdlConstProperty_GoalExpression gexpr = dynamic_cast<CdlConstProperty_GoalExpression>(property)) {
806
 
807
        result += "Goal expression: " + gexpr->get_original_string();
808
 
809
    } else {
810
        CYG_FAIL("Unknown expression type");
811
    }
812
 
813
    CYG_REPORT_RETURN();
814
    return result;
815
}
816
 
817
void
818
CdlConflict_EvalExceptionBody::set_explanation(std::string explanation_arg)
819
{
820
    CYG_REPORT_FUNCNAME("CdlConflict_EvalException::set_explanation");
821
    CYG_REPORT_FUNCARG1XV(this);
822
    CYG_PRECONDITION_THISC();
823
 
824
    explanation = explanation_arg;
825
 
826
    CYG_REPORT_RETURN();
827
}
828
 
829
bool
830
CdlConflict_EvalExceptionBody::check_this(cyg_assert_class_zeal zeal) const
831
{
832
    if (CdlConflict_EvalExceptionBody_Magic != cdlconflict_evalexceptionbody_cookie) {
833
        return false;
834
    }
835
    CYGDBG_MEMLEAK_CHECKTHIS();
836
    return CdlConflictBody::check_this(zeal);
837
}
838
 
839
bool
840
CdlConflict_EvalExceptionBody::test(CdlConflict conf)
841
{
842
    CYG_REPORT_FUNCNAMETYPE("CdlConflict_EvalException::test", "result %d");
843
    CYG_REPORT_FUNCARG1XV(conf);
844
    CYG_PRECONDITION_CLASSC(conf);
845
 
846
    bool result = false;
847
    CdlConflict_EvalException tmp = dynamic_cast<CdlConflict_EvalException>(conf);
848
    if (0 != tmp) {
849
        result = true;
850
    }
851
 
852
    CYG_REPORT_RETVAL(result);
853
    return result;
854
}
855
 
856
//}}}
857
//{{{  CdlConflict_Requires             
858
 
859
// ----------------------------------------------------------------------------
860
// A requires constraint is not satisfied. Producing a decent diagnostic
861
// here requires a detailed understanding of goal expressions. For now
862
// there is no extra data associated with goal expressions.
863
 
864
void
865
CdlConflict_RequiresBody::make(CdlTransaction trans, CdlNode node_arg, CdlProperty prop_arg)
866
{
867
    CdlConflict_Requires tmp = new CdlConflict_RequiresBody(trans, node_arg, prop_arg);
868
    CYG_UNUSED_PARAM(CdlConflict_Requires, tmp);
869
}
870
 
871
CdlConflict_RequiresBody::CdlConflict_RequiresBody(CdlTransaction trans, CdlNode node_arg, CdlProperty prop_arg)
872
    : CdlConflictBody(trans, node_arg, prop_arg, false)
873
{
874
    CYG_REPORT_FUNCNAME("CdlConflict_Requires:: constructor");
875
    CYG_REPORT_FUNCARG1XV(this);
876
    CYG_PRECONDITIONC(0 != dynamic_cast<CdlProperty_GoalExpression>(prop_arg));
877
 
878
    cdlconflict_requiresbody_cookie = CdlConflict_RequiresBody_Magic;
879
    CYGDBG_MEMLEAK_CONSTRUCTOR();
880
 
881
    CYG_POSTCONDITION_THISC();
882
    CYG_REPORT_RETURN();
883
}
884
 
885
CdlConflict_RequiresBody::~CdlConflict_RequiresBody()
886
{
887
    CYG_REPORT_FUNCNAME("CdlConflict_Requires:: destructor");
888
    CYG_REPORT_FUNCARG1XV(this);
889
    CYG_PRECONDITION_THISC();
890
 
891
    cdlconflict_requiresbody_cookie = CdlConflict_RequiresBody_Invalid;
892
    CYGDBG_MEMLEAK_DESTRUCTOR();
893
 
894
    CYG_REPORT_RETURN();
895
}
896
 
897
// FIXME: implement properly
898
std::string
899
CdlConflict_RequiresBody::get_explanation() const
900
{
901
    CYG_REPORT_FUNCNAME("CdlConflict::get_explanation");
902
    CYG_REPORT_FUNCARG1XV(this);
903
    CYG_PRECONDITION_THISC();
904
 
905
    CdlConstProperty_GoalExpression gexpr = dynamic_cast<CdlConstProperty_GoalExpression>(property);
906
    CYG_ASSERTC(0 != gexpr);
907
 
908
    std::string result = "";
909
    result += "\"requires\" constraint not satisfied: " + gexpr->get_original_string();
910
 
911
    CYG_REPORT_RETURN();
912
    return result;
913
}
914
 
915
// Inference is implemented, see infer.cxx
916
bool
917
CdlConflict_RequiresBody::resolution_implemented() const
918
{
919
    CYG_REPORT_FUNCNAME("CdlConflict_Requires");
920
    CYG_REPORT_FUNCARG1XV(this);
921
    CYG_PRECONDITION_THISC();
922
 
923
    CYG_REPORT_RETURN();
924
    return true;
925
}
926
 
927
bool
928
CdlConflict_RequiresBody::check_this(cyg_assert_class_zeal zeal) const
929
{
930
    if (CdlConflict_RequiresBody_Magic != cdlconflict_requiresbody_cookie) {
931
        return false;
932
    }
933
    CYGDBG_MEMLEAK_CHECKTHIS();
934
    return CdlConflictBody::check_this(zeal);
935
}
936
 
937
bool
938
CdlConflict_RequiresBody::test(CdlConflict conf)
939
{
940
    CYG_REPORT_FUNCNAMETYPE("CdlConflict_Requires::test", "result %d");
941
    CYG_REPORT_FUNCARG1XV(conf);
942
    CYG_PRECONDITION_CLASSC(conf);
943
 
944
    bool result = false;
945
    CdlConflict_Requires tmp = dynamic_cast<CdlConflict_Requires>(conf);
946
    if (0 != tmp) {
947
        result = true;
948
    }
949
 
950
    CYG_REPORT_RETVAL(result);
951
    return result;
952
}
953
 
954
//}}}
955
//{{{  CdlConflict_Data                 
956
 
957
// ----------------------------------------------------------------------------
958
// There is some strange problem in the configuration data, for example
959
// a parent property that is resolved but the target is not a container.
960
 
961
void
962
CdlConflict_DataBody::make(CdlTransaction trans, CdlNode node_arg, CdlProperty prop_arg, std::string message_arg)
963
{
964
    CdlConflict_Data tmp = new CdlConflict_DataBody(trans, node_arg, prop_arg, message_arg);
965
    CYG_UNUSED_PARAM(CdlConflict_Data, tmp);
966
}
967
 
968
CdlConflict_DataBody::CdlConflict_DataBody(CdlTransaction trans, CdlNode node_arg, CdlProperty prop_arg,
969
                                           std::string message_arg)
970
    : CdlConflictBody(trans, node_arg, prop_arg, true)
971
{
972
    CYG_REPORT_FUNCNAME("CdlConflict_Data:: constructor");
973
    CYG_REPORT_FUNCARG1XV(this);
974
    CYG_PRECONDITIONC("" != message_arg);
975
 
976
    message = message_arg;
977
    cdlconflict_databody_cookie = CdlConflict_DataBody_Magic;
978
    CYGDBG_MEMLEAK_CONSTRUCTOR();
979
 
980
    CYG_POSTCONDITION_THISC();
981
    CYG_REPORT_RETURN();
982
}
983
 
984
CdlConflict_DataBody::~CdlConflict_DataBody()
985
{
986
    CYG_REPORT_FUNCNAME("CdlConflict_ata: destructor");
987
    CYG_REPORT_FUNCARG1XV(this);
988
    CYG_PRECONDITION_THISC();
989
 
990
    cdlconflict_databody_cookie = CdlConflict_DataBody_Invalid;
991
    CYGDBG_MEMLEAK_DESTRUCTOR();
992
 
993
    CYG_REPORT_RETURN();
994
}
995
 
996
std::string
997
CdlConflict_DataBody::get_explanation() const
998
{
999
    CYG_REPORT_FUNCNAME("CdlConflict_Data::get_explanation");
1000
    CYG_REPORT_FUNCARG1XV(this);
1001
    CYG_PRECONDITION_THISC();
1002
 
1003
    std::string result = message;
1004
 
1005
    CYG_REPORT_RETURN();
1006
    return result;
1007
}
1008
 
1009
bool
1010
CdlConflict_DataBody::check_this(cyg_assert_class_zeal zeal) const
1011
{
1012
    if (CdlConflict_DataBody_Magic != cdlconflict_databody_cookie) {
1013
        return false;
1014
    }
1015
    CYGDBG_MEMLEAK_CHECKTHIS();
1016
    return CdlConflictBody::check_this(zeal);
1017
}
1018
 
1019
bool
1020
CdlConflict_DataBody::test(CdlConflict conf)
1021
{
1022
    CYG_REPORT_FUNCNAMETYPE("CdlConflict_Data::test", "result %d");
1023
    CYG_REPORT_FUNCARG1XV(conf);
1024
    CYG_PRECONDITION_CLASSC(conf);
1025
 
1026
    bool result = false;
1027
    CdlConflict_Data tmp = dynamic_cast<CdlConflict_Data>(conf);
1028
    if (0 != tmp) {
1029
        result = true;
1030
    }
1031
 
1032
    CYG_REPORT_RETVAL(result);
1033
    return result;
1034
}
1035
 
1036
//}}}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.