97c13c1f67715b1e80032fa0fa264fccecba330f
[deliverable/titan.core.git] / compiler2 / ttcn3 / ArrayDimensions.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 * Balasko, Jeno
10 * Beres, Szabolcs
11 * Raduly, Csaba
12 *
13 ******************************************************************************/
14 #ifndef _Ttcn_Array_HH
15 #define _Ttcn_Array_HH
16
17 #include "../Setting.hh"
18 #include "../Type.hh"
19 #include "../Int.hh"
20 #include "../vector.hh"
21
22 namespace Common {
23 // not defined here
24 class Value;
25 class Scope;
26 }
27
28 namespace Ttcn {
29
30 using namespace Common;
31
32 class Ref_base;
33
34 /**
35 * Class to represent the index set of a TTCN-3 array dimension.
36 */
37 class ArrayDimension : public Node, public Location {
38 private:
39 bool checked;
40 bool is_range;
41 bool has_error;
42 union {
43 Value *single;
44 struct {
45 Value *lower, *upper;
46 } range;
47 } u;
48 Scope *my_scope;
49 size_t size;
50 Int offset;
51 ArrayDimension(const ArrayDimension& p);
52 ArrayDimension& operator=(const ArrayDimension& p);
53 public:
54 ArrayDimension(Value *p_single);
55 ArrayDimension(Value *p_lower, Value *p_upper);
56 virtual ~ArrayDimension();
57 virtual ArrayDimension *clone() const;
58 virtual void set_my_scope(Scope *p_scope);
59 virtual void set_fullname(const string& p_fullname);
60 void chk();
61 void chk_index(Value *index, Type::expected_value_t exp_val);
62 size_t get_size();
63 Int get_offset();
64 string get_stringRepr();
65 /** Returns whether \a this and \a p_dim are identical (i.e. both has the
66 * same size and offset). */
67 bool is_identical(ArrayDimension *p_dim);
68 /** Returns the C++ type expression that represents the equivalent value
69 * class at runtime viewed from the module of scope \a p_scope.
70 * Argument \a p_element_type points to the embedded type. */
71 string get_value_type(Type *p_element_type, Scope *p_scope);
72 /** Returns the C++ type expression that represents the equivalent template
73 * class at runtime viewed from the module of scope \a p_scope.
74 * Argument \a p_element_type points to the embedded type. */
75 string get_template_type(Type *p_element_type, Scope *p_scope);
76 bool get_has_error() const { return has_error; }
77 virtual void dump(unsigned level) const;
78 };
79
80 /**
81 * Class to represent the array dimensions of TTCN-3 timers and ports.
82 * These arrays do not support slicing, that is, only a single element of
83 * them can be accessed.
84 */
85 class ArrayDimensions : public Node {
86 private:
87 vector<ArrayDimension> dims;
88 ArrayDimensions(const ArrayDimensions& p);
89 ArrayDimensions& operator=(const ArrayDimensions& p);
90 public:
91 ArrayDimensions() : Node() { }
92 virtual ~ArrayDimensions();
93 virtual ArrayDimensions *clone() const;
94 virtual void set_my_scope(Scope *p_scope);
95 virtual void set_fullname(const string& p_fullname);
96 void add(ArrayDimension *dim);
97 size_t get_nof_dims() { return dims.size(); }
98 ArrayDimension *get_dim_byIndex(size_t index) { return dims[index]; }
99 void chk();
100 /** Checks the field or array references of \a ref against the array
101 * dimensions. If parameter \a allow_slicing is false slicing of timer or
102 * port arrays are not allowed thus the number of array indices in \a ref
103 * must be the same as the number of array dimensions. Otherwise (i.e. if
104 * \a allow_slicing is true \a ref may have fewer indices.
105 * Parameter \a def_name is needed for error messages, it shall be either
106 * "timer" or "port". */
107 void chk_indices(Common::Reference *ref, const char *def_type, bool allow_slicing,
108 Type::expected_value_t exp_val);
109 /** Returns the total number of elements in the array. */
110 size_t get_array_size();
111 /** Generates a C++ code fragment, which is a comma separated list of string
112 * literals containing the array element indices in canonical order. Each
113 * string literal is prefixed with name \a p_name. The generated code is
114 * appended to \a str and the resulting string is returned. The function is
115 * recursive, argument \a start_dim must be zero when calling it from
116 * outside. */
117 char *generate_element_names(char *str, const string& p_name,
118 size_t start_dim = 0);
119 /** Returns the C++ type expression that represents the type of the timer
120 * array. It does not consider the leftmost \a start_dim dimensions. */
121 string get_timer_type(size_t start_dim = 0);
122 /** Returns the C++ type expression that represents the type of the port
123 * array. Parameter \a p_genname is the name of port type class. */
124 string get_port_type(const string& p_genname);
125 virtual void dump(unsigned level) const;
126 bool is_identical(ArrayDimensions *other);
127 };
128
129 }
130
131 #endif // _Ttcn_Array_HH
This page took 0.062561 seconds and 5 git commands to generate.