1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 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 #ifndef TTCN3MODULE_HH_
9 #define TTCN3MODULE_HH_
11 #include "XMLParser.hh"
12 #include "GeneralTypes.hh"
13 #include "GeneralFunctions.hh"
14 #include "TTCN3ModuleInventory.hh"
16 class TTCN3ModuleInventory;
19 //Used only in type substitution, when we have to change the type or a builtintype
20 //due to type substitution
21 struct typeNameDepList {
23 List<SimpleType*> nameDepList;
24 //Used only with builtInTypes
25 ComplexType* typeSubsGroup;
29 * Type that contains information about one TTCN-3 module
30 * and performs the generation of that module
32 * Types defined in the module are stored in a list
37 * this module is connected with this parser object
39 XMLParser * parser; // no responsibility for this member
42 * Name of the XML schema that this module is originating from
46 * Name of the TTCN-3 module (derived from targetNamespace)
50 * contains all main types defined in the module
52 List<RootType*>definedTypes;
54 * Type of the currently processed main type
56 ConstructType actualXsdConstruct;
59 * Attribute values of XML declaration
65 * Attribute values of <schema> tag
67 Mstring targetNamespace;
68 Mstring targetNamespace_connectedPrefix;
69 List<NamespaceType> declaredNamespaces;
70 FormValue elementFormDefault;
71 FormValue attributeFormDefault;
72 BlockValue blockDefault;
74 List<const TTCN3Module*> importedModules; // pointers not owned
76 //Used only in type substitution, stores every possibly substituted type definitions
77 List<ComplexType*> storedTypeSubstitutions; //pointers not owned
79 //Used only in type substitution, stores every element that references a type
80 List<typeNameDepList> element_types;
82 List<Mstring> variant;
84 bool moduleNotIntoFile;
85 bool moduleNotIntoNameConversion;
87 TTCN3Module & operator=(const TTCN3Module &); // not implemented
88 TTCN3Module(const TTCN3Module &); // not implemented
90 TTCN3Module(const char * a_filename, XMLParser * a_parser);
93 void goodbyeParser() {
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);
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);
112 const Mstring & getSchemaname() const {
116 const Mstring & getTargetNamespace() const {
117 return targetNamespace;
120 const Mstring & getTargetNamespaceConnector() const {
121 return targetNamespace_connectedPrefix;
124 const Mstring & getModulename() const {
128 void setSchemaname(const Mstring& name) {
132 void setTargetNamespace(const Mstring& tns) {
133 targetNamespace = tns;
136 FormValue getElementFormDefault() const {
137 return elementFormDefault;
140 void setElementFormDefault(FormValue value) {
141 elementFormDefault = value;
144 FormValue getAttributeFormDefault() const {
145 return attributeFormDefault;
148 void setAttributeFormDefault(FormValue value) {
149 attributeFormDefault = value;
152 BlockValue getBlockDefault() const {
156 ConstructType getActualXsdConstruct() const {
157 return actualXsdConstruct;
160 void setActualXsdConstruct(ConstructType c) {
161 actualXsdConstruct = c;
164 void addAnnotation();
165 void addMainType(const ConstructType typeOfMainType);
166 void addMainType(RootType * type){ definedTypes.push_back(type); }
168 bool hasDefinedMainType() const {
169 return !definedTypes.empty();
171 void replaceLastMainType(RootType * t);
173 const List<RootType*> & getDefinedTypes() const {
177 RootType & getLastMainType() {
178 return *definedTypes.back();
181 bool isnotIntoNameConversion() const {
182 return moduleNotIntoNameConversion;
185 void notIntoNameConversion() {
186 moduleNotIntoNameConversion = true;
189 bool isnotIntoFile() const {
190 return moduleNotIntoFile;
194 moduleNotIntoFile = true;
197 const List<NamespaceType> & getDeclaredNamespaces() const {
198 return declaredNamespaces;
201 void addImportedModule(const TTCN3Module *mod) {
202 importedModules.push_back(mod);
205 const List<const TTCN3Module*> & getImportedModules() const {
206 return importedModules;
209 List<ComplexType*> & getStoredTypeSubstitutions() {
210 return storedTypeSubstitutions;
213 void addStoredTypeSubstitution(ComplexType * type){
214 storedTypeSubstitutions.push_back(type);
217 List<typeNameDepList> & getElementTypes() {
218 return element_types;
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);
229 //New type that has not been in the element_types before
231 typeNameDepList list;
233 list.typeSubsGroup = NULL;
235 list.nameDepList.push_back(st);
237 element_types.push_back(list);
241 /// Compute the TTCN-3 module name
242 void TargetNamespace2ModuleName();
244 friend bool compareModules(TTCN3Module * lhs, TTCN3Module * rhs);
249 inline bool compareModules(TTCN3Module * lhs, TTCN3Module * rhs) {
250 return lhs->targetNamespace < rhs->targetNamespace;
253 #endif /* TTCN3MODULECONTAINER_HH_ */