1 |
/* ATokPtr.h |
2 |
* |
3 |
* SOFTWARE RIGHTS |
4 |
* |
5 |
* We reserve no LEGAL rights to the Purdue Compiler Construction Tool |
6 |
* Set (PCCTS) -- PCCTS is in the public domain. An individual or |
7 |
* company may do whatever they wish with source code distributed with |
8 |
* PCCTS or the code generated by PCCTS, including the incorporation of |
9 |
* PCCTS, or its output, into commerical software. |
10 |
* |
11 |
* We encourage users to develop software with PCCTS. However, we do ask |
12 |
* that credit is given to us for developing PCCTS. By "credit", |
13 |
* we mean that if you incorporate our source code into one of your |
14 |
* programs (commercial product, research project, or otherwise) that you |
15 |
* acknowledge this fact somewhere in the documentation, research report, |
16 |
* etc... If you like PCCTS and have developed a nice tool with the |
17 |
* output, please mention that you developed it using PCCTS. In |
18 |
* addition, we ask that this header remain intact in our source code. |
19 |
* As long as these guidelines are kept, we expect to continue enhancing |
20 |
* this system and expect to make other tools available as they are |
21 |
* completed. |
22 |
* |
23 |
* ANTLR 1.33 |
24 |
* Written by Russell Quong June 30, 1995 |
25 |
* Adapted by Terence Parr to ANTLR stuff |
26 |
* Parr Research Corporation |
27 |
* with Purdue University and AHPCRC, University of Minnesota |
28 |
* 1989-2000 |
29 |
*/ |
30 |
|
31 |
#ifndef ATokPtr_h |
32 |
#define ATokPtr_h |
33 |
|
34 |
#include "pcctscfg.h" |
35 |
|
36 |
#include "pccts_stdio.h" |
37 |
|
38 |
PCCTS_NAMESPACE_STD |
39 |
|
40 |
// pointer to a reference counted object |
41 |
// robust in that an unused ANTLRTokenPtr can point to NULL. |
42 |
|
43 |
class ANTLRAbstractToken; |
44 |
|
45 |
class DllExportPCCTS ANTLRTokenPtr { |
46 |
public: |
47 |
ANTLRTokenPtr(ANTLRAbstractToken *addr=NULL){ptr_ = addr; ref();} |
48 |
ANTLRTokenPtr(const ANTLRTokenPtr &lhs) {ptr_ = lhs.ptr_; lhs.ref();} |
49 |
~ANTLRTokenPtr(); |
50 |
|
51 |
// use ANTLRTokenPtr as a pointer to ANTLRToken |
52 |
// |
53 |
// 8-Apr-97 MR1 Make operator -> a const member function |
54 |
// as well as some other member functions |
55 |
// |
56 |
ANTLRAbstractToken *operator-> () const { return ptr_; } // MR1 |
57 |
// |
58 |
// 7-Apr-97 133MR1 |
59 |
// Fix suggested by Andreas Magnusson |
60 |
// (Andreas.Magnusson@mailbox.swipnet.se) |
61 |
void operator = (const ANTLRTokenPtr & lhs); // MR1 |
62 |
void operator = (ANTLRAbstractToken *addr); |
63 |
int operator != (const ANTLRTokenPtr &q) const // MR1 // MR11 unsigned -> int |
64 |
{ return this->ptr_ != q.ptr_; } |
65 |
int operator == (const ANTLRTokenPtr &q) const // MR1 // MR11 unsigned -> int |
66 |
{ return this->ptr_ == q.ptr_; } |
67 |
int operator == (const ANTLRAbstractToken *addr) const // MR11 |
68 |
{ return this->ptr_ == addr; } |
69 |
int operator != (const ANTLRAbstractToken *addr) const // MR11 |
70 |
{ return this->ptr_ != addr; } |
71 |
|
72 |
void ref() const; |
73 |
void deref(); |
74 |
|
75 |
protected: |
76 |
ANTLRAbstractToken *ptr_; |
77 |
}; |
78 |
|
79 |
//typedef ANTLRTokenPtr _ANTLRTokenPtr; |
80 |
|
81 |
/* |
82 |
* Since you cannot redefine operator->() to return one of the user's |
83 |
* token object types, we must down cast. This is a drag. Here's |
84 |
* a macro that helps. template: "mytoken(a-smart-ptr)->myfield". |
85 |
*/ |
86 |
#define mytoken(tk) ((ANTLRToken *)(tk.operator->())) |
87 |
|
88 |
#endif |