OMNeT++ NEDXML  5.4.1
nedgenerator.h
Go to the documentation of this file.
1 //==========================================================================
2 // NEDGENERATOR.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_NEDGENERATOR_H
18 #define __OMNETPP_NEDXML_NEDGENERATOR_H
19 
20 #include <iostream>
21 
22 #include "errorstore.h"
23 #include "nedelements.h"
24 
25 namespace omnetpp {
26 namespace nedxml {
27 
28 
34 NEDXML_API void generateNed(std::ostream& out, ASTNode *node);
35 
45 {
46  protected:
48  std::ostream *outp;
49 
50  public:
54  NedGenerator();
55 
59  ~NedGenerator();
60 
64  void setIndentSize(int indentsize);
65 
70  void generate(std::ostream& out, ASTNode *node, const char *indent);
71 
75  std::string generate(ASTNode *node, const char *indent);
76 
77  protected:
80  const char *increaseIndent(const char *indent);
81  const char *decreaseIndent(const char *indent);
83 
85  void generateNedItem(ASTNode *node, const char *indent, bool islast, const char *arg=nullptr);;
86 
88  void generateChildren(ASTNode *node, const char *indent, const char *arg=nullptr);
89 
91  void generateChildrenWithType(ASTNode *node, int tagcode, const char *indent, const char *arg=nullptr);
92 
94  void generateChildrenWithTypes(ASTNode *node, int tagcodes[], const char *indent, const char *arg=nullptr);
95 
98  void printInheritance(ASTNode *node, const char *indent);
99  bool hasExpression(ASTNode *node, const char *attr);
100  void printExpression(ASTNode *node, const char *attr, const char *indent);
101  void printOptVector(ASTNode *node, const char *attr, const char *indent);
102  void doMsgClassOrStructBody(ASTNode *msgclassorstruct, const char *indent);
104 
107  std::string concatInnerComments(ASTNode *node);
108  std::string getBannerComment(ASTNode *node, const char *indent);
109  std::string getRightComment(ASTNode *node);
110  std::string getInlineRightComment(ASTNode *node);
111  std::string getTrailingComment(ASTNode *node);
113 
116  void doFiles(FilesElement *node, const char *indent, bool islast, const char *);
117  void doNedFile(NedFileElement *node, const char *indent, bool islast, const char *);
118  void doPackage(PackageElement *node, const char *indent, bool islast, const char *);
119  void doImport(ImportElement *node, const char *indent, bool islast, const char *);
120  void doPropertyDecl(PropertyDeclElement *node, const char *indent, bool islast, const char *);
121  void doExtends(ExtendsElement *node, const char *indent, bool islast, const char *);
122  void doInterfaceName(InterfaceNameElement *node, const char *indent, bool islast, const char *);
123  void doSimpleModule(SimpleModuleElement *node, const char *indent, bool islast, const char *);
124  void doModuleInterface(ModuleInterfaceElement *node, const char *indent, bool islast, const char *);
125  void doCompoundModule(CompoundModuleElement *node, const char *indent, bool islast, const char *);
126  void doChannelInterface(ChannelInterfaceElement *node, const char *indent, bool islast, const char *);
127  void doChannel(ChannelElement *node, const char *indent, bool islast, const char *);
128  void doParameters(ParametersElement *node, const char *indent, bool islast, const char *);
129  void doParam(ParamElement *node, const char *indent, bool islast, const char *);
130  void doProperty(PropertyElement *node, const char *indent, bool islast, const char *);
131  void doPropertyKey(PropertyKeyElement *node, const char *indent, bool islast, const char *);
132  void doGates(GatesElement *node, const char *indent, bool islast, const char *);
133  void doGate(GateElement *node, const char *indent, bool islast, const char *);
134  void doTypes(TypesElement *node, const char *indent, bool islast, const char *);
135  void doSubmodules(SubmodulesElement *node, const char *indent, bool islast, const char *);
136  void doSubmodule(SubmoduleElement *node, const char *indent, bool islast, const char *);
137  void doConnections(ConnectionsElement *node, const char *indent, bool islast, const char *);
138  void doConnection(ConnectionElement *node, const char *indent, bool islast, const char *);
139  void doConnectionGroup(ConnectionGroupElement *node, const char *indent, bool islast, const char *);
140  void doLoop(LoopElement *node, const char *indent, bool islast, const char *);
141  void doCondition(ConditionElement *node, const char *indent, bool islast, const char *);
142  void printConnectionGate(ASTNode *conn, const char *modname, const char *modindexattr,
143  const char *gatename, const char *gateindexattr, bool isplusplus,
144  int gatesubg, const char *indent);
145 
146  // expressions
147  void doExpression(ExpressionElement *node, const char *indent, bool islast, const char *);
148  int getOperatorPrecedence(const char *op, int args);
149  bool isOperatorLeftAssoc(const char *op);
150  void doOperator(OperatorElement *node, const char *indent, bool islast, const char *);
151  void doFunction(FunctionElement *node, const char *indent, bool islast, const char *);
152  void doIdent(IdentElement *node, const char *indent, bool islast, const char *);
153  void doLiteral(LiteralElement *node, const char *indent, bool islast, const char *);
154  void doComment(CommentElement *node, const char *indent, bool islast, const char *);
156 };
157 
158 } // namespace nedxml
159 } // namespace omnetpp
160 
161 
162 #endif
163 
164 
#define NEDXML_API
Definition: nedxmldefs.h:31
NEDXML_API void generateNed(std::ostream &out, ASTNode *node)
Simple front-end to NedGenerator.
std::ostream * outp
Definition: nedgenerator.h:48
Definition: astbuilder.h:25
Generates NED code from a NED AST.
Definition: nedgenerator.h:44
Definition: astnode.h:75
int indentSize
Definition: nedgenerator.h:47