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