OMNeT++ NEDXML  5.4.1
astnode.h
Go to the documentation of this file.
1 //==========================================================================
2 // astnode.h -
3 //
4 // OMNeT++/OMNEST
5 // Discrete System Simulation in C++
6 //
7 // Contents:
8 // class ASTNode
9 //
10 //==========================================================================
11 
12 /*--------------------------------------------------------------*
13  Copyright (C) 2002-2017 Andras Varga
14  Copyright (C) 2006-2017 OpenSim Ltd.
15 
16  This file is distributed WITHOUT ANY WARRANTY. See the file
17  `license' for details on this and other legal matters.
18 *--------------------------------------------------------------*/
19 
20 #ifndef __OMNETPP_NEDXML_ASTNODE_H
21 #define __OMNETPP_NEDXML_ASTNODE_H
22 
23 #ifdef _MSC_VER
24 // disable 4996: VC8.0 warnings on Unix syscalls
25 #pragma warning(disable: 4996)
26 #endif
27 
28 #include <string>
29 #include "nedxmldefs.h"
30 
31 namespace omnetpp {
32 namespace nedxml {
33 
34 
41 {
42  public:
44  UserData() {}
45 
47  virtual ~UserData() {}
48 };
49 
50 
58 {
59  SourceRegion() {startLine=startColumn=endLine=endColumn=0;}
60  int startLine;
62  int endLine;
63  int endColumn;
64 };
65 
76 {
77  private:
78  long id;
79  std::string srcLoc;
80  SourceRegion srcRegion;
81  ASTNode *parent;
82  ASTNode *firstChild;
83  ASTNode *lastChild;
84  ASTNode *prevSibling;
85  ASTNode *nextSibling;
86  UserData *userData;
87 
88  static long lastId;
89  static long numCreated;
90  static long numExisting;
91 
92  protected:
93  static bool stringToBool(const char *s);
94  static const char *boolToString(bool b);
95  static int stringToEnum(const char *s, const char *vals[], int nums[], int n);
96  static const char *enumToString(int b, const char *vals[], int nums[], int n);
97  static void validateEnum(int b, const char *vals[], int nums[], int n);
98 
99  public:
102 
106  ASTNode();
107 
111  ASTNode(ASTNode *parent);
112 
116  virtual ~ASTNode();
117 
122  virtual ASTNode *dup() const = 0;
123 
127  virtual ASTNode *dupTree() const;
129 
132 
137  virtual const char *getTagName() const = 0;
138 
143  virtual int getTagCode() const = 0;
144 
148  virtual long getId() const;
149 
153  virtual void setId(long id);
154 
159  virtual const char *getSourceLocation() const;
160 
165  virtual void setSourceLocation(const char *loc);
166 
171  virtual const SourceRegion& getSourceRegion() const;
172 
177  virtual void setSourceRegion(const SourceRegion& region);
179 
182 
189  virtual void applyDefaults();
190 
195  virtual int getNumAttributes() const = 0;
196 
204  virtual const char *getAttributeName(int k) const = 0;
205 
210  virtual int lookupAttribute(const char *attr) const;
211 
220  virtual const char *getAttribute(int k) const = 0;
221 
228  virtual const char *getAttribute(const char *attr) const;
229 
238  virtual void setAttribute(int k, const char *value) = 0;
239 
246  virtual void setAttribute(const char *attr, const char *value);
247 
256  virtual const char *getAttributeDefault(int k) const = 0;
257 
264  virtual const char *getAttributeDefault(const char *attr) const;
266 
269 
273  virtual ASTNode *getParent() const;
274 
279  virtual ASTNode *getFirstChild() const;
280 
285  virtual ASTNode *getLastChild() const;
286 
302  virtual ASTNode *getNextSibling() const;
303 
308  virtual ASTNode *getPrevSibling() const;
309 
315  virtual void appendChild(ASTNode *node);
316 
325  virtual void insertChildBefore(ASTNode *where, ASTNode *newnode);
326 
332  virtual ASTNode *removeChild(ASTNode *node);
333 
338  virtual ASTNode *getFirstChildWithTag(int tagcode) const;
339 
354  virtual ASTNode *getNextSiblingWithTag(int tagcode) const;
355 
359  virtual int getNumChildren() const;
360 
364  virtual int getNumChildrenWithTag(int tagcode) const;
366 
374  ASTNode *getFirstChildWithAttribute(int tagcode, const char *attr, const char *attrvalue=nullptr);
375 
380  ASTNode *getParentWithTag(int tagcode);
382 
385 
389  static long getNumCreated() {return numCreated;}
390 
395  static long getNumExisting() {return numExisting;}
397 
400 
404  virtual void setUserData(UserData *data);
405 
410  virtual UserData *getUserData() const;
412 };
413 
416 
423 {
424  public:
425  virtual ~ASTNodeFactory() {}
426 
430  virtual ASTNode *createElementWithTag(const char *tagName) = 0;
431 
435  virtual ASTNode *createElementWithTag(int tagCode) = 0;
436 };
437 
438 } // namespace nedxml
439 } // namespace omnetpp
440 
441 
442 #endif
443 
#define NEDXML_API
Definition: nedxmldefs.h:31
int endColumn
Definition: astnode.h:63
ASTNode MsgElement
Definition: astnode.h:415
int endLine
Definition: astnode.h:62
virtual ~ASTNodeFactory()
Definition: astnode.h:425
static long getNumExisting()
Definition: astnode.h:395
UserData()
Definition: astnode.h:44
int startLine
Definition: astnode.h:60
Subclass from this if you want to attach extra data to ASTNode objects.
Definition: astnode.h:40
Definition: astbuilder.h:25
int startColumn
Definition: astnode.h:61
SourceRegion()
Definition: astnode.h:59
Stores a line:col..line:col region in a source file. Used for mapping ASTNodes back to the source cod...
Definition: astnode.h:57
ASTNode * createElementWithTag(ParseContext *np, ASTNodeFactory *factory, int tagcode, ASTNode *parent=nullptr)
ASTNode NedElement
Definition: astnode.h:414
Definition: astnode.h:75
static long getNumCreated()
Definition: astnode.h:389
virtual ~UserData()
Definition: astnode.h:47
Base class for ASTNode factories.
Definition: astnode.h:422