AST_ttcn3.hh 85 KB
Newer Older
Elemer Lelik's avatar
Elemer Lelik committed
1
/******************************************************************************
Adam Knapp's avatar
Adam Knapp committed
2
 * Copyright (c) 2000-2021 Ericsson Telecom AB
Elemer Lelik's avatar
Elemer Lelik committed
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v2.0
Elemer Lelik's avatar
Elemer Lelik committed
5
 * which accompanies this distribution, and is available at
6
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
Elemer Lelik's avatar
Elemer Lelik committed
7
8
9
10
11
12
13
14
15
16
17
18
19
 *
 * Contributors:
 *   Baji, Laszlo
 *   Balasko, Jeno
 *   Baranyi, Botond
 *   Delic, Adam
 *   Kovacs, Ferenc
 *   Raduly, Csaba
 *   Szabados, Kristof
 *   Zalanyi, Balazs Andor
 *   Pandi, Krisztian
 *
 ******************************************************************************/
Elemer Lelik's avatar
Elemer Lelik committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef _Ttcn_AST_HH
#define _Ttcn_AST_HH

#include "../AST.hh"

namespace Common {
class CodeGenHelper;
}

/**
 * This namespace contains classes unique to TTCN-3 and some specializations
 * of classes from Common.
 */
namespace Ttcn {

  /**
   * \addtogroup AST
   *
   * @{
   */

  using namespace Common;

  class Module;
  class Definition;
  class FriendMod;
  class Imports;
  class ImpMod;
  class ActualPar;
  class ActualParList;
  class FormalParList;
  class ParsedActualParameters;
  class Template;
  class TemplateInstance;
  class TemplateInstances;
  class ArrayDimensions;
  class Timer;
  class StatementBlock;
  class AltGuards;
  class ILT;
  class Group;
  class WithAttribPath;
  class ErrorBehaviorList;
  class ErroneousAttributes;
  class ErroneousAttributeSpec;
  class PrintingType;

  /** Class to represent an actual parameter */
  class ActualPar : public Node {
  public:
    enum ap_selection_t {
      AP_ERROR,    ///< erroneous
      AP_VALUE,    ///< "in" value parameter
      AP_TEMPLATE, ///< "in" template parameter
      AP_REF,      ///< out/inout value or template parameter
      AP_DEFAULT   ///< created from the default value of a formal parameter
    };
  private:
    ap_selection_t selection;
    union {
      Value *val; ///< Value for AP_VALUE. Owned by ActualPar
      TemplateInstance *temp; ///< %Template for AP_TEMPLATE. Owned by ActualPar
82
      Reference *ref; ///< %Reference for AP_REF. Owned by ActualPar
Elemer Lelik's avatar
Elemer Lelik committed
83
84
85
86
87
88
89
90
91
92
93
      ActualPar *act; ///< For AP_DEFAULT. \b Not owned by ActualPar
    };
    Scope *my_scope; ///< %Scope. Not owned
    /** tells what runtime template restriction check to generate,
     *  TR_NONE means that no check is needed because it could be determined
     *  in compile time */
    template_restriction_t gen_restriction_check;
    /** if this is an actual template parameter of an external function add
     *  runtime checks for out and inout parameters after the call */
    template_restriction_t gen_post_restriction_check;
  private:
94
    /** Copy constructor */
Elemer Lelik's avatar
Elemer Lelik committed
95
96
97
98
99
100
101
102
103
104
105
106
107
    ActualPar(const ActualPar& p);
    /** %Assignment disabled */
    ActualPar& operator=(const ActualPar& p);
  public:
    /// Constructor for an erroneous object (fallback)
    ActualPar()
    : Node(), selection(AP_ERROR), my_scope(0),
      gen_restriction_check(TR_NONE), gen_post_restriction_check(TR_NONE) {}
    /// Actual par for an in value parameter
    ActualPar(Value *v);
    /// Actual par for an in template parameter
    ActualPar(TemplateInstance *t);
    /// Actual par for an {out or inout} {value or template} parameter
108
    ActualPar(Reference *r);
Elemer Lelik's avatar
Elemer Lelik committed
109
110
111
112
113
114
115
116
117
118
119
    /// Created from the default value of a formal par, at the call site,
    ///
    ActualPar(ActualPar *a);
    virtual ~ActualPar();
    virtual ActualPar *clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    bool is_erroneous() const { return selection == AP_ERROR; }
    ap_selection_t get_selection() const { return selection; }
    Value *get_Value() const;
    TemplateInstance *get_TemplateInstance() const;
120
    Reference *get_Ref() const;
Elemer Lelik's avatar
Elemer Lelik committed
121
122
123
124
125
    ActualPar *get_ActualPar() const;
    /** Checks the embedded recursions within the value or template instance. */
    void chk_recursions(ReferenceChain& refch);
    /** Returns whether the actual parameter can be represented by an in-line
     * C++ expression. */
126
    bool has_single_expr(FormalPar* formal_par);
Elemer Lelik's avatar
Elemer Lelik committed
127
128
129
130
131
    void set_code_section(GovernedSimple::code_section_t p_code_section);
    /** Generates the C++ equivalent of \a this into \a expr.
     * Flag \a copy_needed indicates whether to add an extra copy constructor
     * call if \a this contains a referenced value or template to avoid
     * aliasing problems with other out/inout parameters. */
132
    void generate_code(expression_struct *expr, bool copy_needed, FormalPar* formal_par) const;
Elemer Lelik's avatar
Elemer Lelik committed
133
    /** Appends the initialization sequence of all (directly or indirectly)
Elemer Lelik's avatar
Elemer Lelik committed
134
135
136
137
138
     * referred non-parameterized templates and the default values of all
     *  parameterized templates to \a str and returns the resulting string. 
     *  Only objects belonging to module \a usage_mod are initialized. */
    char *rearrange_init_code(char *str, Common::Module* usage_mod);
    char *rearrange_init_code_defval(char *str, Common::Module* usage_mod);
Elemer Lelik's avatar
Elemer Lelik committed
139
140
141
142
143
144
145
146
147
148
    /** Appends the string representation of the actual parameter to \a str. */
    void append_stringRepr(string& str) const;
    virtual void dump(unsigned level) const;
    void set_gen_restriction_check(template_restriction_t tr)
      { gen_restriction_check = tr; }
    template_restriction_t get_gen_restriction_check()
      { return gen_restriction_check; }
    void set_gen_post_restriction_check(
      template_restriction_t p_gen_post_restriction_check)
      { gen_post_restriction_check = p_gen_post_restriction_check; }
149
    Location* get_location() const;
Elemer Lelik's avatar
Elemer Lelik committed
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
  };

  /// A collection of actual parameters (parameter list)
  class ActualParList : public Node {
    vector<ActualPar> params;
  public:
    ActualParList(): Node(), params() { }
    ActualParList(const ActualParList& p);
    ~ActualParList();
    ActualParList* clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    size_t get_nof_pars() const { return params.size(); }
    void add(ActualPar* p) { params.add(p); }
    ActualPar* get_par(size_t i) const { return params[i]; }
    /** Checks the embedded recursions within the values and template
     * instances of actual parameters. */
    void chk_recursions(ReferenceChain& refch);
168
169

    void chk_immutability();
Elemer Lelik's avatar
Elemer Lelik committed
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
    /** Generates the C++ equivalent of the actual parameter list without
     * considering any aliasing between variables and 'in' parameters. */
    void generate_code_noalias(expression_struct *expr, FormalParList *p_fpl);
    /** Generates the C++ equivalent of the actual parameter list considering
     * aliasing problems between the 'in' parameters and 'out'/'inout'
     * parameters as well as component variables seen by the called definition.
     * Argument \a p_fpl points to the formal parameter list of the referred
     * definition if it is known, otherwise it is NULL. Argument \a p_comptype
     * points to the component type identified by the 'runs on' clause of the
     * referred definition (if exists and relevant for alias analysis,
     * otherwise NULL).
     * When invoke() is used with FAT types: the special case of 'runs on self'
     * has the argument \a p_compself set to true and \a p_comptype is NULL,
     * but the component is 'self' or any compatible component. */
    void generate_code_alias(expression_struct *expr, FormalParList *p_fpl,
      Type *p_comptype, bool p_compself);
    /** Walks through the parameter list and appends the initialization
     * sequence of all (directly or indirectly) referred non-parameterized
Elemer Lelik's avatar
Elemer Lelik committed
188
189
190
191
     * templates and the default values of all parameterized templates to
     * \a str and returns the resulting string. 
     * Only objects belonging to module \a usage_mod are initialized. */
    char *rearrange_init_code(char *str, Common::Module* usage_mod);
Elemer Lelik's avatar
Elemer Lelik committed
192
193
194
195
196
197
    virtual void dump(unsigned level) const;
  };

