Changeset 8472c6c for src/ResolvExpr


Ignore:
Timestamp:
Apr 8, 2023, 3:50:53 PM (15 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/ResolvExpr
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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.