1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 Ericsson Telecom AB
3 // All rights reserved. This program and the accompanying materials
4 // are made available under the terms of the Eclipse Public License v1.0
5 // which accompanies this distribution, and is available at
6 // http://www.eclipse.org/legal/epl-v10.html
7 ///////////////////////////////////////////////////////////////////////////////
9 #include "../common/dbgnew.hh"
10 #include "Identifier.hh"
14 #include "CompilerError.hh"
15 #include "Valuestuff.hh"
16 #include "ttcn3/TtcnTemplate.hh"
17 #include "ttcn3/Templatestuff.hh"
18 #include "ttcn3/PatternString.hh"
19 #include "Constraint.hh"
25 /**************************
27 **************************/
29 SubTypeParse::SubTypeParse(Value
*p_single
)
30 : selection(STP_SINGLE
)
32 if (!p_single
) FATAL_ERROR("SubTypeParse::SubTypeParse()");
36 SubTypeParse::SubTypeParse(Value
*p_min
, bool p_min_exclusive
, Value
*p_max
, bool p_max_exclusive
)
37 : selection(STP_RANGE
)
40 range
.min_exclusive
= p_min_exclusive
;
42 range
.max_exclusive
= p_max_exclusive
;
45 SubTypeParse::SubTypeParse(Ttcn::LengthRestriction
*p_length
)
46 : selection(STP_LENGTH
)
48 if (!p_length
) FATAL_ERROR("SubTypeParse::SubTypeParse()");
52 SubTypeParse::SubTypeParse(Ttcn::PatternString
*p_pattern
)
53 : selection(STP_PATTERN
)
55 if (!p_pattern
) FATAL_ERROR("SubTypeParse::SubTypeParse()");
59 SubTypeParse::~SubTypeParse()
76 FATAL_ERROR("SubTypeParse::~SubTypeParse()");
80 Value
*SubTypeParse::Single() const
82 if (selection
!= STP_SINGLE
) FATAL_ERROR("SubTypeParse::Single()");
86 Value
*SubTypeParse::Min() const
88 if (selection
!= STP_RANGE
) FATAL_ERROR("SubTypeParse::Min()");
92 bool SubTypeParse::MinExclusive() const
94 if (selection
!= STP_RANGE
) FATAL_ERROR("SubTypeParse::MinExclusive()");
95 return range
.min_exclusive
;
98 Value
*SubTypeParse::Max() const
100 if (selection
!= STP_RANGE
) FATAL_ERROR("SubTypeParse::Max()");
104 bool SubTypeParse::MaxExclusive() const
106 if (selection
!= STP_RANGE
) FATAL_ERROR("SubTypeParse::MaxExclusive()");
107 return range
.max_exclusive
;
110 Ttcn::LengthRestriction
*SubTypeParse::Length() const
112 if (selection
!= STP_LENGTH
) FATAL_ERROR("SubTypeParse::Length()");
116 Ttcn::PatternString
*SubTypeParse::Pattern() const
118 if (selection
!= STP_PATTERN
) FATAL_ERROR("SubTypeParse::Pattern()");
122 /********************
123 class SubtypeConstraint
124 ********************/
126 SubtypeConstraint::SubtypeConstraint(subtype_t st
)
129 length_restriction
= NULL
;
150 octetstring_st
= NULL
;
153 charstring_st
= NULL
;
155 case ST_UNIVERSAL_CHARSTRING
:
156 universal_charstring_st
= NULL
;
173 FATAL_ERROR("SubtypeConstraint::SubtypeConstraint()");
177 void SubtypeConstraint::copy(const SubtypeConstraint
* other
)
179 if ((other
==NULL
) || (other
->subtype
!=subtype
)) FATAL_ERROR("SubtypeConstraint::copy()");
183 integer_st
= other
->integer_st
? new IntegerRangeListConstraint(*(other
->integer_st
)) : NULL
;
187 float_st
= other
->float_st
? new RealRangeListConstraint(*(other
->float_st
)) : NULL
;
191 boolean_st
= other
->boolean_st
? new BooleanListConstraint(*(other
->boolean_st
)) : NULL
;
195 verdict_st
= other
->verdict_st
? new VerdicttypeListConstraint(*(other
->verdict_st
)) : NULL
;
199 bitstring_st
= other
->bitstring_st
? new BitstringConstraint(*(other
->bitstring_st
)) : NULL
;
203 hexstring_st
= other
->hexstring_st
? new HexstringConstraint(*(other
->hexstring_st
)) : NULL
;
206 delete octetstring_st
;
207 octetstring_st
= other
->octetstring_st
? new OctetstringConstraint(*(other
->octetstring_st
)) : NULL
;
210 delete charstring_st
;
211 charstring_st
= other
->charstring_st
? new CharstringSubtypeTreeElement(*(other
->charstring_st
)) : NULL
;
213 case ST_UNIVERSAL_CHARSTRING
:
214 delete universal_charstring_st
;
215 universal_charstring_st
= other
->universal_charstring_st
? new UniversalCharstringSubtypeTreeElement(*(other
->universal_charstring_st
)) : NULL
;
226 value_st
= other
->value_st
? new ValueListConstraint(*(other
->value_st
)) : NULL
;
231 recof_st
= other
->recof_st
? new RecofConstraint(*(other
->recof_st
)) : NULL
;
234 FATAL_ERROR("SubtypeConstraint::copy()");
236 delete length_restriction
;
237 length_restriction
= other
->length_restriction
? new SizeRangeListConstraint(*(other
->length_restriction
)) : NULL
;
240 // used by get_asn_type_constraint() to store singleton objects and delete them on program exit
241 struct AsnTypeConstraintSingleton
243 SubtypeConstraint
*printablestring_stc
, *numericstring_stc
, *bmpstring_stc
;
244 AsnTypeConstraintSingleton():
245 printablestring_stc(NULL
), numericstring_stc(NULL
), bmpstring_stc(NULL
) {}
246 ~AsnTypeConstraintSingleton();
249 AsnTypeConstraintSingleton::~AsnTypeConstraintSingleton()
251 delete printablestring_stc
;
252 delete numericstring_stc
;
253 delete bmpstring_stc
;
256 SubtypeConstraint
* SubtypeConstraint::get_asn_type_constraint(Type
* type
)
258 static AsnTypeConstraintSingleton asn_tcs
;
259 static const char_limit_t
zero('0'), nine('9'),
260 bigA('A'), bigZ('Z'), smalla('a'), smallz('z');
261 static const universal_char_limit_t
uni_zero(0);
262 static const universal_char_limit_t
uni_ffff((1<<16)-1);
263 static const CharRangeListConstraint
numeric_string_char_range(
264 CharRangeListConstraint(zero
, nine
) +
265 CharRangeListConstraint(char_limit_t(' ')));
266 static const CharRangeListConstraint
printable_string_char_range(
267 CharRangeListConstraint(bigA
, bigZ
) +
268 CharRangeListConstraint(smalla
, smallz
) +
269 CharRangeListConstraint(zero
, nine
) +
270 CharRangeListConstraint(char_limit_t(' ')) +
271 CharRangeListConstraint(char_limit_t('\'')) +
272 CharRangeListConstraint(char_limit_t('(')) +
273 CharRangeListConstraint(char_limit_t(')')) +
274 CharRangeListConstraint(char_limit_t('+')) +
275 CharRangeListConstraint(char_limit_t(',')) +
276 CharRangeListConstraint(char_limit_t('-')) +
277 CharRangeListConstraint(char_limit_t('.')) +
278 CharRangeListConstraint(char_limit_t('/')) +
279 CharRangeListConstraint(char_limit_t(':')) +
280 CharRangeListConstraint(char_limit_t('=')) +
281 CharRangeListConstraint(char_limit_t('?')));
282 static const UniversalCharRangeListConstraint
bmp_string_char_range(
283 UniversalCharRangeListConstraint(uni_zero
, uni_ffff
));
285 switch (type
->get_typetype()) {
286 case Type::T_TELETEXSTRING
:
287 // TODO: based on ITU-T Recommendation T.61
289 case Type::T_VIDEOTEXSTRING
:
290 // TODO: based on ITU-T Recommendation T.100 and T.101
292 case Type::T_NUMERICSTRING
:
293 if (asn_tcs
.numericstring_stc
==NULL
) {
294 asn_tcs
.numericstring_stc
= new SubtypeConstraint(ST_CHARSTRING
);
295 asn_tcs
.numericstring_stc
->charstring_st
= new CharstringSubtypeTreeElement(numeric_string_char_range
, false);
297 return asn_tcs
.numericstring_stc
;
298 case Type::T_PRINTABLESTRING
:
299 if (asn_tcs
.printablestring_stc
==NULL
) {
300 asn_tcs
.printablestring_stc
= new SubtypeConstraint(ST_CHARSTRING
);
301 asn_tcs
.printablestring_stc
->charstring_st
= new CharstringSubtypeTreeElement(printable_string_char_range
, false);
303 return asn_tcs
.printablestring_stc
;
304 case Type::T_BMPSTRING
:
305 if (asn_tcs
.bmpstring_stc
==NULL
) {
306 asn_tcs
.bmpstring_stc
= new SubtypeConstraint(ST_UNIVERSAL_CHARSTRING
);
307 asn_tcs
.bmpstring_stc
->universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(bmp_string_char_range
, false);
309 return asn_tcs
.bmpstring_stc
;
315 SubtypeConstraint
* SubtypeConstraint::create_from_asn_value(Type
* type
, Value
* value
)
317 Value
* v
= value
->get_value_refd_last();
318 subtype_t st_t
= type
->get_subtype_type();
319 if ( (st_t
==ST_ERROR
) || (v
->get_valuetype()==Value::V_ERROR
) ) return NULL
;
320 SubtypeConstraint
* stc
= new SubtypeConstraint(st_t
);
321 switch (v
->get_valuetype()) {
323 if (st_t
!=ST_INTEGER
) FATAL_ERROR("SubtypeConstraint::create_from_asn_value()");
324 stc
->integer_st
= new IntegerRangeListConstraint(int_limit_t(*(v
->get_val_Int())));
326 case Value::V_REAL
: {
327 if (st_t
!=ST_FLOAT
) FATAL_ERROR("SubtypeConstraint::create_from_asn_value()");
328 ttcn3float r
= v
->get_val_Real();
329 if (r
!=r
) stc
->float_st
= new RealRangeListConstraint(true);
330 else stc
->float_st
= new RealRangeListConstraint(real_limit_t(r
));
333 if (st_t
!=ST_BOOLEAN
) FATAL_ERROR("SubtypeConstraint::create_from_asn_value()");
334 stc
->boolean_st
= new BooleanListConstraint(v
->get_val_bool());
338 if (v
->has_oid_error()) goto invalid_value
;
339 if (st_t
!=ST_OBJID
) FATAL_ERROR("SubtypeConstraint::create_from_asn_value()");
340 stc
->value_st
= new ValueListConstraint(v
);
343 if (st_t
!=ST_BITSTRING
) FATAL_ERROR("SubtypeConstraint::create_from_asn_value()");
344 stc
->bitstring_st
= new BitstringConstraint(v
->get_val_str());
347 if (st_t
!=ST_HEXSTRING
) FATAL_ERROR("SubtypeConstraint::create_from_asn_value()");
348 stc
->hexstring_st
= new HexstringConstraint(v
->get_val_str());
351 if (st_t
!=ST_OCTETSTRING
) FATAL_ERROR("SubtypeConstraint::create_from_asn_value()");
352 stc
->octetstring_st
= new OctetstringConstraint(v
->get_val_str());
355 if (st_t
!=ST_CHARSTRING
) FATAL_ERROR("SubtypeConstraint::create_from_asn_value()");
356 stc
->charstring_st
= new CharstringSubtypeTreeElement(StringValueConstraint
<string
>(v
->get_val_str()));
358 case Value::V_ISO2022STR
:
359 if (st_t
!=ST_CHARSTRING
) FATAL_ERROR("SubtypeConstraint::create_from_asn_value()");
360 stc
->charstring_st
= new CharstringSubtypeTreeElement(StringValueConstraint
<string
>(v
->get_val_iso2022str()));
362 case Value::V_CHARSYMS
:
364 if (st_t
!=ST_UNIVERSAL_CHARSTRING
) FATAL_ERROR("SubtypeConstraint::create_from_asn_value()");
365 stc
->universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(StringValueConstraint
<ustring
>(v
->get_val_ustr()));
368 case Value::V_NULL
: // FIXME: should go to ST_NULL
369 if (st_t
!=ST_ENUM
) FATAL_ERROR("SubtypeConstraint::create_from_asn_value()");
370 stc
->value_st
= new ValueListConstraint(v
);
372 case Value::V_CHOICE
:
373 case Value::V_OPENTYPE
: // FIXME?
374 if (st_t
!=ST_UNION
) FATAL_ERROR("SubtypeConstraint::create_from_asn_value()");
375 stc
->value_st
= new ValueListConstraint(v
);
378 if (st_t
!=ST_RECORD
) FATAL_ERROR("SubtypeConstraint::create_from_asn_value()");
379 stc
->value_st
= new ValueListConstraint(v
);
382 if (st_t
!=ST_SET
) FATAL_ERROR("SubtypeConstraint::create_from_asn_value()");
383 stc
->value_st
= new ValueListConstraint(v
);
386 if (st_t
!=ST_RECORDOF
) FATAL_ERROR("SubtypeConstraint::create_from_asn_value()");
387 stc
->recof_st
= new RecofConstraint(v
);
390 if (st_t
!=ST_SETOF
) FATAL_ERROR("SubtypeConstraint::create_from_asn_value()");
391 stc
->recof_st
= new RecofConstraint(v
);
402 SubtypeConstraint
* SubtypeConstraint::create_from_asn_charvalues(Type
* type
, Value
* value
)
404 Value
* v
= value
->get_value_refd_last();
405 subtype_t st_t
= type
->get_subtype_type();
406 if ( (st_t
==ST_ERROR
) || (v
->get_valuetype()==Value::V_ERROR
) ) return NULL
;
407 SubtypeConstraint
* stc
= new SubtypeConstraint(st_t
);
408 switch (v
->get_valuetype()) {
410 case Value::V_ISO2022STR
: {
411 if (st_t
!=ST_CHARSTRING
) FATAL_ERROR("SubtypeConstraint::create_from_asn_charvalues()");
412 CharRangeListConstraint charvalues
;
413 string val_str
= (v
->get_valuetype()==Value::V_CSTR
) ? v
->get_val_str() : v
->get_val_iso2022str();
414 for (size_t i
=0; i
<val_str
.size(); i
++) {
415 if (!char_limit_t::is_valid_value(val_str
[i
])) {
416 value
->error("Invalid char in string %s at index %lu",
417 value
->get_stringRepr().c_str(), (unsigned long)i
);
420 charvalues
= charvalues
+ CharRangeListConstraint(val_str
[i
]);
422 stc
->charstring_st
= new CharstringSubtypeTreeElement(charvalues
, true);
424 case Value::V_CHARSYMS
: {
426 if (st_t
!=ST_UNIVERSAL_CHARSTRING
) FATAL_ERROR("SubtypeConstraint::create_from_asn_charvalues()");
427 UniversalCharRangeListConstraint ucharvalues
;
428 ustring val_ustr
= v
->get_val_ustr();
429 for (size_t i
=0; i
<val_ustr
.size(); i
++) {
430 if (!universal_char_limit_t::is_valid_value(val_ustr
[i
])) {
431 value
->error("Invalid universal char in string %s at index %lu",
432 value
->get_stringRepr().c_str(), (unsigned long)i
);
435 ucharvalues
= ucharvalues
+ UniversalCharRangeListConstraint(val_ustr
[i
]);
437 stc
->universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(ucharvalues
, true);
440 // error was already reported
449 int_limit_t
SubtypeConstraint::get_int_limit(bool is_upper
, Location
* loc
)
451 int_limit_t default_limit
= is_upper
?
452 int_limit_t::maximum
:
453 ((subtype
==ST_INTEGER
) ? int_limit_t::minimum
: int_limit_t(int_val_t((Int
)0)));
457 if (integer_st
->is_empty()==TTRUE
) {
458 loc
->error("Cannot determine the value of %s: the parent subtype is an empty set.",
459 is_upper
?"MAX":"MIN");
460 return default_limit
;
462 return is_upper
? integer_st
->get_maximal() : integer_st
->get_minimal();
465 return default_limit
;
469 tribool tb
= bitstring_st
->get_size_limit(is_upper
, sl
);
470 if (tb
==TTRUE
) return sl
.to_int_limit();
473 return default_limit
;
477 tribool tb
= hexstring_st
->get_size_limit(is_upper
, sl
);
478 if (tb
==TTRUE
) return sl
.to_int_limit();
481 return default_limit
;
483 if (octetstring_st
) {
485 tribool tb
= octetstring_st
->get_size_limit(is_upper
, sl
);
486 if (tb
==TTRUE
) return sl
.to_int_limit();
489 return default_limit
;
493 tribool tb
= charstring_st
->get_size_limit(is_upper
, sl
);
496 loc
->error("Cannot determine the value of %s: the parent subtype does "
497 "not define a %simal size value", is_upper
?"MAX":"MIN", is_upper
?"max":"min");
500 loc
->warning("Cannot determine the value of %s from parent subtype %s",
501 is_upper
?"MAX":"MIN", to_string().c_str());
504 return sl
.to_int_limit();
506 FATAL_ERROR("SubtypeConstraint::get_int_limit()");
509 return default_limit
;
510 case ST_UNIVERSAL_CHARSTRING
:
511 if (universal_charstring_st
) {
513 tribool tb
= universal_charstring_st
->get_size_limit(is_upper
, sl
);
516 loc
->error("Cannot determine the value of %s: the parent subtype does "
517 "not define a %simal size value", is_upper
?"MAX":"MIN", is_upper
?"max":"min");
520 loc
->warning("Cannot determine the value of %s from parent subtype %s",
521 is_upper
?"MAX":"MIN", to_string().c_str());
524 return sl
.to_int_limit();
526 FATAL_ERROR("SubtypeConstraint::get_int_limit()");
529 return default_limit
;
534 tribool tb
= recof_st
->get_size_limit(is_upper
, sl
);
535 if (tb
==TTRUE
) return sl
.to_int_limit();
538 return default_limit
;
540 FATAL_ERROR("SubtypeConstraint::get_int_limit()");
542 loc
->error("Cannot determine the value of %s from parent subtype %s",
543 is_upper
?"MAX":"MIN", to_string().c_str());
544 return default_limit
;
547 SubtypeConstraint
* SubtypeConstraint::create_from_asn_range(
548 Value
* vmin
, bool min_exclusive
, Value
* vmax
, bool max_exclusive
,
549 Location
* loc
, subtype_t st_t
, SubtypeConstraint
* parent_subtype
)
552 case SubtypeConstraint::ST_INTEGER
: {
553 if (((vmin
!=NULL
) && (vmin
->get_valuetype()!=Value::V_INT
)) ||
554 ((vmax
!=NULL
) && (vmax
->get_valuetype()!=Value::V_INT
))) return NULL
;
556 int_limit_t min_limit
;
558 min_limit
= int_limit_t(*(vmin
->get_val_Int()));
559 } else { // MIN was used
560 if (parent_subtype
) {
561 min_limit
= parent_subtype
->get_int_limit(false, loc
);
563 min_limit
= int_limit_t::minimum
;
568 if (min_limit
==int_limit_t::minimum
) {
569 loc
->error("invalid lower boundary, -infinity cannot be excluded from an INTEGER value range constraint");
572 min_limit
= min_limit
.next();
576 int_limit_t max_limit
;
578 max_limit
= int_limit_t(*(vmax
->get_val_Int()));
579 } else { // MAX was used
580 if (parent_subtype
) {
581 max_limit
= parent_subtype
->get_int_limit(true, loc
);
583 max_limit
= int_limit_t::maximum
;
588 if (max_limit
==int_limit_t::maximum
) {
589 loc
->error("invalid upper boundary, infinity cannot be excluded from an INTEGER value range constraint");
592 max_limit
= max_limit
.previous();
595 if (max_limit
<min_limit
) {
596 loc
->error("lower boundary is bigger than upper boundary in INTEGER value range constraint");
599 SubtypeConstraint
* stc
= new SubtypeConstraint(st_t
);
600 stc
->integer_st
= new IntegerRangeListConstraint(min_limit
, max_limit
);
604 if (((vmin
!=NULL
) && (vmin
->get_valuetype()!=Value::V_REAL
)) ||
605 ((vmax
!=NULL
) && (vmax
->get_valuetype()!=Value::V_REAL
))) return NULL
;
606 if ((vmin
!=NULL
) && (vmin
->get_val_Real()!=vmin
->get_val_Real())) {
607 loc
->error("lower boundary cannot be NOT-A-NUMBER in REAL value range constraint");
610 if ((vmax
!=NULL
) && (vmax
->get_val_Real()!=vmax
->get_val_Real())) {
611 loc
->error("upper boundary cannot be NOT-A-NUMBER in REAL value range constraint");
615 if (parent_subtype
&& (parent_subtype
->subtype
!=ST_FLOAT
)) FATAL_ERROR("SubtypeConstraint::create_from_asn_range()");
616 real_limit_t min_limit
;
618 min_limit
= real_limit_t(vmin
->get_val_Real());
619 } else { // MIN was used
620 if (parent_subtype
&& parent_subtype
->float_st
) {
621 if (parent_subtype
->float_st
->is_range_empty()==TTRUE
) {
622 loc
->error("Cannot determine the value of MIN: the parent subtype has no range");
623 min_limit
= real_limit_t::minimum
;
625 min_limit
= parent_subtype
->float_st
->get_minimal();
628 min_limit
= real_limit_t::minimum
;
633 min_limit
= min_limit
.next();
636 real_limit_t max_limit
;
638 max_limit
= real_limit_t(vmax
->get_val_Real());
639 } else { // MAX was used
640 if (parent_subtype
&& parent_subtype
->float_st
) {
641 if (parent_subtype
->float_st
->is_range_empty()==TTRUE
) {
642 loc
->error("Cannot determine the value of MAX: the parent subtype has no range");
643 max_limit
= real_limit_t::maximum
;
645 max_limit
= parent_subtype
->float_st
->get_maximal();
648 max_limit
= real_limit_t::maximum
;
653 max_limit
= max_limit
.previous();
655 if (max_limit
<min_limit
) {
656 loc
->error("lower boundary is bigger than upper boundary in REAL value range constraint");
659 SubtypeConstraint
* stc
= new SubtypeConstraint(st_t
);
660 stc
->float_st
= new RealRangeListConstraint(min_limit
, max_limit
);
663 case ST_CHARSTRING
: {
664 if (((vmin
!=NULL
) && (vmin
->get_valuetype()!=Value::V_CSTR
)) ||
665 ((vmax
!=NULL
) && (vmax
->get_valuetype()!=Value::V_CSTR
))) return NULL
;
666 if (vmin
&& (vmin
->get_val_str().size()!=1)) {
667 vmin
->error("lower boundary of string value range constraint must be a single element string");
670 if (vmax
&& (vmax
->get_val_str().size()!=1)) {
671 vmax
->error("upper boundary of string value range constraint must be a single element string");
674 if (vmin
&& !char_limit_t::is_valid_value(*vmin
->get_val_str().c_str())) {
675 vmin
->error("lower boundary of string value range constraint is an invalid char");
678 if (vmax
&& !char_limit_t::is_valid_value(*vmax
->get_val_str().c_str())) {
679 vmax
->error("upper boundary of string value range constraint is an invalid char");
683 if (parent_subtype
&& (parent_subtype
->subtype
!=ST_CHARSTRING
)) FATAL_ERROR("SubtypeConstraint::create_from_asn_range()");
685 char_limit_t min_limit
;
687 min_limit
= char_limit_t(*vmin
->get_val_str().c_str());
688 } else { // MIN was used
689 if (parent_subtype
&& parent_subtype
->charstring_st
) {
690 tribool tb
= parent_subtype
->charstring_st
->get_alphabet_limit(false, min_limit
);
693 loc
->error("Cannot determine the value of MIN: the parent subtype does not define a minimal char value");
694 min_limit
= char_limit_t::minimum
;
697 loc
->warning("Cannot determine the value of MIN, using the minimal char value of the type");
698 min_limit
= char_limit_t::minimum
;
701 // min_limit was set to the correct value
704 FATAL_ERROR("SubtypeConstraint::create_from_asn_range()");
707 min_limit
= char_limit_t::minimum
;
712 if (min_limit
==char_limit_t::maximum
) {
713 loc
->error("exclusive lower boundary is not a legal character");
716 min_limit
= min_limit
.next();
719 char_limit_t max_limit
;
721 max_limit
= char_limit_t(*vmax
->get_val_str().c_str());
722 } else { // MAX was used
723 if (parent_subtype
&& parent_subtype
->charstring_st
) {
724 tribool tb
= parent_subtype
->charstring_st
->get_alphabet_limit(true, max_limit
);
727 loc
->error("Cannot determine the value of MAX: the parent subtype does not define a maximal char value");
728 max_limit
= char_limit_t::maximum
;
731 loc
->warning("Cannot determine the value of MAX, using the maximal char value of the type");
732 max_limit
= char_limit_t::maximum
;
735 // max_limit was set to the correct value
738 FATAL_ERROR("SubtypeConstraint::create_from_asn_range()");
741 max_limit
= char_limit_t::maximum
;
746 if (max_limit
==char_limit_t::minimum
) {
747 loc
->error("exclusive upper boundary is not a legal character");
750 max_limit
= max_limit
.previous();
752 if (max_limit
<min_limit
) {
753 loc
->error("lower boundary is bigger than upper boundary in string value range constraint");
756 SubtypeConstraint
* stc
= new SubtypeConstraint(st_t
);
757 stc
->charstring_st
= new CharstringSubtypeTreeElement(CharRangeListConstraint(min_limit
,max_limit
), true);
760 case ST_UNIVERSAL_CHARSTRING
: {
761 if (((vmin
!=NULL
) && (vmin
->get_valuetype()!=Value::V_USTR
)) ||
762 ((vmax
!=NULL
) && (vmax
->get_valuetype()!=Value::V_USTR
))) return NULL
;
763 if (vmin
&& (vmin
->get_val_ustr().size()!=1)) {
764 vmin
->error("lower boundary of string value range constraint must be a single element string");
767 if (vmax
&& (vmax
->get_val_ustr().size()!=1)) {
768 vmax
->error("upper boundary of string value range constraint must be a single element string");
771 if (vmin
&& !universal_char_limit_t::is_valid_value(*vmin
->get_val_ustr().u_str())) {
772 vmin
->error("lower boundary of string value range constraint is an invalid universal char");
775 if (vmax
&& !universal_char_limit_t::is_valid_value(*vmax
->get_val_ustr().u_str())) {
776 vmax
->error("upper boundary of string value range constraint is an invalid universal char");
780 if (parent_subtype
&& (parent_subtype
->subtype
!=ST_UNIVERSAL_CHARSTRING
)) FATAL_ERROR("SubtypeConstraint::create_from_asn_range()");
781 universal_char_limit_t min_limit
;
783 min_limit
= universal_char_limit_t(*vmin
->get_val_ustr().u_str());
784 } else { // MIN was used
785 if (parent_subtype
&& parent_subtype
->universal_charstring_st
) {
786 tribool tb
= parent_subtype
->universal_charstring_st
->get_alphabet_limit(false, min_limit
);
789 loc
->error("Cannot determine the value of MIN: the parent subtype does not define a minimal char value");
790 min_limit
= universal_char_limit_t::minimum
;
793 loc
->warning("Cannot determine the value of MIN, using the minimal char value of the type");
794 min_limit
= universal_char_limit_t::minimum
;
797 // min_limit was set to the correct value
800 FATAL_ERROR("SubtypeConstraint::create_from_asn_range()");
803 min_limit
= universal_char_limit_t::minimum
;
808 if (min_limit
==universal_char_limit_t::maximum
) {
809 loc
->error("exclusive lower boundary is not a legal character");
812 min_limit
= min_limit
.next();
815 universal_char_limit_t max_limit
;
817 max_limit
= universal_char_limit_t(*vmax
->get_val_ustr().u_str());
818 } else { // MAX was used
819 if (parent_subtype
&& parent_subtype
->universal_charstring_st
) {
820 tribool tb
= parent_subtype
->universal_charstring_st
->get_alphabet_limit(true, max_limit
);
823 loc
->error("Cannot determine the value of MAX: the parent subtype does not define a maximal char value");
824 max_limit
= universal_char_limit_t::maximum
;
827 loc
->warning("Cannot determine the value of MAX, using the maximal char value of the type");
828 max_limit
= universal_char_limit_t::maximum
;
831 // max_limit was set to the correct value
834 FATAL_ERROR("SubtypeConstraint::create_from_asn_range()");
837 max_limit
= universal_char_limit_t::maximum
;
842 if (max_limit
==universal_char_limit_t::minimum
) {
843 loc
->error("exclusive upper boundary is not a legal character");
846 max_limit
= max_limit
.previous();
848 if (max_limit
<min_limit
) {
849 loc
->error("lower boundary is bigger than upper boundary in string value range constraint");
852 SubtypeConstraint
* stc
= new SubtypeConstraint(st_t
);
853 stc
->universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(UniversalCharRangeListConstraint(min_limit
,max_limit
), true);
857 FATAL_ERROR("SubtypeConstraint::create_from_asn_range()");
862 SubtypeConstraint
* SubtypeConstraint::create_from_contained_subtype(SubtypeConstraint
* contained_stc
, bool char_context
, Location
* loc
)
864 if (contained_stc
==NULL
) return NULL
;
865 SubtypeConstraint
* rv_stc
= NULL
;
867 switch (contained_stc
->get_subtypetype()) {
869 if (contained_stc
->charstring_st
==NULL
) {
870 rv_stc
= new SubtypeConstraint(contained_stc
->get_subtypetype()); // full set
872 if (contained_stc
->charstring_st
->is_valid_range()) {
873 rv_stc
= new SubtypeConstraint(contained_stc
->get_subtypetype());
874 rv_stc
->copy(contained_stc
);
875 rv_stc
->charstring_st
->set_char_context(true);
877 loc
->error("The type of the contained subtype constraint cannot be used in a permitted alphabet constraint");
881 case ST_UNIVERSAL_CHARSTRING
:
882 if (contained_stc
->universal_charstring_st
==NULL
) {
883 rv_stc
= new SubtypeConstraint(contained_stc
->get_subtypetype()); // full set
885 if (contained_stc
->universal_charstring_st
->is_valid_range()) {
886 rv_stc
= new SubtypeConstraint(contained_stc
->get_subtypetype());
887 rv_stc
->copy(contained_stc
);
888 rv_stc
->universal_charstring_st
->set_char_context(true);
890 loc
->error("The type of the contained subtype constraint cannot be used in a permitted alphabet constraint");
895 // error was already reported
899 rv_stc
= new SubtypeConstraint(contained_stc
->get_subtypetype());
900 rv_stc
->copy(contained_stc
);
905 SubtypeConstraint
* SubtypeConstraint::create_asn_size_constraint(
906 SubtypeConstraint
* integer_stc
, bool char_context
, Type
* type
, Location
* loc
)
908 if (integer_stc
==NULL
) return NULL
;
909 // convert IntegerRangeListConstraint to SizeRangeListConstraint
910 if (integer_stc
->subtype
!=ST_INTEGER
) FATAL_ERROR("SubtypeConstraint::create_asn_size_constraint()");
911 SizeRangeListConstraint
size_constraint(size_limit_t::minimum
, size_limit_t::maximum
);
912 if (integer_stc
->integer_st
) {
913 static const int_val_t
zero((Int
)0);
914 static const int_limit_t
ilt0(zero
);
915 IntegerRangeListConstraint
valid_range(ilt0
, int_limit_t::maximum
);
916 if (integer_stc
->integer_st
->is_subset(valid_range
)==TFALSE
) {
917 loc
->error("Range %s is not a valid range for a size constraint", integer_stc
->to_string().c_str());
919 bool success
= convert_int_to_size(*(integer_stc
->integer_st
), size_constraint
);
921 loc
->error("One or more INTEGER values of range %s are too large to be used in a size constraint", integer_stc
->to_string().c_str());
925 subtype_t st_t
= type
->get_subtype_type();
926 if (st_t
==ST_ERROR
) return NULL
;
927 SubtypeConstraint
* stc
= new SubtypeConstraint(st_t
);
930 stc
->length_restriction
= new SizeRangeListConstraint(size_constraint
); // FIXME? : is this Ok if not a top level constraint?
935 stc
->bitstring_st
= new BitstringConstraint(size_constraint
);
938 stc
->hexstring_st
= new HexstringConstraint(size_constraint
);
941 stc
->octetstring_st
= new OctetstringConstraint(size_constraint
);
945 if (size_constraint
.is_equal(SizeRangeListConstraint(size_limit_t(1)))==TFALSE
) {
946 loc
->error("Only SIZE(1) constraint can be used inside a permitted alphabet constraint");
950 // SIZE(1) is allowed in char context, it means ALL
952 stc
->charstring_st
= new CharstringSubtypeTreeElement(size_constraint
);
955 case ST_UNIVERSAL_CHARSTRING
:
957 if (size_constraint
.is_equal(SizeRangeListConstraint(size_limit_t(1)))==TFALSE
) {
958 loc
->error("Only SIZE(1) constraint can be used inside a permitted alphabet constraint");
962 // SIZE(1) is allowed in char context, it means ALL
964 stc
->universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(size_constraint
);
969 stc
->recof_st
= new RecofConstraint(size_constraint
);
972 loc
->error("Size constraint is not allowed for type `%s'", type
->get_typename().c_str());
979 SubtypeConstraint
* SubtypeConstraint::create_permitted_alphabet_constraint(
980 SubtypeConstraint
* stc
, bool char_context
, Type
* type
, Location
* loc
)
983 loc
->error("Permitted alphabet constraint not allowed inside a permitted alphabet constraint");
986 subtype_t st_t
= type
->get_subtype_type();
989 case ST_UNIVERSAL_CHARSTRING
: {
990 if (stc
==NULL
) return NULL
; // error was reported there
991 if (st_t
!=stc
->get_subtypetype()) FATAL_ERROR("SubtypeConstraint::create_permitted_alphabet_constraint()");
992 SubtypeConstraint
* rv_stc
= new SubtypeConstraint(st_t
);
993 if (st_t
==ST_CHARSTRING
) {
994 if (stc
->charstring_st
) {
995 rv_stc
->charstring_st
= new CharstringSubtypeTreeElement(*(stc
->charstring_st
));
996 rv_stc
->charstring_st
->set_char_context(false);
999 if (stc
->universal_charstring_st
) {
1000 rv_stc
->universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(*(stc
->universal_charstring_st
));
1001 rv_stc
->universal_charstring_st
->set_char_context(false);
1007 // error already reported
1010 loc
->error("Permitted alphabet constraint is not allowed for type `%s'", type
->get_typename().c_str());
1016 void SubtypeConstraint::set_to_error()
1030 case ST_VERDICTTYPE
:
1034 delete bitstring_st
;
1037 delete hexstring_st
;
1039 case ST_OCTETSTRING
:
1040 delete octetstring_st
;
1043 delete charstring_st
;
1045 case ST_UNIVERSAL_CHARSTRING
:
1046 delete universal_charstring_st
;
1063 FATAL_ERROR("SubtypeConstraint::set_to_error()");
1066 delete length_restriction
;
1067 length_restriction
= NULL
;
1070 string
SubtypeConstraint::to_string() const
1074 return string("<error>");
1076 return (integer_st
==NULL
) ? string() : integer_st
->to_string();
1078 return (float_st
==NULL
) ? string() : float_st
->to_string();
1080 return (boolean_st
==NULL
) ? string() : boolean_st
->to_string();
1081 case ST_VERDICTTYPE
:
1082 return (verdict_st
==NULL
) ? string() : verdict_st
->to_string();
1084 return (bitstring_st
==NULL
) ? string() : bitstring_st
->to_string();
1086 return (hexstring_st
==NULL
) ? string() : hexstring_st
->to_string();
1087 case ST_OCTETSTRING
:
1088 return (octetstring_st
==NULL
) ? string() : octetstring_st
->to_string();
1090 return (charstring_st
==NULL
) ? string() : charstring_st
->to_string();
1091 case ST_UNIVERSAL_CHARSTRING
:
1092 return (universal_charstring_st
==NULL
) ? string() : universal_charstring_st
->to_string();
1101 return (value_st
==NULL
) ? string() : value_st
->to_string();
1104 return (recof_st
==NULL
) ? string() : recof_st
->to_string();
1106 FATAL_ERROR("SubtypeConstraint::to_string()");
1110 bool SubtypeConstraint::is_compatible(const SubtypeConstraint
*p_st
) const
1112 if (p_st
==NULL
) return true; // the other type has no subtype restriction
1113 if ( (subtype
==ST_ERROR
) || (p_st
->subtype
==ST_ERROR
) ) return true;
1114 if (subtype
!=p_st
->subtype
) FATAL_ERROR("SubtypeConstraint::is_compatible()");
1115 // if the resulting set.is_empty()==TUNKNOWN then remain silent
1118 if ((integer_st
==NULL
) || (p_st
->integer_st
==NULL
)) return true;
1119 return ((*integer_st
**(p_st
->integer_st
)).is_empty()!=TTRUE
);
1121 if ((float_st
==NULL
) || (p_st
->float_st
==NULL
)) return true;
1122 return ((*float_st
**(p_st
->float_st
)).is_empty()!=TTRUE
);
1124 if ((boolean_st
==NULL
) || (p_st
->boolean_st
==NULL
)) return true;
1125 return ((*boolean_st
**(p_st
->boolean_st
)).is_empty()!=TTRUE
);
1126 case ST_VERDICTTYPE
:
1127 if ((verdict_st
==NULL
) || (p_st
->verdict_st
==NULL
)) return true;
1128 return ((*verdict_st
**(p_st
->verdict_st
)).is_empty()!=TTRUE
);
1130 if ((bitstring_st
==NULL
) || (p_st
->bitstring_st
==NULL
)) return true;
1131 return ((*bitstring_st
**(p_st
->bitstring_st
)).is_empty()!=TTRUE
);
1133 if ((hexstring_st
==NULL
) || (p_st
->hexstring_st
==NULL
)) return true;
1134 return ((*hexstring_st
**(p_st
->hexstring_st
)).is_empty()!=TTRUE
);
1135 case ST_OCTETSTRING
:
1136 if ((octetstring_st
==NULL
) || (p_st
->octetstring_st
==NULL
)) return true;
1137 return ((*octetstring_st
**(p_st
->octetstring_st
)).is_empty()!=TTRUE
);
1138 case ST_CHARSTRING
: {
1139 if ((charstring_st
==NULL
) || (p_st
->charstring_st
==NULL
)) return true;
1140 CharstringSubtypeTreeElement
* cc
= new CharstringSubtypeTreeElement(
1141 CharstringSubtypeTreeElement::ET_INTERSECTION
,
1142 new CharstringSubtypeTreeElement(*charstring_st
),
1143 new CharstringSubtypeTreeElement(*(p_st
->charstring_st
))
1145 bool rv
= (cc
->is_empty()!=TTRUE
);
1149 case ST_UNIVERSAL_CHARSTRING
: {
1150 if ((universal_charstring_st
==NULL
) || (p_st
->universal_charstring_st
==NULL
)) return true;
1151 UniversalCharstringSubtypeTreeElement
* ucc
= new UniversalCharstringSubtypeTreeElement(
1152 UniversalCharstringSubtypeTreeElement::ET_INTERSECTION
,
1153 new UniversalCharstringSubtypeTreeElement(*universal_charstring_st
),
1154 new UniversalCharstringSubtypeTreeElement(*(p_st
->universal_charstring_st
))
1156 bool rv
= (ucc
->is_empty()!=TTRUE
);
1168 if ((value_st
==NULL
) || (p_st
->value_st
==NULL
)) return true;
1169 return ((*value_st
**(p_st
->value_st
)).is_empty()!=TTRUE
);
1172 if ((recof_st
==NULL
) || (p_st
->recof_st
==NULL
)) return true;
1173 return ((*recof_st
**(p_st
->recof_st
)).is_empty()!=TTRUE
);
1175 FATAL_ERROR("SubtypeConstraint::is_compatible()");
1180 bool SubtypeConstraint::is_compatible_with_elem() const
1182 if (subtype
==ST_ERROR
) return true;
1184 case ST_BITSTRING
: {
1185 static BitstringConstraint
str_elem(size_limit_t(1));
1186 if (bitstring_st
==NULL
) return true;
1187 return ((*bitstring_st
*str_elem
).is_empty()!=TTRUE
);
1189 case ST_HEXSTRING
: {
1190 static HexstringConstraint
str_elem(size_limit_t(1));
1191 if (hexstring_st
==NULL
) return true;
1192 return ((*hexstring_st
*str_elem
).is_empty()!=TTRUE
);
1194 case ST_OCTETSTRING
: {
1195 static OctetstringConstraint
str_elem(size_limit_t(1));
1196 if (octetstring_st
==NULL
) return true;
1197 return ((*octetstring_st
*str_elem
).is_empty()!=TTRUE
);
1199 case ST_CHARSTRING
: {
1200 size_limit_t t
= size_limit_t(1);
1201 SizeRangeListConstraint temp
= SizeRangeListConstraint(t
);
1202 static CharstringSubtypeTreeElement
str_elem(temp
);
1203 if (charstring_st
==NULL
) return true;
1204 CharstringSubtypeTreeElement
* cc
= new CharstringSubtypeTreeElement(
1205 CharstringSubtypeTreeElement::ET_INTERSECTION
,
1206 new CharstringSubtypeTreeElement(*charstring_st
),
1207 new CharstringSubtypeTreeElement(str_elem
)
1209 bool rv
= (cc
->is_empty()!=TTRUE
);
1213 case ST_UNIVERSAL_CHARSTRING
: {
1214 size_limit_t t
= size_limit_t(1);
1215 SizeRangeListConstraint temp
= SizeRangeListConstraint(t
);
1216 static UniversalCharstringSubtypeTreeElement
str_elem(temp
);
1217 if (universal_charstring_st
==NULL
) return true;
1218 UniversalCharstringSubtypeTreeElement
* ucc
= new UniversalCharstringSubtypeTreeElement(
1219 UniversalCharstringSubtypeTreeElement::ET_INTERSECTION
,
1220 new UniversalCharstringSubtypeTreeElement(*universal_charstring_st
),
1221 new UniversalCharstringSubtypeTreeElement(str_elem
)
1223 bool rv
= (ucc
->is_empty()!=TTRUE
);
1228 FATAL_ERROR("SubtypeConstraint::is_compatible_with_elem()");
1233 bool SubtypeConstraint::is_length_compatible(const SubtypeConstraint
*p_st
) const
1235 if (p_st
==NULL
) FATAL_ERROR("SubtypeConstraint::is_length_compatible()");
1236 if ((subtype
==ST_ERROR
) || (p_st
->subtype
==ST_ERROR
)) return true;
1237 if (subtype
!= ST_RECORDOF
&& subtype
!= ST_SETOF
&&
1238 p_st
->subtype
!= ST_RECORDOF
&& p_st
->subtype
!= ST_SETOF
)
1239 FATAL_ERROR("SubtypeConstraint::is_length_compatible()");
1240 if (length_restriction
==NULL
|| p_st
->length_restriction
==NULL
) return true;
1241 return ((*length_restriction
* *(p_st
->length_restriction
)).is_empty()!=TTRUE
);
1244 bool SubtypeConstraint::is_upper_limit_infinity() const
1246 if (ST_INTEGER
== subtype
&& integer_st
) {
1247 return integer_st
->is_upper_limit_infinity();
1249 if (ST_FLOAT
== subtype
&& float_st
) {
1250 return float_st
->is_upper_limit_infinity();
1255 bool SubtypeConstraint::is_lower_limit_infinity() const
1257 if (ST_INTEGER
== subtype
&& integer_st
) {
1258 return integer_st
->is_lower_limit_infinity();
1261 if (ST_FLOAT
== subtype
&& float_st
) {
1262 return float_st
->is_lower_limit_infinity();
1268 void SubtypeConstraint::except(const SubtypeConstraint
* other
)
1270 if (other
==NULL
) FATAL_ERROR("SubtypeConstraint::except()");
1271 if (subtype
!=other
->subtype
) FATAL_ERROR("SubtypeConstraint::except()");
1274 if (other
->integer_st
==NULL
) {
1275 if (integer_st
==NULL
) {
1276 integer_st
= new IntegerRangeListConstraint();
1278 *integer_st
= IntegerRangeListConstraint();
1281 if (integer_st
==NULL
) {
1282 integer_st
= new IntegerRangeListConstraint(~*(other
->integer_st
));
1284 *integer_st
= *integer_st
- *(other
->integer_st
);
1289 if (other
->float_st
==NULL
) {
1290 if (float_st
==NULL
) {
1291 float_st
= new RealRangeListConstraint();
1293 *float_st
= RealRangeListConstraint();
1296 if (float_st
==NULL
) {
1297 float_st
= new RealRangeListConstraint(~*(other
->float_st
));
1299 *float_st
= *float_st
- *(other
->float_st
);
1304 if (other
->boolean_st
==NULL
) {
1305 if (boolean_st
==NULL
) {
1306 boolean_st
= new BooleanListConstraint();
1308 *boolean_st
= BooleanListConstraint();
1311 if (boolean_st
==NULL
) {
1312 boolean_st
= new BooleanListConstraint(~*(other
->boolean_st
));
1314 *boolean_st
= *boolean_st
- *(other
->boolean_st
);
1318 case ST_VERDICTTYPE
:
1319 if (other
->verdict_st
==NULL
) {
1320 if (verdict_st
==NULL
) {
1321 verdict_st
= new VerdicttypeListConstraint();
1323 *verdict_st
= VerdicttypeListConstraint();
1326 if (verdict_st
==NULL
) {
1327 verdict_st
= new VerdicttypeListConstraint(~*(other
->verdict_st
));
1329 *verdict_st
= *verdict_st
- *(other
->verdict_st
);
1334 if (other
->bitstring_st
==NULL
) {
1335 if (bitstring_st
==NULL
) {
1336 bitstring_st
= new BitstringConstraint();
1338 *bitstring_st
= BitstringConstraint();
1341 if (bitstring_st
==NULL
) {
1342 bitstring_st
= new BitstringConstraint(~*(other
->bitstring_st
));
1344 *bitstring_st
= *bitstring_st
- *(other
->bitstring_st
);
1349 if (other
->hexstring_st
==NULL
) {
1350 if (hexstring_st
==NULL
) {
1351 hexstring_st
= new HexstringConstraint();
1353 *hexstring_st
= HexstringConstraint();
1356 if (hexstring_st
==NULL
) {
1357 hexstring_st
= new HexstringConstraint(~*(other
->hexstring_st
));
1359 *hexstring_st
= *hexstring_st
- *(other
->hexstring_st
);
1363 case ST_OCTETSTRING
:
1364 if (other
->octetstring_st
==NULL
) {
1365 if (octetstring_st
==NULL
) {
1366 octetstring_st
= new OctetstringConstraint();
1368 *octetstring_st
= OctetstringConstraint();
1371 if (octetstring_st
==NULL
) {
1372 octetstring_st
= new OctetstringConstraint(~*(other
->octetstring_st
));
1374 *octetstring_st
= *octetstring_st
- *(other
->octetstring_st
);
1379 if (other
->charstring_st
==NULL
) {
1380 if (charstring_st
==NULL
) {
1381 charstring_st
= new CharstringSubtypeTreeElement();
1383 *charstring_st
= CharstringSubtypeTreeElement();
1386 if (charstring_st
==NULL
) {
1387 CharstringSubtypeTreeElement
* call_st
= new CharstringSubtypeTreeElement();
1389 charstring_st
= new CharstringSubtypeTreeElement(CharstringSubtypeTreeElement::ET_EXCEPT
,
1390 call_st
, new CharstringSubtypeTreeElement(*(other
->charstring_st
)));
1392 charstring_st
= new CharstringSubtypeTreeElement(CharstringSubtypeTreeElement::ET_EXCEPT
,
1393 charstring_st
, new CharstringSubtypeTreeElement(*(other
->charstring_st
)));
1397 case ST_UNIVERSAL_CHARSTRING
:
1398 if (other
->universal_charstring_st
==NULL
) {
1399 if (universal_charstring_st
==NULL
) {
1400 universal_charstring_st
= new UniversalCharstringSubtypeTreeElement();
1402 *universal_charstring_st
= UniversalCharstringSubtypeTreeElement();
1405 if (universal_charstring_st
==NULL
) {
1406 UniversalCharstringSubtypeTreeElement
* ucall_st
= new UniversalCharstringSubtypeTreeElement();
1407 ucall_st
->set_all();
1408 universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(UniversalCharstringSubtypeTreeElement::ET_EXCEPT
,
1409 ucall_st
, new UniversalCharstringSubtypeTreeElement(*(other
->universal_charstring_st
)));
1411 universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(UniversalCharstringSubtypeTreeElement::ET_EXCEPT
,
1412 universal_charstring_st
, new UniversalCharstringSubtypeTreeElement(*(other
->universal_charstring_st
)));
1424 if (other
->value_st
==NULL
) {
1425 if (value_st
==NULL
) {
1426 value_st
= new ValueListConstraint();
1428 *value_st
= ValueListConstraint();
1431 if (value_st
==NULL
) {
1432 value_st
= new ValueListConstraint(~*(other
->value_st
));
1434 *value_st
= *value_st
- *(other
->value_st
);
1440 if (other
->recof_st
==NULL
) {
1441 if (recof_st
==NULL
) {
1442 recof_st
= new RecofConstraint();
1444 *recof_st
= RecofConstraint();
1447 if (recof_st
==NULL
) {
1448 recof_st
= new RecofConstraint(~*(other
->recof_st
));
1450 *recof_st
= *recof_st
- *(other
->recof_st
);
1455 FATAL_ERROR("SubtypeConstraint::except()");
1457 if (other
->length_restriction
==NULL
) {
1458 if (length_restriction
==NULL
) {
1459 length_restriction
= new SizeRangeListConstraint();
1461 *length_restriction
= SizeRangeListConstraint();
1464 if (length_restriction
==NULL
) {
1465 length_restriction
= new SizeRangeListConstraint(~*(other
->length_restriction
));
1467 *length_restriction
= *length_restriction
- *(other
->length_restriction
);
1472 void SubtypeConstraint::union_(const SubtypeConstraint
* other
)
1474 if (other
==NULL
) FATAL_ERROR("SubtypeConstraint::union_()");
1475 if (subtype
!=other
->subtype
) FATAL_ERROR("SubtypeConstraint::union_()");
1478 if (integer_st
==NULL
) break;
1479 if (other
->integer_st
==NULL
) { delete integer_st
; integer_st
= NULL
; break; }
1480 *integer_st
= *integer_st
+ *(other
->integer_st
);
1483 if (float_st
==NULL
) break;
1484 if (other
->float_st
==NULL
) { delete float_st
; float_st
= NULL
; break; }
1485 *float_st
= *float_st
+ *(other
->float_st
);
1488 if (boolean_st
==NULL
) break;
1489 if (other
->boolean_st
==NULL
) { delete boolean_st
; boolean_st
= NULL
; break; }
1490 *boolean_st
= *boolean_st
+ *(other
->boolean_st
);
1492 case ST_VERDICTTYPE
:
1493 if (verdict_st
==NULL
) break;
1494 if (other
->verdict_st
==NULL
) { delete verdict_st
; verdict_st
= NULL
; break; }
1495 *verdict_st
= *verdict_st
+ *(other
->verdict_st
);
1498 if (bitstring_st
==NULL
) break;
1499 if (other
->bitstring_st
==NULL
) { delete bitstring_st
; bitstring_st
= NULL
; break; }
1500 *bitstring_st
= *bitstring_st
+ *(other
->bitstring_st
);
1503 if (hexstring_st
==NULL
) break;
1504 if (other
->hexstring_st
==NULL
) { delete hexstring_st
; hexstring_st
= NULL
; break; }
1505 *hexstring_st
= *hexstring_st
+ *(other
->hexstring_st
);
1507 case ST_OCTETSTRING
:
1508 if (octetstring_st
==NULL
) break;
1509 if (other
->octetstring_st
==NULL
) { delete octetstring_st
; octetstring_st
= NULL
; break; }
1510 *octetstring_st
= *octetstring_st
+ *(other
->octetstring_st
);
1513 if (charstring_st
==NULL
) break;
1514 if (other
->charstring_st
==NULL
) { delete charstring_st
; charstring_st
= NULL
; break; }
1515 charstring_st
= new CharstringSubtypeTreeElement(CharstringSubtypeTreeElement::ET_UNION
,
1516 charstring_st
, new CharstringSubtypeTreeElement(*(other
->charstring_st
)));
1518 case ST_UNIVERSAL_CHARSTRING
:
1519 if (universal_charstring_st
==NULL
) break;
1520 if (other
->universal_charstring_st
==NULL
) { delete universal_charstring_st
; universal_charstring_st
= NULL
; break; }
1521 universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(UniversalCharstringSubtypeTreeElement::ET_UNION
,
1522 universal_charstring_st
, new UniversalCharstringSubtypeTreeElement(*(other
->universal_charstring_st
)));
1532 if (value_st
==NULL
) break;
1533 if (other
->value_st
==NULL
) { delete value_st
; value_st
= NULL
; break; }
1534 *value_st
= *value_st
+ *(other
->value_st
);
1538 if (recof_st
==NULL
) break;
1539 if (other
->recof_st
==NULL
) { delete recof_st
; recof_st
= NULL
; break; }
1540 *recof_st
= *recof_st
+ *(other
->recof_st
);
1543 FATAL_ERROR("SubtypeConstraint::union_()");
1545 if (length_restriction
!=NULL
) {
1546 if (other
->length_restriction
==NULL
) {
1547 delete length_restriction
;
1548 length_restriction
= NULL
;
1550 *length_restriction
= *length_restriction
+ *(other
->length_restriction
);
1555 void SubtypeConstraint::intersection(const SubtypeConstraint
* other
)
1557 if (other
==NULL
) FATAL_ERROR("SubtypeConstraint::intersection()");
1558 if (subtype
!=other
->subtype
) FATAL_ERROR("SubtypeConstraint::intersection()");
1561 if (other
->integer_st
!=NULL
) {
1562 if (integer_st
==NULL
) {
1563 integer_st
= new IntegerRangeListConstraint(*(other
->integer_st
));
1565 *integer_st
= *integer_st
* *(other
->integer_st
);
1570 if (other
->float_st
!=NULL
) {
1571 if (float_st
==NULL
) {
1572 float_st
= new RealRangeListConstraint(*(other
->float_st
));
1574 *float_st
= *float_st
* *(other
->float_st
);
1579 if (other
->boolean_st
!=NULL
) {
1580 if (boolean_st
==NULL
) {
1581 boolean_st
= new BooleanListConstraint(*(other
->boolean_st
));
1583 *boolean_st
= *boolean_st
* *(other
->boolean_st
);
1587 case ST_VERDICTTYPE
:
1588 if (other
->verdict_st
!=NULL
) {
1589 if (verdict_st
==NULL
) {
1590 verdict_st
= new VerdicttypeListConstraint(*(other
->verdict_st
));
1592 *verdict_st
= *verdict_st
* *(other
->verdict_st
);
1597 if (other
->bitstring_st
!=NULL
) {
1598 if (bitstring_st
==NULL
) {
1599 bitstring_st
= new BitstringConstraint(*(other
->bitstring_st
));
1601 *bitstring_st
= *bitstring_st
* *(other
->bitstring_st
);
1606 if (other
->hexstring_st
!=NULL
) {
1607 if (hexstring_st
==NULL
) {
1608 hexstring_st
= new HexstringConstraint(*(other
->hexstring_st
));
1610 *hexstring_st
= *hexstring_st
* *(other
->hexstring_st
);
1614 case ST_OCTETSTRING
:
1615 if (other
->octetstring_st
!=NULL
) {
1616 if (octetstring_st
==NULL
) {
1617 octetstring_st
= new OctetstringConstraint(*(other
->octetstring_st
));
1619 *octetstring_st
= *octetstring_st
* *(other
->octetstring_st
);
1624 if (other
->charstring_st
!=NULL
) {
1625 if (charstring_st
==NULL
) {
1626 charstring_st
= new CharstringSubtypeTreeElement(*(other
->charstring_st
));
1628 charstring_st
= new CharstringSubtypeTreeElement(CharstringSubtypeTreeElement::ET_INTERSECTION
,
1629 charstring_st
, new CharstringSubtypeTreeElement(*(other
->charstring_st
)));
1633 case ST_UNIVERSAL_CHARSTRING
:
1634 if (other
->universal_charstring_st
!=NULL
) {
1635 if (universal_charstring_st
==NULL
) {
1636 universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(*(other
->universal_charstring_st
));
1638 universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(UniversalCharstringSubtypeTreeElement::ET_INTERSECTION
,
1639 universal_charstring_st
, new UniversalCharstringSubtypeTreeElement(*(other
->universal_charstring_st
)));
1651 if (other
->value_st
!=NULL
) {
1652 if (value_st
==NULL
) {
1653 value_st
= new ValueListConstraint(*(other
->value_st
));
1655 *value_st
= *value_st
* *(other
->value_st
);
1661 if (other
->recof_st
!=NULL
) {
1662 if (recof_st
==NULL
) {
1663 recof_st
= new RecofConstraint(*(other
->recof_st
));
1665 *recof_st
= *recof_st
* *(other
->recof_st
);
1670 FATAL_ERROR("SubtypeConstraint::intersection()");
1672 if (other
->length_restriction
!=NULL
) {
1673 if (length_restriction
==NULL
) {
1674 length_restriction
= new SizeRangeListConstraint(*(other
->length_restriction
));
1676 *length_restriction
= *length_restriction
* *(other
->length_restriction
);
1681 tribool
SubtypeConstraint::is_subset(const SubtypeConstraint
* other
) const
1683 if (other
==NULL
) return TTRUE
;
1684 if (other
->subtype
!=subtype
) FATAL_ERROR("SubtypeConstraint::is_subset()");
1687 if (other
->integer_st
==NULL
) return TTRUE
;
1688 return integer_st
? integer_st
->is_subset(*(other
->integer_st
)) : TTRUE
;
1690 if (other
->float_st
==NULL
) return TTRUE
;
1691 return float_st
? float_st
->is_subset(*(other
->float_st
)) : TTRUE
;
1693 if (other
->boolean_st
==NULL
) return TTRUE
;
1694 return boolean_st
? boolean_st
->is_subset(*(other
->boolean_st
)) : TTRUE
;
1695 case ST_VERDICTTYPE
:
1696 if (other
->verdict_st
==NULL
) return TTRUE
;
1697 return verdict_st
? verdict_st
->is_subset(*(other
->verdict_st
)) : TTRUE
;
1699 if (other
->bitstring_st
==NULL
) return TTRUE
;
1700 return bitstring_st
? bitstring_st
->is_subset(*(other
->bitstring_st
)) : TTRUE
;
1702 if (other
->hexstring_st
==NULL
) return TTRUE
;
1703 return hexstring_st
? hexstring_st
->is_subset(*(other
->hexstring_st
)) : TTRUE
;
1704 case ST_OCTETSTRING
:
1705 if (other
->octetstring_st
==NULL
) return TTRUE
;
1706 return octetstring_st
? octetstring_st
->is_subset(*(other
->octetstring_st
)) : TTRUE
;
1708 if (other
->charstring_st
==NULL
) return TTRUE
;
1709 return charstring_st
? charstring_st
->is_subset(other
->charstring_st
) : TTRUE
;
1710 case ST_UNIVERSAL_CHARSTRING
:
1711 if (other
->universal_charstring_st
==NULL
) return TTRUE
;
1712 return universal_charstring_st
? universal_charstring_st
->is_subset(other
->universal_charstring_st
) : TTRUE
;
1721 if (other
->value_st
==NULL
) return TTRUE
;
1722 return value_st
? value_st
->is_subset(*(other
->value_st
)) : TTRUE
;
1725 if (other
->recof_st
==NULL
) return TTRUE
;
1726 return recof_st
? recof_st
->is_subset(*(other
->recof_st
)) : TTRUE
;
1728 FATAL_ERROR("SubtypeConstraint::is_subset()");
1733 /********************
1735 ********************/
1737 SubType::SubType(subtype_t st
, Type
*p_my_owner
, SubType
* p_parent_subtype
,
1738 vector
<SubTypeParse
> *p_parsed
, Constraints
* p_asn_constraints
)
1739 : SubtypeConstraint(st
), my_owner(p_my_owner
), parent_subtype(p_parent_subtype
)
1740 , parsed(p_parsed
), asn_constraints(p_asn_constraints
)
1741 , root(0), extendable(false), extension(0), checked(STC_NO
)
1744 if (p_my_owner
==NULL
) FATAL_ERROR("SubType::SubType()");
1752 void SubType::chk_this_value(Value
*value
)
1754 if (checked
==STC_NO
) FATAL_ERROR("SubType::chk_this_value()");
1755 if ((checked
==STC_CHECKING
) || (subtype
==ST_ERROR
)) return;
1756 Value
*val
= value
->get_value_refd_last();
1757 bool is_invalid
= false;
1758 switch (val
->get_valuetype()) {
1760 if (subtype
!=ST_INTEGER
) FATAL_ERROR("SubType::chk_this_value()");
1761 is_invalid
= (integer_st
!=NULL
) && !integer_st
->is_element(int_limit_t(*(val
->get_val_Int())));
1764 if (subtype
!=ST_FLOAT
) FATAL_ERROR("SubType::chk_this_value()");
1765 is_invalid
= (float_st
!=NULL
) && !float_st
->is_element(val
->get_val_Real());
1768 if (subtype
!=ST_BOOLEAN
) FATAL_ERROR("SubType::chk_this_value()");
1769 is_invalid
= (boolean_st
!=NULL
) && !boolean_st
->is_element(val
->get_val_bool());
1771 case Value::V_VERDICT
: {
1772 if (subtype
!=ST_VERDICTTYPE
) FATAL_ERROR("SubType::chk_this_value()");
1773 VerdicttypeListConstraint::verdicttype_constraint_t vtc
;
1774 switch (val
->get_val_verdict()) {
1775 case Value::Verdict_NONE
: vtc
= VerdicttypeListConstraint::VC_NONE
; break;
1776 case Value::Verdict_PASS
: vtc
= VerdicttypeListConstraint::VC_PASS
; break;
1777 case Value::Verdict_INCONC
: vtc
= VerdicttypeListConstraint::VC_INCONC
; break;
1778 case Value::Verdict_FAIL
: vtc
= VerdicttypeListConstraint::VC_FAIL
; break;
1779 case Value::Verdict_ERROR
: vtc
= VerdicttypeListConstraint::VC_ERROR
; break;
1780 default: FATAL_ERROR("SubType::chk_this_value()");
1782 is_invalid
= (verdict_st
!=NULL
) && !verdict_st
->is_element(vtc
);
1785 if (subtype
!=ST_BITSTRING
) FATAL_ERROR("SubType::chk_this_value()");
1786 is_invalid
= (bitstring_st
!=NULL
) && !bitstring_st
->is_element(val
->get_val_str());
1789 if (subtype
!=ST_HEXSTRING
) FATAL_ERROR("SubType::chk_this_value()");
1790 is_invalid
= (hexstring_st
!=NULL
) && !hexstring_st
->is_element(val
->get_val_str());
1793 if (subtype
!=ST_OCTETSTRING
) FATAL_ERROR("SubType::chk_this_value()");
1794 is_invalid
= (octetstring_st
!=NULL
) && !octetstring_st
->is_element(val
->get_val_str());
1797 case Value::V_ISO2022STR
:
1798 if (subtype
!=ST_CHARSTRING
) FATAL_ERROR("SubType::chk_this_value()");
1799 is_invalid
= (charstring_st
!=NULL
) && !charstring_st
->is_element(val
->get_val_str());
1802 case Value::V_CHARSYMS
:
1803 if (subtype
!=ST_UNIVERSAL_CHARSTRING
) FATAL_ERROR("SubType::chk_this_value()");
1804 is_invalid
= (universal_charstring_st
!=NULL
) && !universal_charstring_st
->is_element(val
->get_val_ustr());
1806 case Value::V_SEQOF
:
1807 if (subtype
!=ST_RECORDOF
) FATAL_ERROR("SubType::chk_this_value()");
1808 if (value
->is_unfoldable()) return;
1809 is_invalid
= (recof_st
!=NULL
) && !recof_st
->is_element(val
);
1811 case Value::V_SETOF
:
1812 if (subtype
!=ST_SETOF
) FATAL_ERROR("SubType::chk_this_value()");
1813 if (value
->is_unfoldable()) return;
1814 is_invalid
= (recof_st
!=NULL
) && !recof_st
->is_element(val
);
1818 if (subtype
!=ST_OBJID
) FATAL_ERROR("SubType::chk_this_value()");
1819 if (value
->is_unfoldable()) return;
1820 is_invalid
= (value_st
!=NULL
) && !value_st
->is_element(val
);
1823 case Value::V_NULL
: // FIXME: should go to ST_NULL
1824 if (subtype
!=ST_ENUM
) FATAL_ERROR("SubType::chk_this_value()");
1825 if (value
->is_unfoldable()) return;
1826 is_invalid
= (value_st
!=NULL
) && !value_st
->is_element(val
);
1828 case Value::V_CHOICE
:
1829 case Value::V_OPENTYPE
: // FIXME?
1830 if (subtype
!=ST_UNION
) FATAL_ERROR("SubType::chk_this_value()");
1831 if (value
->is_unfoldable()) return;
1832 is_invalid
= (value_st
!=NULL
) && !value_st
->is_element(val
);
1835 if (subtype
!=ST_RECORD
) FATAL_ERROR("SubType::chk_this_value()");
1836 if (value
->is_unfoldable()) return;
1837 is_invalid
= (value_st
!=NULL
) && !value_st
->is_element(val
);
1840 if (subtype
!=ST_SET
) FATAL_ERROR("SubType::chk_this_value()");
1841 if (value
->is_unfoldable()) return;
1842 is_invalid
= (value_st
!=NULL
) && !value_st
->is_element(val
);
1844 case Value::V_FUNCTION
:
1845 if (subtype
!=ST_FUNCTION
) FATAL_ERROR("SubType::chk_this_value()");
1846 if (value
->is_unfoldable()) return;
1847 is_invalid
= (value_st
!=NULL
) && !value_st
->is_element(val
);
1849 case Value::V_ALTSTEP
:
1850 if (subtype
!=ST_ALTSTEP
) FATAL_ERROR("SubType::chk_this_value()");
1851 if (value
->is_unfoldable()) return;
1852 is_invalid
= (value_st
!=NULL
) && !value_st
->is_element(val
);
1854 case Value::V_TESTCASE
:
1855 if (subtype
!=ST_TESTCASE
) FATAL_ERROR("SubType::chk_this_value()");
1856 if (value
->is_unfoldable()) return;
1857 is_invalid
= (value_st
!=NULL
) && !value_st
->is_element(val
);
1859 case Value::V_ERROR
:
1865 value
->error("%s is not a valid value for type `%s' which has subtype %s",
1866 val
->get_stringRepr().c_str(),
1867 my_owner
->get_typename().c_str(),
1868 to_string().c_str());
1873 void SubType::chk_this_template_generic(Template
*templ
)
1875 if (checked
==STC_NO
) FATAL_ERROR("SubType::chk_this_template_generic()");
1876 if ((checked
==STC_CHECKING
) || (subtype
==ST_ERROR
)) return;
1877 templ
= templ
->get_template_refd_last();
1878 switch (templ
->get_templatetype()) {
1879 case Ttcn::Template::OMIT_VALUE
:
1880 case Ttcn::Template::ANY_OR_OMIT
:
1881 case Ttcn::Template::TEMPLATE_ERROR
:
1882 case Ttcn::Template::ANY_VALUE
:
1884 case Ttcn::Template::VALUE_LIST
:
1885 case Ttcn::Template::COMPLEMENTED_LIST
:
1886 /* Should be canonical before */
1888 case Ttcn::Template::SPECIFIC_VALUE
:
1889 /* SPECIFIC_VALUE must be already checked in Type::chk_this_template() */
1891 case Ttcn::Template::TEMPLATE_REFD
:
1892 /* unfoldable reference: cannot be checked at compile time */
1894 case Ttcn::Template::TEMPLATE_INVOKE
:
1895 /* should be already checked in Type::chk_this_template() */
1898 chk_this_template(templ
);
1901 chk_this_template_length_restriction(templ
);
1905 void SubType::chk_this_template(Template
*templ
)
1907 switch (templ
->get_templatetype()) {
1908 case Template::TEMPLATE_LIST
:
1909 if ( (length_restriction
!=NULL
) && !length_restriction
->is_empty() ) {
1910 size_t nof_comp_woaon
= templ
->get_nof_comps_not_anyornone();
1911 if (!templ
->temps_contains_anyornone_symbol() &&
1912 nof_comp_woaon
< length_restriction
->get_minimal().get_size()) {
1913 templ
->error("At least %s elements must be present in the list",
1914 Int2string((Int
)(length_restriction
->get_minimal().get_size())).c_str());
1916 } else if ( !length_restriction
->get_maximal().get_infinity() && (nof_comp_woaon
> length_restriction
->get_maximal().get_size()) ) {
1917 templ
->error("There must not be more than %s elements in the list",
1918 Int2string((Int
)(length_restriction
->get_maximal().get_size())).c_str());
1923 /* Simply break. We don't know how many elements are there.
1924 SUPERSET_MATCH/SUBSET_MATCH is not possible to be an
1925 INDEXED_TEMPLATE_LIST. */
1926 case Template::INDEXED_TEMPLATE_LIST
:
1928 case Template::NAMED_TEMPLATE_LIST
:
1930 case Template::VALUE_RANGE
:
1931 /* Should be canonical before */
1933 case Template::SUPERSET_MATCH
:
1934 case Template::SUBSET_MATCH
:
1935 if (subtype
!=ST_SETOF
){
1936 templ
->error("'subset' template matching mechanism can be used "
1937 "only with 'set of' types");
1940 for (size_t i
=0;i
<templ
->get_nof_comps();i
++)
1941 chk_this_template_generic(templ
->get_temp_byIndex(i
));
1943 case Template::BSTR_PATTERN
:
1944 chk_this_template_pattern("bitstring", templ
);
1946 case Template::HSTR_PATTERN
:
1947 chk_this_template_pattern("hexstring", templ
);
1949 case Template::OSTR_PATTERN
:
1950 chk_this_template_pattern("octetstring", templ
);
1952 case Template::CSTR_PATTERN
:
1953 chk_this_template_pattern("charstring", templ
);
1955 case Template::USTR_PATTERN
:
1956 chk_this_template_pattern("universal charstring", templ
);
1958 case Template::TEMPLATE_ERROR
:
1961 FATAL_ERROR("SubType::chk_this_template()");
1966 void SubType::chk_this_template_length_restriction(Template
*templ
)
1968 if (!templ
->is_length_restricted()) return;
1969 // if there is a length restriction on the template then check if
1970 // the intersection of the two restrictions is not empty
1971 size_limit_t
tmpl_min_len(size_limit_t(0));
1972 size_limit_t
tmpl_max_len(size_limit_t::INFINITE_SIZE
);
1973 Ttcn::LengthRestriction
*lr
=templ
->get_length_restriction();
1974 lr
->chk(Type::EXPECTED_DYNAMIC_VALUE
);
1975 if (!lr
->get_is_range()) { //Template's lr is single
1976 Value
*tmp_val
=lr
->get_single_value();
1977 if (tmp_val
->get_valuetype()!=Value::V_INT
) return;
1978 Int templ_len
= tmp_val
->get_val_Int()->get_val();
1979 tmpl_min_len
= tmpl_max_len
= size_limit_t((size_t)templ_len
);
1980 } else { //Template's lr is range
1981 Value
*tmp_lower
=lr
->get_lower_value();
1982 if (tmp_lower
->get_valuetype()!=Value::V_INT
) return;
1983 Int templ_lower
= tmp_lower
->get_val_Int()->get_val();
1984 tmpl_min_len
= size_limit_t((size_t)templ_lower
);
1985 Value
*tmp_upper
=lr
->get_upper_value();
1986 if (tmp_upper
&& tmp_upper
->get_valuetype()!=Value::V_INT
) return;
1987 if (tmp_upper
) tmpl_max_len
= size_limit_t((size_t)tmp_upper
->get_val_Int()->get_val());
1990 bool is_err
= false;
1993 if (bitstring_st
!=NULL
) {
1994 BitstringConstraint bc
= *bitstring_st
* BitstringConstraint(tmpl_min_len
,tmpl_max_len
);
1995 if (bc
.is_empty()==TTRUE
) is_err
= true;
1999 if (hexstring_st
!=NULL
) {
2000 HexstringConstraint hc
= *hexstring_st
* HexstringConstraint(tmpl_min_len
,tmpl_max_len
);
2001 if (hc
.is_empty()==TTRUE
) is_err
= true;
2004 case ST_OCTETSTRING
:
2005 if (octetstring_st
!=NULL
) {
2006 OctetstringConstraint oc
= *octetstring_st
* OctetstringConstraint(tmpl_min_len
,tmpl_max_len
);
2007 if (oc
.is_empty()==TTRUE
) is_err
= true;
2011 if (charstring_st
!=NULL
) {
2012 CharstringSubtypeTreeElement
* cc
= new CharstringSubtypeTreeElement(
2013 CharstringSubtypeTreeElement::ET_INTERSECTION
,
2014 new CharstringSubtypeTreeElement(*charstring_st
),
2015 new CharstringSubtypeTreeElement(SizeRangeListConstraint(tmpl_min_len
,tmpl_max_len
))
2017 if (cc
->is_empty()==TTRUE
) is_err
= true;
2021 case ST_UNIVERSAL_CHARSTRING
:
2022 if (universal_charstring_st
!=NULL
) {
2023 UniversalCharstringSubtypeTreeElement
* ucc
= new UniversalCharstringSubtypeTreeElement(
2024 UniversalCharstringSubtypeTreeElement::ET_INTERSECTION
,
2025 new UniversalCharstringSubtypeTreeElement(*universal_charstring_st
),
2026 new UniversalCharstringSubtypeTreeElement(SizeRangeListConstraint(tmpl_min_len
,tmpl_max_len
))
2028 if (ucc
->is_empty()==TTRUE
) is_err
= true;
2034 if (recof_st
!=NULL
) {
2035 RecofConstraint rc
= *recof_st
* RecofConstraint(tmpl_min_len
,tmpl_max_len
);
2036 if (rc
.is_empty()==TTRUE
) is_err
= true;
2043 templ
->error("Template's length restriction %s is outside of the type's subtype constraint %s",
2044 SizeRangeListConstraint(tmpl_min_len
,tmpl_max_len
).to_string().c_str(), to_string().c_str());
2048 void SubType::chk_this_template_pattern(const char *patt_type
, Template
*templ
)
2050 Template::templatetype_t temptype
= templ
->get_templatetype();
2051 if ((temptype
==Template::BSTR_PATTERN
&& subtype
!=ST_BITSTRING
) ||
2052 (temptype
==Template::HSTR_PATTERN
&& subtype
!=ST_HEXSTRING
) ||
2053 (temptype
==Template::OSTR_PATTERN
&& subtype
!=ST_OCTETSTRING
) ||
2054 (temptype
==Template::CSTR_PATTERN
&& subtype
!=ST_CHARSTRING
) ||
2055 (temptype
==Template::USTR_PATTERN
&& subtype
!=ST_UNIVERSAL_CHARSTRING
))
2057 templ
->error("Template is incompatible with subtype");
2060 if ( (length_restriction
!=NULL
) && !length_restriction
->is_empty() ) {
2061 Int patt_min_len
= static_cast<Int
>(templ
->get_min_length_of_pattern());
2062 if (patt_min_len
< (Int
)(length_restriction
->get_minimal().get_size()) &&
2063 !templ
->pattern_contains_anyornone_symbol()) {
2064 templ
->error("At least %s string elements must be present in the %s",
2065 Int2string((Int
)(length_restriction
->get_minimal().get_size())).c_str(), patt_type
);
2066 } else if ( !length_restriction
->get_maximal().get_infinity() && (patt_min_len
> (Int
)(length_restriction
->get_maximal().get_size())) ) {
2067 templ
->error("There must not be more than %s string elements in the %s",
2068 Int2string((Int
)(length_restriction
->get_maximal().get_size())).c_str(), patt_type
);
2073 void SubType::add_ttcn_value(Value
*v
)
2075 if (value_st
==NULL
) value_st
= new ValueListConstraint(v
);
2076 else *value_st
= *value_st
+ ValueListConstraint(v
);
2079 void SubType::add_ttcn_recof(Value
*v
)
2081 if (recof_st
==NULL
) recof_st
= new RecofConstraint(v
);
2082 else *recof_st
= *recof_st
+ RecofConstraint(v
);
2085 bool SubType::add_ttcn_type_list_subtype(SubType
* p_st
)
2089 if (p_st
->integer_st
==NULL
) return false;
2090 if (integer_st
==NULL
) integer_st
= new IntegerRangeListConstraint(*(p_st
->integer_st
));
2091 else *integer_st
= *integer_st
+ *(p_st
->integer_st
);
2094 if (p_st
->float_st
==NULL
) return false;
2095 if (float_st
==NULL
) float_st
= new RealRangeListConstraint(*(p_st
->float_st
));
2096 else *float_st
= *float_st
+ *(p_st
->float_st
);
2099 if (p_st
->boolean_st
==NULL
) return false;
2100 if (boolean_st
==NULL
) boolean_st
= new BooleanListConstraint(*(p_st
->boolean_st
));
2101 else *boolean_st
= *boolean_st
+ *(p_st
->boolean_st
);
2103 case ST_VERDICTTYPE
:
2104 if (p_st
->verdict_st
==NULL
) return false;
2105 if (verdict_st
==NULL
) verdict_st
= new VerdicttypeListConstraint(*(p_st
->verdict_st
));
2106 else *verdict_st
= *verdict_st
+ *(p_st
->verdict_st
);
2109 if (p_st
->bitstring_st
==NULL
) return false;
2110 if (bitstring_st
==NULL
) bitstring_st
= new BitstringConstraint(*(p_st
->bitstring_st
));
2111 else *bitstring_st
= *bitstring_st
+ *(p_st
->bitstring_st
);
2114 if (p_st
->hexstring_st
==NULL
) return false;
2115 if (hexstring_st
==NULL
) hexstring_st
= new HexstringConstraint(*(p_st
->hexstring_st
));
2116 else *hexstring_st
= *hexstring_st
+ *(p_st
->hexstring_st
);
2118 case ST_OCTETSTRING
:
2119 if (p_st
->octetstring_st
==NULL
) return false;
2120 if (octetstring_st
==NULL
) octetstring_st
= new OctetstringConstraint(*(p_st
->octetstring_st
));
2121 else *octetstring_st
= *octetstring_st
+ *(p_st
->octetstring_st
);
2124 if (p_st
->charstring_st
==NULL
) return false;
2125 if (charstring_st
==NULL
) {
2126 charstring_st
= new CharstringSubtypeTreeElement(*(p_st
->charstring_st
));
2128 charstring_st
= new CharstringSubtypeTreeElement(
2129 CharstringSubtypeTreeElement::ET_UNION
,
2131 new CharstringSubtypeTreeElement(*(p_st
->charstring_st
)));
2134 case ST_UNIVERSAL_CHARSTRING
:
2135 if (p_st
->universal_charstring_st
==NULL
) return false;
2136 if (universal_charstring_st
==NULL
) {
2137 universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(*(p_st
->universal_charstring_st
));
2139 universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(
2140 UniversalCharstringSubtypeTreeElement::ET_UNION
,
2141 universal_charstring_st
,
2142 new UniversalCharstringSubtypeTreeElement(*(p_st
->universal_charstring_st
)));
2153 if (p_st
->value_st
==NULL
) return false;
2154 if (value_st
==NULL
) value_st
= new ValueListConstraint(*(p_st
->value_st
));
2155 else *value_st
= *value_st
+ *(p_st
->value_st
);
2159 if (p_st
->recof_st
==NULL
) return false;
2160 if (recof_st
==NULL
) recof_st
= new RecofConstraint(*(p_st
->recof_st
));
2161 else *recof_st
= *recof_st
+ *(p_st
->recof_st
);
2164 FATAL_ERROR("SubType::add_ttcn_type_list_subtype()");
2170 bool SubType::add_parent_subtype(SubType
* st
)
2172 if (st
==NULL
) FATAL_ERROR("SubType::add_parent_subtype()");
2173 if (my_parents
.has_key(st
)) return true; // it was already successfully added -> ignore
2174 ReferenceChain
refch(my_owner
, "While checking circular type references in subtype definitions");
2175 refch
.add(my_owner
->get_fullname()); // current type
2176 // recursive check for all parents of referenced type
2177 if (!st
->chk_recursion(refch
)) return false;
2178 // if no recursion was detected then add the referenced type as parent
2179 my_parents
.add(st
,NULL
);
2183 bool SubType::chk_recursion(ReferenceChain
& refch
)
2185 if (!refch
.add(my_owner
->get_fullname())) return false; // try the referenced type
2186 for (size_t i
= 0; i
< my_parents
.size(); i
++) {
2188 if (!my_parents
.get_nth_key(i
)->chk_recursion(refch
)) return false;
2194 bool SubType::add_ttcn_single(Value
*val
, size_t restriction_index
)
2196 val
->set_my_scope(my_owner
->get_my_scope());
2197 val
->set_my_governor(my_owner
);
2198 val
->set_fullname(my_owner
->get_fullname()+".<single_restriction_"+Int2string(restriction_index
) + ">");
2199 my_owner
->chk_this_value_ref(val
);
2201 // check if this is type reference, if not then fall through
2202 if (val
->get_valuetype()==Value::V_REFD
) {
2203 Reference
* ref
= val
->get_reference();
2204 Assignment
*ass
= ref
->get_refd_assignment();
2205 if (ass
==NULL
) return false; // defintion was not found, error was reported
2206 if (ass
->get_asstype()==Assignment::A_TYPE
) {
2207 Type
* t
= ass
->get_Type();
2209 if (t
->get_typetype()==Type::T_ERROR
) return false;
2210 // if there were subreferences then get the referenced field's type
2211 if (ref
->get_subrefs()) {
2212 t
= t
->get_field_type(ref
->get_subrefs(), Type::EXPECTED_CONSTANT
);
2213 if ( (t
==NULL
) || (t
->get_typetype()==Type::T_ERROR
) ) return false;
2215 if (t
->get_typetype()==Type::T_ERROR
) return false;
2217 if (!t
->is_identical(my_owner
)) {
2218 val
->error("Reference `%s' must refer to a type which has the same root type as this type",
2219 val
->get_reference()->get_dispname().c_str());
2222 // check subtype of referenced type
2223 SubType
* t_st
= t
->get_sub_type();
2225 val
->error("Type referenced by `%s' does not have a subtype",
2226 val
->get_reference()->get_dispname().c_str());
2230 // check circular subtype reference
2231 if (!add_parent_subtype(t_st
)) return false;
2233 if (t_st
->get_subtypetype()==ST_ERROR
) return false;
2234 if (t_st
->get_subtypetype()!=subtype
) FATAL_ERROR("SubType::add_ttcn_single()");
2235 // add the subtype as union
2236 bool added
= add_ttcn_type_list_subtype(t_st
);
2238 val
->error("Type referenced by `%s' does not have a subtype",
2239 val
->get_reference()->get_dispname().c_str());
2245 my_owner
->chk_this_value(val
, 0, Type::EXPECTED_CONSTANT
,
2246 INCOMPLETE_NOT_ALLOWED
, OMIT_NOT_ALLOWED
, NO_SUB_CHK
);
2248 Value
*v
=val
->get_value_refd_last();
2250 switch (v
->get_valuetype()) {
2252 if (subtype
!=ST_INTEGER
) FATAL_ERROR("SubType::add_ttcn_single()");
2253 if (integer_st
==NULL
) integer_st
= new IntegerRangeListConstraint(int_limit_t(*(v
->get_val_Int())));
2254 else *integer_st
= *integer_st
+ IntegerRangeListConstraint(int_limit_t(*(v
->get_val_Int())));
2256 case Value::V_REAL
: {
2257 if (subtype
!=ST_FLOAT
) FATAL_ERROR("SubType::add_ttcn_single()");
2258 ttcn3float r
= v
->get_val_Real();
2260 if (float_st
==NULL
) float_st
= new RealRangeListConstraint(true);
2261 else *float_st
= *float_st
+ RealRangeListConstraint(true);
2263 if (float_st
==NULL
) float_st
= new RealRangeListConstraint(real_limit_t(r
));
2264 else *float_st
= *float_st
+ RealRangeListConstraint(real_limit_t(r
));
2268 if (subtype
!=ST_BOOLEAN
) FATAL_ERROR("SubType::add_ttcn_single()");
2269 if (boolean_st
==NULL
) boolean_st
= new BooleanListConstraint(v
->get_val_bool());
2270 else *boolean_st
= *boolean_st
+ BooleanListConstraint(v
->get_val_bool());
2272 case Value::V_VERDICT
: {
2273 if (subtype
!=ST_VERDICTTYPE
) FATAL_ERROR("SubType::add_ttcn_single()");
2274 VerdicttypeListConstraint::verdicttype_constraint_t vtc
;
2275 switch (v
->get_val_verdict()) {
2276 case Value::Verdict_NONE
: vtc
= VerdicttypeListConstraint::VC_NONE
; break;
2277 case Value::Verdict_PASS
: vtc
= VerdicttypeListConstraint::VC_PASS
; break;
2278 case Value::Verdict_INCONC
: vtc
= VerdicttypeListConstraint::VC_INCONC
; break;
2279 case Value::Verdict_FAIL
: vtc
= VerdicttypeListConstraint::VC_FAIL
; break;
2280 case Value::Verdict_ERROR
: vtc
= VerdicttypeListConstraint::VC_ERROR
; break;
2281 default: FATAL_ERROR("SubType::add_ttcn_single()");
2283 if (verdict_st
==NULL
) verdict_st
= new VerdicttypeListConstraint(vtc
);
2284 else *verdict_st
= *verdict_st
+ VerdicttypeListConstraint(vtc
);
2287 if (v
->has_oid_error()) return false;
2288 if (subtype
!=ST_OBJID
) FATAL_ERROR("SubType::add_ttcn_single()");
2289 if (value_st
==NULL
) value_st
= new ValueListConstraint(v
);
2290 else *value_st
= *value_st
+ ValueListConstraint(v
);
2293 if (subtype
!=ST_BITSTRING
) FATAL_ERROR("SubType::add_ttcn_single()");
2294 if (bitstring_st
==NULL
) bitstring_st
= new BitstringConstraint(v
->get_val_str());
2295 else *bitstring_st
= *bitstring_st
+ BitstringConstraint(v
->get_val_str());
2298 if (subtype
!=ST_HEXSTRING
) FATAL_ERROR("SubType::add_ttcn_single()");
2299 if (hexstring_st
==NULL
) hexstring_st
= new HexstringConstraint(v
->get_val_str());
2300 else *hexstring_st
= *hexstring_st
+ HexstringConstraint(v
->get_val_str());
2303 if (subtype
!=ST_OCTETSTRING
) FATAL_ERROR("SubType::add_ttcn_single()");
2304 if (octetstring_st
==NULL
) octetstring_st
= new OctetstringConstraint(v
->get_val_str());
2305 else *octetstring_st
= *octetstring_st
+ OctetstringConstraint(v
->get_val_str());
2307 case Value::V_CSTR
: {
2308 if (subtype
!=ST_CHARSTRING
) FATAL_ERROR("SubType::add_ttcn_single()");
2309 CharstringSubtypeTreeElement
* cst_elem
= new CharstringSubtypeTreeElement(StringValueConstraint
<string
>(v
->get_val_str()));
2310 if (charstring_st
==NULL
) charstring_st
= cst_elem
;
2311 else charstring_st
= new CharstringSubtypeTreeElement(CharstringSubtypeTreeElement::ET_UNION
, charstring_st
, cst_elem
);
2313 case Value::V_USTR
: {
2314 if (subtype
!=ST_UNIVERSAL_CHARSTRING
) FATAL_ERROR("SubType::add_ttcn_single()");
2315 UniversalCharstringSubtypeTreeElement
* ucst_elem
= new UniversalCharstringSubtypeTreeElement(StringValueConstraint
<ustring
>(v
->get_val_ustr()));
2316 if (universal_charstring_st
==NULL
) universal_charstring_st
= ucst_elem
;
2317 else universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(UniversalCharstringSubtypeTreeElement::ET_UNION
, universal_charstring_st
, ucst_elem
);
2320 case Value::V_NULL
: // FIXME: should go to ST_NULL
2321 if (subtype
!=ST_ENUM
) FATAL_ERROR("SubType::add_ttcn_single()");
2324 case Value::V_CHOICE
:
2325 if (subtype
!=ST_UNION
) FATAL_ERROR("SubType::add_ttcn_single()");
2329 if (subtype
!=ST_RECORD
) FATAL_ERROR("SubType::add_ttcn_single()");
2333 if (subtype
!=ST_SET
) FATAL_ERROR("SubType::add_ttcn_single()");
2336 case Value::V_FUNCTION
:
2337 if (subtype
!=ST_FUNCTION
) FATAL_ERROR("SubType::add_ttcn_single()");
2340 case Value::V_ALTSTEP
:
2341 if (subtype
!=ST_ALTSTEP
) FATAL_ERROR("SubType::add_ttcn_single()");
2344 case Value::V_TESTCASE
:
2345 if (subtype
!=ST_TESTCASE
) FATAL_ERROR("SubType::add_ttcn_single()");
2348 case Value::V_SEQOF
:
2349 if (subtype
!=ST_RECORDOF
) FATAL_ERROR("SubType::add_ttcn_single()");
2352 case Value::V_SETOF
:
2353 if (subtype
!=ST_SETOF
) FATAL_ERROR("SubType::add_ttcn_single()");
2356 case Value::V_ERROR
:
2364 bool SubType::add_ttcn_range(Value
*min
, bool min_exclusive
,
2365 Value
*max
, bool max_exclusive
, size_t restriction_index
, bool has_other
)
2371 case ST_UNIVERSAL_CHARSTRING
:
2374 my_owner
->error("Range subtyping is not allowed for type `%s'",
2375 my_owner
->get_typename().c_str());
2380 if (min
==NULL
) vmin
=NULL
;
2382 min
->set_my_scope(my_owner
->get_my_scope());
2383 min
->set_fullname(my_owner
->get_fullname()+".<range_restriction_"+Int2string(restriction_index
)+"_lower>");
2384 my_owner
->chk_this_value_ref(min
);
2385 my_owner
->chk_this_value(min
, 0, Type::EXPECTED_CONSTANT
,
2386 INCOMPLETE_NOT_ALLOWED
, OMIT_NOT_ALLOWED
, NO_SUB_CHK
);
2387 vmin
=min
->get_value_refd_last();
2389 if (max
==NULL
) vmax
=NULL
;
2391 max
->set_my_scope(my_owner
->get_my_scope());
2392 max
->set_fullname(my_owner
->get_fullname()+".<range_restriction_"+Int2string(restriction_index
)+"_upper>");
2393 my_owner
->chk_this_value_ref(max
);
2394 my_owner
->chk_this_value(max
, 0, Type::EXPECTED_CONSTANT
,
2395 INCOMPLETE_NOT_ALLOWED
, OMIT_NOT_ALLOWED
, NO_SUB_CHK
);
2396 vmax
=max
->get_value_refd_last();
2399 if ( (vmin
!=NULL
) && (vmax
!=NULL
) && (vmin
->get_valuetype()!=vmax
->get_valuetype()) ) return false;
2403 if (((vmin
!=NULL
) && (vmin
->get_valuetype()!=Value::V_INT
)) ||
2404 ((vmax
!=NULL
) && (vmax
->get_valuetype()!=Value::V_INT
))) return false;
2405 int_limit_t min_limit
= (vmin
!=NULL
) ? int_limit_t(*(vmin
->get_val_Int())) : int_limit_t::minimum
;
2406 if (min_exclusive
) {
2407 if (min_limit
==int_limit_t::minimum
) {
2408 my_owner
->error("invalid lower boundary, -infinity cannot be excluded from an integer subtype range");
2411 if (min_limit
==int_limit_t::maximum
) {
2412 my_owner
->error("!infinity is not a valid lower boundary");
2415 min_limit
= min_limit
.next();
2418 int_limit_t max_limit
= (vmax
!=NULL
) ? int_limit_t(*(vmax
->get_val_Int())) : int_limit_t::maximum
;
2419 if (max_exclusive
) {
2420 if (max_limit
==int_limit_t::maximum
) {
2421 my_owner
->error("invalid upper boundary, infinity cannot be excluded from an integer subtype range");
2424 if (max_limit
==int_limit_t::minimum
) {
2425 my_owner
->error("!-infinity is not a valid upper boundary");
2428 max_limit
= max_limit
.previous();
2431 if (max_limit
<min_limit
) {
2432 my_owner
->error("lower boundary is bigger than upper boundary in integer subtype range");
2435 if (integer_st
==NULL
) integer_st
= new IntegerRangeListConstraint(min_limit
, max_limit
);
2436 else *integer_st
= *integer_st
+ IntegerRangeListConstraint(min_limit
, max_limit
);
2439 if (((vmin
!=NULL
) && (vmin
->get_valuetype()!=Value::V_REAL
)) ||
2440 ((vmax
!=NULL
) && (vmax
->get_valuetype()!=Value::V_REAL
))) return false;
2441 if ((vmin
!=NULL
) && (vmin
->get_val_Real()!=vmin
->get_val_Real())) {
2442 my_owner
->error("lower boundary cannot be not_a_number in float subtype range");
2445 if ((vmax
!=NULL
) && (vmax
->get_val_Real()!=vmax
->get_val_Real())) {
2446 my_owner
->error("upper boundary cannot be not_a_number in float subtype range");
2449 real_limit_t min_limit
= (vmin
!=NULL
) ? real_limit_t(vmin
->get_val_Real()) : real_limit_t::minimum
;
2450 if (min_exclusive
) {
2451 if (min_limit
==real_limit_t::maximum
) {
2452 my_owner
->error("!infinity is not a valid lower boundary");
2455 min_limit
= min_limit
.next();
2457 real_limit_t max_limit
= (vmax
!=NULL
) ? real_limit_t(vmax
->get_val_Real()) : real_limit_t::maximum
;
2458 if (max_exclusive
) {
2459 if (max_limit
==real_limit_t::minimum
) {
2460 my_owner
->error("!-infinity is not a valid upper boundary");
2463 max_limit
= max_limit
.previous();
2465 if (max_limit
<min_limit
) {
2466 my_owner
->error("lower boundary is bigger than upper boundary in float subtype range");
2469 if (float_st
==NULL
) float_st
= new RealRangeListConstraint(min_limit
, max_limit
);
2470 else *float_st
= *float_st
+ RealRangeListConstraint(min_limit
, max_limit
);
2472 case ST_CHARSTRING
: {
2473 if (((vmin
!=NULL
) && (vmin
->get_valuetype()!=Value::V_CSTR
)) ||
2474 ((vmax
!=NULL
) && (vmax
->get_valuetype()!=Value::V_CSTR
))) return false;
2475 if ((vmin
==NULL
)&&(vmax
==NULL
)) {
2476 my_owner
->error("a range subtype of a charstring cannot be (-infinity..infinity)");
2480 my_owner
->error("lower boundary of a charstring subtype range cannot be -infinity");
2484 my_owner
->error("upper boundary of a charstring subtype range cannot be infinity");
2487 if (vmin
->get_val_str().size()!=1) {
2488 min
->error("lower boundary of charstring subtype range must be a single element string");
2491 if (vmax
->get_val_str().size()!=1) {
2492 max
->error("upper boundary of charstring subtype range must be a single element string");
2495 if (!char_limit_t::is_valid_value(*vmin
->get_val_str().c_str())) {
2496 min
->error("lower boundary of charstring subtype range is an invalid char");
2499 if (!char_limit_t::is_valid_value(*vmax
->get_val_str().c_str())) {
2500 max
->error("upper boundary of charstring subtype range is an invalid char");
2503 char_limit_t
min_limit(*vmin
->get_val_str().c_str()), max_limit(*vmax
->get_val_str().c_str());
2504 if (min_exclusive
) {
2505 if (min_limit
==char_limit_t::maximum
) {
2506 min
->error("exclusive lower boundary is not a legal charstring character");
2509 min_limit
= min_limit
.next();
2511 if (max_exclusive
) {
2512 if (max_limit
==char_limit_t::minimum
) {
2513 max
->error("exclusive upper boundary is not a legal charstring character");
2516 max_limit
= max_limit
.previous();
2518 if (max_limit
<min_limit
) {
2519 my_owner
->error("lower boundary is bigger than upper boundary in charstring subtype range");
2522 if (charstring_st
==NULL
) charstring_st
= new CharstringSubtypeTreeElement(CharRangeListConstraint(min_limit
,max_limit
), false);
2524 if (!has_other
) { // union in char context can be done only with range constraints
2525 charstring_st
->set_char_context(true);
2526 charstring_st
= new CharstringSubtypeTreeElement(CharstringSubtypeTreeElement::ET_UNION
,
2528 new CharstringSubtypeTreeElement(CharRangeListConstraint(min_limit
,max_limit
), true));
2529 charstring_st
->set_char_context(false);
2531 // ignore it, error reported elsewhere
2536 case ST_UNIVERSAL_CHARSTRING
: {
2537 if (((vmin
!=NULL
) && (vmin
->get_valuetype()!=Value::V_USTR
)) ||
2538 ((vmax
!=NULL
) && (vmax
->get_valuetype()!=Value::V_USTR
))) return false;
2539 if ((vmin
==NULL
)&&(vmax
==NULL
)) {
2540 my_owner
->error("a range subtype of a universal charstring cannot be (-infinity..infinity)");
2544 my_owner
->error("lower boundary of a universal charstring subtype range cannot be -infinity");
2548 my_owner
->error("upper boundary of a universal charstring subtype range cannot be infinity");
2551 if (vmin
->get_val_ustr().size()!=1) {
2552 min
->error("lower boundary of universal charstring subtype range must be a single element string");
2555 if (vmax
->get_val_ustr().size()!=1) {
2556 max
->error("upper boundary of universal charstring subtype range must be a single element string");
2559 if (!universal_char_limit_t::is_valid_value(*vmin
->get_val_ustr().u_str())) {
2560 min
->error("lower boundary of universal charstring subtype range is an invalid char");
2563 if (!universal_char_limit_t::is_valid_value(*vmax
->get_val_ustr().u_str())) {
2564 max
->error("upper boundary of universal charstring subtype range is an invalid char");
2567 universal_char_limit_t
min_limit(*vmin
->get_val_ustr().u_str()), max_limit(*vmax
->get_val_ustr().u_str());
2568 if (min_exclusive
) {
2569 if (min_limit
==universal_char_limit_t::maximum
) {
2570 min
->error("exclusive lower boundary is not a legal universal charstring character");
2573 min_limit
= min_limit
.next();
2575 if (max_exclusive
) {
2576 if (max_limit
==universal_char_limit_t::minimum
) {
2577 max
->error("exclusive upper boundary is not a legal universal charstring character");
2580 max_limit
= max_limit
.previous();
2582 if (max_limit
<min_limit
) {
2583 my_owner
->error("lower boundary is bigger than upper boundary in universal charstring subtype range");
2587 if (universal_charstring_st
==NULL
) universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(UniversalCharRangeListConstraint(min_limit
,max_limit
), false);
2589 if (!has_other
) { // union in char context can be done only with range constraints
2590 universal_charstring_st
->set_char_context(true);
2591 universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(UniversalCharstringSubtypeTreeElement::ET_UNION
,
2592 universal_charstring_st
,
2593 new UniversalCharstringSubtypeTreeElement(UniversalCharRangeListConstraint(min_limit
,max_limit
), true));
2594 universal_charstring_st
->set_char_context(false);
2596 // ignore it, error reported elsewhere
2602 FATAL_ERROR("SubType::add_ttcn_range()");
2607 bool SubType::set_ttcn_length(const size_limit_t
& min
, const size_limit_t
& max
)
2610 case ST_BITSTRING
: {
2611 if (bitstring_st
==NULL
) bitstring_st
= new BitstringConstraint(min
,max
);
2612 else *bitstring_st
= *bitstring_st
* BitstringConstraint(min
,max
);
2614 case ST_HEXSTRING
: {
2615 if (hexstring_st
==NULL
) hexstring_st
= new HexstringConstraint(min
,max
);
2616 else *hexstring_st
= *hexstring_st
* HexstringConstraint(min
,max
);
2618 case ST_OCTETSTRING
: {
2619 if (octetstring_st
==NULL
) octetstring_st
= new OctetstringConstraint(min
,max
);
2620 else *octetstring_st
= *octetstring_st
* OctetstringConstraint(min
,max
);
2622 case ST_CHARSTRING
: {
2623 CharstringSubtypeTreeElement
* cst_elem
= new CharstringSubtypeTreeElement(SizeRangeListConstraint(min
,max
));
2624 if (charstring_st
==NULL
) {
2625 charstring_st
= cst_elem
;
2627 charstring_st
= new CharstringSubtypeTreeElement(CharstringSubtypeTreeElement::ET_INTERSECTION
, charstring_st
, cst_elem
);
2630 case ST_UNIVERSAL_CHARSTRING
: {
2631 UniversalCharstringSubtypeTreeElement
* ucst_elem
= new UniversalCharstringSubtypeTreeElement(SizeRangeListConstraint(min
,max
));
2632 if (universal_charstring_st
==NULL
) {
2633 universal_charstring_st
= ucst_elem
;
2635 universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(UniversalCharstringSubtypeTreeElement::ET_INTERSECTION
, universal_charstring_st
, ucst_elem
);
2640 if (recof_st
==NULL
) recof_st
= new RecofConstraint(min
,max
);
2641 else *recof_st
= *recof_st
* RecofConstraint(min
,max
);
2644 my_owner
->error("Length subtyping is not allowed for type `%s'",
2645 my_owner
->get_typename().c_str());
2648 if (length_restriction
==NULL
) length_restriction
= new SizeRangeListConstraint(min
,max
);
2649 else *length_restriction
= *length_restriction
* SizeRangeListConstraint(min
,max
);
2653 void SubType::chk_boundary_valid(Value
* boundary
, Int max_value
, const char* boundary_name
)
2655 const int_val_t
*int_val
= boundary
->get_val_Int();
2656 if (*int_val
> int_val_t(max_value
)) {
2657 boundary
->error("The %s should be less than `%s' instead of `%s'",
2659 int_val_t(max_value
).t_str().c_str(),
2660 int_val
->t_str().c_str());
2661 boundary
->set_valuetype(Value::V_ERROR
);
2665 bool SubType::add_ttcn_length(Ttcn::LengthRestriction
*lr
, size_t restriction_index
)
2668 lr
->append_stringRepr(s
);
2669 Value
*lower
=NULL
,*upper
=NULL
;
2670 lr
->set_my_scope(my_owner
->get_my_scope());
2671 lr
->set_fullname(my_owner
->get_fullname()+".<length_restriction_"+Int2string(restriction_index
)+">");
2672 lr
->chk(Type::EXPECTED_CONSTANT
);
2673 lower
= lr
->get_is_range() ? lr
->get_lower_value() : lr
->get_single_value();
2674 if (!lower
->get_my_scope()) FATAL_ERROR("no scope");
2675 if (lower
->get_valuetype() != Value::V_INT
) return false;
2676 if (lr
->get_is_range()) {
2677 upper
= lr
->get_upper_value();
2678 if (upper
) {//HAS_UPPER
2679 if (upper
->get_valuetype()!=Value::V_INT
) return false;
2680 if (!upper
->get_my_scope()) upper
->set_my_scope(my_owner
->get_my_scope());
2681 chk_boundary_valid(upper
, INT_MAX
, "upper boundary");
2682 if (upper
->get_valuetype()!=Value::V_INT
) return false;
2683 return set_ttcn_length(size_limit_t((size_t)lower
->get_val_Int()->get_val()),
2684 size_limit_t((size_t)upper
->get_val_Int()->get_val()));
2686 chk_boundary_valid(lower
, INT_MAX
, "lower boundary");
2687 if (lower
->get_valuetype()!=Value::V_INT
) return false;
2688 return set_ttcn_length(size_limit_t((size_t)lower
->get_val_Int()->get_val()),
2689 size_limit_t(size_limit_t::INFINITE_SIZE
));
2693 chk_boundary_valid(lower
, INT_MAX
, "length restriction value");
2694 if (lower
->get_valuetype()!=Value::V_INT
) return false;
2695 return set_ttcn_length(size_limit_t((size_t)lower
->get_val_Int()->get_val()),
2696 size_limit_t((size_t)lower
->get_val_Int()->get_val()));
2700 bool SubType::add_ttcn_pattern(Ttcn::PatternString
* pattern
, size_t restriction_index
)
2702 pattern
->set_my_scope(my_owner
->get_my_scope());
2703 pattern
->set_fullname(my_owner
->get_fullname()+".<pattern_restriction_"+Int2string(restriction_index
) + ">");
2705 case ST_CHARSTRING
: {
2706 Error_Context
cntxt(my_owner
, "In character string pattern");
2707 pattern
->chk_refs(Type::EXPECTED_CONSTANT
);
2708 pattern
->join_strings();
2709 if (!pattern
->has_refs()) { // if chk_refs didn't remove all references then ignore
2710 pattern
->chk_pattern();
2711 CharstringSubtypeTreeElement
* cst_elem
= new CharstringSubtypeTreeElement(StringPatternConstraint(pattern
));
2712 if (charstring_st
==NULL
) {
2713 charstring_st
= cst_elem
;
2715 charstring_st
= new CharstringSubtypeTreeElement(CharstringSubtypeTreeElement::ET_INTERSECTION
, charstring_st
, cst_elem
);
2719 case ST_UNIVERSAL_CHARSTRING
: {
2720 Error_Context
cntxt(my_owner
, "In universal string pattern");
2721 pattern
->set_pattern_type(Ttcn::PatternString::USTR_PATTERN
);
2722 pattern
->chk_refs(Type::EXPECTED_CONSTANT
);
2723 pattern
->join_strings();
2724 if (!pattern
->has_refs()) { // if chk_refs didn't remove all references then ignore
2725 pattern
->chk_pattern();
2726 UniversalCharstringSubtypeTreeElement
* ucst_elem
= new UniversalCharstringSubtypeTreeElement(StringPatternConstraint(pattern
));
2727 if (universal_charstring_st
==NULL
) {
2728 universal_charstring_st
= ucst_elem
;
2730 universal_charstring_st
= new UniversalCharstringSubtypeTreeElement(UniversalCharstringSubtypeTreeElement::ET_INTERSECTION
, universal_charstring_st
, ucst_elem
);
2735 my_owner
->error("Pattern subtyping of type `%s' is not allowed", my_owner
->get_typename().c_str());
2741 void SubType::print_full_warning() const
2743 my_owner
->warning("The subtype of type `%s' is a full set, "
2744 "it does not constrain the root type.", my_owner
->get_typename().c_str());
2749 if ((checked
!=STC_NO
) || (subtype
==ST_ERROR
)) FATAL_ERROR("SubType::chk()");
2750 checked
= STC_CHECKING
;
2752 // check for circular subtype reference
2753 if (parent_subtype
&& !add_parent_subtype(parent_subtype
)) {
2759 if (parsed
) { // has TTCN-3 subtype constraint
2760 size_t added_count
= 0;
2761 bool has_single
= false, has_range
= false,
2762 has_length
= false, has_pattern
= false;
2763 for (size_t i
= 0; i
< parsed
->size(); i
++) {
2765 SubTypeParse
*parse
= (*parsed
)[i
];
2766 switch (parse
->get_selection()) {
2767 case SubTypeParse::STP_SINGLE
:
2769 added
= add_ttcn_single(parse
->Single(),i
);
2771 case SubTypeParse::STP_RANGE
:
2773 added
= add_ttcn_range(parse
->Min(), parse
->MinExclusive(),
2774 parse
->Max(), parse
->MaxExclusive(), i
,
2775 has_single
|| has_length
|| has_pattern
);
2777 case SubTypeParse::STP_LENGTH
:
2779 added
= add_ttcn_length(parse
->Length(),i
);
2781 case SubTypeParse::STP_PATTERN
:
2783 added
= add_ttcn_pattern(parse
->Pattern(),i
);
2786 FATAL_ERROR("SubType::chk(): invalid SubTypeParse selection");
2788 if (added
) added_count
++;
2792 case ST_UNIVERSAL_CHARSTRING
:
2793 if (has_single
&& has_range
) {
2795 "Mixing of value list and range subtyping is not allowed for type `%s'",
2796 my_owner
->get_typename().c_str());
2803 // in other cases mixing of different restrictions (which are legal for
2804 // this type) is properly regulated by the TTCN-3 BNF itself
2807 if (added_count
<parsed
->size()) {
2812 if (subtype
==ST_ERROR
) { checked
= STC_YES
; return; }
2814 if (parent_subtype
) {
2815 if (is_subset(parent_subtype
->get_root())==TFALSE
) {
2816 my_owner
->error("The subtype restriction is not a subset of the restriction on the parent type. "
2817 "Subtype %s is not subset of subtype %s", to_string().c_str(), parent_subtype
->get_root()->to_string().c_str());
2822 intersection(parent_subtype
->get_root());
2824 } else if (asn_constraints
) { // has ASN.1 subtype constraint
2825 SubtypeConstraint
* asn_parent_subtype
= NULL
;
2826 if (parent_subtype
) {
2827 // the type constraint of the ASN.1 type is already in the parent_subtype,
2828 // don't add it multiple times
2829 asn_parent_subtype
= parent_subtype
->get_root();
2831 asn_parent_subtype
= get_asn_type_constraint(my_owner
);
2833 asn_constraints
->chk(asn_parent_subtype
);
2834 root
= asn_constraints
->get_subtype();
2835 extendable
= asn_constraints
->is_extendable();
2836 extension
= asn_constraints
->get_extension();
2837 // the TTCN-3 subtype will be the union of the root and extension parts
2838 // the ETSI ES 201 873-7 V4.1.2 (2009-07) document says to "ignore any extension markers"
2839 // but titan now works this way :)
2840 if (root
) copy(root
);
2841 if (extension
) union_(extension
);
2842 } else { // no constraints on this type -> this is an alias type, just copy the subtype from the other
2843 if (parent_subtype
) {
2844 root
= parent_subtype
->root
;
2845 extendable
= parent_subtype
->extendable
;
2846 extension
= parent_subtype
->extension
;
2847 copy(parent_subtype
);
2849 SubtypeConstraint
* asn_parent_subtype
= get_asn_type_constraint(my_owner
);
2850 if (asn_parent_subtype
) copy(asn_parent_subtype
);
2854 // check if subtype is valid: it must not be an empty set (is_empty==TTRUE)
2855 // issue warning if subtype is given but is full set (is_full==TTRUE)
2856 // ignore cases of TUNKNOWN when compiler can't figure out if the aggregate
2857 // set is empty or full
2860 if (integer_st
!=NULL
) {
2861 if (integer_st
->is_empty()==TTRUE
) goto empty_error
;
2862 if (integer_st
->is_full()==TTRUE
) {
2863 print_full_warning();
2870 if (float_st
!=NULL
) {
2871 if (float_st
->is_empty()==TTRUE
) goto empty_error
;
2872 if (float_st
->is_full()==TTRUE
) {
2873 print_full_warning();
2880 if (boolean_st
!=NULL
) {
2881 if (boolean_st
->is_empty()==TTRUE
) goto empty_error
;
2882 if (boolean_st
->is_full()==TTRUE
) {
2883 print_full_warning();
2889 case ST_VERDICTTYPE
:
2890 if (verdict_st
!=NULL
) {
2891 if (verdict_st
->is_empty()==TTRUE
) goto empty_error
;
2892 if (verdict_st
->is_full()==TTRUE
) {
2893 print_full_warning();
2900 if (bitstring_st
!=NULL
) {
2901 if (bitstring_st
->is_empty()==TTRUE
) goto empty_error
;
2902 if (bitstring_st
->is_full()==TTRUE
) {
2903 print_full_warning();
2904 delete bitstring_st
;
2905 bitstring_st
= NULL
;
2910 if (hexstring_st
!=NULL
) {
2911 if (hexstring_st
->is_empty()==TTRUE
) goto empty_error
;
2912 if (hexstring_st
->is_full()==TTRUE
) {
2913 print_full_warning();
2914 delete hexstring_st
;
2915 hexstring_st
= NULL
;
2919 case ST_OCTETSTRING
:
2920 if (octetstring_st
!=NULL
) {
2921 if (octetstring_st
->is_empty()==TTRUE
) goto empty_error
;
2922 if (octetstring_st
->is_full()==TTRUE
) {
2923 print_full_warning();
2924 delete octetstring_st
;
2925 octetstring_st
= NULL
;
2930 if (charstring_st
!=NULL
) {
2931 if (charstring_st
->is_empty()==TTRUE
) goto empty_error
;
2932 if (charstring_st
->is_full()==TTRUE
) {
2933 print_full_warning();
2934 delete charstring_st
;
2935 charstring_st
= NULL
;
2939 case ST_UNIVERSAL_CHARSTRING
:
2940 if (universal_charstring_st
!=NULL
) {
2941 if (universal_charstring_st
->is_empty()==TTRUE
) goto empty_error
;
2942 if (universal_charstring_st
->is_full()==TTRUE
) {
2943 print_full_warning();
2944 delete universal_charstring_st
;
2945 universal_charstring_st
= NULL
;
2957 if (value_st
!=NULL
) {
2958 if (value_st
->is_empty()==TTRUE
) goto empty_error
;
2959 if (value_st
->is_full()==TTRUE
) {
2960 print_full_warning();
2968 if (recof_st
!=NULL
) {
2969 if (recof_st
->is_empty()==TTRUE
) goto empty_error
;
2970 if (recof_st
->is_full()==TTRUE
) {
2971 print_full_warning();
2978 FATAL_ERROR("SubType::chk()");
2980 if ((length_restriction
!=NULL
) && (length_restriction
->is_full()==TTRUE
)) {
2981 delete length_restriction
;
2982 length_restriction
= NULL
;
2988 my_owner
->error("The subtype is an empty set");
2994 void SubType::dump(unsigned level
) const
2996 string str
= to_string();
2997 if (str
.size()>0) DEBUG(level
, "restriction(s): %s", str
.c_str());
3000 Int
SubType::get_length_restriction() const
3002 if (checked
!=STC_YES
) FATAL_ERROR("SubType::get_length_restriction()");
3003 if (parsed
==NULL
) return -1; // only own length restriction counts
3004 if (length_restriction
==NULL
) return -1;
3005 if (length_restriction
->is_empty()) return -1;
3006 return ( (length_restriction
->get_minimal()==length_restriction
->get_maximal()) ?
3007 (Int
)(length_restriction
->get_minimal().get_size()) :
3011 bool SubType::zero_length_allowed() const
3013 if (checked
!=STC_YES
) FATAL_ERROR("SubType::zero_length_allowed()");
3014 if (parsed
==NULL
) return true; // only own length restriction counts
3015 if (length_restriction
==NULL
) return true;
3016 return length_restriction
->is_element(size_limit_t(0));
3019 string
SubType::to_string() const
3022 string
ret_val(root
->to_string());
3023 if (extendable
) ret_val
+= ", ...";
3026 ret_val
+= extension
->to_string();
3030 return SubtypeConstraint::to_string();
3033 ////////////////////////////////////////////////////////////////////////////////
3035 void SubType::generate_code(output_struct
&)
3037 if (checked
!=STC_YES
) FATAL_ERROR("SubType::generate_code()");
3040 } // namespace Common