File: Constraint.hh

package info (click to toggle)
eclipse-titan 6.5.0-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 101,128 kB
  • sloc: cpp: 259,139; ansic: 47,560; yacc: 22,554; makefile: 14,074; sh: 12,630; lex: 9,101; xml: 5,362; java: 4,849; perl: 3,784; awk: 48; php: 32; python: 13
file content (534 lines) | stat: -rw-r--r-- 20,289 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
/******************************************************************************
 * Copyright (c) 2000-2018 Ericsson Telecom AB
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
 *
 * Contributors:
 *   Balasko, Jeno
 *   Delic, Adam
 *   Forstner, Matyas
 *   Raduly, Csaba
 *   Szabo, Janos Zoltan – initial implementation
 *
 ******************************************************************************/
#ifndef _Common_Constraint_HH
#define _Common_Constraint_HH

#include "Setting.hh"

namespace Asn {
  class Block;
  class TableConstraint;
}

namespace Common {

  /**
   * \ingroup Type
   *
   * \defgroup Constraint Constraint specifications
   *
   * These classes provide a unified interface for constraints.
   *
   * @{
   */

  class Constraint;
  class Constraints;

  // not defined here
  class Type;
  class Value;
  class SubtypeConstraint;
  class Identifier;
  
  using Asn::Block;

  /**
   * Class to represent Constraint.
   */
  class Constraint : public Node, public Location {
  public:
    enum constrtype_t {
      CT_UNDEFINEDBLOCK, /** UndefinedBlockConstraint (turns into CT_TABLE or CT_SINGLEVALUE after semantic analysis) */
      CT_ELEMENTSETSPEC, /** ElementSetSpecsConstraint */
      CT_IGNORE, /**< Constraint : used if erroneous or not yet supported */
      CT_TABLE, /**< TableConstraint */
      CT_SINGLEVALUE, /**< SingleValueConstraint */
      CT_CONTAINEDSUBTYPE, /**< ContainedSubtypeConstraint */
      CT_VALUERANGE, /**< ValueRangeConstraint */
      CT_SIZE, /**< SizeConstraint */
      CT_PERMITTEDALPHABET, /**< PermittedAlphabetConstraint */
      CT_PATTERN, /**< PatternConstraint */
      CT_SETOPERATION, /**< SetOperationConstraint */
      CT_FULLSET, /**< FullSetConstraint */
      CT_SINGLEINNERTYPE, /**< SingleInnerTypeConstraint */
      CT_NAMED, /**< NamedConstraint */
      CT_UNPARSEDMULTIPLEINNERTYPE, /**< UnparsedMultipleInnerTypeConstraint */
      CT_MULTIPLEINNERTYPE /**< MultipleInnerTypeConstraint */
    };
  protected:
    constrtype_t constrtype;
    Type* my_type; /**< the type to which this constraint belongs to */
    Scope* my_scope; /**< scope or NULL, if NULL then get scope from my_type */
    Constraint* my_parent; /**< the parent constraint node in AST or NULL */
    Constraints* my_cons; /**< the Constraints object or NULL, it is set if this
                               is the root node of a constraint tree */
    bool checked; /**< set to true by chk() */
    SubtypeConstraint* subtype; /**< NULL or set by chk() if constraint is valid, this is the root part */
    bool extendable; /**< set by chk() */
    SubtypeConstraint* extension; /**< NULL if there is no extension or not valid, set by chk() */