  /** Helper class for the Ttcn::Reference */
  class FieldOrArrayRef : public Node, public Location {
  public:
198
    enum reftype { FIELD_REF, ARRAY_REF, FUNCTION_REF };
Elemer Lelik's avatar
Elemer Lelik committed
199
200
201
202
  private:
    reftype ref_type; ///< reference type
    /** The stored reference. Owned and destroyed by FieldOrArrayRef */
    union {
203
204
205
206
207
      struct {
        Identifier *id; ///< name of the field, used by FIELD_REF and FUNCTION_REF
        bool checked;
        union {
          ParsedActualParameters* parsed_pars; ///< parsed function parameters, used by FUNCTION_REF
208
209
210
211
          struct {
            ActualParList* ap_list; ///< actual parameter list (after semantic analysis), used by FUNCTION_REF
            FormalParList* fp_list; ///< formal parameter list (after semantic analysis, not owned), used by FUNCTION_REF
          };
212
213
214
        };
      } ff; ///< field or function
      Value *arp; ///< value of the index, used by ARRAY_REF
Elemer Lelik's avatar
Elemer Lelik committed
215
216
217
218
219
220
    } u;
    /** Copy constructor for clone() only */
    FieldOrArrayRef(const FieldOrArrayRef& p);
    /** %Assignment disabled */
    FieldOrArrayRef& operator=(const FieldOrArrayRef& p);
  public:
221
    FieldOrArrayRef(Identifier *p_id, ParsedActualParameters* p_params = NULL);
Elemer Lelik's avatar
Elemer Lelik committed
222
223
224
225
226
227
228
229
230
231
232
233
    FieldOrArrayRef(Value *p_arp);
    ~FieldOrArrayRef();
    virtual FieldOrArrayRef* clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    reftype get_type() const { return ref_type; }
    /** Return the identifier.
     * @pre reftype is FIELD_REF, or else FATAL_ERROR */
    const Identifier* get_id() const;
    /** Returns the value.
     * @pre reftype is ARRAY_REF, or else FATAL_ERROR */
    Value* get_val() const;
234
235
    ParsedActualParameters* get_parsed_pars() const;
    ActualParList* get_actual_par_list() const;
236
    FormalParList* get_formal_par_list() const;
237
    bool parameters_checked() const;
238
    void set_parameter_list(ActualParList* p_ap_list, FormalParList* p_fp_list);
Elemer Lelik's avatar
Elemer Lelik committed
239
240
    /** Appends the string representation of the sub-reference to \a str. */
    void append_stringRepr(string& str) const;
Elemer Lelik's avatar
Elemer Lelik committed
241
242
243
244
245
246
    /** Sets the first letter in the name of the field to lowercase if it's an
      * uppercase letter.
      * Used on open types (the name of their alternatives can be given with both
      * an uppercase or a lowercase first letter, and the generated code will need
      * to use the lowercase version). */
    void set_field_name_to_lowercase();
Elemer Lelik's avatar
Elemer Lelik committed
247
248
249
250
251
252
253
254
255
256
  };

  /** A vector of FieldOrArrayRef objects */
  class FieldOrArrayRefs : public Node {
    /** Element holder. This FieldOrArrayRefs object owns the elements
     * and will free them in the destructor. */
    vector<FieldOrArrayRef> refs;
    /** Indicates whether the last array index refers to an element of a
     * string value. */
    bool refs_str_element;
257
    Common::Scope* my_scope; ///< %Scope. Not owned
258
    bool checked; // set by Type::get_field_type
Elemer Lelik's avatar
Elemer Lelik committed
259
  public:
260
    FieldOrArrayRefs() : Node(), refs(), refs_str_element(false), my_scope(NULL), checked(false) { }
Elemer Lelik's avatar
Elemer Lelik committed
261
262
263
264
265
    FieldOrArrayRefs(const FieldOrArrayRefs& p);
    ~FieldOrArrayRefs();
    FieldOrArrayRefs *clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
266
    Scope *get_my_scope() const { return my_scope; }
Elemer Lelik's avatar
Elemer Lelik committed
267
268
269
270
    void add(FieldOrArrayRef *p_ref) { refs.add(p_ref); }
    size_t get_nof_refs() const { return refs.size(); }
    FieldOrArrayRef* get_ref(size_t i) const { return refs[i]; }
    bool has_unfoldable_index() const;
271
272
    bool is_checked() const { return checked; }
    void set_checked() { checked = true; }
Elemer Lelik's avatar
Elemer Lelik committed
273
274
275
276
277
    /** Removes (deletes) the first \a n field references. */
    void remove_refs(size_t n);
    Identifier *remove_last_field();
    /** Generates the C++ sub-expression that accesses
     * the given sub-references of definition \a ass. 
278
     * @param ref_scope scope of the main reference object
Elemer Lelik's avatar
Elemer Lelik committed
279
280
     * @param nof_subrefs indicates the number of sub-references
     * to generate code from (UINT_MAX means all of them) */
281
282
    void generate_code(expression_struct *expr, Common::Assignment *ass,
      Common::Scope* ref_scope, bool const_ref = false, size_t nof_subrefs = UINT_MAX);
283
284
    /** Generates the C++ sub-expression that could access the
      * sub-references of a reference of type \a type
285
      * @param ref_scope scope of the main reference object
286
287
      * @param nof_subrefs indicates the number of sub-references
      * to generate code from (UINT_MAX means all of them) */
288
289
    void generate_code(expression_struct *expr, Type *type, Common::Scope* ref_scope,
      bool const_ref = false, bool is_template = false, size_t nof_subrefs = UINT_MAX);
Elemer Lelik's avatar
Elemer Lelik committed
290
291
292
    /** Appends the string representation of sub-references to \a str. */
    void append_stringRepr(string &str) const;
    bool refers_to_string_element() const { return refs_str_element; }
293
    bool has_function_ref() const;
Elemer Lelik's avatar
Elemer Lelik committed
294
295
    void set_string_element_ref() { refs_str_element = true; }
    void clear_string_element_ref() { refs_str_element = false; }
296
297
298
299
    /** Adds a new field ref for the union type's @default alternative at the specified index.
      * Used when the subreference at the given index is not a valid field name or array index 
      * for the union type it is attributed to. This attempts to use the union's default alternative instead. */
    void use_default_alternative(size_t p_idx, const Identifier& p_alt_name);
Elemer Lelik's avatar
Elemer Lelik committed
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
  };

  /**
   * Base class for all TTCN-3 references.
   * Includes the common functionality for parameterized and non-parameterized
   * references (e.g. handling of field or array subreferences).
   */
  class Ref_base : public Ref_simple {
  protected: // Ttcn::Reference and Ttcn::Ref_pard need access
    Identifier *modid;
    /** If id is a NULL pointer all components are stored in subrefs */
    Identifier *id;
    FieldOrArrayRefs subrefs;
    /** Indicates whether the consistency of formal and actual parameter lists
     * has been verified. */
    bool params_checked;
    bool usedInIsbound;
    Ref_base(const Ref_base& p);
  private:
    Ref_base& operator=(const Ref_base& p);
  public:
    /** Default constructor: sets \a modid and \a id to NULL. Used by
     * non-parameterized references only. It is automatically guessed whether
     * the first component of \a subrefs is a module id or not. */
    Ref_base() : Ref_simple(), modid(0), id(0), subrefs(), params_checked(0)
      , usedInIsbound(false) {}
    Ref_base(Identifier *p_modid, Identifier *p_id);
    ~Ref_base();
    virtual Ref_base *clone() const = 0;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    /** Sets the scope of the base reference to \a p_scope.
     * The scope of array indices in \a subrefs remains unchanged. */
    void set_base_scope(Scope *p_scope) { Ref_simple::set_my_scope(p_scope); }
    virtual bool getUsedInIsbound() {return usedInIsbound;}
    virtual void setUsedInIsbound() {usedInIsbound = true;}
    Setting *get_refd_setting();
    FieldOrArrayRefs *get_subrefs();
    /** Appends \a p_ref to the sub-references */
    void add(FieldOrArrayRef *p_ref) { subrefs.add(p_ref); }
    virtual bool has_single_expr();
    virtual void set_code_section(
      GovernedSimple::code_section_t p_code_section);
343
    void chk_immutability();
Elemer Lelik's avatar
Elemer Lelik committed
344
345
346
347
348
349
350
    /** Generates the C++ equivalent of the reference (including the parameter
     * list and sub-references) as an access to a constant resource.
     */
    virtual void generate_code_const_ref(expression_struct_t *expr);
  };

  /**
351
   * TTCN-3 reference.
Elemer Lelik's avatar
Elemer Lelik committed
352
353
354
355
   * Implements the automatic detection whether the first identifier is a
   * module name or not.
   */
  class Reference : public Ref_base {
356
    reftype_t reftype;
357
358
359
360
    /** "Processed" parameter list, after the semantic check. */
    ActualParList* parlist;
    /** "Raw" parameter list, before the semantic check. */
    Ttcn::ParsedActualParameters* params;
361
    bool gen_const_prefix;
362
363
364
365
366
367
    /** Used by generate_code_cached(). Stores the generated expression string, 
      * so it doesn't get regenerated every time. */
    char* expr_cache;
    
