Commit | Line | Data |
---|---|---|
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 | * > | |
10 | * Balasko, Jeno | |
11 | * Beres, Szabolcs | |
12 | * Godar, Marton | |
13 | * Raduly, Csaba | |
14 | * Szabo, Bence Janos | |
15 | * | |
16 | ******************************************************************************/ | |
970ed795 EL |
17 | #ifndef SIMPLETYPE_H_ |
18 | #define SIMPLETYPE_H_ | |
19 | ||
20 | #include "RootType.hh" | |
21 | ||
22 | class SimpleType; | |
23 | ||
3abe9331 | 24 | class LengthType { |
25 | LengthType & operator=(const LengthType &); // not implemented | |
970ed795 EL |
26 | // it's a bit strange that it has copy constructor but no assignment |
27 | public: | |
28 | SimpleType * parent; // no responsibility for this member | |
29 | bool modified; | |
30 | unsigned long long int facet_minLength; | |
31 | unsigned long long int facet_maxLength; | |
32 | unsigned long long int lower; | |
33 | unsigned long long int upper; | |
34 | ||
3abe9331 | 35 | LengthType(SimpleType * p_parent); |
970ed795 EL |
36 | // Default copy constructor and destructor are used |
37 | ||
3abe9331 | 38 | void applyReference(const LengthType & other); |
39 | void applyFacets(); | |
40 | void printToFile(FILE * file) const; | |
970ed795 EL |
41 | }; |
42 | ||
3abe9331 | 43 | class PatternType { |
44 | PatternType & operator=(const PatternType &); // not implemented | |
970ed795 EL |
45 | // it's a bit strange that it has copy constructor but no assignment |
46 | public: | |
47 | SimpleType * parent; // no responsibility for this member | |
48 | bool modified; | |
49 | Mstring facet; | |
50 | Mstring value; | |
51 | ||
3abe9331 | 52 | PatternType(SimpleType * p_parent); |
970ed795 EL |
53 | // Default copy constructor and destructor are used |
54 | ||
3abe9331 | 55 | void applyReference(const PatternType & other); |
56 | void applyFacet(); | |
57 | void printToFile(FILE * file) const; | |
970ed795 EL |
58 | }; |
59 | ||
3abe9331 | 60 | class EnumerationType { |
61 | EnumerationType & operator=(const EnumerationType &); // not implemented | |
970ed795 EL |
62 | // it's a bit strange that it has copy constructor but no assignment |
63 | public: | |
64 | SimpleType * parent; // no responsibility for this member | |
65 | bool modified; | |
66 | List<Mstring> facets; | |
67 | List<QualifiedName> items_string; | |
68 | List<int> items_int; | |
69 | List<double> items_float; | |
70 | List<QualifiedName> items_time; | |
71 | List<Mstring> items_misc; | |
3abe9331 | 72 | List<Mstring> variants; |
970ed795 | 73 | |
3abe9331 | 74 | EnumerationType(SimpleType * p_parent); |
970ed795 EL |
75 | // Default copy constructor and destructor are used |
76 | ||
3abe9331 | 77 | void applyReference(const EnumerationType & other); |
78 | void applyFacets(); | |
79 | void sortFacets(); | |
80 | void printToFile(FILE * file, unsigned int indent_level = 0) const; | |
81 | void insertVariants(); | |
970ed795 EL |
82 | }; |
83 | ||
3abe9331 | 84 | class WhitespaceType { |
85 | WhitespaceType & operator=(const WhitespaceType &); // not implemented | |
970ed795 EL |
86 | // it's a bit strange that it has copy constructor but no assignment |
87 | public: | |
88 | SimpleType * p_parent; // no responsibility for this member | |
89 | bool modified; | |
90 | Mstring facet; | |
91 | Mstring value; | |
92 | ||
3abe9331 | 93 | WhitespaceType(SimpleType * p_parent); |
970ed795 EL |
94 | // Default copy constructor and destructor are used |
95 | ||
3abe9331 | 96 | void applyReference(const WhitespaceType & other); |
97 | void applyFacet(); | |
98 | void printToFile(FILE * file) const; | |
970ed795 EL |
99 | }; |
100 | ||
3abe9331 | 101 | class ValueType { |
102 | ValueType & operator=(const ValueType &); // not implemented | |
970ed795 EL |
103 | // it's a bit strange that it has copy constructor but no assignment |
104 | public: | |
105 | SimpleType * parent; // no responsibility for this member | |
106 | bool modified; | |
107 | long double facet_minInclusive; | |
108 | long double facet_maxInclusive; | |
109 | long double facet_minExclusive; | |
110 | long double facet_maxExclusive; | |
111 | int facet_totalDigits; | |
112 | long double lower; | |
113 | long double upper; | |
114 | bool lowerExclusive; | |
115 | bool upperExclusive; | |
3abe9331 | 116 | bool not_a_number; |
970ed795 EL |
117 | Mstring fixed_value; |
118 | Mstring default_value; | |
119 | List<Mstring> items_with_value; | |
120 | ||
3abe9331 | 121 | ValueType(SimpleType * p_parent); |
970ed795 EL |
122 | // Default copy constructor and destructor are used |
123 | ||
3abe9331 | 124 | void applyReference(const ValueType & other); |
125 | void applyFacets(); | |
126 | void printToFile(FILE * file) const; | |
970ed795 EL |
127 | }; |
128 | ||
129 | class ComplexType; | |
130 | ||
131 | class ReferenceData { | |
132 | public: // interface | |
3abe9331 | 133 | |
970ed795 EL |
134 | ReferenceData() |
135 | : nst(0) | |
136 | , uri() | |
137 | , value() | |
138 | , resolved(false) | |
3abe9331 | 139 | , ref(NULL) { |
140 | } | |
970ed795 | 141 | |
3abe9331 | 142 | void load(const Mstring& u, const Mstring& v, NamespaceType *n) { |
970ed795 EL |
143 | uri = u; |
144 | value = v; | |
145 | nst = n; | |
146 | } | |
147 | ||
3abe9331 | 148 | const Mstring& get_uri() const { |
149 | return uri; | |
150 | } | |
151 | ||
152 | const Mstring& get_val() const { | |
153 | return value; | |
154 | } | |
155 | ||
156 | RootType *get_ref() const { | |
157 | return ref; | |
158 | } | |
970ed795 EL |
159 | |
160 | bool empty() const { | |
161 | return uri.empty() && value.empty(); | |
162 | } | |
163 | ||
3abe9331 | 164 | bool is_resolved() const { |
165 | return resolved; | |
166 | } | |
970ed795 | 167 | |
3abe9331 | 168 | void set_resolved(RootType *st /*= NULL*/) { |
169 | resolved = true; | |
170 | ref = st; | |
171 | } | |
172 | ||
173 | Mstring repr() const { | |
174 | return uri + Mstring("|") + value; | |
175 | } | |
970ed795 | 176 | private: // implementation |
3abe9331 | 177 | NamespaceType *nst; |
178 | Mstring uri; | |
179 | Mstring value; | |
180 | bool resolved; | |
181 | RootType *ref; // not owned | |
970ed795 EL |
182 | }; |
183 | ||
184 | /** | |
185 | * Type that contains information coming from XSD simpleTypes, elements and attributes | |
186 | * | |
187 | * Source in XSD: | |
188 | * | |
189 | * * <simpleType>, <element> and <attribute> element whose parent element is <schema> | |
190 | * | |
191 | * Result in TTCN-3: | |
192 | * | |
193 | * * TTCN-3 type | |
194 | * | |
195 | */ | |
3abe9331 | 196 | class SimpleType : public RootType { |
970ed795 | 197 | public: |
3abe9331 | 198 | |
199 | enum Mode { | |
970ed795 EL |
200 | noMode, |
201 | restrictionMode, | |
202 | extensionMode, | |
203 | listMode | |
204 | }; | |
205 | ||
206 | protected: | |
207 | Mstring builtInBase; | |
208 | ||
209 | LengthType length; | |
210 | PatternType pattern; | |
211 | EnumerationType enumeration; | |
212 | WhitespaceType whitespace; | |
213 | ValueType value; | |
214 | ||
215 | FormValue element_form_as; | |
216 | FormValue attribute_form_as; | |
217 | ||
218 | Mode mode; | |
219 | ||
220 | ReferenceData outside_reference; | |
221 | ||
222 | /// true if name_dependency would be set (not empty) | |
223 | bool in_name_only; | |
224 | ||
3abe9331 | 225 | // True if element or attribute used with ref attribute |
226 | bool fromRef; | |
227 | // XSD Type of the type | |
228 | TagName xsdtype; | |
229 | bool isOptional; | |
51fa56b9 | 230 | Mstring substitutionGroup; |
231 | //Pointer to the generated element substitution group | |
3abe9331 | 232 | ComplexType * subsGroup; |
51fa56b9 | 233 | //Pointer to the generated type substitution group |
234 | ComplexType * typeSubsGroup; | |
235 | //To determine if already added to type substitution | |
236 | bool addedToTypeSubstitution; | |
3abe9331 | 237 | BlockValue block; |
51fa56b9 | 238 | |
239 | //Element substitution | |
240 | void addToSubstitutions(); | |
3abe9331 | 241 | |
51fa56b9 | 242 | //Type substitution |
243 | void addToTypeSubstitutions(); | |
244 | //Returns the type substitution which the builtInType belongs | |
245 | ComplexType * findBuiltInTypeInStoredTypeSubstitutions(const Mstring& builtInType); | |
970ed795 | 246 | |
51fa56b9 | 247 | //Only used when type substitution is enabled |
248 | //If an element reference is found then it is put to a container | |
249 | //to know if type substitution is possible | |
250 | void collectElementTypes(SimpleType * found_ST = NULL, ComplexType * found_CT = NULL); | |
3abe9331 | 251 | void nameConversion_names(); |
252 | virtual void nameConversion_types(const List<NamespaceType> & ns); | |
970ed795 | 253 | |
3abe9331 | 254 | SimpleType & operator=(const SimpleType &); // not implemented |
970ed795 EL |
255 | // it's a bit strange that it has copy constructor but no assignment |
256 | public: | |
3abe9331 | 257 | SimpleType(XMLParser * a_parser, TTCN3Module * a_module, ConstructType a_construct); |
970ed795 EL |
258 | SimpleType(const SimpleType& other); |
259 | // Default destructor is used | |
260 | ||
3abe9331 | 261 | // Parent of the element (both complexType, and AttributeType) has this |
262 | // Not responsible for this member | |
263 | ComplexType * parent; | |
264 | ||
970ed795 EL |
265 | /** Virtual methods |
266 | * inherited from RootType | |
267 | */ | |
3abe9331 | 268 | void loadWithValues(); |
269 | void printToFile(FILE * file); | |
270 | void referenceResolving(); | |
271 | void nameConversion(const NameConversionMode mode, const List<NamespaceType> & ns); | |
272 | void finalModification(); | |
273 | virtual bool hasUnresolvedReference(); | |
274 | void dump(const unsigned int depth) const; | |
275 | ||
276 | void applyDefaultAttribute(const Mstring& default_value); | |
277 | void applyFixedAttribute(const Mstring& fixed_value); | |
278 | void applyNillableAttribute(const bool nillable_value); | |
279 | void applyAbstractAttribute(const bool abstract_value); | |
280 | void applySubstitionGroupAttribute(const Mstring& substition_group); | |
281 | void applyBlockAttribute(const BlockValue block_); | |
282 | void applyRefAttribute(const Mstring& ref_value); | |
283 | ||
284 | const Mstring & getBuiltInBase() const { | |
285 | return builtInBase; | |
286 | } | |
287 | ||
288 | const LengthType & getLength() const { | |
289 | return length; | |
290 | } | |
291 | ||
292 | const ValueType & getValue() const { | |
293 | return value; | |
294 | } | |
295 | ||
296 | const PatternType & getPattern() const { | |
297 | return pattern; | |
298 | } | |
299 | ||
300 | const WhitespaceType & getWhitespace() const { | |
301 | return whitespace; | |
302 | } | |
303 | ||
304 | const EnumerationType & getEnumeration() const { | |
305 | return enumeration; | |
306 | } | |
307 | ||
308 | FormValue getElementFormAs() const { | |
309 | return element_form_as; | |
310 | } | |
311 | ||
312 | FormValue getAttributeFormAs() const { | |
313 | return attribute_form_as; | |
314 | } | |
315 | ||
316 | Mode getMode() const { | |
317 | return mode; | |
318 | } | |
319 | ||
320 | bool isFromRef() const { | |
321 | return fromRef; | |
322 | } | |
323 | ||
324 | const ReferenceData& getReference() const { | |
325 | return outside_reference; | |
326 | } | |
327 | ||
328 | EnumerationType & getEnumeration() { | |
329 | return enumeration; | |
330 | } | |
331 | ||
332 | void setBuiltInBase(const Mstring& base) { | |
333 | builtInBase = base; | |
334 | } | |
335 | ||
336 | void setMode(Mode m) { | |
337 | mode = m; | |
338 | } | |
339 | ||
340 | void setElementFormAs(FormValue f) { | |
341 | element_form_as = f; | |
342 | } | |
343 | ||
344 | void setAttributeFormAs(FormValue f) { | |
345 | attribute_form_as = f; | |
346 | } | |
347 | ||
348 | void setReference(const Mstring& ref, bool only_name_dependency = false); | |
349 | ||
350 | void referenceForST(SimpleType * found_ST); | |
351 | void referenceForCT(ComplexType * found_CT); | |
352 | ||
353 | void setXsdtype(TagName xsdtype_) { | |
354 | xsdtype = xsdtype_; | |
355 | } | |
356 | ||
357 | TagName getXsdtype() const { | |
358 | return xsdtype; | |
359 | } | |
360 | ||
361 | ComplexType * getSubstitution() const { | |
362 | return subsGroup; | |
363 | } | |
364 | ||
51fa56b9 | 365 | ComplexType * getTypeSubstitution() const { |
366 | return typeSubsGroup; | |
367 | } | |
368 | ||
3abe9331 | 369 | BlockValue getBlock() const { |
370 | return block; | |
371 | } | |
372 | ||
373 | void addToNameDepList(SimpleType * t) { | |
51fa56b9 | 374 | //If the type has a substitution, we add the namedep to the substitution |
3abe9331 | 375 | if(subsGroup != NULL && this != (SimpleType*)subsGroup){ |
376 | SimpleType * substitution = (SimpleType*)subsGroup; | |
377 | substitution->addToNameDepList(t); | |
51fa56b9 | 378 | }else if(typeSubsGroup != NULL && this != (SimpleType*)typeSubsGroup){ |
379 | SimpleType * substitution = (SimpleType*)typeSubsGroup; | |
380 | substitution->addToNameDepList(t); | |
3abe9331 | 381 | }else { |
382 | nameDepList.push_back(t); | |
383 | } | |
384 | } | |
385 | ||
970ed795 EL |
386 | }; |
387 | ||
388 | #endif /* SIMPLETYPE_H_ */ |