Main Page Modules Class Hierarchy Compound List File List Compound Members

# cppgenerator.h

    00001 //==========================================================================
    00002 //   CPPGENERATOR.H -
    00003 //            part of OMNeT++
    00004 //
    00005 //==========================================================================
    00006
    00007 /*--------------------------------------------------------------*
    00008   Copyright (C) 2002-2003 Andras Varga
    00009
    00010   This file is distributed WITHOUT ANY WARRANTY. See the file
    00011   `license' for details on this and other legal matters.
    00012 *--------------------------------------------------------------*/
    00013
    00014 #ifndef __CPPGENERATOR_H
    00015 #define __CPPGENERATOR_H
    00016
    00017 #include <string>
    00018 #include <map>
    00019 #include <vector>
    00020 #include <iostream>
    00021
    00022 #include "nedelements.h"
    00023 #include "cppexprgenerator.h"
    00024 #include "nedcompiler.h" // for NEDSymbolTable
    00025
    00026 using std::ostream;
    00027
    00033 void generateCpp(ostream& out, ostream& outh, NEDElement *node, NEDSymbolTable *symtab);
    00034
    00035
    00044 class NEDCppGenerator
    00045 {
    00046   protected:
    00047     ostream& out;
    00048     ostream& outh;
    00049     bool in_network;
    00050     std::string module_name;
    00051     std::string submodule_name;
    00052     std::string submodule_var;
    00053     int indentsize;
    00054
    00055     enum {
    00056       MODE_NORMAL,
    00057       MODE_CLEANUP,
    00058     };
    00059
    00060     CppExpressionGenerator exprgen;
    00061
    00062     NEDSymbolTable *symboltable;
    00063
    00064   public:
    00070     NEDCppGenerator(ostream& out, ostream& outh, NEDSymbolTable *symtab);
    00071
    00075     ~NEDCppGenerator();
    00076
    00080     void setIndentSize(int indentsize);
    00081
    00086     void generate(NEDElement *node);
    00087
    00088   protected:
    00089     const char *increaseIndent(const char *indent);
    00090     const char *decreaseIndent(const char *indent);
    00091
    00092     void generateItem(NEDElement *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00093     void generateChildren(NEDElement *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00094     void generateChildrenWithTags(NEDElement *node, const char *tags, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00095     void generateChildrenExceptTags(NEDElement *node, const char *tags, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00097     ExpressionNode *findExpression(NEDElement *parent, const char *target);
    00099     ConstNode *getConstantExpression(ExpressionNode *node);
    00101     NEDElement *findFirstChildWithAttribute(NEDElement *node, int tagcode, const char *attr, const char *attrvalue);
    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 doSubmodule(SubmoduleNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00125     void doSubmoduleCleanup(SubmoduleNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00126     void doSubstparams(SubstparamsNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00127     void doSubstparam(SubstparamNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00128     void doGatesizes(GatesizesNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00129     void doGatesize(GatesizeNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00130     void doSubstmachines(SubstmachinesNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00131     void doSubstmachine(SubstmachineNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00132     void doConnections(ConnectionsNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00133     void resolveGate(const char *modname, ExpressionNode *modindex, const char *gatename, ExpressionNode *gateindex);
    00134     void resolveConnectionAttributes(ConnectionNode *node, const char *indent, int mode);
    00135     void doConnection(ConnectionNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00136     void doConnattr(ConnAttrNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00137     void doForloop(ForLoopNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00138     void doLoopvar(LoopVarNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00139     void doDisplayString(DisplayStringNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00140     void doExpression(ExpressionNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00141
    00142     struct ClassDesc;
    00143     struct FieldDesc;
    00144
    00145     void doCppinclude(CppincludeNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00146     void doCppStruct(CppStructNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00147     void doCppCobject(CppCobjectNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00148     void doCppNoncobject(CppNoncobjectNode *node, const char *indent, int mode=MODE_NORMAL, const char *arg=NULL);
    00149     void doEnum(EnumNode *node, const char *indent, int mode, const char *);
    00150     void doEnumFields(EnumFieldsNode *node, const char *indent, int mode, const char *);
    00151     void doEnumField(EnumFieldNode *node, const char *indent, int mode, const char *);
    00152     void doMessage(MessageNode *node, const char *, int, const char *);
    00153     void doClass(ClassNode *node, const char *, int, const char *);
    00154     void doStruct(StructNode *node, const char *, int, const char *);
    00155     void prepareForCodeGeneration(NEDElement *node, ClassDesc& cld, FieldDesc *&fld, int& numfields);
    00156     void generateClass(ClassDesc& cld, FieldDesc *&fld, int numfields);
    00157     void generateStruct(ClassDesc& cld, FieldDesc *&fld, int numfields);
    00158     void generateDescriptorClass(ClassDesc& cld, FieldDesc *&fld, int numfields);
    00159 };
    00160
    00161 #endif
    00162
    00163