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 _Common_Valuestuff_HH
9 #define _Common_Valuestuff_HH
13 #include "ttcn3/AST_ttcn3.hh"
28 * \addtogroup AST_Value
34 * Class to represent an IndexedValue.
36 class IndexedValue : public Node, public Location {
38 Ttcn::FieldOrArrayRef *index;
40 IndexedValue(const IndexedValue& p);
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; }
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);
58 * Class to represent ValueList.
60 class Values : public Node {
65 vector<IndexedValue> *ivs;
67 Values(const Values& p);
69 Values(bool p_indexed = false);
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; }
87 * Class to represent a NamedValue.
89 class NamedValue : public Node, public Location {
93 NamedValue(const NamedValue& p);
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;
107 * Class to represent NamedValueList.
109 class NamedValues : public Node {
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;
117 NamedValues(const NamedValues& p);
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;
135 * Object identifier component.
137 class OID_comp : public Node, public Location {
139 /** Which form was used. */
141 NAMEFORM, /**< NameForm */
142 NUMBERFORM, /**< NumberForm */
143 NAMEANDNUMBERFORM, /**< NameAndNumberForm */
144 DEFDVALUE, /**< DefinedValue */
145 VARIABLE /**< Variable */
147 /** Which state the checking is in. */
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 */
161 static const nameform_t names_root[], names_itu[], names_iso[],
165 /** OID, ROID or INTEGER */
167 /** maybe a reference to an INTEGER or R/OID (if NAMEFORM) */
169 /** Integer (or reference to an integer) */
171 /** Integer variable (cannot be calculated in compile-time) */
174 OID_comp(const OID_comp& p);
176 OID_comp(Identifier *p_name, Value *p_number);
177 OID_comp(Value *p_defdval);
179 virtual OID_comp *clone() const;
180 /** Checking function for OID components */
181 void chk_OID(ReferenceChain& refch, Value *parent, size_t index,
183 /** checking function for ROID components */
184 void chk_ROID(ReferenceChain& refch, size_t index);
185 /** Returns whether the component contains any 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);
191 /** Returns true, if the component's value is unknown at compile-time */
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
222 void chk_numberform_ROID();
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;
231 * Universal charstring element.
233 class CharsDefn : public Node, public Location {
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 */
252 CharsDefn(const CharsDefn& p);
255 CharsDefn(string *p_str);
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;}
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;
280 * Universal charstring elements.
282 class CharSyms : public Node, public Location {
284 vector <CharsDefn> cds;
296 CharSyms(const CharSyms& p);
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;
315 /** @} end of AST_Value group */
317 } // namespace Common
319 #endif // _Common_Value_HH