| 472 | } |
| 473 | |
| 474 | bool EvaluateInitializer( ParserState& state, ASTNode* node, Type& type, ExpressionValue& value, StateValue* stateValues ) |
| 475 | { |
| 476 | type.symbol = nullptr; |
| 477 | if( node->GetNodeType() == NT_INLINE_CONSTRUCTOR ) |
| 478 | { |
| 479 | int elements = type.width * type.height; |
| 480 | |
| 481 | for( unsigned i = 0; i < node->GetChildrenCount(); ++i ) |
| 482 | { |
| 483 | Type childType; |
| 484 | ExpressionValue childValue; |
| 485 | if( !EvaluateExpression( state, node->GetChild( i ), childType, childValue, stateValues ) ) |
| 486 | { |
| 487 | return false; |
| 488 | } |
| 489 | |
| 490 | Type newChildType = childType; |
| 491 | newChildType.builtInType = type.builtInType; |
| 492 | if( !CastExpressionValue( childValue, childType, newChildType ) ) |
| 493 | { |
| 494 | state.ShowMessage( node->GetToken()->fileLocation, EC_INVALID_IMPLICIT_CAST ); |
| 495 | return false; |
| 496 | } |
| 497 | |
| 498 | for( int j = 0; j < childType.width * childType.height; ++j ) |
| 499 | { |
| 500 | value.push_back( childValue[j] ); |
| 501 | if( elements == 0 ) |
| 502 | { |
| 503 | state.ShowMessage( node->GetToken()->fileLocation, EC_INCORRECT_NUMBER_OF_ARGS ); |
| 504 | return false; |
| 505 | } |
| 506 | elements--; |
| 507 | } |
| 508 | } |
| 509 | if( elements > 0 ) |
| 510 | { |
| 511 | state.ShowMessage( node->GetToken()->fileLocation, EC_INCORRECT_NUMBER_OF_ARGS ); |
| 512 | return false; |
| 513 | } |
| 514 | } |
| 515 | else |
| 516 | { |
| 517 | Type exprType; |
| 518 | if( !EvaluateExpression( state, node, exprType, value, stateValues ) ) |
| 519 | { |
| 520 | return false; |
| 521 | } |
| 522 | if( exprType != type ) |
| 523 | { |
| 524 | if( !CastExpressionValue( value, exprType, type ) ) |
| 525 | { |
| 526 | state.ShowMessage( node->GetLocation(), EC_TYPE_MISMATCH ); |
| 527 | return false; |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | return true; |
no test coverage detected