Changeset fac05b3


Ignore:
Timestamp:
Apr 6, 2023, 4:09:24 PM (20 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master
Children:
485393c
Parents:
c468150
Message:

Removed members from TupleType?. They were only used in one place, CurrentObject?. That now has a patch to create its own imaginary members.

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.impl.hpp

    rc468150 rfac05b3  
    20422042        if ( __visit_children() ) {
    20432043                maybe_accept( node, &TupleType::types );
    2044                 maybe_accept( node, &TupleType::members );
    20452044        }
    20462045
  • src/AST/Type.cpp

    rc468150 rfac05b3  
    1010// Created On       : Mon May 13 15:00:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thu Nov 24  9:49:00 2022
    13 // Update Count     : 6
     12// Last Modified On : Thu Apr  6 15:59:00 2023
     13// Update Count     : 7
    1414//
    1515
     
    199199
    200200TupleType::TupleType( std::vector<ptr<Type>> && ts, CV::Qualifiers q )
    201 : Type( q ), types( std::move(ts) ), members() {
    202         // This constructor is awkward. `TupleType` needs to contain objects so that members can be
    203         // named, but members without initializer nodes end up getting constructors, which breaks
    204         // things. This happens because the object decls have to be visited so that their types are
    205         // kept in sync with the types listed here. Ultimately, the types listed here should perhaps
    206         // be eliminated and replaced with a list-view over members. The temporary solution is to
    207         // make a `ListInit` with `maybeConstructed = false`, so when the object is visited it is not
    208         // constructed. Potential better solutions include:
    209         //   a) Separate `TupleType` from its declarations, into `TupleDecl` and `Tuple{Inst?}Type`,
    210         //      similar to the aggregate types.
    211         //   b) Separate initializer nodes better, e.g. add a `MaybeConstructed` node that is replaced
    212         //      by `genInit`, rather than the current boolean flag.
    213         members.reserve( types.size() );
    214         for ( const Type * ty : types ) {
    215                 members.emplace_back( new ObjectDecl{
    216                         CodeLocation(), "", ty, new ListInit( CodeLocation(), {}, {}, NoConstruct ),
    217                         Storage::Classes{}, Linkage::Cforall } );
    218         }
    219 }
     201: Type( q ), types( std::move(ts) ) {}
    220202
    221203bool isUnboundType(const Type * type) {
  • src/AST/Type.hpp

    rc468150 rfac05b3  
    1010// Created On       : Thu May 9 10:00:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thu Nov 24  9:47:00 2022
    13 // Update Count     : 8
     12// Last Modified On : Thu Apr  6 15:58:00 2023
     13// Update Count     : 9
    1414//
    1515
     
    457457public:
    458458        std::vector<ptr<Type>> types;
    459         std::vector<ptr<Decl>> members;
    460459
    461460        TupleType( std::vector<ptr<Type>> && ts, CV::Qualifiers q = {} );
  • src/ResolvExpr/CurrentObject.cc

    rc468150 rfac05b3  
    1010// Created On       : Tue Jun 13 15:28:32 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul  1 09:16:01 2022
    13 // Update Count     : 15
     12// Last Modified On : Thu Apr  6 16:03:00 2023
     13// Update Count     : 16
    1414//
    1515
     
    899899
    900900        class TupleIterator final : public AggregateIterator {
     901                MemberList * memberList;
     902
     903                TupleIterator( const CodeLocation & loc,
     904                        const ast::TupleType * inst, MemberList * memberList )
     905                : AggregateIterator(
     906                        loc, "TupleIterator", toString("Tuple", inst->size()), inst, *memberList
     907                ), memberList( memberList ) {}
     908
     909                // The two layer constructor, this helper and the destructor
     910                // are all to pretend that Tuples have members (they do not).
     911                static MemberList * newImaginaryMembers( const ast::TupleType * inst ) {
     912                        auto ret = new MemberList();
     913                        ret->reserve( inst->types.size() );
     914                        for ( const ast::Type * type : inst->types ) {
     915                                ret->emplace_back( new ast::ObjectDecl(
     916                                        CodeLocation(), "", type,
     917                                        new ast::ListInit( CodeLocation(), {}, {}, ast::NoConstruct )
     918                                ) );
     919                        }
     920                        return ret;
     921                }
     922
    901923        public:
    902924                TupleIterator( const CodeLocation & loc, const TupleType * inst )
    903                 : AggregateIterator(
    904                         loc, "TupleIterator", toString("Tuple", inst->size()), inst, inst->members
    905                 ) {}
     925                : TupleIterator( loc, inst, newImaginaryMembers( inst ) ) {}
     926
     927                virtual ~TupleIterator() {
     928                        delete memberList;
     929                }
    906930
    907931                operator bool() const override {
Note: See TracChangeset for help on using the changeset viewer.