    /** Copy constructor. Private, used by Reference::clone() only */
    Reference(const Reference& p);
Elemer Lelik's avatar
Elemer Lelik committed
368
369
  public:
    Reference(Identifier *p_id);
370
371
372
    Reference(reftype_t p_reftype);
    Reference(Identifier *p_modid, Identifier *p_id, reftype_t p_reftype = REF_BASIC)
      : Ref_base(p_modid, p_id), reftype(p_reftype), parlist(NULL), params(NULL), gen_const_prefix(false), expr_cache(NULL) { }
373
    Reference(Identifier *p_modid, Identifier *p_id,
374
              ParsedActualParameters *p_params, reftype_t p_reftype = REF_BASIC);
Elemer Lelik's avatar
Elemer Lelik committed
375
    ~Reference();
376
    virtual bool has_parameters() const;
Elemer Lelik's avatar
Elemer Lelik committed
377
    virtual Reference *clone() const;
378
    virtual void set_fullname(const string& p_fullname);
379
    virtual void set_my_scope(Scope* p_scope);
Elemer Lelik's avatar
Elemer Lelik committed
380
381
    virtual string get_dispname();
    virtual Common::Assignment *get_refd_assignment(bool check_parlist = true);
382
    virtual Common::Assignment *get_refd_assignment_last(bool check_parlist = true);
383
384
    virtual reftype_t get_reftype() const { return reftype; }
    virtual void set_reftype(reftype_t p_reftype) { reftype = p_reftype; }
Elemer Lelik's avatar
Elemer Lelik committed
385
386
    virtual const Identifier* get_modid();
    virtual const Identifier* get_id();
387
    virtual ActualParList *get_parlist();
388
    void set_gen_const_prefix() { gen_const_prefix = true; }
Elemer Lelik's avatar
Elemer Lelik committed
389
390
391
392
393
394
395
    /** Checks whether \a this points to a variable or value parameter.
     * Returns the type of the respective variable or variable field or NULL
     * in case of error. */
    Type *chk_variable_ref();
    /** Checks if \a this points to a component.
     *  Returns the type of the component if so or NULL in case of error. */
    Type *chk_comptype_ref();
396
    bool chk_activate_argument();
Elemer Lelik's avatar
Elemer Lelik committed
397
    virtual bool has_single_expr();
398
    virtual void set_code_section(GovernedSimple::code_section_t p_code_section);
Elemer Lelik's avatar
Elemer Lelik committed
399
400
401
402
403
404
405
406
407
    virtual void generate_code(expression_struct_t *expr);
    /** Generates the C++ equivalent of port references within
     * connect/disconnect/map/unmap statements into \a expr.
     * Argument \a p_scope shall point to the scope of the statement. */
    void generate_code_portref(expression_struct_t *expr, Scope *p_scope);
    virtual void generate_code_const_ref(expression_struct_t *expr);
    /**
     * Generates code for checking if the reference
     * and the referred objects are bound or not.*/
408
409
    void generate_code_ispresentboundchosen(expression_struct_t *expr,
      bool is_template, const Value::operationtype_t optype, const char* field);
Elemer Lelik's avatar
Elemer Lelik committed
410
411
412
413
414
415
416
417
    /** Used when an 'all from' is called on a function or parametrised template,
      * generate_code would generate new temporaries for the function's parameters
      * each call. This method makes sure the same temporaries are used every time
      * the function is called in the generated code.
      * On the first run calls generate_code and stores its result (only expr.expr
      * is cached, since the preamble is only needed after the first call). 
      * On further runs the cached expression is returned.*/
    virtual void generate_code_cached (expression_struct_t *expr);
418
419
420
    /** Lets the referenced assignment object know, that the reference is used
      * at least once (only relevant for formal parameters and external constants). */
    void ref_usage_found();
421
422
423
424
    /** Appends a new field subref for the union type's @default alternative at the end of the reference.
      * Used when the reference points to a union value or template in a context where a union is not allowed.
      * This attempts to use the union's default alternative instead. */
    void use_default_alternative(const Identifier& p_alt_name);
425
426
427
  private:
    /** Detects whether the first identifier in subrefs is a module id */
    void detect_modid();
Elemer Lelik's avatar
Elemer Lelik committed
428
429
430
431
432
433
434
435
436
437
438
439
  };

  /**
  * Class Ttcn::NameBridgingScope.
  * This scope unit is NOT A REAL SCOPE UNIT,
  * its only purpose is to serve as a bridge with a name between two real scope
  * units. All operations are transfered automatically.
  */
  class NameBridgingScope : public Scope {
    virtual string get_scopeMacro_name() const;
    virtual NameBridgingScope* clone() const;
    virtual Common::Assignment* get_ass_bySRef(Ref_simple *p_ref);
440
    virtual bool is_class_scope() const;
Elemer Lelik's avatar
Elemer Lelik committed
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
  };

  /**
   * Class Ttcn::RunsOnScope.
   * Implements the scoping rules for functions, altsteps and testcases that
   * have a 'runs on' clause. First looks for the definitions in the given
   * component type first then it searches in its parent scope.
   * Note: This scope unit cannot access the parent scope of the component type
   * (which is a module Definitions) unless the component type and the
   * 'runs on' clause is defined in the same module.
   */
  class RunsOnScope : public Scope {
    /** Points to the component type. */
    Type *component_type;
    /** Shortcut to the definitions within \a component_type. */
    ComponentTypeBody *component_defs;

    /** Not implemented. Causes \a FATAL_ERROR. */
    RunsOnScope(const RunsOnScope& p);
    /** %Assignment not implemented */
    RunsOnScope& operator=(const RunsOnScope& p);
  public:
    RunsOnScope(Type *p_comptype);
    virtual RunsOnScope *clone() const;

    Type *get_component_type() const { return component_type; }
    /** Checks the uniqueness of definitions within \a component_defs and
     * reports warnings in case of hiding. */
    void chk_uniq();

    virtual RunsOnScope *get_scope_runs_on();
    virtual Common::Assignment *get_ass_bySRef(Ref_simple *p_ref);
    virtual bool has_ass_withId(const Identifier& p_id);
  };
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
  
  /**
   * Class Ttcn::PortScope.
   * Implements the scoping rules for functions that
   * have a 'port' clause. First looks for the variable definitions in the given
   * port type first then it searches in its parent scope.
   * Note: This scope unit cannot access the parent scope of the port type.
   */
  class PortScope : public Scope {
    /** Points to the port type. */
    Type *port_type;
    /** Shortcut to the definitions within \a port_type. */
    Definitions *vardefs;

    /** Not implemented. Causes \a FATAL_ERROR. */
    PortScope(const PortScope& p);
    /** %Assignment not implemented */
    PortScope& operator=(const PortScope& p);
  public:
    PortScope(Type *p_porttype);
    virtual PortScope *clone() const;

    Type *get_port_type() const { return port_type; }
    /** Checks the uniqueness of definitions within \a portdefs and
     * reports warnings in case of hiding. */
    void chk_uniq();

    virtual PortScope *get_scope_port();
    virtual Common::Assignment *get_ass_bySRef(Ref_simple *p_ref);
    virtual bool has_ass_withId(const Identifier& p_id);
  };
Elemer Lelik's avatar
Elemer Lelik committed
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533

  /**
   * Class Ttcn::Definitions.
   *
   * Owns the contained Definition objects.
   */
  class Definitions : public Common::Assignments {
  protected:
    /** Searchable map of definitions. Used after chk_uniq. */
    map<string, Definition> ass_m;
    /** Indicates whether the uniqueness of identifiers has been checked. */
    bool checked;
    /** Vector containing all definitions. Used for building. */
    vector<Definition> ass_v;

    Definitions(const Definitions& p);
  public:

    Definitions() : Common::Assignments(), ass_m(), checked(false), ass_v() {}
    ~Definitions();
    Definitions *clone() const;
    virtual void set_fullname(const string& p_fullname);
    /** Adds the assignment p_ass and becomes the owner of it.
     *  The uniqueness of the identifier is not checked. */
    void add_ass(Definition *p_ass);
    virtual bool has_local_ass_withId(const Identifier& p_id);
    virtual Common::Assignment* get_local_ass_byId(const Identifier& p_id);
    virtual size_t get_nof_asss();
534
    virtual Common::Assignment* get_ass_byIndex(size_t p_i, bool p_reordered = true);
Elemer Lelik's avatar
Elemer Lelik committed
535
536
    size_t get_nof_raw_asss();
    Definition *get_raw_ass_byIndex(size_t p_i);
537
    virtual bool is_class_scope() const;
Elemer Lelik's avatar
Elemer Lelik committed
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
    /** Checks the uniqueness of identifiers. */
    void chk_uniq();
    /** Checks all definitions. */
    void chk();
    /** Checks the definitions within the header of a for loop. */
    void chk_for();
    /** Sets the genname of embedded definitions using \a prefix. */
    void set_genname(const string& prefix);
    /** Generates code for all assignments into \a target. */
    void generate_code(output_struct *target);
    void generate_code(CodeGenHelper& cgh);
    char* generate_code_str(char *str);
    void ilt_generate_code(ILT *ilt);
    /** Prints the contents of all assignments. */
    virtual void dump(unsigned level) const;
  };

  /**
   * Class Ttcn::Definitions.
   *
   * Owns the contained Definition objects.
   */
/*  class Definitions : public OtherDefinitions {
  public:
    Definitions() : OtherDefinitions() {}
    ~Definitions();
    Definitions *clone() const;
    void add_ass(Definition *p_ass);
  };*/

  /** Represents a TTCN-3 group
   *
   *  @note a Group is not a Scope */
  class Group : public Node, public Location {
  private:
    Group* parent_group;
    WithAttribPath* w_attrib_path;
    /// Definitions that belong to this group (directly)
    vector<Definition> ass_v;
    /// Map the name to the definition (filled in chk_uniq)
    map<string,Definition> ass_m;
    /// Subgroups
    vector<Group> group_v;
    /// Map the name to the subgroup
    map<string,Group> group_m;
    vector<ImpMod> impmods_v;
    vector<FriendMod> friendmods_v;
    Identifier *id;
    bool checked;
  private:
    /** Copy constructor not implemented */
    Group(const Group& p);
    /** %Assignment not implemented */
    Group& operator=(const Group& p);
  public:
    Group(Identifier *p_id);
    ~Group();
    virtual Group* clone() const;
    virtual void set_fullname(const string& p_fullname);
    void add_ass(Definition* p_ass);
    void add_group(Group* p_group);
    void set_parent_group(Group* p_parent_group);
    Group* get_parent_group() const { return parent_group; }
    void set_attrib_path(WithAttribPath* p_path);
    const Identifier& get_id() const { return *id; }
    void chk_uniq();
    virtual void chk();
    void add_impmod(ImpMod *p_impmod);
    void add_friendmod(FriendMod *p_friendmod);
    virtual void dump(unsigned level) const;
    void set_with_attr(MultiWithAttrib* p_attrib);
    WithAttribPath* get_attrib_path();
    void set_parent_path(WithAttribPath* p_path);
  };

  class ControlPart : public Node, public Location {
  private:
    StatementBlock* block;
    WithAttribPath* w_attrib_path;

    NameBridgingScope bridgeScope;

    /// Copy constructor disabled
    ControlPart(const ControlPart& p);
    /// %Assignment disabled
    ControlPart& operator=(const ControlPart& p);
  public:
    ControlPart(StatementBlock* p_block);
    ~ControlPart();
    virtual ControlPart* clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    void chk();
    void generate_code(output_struct *target, Module *my_module);
    void set_with_attr(MultiWithAttrib* p_attrib);
    WithAttribPath* get_attrib_path();
    void set_parent_path(WithAttribPath* p_path);
    void dump(unsigned level) const;
  };

