Changeset f37d9e7
- Timestamp:
- Jul 1, 2022, 5:36:10 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 0edbdb2
- Parents:
- 7991c7d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CurrentObject.cc
r7991c7d rf37d9e7 9 9 // Author : Rob Schluntz 10 10 // Created On : Tue Jun 13 15:28:32 2017 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Tue Jun 13 15:28:44 201713 // Update Count : 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 1 09:16:01 2022 13 // Update Count : 15 14 14 // 15 15 … … 158 158 159 159 private: 160 void setSize( Expression * expr ) { // replace this logic with an eval call161 auto res = eval( expr);160 void setSize( Expression * expr ) { 161 auto res = eval( expr ); 162 162 if (res.second) { 163 163 size = res.first; … … 170 170 void setPosition( Expression * expr ) { 171 171 // need to permit integer-constant-expressions, including: integer constants, enumeration constants, character constants, sizeof expressions, _Alignof expressions, cast expressions 172 if ( ConstantExpr * constExpr = dynamic_cast< ConstantExpr * >( expr ) ) { 173 try { 174 index = constExpr->intValue(); 175 } catch( SemanticErrorException & ) { 176 SemanticError( expr, "Constant expression of non-integral type in array designator: " ); 177 } 178 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 179 setPosition( castExpr->get_arg() ); 180 } else if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( expr ) ) { 181 EnumInstType * inst = dynamic_cast<EnumInstType *>( varExpr->get_result() ); 182 assertf( inst, "ArrayIterator given variable that isn't an enum constant : %s", toString( expr ).c_str() ); 183 long long int value; 184 if ( inst->baseEnum->valueOf( varExpr->var, value ) ) { 185 index = value; 186 } 187 } else if ( dynamic_cast< SizeofExpr * >( expr ) || dynamic_cast< AlignofExpr * >( expr ) ) { 188 index = 0; // xxx - get actual sizeof/alignof value? 189 } else { 190 assertf( false, "bad designator given to ArrayIterator: %s", toString( expr ).c_str() ); 191 } 172 auto arg = eval( expr ); 173 index = arg.first; 174 return; 175 176 // if ( ConstantExpr * constExpr = dynamic_cast< ConstantExpr * >( expr ) ) { 177 // try { 178 // index = constExpr->intValue(); 179 // } catch( SemanticErrorException & ) { 180 // SemanticError( expr, "Constant expression of non-integral type in array designator: " ); 181 // } 182 // } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 183 // setPosition( castExpr->get_arg() ); 184 // } else if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( expr ) ) { 185 // EnumInstType * inst = dynamic_cast<EnumInstType *>( varExpr->get_result() ); 186 // assertf( inst, "ArrayIterator given variable that isn't an enum constant : %s", toString( expr ).c_str() ); 187 // long long int value; 188 // if ( inst->baseEnum->valueOf( varExpr->var, value ) ) { 189 // index = value; 190 // } 191 // } else if ( dynamic_cast< SizeofExpr * >( expr ) || dynamic_cast< AlignofExpr * >( expr ) ) { 192 // index = 0; // xxx - get actual sizeof/alignof value? 193 // } else { 194 // assertf( false, "4 bad designator given to ArrayIterator: %s", toString( expr ).c_str() ); 195 // } 192 196 } 193 197 … … 329 333 assertf( false, "could not find member in %s: %s", kind.c_str(), toString( varExpr ).c_str() ); 330 334 } else { 331 assertf( false, " bad designator given to %s: %s", kind.c_str(), toString( designators.front() ).c_str() );335 assertf( false, "3 bad designator given to %s: %s", kind.c_str(), toString( designators.front() ).c_str() ); 332 336 } // if 333 337 } // if … … 637 641 638 642 void setSize( const Expr * expr ) { 639 auto res = eval( expr);643 auto res = eval( expr ); 640 644 if ( ! res.second ) { 641 SemanticError( location, 642 toString("Array designator must be a constant expression: ", expr ) ); 645 SemanticError( location, toString( "Array designator must be a constant expression: ", expr ) ); 643 646 } 644 647 size = res.first; … … 646 649 647 650 public: 648 ArrayIterator( const CodeLocation & loc, const ArrayType * at ) 649 : location( loc ), array( at ), base( at->base ) { 651 ArrayIterator( const CodeLocation & loc, const ArrayType * at ) : location( loc ), array( at ), base( at->base ) { 650 652 PRINT( std::cerr << "Creating array iterator: " << at << std::endl; ) 651 653 memberIter.reset( createMemberIterator( loc, base ) ); … … 660 662 // enumeration constants, character constants, sizeof expressions, alignof expressions, 661 663 // cast expressions 662 if ( auto constExpr = dynamic_cast< const ConstantExpr * >( expr ) ) { 663 try {664 index = constExpr->intValue();665 } catch ( SemanticErrorException & ) {666 SemanticError( expr, 667 "Constant expression of non-integral type in array designator: " );668 }669 } else if ( auto castExpr = dynamic_cast< const CastExpr * >( expr ) ) {670 setPosition( castExpr->arg );671 } else if (672 dynamic_cast< const SizeofExpr * >( expr )673 || dynamic_cast< const AlignofExpr * >( expr )674 ) {675 index = 0;676 } else {677 assertf( false,678 "bad designator given to ArrayIterator: %s", toString( expr ).c_str() );679 }664 665 auto arg = eval( expr ); 666 index = arg.first; 667 return; 668 669 // if ( auto constExpr = dynamic_cast< const ConstantExpr * >( expr ) ) { 670 // try { 671 // index = constExpr->intValue(); 672 // } catch ( SemanticErrorException & ) { 673 // SemanticError( expr, "Constant expression of non-integral type in array designator: " ); 674 // } 675 // } else if ( auto castExpr = dynamic_cast< const CastExpr * >( expr ) ) { 676 // setPosition( castExpr->arg ); 677 // } else if ( dynamic_cast< const SizeofExpr * >( expr ) || dynamic_cast< const AlignofExpr * >( expr ) ) { 678 // index = 0; 679 // } else { 680 // assertf( false, "2 bad designator given to ArrayIterator: %s", toString( expr ).c_str() ); 681 // } 680 682 } 681 683 … … 723 725 std::deque< InitAlternative > ret = memberIter->first(); 724 726 for ( InitAlternative & alt : ret ) { 725 alt.designation.get_and_mutate()->designators.emplace_front( 726 ConstantExpr::from_ulong( location, index ) ); 727 alt.designation.get_and_mutate()->designators.emplace_front( ConstantExpr::from_ulong( location, index ) ); 727 728 } 728 729 return ret; … … 788 789 return; 789 790 } 790 assertf( false, 791 "could not find member in %s: %s", kind.c_str(), toString( varExpr ).c_str() ); 791 assertf( false, "could not find member in %s: %s", kind.c_str(), toString( varExpr ).c_str() ); 792 792 } else { 793 assertf( false, 794 "bad designator given to %s: %s", kind.c_str(), toString( *begin ).c_str() ); 793 assertf( false, "1 bad designator given to %s: %s", kind.c_str(), toString( *begin ).c_str() ); 795 794 } 796 795 }
Note: See TracChangeset
for help on using the changeset viewer.