Type.cc 263 KB
Newer Older
Elemer Lelik's avatar
Elemer Lelik committed
1
/******************************************************************************
Lenard Nagy's avatar
Lenard Nagy committed
2
 * Copyright (c) 2000-2017 Ericsson Telecom AB
Elemer Lelik's avatar
Elemer Lelik committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Baji, Laszlo
 *   Balasko, Jeno
 *   Baranyi, Botond
 *   Beres, Szabolcs
 *   Bibo, Zoltan
 *   Cserveni, Akos
 *   Delic, Adam
 *   Dimitrov, Peter
 *   Feher, Csaba
 *   Forstner, Matyas
 *   Gecse, Roland
 *   Kovacs, Ferenc
 *   Nagy, Lenard
 *   Raduly, Csaba
 *   Szabados, Kristof
 *   Szabo, Janos Zoltan – initial implementation
25
 *   Szabo, Bence Janos
Elemer Lelik's avatar
Elemer Lelik committed
26
27
28
29
30
 *   Szalai, Gabor
 *   Tatarka, Gabor
 *   Zalanyi, Balazs Andor
 *
 ******************************************************************************/
Elemer Lelik's avatar
Elemer Lelik committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "../common/dbgnew.hh"
#include "Type.hh"
#include <ctype.h>
#include "Typestuff.hh" // FIXME CTs
#include "CompType.hh"
#include "TypeCompat.hh"
#include "CompField.hh"
#include "SigParam.hh"
#include "EnumItem.hh"

#include "Valuestuff.hh"
#include "ttcn3/ArrayDimensions.hh"
#include "asn1/Tag.hh"
#include "asn1/Block.hh"
#include "asn1/Ref.hh"
#include "Constraint.hh"
#include "main.hh"
#include "../common/pattern.hh"
#include "ttcn3/Attributes.hh"
#include "XerAttributes.hh"
#include "ttcn3/Ttcnstuff.hh"
#include "ttcn3/TtcnTemplate.hh"
#include "ttcn3/Templatestuff.hh"

#include "../common/static_check.h"
#include "PredefFunc.hh"

// implemented in coding_attrib_p.y
extern Ttcn::ExtensionAttributes * parse_extattributes(
  Ttcn::WithAttribPath *w_attrib_path);

namespace Common {
63
  
64
  map<Type*, void> Type::RecursionTracker::types;
Elemer Lelik's avatar
Elemer Lelik committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

  using Ttcn::MultiWithAttrib;
  using Ttcn::SingleWithAttrib;
  using Ttcn::WithAttribPath;

  const char* Type::type_as_string[] = {
  "undefined",                                   // T_UNDEF
  "erroneous",                                   // T_ERROR
  "null(ASN)",                                   // T_NULL
  "boolean",                                     // T_BOOL
  "integer",                                     // T_INT
  "integer(ASN.1)",                              // T_INT_A
  "real/float",                                  // T_REAL
  "enumerated(ASN.1)",                           // T_ENUM_A
  "enumerated(TTCN-3)",                          // T_ENUM_T
  "bitstring",                                   // T_BSTR
  "bitstring(ASN)",                              // T_BSTR_A
  "hexstring(TTCN-3)",                           // T_HSTR
  "octetstring",                                 // T_OSTR
  "charstring (TTCN-3)",                         // T_CSTR
  "universal charstring(TTCN-3)",                // T_USTR
  "UTF8String(ASN.1)",                           // T_UTF8STRING
  "NumericString(ASN.1)",                        // T_NUMERICSTRING
  "PrintableString(ASN.1)",                      // T_PRINTABLESTRING
  "TeletexString(ASN.1)",                        //T_TELETEXSTRING
  "VideotexString(ASN.1)",                       // T_VIDEOTEXSTRING
  "IA5String(ASN.1)",                            // T_IA5STRING
  "GraphicString(ASN.1)",                        // T_GRAPHICSTRING,
  "VisibleString(ASN.1)",                        // T_VISIBLESTRING
  "GeneralString (ASN.1)",                       // T_GENERALSTRING
  "UniversalString (ASN.1)",                     // T_UNIVERSALSTRING
  "BMPString (ASN.1)",                           // T_BMPSTRING
  "UnrestrictedCharacterString(ASN.1)",          // T_UNRESTRICTEDSTRING
  "UTCTime(ASN.1)",                              // T_UTCTIME
  "GeneralizedTime(ASN.1)",                      // T_GENERALIZEDTIME
  "Object descriptor, a kind of string (ASN.1)", // T_OBJECTDESCRIPTOR
  "object identifier",                           // T_OID
  "relative OID(ASN.1)",                         // T_ROID
  "choice(ASN-1)",                               // T_CHOICE_A
  "union(TTCN-3)",                               // T_CHOICE_T
  "sequence (record) of",                        // T_SEQOF
  "set of",                                      // T_SETOF
  "sequence(ASN-1)",                             // T_SEQ_A
  "record(TTCN-3)",                              // T_SEQ_T
  "set(ASN.1)",                                  // T_SET_A
  "set(TTCN-3)",                                 // T_SET_T
  "ObjectClassFieldType(ASN.1)",                 // T_OCFT
  "open type(ASN.1)",                            // T_OPENTYPE
  "ANY(deprecated ASN.1)",                       // T_ANY
  "external(ASN.1)",                             // T_EXTERNAL
  "embedded PDV(ASN.1)",                         // T_EMBEDDED_PDV
  "referenced",                                  // T_REFD
  "special referenced(by pointer, not by name)", // T_REFDSPEC
  "selection type(ASN.1)",                       // T_SELTYPE
  "verdict type(TTCN-3)",                        // T_VERDICT
  "port type(TTCN-3)",                           // T_PORT
  "component type(TTCN-3)",                      // T_COMPONENT
  "address type(TTCN-3)",                        // T_ADDRESS
  "default type (TTCN-3)",                       // T_DEFAULT
  "array(TTCN-3)",                               // T_ARRAY
  "signature(TTCN-3)",                           // T_SIGNATURE
  "function reference(TTCN-3)",                  // T_FUNCTION
  "altstep reference(TTCN-3)",                   // T_ALTSTEP
  "testcase reference(TTCN-3)",                  // T_TESTCASE
  "anytype(TTCN-3)",                             // T_ANYTYPE
  };

  // =================================
  // ===== Type
  // =================================
  const char* Type::asString() const {
    if (this->get_typetype() < Type::T_LAST && Type::T_UNDEF < this->get_typetype()) {
      return type_as_string[this->get_typetype()];
    }
    else {
      return type_as_string[Type::T_UNDEF];
    }
  }

  const char* Type::asString(Type::typetype_t type) {
    if (type < Type::T_LAST && Type::T_UNDEF < type) {
      return type_as_string[type];
    }
    else {
      return type_as_string[Type::T_UNDEF];
    }
  }

  // Used by dump() for user-readable messages, by Def_ExtFunction::generate_*
  // The text returned must match the case label without the "CT_" !
  const char *Type::get_encoding_name(MessageEncodingType_t encoding_type)
  {
    ENSURE_EQUAL(Type::T_UNDEF, 0);
    ENSURE_EQUAL(Type::OT_UNKNOWN, 0);
    switch (encoding_type) {
    case CT_BER:
      return "BER";
    case CT_PER:
      return "PER";
    case CT_XER:
      return "XER";
    case CT_RAW:
      return "RAW";
    case CT_TEXT:
      return "TEXT";
    case CT_JSON:
      return "JSON";
172
173
    case CT_OER:
      return "OER";
Elemer Lelik's avatar
Elemer Lelik committed
174
175
    case CT_CUSTOM:
      return "custom";
Elemer Lelik's avatar
Elemer Lelik committed
176
177
178
179
180
    default:
      return "<unknown encoding>";
    }
  }

Elemer Lelik's avatar
Elemer Lelik committed
181
  Type *Type::get_stream_type(MessageEncodingType_t encoding_type, int stream_variant)
Elemer Lelik's avatar
Elemer Lelik committed
182
  {
183
184
185
    if (stream_variant == 0) {
      return get_pooltype(T_BSTR);
    }
Elemer Lelik's avatar
Elemer Lelik committed
186
187
188
189
190
191
    switch (encoding_type) {
    case CT_BER:
    case CT_PER:
    case CT_RAW:
    case CT_XER: // UTF-8 doesn't fit into charstring and universal is wasteful
    case CT_JSON:
192
    case CT_OER:
Elemer Lelik's avatar
Elemer Lelik committed
193
194
      return get_pooltype(T_OSTR);
    case CT_TEXT:
195
      if(stream_variant==1){
Elemer Lelik's avatar
Elemer Lelik committed
196
197
198
199
        return get_pooltype(T_CSTR);
      } else {
        return get_pooltype(T_OSTR);
      }
Elemer Lelik's avatar
Elemer Lelik committed
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
    default:
      FATAL_ERROR("Type::get_stream_type()");
      return 0;
    }
  }

  map<Type::typetype_t, Type> *Type::pooltypes = 0;

  Type* Type::get_pooltype(typetype_t p_typetype)
  {
    p_typetype=get_typetype_ttcn3(p_typetype);
    switch(p_typetype) {
    case T_NULL:
    case T_BOOL:
    case T_INT:
    case T_REAL:
    case T_BSTR:
    case T_HSTR:
    case T_OSTR:
    case T_CSTR:
    case T_USTR:
    case T_OID:
    case T_ERROR:
    case T_VERDICT:
    case T_COMPONENT:
    case T_DEFAULT:
      break; // we have a pool type
    default:
      return 0; // no pool type for you!
    } // switch
    if (!pooltypes) pooltypes = new map<typetype_t, Type>; // lazy init
    else if (pooltypes->has_key(p_typetype)) return (*pooltypes)[p_typetype];
    Type *t;
    if (p_typetype == T_COMPONENT)
      t = new Type(T_COMPONENT, new ComponentTypeBody());
    else t = new Type(p_typetype);
    t->ownertype = OT_POOL;
    pooltypes->add(p_typetype, t);
    return t;
  }

  void Type::destroy_pooltypes()
  {
    if(pooltypes) {
      for(size_t i=0; i<pooltypes->size(); i++)
        delete pooltypes->get_nth_elem(i);
      pooltypes->clear();
      delete pooltypes;
      pooltypes=0;
    }
  }

