Goose  Artifact [bd3a39fa52]

Artifact bd3a39fa52c8eb16f96bd8e7523a1c0ce755a7fc09a275bc451a11a22524bcfa:

  • File bs/builtins/types/struct/builder.h — part of check-in [7bf7fc54a6] at 2024-01-01 23:23:05 on branch trunk — Structs: build the underlying tuple type in finalize() (user: zlodo size: 1359)

#ifndef GOOSE_BUILTINS_TYPES_STRUCT_BUILDER_H
#define GOOSE_BUILTINS_TYPES_STRUCT_BUILDER_H

namespace goose::builtins
{
    class StructBuilder
    {
        public:
            template< typename I >
            StructBuilder( I&& identity ) :
                m_identity( forward< I >( identity ) )
            {
                m_defaultCtorCFG->createBB();
                m_defaultCtorCFG->setCurrentBB( m_defaultCtorCFG->entryBB() );
            }

            const auto& identity() const { return m_identity; }
            const auto& defaultCtorCFG() const { return m_defaultCtorCFG; }

            template< typename T >
            void declareMemberVar( const Context& c, StringId name, T&& type, LocationId loc );

            template< typename T, typename V >
            void declareMemberVar( const Context& c, StringId name, T&& type, LocationId loc, V&& init );

            bool finalize( const Context& c ) const;

        private:
            Term m_identity;
            ptr< cir::CFG > m_defaultCtorCFG = make_shared< cir::CFG >( 0 );

            struct MemberVar
            {
                optional< Value > init;
                Term m_type;
                StringId name;
                LocationId loc;
                uint32_t uid;
            };

            llvm::SmallVector< MemberVar, 8 > m_memberVars;
    };

}

#endif