Last sync 2016.04.01
[deliverable/titan.core.git] / compiler2 / Type.hh
1 /******************************************************************************
2 * Copyright (c) 2000-2016 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 *
8 * Contributors:
9 * Baji, Laszlo
10 * Balasko, Jeno
11 * Baranyi, Botond
12 * Beres, Szabolcs
13 * Bibo, Zoltan
14 * Cserveni, Akos
15 * Delic, Adam
16 * Forstner, Matyas
17 * Gecse, Roland
18 * Kovacs, Ferenc
19 * Raduly, Csaba
20 * Szabados, Kristof
21 * Szabo, Janos Zoltan – initial implementation
22 * Szalai, Gabor
23 * Tatarka, Gabor
24 * Zalanyi, Balazs Andor
25 *
26 ******************************************************************************/
27 #ifndef _Common_Type_HH
28 #define _Common_Type_HH
29
30 #include "Setting.hh"
31 #include "Code.hh"
32 #include "Int.hh"
33 #include "subtype.hh"
34 #include "ttcn3/rawASTspec.h"
35 #include "ttcn3/RawAST.hh"
36 #include "ttcn3/TextAST.hh"
37 #include "ttcn3/BerAST.hh"
38 #include "ttcn3/JsonAST.hh"
39 #include <float.h>
40
41 class XerAttributes;
42 enum namedbool { INCOMPLETE_NOT_ALLOWED = 0, INCOMPLETE_ALLOWED = 1,
43 NO_SUB_CHK = 0, SUB_CHK = 2, OMIT_NOT_ALLOWED = 0, OMIT_ALLOWED = 3,
44 ANY_OR_OMIT_NOT_ALLOWED = 0, ANY_OR_OMIT_ALLOWED = 4,
45 NOT_IMPLICIT_OMIT = 0, IMPLICIT_OMIT = 5, NOT_STR_ELEM = 0, IS_STR_ELEM = 6
46 };
47
48 namespace Asn {
49 // not defined here
50 class Tags;
51 class Tag;
52 class TagCollection;
53 class Block;
54 class OC_defn;
55 class TableConstraint;
56 } // namespace Asn
57
58 namespace Ttcn {
59 // not defined here
60 class ArrayDimension;
61 class FieldOrArrayRefs;
62 class Template;
63 class Definitions;
64 class Definition;
65 class SingleWithAttrib;
66 class MultiWithAttrib;
67 class WithAttribPath;
68 class FormalPar;
69 class FormalParList;
70 class Reference;
71 class PortTypeBody;
72 class Def_Type;
73 class Ref_pard;
74 } // namespace Ttcn
75
76 // not defined here
77 class JSON_Tokenizer;
78
79 namespace Common {
80
81 /**
82 * \ingroup AST
83 *
84 * \defgroup AST_Type Type
85 * @{
86 */
87 using Asn::Tag;
88 using Asn::Tags;
89 using Asn::TagCollection;
90 using Asn::Block;
91 using Asn::OC_defn;
92 using Asn::TableConstraint;
93 using Ttcn::Template;
94
95 class Type;
96
97 // not defined here
98 class Identifier;
99 class Constraints;
100 class Value;
101 class CompField;
102 class CompFieldMap;
103 class EnumItem;
104 class EnumItems;
105 class ExcSpec;
106 class NamedValues;
107 class CTs_EE_CTs;
108 class TypeSet;
109 class TypeChain;
110 class TypeCompatInfo;
111 class ComponentTypeBody;
112 class SignatureParam;
113 class SignatureParamList;
114 class SignatureExceptions;
115 class CodeGenHelper;
116
117 /**
118 * This is the base class for types.
119 */
120 class Type : public Governor {
121 public:
122
123 /** type of type */
124 enum typetype_t {
125 /** Undefined.
126 * There is never a Type object with this typetype.
127 * It may be returned by Value::get_expr_returntype() or
128 * ValueRange::get_expr_returntype(). */
129 T_UNDEF,
130 T_ERROR, /**< erroneous (e.g. nonexistent reference) */
131 T_NULL, /**< null (ASN.1) */
132 T_BOOL, /**< boolean */
133 T_INT, /**< integer */
134 T_INT_A, /**< integer / ASN */
135 T_REAL, /**< real/float */
136 T_ENUM_A, /**< enumerated / ASN */
137 T_ENUM_T, /**< enumerated / TTCN */
138 T_BSTR, /**< bitstring */
139 T_BSTR_A, /**< bitstring */
140 T_HSTR, /**< hexstring (TTCN-3) */
141 T_OSTR, /**< octetstring */
142 T_CSTR, /**< charstring (TTCN-3) */
143 T_USTR, /**< universal charstring (TTCN-3) */
144 T_UTF8STRING, /**< UTF8String (ASN.1) */
145 T_NUMERICSTRING, /**< NumericString (ASN.1) */
146 T_PRINTABLESTRING, /**< PrintableString (ASN.1) */
147 T_TELETEXSTRING, /**< TeletexString (ASN.1) */
148 T_VIDEOTEXSTRING, /**< VideotexString (ASN.1) */
149 T_IA5STRING, /**< IA5String (ASN.1) */
150 T_GRAPHICSTRING, /**< GraphicString (ASN.1) */
151 T_VISIBLESTRING, /**< VisibleString (ASN.1) */
152 T_GENERALSTRING, /**< GeneralString (ASN.1) */
153 T_UNIVERSALSTRING, /**< UniversalString (ASN.1) */
154 T_BMPSTRING, /**< BMPString (ASN.1) */
155 T_UNRESTRICTEDSTRING, /**< UnrestrictedCharacterString (ASN.1) */
156 T_UTCTIME, /**< UTCTime (ASN.1) */
157 T_GENERALIZEDTIME, /**< GeneralizedTime (ASN.1) */
158 T_OBJECTDESCRIPTOR, /** Object descriptor, a kind of string (ASN.1) */
159 T_OID, /**< object identifier */
160 T_ROID, /**< relative OID (ASN.1) */
161 T_CHOICE_A, /**< choice /ASN, uses u.secho */
162 T_CHOICE_T, /**< union /TTCN, uses u.secho */
163 T_SEQOF, /**< sequence (record) of */
164 T_SETOF, /**< set of */
165 T_SEQ_A, /**< sequence /ASN, uses u.secho */
166 T_SEQ_T, /**< record /TTCN, uses u.secho */
167 T_SET_A, /**< set /ASN, uses u.secho */
168 T_SET_T, /**< set /TTCN, uses u.secho */
169 T_OCFT, /**< ObjectClassFieldType (ASN.1) */
170 T_OPENTYPE, /**< open type (ASN.1) */
171 T_ANY, /**< ANY (deprecated ASN.1) */
172 T_EXTERNAL, /**< %EXTERNAL (ASN.1) */
173 T_EMBEDDED_PDV, /**< EMBEDDED PDV (ASN.1) */
174 T_REFD, /**< referenced */
175 T_REFDSPEC, /**< special referenced (by pointer, not by name) */
176 T_SELTYPE, /**< selection type (ASN.1) */
177 T_VERDICT, /**< verdict type (TTCN-3) */
178 T_PORT, /**< port type (TTCN-3) */
179 T_COMPONENT, /**< component type (TTCN-3) */
180 T_ADDRESS, /**< address type (TTCN-3) */
181 T_DEFAULT, /**< default type (TTCN-3) */
182 T_ARRAY, /**< array (TTCN-3), uses u.array */
183 T_SIGNATURE, /**< signature (TTCN-3) */
184 T_FUNCTION, /**< function reference (TTCN-3) */
185 T_ALTSTEP, /**< altstep reference (TTCN-3) */
186 T_TESTCASE, /**< testcase reference (TTCN-3) */
187 T_ANYTYPE, /**< anytype (TTCN-3) */
188 // WRITE new type before this line
189 T_LAST
190 }; //DO NOT FORGET to update type_as_string[] in Type.cc
191
192 /**
193 * Enumeration to represent message encoding types.
194 */
195 enum MessageEncodingType_t {
196 CT_UNDEF, /**< undefined/unused */
197 CT_BER, /**< ASN.1 BER */
198 CT_PER, /**< ASN.1 PER (not supported yet) */
199 CT_RAW, /**< TTCN-3 RAW */
200 CT_TEXT, /**< TTCN-3 TEXT */
201 CT_XER, /**< ASN.1 XER */
202 CT_JSON, /**< TTCN-3 JSON */
203 CT_CUSTOM /**< user defined encoding */
204 };
205
206 /** selector for value checking algorithms */
207 enum expected_value_t {
208 /** the value must be known at compile time (i.e. it may refer
209 * to a TTCN-3 constant or an ASN.1 value) */
210 EXPECTED_CONSTANT,
211 /** the value must be static at execution time, but may be
212 * unknown at compilation time (i.e. it may refer to a TTCN-3
213 * module parameter as well) */
214 EXPECTED_STATIC_VALUE,
215 /** the value is known only at execution time (i.e. it may refer
216 * to a variable in addition to static values) */
217 EXPECTED_DYNAMIC_VALUE,
218 /** the reference may point to a dynamic value or a template
219 * (this selector is also used in template bodies where the
220 * variable references are unaccessible because of the scope
221 * hierarchy) */
222 EXPECTED_TEMPLATE
223 };
224
225 /** Enumeration to represent the owner of the type.
226 * Also align OT_UNKNOWN at line 200. */
227 enum TypeOwner_t {
228 OT_UNKNOWN,
229 OT_TYPE_ASS, ///< ASN.1 type assignment (Ass_T)
230 OT_VAR_ASS, ///< ASN.1 variable assignment (Ass_V)
231 OT_VSET_ASS, ///< ASN.1 value set assignment (Ass_VS)
232 OT_TYPE_FLD, ///< ASN.1 TypeFieldSpec (FieldSpec_T)
233 OT_FT_V_FLD, ///< ASN.1 FixedTypeValueFieldSpec (FieldSpec_V_FT)
234 OT_TYPE_MAP, ///< TTCN-3 TypeMapping
235 OT_TYPE_MAP_TARGET, ///< TTCN-3 TypeMappingTarget
236 OT_TYPE_DEF, ///< TTCN-3 type definition (Def_Type)
237 OT_CONST_DEF, ///< TTCN-3 constant definition (DefConst, Def_ExtCOnst)
238 OT_MODPAR_DEF, ///< TTCN-3 module parameter definition (Def_Modulepar)
239 OT_VAR_DEF, ///< TTCN-3 variable definition (Def_Var)
240 OT_VARTMPL_DEF, ///< TTCN-3 var template definition (Def_Var_Template)
241 OT_FUNCTION_DEF, ///< TTCN-3 function (Def_Function, Def_ExtFunction)
242 OT_TEMPLATE_DEF, ///< TTCN-3 template definition (Def_Template)
243 OT_ARRAY, ///< another Type: TTCN-3 array(T_ARRAY)
244 OT_RECORD_OF, ///< another Type (T_SEQOF, T_SETOF), ASN.1 or TTCN-3
245 OT_FUNCTION, ///< another Type: TTCN-3 function (T_FUNCTION)
246 OT_SIGNATURE, ///< another Type: TTCN-3 signature (T_SIGNATURE)
247 OT_REF, ///< another Type (T_REFD)
248 OT_REF_SPEC, ///< another Type (T_REFDSPEC)
249 OT_COMP_FIELD, ///< a field of a record/set/union (CompField)
250 OT_COMPS_OF, ///< ASN.1 "COMPONENTS OF" (CT_CompsOf)
251 OT_FORMAL_PAR, ///< formal parameter (FormalPar), TTCN-3
252 OT_TYPE_LIST, ///< TypeList for a 'with "extension anytype t1,t2..." '
253 OT_FIELDSETTING, ///< ASN.1 FieldSetting_Type
254 OT_SELTYPE, ///< another Type (T_SELTYPE), ASN.1 selection type
255 OT_OCFT, ///< another Type (T_OCFT), ASN.1 obj.class field type
256 OT_TEMPLATE_INST, ///< a TemplateInstance (TTCN-3)
257 OT_RUNSON_SCOPE, ///< a RunsOnScope (TTCN-3)
258 OT_EXC_SPEC, ///< exception Specification (ExcSpec)
259 OT_SIG_PAR, ///< signature parameter (SignatureParam)
260 OT_POOL ///< It's a pool type, owned by the type pool
261 };
262
263 /** Returns the display string of \a encoding_type. */
264 static const char *get_encoding_name(MessageEncodingType_t encoding_type);
265 /** Returns a pool type that represents the encoded stream of the given
266 * \a encoding_type. */
267 static Type *get_stream_type(MessageEncodingType_t encoding_type, int stream_variant=0);
268
269 enum truth {
270 No, Maybe, Yes
271 };
272
273 private:
274 typetype_t typetype;
275 bool tags_checked;
276 bool tbl_cons_checked;
277 bool text_checked;
278 bool json_checked;
279 bool raw_parsed;
280 bool raw_checked;
281 bool xer_checked;
282 bool raw_length_calculated;
283 bool has_opentypes;
284 bool opentype_outermost;
285 bool code_generated;
286 bool embed_values_possible;
287 bool use_nil_possible;
288 bool use_order_possible;
289 int raw_length;
290 Type *parent_type;
291 Tags *tags;
292 Constraints *constraints;
293 /// The type's attributes (with context)
294 Ttcn::WithAttribPath* w_attrib_path;
295 /** A copy of all the AT_ENCODEs */
296 Ttcn::WithAttribPath* encode_attrib_path;
297 RawAST *rawattrib;
298 TextAST *textattrib;
299 XerAttributes *xerattrib;
300 BerAST *berattrib;
301 JsonAST *jsonattrib;
302
303 vector<SubTypeParse> *parsed_restr; ///< parsed subtype restrictions are stored here until they are moved to the sub_type member
304 SubType *sub_type; ///< effective/aggregate subtype of this type, NULL if neither inherited nor own subtype restrictions exist
305
306 string encoding_str; // needed by codegen for encvalue() and decvalue()
307 string decoding_str;
308 bool coding_by_function; // false - coding attribute is set, true - coding via coding function
309 /** What kind of AST element owns the type.
310 * It may not be known at creation type, so it's initially OT_UNKNOWN.
311 * We want this information so we don't have to bother with XER
312 * if the type is an ASN.1 construct, or it's the type in a "runs on" scope,
313 * the type of a variable declaration/module par/const, etc. */
314 TypeOwner_t ownertype;
315 Node *owner;
316
317 union {
318 struct {
319 Block *block;
320 NamedValues *nvs;
321 } namednums;
322 struct {
323 EnumItems *eis; ///< Final set of enum items
324 Int first_unused; ///< First unused >=0 value (for UNKNOWN_VALUE)
325 Int second_unused; ///< Second unused >=0 value (for UNBOUND_VALUE)
326 Block *block; ///< ASN.1 block to be parsed
327 EnumItems *eis1; ///< First set of enum items before the ellipsis
328 bool ellipsis; ///< true if there was an ellipsis, false otherwise
329 ExcSpec *excSpec; ///< Exception specification
330 EnumItems *eis2; ///< Second set of enum items after the ellipsis
331 map<string, size_t> *eis_by_name;
332 } enums;
333 struct {
334 CompFieldMap *cfm;
335 Block *block; ///< Unparsed block; will be 0 after parse_block_...()
336 CTs_EE_CTs *ctss;
337 bool tr_compsof_ready;
338 bool component_internal;
339 map<string, size_t> *field_by_name;
340 OC_defn *oc_defn; /**< link to... */
341 const Identifier *oc_fieldname; /**< link to... */
342 const TableConstraint *my_tableconstraint; /**< link to... */
343 bool has_single_charenc; /**< Has a single character-encodable field
344 * with the UNTAGGED encoding instruction.
345 * X693amd1 32.2.2 applies to the field. */
346 } secho; /**< data for T_(SEQUENCE|SET_CHOICE)_[AT] */
347 struct {
348 Type *ofType;
349 bool component_internal;
350 } seof; /**< data for SEQUENCE OF/SET OF */
351 struct {
352 Reference *ref;
353 Type *type_refd; /**< link to... */
354 OC_defn *oc_defn; /**< link to... */
355 const Identifier *oc_fieldname; /**< link to... */
356 bool component_internal;
357 } ref;
358 struct {
359 Identifier *id;
360 Type *type;
361 Type *type_refd;
362 } seltype;
363 struct {
364 Type *element_type;
365 Ttcn::ArrayDimension *dimension;
366 bool in_typedef;
367 bool component_internal;
368 } array;
369 Ttcn::PortTypeBody *port;
370 ComponentTypeBody *component;
371 Type *address; /**< link to... */
372 struct {
373 SignatureParamList *parameters;
374 Type *return_type;
375 bool no_block;
376 bool component_internal;
377 SignatureExceptions *exceptions;
378 } signature;
379 struct {
380 Ttcn::FormalParList *fp_list;
381 struct {
382 bool self;
383 Ttcn::Reference *ref;
384 Type *type; // useful only after check
385 } runs_on;
386 union {
387 Type *return_type;
388 struct {
389 Ttcn::Reference *ref;
390 Type *type; // useful only after check
391 } system;
392 };
393 bool returns_template;
394 template_restriction_t template_restriction;
395 bool is_startable;
396 } fatref;
397 } u;
398 static const char* type_as_string[];
399
400 /** True if chk() has finished running.
401 * Prevents force_raw() from running chk_raw(), chk_text() or chk_json() on unchecked types. */
402 bool chk_finished;
403
404 /** Signifies that this type is an instance of an ASN.1 parameterized type.
405 * It will not have its own segment and reference generated in the JSON schema,
406 * its schema segment will be generated as an embedded type's would. */
407 bool pard_type_instance;
408
409 /** Copy constructor, for the use of Type::clone() only. */
410 Type(const Type& p);
411 /** Assignment disabled */
412 Type& operator=(const Type& p);
413 /** Set fields to their default values */
414 void init();
415 /** Free up resources */
416 void clean_up();
417 /** Returns the default tag of the type. */
418 Tag *get_default_tag();
419 /** Returns the number in UNIVERSAL tag class that belongs to ASN.1 type
420 * type \a p_tt. In case of invalid argument -1 is returned */
421 static int get_default_tagnumber(typetype_t p_tt);
422 /** Container for the allocated tags that do not belong to a particular
423 * Type object */
424 static map<typetype_t, Tag> *default_tags;
425 static void destroy_default_tags();
426 /** Container for the allocated pool types */
427 static map<typetype_t, Type> *pooltypes;
428 /** Drops the elements of \a pooltypes */
429 static void destroy_pooltypes();
430 /** Returns the TTCN-3 equivalent of \a p_tt. */
431 static typetype_t get_typetype_ttcn3(typetype_t p_tt);
432
433 public:
434 /** @name Constructors
435 * @{ */
436 /// Construct a predefined type (including anytype and address)
437 Type(typetype_t p_tt);
438 /// Construct a TTCN enumerated type
439 Type(typetype_t p_tt, EnumItems *p_eis);
440 /** Construct an ASN.1 enum, sequence, set, choice, integer with
441 * named numbers, or a bitstring with named bits */
442 Type(typetype_t p_tt, Block *p_block);
443 /// Construct an ASN.1 enum, with or without extension
444 Type(typetype_t p_tt,
445 EnumItems *p_eis1, bool p_ellipsis, EnumItems *p_eis2);
446 /// Construct a TTCN3 sequence, set or choice
447 Type(typetype_t p_tt, CompFieldMap *p_cfm);
448 /** Construct a type with an embedded type: a record-of, set-of,
449 * or a special reference (involved in: ASN.1 table constraint,
450 * TTCN3 (ext)const definition, module parameter, variable instance) */
451 Type(typetype_t p_tt, Type *p_type);
452 /// Create an ASN.1 selection type
453 Type(typetype_t p_tt, Identifier *p_id, Type *p_type);
454 /// ASN.1 ObjectClassFieldType
455 Type(typetype_t p_tt, Type *p_type, OC_defn *p_oc_defn,
456 const Identifier *p_id);
457 /// Create a TTCN3 array
458 Type(typetype_t p_tt, Type *p_type, Ttcn::ArrayDimension *p_dim,
459 bool p_in_typedef);
460 /// Create an ASN.1 open type
461 Type(typetype_t p_tt, OC_defn *p_oc_defn, const Identifier *p_id);
462 /// Create a reference
463 Type(typetype_t p_tt, Reference *p_ref);
464 /// Create a TTCN3 port type
465 Type(typetype_t p_tt, Ttcn::PortTypeBody *p_pb);
466 /// Create a TTCN3 component type
467 Type(typetype_t p_tt, ComponentTypeBody *p_cb);
468 /// Create a TTCN3 signature
469 Type(typetype_t p_tt, SignatureParamList *p_params, Type *p_returntype,
470 bool p_noblock, SignatureExceptions *p_exceptions);
471 /// Create a TTCN3 function reference
472 Type(typetype_t p_tt,Ttcn::FormalParList *p_params,
473 Ttcn::Reference* p_runs_on_ref, bool p_runs_on_self,
474 Type *p_returntype, bool p_returns_template,
475 template_restriction_t p_template_restriction);
476 /// Create a TTCN3 altstep
477 Type(typetype_t p_tt,Ttcn::FormalParList *p_params,
478 Ttcn::Reference* p_runs_on_ref, bool p_runs_on_self);
479 /// Create a TTCN3 testcase
480 Type(typetype_t p_tt,Ttcn::FormalParList *p_params,
481 Ttcn::Reference* p_runs_on_ref, Ttcn::Reference *p_system_ref);
482 /** @} */
483 virtual ~Type();
484 /** This function must be called to clean up the pool types,
485 * tags, etc. It is called by main() */
486 static void free_pools();
487 /** Create a (partial) copy of the object */
488 virtual Type* clone() const;
489 /** Return the type of type. */
490 typetype_t get_typetype() const { return typetype; }
491 /** Returns the TTCN-3 equivalent of \a typetype. */
492 typetype_t get_typetype_ttcn3() const
493 { return get_typetype_ttcn3(typetype); }
494 /** Returns a simple/built-in type from the pool */
495 static Type* get_pooltype(typetype_t p_typetype);
496 /** Returns whether the type is defined in an ASN.1 module. */
497 bool is_asn1() const;
498 /** Returns true if it is a type reference. */
499 bool is_ref() const;
500 /** Returns true if it is a Sequence, Set or Choice. */
501 bool is_secho() const;
502 /** Returns true if this is a character-encodable type.
503 * Being character-encodable is a requirement for a type to be
504 * encoded as an XML attribute. */
505 truth is_charenc();
506 /** Return true if at least one abstract value of the type
507 * has an empty "ExtendedXMLValue" encoding (only possible with EXER).
508 * Possible for record/set when all components are optional,
509 * and record-of/set-of when 0 length is not forbidden. */
510 bool has_empty_xml();
511 /** Returns whether \a this is a sequence-of/record-of or set-of type. */
512 bool is_seof() const { return typetype == T_SEQOF || typetype == T_SETOF; }
513 /** Returns the \a sub_type member */
514 SubType* get_sub_type() const { return sub_type; }
515 /** If this is a reference, returns the referenced type.
516 * Otherwise, it's a fatal error. */
517 Type* get_type_refd(ReferenceChain *refch=0);
518 /** Walk through all references to the referenced type */
519 Type* get_type_refd_last(ReferenceChain *refch=0);
520 /** Returns the type of the field, which is referenced by \a subrefs from
521 * \a this. It checks the array indices against \a expected_index. In case
522 * of error NULL is returned.
523 * Special case: if \a interrupt_if_optional is true then return NULL if an
524 * optional field has been reached. Using this bool parameter it can be
525 * checked if a referenced field is on an optional path (used by template
526 * restriction checking code) */
527 Type *get_field_type(Ttcn::FieldOrArrayRefs *subrefs,
528 expected_value_t expected_index, ReferenceChain *refch = 0,
529 bool interrupt_if_optional = false);
530 /** subrefs must point to an existing field, get_field_type() should be used
531 * to check. subrefs_array will be filled with the indexes of the fields,
532 * type_array will be filled with types whose field indexes were collected,
533 * if an invalid index is encountered false will be returned */
534 bool get_subrefs_as_array(const Ttcn::FieldOrArrayRefs *subrefs,
535 dynamic_array<size_t>& subrefs_array, dynamic_array<Type*>& type_array);
536 /** Returns whether the last field referenced by \a subrefs is an optional
537 * record/SEQUENCE or set/SET field. It can be used only after a successful
538 * semantic check (e.g. during code generation) or the behaviour will be
539 * unpredictable. */
540 bool field_is_optional(Ttcn::FieldOrArrayRefs *subrefs);
541 /** Returns whether this type instance is the type of an optional field. */
542 bool is_optional_field() const;
543 virtual void set_fullname(const string& p_fullname);
544 /** Sets the internal pointer my_scope to \a p_scope. */
545 virtual void set_my_scope(Scope *p_scope);
546 /** Checks the type (including tags). */
547 virtual void chk();
548 /** Return whether the two typetypes are compatible. Sometimes, this is
549 * just a question of \p p_tt1 == \p p_tt2. When there are multiple
550 * typetypes for a type (e.g. T_ENUM_A and T_ENUM_T) then all
551 * combinations of those are compatible. */
552 static bool is_compatible_tt_tt(typetype_t p_tt1, typetype_t p_tt2,
553 bool p_is_asn11, bool p_is_asn12);
554 /** Returns whether the type is compatible with \a p_tt. Used if the
555 * other value is unfoldable, but we can determine its expr_typetype.
556 * Note: The compatibility relation is asymmetric. The function returns
557 * true if the set of possible values in \a p_type is a subset of
558 * possible values in \a this. */
559 bool is_compatible_tt(typetype_t p_tt, bool p_is_asn1);
560 /** Returns whether this type is compatible with \a p_type. Note: The
561 * compatibility relation is asymmetric. The function returns true if
562 * the set of possible values in \a p_type is a subset of possible values
563 * in \a this. It returns false if the two types cannot be compatible
564 * ever. If the two types are compatible, but they need additional
565 * "type" conversion code generated with run-time checks \p p_info will
566 * provide more information. \p p_info is used to collect type
567 * information to report more precise errors. \p p_left_chain and
568 * \p p_right_chain are there to prevent infinite recursion.
569 * \p p_left_chain contains the type chain of the left operand from the
570 * "root" type to this point in the type's structure. \p p_right_chain
571 * is the same for the right operand.
572 * \p p_is_inline_template indicates that the conversion is requested for an
573 * inline template. Type conversion code is not needed in this case. */
574 bool is_compatible(Type *p_type, TypeCompatInfo *p_info,
575 TypeChain *p_left_chain = NULL,
576 TypeChain *p_right_chain = NULL,
577 bool p_is_inline_template = false);
578 /** Check if the restrictions of a T_SEQOF/T_SETOF are "compatible" with
579 * the given type \a p_type. Can be called only as a T_SEQOF/T_SETOF.
580 * Currently, used for structured types only. \a p_type can be any kind
581 * of structured type. */
582 bool is_subtype_length_compatible(Type *p_type);
583 /** Check if it's a structured type. Return true if the current type is a
584 * structured type, false otherwise. */
585 bool is_structured_type() const;
586 /** returns the type as a string */
587 virtual const char* asString() const;
588 static const char* asString(typetype_t type);
589
590 private:
591 /** Helper functions for is_compatible(). These functions can be called
592 * only for a Type that the name suggests. \p p_type is the Type we're
593 * checking compatibility against. \p p_info is used to collect type
594 * information to report more precise errors. \p p_left_chain and
595 * \p p_right_chain are there to prevent infinite recursion.
596 * \p p_left_chain contains the type chain of the left operand from the
597 * "root" type to this point in the type's structure. \p p_right_chain
598 * is the same for the right operand.
599 * \p p_is_inline_template indicates that the conversion is requested for an
600 * inline template. Type conversion code is not needed in this case. */
601 bool is_compatible_record(Type *p_type, TypeCompatInfo *p_info,
602 TypeChain *p_left_chain = NULL,
603 TypeChain *p_right_chain = NULL,
604 bool p_is_inline_template = false);
605 bool is_compatible_record_of(Type *p_type, TypeCompatInfo *p_info,
606 TypeChain *p_left_chain = NULL,
607 TypeChain *p_right_chain = NULL,
608 bool p_is_inline_template = false);
609 bool is_compatible_set(Type *p_type, TypeCompatInfo *p_info,
610 TypeChain *p_left_chain = NULL,
611 TypeChain *p_right_chain = NULL,
612 bool p_is_inline_template = false);
613 bool is_compatible_set_of(Type *p_type, TypeCompatInfo *p_info,
614 TypeChain *p_left_chain = NULL,
615 TypeChain *p_right_chain = NULL,
616 bool p_is_inline_template = false);
617 bool is_compatible_array(Type *p_type, TypeCompatInfo *p_info,
618 TypeChain *p_left_chain = NULL,
619 TypeChain *p_right_chain = NULL,
620 bool p_is_inline_template = false);
621 bool is_compatible_choice_anytype(Type *p_type, TypeCompatInfo *p_info,
622 TypeChain *p_left_chain = NULL,
623 TypeChain *p_right_chain = NULL,
624 bool p_is_inline_template = false);
625 public:
626 /** Returns whether this type is identical to \a p_type from TTCN-3 point
627 * of view. Note: This relation is symmetric. The function returns true
628 * only if the sets of possible values are the same in both types. */
629 bool is_identical(Type *p_type);
630 /** Tasks: Decides whether the type needs automatic tagging, performs the
631 * COMPONENTS OF transformations (recursively) and adds the automatic
632 * tags. */
633 void tr_compsof(ReferenceChain *refch = 0);
634 /** Returns whether the T_FUNCTION is startable.
635 * @pre typetype is T_FUNCTION, or else FATAL_ERROR occurs. */
636 bool is_startable();
637
638 /** Returns true if this is a list type (string, rec.of, set.of or array */
639 bool is_list_type(bool allow_array);
640
641 /** Sets the encoding or decoding function for the type (in case of custom
642 * encoding). */
643 void set_coding_function(bool encode, const string& function_name);
644 void chk_coding(bool encode, bool delayed = false);
645 bool is_coding_by_function() const;
646 const string& get_coding(bool encode) const;
647 private:
648 static MessageEncodingType_t get_enc_type(const Ttcn::SingleWithAttrib& enc);
649
650 void chk_Int_A();
651 void chk_Enum_A();
652 void chk_Enum_item(EnumItem *ei, bool after_ellipsis,
653 map<Int, EnumItem>& value_map);
654 void chk_Enum_T();
655 void chk_BStr_A();
656 void chk_SeCho_T();
657 void chk_Choice_A();
658 void chk_Se_A();
659 void chk_SeOf();
660 void chk_refd();
661 void chk_seltype();
662 void chk_Array();
663 void chk_Signature();
664 void chk_Fat();
665 public:
666 /** Checks whether the type can be the TTCN-3 address type. Not allowed:
667 * the default type, references pointing to port types, component types
668 * and signatures */
669 void chk_address();
670 /** Checks whether the type can be a component of another type definition
671 * (e.g. field of a structured type, parameter/return type/exception of a
672 * signature).
673 * Not allowed types: ports, signatures.
674 * Default type is allowed only within structured types.
675 * The text for the end of the error message is passed as parameter.
676 */
677 void chk_embedded(bool default_allowed, const char *error_msg);
678 /** Checks for circular references within embedded types */
679 void chk_recursions(ReferenceChain& refch);
680 /** Checks that the structured type does not have fields
681 * with the name of its definition.
682 */
683 void chk_constructor_name(const Identifier& p_id);
684 bool chk_startability();
685 /** Checks if it can be a return type */
686 void chk_as_return_type(bool as_value, const char* what);
687 private:
688 void parse_block_Int();
689 void parse_block_Enum();
690 void parse_block_BStr();
691 void parse_block_Choice();
692 void parse_block_Se();
693 int get_length_multiplier();
694 void parse_attributes();
695 void chk_raw();
696 /** If the type does not have a rawattrib, create one. */
697 void force_raw();
698 void chk_text();
699 void chk_text_matching_values(textAST_matching_values *matching_values,
700 const char *attrib_name);
701 /** If the type does not have a textattrib, create one. */
702 void force_text();
703
704 void chk_json();
705 void chk_json_default();
706 /** If the type does not have a jsonattrib, create one. */
707 void force_json();
708
709 void chk_xer();
710 void chk_xer_any_attributes();
711 void chk_xer_any_element();
712 void chk_xer_attribute();
713 void chk_xer_dfe();
714 Value *new_value_for_dfe(Type *last, const char *dfe_str);
715 void target_of_text(string& text);
716 void chk_xer_embed_values(int num_attributes);
717 void chk_xer_text();
718 void chk_xer_untagged();
719 void chk_xer_use_nil();
720 void chk_xer_use_order(int num_attributes);
721 void chk_xer_use_type();
722 void chk_xer_use_union();
723
724 bool is_root_basic();
725 int get_raw_length();
726 public:
727 void set_parent_type(Type *p_parent_type) {parent_type=p_parent_type;}
728 Type* get_parent_type() const {return parent_type;}
729 void set_has_opentypes() {has_opentypes=true;}
730 bool get_has_opentypes() const {return has_opentypes;}
731 void set_opentype_outermost() {opentype_outermost=true;}
732 bool get_is_opentype_outermost() const {return opentype_outermost;}
733 /** If \a value is an undef lowerid, then this member decides
734 * whether it is a reference or a lowerid value (e.g., enum, named
735 * number). */
736 void chk_this_value_ref(Value *value);
737 bool chk_this_value(Value *value, Common::Assignment *lhs,
738 expected_value_t expected_value, namedbool incomplete_allowed,
739 namedbool omit_allowed, namedbool sub_chk,
740 namedbool implicit_omit = NOT_IMPLICIT_OMIT,
741 namedbool str_elem = NOT_STR_ELEM);
742 /** Checks the given referenced value */
743 bool chk_this_refd_value(Value *value, Common::Assignment *lhs,
744 expected_value_t expected_value, ReferenceChain *refch=0,
745 namedbool str_elem = NOT_STR_ELEM);
746 /** Checks the given invocation */
747 void chk_this_invoked_value(Value *value, Common::Assignment *lhs,
748 expected_value_t expected_value);
749 private:
750 void chk_this_value_Null(Value *value);
751 void chk_this_value_Bool(Value *value);
752 void chk_this_value_Int(Value *value);
753 void chk_this_value_Int_A(Value *value);
754 void chk_this_value_Real(Value *value);
755 void chk_this_value_Enum(Value *value);
756 void chk_this_value_BStr(Value *value);
757 void chk_this_value_namedbits(Value *value);
758 void chk_this_value_BStr_A(Value *value);
759 void chk_this_value_HStr(Value *value);
760 void chk_this_value_OStr(Value *value);
761 void chk_this_value_CStr(Value *value);
762 void chk_this_value_OID(Value *value);
763 void chk_this_value_ROID(Value *value);
764 void chk_this_value_Any(Value *value);
765 bool chk_this_value_Choice(Value *value, Common::Assignment *lhs,
766 expected_value_t expected_value, namedbool incomplete_allowed,
767 namedbool implicit_omit = NOT_IMPLICIT_OMIT);
768 bool chk_this_value_Se(Value *value, Common::Assignment *lhs,
769 expected_value_t expected_value, namedbool incomplete_allowed,
770 namedbool implicit_omit = NOT_IMPLICIT_OMIT);
771 bool chk_this_value_Se_T(Value *value, Common::Assignment *lhs,
772 expected_value_t expected_value, namedbool incomplete_allowed,
773 namedbool implicit_omit = NOT_IMPLICIT_OMIT);
774 bool chk_this_value_Seq_T(Value *value, Common::Assignment *lhs,
775 expected_value_t expected_value, namedbool incomplete_allowed,
776 namedbool implicit_omit = NOT_IMPLICIT_OMIT);
777 bool chk_this_value_Set_T(Value *value, Common::Assignment *lhs,
778 expected_value_t expected_value, namedbool incomplete_allowed,
779 namedbool implicit_omit = NOT_IMPLICIT_OMIT);
780 bool chk_this_value_Se_A(Value *value, Common::Assignment *lhs,
781 expected_value_t expected_value, namedbool implicit_omit);
782 bool chk_this_value_Seq_A(Value *value, Common::Assignment *lhs,
783 expected_value_t expected_value, namedbool implicit_omit);
784 bool chk_this_value_Set_A(Value *value, Common::Assignment *lhs,
785 expected_value_t expected_value, namedbool implicit_omit);
786 bool chk_this_value_SeOf(Value *value, Common::Assignment *lhs,
787 expected_value_t expected_value, namedbool incomplete_allowed,
788 namedbool implicit_omit = NOT_IMPLICIT_OMIT);
789 void chk_this_value_Verdict(Value *value);
790 void chk_this_value_Default(Value *value);
791 bool chk_this_value_Array(Value *value, Common::Assignment *lhs,
792 expected_value_t expected_value, namedbool incomplete_allowed,
793 namedbool implicit_omit);
794 bool chk_this_value_Signature(Value *value, Common::Assignment *lhs,
795 expected_value_t expected_value, namedbool incomplete_allowed);
796 void chk_this_value_Component(Value *value);
797 void chk_this_value_FAT(Value *value);
798 public:
799 /** Checks whether template \a t is a specific value and the embedded value
800 * is a referenced one. If the reference in the value points to a
801 * template-like entity then it sets the template type to TEMPLATE_REFD,
802 * otherwise it leaves everything as is. */
803 void chk_this_template_ref(Template *t);
804 /** Checks for self references in functions returning templates (external or otherwise)
805 * and in parametrised templates. Returns true if the reference in assignment \a lhs
806 * is found.
807 * Recursive: calls itself incase of multiple embedded functions / parametrised templates.*/
808 bool chk_this_template_ref_pard(Ttcn::Ref_pard* ref_pard, Common::Assignment* lhs);
809 bool chk_this_template_generic(Template *t, namedbool incomplete_allowed,
810 namedbool allow_omit, namedbool allow_any_or_omit, namedbool sub_chk,
811 namedbool implicit_omit, Common::Assignment *lhs);
812 private:
813 bool chk_this_refd_template(Template *t, Common::Assignment *lhs);
814 void chk_this_template_length_restriction(Template *t);
815 bool chk_this_template(Template *t, namedbool is_modified, namedbool sub_chk,
816 namedbool implicit_omit, Common::Assignment *);
817 void chk_this_template_Str(Template *t);
818 /** Checks whether \a v is a correct range boundary for this type.
819 * Applicable to the following types: integer, float, charstring,
820 * universal charstring.
821 * Argument \a v might be NULL in case of + or - infinity.
822 * Argument \a which shall contain the word "lower" or "upper".
823 * Argument \a loc is used for error reporting if \a v is NULL (it points
824 * to the surrounding template).
825 * If \a v is correct and it is or refers to a constant the constant value
826 * is returned for further checking. Otherwise the return value is NULL. */
827 Value *chk_range_boundary(Value *v, const char *which, const Location& loc);
828 void chk_range_boundary_infinity(Value *v, bool is_upper);
829 void chk_this_template_builtin(Template *t);
830 void chk_this_template_Int_Real(Template *t);
831 void chk_this_template_Enum(Template *t);
832 bool chk_this_template_Choice(Template *t, namedbool is_modified,
833 namedbool implicit_omit, Common::Assignment *lhs);
834 bool chk_this_template_Seq(Template *t, namedbool is_modified,
835 namedbool implicit_omit, Common::Assignment *lhs);
836 bool chk_this_template_Set(Template *t, namedbool is_modified,
837 namedbool implicit_omit, Common::Assignment *lhs);
838 bool chk_this_template_SeqOf(Template *t, namedbool is_modified,
839 namedbool implicit_omit, Common::Assignment *lhs);
840 bool chk_this_template_SetOf(Template *t, namedbool is_modified,
841 namedbool implicit_omit, Common::Assignment *lhs);
842 bool chk_this_template_array(Template *t, namedbool is_modified,
843 namedbool implicit_omit, Common::Assignment *lhs);
844 void chk_this_template_Fat(Template *t);
845 void chk_this_template_Signature(Template *t, namedbool is_modified);
846 public:
847 /** Check whether there is an enum item with the given name.
848 *
849 * @pre typetype is T_ENUM_T or T_ENUM_A */
850 bool has_ei_withName(const Identifier& p_id) const;
851
852 /** Return the enum item with the given name.
853 *
854 * @pre typetype is T_ENUM_T or T_ENUM_A */
855 EnumItem *get_ei_byName(const Identifier& p_id) const;
856
857 /** Return the enum item with the given index.
858 *
859 * @pre typetype is T_ENUM_T or T_ENUM_A */
860 EnumItem *get_ei_byIndex(size_t i) const;
861
862 /** Get the number of components.
863 *
864 * @return the number of components from the appropriate alternative
865 * depending on the \a typetype.
866 *
867 * @pre \a typetype is one of T_CHOICE_T, T_SEQ_T, T_SET_T, T_OPENTYPE,
868 * T_SEQ_A, T_SET_A, T_CHOICE_A, T_ARRAY, T_SIGNATURE, T_ANYTYPE */
869 size_t get_nof_comps();
870
871 /** Get the name (id) of the component with the given index.
872 *
873 * @pre \a typetype is one of T_CHOICE_T, T_SEQ_T, T_SET_T, T_OPENTYPE,
874 * T_SEQ_A, T_SET_A, T_CHOICE_A, T_SIGNATURE, T_ANYTYPE
875 *
876 * @note Not valid for T_ARRAY */
877 const Identifier& get_comp_id_byIndex(size_t n);
878
879 /** Get the component with the given index.
880 *
881 * @pre \a typetype is one of T_CHOICE_T, T_SEQ_T, T_SET_T, T_OPENTYPE,
882 * T_SEQ_A, T_SET_A, T_CHOICE_A, T_ANYTYPE
883 *
884 * @note Not valid for T_ARRAY or T_SIGNATURE */
885 CompField* get_comp_byIndex(size_t n);
886
887 /** Get the index of the component with the given name
888 *
889 * @pre \a typetype of the last referenced type is one of
890 * T_CHOICE_T, T_SEQ_T, T_SET_T, T_OPENTYPE,
891 * T_SEQ_A, T_SET_A, T_CHOICE_A, T_ANYTYPE */
892 size_t get_comp_index_byName(const Identifier& p_name);
893
894 /** Get the index of the enum item with the given name
895 *
896 * @pre typetype is T_ENUM_T or T_ENUM_A */
897 size_t get_eis_index_byName(const Identifier& p_name);
898
899 const Int& get_enum_val_byId(const Identifier& p_name);
900
901 size_t get_nof_root_comps();
902 CompField* get_root_comp_byIndex(size_t n);
903
904 /** Get the name (id) of the component with the given index.
905 *
906 * @pre \a typetype is one of T_CHOICE_T, T_SEQ_T, T_SET_T, T_OPENTYPE,
907 * T_SEQ_A, T_SET_A, T_CHOICE_A, T_SIGNATURE, T_ANYTYPE
908 *
909 * @note Not valid for T_ARRAY */
910 bool has_comp_withName(const Identifier& p_name);
911 CompField* get_comp_byName(const Identifier& p_name);
912 void add_comp(CompField *p_cf);
913
914 /** Returns the embedded type of 'sequence/record of', 'set of' or array
915 * types. */
916 Type *get_ofType();
917
918 OC_defn* get_my_oc();
919 const Identifier& get_oc_fieldname();
920 void set_my_tableconstraint(const TableConstraint *p_tc);
921 const TableConstraint* get_my_tableconstraint();
922
923 /** Returns the array dimension. Applicable only if typetype == T_ARRAY. */
924 Ttcn::ArrayDimension *get_dimension() const;
925
926 /** Returns the PortTypeBody if typetype == T_PORT */
927 Ttcn::PortTypeBody *get_PortBody() const;
928
929 /** Returns the ComponentTypeBody if typetype == T_COMPONENT */
930 ComponentTypeBody *get_CompBody() const;
931
932 /** Returns the parameters of a signature.
933 * Applicable only if typetype == T_SIGNATURE. */
934 SignatureParamList *get_signature_parameters() const;
935 /** Returns the parameters of a signature.
936 * Applicable only if typetype == T_SIGNATURE. */
937 SignatureExceptions *get_signature_exceptions() const;
938 /** Returns the return type of a signature.
939 * Applicable only if typetype == T_SIGNATURE. */
940 Type *get_signature_return_type() const;
941 /** Returns whether the type is a non-blocking signature.
942 * Applicable only if typetype == T_SIGNATURE. */
943 bool is_nonblocking_signature() const;
944 /** Returns the parameters of a functionreference
945 * Applicable only if typetype == T_FUNCTION or T_ALTSTEP or T_TESTCASE */
946 Ttcn::FormalParList *get_fat_parameters();
947 /** Returns the return type of a functionreference
948 * Applicable only if typetype == T_FUNCTION */
949 Type *get_function_return_type();
950 /** Returns the runs on type of a functionreference
951 * Appliacable only if typetype == T_FUNCTION or T_ALTSTEP or T_TESTCASE */
952 Type *get_fat_runs_on_type();
953 /** Returns if a functionreference 'runs on self'
954 * Appliacable only if typetype == T_FUNCTION or T_ALTSTEP or T_TESTCASE */
955 bool get_fat_runs_on_self();
956 /** Applicable only if typetype == T_FUNCTION */
957 bool get_returns_template();
958
959 /** Retruns true if it is a tagged type.*/
960 bool is_tagged() const {return tags!=0;}
961 void add_tag(Tag *p_tag);
962 bool is_constrained() const {return constraints!=0;}
963 void add_constraints(Constraints *p_constraints);
964 Constraints* get_constraints() const {return constraints;}
965 Reference * get_Reference();
966 private:
967 void chk_table_constraints();
968 public:
969 /** Returns true if the type has multiple alternative tags
970 * (i.e. it is a non-tagged CHOICE type). */
971 bool has_multiple_tags();
972 /** Returns the tag of type. If this type is tagged, then the
973 * outermost tag is returned. */
974 Tag *get_tag();
975 void get_tags(TagCollection& coll, map<Type*, void>& chain);
976 /** Returns the smallest possible tag. If !has_multiple_tags()
977 * then returns get_tag(). Used is SET CER encoding, see X.690
978 * 9.3... */
979 Tag *get_smallest_tag();
980 /** Returns whether the type needs explicit tagging. */
981 bool needs_explicit_tag();
982 /** Removes the tag(s) from the type that was added during
983 * automatic tagging transformation. Needed for the implementation
984 * of COMPONENTS OF transformation. */
985 void cut_auto_tags();
986 Tags* build_tags_joined(Tags *p_tags=0);
987 void set_with_attr(Ttcn::MultiWithAttrib* p_attrib);
988 void set_parent_path(Ttcn::WithAttribPath* p_path);
989 Ttcn::WithAttribPath* get_attrib_path() const;
990 bool hasRawAttrs();
991 bool hasNeedofRawAttrs();
992 bool hasNeedofTextAttrs();
993 bool hasNeedofJsonAttrs();
994 bool hasNeedofXerAttrs();
995 bool hasVariantAttrs();
996 /** Returns whether the type has the encoding attribute specified by
997 * the parameter (either in its own 'with' statement or in the module's) */
998 bool hasEncodeAttr(const char* encoding_name);
999 /** Returns whether \a this can be encoded according to rules
1000 * \a p_encoding.
1001 * @note Should be called only during code generation, after the entire
1002 * AST has been checked, or else the compiler might choke on code like:
1003 * type MyRecordOfType[-] ElementTypeAlias; */
1004 bool has_encoding(const MessageEncodingType_t encoding_type, const string* custom_encoding = NULL);
1005 /** Generates the C++ equivalent class(es) of the type. */
1006 void generate_code(output_struct *target);
1007 size_t get_codegen_index(size_t index);
1008 private:
1009 /** Generates code for the case when the C++ classes are implemented by
1010 * hand, includes the header file with name sourcefile and extension hh
1011 */
1012 void generate_code_include(const string& sourcefile, output_struct *target);
1013 /** Generates code for the embedded types the C++ classes of which must be
1014 * placed before the classes of this type (e.g. the types of mandatory
1015 * record/set fields). */
1016 void generate_code_embedded_before(output_struct *target);
1017 /** Generates code for the embedded types the C++ classes of which can be
1018 * placed after the classes of this type (e.g. the types of union fields
1019 * and optional record/set fields). */
1020 void generate_code_embedded_after(output_struct *target);
1021 void generate_code_typedescriptor(output_struct *target);
1022 void generate_code_berdescriptor(output_struct *target);
1023 void generate_code_rawdescriptor(output_struct *target);
1024 void generate_code_textdescriptor(output_struct *target);
1025 void generate_code_jsondescriptor(output_struct *target);
1026 void generate_code_xerdescriptor(output_struct *target);
1027 void generate_code_alias(output_struct *target);
1028 void generate_code_Enum(output_struct *target);
1029 void generate_code_Choice(output_struct *target);
1030 Opentype_t *generate_code_ot(stringpool& pool);
1031 void free_code_ot(Opentype_t* p_ot);
1032 void generate_code_Se(output_struct *target);
1033 void generate_code_SeOf(output_struct *target);
1034 void generate_code_Array(output_struct *target);
1035 void generate_code_Fat(output_struct *target);
1036 void generate_code_Signature(output_struct *target);
1037 /** Returns whether the type needs an explicit C++ typedef alias and/or
1038 * an alias to a type descriptor of another type. It returns true for those
1039 * types that are defined in module-level type definitions hence are
1040 * directly accessible by the users of C++ API (in test ports, external
1041 * functions). */
1042 bool needs_alias();
1043 /** Returns whether this is a pure referenced type that has no tags or
1044 * encoding attributes. */
1045 bool is_pure_refd();
1046 void generate_code_done(output_struct *target);
1047
1048 /** Helper function used in generate_code_ispresentbound() for the
1049 ispresent() function in case of template parameter. Returns true
1050 if the referenced field which is embedded into a "?" is always present,
1051 otherwise returns false. **/
1052 bool ispresent_anyvalue_embedded_field(Type* t,
1053 Ttcn::FieldOrArrayRefs *subrefs, size_t begin_index);
1054
1055 /** Returns true if the C++ class for this type has already been pre-generated
1056 * or false if it still needs to be generated */
1057 bool is_pregenerated();
1058 public:
1059 /** Generates type specific call for the reference used in isbound call
1060 * into argument \a expr. Argument \a subrefs holds the reference path
1061 * that needs to be checked. Argument \a module is the actual module of
1062 * the reference and is used to gain access to temporal identifiers.
1063 * Argument \a global_id is the name of the bool variable where the result
1064 * of the isbound check is calculated. Argument \a external_id is the name
1065 * of the assignment where the call chain starts.
1066 * Argument \a is_template tells if the assignment is a template or not.
1067 * Argument \a isbound tells if the function is isbound or ispresent.
1068 */
1069 void generate_code_ispresentbound(expression_struct *expr,
1070 Ttcn::FieldOrArrayRefs *subrefs, Common::Module* module,
1071 const string& global_id, const string& external_id,
1072 const bool is_template, const bool isbound);
1073
1074 /** Extension attribute for optimized code generation of structured types:
1075 * with { extension "optimize:xxx" }
1076 * xxx tells what to optimize for (e.g.: memory, performance, etc.)
1077 * returns empty if none given
1078 */
1079 string get_optimize_attribute();
1080 /** Extension attribute for hand written TTCN-3 types:
1081 * with { extension "sourcefile:xxx" }
1082 * filename is xxx, source files: xxx.hh and xxx.cc
1083 * returns empty if none given
1084 */
1085 string get_sourcefile_attribute();
1086 bool has_done_attribute();
1087 /** Generates the declaration and definition of a C++ value or template
1088 * object governed by \a this into \a cdef. Argument \a p_scope points to
1089 * the scope of the object to be generated. Argument \a name contains the
1090 * identifier of the target C++ object. If argument \a prefix is not NULL
1091 * the real object will be generated as static, its name will be
1092 * prefixed with \a prefix and a const (read-only) reference will be
1093 * exported with name \a name. This function shall be used when there is no
1094 * Value or Template object in the AST (e.g. in case of variables). */
1095 void generate_code_object(const_def *cdef, Scope* p_scope,
1096 const string& name, const char *prefix, bool is_template);
1097 /** Generates the declaration and definition of a C++ value or template
1098 * object governed by \a this into \a cdef based on the attributes of
1099 * \a p_setting. */
1100 void generate_code_object(const_def *cdef, GovernedSimple *p_setting);
1101 private:
1102 virtual string create_stringRepr();
1103 public:
1104 /** If this type is added to an opentype, then this name is used
1105 * as the name of the alternative. */
1106 Identifier get_otaltname(bool& is_strange);
1107 /** Returns the name of the C++ value class that represents \a this at
1108 * runtime. The class is either pre-defined (written manually in the Base
1109 * Library) or generated by the compiler. The reference is valid in the
1110 * module that \a p_scope belongs to. */
1111 string get_genname_value(Scope *p_scope);
1112 /** Returns the name of the C++ class that represents \a this template at
1113 * runtime. The class is either pre-defined (written manually in the Base
1114 * Library) or generated by the compiler. The reference is valid in the
1115 * module that \a p_scope belongs to. */
1116 string get_genname_template(Scope *p_scope);
1117 /** Returns a C++ identifier that can be used to distinguish the type in
1118 * the union that carries signature exceptions. */
1119 string get_genname_altname();
1120 /** User visible (not code generator) type name */
1121 string get_typename();
1122 /** User visible type name for built-in types */
1123 static const char * get_typename_builtin(typetype_t tt);
1124 string get_genname_typedescriptor(Scope *p_scope);
1125 private:
1126 /** Returns the name prefix of type descriptors, etc. that belong to the
1127 * equivalent C++ class referenced from the module of scope \a p_scope.
1128 * It differs from \a get_genname() only in case of special ASN.1 types
1129 * like RELATIVE-OID or various string types. */
1130 string get_genname_typename(Scope *p_scope);
1131 /** Return the name of the BER descriptor structure.
1132 * It is either the name of the type itself;
1133 * one of "ENUMERATED", "CHOICE", "SEQUENCE", "SET";
1134 * or one of the core classes e.g. ASN_ROID, UTF8String, etc.
1135 * The _ber_ suffix needs to be appended by the caller. */
1136 string get_genname_berdescriptor();
1137 string get_genname_rawdescriptor();
1138 string get_genname_textdescriptor();
1139 string get_genname_xerdescriptor();
1140 string get_genname_jsondescriptor();
1141 /** Return the ASN base type to be written into the type descriptor */
1142 const char* get_genname_typedescr_asnbasetype();
1143 /** parse subtype information and add parent's subtype information to
1144 create the effective/aggregate subtype of this type */
1145 void check_subtype_constraints();
1146 public:
1147 /** Return the type of subtype that is associated with this type */
1148 SubtypeConstraint::subtype_t get_subtype_type();
1149 virtual void dump(unsigned level) const;
1150 void set_parsed_restrictions(vector<SubTypeParse> *stp);
1151 /** Returns true if the values of this type can be used only in 'self'.
1152 * Some types (default, function reference with 'runs on self') are
1153 * invalid outside of the component they were created in, they should not
1154 * be sent/received in ports or used in compref.start(). All structured
1155 * types that may contain such internal types are also internal. */
1156 bool is_component_internal();
1157 /** Prints error messages for types that cannot leave the component.
1158 * Should be called only if is_component_internal() returned true.
1159 * \a type_chain is used to escape infinite recursion by maintaining a
1160 * chain of structured types that call this function recursively,
1161 * \a p_what tells what is the reason of the error. */
1162 void chk_component_internal(map<Type*,void>& type_chain,
1163 const char* p_what);
1164 /** Prints error messages for type that cannot be a type of given ones (parameter: array of typetype_t)
1165 * \a type_chain is used to escape infinite recursion by maintaining a
1166 * chain of structured types that call this function recursively,
1167 * \returns the original type or a not allowed one */
1168 typetype_t search_for_not_allowed_type(map<Type*, void>& type_chain,
1169 map<typetype_t, void>& not_allowed);
1170 /** Set the owner and its type type */
1171 void set_ownertype(TypeOwner_t ot, Node *o) { ownertype = ot; owner = o; }
1172
1173 bool is_untagged() const;
1174
1175 inline boolean is_pard_type_instance() { return pard_type_instance; }
1176 inline void set_pard_type_instance() { pard_type_instance = true; }
1177
1178 /** Calculates the type's display name from the genname (replaces double
1179 * underscore characters with single ones) */
1180 string get_dispname() const;
1181
1182 /** Generates the JSON schema segment that would validate this type and
1183 * inserts it into the main schema.
1184 * @param json JSON tokenizer containing the main JSON schema
1185 * @param embedded true if the type is embedded in another type's definition;
1186 * false if it has its own definition
1187 * @param as_value true if this type is a field of a union with the "as value"
1188 * coding instruction */
1189 void generate_json_schema(JSON_Tokenizer& json, bool embedded, bool as_value);
1190
1191 /** Generates the JSON schema segment that would validate a record of, set of
1192 * or array type and inserts it into the main schema. */
1193 void generate_json_schema_array(JSON_Tokenizer& json);
1194
1195 /** Generates the JSON schema segment that would validate a record or set type
1196 * and inserts it into the main schema. */
1197 void generate_json_schema_record(JSON_Tokenizer& json);
1198
1199 /** Generates the JSON schema segment that would validate a union type or
1200 * an anytype and inserts it into the main schema. */
1201 void generate_json_schema_union(JSON_Tokenizer& json);
1202
1203 /** Generates a reference to this type's schema segment and inserts it into
1204 * the given schema. */
1205 void generate_json_schema_ref(JSON_Tokenizer& json);
1206
1207 JsonAST* get_json_attributes() const { return jsonattrib; }
1208
1209 /** Returns true if the type is a union with the JSON "as value" attribute, or
1210 * if a union with this attribute is embedded in the type. */
1211 bool has_as_value_union();
1212 };
1213
1214 /** @} end of AST_Type group */
1215
1216 } // namespace Common
1217
1218 #endif // _Common_Type_HH
This page took 0.059385 seconds and 5 git commands to generate.