  Tag *Type::get_default_tag()
  {
    typetype_t t_typetype;
    switch (typetype) {
    case T_INT:
      t_typetype = T_INT_A;
      break;
    case T_BSTR:
      t_typetype = T_BSTR_A;
      break;
    case T_ENUM_T:
      t_typetype = T_ENUM_A;
      break;
    case T_SEQ_T:
    case T_SEQOF:
      t_typetype = T_SEQ_A;
      break;
    case T_SET_T:
    case T_SETOF:
      t_typetype = T_SET_A;
      break;
    case T_OPENTYPE:
      t_typetype = T_ANY;
      break;
    case T_REFD:
    case T_REFDSPEC:
    case T_SELTYPE:
    case T_OCFT:
      return get_type_refd()->get_tag();
    default:
      t_typetype = typetype;
      break;
    }
    if (!default_tags) default_tags = new map<typetype_t, Tag>;
    else if (default_tags->has_key(t_typetype))
      return (*default_tags)[t_typetype];
    Tag *tag;
    switch (t_typetype) {
    case T_ANY:
      tag = new Tag(Tag::TAG_EXPLICIT, Tag::TAG_ALL, (Int)0);
      break;
    case T_ERROR:
      tag = new Tag(Tag::TAG_EXPLICIT, Tag::TAG_ERROR, (Int)0);
      break;
    default: {
      int tagnumber = get_default_tagnumber(t_typetype);
      if (tagnumber < 0) FATAL_ERROR ("Type::get_default_tag():type `%s' "
        "does not have default tag", get_typename().c_str());
      tag = new Tag(Tag::TAG_EXPLICIT, Tag::TAG_UNIVERSAL, Int(tagnumber));
      break; }
    }
    default_tags->add(t_typetype, tag);
    return tag;
  }

  int Type::get_default_tagnumber(typetype_t p_tt)
  {
    switch (p_tt) {
    // note: tag number 0 is reserved for internal use
    case T_BOOL:
      return 1;
    case T_INT_A:
      return 2;
    case T_BSTR_A:
      return 3;
    case T_OSTR:
      return 4;
    case T_NULL:
      return 5;
    case T_OID:
      return 6;
    case T_OBJECTDESCRIPTOR:
      return 7;
    case T_EXTERNAL:
      return 8;
    case T_REAL:
      return 9;
    case T_ENUM_A:
      return 10;
    case T_EMBEDDED_PDV:
      return 11;
    case T_UTF8STRING:
      return 12;
    case T_ROID:
      return 13;
    // note: tag numbers 14 and 15 are reserved for future use
    case T_SEQ_A:
      return 16;
    case T_SET_A:
      return 17;
    case T_NUMERICSTRING:
      return 18;
    case T_PRINTABLESTRING:
      return 19;
    case T_TELETEXSTRING:
      return 20;
    case T_VIDEOTEXSTRING:
      return 21;
    case T_IA5STRING:
      return 22;
    case T_UTCTIME:
      return 23;
    case T_GENERALIZEDTIME:
      return 24;
    case T_GRAPHICSTRING:
      return 25;
    case T_VISIBLESTRING:
      return 26;
    case T_GENERALSTRING:
      return 27;
    case T_UNIVERSALSTRING:
      return 28;
    case T_UNRESTRICTEDSTRING:
      return 29;
    case T_BMPSTRING:
      return 30;
    default:
      return -1;
    }
  }

  map<Type::typetype_t, Tag> *Type::default_tags = 0;

  void Type::destroy_default_tags()
  {
    if (default_tags) {
      size_t nof_tags = default_tags->size();
      for (size_t i = 0; i < nof_tags; i++)
        delete default_tags->get_nth_elem(i);
      default_tags->clear();
      delete default_tags;
      default_tags = 0;
    }
  }

  Type::Type(const Type& p)
    : Governor(p), typetype(p.typetype)
  {
    init();
    if (p.w_attrib_path != NULL) FATAL_ERROR("Type::Type()");
    tags=p.tags?p.tags->clone():0;
    if(p.constraints) {
      constraints=p.constraints->clone();
      constraints->set_my_type(this);
    }
    else constraints=0;
    if(p.parsed_restr!=NULL) {
      parsed_restr=new vector<SubTypeParse>;
      for(size_t i=0;i<p.parsed_restr->size();i++) {
        SubTypeParse *stp = 0;
        switch((*p.parsed_restr)[i]->get_selection()) {
        case SubTypeParse::STP_SINGLE:
          stp=new SubTypeParse((*p.parsed_restr)[i]->Single());
          break;
        case SubTypeParse::STP_RANGE:
          stp=new SubTypeParse((*p.parsed_restr)[i]->Min(),
            (*p.parsed_restr)[i]->MinExclusive(),
            (*p.parsed_restr)[i]->Max(),
            (*p.parsed_restr)[i]->MaxExclusive());
          break;
        case SubTypeParse::STP_LENGTH:
          FATAL_ERROR("Type::Type(Type&): STP_LENGTH");
          break;
        default: FATAL_ERROR("Type::Type()");
        }
        parsed_restr->add(stp);
      }
    }
    else parsed_restr=0;
421
422
423
    if (coding_table.size() != 0 || coders_to_generate.size() != 0) {
      FATAL_ERROR("Type::Type()");
    }
Elemer Lelik's avatar
Elemer Lelik committed
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
    switch(typetype) {
    case T_ERROR:
    case T_NULL:
    case T_BOOL:
    case T_INT:
    case T_REAL:
    case T_BSTR:
    case T_HSTR:
    case T_OSTR:
    case T_CSTR:
    case T_USTR:
    case T_UTF8STRING:
    case T_NUMERICSTRING:
    case T_PRINTABLESTRING:
    case T_TELETEXSTRING:
    case T_VIDEOTEXSTRING:
    case T_IA5STRING:
    case T_GRAPHICSTRING:
    case T_VISIBLESTRING:
    case T_GENERALSTRING:
    case T_UNIVERSALSTRING:
    case T_BMPSTRING:
    case T_UTCTIME:
    case T_GENERALIZEDTIME:
    case T_OBJECTDESCRIPTOR:
    case T_OID:
    case T_ROID:
    case T_ANY:
    case T_EXTERNAL:
    case T_EMBEDDED_PDV:
    case T_UNRESTRICTEDSTRING:
    case T_VERDICT:
    case T_DEFAULT:
      break;
    case T_INT_A:
    case T_BSTR_A:
      u.namednums.block=p.u.namednums.block?p.u.namednums.block->clone():0;
      u.namednums.nvs=p.u.namednums.nvs?p.u.namednums.nvs->clone():0;
      break;
    case T_ENUM_A:
      u.enums.block=p.u.enums.block?p.u.enums.block->clone():0;
      u.enums.eis1=p.u.enums.eis1?p.u.enums.eis1->clone():0;
      u.enums.ellipsis=p.u.enums.ellipsis;
      u.enums.excSpec=p.u.enums.excSpec?p.u.enums.excSpec->clone():0;
      u.enums.eis2=p.u.enums.eis2?p.u.enums.eis2->clone():0;
      // no break
    case T_ENUM_T:
      u.enums.eis=p.u.enums.eis->clone();
      u.enums.eis_by_name=0;
      break;
    case T_CHOICE_T:
    case T_SEQ_T:
    case T_SET_T:
    case T_ANYTYPE:
      u.secho.cfm=p.u.secho.cfm->clone();
      u.secho.field_by_name = 0;
      u.secho.component_internal = false;
      u.secho.has_single_charenc = false;
      break;
    case T_SEQ_A:
    case T_SET_A:
      u.secho.tr_compsof_ready=p.u.secho.tr_compsof_ready;
      // no break
    case T_CHOICE_A:
      u.secho.cfm = 0;
      u.secho.block=p.u.secho.block?p.u.secho.block->clone():0;
      u.secho.ctss=p.u.secho.ctss?p.u.secho.ctss->clone():0;
      u.secho.field_by_name = 0;
      u.secho.component_internal = false;
      u.secho.has_single_charenc = false;
      break;
    case T_SEQOF:
    case T_SETOF:
      u.seof.ofType=p.u.seof.ofType->clone();
      u.seof.component_internal = false;
      break;
    case T_REFD:
      u.ref.ref=p.u.ref.ref->clone();
      u.ref.type_refd=0;
      u.ref.component_internal = false;
      break;
    case T_OCFT:
      u.ref.oc_defn=p.u.ref.oc_defn;
      u.ref.oc_fieldname=p.u.ref.oc_fieldname;
      // no break
    case T_REFDSPEC:
      u.ref.type_refd=p.u.ref.type_refd;
      u.ref.component_internal = false;
      break;
    case T_SELTYPE:
      u.seltype.id=p.u.seltype.id->clone();
      u.seltype.type=p.u.seltype.type->clone();
      u.seltype.type_refd=0;
      break;
    case T_OPENTYPE:
      u.secho.cfm=new CompFieldMap();
      u.secho.cfm->set_my_type(this);
      u.secho.oc_defn=p.u.secho.oc_defn;
      u.secho.oc_fieldname=p.u.secho.oc_fieldname;
      u.secho.my_tableconstraint=0;
      u.secho.field_by_name = 0;
      u.secho.component_internal = false;
      u.secho.has_single_charenc = false;
      break;
    case T_ARRAY:
      u.array.element_type=p.u.array.element_type->clone();
      u.array.dimension = p.u.array.dimension->clone();
      u.array.in_typedef = p.u.array.in_typedef;
      u.array.component_internal = false;
      break;
    case T_PORT:
      u.port = p.u.port->clone();
      break;
    case T_COMPONENT:
      u.component = p.u.component->clone();
      break;
    case T_ADDRESS:
      u.address = 0;
      break;
    case T_SIGNATURE:
      u.signature.parameters = p.u.signature.parameters ?
        p.u.signature.parameters->clone() : 0;
      u.signature.return_type = p.u.signature.return_type ?
        p.u.signature.return_type->clone() : 0;
      u.signature.no_block = p.u.signature.no_block;
      u.signature.exceptions = p.u.signature.exceptions ?
        p.u.signature.exceptions->clone() : 0;
      u.signature.component_internal = false;
      break;
    case T_FUNCTION:
    case T_ALTSTEP:
      u.fatref.fp_list = p.u.fatref.fp_list->clone();
      u.fatref.runs_on.ref = p.u.fatref.runs_on.ref ?
        p.u.fatref.runs_on.ref->clone() : 0;
      u.fatref.runs_on.self = p.u.fatref.runs_on.self;
      u.fatref.runs_on.type = 0;
      u.fatref.return_type = p.u.fatref.return_type ?
        p.u.fatref.return_type->clone() : 0;
      u.fatref.is_startable = false;
      u.fatref.returns_template = p.u.fatref.returns_template;
      u.fatref.template_restriction = p.u.fatref.template_restriction;
      break;
    case T_TESTCASE:
      u.fatref.fp_list = p.u.fatref.fp_list->clone();
      u.fatref.runs_on.ref = p.u.fatref.runs_on.ref ?
        p.u.fatref.runs_on.ref->clone() : 0;
      u.fatref.runs_on.self = false;
      u.fatref.runs_on.type = 0;
      u.fatref.system.ref = p.u.fatref.system.ref ?
          p.u.fatref.system.ref->clone() : 0;
      u.fatref.system.type = 0;
      u.fatref.is_startable = false;
      u.fatref.returns_template = false;
      u.fatref.template_restriction = TR_NONE;
      break;
    default:
      FATAL_ERROR("Type::Type()");
    } // switch
  }

