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