Changeset 8472c6c


Ignore:
Timestamp:
Apr 8, 2023, 3:50:53 PM (21 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master
Children:
372b6d3, ea2759b
Parents:
beabdf3 (diff), 485393c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
5 edited

Legend:

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

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

    rbeabdf3 r8472c6c  
    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

    rbeabdf3 r8472c6c  
    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

    rbeabdf3 r8472c6c  
    99// Author           : Rob Schluntz
    1010// Created On       : Tue Jun 13 15:28:32 2017
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul  1 09:16:01 2022
    13 // Update Count     : 15
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu Apr  6 16:25:00 2023
     13// Update Count     : 17
    1414//
    1515
     
    593593
    594594namespace ast {
     595        /// Iterates members of a type by initializer.
     596        class MemberIterator {
     597        public:
     598                virtual ~MemberIterator() {}
     599
     600                /// Internal set position based on iterator ranges.
     601                virtual void setPosition(
     602                        std::deque< ptr< Expr > >::const_iterator it,
     603                        std::deque< ptr< Expr > >::const_iterator end ) = 0;
     604
     605                /// Walks the current object using the given designators as a guide.
     606                void setPosition( const std::deque< ptr< Expr > > & designators ) {
     607                        setPosition( designators.begin(), designators.end() );
     608                }
     609
     610                /// Retrieve the list of possible (Type,Designation) pairs for the
     611                /// current position in the current object.
     612                virtual std::deque< InitAlternative > operator* () const = 0;
     613
     614                /// True if the iterator is not currently at the end.
     615                virtual operator bool() const = 0;
     616
     617                /// Moves the iterator by one member in the current object.
     618                virtual MemberIterator & bigStep() = 0;
     619
     620                /// Moves the iterator by one member in the current subobject.
     621                virtual MemberIterator & smallStep() = 0;
     622
     623                /// The type of the current object.
     624                virtual const Type * getType() = 0;
     625
     626                /// The type of the current subobject.
     627                virtual const Type * getNext() = 0;
     628
     629                /// Helper for operator*; aggregates must add designator to each init
     630                /// alternative, but adding designators in operator* creates duplicates.
     631                virtual std::deque< InitAlternative > first() const = 0;
     632        };
     633
    595634        /// create a new MemberIterator that traverses a type correctly
    596635        MemberIterator * createMemberIterator( const CodeLocation & loc, const Type * type );
     
    684723
    685724                void setPosition(
    686                         std::deque< ptr< Expr > >::const_iterator begin,
    687                         std::deque< ptr< Expr > >::const_iterator end
     725                        std::deque<ast::ptr<ast::Expr>>::const_iterator begin,
     726                        std::deque<ast::ptr<ast::Expr>>::const_iterator end
    688727                ) override {
    689728                        if ( begin == end ) return;
     
    899938
    900939        class TupleIterator final : public AggregateIterator {
     940                MemberList * memberList;
     941
     942                TupleIterator( const CodeLocation & loc,
     943                        const ast::TupleType * inst, MemberList * memberList )
     944                : AggregateIterator(
     945                        loc, "TupleIterator", toString("Tuple", inst->size()), inst, *memberList
     946                ), memberList( memberList ) {}
     947
     948                // The two layer constructor, this helper and the destructor
     949                // are all to pretend that Tuples have members (they do not).
     950                static MemberList * newImaginaryMembers( const ast::TupleType * inst ) {
     951                        auto ret = new MemberList();
     952                        ret->reserve( inst->types.size() );
     953                        for ( const ast::Type * type : inst->types ) {
     954                                ret->emplace_back( new ast::ObjectDecl(
     955                                        CodeLocation(), "", type,
     956                                        new ast::ListInit( CodeLocation(), {}, {}, ast::NoConstruct )
     957                                ) );
     958                        }
     959                        return ret;
     960                }
     961
    901962        public:
    902963                TupleIterator( const CodeLocation & loc, const TupleType * inst )
    903                 : AggregateIterator(
    904                         loc, "TupleIterator", toString("Tuple", inst->size()), inst, inst->members
    905                 ) {}
     964                : TupleIterator( loc, inst, newImaginaryMembers( inst ) ) {}
     965
     966                virtual ~TupleIterator() {
     967                        delete memberList;
     968                }
    906969
    907970                operator bool() const override {
  • src/ResolvExpr/CurrentObject.h

    rbeabdf3 r8472c6c  
    99// Author           : Rob Schluntz
    1010// Created On       : Thu Jun  8 11:07:25 2017
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:36:48 2017
    13 // Update Count     : 3
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu Apr  6 16:14:00 2023
     13// Update Count     : 4
    1414//
    1515
     
    6565
    6666        /// Iterates members of a type by initializer
    67         class MemberIterator {
    68         public:
    69                 virtual ~MemberIterator() {}
    70 
    71                 /// Internal set position based on iterator ranges
    72                 virtual void setPosition(
    73                         std::deque< ptr< Expr > >::const_iterator it,
    74                         std::deque< ptr< Expr > >::const_iterator end ) = 0;
    75 
    76                 /// walks the current object using the given designators as a guide
    77                 void setPosition( const std::deque< ptr< Expr > > & designators ) {
    78                         setPosition( designators.begin(), designators.end() );
    79                 }
    80 
    81                 /// retrieve the list of possible (Type,Designation) pairs for the current position in the
    82                 /// current object
    83                 virtual std::deque< InitAlternative > operator* () const = 0;
    84 
    85                 /// true if the iterator is not currently at the end
    86                 virtual operator bool() const = 0;
    87 
    88                 /// moves the iterator by one member in the current object
    89                 virtual MemberIterator & bigStep() = 0;
    90 
    91                 /// moves the iterator by one member in the current subobject
    92                 virtual MemberIterator & smallStep() = 0;
    93 
    94                 /// the type of the current object
    95                 virtual const Type * getType() = 0;
    96 
    97                 /// the type of the current subobject
    98                 virtual const Type * getNext() = 0;
    99        
    100                 /// helper for operator*; aggregates must add designator to each init alternative, but
    101                 /// adding designators in operator* creates duplicates
    102                 virtual std::deque< InitAlternative > first() const = 0;
    103         };
     67        class MemberIterator;
    10468
    10569        /// Builds initializer lists in resolution
Note: See TracChangeset for help on using the changeset viewer.