  void Type::init()
  {
    tags_checked = false;
    tbl_cons_checked = false;
    text_checked = false;
    json_checked = false;
    raw_parsed  = false;
    raw_checked = false;
    xer_checked = false;
593
    variants_checked = false;
Elemer Lelik's avatar
Elemer Lelik committed
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
    raw_length_calculated = false;
    has_opentypes = false;
    opentype_outermost = false;
    code_generated = false;
    embed_values_possible = false;
    use_nil_possible = false;
    use_order_possible = false;
    raw_length = -1;
    parent_type = 0;
    tags = 0;
    constraints = 0;
    w_attrib_path = 0;
    encode_attrib_path = 0;
    rawattrib = 0;
    textattrib = 0;
    xerattrib = 0;
    berattrib = 0;
    jsonattrib = 0;
612
    oerattrib = 0;
Elemer Lelik's avatar
Elemer Lelik committed
613
614
615
616
617
    sub_type = 0;
    parsed_restr = 0;
    ownertype = OT_UNKNOWN;
    owner = 0;
    chk_finished = false;
Elemer Lelik's avatar
Elemer Lelik committed
618
    pard_type_instance = false;
619
    needs_any_from_done = false;
620
621
    default_encoding.type = CODING_UNSET;
    default_decoding.type = CODING_UNSET;
622
    checked_incorrect_field = false;
623
    encode_attrib_mod_conflict = false;
Elemer Lelik's avatar
Elemer Lelik committed
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
  }

  void Type::clean_up()
  {
    switch (typetype) {
    case T_ERROR:
    case T_NULL:
    case T_BOOL:
    case T_INT:
    case T_REAL:
    case T_BSTR:
    case T_HSTR:
    case T_OSTR:
    case T_CSTR:
    case T_USTR:
    case T_UTF8STRING:
    case T_NUMERICSTRING:
    case T_PRINTABLESTRING:
    case T_TELETEXSTRING:
    case T_VIDEOTEXSTRING:
    case T_IA5STRING:
    case T_GRAPHICSTRING:
    case T_VISIBLESTRING:
    case T_GENERALSTRING:
    case T_UNIVERSALSTRING:
    case T_BMPSTRING:
    case T_UTCTIME:
    case T_GENERALIZEDTIME:
    case T_OBJECTDESCRIPTOR:
    case T_OID:
    case T_ROID:
    case T_ANY:
    case T_EXTERNAL:
    case T_EMBEDDED_PDV:
    case T_UNRESTRICTEDSTRING:
    case T_REFDSPEC:
    case T_OCFT:
    case T_VERDICT:
    case T_ADDRESS:
    case T_DEFAULT:
      break;
    case T_INT_A:
    case T_BSTR_A:
      delete u.namednums.block;
      delete u.namednums.nvs;
      break;
    case T_ENUM_A:
      delete u.enums.block;
      if(u.enums.eis1) {
        u.enums.eis1->release_eis();
        delete u.enums.eis1;
      }
      if(u.enums.eis2) {
        u.enums.eis2->release_eis();
        delete u.enums.eis2;
      }
      /* no break */
    case T_ENUM_T:
      delete u.enums.eis;
      if (u.enums.eis_by_name) {
        for (size_t a = 0; a < u.enums.eis_by_name->size(); a++) {
          delete u.enums.eis_by_name->get_nth_elem(a);
        }
        u.enums.eis_by_name->clear();
        delete u.enums.eis_by_name;
      }
      break;
    case T_CHOICE_A:
    case T_SEQ_A:
    case T_SET_A:
      delete u.secho.block;
      delete u.secho.ctss;
      /* no break */
    case T_ANYTYPE:
    case T_CHOICE_T:
    case T_SEQ_T:
    case T_SET_T:
    case T_OPENTYPE:
      delete u.secho.cfm;
      if (u.secho.field_by_name) {
        for(size_t a = 0; a < u.secho.field_by_name->size(); a++) {
          delete u.secho.field_by_name->get_nth_elem(a);
        }
        u.secho.field_by_name->clear();
        delete u.secho.field_by_name;
      }
      break;
    case T_SEQOF:
    case T_SETOF:
      delete u.seof.ofType;
      break;
    case T_REFD:
      delete u.ref.ref;
      break;
    case T_SELTYPE:
      delete u.seltype.id;
      delete u.seltype.type;
      break;
    case T_ARRAY:
      delete u.array.element_type;
      delete u.array.dimension;
      break;
    case T_PORT:
      delete u.port;
      break;
    case T_COMPONENT:
      delete u.component;
      break;
    case T_SIGNATURE:
      delete u.signature.parameters;
      delete u.signature.return_type;
      delete u.signature.exceptions;
      break;
    case T_FUNCTION:
    case T_ALTSTEP:
      delete u.fatref.fp_list;
      delete u.fatref.runs_on.ref;
      delete u.fatref.return_type;
      break;
    case T_TESTCASE:
      delete u.fatref.fp_list;
      delete u.fatref.runs_on.ref;
      delete u.fatref.system.ref;
      break;
    default:
      FATAL_ERROR("Type::clean_up()");
    } // switch
    typetype = T_ERROR;
    delete tags;
    tags = 0;
    delete constraints;
    constraints = 0;
    delete rawattrib;
    rawattrib = 0;
    delete textattrib;
    textattrib = 0;
    delete xerattrib;
    xerattrib = 0;
    delete sub_type;
    sub_type = 0;
    delete berattrib;
    berattrib = 0;
    delete jsonattrib;
    jsonattrib = 0;
768
769
    delete oerattrib;
    oerattrib = 0;
Elemer Lelik's avatar
Elemer Lelik committed
770
771
772
773
774
775
776
777
778
779
780
    if (parsed_restr) {
      for (size_t i = 0; i < parsed_restr->size(); i++)
        delete (*parsed_restr)[i];
      parsed_restr->clear();
      delete parsed_restr;
      parsed_restr = 0;
    }
    delete w_attrib_path;
    w_attrib_path = 0;
    delete encode_attrib_path;
    encode_attrib_path = 0;
781
782
783
    for (size_t i = 0; i < coding_table.size(); ++i) {
      if (!coding_table[i]->built_in) {
        Free(coding_table[i]->custom_coding.name);
784
785
786
787
788
789
790
791
792
793
        for (size_t j = 0; j < coding_table[i]->custom_coding.encoders->size(); ++j) {
          delete coding_table[i]->custom_coding.encoders->get_nth_elem(j);
        }
        coding_table[i]->custom_coding.encoders->clear();
        delete coding_table[i]->custom_coding.encoders;
        for (size_t j = 0; j < coding_table[i]->custom_coding.decoders->size(); ++j) {
          delete coding_table[i]->custom_coding.decoders->get_nth_elem(j);
        }
        coding_table[i]->custom_coding.decoders->clear();
        delete coding_table[i]->custom_coding.decoders;
794
795
796
797
798
799
800
801
      }
      delete coding_table[i];
    }
    coding_table.clear();
    for (size_t i = 0; i < coders_to_generate.size(); ++i) {
      delete coders_to_generate[i];
    }
    coders_to_generate.clear();
Elemer Lelik's avatar
Elemer Lelik committed
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
  }

  Type::Type(typetype_t p_tt)
    : Governor(S_T), typetype(p_tt)
  {
    init();
    switch(p_tt) {
    case T_ERROR:
    case T_NULL:
    case T_BOOL:
    case T_INT:
    case T_REAL:
    case T_BSTR:
    case T_HSTR:
    case T_OSTR:
    case T_CSTR:
    case T_USTR:
    case T_UTF8STRING:
    case T_NUMERICSTRING:
    case T_PRINTABLESTRING:
    case T_TELETEXSTRING:
    case T_VIDEOTEXSTRING:
    case T_IA5STRING:
    case T_GRAPHICSTRING:
    case T_VISIBLESTRING:
    case T_GENERALSTRING:
    case T_UNIVERSALSTRING:
    case T_BMPSTRING:
    case T_UTCTIME:
    case T_GENERALIZEDTIME:
    case T_OBJECTDESCRIPTOR:
    case T_OID:
    case T_ROID:
    case T_ANY:
    case T_EXTERNAL:
    case T_EMBEDDED_PDV:
    case T_UNRESTRICTEDSTRING:
    case T_VERDICT:
    case T_DEFAULT:
      break;
    case T_ANYTYPE: {
      u.secho.cfm = new CompFieldMap;
      u.secho.cfm->set_my_type(this);
      u.secho.block=0;
      u.secho.ctss=0;
      u.secho.field_by_name = 0;
      u.secho.component_internal = false;
      u.secho.has_single_charenc = false;
      break; }
    case T_INT_A:
    case T_BSTR_A:
      u.namednums.block=0;
      u.namednums.nvs=0;
      break;
    case T_ADDRESS:
      u.address = 0;
      break;
    default:
      FATAL_ERROR("Type::Type()");
    } // switch
  }

  Type::Type(typetype_t p_tt, EnumItems *p_eis)
    : Governor(S_T), typetype(p_tt)
  {
    if (p_tt != T_ENUM_T || !p_eis) FATAL_ERROR("Type::Type()");
    init();
    u.enums.eis=p_eis;
    u.enums.eis_by_name=0;
  }

  Type::Type(typetype_t p_tt, Block *p_block)
    : Governor(S_T), typetype(p_tt)
  {
    if (!p_block) FATAL_ERROR("NULL parameter");
    init();
    switch(p_tt) {
    case T_INT_A:
    case T_BSTR_A:
      u.namednums.block=p_block;
      u.namednums.nvs=0;
      break;
    case T_ENUM_A:
      u.enums.eis=new EnumItems();
      u.enums.block=p_block;
      u.enums.eis1=0;
      u.enums.ellipsis=false;
      u.enums.excSpec=0;
      u.enums.eis2=0;
      u.enums.eis_by_name=0;
      break;
    case T_SEQ_A:
    case T_SET_A:
      u.secho.tr_compsof_ready=false;
      // no break
    case T_CHOICE_A:
      u.secho.cfm = 0;
      u.secho.block=p_block;
      u.secho.ctss=0;
      u.secho.field_by_name = 0;
      u.secho.component_internal = false;
      u.secho.has_single_charenc = false;
      break;
    default:
      FATAL_ERROR("Type::Type()");
    } // switch
  }

  Type::Type(typetype_t p_tt,
             EnumItems *p_eis1, bool p_ellipsis, EnumItems *p_eis2)
    : Governor(S_T), typetype(p_tt)
  {
    if (p_tt != T_ENUM_A || !p_eis1) FATAL_ERROR("Type::Type()");
    init();
    u.enums.eis=new EnumItems();
    u.enums.block=0;
    u.enums.eis1=p_eis1;
    u.enums.ellipsis=p_ellipsis;
    u.enums.eis2=p_eis2;
    u.enums.eis_by_name=0;
  }

