added any2unistr predefined function (artf724008)
[deliverable/titan.core.git] / compiler2 / ttcn3 / Attributes.hh
CommitLineData
d44e3c4f 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 * Delic, Adam
11 * Raduly, Csaba
12 * Szabados, Kristof
13 * Szabo, Janos Zoltan – initial implementation
14 * Zalanyi, Balazs Andor
15 *
16 ******************************************************************************/
970ed795
EL
17#ifndef ATTRIBUTES_HH
18#define ATTRIBUTES_HH
19
20#include "../string.hh"
21#include "../vector.hh"
22#include "../Identifier.hh"
23#include "../Setting.hh"
24#include "AST_ttcn3.hh"
25
26namespace Ttcn {
27
28 using namespace Common;
29
30 class Definition;
31 class ImpMod;
32 class Group;
33 class Def_Template;
34 class TemplateInstance;
35
36 /** Attribute qualifier (DefOrFieldRef). */
37 class Qualifier: public FieldOrArrayRefs, public Location
38 {
39 /// Assignment disabled.
40 Qualifier& operator=(const Qualifier& p);
41 public:
42 Qualifier(): FieldOrArrayRefs(), Location() { }
43 Qualifier(const Qualifier& p): FieldOrArrayRefs(p), Location(p) { }
44 virtual Qualifier* clone() const;
45 /** return array indexes as "_0" identifiers TODO: remove */
46 const Identifier* get_identifier(size_t p_index) const;
47 /** use with get_identifier() TODO: remove */
48 size_t get_nof_identifiers() const { return get_nof_refs(); }
49 /** Returns a newly allocated Qualifier, without the first identifier.
50 * Used by Common::Type::parse_raw to propagate an attribute
51 * with a qualifier from a type (record,union,rec-of) to its component */
52 Qualifier* get_qualifier_without_first_id() const;
53 string get_stringRepr() const;
54 void dump(unsigned level) const;
55 };
56
57 /** Attribute qualifiers, when there were multiple qualifiers
58 * in the DefOrFieldRefList.
59 *
60 * E.g. the three-element list from below:
61 * @code variant (foo.f00, bar, baz[-]) "something" @endcode */
62 class Qualifiers: public Node{
63 /// Copy constructor disabled.
64 Qualifiers(const Qualifiers& p);
65 /// Assignment disabled.
66 Qualifiers& operator=(const Qualifiers& p);
67 private:
68 vector<Qualifier> qualifiers;
69 public:
70 Qualifiers() : Node() { }
71 ~Qualifiers();
72 size_t get_nof_qualifiers() const { return qualifiers.size(); }
73 void add_qualifier(Qualifier* p_qualifier);
74 void delete_qualifier(size_t p_index);
75 const Qualifier* get_qualifier(size_t p_index) const;
76 virtual Qualifiers* clone() const;
77 virtual void set_fullname(const string& p_fullname);
78 bool has_qualifier(Qualifier* p_qualifier)const;
79 void dump(unsigned level) const;
80 };
81
82 /**
83 * The errouneous attribute spec. string is parsed into this AST node
84 */
85 class ErroneousAttributeSpec : public Node, public Location
86 {
87 public:
88 enum indicator_t {
89 I_BEFORE,
90 I_VALUE,
91 I_AFTER,
92 I_INVALID
93 };
94 private:
95 ErroneousAttributeSpec(const ErroneousAttributeSpec& p);
96 /// Assignment disabled.
97 ErroneousAttributeSpec& operator=(const ErroneousAttributeSpec& p);
98 bool is_raw;
99 bool has_all_keyword;
100 indicator_t indicator;
101 TemplateInstance* tmpl_inst;
102 Type* type; // set by chk or NULL if tmpl_inst is invalid or omit
103 Value* value; // set by chk or NULL if tmpl_inst is invalid or omit
104 string first_genname; // used by generate_code_str()to avoid generating
105 // multiple C++ objects for the same TTCN-3 constant value,
106 // after the first object all are only references
107 public:
108 ErroneousAttributeSpec(bool p_is_raw, indicator_t p_indicator, TemplateInstance* p_tmpl_inst, bool p_has_all_keyword);
109 ~ErroneousAttributeSpec();
110 ErroneousAttributeSpec *clone() const;
111 void set_fullname(const string& p_fullname);
112 void set_my_scope(Scope *p_scope);
113 void dump(unsigned level) const;
114 /** basic check, the qualifier of the field is not known here */
115 void chk();
116 indicator_t get_indicator() const { return indicator; }
117 Type* get_type() const { return type; }
118 bool get_is_raw() const { return is_raw; }
119 bool get_is_omit() const;
120 static const char* get_indicator_str(indicator_t i);
121 char* generate_code_str(char *str, string genname);
122 char* generate_code_init_str(char *str, string genname);
123 string get_typedescriptor_str();
124 void chk_recursions(ReferenceChain& refch);
125 };
126
127 /**
128 * helper to construct the tree of erroneous attributes
129 */
130 struct ErroneousValues {
131 ErroneousAttributeSpec *before, *value, *after; // NULL if not specified
132 string field_name; // qualifier string
133 ErroneousValues(const string& p_field_name): before(0), value(0), after(0), field_name(p_field_name) {}
134 char* generate_code_embedded_str(char *str, string genname);
135 char* generate_code_init_str(char *str, string genname);
136 char* generate_code_embedded_str(char *str, string genname, ErroneousAttributeSpec* attr_spec);
137 char* generate_code_struct_str(char *str, string genname, int field_index);
138 void chk_recursions(ReferenceChain& refch);
139 };
140
141 /**
142 * helper to construct the tree of erroneous attributes
143 */
144 struct ErroneousDescriptor {
145 int omit_before, omit_after; // -1 if not set
146 string omit_before_name, omit_after_name; // qualifier string or empty
147 map<size_t,ErroneousDescriptor> descr_m; // descriptors for the fields
148 map<size_t,ErroneousValues> values_m; // erroneous values for the fields
149 ErroneousDescriptor(const ErroneousDescriptor& p); // disabled
150 ErroneousDescriptor& operator=(const ErroneousDescriptor& p); // disabled
151 public:
152 ErroneousDescriptor(): omit_before(-1), omit_after(-1) {}
153 ~ErroneousDescriptor();
154 char* generate_code_embedded_str(char *str, string genname);
155 char* generate_code_init_str(char *str, string genname);
156 char* generate_code_struct_str(char *str, string genname, int field_index);
157 char* generate_code_str(char *str, string genname);
158 void chk_recursions(ReferenceChain& refch);
159 };
160
161 /**
162 * Contains erroneous attr. specs and the pointers to the qualifiers
163 */
164 class ErroneousAttributes : public Node
165 {
166 public:
167 struct field_err_t {
168 const Qualifier* qualifier; // not owned
169 ErroneousAttributeSpec* err_attr; // not owned
170 dynamic_array<size_t> subrefs_array; // used in chk()
171 dynamic_array<Type*> type_array; // used in chk()
172 };
173 private:
174 Type* type; // not owned
175 vector<ErroneousAttributeSpec> spec_vec; // all elements owned
176 dynamic_array<field_err_t> field_array;
177 ErroneousDescriptor* err_descr_tree; // owned, constructed in chk()
178 ErroneousAttributes(const ErroneousAttributes& p);
179 /// Assignment disabled.
180 ErroneousAttributes& operator=(const ErroneousAttributes& p);
181 /** builds a tree of descriptors and err.values calling itself recursively, reports errors */
182 ErroneousDescriptor* build_descr_tree(dynamic_array<field_err_t>& fld_array);
183 public:
184 ErroneousAttributes(Type* p_type);
185 ~ErroneousAttributes();
186 ErroneousAttributes *clone() const;
187 void set_fullname(const string& p_fullname);
188 void dump(unsigned level) const;
189
190 void add_spec(ErroneousAttributeSpec* err_attr_spec);
191 void add_pair(const Qualifier* qualifier, ErroneousAttributeSpec* err_attr_spec);
192 /** check every field_err_t value */
193 void chk();
194 ErroneousDescriptor* get_err_descr() const { return err_descr_tree; }
195 };
196
197 /**
198 * Stores the attribute specification and its location
199 */
200 class AttributeSpec : public Node, public Location {
201 /// Assignment disabled, even though copy constructor isn't
202 AttributeSpec& operator=(const AttributeSpec& p);
203 private:
204 string spec; ///< The attribute specification (free text)
205 /// Copy constructor, for clone() only
206 AttributeSpec(const AttributeSpec& p)
207 : Node(p), Location(p), spec(p.spec) { }
208 public:
209 AttributeSpec(const string& p_spec)
210 : Node(), Location(), spec(p_spec) { }
211 virtual AttributeSpec* clone() const;
212 virtual void set_fullname(const string& p_fullname);
213 const string& get_spec() const { return spec; }
214 virtual void dump(unsigned level) const;
215 };
216
217 /**
218 * Stores a single attribute
219 */
220 class SingleWithAttrib : public Node, public Location {
221 /// Copy constructor disabled.
222 SingleWithAttrib(const SingleWithAttrib& p);
223 /// Assignment disabled.
224 SingleWithAttrib& operator=(const SingleWithAttrib& p);
225 public:
226 enum attribtype_t{
227 AT_ENCODE,
228 AT_VARIANT,
229 AT_DISPLAY,
230 AT_EXTENSION,
231 AT_OPTIONAL,
232 AT_ERRONEOUS,
233 AT_INVALID /// invalid keyword was used
234 };
235 private:
236 attribtype_t attribKeyword;
237 /// True if the \c override keyword was used
238 bool hasOverride;
239 /// The stuff in parenthesis before the attribute text. Owned.
240 Qualifiers *attribQualifiers;
241 /// The attribute text (FreeText). Owned.
242 AttributeSpec* attribSpec;
243
244 public:
245 SingleWithAttrib(attribtype_t p_attribKeyword, bool p_hasOverride,
246 Qualifiers *p_attribQualifiers, AttributeSpec *p_attribSpec);
247 ~SingleWithAttrib();
248 virtual SingleWithAttrib* clone() const;
249 virtual void set_fullname(const string& p_fullname);
250 attribtype_t get_attribKeyword() const{ return attribKeyword; }
251 bool has_override() const { return hasOverride; }
252 AttributeSpec const& get_attribSpec() const { return *attribSpec; }
253 Qualifiers *get_attribQualifiers() const { return attribQualifiers; }
254 virtual void dump(unsigned level) const;
255 };
256
257 /**
258 * Stores all the attributes found in one \c with statement
259 */
260 class MultiWithAttrib: public Node, public Location{
261 /// Copy constructor disabled.
262 MultiWithAttrib(const MultiWithAttrib& p);
263 /// Assignment disabled.
264 MultiWithAttrib& operator=(const MultiWithAttrib& p);
265 private:
266 vector<SingleWithAttrib> elements;
267 public:
268 MultiWithAttrib() : Node(), Location() { }
269 ~MultiWithAttrib();
270 virtual MultiWithAttrib* clone() const;
271 virtual void set_fullname(const string& p_fullname);
272 size_t get_nof_elements() const{ return elements.size();}
273 void add_element(SingleWithAttrib* p_single){ elements.add(p_single);}
274 void add_element_front(SingleWithAttrib* p_single)
275 { elements.add_front(p_single);}
276 const SingleWithAttrib* get_element(size_t p_index) const;
277 SingleWithAttrib* get_element_for_modification(size_t p_index);
278 void delete_element(size_t p_index);
279 virtual void dump(unsigned level) const;
280 };
281
282 /**
283 * With this class we create a path from the actual type to the module
284 * including all groups.
285 *
286 * Known owners:
287 * - Ttcn::Group
288 * - Ttcn::ControlPart
289 * - Ttcn::Module
290 * - Ttcn::FriendMod
291 * - Ttcn::ImpMod
292 * - Ttcn::Definition
293 * - Common::Type
294 */
295 class WithAttribPath : public Node {
296 /// Copy constructor disabled.
297 WithAttribPath(const WithAttribPath& p);
298 /// Assignment disabled.
299 WithAttribPath& operator=(const WithAttribPath& p);
300 private:
301 bool had_global_variants;
302 bool attributes_checked;
303 bool cached;
304 bool s_o_encode;
305 WithAttribPath* parent;
306 MultiWithAttrib* m_w_attrib;
307 vector<SingleWithAttrib> cache;
308
309 void qualifierless_attrib_finder(vector<SingleWithAttrib>& p_result,
310 bool& stepped_over_encode);
311 public:
312 WithAttribPath() : Node(), had_global_variants(false),
313 attributes_checked(false), cached(false), s_o_encode(false),
314 parent(0), m_w_attrib(0) { }
315 ~WithAttribPath();
316 virtual WithAttribPath* clone() const;
317 virtual void set_fullname(const string& p_fullname);
318 void set_had_global_variants(bool has) { had_global_variants = has; }
319 bool get_had_global_variants() { return had_global_variants; }
320 void chk_no_qualif();
321 void chk_global_attrib(bool erroneous_allowed=false);
322 void set_parent(WithAttribPath* p_parent) { parent = p_parent; }
323 WithAttribPath* get_parent() { return parent; }
324 /** Set the contained attribute.
325 *
326 * @param p_m_w_attr
327 * @pre \c add_with_attr has not been called before with a non-NULL arg
328 * @post \c attributes_checked is \c false
329 */
330 void set_with_attr(MultiWithAttrib* p_m_w_attr);
331 MultiWithAttrib* get_with_attr() { return m_w_attrib;}
332 /** Fills the cache and returns it.
333 *
334 * @return a reference to the cached list of qualifier-less attributes.
335 */
336 const vector<SingleWithAttrib>& get_real_attrib();
337 const MultiWithAttrib* get_local_attrib() const { return m_w_attrib; }
338 bool has_attribs();
339 virtual void dump(unsigned int level) const;
340 };
341}
342
343#endif
This page took 0.036698 seconds and 5 git commands to generate.