OMNeT++ NEDXML 6.1
Discrete Event Simulation Library
yyutil.h
Go to the documentation of this file.
1 //==========================================================================
2 // yyutil.h -
3 //
4 // OMNeT++/OMNEST
5 // Discrete System Simulation in C++
6 //
7 //==========================================================================
8 
9 /*--------------------------------------------------------------*
10  Copyright (C) 2002-2017 Andras Varga
11  Copyright (C) 2006-2017 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 __OMNETPP_NEDXML_YYUTIL_H
18 #define __OMNETPP_NEDXML_YYUTIL_H
19 
20 #include <string>
21 #include "astnode.h"
22 #include "yydefs.h"
23 
24 namespace omnetpp {
25 namespace nedxml {
26 
27 extern bool parseInProgress;
28 
29 #define DETECT_PARSER_REENTRY() \
30  struct Guard { \
31  Guard() {if (parseInProgress) throw opp_runtime_error("non-reentrant parser invoked again while parsing"); parseInProgress = true;} \
32  ~Guard() {parseInProgress = false;} \
33  } __guard;
34 
35 std::string slashifyFilename(const char *fname);
36 ASTNode *createElementWithTag(ParseContext *np, ASTNodeFactory *factory, int tagcode, ASTNode *parent=nullptr);
37 ASTNode *getOrCreateElementWithTag(ParseContext *np, ASTNodeFactory *factory, int tagcode, ASTNode *parent);
38 
39 void storePos(ParseContext *np, ASTNode *node, YYLoc pos);
40 void storePos(ParseContext *np, ASTNode *node, YYLoc firstpos, YYLoc lastpos);
41 
42 void swapAttributes(ASTNode *node, const char *attr1, const char *attr2);
43 void transferChildren(ASTNode *from, ASTNode *to);
44 
45 YYLoc trimQuotes(YYLoc vectorpos);
46 YYLoc trimDoubleBraces(YYLoc vectorpos);
47 
48 const char *toString(ParseContext *np, YYLoc);
49 const char *toString(long);
50 std::string removeSpaces(ParseContext *np, YYLoc pos);
51 
52 inline bool isEmpty(YYLoc pos) {
53  return pos.first_line > pos.last_line ||
54  (pos.first_line == pos.last_line && pos.first_column >= pos.last_column);
55 }
56 
57 inline YYLoc makeYYLoc(int fl, int fc, int ll, int lc) { //TODO ctor!
58  YYLoc pos;
59  pos.first_line = fl;
60  pos.first_column = fc;
61  pos.last_line = ll;
62  pos.last_column = lc;
63  return pos;
64 }
65 
66 inline YYLoc makeEmptyYYLoc() { //TODO ctor!
67  return makeYYLoc(1,0,1,0);
68 }
69 
70 } // namespace nedxml
71 } // namespace omnetpp
72 
73 
74 #endif
75 
omnetpp::nedxml::getOrCreateElementWithTag
ASTNode * getOrCreateElementWithTag(ParseContext *np, ASTNodeFactory *factory, int tagcode, ASTNode *parent)
omnetpp::nedxml::removeSpaces
std::string removeSpaces(ParseContext *np, YYLoc pos)
omnetpp::nedxml::makeEmptyYYLoc
YYLoc makeEmptyYYLoc()
Definition: yyutil.h:66
omnetpp::nedxml::createElementWithTag
ASTNode * createElementWithTag(ParseContext *np, ASTNodeFactory *factory, int tagcode, ASTNode *parent=nullptr)
astnode.h
omnetpp::nedxml::makeYYLoc
YYLoc makeYYLoc(int fl, int fc, int ll, int lc)
Definition: yyutil.h:57
omnetpp::nedxml::YYLoc
Definition: yydefs.h:37
omnetpp::nedxml::storePos
void storePos(ParseContext *np, ASTNode *node, YYLoc pos)
omnetpp::nedxml::pos
LineColumn pos
omnetpp::nedxml::swapAttributes
void swapAttributes(ASTNode *node, const char *attr1, const char *attr2)
yydefs.h
omnetpp
Definition: astbuilder.h:25
omnetpp::nedxml::parseInProgress
bool parseInProgress
omnetpp::nedxml::trimQuotes
YYLoc trimQuotes(YYLoc vectorpos)
omnetpp::nedxml::transferChildren
void transferChildren(ASTNode *from, ASTNode *to)
omnetpp::nedxml::slashifyFilename
std::string slashifyFilename(const char *fname)
omnetpp::nedxml::trimDoubleBraces
YYLoc trimDoubleBraces(YYLoc vectorpos)
omnetpp::nedxml::isEmpty
bool isEmpty(YYLoc pos)
Definition: yyutil.h:52
omnetpp::nedxml::toString
const char * toString(ParseContext *np, YYLoc)