  Type::Type(typetype_t p_tt, CompFieldMap *p_cfm)
    : Governor(S_T), typetype(p_tt)
  {
    if (!p_cfm) FATAL_ERROR("NULL parameter");
    init();
    switch (p_tt) {
    case T_CHOICE_T:
    case T_SEQ_T:
    case T_SET_T:
      u.secho.cfm=p_cfm;
      u.secho.field_by_name = 0;
      u.secho.component_internal = false;
      u.secho.has_single_charenc = false;
      break;
    default:
      FATAL_ERROR("Type::Type()");
    } // switch
  }

  Type::Type(typetype_t p_tt, Type *p_type)
    : Governor(S_T), typetype(p_tt)
  {
    if (!p_type) FATAL_ERROR("NULL parameter");
    init();
    switch (p_tt) {
    case T_SEQOF:
    case T_SETOF:
      u.seof.ofType=p_type;
      u.seof.ofType->set_ownertype(OT_RECORD_OF, this);
      u.seof.component_internal = false;
      break;
    case T_REFDSPEC:
      u.ref.type_refd=p_type;
      u.ref.type_refd->set_ownertype(OT_REF_SPEC, this);
      u.ref.component_internal = false;
      break;
    default:
      FATAL_ERROR("Type::Type()");
    } // switch
  }

  Type::Type(typetype_t p_tt, Identifier *p_id, Type *p_type)
    : Governor(S_T), typetype(p_tt)
  {
    if (p_tt != T_SELTYPE || !p_id || !p_type) FATAL_ERROR("Type::Type()");
    init();
    u.seltype.id=p_id;
    u.seltype.type=p_type;
    u.seltype.type->set_ownertype(OT_SELTYPE, this);
    u.seltype.type_refd=0;
  }

  Type::Type(typetype_t p_tt, Type *p_type, Ttcn::ArrayDimension *p_dim,
             bool p_in_typedef)
    : Governor(S_T), typetype(p_tt)
  {
    if (p_tt != T_ARRAY || !p_type || !p_dim) FATAL_ERROR("Type::Type()");
    init();
    u.array.element_type = p_type;
    u.array.element_type->set_ownertype(OT_ARRAY, this);
    u.array.dimension = p_dim;
    u.array.in_typedef = p_in_typedef;
    u.array.component_internal = false;
  }

  Type::Type(typetype_t p_tt, Type *p_type, OC_defn *p_oc_defn,
             const Identifier *p_id)
    : Governor(S_T), typetype(p_tt)
  {
    if (p_tt != T_OCFT || !p_type ||!p_oc_defn || !p_id)
      FATAL_ERROR("Type::Type()");
    init();
    u.ref.type_refd=p_type;
    u.ref.type_refd->set_ownertype(OT_OCFT, this);
    u.ref.oc_defn=p_oc_defn;
    u.ref.oc_fieldname=p_id;
    u.ref.component_internal = false;
  }

  Type::Type(typetype_t p_tt, OC_defn *p_oc_defn,
             const Identifier *p_id)
    : Governor(S_T), typetype(p_tt)
  {
    if (p_tt != T_OPENTYPE || !p_oc_defn || !p_id) FATAL_ERROR("Type::Type()");
    init();
    has_opentypes=true;
    u.secho.cfm=new CompFieldMap();
    u.secho.cfm->set_my_type(this);
    u.secho.oc_defn=p_oc_defn;
    u.secho.oc_fieldname=p_id;
    u.secho.my_tableconstraint=0;
    u.secho.field_by_name = 0;
    u.secho.component_internal = false;
    u.secho.has_single_charenc = false;
  }

  Type::Type(typetype_t p_tt, Reference *p_ref)
    : Governor(S_T), typetype(p_tt)
  {
    if (p_tt != T_REFD || !p_ref) FATAL_ERROR("Type::Type()");
    init();
    u.ref.ref=p_ref;
    u.ref.type_refd=0;
    u.ref.component_internal = false;
  }

  Type::Type(typetype_t p_tt, Ttcn::PortTypeBody *p_pb)
    : Governor(S_T), typetype(p_tt)
  {
    if (p_tt != T_PORT || !p_pb) FATAL_ERROR("Type::Type()");
    init();
    u.port = p_pb;
    p_pb->set_my_type(this);
  }

  Type::Type(typetype_t p_tt, ComponentTypeBody *p_cb)
    : Governor(S_T), typetype(p_tt)
  {
    if (p_tt != T_COMPONENT || !p_cb) FATAL_ERROR("Type::Type()");
    init();
    u.component = p_cb;
    p_cb->set_my_type(this);
  }

  Type::Type(typetype_t p_tt, SignatureParamList *p_params, Type *p_returntype,
             bool p_noblock, SignatureExceptions *p_exceptions)
    : Governor(S_T), typetype(p_tt)
  {
    if (p_tt != T_SIGNATURE || (p_returntype && p_noblock))
      FATAL_ERROR("Type::Type()");
    init();
    u.signature.parameters = p_params;
    if ((u.signature.return_type = p_returntype)) { // check assignment for 0
      u.signature.return_type->set_ownertype(OT_SIGNATURE, this);
    }
    u.signature.no_block = p_noblock;
    u.signature.exceptions = p_exceptions;
    u.signature.component_internal = false;
  }

  Type::Type(typetype_t p_tt,Ttcn::FormalParList *p_params,
        Ttcn::Reference* p_runs_on_ref, bool p_runs_on_self,
        Type *p_returntype, bool p_returns_template,
        template_restriction_t p_template_restriction)
    : Governor(S_T), typetype(p_tt)
  {
    if (p_tt != T_FUNCTION || !p_params || (!p_returntype && p_returns_template)
        || (p_runs_on_ref && p_runs_on_self)) FATAL_ERROR("Type::Type()");
    init();
    u.fatref.fp_list = p_params;
    u.fatref.runs_on.ref = p_runs_on_ref;
    u.fatref.runs_on.self = p_runs_on_self;
    u.fatref.runs_on.type = 0;
    if ((u.fatref.return_type = p_returntype)) { // check assignment for 0
      u.fatref.return_type->set_ownertype(OT_FUNCTION, this);
    }
    u.fatref.is_startable = false;
    u.fatref.returns_template = p_returns_template;
    u.fatref.template_restriction = p_template_restriction;
  }

  Type::Type(typetype_t p_tt,Ttcn::FormalParList *p_params,
        Ttcn::Reference* p_runs_on_ref, bool p_runs_on_self)
    : Governor(S_T), typetype(p_tt)
  {
    if(p_tt != T_ALTSTEP || !p_params || (p_runs_on_ref && p_runs_on_self))
      FATAL_ERROR("Type::Type()");
    init();
    u.fatref.fp_list = p_params;
    u.fatref.runs_on.ref = p_runs_on_ref;
    u.fatref.runs_on.self = p_runs_on_self;
    u.fatref.runs_on.type = 0;
    u.fatref.return_type = 0;
    u.fatref.is_startable = false;
    u.fatref.returns_template = false;
    u.fatref.template_restriction = TR_NONE;
  }

  Type::Type(typetype_t p_tt,Ttcn::FormalParList *p_params,
        Ttcn::Reference* p_runs_on_ref, Ttcn::Reference *p_system_ref)
    : Governor(S_T), typetype(p_tt)
  {
    if(p_tt != T_TESTCASE || !p_params || !p_runs_on_ref)
      FATAL_ERROR("Type::Type()");
    init();
    u.fatref.fp_list = p_params;
    u.fatref.runs_on.ref = p_runs_on_ref;
    u.fatref.runs_on.self = false;
    u.fatref.runs_on.type = 0;
    u.fatref.system.ref = p_system_ref;
    u.fatref.system.type = 0;
    u.fatref.is_startable = false;
    u.fatref.returns_template = false;
    u.fatref.template_restriction = TR_NONE;
  }

  Type::~Type()
  {
    clean_up();
  }

  void Type::free_pools()
  {
    destroy_default_tags();// Additionally: R&S license warning
    destroy_pooltypes();// Additionally: R&S license checkin/disconnect/shutdown
  }

  Type *Type::clone() const
  {
    return new Type(*this);
  }

  Type::typetype_t Type::get_typetype_ttcn3(typetype_t p_tt)
  {
    switch (p_tt) {
    case T_INT_A:
      return T_INT;
    case T_ENUM_A:
      return T_ENUM_T;
    case T_BSTR_A:
      return T_BSTR;
    case T_UTF8STRING:
    case T_BMPSTRING:
    case T_UNIVERSALSTRING:
      return T_USTR;
    case T_TELETEXSTRING:
    case T_VIDEOTEXSTRING:
    case T_GRAPHICSTRING:
    case T_OBJECTDESCRIPTOR:
    case T_GENERALSTRING:
      // iso2022str
    case T_NUMERICSTRING:
    case T_PRINTABLESTRING:
    case T_IA5STRING:
    case T_VISIBLESTRING:
    case T_UTCTIME:
    case T_GENERALIZEDTIME:
      return T_CSTR;
    case T_ROID:
      return T_OID;
    case T_ANY:
      return T_OSTR;
    case T_CHOICE_A:
    case T_OPENTYPE:
      return T_CHOICE_T;
    case T_SEQ_A:
    case T_EXTERNAL:
    case T_EMBEDDED_PDV:
    case T_UNRESTRICTEDSTRING:
      return T_SEQ_T;
    case T_SET_A:
      return T_SET_T;
    default:
      return p_tt;
    } // switch typetype
  }

  bool Type::is_asn1() const
  {
    if (my_scope) return Setting::is_asn1();
    // the type might be a pool type, which is considered to be a TTCN-3 type
    typetype_t t_typetype = get_typetype_ttcn3(typetype);
    if (pooltypes && pooltypes->has_key(t_typetype) &&
        (*pooltypes)[t_typetype] == this) return false;
    else FATAL_ERROR("Type::is_asn1()");
  }

  bool Type::is_ref() const
  {
    switch(typetype) {
    case T_UNRESTRICTEDSTRING:
    case T_OCFT:
    case T_EXTERNAL:
    case T_EMBEDDED_PDV:
    case T_REFD:
    case T_REFDSPEC:
    case T_SELTYPE:
    case T_ADDRESS:
      return true;
    default:
      return false;
    } // switch
  }

  bool Type::is_secho() const
  {
    switch(typetype) {
    case T_ANYTYPE:
    case T_CHOICE_A:
    case T_CHOICE_T:
    case T_OPENTYPE:
    case T_SEQ_A:
    case T_SEQ_T:
    case T_SET_A:
    case T_SET_T:
      return true;
    default:
      return false;
    } // switch
  }

