Changeset 2890212 for src/ResolvExpr/CurrentObject.cc
- Timestamp:
- Jul 31, 2019, 3:23:04 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- ae265b55, f49b3fc
- Parents:
- 504eb72
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CurrentObject.cc
r504eb72 r2890212 25 25 #include "AST/Init.hpp" // for Designation 26 26 #include "AST/Node.hpp" // for readonly 27 #include "AST/Print.hpp" // for readonly 27 28 #include "AST/Type.hpp" 28 29 #include "Common/Indenter.h" // for Indenter, operator<< … … 596 597 SimpleIterator( const CodeLocation & loc, const Type * t ) : location( loc ), type( t ) {} 597 598 598 void setPosition( 599 std::deque< ptr< Expr > >::const_iterator begin, 599 void setPosition( 600 std::deque< ptr< Expr > >::const_iterator begin, 600 601 std::deque< ptr< Expr > >::const_iterator end 601 602 ) override { … … 637 638 auto res = eval(expr); 638 639 if ( ! res.second ) { 639 SemanticError( location, 640 SemanticError( location, 640 641 toString("Array designator must be a constant expression: ", expr ) ); 641 642 } … … 644 645 645 646 public: 646 ArrayIterator( const CodeLocation & loc, const ArrayType * at ) 647 ArrayIterator( const CodeLocation & loc, const ArrayType * at ) 647 648 : location( loc ), array( at ), base( at->base ) { 648 649 PRINT( std::cerr << "Creating array iterator: " << at << std::endl; ) … … 655 656 656 657 void setPosition( const Expr * expr ) { 657 // need to permit integer-constant-expressions, including: integer constants, 658 // enumeration constants, character constants, sizeof expressions, alignof expressions, 658 // need to permit integer-constant-expressions, including: integer constants, 659 // enumeration constants, character constants, sizeof expressions, alignof expressions, 659 660 // cast expressions 660 661 if ( auto constExpr = dynamic_cast< const ConstantExpr * >( expr ) ) { … … 662 663 index = constExpr->intValue(); 663 664 } catch ( SemanticErrorException & ) { 664 SemanticError( expr, 665 SemanticError( expr, 665 666 "Constant expression of non-integral type in array designator: " ); 666 667 } 667 668 } else if ( auto castExpr = dynamic_cast< const CastExpr * >( expr ) ) { 668 669 setPosition( castExpr->arg ); 669 } else if ( 670 dynamic_cast< const SizeofExpr * >( expr ) 671 || dynamic_cast< const AlignofExpr * >( expr ) 670 } else if ( 671 dynamic_cast< const SizeofExpr * >( expr ) 672 || dynamic_cast< const AlignofExpr * >( expr ) 672 673 ) { 673 674 index = 0; 674 675 } else { 675 assertf( false, 676 assertf( false, 676 677 "bad designator given to ArrayIterator: %s", toString( expr ).c_str() ); 677 678 } 678 679 } 679 680 680 void setPosition( 681 std::deque< ptr< Expr > >::const_iterator begin, 681 void setPosition( 682 std::deque< ptr< Expr > >::const_iterator begin, 682 683 std::deque< ptr< Expr > >::const_iterator end 683 684 ) override { … … 758 759 } 759 760 760 AggregateIterator( 761 const CodeLocation & loc, const std::string k, const std::string & n, const Type * i, 761 AggregateIterator( 762 const CodeLocation & loc, const std::string k, const std::string & n, const Type * i, 762 763 const MemberList & ms ) 763 : location( loc ), kind( k ), name( n ), inst( i ), members( ms ), curMember( ms.begin() ), 764 : location( loc ), kind( k ), name( n ), inst( i ), members( ms ), curMember( ms.begin() ), 764 765 sub( genericSubstitution( i ) ) { 765 766 PRINT( std::cerr << "Creating " << kind << "(" << name << ")"; ) … … 768 769 769 770 public: 770 void setPosition( 771 std::deque< ptr< Expr > >::const_iterator begin, 771 void setPosition( 772 std::deque< ptr< Expr > >::const_iterator begin, 772 773 std::deque< ptr< Expr > >::const_iterator end 773 774 ) final { … … 786 787 return; 787 788 } 788 assertf( false, 789 assertf( false, 789 790 "could not find member in %s: %s", kind.c_str(), toString( varExpr ).c_str() ); 790 791 } else { 791 assertf( false, 792 assertf( false, 792 793 "bad designator given to %s: %s", kind.c_str(), toString( *begin ).c_str() ); 793 794 } … … 842 843 for ( InitAlternative & alt : ret ) { 843 844 PRINT( std::cerr << "iterating and adding designators" << std::endl; ) 844 alt.designation.get_and_mutate()->designators.emplace_front( 845 alt.designation.get_and_mutate()->designators.emplace_front( 845 846 new VariableExpr{ location, curMember->strict_as< ObjectDecl >() } ); 846 847 } … … 897 898 class TupleIterator final : public AggregateIterator { 898 899 public: 899 TupleIterator( const CodeLocation & loc, const TupleType * inst ) 900 : AggregateIterator( 901 loc, "TupleIterator", toString("Tuple", inst->size()), inst, inst->members 900 TupleIterator( const CodeLocation & loc, const TupleType * inst ) 901 : AggregateIterator( 902 loc, "TupleIterator", toString("Tuple", inst->size()), inst, inst->members 902 903 ) {} 903 904 … … 926 927 return new UnionIterator{ loc, uit }; 927 928 } else { 928 assertf( 929 dynamic_cast< const EnumInstType * >( aggr )930 || dynamic_cast< const TypeInstType * >( aggr ),929 assertf( 930 dynamic_cast< const EnumInstType * >( type ) 931 || dynamic_cast< const TypeInstType * >( type ), 931 932 "Encountered unhandled ReferenceToType in createMemberIterator: %s", 932 933 toString( type ).c_str() ); … … 949 950 using DesignatorChain = std::deque< ptr< Expr > >; 950 951 PRINT( std::cerr << "___findNext" << std::endl; ) 951 952 952 953 // find all the d's 953 954 std::vector< DesignatorChain > desigAlts{ {} }, newDesigAlts; … … 1013 1014 // set new designators 1014 1015 assertf( ! objStack.empty(), "empty object stack when setting designation" ); 1015 Designation * actualDesignation = 1016 Designation * actualDesignation = 1016 1017 new Designation{ designation->location, DesignatorChain{d} }; 1017 1018 objStack.back()->setPosition( d ); // destroys d
Note: See TracChangeset
for help on using the changeset viewer.