Commit | Line | Data |
---|---|---|
970ed795 | 1 | /////////////////////////////////////////////////////////////////////////////// |
3abe9331 | 2 | // Copyright (c) 2000-2015 Ericsson Telecom AB |
970ed795 EL |
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 _Common_Valuestuff_HH | |
9 | #define _Common_Valuestuff_HH | |
10 | ||
11 | #include "Setting.hh" | |
12 | #include "Int.hh" | |
13 | #include "ttcn3/AST_ttcn3.hh" | |
14 | ||
15 | class ustring; | |
16 | ||
17 | namespace Asn { | |
18 | class Block; | |
19 | } | |
20 | ||
21 | namespace Common { | |
22 | ||
23 | // not defined here | |
24 | class Value; | |
25 | using Asn::Block; | |
26 | ||
27 | /** | |
28 | * \addtogroup AST_Value | |
29 | * | |
30 | * @{ | |
31 | */ | |
32 | ||
33 | /** | |
34 | * Class to represent an IndexedValue. | |
35 | */ | |
36 | class IndexedValue : public Node, public Location { | |
37 | private: | |
38 | Ttcn::FieldOrArrayRef *index; | |
39 | Value *value; | |
40 | IndexedValue(const IndexedValue& p); | |
41 | public: | |
42 | IndexedValue(Ttcn::FieldOrArrayRef *p_index, Value *p_value); | |
43 | virtual ~IndexedValue(); | |
44 | virtual IndexedValue* clone() const; | |
45 | virtual void set_fullname(const string& p_fullname); | |
46 | virtual void set_my_scope(Scope *p_scope); | |
47 | void set_code_section(GovernedSimple::code_section_t p_code_section); | |
48 | inline Value *get_index() const { return index->get_val(); } | |
49 | inline Value *get_value() const { return value; } | |
50 | Value *steal_value(); | |
51 | virtual void dump(unsigned level) const; | |
52 | virtual bool is_unfoldable(ReferenceChain *refch=0, | |
53 | Type::expected_value_t exp_val=Type::EXPECTED_DYNAMIC_VALUE); | |
54 | ||
55 | }; | |
56 | ||
57 | /** | |
58 | * Class to represent ValueList. | |
59 | */ | |
60 | class Values : public Node { | |
61 | private: | |
62 | bool indexed; | |
63 | union { | |
64 | vector<Value> *vs; | |
65 | vector<IndexedValue> *ivs; | |
66 | }; | |
67 | Values(const Values& p); | |
68 | public: | |
69 | Values(bool p_indexed = false); | |
70 | virtual ~Values(); | |
71 | virtual Values *clone() const; | |
72 | virtual void set_fullname(const string& p_fullname); | |
73 | virtual void set_my_scope(Scope *p_scope); | |
74 | void add_v(Value *p_v); | |
75 | void add_iv(IndexedValue *p_iv); | |
76 | size_t get_nof_vs() const; | |
77 | size_t get_nof_ivs() const; | |
78 | Value *get_v_byIndex(size_t p_i) const; | |
79 | IndexedValue *get_iv_byIndex(size_t p_i) const; | |
80 | Value *steal_v_byIndex(size_t p_i); | |
81 | IndexedValue *steal_iv_byIndex(size_t p_i); | |
82 | virtual void dump(unsigned p_level) const; | |
83 | inline bool is_indexed() const { return indexed; } | |
84 | }; | |
85 | ||
86 | /** | |
87 | * Class to represent a NamedValue. | |
88 | */ | |
89 | class NamedValue : public Node, public Location { | |
90 | private: | |
91 | Identifier *name; | |
92 | Value *value; | |
93 | NamedValue(const NamedValue& p); | |
94 | public: | |
95 | NamedValue(Identifier *p_name, Value *p_value); | |
96 | virtual ~NamedValue(); | |
97 | virtual NamedValue* clone() const; | |
98 | virtual void set_fullname(const string& p_fullname); | |
99 | virtual void set_my_scope(Scope *p_scope); | |
100 | const Identifier& get_name() const { return *name; } | |
101 | Value *get_value() const { return value; } | |
102 | Value *steal_value(); | |
103 | virtual void dump(unsigned level) const; | |
104 | }; | |
105 | ||
106 | /** | |
107 | * Class to represent NamedValueList. | |
108 | */ | |
109 | class NamedValues : public Node { | |
110 | private: | |
111 | /** named values */ | |
112 | vector<NamedValue> nvs_v; | |
113 | /** Stores the first occurence of NamedValue with id. The string | |
114 | * parameter refers to the id of the nv. */ | |
115 | map<string, NamedValue> nvs_m; | |
116 | bool checked; | |
117 | NamedValues(const NamedValues& p); | |
118 | public: | |
119 | NamedValues() : Node(), checked(false) { } | |
120 | virtual ~NamedValues(); | |
121 | virtual NamedValues *clone() const; | |
122 | virtual void set_fullname(const string& p_fullname); | |
123 | virtual void set_my_scope(Scope *p_scope); | |
124 | void add_nv(NamedValue *p_nv); | |
125 | /** Returns the vector's size! */ | |
126 | size_t get_nof_nvs() const { return nvs_v.size(); } | |
127 | NamedValue *get_nv_byIndex(const size_t p_i) const { return nvs_v[p_i]; } | |
128 | bool has_nv_withName(const Identifier& p_name); | |
129 | NamedValue *get_nv_byName(const Identifier& p_name); | |
130 | void chk_dupl_id(bool report_errors = true); | |
131 | virtual void dump(unsigned level) const; | |
132 | }; | |
133 | ||
134 | /** | |
135 | * Object identifier component. | |
136 | */ | |
137 | class OID_comp : public Node, public Location { | |
138 | public: | |
139 | /** Which form was used. */ | |
140 | enum formtype_t { | |
141 | NAMEFORM, /**< NameForm */ | |
142 | NUMBERFORM, /**< NumberForm */ | |
143 | NAMEANDNUMBERFORM, /**< NameAndNumberForm */ | |
144 | DEFDVALUE, /**< DefinedValue */ | |
145 | VARIABLE /**< Variable */ | |
146 | }; | |
147 | /** Which state the checking is in. */ | |
148 | enum oidstate_t { | |
149 | START, /**< at the beginning */ | |
150 | ITU, /**< after itu-t */ | |
151 | ISO, /**< after iso */ | |
152 | JOINT, /**< after joint-iso-itu-t */ | |
153 | ITU_REC, /**< after itu-t recommendation */ | |
154 | LATER /**< later anywhere */ | |
155 | }; | |
156 | private: | |
157 | struct nameform_t { | |
158 | const char *name; | |
159 | unsigned int value; | |
160 | }; | |
161 | static const nameform_t names_root[], names_itu[], names_iso[], | |
162 | names_joint[]; | |
163 | private: | |
164 | formtype_t formtype; | |
165 | /** OID, ROID or INTEGER */ | |
166 | Value *defdval; | |
167 | /** maybe a reference to an INTEGER or R/OID (if NAMEFORM) */ | |
168 | Identifier *name; | |
169 | /** Integer (or reference to an integer) */ | |
170 | Value *number; | |
171 | /** Integer variable (cannot be calculated in compile-time) */ | |
172 | Value *var; | |
173 | ||
174 | OID_comp(const OID_comp& p); | |
175 | public: | |
176 | OID_comp(Identifier *p_name, Value *p_number); | |
177 | OID_comp(Value *p_defdval); | |
178 | virtual ~OID_comp(); | |
179 | virtual OID_comp *clone() const; | |
180 | /** Checking function for OID components */ | |
181 | void chk_OID(ReferenceChain& refch, Value *parent, size_t index, | |
182 | oidstate_t& state); | |
183 | /** checking function for ROID components */ | |
184 | void chk_ROID(ReferenceChain& refch, size_t index); | |
185 | /** Returns whether the component contains any error. */ | |
186 | bool has_error(); | |
187 | /** Appends the integer value of number or the components of the referenced | |
188 | * OID/ROID value to \a comps. */ | |
189 | void get_comps(vector<string>& comps); | |
190 | ||
191 | /** Returns true, if the component's value is unknown at compile-time */ | |
192 | bool is_variable(); | |
193 | private: | |
194 | /** Detects whether the identifier in \a name is a valid name form in | |
195 | * state \a state. If yes the equivalent non-negative numeric value is | |
196 | * returned and \a state is updated. Otherwise -1 is returned and | |
197 | * \a state remains unchanged. */ | |
198 | Int detect_nameform(oidstate_t& state); | |
199 | /** Checks the defined value in \a defdval in an OID component and | |
200 | * updates \a state accordingly. */ | |
201 | void chk_defdvalue_OID(ReferenceChain& refch, oidstate_t& state); | |
202 | /** Checks the NumberForm (or the number part of NameAndNumberForm) in an | |
203 | * OID component and updates \a state accordingly. */ | |
204 | void chk_numberform_OID(oidstate_t& state); | |
205 | /** Checks the NameAndNumberForm: checks the \a number, updates \a state | |
206 | * and verifies whether the name is in accordance with \a name and the | |
207 | * initial \a state. */ | |
208 | void chk_nameandnumberform(oidstate_t& state); | |
209 | /** Returns whether \a p_name is a correct name for \a p_number according | |
210 | * to the table \a p_names. */ | |
211 | static bool is_valid_name_for_number(const string& p_name, | |
212 | const Int& p_number, const nameform_t *p_names); | |
213 | /** Returns the expected name(s) for number \a p_number according to table | |
214 | * \a p_names. Flag \a p_asn1 indicates the the ASN.1 or TTCN-3 notation | |
215 | * shall be used in the identifiers. */ | |
216 | static string get_expected_name_for_number(const Int& p_number, | |
217 | bool p_asn1, const nameform_t *p_names); | |
218 | /** Checks the defined value in \a defdval in a ROID component. */ | |
219 | void chk_defdvalue_ROID(ReferenceChain& refch); | |
220 | /** Checks the NumberForm (or the number part of NameAndNumberForm) in a | |
221 | * ROID component. */ | |
222 | void chk_numberform_ROID(); | |
223 | public: | |
224 | virtual void set_fullname(const string& p_fullname); | |
225 | void set_my_scope(Scope *p_scope); | |
226 | /** Appends the string representation of the OID component to \a str. */ | |
227 | void append_stringRepr(string& str) const; | |
228 | }; | |
229 | ||
230 | /** | |
231 | * Universal charstring element. | |
232 | */ | |
233 | class CharsDefn : public Node, public Location { | |
234 | public: | |
235 | enum selector_t { | |
236 | CD_CSTRING, | |
237 | CD_QUADRUPLE, | |
238 | CD_TUPLE, | |
239 | CD_VALUE, | |
240 | CD_BLOCK | |
241 | } selector; | |
242 | bool checked; | |
243 | private: | |
244 | union { | |
245 | string *str; /**< cstring */ | |
246 | struct {Int g, p, r, c;} quadruple; /**< quadruple */ | |
247 | struct {Int c, r;} tuple; /**< tuple */ | |
248 | Value *val; /**< defined val => referenced val */ | |
249 | Block *block; /**< quadruple or tuple block */ | |
250 | } u; | |
251 | ||
252 | CharsDefn(const CharsDefn& p); | |
253 | public: | |
254 | /** ctor for cstr */ | |
255 | CharsDefn(string *p_str); | |
256 | /** ctor for val */ | |
257 | CharsDefn(Value *p_val); | |
258 | /** ctor for quadruple */ | |
259 | CharsDefn(Int p_g, Int p_p, Int p_r, Int p_c); | |
260 | /** ctor for tuple */ | |
261 | CharsDefn(Int p_c, Int p_r); | |
262 | /** ctor for block */ | |
263 | CharsDefn(Block *p_block); | |
264 | virtual ~CharsDefn(); | |
265 | virtual CharsDefn* clone() const; | |
266 | virtual void set_fullname(const string& p_fullname); | |
267 | virtual void set_my_scope(Scope *p_scope); | |
268 | selector_t get_selector() {return selector;} | |
269 | void chk(); | |
270 | string get_string(ReferenceChain *refch=0); | |
271 | ustring get_ustring(ReferenceChain *refch=0); | |
272 | string get_iso2022string(ReferenceChain *refch=0); | |
273 | size_t get_len(ReferenceChain *refch); | |
274 | virtual void dump(unsigned level) const; | |
275 | private: | |
276 | void parse_block(); | |
277 | }; | |
278 | ||
279 | /** | |
280 | * Universal charstring elements. | |
281 | */ | |
282 | class CharSyms : public Node, public Location { | |
283 | private: | |
284 | vector <CharsDefn> cds; | |
285 | enum selector_t { | |
286 | CS_UNDEF, | |
287 | CS_CHECKING, | |
288 | CS_CSTRING, | |
289 | CS_USTRING, | |
290 | CS_ISO2022STRING | |
291 | } selector; | |
292 | union { | |
293 | string *str; | |
294 | ustring *ustr; | |
295 | } u; | |
296 | CharSyms(const CharSyms& p); | |
297 | public: | |
298 | CharSyms(); | |
299 | virtual ~CharSyms(); | |
300 | virtual CharSyms* clone() const; | |
301 | virtual void set_fullname(const string& p_fullname); | |
302 | virtual void set_my_scope(Scope *p_scope); | |
303 | /** \a p_cd can be 0 in case of error => drop it */ | |
304 | void add_cd(CharsDefn *p_cd); | |
305 | void chk(bool tuple_enabled, bool quadruple_enabled); | |
306 | size_t get_nof_cds() const {return cds.size();} | |
307 | CharsDefn*& get_cd_byIndex(size_t p_i) {return cds[p_i];} | |
308 | string get_string(ReferenceChain *refch=0); | |
309 | ustring get_ustring(ReferenceChain *refch=0); | |
310 | string get_iso2022string(ReferenceChain *refch=0); | |
311 | size_t get_len(ReferenceChain *refch=0); | |
312 | virtual void dump(unsigned level) const; | |
313 | }; | |
314 | ||
315 | /** @} end of AST_Value group */ | |
316 | ||
317 | } // namespace Common | |
318 | ||
319 | #endif // _Common_Value_HH |