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
14 ******************************************************************************/
15 #ifndef TTCN3MODULE_HH_
16 #define TTCN3MODULE_HH_
18 #include "XMLParser.hh"
19 #include "GeneralTypes.hh"
20 #include "GeneralFunctions.hh"
21 #include "TTCN3ModuleInventory.hh"
23 class TTCN3ModuleInventory;
26 //Used only in type substitution, when we have to change the type or a builtintype
27 //due to type substitution
28 struct typeNameDepList {
30 List<SimpleType*> nameDepList;
31 //Used only with builtInTypes
32 ComplexType* typeSubsGroup;
36 * Type that contains information about one TTCN-3 module
37 * and performs the generation of that module
39 * Types defined in the module are stored in a list
44 * this module is connected with this parser object
46 XMLParser * parser; // no responsibility for this member
49 * Name of the XML schema that this module is originating from
53 * Name of the TTCN-3 module (derived from targetNamespace)
57 * contains all main types defined in the module
59 List<RootType*>definedTypes;
61 * Type of the currently processed main type
63 ConstructType actualXsdConstruct;
66 * Attribute values of XML declaration
72 * Attribute values of <schema> tag
74 Mstring targetNamespace;
75 Mstring targetNamespace_connectedPrefix;
76 List<NamespaceType> declaredNamespaces;
77 FormValue elementFormDefault;
78 FormValue attributeFormDefault;
79 BlockValue blockDefault;
81 List<const TTCN3Module*> importedModules; // pointers not owned
83 //Used only in type substitution, stores every possibly substituted type definitions
84 List<ComplexType*> storedTypeSubstitutions; //pointers not owned
86 //Used only in type substitution, stores every element that references a type
87 List<typeNameDepList> element_types;
89 List<Mstring> variant;
91 bool moduleNotIntoFile;
92 bool moduleNotIntoNameConversion;
94 TTCN3Module & operator=(const TTCN3Module &); // not implemented
95 TTCN3Module(const TTCN3Module &); // not implemented
97 TTCN3Module(const char * a_filename, XMLParser * a_parser);
100 void goodbyeParser() {
104 void loadValuesFromXMLDeclaration(const char *a_version,
105 const char *a_encoding, int a_standalone);
106 void loadValuesFromSchemaTag(const Mstring& a_targetNamespace, List<NamespaceType> declaredNamespaces,
107 FormValue a_elementFormDefault,
108 FormValue a_attributeFormDefault,
109 BlockValue a_blockDefault);
111 void generate_TTCN3_fileinfo(FILE * file);
112 void generate_TTCN3_modulestart(FILE * file);
113 void generate_TTCN3_included_types(FILE * file);
114 void generate_TTCN3_import_statements(FILE * file);
115 void generate_TTCN3_types(FILE * file);
116 void generate_with_statement(FILE * file, List<NamespaceType> used_namespaces);
118 const Mstring & getSchemaname() const {
122 const Mstring & getTargetNamespace() const {
123 return targetNamespace;
126 const Mstring & getTargetNamespaceConnector() const {
127 return targetNamespace_connectedPrefix;
130 const Mstring & getModulename() const {
134 void setSchemaname(const Mstring& name) {
138 void setTargetNamespace(const Mstring& tns) {
139 targetNamespace = tns;
142 FormValue getElementFormDefault() const {
143 return elementFormDefault;
146 void setElementFormDefault(FormValue value) {
147 elementFormDefault = value;
150 FormValue getAttributeFormDefault() const {
151 return attributeFormDefault;
154 void setAttributeFormDefault(FormValue value) {
155 attributeFormDefault = value;
158 BlockValue getBlockDefault() const {
162 ConstructType getActualXsdConstruct() const {
163 return actualXsdConstruct;
166 void setActualXsdConstruct(ConstructType c) {
167 actualXsdConstruct = c;
170 void addAnnotation();
171 void addMainType(const ConstructType typeOfMainType);
172 void addMainType(RootType * type){ definedTypes.push_back(type); }
174 bool hasDefinedMainType() const {
175 return !definedTypes.empty();
177 void replaceLastMainType(RootType * t);
179 const List<RootType*> & getDefinedTypes() const {
183 RootType & getLastMainType() {
184 return *definedTypes.back();
187 bool isnotIntoNameConversion() const {
188 return moduleNotIntoNameConversion;
191 void notIntoNameConversion() {
192 moduleNotIntoNameConversion = true;
195 bool isnotIntoFile() const {
196 return moduleNotIntoFile;
200 moduleNotIntoFile = true;
203 const List<NamespaceType> & getDeclaredNamespaces() const {
204 return declaredNamespaces;
207 void addImportedModule(const TTCN3Module *mod) {
208 importedModules.push_back(mod);
211 const List<const TTCN3Module*> & getImportedModules() const {
212 return importedModules;
215 List<ComplexType*> & getStoredTypeSubstitutions() {
216 return storedTypeSubstitutions;
219 void addStoredTypeSubstitution(ComplexType * type){
220 storedTypeSubstitutions.push_back(type);
223 List<typeNameDepList> & getElementTypes() {
224 return element_types;
227 void addElementType(const Mstring& type, SimpleType* st) {
228 List<typeNameDepList>::iterator it = element_types.begin();
229 for(; it; it = it->Next){
230 if(it->Data.type == type && st != NULL){
231 it->Data.nameDepList.push_back(st);
235 //New type that has not been in the element_types before
237 typeNameDepList list;
239 list.typeSubsGroup = NULL;
241 list.nameDepList.push_back(st);
243 element_types.push_back(list);
247 /// Compute the TTCN-3 module name
248 void TargetNamespace2ModuleName();
250 friend bool compareModules(TTCN3Module * lhs, TTCN3Module * rhs);
255 inline bool compareModules(TTCN3Module * lhs, TTCN3Module * rhs) {
256 return lhs->targetNamespace < rhs->targetNamespace;
259 #endif /* TTCN3MODULECONTAINER_HH_ */