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