Goose  Artifact [975600085e]

Artifact 975600085efc63f670c4619d1d7b6a35a6341e130c3da2b6fc653c46c32e8051:

  • File bs/builtins/types/overloadset/overloadset.h — part of check-in [9089b014a2] at 2019-03-16 23:19:44 on branch trunk — Overloading: parse function overloading, and multiple fixes. Overloading now works. (user: achavasse size: 1373)

#ifndef EMPATHY_BUILTINS_TYPES_OVERLOADSET_H
#define EMPATHY_BUILTINS_TYPES_OVERLOADSET_H

namespace empathy::builtins
{
    void SetupOverloadSetInvocationRule( Env& e );

    class OverloadSet
    {
        public:
            struct Overload
            {
                ptr< InvocationRule > pInvRule;
                optional< Value > callee;
            };

            OverloadSet( const StringId& name ) :
                m_name( name )
            {}

            const auto& name() const { return m_name; }

            bool add( const sema::Context& context, const Value& callee );

            using UniGen = Generator< tuple<
                Term,
                const Overload&,
                UnificationContext
            > >;

            UniGen unify( const Term& argsPat, const Term& rtPat, UnificationContext& uc ) const;

        private:
            StringId m_name;

            using utrie_type = UTrie< Trie< Overload > >;
            ptr< utrie_type > m_trie = make_shared< utrie_type >();
    };

    extern bool IsOverloadSet( const Value& os );
}

namespace empathy::ir
{
    template<>
    struct Bridge< ptr< builtins::OverloadSet > >
    {
        static const Term& Type();
        static Value ToValue( const ptr< builtins::OverloadSet >& os );
        static ptr< builtins::OverloadSet > FromValue( const Value& v );
    };
}

#endif