  /** A TTCN-3 module */
  class Module : public Common::Module {
  private:
    string *language_spec;
    Definitions *asss;
    vector<Group> group_v;
    map<string, Group> group_m;
    WithAttribPath* w_attrib_path;
    Imports *imp;
    ControlPart* controlpart;
    /** For caching the scope objects that are created in
649
     * \a get_runs_on_scope() and get_port_scope(). */
Elemer Lelik's avatar
Elemer Lelik committed
650
    vector<RunsOnScope> runs_on_scopes;
651
    vector<PortScope> port_scopes;
Elemer Lelik's avatar
Elemer Lelik committed
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
  private:
    /** Copy constructor not implemented */
    Module(const Module& p);
    /** %Assignment not implemented */
    Module& operator=(const Module& p);
  public:
    vector<FriendMod> friendmods_v;
    Module(Identifier *p_modid);
    ~Module();
    void add_group(Group* p_group);
    void add_friendmod(FriendMod *p_friendmod);
    virtual Module* clone() const;
    virtual Common::Assignment* importAssignment(
      const Identifier& p_source_modid, const Identifier& p_id) const;
    virtual void set_fullname(const string& p_fullname);
    virtual Common::Assignments* get_scope_asss();
    virtual bool has_imported_ass_withId(const Identifier& p_id);
    virtual Common::Assignment* get_ass_bySRef(Ref_simple *p_ref);
    virtual bool is_valid_moduleid(const Identifier& p_id);
    virtual Common::Assignments *get_asss();
    virtual bool exports_sym(const Identifier& p_id);
    virtual Type *get_address_type();
    virtual void chk_imp(ReferenceChain& refch, vector<Common::Module>& moduleStack);
    virtual void chk();
  private:
    void chk_friends();
    void chk_groups();
    virtual void get_imported_mods(module_set_t& p_imported_mods);
    virtual void generate_code_internal(CodeGenHelper& cgh);
  public:
    /** Returns a scope that can access the definitions within component type
     * \a comptype (which is imported from another module) and its parent scope
     * is \a asss. Note that this scope cannot see the scope of \a comptype.
     * The function uses \a runs_on_scopes for caching the scope objects: if an
     * object has been created for a component type it will be returned later
     * instead of creating a new one. */
    RunsOnScope *get_runs_on_scope(Type *comptype);
689
690
691
692
    /* The same as get_runs_on_scope except that the returned scope can access
     * the port types definitions.
     */
    PortScope *get_port_scope(Type *porttype);
Elemer Lelik's avatar
Elemer Lelik committed
693
694
695
696
697
698
699
700
    virtual void dump(unsigned level) const;
    void set_language_spec(const char *p_language_spec);
    void add_ass(Definition* p_ass);
    void add_impmod(ImpMod *p_impmod);
    void add_controlpart(ControlPart* p_controlpart);
    void set_with_attr(MultiWithAttrib* p_attrib);
    WithAttribPath* get_attrib_path();
    void set_parent_path(WithAttribPath* p_path);
701
    Imports& get_imports() { return *imp; }
Elemer Lelik's avatar
Elemer Lelik committed
702
703
704

    bool is_visible(const Identifier& id, visibility_t visibility);
    
Elemer Lelik's avatar
Elemer Lelik committed
705
706
707
708
709
710
711
712
713
    /** Generates JSON schema segments for the types defined in the modules,
      * and references to these types. Information related to the types' 
      * JSON encoding and decoding functions is also inserted after the references.
      *
      * @param json JSON document containing the main schema, schema segments for 
      * the types will be inserted here
      * @param json_refs map of JSON documents containing the references and function
      * info related to each type */
    virtual void generate_json_schema(JSON_Tokenizer& json, map<Type*, JSON_Tokenizer>& json_refs);
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
    
    /** Generates the debugger initialization function for this module.
      * The function creates the global debug scope associated with this module,
      * and initializes it with all the global variables visible in the module
      * (including imported variables).
      * The debug scopes of all component types defined in the module are also
      * created and initialized with their variables. */
    virtual void generate_debugger_init(output_struct *output);
    
    /** Generates the variable adding code for all global variables defined
      * in this module. This function is called by generate_debugger_init()
      * for both the current module and all imported modules. */
    virtual char* generate_debugger_global_vars(char* str, Common::Module* current_mod);
    
    /** Generates the debugger variable printing function, which can print values
      * and templates of all types defined in this module (excluding subtypes). */
    virtual void generate_debugger_functions(output_struct *output);
Elemer Lelik's avatar
Elemer Lelik committed
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
  };

  /**
  * Module friendship declaration.
  */
  class FriendMod : public Node, public Location {
  private:
    Module *my_mod;
    Identifier *modid;
    WithAttribPath* w_attrib_path;
    Group* parentgroup;
    /** Indicates whether this friend module declaration was checked */
    bool checked;
  private:
    /** Copy constructor not implemented. */
    FriendMod(const FriendMod&);
    /** %Assignment not implemented. */
    FriendMod& operator=(const FriendMod&);
  public:
    FriendMod(Identifier *p_modid);
    ~FriendMod();
    virtual FriendMod* clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void chk();
    void set_my_mod(Module *p_mod) { my_mod = p_mod; }
    const Identifier& get_modid() const {return *modid;}
    void set_with_attr(MultiWithAttrib* p_attrib);
    WithAttribPath* get_attrib_path();
    void set_parent_path(WithAttribPath* p_path);
    void set_parent_group(Group* p_group);
  };


  /**
   * Imported module. Represents an import statement.
   */
  class ImpMod : public Node, public Location {
  public:
    enum imptype_t {
      I_UNDEF,
      I_ERROR,
      I_ALL,
      I_IMPORTSPEC,
774
775
776
777
778
779
780
781
      I_IMPORTIMPORT,
      /** Phantom import for when the 'include' is needed in the generated C++
        * code, but the TTCN-3 'import' statement is optional.
        * Currently this can only happen when using coding values of a type that
        * has custom or PER coder functions set (the module containing the coder
        * function declarations does not have to be imported to the module that
        * contains the coding operation). */
      I_DEPENDENCY
Elemer Lelik's avatar
Elemer Lelik committed
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
    };
  private:
    /** Points to the target (imported) module. This is initially NULL;
     *  set during semantic analysis by Ttcn::Imports::chk_uniq() */
    Common::Module *mod;
    /** The importing module (indirectly our owner) */
    Module *my_mod;
    /** Import type: "import all", selective import, import of import, etc. */
    imptype_t imptype;
    /** The name given in the import statement;
     *  hopefully an actual module name */
    Identifier *modid;
    /** The text after "import from name language" */
    string *language_spec;
    /** Recursive import (already deprecated in v3.2.1) */
    bool is_recursive;
    WithAttribPath* w_attrib_path;
    /** Group in which the import statement is located, if any */
    Group* parentgroup;
    visibility_t visibility;
  private:
    /** Copy constructor not implemented. */
    ImpMod(const ImpMod&);
    /** %Assignment not implemented */
    ImpMod& operator=(const ImpMod&);
  public:
    ImpMod(Identifier *p_modid);
    ~ImpMod();
    virtual ImpMod* clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void chk();
    /** Checks the existence of imported symbols and checks import definitions
     * in the imported modules recursively. */
    void chk_imp(ReferenceChain& refch, vector<Common::Module>& moduleStack);
    void set_my_mod(Module *p_mod) { my_mod = p_mod; }
    const Identifier& get_modid() const {return *modid;}
    void set_mod(Common::Module *p_mod) { mod = p_mod; }
    Common::Module *get_mod() const { return mod; }
    /** Returns the imported definition with name \a p_id if it is imported or
     * NULL otherwise.
     * \a loc is used to report an error if it is needed */
    Common::Assignment *get_imported_def(const Identifier& p_source_modid,
        const Identifier& p_id, const Location *loc,
        ReferenceChain* refch, vector<ImpMod>& usedImpMods) const;
    bool has_imported_def(const Identifier& p_source_modid,
            const Identifier& p_id, const Location *loc) const;
    void set_imptype(imptype_t p_imptype) { imptype = p_imptype; }
    void set_language_spec(const char *p_language_spec);
    void set_recursive() { is_recursive = true; }
    void generate_code(output_struct *target);
    virtual void dump(unsigned level) const;
    void set_with_attr(MultiWithAttrib* p_attrib);
    WithAttribPath* get_attrib_path();
    void set_parent_path(WithAttribPath* p_path);
    void set_parent_group(Group* p_group);
    imptype_t get_imptype() {
      return imptype;
    }
    void set_visibility(visibility_t p_visibility){
      visibility = p_visibility;
    }
    visibility_t get_visibility() const{
      return visibility;
    }
  };

  /**
   * Class Imports.
   */
  class Imports : public Node {
  private:
    /** my module */
    Module *my_mod;
    /** imported modules */
    vector<ImpMod> impmods_v;
    /** Indicates whether the import list has been checked. */
    bool checked;

    friend class ImpMod;
  private:
    /** Copy constructor not implemented. */
    Imports(const Imports&);
    /** %Assignment not implemented */
    Imports& operator=(const Imports&);
  public:
    Imports() : Node(), my_mod(0), impmods_v(), checked(false) {}
    virtual ~Imports();
    virtual Imports* clone() const;
    void add_impmod(ImpMod *p_impmod);
    void set_my_mod(Module *p_mod);
872
873
    size_t get_imports_size() const {return impmods_v.size();}
    ImpMod* get_impmod(size_t index) const {return impmods_v[index];}
Elemer Lelik's avatar
Elemer Lelik committed
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
    /** Checks the existence of imported modules and detects duplicated imports
     * from the same module. Initializes \a impmods_m. */
    void chk_uniq();
    /** Checks the existence of imported symbols and checks import definitions
     * in the imported modules recursively. */
    void chk_imp(ReferenceChain& refch, vector<Common::Module>& moduleStack);
    /** Returns \p true if an imported module with the given name exists,
     *  else returns \p false. */
    bool has_impmod_withId(const Identifier& p_id) const;
    /** Returns whether a definition with identifier \a p_id is imported
     * from one or more modules */
    bool has_imported_def(const Identifier& p_id, const Location *loc) const;
    /** Returns the imported definition with name \a p_id if it is
     * unambiguous or NULL otherwise.
     * \a loc is used to report an error if it is needed */
    Common::Assignment *get_imported_def(const Identifier& p_source_modid,
        const Identifier& p_id, const Location *loc, ReferenceChain* refch);
    void get_imported_mods(Module::module_set_t& p_imported_mods) const;
    void generate_code(output_struct *target);
    void generate_code(CodeGenHelper& cgh);
    virtual void dump(unsigned level) const;
  };

