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