
class Expression;

/** Interface for HILTI expressions. */
class Concept : public hilti::util::type_erasure::ConceptBase {
public:
    Concept() = default;
    Concept(const Concept&) = default;
    Concept(Concept&&) = default;
    virtual ~Concept() = default;
    /** Returns the expressions's HILTI type when evaluated. */
    virtual const hilti::Type& type() const = 0;
    /**
* Returns true if the constructor's value is a value that will never
* change.
*/
    virtual bool isConstant() const = 0;
    /** Returns true if the expression is equivalent to another one in HILTI semantics. */
    virtual bool isEqual(const Expression& other) const = 0;
    /** Returns true if the expression can be the target of an assignment. */
    virtual bool isLhs() const = 0;
    /**
* Returns true if, when evaluated as RHS, the expression will yield a
* temporary value.
*/
    virtual bool isTemporary() const = 0;
    /** Implements the `Node` interface. */
    virtual hilti::node::Properties properties() const = 0;
    /** Implements the `Node` interface. */
    virtual const std::vector<hilti::Node>& children() const = 0;
    /** Implements the `Node` interface. */
    virtual std::vector<hilti::Node>& children()  = 0;
    /** Implements the `Node` interface. */
    virtual const Meta& meta() const = 0;
    /** Implements the `Node` interface. */
    virtual void setMeta(Meta m)  = 0;
    /** Implements the `Node` interface. */
    virtual bool pruneWalk() const = 0;
    Concept& operator=(const Concept&) = default;
    Concept& operator=(Concept&&) = default;
    virtual Expression _clone() const = 0;
    virtual hilti::IntrusivePtr<Concept> _clone_ptr() const = 0;
private:
    
};

template<typename T>
using ModelBase = hilti::util::type_erasure::ModelBase<T, Concept>;

template<class T>
class Model : public ModelBase<T> {
public:
    using ModelBase<T>::ModelBase;
    using ModelBase<T>::data;

    const hilti::Type& type() const final;
    bool isConstant() const final;
    bool isEqual(const Expression& other) const final;
    bool isLhs() const final;
    bool isTemporary() const final;
    hilti::node::Properties properties() const final;
    const std::vector<hilti::Node>& children() const final;
    std::vector<hilti::Node>& children()  final;
    const Meta& meta() const final;
    void setMeta(Meta m)  final;
    bool pruneWalk() const final;
    Expression _clone() const final;
    hilti::IntrusivePtr<Concept> _clone_ptr() const final;
};

using ErasedBase = hilti::util::type_erasure::ErasedBase<hilti::trait::isExpression, Concept, Model>;

class Expression : public ErasedBase, public hilti::trait::isNode {
public:
    using ErasedBase::ErasedBase;

    Expression() noexcept = default;
    Expression(Expression&&) noexcept = default;
    Expression& operator=(Expression&&) = default;
    ~Expression() override = default;
    Expression(const Expression& other) = default;
    Expression& operator=(const Expression& other) = default;

    const hilti::Type& type() const;
    bool isConstant() const;
    bool isEqual(const Expression& other) const;
    bool isLhs() const;
    bool isTemporary() const;
    hilti::node::Properties properties() const;
    const std::vector<hilti::Node>& children() const;
    std::vector<hilti::Node>& children() ;
    const Meta& meta() const;
    void setMeta(Meta m) ;
    bool pruneWalk() const;
    Expression _clone() const;

    hilti::IntrusivePtr<Concept> _clone_ptr() const;

protected:
    
};

template<typename T>
const hilti::Type& Model<T>::type() const { return data().type(); }

template<typename T>
bool Model<T>::isConstant() const { return data().isConstant(); }

template<typename T>
bool Model<T>::isEqual(const Expression& other) const { return data().isEqual(other); }

template<typename T>
bool Model<T>::isLhs() const { return data().isLhs(); }

template<typename T>
bool Model<T>::isTemporary() const { return data().isTemporary(); }

template<typename T>
hilti::node::Properties Model<T>::properties() const { return data().properties(); }

template<typename T>
const std::vector<hilti::Node>& Model<T>::children() const { return data().children(); }

template<typename T>
std::vector<hilti::Node>& Model<T>::children()  { return data().children(); }

template<typename T>
const Meta& Model<T>::meta() const { return data().meta(); }

template<typename T>
void Model<T>::setMeta(Meta m)  { return data().setMeta(m); }

template<typename T>
bool Model<T>::pruneWalk() const { return data().pruneWalk(); }

template<typename T>
Expression Model<T>::_clone() const { return T(data()); }

template<typename T>
hilti::IntrusivePtr<Concept> Model<T>::_clone_ptr() const {
    if constexpr ( std::is_base_of<hilti::util::type_erasure::trait::Singleton, T>::value )
        return nullptr;
    else
        return hilti::make_intrusive<Model>(T(data()));
}

inline const hilti::Type& Expression::type() const { return data()->type(); }

inline bool Expression::isConstant() const { return data()->isConstant(); }

inline bool Expression::isEqual(const Expression& other) const { return data()->isEqual(other); }

inline bool Expression::isLhs() const { return data()->isLhs(); }

inline bool Expression::isTemporary() const { return data()->isTemporary(); }

inline hilti::node::Properties Expression::properties() const { return data()->properties(); }

inline const std::vector<hilti::Node>& Expression::children() const { return data()->children(); }

inline std::vector<hilti::Node>& Expression::children()  { return data()->children(); }

inline const Meta& Expression::meta() const { return data()->meta(); }

inline void Expression::setMeta(Meta m)  { return data()->setMeta(std::move(m)); }

inline bool Expression::pruneWalk() const { return data()->pruneWalk(); }

inline Expression Expression::_clone() const { return data() ? data()->_clone() : Expression(); }

inline hilti::IntrusivePtr<Concept> Expression::_clone_ptr() const {
    if ( data() )
        return data()->_clone_ptr();
    else
        return nullptr;
}