    Constraint(const Constraint& p);
    /// Assignment disabled
    Constraint& operator=(const Constraint& p);
  public:
    Constraint(constrtype_t p_constrtype);
    virtual ~Constraint();
    virtual Constraint* clone() const = 0;
    constrtype_t get_constrtype() const { return constrtype; }
    void set_my_type(Type *p_my_type) { my_type = p_my_type; }
    void set_my_parent(Constraint* p_my_parent) { my_parent = p_my_parent; }
    Constraint* get_my_parent() const { return my_parent; }
    void set_my_scope(Scope* p_my_scope) { my_scope = p_my_scope; }
    Scope* get_my_scope();
    void set_my_cons(Constraints* p_my_cons);
    Constraints* get_my_cons();
    virtual void chk() = 0;
    /** return the subtype constraint */
    virtual SubtypeConstraint* get_subtype() const { return subtype; }
    bool is_extendable() const { return extendable; }
    virtual SubtypeConstraint* get_extension() const { return extension; }
    /** returns the name of this constraint which can be used in error messages */
    virtual const char* get_name() const = 0;
    /** if this constraint is inside a FROM() constraint then we are in
        a char context */
    bool in_char_context() const;
    /** returns true if this constraint is inside a single or multiple inner type constraint */
    bool in_inner_constraint() const;
    /** returns if this kind of constraint is ignored, when ignored the 
        full set is used as it's subtype value
        TODO: set operations which have operands that are ignored constraints should
             somehow drop or simplify their constraint, example: (inner subtype) EXCEPT (inner subtype)
    */
    virtual bool is_ignored() const { return false; }
    
    /** Returns this (for TableConstraints) or the embedded TableConstraint
      * object (for UndefinedBlockConstraints that contain a TableConstraint
      * after semantic analysis) */
    virtual const Constraint* get_tableconstraint() const;
    
    virtual bool is_all_except_constraint() const { return false; }
  };

  /**
   * Class to represent constraints.
   */
  class Constraints : public Node {
  private:
    vector<Constraint> cons;
    Type *my_type;
    SubtypeConstraint* subtype; /**< NULL or set by chk() if constraint is valid, this is the root part */
    bool extendable; /**< set by chk() */
    SubtypeConstraint* extension; /**< NULL if there is no extension or not valid, set by chk() */

    Constraints(const Constraints& p);
    /// Assignment disabled
    Constraints& operator=(const Constraints& p);
  public:
    Constraints() : Node(), cons(), my_type(0), subtype(0), extendable(false), extension(0) {}
    virtual ~Constraints();
    virtual Constraints *clone() const;
    void add_con(Constraint *p_con);
    size_t get_nof_cons() const {return cons.size();}
    Constraint* get_con_byIndex(size_t p_i) const { return cons[p_i]; }
    const Constraint* get_tableconstraint() const;
    void set_my_type(Type *p_my_type);
    Type* get_my_type() const { return my_type; }
    void chk(SubtypeConstraint* parent_subtype);
    void chk_table();
    /* return the subtype constraint */
    SubtypeConstraint* get_subtype() const { return subtype; }
    bool is_extendable() const { return extendable; }
    SubtypeConstraint* get_extension() const { return extension; }
  };

  /** @} end of Constraint group */

  
  // =================================
  // ===== ElementSetSpecsConstraint
  // =================================
  
  /* This AST element is used only if "..." is present, otherwise it's not
     created, therefore the extendable bool is always true in this constraint */
  class ElementSetSpecsConstraint : public Constraint
  {
    Constraint* root_constr;
    Constraint* ext_constr; /* NULL if no extension addition was present */
    ElementSetSpecsConstraint(const ElementSetSpecsConstraint& p);
    /// Assignment disabled
    ElementSetSpecsConstraint& operator=(const ElementSetSpecsConstraint& p);
  public:
    ElementSetSpecsConstraint(Constraint* p_root_constr, Constraint* p_ext_constr);
    virtual ~ElementSetSpecsConstraint();
    ElementSetSpecsConstraint* clone() const { return new ElementSetSpecsConstraint(*this); }
    void chk();
    const char* get_name() const { return "ElementSetSpecs constraint"; }
    void set_fullname(const string& p_fullname);
  };

  // =================================
  // ===== IgnoredConstraint
  // =================================

  class IgnoredConstraint : public Constraint
  {
    const char* my_name;
    IgnoredConstraint(const IgnoredConstraint& p);
    /// Assignment disabled
    IgnoredConstraint& operator=(const IgnoredConstraint& p);
  public:
    IgnoredConstraint(const char* p_name);
    IgnoredConstraint* clone() const { return new IgnoredConstraint(*this); }
    void chk();
    const char* get_name() const { return my_name; }
    bool is_ignored() const { return true; }
  };


  // =================================
  // ===== SingleValueConstraint
  // =================================

