# cppgenerator.h

Go to the documentation of this file.

    00001 //==========================================================================
    00002 //  CPPGENERATOR.H - part of
    00003 //
    00004 //                     OMNeT++/OMNEST
    00005 //            Discrete System Simulation in C++
    00006 //
    00007 //==========================================================================
    00008
    00009 /*--------------------------------------------------------------*
    00010   Copyright (C) 2002-2005 Andras Varga
    00011
    00012   This file is distributed WITHOUT ANY WARRANTY. See the file
    00013   `license' for details on this and other legal matters.
    00014 *--------------------------------------------------------------*/
    00015
    00016 #ifndef __CPPGENERATOR_H
    00017 #define __CPPGENERATOR_H
    00018
    00019 #include <string>
    00020 #include <map>
    00021 #include <vector>
    00022 #include <iostream>
    00023
    00024 #include "nedelements.h"
    00025 #include "cppexprgenerator.h"
    00026 #include "nedcompiler.h" // for NEDSymbolTable
    00027
    00028 using std::ostream;
    00029
    00035 void generateCpp(ostream& out, ostream& outh, NEDElement *node, NEDSymbolTable *symtab);
    00036
    00037
    00046 class NEDCppGenerator
    00047 {
    00048   protected:
    00049     ostream& out;  // stream for writing .cc file
    00050     ostream& outh; // stream for writing .h file
    00051
    00052     bool in_network;
    00053     std::string submodule_var;
    00054     int indentsize;
    00055
    00056     enum {
    00057       MODE_NORMAL,
    00058       MODE_FINALLY
    00059     };
    00060
    00061     CppExpressionGenerator exprgen;
    00062
    00063     NEDSymbolTable *symboltable;
    00064
    00065   public:
    00071     NEDCppGenerator(ostream& out, ostream& outh, NEDSymbolTable *symtab);
    00072
    00076     ~NEDCppGenerator();
    00077
    00081     void setIndentSize(int indentsize);
    00082
    00087     void generate(NEDElement *node);
    00088
    00089   protected:
    00090     const char *increaseIndent(const char *indent);
    00091     const char *decreaseIndent(const char *indent);
    00092
    00093     void generateItem(NEDElement *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00094     void generateChildren(NEDElement *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00095     void generateChildrenWithTags(NEDElement *node, const char *tags, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00096     void generateChildrenExceptTags(NEDElement *node, const char *tags, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00097
    00098     // find given expression node in parent.
    00099     ExpressionNode *findExpression(NEDElement *parent, const char *target);
    00100     // if expression consists of a constant, return its pointer, NULL otherwise.
    00101     ConstNode *getConstantExpression(ExpressionNode *node);
    00102
    00103     void writeProlog(ostream& out);
    00104     void printTemporaryVariables(const char *indent);
    00105     void beginConditionalBlock(NEDElement *node, const char *&indent, int mode, const char *);
    00106     void endConditionalBlock(NEDElement *node, const char *&indent, int mode, const char *);
    00107
    00108     void doNedFile(NedFileNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00109     void doNedFiles(NedFilesNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00110     void doImports(ImportNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00111     void doImport(ImportedFileNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00112     void doChannel(ChannelNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00113     void doChannelAttr(ChannelAttrNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00114     void doNetwork(NetworkNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00115     void doSimple(SimpleModuleNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00116     void doModule(CompoundModuleNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00117     void doParams(ParamsNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00118     void doParam(ParamNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00119     void doGates(GatesNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00120     void doGate(GateNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00121     void doMachines(MachinesNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00122     void doMachine(MachineNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00123     void doSubmodules(SubmodulesNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00124     void resolveSubmoduleType(SubmoduleNode *node, const char *indent);
    00125     void doSubmodule(SubmoduleNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00126     void doSubmoduleFinally(SubmoduleNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00127     void doSubstparams(SubstparamsNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00128     void doSubstparam(SubstparamNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00129     void doGatesizes(GatesizesNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00130     void doGatesize(GatesizeNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00131     void doSubstmachines(SubstmachinesNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00132     void doSubstmachine(SubstmachineNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00133     void doConnections(ConnectionsNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00134     void resolveGate(const char *modname, ExpressionNode *modindex, const char *gatename, ExpressionNode *gateindex, bool isplusplus);
    00135     void resolveConnectionAttributes(ConnectionNode *node, const char *indent, int mode);
    00136     void doConnection(ConnectionNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00137     void doConnattr(ConnAttrNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00138     void doForloop(ForLoopNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00139     void doLoopvar(LoopVarNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00140     void doDisplayString(DisplayStringNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00141     void doExpression(ExpressionNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00142
    00143     struct ClassDesc;
    00144     struct FieldDesc;
    00145
    00146     void doCplusplus(CplusplusNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00147     void doStructDecl(StructDeclNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00148     void doClassDecl(ClassDeclNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00149     void doMessageDecl(MessageDeclNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00150     void doEnumDecl(EnumDeclNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00151     void doEnum(EnumNode *node, const char *indent, int mode, const char *);
    00152     void doEnumFields(EnumFieldsNode *node, const char *indent, int mode, const char *);
    00153     void doEnumField(EnumFieldNode *node, const char *indent, int mode, const char *);
    00154     void doMessage(MessageNode *node, const char *, int, const char *);
    00155     void doClass(ClassNode *node, const char *, int, const char *);
    00156     void doStruct(StructNode *node, const char *, int, const char *);
    00157     void prepareForCodeGeneration(NEDElement *node, ClassDesc& cld, FieldDesc *&fld, int& numfields);
    00158     void generateClass(ClassDesc& cld, FieldDesc *&fld, int numfields);
    00159     void generateStruct(ClassDesc& cld, FieldDesc *&fld, int numfields);
    00160     void generateDescriptorClass(ClassDesc& cld, FieldDesc *&fld, int numfields);
    00161 };
    00162
    00163 #endif
    00164
    00165