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