- Timestamp:
- Apr 10, 2023, 9:25:28 PM (22 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- a1b41e3
- Parents:
- 372b6d3 (diff), a085470 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CurrentObject.cc
r372b6d3 r6adeb5f 10 10 // Created On : Tue Jun 13 15:28:32 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu Apr 6 16:25:00 202313 // Update Count : 1 712 // Last Modified On : Mon Apr 10 9:40:00 2023 13 // Update Count : 18 14 14 // 15 15 … … 937 937 }; 938 938 939 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 962 public: 963 TupleIterator( const CodeLocation & loc, const TupleType * inst ) 964 : TupleIterator( loc, inst, newImaginaryMembers( inst ) ) {} 965 966 virtual ~TupleIterator() { 967 delete memberList; 939 /// Iterates across the positions in a tuple: 940 class TupleIterator final : public MemberIterator { 941 CodeLocation location; 942 ast::TupleType const * const tuple; 943 size_t index = 0; 944 size_t size = 0; 945 std::unique_ptr<MemberIterator> sub_iter; 946 947 const ast::Type * typeAtIndex() const { 948 assert( index < size ); 949 return tuple->types[ index ].get(); 950 } 951 952 public: 953 TupleIterator( const CodeLocation & loc, const TupleType * type ) 954 : location( loc ), tuple( type ), size( type->size() ) { 955 PRINT( std::cerr << "Creating tuple iterator: " << type << std::endl; ) 956 sub_iter.reset( createMemberIterator( loc, typeAtIndex() ) ); 957 } 958 959 void setPosition( const ast::Expr * expr ) { 960 auto arg = eval( expr ); 961 index = arg.first; 962 } 963 964 void setPosition( 965 std::deque< ptr< Expr > >::const_iterator begin, 966 std::deque< ptr< Expr > >::const_iterator end ) { 967 if ( begin == end ) return; 968 969 setPosition( *begin ); 970 sub_iter->setPosition( ++begin, end ); 971 } 972 973 std::deque< InitAlternative > operator*() const override { 974 return first(); 968 975 } 969 976 970 977 operator bool() const override { 971 return curMember != members.end() || (memberIter && *memberIter);978 return index < size; 972 979 } 973 980 974 981 TupleIterator & bigStep() override { 975 PRINT( std::cerr << "bigStep in " << kind << std::endl; ) 976 atbegin = false; 977 memberIter = nullptr; 978 curType = nullptr; 979 while ( curMember != members.end() ) { 980 ++curMember; 981 if ( init() ) return *this; 982 } 982 ++index; 983 sub_iter.reset( index < size ? 984 createMemberIterator( location, typeAtIndex() ) : nullptr ); 983 985 return *this; 986 } 987 988 TupleIterator & smallStep() override { 989 if ( sub_iter ) { 990 PRINT( std::cerr << "has member iter: " << *sub_iter << std::endl; ) 991 sub_iter->smallStep(); 992 if ( !sub_iter ) { 993 PRINT( std::cerr << "has valid member iter" << std::endl; ) 994 return *this; 995 } 996 } 997 return bigStep(); 998 } 999 1000 const ast::Type * getType() override { 1001 return tuple; 1002 } 1003 1004 const ast::Type * getNext() override { 1005 return ( sub_iter && *sub_iter ) ? sub_iter->getType() : nullptr; 1006 } 1007 1008 std::deque< InitAlternative > first() const override { 1009 PRINT( std::cerr << "first in TupleIterator (" << index << "/" << size << ")" << std::endl; ) 1010 if ( sub_iter && *sub_iter ) { 1011 std::deque< InitAlternative > ret = sub_iter->first(); 1012 for ( InitAlternative & alt : ret ) { 1013 alt.designation.get_and_mutate()->designators.emplace_front( 1014 ConstantExpr::from_ulong( location, index ) ); 1015 } 1016 return ret; 1017 } 1018 return {}; 984 1019 } 985 1020 };
Note: See TracChangeset
for help on using the changeset viewer.