Line data Source code
1 : // Author(s): Jan Friso Groote 2 : // Copyright: see the accompanying file COPYING or copy at 3 : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING 4 : // 5 : // Distributed under the Boost Software License, Version 1.0. 6 : // (See accompanying file LICENSE_1_0.txt or copy at 7 : // http://www.boost.org/LICENSE_1_0.txt) 8 : // 9 : 10 : #ifndef MCRL2_ATERMPP_DETAIL_ATERM_H 11 : #define MCRL2_ATERMPP_DETAIL_ATERM_H 12 : 13 : #include <limits> 14 : 15 : #include "mcrl2/utilities/type_traits.h" 16 : #include "mcrl2/atermpp/function_symbol.h" 17 : 18 : namespace atermpp 19 : { 20 : 21 : // Forward declaration. 22 : class unprotected_aterm; 23 : class aterm; 24 : 25 : namespace detail 26 : { 27 : 28 : class _aterm; 29 : inline void debug_print(std::ostream& o, const _aterm* t, const std::size_t d = 3); 30 : 31 : /// Can be used to check whether all elements in the parameter pack are derived from aterms. 32 : template<typename ...Terms> 33 : using are_terms = mcrl2::utilities::forall<std::is_convertible<Terms, unprotected_aterm>...>; 34 : 35 : /// Check whether all arguments of a parameter pack are terms, constant functions yielding a term 36 : /// or a function putting a term in a result parameter. 37 : 38 : template <typename Term> 39 : using is_term_or_function = std::disjunction<std::is_convertible<Term, unprotected_aterm>, 40 : std::disjunction<mcrl2::utilities::is_applicable<Term, unprotected_aterm&>, 41 : mcrl2::utilities::is_constant_function_yielding<Term, unprotected_aterm> > >; 42 : 43 : template<typename ...Terms> 44 : using are_terms_or_functions = mcrl2::utilities::forall<is_term_or_function<Terms>...>; 45 : 46 : /// \brief This is the class to which an aterm points. 47 : class _aterm : public mcrl2::utilities::noncopyable 48 : { 49 : public: 50 : /// \brief Create a term from a function symbol. 51 1070150 : _aterm(const function_symbol& symbol) : 52 1070150 : m_function_symbol(symbol) 53 1070150 : {} 54 : 55 69935556642 : const function_symbol& function() const noexcept 56 : { 57 69935556642 : return m_function_symbol; 58 : } 59 : 60 : /// \brief Mark this term to be garbage collected. 61 48405 : void mark() const 62 : { 63 48405 : m_function_symbol.m_function_symbol.tag(); 64 48405 : } 65 : 66 : /// \brief Remove the mark from a term. 67 29474 : void unmark() const 68 : { 69 29474 : m_function_symbol.m_function_symbol.untag(); 70 29474 : } 71 : 72 : /// \brief Check if the term is already marked. 73 6546423 : bool is_marked() const 74 : { 75 6546423 : return m_function_symbol.m_function_symbol.tagged(); 76 : } 77 : 78 : private: 79 : function_symbol m_function_symbol; 80 : }; 81 : 82 : inline _aterm* address(const unprotected_aterm& t); 83 : 84 : } // namespace detail 85 : } // namespace atermpp 86 : 87 : #endif /* MCRL2_ATERMPP_DETAIL_ATERM_H */