msganalyzer.h Source File

NEDXML API: msganalyzer.h Source File
NEDXML API
msganalyzer.h
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
32namespace omnetpp {
33namespace nedxml {
34
41class NEDXML_API MsgAnalyzer
42{
43 public:
44 typedef std::set<std::string> StringSet;
45 typedef std::vector<std::string> StringVector;
46 typedef MsgTypeTable::Property Property;
47 typedef MsgTypeTable::Properties Properties;
48 typedef MsgTypeTable::FieldInfo FieldInfo;
49 typedef MsgTypeTable::ClassInfo ClassInfo;
50 typedef MsgTypeTable::EnumItem EnumItem;
51
52 public:
53 static const StringSet RESERVED_WORDS;
54
55 protected:
56 ErrorStore *errors;
57 MsgTypeTable *typeTable;
58 const MsgCompilerOptions& opts;
59
60 protected:
61 void extractFields(ClassInfo& classInfo);
62 void analyzeClassOrStruct(ClassInfo& classInfo, const std::string& namespaceName);
63 void analyzeFields(ClassInfo& classInfo, const std::string& namespaceName);
64 void analyzeField(ClassInfo& classInfo, FieldInfo *field, const std::string& namespaceName);
65 void analyzeInheritedField(ClassInfo& classInfo, FieldInfo *field);
66 std::string prefixWithNamespace(const std::string& name, const std::string& namespaceName);
67 Properties extractProperties(ASTNode *node);
68 bool hasSuperclass(ClassInfo& classInfo, const std::string& superclassQName);
69 FieldInfo *findField(ClassInfo& classInfo, const std::string& name);
70 FieldInfo *findSuperclassField(ClassInfo& classInfo, const std::string& fieldName);
71 bool hasProperty(const Properties& p, const char *name) {return p.get(name) != nullptr;}
72 bool getPropertyAsBool(const Properties& p, const char *name, bool defval);
73 std::string getProperty(const Properties& p, const char *name, const std::string& defval = std::string());
74 std::string getMethodProperty(const Properties& props, const char *propName, bool existingClass);
75 std::string decorateType(const std::string& typeName, bool isConst, bool isPointer, bool isRef);
76 std::string makeRelative(const std::string& qname, const std::string& namespaceName);
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 ClassInfo extractEnumInfo(ASTNode *node, const std::string& namespaceName);
87 Property extractProperty(PropertyElement *propertyElem);
88 void validateFileProperty(const Property& property);
89 void analyzeCplusplusBlockTarget(CplusplusElement *cppElem, const std::string& currentNamespace);
90
91 public:
92 static constexpr const char* ATT_NAME = "name";
93 static constexpr const char* ATT_EXTENDS_NAME = "extends-name";
94
95 static constexpr const char* PROP_PROPERTY = "property";
96 static constexpr const char* PROP_ABSTRACT = "abstract";
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_POLYMORPHIC = "polymorphic";
104 static constexpr const char* PROP_CLASS = "class";
105 static constexpr const char* PROP_BASETYPE = "baseType";
106 static constexpr const char* PROP_DEFAULTVALUE = "defaultValue";
107 static constexpr const char* PROP_CPPTYPE = "cppType";
108 static constexpr const char* PROP_DATAMEMBERTYPE = "datamemberType";
109 static constexpr const char* PROP_ARGTYPE = "argType";
110 static constexpr const char* PROP_RETURNTYPE = "returnType";
111 static constexpr const char* PROP_TOSTRING = "toString";
112 static constexpr const char* PROP_FROMSTRING = "fromString";
113 static constexpr const char* PROP_TOVALUE = "toValue";
114 static constexpr const char* PROP_FROMVALUE = "fromValue";
115 static constexpr const char* PROP_GETTERCONVERSION = "getterConversion";
116 static constexpr const char* PROP_CLONE = "clone";
117 static constexpr const char* PROP_EXISTINGCLASS = "existingClass";
118 static constexpr const char* PROP_DESCRIPTOR = "descriptor";
119 static constexpr const char* PROP_CASTFUNCTION = "castFunction";
120 static constexpr const char* PROP_OMITGETVERB = "omitGetVerb";
121 static constexpr const char* PROP_FIELDNAMESUFFIX = "fieldNameSuffix";
122 static constexpr const char* PROP_BEFORECHANGE = "beforeChange";
123 static constexpr const char* PROP_IMPLEMENTS = "implements";
124 static constexpr const char* PROP_NOPACK = "nopack";
125 static constexpr const char* PROP_OWNED = "owned";
126 static constexpr const char* PROP_EDITABLE = "editable";
127 static constexpr const char* PROP_REPLACEABLE = "replaceable";
128 static constexpr const char* PROP_RESIZABLE = "resizable";
129 static constexpr const char* PROP_READONLY = "readonly";
130 static constexpr const char* PROP_OVERRIDEGETTER = "overrideGetter";
131 static constexpr const char* PROP_OVERRIDESETTER = "overrideSetter";
132 static constexpr const char* PROP_ENUM = "enum";
133 static constexpr const char* PROP_SIZETYPE = "sizeType";
134 static constexpr const char* PROP_SETTER = "setter";
135 static constexpr const char* PROP_GETTER = "getter";
136 static constexpr const char* PROP_GETTERFORUPDATE = "getterForUpdate";
137 static constexpr const char* PROP_SIZESETTER = "sizeSetter";
138 static constexpr const char* PROP_SIZEGETTER = "sizeGetter";
139 static constexpr const char* PROP_INSERTER = "inserter";
140 static constexpr const char* PROP_APPENDER = "appender";
141 static constexpr const char* PROP_ERASER = "eraser";
142 static constexpr const char* PROP_REMOVER = "remover";
143 static constexpr const char* PROP_ALLOWREPLACE = "allowReplace";
144 static constexpr const char* PROP_STR = "str";
145 static constexpr const char* PROP_CUSTOMIZE = "customize";
146 static constexpr const char* PROP_OVERWRITEPREVIOUSDEFINITION = "overwritePreviousDefinition";
147 static constexpr const char* PROP_CUSTOM = "custom";
148 static constexpr const char* PROP_CUSTOMIMPL = "customImpl";
149};
150
151} // namespace nedxml
152} // namespace omnetpp
153
154
155#endif
156
157
Definition astnode.h:88
Definition errorstore.h:38
Definition msgtypetable.h:40
Options for MsgCompiler.
Definition msgcompileroptions.h:33