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