  class SingleValueConstraint : public Constraint
  {
    Value* value;
    SingleValueConstraint(const SingleValueConstraint& p);
    /// Assignment disabled
    SingleValueConstraint& operator=(const SingleValueConstraint& p);
  public:
    SingleValueConstraint(Value* p_value);
    virtual ~SingleValueConstraint();
    SingleValueConstraint* clone() const { return new SingleValueConstraint(*this); }
    void chk();
    const char* get_name() const { return "single value constraint"; }
    void set_fullname(const string& p_fullname);
  };

  // =================================
  // ===== ContainedSubtypeConstraint
  // =================================

  class ContainedSubtypeConstraint : public Constraint
  {
    Type* type;
    bool has_includes; /**< INCLUDES keyword was used, then this cannot be a TypeConstraint,
                            otherwise it can be both TypeConstraint and ContainedSubtypeConstraint */
    ContainedSubtypeConstraint(const ContainedSubtypeConstraint& p);
    /// Assignment disabled
    ContainedSubtypeConstraint& operator=(const ContainedSubtypeConstraint& p);
  public:
    ContainedSubtypeConstraint(Type* p_type, bool p_has_includes);
    virtual ~ContainedSubtypeConstraint();
    ContainedSubtypeConstraint* clone() const { return new ContainedSubtypeConstraint(*this); }
    void chk();
    const char* get_name() const { return "contained subtype constraint"; }
    void set_fullname(const string& p_fullname);
  };

  // =================================
  // ===== RangeEndpoint
  // =================================

  class ValueRangeConstraint;

  class RangeEndpoint : public Node, public Location
  {
  public:
    enum endpoint_t {
      MIN, /**< minimum value */
      VALUE, /**< value */
      MAX /**< maximum value */
    };
  private:
    endpoint_t type; /**< type of endpoint */
    Value* value; /**< a value or NULL if type!=VALUE */
    bool inclusive; /**< true if the endpoint is part of the range */
    RangeEndpoint(const RangeEndpoint& p);
    RangeEndpoint& operator=(const RangeEndpoint& p); // = disabled
  public:
    RangeEndpoint(endpoint_t p_type);
    RangeEndpoint(Value* p_value);
    void set_exclusive() { inclusive = false; }
    bool get_exclusive() const { return !inclusive; }
    endpoint_t get_type() const { return type; }
    Value* get_value() const { return value; }
    ~RangeEndpoint();
    RangeEndpoint* clone() const { return new RangeEndpoint(*this); }
    void chk(Type* my_type, ValueRangeConstraint* constraint);
    void set_fullname(const string& p_fullname);
  };

  // =================================
  // ===== ValueRangeConstraint
  // =================================

  class ValueRangeConstraint : public Constraint
  {
    RangeEndpoint* lower_endpoint;
    RangeEndpoint* upper_endpoint;
    ValueRangeConstraint(const ValueRangeConstraint& p);
    /// Assignment disabled
    ValueRangeConstraint& operator=(const ValueRangeConstraint& p);
  public:
    ValueRangeConstraint(RangeEndpoint* p_lower, RangeEndpoint* p_upper);
    virtual ~ValueRangeConstraint() { delete lower_endpoint; delete upper_endpoint; }
    ValueRangeConstraint* clone() const { return new ValueRangeConstraint(*this); }
    void chk();
    const char* get_name() const { return "value range constraint"; }
    void set_fullname(const string& p_fullname);
  };

  // =================================
  // ===== SizeConstraint
  // =================================

  class SizeConstraint : public Constraint
  {
    Constraint* constraint;
    SizeConstraint(const SizeConstraint& p);
    /// Assignment disabled
    SizeConstraint& operator=(const SizeConstraint& p);
  public:
    SizeConstraint(Constraint* p);
    virtual ~SizeConstraint() { delete constraint; }
    SizeConstraint* clone() const { return new SizeConstraint(*this); }
    void chk();
    const char* get_name() const { return "size constraint"; }
    void set_fullname(const string& p_fullname);
  };

  // =================================
  // ===== PermittedAlphabetConstraint
  // =================================