  class Definition : public Common::Assignment {
  protected: // many derived classes
    /** Contains the C++ identifier of the definition. If empty the C++
     * identifier is generated from \a id. */
    string genname;
    /** The group it's in, if any */
    Group *parentgroup;
    WithAttribPath* w_attrib_path;
    ErroneousAttributes* erroneous_attrs; // set by chk_erroneous_attr() or NULL
    /** True if function/altstep/default scope, not module scope */
    bool local_scope;

    Definition(const Definition& p)
      : Common::Assignment(p), genname(), parentgroup(0),
        w_attrib_path(0), erroneous_attrs(0), local_scope(false)
      { }

    namedbool has_implicit_omit_attr() const;
  private:
    /// %Assignment disabled
    Definition& operator=(const Definition& p);
  public:
    Definition(asstype_t p_asstype, Identifier *p_id)
      : Common::Assignment(p_asstype, p_id), genname(), parentgroup(0),
        w_attrib_path(0), erroneous_attrs(0), local_scope(false)
      { }
    virtual ~Definition();
    virtual Definition* clone() const = 0;
    virtual void set_fullname(const string& p_fullname);
    virtual bool is_local() const;
    /** Sets the visibility type of the definition */
    void set_visibility(const visibility_t p_visibility)
      { visibilitytype = p_visibility; }
    /** Marks the (template) definition as local to a func/altstep/default */
    inline void set_local() { local_scope = true; }

933
    virtual string get_genname() const;
Elemer Lelik's avatar
Elemer Lelik committed
934
935
936
937
938
939
    void set_genname(const string& p_genname) { genname = p_genname; }
    /** Check if two definitions are (almost) identical, the type and dimensions
     * must always be identical, the initial values can be different depending
     * on the definition type. If error was reported the return value is false.
     * The initial values (if applicable) may be present/absent, different or
     * unfoldable. The function must be overridden to be used.
940
     */ 
Elemer Lelik's avatar
Elemer Lelik committed
941
942
    virtual bool chk_identical(Definition *p_def);
    /** Parse and check the erroneous attribute data,
943
944
945
      * returns erroneous attributes or NULL */
    static ErroneousAttributes* chk_erroneous_attr(WithAttribPath* p_attrib_path,
      Type* p_type, Scope* p_scope, string p_fullname, bool in_update_stmt);
Elemer Lelik's avatar
Elemer Lelik committed
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
    /** This code generation is used when this definition is embedded
     * in a statement block. */
    virtual char* generate_code_str(char *str);
    virtual void ilt_generate_code(ILT *ilt);
    /** Generates the C++ initializer sequence for a definition of a component
     * type, appends to \a str and returns the resulting string. The function
     * is used when \a this is realized using the C++ objects of definition
     * \a base_defn inherited from another component type. The function is
     * implemented only for those definitions that can appear within component
     * types, the generic version causes \a FATAL_ERROR. */
    virtual char *generate_code_init_comp(char *str, Definition *base_defn);
    virtual void dump_internal(unsigned level) const;
    virtual void dump(unsigned level) const;
    virtual void set_with_attr(MultiWithAttrib* p_attrib);
    virtual WithAttribPath* get_attrib_path();
    virtual void set_parent_path(WithAttribPath* p_path);
    virtual void set_parent_group(Group* p_group);
    virtual Group* get_parent_group();
  };

  /**
   * TTCN-3 type definition (including signatures and port types).
   */
  class Def_Type : public Definition {
  private:
    Type *type;

    NameBridgingScope bridgeScope;

    /** Copy constructor not implemented */
    Def_Type(const Def_Type& p);
    /** %Assignment disabled */
    Def_Type& operator=(const Def_Type& p);
  public:
    Def_Type(Identifier *p_id, Type *p_type);
    virtual ~Def_Type();
    virtual Def_Type* clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    virtual Setting *get_Setting();
    virtual Type *get_Type();
    virtual void chk();
    virtual void generate_code(output_struct *target, bool clean_up = false);
    virtual void generate_code(CodeGenHelper& cgh);
    virtual void dump_internal(unsigned level) const;
    virtual void set_with_attr(MultiWithAttrib* p_attrib);
    virtual WithAttribPath* get_attrib_path();
    virtual void set_parent_path(WithAttribPath* p_path);
  };

  /**
   * TTCN-3 constant definition.
   */
  class Def_Const : public Definition {
  private:
    Type *type;
    Value *value;
    bool value_under_check;

    /// Copy constructor disabled
    Def_Const(const Def_Const& p);
    /// %Assignment disabled
    Def_Const& operator=(const Def_Const& p);
  public:
    Def_Const(Identifier *p_id, Type *p_type, Value *p_value);
    virtual ~Def_Const();
    virtual Def_Const *clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    virtual Setting *get_Setting();
    virtual Type *get_Type();
    virtual Value *get_Value();
    virtual void chk();
    virtual bool chk_identical(Definition *p_def);
    virtual void generate_code(output_struct *target, bool clean_up = false);
    virtual void generate_code(CodeGenHelper& cgh);
    virtual char* generate_code_str(char *str);
    virtual void ilt_generate_code(ILT *ilt);
    virtual char *generate_code_init_comp(char *str, Definition *base_defn);
    virtual void dump_internal(unsigned level) const;
  };

  /**
   * TTCN-3 external constant definition.
   */
  class Def_ExtConst : public Definition {
  private:
    Type *type;
1034
    bool usage_found;
Elemer Lelik's avatar
Elemer Lelik committed
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050

    /// Copy constructor disabled
    Def_ExtConst(const Def_ExtConst& p);
    /// %Assignment disabled
    Def_ExtConst& operator=(const Def_ExtConst& p);
  public:
    Def_ExtConst(Identifier *p_id, Type *p_type);
    virtual ~Def_ExtConst();
    virtual Def_ExtConst *clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    virtual Type *get_Type();
    virtual void chk();
    virtual void generate_code(output_struct *target, bool clean_up = false);
    virtual void generate_code(CodeGenHelper& cgh);
    virtual void dump_internal(unsigned level) const;
1051
1052
1053
1054
    /** Indicates that the parameter is used at least once. */
    void set_usage_found() { usage_found = true; }
    /** Returns true if the external constant is used at least once. */
    bool is_used() const { return usage_found; }
Elemer Lelik's avatar
Elemer Lelik committed
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
  };

  /**
   * TTCN-3 module parameter definition.
   */
  class Def_Modulepar : public Definition {
  private:
    Type *type;
    Value*    def_value;
    /// Copy constructor disabled
    Def_Modulepar(const Def_Modulepar& p);
    /// %Assignment disabled
    Def_Modulepar& operator=(const Def_Modulepar& p);
  public:
    Def_Modulepar(Identifier *p_id, Type *p_type, Value *p_defval);
    virtual ~Def_Modulepar();
    virtual Def_Modulepar* clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    virtual Type *get_Type();
    virtual void chk();
    virtual void generate_code(output_struct *target, bool clean_up = false);
    virtual void generate_code(CodeGenHelper& cgh);
    virtual void dump_internal(unsigned level) const;
  };

  /**
   * TTCN-3 template module parameter definition.
   */
  class Def_Modulepar_Template : public Definition {
  private:
    Type *type;
    Template* def_template;
    /// Copy constructor disabled
    Def_Modulepar_Template(const Def_Modulepar_Template& p);
    /// %Assignment disabled
    Def_Modulepar_Template& operator=(const Def_Modulepar_Template& p);
  public:
    Def_Modulepar_Template(Identifier *p_id, Type *p_type, Template *p_defval);
    virtual ~Def_Modulepar_Template();
    virtual Def_Modulepar_Template* clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    virtual Type *get_Type();
    virtual void chk();
    virtual void generate_code(output_struct *target, bool clean_up = false);
    virtual void generate_code(CodeGenHelper& cgh);
    virtual void dump_internal(unsigned level) const;
  };

  /**
   * Def_Template class represents a template definition.
   */
  class Def_Template : public Definition {
  private:
    /* the type of the template */
    Type *type;
    /** The formal parameter list of the template. It is NULL in case of
     * non-parameterized templates. */
    FormalParList *fp_list;
    /** points to the base template reference in case of modified templates,
     * otherwise it is NULL */
    Reference *derived_ref;
    /** shortcut to the base template in case of modified templates,
     * otherwise it is NULL */
    Def_Template *base_template;
    /** Indicates whether the circular recursion chain of modified templates
     * has been checked. */
    bool recurs_deriv_checked;
    /** the body of the template */
    Template *body;
    /** template definition level restriction */
    template_restriction_t template_restriction;
    /** set in chk(), used by code generation,
     *  valid if template_restriction!=TR_NONE */
    bool gen_restriction_check;

    NameBridgingScope bridgeScope;

    /// Copy constructor for Def_Template::clone() only
    Def_Template(const Def_Template& p);
    /// %Assignment disabled
    Def_Template& operator=(const Def_Template& p);
  public:
    Def_Template(template_restriction_t p_template_restriction,
      Identifier *p_id, Type *p_type, FormalParList *p_fpl,
      Reference *p_derived_ref, Template *p_body);
    virtual ~Def_Template();
    virtual Def_Template *clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    virtual Setting *get_Setting();
    virtual Type *get_Type();
    virtual Template *get_Template();
    virtual FormalParList *get_FormalParList();
    virtual void chk();
  private:
    void chk_modified();
    void chk_default() const;
    void chk_recursive_derivation();
  public:
    virtual void generate_code(output_struct *target, bool clean_up = false);
    virtual void generate_code(CodeGenHelper& cgh);
    virtual char* generate_code_str(char *str);
    virtual void ilt_generate_code(ILT *ilt);
    virtual void dump_internal(unsigned level) const;
    template_restriction_t get_template_restriction()
      { return template_restriction; }
  };

