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