1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 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 ///////////////////////////////////////////////////////////////////////////////
10 #include "TTCN3Module.hh"
12 RootType::RootType(XMLParser
* a_parser
, TTCN3Module
* a_module
, ConstructType a_construct
)
23 , construct(a_construct
)
24 , origin(from_unknown
)
34 //redundant: origin = from_unknown;
36 case c_unknown
: // because when using fields in complextypes we set construct to c_unknown
38 origin
= from_simpleType
;
39 type
.upload(Mstring("anySimpleType"));
42 origin
= from_element
;
43 type
.upload(Mstring("anyType"));
44 addVariant(V_element
);
47 origin
= from_attribute
;
48 type
.upload(Mstring("anySimpleType"));
49 addVariant(V_attribute
);
52 origin
= from_complexType
;
53 type
.upload(Mstring("record"));
57 type
.upload(Mstring("record"));
58 addVariant(V_untagged
);
60 case c_attributeGroup
:
61 origin
= from_attributeGroup
;
62 type
.upload(Mstring("record"));
63 addVariant(V_attributeGroup
);
69 void RootType::addVariant(VariantMode var
, const Mstring
& var_value
, bool into_variant_ref
)
71 Mstring variantstring
;
76 variantstring
= "\"anyAttributes" + var_value
+ "\"";
79 variantstring
= "\"anyElement" + var_value
+ "\"";
82 variantstring
= "\"attribute\"";
84 case V_attributeFormQualified
:
85 variantstring
= "\"attributeFormQualified\"";
87 case V_attributeGroup
:
88 variantstring
= "\"attributeGroup\"";
90 case V_controlNamespace
:
91 variantstring
= "\"controlNamespace" + var_value
+ "\"";
93 case V_defaultForEmpty
:
94 variantstring
= "\"defaultForEmpty as \'" + var_value
+ "\'\""; // chapter 7.1.5
97 variantstring
= "\"element\"";
99 case V_elementFormQualified
:
100 variantstring
= "\"elementFormQualified\"";
103 variantstring
= "\"embedValues\"";
106 variantstring
= "\"form as " + var_value
+ "\"";
109 variantstring
= "\"list\"";
112 variantstring
= "\"name as \'" + var_value
+ "\'\"";
114 case V_namespaceAs
: {
117 for (List
<NamespaceType
>::iterator namesp
= module
->getDeclaredNamespaces().begin(); namesp
; namesp
= namesp
->Next
) {
118 if (namesp
->Data
.uri
== var_value
) {
119 prefix
= namesp
->Data
.prefix
;
120 uri
= namesp
->Data
.uri
;
124 if (prefix
.empty() || uri
.empty()) {
127 variantstring
= "\"namespace as \'" + uri
+ "\' prefix \'" + prefix
+ "\'\"";
130 variantstring
= var_value
;
133 variantstring
= "\"untagged\"";
136 variantstring
= "\"useNil\"";
139 variantstring
= "\"useNumber\"";
142 variantstring
= "\"useOrder\"";
145 variantstring
= "\"useUnion\"";
148 variantstring
= "\"whiteSpace " + var_value
+ "\"";
152 if (!variantstring
.empty()) {
153 variant
.push_back(variantstring
);
154 if (into_variant_ref
) {
155 variant_ref
.push_back(variantstring
);
160 void RootType::printVariant(FILE * file
)
162 if (!e_flag_used
&& !variant
.empty())
164 fprintf(file
, "\nwith {\n");
165 for (List
<Mstring
>::iterator var
= variant
.end(); var
; var
= var
->Prev
)
167 fprintf(file
, "variant %s;\n", var
->Data
.c_str());
173 void RootType::addComment(const Mstring
& text
)
175 comment
+= "/* " + text
+ " */\n";
178 void RootType::printComment(FILE * file
)
182 fprintf(file
, "%s", comment
.c_str());
186 void RootType::printMinOccursMaxOccurs(FILE * file
, bool inside_union
,
187 bool empty_allowed
/* = true */) const
189 unsigned long long tmp_minOccurs
= minOccurs
;
190 if (minOccurs
== 0 && !empty_allowed
) tmp_minOccurs
= 1ULL;
194 if (minOccurs
== 0) {
195 if (inside_union
|| name
.list_extension
) {
196 fputs("record length(", file
);
197 if (empty_allowed
) fputs("0 .. ", file
);
198 // else: length(1..1) is shortened to length(1)
199 fputs("1) of ", file
);
201 // else it's optional which is not printed from here
203 else if (minOccurs
== 1) {
204 // min==max==1; do nothing unless...
205 if (name
.convertedValue
== "embed_values") fputs("record length(1) of ", file
);
208 else if (maxOccurs
== ULLONG_MAX
) {
209 if (minOccurs
== 0) {
210 fputs("record ", file
);
211 if (!empty_allowed
) fputs("length(1 .. infinity) ", file
);
214 else fprintf(file
, "record length(%llu .. infinity) of ", tmp_minOccurs
);
218 fprintf(file
, "record length(%llu .. %llu) of ", tmp_minOccurs
, maxOccurs
);