  class PermittedAlphabetConstraint : public Constraint
  {
    Constraint* constraint;
    PermittedAlphabetConstraint(const PermittedAlphabetConstraint& p);
    /// Assignment disabled
    PermittedAlphabetConstraint& operator=(const PermittedAlphabetConstraint& p);
  public:
    PermittedAlphabetConstraint(Constraint* p);
    virtual ~PermittedAlphabetConstraint() { delete constraint; }
    PermittedAlphabetConstraint* clone() const { return new PermittedAlphabetConstraint(*this); }
    void chk();
    const char* get_name() const { return "permitted alphabet constraint"; }
    void set_fullname(const string& p_fullname);
  };

  // =================================
  // ===== SetOperationConstraint
  // =================================

  class SetOperationConstraint : public Constraint
  {
  public:
    enum operationtype_t {
      UNION,
      INTERSECTION,
      EXCEPT
    };
  private:
    operationtype_t operationtype;
    Constraint* operand_a;
    Constraint* operand_b;
    SetOperationConstraint(const SetOperationConstraint& p);
    /// Assignment disabled
    SetOperationConstraint& operator=(const SetOperationConstraint& p);
  public:
    SetOperationConstraint(Constraint* p_a, operationtype_t p_optype, Constraint* p_b);
    virtual ~SetOperationConstraint() { delete operand_a; delete operand_b; }
    void set_first_operand(Constraint* p_a);
    SetOperationConstraint* clone() const { return new SetOperationConstraint(*this); }
    const char* get_operationtype_str() const;
    void chk();
    const char* get_name() const { return get_operationtype_str(); }
    void set_fullname(const string& p_fullname);
    bool is_all_except_constraint() const;
  };
  
  // =================================
  // ===== FullSetConstraint
  // =================================

  class FullSetConstraint : public Constraint
  {
    FullSetConstraint(const FullSetConstraint& p): Constraint(p) {}
    /// Assignment disabled
    FullSetConstraint& operator=(const FullSetConstraint& p);
  public:
    FullSetConstraint(): Constraint(CT_FULLSET) {}
    FullSetConstraint* clone() const { return new FullSetConstraint(*this); }
    void chk();
    const char* get_name() const { return "ALL"; }
  };

  // =================================
  // ===== PatternConstraint
  // =================================

  class PatternConstraint : public Constraint
  {
    Value* value;
    PatternConstraint(const PatternConstraint& p);
    /// Assignment disabled
    PatternConstraint& operator=(const PatternConstraint& p);
  public:
    PatternConstraint(Value* p_value);
    virtual ~PatternConstraint();
    PatternConstraint* clone() const { return new PatternConstraint(*this); }
    void chk();
    const char* get_name() const { return "pattern constraint"; }
    void set_fullname(const string& p_fullname);
    bool is_ignored() const { return true; }
  };

  // =================================
  // ===== SingleInnerTypeConstraint
  // =================================

  class SingleInnerTypeConstraint : public Constraint
  {
    Constraint* constraint;
    SingleInnerTypeConstraint(const SingleInnerTypeConstraint& p);
    /// Assignment disabled
    SingleInnerTypeConstraint& operator=(const SingleInnerTypeConstraint& p);
  public:
    SingleInnerTypeConstraint(Constraint* p);
    virtual ~SingleInnerTypeConstraint() { delete constraint; }
    SingleInnerTypeConstraint* clone() const { return new SingleInnerTypeConstraint(*this); }
    void chk();
    void set_fullname(const string& p_fullname);
    const char* get_name() const { return "inner type constraint"; }
    bool is_ignored() const { return true; }
  };

  // =================================
  // ===== NamedConstraint
  // =================================

