yyutil.h Source File

NEDXML API: yyutil.h Source File
NEDXML API
yyutil.h
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
24namespace omnetpp {
25namespace nedxml {
26
27extern 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
35std::string slashifyFilename(const char *fname);
36ASTNode *createElementWithTag(ParseContext *np, ASTNodeFactory *factory, int tagcode, ASTNode *parent=nullptr);
37ASTNode *getOrCreateElementWithTag(ParseContext *np, ASTNodeFactory *factory, int tagcode, ASTNode *parent);
38
39void storePos(ParseContext *np, ASTNode *node, YYLoc pos);
40void storePos(ParseContext *np, ASTNode *node, YYLoc firstpos, YYLoc lastpos);
41
42void swapAttributes(ASTNode *node, const char *attr1, const char *attr2);
43void transferChildren(ASTNode *from, ASTNode *to);
44
45YYLoc trimQuotes(YYLoc vectorpos);
46YYLoc trimDoubleBraces(YYLoc vectorpos);
47
48const char *toString(ParseContext *np, YYLoc);
49const char *toString(long);
50std::string removeSpaces(ParseContext *np, YYLoc pos);
51
52inline 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
57inline 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
66inline YYLoc makeEmptyYYLoc() { //TODO ctor!
67 return makeYYLoc(1,0,1,0);
68}
69
70} // namespace nedxml
71} // namespace omnetpp
72
73
74#endif
75
Base class for ASTNode factories.
Definition astnode.h:460
Definition astnode.h:88