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