OMNeT++ NEDXML  5.4.1
msganalyzer.h
Go to the documentation of this file.
1 //==========================================================================
2 // MSGANALYZER.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_MSGANALYZER_H
18 #define __OMNETPP_NEDXML_MSGANALYZER_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 
31 namespace omnetpp {
32 namespace nedxml {
33 
34 struct MsgCompilerOptions;
35 
43 {
44  public:
45  typedef std::set<std::string> StringSet;
46  typedef std::vector<std::string> StringVector;
53 
54  public:
55  static StringSet RESERVED_WORDS;
56 
57  protected:
61 
62  protected:
63  void extractFields(ClassInfo& classInfo);
64  void analyzeClassOrStruct(ClassInfo& classInfo, const std::string& namespaceName);
65  void analyzeFields(ClassInfo& classInfo, const std::string& namespaceName);
66  void analyzeField(ClassInfo& classInfo, FieldInfo *field, const std::string& namespaceName);
67  void analyzeInheritedField(ClassInfo& classInfo, FieldInfo *field);
68  std::string prefixWithNamespace(const std::string& name, const std::string& namespaceName);
69  Properties extractProperties(ASTNode *node);
70  bool hasSuperclass(ClassInfo& classInfo, const std::string& superclassQName);
71  FieldInfo *findField(ClassInfo& classInfo, const std::string& name);
72  FieldInfo *findSuperclassField(ClassInfo& classInfo, const std::string& fieldName);
73  bool hasProperty(const Properties& p, const char *name) {return p.get(name) != nullptr;}
74  bool getPropertyAsBool(const Properties& p, const char *name, bool defval);
75  std::string getProperty(const Properties& p, const char *name, const std::string& defval = std::string());
76  std::string decorateType(const std::string& typeName, bool isConst, bool isPointer, bool isRef);
77  std::string lookupExistingClassName(const std::string& name, const std::string& contextNamespace, ClassInfo *contextClass=nullptr);
78  void validateProperty(const Property& property, const char *usage);
79 
80  public:
81  MsgAnalyzer(const MsgCompilerOptions& opts, MsgTypeTable *typeTable, ErrorStore *errors);
82  ~MsgAnalyzer();
83  ClassInfo extractClassInfo(ASTNode *node, const std::string& namespaceName, bool isImported); // accepts StructElement, ClassElement, MessageElement, PacketElement
84  void ensureAnalyzed(ClassInfo& classInfo);
85  void ensureFieldsAnalyzed(ClassInfo& classInfo);
86  EnumInfo extractEnumDecl(EnumDeclElement *node, const std::string& namespaceName);
87  EnumInfo extractEnumInfo(EnumElement *node, const std::string& namespaceName);
88  ClassInfo extractClassInfoFromEnum(EnumElement *node, const std::string& namespaceName, bool isImported);
89  Property extractProperty(PropertyElement *propertyElem);
90  void validateFileProperty(const Property& property);
91 
92  public:
93  static constexpr const char* ATT_NAME = "name";
94  static constexpr const char* ATT_EXTENDS_NAME = "extends-name";
95 
96  static constexpr const char* PROP_PROPERTY = "property";
97  static constexpr const char* PROP_ACTUALLY = "actually";
98  static constexpr const char* PROP_PRIMITIVE = "primitive";
99  static constexpr const char* PROP_OPAQUE = "opaque";
100  static constexpr const char* PROP_BYVALUE = "byValue";
101  static constexpr const char* PROP_SUPPORTSPTR = "supportsPtr";
102  static constexpr const char* PROP_SUBCLASSABLE = "subclassable";
103  static constexpr const char* PROP_DEFAULTVALUE = "defaultValue";
104  static constexpr const char* PROP_CPPTYPE = "cppType";
105  static constexpr const char* PROP_ARGTYPE = "argType";
106  static constexpr const char* PROP_RETURNTYPE = "returnType";
107  static constexpr const char* PROP_TOSTRING = "toString";
108  static constexpr const char* PROP_FROMSTRING = "fromString";
109  static constexpr const char* PROP_GETTERCONVERSION = "getterConversion";
110  static constexpr const char* PROP_CLONE = "clone";
111  static constexpr const char* PROP_EXISTINGCLASS = "existingClass";
112  static constexpr const char* PROP_DESCRIPTOR = "descriptor";
113  static constexpr const char* PROP_OMITGETVERB = "omitGetVerb";
114  static constexpr const char* PROP_FIELDNAMESUFFIX = "fieldNameSuffix";
115  static constexpr const char* PROP_BEFORECHANGE = "beforeChange";
116  static constexpr const char* PROP_IMPLEMENTS = "implements";
117  static constexpr const char* PROP_NOPACK = "nopack";
118  static constexpr const char* PROP_OWNED = "owned";
119  static constexpr const char* PROP_EDITABLE = "editable";
120  static constexpr const char* PROP_OVERRIDEGETTER = "overrideGetter";
121  static constexpr const char* PROP_OVERRIDESETTER = "overrideSetter";
122  static constexpr const char* PROP_ENUM = "enum";
123  static constexpr const char* PROP_SIZETYPE = "sizeType";
124  static constexpr const char* PROP_SETTER = "setter";
125  static constexpr const char* PROP_GETTER = "getter";
126  static constexpr const char* PROP_GETTERFORUPDATE = "getterForUpdate";
127  static constexpr const char* PROP_SIZESETTER = "sizeSetter";
128  static constexpr const char* PROP_SIZEGETTER = "sizeGetter";
129  static constexpr const char* PROP_INSERTER = "inserter";
130  static constexpr const char* PROP_ERASER = "eraser";
131  static constexpr const char* PROP_ALLOWREPLACE = "allowReplace";
132  static constexpr const char* PROP_STR = "str";
133  static constexpr const char* PROP_CUSTOMIZE = "customize";
134  static constexpr const char* PROP_OVERWRITEPREVIOUSDEFINITION = "overwritePreviousDefinition";
135 };
136 
137 } // namespace nedxml
138 } // namespace omnetpp
139 
140 
141 #endif
142 
143 
#define NEDXML_API
Definition: nedxmldefs.h:31
Definition: msgtypetable.h:42
std::vector< std::string > StringVector
Definition: msganalyzer.h:46
MsgTypeTable::ClassInfo ClassInfo
Definition: msganalyzer.h:50
Options for MsgCompiler.
Definition: msgcompiler.h:41
Part of the message compiler. Produces ClassInfo/EnumInfo objects from the ASTNode tree...
Definition: msganalyzer.h:42
const MsgCompilerOptions & opts
Definition: msganalyzer.h:60
MsgTypeTable::EnumInfo EnumInfo
Definition: msganalyzer.h:52
std::set< std::string > StringSet
Definition: msganalyzer.h:45
Definition: msgtypetable.h:74
static StringSet RESERVED_WORDS
Definition: msganalyzer.h:55
MsgTypeTable::Properties Properties
Definition: msganalyzer.h:48
MsgTypeTable::FieldInfo FieldInfo
Definition: msganalyzer.h:49
Definition: msgtypetable.h:139
MsgTypeTable * typeTable
Definition: msganalyzer.h:59
bool hasProperty(const Properties &p, const char *name)
Definition: msganalyzer.h:73
Definition: astbuilder.h:25
Definition: msgtypetable.h:62
ErrorStore * errors
Definition: msganalyzer.h:58
MsgTypeTable::Property Property
Definition: msganalyzer.h:47
Definition: msgtypetable.h:37
MsgTypeTable::EnumItem EnumItem
Definition: msganalyzer.h:51
Definition: astnode.h:75
Definition: errorstore.h:37
const Property * get(const std::string &name, const std::string &index="") const
Definition: msgtypetable.h:198
Definition: msgtypetable.h:207