diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2020-12-17 20:50:19 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2020-12-17 23:51:16 +0900 |
commit | 4ae7b32dc09eb7acd9411a8af63a767660aa64ec (patch) | |
tree | 3d150131675502f5d5a3ff054ec6fc3dbe4e78fd /lib/antlr/antlr/ASTRefCount.h | |
parent | 25071ecede33675972c3163f4b46df964a06dadf (diff) | |
download | tdevelop-4ae7b32dc09eb7acd9411a8af63a767660aa64ec.tar.gz tdevelop-4ae7b32dc09eb7acd9411a8af63a767660aa64ec.zip |
Renaming of files in preparation for code style tools.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit 3e3d9eda9d1dd8c67c1c27c6a9bdc68bdecfcc30)
Diffstat (limited to 'lib/antlr/antlr/ASTRefCount.h')
-rw-r--r-- | lib/antlr/antlr/ASTRefCount.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/lib/antlr/antlr/ASTRefCount.h b/lib/antlr/antlr/ASTRefCount.h new file mode 100644 index 00000000..889ecc9d --- /dev/null +++ b/lib/antlr/antlr/ASTRefCount.h @@ -0,0 +1,98 @@ +#ifndef INC_ASTRefCount_h__ +# define INC_ASTRefCount_h__ + +/* ANTLR Translator Generator + * Project led by Terence Parr at http://www.jGuru.com + * Software rights: http://www.antlr.org/license.html + * + * $Id$ + */ + +# include <antlr/config.h> + +#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE +namespace antlr { +#endif + + class AST; + +struct ANTLR_API ASTRef +{ + AST* const ptr; + unsigned int count; + + ASTRef(AST* p); + ~ASTRef(); + ASTRef* increment() + { + ++count; + return this; + } + bool decrement() + { + return (--count==0); + } + + static ASTRef* getRef(const AST* p); +private: + ASTRef( const ASTRef& ); + ASTRef& operator=( const ASTRef& ); +}; + +template<class T> + class ANTLR_API ASTRefCount +{ +private: + ASTRef* ref; + +public: + ASTRefCount(const AST* p=0) + : ref(p ? ASTRef::getRef(p) : 0) + { + } + ASTRefCount(const ASTRefCount<T>& other) + : ref(other.ref ? other.ref->increment() : 0) + { + } + ~ASTRefCount() + { + if (ref && ref->decrement()) + delete ref; + } + ASTRefCount<T>& operator=(AST* other) + { + ASTRef* tmp = ASTRef::getRef(other); + + if (ref && ref->decrement()) + delete ref; + + ref=tmp; + + return *this; + } + ASTRefCount<T>& operator=(const ASTRefCount<T>& other) + { + if( other.ref != ref ) + { + ASTRef* tmp = other.ref ? other.ref->increment() : 0; + + if (ref && ref->decrement()) + delete ref; + + ref=tmp; + } + return *this; + } + + operator T* () const { return ref ? static_cast<T*>(ref->ptr) : 0; } + T* operator->() const { return ref ? static_cast<T*>(ref->ptr) : 0; } + T* get() const { return ref ? static_cast<T*>(ref->ptr) : 0; } +}; + +typedef ASTRefCount<AST> RefAST; + +#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE +} +#endif + +#endif //INC_ASTRefCount_h__ |