public static CodegenExpression CodegenMultiKeyFromArrayTransform( MultiKeyClassRef optionalMultiKeyClasses, CodegenMethod method, CodegenClassScope classScope) { var fromLambda = new CodegenExpressionLambda(method.Block).WithParam <object[]>("keys"); var fromClass = NewInstance <ProxyMultiKeyFromObjectArray>(fromLambda); // CodegenExpressionNewAnonymousClass fromClass = NewAnonymousClass(method.Block, typeof(MultiKeyFromObjectArray)); // CodegenMethod from = CodegenMethod // .MakeParentNode(typeof(object), typeof(MultiKeyCodegen), classScope) // .AddParam(typeof(object[]), "keys"); // fromClass.AddMethod("from", from); if (optionalMultiKeyClasses == null || optionalMultiKeyClasses.ClassNameMK == null) { fromLambda.Block.BlockReturn(ArrayAtIndex(Ref("keys"), Constant(0))); } else if (optionalMultiKeyClasses.MKTypes.Length == 1) { var paramType = optionalMultiKeyClasses.MKTypes[0]; if (paramType == null || !paramType.IsArray) { fromLambda.Block.BlockReturn(ArrayAtIndex(Ref("keys"), Constant(0))); } else { var mktype = MultiKeyPlanner.GetMKClassForComponentType(paramType.GetElementType()); fromLambda.Block.BlockReturn(NewInstance(mktype, FlexCast(paramType, ArrayAtIndex(Ref("keys"), Constant(0))))); } } else { var expressions = new CodegenExpression[optionalMultiKeyClasses.MKTypes.Length]; for (var i = 0; i < expressions.Length; i++) { expressions[i] = FlexCast(optionalMultiKeyClasses.MKTypes[i], ArrayAtIndex(Ref("keys"), Constant(i))); } var instance = optionalMultiKeyClasses.ClassNameMK.Type != null ? NewInstance(optionalMultiKeyClasses.ClassNameMK.Type, expressions) : NewInstanceInner(optionalMultiKeyClasses.ClassNameMK.Name, expressions); fromLambda.Block.BlockReturn(instance); } return(fromClass); }
public static CodegenExpression CodegenEvaluatorReturnObjectOrArrayWCoerce( ExprForge[] forges, Type[] targetTypes, bool arrayMultikeyWhenSingleEvaluator, CodegenMethod method, Type generator, CodegenClassScope classScope) { var evaluate = new CodegenExpressionLambda(method.Block) .WithParams(PARAMS); var evaluator = NewInstance <ProxyExprEvaluator>(evaluate); // CodegenMethod evaluate = CodegenMethod // .MakeParentNode(typeof(object), generator, classScope) // .AddParam(ExprForgeCodegenNames.PARAMS); // evaluator.AddMethod("evaluate", evaluate); var exprSymbol = new ExprForgeCodegenSymbol(true, null); var exprMethod = method .MakeChildWithScope(typeof(object), typeof(CodegenLegoMethodExpression), exprSymbol, classScope) .AddParam(ExprForgeCodegenNames.PARAMS); var expressions = new CodegenExpression[forges.Length]; for (var i = 0; i < forges.Length; i++) { expressions[i] = forges[i].EvaluateCodegen(forges[i].EvaluationType, exprMethod, exprSymbol, classScope); } exprSymbol.DerivedSymbolsCodegen(method, exprMethod.Block, classScope); if (forges.Length == 0) { exprMethod.Block.MethodReturn(ConstantNull()); } else if (forges.Length == 1) { var evaluationType = forges[0].EvaluationType; CodegenExpression coerced; if (arrayMultikeyWhenSingleEvaluator && evaluationType.IsArray) { var clazz = MultiKeyPlanner.GetMKClassForComponentType(evaluationType.GetElementType()); coerced = NewInstance(clazz, expressions[0]); } else { coerced = ExprNodeUtilityCodegen.CodegenCoerce(expressions[0], evaluationType, targetTypes?[0], false); } exprMethod.Block.MethodReturn(coerced); } else { exprMethod.Block.DeclareVar <object[]>("values", NewArrayByLength(typeof(object), Constant(forges.Length))); for (var i = 0; i < forges.Length; i++) { var coerced = ExprNodeUtilityCodegen.CodegenCoerce( expressions[i], forges[i].EvaluationType, targetTypes?[i], false); exprMethod.Block.AssignArrayElement("values", Constant(i), coerced); } exprMethod.Block.MethodReturn(Ref("values")); } evaluate.Block.BlockReturn(LocalMethod(exprMethod, REF_EPS, REF_ISNEWDATA, REF_EXPREVALCONTEXT)); return(evaluator); }