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

Function GetCommonType

shadercompiler/Type.cpp:704–759  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

702}
703
704bool GetCommonType( const Type& type0, const Type& type1, Type& type )
705{
706 int casts = 0;
707 if( !type1.CanImplicitCast( type0, casts ) && !type0.CanImplicitCast( type1, casts ) )
708 {
709 return false;
710 }
711 if( type0.symbol )
712 {
713 type = type0;
714 return true;
715 }
716 if( type1.symbol )
717 {
718 type = type1;
719 return true;
720 }
721 //static const int typePrecedence[] = { OP_BOOL, OP_INT, OP_UINT, OP_HALF, OP_FLOAT, OP_DOUBLE };
722 int prec0 = GetNumericTypePrecedence( type0.builtInType );
723 int prec1 = GetNumericTypePrecedence( type1.builtInType );
724 if( prec0 == -1 )
725 {
726 type = type0;
727 return true;
728 }
729 if( prec1 == -1 )
730 {
731 type = type1;
732 return true;
733 }
734 if( prec0 > prec1 )
735 {
736 type = type0;
737 }
738 else
739 {
740 type = type1;
741 }
742 if( type0.width == 1 || type1.width == 1 )
743 {
744 type.width = std::max( type0.width, type1.width );
745 }
746 else
747 {
748 type.width = std::min( type0.width, type1.width );
749 }
750 if( type0.height == 1 || type1.height == 1 )
751 {
752 type.height = std::max( type0.height, type1.height );
753 }
754 else
755 {
756 type.height = std::min( type0.height, type1.height );
757 }
758 return true;
759}
760
761int GetNumericTypePrecedence( int type )

Callers 3

EvaluateExpressionFunction · 0.85
NewBinaryExpressionFunction · 0.85
NewConditionalExpressionFunction · 0.85

Calls 2

GetNumericTypePrecedenceFunction · 0.85
CanImplicitCastMethod · 0.80

Tested by

no test coverage detected