Commit | Line | Data |
---|---|---|
970ed795 | 1 | /////////////////////////////////////////////////////////////////////////////// |
3abe9331 | 2 | // Copyright (c) 2000-2015 Ericsson Telecom AB |
970ed795 EL |
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 TTCN3MODULE_HH_ | |
9 | #define TTCN3MODULE_HH_ | |
10 | ||
11 | #include "XMLParser.hh" | |
12 | #include "GeneralTypes.hh" | |
3abe9331 | 13 | #include "GeneralFunctions.hh" |
14 | #include "TTCN3ModuleInventory.hh" | |
970ed795 EL |
15 | |
16 | class TTCN3ModuleInventory; | |
17 | class RootType; | |
18 | ||
51fa56b9 | 19 | //Used only in type substitution, when we have to change the type or a builtintype |
20 | //due to type substitution | |
21 | struct typeNameDepList { | |
22 | Mstring type; | |
23 | List<SimpleType*> nameDepList; | |
24 | //Used only with builtInTypes | |
25 | ComplexType* typeSubsGroup; | |
26 | }; | |
27 | ||
970ed795 EL |
28 | /** |
29 | * Type that contains information about one TTCN-3 module | |
30 | * and performs the generation of that module | |
31 | * | |
32 | * Types defined in the module are stored in a list | |
33 | * | |
34 | */ | |
3abe9331 | 35 | class TTCN3Module { |
970ed795 EL |
36 | /** |
37 | * this module is connected with this parser object | |
38 | */ | |
39 | XMLParser * parser; // no responsibility for this member | |
40 | ||
41 | /** | |
42 | * Name of the XML schema that this module is originating from | |
43 | */ | |
44 | Mstring schemaname; | |
45 | /** | |
46 | * Name of the TTCN-3 module (derived from targetNamespace) | |
47 | */ | |
48 | Mstring modulename; | |
49 | /** | |
50 | * contains all main types defined in the module | |
51 | */ | |
52 | List<RootType*>definedTypes; | |
53 | /** | |
54 | * Type of the currently processed main type | |
55 | */ | |
56 | ConstructType actualXsdConstruct; | |
57 | ||
58 | /** | |
59 | * Attribute values of XML declaration | |
60 | */ | |
61 | Mstring xsdVersion; | |
62 | Mstring xsdEncoding; | |
63 | int xsdStandalone; | |
64 | /** | |
65 | * Attribute values of <schema> tag | |
66 | */ | |
67 | Mstring targetNamespace; | |
68 | Mstring targetNamespace_connectedPrefix; | |
69 | List<NamespaceType> declaredNamespaces; | |
70 | FormValue elementFormDefault; | |
71 | FormValue attributeFormDefault; | |
3abe9331 | 72 | BlockValue blockDefault; |
970ed795 EL |
73 | |
74 | List<const TTCN3Module*> importedModules; // pointers not owned | |
75 | ||
51fa56b9 | 76 | //Used only in type substitution, stores every possibly substituted type definitions |
77 | List<ComplexType*> storedTypeSubstitutions; //pointers not owned | |
78 | ||
79 | //Used only in type substitution, stores every element that references a type | |
80 | List<typeNameDepList> element_types; | |
81 | ||
970ed795 EL |
82 | List<Mstring> variant; |
83 | ||
84 | bool moduleNotIntoFile; | |
85 | bool moduleNotIntoNameConversion; | |
86 | ||
3abe9331 | 87 | TTCN3Module & operator=(const TTCN3Module &); // not implemented |
88 | TTCN3Module(const TTCN3Module &); // not implemented | |
970ed795 | 89 | public: |
3abe9331 | 90 | TTCN3Module(const char * a_filename, XMLParser * a_parser); |
91 | ~TTCN3Module(); | |
92 | ||
93 | void goodbyeParser() { | |
94 | parser = 0; | |
95 | } | |
96 | ||
97 | void loadValuesFromXMLDeclaration(const char *a_version, | |
98 | const char *a_encoding, int a_standalone); | |
99 | void loadValuesFromSchemaTag(const Mstring& a_targetNamespace, List<NamespaceType> declaredNamespaces, | |
100 | FormValue a_elementFormDefault, | |
101 | FormValue a_attributeFormDefault, | |
102 | BlockValue a_blockDefault); | |
103 | ||
104 | void generate_TTCN3_header(FILE * file); | |
105 | void generate_TTCN3_fileinfo(FILE * file); | |
106 | void generate_TTCN3_modulestart(FILE * file); | |
107 | void generate_TTCN3_included_types(FILE * file); | |
108 | void generate_TTCN3_import_statements(FILE * file); | |
109 | void generate_TTCN3_types(FILE * file); | |
110 | void generate_with_statement(FILE * file, List<NamespaceType> used_namespaces); | |
111 | ||
112 | const Mstring & getSchemaname() const { | |
113 | return schemaname; | |
114 | } | |
115 | ||
116 | const Mstring & getTargetNamespace() const { | |
117 | return targetNamespace; | |
118 | } | |
119 | ||
120 | const Mstring & getTargetNamespaceConnector() const { | |
121 | return targetNamespace_connectedPrefix; | |
122 | } | |
123 | ||
124 | const Mstring & getModulename() const { | |
125 | return modulename; | |
126 | } | |
127 | ||
128 | void setSchemaname(const Mstring& name) { | |
129 | schemaname = name; | |
130 | } | |
131 | ||
132 | void setTargetNamespace(const Mstring& tns) { | |
133 | targetNamespace = tns; | |
134 | } | |
135 | ||
136 | FormValue getElementFormDefault() const { | |
137 | return elementFormDefault; | |
138 | } | |
139 | ||
140 | void setElementFormDefault(FormValue value) { | |
141 | elementFormDefault = value; | |
142 | } | |
143 | ||
144 | FormValue getAttributeFormDefault() const { | |
145 | return attributeFormDefault; | |
146 | } | |
147 | ||
148 | void setAttributeFormDefault(FormValue value) { | |
149 | attributeFormDefault = value; | |
150 | } | |
151 | ||
152 | BlockValue getBlockDefault() const { | |
153 | return blockDefault; | |
154 | } | |
155 | ||
156 | ConstructType getActualXsdConstruct() const { | |
157 | return actualXsdConstruct; | |
158 | } | |
159 | ||
160 | void setActualXsdConstruct(ConstructType c) { | |
161 | actualXsdConstruct = c; | |
162 | } | |
163 | ||
164 | void addAnnotation(); | |
165 | void addMainType(const ConstructType typeOfMainType); | |
166 | void addMainType(RootType * type){ definedTypes.push_back(type); } | |
167 | ||
168 | bool hasDefinedMainType() const { | |
169 | return !definedTypes.empty(); | |
170 | } | |
171 | void replaceLastMainType(RootType * t); | |
172 | ||
173 | const List<RootType*> & getDefinedTypes() const { | |
174 | return definedTypes; | |
175 | } | |
176 | ||
177 | RootType & getLastMainType() { | |
178 | return *definedTypes.back(); | |
179 | } | |
180 | ||
181 | bool isnotIntoNameConversion() const { | |
182 | return moduleNotIntoNameConversion; | |
183 | } | |
184 | ||
185 | void notIntoNameConversion() { | |
186 | moduleNotIntoNameConversion = true; | |
187 | } | |
188 | ||
189 | bool isnotIntoFile() const { | |
190 | return moduleNotIntoFile; | |
191 | } | |
192 | ||
193 | void notIntoFile() { | |
194 | moduleNotIntoFile = true; | |
195 | } | |
196 | ||
197 | const List<NamespaceType> & getDeclaredNamespaces() const { | |
198 | return declaredNamespaces; | |
199 | } | |
200 | ||
201 | void addImportedModule(const TTCN3Module *mod) { | |
202 | importedModules.push_back(mod); | |
203 | } | |
204 | ||
205 | const List<const TTCN3Module*> & getImportedModules() const { | |
206 | return importedModules; | |
207 | } | |
970ed795 | 208 | |
51fa56b9 | 209 | List<ComplexType*> & getStoredTypeSubstitutions() { |
210 | return storedTypeSubstitutions; | |
211 | } | |
212 | ||
213 | void addStoredTypeSubstitution(ComplexType * type){ | |
214 | storedTypeSubstitutions.push_back(type); | |
215 | } | |
216 | ||
217 | List<typeNameDepList> & getElementTypes() { | |
218 | return element_types; | |
219 | } | |
220 | ||
221 | void addElementType(const Mstring& type, SimpleType* st) { | |
222 | List<typeNameDepList>::iterator it = element_types.begin(); | |
223 | for(; it; it = it->Next){ | |
224 | if(it->Data.type == type && st != NULL){ | |
225 | it->Data.nameDepList.push_back(st); | |
226 | break; | |
227 | } | |
228 | } | |
229 | //New type that has not been in the element_types before | |
230 | if(it == NULL){ | |
231 | typeNameDepList list; | |
232 | list.type = type; | |
233 | list.typeSubsGroup = NULL; | |
234 | if(st != NULL){ | |
235 | list.nameDepList.push_back(st); | |
236 | } | |
237 | element_types.push_back(list); | |
238 | } | |
239 | } | |
240 | ||
970ed795 | 241 | /// Compute the TTCN-3 module name |
3abe9331 | 242 | void TargetNamespace2ModuleName(); |
970ed795 | 243 | |
3abe9331 | 244 | friend bool compareModules(TTCN3Module * lhs, TTCN3Module * rhs); |
970ed795 | 245 | |
3abe9331 | 246 | void dump() const; |
970ed795 EL |
247 | }; |
248 | ||
3abe9331 | 249 | inline bool compareModules(TTCN3Module * lhs, TTCN3Module * rhs) { |
970ed795 EL |
250 | return lhs->targetNamespace < rhs->targetNamespace; |
251 | } | |
252 | ||
253 | #endif /* TTCN3MODULECONTAINER_HH_ */ |