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