  Type::truth Type::is_charenc()
  {
1227
1228
1229
1230
1231
    // this helps avoid infinite recursions in self-referencing types
    if (RecursionTracker::is_happening(this)) {
      return Maybe;
    }
    RecursionTracker tracker(this);
Elemer Lelik's avatar
Elemer Lelik committed
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
    switch(typetype) {
    case T_CHOICE_A:
    case T_CHOICE_T:
    {
      bool possible = true;
      size_t ncomp = u.secho.cfm->get_nof_comps();
      for (size_t i=0; i<ncomp; ++i) {
        CompField * cf = u.secho.cfm->get_comp_byIndex(i);
        if (cf->get_type()->is_charenc() == No) {
          possible = false; break;
        }
      } // next i
      if (possible) {
        return (xerattrib && (xerattrib->useUnion_ || xerattrib->useType_)) ? Yes : No;
      }
    }
    // no break
    case T_SEQ_A:
    case T_SEQ_T:
    case T_SET_A:
    case T_SET_T:
    case T_OPENTYPE:
      // UNTAGGED cannot be used to make a type character-encodable!
      // But USE-QNAME can!
      return (xerattrib && xerattrib->useQName_) ? Yes : No;

    case T_SEQOF: // A record-of is character-encodable if it has the "list"
    case T_SETOF: // attribute and its element is character-encodable.
      return (xerattrib && xerattrib->list_ && (u.seof.ofType->is_charenc()==Yes))
      ? Yes : No;

    case T_ENUM_A:
    case T_ENUM_T:
    case T_VERDICT:
      return Yes;

    default:
      if (is_ref()) {
        truth retval = get_type_refd_last()->is_charenc();
        if (retval == Yes) return Yes;
        else if (retval == Maybe) {
          if (xerattrib && xerattrib->useUnion_) return Yes;
        }
        // else fall through to No
      }
      return No;

    case T_BSTR:
    case T_OSTR:
    case T_HSTR:
    case T_CSTR:
    case T_USTR:
    case T_UTF8STRING:
      // TODO ASN.1 restricted character string types when (if) ASN.1 gets XER
      // TODO check subtype; strings must be restricted to not contain
      // control characters (0..0x1F except 9,0x0A,0x0D)
    case T_INT_A:
    case T_INT:
    case T_BOOL:
    case T_REAL:
      // TODO more types
      /* FIXME : this kind of check should be applied to elements of secho,
       *  not to the type of the element ! */
      return Yes;
    }
  }

  bool Type::has_empty_xml() {
    bool answer = false;
    switch (typetype) {
    case T_SEQ_A: case T_SEQ_T:
    case T_SET_A: case T_SET_T: {
      answer = true; // If all components are optional.
      size_t n_comps = get_nof_comps();
      for (size_t i = 0; i < n_comps; ++i) {
        CompField* cf = get_comp_byIndex(i);
        if (!cf->get_is_optional()) {
          answer = false;
          break; // the loop
        }
      }
      break; }
    case T_SEQOF: case T_SETOF:
      // _If_ there is a length restriction, 0 length must be allowed.
      // By this time parsed_restr has been absorbed into sub_type.
      answer = (sub_type==0) || sub_type->zero_length_allowed();
      break;
    default:
      break;
    } // switch
    return answer;
  }

  void Type::set_fullname(const string& p_fullname)
  {
    Governor::set_fullname(p_fullname);
    switch(typetype) {
    case T_INT_A:
    case T_BSTR_A:
      if(u.namednums.block) u.namednums.block->set_fullname(p_fullname);
      if(u.namednums.nvs)
        u.namednums.nvs->set_fullname(p_fullname+".<namedvalues>");
      break;
    case T_ENUM_A:
      if(u.enums.eis1) u.enums.eis1->set_fullname(p_fullname);
      if(u.enums.eis2) u.enums.eis2->set_fullname(p_fullname);
      // no break
    case T_ENUM_T:
      u.enums.eis->set_fullname(p_fullname);
      break;
    case T_ANYTYPE:
    case T_CHOICE_T:
    case T_SEQ_T:
    case T_SET_T:
    case T_OPENTYPE:
      u.secho.cfm->set_fullname(p_fullname);
      break;
    case T_SEQ_A:
    case T_SET_A:
    case T_CHOICE_A:
      if (u.secho.ctss) u.secho.ctss->set_fullname(p_fullname);
      break;
    case T_SEQOF:
    case T_SETOF: {
      string subtypename(".<oftype>");
      Type * t = u.seof.ofType;
      /* Do NOT call get_type_refd_last() or else fatal_error !
       * The AST is not fully set up. */

      /* XER will use these strings */
      switch (t->typetype)
      {
      case T_EMBEDDED_PDV: case T_EXTERNAL:
      case T_SEQ_A: case T_SEQ_T:
        subtypename = ".SEQUENCE";
        break;

      case T_SET_A: case T_SET_T:
        subtypename = ".SET";
        break;

      case T_SEQOF:
        subtypename = ".SEQUENCE_OF";
        break;

      case T_SETOF:
        subtypename = ".SET_OF";
        break;

      case T_BSTR_A:
        subtypename = ".BITSTRING";
        break;

      case T_BOOL:
        subtypename = ".BOOLEAN";
        break;

      case T_CHOICE_A: case T_CHOICE_T:
        subtypename = ".CHOICE";
        break;

      case T_ENUM_A: case T_ENUM_T:
        subtypename = ".ENUMERATED";
        break;

      case T_INT_A: case T_INT:
        subtypename = ".INTEGER";
        break;

      default:
        break;
      }
      u.seof.ofType->set_fullname(p_fullname+subtypename);
      break; }
    case T_REFD:
      u.ref.ref->set_fullname(p_fullname);
      break;
    case T_SELTYPE:
      u.seltype.type->set_fullname(p_fullname+".<selection>");
      break;
    case T_PORT:
      u.port->set_fullname(p_fullname);
      break;
    case T_COMPONENT:
      u.component->set_fullname(p_fullname);
      break;
    case T_ARRAY:
      u.array.element_type->set_fullname(p_fullname + ".<element_type>");
      u.array.dimension->set_fullname(p_fullname + ".<dimension>");
      break;
    case T_SIGNATURE:
      if (u.signature.parameters)
        u.signature.parameters->set_fullname(p_fullname);
      if (u.signature.return_type)
        u.signature.return_type->set_fullname(p_fullname + ".<return_type>");
      if (u.signature.exceptions)
        u.signature.exceptions->set_fullname(p_fullname + ".<exception_list>");
      break;
    case T_FUNCTION:
    case T_ALTSTEP:
      u.fatref.fp_list->set_fullname(p_fullname + "<formal_par_list>");
      if (u.fatref.runs_on.ref)
        u.fatref.runs_on.ref->set_fullname(p_fullname + "<runs_on_type>");
      if (u.fatref.return_type)
        u.fatref.return_type->set_fullname(p_fullname + "<return type>");
      break;
    case T_TESTCASE:
      u.fatref.fp_list->set_fullname(p_fullname + ".<formal_par_list>");
      if (u.fatref.runs_on.ref)
        u.fatref.runs_on.ref->set_fullname(p_fullname+".<runs_on_type>");
      if (u.fatref.system.ref)
        u.fatref.system.ref->set_fullname(p_fullname + ".<system_type>");
      break;
    default:
      break;
    } // switch
  }

  void Type::set_my_scope(Scope *p_scope)
  {
    Governor::set_my_scope(p_scope);
    if(tags) tags->set_my_scope(p_scope);
    switch(typetype) {
    case T_INT_A:
    case T_BSTR_A:
      if(u.namednums.nvs) u.namednums.nvs->set_my_scope(p_scope);
      break;
    case T_ENUM_A:
      if(u.enums.eis1) u.enums.eis1->set_my_scope(p_scope);
      if(u.enums.eis2) u.enums.eis2->set_my_scope(p_scope);
      // no break
    case T_ENUM_T:
      u.enums.eis->set_my_scope(p_scope);
      break;
    case T_CHOICE_T:
    case T_SEQ_T:
    case T_SET_T:
    case T_OPENTYPE:
    case T_ANYTYPE:
      u.secho.cfm->set_my_scope(p_scope);
      break;
    case T_SEQ_A:
    case T_SET_A:
    case T_CHOICE_A:
      if(u.secho.ctss) u.secho.ctss->set_my_scope(p_scope);
      break;
    case T_SEQOF:
    case T_SETOF:
      u.seof.ofType->set_my_scope(p_scope);
      break;
    case T_REFD:
      u.ref.ref->set_my_scope(p_scope);
      break;
    case T_SELTYPE:
      u.seltype.type->set_my_scope(p_scope);
      break;
    case T_ARRAY:
      u.array.element_type->set_my_scope(p_scope);
      u.array.dimension->set_my_scope(p_scope);
      break;
    case T_PORT:
      u.port->set_my_scope(p_scope);
      break;
    case T_SIGNATURE:
      if (u.signature.parameters)
        u.signature.parameters->set_my_scope(p_scope);
      if (u.signature.return_type)
        u.signature.return_type->set_my_scope(p_scope);
      if (u.signature.exceptions)
        u.signature.exceptions->set_my_scope(p_scope);
      break;
    case T_COMPONENT:
      u.component->set_my_scope(p_scope);
      break;
    case T_FUNCTION:
    case T_ALTSTEP:
      // the scope of parameter list is set later in chk_Fat()
      if (u.fatref.runs_on.ref)
        u.fatref.runs_on.ref->set_my_scope(p_scope);
      if (u.fatref.return_type)
        u.fatref.return_type->set_my_scope(p_scope);
      break;
    case T_TESTCASE:
      // the scope of parameter list is set later in chk_Fat()
      if (u.fatref.runs_on.ref)
        u.fatref.runs_on.ref->set_my_scope(p_scope);
      if (u.fatref.system.ref)
        u.fatref.system.ref->set_my_scope(p_scope);
      break;
    default:
      break;
    } // switch
  }

