Changes in src/ResolvExpr/CurrentObject.cc [8e1467d:2d11663]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CurrentObject.cc
r8e1467d r2d11663 21 21 #include <string> // for string, operator<<, allocator 22 22 23 #include "AST/Copy.hpp" // for shallowCopy24 23 #include "AST/Expr.hpp" // for InitAlternative 25 24 #include "AST/GenericSubstitution.hpp" // for genericSubstitution 26 25 #include "AST/Init.hpp" // for Designation 27 26 #include "AST/Node.hpp" // for readonly 28 #include "AST/Print.hpp" // for readonly29 27 #include "AST/Type.hpp" 30 28 #include "Common/Indenter.h" // for Indenter, operator<< … … 598 596 SimpleIterator( const CodeLocation & loc, const Type * t ) : location( loc ), type( t ) {} 599 597 600 void setPosition( 601 std::deque< ptr< Expr > >::const_iterator begin, 598 void setPosition( 599 std::deque< ptr< Expr > >::const_iterator begin, 602 600 std::deque< ptr< Expr > >::const_iterator end 603 601 ) override { … … 639 637 auto res = eval(expr); 640 638 if ( ! res.second ) { 641 SemanticError( location, 639 SemanticError( location, 642 640 toString("Array designator must be a constant expression: ", expr ) ); 643 641 } … … 646 644 647 645 public: 648 ArrayIterator( const CodeLocation & loc, const ArrayType * at ) 646 ArrayIterator( const CodeLocation & loc, const ArrayType * at ) 649 647 : location( loc ), array( at ), base( at->base ) { 650 648 PRINT( std::cerr << "Creating array iterator: " << at << std::endl; ) … … 657 655 658 656 void setPosition( const Expr * expr ) { 659 // need to permit integer-constant-expressions, including: integer constants, 660 // enumeration constants, character constants, sizeof expressions, alignof expressions, 657 // need to permit integer-constant-expressions, including: integer constants, 658 // enumeration constants, character constants, sizeof expressions, alignof expressions, 661 659 // cast expressions 662 660 if ( auto constExpr = dynamic_cast< const ConstantExpr * >( expr ) ) { … … 664 662 index = constExpr->intValue(); 665 663 } catch ( SemanticErrorException & ) { 666 SemanticError( expr, 664 SemanticError( expr, 667 665 "Constant expression of non-integral type in array designator: " ); 668 666 } 669 667 } else if ( auto castExpr = dynamic_cast< const CastExpr * >( expr ) ) { 670 668 setPosition( castExpr->arg ); 671 } else if ( 672 dynamic_cast< const SizeofExpr * >( expr ) 673 || dynamic_cast< const AlignofExpr * >( expr ) 669 } else if ( 670 dynamic_cast< const SizeofExpr * >( expr ) 671 || dynamic_cast< const AlignofExpr * >( expr ) 674 672 ) { 675 673 index = 0; 676 674 } else { 677 assertf( false, 675 assertf( false, 678 676 "bad designator given to ArrayIterator: %s", toString( expr ).c_str() ); 679 677 } 680 678 } 681 679 682 void setPosition( 683 std::deque< ptr< Expr > >::const_iterator begin, 680 void setPosition( 681 std::deque< ptr< Expr > >::const_iterator begin, 684 682 std::deque< ptr< Expr > >::const_iterator end 685 683 ) override { … … 760 758 } 761 759 762 AggregateIterator( 763 const CodeLocation & loc, const std::string k, const std::string & n, const Type * i, 760 AggregateIterator( 761 const CodeLocation & loc, const std::string k, const std::string & n, const Type * i, 764 762 const MemberList & ms ) 765 : location( loc ), kind( k ), name( n ), inst( i ), members( ms ), curMember( ms.begin() ), 763 : location( loc ), kind( k ), name( n ), inst( i ), members( ms ), curMember( ms.begin() ), 766 764 sub( genericSubstitution( i ) ) { 767 765 PRINT( std::cerr << "Creating " << kind << "(" << name << ")"; ) … … 770 768 771 769 public: 772 void setPosition( 773 std::deque< ptr< Expr > >::const_iterator begin, 770 void setPosition( 771 std::deque< ptr< Expr > >::const_iterator begin, 774 772 std::deque< ptr< Expr > >::const_iterator end 775 773 ) final { … … 788 786 return; 789 787 } 790 assertf( false, 788 assertf( false, 791 789 "could not find member in %s: %s", kind.c_str(), toString( varExpr ).c_str() ); 792 790 } else { 793 assertf( false, 791 assertf( false, 794 792 "bad designator given to %s: %s", kind.c_str(), toString( *begin ).c_str() ); 795 793 } … … 805 803 new VariableExpr{ location, curMember->strict_as< ObjectDecl >() } ); 806 804 // need to substitute for generic types so that casts are to concrete types 807 alt.type = shallowCopy(alt.type.get());808 805 PRINT( std::cerr << " type is: " << alt.type; ) 809 806 sub.apply( alt.type ); // also apply to designation?? … … 845 842 for ( InitAlternative & alt : ret ) { 846 843 PRINT( std::cerr << "iterating and adding designators" << std::endl; ) 847 alt.designation.get_and_mutate()->designators.emplace_front( 844 alt.designation.get_and_mutate()->designators.emplace_front( 848 845 new VariableExpr{ location, curMember->strict_as< ObjectDecl >() } ); 849 846 } … … 900 897 class TupleIterator final : public AggregateIterator { 901 898 public: 902 TupleIterator( const CodeLocation & loc, const TupleType * inst ) 903 : AggregateIterator( 904 loc, "TupleIterator", toString("Tuple", inst->size()), inst, inst->members 899 TupleIterator( const CodeLocation & loc, const TupleType * inst ) 900 : AggregateIterator( 901 loc, "TupleIterator", toString("Tuple", inst->size()), inst, inst->members 905 902 ) {} 906 903 … … 929 926 return new UnionIterator{ loc, uit }; 930 927 } else { 931 assertf( 932 dynamic_cast< const EnumInstType * >( type )933 || dynamic_cast< const TypeInstType * >( type ),928 assertf( 929 dynamic_cast< const EnumInstType * >( aggr ) 930 || dynamic_cast< const TypeInstType * >( aggr ), 934 931 "Encountered unhandled ReferenceToType in createMemberIterator: %s", 935 932 toString( type ).c_str() ); … … 952 949 using DesignatorChain = std::deque< ptr< Expr > >; 953 950 PRINT( std::cerr << "___findNext" << std::endl; ) 954 951 955 952 // find all the d's 956 953 std::vector< DesignatorChain > desigAlts{ {} }, newDesigAlts; … … 1016 1013 // set new designators 1017 1014 assertf( ! objStack.empty(), "empty object stack when setting designation" ); 1018 Designation * actualDesignation = 1015 Designation * actualDesignation = 1019 1016 new Designation{ designation->location, DesignatorChain{d} }; 1020 1017 objStack.back()->setPosition( d ); // destroys d
Note:
See TracChangeset
for help on using the changeset viewer.