  /**
   * Def_Var class represents a variable definition.
   */
  class Def_Var : public Definition {
1169
  protected:
Elemer Lelik's avatar
Elemer Lelik committed
1170
    Type *type;
1171
1172
  
  private:
Elemer Lelik's avatar
Elemer Lelik committed
1173
1174
    /** the initial value: optional and maybe incomplete */
    Value *initial_value;
1175
    
Elemer Lelik's avatar
Elemer Lelik committed
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
    /// Copy constructor disabled
    Def_Var(const Def_Var& p);
    /// %Assignment disabled
    Def_Var& operator=(const Def_Var& p);
  public:
    Def_Var(Identifier *p_id, Type *p_type, Value *p_initial_value);
    virtual ~Def_Var();
    virtual Def_Var *clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    virtual Type *get_Type();
    virtual void chk();
    virtual bool chk_identical(Definition *p_def);
    virtual void generate_code(output_struct *target, bool clean_up = false);
    virtual void generate_code(CodeGenHelper& cgh);
    virtual char* generate_code_str(char *str);
    virtual void ilt_generate_code(ILT *ilt);
    virtual char *generate_code_init_comp(char *str, Definition *base_defn);
    virtual void dump_internal(unsigned level) const;
  };
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
  
  class Def_Exception : public Def_Var {
  private:
    /// Copy constructor disabled
    Def_Exception(const Def_Exception& p);
    /// %Assignment disabled
    Def_Exception& operator=(const Def_Exception& p);
    
  public:
    Def_Exception(Identifier* p_id, Type* p_type);
    virtual char* generate_code_str(char *str);
  };
Elemer Lelik's avatar
Elemer Lelik committed
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385

  /**
   * Def_Var_Template class represents a template variable (dynamic template)
   * definition.
   */
  class Def_Var_Template : public Definition {
  private:
    Type *type;
    /** the initial value: optional and maybe incomplete */
    Template *initial_value;
    /** optional restriction on this variable */
    template_restriction_t template_restriction;
    /** set in chk(), used by code generation,
     *  valid if template_restriction!=TR_NONE */
    bool gen_restriction_check;

    /// Copy constructor disabled
    Def_Var_Template(const Def_Var_Template& p);
    /// %Assignment disabled
    Def_Var_Template& operator=(const Def_Var_Template& p);
  public:
    Def_Var_Template(Identifier *p_id, Type *p_type, Template *p_initial_value,
                     template_restriction_t p_template_restriction);
    virtual ~Def_Var_Template();
    virtual Def_Var_Template *clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    virtual Type *get_Type();
    virtual void chk();
    virtual bool chk_identical(Definition *p_def);
    virtual void generate_code(output_struct *target, bool clean_up = false);
    virtual void generate_code(CodeGenHelper& cgh);
    virtual char* generate_code_str(char *str);
    virtual void ilt_generate_code(ILT *ilt);
    virtual char *generate_code_init_comp(char *str, Definition *base_defn);
    virtual void dump_internal(unsigned level) const;
    template_restriction_t get_template_restriction()
      { return template_restriction; }
  };

  /**
   * Def_Timer class represents a single timer declaration (e.g. in a
   * TTCN component type).
   */
  class Def_Timer : public Definition {
  private:
    /** Describes the dimensions of a timer array. It is NULL in case
     * of single timer instance. */
    ArrayDimensions *dimensions;
    /** Default duration of the timers. It can be either a single
     * float value or an array of floats. If it is NULL the timer(s)
     * has no default duration. */
    Value *default_duration;

    /// Copy constructor disabled
    Def_Timer(const Def_Timer& p);
    /// %Assignment disabled
    Def_Timer& operator=(const Def_Timer& p);
  public:
    Def_Timer(Identifier *p_id, ArrayDimensions *p_dims, Value *p_dur)
      : Definition(A_TIMER, p_id), dimensions(p_dims),
      default_duration(p_dur) { }
    virtual ~Def_Timer();
    virtual Def_Timer *clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    virtual ArrayDimensions *get_Dimensions();
    virtual void chk();
    virtual bool chk_identical(Definition *p_def);
    /** Returns false if it is sure that the timer referred by array
     * indices \a p_subrefs does not have a default
     * duration. Otherwise it returns true. Argument \a p_subrefs
     * might be NULL when examining a single timer. */
    bool has_default_duration(FieldOrArrayRefs *p_subrefs);
  private:
    /** Checks if the value \a dur is suitable as duration for a single
     * timer. */
    void chk_single_duration(Value *dur);
    /** Checks if the value \a dur is suitable as duration for a timer
     * array.  The function calls itself recursively, argument \a
     * start_dim shall be zero when called from outside. */
    void chk_array_duration(Value *dur, size_t start_dim = 0);
  public:
    virtual void generate_code(output_struct *target, bool clean_up = false);
    virtual void generate_code(CodeGenHelper& cgh);
  private:
    /** Generates a C++ code fragment that sets the default duration
     * of a timer array. The generated code is appended to \a str and
     * the resulting string is returned. The equivalent C++ object of
     * timer array is named \a object_name, the array value containing
     * the default durations is \a dur. The function calls itself
     * recursively, argument \a start_dim shall be zero when called
     * from outside. */
    char *generate_code_array_duration(char *str, const char *object_name,
      Value *dur, size_t start_dim = 0);
  public:
    virtual char* generate_code_str(char *str);
    virtual void ilt_generate_code(ILT *ilt);
    virtual char *generate_code_init_comp(char *str, Definition *base_defn);
    virtual void dump_internal(unsigned level) const;
  };

  /**
   * Def_Port class represents a port declaration (in a component type).
   */
  class Def_Port : public Definition {
  private:
    /** Contains a reference to a TTCN-3 port type */
    Reference *type_ref;
    /** Points to the object describing the port type.
     *
     * Derived from \a type_ref during Def_Port::chk().
     * It can be NULL in case of any error (e.g. the reference points to a
     * non-existent port type or the referenced entity is not a port type. */
    Type *port_type;
    /** Describes the dimensions of a port array.
     * It is NULL in case of single port instance. */
    ArrayDimensions *dimensions;

    /// Copy constructor disabled
    Def_Port(const Def_Port& p);
    /// %Assignment disabled
    Def_Port& operator=(const Def_Port& p);
  public:
    /** Constructor
     *
     * @param p_id identifier (must not be NULL), the name of the port
     * @param p_tref type reference (must not be NULL)
     * @param p_dims array dimensions (NULL for a single port instance)
     */
    Def_Port(Identifier *p_id, Reference *p_tref, ArrayDimensions *p_dims);
    virtual ~Def_Port();
    virtual Def_Port *clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    /** Get the \a port_type
     *
     * @pre chk() has been called (because it computes \a port_type)
     */
    virtual Type *get_Type();
    virtual ArrayDimensions *get_Dimensions();
    virtual void chk();
    virtual bool chk_identical(Definition *p_def);
    virtual void generate_code(output_struct *target, bool clean_up = false);
    virtual void generate_code(CodeGenHelper& cgh);
    virtual char *generate_code_init_comp(char *str, Definition *base_defn);
    virtual void dump_internal(unsigned level) const;
  };

  /**
   * Common base class for function and external function definitions.
   */
  class Def_Function_Base : public Definition {
  public:
    enum prototype_t {
      PROTOTYPE_NONE, /**< no prototype(...) attribute */
      PROTOTYPE_CONVERT, /**< attribute prototype(convert) */
      PROTOTYPE_FAST, /**< attribute prototype(fast) */
      PROTOTYPE_BACKTRACK, /**< attribute prototype(backtrack) */
      PROTOTYPE_SLIDING /**< attribute prototype(sliding) */
    };
  protected: // Def_Function and Def_ExtFunction need access
    /** The formal parameter list of the function. It is never NULL even if
     * the function has empty parameter list. Owned. */
    FormalParList *fp_list;
    /** The return type of the function or NULL in case of no return type.
     *  Owned. */
    Type *return_type;
    /** Identifier of the enc/dec API implemented by the function */
    prototype_t prototype;
    /** Shortcut to the input type if the function implements one of the
     * enc/dec APIs or NULL otherwise. Not owned. */
    Type *input_type;
    /** Shortcut to the output type if the function implements one of the
     * enc/dec APIs or NULL otherwise. Not owned */
    Type *output_type;
    /** optional template restriction on return template value */
    template_restriction_t template_restriction;
1386
    bool final;
Elemer Lelik's avatar
Elemer Lelik committed
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406

    static asstype_t determine_asstype(bool is_external, bool has_return_type,
      bool returns_template);
    /// Copy constructor disabled
    Def_Function_Base(const Def_Function_Base& p);
    /// %Assignment disabled
    Def_Function_Base& operator=(const Def_Function_Base& p);
  public:
    /** Constructor.
     *
     * @param is_external true if external function (the derived type is
     *        Def_ExtFunction), false if a TTCN-3 function (Def_Function)
     * @param p_id the name of the function
     * @param p_fpl formal parameter list
     * @param p_return_type return type (may be NULL)
     * @param returns_template true if the return is a template
     * @param p_template_restriction restriction type
     */
    Def_Function_Base(bool is_external, Identifier *p_id,
      FormalParList *p_fpl, Type *p_return_type, bool returns_template,
1407
      template_restriction_t p_template_restriction, bool p_final);
Elemer Lelik's avatar
Elemer Lelik committed
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
    virtual ~Def_Function_Base();
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    virtual Type *get_Type();
    virtual FormalParList *get_FormalParList();
    prototype_t get_prototype() const { return prototype; }
    void set_prototype(prototype_t p_prototype) { prototype = p_prototype; }
    const char *get_prototype_name() const;
    void chk_prototype();
    Type *get_input_type();
    Type *get_output_type();
1419
    Type* get_return_type() const { return return_type; }
1420
    //virtual Type *get_RunsOnType();
1421
    bool is_identical(Def_Function_Base* p_other);
Elemer Lelik's avatar
Elemer Lelik committed
1422
1423
    template_restriction_t get_template_restriction()
      { return template_restriction; }
1424
    virtual bool is_final() const { return final; }
1425
1426
1427
    /** Checks and returns whether the function is startable.
     * Reports the appropriate error message(s) if not. */
    //bool chk_startable(Location* caller_location);
Elemer Lelik's avatar
Elemer Lelik committed
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
  };