  Type* Type::get_type_refd(ReferenceChain *refch)
  {
    switch(typetype) {
    case T_REFD: {
      if(refch && !refch->add(get_fullname())) goto error;
      if(!u.ref.type_refd) {
        Assignment *ass = u.ref.ref->get_refd_assignment();
        if (!ass) goto error; // The referenced assignment is not found
        switch (ass->get_asstype()) {
        case Assignment::A_ERROR:
          goto error;
        case Assignment::A_TYPE:
        case Assignment::A_VS:
          u.ref.type_refd = ass->get_Type()->get_field_type(
            u.ref.ref->get_subrefs(), EXPECTED_DYNAMIC_VALUE, refch);
          if (!u.ref.type_refd) goto error;
          break;
          //case Assignment::A_VS:
          //u.ref.type_refd = ass->get_Type();
          //      if(!u.ref.type_refd) goto error;
          //break;
        case Assignment::A_OC:
        case Assignment::A_OBJECT:
        case Assignment::A_OS: {
          Setting *setting = u.ref.ref->get_refd_setting();
          if (!setting || setting->get_st() == Setting::S_ERROR) goto error;
          /* valueset? */
          u.ref.type_refd = dynamic_cast<Type*>(setting);
          if(!u.ref.type_refd) {
            error("`%s' is not a reference to a type",
              u.ref.ref->get_dispname().c_str());
            goto error;
          }

          if (u.ref.type_refd->ownertype == OT_UNKNOWN) {
            u.ref.type_refd->set_ownertype(OT_REF, this);
          }

          break;}
        default:
          error("`%s' is not a reference to a type",
            u.ref.ref->get_dispname().c_str());
          goto error;
        } // switch
        if(!u.ref.type_refd->get_my_scope()) {
          // opentype or OCFT
          u.ref.type_refd->set_my_scope(get_my_scope());
          u.ref.type_refd->set_parent_type(get_parent_type());
          u.ref.type_refd->set_genname(get_genname_own(), string("type"));
          u.ref.type_refd->set_fullname(get_fullname()+".type");
        }
        if (u.ref.type_refd->typetype == T_OPENTYPE && !constraints)
          warning("An open type without table constraint is useless in TTCN-3");
      }
      return u.ref.type_refd;
      break;}
    case T_SELTYPE: {
      if(refch && !refch->add(get_fullname())) goto error;
      if(!u.seltype.type_refd) {
        Type *t=u.seltype.type->get_type_refd_last(refch);
        if(t->typetype==T_ERROR) goto error;
        if(t->typetype!=T_CHOICE_A) {
          error("(Reference to) a CHOICE type was expected"
            " in selection type.");
          goto error;
        }
        if(!t->has_comp_withName(*u.seltype.id)) {
          error("No alternative with name `%s' in the given type `%s'.",
            u.seltype.id->get_dispname().c_str(),
            t->get_fullname().c_str());
          goto error;
        }
        u.seltype.type_refd=t->get_comp_byName(*u.seltype.id)->get_type();
      }
      return u.seltype.type_refd;
      break;}
    case T_REFDSPEC:
    case T_OCFT:
      if(refch && !refch->add(get_fullname())) goto error;
      return u.ref.type_refd;
      break;
    case T_EXTERNAL: {
      if (!my_scope) FATAL_ERROR("Type::get_type_refd()");
      Identifier t_id(Identifier::ID_ASN, string("EXTERNAL"));
      return my_scope->get_scope_asss()->get_local_ass_byId(t_id)->get_Type(); }
    case T_EMBEDDED_PDV: {
      if (!my_scope) FATAL_ERROR("Type::get_type_refd()");
      Identifier t_id(Identifier::ID_ASN, string("EMBEDDED PDV"));
      return my_scope->get_scope_asss()->get_local_ass_byId(t_id)->get_Type(); }
    case T_UNRESTRICTEDSTRING: {
      if (!my_scope) FATAL_ERROR("Type::get_type_refd()");
      Identifier t_id(Identifier::ID_ASN, string("CHARACTER STRING"));
      return my_scope->get_scope_asss()->get_local_ass_byId(t_id)->get_Type(); }
    case T_ADDRESS:
      if (refch && !refch->add(get_fullname())) goto error;
      if (u.address) return u.address;
      if (!my_scope) FATAL_ERROR("Type::get_type_refd()");
      u.address = my_scope->get_scope_mod()->get_address_type();
      if (!u.address) {
        error("Type `address' is not defined in this module");
        goto error;
      }
      return u.address;
    default:
      FATAL_ERROR("Type::get_type_refd()");
      return 0;
    } // switch
    error:
    clean_up();
    return this;
  }

  Type* Type::get_type_refd_last(ReferenceChain *refch)
  {
    Type *t=this;
    while(t->is_ref()) t=t->get_type_refd(refch);
    return t;
  }

  Type *Type::get_field_type(Ttcn::FieldOrArrayRefs *subrefs,
    expected_value_t expected_index, ReferenceChain *refch,
    bool interrupt_if_optional)
  {
    if (!subrefs) return this;
    Type *t = this;
    if (expected_index == EXPECTED_TEMPLATE)
      expected_index = EXPECTED_DYNAMIC_VALUE;
    size_t nof_refs = subrefs->get_nof_refs();
    subrefs->clear_string_element_ref();
    for (size_t i = 0; i < nof_refs; i++) {
      if (refch) refch->mark_state();
      t = t->get_type_refd_last(refch);
      if (refch) refch->prev_state();
      // stop immediately if current type t is erroneous
      // (e.g. because of circular reference)
      if (t->typetype == T_ERROR) return 0;
      Ttcn::FieldOrArrayRef *ref = subrefs->get_ref(i);
      switch (ref->get_type()) {
      case Ttcn::FieldOrArrayRef::FIELD_REF: {
Elemer Lelik's avatar
Elemer Lelik committed
1665
1666
1667
1668
        if (t->typetype == T_OPENTYPE) {
          // allow the alternatives of open types as both lower and upper identifiers
          ref->set_field_name_to_lowercase();
        }
Elemer Lelik's avatar
Elemer Lelik committed
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
        const Identifier& id = *ref->get_id();
        switch (t->typetype) {
        case T_CHOICE_A:
        case T_CHOICE_T:
        case T_OPENTYPE:
        case T_SEQ_A:
        case T_SEQ_T:
        case T_SET_A:
        case T_SET_T:
        case T_ANYTYPE:
          break;
Elemer Lelik's avatar
Elemer Lelik committed
1680
1681
1682
	case T_COMPONENT:
	  ref->error("Referencing fields of a component is not allowed");
	  return 0;
Elemer Lelik's avatar
Elemer Lelik committed
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
        default:
          ref->error("Invalid field reference `%s': type `%s' "
            "does not have fields", id.get_dispname().c_str(),
            t->get_typename().c_str());
          return 0;
        }
        if (!t->has_comp_withName(id)) {
          ref->error("Reference to non-existent field `%s' in type `%s'",
            id.get_dispname().c_str(),
            t->get_typename().c_str());
          return 0;
        }
        CompField* cf = t->get_comp_byName(id);
        if (interrupt_if_optional && cf->get_is_optional()) return 0;
        t = cf->get_type();
        break; }
      case Ttcn::FieldOrArrayRef::ARRAY_REF: {
        Type *embedded_type = 0;
        switch (t->typetype) {
        case T_SEQOF:
        case T_SETOF:
          embedded_type = t->u.seof.ofType;
          break;
        case T_ARRAY:
          embedded_type = t->u.array.element_type;
          break;
        case T_BSTR:
        case T_BSTR_A:
        case T_HSTR:
        case T_OSTR:
        case T_CSTR:
        case T_USTR:
        case T_UTF8STRING:
        case T_NUMERICSTRING:
        case T_PRINTABLESTRING:
        case T_TELETEXSTRING:
        case T_VIDEOTEXSTRING:
        case T_IA5STRING:
        case T_GRAPHICSTRING:
        case T_VISIBLESTRING:
        case T_GENERALSTRING:
        case T_UNIVERSALSTRING:
        case T_BMPSTRING:
        case T_UTCTIME:
        case T_GENERALIZEDTIME:
        case T_OBJECTDESCRIPTOR:
          if (subrefs->refers_to_string_element()) {
            ref->error("A string element of type `%s' cannot be indexed",
              t->get_typename().c_str());
            return 0;
          } else {
            subrefs->set_string_element_ref();
            // string elements have the same type as the string itself
            embedded_type = t;
            break;
          }
        default:
          ref->error("Type `%s' cannot be indexed",
            t->get_typename().c_str());
          return 0;
        }
        // check the index value
        Value *index_value = ref->get_val();
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
        index_value->set_lowerid_to_ref();
        
        // pt is the type with the indexing is made, while t is the type on the
        // indexing is applied.
        Type* pt = index_value->get_expr_governor_last();
        if (pt != NULL &&
          // The indexer type is an array or record of
           (pt->get_typetype() == T_ARRAY || pt->get_typetype() == T_SEQOF) &&
          // The indexed type is a record of or set of or array
           (t->get_typetype() == T_SEQOF || t->get_typetype() == T_SETOF || t->get_typetype() == T_ARRAY)) {
          
          // The indexer type must be of type integer
          if (pt->get_ofType()->get_type_refd_last()->get_typetype() != T_INT) {
            ref->error("Only fixed length array or record of integer types are allowed for short-hand notation for nested indexes.");
            return 0;
          }
          int len = 0;
          // Get the length of the array or record of
          if (pt->get_typetype() == T_ARRAY) {
            len = (int)pt->get_dimension()->get_size();
          } else if (pt->get_typetype() == T_SEQOF) {
            SubType* sub = pt->get_sub_type();
            if (sub == NULL) {
              ref->error("The type `%s' must have single size length restriction when used as a short-hand notation for nested indexes.",
                pt->get_typename().c_str());
              return 0;
            }
            len = pt->get_sub_type()->get_length_restriction();
            if (len == -1) {
              ref->error("The type `%s' must have single size length restriction when used as a short-hand notation for nested indexes.",
                pt->get_typename().c_str());
              return 0;
            }
          }
          embedded_type = embedded_type->get_type_refd_last();
          int j = 0;
          // Get the len - 1'th inner type
          while (j < len - 1) {
            switch (embedded_type->get_typetype()) {
              case T_SEQOF:
              case T_SETOF:
              case T_ARRAY:
                embedded_type = embedded_type->get_ofType()->get_type_refd_last();
                break;
              default:
                ref->error("The type `%s' contains too many indexes (%i) in the short-hand notation for nested indexes.",
                  pt->get_typename().c_str(), len);
                return 0;
            }
            j++;
          }
        } else if (t->typetype == T_ARRAY) {
Elemer Lelik's avatar
Elemer Lelik committed
1798
1799
1800
1801
          // checking of array index is performed by the array dimension
          t->u.array.dimension->chk_index(index_value, expected_index);
        } else {
          // perform a generic index check for other types
1802
          if (index_value->get_valuetype() != Value::V_NOTUSED) {
Elemer Lelik's avatar
Elemer Lelik committed
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
            Error_Context cntxt(index_value, "In index value");
            index_value->chk_expr_int(expected_index);
          }
          Value *v_last = index_value->get_value_refd_last();
          if (v_last->get_valuetype() == Value::V_INT) {
            const int_val_t *index_int = v_last->get_val_Int();
            if (*index_int > INT_MAX) {
              index_value->error("Integer value `%s' is too big for indexing "
                "type `%s'", (index_int->t_str()).c_str(),
                (t->get_typename()).c_str());
              index_value->set_valuetype(Value::V_ERROR);
            } else {
              if (*index_int < 0) {
                index_value->error("A non-negative integer value was "
                  "expected for indexing type `%s' instead of `%s'",
                  t->get_typename().c_str(), (index_int->t_str()).c_str());
                index_value->set_valuetype(Value::V_ERROR);
              }
            }
          }
        }
        // change t to the embedded type
        t = embedded_type;
        break; }
      default:
        FATAL_ERROR("Type::get_field_type(): invalid reference type");
      }
    }
    return t;
  }

