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