  /**
   * Def_Function class represents a function definition.
   */
  class Def_Function : public Def_Function_Base {
  private:
    /** The 'runs on' clause (i.e. a reference to a TTCN-3 component type)
     * It is NULL if the function has no 'runs on' clause. */
    Reference *runs_on_ref;
    /** Points to the object describing the component type referred by
     * 'runs on' clause.
     * It is NULL if the function has no 'runs on' clause or \a runs_on_ref is
     * erroneous. */
    Type *runs_on_type;
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
    /** The 'mtc' clause (i.e. a reference to a TTCN-3 component type)
     * It is NULL if the function has no 'mtc' clause. */
    Reference *mtc_ref;
    /** Points to the object describing the component type referred by
     * 'mtc' clause.
     * It is NULL if the function has no 'mtc' clause or \a mtc_ref is
     * erroneous. */
    Type *mtc_type;
    /** The 'system' clause (i.e. a reference to a TTCN-3 component type)
     * It is NULL if the function has no 'system' clause. */
    Reference *system_ref;
    /** Points to the object describing the component type referred by
     * 'system' clause.
     * It is NULL if the function has no 'system' clause or \a system_ref is
     * erroneous. */
    Type *system_type;
1459
1460
1461
1462
1463
1464
1465
1466
    /** The 'port' clause (i.e. a reference to a TTCN-3 port type)
     * It is NULL if the function has no 'port' clause. */
    Reference *port_ref;
    /** Points to the object describing the port type referred by
     * 'port' clause.
     * It is NULL if the function has no 'port' clause or \a port_ref is
     * erroneous. */
    Type *port_type;
Elemer Lelik's avatar
Elemer Lelik committed
1467
1468
1469
1470
1471
1472
1473
1474
    /** The body of the function */
    StatementBlock *block;
    /** Indicates whether the function is startable. That is, it can be
     * launched as PTC behaviour as argument of a start test component
     * statement. */
    bool is_startable;
    /** Opts out from location information */
    bool transparent;
1475
    bool deterministic;
Elemer Lelik's avatar
Elemer Lelik committed
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487

    NameBridgingScope bridgeScope;

    /// Copy constructor disabled
    Def_Function(const Def_Function& p);
    /// %Assignment disabled
    Def_Function& operator=(const Def_Function& p);
  public:
    /** Constructor for a TTCN-3 function definition
     *
     * Called from a single location in compiler.y
     *
1488
     * @param p_deterministic true if deterministic
Elemer Lelik's avatar
Elemer Lelik committed
1489
1490
1491
     * @param p_id function name
     * @param p_fpl formal parameter list
     * @param p_runs_on_ref "runs on", else NULL
1492
1493
     * @param p_mtc_ref "mtc", else NULL
     * @param p_system_ref "system", else NULL
1494
     * @param p_port_ref "port", else NULL
Elemer Lelik's avatar
Elemer Lelik committed
1495
1496
1497
1498
1499
     * @param p_return_type return type, may be NULL
     * @param returns_template true if the return value is a template
     * @param p_template_restriction restriction type
     * @param p_block the body of the function
     */
1500
    Def_Function(bool p_deterministic, Identifier *p_id, FormalParList *p_fpl,
1501
1502
                 Reference *p_runs_on_ref, Reference *p_mtc_ref,
                 Reference *p_system_ref, Reference *p_port_ref,
1503
                 Type *p_return_type, bool returns_template,
Elemer Lelik's avatar
Elemer Lelik committed
1504
                 template_restriction_t p_template_restriction,
1505
                 bool p_final, StatementBlock *p_block);
Elemer Lelik's avatar
Elemer Lelik committed
1506
1507
1508
1509
1510
    virtual ~Def_Function();
    virtual Def_Function *clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    virtual Type *get_RunsOnType();
1511
1512
    virtual Type *get_MtcType();
    virtual Type *get_SystemType();
1513
    virtual Type *get_PortType();
Elemer Lelik's avatar
Elemer Lelik committed
1514
1515
1516
    /** Returns a scope that can access the definitions within component type
     * \a comptype and its parent is \a parent_scope.*/
    RunsOnScope *get_runs_on_scope(Type *comptype);
1517
1518
1519
    /** Returns a scope that can access the definitions within port type
     * \a porttype and its parent is \a parent_scope.*/
    PortScope *get_port_scope(Type *porttype);
Elemer Lelik's avatar
Elemer Lelik committed
1520
1521
1522
    virtual void chk();
    /** Checks and returns whether the function is startable.
     * Reports the appropriate error message(s) if not. */
1523
    bool chk_startable(Location* caller_location);
Elemer Lelik's avatar
Elemer Lelik committed
1524
1525
1526

    bool is_transparent() const { return transparent; }

1527
1528
    // Reuse of clean_up variable to allow or disallow the generation.
    // clean_up is true when it is called from PortTypeBody::generate_code()
Elemer Lelik's avatar
Elemer Lelik committed
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
    virtual void generate_code(output_struct *target, bool clean_up = false);
    virtual void generate_code(CodeGenHelper& cgh);
    virtual void dump_internal(unsigned level) const;

    virtual void set_parent_path(WithAttribPath* p_path);
  };

  /** RAII class for transparent functions.
   *
   *  Calls to TTCN_Location::update_lineno are written by Ttcn::Statement
   *  by calling Common::Location::update_location_object. These calls
   *  need to be removed inside transparent functions.
   *
   *  It is difficult (impossible) for a Statement to navigate up in the AST
   *  to the function/altstep/testcase/control part that contains it;
   *  instead, the Def_Function sets a static flag inside Common::Location
   *  that says "you are inside a transparent function" while
   *  Def_Function::generate_code function runs.
   */
  class transparency_holder {
    bool old_transparency;
  public:
    /** Sets Common::Location::transparency (but remembers its old vaue)
     *
     * @param df the function definition
     */
    transparency_holder(const Def_Function &df)
    : old_transparency(Common::Location::transparency)
    { Common::Location::transparency = df.is_transparent(); }

    /** Restores the value of Common::Location::transparency */
    ~transparency_holder()
    { Common::Location::transparency = old_transparency; }
  };

  /**
   * Def_ExtFunction class represents an external function definition.
   */
  class Def_ExtFunction : public Def_Function_Base {
  public:
    enum ExternalFunctionType_t {
      EXTFUNC_MANUAL, /**< written manually by the user */
      EXTFUNC_ENCODE, /**< automatically generated encoder function */
      EXTFUNC_DECODE /**< automatically generated decoder function */
    };
  private:
    ExternalFunctionType_t function_type;
    Type::MessageEncodingType_t encoding_type;
    string *encoding_options;
    Ttcn::ErrorBehaviorList *eb_list;
1579
1580
    // pretty or compact printing for json or xml
    Ttcn::PrintingType *printing;
1581
    bool deterministic;
1582
    bool ext_keyword;
Elemer Lelik's avatar
Elemer Lelik committed
1583
1584
1585
1586
1587
1588
1589
1590
1591
    /// Copy constructor disabled
    Def_ExtFunction(const Def_ExtFunction& p);
    /// %Assignment disabled
    Def_ExtFunction& operator=(const Def_ExtFunction& p);
  public:
    /** Constructor for an external function definition
     *
     * Called from a single location in compiler.y
     *
1592
     * @param p_deterministic true if deterministic function
Elemer Lelik's avatar
Elemer Lelik committed
1593
1594
1595
1596
1597
1598
     * @param p_id the name
     * @param p_fpl formal parameters
     * @param p_return_type the return type
     * @param returns_template true if it returns a template
     * @param p_template_restriction restriction type
     */
1599
    Def_ExtFunction(bool p_deterministic, Identifier *p_id, FormalParList *p_fpl,
Elemer Lelik's avatar
Elemer Lelik committed
1600
      Type *p_return_type, bool returns_template,
1601
      template_restriction_t p_template_restriction, bool p_final, bool p_ext_keyword)
Elemer Lelik's avatar
Elemer Lelik committed
1602
      : Def_Function_Base(true, p_id, p_fpl, p_return_type, returns_template,
1603
          p_template_restriction, p_final),
Elemer Lelik's avatar
Elemer Lelik committed
1604
      function_type(EXTFUNC_MANUAL), encoding_type(Type::CT_UNDEF),
1605
      encoding_options(0), eb_list(0), printing(0),
1606
      deterministic(p_deterministic), ext_keyword(p_ext_keyword) { }
Elemer Lelik's avatar
Elemer Lelik committed
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
    ~Def_ExtFunction();
    virtual Def_ExtFunction *clone() const;
    virtual void set_fullname(const string& p_fullname);
    void set_encode_parameters(Type::MessageEncodingType_t p_encoding_type,
      string *p_encoding_options);
    void set_decode_parameters(Type::MessageEncodingType_t p_encoding_type,
      string *p_encoding_options);
    void add_eb_list(Ttcn::ErrorBehaviorList *p_eb_list);
    ExternalFunctionType_t get_function_type() const { return function_type; }
  private:
    void chk_function_type();
    void chk_allowed_encode();
  public:
    virtual void chk();
  private:
    char *generate_code_encode(char *str);
    char *generate_code_decode(char *str);
  public:
    virtual void generate_code(output_struct *target, bool clean_up = false);
    /// Just a shim for code splitting
    virtual void generate_code(CodeGenHelper& cgh);
    virtual void dump_internal(unsigned level) const;
    
