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
16 ******************************************************************************/
17 #include "ComplexType.hh"
19 #include "GeneralFunctions.hh"
20 #include "XMLParser.hh"
21 #include "TTCN3Module.hh"
22 #include "TTCN3ModuleInventory.hh"
23 #include "Annotation.hh"
27 ComplexType::ComplexType(XMLParser
* a_parser
, TTCN3Module
* a_module
, ConstructType a_construct
)
28 : SimpleType(a_parser
, a_module
, a_construct
)
40 , actualPath(empty_string
)
43 , nillable_field(NULL
)
45 , cmode(CT_undefined_mode
)
47 , parentTypeSubsGroup(NULL
)
52 xsdtype
= n_complexType
;
55 ComplexType::ComplexType(ComplexType
& other
)
58 , nillable(other
.nillable
)
59 , enumerated(other
.enumerated
)
61 , with_union(other
.with_union
)
62 , first_child(other
.first_child
)
63 , fromAll(other
.fromAll
)
64 , max_alt(other
.max_alt
)
65 , skipback(other
.skipback
)
67 , lastType(other
.lastType
)
68 , actualPath(other
.actualPath
)
70 , nameDep(other
.nameDep
)
71 , nillable_field(NULL
)
74 , resolved(other
.resolved
)
75 , parentTypeSubsGroup(other
.parentTypeSubsGroup
) {
76 type
.originalValueWoPrefix
= other
.type
.originalValueWoPrefix
;
77 for (List
<AttributeType
*>::iterator attr
= other
.attribfields
.begin(); attr
; attr
= attr
->Next
) {
78 attribfields
.push_back(new AttributeType(*attr
->Data
));
79 attribfields
.back()->parent
= this;
82 for (List
<ComplexType
*>::iterator field
= other
.complexfields
.begin(); field
; field
= field
->Next
) {
83 complexfields
.push_back(new ComplexType(*field
->Data
));
84 complexfields
.back()->parent
= this;
85 if(field
->Data
== other
.basefield
){
86 basefield
= complexfields
.back();
87 }else if(field
->Data
== other
.nillable_field
){
88 nillable_field
= complexfields
.back();
92 if (other
.nameDep
!= NULL
) {
93 SimpleType
* dep
= other
.nameDep
;
94 if(dep
->getSubstitution() != NULL
){
95 dep
->getSubstitution()->addToNameDepList(this);
96 nameDep
= dep
->getSubstitution();
98 other
.nameDep
->addToNameDepList(this);
103 ComplexType::ComplexType(ComplexType
* other
)
104 : SimpleType(other
->getParser(), other
->getModule(), c_unknown
)
116 , actualPath(empty_string
)
119 , nillable_field(NULL
)
121 , cmode(CT_undefined_mode
)
123 , parentTypeSubsGroup(NULL
)
128 xsdtype
= n_complexType
;
130 outside_reference
= ReferenceData();
133 ComplexType::ComplexType(const SimpleType
& other
, CT_fromST c
)
146 , actualPath(empty_string
)
149 , nillable_field(NULL
)
151 , cmode(CT_simpletype_mode
)
153 , parentTypeSubsGroup(NULL
)
159 if(c
!= fromTagSubstitution
&& c
!= fromTypeSubstitution
){
160 module
->replaceLastMainType(this);
161 module
->setActualXsdConstruct(c_complexType
);
163 construct
= c_complexType
;
167 type
.upload(Mstring("union"));
171 case fromTagNillable
:
172 addVariant(V_useNil
);
173 type
.upload(Mstring("record"));
175 case fromTagComplexType
:
176 type
.upload(Mstring("record"));
177 xsdtype
= n_complexType
;
179 case fromTagSubstitution
:
180 type
.upload(Mstring("union"));
181 name
.upload(getName().originalValueWoPrefix
+ Mstring("_group"));
185 hidden_variant
.clear();
186 enumeration
.modified
= false;
187 value
.modified
= false;
188 pattern
.modified
= false;
189 length
.modified
= false;
190 whitespace
.modified
= false;
192 case fromTypeSubstitution
:
193 type
.upload(Mstring("union"));
194 name
.upload(getName().originalValueWoPrefix
+ Mstring("_derivations"));
196 substitutionGroup
= empty_string
;
197 typeSubsGroup
= this;
199 hidden_variant
.clear();
200 enumeration
.modified
= false;
201 value
.modified
= false;
202 pattern
.modified
= false;
203 length
.modified
= false;
204 whitespace
.modified
= false;
208 ComplexType::~ComplexType() {
209 for (List
<ComplexType
*>::iterator field
= complexfields
.begin(); field
; field
= field
->Next
) {
213 complexfields
.clear();
215 for (List
<AttributeType
*>::iterator field
= attribfields
.begin(); field
; field
= field
->Next
) {
219 attribfields
.clear();
222 void ComplexType::loadWithValues() {
223 //Find the last field where the tag is found
224 if (this != actfield
) {
225 actfield
->loadWithValues();
229 const XMLParser::TagAttributes
& atts
= parser
->getActualTagAttributes();
231 switch (parser
->getActualTagName()) {
233 if (!top
&& xsdtype
!= n_sequence
&& xsdtype
!= n_complexType
&& xsdtype
!= n_extension
&& xsdtype
!= n_restriction
&& xsdtype
!= n_element
) {
235 ComplexType
* rec
= new ComplexType(this);
236 rec
->type
.upload(Mstring("record"));
237 rec
->name
.upload(Mstring("sequence"));
238 rec
->addVariant(V_untagged
);
239 rec
->setMinMaxOccurs(atts
.minOccurs
, atts
.maxOccurs
);
240 rec
->setXsdtype(n_sequence
);
241 complexfields
.push_back(rec
);
244 //Do not create new record, it is an embedded sequence
245 if (xsdtype
== n_sequence
&& atts
.minOccurs
== 1 && atts
.maxOccurs
== 1) {
248 type
.upload(Mstring("record"));
249 xsdtype
= n_sequence
;
250 setMinMaxOccurs(atts
.minOccurs
, atts
.maxOccurs
);
254 if (!top
|| xsdtype
!= n_group
) {
255 //Create new union field
256 ComplexType
* choice
= new ComplexType(this);
257 choice
->type
.upload(Mstring("union"));
258 choice
->name
.upload(Mstring("choice"));
259 choice
->setXsdtype(n_choice
);
260 choice
->addVariant(V_untagged
);
261 choice
->setMinMaxOccurs(atts
.minOccurs
, atts
.maxOccurs
);
263 complexfields
.push_back(choice
);
266 type
.upload(Mstring("union"));
271 //Create the record of enumerated field
273 ComplexType
* enumField
= new ComplexType(this);
274 enumField
->setTypeValue(Mstring("enumerated"));
275 enumField
->setNameValue(Mstring("order"));
276 enumField
->setBuiltInBase(Mstring("string"));
277 enumField
->enumerated
= true;
278 enumField
->setMinMaxOccurs(0, ULLONG_MAX
, false);
279 setMinMaxOccurs(atts
.minOccurs
, atts
.maxOccurs
);
280 addVariant(V_useOrder
);
281 complexfields
.push_back(enumField
);
282 if (atts
.minOccurs
== 0) {
288 mode
= restrictionMode
;
289 //If it is an xsd:union then call SimpleType::loadWithValues
290 if (parent
!= NULL
&& parent
->with_union
) {
291 SimpleType::loadWithValues();
294 if (cmode
== CT_simpletype_mode
) {
295 //if it is from a SimpleType, then create a base field
296 ComplexType
* f
= new ComplexType(this);
297 f
->name
.upload(Mstring("base"));
298 f
->type
.upload(atts
.base
);
299 f
->setReference(atts
.base
);
300 f
->addVariant(V_untagged
);
301 complexfields
.push_back(f
);
304 } else if (cmode
== CT_complextype_mode
) {
305 setReference(atts
.base
);
306 xsdtype
= n_restriction
;
310 mode
= extensionMode
;
311 if (cmode
== CT_simpletype_mode
) {
312 //if it is from a SimpleType, then create a base field
313 ComplexType
* f
= new ComplexType(this);
314 f
->name
.upload(Mstring("base"));
315 f
->type
.upload(atts
.base
);
316 f
->setReference(atts
.base
);
317 f
->addVariant(V_untagged
);
318 complexfields
.push_back(f
);
321 } else if (cmode
== CT_complextype_mode
) {
322 setReference(atts
.base
);
323 xsdtype
= n_extension
;
329 if(cmode
== CT_simpletype_mode
){
330 //If a simple top level element is nillable
331 ComplexType
* nilrec
= new ComplexType(this);
332 if (atts
.type
.empty()) {
333 nilrec
->type
.upload(Mstring("record"));
335 nilrec
->type
.upload(atts
.type
);
337 nilrec
->name
.upload(Mstring("content"));
338 nilrec
->isOptional
= true;
339 nilrec
->nillable
= true;
340 setMinMaxOccurs(atts
.minOccurs
, atts
.maxOccurs
);
341 complexfields
.push_back(nilrec
);
342 type
.upload(Mstring("record"));
343 name
.upload(atts
.name
);
345 nillable_field
= nilrec
;
347 //From a complexType element is nillable
348 ComplexType
* record
= new ComplexType(this);
349 ComplexType
* nilrec
= new ComplexType(record
);
350 if (atts
.type
.empty()) {
351 nilrec
->type
.upload(Mstring("record"));
353 nilrec
->type
.upload(atts
.type
);
355 record
->name
.upload(atts
.name
);
356 record
->type
.upload(Mstring("record"));
357 record
->complexfields
.push_back(nilrec
);
358 record
->addVariant(V_useNil
);
359 record
->nillable_field
= nilrec
;
360 record
->setMinMaxOccurs(atts
.minOccurs
, atts
.maxOccurs
);
362 nilrec
->name
.upload(Mstring("content"));
363 nilrec
->nillable
= true;
364 nilrec
->isOptional
= true;
365 nilrec
->tagNames
.push_back(parser
->getActualTagName());
366 complexfields
.push_back(record
);
370 //It is a simple element
371 ComplexType
* c
= new ComplexType(this);
372 c
->setXsdtype(n_element
);
373 c
->type
.upload(atts
.type
);
374 c
->name
.upload(atts
.name
);
375 c
->setReference(atts
.type
);
376 c
->setMinMaxOccurs(atts
.minOccurs
, atts
.maxOccurs
);
377 c
->applyDefaultAttribute(atts
.default_
);
378 c
->applyFixedAttribute(atts
.fixed
);
379 c
->setElementFormAs(atts
.form
);
380 if (atts
.ref
.empty()) {
381 c
->setReference(atts
.type
);
383 c
->applyRefAttribute(atts
.ref
);
384 c
->name
.upload(atts
.ref
.getValueWithoutPrefix(':'));
385 c
->type
.upload(atts
.ref
);
387 c
->applySubstitionGroupAttribute(atts
.substitionGroup
);
388 c
->applyBlockAttribute(atts
.block
);
391 //Inside all have some special conditions
392 if (xsdtype
== n_all
) {
393 if (atts
.minOccurs
> 1) {
394 printError(getModule()->getSchemaname(), name
.convertedValue
,
395 Mstring("Inside <all>, minOccurs must be 0 or 1"));
396 TTCN3ModuleInventory::incrNumErrors();
398 if (atts
.maxOccurs
!= 1) {
399 printError(getModule()->getSchemaname(), name
.convertedValue
,
400 Mstring("Inside <all>, maxOccurs must be 1"));
401 TTCN3ModuleInventory::incrNumErrors();
404 complexfields
.push_back(c
);
406 c
->isOptional
= true;
409 complexfields
.push_back(c
);
416 AttributeType
* attribute
= new AttributeType(this);
417 attribute
->addVariant(V_attribute
);
418 attribute
->applyMinMaxOccursAttribute(0, 1);
419 attribute
->setXsdtype(n_attribute
);
420 attribute
->applyDefaultAttribute(atts
.default_
);
421 attribute
->applyFixedAttribute(atts
.fixed
);
422 attribute
->setUseVal(atts
.use
);
423 attribute
->setAttributeFormAs(atts
.form
);
424 lastType
= n_attribute
;
425 if (atts
.ref
.empty()) {
426 attribute
->setNameOfField(atts
.name
);
427 attribute
->setTypeOfField(atts
.type
);
428 attribute
->setReference(atts
.type
, true);
430 attribute
->applyRefAttribute(atts
.ref
);
432 actfield
= attribute
;
434 //In case of nillable parent it is difficult...
435 if (nillable
&& parent
!= NULL
) {
436 parent
->attribfields
.push_back(attribute
);
437 attribute
->parent
= parent
;
438 } else if (nillable
&& !complexfields
.empty() && parent
== NULL
) {
439 complexfields
.back()->attribfields
.push_back(attribute
);
440 } else if (parent
!= NULL
&& (parent
->mode
== extensionMode
|| parent
->mode
== restrictionMode
) && name
.convertedValue
== Mstring("base")) {
441 parent
->attribfields
.push_back(attribute
);
442 attribute
->parent
= parent
;
444 attribfields
.push_back(attribute
);
450 ComplexType
* any
= new ComplexType(this);
451 any
->name
.upload(Mstring("elem"));
452 any
->type
.upload(Mstring("xsd:string"));
453 any
->applyNamespaceAttribute(V_anyElement
, atts
.namespace_
);
454 any
->setMinMaxOccurs(atts
.minOccurs
, atts
.maxOccurs
);
455 any
->setXsdtype(n_any
);
456 complexfields
.push_back(any
);
461 AttributeType
* anyattr
= new AttributeType(this);
462 anyattr
->setXsdtype(n_anyAttribute
);
463 anyattr
->setNameOfField(Mstring("attr"));
464 anyattr
->setTypeValue(Mstring("xsd:string"));
465 anyattr
->setToAnyAttribute();
466 anyattr
->applyMinMaxOccursAttribute(0, ULLONG_MAX
);
467 anyattr
->addNameSpaceAttribute(atts
.namespace_
);
470 //In case of nillable parent it is difficult...
471 if (nillable
&& parent
!= NULL
) {
472 parent
->attribfields
.push_back(anyattr
);
473 anyattr
->parent
= parent
;
474 } else if (nillable
&& !complexfields
.empty() && parent
== NULL
) {
475 complexfields
.back()->attribfields
.push_back(anyattr
);
476 } else if (parent
!= NULL
&& (parent
->mode
== extensionMode
|| parent
->mode
== restrictionMode
) && name
.convertedValue
== Mstring("base")) {
477 parent
->attribfields
.push_back(anyattr
);
478 anyattr
->parent
= parent
;
480 attribfields
.push_back(anyattr
);
484 case n_attributeGroup
:
485 if (!atts
.ref
.empty()) {
486 ComplexType
* g
= new ComplexType(this);
487 g
->setXsdtype(n_attributeGroup
);
488 g
->setReference(atts
.ref
);
489 complexfields
.push_back(g
);
492 xsdtype
= n_attributeGroup
;
493 name
.upload(Mstring(atts
.name
));
498 if (atts
.ref
.empty()) {
501 name
.upload(atts
.name
);
504 ComplexType
* group
= new ComplexType(this);
505 group
->setXsdtype(n_group
);
506 group
->name
.upload(atts
.name
);
507 group
->setReference(Mstring(atts
.ref
));
508 group
->setMinMaxOccurs(atts
.minOccurs
, atts
.maxOccurs
);
509 complexfields
.push_back(group
);
517 type
.upload(Mstring("union"));
518 addVariant(V_useUnion
);
519 if (!atts
.memberTypes
.empty()) {
521 //Get the union values
522 expstring_t valueToSplitIntoTokens
= mcopystr(atts
.memberTypes
.c_str());
524 token
= strtok(valueToSplitIntoTokens
, " ");
525 while (token
!= NULL
) {
526 types
.push_back(Mstring(token
));
527 token
= strtok(NULL
, " ");
529 Free(valueToSplitIntoTokens
);
531 //Create the union elements and push into the container
532 for (List
<Mstring
>::iterator memberType
= types
.begin(); memberType
; memberType
= memberType
->Next
) {
533 Mstring tmp_name
= memberType
->Data
.getValueWithoutPrefix(':');
534 ComplexType
* f
= new ComplexType(this);
535 f
->name
.upload(tmp_name
);
536 f
->type
.upload(memberType
->Data
);
537 f
->setXsdtype(n_simpleType
);
538 f
->setReference(memberType
->Data
);
539 complexfields
.push_back(f
);
545 case n_simpleContent
:
547 xsdtype
= parser
->getActualTagName();
548 cmode
= CT_simpletype_mode
;
552 fieldname
= Mstring("alt_");
554 fieldname
= mprintf("alt_%d", max_alt
);
557 ComplexType
* field
= new ComplexType(this);
558 field
->name
.upload(fieldname
);
559 field
->setXsdtype(n_simpleType
);
560 field
->addVariant(V_nameAs
, empty_string
, true);
561 complexfields
.push_back(field
);
567 name
.upload(atts
.name
);
568 type
.upload(Mstring("record"));
569 applyAbstractAttribute(atts
.abstract
);
570 applySubstitionGroupAttribute(atts
.substitionGroup
);
571 applyBlockAttribute(atts
.block
);
573 case n_complexContent
:
574 tagNames
.push_back(parser
->getActualTagName());
575 cmode
= CT_complextype_mode
;
577 ComplexType
* mixed
= new ComplexType(this);
578 mixed
->name
.upload(Mstring("embed_values"));
579 mixed
->type
.upload(Mstring("xsd:string"));
580 mixed
->setMinMaxOccurs(0, ULLONG_MAX
, false);
582 complexfields
.push_back(mixed
);
583 addVariant(V_embedValues
);
587 if (parent
!= NULL
&& parent
->basefield
== this) {
589 parent
->SimpleType::loadWithValues();
590 parent
->basefield
= NULL
;
605 case n_fractionDigits
:
606 SimpleType::loadWithValues();
609 addComment(Mstring("LABEL:"));
612 addComment(Mstring("DEFINITION:"));
619 // called from endelementHandler
620 void ComplexType::modifyValues() {
621 if (this != actfield
) {
622 actfield
->modifyValues();
625 if (xsdtype
== n_sequence
) {
626 skipback
= skipback
- 1;
629 //embedded simpletype with list in element
630 if(xsdtype
== n_simpleType
&& list
) {
636 if ( parent
!= NULL
&&
637 (xsdtype
== n_element
||
638 xsdtype
== n_complexType
||
639 xsdtype
== n_complexContent
||
641 xsdtype
== n_attribute
||
642 xsdtype
== n_anyAttribute
||
643 xsdtype
== n_choice
||
644 xsdtype
== n_group
||
645 xsdtype
== n_attributeGroup
||
646 xsdtype
== n_extension
||
647 xsdtype
== n_restriction
||
648 (xsdtype
== n_simpleType
&& !list
) ||
649 xsdtype
== n_simpleContent
||
650 (xsdtype
== n_sequence
&& skipback
< 0)
652 if (!tagNames
.empty() && tagNames
.back() == parser
->getParentTagName()) {
653 if (nillable
&& tagNames
.back() == n_element
) {
654 parent
->modifyValues();
657 } else if (tagNames
.empty()) {
658 parent
->actfield
= parent
;
659 parent
->lastType
= xsdtype
;
664 void ComplexType::referenceResolving() {
665 if (resolved
!= No
) return; // nothing to do
666 if(this == subsGroup
){
670 resolved
= InProgress
;
671 for (List
<ComplexType
*>::iterator ct
= complexfields
.begin(); ct
; ct
= ct
->Next
) {
672 // Referenece resolving of ComplexTypes
673 ct
->Data
->referenceResolving();
675 for (List
<AttributeType
*>::iterator attr
= attribfields
.begin(); attr
; attr
= attr
->Next
) {
676 //Reference resolving for Attributes
677 resolveAttribute(attr
->Data
);
680 reference_resolving_funtion();
682 if(!substitutionGroup
.empty()){
683 addToSubstitutions();
688 void ComplexType::reference_resolving_funtion() {
689 //Every child element references are resolved here.
690 if (outside_reference
.empty() && basefield
== NULL
) {
691 //Its not in the resolveElement function because we need the built in type
692 //reference too, and then the outside_reference is empty.
693 if(xsdtype
== n_element
){
694 collectElementTypes(NULL
, NULL
);
699 SimpleType
* st
= (SimpleType
*) TTCN3ModuleInventory::getInstance().lookup(this, want_BOTH
);
700 if (st
== NULL
&& basefield
== NULL
) {
701 printError(module
->getSchemaname(), name
.convertedValue
,
702 "Reference for a non-defined type: " + getReference().repr());
703 TTCN3ModuleInventory::getInstance().incrNumErrors();
704 outside_reference
.set_resolved(NULL
);
708 resolveAttributeGroup(st
);
714 resolveSimpleTypeExtension();
716 resolveSimpleTypeRestriction();
718 resolveComplexTypeExtension();
720 resolveComplexTypeRestriction();
724 addToTypeSubstitutions();
728 void ComplexType::setParent(ComplexType
* par
, SimpleType
* child
) {
732 void ComplexType::applyReference(const SimpleType
& other
, const bool on_attributes
) {
733 type
.convertedValue
= other
.getType().convertedValue
;
734 type
.originalValueWoPrefix
= other
.getType().convertedValue
.getValueWithoutPrefix(':');
736 if (other
.getMinOccurs() > minOccurs
|| other
.getMaxOccurs() < maxOccurs
) {
737 if (!on_attributes
) {
738 expstring_t temp
= memptystr();
741 "The occurrence range (%llu .. %llu) of the element (%s) is not compatible "
742 "with the occurrence range (%llu .. %llu) of the referenced element.",
745 name
.originalValueWoPrefix
.c_str(),
746 other
.getMinOccurs(),
747 other
.getMaxOccurs());
748 printError(module
->getSchemaname(), parent
->getName().originalValueWoPrefix
,
751 TTCN3ModuleInventory::getInstance().incrNumErrors();
754 minOccurs
= llmax(minOccurs
, other
.getMinOccurs());
755 maxOccurs
= llmin(maxOccurs
, other
.getMaxOccurs());
758 for (List
<Mstring
>::iterator var
= other
.getVariantRef().begin(); var
; var
= var
->Next
) {
760 for (List
<Mstring
>::iterator var1
= variant
.begin(); var1
; var1
= var1
->Next
) {
761 if (var
->Data
== var1
->Data
) {
767 variant
.push_back(var
->Data
);
768 variant_ref
.push_back(var
->Data
);
772 builtInBase
= other
.getBuiltInBase();
774 length
.applyReference(other
.getLength());
775 pattern
.applyReference(other
.getPattern());
776 enumeration
.applyReference(other
.getEnumeration());
777 whitespace
.applyReference(other
.getWhitespace());
778 value
.applyReference(other
.getValue());
781 void ComplexType::nameConversion(NameConversionMode conversion_mode
, const List
<NamespaceType
> & ns
) {
783 switch (conversion_mode
) {
785 nameConversion_names(ns
);
788 nameConversion_types(ns
);
791 nameConversion_fields(ns
);
796 void ComplexType::nameConversion_names(const List
<NamespaceType
> &) {
797 Mstring res
, var(module
->getTargetNamespace());
798 XSDName2TTCN3Name(name
.convertedValue
, TTCN3ModuleInventory::getInstance().getTypenames(), type_name
, res
, var
);
799 name
.convertedValue
= res
;
801 for (List
<Mstring
>::iterator vari
= variant
.begin(); vari
; vari
= vari
->Next
) {
802 if (vari
->Data
== "\"untagged\"") {
808 addVariant(V_onlyValue
, var
);
810 for (List
<SimpleType
*>::iterator dep
= nameDepList
.begin(); dep
; dep
= dep
->Next
) {
811 dep
->Data
->setTypeValue(res
);
815 void ComplexType::nameConversion_types(const List
<NamespaceType
> & ns
) {
816 attribfields
.sort(compareAttributeNameSpaces
);
817 attribfields
.sort(compareAttributeTypes
);
818 for (List
<AttributeType
*>::iterator field
= attribfields
.begin(); field
; field
= field
->Next
) {
819 field
->Data
->nameConversion(typeMode
, ns
);
822 for (List
<ComplexType
*>::iterator field
= complexfields
.begin(); field
; field
= field
->Next
) {
823 field
->Data
->nameConversion_types(ns
);
826 Mstring prefix
, uri
, typeValue
;
828 if (type
.convertedValue
== "record" ||
829 type
.convertedValue
== "set" ||
830 type
.convertedValue
== "union" ||
831 type
.convertedValue
== "enumerated") {
835 prefix
= type
.convertedValue
.getPrefix(':');
836 typeValue
= type
.convertedValue
.getValueWithoutPrefix(':');
838 for (List
<NamespaceType
>::iterator namesp
= ns
.begin(); namesp
; namesp
= namesp
->Next
) {
839 if (prefix
== namesp
->Data
.prefix
) {
840 uri
= namesp
->Data
.uri
;
845 QualifiedName
in(uri
, typeValue
); // ns uri + original name
847 // Check all known types
848 QualifiedNames::iterator origTN
= TTCN3ModuleInventory::getInstance().getTypenames().begin();
849 for (; origTN
; origTN
= origTN
->Next
) {
850 if (origTN
->Data
== in
) {
851 QualifiedName
tmp_name(module
->getTargetNamespace(), name
.convertedValue
);
852 if (origTN
->Data
!= tmp_name
){
858 if (origTN
!= NULL
) {
859 setTypeValue(origTN
->Data
.name
);
862 XSDName2TTCN3Name(typeValue
, TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name
, res
, var
, type
.no_replace
);
867 void ComplexType::nameConversion_fields(const List
<NamespaceType
> & ns
) {
868 QualifiedNames used_field_names
;
870 for (List
<AttributeType
*>::iterator field
= attribfields
.begin(); field
; field
= field
->Next
) {
871 field
->Data
->nameConversion_names(used_field_names
);
874 for (List
<ComplexType
*>::iterator field
= complexfields
.begin(); field
; field
= field
->Next
) {
875 if (field
->Data
->getMinOccurs() == 0 && field
->Data
->getMaxOccurs() == 0) {
878 if (!field
->Data
->isVisible()) {
882 field
->Data
->nameConversion_fields(ns
);
884 Mstring prefix
= field
->Data
->getType().convertedValue
.getPrefix(':');
885 Mstring typeValue
= field
->Data
->getType().convertedValue
.getValueWithoutPrefix(':');
888 var
= getModule()->getTargetNamespace();
889 XSDName2TTCN3Name(typeValue
, TTCN3ModuleInventory::getInstance().getTypenames(), type_reference_name
, res
, var
);
891 field
->Data
->addVariant(V_onlyValue
, var
);
892 var
= getModule()->getTargetNamespace();
894 if (field
->Data
->getName().list_extension
) {
895 field
->Data
->useNameListProperty();
896 XSDName2TTCN3Name(field
->Data
->getName().convertedValue
,
897 used_field_names
, field_name
, res
, var
);
898 field
->Data
->setNameValue(res
);
899 bool found_in_variant
= false;
900 for (List
<Mstring
>::iterator vari
= field
->Data
->getVariant().begin(); vari
; vari
= vari
->Next
) {
901 if (vari
->Data
== Mstring("\"untagged\"")) {
902 found_in_variant
= true;
906 if (!field
->Data
->getName().originalValueWoPrefix
.empty() &&
907 field
->Data
->getName().originalValueWoPrefix
!= "sequence" &&
908 field
->Data
->getName().originalValueWoPrefix
!= "choice" &&
909 field
->Data
->getName().originalValueWoPrefix
!= "elem" &&
911 field
->Data
->addVariant(V_nameAs
, field
->Data
->getName().originalValueWoPrefix
);
915 if (!found_in_variant
) {
916 field
->Data
->addVariant(V_untagged
, empty_string
, true);
919 XSDName2TTCN3Name(field
->Data
->getName().convertedValue
,
920 used_field_names
, field_name
, res
, var
);
921 field
->Data
->setNameValue(res
);
922 field
->Data
->addVariant(V_onlyValue
, var
);
928 void ComplexType::setFieldPaths(Mstring path
) {
931 Mstring field_prefix
= empty_string
;
932 if(parent
->minOccurs
== 0 && parent
->maxOccurs
== ULLONG_MAX
){
933 field_prefix
= "[-].";
935 path
= field_prefix
+ getName().convertedValue
;
936 actualPath
= field_prefix
+ getName().convertedValue
;
938 actualPath
= getName().convertedValue
;
940 } else if (parent
!= NULL
&& (parent
->getMinOccurs() != 1 || parent
->getMaxOccurs() != 1) &&
941 (parent
->getName().list_extension
|| parent
->mode
== listMode
)) {
942 path
= path
+ Mstring("[-].") + getName().convertedValue
;
945 path
= path
+ Mstring(".") + getName().convertedValue
;
949 for (List
<ComplexType
*>::iterator field
= complexfields
.begin(); field
; field
= field
->Next
) {
950 field
->Data
->setFieldPaths(path
);
952 for (List
<AttributeType
*>::iterator attr
= attribfields
.begin(); attr
; attr
= attr
->Next
) {
953 attr
->Data
->setFieldPath(path
);
957 void ComplexType::finalModification2() {
958 //Call SimpleType finalModification
959 SimpleType::finalModification();
961 //Set isOptional field
962 isOptional
= isOptional
|| (minOccurs
== 0 && maxOccurs
== 1);
965 List
<Mstring
> enumNames
;
966 for (List
<ComplexType
*>::iterator field
= complexfields
.begin(), nextField
; field
; field
= nextField
) {
967 nextField
= field
->Next
;
968 //Remove invisible fields
969 if ((field
->Data
->minOccurs
== 0 && field
->Data
->maxOccurs
== 0) || !field
->Data
->isVisible()) {
972 complexfields
.remove(field
);
975 field
->Data
->finalModification2();
976 //collect <xsd:all> elements
977 if (field
->Data
->fromAll
) {
978 enumNames
.push_back(field
->Data
->getName().convertedValue
);
983 ComplexType
* embedField
= NULL
;
984 ComplexType
* enumField
= NULL
;
986 //Find the embed and order fields, and remove them
987 for (List
<ComplexType
*>::iterator field
= complexfields
.begin(), nextField
; field
; field
= nextField
) {
988 nextField
= field
->Next
;
989 if (field
->Data
->embed
) {
990 embedField
= new ComplexType(*field
->Data
);
991 embedField
->parent
= this;
994 complexfields
.remove(field
);
995 } else if (field
->Data
->enumerated
) {
996 enumField
= new ComplexType(*field
->Data
);
997 enumField
->parent
= this;
1000 complexfields
.remove(field
);
1004 if (enumField
!= NULL
) {
1005 //Insert the order field in the front
1006 complexfields
.push_front(enumField
);
1007 //Push the field names into the order field
1008 for (List
<Mstring
>::iterator field
= enumNames
.begin(); field
; field
= field
->Next
) {
1009 enumField
->enumfields
.push_back(field
->Data
);
1013 if (embedField
!= NULL
) {
1014 //Insert the embed field to the front
1015 complexfields
.push_front(embedField
);
1019 unsigned number
= 0;
1020 for (List
<ComplexType
*>::iterator field
= complexfields
.begin(); field
; field
= field
->Next
) {
1021 if (field
->Data
->name
.convertedValue
.foundAt("alt_") == field
->Data
->name
.convertedValue
.c_str()) {
1023 field
->Data
->name
.upload(Mstring("alt_"));
1025 field
->Data
->name
.upload(Mstring(mprintf("alt_%d", number
)));
1032 AttributeType
* anyAttr
= NULL
;
1033 for (List
<AttributeType
*>::iterator field
= attribfields
.begin(), nextField
; field
; field
= nextField
) {
1034 nextField
= field
->Next
;
1035 field
->Data
->applyUseAttribute();
1036 //Find anyattribute, and remove it
1037 if (field
->Data
->isAnyAttribute()) {
1038 anyAttr
= new AttributeType(*field
->Data
);
1039 setParent(this, anyAttr
);
1042 attribfields
.remove(field
);
1043 } else if (field
->Data
->getUseVal() == prohibited
|| !field
->Data
->isVisible()) {
1044 //Not visible attribute removed
1047 attribfields
.remove(field
);
1049 field
->Data
->SimpleType::finalModification();
1053 //Push anyattribute to the front
1054 if (anyAttr
!= NULL
) {
1055 anyAttr
->applyNamespaceAttribute(V_anyAttributes
);
1056 attribfields
.push_back(anyAttr
);
1059 //Substitution group ordering
1060 if(subsGroup
== this || typeSubsGroup
== this){ //We are a generated substitution group
1061 //Substitution group never empty
1062 ComplexType
* front
= complexfields
.front();
1063 List
<ComplexType
*>::iterator it
= complexfields
.begin();
1064 complexfields
.remove(it
);
1065 complexfields
.sort(compareComplexTypeNameSpaces
);
1066 complexfields
.sort(compareTypes
);
1067 complexfields
.push_front(front
);
1071 void ComplexType::finalModification() {
1072 finalModification2();
1073 setFieldPaths(empty_string
);
1074 List
<Mstring
> container
;
1075 collectVariants(container
);
1077 variant
= container
;
1080 void ComplexType::printToFile(FILE * file
) {
1081 printToFile(file
, 0, false);
1084 void ComplexType::printToFile(FILE * file
, const unsigned level
, const bool is_union
) {
1088 printComment(file
, level
);
1090 fprintf(file
, "type ");
1091 if(mode
== listMode
){
1092 printMinOccursMaxOccurs(file
, is_union
);
1093 fprintf(file
, "%s", type
.convertedValue
.c_str());
1095 fprintf(file
, "%s %s", type
.convertedValue
.c_str(), name
.convertedValue
.c_str());
1097 fprintf(file
, "\n{\n");
1099 if (attribfields
.empty() && complexfields
.empty()) {
1100 fprintf(file
, "\n");
1103 for (List
<ComplexType
*>::iterator c
= complexfields
.begin(), nextField
; c
; c
= nextField
) {
1104 nextField
= c
->Next
;
1105 if (c
->Data
->embed
|| c
->Data
->enumerated
) {
1106 c
->Data
->printToFile(file
, level
+ 1, is_union
);
1107 if (c
->Next
!= NULL
|| !attribfields
.empty()) {
1108 fprintf(file
, ",\n");
1110 fprintf(file
, "\n");
1114 complexfields
.remove(c
);
1118 for (List
<AttributeType
*>::iterator f
= attribfields
.begin(); f
; f
= f
->Next
) {
1119 f
->Data
->printToFile(file
, level
+ 1);
1120 if (f
->Next
!= NULL
|| !complexfields
.empty()) {
1121 fprintf(file
, ",\n");
1123 fprintf(file
, "\n");
1127 for (List
<ComplexType
*>::iterator c
= complexfields
.begin(); c
; c
= c
->Next
) {
1128 c
->Data
->printToFile(file
, level
+ 1, is_union
);
1129 if (c
->Next
!= NULL
) {
1130 fprintf(file
, ",\n");
1132 fprintf(file
, "\n");
1136 const bool field_is_record
= getType().convertedValue
== Mstring("record");
1137 const bool field_is_union
= getType().convertedValue
== "union";
1138 if (complexfields
.empty() && attribfields
.empty() && (field_is_record
|| field_is_union
)) {
1139 if (field_is_record
) {
1140 indent(file
, level
);
1141 printMinOccursMaxOccurs(file
, is_union
);
1142 fprintf(file
, "%s {\n", getType().convertedValue
.c_str());
1143 indent(file
, level
);
1144 fprintf(file
, "} %s", getName().convertedValue
.c_str());
1146 fprintf(file
, " optional");
1148 } else if (field_is_union
) {
1149 indent(file
, level
);
1150 printMinOccursMaxOccurs(file
, is_union
);
1151 fprintf(file
, "%s {\n", getType().convertedValue
.c_str());
1152 indent(file
, level
+ 1);
1153 fprintf(file
, "record length(0 .. 1) of enumerated { NULL_ } choice\n");
1154 indent(file
, level
);
1155 fprintf(file
, "} %s", getName().convertedValue
.c_str());
1157 fprintf(file
, " optional");
1161 indent(file
, level
);
1162 if (getEnumeration().modified
) {
1163 if (isFloatType(getBuiltInBase())) {
1164 fprintf(file
, "%s (", type
.convertedValue
.c_str());
1165 getEnumeration().sortFacets();
1166 getEnumeration().printToFile(file
);
1169 printMinOccursMaxOccurs(file
, with_union
);
1170 fprintf(file
, "enumerated {\n");
1171 //getEnumeration().sortFacets();
1172 getEnumeration().printToFile(file
, level
);
1173 fprintf(file
, "\n");
1174 indent(file
, level
);
1175 fprintf(file
, "} ");
1178 int multiplicity
= multi(module
, getReference(), this);
1179 if ((multiplicity
> 1) && getReference().get_ref()) {
1180 fprintf(file
, "%s.", getReference().get_ref()->getModule()->getModulename().c_str());
1182 if (field_is_record
|| field_is_union
) {
1183 printMinOccursMaxOccurs(file
, with_union
, !first_child
|| parent
->getXsdtype() != n_choice
);
1184 fprintf(file
, "%s {\n", getType().convertedValue
.c_str());
1185 for (List
<AttributeType
*>::iterator f
= attribfields
.begin(); f
; f
= f
->Next
) {
1186 f
->Data
->printToFile(file
, level
+ 1);
1187 if (f
->Next
!= NULL
|| !complexfields
.empty()) {
1188 fprintf(file
, ",\n");
1190 fprintf(file
, "\n");
1194 for (List
<ComplexType
*>::iterator c
= complexfields
.begin(); c
; c
= c
->Next
) {
1195 c
->Data
->printToFile(file
, level
+ 1, is_union
);
1196 if (c
->Next
!= NULL
) {
1197 fprintf(file
, ",\n");
1199 fprintf(file
, "\n");
1203 printMinOccursMaxOccurs(file
, with_union
, !first_child
);
1204 fprintf(file
, "%s ", getType().convertedValue
.c_str());
1205 if (getName().convertedValue
== Mstring("order") && getType().convertedValue
== Mstring("enumerated")) {
1206 fprintf(file
, "{\n");
1207 for (List
<Mstring
>::iterator e
= enumfields
.begin(); e
; e
= e
->Next
) {
1208 indent(file
, level
+ 1);
1209 fprintf(file
, "%s", e
->Data
.c_str());
1210 if (e
->Next
!= NULL
) {
1211 fprintf(file
, ",\n");
1213 fprintf(file
, "\n");
1216 indent(file
, level
);
1217 fprintf(file
, "} ");
1221 if (field_is_record
|| field_is_union
) {
1222 indent(file
, level
);
1223 fprintf(file
, "} ");
1226 fprintf(file
, "%s", getName().convertedValue
.c_str());
1227 getPattern().printToFile(file
);
1228 getValue().printToFile(file
);
1229 getLength().printToFile(file
);
1230 if (!with_union
&& isOptional
) {
1231 fprintf(file
, " optional");
1238 if(mode
== listMode
){
1239 fprintf(file
, " %s", name
.convertedValue
.c_str());
1242 fprintf(file
, ";\n\n\n");
1246 void ComplexType::collectVariants(List
<Mstring
>& container
) {
1248 if (e_flag_used
|| !isVisible()) {
1253 bool useUnionVariantWhenMainTypeIsRecordOf
= false;
1254 for (List
<Mstring
>::iterator var
= variant
.end(); var
; var
= var
->Prev
) {
1255 if ((minOccurs
!= 1 || maxOccurs
!= 1) && (var
->Data
== "\"useUnion\"")) { // main type is a record of
1256 useUnionVariantWhenMainTypeIsRecordOf
= true; // TR HL15893
1258 container
.push_back(Mstring("variant ") + Mstring(var
->Data
.c_str()) + Mstring(";\n"));
1261 if (useUnionVariantWhenMainTypeIsRecordOf
) {
1262 container
.push_back(Mstring("variant ([-]) \"useUnion\";\n"));
1264 for (List
<Mstring
>::iterator var
= hidden_variant
.end(); var
; var
= var
->Prev
) {
1265 container
.push_back(Mstring("//variant ") + Mstring(var
->Data
.c_str()) + Mstring(";\n"));
1269 //Collect variants of attributes
1270 for (List
<AttributeType
*>::iterator field
= attribfields
.begin(); field
; field
= field
->Next
) {
1271 field
->Data
->collectVariants(container
);
1274 for (List
<ComplexType
*>::iterator field
= complexfields
.begin(); field
; field
= field
->Next
) {
1276 if (!field
->Data
->isVisible()) {
1280 if (field
->Data
->getVariant().empty() && field
->Data
->getHiddenVariant().empty() &&
1281 field
->Data
->complexfields
.empty() && field
->Data
->attribfields
.empty() &&
1282 field
->Data
->enumeration
.variants
.empty()) {
1286 bool already_used
= false;
1288 for (List
<Mstring
>::iterator var2
= field
->Data
->getVariant().end(); var2
; var2
= var2
->Prev
) {
1289 if (var2
->Data
== "\"untagged\"" && !already_used
) {
1290 container
.push_back(Mstring("variant (") + field
->Data
->actualPath
+ Mstring(") ") + Mstring(var2
->Data
.c_str()) + Mstring(";\n"));
1291 already_used
= true;
1293 if ((field
->Data
->getMinOccurs() != 1 || field
->Data
->getMaxOccurs() != 1) &&
1294 (field
->Data
->getName().list_extension
|| var2
->Data
== "\"useUnion\"")) {
1295 container
.push_back(Mstring("variant (") + field
->Data
->actualPath
+ Mstring("[-]) ") + Mstring(var2
->Data
.c_str()) + Mstring(";\n"));
1296 } else if (var2
->Data
!= "\"untagged\"") {
1297 container
.push_back(Mstring("variant (") + field
->Data
->actualPath
+ Mstring(") ") + Mstring(var2
->Data
.c_str()) + Mstring(";\n"));
1301 for (List
<Mstring
>::iterator hidden_var
= field
->Data
->getHiddenVariant().end();
1302 hidden_var
; hidden_var
= hidden_var
->Prev
) {
1303 if ((field
->Data
->getMinOccurs() != 1 || field
->Data
->getMaxOccurs() != 1) &&
1304 field
->Data
->getName().list_extension
) {
1305 container
.push_back(Mstring("//variant (") + field
->Data
->actualPath
+ Mstring("[-]) ") + Mstring(hidden_var
->Data
.c_str()) + Mstring(";\n"));
1307 container
.push_back(Mstring("//variant (") + field
->Data
->actualPath
+ Mstring(") ") + Mstring(hidden_var
->Data
.c_str()) + Mstring(";\n"));
1311 if(field
->Data
->enumeration
.modified
){
1312 Mstring path
= empty_string
;
1313 if(field
->Data
->getMinOccurs() != 1 && field
->Data
->getMaxOccurs() != 1){
1314 path
= field
->Data
->actualPath
+ Mstring("[-]");
1316 path
= field
->Data
->actualPath
;
1318 for(List
<Mstring
>::iterator var
= field
->Data
->enumeration
.variants
.end(); var
; var
= var
->Prev
){
1319 if(var
->Data
.empty()) continue;
1320 container
.push_back("variant (" + path
+ ") " + var
->Data
+ ";\n");
1324 field
->Data
->collectVariants(container
);
1328 void ComplexType::printVariant(FILE * file
) {
1333 bool foundAtLeastOneVariant
= false;
1334 bool foundAtLeastOneHiddenVariant
= false;
1336 if (!variant
.empty()) {
1337 for (List
<Mstring
>::iterator var
= variant
.begin(); var
; var
= var
->Next
) {
1338 if (foundAtLeastOneVariant
&& foundAtLeastOneHiddenVariant
) {
1341 if (var
->Data
[0] != '/') {
1342 foundAtLeastOneVariant
= true;
1344 foundAtLeastOneHiddenVariant
= true;
1349 if (!foundAtLeastOneVariant
&& !foundAtLeastOneHiddenVariant
) {
1353 if (!foundAtLeastOneVariant
) {
1354 //No other variants, only commented, so the 'with' must be commented also.
1355 fprintf(file
, ";\n//with {\n");
1357 fprintf(file
, "\nwith {\n");
1360 for (List
<Mstring
>::iterator var
= variant
.begin(); var
; var
= var
->Next
) {
1361 fprintf(file
, " %s", var
->Data
.c_str());
1364 if (!foundAtLeastOneVariant
) {
1365 fprintf(file
, "//");
1370 void ComplexType::dump(unsigned int depth
) const {
1371 fprintf(stderr
, "%*s %sComplexType at %p | Top:%s\n", depth
* 2, "", isVisible() ? "" : "(hidden)", (const void*) this, top
? "true" : "false");
1372 if (parent
!= NULL
) {
1373 fprintf(stderr
, "%*s parent: %p | parent xsdtype: %i | my xsdtype: %i\n", depth
* 2, "", (const void*) parent
, parent
->getXsdtype(), xsdtype
);
1375 fprintf(stderr
, "%*s parent: %p | parent xsdtype: %s | my xsdtype: %i\n", depth
* 2, "", "NULL", "NULL", xsdtype
);
1377 fprintf(stderr
, "%*s name='%s' -> '%s', type='%s' %d complexfields | %s | %s | %s\n", depth
* 2, "",
1378 name
.originalValueWoPrefix
.c_str(), name
.convertedValue
.c_str(), type
.convertedValue
.c_str(), (int) complexfields
.size(),
1379 outside_reference
.empty() ? "" : outside_reference
.get_val().c_str(), mode
== restrictionMode
? "restriction" : "",
1380 mode
== extensionMode
? "extension" : "");
1381 for (List
<ComplexType
*>::iterator field
= complexfields
.begin(); field
; field
= field
->Next
) {
1382 field
->Data
->dump(depth
+ 1);
1384 fprintf(stderr
, "%*s %d attribields\n", depth
* 2, "", (int) attribfields
.size());
1385 for (List
<AttributeType
*>::iterator field
= attribfields
.begin(); field
; field
= field
->Next
) {
1386 field
->Data
->dump(depth
+ 1);
1388 fprintf(stderr
, "%*s %d enumfields\n", depth
* 2, "", (int) enumfields
.size());
1389 for (List
<Mstring
>::iterator field
= enumfields
.begin(); field
; field
= field
->Next
) {
1390 fprintf(stderr
, "%*s enum: %s\n", depth
* 2 + depth
, "", field
->Data
.c_str());
1392 fprintf(stderr
, "%*s (%llu .. %llu) | Optional:%s | List:%s\n", (depth
+ 1) * 2, "", minOccurs
, maxOccurs
, isOptional
? "true" : "false", name
.list_extension
? "true" : "false");
1393 fprintf(stderr
, "%*s %d variants: ", (depth
+ 1) * 2, "", (int) variant
.size());
1394 for (List
<Mstring
>::iterator var
= variant
.begin(); var
; var
= var
->Next
) {
1395 fprintf(stderr
, "%s, ", var
->Data
.c_str());
1397 fprintf(stderr
, "%*s pattern:%s | length:%i \n ", (depth
+ 1) * 2, "", this->pattern
.facet
.c_str(), (int) (this->length
.facet_maxLength
));
1398 fprintf(stderr
, "%*s enum: %i \n", (depth
+ 1)*2, "", (int) this->enumeration
.facets
.size());
1399 fprintf(stderr
, "\n");
1402 void ComplexType::setMinMaxOccurs(const unsigned long long min
, const unsigned long long max
, const bool generate_list_postfix
) {
1404 if (min
!= 1 || max
!= 1) {
1405 if (xsdtype
== n_choice
) {
1408 addVariant(V_untagged
);
1409 first_child
= false;
1410 } else if (xsdtype
== n_sequence
) {
1411 ComplexType
* rec
= new ComplexType(this);
1412 rec
->type
.upload(Mstring("record"));
1413 rec
->name
.upload(Mstring("sequence"));
1414 rec
->setXsdtype(n_sequence
);
1415 rec
->addVariant(V_untagged
);
1416 rec
->addVariant(V_untagged
);
1417 rec
->minOccurs
= min
;
1418 rec
->maxOccurs
= max
;
1419 complexfields
.push_back(rec
);
1421 if ((rec
->minOccurs
== 0 && rec
->maxOccurs
> 1) || rec
->minOccurs
> 0) {
1422 rec
->name
.list_extension
= true;
1427 if ((minOccurs
== 0 && maxOccurs
> 1) || minOccurs
> 0) {
1428 if (generate_list_postfix
) {
1429 name
.list_extension
= true;
1432 if (parent
!= NULL
&& parent
->getXsdtype() == n_choice
) {
1433 name
.list_extension
= true;
1434 if ((parent
!= NULL
&& parent
->getXsdtype() == n_choice
)) {
1435 if (parent
->first_child
== false && minOccurs
== 0) {
1436 parent
->first_child
= true;
1438 first_child
= false;
1448 if (maxOccurs
> 1 && generate_list_postfix
) {
1449 name
.list_extension
= true;
1453 void ComplexType::applyNamespaceAttribute(VariantMode varLabel
, const Mstring
& ns_list
) {
1454 List
<Mstring
> namespaces
;
1455 if (!ns_list
.empty()) {
1456 expstring_t valueToSplitIntoTokens
= mcopystr(ns_list
.c_str());
1458 token
= strtok(valueToSplitIntoTokens
, " ");
1459 while (token
!= NULL
) {
1460 namespaces
.push_back(Mstring(token
));
1461 token
= strtok(NULL
, " ");
1463 Free(valueToSplitIntoTokens
);
1468 // Note: libxml2 will verify the namespace list according to the schema
1469 // of XML Schema. It is either ##any, ##other, ##local, ##targetNamespace,
1470 // or a list of (namespace reference | ##local | ##targetNamespace).
1471 for (List
<Mstring
>::iterator ns
= namespaces
.begin(); ns
; ns
= ns
->Next
) {
1472 static const Mstring
xxany("##any"), xxother("##other"), xxlocal("##local"),
1473 xxtargetNamespace("##targetNamespace");
1474 if (!first
) any_ns
+= ',';
1476 if (ns
->Data
== xxany
) {
1477 }// this must be the only element, nothing to add
1478 else if (ns
->Data
== xxother
) { // this must be the only element
1479 any_ns
+= " except unqualified";
1480 if (module
->getTargetNamespace() != "NoTargetNamespace") {
1482 any_ns
+= parent
->getModule()->getTargetNamespace();
1485 }// The three cases below can happen multiple times
1487 if (first
) any_ns
+= " from ";
1488 // else a comma was already added
1489 if (ns
->Data
== xxtargetNamespace
) {
1491 any_ns
+= parent
->getModule()->getTargetNamespace();
1493 } else if (ns
->Data
== xxlocal
) {
1494 any_ns
+= "unqualified";
1505 addVariant(varLabel
, any_ns
, true);
1508 void ComplexType::addComment(const Mstring
& text
) {
1509 if (this == actfield
) {
1510 if (lastType
== n_attribute
) { // ez nem teljesen jo, stb, tobb lehetoseg, es rossy sorrend
1511 if (!attribfields
.empty()) {
1512 attribfields
.back()->addComment(text
);
1515 if (actfield
->getName().convertedValue
== Mstring("base") && parent
!= NULL
) {
1516 parent
->getComment().push_back(Mstring("/* " + text
+ " */\n"));
1518 comment
.push_back(Mstring("/* " + text
+ " */\n"));
1522 actfield
->addComment(text
);
1527 //Attribute extension logic when extending complextypes
1528 void ComplexType::applyAttributeExtension(ComplexType
* found_CT
, AttributeType
* anyAttrib
/* = NULL */) {
1529 for (List
<AttributeType
*>::iterator attr
= found_CT
->attribfields
.begin(); attr
; attr
= attr
->Next
) {
1531 if (anyAttrib
!= NULL
&& attr
->Data
->isAnyAttribute()) {
1532 anyAttrib
->addNameSpaceAttribute(attr
->Data
->getNameSpaceAttribute());
1535 for (List
<AttributeType
*>::iterator attr2
= attribfields
.begin(); attr2
; attr2
= attr2
->Next
) {
1536 if (attr
->Data
->getName().convertedValue
== attr2
->Data
->getName().convertedValue
&&
1537 attr
->Data
->getType().convertedValue
== attr2
->Data
->getType().convertedValue
) {
1538 if (attr
->Data
->getUseVal() == optional
) {
1539 attr2
->Data
->setUseVal(optional
);
1547 AttributeType
* newAttrib
= new AttributeType(*attr
->Data
);
1548 attribfields
.push_back(newAttrib
);
1549 setParent(this, newAttrib
);
1554 //Attribute restriction logic when restricting complextypes
1555 void ComplexType::applyAttributeRestriction(ComplexType
* found_CT
) {
1556 for (List
<AttributeType
*>::iterator attr
= attribfields
.begin(), nextAttr
; attr
; attr
= nextAttr
) {
1557 nextAttr
= attr
->Next
;
1559 for (List
<AttributeType
*>::iterator attr2
= found_CT
->attribfields
.begin(); attr2
; attr2
= attr2
->Next
) {
1560 if (attr
->Data
->getName().convertedValue
== attr2
->Data
->getName().convertedValue
&&
1561 attr
->Data
->getType().convertedValue
== attr2
->Data
->getType().convertedValue
) {
1569 attribfields
.remove(attr
);
1572 size_t size
= found_CT
->attribfields
.size();
1573 size_t size2
= attribfields
.size();
1575 List
<AttributeType
*>::iterator attr
= found_CT
->attribfields
.begin();
1576 for (; i
< size
; attr
= attr
->Next
, i
= i
+ 1) {
1579 List
<AttributeType
*>::iterator attr2
= attribfields
.begin();
1580 for (; j
< size2
; attr2
= attr2
->Next
, j
= j
+ 1) {
1581 if (attr
->Data
->getName().convertedValue
== attr2
->Data
->getName().convertedValue
&&
1582 attr
->Data
->getType().convertedValue
== attr2
->Data
->getType().convertedValue
&& !attr2
->Data
->getUsed()) {
1584 attr2
->Data
->setUsed(true);
1589 AttributeType
* newAttrib
= new AttributeType(*attr
->Data
);
1590 attribfields
.push_back(newAttrib
);
1591 setParent(this, newAttrib
);
1596 void ComplexType::addNameSpaceAsVariant(RootType
* root
, RootType
* other
) {
1597 if (other
->getModule()->getTargetNamespace() != root
->getModule()->getTargetNamespace() &&
1598 other
->getModule()->getTargetNamespace() != "NoTargetNamespace") {
1599 root
->addVariant(V_namespaceAs
, other
->getModule()->getTargetNamespace());
1603 void ComplexType::resolveAttribute(AttributeType
* attr
) {
1604 if (attr
->getXsdtype() == n_attribute
&& !attr
->getReference().empty()) {
1605 SimpleType
* st
= (SimpleType
*) TTCN3ModuleInventory::getInstance().lookup(attr
, want_BOTH
);
1607 if (attr
->isFromRef()) {
1608 addNameSpaceAsVariant(attr
, st
);
1609 attr
->setTypeOfField(st
->getName().convertedValue
);
1610 attr
->setNameOfField(st
->getName().originalValueWoPrefix
);
1611 attr
->setOrigModule(st
->getModule());
1613 attr
->setTypeOfField(st
->getName().convertedValue
);
1614 if (st
->getType().convertedValue
== "record" || st
->getType().convertedValue
== "union") {
1615 st
->addToNameDepList(attr
);
1619 printError(module
->getSchemaname(), name
.convertedValue
,
1620 "Reference for a non-defined type: " + attr
->getReference().repr());
1621 TTCN3ModuleInventory::getInstance().incrNumErrors();
1626 void ComplexType::resolveAttributeGroup(SimpleType
* st
) {
1627 if (xsdtype
== n_attributeGroup
&& !outside_reference
.empty()) {
1628 ComplexType
* ct
= (ComplexType
*) st
;
1629 if(ct
->resolved
== No
){
1630 ct
->referenceResolving();
1632 outside_reference
.set_resolved(ct
);
1634 bool addNameSpaceas
= false;
1635 if (ct
->getModule()->getTargetNamespace() != module
->getTargetNamespace() &&
1636 ct
->getModule()->getTargetNamespace() != "NoTargetNamespace") {
1637 addNameSpaceas
= true;
1640 if(parent
->nillable
&& parent
->parent
!= NULL
){
1641 par
= parent
->parent
;
1645 List
<AttributeType
*>::iterator anyAttrib
= par
->attribfields
.begin();
1646 for (; anyAttrib
; anyAttrib
= anyAttrib
->Next
) {
1647 if (anyAttrib
->Data
->isAnyAttribute()) {
1651 for (List
<AttributeType
*>::iterator attr
= ct
->attribfields
.begin(); attr
; attr
= attr
->Next
) {
1652 AttributeType
* attrib
= new AttributeType(*attr
->Data
);
1653 attr
->Data
->setOrigModule(ct
->getModule());
1654 if (addNameSpaceas
) {
1655 attrib
->addVariant(V_namespaceAs
, ct
->getModule()->getTargetNamespace());
1657 if (anyAttrib
!= NULL
&& attr
->Data
->isAnyAttribute()) {
1658 anyAttrib
->Data
->addNameSpaceAttribute(attr
->Data
->getNameSpaceAttribute());
1660 //Nillable attribute placement is hard...
1661 if (parent
->nillable
&& parent
->parent
!= NULL
) {
1662 parent
->parent
->attribfields
.push_back(attrib
);
1663 attrib
->parent
= parent
->parent
;
1664 setParent(parent
->parent
, attrib
);
1665 } else if (parent
->nillable
&& !parent
->complexfields
.empty()) {
1666 parent
->complexfields
.back()->attribfields
.push_back(attrib
);
1667 attrib
->parent
= parent
->complexfields
.back();
1668 } else if (parent
->parent
!= NULL
&& (parent
->parent
->mode
== extensionMode
|| parent
->parent
->mode
== restrictionMode
)) {
1669 parent
->parent
->attribfields
.push_back(attrib
);
1670 setParent(parent
->parent
, attrib
);
1672 parent
->attribfields
.push_back(attrib
);
1673 setParent(parent
, attrib
);
1680 void ComplexType::resolveGroup(SimpleType
*st
) {
1681 if (xsdtype
== n_group
&& !outside_reference
.empty()) {
1682 ComplexType
* ct
= (ComplexType
*) st
;
1683 outside_reference
.set_resolved(ct
);
1685 if(ct
->resolved
== No
){
1686 ct
->referenceResolving();
1688 //Decide if namespaceas variant needs to be added
1689 bool addNameSpaceas
= false;
1690 if (ct
->getModule()->getTargetNamespace() != module
->getTargetNamespace() &&
1691 ct
->getModule()->getTargetNamespace() != "NoTargetNamespace") {
1692 addNameSpaceas
= true;
1694 if (ct
->getXsdtype() == n_sequence
&& minOccurs
== 1 && maxOccurs
== 1 && (parent
->getXsdtype() == n_complexType
|| parent
->getXsdtype() == n_sequence
)) {
1695 for (List
<ComplexType
*>::iterator c
= ct
->complexfields
.begin(); c
; c
= c
->Next
) {
1696 ComplexType
* newField
= new ComplexType(*c
->Data
);
1697 parent
->complexfields
.push_back(newField
);
1698 setParent(parent
, newField
);
1699 parent
->complexfields
.back()->setModule(getModule());
1700 if (addNameSpaceas
) {
1701 parent
->complexfields
.back()->addVariant(V_namespaceAs
, ct
->getModule()->getTargetNamespace());
1704 } else if (ct
->getXsdtype() == n_all
) {
1705 //If the parent optional, then every field is optional
1706 for (List
<ComplexType
*>::iterator c
= ct
->complexfields
.begin(); c
; c
= c
->Next
) {
1707 ComplexType
* f
= new ComplexType(*c
->Data
);
1708 if (minOccurs
== 0 && !f
->enumerated
) {
1709 f
->isOptional
= true;
1711 ((ComplexType
*) parent
)->complexfields
.push_back(f
);
1712 setParent(parent
, f
);
1713 f
->setModule(getModule());
1714 if (addNameSpaceas
) {
1715 f
->addVariant(V_namespaceAs
, ct
->getModule()->getTargetNamespace());
1718 parent
->addVariant(V_useOrder
);
1720 if (name
.list_extension
) {
1721 addVariant(V_untagged
);
1723 type
.upload(ct
->getName().convertedValue
);
1724 name
.upload(ct
->getName().convertedValue
);
1725 ct
->addToNameDepList(this);
1728 if (addNameSpaceas
) {
1729 addVariant(V_namespaceAs
, ct
->getModule()->getTargetNamespace());
1735 void ComplexType::resolveElement(SimpleType
*st
) {
1736 if (xsdtype
== n_element
&& !outside_reference
.empty()) {
1737 outside_reference
.set_resolved(st
);
1738 type
.upload(st
->getModule()->getTargetNamespaceConnector() + Mstring(":") + st
->getName().convertedValue
);
1739 if (name
.originalValueWoPrefix
.empty()) {
1740 name
.upload(st
->getName().convertedValue
);
1743 addNameSpaceAsVariant(this, st
);
1746 collectElementTypes(st
, NULL
);
1748 //Namedep is added to the substitutions, if any
1749 if(st
->getSubstitution() != NULL
){
1750 st
->getSubstitution()->addToNameDepList(this);
1751 nameDep
= st
->getSubstitution();
1752 }if(st
->getTypeSubstitution() != NULL
){
1753 st
->getTypeSubstitution()->addToNameDepList(this);
1754 nameDep
= st
->getTypeSubstitution();
1756 st
->addToNameDepList(this);
1762 void ComplexType::resolveSimpleTypeExtension() {
1763 if (mode
== extensionMode
&& cmode
== CT_simpletype_mode
&& basefield
!= NULL
) {
1764 SimpleType
* st
= (SimpleType
*) TTCN3ModuleInventory::getInstance().lookup(basefield
, want_BOTH
);
1766 if (st
->getXsdtype() != n_NOTSET
&& ((ComplexType
*) st
)->basefield
!= NULL
) { // if the xsdtype != simpletype
1767 ComplexType
* ct
= (ComplexType
*) st
;
1768 if (ct
->resolved
== No
) {
1769 ct
->referenceResolving();
1771 basefield
->outside_reference
.set_resolved(ct
);
1772 ct
->basefield
->addToNameDepList(basefield
);
1773 basefield
->nameDep
= ct
->basefield
;
1774 basefield
->mode
= extensionMode
;
1775 basefield
->applyReference(*ct
->basefield
, true);
1776 addNameSpaceAsVariant(basefield
, ct
->basefield
);
1777 applyAttributeExtension(ct
);
1779 if (!st
->getReference().empty() && !st
->getReference().is_resolved()) {
1780 st
->referenceResolving();
1782 st
->addToNameDepList(basefield
);
1783 basefield
->nameDep
= st
;
1784 addNameSpaceAsVariant(basefield
, st
);
1785 const Mstring old_type
= basefield
->getType().originalValueWoPrefix
;
1786 basefield
->applyReference(*st
);
1787 // If st has enumeration then the type is restored to the original value
1788 // because enumerations cannot be extended here and this way we just
1789 // we just create an alias.
1790 if (st
->getEnumeration().modified
) {
1791 basefield
->setTypeValue(old_type
);
1792 basefield
->getEnumeration().modified
= false;
1795 } else if(!isBuiltInType(basefield
->getType().convertedValue
)){
1796 printError(module
->getSchemaname(), name
.convertedValue
,
1797 "Reference for a non-defined type: " + basefield
->getReference().repr());
1798 TTCN3ModuleInventory::getInstance().incrNumErrors();
1805 void ComplexType::resolveSimpleTypeRestriction() {
1806 if (mode
== restrictionMode
&& cmode
== CT_simpletype_mode
&& basefield
!= NULL
&& !basefield
->outside_reference
.empty()) {
1807 SimpleType
* st
= (SimpleType
*) TTCN3ModuleInventory::getInstance().lookup(basefield
, want_BOTH
);
1809 printError(module
->getSchemaname(), name
.convertedValue
,
1810 "Reference for a non-defined type: " + basefield
->getReference().repr());
1811 TTCN3ModuleInventory::getInstance().incrNumErrors();
1814 basefield
->outside_reference
.set_resolved(st
);
1815 if (st
->getXsdtype() != n_NOTSET
) {
1816 ComplexType
* ct
= (ComplexType
*) st
;
1817 if (ct
->resolved
== No
) {
1818 ct
->referenceResolving();
1820 applyAttributeRestriction(ct
);
1821 basefield
->mode
= restrictionMode
;
1822 if (ct
->cmode
== CT_complextype_mode
) {
1823 applyReference(*ct
, true);
1824 type
.upload(ct
->getName().convertedValue
);
1825 basefield
->setInvisible();
1826 } else if (ct
->basefield
!= NULL
) {
1827 basefield
->applyReference(*ct
->basefield
);
1828 addNameSpaceAsVariant(basefield
, ct
->basefield
);
1829 } else if (ct
->basefield
== NULL
) {
1830 basefield
->applyReference(*ct
);
1831 addNameSpaceAsVariant(basefield
, ct
);
1834 if (!st
->getReference().empty() && !st
->getReference().is_resolved()) {
1835 st
->referenceResolving();
1837 if(xsdtype
== n_simpleContent
){
1838 basefield
->applyReference(*st
, true);
1839 addNameSpaceAsVariant(basefield
, st
);
1840 basefield
->mode
= restrictionMode
;
1841 }else if(xsdtype
== n_simpleType
){
1842 basefield
->setInvisible();
1843 applyReference(*basefield
, true);
1844 applyReference(*st
, true);
1845 addNameSpaceAsVariant(this, st
);
1846 basefield
->mode
= restrictionMode
;
1849 } else if (mode
== restrictionMode
&& cmode
== CT_simpletype_mode
&& basefield
!= NULL
) {
1850 ComplexType
* ct
= (ComplexType
*) TTCN3ModuleInventory::getInstance().lookup(basefield
, want_CT
);
1851 if (ct
== NULL
&& !isBuiltInType(basefield
->getType().convertedValue
)) {
1852 printError(module
->getSchemaname(), name
.convertedValue
,
1853 "Reference for a non-defined type: " + basefield
->getReference().repr());
1854 TTCN3ModuleInventory::getInstance().incrNumErrors();
1858 basefield
->outside_reference
.set_resolved(ct
);
1860 if (ct
->resolved
== No
) {
1861 ct
->referenceResolving();
1863 for (List
<AttributeType
*>::iterator f
= ct
->attribfields
.begin(); f
; f
= f
->Next
) {
1864 AttributeType
* attr
= new AttributeType(*f
->Data
);
1865 attribfields
.push_back(attr
);
1866 setParent(this, attr
);
1868 addNameSpaceAsVariant(this, ct
);
1870 if(!basefield
->parent
->top
){
1871 applyReference(*basefield
, true);
1872 basefield
->setInvisible();
1877 void ComplexType::resolveComplexTypeExtension() {
1878 if (mode
== extensionMode
&& cmode
== CT_complextype_mode
&& !outside_reference
.empty()) {
1879 ComplexType
* ct
= (ComplexType
*) TTCN3ModuleInventory::getInstance().lookup(this, want_CT
);
1881 printError(module
->getSchemaname(), name
.convertedValue
,
1882 "Reference for a non-defined type: " + getReference().repr());
1883 TTCN3ModuleInventory::getInstance().incrNumErrors();
1886 if(ct
->getXsdtype() != n_NOTSET
){
1887 outside_reference
.set_resolved(ct
);
1888 if (ct
->resolved
== No
) {
1889 ct
->referenceResolving();
1891 List
<AttributeType
*>::iterator anyAttr
= attribfields
.begin();
1892 for (; anyAttr
; anyAttr
= anyAttr
->Next
) {
1893 if (anyAttr
->Data
->isAnyAttribute()) {
1898 if (anyAttr
!= NULL
) {
1899 applyAttributeExtension(ct
, anyAttr
->Data
);
1901 applyAttributeExtension(ct
);
1904 if (ct
->getName().convertedValue
== outside_reference
.get_val() && ct
->getModule()->getTargetNamespace() == outside_reference
.get_uri()) {
1906 outside_reference
.set_resolved(ct
);
1907 for (List
<ComplexType
*>::iterator f
= ct
->complexfields
.end(); f
; f
= f
->Prev
) {
1908 if (f
->Data
!= this) { //not a self recursive field
1909 ComplexType
* newField
= new ComplexType(*f
->Data
);
1910 complexfields
.push_front(newField
);
1911 setParent(this, newField
);
1913 //Self recursive field
1914 ComplexType
* field
= new ComplexType(this);
1915 field
->name
.upload(f
->Data
->getName().convertedValue
);
1916 field
->applyReference(*f
->Data
);
1917 field
->type
.upload(ct
->getName().convertedValue
+ Mstring(".") + f
->Data
->getName().convertedValue
);
1918 field
->type
.no_replace
= true;
1919 field
->minOccurs
= f
->Data
->minOccurs
;
1920 field
->maxOccurs
= f
->Data
->maxOccurs
;
1921 complexfields
.push_front(field
);
1922 setParent(this, field
);
1927 for (List
<ComplexType
*>::iterator f
= ct
->complexfields
.end(); f
; f
= f
->Prev
) {
1928 ComplexType
* newField
= new ComplexType(*f
->Data
);
1929 complexfields
.push_front(newField
);
1930 setParent(this, newField
);
1937 void ComplexType::resolveComplexTypeRestriction() {
1938 if (mode
== restrictionMode
&& cmode
== CT_complextype_mode
&& !outside_reference
.empty()) {
1939 ComplexType
* ct
= (ComplexType
*) TTCN3ModuleInventory::getInstance().lookup(this, want_CT
);
1940 if(ct
->getXsdtype() != n_NOTSET
){
1941 if (ct
->resolved
== No
) {
1942 ct
->referenceResolving();
1944 outside_reference
.set_resolved(ct
);
1945 applyAttributeRestriction(ct
);
1947 size_t size
= complexfields
.size();
1949 List
<ComplexType
*>::iterator field
= complexfields
.begin();
1950 for (; i
< size
; field
= field
->Next
, i
= i
+ 1){
1951 List
<ComplexType
*>::iterator field2
= ct
->complexfields
.begin();
1952 for (; field2
; field2
= field2
->Next
) {
1953 if (field
->Data
->getName().convertedValue
== field2
->Data
->getName().convertedValue
&&
1954 field
->Data
->getType().convertedValue
== field2
->Data
->getType().convertedValue
) {
1955 field
->Data
->applyReference(*field2
->Data
, false);
1960 field
->Data
->setInvisible();
1967 void ComplexType::resolveUnion(SimpleType
*st
) {
1968 if (parent
!= NULL
&& parent
->with_union
&& xsdtype
== n_simpleType
&& !outside_reference
.empty()) {
1969 if (st
->getXsdtype() != n_NOTSET
) {
1970 ComplexType
* ct
= (ComplexType
*) st
;
1971 outside_reference
.set_resolved(ct
);
1972 for (List
<ComplexType
*>::iterator field
= ct
->complexfields
.begin(); field
; field
= field
->Next
) {
1973 ComplexType
* newField
= new ComplexType(*field
->Data
);
1974 parent
->complexfields
.push_back(newField
);
1975 setParent(parent
, newField
);
1982 void ComplexType::modifyAttributeParent() {
1983 if (nillable_field
!= NULL
) {
1984 ((ComplexType
*) nillable_field
)->actfield
= nillable_field
;
1990 //Element substitution
1991 void ComplexType::addSubstitution(SimpleType
* st
){
1992 ComplexType
* element
;
1993 if(st
->getXsdtype() == n_NOTSET
|| !complexfields
.empty()){
1994 element
= new ComplexType(*st
, fromTagSubstitution
);
1996 element
= new ComplexType(*(ComplexType
*)st
);
1997 element
->variant
.clear();
1999 element
->subsGroup
= this;
2000 element
->parent
= this;
2001 if(complexfields
.empty()){ //The first element(head) is the st
2002 element
->setTypeValue(st
->getType().convertedValue
);
2003 if(st
->hasVariant(Mstring("\"abstract\""))){
2004 element
->addVariant(V_abstract
);
2006 if(st
->getReference().get_ref() != NULL
){
2007 ((SimpleType
*)st
->getReference().get_ref())->addToNameDepList(element
);
2008 nameDep
= ((SimpleType
*)st
->getReference().get_ref());
2010 module
->addElementType(element
->getType().convertedValue
, element
);
2011 element
->addVariant(V_formAs
, Mstring("qualified"));
2014 if(st
->getType().convertedValue
== "anyType"){
2015 newType
= complexfields
.front()->getType().convertedValue
;
2017 newType
= st
->getName().convertedValue
;
2018 st
->addToNameDepList(element
);
2019 element
->nameDep
= st
;
2021 element
->setTypeValue(newType
);
2022 BlockValue front_block
= complexfields
.front()->getBlock();
2023 if(front_block
== all
|| front_block
== substitution
){
2024 element
->addVariant(V_block
);
2025 }else if(front_block
== restriction
|| front_block
== extension
){
2026 const Mstring
& head_type
= complexfields
.front()->getType().convertedValue
.getValueWithoutPrefix(':');
2027 //To decide if they came from a common ancestor
2028 Mstring elem_type
= findRoot(front_block
, st
, head_type
, true);
2029 if(head_type
== elem_type
){
2030 element
->addVariant(V_block
);
2035 element
->setNameValue(st
->getName().convertedValue
);
2036 element
->top
= false;
2037 complexfields
.push_back(element
);
2040 void ComplexType::addTypeSubstitution(SimpleType
* st
){
2041 ComplexType
* element
;
2042 if(st
->getXsdtype() == n_NOTSET
|| !complexfields
.empty()){
2043 element
= new ComplexType(*st
, fromTypeSubstitution
);
2045 //Only need a plain complextype
2047 element
= new ComplexType(this);
2048 //Just the block needed from st
2049 element
->block
= st
->getBlock();
2051 st
->addToNameDepList(element
);
2052 element
->nameDep
= st
;
2053 element
->typeSubsGroup
= this;
2054 element
->parent
= this;
2055 if(complexfields
.empty()){ //The first element(head) is the st
2056 if(st
->hasVariant(Mstring("\"abstract\""))){
2057 element
->addVariant(V_abstract
);
2060 BlockValue front_block
= complexfields
.front()->getBlock();
2061 if(front_block
== all
){
2062 element
->addVariant(V_block
);
2063 }else if(front_block
== restriction
|| front_block
== extension
){
2064 const Mstring
& head_type
= complexfields
.front()->getType().convertedValue
.getValueWithoutPrefix(':');
2065 //To decide if they came from a common ancestor
2066 Mstring elem_type
= findRoot(front_block
, st
, head_type
, true);
2067 if(head_type
== elem_type
){
2068 element
->addVariant(V_block
);
2072 //Cascading to parent type substitution
2073 if(parentTypeSubsGroup
!= NULL
&& !complexfields
.empty()){
2074 parentTypeSubsGroup
->addTypeSubstitution(st
);
2076 element
->top
= false;
2077 complexfields
.push_back(element
);
2078 element
->setTypeValue(st
->getName().convertedValue
.getValueWithoutPrefix(':'));
2079 element
->setNameValue(st
->getName().convertedValue
.getValueWithoutPrefix(':'));
2082 Mstring
ComplexType::findRoot(const BlockValue block_value
, SimpleType
* elem
, const Mstring
& head_type
, const bool first
){
2083 const Mstring elemName
= elem
->getName().convertedValue
.getValueWithoutPrefix(':');
2084 const Mstring elemType
= elem
->getType().convertedValue
.getValueWithoutPrefix(':');
2086 if(!first
&& !isFromRef() && elemType
== head_type
){
2088 }else if((isFromRef() &&
2089 ((elem
->getMode() == restrictionMode
&& block_value
== restriction
) ||
2090 (elem
->getMode() == extensionMode
&& block_value
== extension
))) && elemType
== head_type
){
2092 }else if(!first
&& elemName
== head_type
){
2095 SimpleType
* st
= NULL
;
2096 if((elem
->getMode() == restrictionMode
&& block_value
== restriction
) ||
2097 (elem
->getMode() == extensionMode
&& block_value
== extension
)){
2098 if(!elem
->getReference().is_resolved()){
2099 elem
->referenceResolving();
2101 if(elem
->getXsdtype() != n_NOTSET
){
2102 ComplexType
* ct
= (ComplexType
*)elem
;
2103 if(ct
->basefield
!= NULL
&& ct
->basefield
->getType().convertedValue
.getValueWithoutPrefix(':') == head_type
){
2105 }else if(ct
->basefield
!= NULL
){
2106 st
= (SimpleType
*)TTCN3ModuleInventory::getInstance().lookup(ct
->basefield
, want_BOTH
);
2110 st
= (SimpleType
*)(elem
->getReference().get_ref());
2112 }else if(elem
->getMode() == noMode
&& (block_value
== restriction
|| block_value
== extension
)){
2113 st
= (SimpleType
*)TTCN3ModuleInventory::getInstance().lookup(this, elem
->getType().convertedValue
, want_BOTH
);
2115 if(st
!= NULL
&& elem
!= st
){
2116 return findRoot(block_value
, st
, head_type
, false);
2119 if(elem
->getMode() == noMode
&& !first
){
2122 return empty_string
;