ATokPtrImpl.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * ATokPtrImpl.h (formerly ATokPtr.cpp)
  3. *
  4. * This is #included in ATokBuffer.cpp for historical reasons.
  5. * It has been renamed because of problems with the .cpp extension
  6. * when used with IDE.
  7. *
  8. *
  9. * ANTLRToken MUST be defined before entry to this file.
  10. *
  11. * SOFTWARE RIGHTS
  12. *
  13. * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  14. * Set (PCCTS) -- PCCTS is in the public domain. An individual or
  15. * company may do whatever they wish with source code distributed with
  16. * PCCTS or the code generated by PCCTS, including the incorporation of
  17. * PCCTS, or its output, into commerical software.
  18. *
  19. * We encourage users to develop software with PCCTS. However, we do ask
  20. * that credit is given to us for developing PCCTS. By "credit",
  21. * we mean that if you incorporate our source code into one of your
  22. * programs (commercial product, research project, or otherwise) that you
  23. * acknowledge this fact somewhere in the documentation, research report,
  24. * etc... If you like PCCTS and have developed a nice tool with the
  25. * output, please mention that you developed it using PCCTS. In
  26. * addition, we ask that this header remain intact in our source code.
  27. * As long as these guidelines are kept, we expect to continue enhancing
  28. * this system and expect to make other tools available as they are
  29. * completed.
  30. *
  31. * ANTLR 1.33
  32. * Written by Russell Quong June 30, 1995
  33. * Adapted by Terence Parr to ANTLR stuff
  34. * Parr Research Corporation
  35. * with Purdue University and AHPCRC, University of Minnesota
  36. * 1989-2000
  37. */
  38. #include "pcctscfg.h"
  39. PCCTS_NAMESPACE_STD
  40. #include "ATokPtr.h"
  41. void ANTLRTokenPtr::ref() const
  42. {
  43. if (ptr_ != NULL) {
  44. ptr_->ref();
  45. }
  46. }
  47. void ANTLRTokenPtr::deref()
  48. {
  49. if (ptr_ != NULL)
  50. {
  51. ptr_->deref();
  52. if ( ptr_->nref()==0 )
  53. {
  54. delete ptr_;
  55. ptr_ = NULL;
  56. }
  57. }
  58. }
  59. ANTLRTokenPtr::~ANTLRTokenPtr()
  60. {
  61. deref();
  62. }
  63. //
  64. // 8-Apr-97 MR1 Make operator -> a const member function
  65. // as well as some other member functions
  66. //
  67. ANTLRTokenPtr& ANTLRTokenPtr::operator = (const ANTLRTokenPtr & lhs) // MR1
  68. {
  69. lhs.ref(); // protect against "xp = xp"; ie same underlying object
  70. deref();
  71. ptr_ = lhs.ptr_;
  72. return *this;
  73. }
  74. ANTLRTokenPtr& ANTLRTokenPtr::operator = (ANTLRAbstractToken *addr)
  75. {
  76. if (addr != NULL) {
  77. addr->ref();
  78. }
  79. deref();
  80. ptr_ = addr;
  81. return *this;
  82. }