| 7678 | } |
| 7679 | |
| 7680 | asUINT asCCompiler::ImplicitConvObjectToPrimitive(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv convType, bool generateCode) |
| 7681 | { |
| 7682 | if( ctx->type.isExplicitHandle ) |
| 7683 | { |
| 7684 | // An explicit handle cannot be converted to a primitive |
| 7685 | if( convType != asIC_IMPLICIT_CONV && node ) |
| 7686 | { |
| 7687 | asCString str; |
| 7688 | str.Format(TXT_CANT_IMPLICITLY_CONVERT_s_TO_s, ctx->type.dataType.Format(outFunc->nameSpace).AddressOf(), to.Format(outFunc->nameSpace).AddressOf()); |
| 7689 | Error(str, node); |
| 7690 | } |
| 7691 | return asCC_NO_CONV; |
| 7692 | } |
| 7693 | |
| 7694 | // Find matching value cast behaviours |
| 7695 | // Here we're only interested in those that convert the type to a primitive type |
| 7696 | asCArray<int> funcs; |
| 7697 | asCObjectType *ot = CastToObjectType(ctx->type.dataType.GetTypeInfo()); |
| 7698 | if( ot == 0 ) |
| 7699 | { |
| 7700 | if( convType != asIC_IMPLICIT_CONV && node ) |
| 7701 | { |
| 7702 | asCString str; |
| 7703 | str.Format(TXT_CANT_IMPLICITLY_CONVERT_s_TO_s, ctx->type.dataType.Format(outFunc->nameSpace).AddressOf(), to.Format(outFunc->nameSpace).AddressOf()); |
| 7704 | Error(str, node); |
| 7705 | } |
| 7706 | return asCC_NO_CONV; |
| 7707 | } |
| 7708 | |
| 7709 | |
| 7710 | if( convType == asIC_EXPLICIT_VAL_CAST ) |
| 7711 | { |
| 7712 | for( unsigned int n = 0; n < ot->methods.GetLength(); n++ ) |
| 7713 | { |
| 7714 | // accept both implicit and explicit cast |
| 7715 | asCScriptFunction *mthd = engine->scriptFunctions[ot->methods[n]]; |
| 7716 | if( (mthd->name == "opConv" || mthd->name == "opImplConv") && |
| 7717 | mthd->parameterTypes.GetLength() == 0 && |
| 7718 | mthd->returnType.IsPrimitive() ) |
| 7719 | funcs.PushLast(ot->methods[n]); |
| 7720 | } |
| 7721 | } |
| 7722 | else |
| 7723 | { |
| 7724 | for( unsigned int n = 0; n < ot->methods.GetLength(); n++ ) |
| 7725 | { |
| 7726 | // accept only implicit cast |
| 7727 | asCScriptFunction *mthd = engine->scriptFunctions[ot->methods[n]]; |
| 7728 | if( mthd->name == "opImplConv" && |
| 7729 | mthd->parameterTypes.GetLength() == 0 && |
| 7730 | mthd->returnType.IsPrimitive() ) |
| 7731 | funcs.PushLast(ot->methods[n]); |
| 7732 | } |
| 7733 | } |
| 7734 | |
| 7735 | FilterConst(funcs, !ctx->type.dataType.IsReadOnly()); |
| 7736 | |
| 7737 | int funcId = 0; |
nothing calls this directly
no test coverage detected