nedyylib.h

Go to the documentation of this file.
00001 //==========================================================================
00002 // nedyylib.h  -
00003 //
00004 //                     OMNeT++/OMNEST
00005 //            Discrete System Simulation in C++
00006 //
00007 //==========================================================================
00008 
00009 /*--------------------------------------------------------------*
00010   Copyright (C) 2002-2008 Andras Varga
00011   Copyright (C) 2006-2008 OpenSim Ltd.
00012 
00013   This file is distributed WITHOUT ANY WARRANTY. See the file
00014   `license' for details on this and other legal matters.
00015 *--------------------------------------------------------------*/
00016 
00017 #ifndef __NEDYYLIB_H
00018 #define __NEDYYLIB_H
00019 
00020 #include <string>
00021 #include "nedelements.h"
00022 #include "nedyydefs.h"
00023 #include "nedparser.h"
00024 
00025 NAMESPACE_BEGIN
00026 
00027 #define NONREENTRANT_NED_PARSER(p) \
00028     struct Guard { \
00029       Guard(NEDParser *parser) {if (np) throw opp_runtime_error("non-reentrant parser invoked again while parsing"); np=parser;} \
00030       ~Guard() {np=NULL;} \
00031     } __guard(p);
00032 
00033 std::string slashifyFilename(const char *fname);
00034 const char *currentLocation();
00035 
00036 NEDElement *createElementWithTag(int tagcode, NEDElement *parent=NULL);
00037 NEDElement *getOrCreateElementWithTag(int tagcode, NEDElement *parent);
00038 
00039 void storePos(NEDElement *node, YYLTYPE pos);
00040 void storePos(NEDElement *node, YYLTYPE firstpos, YYLTYPE lastpos);
00041 
00042 PropertyElement *addProperty(NEDElement *node, const char *name);  // directly under the node
00043 PropertyElement *addComponentProperty(NEDElement *node, const char *name); // into ParametersElement child of node
00044 
00045 PropertyElement *storeSourceCode(NEDElement *node, YYLTYPE tokenpos);  // directly under the node
00046 PropertyElement *storeComponentSourceCode(NEDElement *node, YYLTYPE tokenpos); // into ParametersElement child
00047 PropertyElement *setIsNetworkProperty(NEDElement *node); // into ParametersElement child
00048 
00049 void addComment(NEDElement *node, const char *locId, const char *comment, const char *defaultValue);
00050 void storeFileComment(NEDElement *node);
00051 void storeBannerComment(NEDElement *node, YYLTYPE tokenpos);
00052 void storeRightComment(NEDElement *node, YYLTYPE tokenpos);
00053 void storeTrailingComment(NEDElement *node, YYLTYPE tokenpos);
00054 void storeBannerAndRightComments(NEDElement *node, YYLTYPE pos);
00055 void storeBannerAndRightComments(NEDElement *node, YYLTYPE firstpos, YYLTYPE lastpos);
00056 void storeInnerComments(NEDElement *node, YYLTYPE pos);
00057 
00058 ParamElement *addParameter(NEDElement *params, YYLTYPE namepos);
00059 ParamElement *addParameter(NEDElement *params, const char *name, YYLTYPE namepos);
00060 GateElement *addGate(NEDElement *gates, YYLTYPE namepos);
00061 
00062 YYLTYPE trimQuotes(YYLTYPE vectorpos);
00063 YYLTYPE trimDoubleBraces(YYLTYPE vectorpos);
00064 void swapAttributes(NEDElement *node, const char *attr1, const char *attr2);
00065 void swapExpressionChildren(NEDElement *node, const char *attr1, const char *attr2);
00066 void swapConnection(NEDElement *conn);
00067 void transferChildren(NEDElement *from, NEDElement *to);
00068 
00069 const char *toString(YYLTYPE);
00070 const char *toString(long);
00071 std::string removeSpaces(YYLTYPE pos);
00072 
00073 ExpressionElement *createExpression(NEDElement *expr);
00074 OperatorElement *createOperator(const char *op, NEDElement *operand1, NEDElement *operand2=NULL, NEDElement *operand3=NULL);
00075 FunctionElement *createFunction(const char *funcname, NEDElement *arg1=NULL, NEDElement *arg2=NULL, NEDElement *arg3=NULL, NEDElement *arg4=NULL, NEDElement *arg5=NULL, NEDElement *arg6=NULL, NEDElement *arg7=NULL, NEDElement *arg8=NULL, NEDElement *arg9=NULL, NEDElement *arg10=NULL);
00076 IdentElement *createIdent(YYLTYPE parampos);
00077 IdentElement *createIdent(YYLTYPE parampos, YYLTYPE modulepos, NEDElement *moduleindexoperand=NULL);
00078 LiteralElement *createPropertyValue(YYLTYPE textpos);
00079 LiteralElement *createLiteral(int type, YYLTYPE valuepos, YYLTYPE textpos);
00080 LiteralElement *createLiteral(int type, const char *value, const char *text);
00081 LiteralElement *createStringLiteral(YYLTYPE textpos);
00082 LiteralElement *createQuantityLiteral(YYLTYPE textpos);
00083 NEDElement *unaryMinus(NEDElement *node);
00084 
00085 void addOptionalExpression(NEDElement *elem, const char *attrname, YYLTYPE exprpos, NEDElement *expr);
00086 void addExpression(NEDElement *elem, const char *attrname, YYLTYPE exprpos, NEDElement *expr);
00087 
00088 std::string convertBackgroundDisplayString(const char *old);
00089 
00090 inline bool isEmpty(YYLTYPE pos) {
00091     return pos.first_line > pos.last_line ||
00092            (pos.first_line == pos.last_line && pos.first_column >= pos.last_column);
00093 }
00094 
00095 inline YYLTYPE makeYYLTYPE(int fl, int fc, int ll, int lc) {
00096     YYLTYPE pos;
00097     pos.first_line = fl;
00098     pos.first_column = fc;
00099     pos.last_line = ll;
00100     pos.last_column = lc;
00101     return pos;
00102 }
00103 
00104 inline YYLTYPE makeEmptyYYLTYPE() {
00105     return makeYYLTYPE(1,0,1,0);
00106 }
00107 
00108 NAMESPACE_END
00109 
00110 
00111 #endif
00112 
Generated on Tue Dec 2 11:16:31 2014 for OMNeT++ NEDXML by  doxygen 1.6.3