  class NamedConstraint : public Constraint
  {
  public:
    enum presence_constraint_t {
      PC_NONE, // presence constraint was not specified
      PC_PRESENT,
      PC_ABSENT,
      PC_OPTIONAL
    };
  private:
    Identifier* id;
    Constraint* value_constraint; // NULL if it was not specified
    presence_constraint_t presence_constraint;
    NamedConstraint(const NamedConstraint& p);
    /// Assignment disabled
    NamedConstraint& operator=(const NamedConstraint& p);
  public:
    NamedConstraint(Identifier* p_id, Constraint* p_value_constraint, presence_constraint_t p_presence_constraint);
    ~NamedConstraint();
    const Identifier& get_id() const { return *id; }
    Constraint* get_value_constraint() const { return value_constraint; }
    presence_constraint_t get_presence_constraint() const { return presence_constraint; }
    const char* get_presence_constraint_name() const;
    NamedConstraint* clone() const { return new NamedConstraint(*this); }
    void chk();
    void set_fullname(const string& p_fullname);
    const char* get_name() const { return "named constraint"; }
    bool is_ignored() const { return true; }
  };

  // =================================
  // ===== MultipleInnerTypeConstraint
  // =================================

  class MultipleInnerTypeConstraint : public Constraint
  {
    bool partial; // Full/Partial Specification
    vector<NamedConstraint> named_con_vec;
    map<Identifier,NamedConstraint> named_con_map; // values owned by named_con_vec, filled by chk()
    MultipleInnerTypeConstraint(const MultipleInnerTypeConstraint& p);
    /// Assignment disabled
    MultipleInnerTypeConstraint& operator=(const MultipleInnerTypeConstraint& p);
  public:
    MultipleInnerTypeConstraint(): Constraint(CT_MULTIPLEINNERTYPE) {}
    virtual ~MultipleInnerTypeConstraint();
    MultipleInnerTypeConstraint* clone() const { return new MultipleInnerTypeConstraint(*this); }

    void set_partial(bool b) { partial = b; }
    bool get_partial() const { return partial; }
    void addNamedConstraint(NamedConstraint* named_con);

    void chk();
    void set_fullname(const string& p_fullname);
    const char* get_name() const { return "inner type constraint"; }
    bool is_ignored() const { return true; }
  };

  // =================================
  // ===== UnparsedMultipleInnerTypeConstraint
  // =================================

  class UnparsedMultipleInnerTypeConstraint : public Constraint
  {
    Block* block;
    MultipleInnerTypeConstraint* constraint;
    UnparsedMultipleInnerTypeConstraint(const UnparsedMultipleInnerTypeConstraint& p);
    /// Assignment disabled
    UnparsedMultipleInnerTypeConstraint& operator=(const UnparsedMultipleInnerTypeConstraint& p);
  public:
    UnparsedMultipleInnerTypeConstraint(Block* p_block);
    virtual ~UnparsedMultipleInnerTypeConstraint();
    UnparsedMultipleInnerTypeConstraint* clone() const { return new UnparsedMultipleInnerTypeConstraint(*this); }
    void chk();
    void set_fullname(const string& p_fullname);
    const char* get_name() const { return "inner type constraint"; }
    bool is_ignored() const { return true; }
  };
  
  
  // =================================
  // ===== UndefinedBlockConstraint
  // =================================
  
  /** This class represents a constraint containing a block.
    * During semantic analysis the block is parsed and causes this object to act
    * as either a SingleValueConstraint or a TableConstraint afterwards. */
  class UndefinedBlockConstraint : public Constraint
  {
    union {
      Block* block; // CT_UNDEFINEDBLOCK, before chk()
      SingleValueConstraint* single; // CT_SINGLEVALUE, after chk()
      Asn::TableConstraint* table; // CT_TABLE, after chk()
    };
    UndefinedBlockConstraint(const UndefinedBlockConstraint& p);
    /// Assignment disabled
    UndefinedBlockConstraint& operator=(const UndefinedBlockConstraint& p);
  public:
    UndefinedBlockConstraint(Block* p_block);
    virtual ~UndefinedBlockConstraint();
    UndefinedBlockConstraint* clone() const { return new UndefinedBlockConstraint(*this); }
    void chk();
    const char* get_name() const { return "Undefined block constraint"; }
    void set_fullname(const string& p_fullname);
    SubtypeConstraint* get_subtype() const;
    SubtypeConstraint* get_extension() const;
    const Constraint* get_tableconstraint() const;
  };

} // namespace Common

#endif // _Common_Constraint_HH