MCPcopy Create free account
hub / github.com/carbonengine/trinity / EvaluateInitializer

Function EvaluateInitializer

shadercompiler/FXAnalyzer.cpp:474–532  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

472}
473
474bool 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;

Callers 3

FillDefaultsFunction · 0.85
EvaluateExpressionFunction · 0.85
GetStateValueFunction · 0.85

Calls 7

EvaluateExpressionFunction · 0.85
CastExpressionValueFunction · 0.85
GetNodeTypeMethod · 0.80
GetChildrenCountMethod · 0.80
ShowMessageMethod · 0.80
GetTokenMethod · 0.80
GetChildMethod · 0.45

Tested by

no test coverage detected