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 ///////////////////////////////////////////////////////////////////////////////
11 #include "../Setting.hh"
14 #include "../vector.hh"
24 using namespace Common;
29 * Class to represent the index set of a TTCN-3 array dimension.
31 class ArrayDimension : public Node, public Location {
45 ArrayDimension(const ArrayDimension& p);
46 ArrayDimension& operator=(const ArrayDimension& p);
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);
55 void chk_index(Value *index, Type::expected_value_t exp_val);
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;
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.
79 class ArrayDimensions : public Node {
81 vector<ArrayDimension> dims;
82 ArrayDimensions(const ArrayDimensions& p);
83 ArrayDimensions& operator=(const ArrayDimensions& p);
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]; }
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
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);
125 #endif // _Ttcn_Array_HH