  bool Type::get_subrefs_as_array(const Ttcn::FieldOrArrayRefs *subrefs, dynamic_array<size_t>& subrefs_array, dynamic_array<Type*>& type_array)
  {
    if (!subrefs) FATAL_ERROR("Type::get_subrefs_as_array()");
    Type *t = this;
    size_t nof_refs = subrefs->get_nof_refs();
    for (size_t i = 0; i < nof_refs; i++) {
      t = t->get_type_refd_last();
      type_array.add(t);
      if (t->typetype == T_ERROR) FATAL_ERROR("Type::get_subrefs_as_array()");
      Ttcn::FieldOrArrayRef *ref = subrefs->get_ref(i);
      size_t field_index=0;
      switch (ref->get_type()) {
      case Ttcn::FieldOrArrayRef::FIELD_REF: {
        const Identifier& id = *ref->get_id();
        if (!t->has_comp_withName(id)) FATAL_ERROR("Type::get_subrefs_as_array()");
        CompField* cf = t->get_comp_byName(id);
        field_index = t->get_comp_index_byName(id);
        field_index = t->get_codegen_index(field_index);
        t = cf->get_type();
        break; }
      case Ttcn::FieldOrArrayRef::ARRAY_REF: {
        Value *index_value = ref->get_val();
        Value *v_last = index_value->get_value_refd_last();
        if (v_last->get_valuetype()!=Value::V_INT) {
          // workaround: get_field_type() does not return NULL if the index
          // value is invalid, this function returns false in this case
          return false;
        }
        const int_val_t *index_int = v_last->get_val_Int();
        if (!index_int->is_native() || index_int->is_negative()) {
          return false;
        }
        field_index = (size_t)index_int->get_val();
        Type *embedded_type = 0;
        switch (t->typetype) {
        case T_SEQOF:
        case T_SETOF:
          embedded_type = t->u.seof.ofType;
          break;
        case T_ARRAY:
          embedded_type = t->u.array.element_type;
          break;
        default:
          embedded_type = t;
          break;
        }
        // change t to the embedded type
        t = embedded_type;
        break; }
      default:
        FATAL_ERROR("Type::get_subrefs_as_array()");
      }
      subrefs_array.add(field_index);
    }
    return true;
  }

  bool Type::is_optional_field() const {
    if (ownertype == OT_COMP_FIELD) {
        const CompField* const myOwner = (CompField*) owner;
        return myOwner && myOwner->get_is_optional();
    }
    return false;
  }

  bool Type::field_is_optional(Ttcn::FieldOrArrayRefs *subrefs)
  {
    // handling trivial cases
    if (!subrefs) return false;
    size_t nof_subrefs = subrefs->get_nof_refs();
    if (nof_subrefs < 1) return false;
    Ttcn::FieldOrArrayRef *last_ref = subrefs->get_ref(nof_subrefs - 1);
    if (last_ref->get_type() == Ttcn::FieldOrArrayRef::ARRAY_REF) return false;
    // following the embedded types
    Type *t=get_type_refd_last();
    for (size_t i = 0; i < nof_subrefs - 1; i++) {
      Ttcn::FieldOrArrayRef *ref = subrefs->get_ref(i);
      if (ref->get_type() == Ttcn::FieldOrArrayRef::FIELD_REF)
        t = t->get_comp_byName(*ref->get_id())->get_type();
      else t = t->get_ofType();
      t=t->get_type_refd_last();
    }
    // now last_ref refers to a field of t
    return t->get_comp_byName(*last_ref->get_id())->get_is_optional();
  }

  bool Type::is_root_basic(){
    Type *t=get_type_refd_last();
    switch(t->typetype){
    case T_INT:
    case T_BOOL:
    case T_BSTR:
    case T_HSTR:
    case T_OSTR:
    case T_CSTR:
      return true;
      break;
    default:
      break;
    }
    return false;
  }

1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
  int Type::get_default_raw_fieldlength(){
    switch(typetype) {
    case T_REFD:
      return get_type_refd_last()->get_default_raw_fieldlength();
      break;
    case T_INT:
      return 8;
      break;
    case T_BOOL:
      return 1;
      break;
    case T_REAL:
      return 64;
      break;
    default:
      break;
    }
    return 0;
  }

Elemer Lelik's avatar
Elemer Lelik committed
1957
1958
1959
1960
1961
1962
1963
1964
1965
  int Type::get_raw_length(){
    if(!raw_checked) FATAL_ERROR("Type::get_raw_length()");
    if(raw_length_calculated) return raw_length;
    raw_length_calculated=true;
    switch(typetype) {
    case T_REFD:
      raw_length=get_type_refd()->get_raw_length();
      break;
    case T_BOOL:
1966
1967
    case T_INT:
    case T_REAL:
Elemer Lelik's avatar
Elemer Lelik committed
1968
      if(rawattrib) raw_length=rawattrib->fieldlength;
1969
      else raw_length=get_default_raw_fieldlength();
Elemer Lelik's avatar
Elemer Lelik committed
1970
1971
1972
1973
1974
      break;
    case T_BSTR:
    case T_HSTR:
    case T_OSTR:
    case T_CSTR:
1975
      if(rawattrib && rawattrib->fieldlength>0) raw_length=rawattrib->fieldlength;
Elemer Lelik's avatar
Elemer Lelik committed
1976
1977
1978
1979
1980
1981
1982
1983
      else raw_length=-1;
      break;
    case T_ENUM_T:
      if(rawattrib && rawattrib->fieldlength) raw_length=rawattrib->fieldlength;
      else{
        int min_bits=0;
        int max_val=u.enums.first_unused;
        for(size_t a=0;a<u.enums.eis->get_nof_eis();a++){
1984
          int val=u.enums.eis->get_ei_byIndex(a)->get_int_val()->get_val();
Elemer Lelik's avatar
Elemer Lelik committed
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
          if((max_val<0?-max_val:max_val)<(val<0?-val:val)) max_val=val;
        }
        if(max_val<0){ min_bits=1;max_val=-max_val;}
        while(max_val){ min_bits++; max_val/=2;}
        raw_length=min_bits;
      }
      break;
    case T_SEQ_T:
    case T_SET_T:
      raw_length=0;
      for(size_t i = 0; i < get_nof_comps(); i++){
        int l=0;
        CompField* cf=get_comp_byIndex(i);
        if(cf->get_is_optional()){
          raw_length=-1;
          return raw_length;
        }
2002
        l=cf->get_type()->get_type_refd_last()->get_raw_length();
Elemer Lelik's avatar
Elemer Lelik committed
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
        if(l==-1){
          raw_length=-1;
          return raw_length;
        }
        if(cf->get_type()->rawattrib
        && (cf->get_type()->rawattrib->pointerto
          || cf->get_type()->rawattrib->lengthto_num)){
          raw_length=-1;
          return raw_length;
        }
        raw_length+=l;
      }
      break;
    // TODO: case T_ANYTYPE: for get_raw_length needed ?
    case T_CHOICE_T:
      for(size_t i = 0; i < get_nof_comps(); i++){
        CompField *cf=get_comp_byIndex(i);
        int l=0;
2021
        l=cf->get_type()->get_type_refd_last()->get_raw_length();
Elemer Lelik's avatar
Elemer Lelik committed
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
        if(l==-1){
          raw_length=-1;
          return raw_length;
        }
        if(i){
          if(raw_length!=l){
            raw_length=-1;
            return raw_length;
          }
        }
        else raw_length=l;
      }
      break;
    default:
      raw_length=-1;
      break;
    }
    return raw_length;
  }

