| 8805 | } |
| 8806 | |
| 8807 | asUINT asCCompiler::ImplicitConvPrimitiveToObject(asCExprContext *ctx, const asCDataType &to, asCScriptNode *node, EImplicitConv isExplicit, bool generateCode, bool allowObjectConstruct) |
| 8808 | { |
| 8809 | asCObjectType *objType = CastToObjectType(to.GetTypeInfo()); |
| 8810 | asASSERT( objType || CastToFuncdefType(to.GetTypeInfo()) ); |
| 8811 | if( !objType ) |
| 8812 | return asCC_NO_CONV; |
| 8813 | |
| 8814 | asCArray<int> funcs; |
| 8815 | if (objType->flags & asOBJ_VALUE) |
| 8816 | { |
| 8817 | // For value types the object must have a constructor that takes a single primitive argument either by value or as input reference |
| 8818 | for (asUINT n = 0; n < objType->beh.constructors.GetLength(); n++) |
| 8819 | { |
| 8820 | asCScriptFunction *func = engine->scriptFunctions[objType->beh.constructors[n]]; |
| 8821 | if (func->parameterTypes.GetLength() == 1 && |
| 8822 | func->parameterTypes[0].IsPrimitive() && |
| 8823 | !(func->inOutFlags[0] & asTM_OUTREF) && |
| 8824 | (isExplicit == asIC_EXPLICIT_VAL_CAST || !func->IsExplicit()) ) |
| 8825 | { |
| 8826 | funcs.PushLast(func->id); |
| 8827 | } |
| 8828 | } |
| 8829 | } |
| 8830 | else if (objType->flags & asOBJ_REF) |
| 8831 | { |
| 8832 | // For ref types the object must have a factory that takes a single primitive argument either by value or as input reference |
| 8833 | for (asUINT n = 0; n < objType->beh.factories.GetLength(); n++) |
| 8834 | { |
| 8835 | asCScriptFunction *func = engine->scriptFunctions[objType->beh.factories[n]]; |
| 8836 | if (func->parameterTypes.GetLength() == 1 && |
| 8837 | func->parameterTypes[0].IsPrimitive() && |
| 8838 | !(func->inOutFlags[0] & asTM_OUTREF) && |
| 8839 | (isExplicit == asIC_EXPLICIT_VAL_CAST || !func->IsExplicit())) |
| 8840 | { |
| 8841 | funcs.PushLast(func->id); |
| 8842 | } |
| 8843 | } |
| 8844 | } |
| 8845 | |
| 8846 | if( funcs.GetLength() == 0 ) |
| 8847 | return asCC_NO_CONV; |
| 8848 | |
| 8849 | // Check if it is possible to choose a best match |
| 8850 | asCExprContext arg(engine); |
| 8851 | arg.type = ctx->type; |
| 8852 | arg.exprNode = ctx->exprNode; // Use the same node for compiler messages |
| 8853 | asCArray<asCExprContext*> args; |
| 8854 | args.PushLast(&arg); |
| 8855 | asUINT cost = asCC_TO_OBJECT_CONV + MatchFunctions(funcs, args, 0, 0, 0, objType, false, true, false); |
| 8856 | if( funcs.GetLength() != 1 ) |
| 8857 | return asCC_NO_CONV; |
| 8858 | |
| 8859 | if( !generateCode ) |
| 8860 | { |
| 8861 | ctx->type.Set(to); |
| 8862 | return cost; |
| 8863 | } |
| 8864 |
nothing calls this directly
no test coverage detected