OMNeT++ NEDXML  5.4.1
msgcompiler.h
Go to the documentation of this file.
1 //==========================================================================
2 // MSGCOMPILER.H - part of
3 //
4 // OMNeT++/OMNEST
5 // Discrete System Simulation in C++
6 //
7 //==========================================================================
8 
9 /*--------------------------------------------------------------*
10  Copyright (C) 2002-2017 Andras Varga
11  Copyright (C) 2006-2017 OpenSim Ltd.
12 
13  This file is distributed WITHOUT ANY WARRANTY. See the file
14  `license' for details on this and other legal matters.
15 *--------------------------------------------------------------*/
16 
17 #ifndef __OMNETPP_NEDXML_MSGCOMPILER_H
18 #define __OMNETPP_NEDXML_MSGCOMPILER_H
19 
20 #include <iostream>
21 #include <sstream>
22 #include <string>
23 #include <vector>
24 #include <map>
25 #include <set>
26 
27 #include "errorstore.h"
28 #include "msgelements.h"
29 #include "msgtypetable.h"
30 #include "msganalyzer.h"
31 #include "msgcodegenerator.h"
32 
33 namespace omnetpp {
34 namespace nedxml {
35 
42 {
43  std::vector<std::string> importPath;
44  std::string exportDef;
48 
50  generateClasses(true),
51  generateDescriptors(true),
52  generateSettersInDescriptors(true)
53  {}
54 };
55 
64 {
65  public:
66  typedef std::set<std::string> StringSet;
67  typedef std::vector<std::string> StringVector;
74 
75  protected:
80 
81  bool used = false;
83  StringSet importsSeen;
84  StringSet importedFiles;
85 
86  protected:
87  void importBuiltinDefinitions();
88  void processBuiltinImport(const char *txt, const char *fname);
89 
90  void processImport(ImportElement *importElem, const std::string& currentDir);
91  std::string resolveImport(const std::string& importName, const std::string& currentDir);
92  void collectTypes(MsgFileElement *fileElement, bool isImport);
93  void generateCode(MsgFileElement *fileElement);
94  std::string prefixWithNamespace(const std::string& name, const std::string& namespaceName);
95  void validateNamespaceName(const std::string& namespaceName, ASTNode *element);
96 
97  public:
101  MsgCompiler(const MsgCompilerOptions& options, ErrorStore *errors);
102 
106  ~MsgCompiler();
107 
112  void generate(MsgFileElement *fileElement, const char *hFile, const char *ccFile, StringSet& outImportedFiles);
113 
114  private:
115  static constexpr const char* ATT_NAME = "name";
116 };
117 
118 } // namespace nedxml
119 } // namespace omnetpp
120 
121 
122 #endif
123 
124 
Generates C++ code from a MSG file object tree.
Definition: msgcompiler.h:63
#define NEDXML_API
Definition: nedxmldefs.h:31
StringSet importedFiles
Definition: msgcompiler.h:84
Code generator part of the message compiler.
Definition: msgcodegenerator.h:40
Definition: msgtypetable.h:42
Options for MsgCompiler.
Definition: msgcompiler.h:41
std::string exportDef
Definition: msgcompiler.h:44
bool generateClasses
Definition: msgcompiler.h:45
Part of the message compiler. Produces ClassInfo/EnumInfo objects from the ASTNode tree...
Definition: msganalyzer.h:42
MsgCompilerOptions()
Definition: msgcompiler.h:49
MsgTypeTable::EnumItem EnumItem
Definition: msgcompiler.h:72
std::set< std::string > StringSet
Definition: msgcompiler.h:66
MsgTypeTable::EnumInfo EnumInfo
Definition: msgcompiler.h:73
ErrorStore * errors
Definition: msgcompiler.h:82
Definition: msgtypetable.h:74
bool generateSettersInDescriptors
Definition: msgcompiler.h:47
MsgTypeTable::ClassInfo ClassInfo
Definition: msgcompiler.h:71
bool generateDescriptors
Definition: msgcompiler.h:46
MsgTypeTable::FieldInfo FieldInfo
Definition: msgcompiler.h:70
MsgAnalyzer analyzer
Definition: msgcompiler.h:78
MsgTypeTable::Properties Properties
Definition: msgcompiler.h:69
Definition: msgtypetable.h:139
MsgTypeTable::Property Property
Definition: msgcompiler.h:68
StringSet importsSeen
Definition: msgcompiler.h:83
Definition: astbuilder.h:25
Definition: msgtypetable.h:62
std::vector< std::string > StringVector
Definition: msgcompiler.h:67
MsgTypeTable typeTable
Definition: msgcompiler.h:77
std::vector< std::string > importPath
Definition: msgcompiler.h:43
Definition: msgtypetable.h:37
Definition: astnode.h:75
Definition: errorstore.h:37
MsgCodeGenerator codegen
Definition: msgcompiler.h:79
Definition: msgtypetable.h:198
Definition: msgtypetable.h:207
MsgCompilerOptions opts
Definition: msgcompiler.h:76