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
17 * Szabo, Janos Zoltan – initial implementation
19 ******************************************************************************/
20 #ifndef _Common_Valuestuff_HH
21 #define _Common_Valuestuff_HH
25 #include "ttcn3/AST_ttcn3.hh"
40 * \addtogroup AST_Value
46 * Class to represent an IndexedValue.
48 class IndexedValue : public Node, public Location {
50 Ttcn::FieldOrArrayRef *index;
52 IndexedValue(const IndexedValue& p);
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; }
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);
70 * Class to represent ValueList.
72 class Values : public Node {
77 vector<IndexedValue> *ivs;
79 Values(const Values& p);
81 Values(bool p_indexed = false);
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; }
99 * Class to represent a NamedValue.
101 class NamedValue : public Node, public Location {
105 NamedValue(const NamedValue& p);
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;
119 * Class to represent NamedValueList.
121 class NamedValues : public Node {
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;
129 NamedValues(const NamedValues& p);
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;
147 * Object identifier component.
149 class OID_comp : public Node, public Location {
151 /** Which form was used. */
153 NAMEFORM, /**< NameForm */
154 NUMBERFORM, /**< NumberForm */
155 NAMEANDNUMBERFORM, /**< NameAndNumberForm */
156 DEFDVALUE, /**< DefinedValue */
157 VARIABLE /**< Variable */
159 /** Which state the checking is in. */
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 */
173 static const nameform_t names_root[], names_itu[], names_iso[],
177 /** OID, ROID or INTEGER */
179 /** maybe a reference to an INTEGER or R/OID (if NAMEFORM) */
181 /** Integer (or reference to an integer) */
183 /** Integer variable (cannot be calculated in compile-time) */
186 OID_comp(const OID_comp& p);
188 OID_comp(Identifier *p_name, Value *p_number);
189 OID_comp(Value *p_defdval);
191 virtual OID_comp *clone() const;
192 /** Checking function for OID components */
193 void chk_OID(ReferenceChain& refch, Value *parent, size_t index,
195 /** checking function for ROID components */
196 void chk_ROID(ReferenceChain& refch, size_t index);
197 /** Returns whether the component contains any 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);
203 /** Returns true, if the component's value is unknown at compile-time */
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
234 void chk_numberform_ROID();
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;
243 * Universal charstring element.
245 class CharsDefn : public Node, public Location {
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 */
264 CharsDefn(const CharsDefn& p);
267 CharsDefn(string *p_str);
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;}
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;
292 * Universal charstring elements.
294 class CharSyms : public Node, public Location {
296 vector <CharsDefn> cds;
308 CharSyms(const CharSyms& p);
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;
327 /** @} end of AST_Value group */
329 } // namespace Common
331 #endif // _Common_Value_HH