Project

General

Profile

Statistics
| Branch: | Revision:

root / src / nedxml / nedyylib.h @ 79bb12dc

History | View | Annotate | Download (4.71 KB)

1
//==========================================================================
2
// nedyylib.h  -
3
//
4
//                     OMNeT++/OMNEST
5
//            Discrete System Simulation in C++
6
//
7
//==========================================================================
8

    
9
/*--------------------------------------------------------------*
10
  Copyright (C) 2002-2008 Andras Varga
11
  Copyright (C) 2006-2008 OpenSim Ltd.
12

13
  This file is distributed WITHOUT ANY WARRANTY. See the file
14
  `license' for details on this and other legal matters.
15
*--------------------------------------------------------------*/
16

    
17
#ifndef __NEDYYLIB_H
18
#define __NEDYYLIB_H
19

    
20
#include <string>
21
#include "nedelements.h"
22
#include "nedyydefs.h"
23
#include "nedparser.h"
24

    
25
NAMESPACE_BEGIN
26

    
27
#define NONREENTRANT_NED_PARSER(p) \
28
    struct Guard { \
29
      Guard(NEDParser *parser) {if (np) throw opp_runtime_error("non-reentrant parser invoked again while parsing"); np=parser;} \
30
      ~Guard() {np=NULL;} \
31
    } __guard(p);
32

    
33
std::string slashifyFilename(const char *fname);
34
const char *currentLocation();
35

    
36
NEDElement *createElementWithTag(int tagcode, NEDElement *parent=NULL);
37
NEDElement *getOrCreateElementWithTag(int tagcode, NEDElement *parent);
38

    
39
void storePos(NEDElement *node, YYLTYPE pos);
40
void storePos(NEDElement *node, YYLTYPE firstpos, YYLTYPE lastpos);
41

    
42
PropertyElement *addProperty(NEDElement *node, const char *name);  // directly under the node
43
PropertyElement *addComponentProperty(NEDElement *node, const char *name); // into ParametersElement child of node
44

    
45
PropertyElement *storeSourceCode(NEDElement *node, YYLTYPE tokenpos);  // directly under the node
46
PropertyElement *storeComponentSourceCode(NEDElement *node, YYLTYPE tokenpos); // into ParametersElement child
47
PropertyElement *setIsNetworkProperty(NEDElement *node); // into ParametersElement child
48

    
49
void addComment(NEDElement *node, const char *locId, const char *comment, const char *defaultValue);
50
void storeFileComment(NEDElement *node);
51
void storeBannerComment(NEDElement *node, YYLTYPE tokenpos);
52
void storeRightComment(NEDElement *node, YYLTYPE tokenpos);
53
void storeTrailingComment(NEDElement *node, YYLTYPE tokenpos);
54
void storeBannerAndRightComments(NEDElement *node, YYLTYPE pos);
55
void storeBannerAndRightComments(NEDElement *node, YYLTYPE firstpos, YYLTYPE lastpos);
56
void storeInnerComments(NEDElement *node, YYLTYPE pos);
57

    
58
ParamElement *addParameter(NEDElement *params, YYLTYPE namepos);
59
ParamElement *addParameter(NEDElement *params, const char *name, YYLTYPE namepos);
60
GateElement *addGate(NEDElement *gates, YYLTYPE namepos);
61

    
62
YYLTYPE trimBrackets(YYLTYPE vectorpos);
63
YYLTYPE trimAngleBrackets(YYLTYPE vectorpos);
64
YYLTYPE trimQuotes(YYLTYPE vectorpos);
65
YYLTYPE trimDoubleBraces(YYLTYPE vectorpos);
66
void swapAttributes(NEDElement *node, const char *attr1, const char *attr2);
67
void swapExpressionChildren(NEDElement *node, const char *attr1, const char *attr2);
68
void swapConnection(NEDElement *conn);
69
void transferChildren(NEDElement *from, NEDElement *to);
70

    
71
const char *toString(YYLTYPE);
72
const char *toString(long);
73
std::string removeSpaces(YYLTYPE pos);
74

    
75
ExpressionElement *createExpression(NEDElement *expr);
76
OperatorElement *createOperator(const char *op, NEDElement *operand1, NEDElement *operand2=NULL, NEDElement *operand3=NULL);
77
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);
78
IdentElement *createIdent(YYLTYPE parampos);
79
IdentElement *createIdent(YYLTYPE parampos, YYLTYPE modulepos, NEDElement *moduleindexoperand=NULL);
80
LiteralElement *createLiteral(int type, YYLTYPE valuepos, YYLTYPE textpos);
81
LiteralElement *createLiteral(int type, const char *value, const char *text);
82
LiteralElement *createStringLiteral(YYLTYPE textpos);
83
LiteralElement *createQuantityLiteral(YYLTYPE textpos);
84
NEDElement *unaryMinus(NEDElement *node);
85

    
86
void addVector(NEDElement *elem, const char *attrname, YYLTYPE exprpos, NEDElement *expr);
87
void addLikeParam(NEDElement *elem, const char *attrname, YYLTYPE exprpos, NEDElement *expr);
88
void addExpression(NEDElement *elem, const char *attrname, YYLTYPE exprpos, NEDElement *expr);
89

    
90
std::string convertBackgroundDisplayString(const char *old);
91

    
92
inline bool isEmpty(YYLTYPE pos) {
93
    return pos.first_line > pos.last_line ||
94
           (pos.first_line == pos.last_line && pos.first_column >= pos.last_column);
95
}
96

    
97
inline YYLTYPE makeYYLTYPE(int fl, int fc, int ll, int lc) {
98
    YYLTYPE pos;
99
    pos.first_line = fl;
100
    pos.first_column = fc;
101
    pos.last_line = ll;
102
    pos.last_column = lc;
103
    return pos;
104
}
105

    
106
inline YYLTYPE makeEmptyYYLTYPE() {
107
    return makeYYLTYPE(1,0,1,0);
108
}
109

    
110
NAMESPACE_END
111

    
112

    
113
#endif
114