Sync with 5.4.0
[deliverable/titan.core.git] / compiler2 / ttcn3 / AST_ttcn3.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 _Ttcn_AST_HH
9 #define _Ttcn_AST_HH
10
11 #include "../AST.hh"
12
13 namespace Common {
14 class CodeGenHelper;
15 }
16
17 /**
18 * This namespace contains classes unique to TTCN-3 and some specializations
19 * of classes from Common.
20 */
21 namespace Ttcn {
22
23 /**
24 * \addtogroup AST
25 *
26 * @{
27 */
28
29 using namespace Common;
30
31 class Module;
32 class Definition;
33 class FriendMod;
34 class Imports;
35 class ImpMod;
36 class ActualPar;
37 class ActualParList;
38 class FormalParList;
39 class ParsedActualParameters;
40 class Template;
41 class TemplateInstance;
42 class TemplateInstances;
43 class ArrayDimensions;
44 class Timer;
45 class StatementBlock;
46 class AltGuards;
47 class ILT;
48 class Group;
49 class WithAttribPath;
50 class ErrorBehaviorList;
51 class ErroneousAttributes;
52 class ErroneousAttributeSpec;
53 class PrintingType;
54
55 /** Class to represent an actual parameter */
56 class ActualPar : public Node {
57 public:
58 enum ap_selection_t {
59 AP_ERROR, ///< erroneous
60 AP_VALUE, ///< "in" value parameter
61 AP_TEMPLATE, ///< "in" template parameter
62 AP_REF, ///< out/inout value or template parameter
63 AP_DEFAULT ///< created from the default value of a formal parameter
64 };
65 private:
66 ap_selection_t selection;
67 union {
68 Value *val; ///< Value for AP_VALUE. Owned by ActualPar
69 TemplateInstance *temp; ///< %Template for AP_TEMPLATE. Owned by ActualPar
70 Ref_base *ref; ///< %Reference for AP_REF. Owned by ActualPar
71 ActualPar *act; ///< For AP_DEFAULT. \b Not owned by ActualPar
72 };
73 Scope *my_scope; ///< %Scope. Not owned
74 /** tells what runtime template restriction check to generate,
75 * TR_NONE means that no check is needed because it could be determined
76 * in compile time */
77 template_restriction_t gen_restriction_check;
78 /** if this is an actual template parameter of an external function add
79 * runtime checks for out and inout parameters after the call */
80 template_restriction_t gen_post_restriction_check;
81 private:
82 /** Copy constructor not implemented */
83 ActualPar(const ActualPar& p);
84 /** %Assignment disabled */
85 ActualPar& operator=(const ActualPar& p);
86 public:
87 /// Constructor for an erroneous object (fallback)
88 ActualPar()
89 : Node(), selection(AP_ERROR), my_scope(0),
90 gen_restriction_check(TR_NONE), gen_post_restriction_check(TR_NONE) {}
91 /// Actual par for an in value parameter
92 ActualPar(Value *v);
93 /// Actual par for an in template parameter
94 ActualPar(TemplateInstance *t);
95 /// Actual par for an {out or inout} {value or template} parameter
96 ActualPar(Ref_base *r);
97 /// Created from the default value of a formal par, at the call site,
98 ///
99 ActualPar(ActualPar *a);
100 virtual ~ActualPar();
101 virtual ActualPar *clone() const;
102 virtual void set_fullname(const string& p_fullname);
103 virtual void set_my_scope(Scope *p_scope);
104 bool is_erroneous() const { return selection == AP_ERROR; }
105 ap_selection_t get_selection() const { return selection; }
106 Value *get_Value() const;
107 TemplateInstance *get_TemplateInstance() const;
108 Ref_base *get_Ref() const;
109 ActualPar *get_ActualPar() const;
110 /** Checks the embedded recursions within the value or template instance. */
111 void chk_recursions(ReferenceChain& refch);
112 /** Returns whether the actual parameter can be represented by an in-line
113 * C++ expression. */
114 bool has_single_expr();
115 void set_code_section(GovernedSimple::code_section_t p_code_section);
116 /** Generates the C++ equivalent of \a this into \a expr.
117 * Flag \a copy_needed indicates whether to add an extra copy constructor
118 * call if \a this contains a referenced value or template to avoid
119 * aliasing problems with other out/inout parameters. */
120 void generate_code(expression_struct *expr, bool copy_needed, bool lazy_param=false, bool used_as_lvalue=false) const;
121 /** Appends the initialization sequence of all (directly or indirectly)
122 * referred non-parameterized templates to \a str and returns the resulting
123 * string. Flag \a is_local indicates whether the respective formal
124 * parameter is in the same module as \a this. It is considered only if
125 * \a selection is AP_DEFAULT. */
126 char *rearrange_init_code(char *str, bool is_local);
127 char *rearrange_init_code_defval(char *str);
128 /** Appends the string representation of the actual parameter to \a str. */
129 void append_stringRepr(string& str) const;
130 virtual void dump(unsigned level) const;
131 void set_gen_restriction_check(template_restriction_t tr)
132 { gen_restriction_check = tr; }
133 template_restriction_t get_gen_restriction_check()
134 { return gen_restriction_check; }
135 void set_gen_post_restriction_check(
136 template_restriction_t p_gen_post_restriction_check)
137 { gen_post_restriction_check = p_gen_post_restriction_check; }
138 };
139
140 /// A collection of actual parameters (parameter list)
141 class ActualParList : public Node {
142 vector<ActualPar> params;
143 public:
144 ActualParList(): Node(), params() { }
145 ActualParList(const ActualParList& p);
146 ~ActualParList();
147 ActualParList* clone() const;
148 virtual void set_fullname(const string& p_fullname);
149 virtual void set_my_scope(Scope *p_scope);
150 size_t get_nof_pars() const { return params.size(); }
151 void add(ActualPar* p) { params.add(p); }
152 ActualPar* get_par(size_t i) const { return params[i]; }
153 /** Checks the embedded recursions within the values and template
154 * instances of actual parameters. */
155 void chk_recursions(ReferenceChain& refch);
156 /** Generates the C++ equivalent of the actual parameter list without
157 * considering any aliasing between variables and 'in' parameters. */
158 void generate_code_noalias(expression_struct *expr, FormalParList *p_fpl);
159 /** Generates the C++ equivalent of the actual parameter list considering
160 * aliasing problems between the 'in' parameters and 'out'/'inout'
161 * parameters as well as component variables seen by the called definition.
162 * Argument \a p_fpl points to the formal parameter list of the referred
163 * definition if it is known, otherwise it is NULL. Argument \a p_comptype
164 * points to the component type identified by the 'runs on' clause of the
165 * referred definition (if exists and relevant for alias analysis,
166 * otherwise NULL).
167 * When invoke() is used with FAT types: the special case of 'runs on self'
168 * has the argument \a p_compself set to true and \a p_comptype is NULL,
169 * but the component is 'self' or any compatible component. */
170 void generate_code_alias(expression_struct *expr, FormalParList *p_fpl,
171 Type *p_comptype, bool p_compself);
172 /** Walks through the parameter list and appends the initialization
173 * sequence of all (directly or indirectly) referred non-parameterized
174 * templates to \a str and returns the resulting string. Flag \a is_local
175 * indicates whether the respective formal parameter list is in the same
176 * module as \a this. */
177 char *rearrange_init_code(char *str, bool is_local);
178 virtual void dump(unsigned level) const;
179 };
180
181 /** Helper class for the Ttcn::Reference */
182 class FieldOrArrayRef : public Node, public Location {
183 public:
184 enum reftype { FIELD_REF, ARRAY_REF };
185 private:
186 reftype ref_type; ///< reference type
187 /** The stored reference. Owned and destroyed by FieldOrArrayRef */
188 union {
189 Identifier *id; ///< name of the field, used by FIELD_REF
190 Value *arp; ///< value of the index, used by ARRAY_REF
191 } u;
192 /** Copy constructor for clone() only */
193 FieldOrArrayRef(const FieldOrArrayRef& p);
194 /** %Assignment disabled */
195 FieldOrArrayRef& operator=(const FieldOrArrayRef& p);
196 public:
197 FieldOrArrayRef(Identifier *p_id);
198 FieldOrArrayRef(Value *p_arp);
199 ~FieldOrArrayRef();
200 virtual FieldOrArrayRef* clone() const;
201 virtual void set_fullname(const string& p_fullname);
202 virtual void set_my_scope(Scope *p_scope);
203 reftype get_type() const { return ref_type; }
204 /** Return the identifier.
205 * @pre reftype is FIELD_REF, or else FATAL_ERROR */
206 const Identifier* get_id() const;
207 /** Returns the value.
208 * @pre reftype is ARRAY_REF, or else FATAL_ERROR */
209 Value* get_val() const;
210 /** Appends the string representation of the sub-reference to \a str. */
211 void append_stringRepr(string& str) const;
212 /** Sets the first letter in the name of the field to lowercase if it's an
213 * uppercase letter.
214 * Used on open types (the name of their alternatives can be given with both
215 * an uppercase or a lowercase first letter, and the generated code will need
216 * to use the lowercase version). */
217 void set_field_name_to_lowercase();
218 };
219
220 /** A vector of FieldOrArrayRef objects */
221 class FieldOrArrayRefs : public Node {
222 /** Element holder. This FieldOrArrayRefs object owns the elements
223 * and will free them in the destructor. */
224 vector<FieldOrArrayRef> refs;
225 /** Indicates whether the last array index refers to an element of a
226 * string value. */
227 bool refs_str_element;
228 public:
229 FieldOrArrayRefs() : Node(), refs(), refs_str_element(false) { }
230 FieldOrArrayRefs(const FieldOrArrayRefs& p);
231 ~FieldOrArrayRefs();
232 FieldOrArrayRefs *clone() const;
233 virtual void set_fullname(const string& p_fullname);
234 virtual void set_my_scope(Scope *p_scope);
235 void add(FieldOrArrayRef *p_ref) { refs.add(p_ref); }
236 size_t get_nof_refs() const { return refs.size(); }
237 FieldOrArrayRef* get_ref(size_t i) const { return refs[i]; }
238 bool has_unfoldable_index() const;
239 /** Removes (deletes) the first \a n field references. */
240 void remove_refs(size_t n);
241 Identifier *remove_last_field();
242 /** Generates the C++ sub-expression that accesses
243 * the given sub-references of definition \a ass.
244 * @param nof_subrefs indicates the number of sub-references
245 * to generate code from (UINT_MAX means all of them) */
246 void generate_code(expression_struct *expr, Common::Assignment *ass, size_t nof_subrefs = UINT_MAX);
247 /** Appends the string representation of sub-references to \a str. */
248 void append_stringRepr(string &str) const;
249 bool refers_to_string_element() const { return refs_str_element; }
250 void set_string_element_ref() { refs_str_element = true; }
251 void clear_string_element_ref() { refs_str_element = false; }
252 };
253
254 /**
255 * Base class for all TTCN-3 references.
256 * Includes the common functionality for parameterized and non-parameterized
257 * references (e.g. handling of field or array subreferences).
258 */
259 class Ref_base : public Ref_simple {
260 protected: // Ttcn::Reference and Ttcn::Ref_pard need access
261 Identifier *modid;
262 /** If id is a NULL pointer all components are stored in subrefs */
263 Identifier *id;
264 FieldOrArrayRefs subrefs;
265 /** Indicates whether the consistency of formal and actual parameter lists
266 * has been verified. */
267 bool params_checked;
268 bool usedInIsbound;
269 Ref_base(const Ref_base& p);
270 private:
271 Ref_base& operator=(const Ref_base& p);
272 public:
273 /** Default constructor: sets \a modid and \a id to NULL. Used by
274 * non-parameterized references only. It is automatically guessed whether
275 * the first component of \a subrefs is a module id or not. */
276 Ref_base() : Ref_simple(), modid(0), id(0), subrefs(), params_checked(0)
277 , usedInIsbound(false) {}
278 Ref_base(Identifier *p_modid, Identifier *p_id);
279 ~Ref_base();
280 virtual Ref_base *clone() const = 0;
281 virtual void set_fullname(const string& p_fullname);
282 virtual void set_my_scope(Scope *p_scope);
283 /** Sets the scope of the base reference to \a p_scope.
284 * The scope of array indices in \a subrefs remains unchanged. */
285 void set_base_scope(Scope *p_scope) { Ref_simple::set_my_scope(p_scope); }
286 virtual bool getUsedInIsbound() {return usedInIsbound;}
287 virtual void setUsedInIsbound() {usedInIsbound = true;}
288 Setting *get_refd_setting();
289 FieldOrArrayRefs *get_subrefs();
290 /** Appends \a p_ref to the sub-references */
291 void add(FieldOrArrayRef *p_ref) { subrefs.add(p_ref); }
292 virtual bool has_single_expr();
293 virtual void set_code_section(
294 GovernedSimple::code_section_t p_code_section);
295 /** Generates the C++ equivalent of the reference (including the parameter
296 * list and sub-references) as an access to a constant resource.
297 */
298 virtual void generate_code_const_ref(expression_struct_t *expr);
299 };
300
301 /**
302 * TTCN-3 reference without parameters.
303 * Implements the automatic detection whether the first identifier is a
304 * module name or not.
305 */
306 class Reference : public Ref_base {
307 ActualParList *parlist;
308 public:
309 Reference(Identifier *p_id);
310 Reference(Identifier *p_modid, Identifier *p_id)
311 : Ref_base(p_modid, p_id), parlist(0) { }
312 ~Reference();
313 virtual Reference *clone() const;
314 virtual string get_dispname();
315 virtual Common::Assignment *get_refd_assignment(bool check_parlist = true);
316 virtual const Identifier* get_modid();
317 virtual const Identifier* get_id();
318 /** Checks whether \a this points to a variable or value parameter.
319 * Returns the type of the respective variable or variable field or NULL
320 * in case of error. */
321 Type *chk_variable_ref();
322 /** Checks if \a this points to a component.
323 * Returns the type of the component if so or NULL in case of error. */
324 Type *chk_comptype_ref();
325 virtual bool has_single_expr();
326 virtual void generate_code(expression_struct_t *expr);
327 /** Generates the C++ equivalent of port references within
328 * connect/disconnect/map/unmap statements into \a expr.
329 * Argument \a p_scope shall point to the scope of the statement. */
330 void generate_code_portref(expression_struct_t *expr, Scope *p_scope);
331 virtual void generate_code_const_ref(expression_struct_t *expr);
332 /**
333 * Generates code for checking if the reference
334 * and the referred objects are bound or not.*/
335 void generate_code_ispresentbound(expression_struct_t *expr,
336 bool is_template, const bool isbound);
337 private:
338 /** Detects whether the first identifier in subrefs is a module id */
339 void detect_modid();
340 };
341
342 /**
343 * Parameterized TTCN-3 reference
344 */
345 class Ref_pard : public Ref_base {
346 /** "Processed" parameter list, after the semantic check. */
347 ActualParList parlist;
348 /** "Raw" parameter list, before the semantic check. */
349 Ttcn::ParsedActualParameters *params;
350 /** Used by generate_code_cached(). Stores the generated expression string,
351 * so it doesn't get regenerated every time. */
352 char* expr_cache;
353 /** Copy constructor. Private, used by Ref_pard::clone() only */
354 Ref_pard(const Ref_pard& p);
355 /// %Assignment disabled
356 Ref_pard& operator=(const Ref_pard& p);
357 public:
358 /** Constructor
359 * \param p_modid the module in which it resides
360 * \param p_id the identifier
361 * \param p_params parameters. For a function, this is the list constructed
362 * for the actual parameters.
363 * */
364 Ref_pard(Identifier *p_modid, Identifier *p_id,
365 ParsedActualParameters *p_params);
366 ~Ref_pard();
367 virtual Ref_pard *clone() const;
368 virtual void set_fullname(const string& p_fullname);
369 virtual void set_my_scope(Scope *p_scope);
370 string get_dispname();
371 virtual Common::Assignment *get_refd_assignment(bool check_parlist = true);
372 virtual const Identifier *get_modid();
373 virtual const Identifier *get_id();
374 virtual ActualParList *get_parlist();
375 /** Checks whether \a this is a correct argument of an activate operation
376 * or statement. The reference shall point to an altstep with proper
377 * `runs on' clause and the actual parameters that are passed by reference
378 * shall not point to local definitions. The function returns true if the
379 * altstep reference is correct and false in case of any error. */
380 bool chk_activate_argument();
381 virtual bool has_single_expr();
382 virtual void set_code_section(
383 GovernedSimple::code_section_t p_code_section);
384 virtual void generate_code (expression_struct_t *expr);
385 virtual void generate_code_const_ref(expression_struct_t *expr);
386
387 /** Used when an 'all from' is called on a function or parametrised template,
388 * generate_code would generate new temporaries for the function's parameters
389 * each call. This method makes sure the same temporaries are used every time
390 * the function is called in the generated code.
391 * On the first run calls generate_code and stores its result (only expr.expr
392 * is cached, since the preamble is only needed after the first call).
393 * On further runs the cached expression is returned.*/
394 virtual void generate_code_cached (expression_struct_t *expr);
395 };
396
397 /**
398 * Class Ttcn::NameBridgingScope.
399 * This scope unit is NOT A REAL SCOPE UNIT,
400 * its only purpose is to serve as a bridge with a name between two real scope
401 * units. All operations are transfered automatically.
402 */
403 class NameBridgingScope : public Scope {
404 virtual string get_scopeMacro_name() const;
405 virtual NameBridgingScope* clone() const;
406 virtual Common::Assignment* get_ass_bySRef(Ref_simple *p_ref);
407 };
408
409 /**
410 * Class Ttcn::RunsOnScope.
411 * Implements the scoping rules for functions, altsteps and testcases that
412 * have a 'runs on' clause. First looks for the definitions in the given
413 * component type first then it searches in its parent scope.
414 * Note: This scope unit cannot access the parent scope of the component type
415 * (which is a module Definitions) unless the component type and the
416 * 'runs on' clause is defined in the same module.
417 */
418 class RunsOnScope : public Scope {
419 /** Points to the component type. */
420 Type *component_type;
421 /** Shortcut to the definitions within \a component_type. */
422 ComponentTypeBody *component_defs;
423
424 /** Not implemented. Causes \a FATAL_ERROR. */
425 RunsOnScope(const RunsOnScope& p);
426 /** %Assignment not implemented */
427 RunsOnScope& operator=(const RunsOnScope& p);
428 public:
429 RunsOnScope(Type *p_comptype);
430 virtual RunsOnScope *clone() const;
431
432 Type *get_component_type() const { return component_type; }
433 /** Checks the uniqueness of definitions within \a component_defs and
434 * reports warnings in case of hiding. */
435 void chk_uniq();
436
437 virtual RunsOnScope *get_scope_runs_on();
438 virtual Common::Assignment *get_ass_bySRef(Ref_simple *p_ref);
439 virtual bool has_ass_withId(const Identifier& p_id);
440 };
441
442 /**
443 * Class Ttcn::Definitions.
444 *
445 * Owns the contained Definition objects.
446 */
447 class Definitions : public Common::Assignments {
448 protected:
449 /** Searchable map of definitions. Used after chk_uniq. */
450 map<string, Definition> ass_m;
451 /** Indicates whether the uniqueness of identifiers has been checked. */
452 bool checked;
453 /** Vector containing all definitions. Used for building. */
454 vector<Definition> ass_v;
455
456 Definitions(const Definitions& p);
457 public:
458
459 Definitions() : Common::Assignments(), ass_m(), checked(false), ass_v() {}
460 ~Definitions();
461 Definitions *clone() const;
462 virtual void set_fullname(const string& p_fullname);
463 /** Adds the assignment p_ass and becomes the owner of it.
464 * The uniqueness of the identifier is not checked. */
465 void add_ass(Definition *p_ass);
466 virtual bool has_local_ass_withId(const Identifier& p_id);
467 virtual Common::Assignment* get_local_ass_byId(const Identifier& p_id);
468 virtual size_t get_nof_asss();
469 virtual Common::Assignment* get_ass_byIndex(size_t p_i);
470 size_t get_nof_raw_asss();
471 Definition *get_raw_ass_byIndex(size_t p_i);
472 /** Checks the uniqueness of identifiers. */
473 void chk_uniq();
474 /** Checks all definitions. */
475 void chk();
476 /** Checks the definitions within the header of a for loop. */
477 void chk_for();
478 /** Sets the genname of embedded definitions using \a prefix. */
479 void set_genname(const string& prefix);
480 /** Generates code for all assignments into \a target. */
481 void generate_code(output_struct *target);
482 void generate_code(CodeGenHelper& cgh);
483 char* generate_code_str(char *str);
484 void ilt_generate_code(ILT *ilt);
485 /** Prints the contents of all assignments. */
486 virtual void dump(unsigned level) const;
487 };
488
489 /**
490 * Class Ttcn::Definitions.
491 *
492 * Owns the contained Definition objects.
493 */
494 /* class Definitions : public OtherDefinitions {
495 public:
496 Definitions() : OtherDefinitions() {}
497 ~Definitions();
498 Definitions *clone() const;
499 void add_ass(Definition *p_ass);
500 };*/
501
502 /** Represents a TTCN-3 group
503 *
504 * @note a Group is not a Scope */
505 class Group : public Node, public Location {
506 private:
507 Group* parent_group;
508 WithAttribPath* w_attrib_path;
509 /// Definitions that belong to this group (directly)
510 vector<Definition> ass_v;
511 /// Map the name to the definition (filled in chk_uniq)
512 map<string,Definition> ass_m;
513 /// Subgroups
514 vector<Group> group_v;
515 /// Map the name to the subgroup
516 map<string,Group> group_m;
517 vector<ImpMod> impmods_v;
518 vector<FriendMod> friendmods_v;
519 Identifier *id;
520 bool checked;
521 private:
522 /** Copy constructor not implemented */
523 Group(const Group& p);
524 /** %Assignment not implemented */
525 Group& operator=(const Group& p);
526 public:
527 Group(Identifier *p_id);
528 ~Group();
529 virtual Group* clone() const;
530 virtual void set_fullname(const string& p_fullname);
531 void add_ass(Definition* p_ass);
532 void add_group(Group* p_group);
533 void set_parent_group(Group* p_parent_group);
534 Group* get_parent_group() const { return parent_group; }
535 void set_attrib_path(WithAttribPath* p_path);
536 const Identifier& get_id() const { return *id; }
537 void chk_uniq();
538 virtual void chk();
539 void add_impmod(ImpMod *p_impmod);
540 void add_friendmod(FriendMod *p_friendmod);
541 virtual void dump(unsigned level) const;
542 void set_with_attr(MultiWithAttrib* p_attrib);
543 WithAttribPath* get_attrib_path();
544 void set_parent_path(WithAttribPath* p_path);
545 };
546
547 class ControlPart : public Node, public Location {
548 private:
549 StatementBlock* block;
550 WithAttribPath* w_attrib_path;
551
552 NameBridgingScope bridgeScope;
553
554 /// Copy constructor disabled
555 ControlPart(const ControlPart& p);
556 /// %Assignment disabled
557 ControlPart& operator=(const ControlPart& p);
558 public:
559 ControlPart(StatementBlock* p_block);
560 ~ControlPart();
561 virtual ControlPart* clone() const;
562 virtual void set_fullname(const string& p_fullname);
563 virtual void set_my_scope(Scope *p_scope);
564 void chk();
565 void generate_code(output_struct *target, Module *my_module);
566 void set_with_attr(MultiWithAttrib* p_attrib);
567 WithAttribPath* get_attrib_path();
568 void set_parent_path(WithAttribPath* p_path);
569 void dump(unsigned level) const;
570 };
571
572 /** A TTCN-3 module */
573 class Module : public Common::Module {
574 private:
575 string *language_spec;
576 Definitions *asss;
577 vector<Group> group_v;
578 map<string, Group> group_m;
579 WithAttribPath* w_attrib_path;
580 Imports *imp;
581 ControlPart* controlpart;
582 /** For caching the scope objects that are created in
583 * \a get_runs_on_scope(). */
584 vector<RunsOnScope> runs_on_scopes;
585 private:
586 /** Copy constructor not implemented */
587 Module(const Module& p);
588 /** %Assignment not implemented */
589 Module& operator=(const Module& p);
590 public:
591 vector<FriendMod> friendmods_v;
592 Module(Identifier *p_modid);
593 ~Module();
594 void add_group(Group* p_group);
595 void add_friendmod(FriendMod *p_friendmod);
596 virtual Module* clone() const;
597 virtual Common::Assignment* importAssignment(
598 const Identifier& p_source_modid, const Identifier& p_id) const;
599 virtual void set_fullname(const string& p_fullname);
600 virtual Common::Assignments* get_scope_asss();
601 virtual bool has_imported_ass_withId(const Identifier& p_id);
602 virtual Common::Assignment* get_ass_bySRef(Ref_simple *p_ref);
603 virtual bool is_valid_moduleid(const Identifier& p_id);
604 virtual Common::Assignments *get_asss();
605 virtual bool exports_sym(const Identifier& p_id);
606 virtual Type *get_address_type();
607 virtual void chk_imp(ReferenceChain& refch, vector<Common::Module>& moduleStack);
608 virtual void chk();
609 private:
610 void chk_friends();
611 void chk_groups();
612 virtual void get_imported_mods(module_set_t& p_imported_mods);
613 virtual void generate_code_internal(CodeGenHelper& cgh);
614 public:
615 /** Returns a scope that can access the definitions within component type
616 * \a comptype (which is imported from another module) and its parent scope
617 * is \a asss. Note that this scope cannot see the scope of \a comptype.
618 * The function uses \a runs_on_scopes for caching the scope objects: if an
619 * object has been created for a component type it will be returned later
620 * instead of creating a new one. */
621 RunsOnScope *get_runs_on_scope(Type *comptype);
622 virtual void dump(unsigned level) const;
623 void set_language_spec(const char *p_language_spec);
624 void add_ass(Definition* p_ass);
625 void add_impmod(ImpMod *p_impmod);
626 void add_controlpart(ControlPart* p_controlpart);
627 void set_with_attr(MultiWithAttrib* p_attrib);
628 WithAttribPath* get_attrib_path();
629 void set_parent_path(WithAttribPath* p_path);
630 const Imports& get_imports() const { return *imp; }
631
632 bool is_visible(const Identifier& id, visibility_t visibility);
633
634 /** Generates JSON schema segments for the types defined in the modules,
635 * and references to these types. Information related to the types'
636 * JSON encoding and decoding functions is also inserted after the references.
637 *
638 * @param json JSON document containing the main schema, schema segments for
639 * the types will be inserted here
640 * @param json_refs map of JSON documents containing the references and function
641 * info related to each type */
642 virtual void generate_json_schema(JSON_Tokenizer& json, map<Type*, JSON_Tokenizer>& json_refs);
643 };
644
645 /**
646 * Module friendship declaration.
647 */
648 class FriendMod : public Node, public Location {
649 private:
650 Module *my_mod;
651 Identifier *modid;
652 WithAttribPath* w_attrib_path;
653 Group* parentgroup;
654 /** Indicates whether this friend module declaration was checked */
655 bool checked;
656 private:
657 /** Copy constructor not implemented. */
658 FriendMod(const FriendMod&);
659 /** %Assignment not implemented. */
660 FriendMod& operator=(const FriendMod&);
661 public:
662 FriendMod(Identifier *p_modid);
663 ~FriendMod();
664 virtual FriendMod* clone() const;
665 virtual void set_fullname(const string& p_fullname);
666 virtual void chk();
667 void set_my_mod(Module *p_mod) { my_mod = p_mod; }
668 const Identifier& get_modid() const {return *modid;}
669 void set_with_attr(MultiWithAttrib* p_attrib);
670 WithAttribPath* get_attrib_path();
671 void set_parent_path(WithAttribPath* p_path);
672 void set_parent_group(Group* p_group);
673 };
674
675
676 /**
677 * Imported module. Represents an import statement.
678 */
679 class ImpMod : public Node, public Location {
680 public:
681 enum imptype_t {
682 I_UNDEF,
683 I_ERROR,
684 I_ALL,
685 I_IMPORTSPEC,
686 I_IMPORTIMPORT
687 };
688 private:
689 /** Points to the target (imported) module. This is initially NULL;
690 * set during semantic analysis by Ttcn::Imports::chk_uniq() */
691 Common::Module *mod;
692 /** The importing module (indirectly our owner) */
693 Module *my_mod;
694 /** Import type: "import all", selective import, import of import, etc. */
695 imptype_t imptype;
696 /** The name given in the import statement;
697 * hopefully an actual module name */
698 Identifier *modid;
699 /** The text after "import from name language" */
700 string *language_spec;
701 /** Recursive import (already deprecated in v3.2.1) */
702 bool is_recursive;
703 WithAttribPath* w_attrib_path;
704 /** Group in which the import statement is located, if any */
705 Group* parentgroup;
706 visibility_t visibility;
707 private:
708 /** Copy constructor not implemented. */
709 ImpMod(const ImpMod&);
710 /** %Assignment not implemented */
711 ImpMod& operator=(const ImpMod&);
712 public:
713 ImpMod(Identifier *p_modid);
714 ~ImpMod();
715 virtual ImpMod* clone() const;
716 virtual void set_fullname(const string& p_fullname);
717 virtual void chk();
718 /** Checks the existence of imported symbols and checks import definitions
719 * in the imported modules recursively. */
720 void chk_imp(ReferenceChain& refch, vector<Common::Module>& moduleStack);
721 void set_my_mod(Module *p_mod) { my_mod = p_mod; }
722 const Identifier& get_modid() const {return *modid;}
723 void set_mod(Common::Module *p_mod) { mod = p_mod; }
724 Common::Module *get_mod() const { return mod; }
725 /** Returns the imported definition with name \a p_id if it is imported or
726 * NULL otherwise.
727 * \a loc is used to report an error if it is needed */
728 Common::Assignment *get_imported_def(const Identifier& p_source_modid,
729 const Identifier& p_id, const Location *loc,
730 ReferenceChain* refch, vector<ImpMod>& usedImpMods) const;
731 bool has_imported_def(const Identifier& p_source_modid,
732 const Identifier& p_id, const Location *loc) const;
733 void set_imptype(imptype_t p_imptype) { imptype = p_imptype; }
734 void set_language_spec(const char *p_language_spec);
735 void set_recursive() { is_recursive = true; }
736 void generate_code(output_struct *target);
737 virtual void dump(unsigned level) const;
738 void set_with_attr(MultiWithAttrib* p_attrib);
739 WithAttribPath* get_attrib_path();
740 void set_parent_path(WithAttribPath* p_path);
741 void set_parent_group(Group* p_group);
742 imptype_t get_imptype() {
743 return imptype;
744 }
745 void set_visibility(visibility_t p_visibility){
746 visibility = p_visibility;
747 }
748 visibility_t get_visibility() const{
749 return visibility;
750 }
751 };
752
753 /**
754 * Class Imports.
755 */
756 class Imports : public Node {
757 private:
758 /** my module */
759 Module *my_mod;
760 /** imported modules */
761 vector<ImpMod> impmods_v;
762 /** Indicates whether the import list has been checked. */
763 bool checked;
764
765 friend class ImpMod;
766 private:
767 /** Copy constructor not implemented. */
768 Imports(const Imports&);
769 /** %Assignment not implemented */
770 Imports& operator=(const Imports&);
771 public:
772 Imports() : Node(), my_mod(0), impmods_v(), checked(false) {}
773 virtual ~Imports();
774 virtual Imports* clone() const;
775 void add_impmod(ImpMod *p_impmod);
776 void set_my_mod(Module *p_mod);
777 int get_imports_size() const {return impmods_v.size();}
778 ImpMod* get_impmod(int index) const {return impmods_v[index];}
779 /** Checks the existence of imported modules and detects duplicated imports
780 * from the same module. Initializes \a impmods_m. */
781 void chk_uniq();
782 /** Checks the existence of imported symbols and checks import definitions
783 * in the imported modules recursively. */
784 void chk_imp(ReferenceChain& refch, vector<Common::Module>& moduleStack);
785 /** Returns \p true if an imported module with the given name exists,
786 * else returns \p false. */
787 bool has_impmod_withId(const Identifier& p_id) const;
788 /** Returns whether a definition with identifier \a p_id is imported
789 * from one or more modules */
790 bool has_imported_def(const Identifier& p_id, const Location *loc) const;
791 /** Returns the imported definition with name \a p_id if it is
792 * unambiguous or NULL otherwise.
793 * \a loc is used to report an error if it is needed */
794 Common::Assignment *get_imported_def(const Identifier& p_source_modid,
795 const Identifier& p_id, const Location *loc, ReferenceChain* refch);
796 void get_imported_mods(Module::module_set_t& p_imported_mods) const;
797 void generate_code(output_struct *target);
798 void generate_code(CodeGenHelper& cgh);
799 virtual void dump(unsigned level) const;
800 };
801
802 class Definition : public Common::Assignment {
803 protected: // many derived classes
804 /** Contains the C++ identifier of the definition. If empty the C++
805 * identifier is generated from \a id. */
806 string genname;
807 /** The group it's in, if any */
808 Group *parentgroup;
809 WithAttribPath* w_attrib_path;
810 ErroneousAttributes* erroneous_attrs; // set by chk_erroneous_attr() or NULL
811 /** True if function/altstep/default scope, not module scope */
812 bool local_scope;
813
814 Definition(const Definition& p)
815 : Common::Assignment(p), genname(), parentgroup(0),
816 w_attrib_path(0), erroneous_attrs(0), local_scope(false)
817 { }
818 virtual string get_genname() const;
819
820 namedbool has_implicit_omit_attr() const;
821 private:
822 /// %Assignment disabled
823 Definition& operator=(const Definition& p);
824 public:
825 Definition(asstype_t p_asstype, Identifier *p_id)
826 : Common::Assignment(p_asstype, p_id), genname(), parentgroup(0),
827 w_attrib_path(0), erroneous_attrs(0), local_scope(false)
828 { }
829 virtual ~Definition();
830 virtual Definition* clone() const = 0;
831 virtual void set_fullname(const string& p_fullname);
832 virtual bool is_local() const;
833 /** Sets the visibility type of the definition */
834 void set_visibility(const visibility_t p_visibility)
835 { visibilitytype = p_visibility; }
836 /** Marks the (template) definition as local to a func/altstep/default */
837 inline void set_local() { local_scope = true; }
838
839 void set_genname(const string& p_genname) { genname = p_genname; }
840 /** Check if two definitions are (almost) identical, the type and dimensions
841 * must always be identical, the initial values can be different depending
842 * on the definition type. If error was reported the return value is false.
843 * The initial values (if applicable) may be present/absent, different or
844 * unfoldable. The function must be overridden to be used.
845 */
846 virtual bool chk_identical(Definition *p_def);
847 /** Parse and check the erroneous attribute data,
848 * sets erroneous_attrs member */
849 void chk_erroneous_attr();
850 /** This code generation is used when this definition is embedded
851 * in a statement block. */
852 virtual char* generate_code_str(char *str);
853 virtual void ilt_generate_code(ILT *ilt);
854 /** Generates the C++ initializer sequence for a definition of a component
855 * type, appends to \a str and returns the resulting string. The function
856 * is used when \a this is realized using the C++ objects of definition
857 * \a base_defn inherited from another component type. The function is
858 * implemented only for those definitions that can appear within component
859 * types, the generic version causes \a FATAL_ERROR. */
860 virtual char *generate_code_init_comp(char *str, Definition *base_defn);
861 virtual void dump_internal(unsigned level) const;
862 virtual void dump(unsigned level) const;
863 virtual void set_with_attr(MultiWithAttrib* p_attrib);
864 virtual WithAttribPath* get_attrib_path();
865 virtual void set_parent_path(WithAttribPath* p_path);
866 virtual void set_parent_group(Group* p_group);
867 virtual Group* get_parent_group();
868 };
869
870 /**
871 * TTCN-3 type definition (including signatures and port types).
872 */
873 class Def_Type : public Definition {
874 private:
875 Type *type;
876
877 NameBridgingScope bridgeScope;
878
879 /** Copy constructor not implemented */
880 Def_Type(const Def_Type& p);
881 /** %Assignment disabled */
882 Def_Type& operator=(const Def_Type& p);
883 public:
884 Def_Type(Identifier *p_id, Type *p_type);
885 virtual ~Def_Type();
886 virtual Def_Type* clone() const;
887 virtual void set_fullname(const string& p_fullname);
888 virtual void set_my_scope(Scope *p_scope);
889 virtual Setting *get_Setting();
890 virtual Type *get_Type();
891 virtual void chk();
892 virtual void generate_code(output_struct *target, bool clean_up = false);
893 virtual void generate_code(CodeGenHelper& cgh);
894 virtual void dump_internal(unsigned level) const;
895 virtual void set_with_attr(MultiWithAttrib* p_attrib);
896 virtual WithAttribPath* get_attrib_path();
897 virtual void set_parent_path(WithAttribPath* p_path);
898 };
899
900 /**
901 * TTCN-3 constant definition.
902 */
903 class Def_Const : public Definition {
904 private:
905 Type *type;
906 Value *value;
907 bool value_under_check;
908
909 /// Copy constructor disabled
910 Def_Const(const Def_Const& p);
911 /// %Assignment disabled
912 Def_Const& operator=(const Def_Const& p);
913 public:
914 Def_Const(Identifier *p_id, Type *p_type, Value *p_value);
915 virtual ~Def_Const();
916 virtual Def_Const *clone() const;
917 virtual void set_fullname(const string& p_fullname);
918 virtual void set_my_scope(Scope *p_scope);
919 virtual Setting *get_Setting();
920 virtual Type *get_Type();
921 virtual Value *get_Value();
922 virtual void chk();
923 virtual bool chk_identical(Definition *p_def);
924 virtual void generate_code(output_struct *target, bool clean_up = false);
925 virtual void generate_code(CodeGenHelper& cgh);
926 virtual char* generate_code_str(char *str);
927 virtual void ilt_generate_code(ILT *ilt);
928 virtual char *generate_code_init_comp(char *str, Definition *base_defn);
929 virtual void dump_internal(unsigned level) const;
930 };
931
932 /**
933 * TTCN-3 external constant definition.
934 */
935 class Def_ExtConst : public Definition {
936 private:
937 Type *type;
938
939 /// Copy constructor disabled
940 Def_ExtConst(const Def_ExtConst& p);
941 /// %Assignment disabled
942 Def_ExtConst& operator=(const Def_ExtConst& p);
943 public:
944 Def_ExtConst(Identifier *p_id, Type *p_type);
945 virtual ~Def_ExtConst();
946 virtual Def_ExtConst *clone() const;
947 virtual void set_fullname(const string& p_fullname);
948 virtual void set_my_scope(Scope *p_scope);
949 virtual Type *get_Type();
950 virtual void chk();
951 virtual void generate_code(output_struct *target, bool clean_up = false);
952 virtual void generate_code(CodeGenHelper& cgh);
953 virtual void dump_internal(unsigned level) const;
954 };
955
956 /**
957 * TTCN-3 module parameter definition.
958 */
959 class Def_Modulepar : public Definition {
960 private:
961 Type *type;
962 Value* def_value;
963 /// Copy constructor disabled
964 Def_Modulepar(const Def_Modulepar& p);
965 /// %Assignment disabled
966 Def_Modulepar& operator=(const Def_Modulepar& p);
967 public:
968 Def_Modulepar(Identifier *p_id, Type *p_type, Value *p_defval);
969 virtual ~Def_Modulepar();
970 virtual Def_Modulepar* clone() const;
971 virtual void set_fullname(const string& p_fullname);
972 virtual void set_my_scope(Scope *p_scope);
973 virtual Type *get_Type();
974 virtual void chk();
975 virtual void generate_code(output_struct *target, bool clean_up = false);
976 virtual void generate_code(CodeGenHelper& cgh);
977 virtual void dump_internal(unsigned level) const;
978 };
979
980 /**
981 * TTCN-3 template module parameter definition.
982 */
983 class Def_Modulepar_Template : public Definition {
984 private:
985 Type *type;
986 Template* def_template;
987 /// Copy constructor disabled
988 Def_Modulepar_Template(const Def_Modulepar_Template& p);
989 /// %Assignment disabled
990 Def_Modulepar_Template& operator=(const Def_Modulepar_Template& p);
991 public:
992 Def_Modulepar_Template(Identifier *p_id, Type *p_type, Template *p_defval);
993 virtual ~Def_Modulepar_Template();
994 virtual Def_Modulepar_Template* clone() const;
995 virtual void set_fullname(const string& p_fullname);
996 virtual void set_my_scope(Scope *p_scope);
997 virtual Type *get_Type();
998 virtual void chk();
999 virtual void generate_code(output_struct *target, bool clean_up = false);
1000 virtual void generate_code(CodeGenHelper& cgh);
1001 virtual void dump_internal(unsigned level) const;
1002 };
1003
1004 /**
1005 * Def_Template class represents a template definition.
1006 */
1007 class Def_Template : public Definition {
1008 private:
1009 /* the type of the template */
1010 Type *type;
1011 /** The formal parameter list of the template. It is NULL in case of
1012 * non-parameterized templates. */
1013 FormalParList *fp_list;
1014 /** points to the base template reference in case of modified templates,
1015 * otherwise it is NULL */
1016 Reference *derived_ref;
1017 /** shortcut to the base template in case of modified templates,
1018 * otherwise it is NULL */
1019 Def_Template *base_template;
1020 /** Indicates whether the circular recursion chain of modified templates
1021 * has been checked. */
1022 bool recurs_deriv_checked;
1023 /** the body of the template */
1024 Template *body;
1025 /** template definition level restriction */
1026 template_restriction_t template_restriction;
1027 /** set in chk(), used by code generation,
1028 * valid if template_restriction!=TR_NONE */
1029 bool gen_restriction_check;
1030
1031 NameBridgingScope bridgeScope;
1032
1033 /// Copy constructor for Def_Template::clone() only
1034 Def_Template(const Def_Template& p);
1035 /// %Assignment disabled
1036 Def_Template& operator=(const Def_Template& p);
1037 public:
1038 Def_Template(template_restriction_t p_template_restriction,
1039 Identifier *p_id, Type *p_type, FormalParList *p_fpl,
1040 Reference *p_derived_ref, Template *p_body);
1041 virtual ~Def_Template();
1042 virtual Def_Template *clone() const;
1043 virtual void set_fullname(const string& p_fullname);
1044 virtual void set_my_scope(Scope *p_scope);
1045 virtual Setting *get_Setting();
1046 virtual Type *get_Type();
1047 virtual Template *get_Template();
1048 virtual FormalParList *get_FormalParList();
1049 virtual void chk();
1050 private:
1051 void chk_modified();
1052 void chk_default() const;
1053 void chk_recursive_derivation();
1054 public:
1055 virtual void generate_code(output_struct *target, bool clean_up = false);
1056 virtual void generate_code(CodeGenHelper& cgh);
1057 virtual char* generate_code_str(char *str);
1058 virtual void ilt_generate_code(ILT *ilt);
1059 virtual void dump_internal(unsigned level) const;
1060 template_restriction_t get_template_restriction()
1061 { return template_restriction; }
1062 };
1063
1064 /**
1065 * Def_Var class represents a variable definition.
1066 */
1067 class Def_Var : public Definition {
1068 private:
1069 Type *type;
1070 /** the initial value: optional and maybe incomplete */
1071 Value *initial_value;
1072
1073 /// Copy constructor disabled
1074 Def_Var(const Def_Var& p);
1075 /// %Assignment disabled
1076 Def_Var& operator=(const Def_Var& p);
1077 public:
1078 Def_Var(Identifier *p_id, Type *p_type, Value *p_initial_value);
1079 virtual ~Def_Var();
1080 virtual Def_Var *clone() const;
1081 virtual void set_fullname(const string& p_fullname);
1082 virtual void set_my_scope(Scope *p_scope);
1083 virtual Type *get_Type();
1084 virtual void chk();
1085 virtual bool chk_identical(Definition *p_def);
1086 virtual void generate_code(output_struct *target, bool clean_up = false);
1087 virtual void generate_code(CodeGenHelper& cgh);
1088 virtual char* generate_code_str(char *str);
1089 virtual void ilt_generate_code(ILT *ilt);
1090 virtual char *generate_code_init_comp(char *str, Definition *base_defn);
1091 virtual void dump_internal(unsigned level) const;
1092 };
1093
1094 /**
1095 * Def_Var_Template class represents a template variable (dynamic template)
1096 * definition.
1097 */
1098 class Def_Var_Template : public Definition {
1099 private:
1100 Type *type;
1101 /** the initial value: optional and maybe incomplete */
1102 Template *initial_value;
1103 /** optional restriction on this variable */
1104 template_restriction_t template_restriction;
1105 /** set in chk(), used by code generation,
1106 * valid if template_restriction!=TR_NONE */
1107 bool gen_restriction_check;
1108
1109 /// Copy constructor disabled
1110 Def_Var_Template(const Def_Var_Template& p);
1111 /// %Assignment disabled
1112 Def_Var_Template& operator=(const Def_Var_Template& p);
1113 public:
1114 Def_Var_Template(Identifier *p_id, Type *p_type, Template *p_initial_value,
1115 template_restriction_t p_template_restriction);
1116 virtual ~Def_Var_Template();
1117 virtual Def_Var_Template *clone() const;
1118 virtual void set_fullname(const string& p_fullname);
1119 virtual void set_my_scope(Scope *p_scope);
1120 virtual Type *get_Type();
1121 virtual void chk();
1122 virtual bool chk_identical(Definition *p_def);
1123 virtual void generate_code(output_struct *target, bool clean_up = false);
1124 virtual void generate_code(CodeGenHelper& cgh);
1125 virtual char* generate_code_str(char *str);
1126 virtual void ilt_generate_code(ILT *ilt);
1127 virtual char *generate_code_init_comp(char *str, Definition *base_defn);
1128 virtual void dump_internal(unsigned level) const;
1129 template_restriction_t get_template_restriction()
1130 { return template_restriction; }
1131 };
1132
1133 /**
1134 * Def_Timer class represents a single timer declaration (e.g. in a
1135 * TTCN component type).
1136 */
1137 class Def_Timer : public Definition {
1138 private:
1139 /** Describes the dimensions of a timer array. It is NULL in case
1140 * of single timer instance. */
1141 ArrayDimensions *dimensions;
1142 /** Default duration of the timers. It can be either a single
1143 * float value or an array of floats. If it is NULL the timer(s)
1144 * has no default duration. */
1145 Value *default_duration;
1146
1147 /// Copy constructor disabled
1148 Def_Timer(const Def_Timer& p);
1149 /// %Assignment disabled
1150 Def_Timer& operator=(const Def_Timer& p);
1151 public:
1152 Def_Timer(Identifier *p_id, ArrayDimensions *p_dims, Value *p_dur)
1153 : Definition(A_TIMER, p_id), dimensions(p_dims),
1154 default_duration(p_dur) { }
1155 virtual ~Def_Timer();
1156 virtual Def_Timer *clone() const;
1157 virtual void set_fullname(const string& p_fullname);
1158 virtual void set_my_scope(Scope *p_scope);
1159 virtual ArrayDimensions *get_Dimensions();
1160 virtual void chk();
1161 virtual bool chk_identical(Definition *p_def);
1162 /** Returns false if it is sure that the timer referred by array
1163 * indices \a p_subrefs does not have a default
1164 * duration. Otherwise it returns true. Argument \a p_subrefs
1165 * might be NULL when examining a single timer. */
1166 bool has_default_duration(FieldOrArrayRefs *p_subrefs);
1167 private:
1168 /** Checks if the value \a dur is suitable as duration for a single
1169 * timer. */
1170 void chk_single_duration(Value *dur);
1171 /** Checks if the value \a dur is suitable as duration for a timer
1172 * array. The function calls itself recursively, argument \a
1173 * start_dim shall be zero when called from outside. */
1174 void chk_array_duration(Value *dur, size_t start_dim = 0);
1175 public:
1176 virtual void generate_code(output_struct *target, bool clean_up = false);
1177 virtual void generate_code(CodeGenHelper& cgh);
1178 private:
1179 /** Generates a C++ code fragment that sets the default duration
1180 * of a timer array. The generated code is appended to \a str and
1181 * the resulting string is returned. The equivalent C++ object of
1182 * timer array is named \a object_name, the array value containing
1183 * the default durations is \a dur. The function calls itself
1184 * recursively, argument \a start_dim shall be zero when called
1185 * from outside. */
1186 char *generate_code_array_duration(char *str, const char *object_name,
1187 Value *dur, size_t start_dim = 0);
1188 public:
1189 virtual char* generate_code_str(char *str);
1190 virtual void ilt_generate_code(ILT *ilt);
1191 virtual char *generate_code_init_comp(char *str, Definition *base_defn);
1192 virtual void dump_internal(unsigned level) const;
1193 };
1194
1195 /**
1196 * Def_Port class represents a port declaration (in a component type).
1197 */
1198 class Def_Port : public Definition {
1199 private:
1200 /** Contains a reference to a TTCN-3 port type */
1201 Reference *type_ref;
1202 /** Points to the object describing the port type.
1203 *
1204 * Derived from \a type_ref during Def_Port::chk().
1205 * It can be NULL in case of any error (e.g. the reference points to a
1206 * non-existent port type or the referenced entity is not a port type. */
1207 Type *port_type;
1208 /** Describes the dimensions of a port array.
1209 * It is NULL in case of single port instance. */
1210 ArrayDimensions *dimensions;
1211
1212 /// Copy constructor disabled
1213 Def_Port(const Def_Port& p);
1214 /// %Assignment disabled
1215 Def_Port& operator=(const Def_Port& p);
1216 public:
1217 /** Constructor
1218 *
1219 * @param p_id identifier (must not be NULL), the name of the port
1220 * @param p_tref type reference (must not be NULL)
1221 * @param p_dims array dimensions (NULL for a single port instance)
1222 */
1223 Def_Port(Identifier *p_id, Reference *p_tref, ArrayDimensions *p_dims);
1224 virtual ~Def_Port();
1225 virtual Def_Port *clone() const;
1226 virtual void set_fullname(const string& p_fullname);
1227 virtual void set_my_scope(Scope *p_scope);
1228 /** Get the \a port_type
1229 *
1230 * @pre chk() has been called (because it computes \a port_type)
1231 */
1232 virtual Type *get_Type();
1233 virtual ArrayDimensions *get_Dimensions();
1234 virtual void chk();
1235 virtual bool chk_identical(Definition *p_def);
1236 virtual void generate_code(output_struct *target, bool clean_up = false);
1237 virtual void generate_code(CodeGenHelper& cgh);
1238 virtual char *generate_code_init_comp(char *str, Definition *base_defn);
1239 virtual void dump_internal(unsigned level) const;
1240 };
1241
1242 /**
1243 * Common base class for function and external function definitions.
1244 */
1245 class Def_Function_Base : public Definition {
1246 public:
1247 enum prototype_t {
1248 PROTOTYPE_NONE, /**< no prototype(...) attribute */
1249 PROTOTYPE_CONVERT, /**< attribute prototype(convert) */
1250 PROTOTYPE_FAST, /**< attribute prototype(fast) */
1251 PROTOTYPE_BACKTRACK, /**< attribute prototype(backtrack) */
1252 PROTOTYPE_SLIDING /**< attribute prototype(sliding) */
1253 };
1254 protected: // Def_Function and Def_ExtFunction need access
1255 /** The formal parameter list of the function. It is never NULL even if
1256 * the function has empty parameter list. Owned. */
1257 FormalParList *fp_list;
1258 /** The return type of the function or NULL in case of no return type.
1259 * Owned. */
1260 Type *return_type;
1261 /** Identifier of the enc/dec API implemented by the function */
1262 prototype_t prototype;
1263 /** Shortcut to the input type if the function implements one of the
1264 * enc/dec APIs or NULL otherwise. Not owned. */
1265 Type *input_type;
1266 /** Shortcut to the output type if the function implements one of the
1267 * enc/dec APIs or NULL otherwise. Not owned */
1268 Type *output_type;
1269 /** optional template restriction on return template value */
1270 template_restriction_t template_restriction;
1271
1272 static asstype_t determine_asstype(bool is_external, bool has_return_type,
1273 bool returns_template);
1274 /// Copy constructor disabled
1275 Def_Function_Base(const Def_Function_Base& p);
1276 /// %Assignment disabled
1277 Def_Function_Base& operator=(const Def_Function_Base& p);
1278 public:
1279 /** Constructor.
1280 *
1281 * @param is_external true if external function (the derived type is
1282 * Def_ExtFunction), false if a TTCN-3 function (Def_Function)
1283 * @param p_id the name of the function
1284 * @param p_fpl formal parameter list
1285 * @param p_return_type return type (may be NULL)
1286 * @param returns_template true if the return is a template
1287 * @param p_template_restriction restriction type
1288 */
1289 Def_Function_Base(bool is_external, Identifier *p_id,
1290 FormalParList *p_fpl, Type *p_return_type, bool returns_template,
1291 template_restriction_t p_template_restriction);
1292 virtual ~Def_Function_Base();
1293 virtual void set_fullname(const string& p_fullname);
1294 virtual void set_my_scope(Scope *p_scope);
1295 virtual Type *get_Type();
1296 virtual FormalParList *get_FormalParList();
1297 prototype_t get_prototype() const { return prototype; }
1298 void set_prototype(prototype_t p_prototype) { prototype = p_prototype; }
1299 const char *get_prototype_name() const;
1300 void chk_prototype();
1301 Type *get_input_type();
1302 Type *get_output_type();
1303 template_restriction_t get_template_restriction()
1304 { return template_restriction; }
1305 };
1306
1307 /**
1308 * Def_Function class represents a function definition.
1309 */
1310 class Def_Function : public Def_Function_Base {
1311 private:
1312 /** The 'runs on' clause (i.e. a reference to a TTCN-3 component type)
1313 * It is NULL if the function has no 'runs on' clause. */
1314 Reference *runs_on_ref;
1315 /** Points to the object describing the component type referred by
1316 * 'runs on' clause.
1317 * It is NULL if the function has no 'runs on' clause or \a runs_on_ref is
1318 * erroneous. */
1319 Type *runs_on_type;
1320 /** The body of the function */
1321 StatementBlock *block;
1322 /** Indicates whether the function is startable. That is, it can be
1323 * launched as PTC behaviour as argument of a start test component
1324 * statement. */
1325 bool is_startable;
1326 /** Opts out from location information */
1327 bool transparent;
1328
1329 NameBridgingScope bridgeScope;
1330
1331 /// Copy constructor disabled
1332 Def_Function(const Def_Function& p);
1333 /// %Assignment disabled
1334 Def_Function& operator=(const Def_Function& p);
1335 public:
1336 /** Constructor for a TTCN-3 function definition
1337 *
1338 * Called from a single location in compiler.y
1339 *
1340 * @param p_id function name
1341 * @param p_fpl formal parameter list
1342 * @param p_runs_on_ref "runs on", else NULL
1343 * @param p_return_type return type, may be NULL
1344 * @param returns_template true if the return value is a template
1345 * @param p_template_restriction restriction type
1346 * @param p_block the body of the function
1347 */
1348 Def_Function(Identifier *p_id, FormalParList *p_fpl,
1349 Reference *p_runs_on_ref, Type *p_return_type,
1350 bool returns_template,
1351 template_restriction_t p_template_restriction,
1352 StatementBlock *p_block);
1353 virtual ~Def_Function();
1354 virtual Def_Function *clone() const;
1355 virtual void set_fullname(const string& p_fullname);
1356 virtual void set_my_scope(Scope *p_scope);
1357 virtual Type *get_RunsOnType();
1358 /** Returns a scope that can access the definitions within component type
1359 * \a comptype and its parent is \a parent_scope.*/
1360 RunsOnScope *get_runs_on_scope(Type *comptype);
1361 virtual void chk();
1362 /** Checks and returns whether the function is startable.
1363 * Reports the appropriate error message(s) if not. */
1364 bool chk_startable();
1365
1366 bool is_transparent() const { return transparent; }
1367
1368 virtual void generate_code(output_struct *target, bool clean_up = false);
1369 virtual void generate_code(CodeGenHelper& cgh);
1370 virtual void dump_internal(unsigned level) const;
1371
1372 virtual void set_parent_path(WithAttribPath* p_path);
1373 };
1374
1375 /** RAII class for transparent functions.
1376 *
1377 * Calls to TTCN_Location::update_lineno are written by Ttcn::Statement
1378 * by calling Common::Location::update_location_object. These calls
1379 * need to be removed inside transparent functions.
1380 *
1381 * It is difficult (impossible) for a Statement to navigate up in the AST
1382 * to the function/altstep/testcase/control part that contains it;
1383 * instead, the Def_Function sets a static flag inside Common::Location
1384 * that says "you are inside a transparent function" while
1385 * Def_Function::generate_code function runs.
1386 */
1387 class transparency_holder {
1388 bool old_transparency;
1389 public:
1390 /** Sets Common::Location::transparency (but remembers its old vaue)
1391 *
1392 * @param df the function definition
1393 */
1394 transparency_holder(const Def_Function &df)
1395 : old_transparency(Common::Location::transparency)
1396 { Common::Location::transparency = df.is_transparent(); }
1397
1398 /** Restores the value of Common::Location::transparency */
1399 ~transparency_holder()
1400 { Common::Location::transparency = old_transparency; }
1401 };
1402
1403 /**
1404 * Def_ExtFunction class represents an external function definition.
1405 */
1406 class Def_ExtFunction : public Def_Function_Base {
1407 public:
1408 enum ExternalFunctionType_t {
1409 EXTFUNC_MANUAL, /**< written manually by the user */
1410 EXTFUNC_ENCODE, /**< automatically generated encoder function */
1411 EXTFUNC_DECODE /**< automatically generated decoder function */
1412 };
1413 private:
1414 ExternalFunctionType_t function_type;
1415 Type::MessageEncodingType_t encoding_type;
1416 string *encoding_options;
1417 Ttcn::ErrorBehaviorList *eb_list;
1418 Ttcn::PrintingType *json_printing;
1419 /// Copy constructor disabled
1420 Def_ExtFunction(const Def_ExtFunction& p);
1421 /// %Assignment disabled
1422 Def_ExtFunction& operator=(const Def_ExtFunction& p);
1423 public:
1424 /** Constructor for an external function definition
1425 *
1426 * Called from a single location in compiler.y
1427 *
1428 * @param p_id the name
1429 * @param p_fpl formal parameters
1430 * @param p_return_type the return type
1431 * @param returns_template true if it returns a template
1432 * @param p_template_restriction restriction type
1433 */
1434 Def_ExtFunction(Identifier *p_id, FormalParList *p_fpl,
1435 Type *p_return_type, bool returns_template,
1436 template_restriction_t p_template_restriction)
1437 : Def_Function_Base(true, p_id, p_fpl, p_return_type, returns_template,
1438 p_template_restriction),
1439 function_type(EXTFUNC_MANUAL), encoding_type(Type::CT_UNDEF),
1440 encoding_options(0), eb_list(0), json_printing(0) { }
1441 ~Def_ExtFunction();
1442 virtual Def_ExtFunction *clone() const;
1443 virtual void set_fullname(const string& p_fullname);
1444 void set_encode_parameters(Type::MessageEncodingType_t p_encoding_type,
1445 string *p_encoding_options);
1446 void set_decode_parameters(Type::MessageEncodingType_t p_encoding_type,
1447 string *p_encoding_options);
1448 void add_eb_list(Ttcn::ErrorBehaviorList *p_eb_list);
1449 ExternalFunctionType_t get_function_type() const { return function_type; }
1450 private:
1451 void chk_function_type();
1452 void chk_allowed_encode();
1453 public:
1454 virtual void chk();
1455 private:
1456 char *generate_code_encode(char *str);
1457 char *generate_code_decode(char *str);
1458 public:
1459 virtual void generate_code(output_struct *target, bool clean_up = false);
1460 /// Just a shim for code splitting
1461 virtual void generate_code(CodeGenHelper& cgh);
1462 virtual void dump_internal(unsigned level) const;
1463
1464 /** For JSON encoding and decoding functions only
1465 * Generates a JSON schema segment containing a reference to the encoded
1466 * type's schema and any information required to recreate this function.
1467 * If the schema with the reference already exists, the function's info is
1468 * inserted in the schema. */
1469 void generate_json_schema_ref(map<Type*, JSON_Tokenizer>& json_refs);
1470 };
1471
1472 /**
1473 * Represents an altstep definition.
1474 */
1475 class Def_Altstep : public Definition {
1476 private:
1477 /** The formal parameter list of the altstep. It is never NULL even if
1478 * the altstep has no parameters. */
1479 FormalParList *fp_list;
1480 /** The 'runs on' clause (i.e. a reference to a TTCN-3 component type)
1481 * It is NULL if the altstep has no 'runs on' clause. */
1482 Reference *runs_on_ref;
1483 /** Points to the object describing the component type referred by
1484 * 'runs on' clause.
1485 * It is NULL if the altstep has no 'runs on' clause or \a runs_on_ref is
1486 * erroneous. */
1487 Type *runs_on_type;
1488 StatementBlock *sb; /**< contains the local definitions */
1489 AltGuards *ags;
1490
1491 NameBridgingScope bridgeScope;
1492
1493 /// Copy constructor disabled
1494 Def_Altstep(const Def_Altstep& p);
1495 /// %Assignment disabled
1496 Def_Altstep& operator=(const Def_Altstep& p);
1497 public:
1498 Def_Altstep(Identifier *p_id, FormalParList *p_fpl,
1499 Reference *p_runs_on_ref, StatementBlock *p_sb,
1500 AltGuards *p_ags);
1501 virtual ~Def_Altstep();
1502 virtual Def_Altstep *clone() const;
1503 virtual void set_fullname(const string& p_fullname);
1504 virtual void set_my_scope(Scope *p_scope);
1505 virtual Type *get_RunsOnType();
1506 virtual FormalParList *get_FormalParList();
1507 /** Returns a scope that can access the definitions within component type
1508 * \a comptype and its parent is \a parent_scope.*/
1509 RunsOnScope *get_runs_on_scope(Type *comptype);
1510 virtual void chk();
1511 virtual void generate_code(output_struct *target, bool clean_up = false);
1512 virtual void generate_code(CodeGenHelper& cgh);
1513 virtual void dump_internal(unsigned level) const;
1514
1515 virtual void set_parent_path(WithAttribPath* p_path);
1516 };
1517
1518 /**
1519 * Represents an testcase definition.
1520 */
1521 class Def_Testcase : public Definition {
1522 private:
1523 /** The formal parameter list of the testcase. It is never NULL even if
1524 * the testcase has no parameters. */
1525 FormalParList *fp_list;
1526 /** The 'runs on' clause (i.e. a reference to a TTCN-3 component type)
1527 * It is never NULL. */
1528 Reference *runs_on_ref;
1529 /** Points to the object describing the component type referred by
1530 * 'runs on' clause. It is NULL only if \a runs_on_ref is erroneous. */
1531 Type *runs_on_type;
1532 /** The 'system' clause (i.e. a reference to a TTCN-3 component type)
1533 * It is NULL if the testcase has no 'system' clause. */
1534 Reference *system_ref;
1535 /** Points to the object describing the component type referred by
1536 * 'system' clause. It is NULL if the testcase has no 'system' clause or
1537 * \a system_ref is erroneous. */
1538 Type *system_type;
1539 StatementBlock *block;
1540
1541 NameBridgingScope bridgeScope;
1542
1543 /// Copy constructor disabled
1544 Def_Testcase(const Def_Testcase& p);
1545 /// %Assignment disabled
1546 Def_Testcase& operator=(const Def_Testcase& p);
1547 public:
1548 Def_Testcase(Identifier *p_id, FormalParList *p_fpl,
1549 Reference *p_runs_on_ref, Reference *p_system_ref,
1550 StatementBlock *p_block);
1551 virtual ~Def_Testcase();
1552 virtual Def_Testcase *clone() const;
1553 virtual void set_fullname(const string& p_fullname);
1554 virtual void set_my_scope(Scope *p_scope);
1555 virtual Type *get_RunsOnType();
1556 Type *get_SystemType();
1557 virtual FormalParList *get_FormalParList();
1558 /** Returns a scope that can access the definitions within component type
1559 * \a comptype and its parent is \a parent_scope.*/
1560 RunsOnScope *get_runs_on_scope(Type *comptype);
1561 virtual void chk();
1562 virtual void generate_code(output_struct *target, bool clean_up = false);
1563 virtual void generate_code(CodeGenHelper& cgh);
1564 virtual void dump_internal(unsigned level) const;
1565
1566 virtual void set_parent_path(WithAttribPath* p_path);
1567 };
1568
1569 /** General class to represent formal parameters. The inherited
1570 * attribute asstype carries the kind and direction of the
1571 * parameter. */
1572 class FormalPar : public Definition {
1573 private:
1574 Type *type;
1575 /** Default value of the parameter (optional). If \a checked flag is true
1576 * then field \a ap is used otherwise \a ti is active. */
1577 union {
1578 TemplateInstance *ti;
1579 ActualPar *ap;
1580 } defval;
1581 /** Points to the formal parameter list that \a this belongs to. */
1582 FormalParList *my_parlist;
1583 /** Flag that indicates whether the value of the parameter is overwritten
1584 * within the function/altstep/testcase body.
1585 * Used only in case of `in' value or template parameters. */
1586 bool used_as_lvalue;
1587 /** restriction on template value */
1588 template_restriction_t template_restriction;
1589 /** normal or lazy evaluation parametrization should be used */
1590 bool lazy_eval;
1591
1592 /// Copy constructor disabled
1593 FormalPar(const FormalPar& p);
1594 /// %Assignment disabled
1595 FormalPar& operator=(const FormalPar& p);
1596 public:
1597 FormalPar(asstype_t p_asstype, Type *p_type, Identifier* p_name,
1598 TemplateInstance *p_defval, bool p_lazy_eval=false);
1599 FormalPar(asstype_t p_asstype,
1600 template_restriction_t p_template_restriction,
1601 Type *p_type, Identifier* p_name, TemplateInstance *p_defval,
1602 bool p_lazy_eval=false);
1603 FormalPar(asstype_t p_asstype, Identifier* p_name,
1604 TemplateInstance *p_defval);
1605 ~FormalPar();
1606 virtual FormalPar *clone() const;
1607 virtual void set_fullname(const string& p_fullname);
1608 virtual void set_my_scope(Scope *p_scope);
1609 /** Always true. Formal parameters are considered as local definitions
1610 * even if their scope is the module definitions. */
1611 virtual bool is_local() const;
1612 virtual Type *get_Type();
1613 virtual void chk();
1614 bool has_defval() const;
1615 bool has_notused_defval() const;
1616 /** Get the default value.
1617 * \pre chk() has been called (checked==true) */
1618 ActualPar *get_defval() const;
1619 void set_defval(ActualPar *defpar);
1620 void set_my_parlist(FormalParList *p_parlist) { my_parlist = p_parlist; }
1621 FormalParList *get_my_parlist() const { return my_parlist; }
1622 ActualPar *chk_actual_par(TemplateInstance *actual_par,
1623 Type::expected_value_t exp_val);
1624 private:
1625 ActualPar *chk_actual_par_value(TemplateInstance *actual_par,
1626 Type::expected_value_t exp_val);
1627 ActualPar *chk_actual_par_template(TemplateInstance *actual_par,
1628 Type::expected_value_t exp_val);
1629 ActualPar *chk_actual_par_by_ref(TemplateInstance *actual_par,
1630 bool is_template, Type::expected_value_t exp_val);
1631 ActualPar *chk_actual_par_timer(TemplateInstance *actual_par,
1632 Type::expected_value_t exp_val);
1633 ActualPar *chk_actual_par_port(TemplateInstance *actual_par,
1634 Type::expected_value_t exp_val);
1635 public:
1636 /** Checks whether the value of the parameter may be modified in the body
1637 * of the parameterized definition (in assignment, port redirect or passing
1638 * it further as 'out' or 'inout' parameter). Applicable to `in' value or
1639 * template parameters only. Note that formal parameters of templates cannot
1640 * be modified. If the modification is allowed a flag is set, which is
1641 * considered at C++ code generation. Argument \a p_loc is used for error
1642 * reporting. */
1643 virtual void use_as_lvalue(const Location& p_loc);
1644 bool get_used_as_lvalue() const { return used_as_lvalue; }
1645 /** Generates the C++ objects that represent the default value for the
1646 * parameter (if present). */
1647 virtual void generate_code_defval(output_struct *target, bool clean_up = false);
1648 /** Generates the C++ equivalent of the formal parameter, appends it to
1649 * \a str and returns the resulting string. */
1650 char *generate_code_fpar(char *str);
1651 /** Generates a C++ statement that defines an object (variable) for the
1652 * formal parameter, appends it to \a str and returns the resulting
1653 * string. The name of the object is constructed from \a p_prefix and the
1654 * parameter identifier.
1655 * The \a refch parameter is needed when the code for start_ptc_function is
1656 * generated, because reference is generated in case of inout parameters. */
1657 char *generate_code_object(char *str, const char *p_prefix,
1658 char refch = '&');
1659 /** Generates a C++ statement that instantiates a shadow object for the
1660 * parameter when necessary. It is used when the value of an 'in' value or
1661 * template parameter is overwritten within the function body. */
1662 char *generate_shadow_object(char *str) const;
1663 /** Generates a C++ statement that calls a function that sets the parameter unbound
1664 * It is used when the value of an 'out' value */
1665 char *generate_code_set_unbound(char *str) const;
1666 virtual void dump_internal(unsigned level) const;
1667 template_restriction_t get_template_restriction()
1668 { return template_restriction; }
1669 virtual bool get_lazy_eval() const { return lazy_eval; }
1670 // code generation: get the C++ string that refers to the formal parameter
1671 // adds a casting to data type if wrapped into a lazy param
1672 string get_reference_name(Scope* scope) const;
1673 };
1674
1675 /** Class to represent a list of formal parameters. Owned by a
1676 * Def_Template, Def_Function_Base, Def_Altstep or Def_Testcase. */
1677 class FormalParList : public Scope, public Location {
1678 private:
1679 vector<FormalPar> pars_v;
1680 /** Map names to the formal parameters in pars_v. Filled by
1681 * FormalParList::chk*/
1682 map<string, FormalPar> pars_m;
1683 /** Indicates the minimal number of actual parameters that must be present
1684 * in parameterized references. Could be less than the size of pars_v
1685 * if some parameters have default values. */
1686 size_t min_nof_pars;
1687 /** Points to the definition that the parameter list belongs to. */
1688 Definition *my_def;
1689 bool checked;
1690 bool is_startable;
1691
1692 /** Copy constructor. For FormalParList::clone() only. */
1693 FormalParList(const FormalParList& p);
1694 /** %Assignment disallowed. */
1695 FormalParList& operator=(const FormalParList& p);
1696 public:
1697 FormalParList() : Scope(), Location(), pars_v(), pars_m()
1698 , min_nof_pars(0), my_def(0), checked(false), is_startable(false) {}
1699 ~FormalParList();
1700 virtual FormalParList *clone() const;
1701 virtual void set_fullname(const string& p_fullname);
1702 /** Sets the parent scope and the scope of parameters to \a p_scope. */
1703 virtual void set_my_scope(Scope *p_scope);
1704 void set_my_def(Definition *p_def) { my_def = p_def; }
1705 Definition *get_my_def() const { return my_def; }
1706 void add_fp(FormalPar *p_fp);
1707 size_t get_nof_fps() const { return pars_v.size(); }
1708 bool has_notused_defval() const;
1709 bool has_only_default_values() const;
1710 bool has_fp_withName(const Identifier& p_name);
1711 FormalPar *get_fp_byName(const Identifier& p_name);
1712 FormalPar *get_fp_byIndex(size_t n) const { return pars_v[n]; }
1713 bool get_startability();
1714 virtual Common::Assignment *get_ass_bySRef(Common::Ref_simple *p_ref);
1715 virtual bool has_ass_withId(const Identifier& p_id);
1716 /** Checks the parameter list, which belongs to definition of type
1717 * \a deftype. */
1718 void chk(Definition::asstype_t deftype);
1719 void chk_noLazyParams();
1720 /** Checks the parameter list for startability: reports error if the owner
1721 * function cannot be started on a PTC. Used by functions and function
1722 * types. Parameter \a p_what shall contain "Function" or "Function type",
1723 * \a p_name shall contain the name of the function or function type. */
1724 void chk_startability(const char *p_what, const char *p_name);
1725 /** Checks the compatibility of two formal parameter list.
1726 * They are compatible if every parameter is compatible, has the same
1727 * attribute, and name */
1728 void chk_compatibility(FormalParList* p_fp_list, const char* where);
1729 /** Checks the parsed actual parameters in \a p_tis against \a this.
1730 * The actual parameters that are the result of transformation are added to
1731 * \a p_aplist (which is usually empty when this function is called).
1732 * \return true in case of any error, false after a successful check. */
1733 bool chk_actual_parlist(TemplateInstances *p_tis, ActualParList *p_aplist);
1734 /** Fold named parameters into the unnamed (order-based) param list.
1735 *
1736 * Named parameters are checked against the formal parameters.
1737 * Found ones are transferred into the unnamed param list at the
1738 * appropriate index.
1739 *
1740 * @param p_paps actual parameters from the parser (Bison); contains
1741 * both named and unnamed parameters
1742 * @param p_aplist actual parameters
1743 * @return the result of calling chk_actual_parlist, above:
1744 * true if error, false if the check is successful
1745 */
1746 bool fold_named_and_chk(ParsedActualParameters *p_paps, ActualParList *p_aplist);
1747 bool chk_activate_argument(ActualParList *p_aplist,
1748 const char* p_description);
1749 void set_genname(const string& p_prefix);
1750 /** Generates the C++ equivalent of the formal parameter list, appends it
1751 * to \a str and returns the resulting string. */
1752 char *generate_code(char *str);
1753 /** Generates the C++ objects that represent the default values for the
1754 * parameters (if present). */
1755 void generate_code_defval(output_struct *target);
1756 /** Generates a C++ actual parameter list for wrapper functions, appends it
1757 * to \a str and returns the resulting string. It contains the
1758 * comma-separated list of parameter identifiers prefixed by \a p_prefix. */
1759 char *generate_code_actual_parlist(char *str, const char *p_prefix);
1760 /** Generates a C++ code sequence that defines an object (variable) for
1761 * each formal parameter (which is used in wrapper functions), appends it
1762 * to \a str and returns the resulting string. The name of each object is
1763 * constructed from \a p_prefix and the parameter identifier.
1764 * The \a refch parameter is needed when the code for start_ptc_function is
1765 * generated, because reference is generated in case of inout parameters. */
1766 char *generate_code_object(char *str, const char *p_prefix,
1767 char refch = '&');
1768 /** Generates the C++ shadow objects for all parameters. */
1769 char *generate_shadow_objects(char *str) const;
1770 char *generate_code_set_unbound(char *str) const;
1771 void dump(unsigned level) const;
1772 };
1773
1774 } // namespace Ttcn
1775
1776 #endif // _Ttcn_AST_HH
This page took 0.093303 seconds and 5 git commands to generate.