    /** For JSON encoding and decoding functions only
      * Generates a JSON schema segment containing a reference to the encoded
      * type's schema and any information required to recreate this function.
      * If the schema with the reference already exists, the function's info is
      * inserted in the schema. */
    void generate_json_schema_ref(map<Type*, JSON_Tokenizer>& json_refs);
  };
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
  
  /**
    * Represents an abstract function definition (inside a class definition)
    */
  class Def_AbsFunction : public Def_Function_Base {
    bool deterministic;
  public:
    Def_AbsFunction(bool p_deterministic, Identifier* p_id, FormalParList* p_fpl,
      Type* p_return_type, bool returns_template,
      template_restriction_t p_template_restriction)
    : Def_Function_Base(false, p_id, p_fpl, p_return_type, returns_template,
1648
      p_template_restriction, false) { }
1649
1650
1651
1652
1653
    virtual ~Def_AbsFunction();
    virtual Definition* clone() const;
    virtual void chk();
    virtual void generate_code(output_struct* target, bool clean_up = false);
  };
Elemer Lelik's avatar
Elemer Lelik committed
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670

  /**
   * Represents an altstep definition.
   */
  class Def_Altstep : public Definition {
  private:
    /** The formal parameter list of the altstep. It is never NULL even if
     * the altstep has no parameters. */
    FormalParList *fp_list;
    /** The 'runs on' clause (i.e. a reference to a TTCN-3 component type)
     * It is NULL if the altstep has no 'runs on' clause. */
    Reference *runs_on_ref;
    /** Points to the object describing the component type referred by
     * 'runs on' clause.
     * It is NULL if the altstep has no 'runs on' clause or \a runs_on_ref is
     * erroneous. */
    Type *runs_on_type;
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
    /** The 'mtc' clause (i.e. a reference to a TTCN-3 component type)
     * It is NULL if the altstep has no 'mtc' clause. */
    Reference *mtc_ref;
    /** Points to the object describing the component type referred by
     * 'mtc' clause.
     * It is NULL if the altstep has no 'mtc' clause or \a mtc_ref is
     * erroneous. */
    Type *mtc_type;
    /** The 'system' clause (i.e. a reference to a TTCN-3 component type)
     * It is NULL if the altstep has no 'system' clause. */
    Reference *system_ref;
    /** Points to the object describing the component type referred by
     * 'system' clause.
     * It is NULL if the altstep has no 'system' clause or \a system_ref is
     * erroneous. */
    Type *system_type;
Elemer Lelik's avatar
Elemer Lelik committed
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
    StatementBlock *sb; /**< contains the local definitions */
    AltGuards *ags;

    NameBridgingScope bridgeScope;

    /// Copy constructor disabled
    Def_Altstep(const Def_Altstep& p);
    /// %Assignment disabled
    Def_Altstep& operator=(const Def_Altstep& p);
  public:
    Def_Altstep(Identifier *p_id, FormalParList *p_fpl,
1698
1699
                Reference *p_runs_on_ref, Reference *p_mtc_ref,
                Reference *p_system_ref, StatementBlock *p_sb,
Elemer Lelik's avatar
Elemer Lelik committed
1700
1701
1702
1703
1704
1705
                AltGuards *p_ags);
    virtual ~Def_Altstep();
    virtual Def_Altstep *clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    virtual Type *get_RunsOnType();
1706
1707
    virtual Type *get_MtcType();
    virtual Type *get_SystemType();
Elemer Lelik's avatar
Elemer Lelik committed
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
    virtual FormalParList *get_FormalParList();
    /** Returns a scope that can access the definitions within component type
     * \a comptype and its parent is \a parent_scope.*/
    RunsOnScope *get_runs_on_scope(Type *comptype);
    virtual void chk();
    virtual void generate_code(output_struct *target, bool clean_up = false);
    virtual void generate_code(CodeGenHelper& cgh);
    virtual void dump_internal(unsigned level) const;

    virtual void set_parent_path(WithAttribPath* p_path);
  };

  /**
   * Represents an testcase definition.
   */
  class Def_Testcase : public Definition {
  private:
    /** The formal parameter list of the testcase. It is never NULL even if
     * the testcase has no parameters. */
    FormalParList *fp_list;
    /** The 'runs on' clause (i.e. a reference to a TTCN-3 component type)
     *  It is never NULL. */
    Reference *runs_on_ref;
    /** Points to the object describing the component type referred by
     * 'runs on' clause. It is NULL only if \a runs_on_ref is erroneous. */
    Type *runs_on_type;
    /** The 'system' clause (i.e. a reference to a TTCN-3 component type)
     *  It is NULL if the testcase has no 'system' clause. */
    Reference *system_ref;
    /** Points to the object describing the component type referred by
     * 'system' clause. It is NULL if the testcase has no 'system' clause or
     * \a system_ref is erroneous. */
    Type *system_type;
    StatementBlock *block;

    NameBridgingScope bridgeScope;

    /// Copy constructor disabled
    Def_Testcase(const Def_Testcase& p);
    /// %Assignment disabled
    Def_Testcase& operator=(const Def_Testcase& p);
  public:
    Def_Testcase(Identifier *p_id, FormalParList *p_fpl,
                 Reference *p_runs_on_ref, Reference *p_system_ref,
                 StatementBlock *p_block);
    virtual ~Def_Testcase();
    virtual Def_Testcase *clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    virtual Type *get_RunsOnType();
    Type *get_SystemType();
    virtual FormalParList *get_FormalParList();
    /** Returns a scope that can access the definitions within component type
     * \a comptype and its parent is \a parent_scope.*/
    RunsOnScope *get_runs_on_scope(Type *comptype);
    virtual void chk();
    virtual void generate_code(output_struct *target, bool clean_up = false);
    virtual void generate_code(CodeGenHelper& cgh);
    virtual void dump_internal(unsigned level) const;

    virtual void set_parent_path(WithAttribPath* p_path);
  };
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
  
  /**
   * Represents a constructor definition (inside a class definition).
   */
  class Def_Constructor : public Definition {
  private:
    /** The formal parameter list of the constructor. It is never NULL even if
     * the constructor has no parameters. */
    FormalParList* fp_list;
    
1780
    Reference* base_call;
1781
1782
1783
    
    StatementBlock* block;
    
1784
    NameBridgingScope bridgeScope;
1785
1786
1787
1788
1789
1790
    
    /// Copy constructor disabled
    Def_Constructor(const Def_Constructor& p);
    /// %Assignment disabled
    Def_Constructor& operator=(const Def_Constructor& p);
  public:
1791
    Def_Constructor(FormalParList* p_fp_list, Reference* p_base_call,
1792
1793
1794
1795
1796
      StatementBlock* p_block);
    virtual ~Def_Constructor();
    virtual Def_Constructor* clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope* p_scope);
1797
    virtual FormalParList* get_FormalParList();
1798
    virtual Reference* get_base_call() const { return base_call; }
1799
1800
1801
1802
    virtual void chk();
    virtual void generate_code(output_struct *target, bool clean_up = false);
    virtual void set_parent_path(WithAttribPath* p_path);
  };
Elemer Lelik's avatar
Elemer Lelik committed
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823

  /** General class to represent formal parameters. The inherited
   * attribute asstype carries the kind and direction of the
   * parameter. */
  class FormalPar : public Definition {
  private:
    Type *type;
    /** Default value of the parameter (optional). If \a checked flag is true
     *  then field \a ap is used otherwise \a ti is active. */
    union {
      TemplateInstance *ti;
      ActualPar *ap;
    } defval;
    /** Points to the formal parameter list that \a this belongs to. */
    FormalParList *my_parlist;
    /** Flag that indicates whether the value of the parameter is overwritten
     * within the function/altstep/testcase body.
     * Used only in case of `in' value or template parameters. */
    bool used_as_lvalue;
    /** restriction on template value */
    template_restriction_t template_restriction;
1824
1825
    /** normal, lazy or fuzzy evaluation parametrization should be used */
    param_eval_t eval;
Elemer Lelik's avatar
Elemer Lelik committed
1826
1827
1828
    /** Flag that indicates whether the C++ code for the parameter's default
      * value has been generated or not. */
    bool defval_generated;
Elemer Lelik's avatar
Elemer Lelik committed
1829
1830
1831
    /** Flag that indicates whether the parameter is used in the function/
     * altstep/testcase/parameterized template body. */
    bool usage_found;
Elemer Lelik's avatar
Elemer Lelik committed
1832
1833
1834
1835
1836
1837
1838

    /// Copy constructor disabled
    FormalPar(const FormalPar& p);
    /// %Assignment disabled
    FormalPar& operator=(const FormalPar& p);
  public:
    FormalPar(asstype_t p_asstype, Type *p_type, Identifier* p_name,
1839
      TemplateInstance *p_defval, param_eval_t p_eval = NORMAL_EVAL);
Elemer Lelik's avatar
Elemer Lelik committed
1840
1841
1842
    FormalPar(asstype_t p_asstype,
      template_restriction_t p_template_restriction,
      Type *p_type, Identifier* p_name, TemplateInstance *p_defval,
1843
      param_eval_t p_eval = NORMAL_EVAL);
Elemer Lelik's avatar
Elemer Lelik committed
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
    FormalPar(asstype_t p_asstype, Identifier* p_name,
      TemplateInstance *p_defval);
    ~FormalPar();
    virtual FormalPar *clone() const;
    virtual void set_fullname(const string& p_fullname);
    virtual void set_my_scope(Scope *p_scope);
    /** Always true. Formal parameters are considered as local definitions
     * even if their scope is the module definitions. */
    virtual bool is_local() const;
    virtual Type *get_Type();
    virtual void chk();
1855
1856