Changes in src/ResolvExpr/CurrentObject.cc [f37d9e7:1df492a]
- File:
-
- 1 edited
-
src/ResolvExpr/CurrentObject.cc (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CurrentObject.cc
rf37d9e7 r1df492a 9 9 // Author : Rob Schluntz 10 10 // Created On : Tue Jun 13 15:28:32 2017 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Jul 1 09:16:01 202213 // Update Count : 1511 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jun 13 15:28:44 2017 13 // Update Count : 2 14 14 // 15 15 … … 158 158 159 159 private: 160 void setSize( Expression * expr ) { 161 auto res = eval( expr);160 void setSize( Expression * expr ) { // replace this logic with an eval call 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 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 // } 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 } 196 192 } 197 193 … … 333 329 assertf( false, "could not find member in %s: %s", kind.c_str(), toString( varExpr ).c_str() ); 334 330 } else { 335 assertf( false, " 3bad designator given to %s: %s", kind.c_str(), toString( designators.front() ).c_str() );331 assertf( false, "bad designator given to %s: %s", kind.c_str(), toString( designators.front() ).c_str() ); 336 332 } // if 337 333 } // if … … 641 637 642 638 void setSize( const Expr * expr ) { 643 auto res = eval( expr);639 auto res = eval(expr); 644 640 if ( ! res.second ) { 645 SemanticError( location, toString( "Array designator must be a constant expression: ", expr ) ); 641 SemanticError( location, 642 toString("Array designator must be a constant expression: ", expr ) ); 646 643 } 647 644 size = res.first; … … 649 646 650 647 public: 651 ArrayIterator( const CodeLocation & loc, const ArrayType * at ) : location( loc ), array( at ), base( at->base ) { 648 ArrayIterator( const CodeLocation & loc, const ArrayType * at ) 649 : location( loc ), array( at ), base( at->base ) { 652 650 PRINT( std::cerr << "Creating array iterator: " << at << std::endl; ) 653 651 memberIter.reset( createMemberIterator( loc, base ) ); … … 662 660 // enumeration constants, character constants, sizeof expressions, alignof expressions, 663 661 // cast expressions 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, "2bad designator given to ArrayIterator: %s", toString( expr ).c_str() );681 //}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 } 682 680 } 683 681 … … 725 723 std::deque< InitAlternative > ret = memberIter->first(); 726 724 for ( InitAlternative & alt : ret ) { 727 alt.designation.get_and_mutate()->designators.emplace_front( ConstantExpr::from_ulong( location, index ) ); 725 alt.designation.get_and_mutate()->designators.emplace_front( 726 ConstantExpr::from_ulong( location, index ) ); 728 727 } 729 728 return ret; … … 789 788 return; 790 789 } 791 assertf( false, "could not find member in %s: %s", kind.c_str(), toString( varExpr ).c_str() ); 790 assertf( false, 791 "could not find member in %s: %s", kind.c_str(), toString( varExpr ).c_str() ); 792 792 } else { 793 assertf( false, "1 bad designator given to %s: %s", kind.c_str(), toString( *begin ).c_str() ); 793 assertf( false, 794 "bad designator given to %s: %s", kind.c_str(), toString( *begin ).c_str() ); 794 795 } 795 796 }
Note:
See TracChangeset
for help on using the changeset viewer.