Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

cppexprgenerator.h

00001 //==========================================================================
00002 //   CPPEXPRGENERATOR.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 __CPPEXPRGENERATOR_H
00015 #define __CPPEXPRGENERATOR_H
00016 
00017 #ifdef _MSC_VER
00018 // disable tons of "identifier was truncated to '255' characters in the debug
00019 // information" warnings that comes as bonus with using STL
00020 #pragma warning(disable:4786)
00021 #endif
00022 
00023 #include <string>
00024 #include <map>
00025 #include <vector>
00026 #include <iostream>
00027 #include "nedelements.h"
00028 
00029 using std::ostream;
00030 
00046 class CppExpressionGenerator
00047 {
00048   protected:
00049     typedef std::vector<NEDElement *> NEDElementVector;
00050     struct ExpressionInfo {
00051         ExpressionNode *expr;
00052         int ctxtype; // tagcode of toplevel element which contains this expr.
00053         std::string name;
00054         NEDElementVector ctorargs;
00055         NEDElementVector cachedvars;
00056     };
00057     typedef std::map<ExpressionNode *,ExpressionInfo> NEDExpressionMap;
00058 
00059     static int count;
00060     ostream& out;
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);
00070     void collectExpressionInfo(ExpressionNode *expr);
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);
00087 
00088   public:
00092     CppExpressionGenerator(ostream& out);
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 

Generated at Mon Jun 16 23:37:38 2003 for OMNeT++NEDXML by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001