  /** \todo: add extra checks and warnings for unsupported attributes
   * e.g. when TAG refers to a record/set field which has union type */
  void Type::chk_raw()
  {
    bool self_ref = false;
    if (raw_checked) return;
    raw_checked = true;
    if (!enable_raw()) return;
    int restrlength=-1;
    if(sub_type)
      restrlength=(int)sub_type->get_length_restriction();
    if(restrlength!=-1){
      if(!rawattrib){
2055
        rawattrib=new RawAST(get_default_raw_fieldlength());
Elemer Lelik's avatar
Elemer Lelik committed
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
      }
      rawattrib->length_restrition=restrlength;
    }
    if(!rawattrib) return;
    switch(typetype) {
    case T_REFD:
      get_type_refd()->force_raw();
      if(rawattrib->fieldlength==0 && rawattrib->length_restrition!=-1){
        typetype_t basic_type=get_type_refd_last()->typetype;
        switch(basic_type){
          case T_BSTR:
            rawattrib->fieldlength=rawattrib->length_restrition;
            rawattrib->length_restrition=-1;
            break;
          case T_HSTR:
            rawattrib->fieldlength=rawattrib->length_restrition*4;
            rawattrib->length_restrition=-1;
            break;
          case T_OSTR:
            rawattrib->fieldlength=rawattrib->length_restrition*8;
            rawattrib->length_restrition=-1;
            break;
          case T_CSTR:
Elemer Lelik's avatar
Elemer Lelik committed
2079
          case T_USTR:
Elemer Lelik's avatar
Elemer Lelik committed
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
            rawattrib->fieldlength=rawattrib->length_restrition*8;
            rawattrib->length_restrition=-1;
            break;
          case T_SEQOF:
          case T_SETOF:
            rawattrib->fieldlength=rawattrib->length_restrition;
            rawattrib->length_restrition=-1;
            break;
          default:
            break;
        }
      }
      break;
    case T_CHOICE_T:
      if(rawattrib){
        size_t nof_comps = get_nof_comps();
        for (size_t i = 0; i < nof_comps; i++)
          get_comp_byIndex(i)->get_type()->force_raw();
        for(int c=0;c<rawattrib->taglist.nElements;c++){
          Identifier *idf=rawattrib->taglist.tag[c].fieldName;
          if(!has_comp_withName(*idf)){
            error("Invalid field name `%s' in RAW parameter TAG for type `%s'",
              idf->get_dispname().c_str(), get_typename().c_str());
            continue;
          }
          size_t fieldnum = get_comp_index_byName(*idf);
          for(int a=0;a<rawattrib->taglist.tag[c].nElements;a++){
            bool hiba=false;
            CompField *cf=get_comp_byIndex(fieldnum);
            Type *t=cf->get_type()->get_type_refd_last();
            for(int b=0;b<rawattrib->taglist.tag[c].keyList[a].
                  keyField->nElements;b++){
              Identifier *idf2=
                      rawattrib->taglist.tag[c].keyList[a].keyField->names[b];
              if(!t->is_secho()){
                error("Invalid fieldmember type in RAW parameter TAG"
                      " for field %s."
                      ,cf->get_name().get_dispname().c_str());
                hiba=true;
                break;
              }
              if(!t->has_comp_withName(*idf2)){
                error("Invalid field member name `%s' in RAW parameter TAG "
                  "for field `%s'", idf2->get_dispname().c_str(),
                  cf->get_name().get_dispname().c_str());
                hiba=true;
                break;
              }
              size_t comp_index=t->get_comp_index_byName(*idf2);
              CompField *cf2=t->get_comp_byIndex(comp_index);
              t=cf2->get_type()->get_type_refd_last();
            }
            if(!hiba){
              Error_Context cntx(this, "In Raw parmeter TAG");
              Value *v = rawattrib->taglist.tag[c].keyList[a].v_value;
              v->set_my_scope(get_my_scope());
              v->set_my_governor(t);
              t->chk_this_value_ref(v);
              self_ref = t->chk_this_value(v, 0, EXPECTED_CONSTANT,
                INCOMPLETE_NOT_ALLOWED, OMIT_NOT_ALLOWED, SUB_CHK);
              Value::valuetype_t vt = v->get_valuetype();
              if (vt == Value::V_ENUM || vt == Value::V_REFD) {
                Free(rawattrib->taglist.tag[c].keyList[a].value);
                rawattrib->taglist.tag[c].keyList[a].value =
                  mcopystr(v->get_single_expr().c_str());
              }
            }
          }
        }
      }
      break;
    case T_SEQ_T:
Elemer Lelik's avatar
Elemer Lelik committed
2152
    case T_SET_T: {
Elemer Lelik's avatar
Elemer Lelik committed
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
      if(rawattrib){
        size_t fieldnum;
        for(int c=0;c<rawattrib->taglist.nElements;c++) { // check TAG
          Identifier *idf=rawattrib->taglist.tag[c].fieldName;
          if(!has_comp_withName(*idf)){
            error("Invalid field name `%s' in RAW parameter TAG "
              "for type `%s'", idf->get_dispname().c_str(),
              get_typename().c_str());
            continue;
          }
          fieldnum=get_comp_index_byName(*idf);
          for(int a=0;a<rawattrib->taglist.tag[c].nElements;a++){
            bool hiba=false;
            CompField *cf=get_comp_byIndex(fieldnum);
            Type *t=cf->get_type()->get_type_refd_last();
            for(int b=0;b<rawattrib->taglist.tag[c].keyList[a].
                  keyField->nElements;b++){
              Identifier *idf2=
                        rawattrib->taglist.tag[c].keyList[a].keyField->names[b];
              if(!t->is_secho()){
                error("Invalid fieldmember type in RAW parameter TAG"
                      " for field %s."
                      ,cf->get_name().get_dispname().c_str());
                hiba=true;
                break;
              }
              if(!t->has_comp_withName(*idf2)){
                error("Invalid field member name `%s' in RAW parameter TAG "
                  "for field `%s'", idf2->get_dispname().c_str(),
                  cf->get_name().get_dispname().c_str());
                hiba=true;
                break;
              }
              size_t comp_index=t->get_comp_index_byName(*idf2);
              CompField *cf2=t->get_comp_byIndex(comp_index);
              t=cf2->get_type()->get_type_refd_last();
            }
            if(!hiba){
              Error_Context cntx(this, "In Raw parmeter TAG");
              Value *v = rawattrib->taglist.tag[c].keyList[a].v_value;
              v->set_my_scope(get_my_scope());
              v->set_my_governor(t);
              t->chk_this_value_ref(v);
              self_ref = t->chk_this_value(v, 0, EXPECTED_CONSTANT,
                INCOMPLETE_NOT_ALLOWED, OMIT_NOT_ALLOWED, SUB_CHK);
              Value::valuetype_t vt = v->get_valuetype();
              if (vt == Value::V_ENUM || vt == Value::V_REFD) {
                Free(rawattrib->taglist.tag[c].keyList[a].value);
                rawattrib->taglist.tag[c].keyList[a].value =
                  mcopystr(v->get_single_expr().c_str());
              }
            }
          }
        }
        for(int a=0; a<rawattrib->ext_bit_goup_num;a++){ // EXTENSION_BIT_GROUP
          Identifier *idf=rawattrib->ext_bit_groups[a].from;
          Identifier *idf2=rawattrib->ext_bit_groups[a].to;
          bool hiba=false;
          if(!has_comp_withName(*idf)){
            error("Invalid field name `%s' in RAW parameter "
              "EXTENSION_BIT_GROUP for type `%s'",
              idf->get_dispname().c_str(), get_typename().c_str());
            hiba=true;
          }
          if(!has_comp_withName(*idf2)){
            error("Invalid field name `%s' in RAW parameter "
              "EXTENSION_BIT_GROUP for type `%s'",
              idf2->get_dispname().c_str(), get_typename().c_str());
            hiba=true;
          }
          if(!hiba){
            size_t kezd=get_comp_index_byName(*idf);
            size_t veg=get_comp_index_byName(*idf2);
            if(kezd>veg){
              error("Invalid field order in RAW parameter "
                "EXTENSION_BIT_GROUP for type `%s': `%s', `%s'",
                get_typename().c_str(), idf->get_dispname().c_str(),
                idf2->get_dispname().c_str());
              hiba=true;
            }
          }
        }
        if(rawattrib->paddall!=XDEFDEFAULT){ // PADDALL
          for(size_t i = 0; i < get_nof_comps(); i++) {
            CompField *cfield=get_comp_byIndex(i);
            RawAST *field_rawattr=cfield->get_type()->rawattrib;
            if(field_rawattr==NULL){
2240
              Type *t=cfield->get_type();
Elemer Lelik's avatar
Elemer Lelik committed
2241
2242
              if(t->is_ref()) t=t->get_type_refd();
              while(!t->rawattrib && t->is_ref()) t=t->get_type_refd();
2243
              cfield->get_type()->rawattrib= new RawAST(t->rawattrib,cfield->get_type()->get_default_raw_fieldlength());
BenceJanosSzabo's avatar
BenceJanosSzabo committed
2244
              field_rawattr=cfield->get_type()->rawattrib;
Elemer Lelik's avatar
Elemer Lelik committed
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
            }
            if(field_rawattr->padding==0)
              field_rawattr->padding=rawattrib->padding;
            if(field_rawattr->prepadding==0)
              field_rawattr->prepadding=rawattrib->prepadding;
            if (field_rawattr->padding_pattern_length == 0 &&
                rawattrib->padding_pattern_length > 0) {
              Free(field_rawattr->padding_pattern);
              field_rawattr->padding_pattern =
                mcopystr(rawattrib->padding_pattern);
              field_rawattr->padding_pattern_length =
                rawattrib->padding_pattern_length;
            }
          }
        }
        if(rawattrib->fieldorder!=XDEFDEFAULT){ // FIELDORDER
          for(size_t i = 0; i < get_nof_comps(); i++) {
            CompField *cfield=get_comp_byIndex(i);
            RawAST *field_rawattr=cfield->get_type()->rawattrib;
            if(field_rawattr==NULL){
2265
              Type *t=cfield->get_type();
Elemer Lelik's avatar
Elemer Lelik committed
2266
2267
              if(t->is_ref()) t=t->get_type_refd();
              while(!t->rawattrib && t->is_ref()) t=t->get_type_refd();
2268
              cfield->get_type()->rawattrib= new RawAST(t->rawattrib,cfield->get_type()->get_default_raw_fieldlength());
BenceJanosSzabo's avatar
BenceJanosSzabo committed
2269
              field_rawattr=cfield->get_type()->rawattrib;
Elemer Lelik's avatar
Elemer Lelik committed
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
            }
            if(field_rawattr->fieldorder==XDEFDEFAULT)
              field_rawattr->fieldorder=rawattrib->fieldorder;
          }
        }
      }
      for(int a=0;a<rawattrib->presence.nElements;a++){  //PRESENCE
        Type *t=this;
        bool hiba=false;
        for(int b=0;b<rawattrib->presence.keyList[a].keyField->nElements;b++){
          Identifier *idf=rawattrib->presence.keyList[a].keyField->names[b];
          if(!t->is_secho()){
            error("Invalid fieldmember type in RAW parameter PRESENCE"
                  " for the record %s."
                  ,get_typename().c_str());
            hiba=true;
            break;
          }
          if(!t->has_comp_withName(*idf)){
            error("Invalid fieldname in RAW parameter"
                  " PRESENCE for the record %s: %s"
                  ,get_typename().c_str()
                  ,rawattrib->presence.keyList[a].keyField->names[b]
                                                  ->get_dispname().c_str());
            hiba=true;
            break;
          }
          t=t->get_comp_byName(*idf)->get_type()->get_type_refd_last();
        }
        if(!hiba){
          Error_Context cntx(this, "In Raw parameter PRESENCE");
          Value *v = rawattrib->presence.keyList[a].v_value;
          v->set_my_scope(get_my_scope());
          v->set_my_governor(t);
          t->chk_this_value_ref(v);
          self_ref = t->chk_this_value(v, 0, EXPECTED_CONSTANT,
            INCOMPLETE_NOT_ALLOWED, OMIT_NOT_ALLOWED, SUB_CHK);
          Value::valuetype_t vt = v->get_valuetype();
          if (vt == Value::V_ENUM || vt == Value::V_REFD) {
            Free(rawattrib->presence.keyList[a].value);
            rawattrib->presence.keyList[a].value =
              mcopystr(v->get_single_expr().c_str());
          }
        }
      }
Elemer Lelik's avatar
Elemer Lelik committed
2315
      int used_bits = 0; // number of bits used to store all previous fields
Elemer Lelik's avatar
Elemer Lelik committed
2316
2317
2318
2319
2320
2321
      for(size_t i = 0; i < get_nof_comps(); i++) { // field attributes
        CompField *cf = get_comp_byIndex(i);
        Type *field_type = cf->get_type();
        field_type->force_raw();
        RawAST *rawpar = field_type->rawattrib;
        if (rawpar) {
2322
2323
          const Identifier& field_id = cf->get_name();
          Type *field_type_last = field_type->get_type_refd_last();
Elemer Lelik's avatar
Elemer Lelik committed
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
          if (rawpar->prepadding != 0) {
            used_bits = (used_bits + rawpar->prepadding - 1) / rawpar->prepadding *
              rawpar->prepadding;
          }
          if (rawpar->intx && field_type_last->get_typetype() == T_INT) { // IntX
            if (used_bits % 8 != 0 &&
                (!rawattrib || rawattrib->fieldorder != XDEFMSB)) {
              error("Using RAW parameter IntX in a record/set with FIELDORDER "
                "set to 'lsb' is only supported if the IntX field starts at "
                "the beginning of a new octet. There are %d unused bits in the "
                "last octet before field %s.", 8 - (used_bits % 8),
                field_id.get_dispname().c_str());
            }
          }
2338
          else if(rawpar->fieldlength>0) {
Elemer Lelik's avatar
Elemer Lelik committed
2339
2340
2341
2342
2343
2344
            used_bits += rawpar->fieldlength;
          }
          if (rawpar->padding != 0) {
            used_bits = (used_bits + rawpar->padding - 1) / rawpar->padding *
              rawpar->padding;
          }
Elemer Lelik's avatar
Elemer Lelik committed
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379