Changes in src/ResolvExpr/CurrentObject.cc [c6747a1:4b97770]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CurrentObject.cc
rc6747a1 r4b97770 38 38 39 39 namespace ResolvExpr { 40 long long int getConstValue( ConstantExpr * constExpr ) {41 if ( BasicType * basicType = dynamic_cast< BasicType * >( constExpr->get_result() ) ) {42 if ( basicType->isInteger() ) {43 return constExpr->get_constant()->get_ival();44 } else {45 assertf( false, "Non-integer constant expression in getConstValue %s", toString( constExpr ).c_str() ); // xxx - might be semantic error46 }47 } else if ( dynamic_cast< OneType * >( constExpr->get_result() ) ) {48 return 1;49 } else if ( dynamic_cast< ZeroType * >( constExpr->get_result() ) ) {50 return 0;51 } else {52 assertf( false, "unhandled type on getConstValue %s", toString( constExpr->get_result() ).c_str() ); // xxx - might be semantic error53 }54 }55 56 40 template< typename AggrInst > 57 41 TypeSubstitution makeGenericSubstitution( AggrInst * inst ) { … … 141 125 base = at->get_base(); 142 126 memberIter = createMemberIterator( base ); 127 if ( at->isVarLen ) throw SemanticError( "VLA initialization does not support @=", at ); 143 128 setSize( at->get_dimension() ); 144 129 } … … 151 136 void setSize( Expression * expr ) { 152 137 if ( ConstantExpr * constExpr = dynamic_cast< ConstantExpr * >( expr ) ) { 153 size = getConstValue( constExpr ); 154 PRINT( std::cerr << "array type with size: " << size << std::endl; ) 138 try { 139 size = constExpr->intValue(); 140 PRINT( std::cerr << "array type with size: " << size << std::endl; ) 141 } catch ( SemanticError & ) { 142 throw SemanticError( "Constant expression of non-integral type in array dimension: ", expr ); 143 } 155 144 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 156 145 setSize( castExpr->get_arg() ); // xxx - need to perform the conversion specified by the cast 146 } else if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( expr ) ) { 147 if ( EnumInstType * inst = dynamic_cast< EnumInstType * > ( varExpr->result ) ) { 148 long long int value; 149 if ( inst->baseEnum->valueOf( varExpr->var, value ) ) { 150 size = value; 151 } 152 } 157 153 } else { 158 154 assertf( false, "unhandled expression in setSize: %s", toString( expr ).c_str() ); // xxx - if not a constant expression, it's not simple to determine how long the array actually is, which is necessary for initialization to be done correctly -- fix this … … 164 160 // need to permit integer-constant-expressions, including: integer constants, enumeration constants, character constants, sizeof expressions, _Alignof expressions, cast expressions 165 161 if ( ConstantExpr * constExpr = dynamic_cast< ConstantExpr * >( expr ) ) { 166 index = getConstValue( constExpr ); 162 try { 163 index = constExpr->intValue(); 164 } catch( SemanticError & ) { 165 throw SemanticError( "Constant expression of non-integral type in array designator: ", expr ); 166 } 167 167 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 168 168 setPosition( castExpr->get_arg() ); 169 169 } else if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( expr ) ) { 170 assertf( dynamic_cast<EnumInstType *> ( varExpr->get_result() ), "ArrayIterator given variable that isn't an enum constant : %s", toString( expr ).c_str() ); 171 index = 0; // xxx - get actual value of enum constant 170 EnumInstType * inst = dynamic_cast<EnumInstType *>( varExpr->get_result() ); 171 assertf( inst, "ArrayIterator given variable that isn't an enum constant : %s", toString( expr ).c_str() ); 172 long long int value; 173 if ( inst->baseEnum->valueOf( varExpr->var, value ) ) { 174 index = value; 175 } 172 176 } else if ( dynamic_cast< SizeofExpr * >( expr ) || dynamic_cast< AlignofExpr * >( expr ) ) { 173 177 index = 0; // xxx - get actual sizeof/alignof value?
Note:
See TracChangeset
for help on using the changeset viewer.