| 6823 | } |
| 6824 | |
| 6825 | bool asCCompiler::CompileRefCast(asCExprContext *ctx, const asCDataType &to, bool isExplicit, asCScriptNode *node, bool generateCode) |
| 6826 | { |
| 6827 | bool conversionDone = false; |
| 6828 | |
| 6829 | asCArray<int> ops; |
| 6830 | |
| 6831 | // A ref cast must not remove the constness |
| 6832 | bool isConst = ctx->type.dataType.IsObjectConst(); |
| 6833 | |
| 6834 | // Find a suitable opCast or opImplCast method |
| 6835 | asCObjectType *ot = CastToObjectType(ctx->type.dataType.GetTypeInfo()); |
| 6836 | for( asUINT n = 0; ot && n < ot->methods.GetLength(); n++ ) |
| 6837 | { |
| 6838 | asCScriptFunction *func = engine->scriptFunctions[ot->methods[n]]; |
| 6839 | if( (isExplicit && func->name == "opCast") || |
| 6840 | func->name == "opImplCast" ) |
| 6841 | { |
| 6842 | // Skip functions with arguments as they are not valid cast operators |
| 6843 | if (func->parameterTypes.GetLength() > 0) |
| 6844 | continue; |
| 6845 | |
| 6846 | // Is the operator for the output type? |
| 6847 | if( func->returnType.GetTypeInfo() != to.GetTypeInfo() ) |
| 6848 | continue; |
| 6849 | |
| 6850 | // Can't call a non-const function on a const object |
| 6851 | if( isConst && !func->IsReadOnly() ) |
| 6852 | continue; |
| 6853 | |
| 6854 | ops.PushLast(func->id); |
| 6855 | } |
| 6856 | } |
| 6857 | |
| 6858 | // Filter the list by constness to remove const methods if there are matching non-const methods |
| 6859 | FilterConst(ops, !isConst); |
| 6860 | |
| 6861 | // If there is multiple matches, then pick the most appropriate one |
| 6862 | if (ops.GetLength() > 1) |
| 6863 | { |
| 6864 | // This should only happen if an explicit cast is compiled |
| 6865 | // and the type has both the opCast and opImplCast |
| 6866 | asASSERT(isExplicit); |
| 6867 | asASSERT(ops.GetLength() == 2); |
| 6868 | |
| 6869 | for (asUINT n = 0; n < ops.GetLength(); n++) |
| 6870 | { |
| 6871 | asCScriptFunction *func = engine->scriptFunctions[ops[n]]; |
| 6872 | if (func->name == "opImplCast") |
| 6873 | { |
| 6874 | ops.RemoveIndex(n); |
| 6875 | n--; |
| 6876 | } |
| 6877 | } |
| 6878 | } |
| 6879 | |
| 6880 | // Should only have one behaviour for each output type |
| 6881 | if( ops.GetLength() == 1 ) |
| 6882 | { |
nothing calls this directly
no test coverage detected