OMNeT++ NEDXML  6.0.3
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 const char *currentLocation(ParseContext *np);
37 
38 ASTNode *createElementWithTag(ParseContext *np, ASTNodeFactory *factory, int tagcode, ASTNode *parent=nullptr);
39 ASTNode *getOrCreateElementWithTag(ParseContext *np, ASTNodeFactory *factory, int tagcode, ASTNode *parent);
40 
41 void storePos(ParseContext *np, ASTNode *node, YYLoc pos);
42 void storePos(ParseContext *np, ASTNode *node, YYLoc firstpos, YYLoc lastpos);
43 
44 void swapAttributes(ASTNode *node, const char *attr1, const char *attr2);
45 void transferChildren(ASTNode *from, ASTNode *to);
46 
47 YYLoc trimQuotes(YYLoc vectorpos);
48 YYLoc trimDoubleBraces(YYLoc vectorpos);
49 
50 const char *toString(ParseContext *np, YYLoc);
51 const char *toString(long);
52 std::string removeSpaces(ParseContext *np, YYLoc pos);
53 
54 inline bool isEmpty(YYLoc pos) {
55  return pos.first_line > pos.last_line ||
56  (pos.first_line == pos.last_line && pos.first_column >= pos.last_column);
57 }
58 
59 inline YYLoc makeYYLoc(int fl, int fc, int ll, int lc) { //TODO ctor!
60  YYLoc pos;
61  pos.first_line = fl;
62  pos.first_column = fc;
63  pos.last_line = ll;
64  pos.last_column = lc;
65  return pos;
66 }
67 
68 inline YYLoc makeEmptyYYLoc() { //TODO ctor!
69  return makeYYLoc(1,0,1,0);
70 }
71 
72 } // namespace nedxml
73 } // namespace omnetpp
74 
75 
76 #endif
77 
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:68
omnetpp::nedxml::createElementWithTag
ASTNode * createElementWithTag(ParseContext *np, ASTNodeFactory *factory, int tagcode, ASTNode *parent=nullptr)
astnode.h
omnetpp::nedxml::currentLocation
const char * currentLocation(ParseContext *np)
omnetpp::nedxml::makeYYLoc
YYLoc makeYYLoc(int fl, int fc, int ll, int lc)
Definition: yyutil.h:59
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:54
omnetpp::nedxml::toString
const char * toString(ParseContext *np, YYLoc)