Statistics
| Branch: | Revision:

root / src / nedxml / ned2generator.h @ 7c7d95e5

History | View | Annotate | Download (8.35 KB)

1
//==========================================================================
2
//  NEDGENERATOR.H - part of
3
//
4
//                     OMNeT++/OMNEST
5
//            Discrete System Simulation in C++
6
//
7
//==========================================================================
8

    
9
/*--------------------------------------------------------------*
10
  Copyright (C) 2002-2008 Andras Varga
11
  Copyright (C) 2006-2008 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 __NEDGENERATOR_H
18
#define __NEDGENERATOR_H
19

    
20
#include <iostream>
21
#include "nedelements.h"
22
#include "nederror.h"
23

    
24
NAMESPACE_BEGIN
25

    
26

    
27
/**
28
 * Simple front-end to NED2Generator.
29
 *
30
 * @ingroup NEDGenerator
31
 */
32
NEDXML_API void generateNED2(std::ostream& out, NEDElement *node, NEDErrorStore *e);
33

    
34
/**
35
 * Generates NED code from a NED object tree.
36
 * Assumes object tree has already passed all validation stages (DTD, syntax, semantic).
37
 *
38
 * @ingroup NEDGenerator
39
 */
40
class NEDXML_API NED2Generator
41
{
42
  protected:
43
    int indentsize;
44
    std::ostream *outp;
45
    NEDErrorStore *errors;
46

    
47
  public:
48
    /**
49
     * Constructor.
50
     */
51
    NED2Generator(NEDErrorStore *errors);
52

    
53
    /**
54
     * Destructor.
55
     */
56
    ~NED2Generator();
57

    
58
    /**
59
     * Sets the indent size in the generated NED code. Default is 4 spaces.
60
     */
61
    void setIndentSize(int indentsize);
62

    
63
    /**
64
     * Generates NED code. Takes an output stream where the generated NED code
65
     * will be written, the object tree and the base indentation.
66
     */
67
    void generate(std::ostream& out, NEDElement *node, const char *indent);
68

    
69
    /**
70
     * Generates NED code and returns it as a string.
71
     */
72
    std::string generate(NEDElement *node, const char *indent);
73

    
74
  protected:
75
    /** @name Change indentation level */
76
    //@{
77
    const char *increaseIndent(const char *indent);
78
    const char *decreaseIndent(const char *indent);
79
    //@}
80

    
81
    /** Dispatch to various doXXX() methods according to node type */
82
    void generateNedItem(NEDElement *node, const char *indent, bool islast, const char *arg=NULL);;
83

    
84
    /** Invoke generateNedItem() on all children */
85
    void generateChildren(NEDElement *node, const char *indent, const char *arg=NULL);
86

    
87
    /** Invoke generateNedItem() on all children of the given tagcode */
88
    void generateChildrenWithType(NEDElement *node, int tagcode, const char *indent, const char *arg=0);
89

    
90
    /** Invoke generateNedItem() on children of the given tagcodes (NED_NULL-terminated array) */
91
    void generateChildrenWithTypes(NEDElement *node, int tagcodes[], const char *indent, const char *arg=0);
92

    
93
    /** @name Utilities */
94
    //@{
95
    void printInheritance(NEDElement *node, const char *indent);
96
    bool hasExpression(NEDElement *node, const char *attr);
97
    void printExpression(NEDElement *node, const char *attr, const char *indent);
98
    void printOptVector(NEDElement *node, const char *attr, const char *indent);
99
    bool isEmptyChannelSpec(ChannelSpecElement *node);
100
    void doMsgClassOrStructBody(NEDElement *msgclassorstruct, const char *indent);
101
    //@}
102

    
103
    /** @name Getters for comments */
104
    //@{
105
    std::string concatInnerComments(NEDElement *node);
106
    std::string getBannerComment(NEDElement *node, const char *indent);
107
    std::string getRightComment(NEDElement *node);
108
    std::string getInlineRightComment(NEDElement *node);
109
    std::string getTrailingComment(NEDElement *node);
110
    //@}
111

    
112
    /** @name Generate NED code from the given element */
113
    //@{
114
    void doFiles(FilesElement *node, const char *indent, bool islast, const char *);
115
    void doNedFile(NedFileElement *node, const char *indent, bool islast, const char *);
116
    void doPackage(PackageElement *node, const char *indent, bool islast, const char *);
117
    void doImport(ImportElement *node, const char *indent, bool islast, const char *);
118
    void doPropertyDecl(PropertyDeclElement *node, const char *indent, bool islast, const char *);
119
    void doExtends(ExtendsElement *node, const char *indent, bool islast, const char *);
120
    void doInterfaceName(InterfaceNameElement *node, const char *indent, bool islast, const char *);
121
    void doSimpleModule(SimpleModuleElement *node, const char *indent, bool islast, const char *);
122
    void doModuleInterface(ModuleInterfaceElement *node, const char *indent, bool islast, const char *);
123
    void doCompoundModule(CompoundModuleElement *node, const char *indent, bool islast, const char *);
124
    void doChannelInterface(ChannelInterfaceElement *node, const char *indent, bool islast, const char *);
125
    void doChannel(ChannelElement *node, const char *indent, bool islast, const char *);
126
    void doParameters(ParametersElement *node, const char *indent, bool islast, const char *);
127
    void doParam(ParamElement *node, const char *indent, bool islast, const char *);
128
    void doProperty(PropertyElement *node, const char *indent, bool islast, const char *);
129
    void doPropertyKey(PropertyKeyElement *node, const char *indent, bool islast, const char *);
130
    void doGates(GatesElement *node, const char *indent, bool islast, const char *);
131
    void doGate(GateElement *node, const char *indent, bool islast, const char *);
132
    void doTypes(TypesElement *node, const char *indent, bool islast, const char *);
133
    void doSubmodules(SubmodulesElement *node, const char *indent, bool islast, const char *);
134
    void doSubmodule(SubmoduleElement *node, const char *indent, bool islast, const char *);
135
    void doConnections(ConnectionsElement *node, const char *indent, bool islast, const char *);
136
    void doConnection(ConnectionElement *node, const char *indent, bool islast, const char *);
137
    void doChannelSpec(ChannelSpecElement *node, const char *indent, bool islast, const char *);
138
    void doConnectionGroup(ConnectionGroupElement *node, const char *indent, bool islast, const char *);
139
    void doLoop(LoopElement *node, const char *indent, bool islast, const char *);
140
    void doCondition(ConditionElement *node, const char *indent, bool islast, const char *);
141
    void printConnectionGate(NEDElement *conn, const char *modname, const char *modindexattr,
142
                             const char *gatename, const char *gateindexattr, bool isplusplus,
143
                             int gatesubg, const char *indent);
144

    
145
    // expressions
146
    void doExpression(ExpressionElement *node, const char *indent, bool islast, const char *);
147
    int getOperatorPrecedence(const char *op, int args);
148
    bool isOperatorLeftAssoc(const char *op);
149
    void doOperator(OperatorElement *node, const char *indent, bool islast, const char *);
150
    void doFunction(FunctionElement *node, const char *indent, bool islast, const char *);
151
    void doIdent(IdentElement *node, const char *indent, bool islast, const char *);
152
    void doLiteral(LiteralElement *node, const char *indent, bool islast, const char *);
153

    
154
    // msg stuff
155
    void doMsgFile(MsgFileElement *node, const char *indent, bool islast, const char *);
156
    void doNamespace(NamespaceElement *node, const char *indent, bool islast, const char *);
157
    void doCplusplus(CplusplusElement *node, const char *indent, bool islast, const char *);
158
    void doStructDecl(StructDeclElement *node, const char *indent, bool islast, const char *);
159
    void doClassDecl(ClassDeclElement *node, const char *indent, bool islast, const char *);
160
    void doMessageDecl(MessageDeclElement *node, const char *indent, bool islast, const char *);
161
    void doPacketDecl(PacketDeclElement *node, const char *indent, bool islast, const char *);
162
    void doEnumDecl(EnumDeclElement *node, const char *indent, bool islast, const char *);
163
    void doEnum(EnumElement *node, const char *indent, bool islast, const char *);
164
    void doEnumFields(EnumFieldsElement *node, const char *indent, bool islast, const char *);
165
    void doEnumField(EnumFieldElement *node, const char *indent, bool islast, const char *);
166
    void doMessage(MessageElement *node, const char *indent, bool islast, const char *);
167
    void doPacket(PacketElement *node, const char *indent, bool islast, const char *);
168
    void doClass(ClassElement *node, const char *indent, bool islast, const char *);
169
    void doStruct(StructElement *node, const char *indent, bool islast, const char *);
170
    void doField(FieldElement *node, const char *indent, bool islast, const char *);
171
    void doComment(CommentElement *node, const char *indent, bool islast, const char *);
172
    //@}
173
};
174

    
175
NAMESPACE_END
176

    
177

    
178
#endif
179

    
180