GME
13
|
00001 /* ATokPtr.C 00002 * 00003 * ANTLRToken MUST be defined before entry to this file. 00004 * 00005 * SOFTWARE RIGHTS 00006 * 00007 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool 00008 * Set (PCCTS) -- PCCTS is in the public domain. An individual or 00009 * company may do whatever they wish with source code distributed with 00010 * PCCTS or the code generated by PCCTS, including the incorporation of 00011 * PCCTS, or its output, into commerical software. 00012 * 00013 * We encourage users to develop software with PCCTS. However, we do ask 00014 * that credit is given to us for developing PCCTS. By "credit", 00015 * we mean that if you incorporate our source code into one of your 00016 * programs (commercial product, research project, or otherwise) that you 00017 * acknowledge this fact somewhere in the documentation, research report, 00018 * etc... If you like PCCTS and have developed a nice tool with the 00019 * output, please mention that you developed it using PCCTS. In 00020 * addition, we ask that this header remain intact in our source code. 00021 * As long as these guidelines are kept, we expect to continue enhancing 00022 * this system and expect to make other tools available as they are 00023 * completed. 00024 * 00025 * ANTLR 1.33 00026 * Written by Russell Quong June 30, 1995 00027 * Adapted by Terence Parr to ANTLR stuff 00028 * Parr Research Corporation 00029 * with Purdue University and AHPCRC, University of Minnesota 00030 * 1989-1998 00031 */ 00032 00033 #include "ATokPtr.h" 00034 00035 void ANTLRTokenPtr::ref() const 00036 { 00037 if (ptr_ != NULL) { 00038 ptr_->ref(); 00039 } 00040 } 00041 00042 #include <stdio.h> 00043 00044 void ANTLRTokenPtr::deref() 00045 { 00046 if (ptr_ != NULL) 00047 { 00048 ptr_->deref(); 00049 if ( ptr_->nref()==0 ) 00050 { 00051 delete ptr_; 00052 ptr_ = NULL; 00053 } 00054 } 00055 } 00056 00057 ANTLRTokenPtr::~ANTLRTokenPtr() 00058 { 00059 deref(); 00060 } 00061 00062 // 00063 // 8-Apr-97 MR1 Make operator -> a const member function 00064 // as weall as some other member functions 00065 // 00066 void ANTLRTokenPtr::operator = (const ANTLRTokenPtr & lhs) // MR1 00067 { 00068 lhs.ref(); // protect against "xp = xp"; ie same underlying object 00069 deref(); 00070 ptr_ = lhs.ptr_; 00071 } 00072 00073 void ANTLRTokenPtr::operator = (ANTLRAbstractToken *addr) 00074 { 00075 if (addr != NULL) { 00076 addr->ref(); 00077 } 00078 deref(); 00079 ptr_ = addr; 00080 }