| 384 | } |
| 385 | |
| 386 | bool CastExpressionValue( ExpressionValue& value, const Type& from, const Type& to ) |
| 387 | { |
| 388 | if( from == to ) |
| 389 | { |
| 390 | return true; |
| 391 | } |
| 392 | |
| 393 | if( from.width == 1 && from.height == 1 ) |
| 394 | { |
| 395 | if( from.builtInType != to.builtInType ) |
| 396 | { |
| 397 | if( !CastExpressionElementValue( value[0], from.builtInType, to.builtInType ) ) |
| 398 | { |
| 399 | return false; |
| 400 | } |
| 401 | } |
| 402 | auto element = value[0]; |
| 403 | value.resize( to.width * to.height, element ); |
| 404 | return true; |
| 405 | } |
| 406 | |
| 407 | if( to.width > from.width || to.height > from.height ) |
| 408 | { |
| 409 | return false; |
| 410 | } |
| 411 | |
| 412 | ExpressionValue result; |
| 413 | for( int j = 0; j < to.height; ++j ) |
| 414 | { |
| 415 | for( int i = 0; i < to.width; ++i ) |
| 416 | { |
| 417 | ExpressionValueElement element = value[std::min( j, from.height ) * from.width + std::min( i, from.width )]; |
| 418 | if( from.builtInType != to.builtInType ) |
| 419 | { |
| 420 | if( !CastExpressionElementValue( element, from.builtInType, to.builtInType ) ) |
| 421 | { |
| 422 | return false; |
| 423 | } |
| 424 | } |
| 425 | result.push_back( element ); |
| 426 | } |
| 427 | } |
| 428 | value.clear(); |
| 429 | value.assign( result.begin(), result.end() ); |
| 430 | return true; |
| 431 | } |
| 432 | |
| 433 | static bool GetElementType( const Type& type, unsigned index, Type& elementType ) |
| 434 | { |
no test coverage detected