- Main Page
- Modules
- Classes
- Files
- Directories

- File List
- File Members

# cppexprgenerator.h

Go to the documentation of this file.

    00001 //==========================================================================
    00002 //  CPPEXPRGENERATOR.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 __CPPEXPRGENERATOR_H
    00017 #define __CPPEXPRGENERATOR_H
    00018
    00019 #include <string>
    00020 #include <map>
    00021 #include <vector>
    00022 #include <iostream>
    00023 #include "nedelements.h"
    00024
    00025 using std::ostream;
    00026 class NEDSymbolTable;
    00027
    00028
    00044 class CppExpressionGenerator
    00045 {
    00046   protected:
    00047     typedef std::vector<NEDElement *> NEDElementVector;
    00048     struct ExpressionInfo {
    00049         ExpressionNode *expr;
    00050         int ctxtype; // tagcode of toplevel element which contains this expr.
    00051         NEDElement *submoduleTypeDecl; // if submodule or network, the type decl.
    00052         std::string name; // generated expression class name (Expr0, Expr1, etc)
    00053         NEDElementVector ctorargs;
    00054         NEDElementVector cachedvars;
    00055     };
    00056     typedef std::map<ExpressionNode *,ExpressionInfo> NEDExpressionMap;
    00057
    00058     static int count;
    00059     ostream& out;
    00060     NEDSymbolTable *symboltable;
    00061     NEDExpressionMap exprMap;
    00062
    00063     enum {
    00064       MODE_INLINE_EXPRESSION,
    00065       MODE_EXPRESSION_CLASS
    00066     };
    00067
    00068     void doExtractArgs(ExpressionInfo& info, NEDElement *node);
    00069     void doCollectExpressions(NEDElement *node, NEDElement *currentSubmodTypeDecl);
    00070     void collectExpressionInfo(ExpressionNode *expr, NEDElement *currentSubmodTypeDecl);
    00071     void generateExpressionClass(ExpressionInfo& info);
    00072     const char *getTypeForArg(NEDElement *node);
    00073     const char *getNameForArg(NEDElement *node);
    00074     void doValueForArg(NEDElement *node);
    00075     void doValueForCachedVar(NEDElement *node);
    00076
    00077     void generateChildren(NEDElement *node, const char *indent, int mode);
    00078     void generateItem(NEDElement *node, const char *indent, int mode);
    00079     void doOperator(OperatorNode *node, const char *indent, int mode);
    00080     void doFunction(FunctionNode *node, const char *indent, int mode);
    00081     void doParamref(ParamRefNode *node, const char *indent, int mode);
    00082     void doIdent(IdentNode *node, const char *indent, int mode);
    00083     void doConst(ConstNode *node, const char *indent, int mode);
    00084     void doExpression(ExpressionNode *node, const char *indent, int mode);
    00085
    00086     bool needsExpressionClass(ExpressionNode *expr, NEDElement *currentSubmodTypeDecl);
    00087
    00088   public:
    00092     CppExpressionGenerator(ostream& out, NEDSymbolTable *symboltable);
    00093
    00097     ~CppExpressionGenerator() {}
    00098
    00103     void collectExpressions(NEDElement *node);
    00104
    00110     void generateExpressionClasses();
    00111
    00116     void generateExpressionUsage(ExpressionNode *expr, const char *indent);
    00117 };
    00118
    00119 #endif
    00120
    00121